48

如何在另一个 Object3D 中获取 Object3D 的全局位置?

设置:

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);

笔记:

我认为这将是做到这一点的方法:

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

...但它给了我(100, 100, 100),而不是(200, 200, 200)

4

2 回答 2

65

您可以像这样提取世界位置:

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

child.getWorldPosition( target );

target将包含结果。

编辑:更新到three.js r.120

于 2013-02-26T20:43:01.137 回答
13

在threejs r89中,您可以通过Object3D.getWorldPosition. 不知道什么时候加的。

于 2018-02-11T08:26:24.257 回答