Translate Object in World Space instead of Object Space

I have a GLTF file with a “deep” group/child
The GLTF contain a group that contain a group that contain a group that contain a geometry.
Each group may have different rotation/position.

I’m trying to do some kind of explosed view, where each pieces will translate in the opposite direction of the whole GLTF object (his center).

I calculated the center of the whole object (in world space (position)).
I got the center position of each pieces indivially (in world space (position)).
I calculated where I need to translate each pieces (in world space (position)).

Problem is, I don’t know how to setPosition of an object, in world space.
When I try, the rotation of the parent and olders parent are affecting the translation.

I tried with node.position, with node.matrix.setPosition( newPos ), node.translateX() which all gave me the same result.
I think it is possible with node.matrixWorld.setPosition( newPos ), but I don’t think I understand how to use it, as it doesn’t change anything (nothing move).

If this isn’t clear enough, I can create a codeSandBox with my example if that can help you to help me ^^

The idea is to transform the target position in world space to object space and then set it to Object3D.position. The transformation can be done by using Object3D.worldToLocal().

1 Like

Tried, but it doesn’t seems to do what I expected.

Here is what I get without worldToLocal()
(cyan is center of the scene [0,0,0])
(yellow is center of whole object)
(left purple is center of piece when initialized)
(right purple is where I expect the piece to be moved)
(red piece is the piece after I move it)


And here with worldToLocal()

It is actually better, I mean, distance from [0,0,0] are same between real position and where it should be.
But it seems like there is a rotation from a parent still affecting it

Made a small codesandbox
(it acts a bit weirdly though)

It’s made with React Three Fiber, so some things might a bit different than “Pure Js”.

function Pieces is the one that matter.
Cyan Cube is [0,0,0]
Yellow Cube is center of the whole GLTF
Purple Cube is center Position of the piece
Red Cube is where I try to translate the piece
Red piece is the piece I try to move

Hope that will helps

It is as if worldToLocal is doing parentToLocal