使用 js 获取 3d 模型的尺寸(大小)
Get the dimensions(sizes) of a 3d model with js
我实际上使用 three.js 从事 AR 项目,我处理一些 3d 模型,但我对模型的大小有一些疑问。因为我希望它们都具有相同的尺寸,所以我需要为所有模型设置相同的尺寸。我首先尝试通过使用 boundingbox 和 boundingsphere 来解决这个问题,但它不起作用。
那么如何获取尺寸以及如何设置尺寸?
var size = new THREE.Box3().setFromObject( yourObject ).getSize(new THREE.Vector3())
我还需要一些其他东西,因为 manthrax 的代码很有趣但有一些限制.. 例如这个代码:
andy.scale.set(0.011, 0.011, 0.011);
andy.rotation.set(0, 0, 0);
andy.position.set(0,0,0);
var size = new THREE.Box3().setFromObject(andy).getSize(new THREE.Vector3())
console.log(size);
function moy(vect){
return ((vect.x+vect.y+vect.z)/3);;
}
console.log(moy(size));
andy.scale.set(0.030, 0.030, 0.030);
console.log(moy(size));
如果我想更改 "size" 的值,我该怎么做?
PS: 安迪是我的3d模型
我解决了,我创建了我自己的box3:
andy.scale.set(0.011, 0.011, 0.011);
andy.rotation.set(0, 0, 0);
andy.position.set(0,0,0);
var box3d = new THREE.Box3();
var size = box3d.setFromObject(andy).getSize(new THREE.Vector3())
console.log(size);
function moy(vect){
return ((vect.x+vect.y+vect.z)/3);;
}
console.log(moy(size));
andy.scale.set(0.030, 0.030, 0.030);
box3d.setFromObject(andy).getSize(size);
console.log(moy(size));
我实际上使用 three.js 从事 AR 项目,我处理一些 3d 模型,但我对模型的大小有一些疑问。因为我希望它们都具有相同的尺寸,所以我需要为所有模型设置相同的尺寸。我首先尝试通过使用 boundingbox 和 boundingsphere 来解决这个问题,但它不起作用。
那么如何获取尺寸以及如何设置尺寸?
var size = new THREE.Box3().setFromObject( yourObject ).getSize(new THREE.Vector3())
我还需要一些其他东西,因为 manthrax 的代码很有趣但有一些限制.. 例如这个代码:
andy.scale.set(0.011, 0.011, 0.011);
andy.rotation.set(0, 0, 0);
andy.position.set(0,0,0);
var size = new THREE.Box3().setFromObject(andy).getSize(new THREE.Vector3())
console.log(size);
function moy(vect){
return ((vect.x+vect.y+vect.z)/3);;
}
console.log(moy(size));
andy.scale.set(0.030, 0.030, 0.030);
console.log(moy(size));
如果我想更改 "size" 的值,我该怎么做?
PS: 安迪是我的3d模型
我解决了,我创建了我自己的box3:
andy.scale.set(0.011, 0.011, 0.011);
andy.rotation.set(0, 0, 0);
andy.position.set(0,0,0);
var box3d = new THREE.Box3();
var size = box3d.setFromObject(andy).getSize(new THREE.Vector3())
console.log(size);
function moy(vect){
return ((vect.x+vect.y+vect.z)/3);;
}
console.log(moy(size));
andy.scale.set(0.030, 0.030, 0.030);
box3d.setFromObject(andy).getSize(size);
console.log(moy(size));