Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rotate a mesh by 90 degrees in ThreeJS?

I have a mesh that I want to rotate by 90 degrees inside Three JS. Here is the image of the current situation: enter image description here

I want the selected mesh to be rotated parallelly to the large mesh. I have tried rotating the matrix like this:

matrix =   new THREE.Matrix4().makeRotationX(1.57) 

But the mesh goes into strange rotations. Is there any easier way to rotate it by 90 degrees ?

like image 392
Zaay Avatar asked Apr 27 '15 23:04

Zaay


People also ask

How do you rotate a mesh?

Put a HingeConstraint in the Mesh and connect it to something Anchored. UnAnchor the Mesh. Set the HingeConstraint to Motor and the Torque and Rotational Velocity values. The Mesh should rotate around the axis (the side) the HingeConstraint was attached to.

How do you rotate a shape 90 degrees in blender?

Press R to rotate, press Y to snap to the Y-axis, and enter -90 on your keyboard to rotate an object -90 degrees on the Y-axis.


2 Answers

The threejs rotation uses Radians (as you might know)

you can use this

mesh.rotation.x = Math.PI / 2; 

or

mesh.rotation.set(new THREE.Vector3( 0, 0, Math.PI / 2)); 
like image 68
Absulit Avatar answered Oct 04 '22 12:10

Absulit


You can rotate an object by using this function:

function rotateObject(object, degreeX=0, degreeY=0, degreeZ=0) {    object.rotateX(THREE.Math.degToRad(degreeX));    object.rotateY(THREE.Math.degToRad(degreeY));    object.rotateZ(THREE.Math.degToRad(degreeZ)); }  // usage: rotateObject(myPlane, 40, 30, 20); 
like image 36
Harun ERGUL Avatar answered Oct 04 '22 12:10

Harun ERGUL