问题
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