简体   繁体   中英

Rotate model in Autodesk Forge Viewer

Hi I am developing an application using the viewer api. I have a master model. And I load other models on this model. I can move and resize these models that I have uploaded later. I achieved rotation using makeRotationX ,makeRotationY,makeRotationZ functions. But when I rotate the loaded model, it moves it to the starting point. What could be the reason for this? So for example, I add the cube to the left, but it moves to the main 0,0,0 point and does the rotation. 第一的

I just change the rotation Y value and this is the result. 第二

Code :

cubeModel.getModelTransform().makeRotationY(inputValue * Math.PI / 180);
                viewer.impl.invalidate(true, true, true)

This is because the model's THREE.Matrix4 transform that you retrieve using model.getModelTransform() may already include some transformation (in this particular case, the transformation is offsetting the red cube to the left). And the makeRotationY method doesn't append any transformation, it simply resets the matrix to a new transformation that only rotates around the Y axis.

Instead, what you'll want to do is something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM