⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concepts.html

📁 JAVA多媒体开发类库说明
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>Java 3D API - Concepts</title></head><body><h2>Java 3D Concepts</h2><p>The Java 3D API specification serves to define objects, methods, andtheir actions precisely. Describing how to use an API belongs in atutorial or programmer'sreference manual, and is well beyond the scope of this specification.However, a short introduction to the main concepts in Java 3D willprovide the context for understanding the detailed, but isolated,specification found in the class and method descriptions. We introducesome of the key Java 3D concepts and illustrate them with some simpleprogram fragments.</p><p></p><h2>Basic Scene Graph Concepts</h2><p>A scene graph is a "tree" structure that contains data arranged in ahierarchical manner. The scene graph consists of parent nodes, childnodes, and data objects. The parent nodes, called Group nodes, organizeand, in some cases, control how Java 3D interprets their descendants.Group nodes serve as the glue that holds a scene graph together. Childnodes can be either Group nodes or Leaf nodes. Leaf nodes have nochildren. They encode the core semantic elements of a scene graph- forexample, what to draw (geometry), what to play (audio), how toilluminate objects (lights), or what code to execute (behaviors). Leafnodes refer to data objects, called NodeComponent objects.NodeComponent objects are not scene graph nodes, but they contain thedata that Leaf nodes require, such as the geometry to draw or the soundsample to play.</p><p>A Java 3D application builds and manipulates a scene graph byconstructing Java 3D objects and then later modifying those objects byusing their methods. A Java 3D program first constructs a scene graph,then, once built, hands that scene graph to Java 3D for processing.</p><p>The structure of a scene graph determines the relationships amongtheobjects in the graph and determines which objects a programmer canmanipulate as a single entity. Group nodes provide a single point forhandling or manipulating all the nodes beneath it. A programmer cantune a scene graph appropriately by thinking about what manipulationsan application will need to perform. He or she can make a particularmanipulation easy or difficult by grouping or regrouping nodes invarious ways.</p><p></p><h3>Constructing a Simple SceneGraph</h3><p>The following code constructs a simple scene graph consisting of agroup node and two leafnodes.<br></p><p><font size="-1"><b><a name="Listing_1"><i>Listing 1</i> &#8211; Code for Constructing a Simple Scene Graph</a></b></font></p><hr><pre>Shape3D myShape1 = new Shape3D(myGeometry1, myAppearance1);<br>Shape3D myShape2 = new Shape3D(myGeometry2);<br>myShape2.setAppearance(myAppearance2);<br><br>Group myGroup = new Group();<br>myGroup.addChild(myShape1);<br>myGroup.addChild(myShape2);<br></pre><hr><p>It first constructs one leaf node, the first of two Shape3Dnodes, using a constructor that takes both a Geometry and an AppearanceNodeComponent object. It then constructs the second Shape3D node, withonly a Geometry object. Next, since the second Shape3D node was createdwithout an Appearance object, it supplies the missing Appearance objectusing the Shape3D node's <code>setAppearance</code> method. At thispoint both leaf nodes have been fully constructed. The code nextconstructs a group node to hold the two leaf nodes. Ituses the Group node's <code>addChild</code> method to add the two leafnodes as children to the group node, finishing the construction of thescene graph. <a href="#Figure_1">Figure1</a>shows the constructed scene graph, all the nodes, the node componentobjects, and the variables used in constructing the scene graph.</p><p><a name="Figure_1"></a><img style="width: 491px; height: 279px;" alt="A Simple Scene Graph" title="A Simple Scene Graph" src="Concepts1.gif"></p><ul>  <font size="-1"><b><i>Figure 1</i> &#8211; A Simple Scene Graph</b></font></ul><h3>A Place For Scene Graphs</h3>Once a scene graph has been constructed, thequestion becomes what to do with it? Java 3D cannot start rendering ascene graph until a program "gives" it the scene graph. The programdoes this by inserting the scene graph into the virtual universe.<p>Java 3D places restrictions on how a program can insert a scenegraphinto a universe.</p><p>A Java 3D environment consists of two superstructure objects,VirtualUniverse and Locale, and one or more graphs, rooted by a specialBranchGroup node. <a href="#Figure_2">Figure 2</a> shows these objectsin context with other scene graph objects.</p><p>The VirtualUniverse object defines a universe. A universe allows aJava3D program to create a separate and distinct arena for defining objectsand their relationships to one another. Typically, Java 3D programshave only one VirtualUniverse object. Programs that have more than oneVirtualUniverse may share NodeComponent objects but not scene graphnode objects.</p><p>The Locale object specifies a fixed position within the universe.Thatfixed position defines an origin for all scene graph nodes beneath it.The Locale object allows a programmer to specify that origin veryprecisely and with very high dynamic range. A Locale can accuratelyspecify a location anywhere in the known physical universe and at theprecision of Plank's distance. Typically, Java 3D programs have onlyone Locale object with a default origin of (0, 0, 0). Programs thathave more than one Locale object will set the location of theindividual Locale objects so that they provide an appropriate localorigin for the nodes beneath them. For example, to model the Marslanding, a programmer might create one Locale object with an origin atCape Canaveral and another with an origin located at the landing siteon Mars.</p><p><a name="Figure_2"></a><img style="width: 500px; height: 286px;" alt="Content Branch, View Branch, Superstructure" title="Superstructure" src="Concepts2.gif"></p><ul>  <font size="-1"><b><i>Figure 2</i> &#8211; Content Branch, View Branch, andSuperstructure</b></font></ul><p>The BranchGroup node serves as the root of a <em>branch graph</em>.Collectively, the BranchGroup node and all of its children form thebranch graph. The two kinds of branch graphs are called contentbranches and view branches. A <em>content branch</em> contains onlycontent-related leaf nodes, while a <em>view branch</em>contains a ViewPlatform leaf node and may contain other content-relatedleaf nodes. Typically, a universe contains more than one branchgraph-one view branch, and any number of content branches.</p><p>Besides serving as the root of a branch graph, the BranchGroup nodehastwo special properties: It alone may be inserted into a Locale object,and it may be compiled. Java 3D treats uncompiled and compiled branchgraphs identically, though compiled branch graphs will typically rendermore efficiently.</p><p>We could not insert the scene graph created by our simple example (<a href="#Listing_1">Listing1</a>) into a Locale because it does not have a BranchGoup node forits root. <a href="#Listing_2">Listing 2</a>shows a modified version of our first code example that creates asimple content branch graph and the minimum of superstructure objects.Of special note, Locales do not have children, and they are not part ofthe scene graph. The method for inserting a branch graph is <code>addBranchGraph</code>,whereas <code>addChild</code> is the method for adding children to allgroup nodes.</p><p><font size="-1"><b><i><a name="Listing_2"></a>Listing 2</i> &#8211; Code for Constructing aScene Graph and SomeSuperstructure Objects</b></font></p><hr><pre>Shape3D myShape1 = new Shape3D(myGeometry1, myAppearance1);<br>Shape3D myShape2 = new Shape3D(myGeometry2, myAppearance2);<br><br>BranchGroup myBranch = new BranchGroup();<br>myBranch.addChild(myShape1);<br>myBranch.addChild(myShape2);<br>myBranch.compile();<br><br>VirtualUniverse myUniverse = new VirtualUniverse();<br>Locale myLocale = new Locale(myUniverse);<br>myLocale.addBranchGraph(myBranch);<br></pre><hr><h3>SimpleUniverse Utility</h3>Most Java 3D programs build an identical set of superstructure and viewbranch objects, so the Java 3D utility packages provide a <code>universe</code>package for constructing and manipulating the objects in a view branch.The classes in the <code>universe</code> package provide a quick meansfor building a single view (single window) application. <a href="#Listing_3">Listing 3</a>shows a code fragment for using the SimpleUniverse class. Note that theSimpleUniverse constructor takes a Canvas3D as an argument, in thiscase referred to by the variable <code>myCanvas</code>.<p><font size="-1"><b><i><a name="Listing_3"></a>Listing 3</i> &#8211; Codefor Constructing a Scene Graph Using the UniversePackage</b></font></p><hr><pre>import com.sun.j3d.utils.universe.*;<br><br>Shape3D myShape1 = new Shape3D(myGeometry1, myAppearance1);<br>Shape3D myShape2 = new Shape3D(myGeometry2, myAppearance2);<br><br>BranchGroup myBranch = new BranchGroup();<br>myBranch.addChild(myShape1);<br>myBranch.addChild(myShape2);<br>myBranch.compile();<br><br>SimpleUniverse myUniv = new SimpleUniverse(myCanvas);<br>myUniv.addBranchGraph(myBranch);<br></pre><hr><h3>Processing a Scene Graph</h3>When given a scene graph, Java 3D processes that scene graph asefficiently as possible. How a Java 3D implementation processes a scenegraph can vary, as long as the implementation conforms to the semanticsof the API. In general, a Java 3D implementation will render allvisible objects, play all enabled sounds, execute all triggeredbehaviors, process any identified input devices, and check for andgenerate appropriate collision events.<p>The order that a particular Java 3D implementation renders objectsontothe display is carefully not defined. One implementation might renderthe first Shape3D object and then the second. Another might firstrender the second Shape3D node before it renders the first one. Yetanother implementation may render both Shape3D nodes in parallel.</p><p></p><h2>Features of Java 3D</h2>Java 3D allows a programmer to specify a broad range of information. Itallows control over the shape of objects, their color, andtransparency. It allows control over background effects, lighting, andenvironmental effects such as fog. It allows control over the placementof all objects (even nonvisible objects such as lights and behaviors)in the scene graph and over their orientation and scale. It allowscontrol over how those objects move, rotate, stretch, shrink, or morphover time. It allows control over what code should execute, what soundsshould play, and how they should sound and change over time.<p>Java 3D provides different techniques for controlling the effect ofvarious features. Some techniques act fairly locally, such as gettingthe color of a vertex. Other techniques have broader influence, such aschanging the color or appearance of an entire object. Still othertechniques apply to a broad number of objects. In the first two cases,the programmer can modify a particular object or an object associatedwith the affected object. In the latter case, Java 3D provides a meansfor specifying more than one object spatially.</p><p></p><h3>Bounds</h3>Bounds objects allow a programmer to define a volume in space. Thereare three ways to specify this volume: as a box, a sphere, or a set ofplanes enclosing a space.<p>Bounds objects specify a volume in which particular operationsapply.Environmental effects such as lighting, fog, alternate appearance, andmodel clipping planes use bounds objects to specify their region ofinfluence. Any object that falls within the space defined by the boundsobject has the particular environmental effect applied. The proper useof bounds objects can ensure that these environmental effects areapplied only to those objects in a particular volume, such as a lightapplying only to the objects within a single room.</p><p>Bounds objects are also used to specify a region of action.Behaviorsand sounds execute or play only if they are close enough to the viewer.The use of behavior and sound bounds objects allows Java 3D to cullaway those behaviors and sounds that are too far away to affect theviewer (listener). By using bounds properly, a programmer can ensurethat only the relevant behaviors and sounds execute or play.</p><p>Finally, bounds objects are used to specify a region of applicationforper-view operations such as background, clip, and soundscape selection.For example, the background node whose region of application is closestto the viewer is selected for a given view.</p><p></p><h3>Nodes</h3>All scene graph nodes have an implicit location in space of (0, 0, 0).For objects that exist in space, this implicit location provides alocal coordinate system for that object, a fixed reference point. Evenabstract objects that may not seem to have a well-defined location,such as behaviors and ambient lights, have this implicit location. Anobject's location provides an origin for its local coordinate systemand, just as importantly, an origin for any bounding volume informationassociated with that object.<h3>Live and/or Compiled</h3>All scene graph objects, including nodes and node component objects,are either part of an active universe or not. An object is said to be <em>live</em>if it is part of an active universe. Additionally, branch graphs areeither <em>compiled</em>or not. When a node is either live or compiled, Java 3D enforces accessrestrictions to nodes and node component objects. Java 3D allows onlythose operations that are enabled by the program before a node or nodecomponent becomes live or is compiled. It is best to set capabilitieswhen you build your content. <a href="#Listing_4">Listing 4</a> showsan example where we create a TransformGroup node andenable it for writing.<p><font size="-1"><b><i><a name="Listing_4"></a>Listing 4</i> &#8211;Capabilities Example</b></font></p><hr><pre>TransformGroup myTrans = new TransformGroup();<br>myTrans.setCapability(Transform.ALLOW_TRANSFORM_WRITE);<br></pre><hr><p>By setting the capability to write the transform, Java 3D will allowthe following code to execute:</p><pre>myTrans.setTransform3D(myT3D);<br></pre><p>It is important to ensure that all needed capabilities are set andthatunnecessary capabilities are not set. The process of compiling a branchgraph examines the capability bits and uses that information to reducethe amount of computation needed to run a program.</p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -