MDEV
MDEV

Reputation: 10838

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?

Upvotes: 0

Views: 442

Answers (1)

Eason Kang
Eason Kang

Reputation: 7090

If you models haven't set up with co-origin or in share coordinates before, then they won't be aligned with globalOffset option.

And yes, the model can be moved after loaded. You can check out this awesome extension, Viewing.Extension.Transform, written by our cool colleague Philippe and the translation tool is here.

Here is a sample showing how to move the whole model -100 units in the x-direction. Its key concept is applying your model offsets to each Forge fragments as below code snippet.

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 );

Upvotes: 1

Related Questions