[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: AW: [x3d-public] containerField



ok, i condensed it to one file in the attachment. it does the following:

a browser and a scene is created
method "createTransform" adds a transform with two children as rootNode to
the scene
method "traverse" traverses the scenegraph recursively from the rootNode. it
should output the nodeNames of all Nodes in the scenegraph, but it does not
output anything. (the nodes are definitively there, because you can see the
shape in the gui).

my question: why is no node found by "traversal"? when loading the x3d scene
from a file, it does work. is it a timing prob? 

the recursive traversal in findChildren of course makes no sense here. but
later more children should be added to the transform and its children. so
that there will still be one rootNode (namely "transf") containing all other
nodes of the scenegraph. is this a proper approach?

thanks, mirko gontek


-----Ursprüngliche Nachricht-----
Von: Alan Hudson [mailto:giles@yumetech.com] 
Gesendet: Donnerstag, 2. März 2006 19:10
An: Mirko Gontek
Cc: 'X3D PUBLIC'
Betreff: Re: AW: [x3d-public] containerField

Mirko Gontek wrote:
> thank you! maybe someone can help me with another problem.... 
> 
> i try to create a scenegraph with sai that looks like this:
> 
> 		<Transform>
> 			<Shape>
> 			   <Sphere/>
> 			</Shape>
> 			<TouchSensor/>
> 		</Transform>
> 
> i did this:
> 
>             //create Shape            
>             X3DNode shape = mainScene.createNode("Shape");
>             SFNode shape_geometry = (SFNode) (shape.getField("geometry"));
>             X3DNode sphere = mainScene.createNode("Sphere");            
>             shape_geometry.setValue(sphere);
>             
>             //create TouchSensor
>             X3DNode touch = mainScene.createNode("TouchSensor");
>     
>             //create Transform
>             X3DNode transf = mainScene.createNode("Transform");
>             
>             //add shape and touchSensor as children to Transform
>             MFNode ch = (MFNode)transf.getField("children"); //or 
> addChildren
>             ch.setValue(2, new X3DNode[] {shape, touch });
>             
> 	    //add Transform to Scene
>             mainScene.addRootNode(transf);
> 
> 
> but: where are the children? they are visible, but here nothing appears:
> 
> 		MFNode children = (MFNode)transf.getField("children");
>             		for(int j=0; j<children.size();j++){
>                  	X3DNode n = children.get1Value(j);
>                 	System.out.println(n.getNodeName());
>             		}
> 
might be a timing issue.  If your reading them directly after writing them
they may not be in the nodes yet.  The writes are buffered till the frame
they are processed in.

> and: when walking the scenegraph with rootNodes as parameter (like in 
> the
> SAISGWalkDemo) it does not work:
> 		X3DNode[] roots = mainScene.getRootNodes();
> 		walkSG(roots);
> 
> i thought that getRootNodes() returned all Nodes of the Scene. is that 
> wrong? if yes, how can i achieve this? what would be  the correct way 
> to make all nodes of the scene available (also the children of the
transform)?
>

getRootNodes returns all the top level nodes(in your case everything added
with addRootNode).  I haven't tried what your doing, so perhaps the
rootNodes field has not been updated correctly.


Not sure I follow the whole code.  Can you send me a complete .java file and
I'll look at it.

--
Alan Hudson

President Yumetech, Inc.                               www.yumetech.com
President Web3D Consortium                             www.web3d.org
206 340 8900

Attachment: CreateSG.java
Description: Binary data