Get sub geometry local translation?

I’m trying to get the position of a particular geometry in a spatial. When I call getLocalTranslation it returns the parents(spatial) location which is (0,0,0) since I haven’t move it. This particular piece of geometry is attached to the spatial but far from center.

getLocalTranslation() returns the geometry’s location relative to its parent. Always.

getWorldTranslation() returns the geometry’s location in the world, including the translation, rotation, etc. of all parents. Always.

If you are seeing something different then it’s your eyes that are invalid. Else explain what you are really trying to to and we can help sort it out.

http://wiki.jmonkeyengine.org/doku.php/jme3:scenegraph_for_dummies

I tried getWorldTranslation as well and that had the same issue.

I have a small city that is loaded as one .obj file. I’m getting the sub meshes which are things like buildings and ground glutter so I can track the distance between them and the player. I want to add and remove mesh/geometries from the collision tree based on player distance. Their isn’t a need to perform collision on a building that is the next block over.

private void getGeometry(String name){

    Node temp;
    temp = (Node)sceneModel;
    for (Spatial x : temp.getChildren() ) {
       if (x instanceof Geometry) {
       if (x.getName().equals(name)) {
           
           System.out.println(x.getLocalTranslation().toString());
           System.out.println(x.getWorldTranslation().toString());
           
       }
    } 
    }
      
}

When I call this function no matter what mesh I use the translation is (0,0,0). My eyes do not deceive me :smiley:

Then the meshes have their position embedded in them such that their own local origin is still world 0,0,0.

ie: the building at 100, 100 has vertexes at 100, 00 +/- building size.

IIRC OBJs dont support relative coordinates, meaning that stored vertex positions are calculated always from the origin of the world. I’m not sure about that, though.
But if this is the case you have two way to solve the problem:

  1. Set the correct origin (blender: Object → Transform - > Origin to center of mass) and export in another format.
  2. Obtain the Mesh object from the Geometry, get the position of every vertex and calculate the middle point and use it as origin.

I was afraid that might be the case. I think a more efficient idea would be to use riccardo’s idea but only get the position of the first vertex and base the position of that. I don’t need to have the exact center of the object. A close estimate of where it is at will work fine.

if you want a rough center, you could just ask the boundingbox/sphere for it.

1 Like

I decided to build the scene manually in the scene editor. This way I could have access the worldTranslation. All of my models are centered on 0,0,0 so when I load then I already have center.