在 three.js / Autodesk 3D 查看器(Autodesk Forge 查看器)中调整对象大小

resize an object in three.js / Autodesk 3D Viewer (Autodesk Forge Viewer)

如何调整对象大小以及移动或平移对象?

这个变化让我不得不将窗帘向上或向下移动

我需要调整大小位置一个对象动画或在一个地方(没有区别)

viewer3D : LMV v3.3.6

try 1:

oViewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectedCallback);
function onSelectedCallback(event) {
    var fragId = oViewer.getSelection()[0];
    if (typeof fragId == 'undefined') {return; }
    var fragIdsArray = (Array.isArray(fragId) ? fragId : [fragId]);

    fragIdsArray.forEach(function (subFragId) {

        var mesh = oViewer.impl.getRenderProxy(oViewer, subFragId);
        var mtx_for_method1 = mesh.matrixWorld.elements;
        mtx_for_method1[12] += 10;
        mtx_for_method1[13] += 20;
        mtx_for_method1[14] += 30;

    });

    oViewer.impl.invalidate(true);
}

try 2:

oViewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectedCallback);
function onSelectedCallback(event) {
    var fragId = oViewer.getSelection()[0];
    if (typeof fragId == 'undefined') {return; }
    var fragIdsArray = (Array.isArray(fragId) ? fragId : [fragId]);
    fragIdsArray.forEach(function (subFragId) {
        var mesh = oViewer.impl.getRenderProxy(oViewer, subFragId);
            var transMat = new THREE.Matrix4();
            var m1 = new THREE.Matrix4();
            var m2 = new THREE.Matrix4();
            var m3 = new THREE.Matrix4();
            var alpha = 0;
            var beta = Math.PI;
            var gamma = Math.PI / 2;
            m1.makeRotationX(alpha);
            m2.makeRotationY(beta);
            m3.makeRotationZ(gamma);
            transMat.multiplyMatrices(m1, m2);
            transMat.multiply(m3);
            var mtx_for_method2 = mesh.matrixWorld;
            mtx_for_method2.multiply(transMat);
            mtx_for_method2.matrixWorldNeedsUpdate = True;
    });

    oViewer.impl.invalidate(true);
}

这可能吗?

当然可以,但是可以看到您的代码存在一些问题,它们是:

  • 使用 instanceTree.enumNodeFragments 获取片段,viewer.getSelection 只会获取当前所选组件的 dbids

编辑:

  • 使用片段代理而不是网格代理...
const model = NOP_VIEWER.model;
model.getData().instanceTree.enumNodeFragments(
      dbid, fragId => {
        const fragProxy = NOP_VIEWER.impl.getFragmentProxy(model, fragId);
        fragProxy.scale = new THREE.Vector3(1.1,1.1,1.1);
        fragProxy.updateAnimTransform()
    });
NOP_VIEWER.impl.invalidate(true)