Help needed with rotation in three.js I am facing a challenge when trying to rotate a 3D cube in one of my games.
//initialize
geometry = new THREE.CubeGeometry grid, grid, grid
material = new THREE.MeshLambertMaterial {color:0xFFFFFF * Math.random(), shading:THREE.FlatShading, overdraw:true, transparent: true, opacity:0.8}
for i in [<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0819e9e9ef0c3d8d1c0d59edcd5ded7c4d8">[email protected]</a>]
othergeo = new THREE.Mesh new THREE.CubeGeometry(grid, grid, grid)
othergeo.position.x = grid * @shape[i][0]
othergeo.position.y = grid * @shape[i][1]
THREE.GeometryUtils.merge geometry, othergeo
@mesh = new THREE.Mesh geometry, material
//rotate
@mesh.rotation.y += y * Math.PI / 180
@mesh.rotation.x += x * Math.PI / 180
@mesh.rotation.z += z * Math.PI / 180
When using values (1, 0, 0) for (x, y, z), the cube is able to rotate. However, the issue arises as the cube rotates on its own axis, preventing it from rotating as intended.
I came across a page How to rotate a Three.js Vector3 around an axis?, which explains rotating a Vector3 point around the world axis.
I attempted using matrixRotationWorld like this:
@mesh.matrixRotationWorld.x += x * Math.PI / 180
@mesh.matrixRotationWorld.y += y * Math.PI / 180
@mesh.matrixRotationWorld.z += z * Math.PI / 180
Unfortunately, this approach did not yield the desired results. I am unsure if I am using it incorrectly or if there are alternative methods...
Therefore, how can I make the 3D cube rotate around the world's axis?