如何获得子对象的全局/世界位置? [英] 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).
推荐答案
第一次致电
scene.updateMatrixWorld();
或在您的示例中,只需拨打
or in your example, it is sufficient to call
parent.updateMatrixWorld();
然后提取世界排名
var vector = new THREE.Vector3();
vector.setFromMatrixPosition( child.matrixWorld );
但实际上,渲染器调用 updateMatrixWorld()
为你在每个渲染循环中,所以你不必。
In practice, however, the renderer calls updateMatrixWorld()
for you in each render loop, so you don't have to.
编辑:更新为three.js r.65
updated to three.js r.65
这篇关于如何获得子对象的全局/世界位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文