I am working on an aframe project that involves loading 3D objects of unknown sizes into my scene. Naturally I would want to resize the object to a certain size (like fixed height) before I put it in the scene. But how do I extract information like width, height and depth from the object's bounding box?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You'll need to use A-Frame's underlying three.js APIs here. That answer has been posted for three.js before, but here's an A-Frame version:
// get three.js object from aframe entity
var el = document.querySelector('#my-element');
var object = el.getObject3D('mesh');
// compute bounding box
var bbox = new THREE.Box3().setFromObject(obj);
console.log(bbox.min, bbox.max)