I currently have one mesh with LineSegmets and another with BoxGeometry since I have a requirement where I need to check the bounding box size of the mesh and return mesh that has a tiny bounding box. basically the small mesh .
The bounding box size and radius of BoxGeometry are greater than those of LineSegment mesh, even if LineSegment mesh appears to be larger when compared to BoxGeometry
Therefore, I fail to see why the LineSegment geometry box and radius size are not larger.
here is my code and link to the CodeSandbox codesandbox
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/Addons.js";
let box1, scene, camera, renderer, materialLines, geometryLines, boxMesh;
function getBoundingBoxSize(object) {
const box = new THREE.Box3().setFromObject(object);
const size = new THREE.Vector3();
box.getSize(size);
return size.length();
}
function getBoundingSphere(object) {
const sphere = new THREE.Sphere();
object.geometry.computeBoundingSphere();
sphere.copy(object.geometry.boundingSphere);
return sphere.radius;
}
function init() {
scene = new THREE.Scene();
camera = new THREE.OrthographicCamera();
camera.position.z = 2;
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new OrbitControls(camera, renderer.domElement);
materialLines = new THREE.LineBasicMaterial({
color: 0xff0000,
side: THREE.DoubleSide,
});
const w = 0.2;
const h = 0.5;
const verticesBox1 = new Float32Array([
-w / 2,
h / 2,
0,
w / 2,
h / 2,
0,
w / 2,
h / 2,
0,
w / 2,
-h / 2,
0,
w / 2,
-h / 2,
0,
-w / 2,
-h / 2,
0,
-w / 2,
-h / 2,
0,
-w / 2,
h / 2,
0,
]);
geometryLines = new THREE.BufferGeometry();
geometryLines.setAttribute(
"position",
new THREE.BufferAttribute(verticesBox1, 3)
);
box1 = new THREE.LineSegments(geometryLines, materialLines);
box1.position.set(-0.2, 0, 0);
scene.add(box1);
boxMesh = new THREE.Mesh(new THREE.BoxGeometry(0.05, 0.05));
boxMesh.position.set(-0.2, 0, 0);
scene.add(boxMesh);
console.log("bboxsize line box1", getBoundingBoxSize(box1));
console.log("bboxsize boxMesh", getBoundingBoxSize(boxMesh));
console.log("bounding sphere box1", getBoundingSphere(box1));
console.log("bounding sphere boxMesh", getBoundingSphere(boxMesh));
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
init();
animate();