How to get bounding box information from a 3D obje

2019-02-28 06:32发布

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条回答
对你真心纯属浪费
2楼-- · 2019-02-28 07:23

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)
查看更多
登录 后发表回答