How to resize on object - Autodesk Forge Viewer

情到浓时终转凉″ 提交于 2019-12-06 18:48:30

Consider setting the scale of objects:

mesh.scale.set(x,y,z)

See usage reference here

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);
    
    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!