Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the height of a cube in Three.js

Tags:

three.js

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.

like image 719
srayner Avatar asked Sep 06 '25 03:09

srayner


1 Answers

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

like image 90
WestLangley Avatar answered Sep 07 '25 22:09

WestLangley