How to get bounding box information from a 3D object in aframe?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 11:55:01

问题


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)


来源:https://stackoverflow.com/questions/49291812/how-to-get-bounding-box-information-from-a-3d-object-in-aframe

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