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/*
******************************************************************

Reply via email to