This is my first time delving into the world of javascript, WebGL, and Three.js. I successfully added a dae 3D model to my scene, but now I need to determine its size in order to generate objects within it. However, upon adding the dae object, it appeared rotated within the scene. After researching and testing, I discovered that simply rotating the object won't work as the bounding box will not rotate along with it. What steps should I take to accurately determine the size of the object?
<!DOCTYPE html>
<html>
<head>
<title>Collada Size.js</title>
</head>
<body>
<script src="js/three.min.js"></script>
<script src="js/ColladaLoader.js"></script>
<script>
window.onload = function () {
var renderer = new THREE.WebGLRenderer();
renderer.setSize(800, 600);
document.body.appendChild(renderer.domElement);
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
55, // Field of view
800 / 600, // Aspect ratio
0.1, // Near plane
1000 // Far plane
);
camera.position.set(-15, 1000, 10);
camera.lookAt(scene.position);
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load('models/MyFile.dae', function (collada) {
var dae = collada.scene;
var skin = collada.skins[0];
dae.position.set(0, 0, 0);
//dae.rotation.y = 45;
render();
dae.scale.set(120, 150, 120);
scene.add(dae);
sizeofDesk(dae);
});
function sizeofDesk(dae) {
var helper = new THREE.BoundingBoxHelper(dae, 0xff0000);
helper.update();
// If you want a visible bounding box
scene.add(helper);
// If you just want the numbers
var min = helper.box.min;
var max = helper.box.max;
console.log(min);
console.log(max);
}
var dirLight = new THREE.DirectionalLight(0xffffff, 1);
dirLight.position.set(100, 100, 50);
scene.add(dirLight);
renderer.setClearColor(0xffe5e5, 1);
render();
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
};
</script>
</body>
</html>