Search code examples
androidarcoresceneform

Get TransformableNode size in metres


I am setting my TransformableNode Size initially in Vector3. Then I scaled my TransformableNode. I want now the scaled TransformableNode size in metres nit in Vector3. Please help me in that. I tried these but not getting any solution:

Vector3 vec = transformableNode.getLocalPosition();
Vector3 vector = transformableNode.getWorldPosition();
Vector3 vector31 = transformableNode.getWorldScale();
Vector3 vector32 = transformableNode.getLocalScale();
Log.e("Vector Local Position: ", String.valueOf(vec.x + " " + vec.y + " " + vec.z));
Log.e("Vector World Position: ", String.valueOf(vector.x + " " + vector.y + " " + vector.z));
Log.e("Vector World Scale: ", String.valueOf(vector31.x + " " + vector31.y + " " + vector31.z));
Log.e("Vector Local Scale: ", String.valueOf(vector32.x + " " + vector32.y + " " + vector32.z));

Solution

  • To get the size of a renderable in meters, you can do this:

    Box box = (Box) transformableNode.getRenderable().getCollisionShape();
    Vector3 renderableSize = box.getSize();
    

    Once you have the size of the renderable, you can get the final size of the TransformableNode by multiplying the renderable's size by the scale:

    Vector3 transformableNodeScale = transformableNode.getWorldScale();
      Vector3 finalSize =
          new Vector3(
              renderableSize.x * transformableNodeScale.x,
              renderableSize.y * transformableNodeScale.y,
              renderableSize.z * transformableNodeScale.z);