简体   繁体   中英

How to get the global/world position of a child object?

How do I get the global position of an Object3D inside another Object3D?

setup:

var parent = new THREE.Object3D();
parent.position.set(100, 100, 100);

var child = new THREE.Object3D();
child.position.set(100, 100, 100);
parent.add(child);

scene.add(parent);

notes:

I thought that this would be the way to do it:

console.log(child.localToWorld(parent.position));

...but it gives me (100, 100, 100) , not (200, 200, 200) .

You can extract the world position like so:

var target = new THREE.Vector3(); // create once an reuse it

child.getWorldPosition( target );

target will contain the result.

EDIT: updated to three.js r.120

In threejs r89 you can just get the world position by Object3D.getWorldPosition . I don't know when it was added.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM