gpt4 book ai didi

javascript - 矩阵世界中的三个 JS 位置与本地位置相同

转载 作者:行者123 更新时间:2023-12-03 04:50:54 25 4
gpt4 key购买 nike

我从 Cinema4D 导入了一个带有父对象树的 collada 文件。当我像这样获得对象的世界位置时:

var thing = scene.getObjectByName("thing");
thing.updateMatrixWorld();
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(thing.matrixWorld);

它与 thing.position 相同,文档称其为本地位置。我知道这个对象有一个非零位置的父对象。当我在没有 updateMatrixWorld() 的情况下尝试相同的操作时,世界位置为零。我怎样才能获得正确的世界位置?

最佳答案

我需要为我的对象的每个父对象updateMatrixWorld(),我这样做是这样的:

function updateWorldMatrices (object)
{
var parent = object;
while (parent.parent != null)
{
parent.updateMatrixWorld();
parent = parent.parent;
}
}

关于javascript - 矩阵世界中的三个 JS 位置与本地位置相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42660543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com