Is there anyway to clone nodes as yet? Since Link/Shared Group isn’t availabe (or is it?) I was hoping to clone everything instead.
Kev
Is there anyway to clone nodes as yet? Since Link/Shared Group isn’t availabe (or is it?) I was hoping to clone everything instead.
Kev
You can use node.sharedCopy(Node node). This will copy everything except the geometry, which is shared. There are limitations, but it handles models very well.
Dave
Thanks for the prompt (and useful) reply!
Kev
How does this work in practice? For example when I use your 3ds-loader?
I’d like to load a model once and duplicate as often as I need in the game’s map:
TDSLoader dsloader = new TDSLoader();
TDSModel model = dsloader.load(...);
How to clone this “model” then?
I used sharedCopy at the weekend but ran into a problem with the visibility of the cloned objects. You might have a look at
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1077452761
where I posted the main code regarding this topic.
Briefly the problem is as follows:
Imagine a 3-by-3 field
abc
def
ghi
where all objects are cloned from a basic object.
The strange thing is that as soon as ‘a’ becomes invisible due to the current view point ANY clone will disappear also.
It is like standing directly in front of a wall but being unable to look at it …
Hi, I had the same problem and as a quick hack I copied the load method in TDSLoader and just changed the return value to return the shape of the model. Of course animation doesn’t work then. You even could return just the geometry but then you can’t access the Appearance, code looks like this
public Shape3D loadShape(String path,InputStream in) throws IOException {
//fill in original code of load(String, InputStream )
return file.getContext().shape;
}
You can get the geometry and appearance from this shape and create new shapes with it. Works fine for me and much better than loading 3ds files during game ( I use the inputstream-method to load it, if you use the filename-method you’d have to change some other methods).
If you just want to clone the model…
BranchGroup clone = model.sharedCopy(model);
Will probably work…
Returning the shape is fine assuming you’ve not got more than one “element” in your 3ds model.
Kev