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

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

问题描述

如何更改对象的大小??

我需要改变对象的高度

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

<块引用>

在这段代码中,我的对象消失了

let change = function () {const 查看器 = oViewer;const 模型 = viewer.model;常量片段 = [123,361,];for(让我在碎片中){让 fragId = frags[i];//获取带有片段 ID 的网格让mesh = viewer.impl.getRenderProxy(model, fragId);//选择 ID让 dbId = 1280;//viewer.getSelection()[0]model.getData().instanceTree.enumNodeFragments(dbId, fragId => {网格.scale.x += 0.5;//网格.scale.y = 5;//网格.scale.z = 5;model.getFragmentList().setMesh(fragId, mesh, true);viewer.impl.invalidate(true);});}};

<块引用>

以下代码调整对象大小但变得太大且无法缩放

const viewer = oViewer;const 模型 = viewer.model;viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT,onSelectedCallback);函数 onSelectedCallback(事件){const fragId = event.fragIdsArray[0];if (typeof fragId == 'undefined') {return;}const fragIdsArray = (Array.isArray(fragId) ? fragId : [fragId]);fragIdsArray.forEach(function (subFragId) {让mesh = viewer.impl.getRenderProxy(model, subFragId).clone();网格.scale.y += 0.2;网格.scale.x += 0.2;网格.scale.z += 0.2;model.getFragmentList().setMesh(subFragId, mesh, true);viewer.impl.invalidate(true);});}

解决方案

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

let transform = new function () {让_self = this;this.fragId = null;this.proxy = null;this.viewer = oViewer;this.model = this.viewer.model;this.setFragId = 函数(fragId){this.fragId = fragId;this.proxy = this.viewer.impl.getFragmentProxy(this.model, this.fragId);this.proxy.getAnimTransform();};this.update = 函数(){this.proxy.updateAnimTransform();this.viewer.impl.sceneUpdated(true);};this.scaleX = 函数(数量){this.proxy.scale.x = num + 1;this.update();};this.scaleY = 函数(数量){this.proxy.scale.y = num + 1;this.update();};this.scaleZ = 函数(数量){this.proxy.scale.z = num + 1;this.update();};this.positionX = 函数(数量){this.proxy.position.x = num;this.update();};this.positionY = 函数(数量){this.proxy.position.y = num;this.update();};this.positionZ = 函数(数量){this.proxy.position.z = num;this.update();};};

<块引用>

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

let selection = new function () {this.viewer = oViewer;让_self = this;this.ids = 函数 () {返回 this.viewer.getSelection();};this.count = 函数 () {返回 this.viewer.getSelectionCount();};//网格对象this.mesh = 新函数 () {this.all = 函数 () {if (_self.count() === 0) return {};让网格 = _self.viewer.impl.selectionMeshes;让输出 = [];for(让索引在网格中){输出.推(网格[索引]);}返回输出;};this.fragIds = function(){让网格 = this.all();让 ids = [];网格.forEach(功能(网格){ids.push(mesh.fragId);});返回 ID;};this.first = 函数 () {返回 this.all()[0];};this.last = 函数 () {返回 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);

    How can i change size of on object ??

    i need to change height of on object

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

    on this code my object disappears

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

    The following code resizes objects but becomes too large and cannot be scaled

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

    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];
            }
        };
    
    };
    
    

    How to use ?

  • Select your element with mouse
  • Open browser console
  • Type selection.mesh.fragIds() // [11]
  • Type transform.setFragId(11)
  • Now You Can Change Scale and position :)

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

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

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