在three.js / Autodesk 3D Viewer(Autodesk Forge Viewer)中调整对象的大小

时间:2019-09-16 06:47:56

标签: canvas three.js autodesk-forge autodesk-viewer autodesk

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

此更改使我不得不上下移动窗帘

我需要调整大小位置一个动画对象或放置在一个位置(无差异)

viewer3D:LMV v3.3.6

  

尝试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);
}
  

尝试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);
}

这可能吗?

1 个答案:

答案 0 :(得分:1)

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

  • 使用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)