How to transform(move) a complete Orge Model identified with ray tracing

Hi,

I want to make an interface such that user can click to select an object and then again click to place it somewhere else. I have already built it and it works fine with existing geometries (boxes) and models imported as objs. However when I try it on a model imported as Orge XML, only part of object gets transformed. This is because the object seems to have made of more than one geometry with different names. When the user selects the object only a part of object gets selected and when he clicks somewhere, only that part moves. How to move the entire object at once.
I have made the model in google sketchup and exported as Orge XML.

Here is the pick/ place code I’m using

[java] CollisionResult closest = results.getClosestCollision();

  // Code to pick an object (if its in shootables)
  Spatial shot = closest.getGeometry();

  // Some useful log for debugging at this point
  //System.out.println("\n" + "SIMAR" + "\n");
  //System.out.println(shot.getParent().getName());
  //System.out.println(shot.getParent().getParent().getName());

  // Some objects have material, so we need to check parent and parent of parent
  if ("Shootables".equals(shot.getParent().getName()) || "Shootables".equals(shot.getParent().getParent().getName())) {
      // some shootable has been clicked
          if (picked == null) {

            picked = shot;
            shootables.detachChild(picked);
            rootNode.getLocalLightList().get(0).setColor(ColorRGBA.Red);
          }
    }
  else
  {
      if (picked!=null)
      {
        Vector3f newLoc;
        float height;

        height = ((BoundingBox)picked.getWorldBound()).getXExtent();
        newLoc = closest.getContactPoint().addLocal(0,height,0);

        picked.setLocalTranslation(newLoc);
        shootables.attachChild(picked);
        picked = null;
        rootNode.getLocalLightList().get(0).setColor(ColorRGBA.White);

        //System.out.println("SIMAR\n\n\n" + cam.getLocation() + "  " + newLoc);
      }
  }     [/java]

The object that gets selected is
drink-final-geon1
drink-final-geon2

depending on the point of click… I want to move the entire mesh altogether

You can look at the model in the SceneExplorer, it probably has a parent node where the geometry you get as result is attached. So get the parent of those.

Got it thanks a lot!!

Is there a good method to find out whether should I pick the parent or the closest object??

PS: When I import obj then I must pick closest and when I import Orge I must pick parent.

depends on how you manage them, for example if you attach the loaded stuff only to rootnode, just recursivly go to parent untill the parent is the rootnode.

In Lemur, for example, a MouseEventControl gets added to the Spatial that should be receiving the mouse events (ie: not the leaves in the case of a complicated model hierarchy). So my picking code (MouseAppState) is general. Something gets clicked and I go up the hierarchy until I find one of those controls and then deliver the event.

You could similarly use a control to mark the roots or just set a UserData to mark the roots.

Alternatively you could getParent() until the current node’s parent is the node you add these clickable objects to. This will save you from having to flag nodes and such… and should be constant as you are defining your scene graph. I could be wrong… but object comparison should be less expensive than hasmap lookup + cast + comparison.

@t0neg0d said: Alternatively you could getParent() until the current node's parent is the node you add these clickable objects to. This will save you from having to flag nodes and such... and should be constant as you are defining your scene graph. I could be wrong... but object comparison should be less expensive than hasmap lookup + cast + comparison.

Presuming there are lots of clickable objects in the scene then it seems like you’d just trade one collection lookup for another.

Edit: I see you are basically restating empire’s suggestion in a more general way. Useful when your scene is structured mostly for your picking, I guess.