autodesk-forge - Translate a model after load (move origin)
问题描述
My company is using the latest version that supports multiple models for federation, the problem that we are facing is that sometimes the models don't quite line up correctly. I'm aware of the load option globalOffset
but even with that in place, they don't line up.
I'm therefore looking for a way to move the model after it's been loaded, so that I can then store this new offset in the database, so that it loads correctly next time.
Is this possible at the moment?
解决方案
如果您的模型之前没有设置同源或共享坐标,那么它们将不会与globalOffset
选项对齐。
是的,模型可以在加载后移动。你可以查看这个很棒的扩展,Viewing.Extension.Transform,它是由我们很酷的同事 Philippe 编写的,翻译工具就在这里。
这是一个示例,展示了如何在 x 方向上移动整个模型 -100 个单位。它的关键概念是将您的模型偏移量应用于每个 Forge 片段,如下面的代码片段。
const fragCount = viewer.model.getFragmentList().fragments.fragId2dbId.length;
// Move whole model -100 units in the x-direction
const offset = new THREE.Vector3( -100, 0 , 0 );
for( let fragId = 0; fragId < fragCount; ++fragId ) {
const fragProxy = viewer.impl.getFragmentProxy( model, fragId );
fragProxy.getAnimTransform();
const position = new THREE.Vector3(
fragProxy.position.x + offset.x,
fragProxy.position.y + offset.y,
fragProxy.position.z + offset.z
);
fragProxy.position = position;
fragProxy.updateAnimTransform();
}
viewer.impl.sceneUpdated( true );
推荐阅读
- sql - 取时间差之和和列的最后一个值
- php - join():不推荐使用数组后传递胶水字符串。交换参数
- gtsummary - 使用 gtsummary,是否可以将 N 放在列名的单独行上?
- reactjs - 是否可以“部分”在 Django 项目中使用 React?
- laravel - 基于 Laravel 7.24 中的数据库值预选单选按钮
- sql - 如何使用匹配调用 regexp_replace 中的函数?
- python - 使用python解压缩.Z文件时出错
- listview - BindCommand 与参数 ListView ReactiveUI Xamarin 表单
- java - 命令“javac -h”和“javah -jni”找不到我指定的文件
- oracle - 如何正确映射 MyBatis 父关系?