Hi All, I'm new to java3d, I'm having trouble allowing the user to add and remove objects in the scene. I'm not sure how to remove a child object from a BranchGroup. I alwas get a Exception occurred during event dispatching: java.lang.NullPointerException.
I tried it with detach()! How can optimize this code?? Thanks, N BranchGroup scene; BranchGroup objRoot = new BranchGroup(); TransformGroup objTrans = new TransformGroup(); SimpleUniverse u = null; BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); // Event: when user click a Button public void drawnew() { scene.detach(); Transform3D t3 = new Transform3D(); TransformGroup objTrans = new TransformGroup(t3); BranchGroup objBGroup = new BranchGroup (); objBGroup.setCapability(BranchGroup.ALLOW_DETACH); objTrans.addChild(new ColorCube(0.5)); objBGroup.addChild (objTrans); scene.addChild(objBGroup); u.addBranchGraph(objTrans); setVisible(true); } public BranchGroup createSceneGraph() { objRoot.setCapability (Group.ALLOW_CHILDREN_WRITE); objRoot.setCapability (Group.ALLOW_CHILDREN_EXTEND); objRoot.setCapability (Group.ALLOW_CHILDREN_READ); objRoot.setCapability (BranchGroup.ALLOW_DETACH); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTrans); objTrans.addChild(new ColorCube(1.5)); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); addLights(objRoot); return objRoot; } public void init() { parent=new BranchGroup(); scene = new BranchGroup(); setLayout(new BorderLayout()); add("Center", c); scene = createSceneGraph(); scene.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); scene.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); u = new SimpleUniverse(c); TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform(); u.addBranchGraph(scene); setVisible(true); } protected void addLights(BranchGroup b){ Color3f ambientColour = new Color3f(1.0f,1.0f,1.0f); AmbientLight ambtLight = new AmbientLight(ambientColour); ambtLight.setInfluencingBounds(bounds); Color3f dirLightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f dirLightDir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(dirLightColour, dirLightDir); dirLight.setInfluencingBounds(bounds); b.addChild(ambtLight); b.addChild(dirLight); } -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".