Using Box Geometry to make cuboids and cubes

Using Box Geometry to make cuboids and cubes

ยท

1 min read

Box Geometry

const geometry = new THREE.BoxGeometry( 10, 20, 10, 1, 1 );
const material = new THREE.MeshNormalMaterial( {flatShading : false} );
const box = new THREE.Mesh( geometry, material );
scene.add( box );

animate();

function animate() {
      requestAnimationFrame(animate);
      box.rotation.x += 0.01;
      box.rotation.y += 0.01;
      box.rotation.z += 0.01;
      renderer.render(scene, camera);
}
  • BoxGeometry(width : Float, height : Float, depth : Float, widthSegments : Integer, heightSegments : Integer, depthSegments : Integer) creates a box of dimensions width height depth.
  • width is considered along X-axis. Default: 1
  • height is considered along Y-axis. Default: 1
  • depth is considered along Z-axis. Default: 1
  • widthSegments, heightSegments & depthSegments are the number of segments used to construct each face.

    For making Cubes we just have to make height, width & depth equal.

  • This is the simplest Geometry.๐Ÿ˜„

box.PNG

๐Ÿคฉ Looking forward to hear from you.

Follow me on Twitter or LinkedIn. ๐Ÿ˜„๐Ÿ˜„๐Ÿ˜„

ย