ObjectFile.load(url).getNamedObjects()

Can anyone help me?
I tryed this code and the VM throws a MultipleParentExeption

ObjectFile file = new ObjectFile();

Hashtable objects;
try {
objects = file.load(url).getNamedObjects();
}
catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
}
catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
}
catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}

Enumeration e = objects.keys();

while(e.hasMoreElements()) {

String name = (String)e.nextElement();
Shape3D part = (Shape3D)objects.get(name);

if (name.equals(“gun”)) {
System.out.println(“set gun”);
this.gun = new TransformGroup();
this.gun.addChild(part);
}else if (name.equals(“body”)) {
System.out.println(“set body”);
this.robotbody = new TransformGroup();
this.robotbody.addChild(part);
}else if…

}

=>
set gun
javax.media.j3d.MultipleParentException: Group.addChild: child already has a parent
at javax.media.j3d.GroupRetained.checkValidChild(GroupRetained.java:440)
at javax.media.j3d.GroupRetained.addChild(GroupRetained.java:449)
at javax.media.j3d.Group.addChild(Group.java:266)
at engine.object.Robot.init(Robot.java:60)
at engine.object.Robot.(Robot.java:36)
at engine.object.ObjectManager.addRobot(ObjectManager.java:41)
at engine.Metaversum.createSceneGraph(Metaversum.java:134)
at engine.Metaversum.init(Metaversum.java:71)
at engine.Metaversum.(Metaversum.java:54)
at engine.Driver.main(Driver.java:50)
Exception in thread “main”

Is it not possible to split a obj file in different Transformgroups?
If yes, please let me know.

When loading a model, all nodes already are organized in a scenegraph and therefor have a parent.
So you have to detach it first before you can add it to you transformgroup.

Thank you for the answer.

But how should I detach the childs?
getNamedObjects() returns Shape3D

Bienator

IT WORKS!!! :slight_smile:

I have only to write
object.getSceneGroup().removeAllChildren()
after I have the Hashtable with
object.getNamedObjects()

Thank you again

Bienator

That’s how it’s meant to be.
The question remains why you load a model with submodels where you are only interested in the submodels. You are creating some overhead…