首页 > 解决方案 > 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?

标签: autodesk-forgeautodesk-viewer

解决方案


如果您的模型之前没有设置同源或共享坐标,那么它们将不会与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 );

推荐阅读