13 Replies Latest reply on Mar 17, 2004 8:14 AM by 843799

    problem picking geometry of shape3D

    843799
      Hi,

      have found similar problems to mine, but I've gone thru the whole list and no one deals completely with this. Basically I have ball and stick type tree graphs and I need to be able to pick ComponentNodes - represented as spheres. I create a sphere, then get its shape3D, which is what is used to pick, change appearance, blah, blah. Everything works fine, except that picking using bounds is not accurate enough. Once total number of nodes in a graph exceeds 60 overlap of nodes starts to happen. So if I try to pick a specific node another one ends up being picked instead. So I switched this so it picks on geometry, because the picking accuracy is much better. And this works fine - even where there is serious occlusion - say, only a sliver of a node is not obscured by any other, the node I want to pick IS the one picked.

      Now, the problem is that I add trees to to the canvas after it's live - using child-extend, blah, blah. Which also worked fine. And still does. Except that once I've attempted to pick anything trying to add new trees generates this exception:


      Exception occurred during Behavior execution:
      javax.media.j3d.RestrictedAccessException: Cannot modify capability bits on a live or compiled object
      at javax.media.j3d.SceneGraphObject.setCapability(SceneGraphObject.java:101)
      at ComponentNode3D.setCapabilities(ComponentNode3D.java:50)
      at ComponentNode3D.<init>(ComponentNode3D.java:34)
      at AnatomyTree3D.<init>(AnatomyTree3D.java:38)
      at MultiStageListener.getAnatomyTrees(MultiStageListener.java:448)
      at MultiStageListener.processStimulus(MultiStageListener.java:69)
      at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
      at javax.media.j3d.J3dThread.run(J3dThread.java:250)



      any help, anyone - the error makes no sense to me because it doesn't occur when I do the exact same thing when picking bounds. And I don't get the bit about modifying capability bits on a live or compiled object, 'cos the bits are set when each ComponentNode3D is created, and that is done before the tree is generated and it becomes live - the same process is used to create and draw trees before AND after the error is generated!

      the code used to set the capabilities in the ComponentNode3D class - called in the constructor is as below:
      public void setCapabilities()
      {     
        setNodeDiameter(0.05f);
        //node = new Sphere((float) getNodeDiameter(), Sphere.GENERATE_NORMALS, 16);
        node = new Sphere((float) getNodeDiameter());
                
        shape3D = node.getShape();
        shape3D.setCapability(shape3D.ALLOW_APPEARANCE_READ);
        shape3D.setCapability(shape3D.ALLOW_APPEARANCE_WRITE);
        shape3D.setCapability(shape3D.ALLOW_GEOMETRY_READ);
        shape3D.setCapability(shape3D.ALLOW_PICKABLE_READ);
       
        Geometry geometry = shape3D.getGeometry();
        geometry.setCapability(Geometry.ALLOW_INTERSECT);
                
        appearance = new Appearance();
        appearance.setCapability(appearance.ALLOW_MATERIAL_WRITE);
      }
        • 1. Re: problem picking geometry of shape3D
          843799
          Hi,

          I don't know how your scene tree is organised, but have you used this capability - Group.ENABLE_PICK_REPORTING - on a/the Group node(s) ?

          I had problems with picking before, but I don't remember if the exception was similar with yours.

          Best regards
          • 2. Re: problem picking geometry of shape3D
            843799
            no, I'm setting the picking capabilities for the individual elements - I suppose they would be the leaves, and I add them to a branchgroup to form a tree. I just tried setting ENABLE_PICK_REPORTING for the branchgroup that holds the ComponentNodes, but it makes no difference - I'm still getting the same error.
            What I don't understand is why I'm getting the error only when I try picking on geometry, and also, that it only becomes a problem when I add new objects to the scenegraph, after the first lot. Picking on geometry is not a problem before that. And the error doesn't happen for picking on bounds.
            • 3. Re: problem picking geometry of shape3D - shared geometry?
              843799
              hi again,

              still need help - someone! Just went through the API again - and found the error I'm getting is being generated when it is because I'm using a Sphere - and the geometries are shared, so once I've drawn any trees it's unable to set the geometry.ALLOW_INTERSECT capability for subsequent nodes. So I set the capability so they're not shared:
              node = new Sphere((float) getNodeDiameter());
              node.setCapability(node.GEOMETRY_NOT_SHARED);
                        
              shape3D = node.getShape();
              shape3D.setCapability(shape3D.ALLOW_APPEARANCE_READ);
              shape3D.setCapability(shape3D.ALLOW_APPEARANCE_WRITE);
              shape3D.setCapability(shape3D.ALLOW_GEOMETRY_READ);
              shape3D.setCapability(shape3D.ALLOW_PICKABLE_READ);
              
              Geometry geometry = shape3D.getGeometry();
              geometry.setCapability(geometry.ALLOW_INTERSECT);
              and when I tested it the program confirmed the geometries are no longer shared. But I'm still getting the same error - it still complains I'm trying to set capabilities on a live object. Help, someone! Am I missing something?
              • 4. Re: problem picking geometry of shape3D - shared geometry?
                843799
                Remember that you can't set any capabilities after you have compiled your branchgroup.
                • 5. Re: problem picking geometry of shape3D - shared geometry?
                  843799
                  I know that - I'm NOT setting the capabilities after it becomes live - the capabilites are set when the component is created, before the tree is generated and it's added to the scenegraph. The problem is that Spheres share their geometry, so creation of new Spheres does NOT create new geometries, so it attempts to set the capability on a live object. Which is why I set the capability GEOMETRY_NOT_SHARED. However, even when I check using getCapability to make sure it's been set - it returns true, but it still generates the error. I get the impression that might be because I'm getting the geometry from its Shape3D - since I can't find any method that can get the geometry directly from a primitive (someone correct me if I'm wrong).
                  • 6. Re: problem picking geometry of shape3D - shared geometry?
                    843799
                    I'm currently having the same problem as well. I tried picking and creating a sphere once without any trouble, but upon clicking on the same spot the error mentioned above occurs. Capabilities have been set b4 compiling hte BranchGroup. Pls helps us! (-_-*).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                    • 7. Re: problem picking geometry of shape3D - shared geometry?
                      843799
                      can you post the code where the error comes from?
                      • 8. Re: problem picking geometry of shape3D - shared geometry?
                        843799
                        I may be stating the obvious here but it looks like your setting the capabilities too late... Can't tell without looking at your code! :)
                        • 9. Re: problem picking geometry of shape3D
                          843799
                          ok I know this is a workaround and not the right solution, but you can test isLive() on your geometry object before setting the bits (assuling it is the geometry object on which the bits are again when they should not be)
                          I successfuly used that trick in a slightly different context with Cylinder instances which also share geometries
                          • 10. Re: problem picking geometry of shape3D
                            843799
                            Exactly how did you solve your problem - I already posted my code above, showing where I set the sphere NOT to share geometries. I already did the capability tests - to see if the geometries are still shared - I get a false, to see if the sphere becomes live or is compiled before it is created/drawn - I get a false. But I just tried one more test - I checked to see if the geometry is live. And I found that after the first set of trees is displayed any others I attempt to display already have their geometry live. I'm assuming this is because I get the geometry from the shape3D I get from the sphere, so that it's ignoring the sphere's geometry and creating its own. But I can't find an option to turn off sharing of geometries for shape3Ds.
                            • 11. Re: problem picking geometry of shape3D
                              843799
                              node.setCapability(node.GEOMETRY_NOT_SHARED);

                              ^^ this is the problem, set the GEOMETRY_NOT_SHARED flag when creating the node (-> use a constructor with a primflag argument).
                              In your code the geometry is cached when creating the node and then the flag is set. this is too late.
                              • 12. Re: problem picking geometry of shape3D
                                843799
                                I have the same problem as you but I don't know how can I set the flags at construction time.
                                What kind of constructor do I have to use the constructors for the node does not support any capability settings in the call. I chekced the node and Shape3D api documentation and found no solution to set them on construction time. Thank you.
                                • 13. Re: problem picking geometry of shape3D
                                  843799
                                  I think errors come from this line => simpleU.getViewingPlatform().getViewPlatformTransform();
                                  ********************************************************************************************************
                                  I tested the isLive() method in the constructor of MyKeyboard and MyCollision and the result is TRUE. My TransformGroup is alive and then my setCapabilities in the both constructors produce erros...

                                  | TransformGroup view=simpleU.getViewingPlatform().getViewPlatformTransform();
                                  |
                                  | MyKeyboard behav =new MyKeyboard(view);
                                  | MyCollision behav2=new MyCollision(view);

                                  Can you give me a correct example of collision.

                                  Best regards,
                                  B@ron (from Belgium)