thanks Wenger...

as you have mentioned that if i want to make real copies,then there are some methods in Xith,which can help....
actually i didn't get the idea of "real" copies...can u plz tell what does you mean by REAL copiesand what are the methods to create them....
sorry I didn't explained acceptably.
So our scenegraph is
acyclic. That does mean that nodes can't have more than one parents (that is, they cannot be added twice, cannot exists in two places of the scenegraph).
So you can not just make :
1 2 3 4 5
| Shape3D sphere = new Sphere(10, 10, 2f); for(int i = 0; i < 20; i++) { scene.addChild((new Transform(model)).setTranslationX(model)); } |
However, what you can make is to clone the Shape3D
1 2 3 4 5
| Shape3D sphere = new Sphere(10, 10, 2f); for(int i = 0; i < 20; i++) { scene.addChild((new Transform((Shape3D)model.clone())).setTranslationX(model)); } |
This makes a "real" copy of the shape, which means everything is copied (Shape3D, Appearance, Material, all Attributes, + Geometry, all vertex data, texture UV, and so on).
This is bad from a memory and loading time / run time point of view, because all data is
duplicated.
What you can do to reduce memory usage and load/run time is to make shared copies :
1 2 3 4 5
| Shape3D sphere = new Sphere(10, 10, 2f); for(int i = 0; i < 20; i++) { scene.addChild((new Transform((Shape3D)model.sharedCopy())).setTranslationX(model)); } |
This won't copy e.g. vertex data, UV, but just creates a new Shape3D and assign the same Material & Appearance objects.
Even better is creating links :
1 2 3 4 5 6 7 8
| Shape3D sphere = new Sphere(10, 10, 2f); SharedGroup sg = new SharedGroup(); sg.addChild(sphere); for(int i = 0; i < 20; i++) { Link l = new Link(sg); scene.addChild((new Transform(l).setTranslationX(model)); } |
In this case, the Link points to a SharedGroup which can be rendered any number of times. The benefit is that no duplicate Shape3D objects are created, just links... and anything can be added to Links..
A last thing : beware of shared copies : if you change something in the geometry of one it will change every other.. but it's probably not a problem.
I hope you got my point, if it was clear enough I'll make a code example in W3G for that..