Skip to main content

Multiple Transformgroups from one object

No replies
omniflash
Offline
Joined: 2010-04-26

Hi,

I have a problem with transformgroups.I am loading an obj file with a loader, that gives you a transformgroup.I'm loading chess figures.I only want to read the obj once from the file, for the same figures, but i didnt know how to literally clone the transformgroup, i keep getting the multiple parent exception. Here is some of my code :

public class Loader {

String fileName;

public static TransformGroup LoadModell(String filename) {

Scene s=null;
ObjectFile f = new ObjectFile ();
f.setFlags (ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY);

try {
s = f.load (filename);
} catch(IOException e ) {System.out.println("Nincs meg a fájl!");}

TransformGroup tg = new TransformGroup();
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

tg.addChild (s.getSceneGroup ());

return tg;
}

Now im loading all the transformgroups one by one with the loader :

TransformGroup tg5 = Loader.LoadModell("gyalog.obj");
objRoot.addChild(positionFigure(tg5,Chessboard,"C2",0.65f));
Babu FeherGyalog3 = new Babu(0,"C2",1);

TransformGroup tg6 = Loader.LoadModell("gyalog.obj");
objRoot.addChild(positionFigure(tg6,Chessboard,"D2",0.65f));
Babu FeherGyalog4 = new Babu(0,"D2",1);

I'd like to find a way to load it only once, and then "clone" or copy the transformgroup like :

TransformGroup tg7=tg6; or something like this.
Is there a good way for this? Thank you very much for the help in advance!

Peter