如何获取子对象的全局/世界位置? [英] How to get the global/world position of a child object?
本文介绍了如何获取子对象的全局/世界位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取一个 Object3D 在另一个 Object3D 中的全局位置?
How do I get the global position of an Object3D inside another 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);
注意事项:
我认为这是这样做的方式:
I thought that this would be the way to do it:
console.log(child.localToWorld(parent.position));
...但它给了我 (100, 100, 100),而不是 (200, 200, 200).
...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
将包含结果.
更新为three.js r.120
updated to three.js r.120
这篇关于如何获取子对象的全局/世界位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文