Hi all again, I've added a small testcase to verify my last 2 postings about that problem. My question is what does it mean if that was a "design feature" of Java3D and not only a bug...? description: Shows a ColorCube twice in a Canvas3D using SharedGroup and Link. The cube is linked to two branchs which are added to the locale. The left branch can be detached and re-added. The cube can be reloaded with another size (first change code) to show the difference. All that can be done at runtime. problem: Detach the left cube, then reload the cube and minimize the frame the canvas is added to. Then pop it up again. You will get a NullPointException and the canvas isn't shown anymore. Furthermore canvas doesn't get updated when the cube is detached and reloaded (because the scene isn't live at this moment..?). To see that first change source at line 183 (method actionPerformed()) to get a new cube of a different size. You also can see that the scene subGraph of the cube isn't alive anymore when the left branch gets detached. This may be the reason for the Exception. So all that means to me I can never build a scene reusing scenegraphs and change, detach or add them at runtime with SharedGroup and Link. This would be a big restriction of usability of that all. Gernot Veith [EMAIL PROTECTED] http://www.janet.de --------------------------- source starts here --------------------------------- import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.geometry.ColorCube; import java.net.URL; import java.net.MalformedURLException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class SharedGroupTestCase { BranchGroup leftBG, rightBG, rootBG; Scene scene; SharedGroup sg; Link leftLink, rightLink; Canvas3D canvas3d; ColorCube cube; //create the scene public void create() { Bounds bounds = new BoundingSphere(new Point3d(0,0,0), 10000); //scene scene = new Scene(1); sg = new SharedGroup(); sg.setCapability(Group.ALLOW_CHILDREN_WRITE); sg.setCapability(Group.ALLOW_CHILDREN_EXTEND); sg.addChild(scene); //left branch leftBG = new BranchGroup(); leftBG.setCapability(BranchGroup.ALLOW_DETACH); TransformGroup leftTG = new TransformGroup(); Transform3D leftTrans = new Transform3D(); leftTrans.setTranslation(new Vector3f(-2,0,0)); leftTG.setTransform(leftTrans); leftBG.addChild(leftTG); leftLink = new Link(); leftLink.setCapability(Link.ALLOW_SHARED_GROUP_READ); leftLink.setCapability(Link.ALLOW_SHARED_GROUP_WRITE); leftTG.addChild(leftLink); //right branch rightBG = new BranchGroup(); TransformGroup rightTG = new TransformGroup(); Transform3D rightTrans = new Transform3D(); rightTrans.setTranslation(new Vector3f(2,0,0)); rightTG.setTransform(rightTrans); rightBG.addChild(rightTG); rightLink = new Link(); rightLink.setCapability(Link.ALLOW_SHARED_GROUP_READ); rightLink.setCapability(Link.ALLOW_SHARED_GROUP_WRITE); rightTG.addChild(rightLink); //link leftLink.setSharedGroup(sg); rightLink.setSharedGroup(sg); //universe Locale locale = new Locale(new VirtualUniverse()); rootBG = new BranchGroup(); rootBG.setCapability(Group.ALLOW_CHILDREN_WRITE); rootBG.setCapability(Group.ALLOW_CHILDREN_EXTEND); rootBG.setCapability(Node.ENABLE_PICK_REPORTING); rootBG.addChild(leftBG); rootBG.addChild(rightBG); //Viewer View view = new View(); view.setPhysicalBody(new PhysicalBody()); view.setPhysicalEnvironment(new PhysicalEnvironment()); canvas3d = new Canvas3D(null); view.addCanvas3D(canvas3d); ViewPlatform platform = new ViewPlatform(); view.attachViewPlatform(platform); TransformGroup viewTG = new TransformGroup(); Transform3D trans = new Transform3D(); trans.set(new Vector3f(0,0,10)); viewTG.setTransform(trans); viewTG.addChild(platform); BranchGroup viewBG = new BranchGroup(); viewBG.addChild(viewTG); //make scene live locale.addBranchGraph(rootBG); locale.addBranchGraph(viewBG); //JFrame for canvas3d JFrame frame = new JFrame("tescase"); frame.setBounds(10,10, 300,200); frame.getContentPane().add("Center", canvas3d); frame.setVisible(true); //Navigation frame Nav nav = new Nav(); nav.setVisible(true); } public static void main(String[] args) { SharedGroupTestCase test = new SharedGroupTestCase(); test.create(); } //Navigation frame to supply add/detach a BranchGroup //and reload scene class Nav extends JFrame implements ActionListener { JButton addB, detachB, reloadB; public Nav() { super("Navigaton"); setBounds(550,50,200,100); JButton addB = new JButton("add"); addB.addActionListener(this); JButton detachB = new JButton("detach"); detachB.addActionListener(this); reloadB = new JButton("reload"); reloadB.addActionListener(this); getContentPane().add("West", addB); getContentPane().add("Center", detachB); getContentPane().add("North", reloadB); } public void actionPerformed(ActionEvent e) { if(e.getSource() instanceof JButton) { if(((JButton)e.getSource()).getText() == "add") { if(leftBG.isLive() == false) { rootBG.addChild(leftBG); System.out.println("left branch: " + leftBG.isLive() + " scene alive: " + scene.isLive()); } } else if(((JButton)e.getSource()).getText() == "detach") { if(leftBG.isLive()) { leftBG.detach(); System.out.println("left branch: " + leftBG.isLive() + " scene alive: " + scene.isLive()); } } else if(((JButton)e.getSource()).getText() == "reload") { System.out.println("if scene alive reload: " + scene.isLive()); if(/* scene.isLive() == true */ true) { scene.detach(); //here you can chance cube size from described above. float size = 1.0f; scene = new Scene(size); sg.addChild(scene); System.out.println("scene reloaded"); } } } } } } //simple scene consisting of a Branchgroup and a ColorCube class Scene extends BranchGroup { public Scene(float size) { setCapability(BranchGroup.ALLOW_DETACH); addChild(new ColorCube(size)); } } ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------------------------------------------------------------- =========================================================================== 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".
