如何在对象上调整大小-Autodesk Forge Viewer [英] How to resize on object - Autodesk Forge Viewer

查看:410
本文介绍了如何在对象上调整大小-Autodesk Forge Viewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改对象的大小?

我需要更改物体上的高度

i need to change height of on object

例如,我们需要更改门或窗帘的高度

For example, we need to change the height of a door or curtain

在此代码上,我的对象消失了

let change = function () {

    const viewer = oViewer;
    const model = viewer.model;

    const frags = [
        123,
        361,
    ];

    for(let i in frags){

        let fragId = frags[i];

        // Get mesh with frag id
        let mesh = viewer.impl.getRenderProxy(model, fragId);

        // Selection ID
        let dbId = 1280; // viewer.getSelection()[0]

        model.getData().instanceTree.enumNodeFragments(dbId, fragId => {
            mesh.scale.x += 0.5;
            // mesh.scale.y = 5;
            // mesh.scale.z = 5;

            model.getFragmentList().setMesh(fragId, mesh, true);
            viewer.impl.invalidate(true);
        });
    }
};

以下代码会调整对象的大小,但会变得太大而无法缩放

const viewer = oViewer;
const model = viewer.model;

viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectedCallback);

function onSelectedCallback(event) {

    const fragId = event.fragIdsArray[0];

    if (typeof fragId == 'undefined') {return;}

    const fragIdsArray = (Array.isArray(fragId) ? fragId : [fragId]);

    fragIdsArray.forEach(function (subFragId) {

        let mesh = viewer.impl.getRenderProxy(model, subFragId).clone();

        mesh.scale.y += 0.2;
        mesh.scale.x += 0.2;
        mesh.scale.z += 0.2;

        model.getFragmentList().setMesh(subFragId, mesh, true);
        viewer.impl.invalidate(true);
    });
}

推荐答案

我找到了解决方案并为此编写了脚本

I found the solution and wrote the script for it

let transform = new function () {

    let _self = this;

    this.fragId = null;
    this.proxy = null;
    this.viewer = oViewer;
    this.model = this.viewer.model;

    this.setFragId = function (fragId) {
        this.fragId = fragId;
        this.proxy = this.viewer.impl.getFragmentProxy(this.model, this.fragId);
        this.proxy.getAnimTransform();
    };

    this.update = function(){
        this.proxy.updateAnimTransform();
        this.viewer.impl.sceneUpdated(true);
    };

    this.scaleX = function (num) {
        this.proxy.scale.x = num + 1;
        this.update();
    };

    this.scaleY = function (num) {
        this.proxy.scale.y = num + 1;
        this.update();
    };

    this.scaleZ = function (num) {
        this.proxy.scale.z = num + 1;
        this.update();
    };

    this.positionX = function (num) {
        this.proxy.position.x = num;
        this.update();
    };

    this.positionY = function (num) {
        this.proxy.position.y = num;
        this.update();
    };

    this.positionZ = function (num) {
        this.proxy.position.z = num;
        this.update();
    };

};

对于查找碎片ID,您可以使用以下代码

for find frag Ids you can use follow code

let selection = new function () {

    this.viewer = oViewer;

    let _self = this;

    this.ids = function () {
        return this.viewer.getSelection();
    };

    this.count = function () {
        return this.viewer.getSelectionCount();
    };

    // Mesh Object
    this.mesh = new function () {
        this.all = function () {
            if (_self.count() === 0) return {};

            let meshes = _self.viewer.impl.selectionMeshes;
            let output = [];

            for (let index in meshes) {
                output.push(meshes[index]);
            }

            return output;
        };

        this.fragIds = function(){
            let meshes = this.all();
            let ids = [];
            meshes.forEach(function(mesh){
                ids.push(mesh.fragId);
            });
            return ids;
        };

        this.first = function () {
            return this.all()[0];
        };

        this.last = function () {
            return this.all().reverse()[0];
        }
    };

};

如何使用?

  • 用鼠标选择元素
  • 打开浏览器控制台
  • 键入selection.mesh.fragIds() // [11]
  • 键入transform.setFragId(11)
  • 现在您可以更改比例和位置:)

    transform.scaleX(number);
    
    transform.scaleY(number);
    
    transform.scaleZ(number);
    
    
    transform.positionX(number);
    
    transform.positionY(number);
    
    transform.positionZ(number);
    

    这篇关于如何在对象上调整大小-Autodesk Forge Viewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆