Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

THREE.JS create custom 3D shape

How can I create the shape below with THREE.JS in WebGLRenderer.

Image of required shape

This shape is a cube, the top face of which has been rotated 45 degrees.
Is it possible to create the cube then change it vertexes or ...
any idea?

like image 213
MeTe-30 Avatar asked Feb 16 '23 19:02

MeTe-30


1 Answers

You can access the vertex positions using the array cubeMesh.geometry.vertices.

//create a cube as per usual
var cubeMesh = new THREE.Mesh(
    new THREE.CubeGeometry(1, 2, 1),
    new THREE.MeshLambertMaterial()
);
scene.add(cubeMesh);

//change vertex positions
cubeMesh.geometry.vertices[1].y += 1;
cubeMesh.geometry.vertices[4].y += 1;

//indicate that the vertices need update
cubeMesh.geometry.verticesNeedUpdate = true;
like image 120
chaindriver Avatar answered Feb 23 '23 20:02

chaindriver