Java 3D API official tutorial [TRANSLATION 1]

Source: Internet
Author: User
Java 3D API official tutorial [TRANSLATION 1]

Start learning Java3D APIs

1

Chapter 1: getting started

Objectives of this chapter:

After learning this chapter, you can:

• You can use some basic terms to explain what Java3D is.

• Describes the basic structure of Java3D programs.

• Identifies many classes in Java3D APIs.

• Compile a simple Java3D animation program.

Java 3D API is an interface used to compile programs for displaying and interacting with 3D graphics objects. Java 3D is also a standard extension in the Java SDK Java2 (JDK. This API provides a high-end construction method for creating and manipulating a 3D image and rendering some data structures of the image. Java3D allows you to create images, visualize images,AnimationAnd functions of 3D interactive graphics applications.

1.1 What is Java 3D API?

Javae 3D APIs are collectively referred to as a series of hierarchical Java classes that act as interfaces for complex 3D graphics and sound Rendering Systems.

Programmers can use Java3D to develop high-end applications that create and manipulate 3D graphics objects. This graphic object is in a rendered virtual world (virtual universe. This API is designed for flexible and convenient creation of virtual environments of various sizes. It can be as large as a large empty object and as small as an atom.

In addition to these functions, APIs are directly used. APIs can automatically process rendering details. Due to the advantages of Java thread mechanism, Java3D Renderer works in parallel. The Renderer can also automatically optimize and improve rendering performance.

A Java3D program creates the actual Java3D object and places it in the scene graph data structure. In this scenario, all 3D objects are stored in a tree structure that completely specifies the virtual world content and how it is rendered,

Java3D can be used to write applications that can run independently, applets that can be embedded in a browser, or both.

Java 3D API 1.2

Each Java3D program at least partially integrates objects from the Java class hierarchy. The collection of these objects is called virtual world (Virtual universe), Which is the object to be rendered. This API defines more than 100 classes in the javax. Media. j3d package. These classes are generally called Java3D core classes.

There are hundreds of attributes and methods in the Java3D API. However, building a simple virtual world that contains animation functions requires only a few classes. This chapter discusses how to render a simple virtual world with few object sets and interactions.

This chapter contains a simple but complete development process of a program called hellojava3d. This program shows a cube that can be rotated. This sample program is developed step by step, therefore, this process uses many versions to demonstrate every part of Java 3D programming. All programs in this tutorial can obtain the electronic version. For more information, see "get this tutorial" in the preface. [Note: http://java.sun.com/products/java-media/3d/collateral/#.

In addition to the Java3D core package, Java3D programming also uses other packages, such as COM. sun. j3d. utils, this package is usually called the Java3D tool class. The core class only contains the lowest-level class required in Java3D programming, and the tool class is a convenient and powerful supplement to the core class.

There are four types of tools: Content loader, Scene Graph construction helper, graphics, and convenient tools. In the future, some functions, such as [non-uniform rational B-spline, non-even rational B-spline], will also be added to the tool class, rather than the Java3D core package. Some tool classes may be moved to the core package in future Java 3D API versions.

The tool class greatly reduces the number of lines of code in the Java3D program. In addition to the Java3D core class and tool package, each Java3D program also references Java. AWT package and javax. classes in the vecmath package. java. the AWT package is abstract objective wingtoolkit (AWT ). the AWT class is used to create display and rendering scenarios and windows. The javax. vecmath package defines classes for mathematical operations on points, vectors, matrices, and other mathematical objects.

In the remaining tutorial, the Vocabulary Visual Object (Visual ObjectIs an object in a scene chart, such as a cube or sphere. Object (Object) Is an instance of a class. Content (Content) Refers to all the visual objects in a scenario diagram.

1.3 Build scenario Diagram

A Java3D virtual world is created from a scene map, which is built by an instance of the Java3D class. A scene gallery is an object that defines graphics, sound, light, position, direction, and the surface attributes of visual objects and sound objects. A Common graphic definition is a data structure composed of nodes and edges. A node is a data element, while an edge is the relationship between data elements. The node in the scenario diagram is an instance of the Java3D class, And the edge shows theseJavaThe relationship between 3D instances. The most common relationship is the parent-child relationship (Parent-child relationshipA group of nodes can have any number of children but only one parent. One leaf may have one parent but no child.

Another link is reference (Reference). A node component in a reference and scenario graph node (NodecomponentObject Association. The node component defines the graphic and surface attributes used to render a visual object.

A Java 3D scene map is a tree structure built by a bunch of nodes with parent-child relationships. In the tree structure, only one node is the root node, and the common node can be accessed along the arc edge starting from the root. The node in the tree structure has no loop. A scenario diagram is formed by a tree rooted in a local object. Node components and referenced arc edges are not part of the scene tree.

In the tree structure, there is only one path from the root node to the leaf node. Therefore, there is only one path from the root of the scene graph to each of its leaf nodes. From the scene graph root node to the path of the characteristic leaf result, we call this scene graph path of the leaf node (Scene Graph path). Therefore, a scene map path only leads to one leaf node. In the scenario diagram, there is a path from the root to each leaf node. The path of each scene graph in the Java3D scene graph completely defines the leaf state information of the path. The status information includes the location, direction, and size of the visual object. It can be seen that the visual attributes of each visual object are only determined by the scene and scene. Java3D rendering leverages this to render leaf objects only effectively in the order it defines. Java 3D programmers generally do not need to control the order of rendering objects. [Original note: Java3D programmers can only control the order of rendering objects by using orderedgroup nodes.TutorialThis section is not discussed. See Java3DAPIStandard document]

 

In the tree structure, there is only one path from the root node to the leaf node. Therefore, there is only one path from the root of the scene graph to each of its leaf nodes. From the scene graph root node to the path of the characteristic leaf result, we call this scene graph path of the leaf node (Scene Graph path). Therefore, a scene map path only leads to one leaf node. In the scenario diagram, there is a path from the root to each leaf node. The path of each scene graph in the Java3D scene graph completely defines the leaf state information of the path. The status information includes the location, direction, and size of the visual object. It can be seen that the visual attributes of each visual object are only determined by the scene and scene. Java3D rendering leverages this to render leaf objects only effectively in the order it defines. Java 3D programmers generally do not need to control the order of rendering objects. [Original note: The orderedgroup class node can only be used by Java 3D programmers to control the rendering Object Sequence. This section is not discussed in this tutorial. For details, see Java3D API specification documentation]

The graphic representation of a scene chart can be used as a design tool or a Java3D program document. A scenario diagram is generally drawn using some standard graphic tags, as shown in Figure 1-1. Java 3D programs may contain more than the objects in the scenario diagram.

You can use the above sign set to design a Java3D virtual world scene map. After the design is completed, the design of the scenario diagram is the specification of the program design. When the program is also designed, the same scenario diagram is the final expression of the Program (assuming that the program is based on the design diagram ). A scenario diagram drawn from an existing program can be used as a document to create a scenario diagram.

You can use the above sign set to design a Java3D virtual world scene map. After the design is completed, the design of the scenario diagram is the specification of the program design. When the program is also designed, the same scenario diagram is the final expression of the Program (assuming that the program is based on the design diagram ). A scenario diagram drawn from an existing program can be used as a document to create a scenario diagram.

Each tag shown on the left of Figure 1-1 represents every object in the scenario diagram. The first two tags represent objects of a specific class, that is, objects of the virtualuniversee and locale classes, the following three classes are often used to mark the subclass of a specific object [Translator's note: group subclass object, etc.]. The last tag is used to represent objects of other classes. The solid-line arrow indicates that there is a parent-child relationship between the two connected objects. The dotted arrow shows that an object is referenced by another object. The referenced object can be shared by different branches in a scenario diagram. 1-2 examples of a simple scenario diagram are shown.


It is also possible to create an incorrect scenario diagram at ordinary times, as shown in Example 1-3 of an unreasonable scenario diagram.

Figure 1-3 illustrates the unreasonable scenario because it conflicts with the rules of a directed acyclic graph or Dag. the problem is that both transformgroup objects use the same shape3d leaf subobject as their children. Remember that a leaf node can have only one parent, that is, there can be only one path from the locale object to the leaf node (or there can be only one path from the leaf node to the locale object ). You may think that the scenario shown in Figure 1-3 defines three visual objects in the virtual world. It seems that this scene map defines two objects by reusing the Visual Object (shape3d) on the right of the image. Conceptually, each transformgroup object serves as the parent of the shared shape3d. This shape3d visualization object allows an image to be placed in different places. However, because the relationship between the parent and child sides does not constitute a tree structure, the scene graph is invalid. In this example, the shape3d object has more than one parent.

 

It is correct to discuss tree structures and Directed Acyclic graphs. However, the Java 3D runtime system reports errors between parent-child relationships. The restriction of the tree structure is that each shape3d object can have only one parent.

 

From the example shown in Figure 1-3, the 'Multiple pares' exception is reported during runtime. Figure 1-4 shows a solution to this illegal scenario. Each shape3d has only one parent.

A Java3D program that defines an unreasonable (method) scene graph may be compiled but not rendered at runtime. When a Java3D program that defines an invalid scenario graph runs, the Java3D system detects this problem and reports an exception. The program will continue to run, but the result is that the program should be closed without any rendered images. Each scene graph has a unique virtualuniverse, which has a series of locale objects.

 

A Locale object that provides a reference point in the virtual world. The Locale object can be seen as a marker for defining the location of a visual object in the virtual world. A Java3D program has more than one virtualuniverse object, which is technically feasible. Therefore, multiple locale objects can be defined in the virtual world. However, there is no internal communication between multiple virtual worlds. Further, a scene map cannot be stored in multiple virtual worlds. At the same time, we strongly recommend that you only have one and only one virtualuniverse in a Java 3D program. A virtualuniverse may be referenced in multiple locale objects, but more Java 3D programs only have one locale object. Each locale object can be used as the root node of multiple subgraphs in the scenario diagram. See Figure 1-2 as an example of a scenario diagram. Note that the locale object in the diagram has two subgraph branches.

 

A branchgroup object is the root node of a subgraph or the root node of a branch graph. Scenario subgraphs can be divided into two types:View branch graph) andContent branch diagram (Content branch Graph.). The content branch diagram specifies the content of the virtual world --Graphics, surfaces, movements, positions, sound and light.The view branch subgraph specifies the view parameters, such as the viewing position and direction. In general, two subgraphs specify a lot of work to complete rendering.

1.3.1 high-endJava3D API class hierarchy

Figure 1-5 shows the first three layers in the Java 3D API class hierarchy.


Virtualuniverse, locale, group, and leaf classes are at the class level. Except virtualuniverse and locale objects, the rest of the scene graph consists of scenegraphobject objects. Scenegraphobject is almost the superclass of every core class and tool class in Java3D. [Note: superclass is the upper class, which can be a parent class or an ancestor class].

Scenegraphobject has two subclasses: node class nodecomponent. class. The Node subclass provides the vast majority of objects in the scenario diagram. A Node object can be a group or a leaf node object.

Group and leaf are superclasses of a series of classes. Here we can see at a glance the subclass of the node class, which has two subclasses, And the nodecomponent class, which will be explained in the Construction of Java3D program after the background knowledge is introduced.

Node Class

Node is an abstract superclass of the group and leaf classes. node defines some important public methods for its subclass. Information about some methods will be mentioned after more background information. Child classes of node constitute subgraphs.

Group Class

A group class is a superclass used to specify the position and direction of a visual object in the virtual world. The two lower-level classes of the group class are branchgroup, Which is transformgroup. In the graphic representation of the scene graph, the Group mark (represented by a circle ). Branchgroups indicates GB, transformgroups indicates TG, and so on. See Figure 1-2 for specific examples.

Leaf class

Leaf is a superclass used to specify the shape, sound, and action of visual objects in the virtual world. Some sub-classes of leaf, such as shape3d, light, behav parent or, and sound. These objects cannot have their own children and may reference nodecomponents objects.

Nodecomponent class

Nodecomponent class is a superclass used to specify the graphics, surfaces, textures, and material attributes of shape3d (leaf) node objects. Nodecomponents is not an integral part of a scene chart, but is referenced by nodecomponents. A nodecomponent object may be referenced by multiple shape3d objects (for example, multiple shape3d objects can be assigned to the same material object ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.