I have the following code;
// World
var geometry = new THREE.BoxGeometry( 100, 200, 100 );
var material = new THREE.MeshLambertMaterial( { color: 'green' } );
var cube = new THREE.Mesh( geometry, material );
cube.position.y = (cube.height / 2); // this doesn't work
scene.add( cube );
What is the correct method to get the height of the cube? I know the height = 100, but I want to understand how I get the height using program code.
If you create a cube mesh using THREE.BoxGeometry, you can get the height of the cube by accessing the parameters property of the geometry:
height = mesh.geometry.parameters.height;
If you have changed the mesh property scale.y from its default value of 1, then you will have to multiply the above quantity by scale.y.
three.js r.71
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With