I'm looking to generate a box mesh within a three.js scene, with the points of the box mesh matching the bounding box of an existing object in the scene.
I attempted to create the box mesh from box3 using the method outlined below, but I'm not achieving the correct outcome:
let threeObject = the existing object in the scene;
let boundingBox = new THREE.Box3();
boundingBox.setFromObject(threeObject);
let geometry = new THREE.BufferGeometry();
let vertices = new Float32Array( [
boundingBox.min.x, boundingBox.min.y, boundingBox.min.z,
boundingBox.min.x, boundingBox.max.y, boundingBox.min.z,
boundingBox.min.x, boundingBox.min.y, boundingBox.max.z,
boundingBox.min.x, boundingBox.max.y, boundingBox.max.z,
boundingBox.max.x, boundingBox.min.y, boundingBox.min.z,
boundingBox.max.x, boundingBox.max.y, boundingBox.min.z,
boundingBox.max.x, boundingBox.min.y, boundingBox.max.z,
boundingBox.max.x, boundingBox.max.y, boundingBox.max.z,
] );
geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
let material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
let mesh = new THREE.Mesh( geometry, material );
viewer.scene.add(mesh);
Any advice on how to properly create a mesh box from box3? Your assistance is greatly appreciated!