Node clone

I like to make a complete copy of a node and all of its children. I am thinking about using CloneNode but not sure if it copies all the information regarding the node I want to clone i.e. texture etc.



I also looked at Clone, but it doesnt show how I can make a copy of my node. How do you go about getting the info from your real node into the clone node?

tomcat

The thing about CloneNode is that it takes Geomtery as an argument, not a Node.



There are two classes that inherit from Spatial and they are Node and Geometry.



Geometry cannot have any children, but nodes can.



So unfortunetly, with the current CloneNode, you cannot do what is required.



DP

well, no.



If you have a single model that needs to be cloned.



Then simply do this:



Geometry geo = (Geometry)someModel.getChild(0);



that will return the model.



Then simply clone that, for an example on how to do that. See jmetest.renderer.TestManyChildren



But if you have a node, with multiply geometries underneath, then you will have to clone each individual geometry.



DP

OK, I was thinking about loading an obj file which is then read into a node and its this node that you then add to the scene judging by the way JmeBinaryReader works.


Node mynode = JmeBinaryReader.loadBinaryFormat(....)



So this means that I got to load my model several times if I am looking for several instances of it or am I missing something here?
tomcat

if the model consists of a single mesh. Then this is how you do it:



birdNode = jmeBinaryReaderInstance.loadBinaryFormat(birdURL.openStream());

Geometry cloneG = (Geometry)birdNode.getChild(0);

CloneNode cloneNode = new CloneNode("Bird Clone Node");
cloneNode.setGeometry(cloneG);

for (int i = 0; i < 1024; i++) {
  float x = (float) FastMath.nextRandomFloat() * 10;
  float y = (float) FastMath.nextRandomFloat() * 10;
  float z = (float) FastMath.nextRandomFloat() * 10;

  Clone c = new Clone("Bird Clone " + i);
  c.setLocalTranslation(new Vector3f(x, y, z));
  cloneNode.attachChild(c);
}



And thats how you do it. The above pseudo-code will create 1024 clones of a bird.

Is that what you wanted?

DP

Thx DP. I try this and see what happens. I am using an obj file which uses a texture file. My worry is that Geometry may not help me with texture for the object.



I will test it and let you know.

tomcat