gpt4 book ai didi

javascript - 如何调整对象的大小 - Autodesk Forge Viewer

转载 作者:行者123 更新时间:2023-11-30 13:52:29 26 4
gpt4 key购买 nike

如何更改对象的大小??

我需要改变物体的高度

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

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

最佳答案

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

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

};

如何使用?

  • 用鼠标选择你的元素
  • 打开浏览器控制台
  • 键入 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);

    关于javascript - 如何调整对象的大小 - Autodesk Forge Viewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57970267/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com