'What is the proper use of threejs Box3().getSize() method?

Everywhere on stackoverflow et al seem to agree that the proper use of the Box3() getSize() method is as follows:

const geometry = new THREE.BoxGeometry( 10, 10, 10 );
const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );

let cubeBoundingBox = new THREE.Box3().setFromObject( cube );
let boxSize = cubeBoundingBox.getSize();
console.log("BoxSize: " + boxSize);

However this doesn't seem to be the case. See the error in this example: https://jsfiddle.net/8L5dczmf/3/

I can see in the three.js documentation that getSize() is in fact supposed to be used this way... unless I'm reading .getSize ( target : Vector3 ) : Vector3 incorrectly. What is wrong with the code in the fiddle above then?



Solution 1:[1]

You're expected to pass in a vector into which the result will be written:

// ...

let boxSize = new THREE.Vector3();
cubeBoundingBox.getSize(boxSize);

console.log("BoxSize: " + boxSize);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander