Are you sure you're passing in a brand new BranchGroup every call?  Also,
which call to addChild is giving you the exception? vrmlTrans.addChild or
objGroup.addChild?  Try putting print statements between the lines to find
out, like this: System.err.println("got this far");
Hope this helps.
-Guillermo Gutierrez


Andreea Francu wrote:

> I'm trying to write a method that will add a vrml object to a BranchGroup.
> The vrml object is loaded in another class and is given to the method as a
> BranchGroup parameter. The problem appears when I try to add more than one
> vrml objects. Then I get the following exception:

> javax.media.j3d.MultipleParentException:Group.addChild: child already has

> a parent
>
> Does anybody know how can I avoid getting this error?
>
> Here is the relevant code:
>
> public void addVRML(Point3d placePoint, BranchGroup vrmlbg)
>   {
>     placePoint_ = placePoint;
>     BranchGroup objGroup = new BranchGroup();
>
>     Transform3D transformation = new Transform3D();
>     transformation.setTranslation(new Vector3d(placePoint_.x,
>                                                        placePoint_.y,
>                                                        placePoint_.z));
>
>     TransformGroup vrmlTrans = new TransformGroup(transformation);
>     vrmlTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
>     vrmlTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
>     vrmlTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
>     vrmlTrans.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
>     vrmlTrans.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
>
>     objGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
>     objGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
>     objGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
>
>     vrmlTrans.addChild(vrmlbg);
>     objGroup.addChild(vrmlTrans);
>
>     scene_.addChild(objGroup);
>   }
>
> ******************************************************************
> * Andreea Francu                                                 *
> * Graduate Student                                               *
> * CAIP Center, Rutgers University                                *
> * 96 Frelinghuysen Rd., Piscataway, NJ, 08854                    *
> * [EMAIL PROTECTED]  http://www.caip.rutgers.edu/~afrancu/*
> ******************************************************************
begin:vcard
n:Gutierrez;Guillermo
tel;fax:407-984-6323
tel;work:407-984-6543
x-mozilla-html:TRUE
org:Harris Corporation;ISD
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Software Engineer
x-mozilla-cpt:;-2976
fn:Guillermo Gutierrez
end:vcard

Reply via email to