autodesk-forge - 在 Autodesk Forge Viewer 中旋转模型

标签 autodesk-forge autodesk-viewer autodesk-model-derivative

您好,我正在使用查看器 API 开发一个应用程序。我有一个大师模型。我在这个模型上加载其他模型。我可以移动稍后上传的这些模型并调整其大小。我使用 makeRotationX 、makeRotationY、makeRotationZ 函数实现了旋转。但是当我旋转加载的模型时,它会将其移动到起点。这可能是什么原因?例如,我将立方体添加到左侧,但它移动到主 0,0,0 点并进行旋转。 first

我只是改变了旋转Y值,这就是结果。 second

代码:

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/

相关文章:

three.js - 三个 CSG 的 3D bool 运算

autodesk-forge - 更改 Forge 中的 Material

autodesk-forge - Revit 模型中的自定义属性(身份数据)翻译错误

javascript - 使用交叉请求获取 Forge 2-legged 身份验证

autodesk-forge - Autodesk Forge 查看器 v7 : Open PDFs

javascript - 在 Forge Viewer 中第二次之后扩展不会加载

autodesk-forge - 在 Autodesk forge 查看器中查看文件时出错 - 调用 doc.getRootItem() 时出错

javascript - 有什么方法可以从查看器中的 Revit 文档中读取实体(架构)吗?