Three.js: making bounding box

主宰稳场 提交于 2021-01-28 11:49:32

问题


In my program, I am trying to make bounding box around a point cloud. I have calculated the opposite vertices for this purpose.

Here, documentation for BoxGeomtery is available. But I am not able to understand the constructor. Constructor takes width,height, depth as inputs. But what about location of the box. Where in the scene would this box be created?I want bounding box to be defined by two vertices I have.

Edit:

var geometry = new THREE.Box3(mn,mx);
var material = new THREE.MeshBasicMaterial({color: 0xfffff, wireframe: true});
var bBox = new THREE.Mesh(geometry, material);
scene.add(bBox);

mn,mx are vertices of the box. Above code gives error as:

Uncaught TypeError: object.geometry.addEventListener is not a function


回答1:


BoxGeomtery is a geometry generator. What you are looking for is Box3, three.js's AABB implementation. You can use Box3.setFromObject to generate a bounding box for a 3D object.

const aabb = new THREE.Box3().setFromObject( points );

You can then use Box3.getCenter to retrieve the center of the box.



来源:https://stackoverflow.com/questions/49998810/three-js-making-bounding-box

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