[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AW: AW: [x3d-public] containerField
- To: "'George Anastassakis'" <anastas@unipi.gr>, "'X3D PUBLIC'" <x3d-public@web3d.org>
- Subject: AW: AW: [x3d-public] containerField
- From: "Mirko Gontek" <mgontek@yahoo.de>
- Date: Fri, 3 Mar 2006 15:57:56 +0100
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=Received:From:To:Subject:Date:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:X-MimeOLE:In-Reply-To:Thread-Index; b=CUbexu7uF6NHUiDfOHhfINCx8qQpwjvmN52a1TKI2742HJTrLs8RFhuTDcBnEIB0/aScuAo08mg4npcG2mK8LKsplXe7UiPQNedLkPcN5vsStJXq9700bKp1UpAwPuEEFHX0sByAUebnoY/kawizDWXRcsqxswIf3J5ucJLE9H8= ;
- In-reply-to: <001701c63e5d$79cff3f0$0400000a@timemachineiv>
- Sender: owner-x3d-public@web3d.org
- Thread-index: AcY+Y1JLEJS2fpfDSSWo7eyUehBvQgAbsSCA
thanks georg and alan! i can live with the 2seconds sleep for the moment.
maybe it would be nice to have a "flush" method for the buffer.
mirko gontek
-----Ursprüngliche Nachricht-----
Von: owner-x3d-public@web3d.org [mailto:owner-x3d-public@web3d.org] Im
Auftrag von George Anastassakis
Gesendet: Freitag, 3. März 2006 01:58
An: 'X3D PUBLIC'
Betreff: Re: AW: [x3d-public] containerField
Here's a modified version of your code that adds a button to the frame to
call the traversal function. If you click on it, the output is as expected.
To my understanding, this is due to the fact that addRootNode is a buffered
operation, that is, it does not happen at the exact time you call it but
later. This is why getRootNodes does not return anything if you call it
immediately after a call to addRootNode.
George
import java.io.*;
import java.awt.*;
import javax.swing.*;
import org.web3d.x3d.sai.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class CreateSG
extends JFrame {
X3DScene mainScene;
public CreateSG() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
// Create an SAI component
X3DComponent x3dComp = BrowserFactory.createX3DComponent(null);
// Add the component to the UI
JComponent x3dPanel = (JComponent) x3dComp.getImplementation();
contentPane.add(x3dPanel, BorderLayout.CENTER);
JButton jbTraverse = new JButton("Traverse");
jbTraverse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionTraverse();
}
});
contentPane.add(jbTraverse, BorderLayout.SOUTH);
// Get an external browser
ExternalBrowser x3dBrowser = x3dComp.getBrowser();
setSize(500, 500);
show();
// create a new Scene:
ProfileInfo profile = x3dBrowser.getProfile("Immersive");
mainScene = x3dBrowser.createScene(profile, null);
// add a X3DTransform to Scene
createTransform(mainScene);
}
public void actionTraverse() {
//get rootNodes and traverse SG
X3DNode[] roots = mainScene.getRootNodes();
traverse(roots);
}
/**
* creates one X3DTransform with two Children: a Shape and a TouchSensor
* adds the Transform to the scene as rootNode
*/
private void createTransform(X3DScene mainScene) {
//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, add Shape and TouchSensor as children
X3DNode transf = mainScene.createNode("Transform");
MFNode ch = (MFNode) transf.getField("children");
ch.setValue(2, new X3DNode[] {shape, touch});
//add Transform to Scene as a rootNode
mainScene.addRootNode(transf);
}
/**
* traverse all Nodes and output NodeNames
*/
private void traverse(X3DNode[] nodes) {
int len = nodes.length;
int types[];
X3DFieldDefinition[] decls;
int dlen;
X3DNode node;
for (int i = 0; i < len; i++) {
node = nodes[i];
//this is never reached:
System.out.println("Node found:" + node.getNodeName());
decls = node.getFieldDefinitions();
dlen = decls.length;
int ftype;
int atype;
MFNode mfnode;
SFNode sfnode;
X3DNode[] snodes;
for (int j = 0; j < dlen; j++) {
ftype = decls[j].getFieldType();
atype = decls[j].getAccessType();
if (atype == X3DFieldTypes.INPUT_OUTPUT ||
atype == X3DFieldTypes.INITIALIZE_ONLY) {
if (ftype == X3DFieldTypes.MFNODE) {
mfnode = (MFNode) node.getField(decls[j].getName());
snodes = new X3DNode[mfnode.size()];
mfnode.getValue(snodes);
traverse(snodes);
}
else if (ftype == X3DFieldTypes.SFNODE) {
sfnode = (SFNode) node.getField(decls[j].getName());
snodes = new X3DNode[1];
snodes[0] = sfnode.getValue();
if (snodes[0] != null) {
traverse(snodes);
}
}
}
}
}
}
/**
* Main method.
*
* @param args None handled
*/
public static void main(String[] args) {
CreateSG demo = new CreateSG();
}
}
----- Original Message -----
From: "Mirko Gontek" <mgontek@yahoo.de>
To: <giles@oz.net>
Cc: "'X3D PUBLIC'" <x3d-public@web3d.org>
Sent: Friday, March 03, 2006 1:08 AM
Subject: 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
-------------------------------------------------------------------------
for list subscription/unsubscription,
go to http://www.web3d.org/cgi-bin/public_list_signup/lwgate/listsavail.html
___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
-------------------------------------------------------------------------
for list subscription/unsubscription,
go to http://www.web3d.org/cgi-bin/public_list_signup/lwgate/listsavail.html