> From: Rui Prada <[EMAIL PROTECTED]>
> At 01:51 PM 4/22/99 +0200, Lars Lackmann wrote:
> >Hello,
> >
> >just general interest: If you want to use objects an several subtrees,
> >you have to use
> >SharedGroup and Link. Why not just add the object directly to several
> >subtrees by using addChild. Is this because of optimisation purposes or
> >are there other reasons ?
> >
> 
> I've built the scene in VRML, and use the VRML loader to create the java3D
> SceneGraph. The Loader creates the Link nodes!!!!


The loader creates Link notes to allow the J3D subgraph to appear another time 
in the scene graph.  If you only want to have one instance of the scene graph 
you can use the Link to get the SharedGroup and then remove the child sub-graph 
from the SharedGroup and use it directly.

Here are the details:

Java3D does not allow Nodes to appear multiple times in the scene graph.  If you 
want a Node to appear in more than one instance then you need to put the Node 
into a SharedGroup and have multiple Links point to the SharedGroup.

The getImplNode() method on VRML nodes means "give me a Java3D node which I can 
use to make a new instance of the Java3D subgraph assoicated with this VRML 
node."  If the subgraph associated with the VRML node is a NodeComponent (such 
as an Appearance) then getImplNode() will return the NodeComponent. If the J3D 
subgraph has Node in it (such as a Group or Shape3D), then the loader is forced 
to put the subgraph into a SharedGroup and return a Link so that the new 
instance won't cause an illegal sharing exception.

If you are using the Loader to get the only instance of the Node which will be 
made live, the Link/SharedGraph structure is not needed.  You can inquire the 
SharedGraph from the Link and then remove the child from the SharedGroup and 
attach the child directly.  Note: after removing the child, subsequent calls 
getImplNode() will return a Link to an empty SharedGroup.

If you want the VRML defined Node to appear multiple times you need to either 
use Links/SharedGroup or do a cloneTree() on the Node.  

One more note:  a SharedGroup can't have Behavior nodes in it.  So if the J3D 
subgraph for a VRML node contains a behavior (including a Billboard or LOD node) 
then getImplNode() will return a clone the tree instead of returning a Link.

Hope this helps,

Doug Gehringer
Sun Microsystems

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to