Am I misunderstanding .localToWorld()?

I have the following code:

const g = new THREE.Group();
scene.add(g);
g.position.set(10, 20, 30);
console.log(g.position); //returns vector 10, 20, 30

const v = new THREE.Vector3(0, 0, 0);
console.log(v); //returns vector 0, 0, 0
g.localToWorld(v);
console.log(v); //returns vector 0, 0, 0

Shouldn’t localToWorld set the value of v to 10, 20, 30 ?

I feel like I’m being very dumb - what am I missing?

The logic is correct.

After updating the position of g, try calling g.updateMatrixWorld. localToWorld uses it (here) to apply relative transformation, and iirc matrix world isn’t updated right away - you either have to do it manually or wait for the next frame to render.

1 Like

Yep, that’s what I was missing!

Thank you