簡體   English   中英

在 Autodesk Forge Viewer 中旋轉模型

[英]Rotate model in Autodesk Forge Viewer

嗨,我正在使用查看器 api 開發一個應用程序。 我有一個主模型。 我在這個模型上加載其他模型。 我可以移動和調整我稍后上傳的這些模型的大小。 我使用 makeRotationX ,makeRotationY,makeRotationZ 函數實現了旋轉。 但是當我旋轉加載的模型時,它會將其移動到起點。 這可能是什么原因? 例如,我將立方體添加到左側,但它會移動到主要的 0,0,0 點並進行旋轉。 第一的

我只是改變了旋轉 Y 值,這就是結果。 第二

代碼 :

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM