您好,我正在使用查看器 API 开发一个应用程序。我有一个大师模型。我在这个模型上加载其他模型。我可以移动稍后上传的这些模型并调整其大小。我使用 makeRotationX 、makeRotationY、makeRotationZ 函数实现了旋转。但是当我旋转加载的模型时,它会将其移动到起点。这可能是什么原因?例如,我将立方体添加到左侧,但它移动到主 0,0,0 点并进行旋转。
代码:
cubeModel.getModelTransform().makeRotationY(inputValue * Math.PI / 180);
viewer.impl.invalidate(true, true, true)
最佳答案
这是因为您使用 model.getModelTransform()
检索的模型的 THREE.Matrix4
转换可能已经包含一些转换(在这种特殊情况下,转换正在抵消左边的红色立方体)。 makeRotationY
方法不会附加任何变换,它只是将矩阵重置为仅绕 Y 轴旋转的新变换。
相反,您想要做的是这样的:
let xform = model.getModelTransform().clone();
// modify the xform instead of resetting it, for example
let rotate = new THREE.Matrix4().makeRotationY(0.1);
let scale = new THREE.Matrix4().makeScale(0.1, 0.5, 0.1);
xform.premultiply(rotate);
xform.multiply(scale);
// since we cloned the matrix earlier (good practice), apply it back to the model
model.setModelTransform(xform);
关于autodesk-forge - 在 Autodesk Forge Viewer 中旋转模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68530890/