GetAbsolutePosition after setPositionWithLocalVector

Hi everybody,

I can’t understand why the method getAbsolutePosition is not giving the position displayed in the scene after setting the position with setPositionWithLocalVector.
In the playground below, the position of the box is (0,1,0) in the world coordinates but getAbsolutePosition is giving (0,-2,0).

I there a way to have the real absolute position of the mesh?
Thanks a lot.

@frederic, welcome back

Imagine there is a vertex A with value (0, 1, 0) and the mesh is at position (0, 0, 0)

we position the mesh at (0, 3, 0) so that A is at (0, 4, 0). Now we bake this transformation into the mesh, so that now vertex A has the value (0, 4, 0). Relative to the local origin of the mesh vertex A is now 4 units higher than the mesh’s origin rather than 1 unit. Leaving the mesh at (0, 3, 0) would place A at (0, 7, 0) and then baking would make the mesh jump. Therefore baking a transformation has to reposition the mesh so that vertex A remains at (0, 4, 0) and the mesh local origin is repositioned to (0, 0, 0)

Whether we then position or setPositionWithLocalVector the mesh to (0, -2, 0) makes no difference (since no rotation has taken place) the position and absolutePosition of the mesh is now (0, -2, 0) and vertex A is at (0, 2, 0).

In your case the center of the box and its local origin both start out at (0, 0, 0), after box.position.y = 3 the center of the box and its local origin are both at (0, 3, 0). At this point you bake the transformation. This resets the values of the vertices so now the local origin of the box is (0, 0, 0) but its center is at (0, 3, 0). You then reset the box’s position to (0, -2, 0) since no other frame of reference is involved this is its absolutePosition as well. The center of the box is as you see it at (0, 1, 0)

In answer to the question

it is yes, the real absolute position of the mesh is (0, -2, 0), however this is not the position of the center of the box.

1 Like

OK, I can understand much better what “bake the transformation” is doing. Thanks a lot.
Is there a way to get the position of the center of the box in my example?

Add the transformation you baked to the position