Javascript 如何在 ThreeJS 中将网格旋转 90 度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29907536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:17:37  来源:igfitidea点击:

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

javascriptmatrix3drotationthree.js

提问by Zaay

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

我有一个网格,我想在 Three JS 中旋转 90 度。这是当前情况的图像: 在此处输入图片说明

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 ?

但是网格会发生奇怪的旋转。有没有更简单的方法将它旋转 90 度?

回答by Absulit

The threejs rotation uses Radians (as you might know)

Threejs 旋转使用弧度(你可能知道)

you can use this

你可以用这个

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

or

或者

mesh.rotation.set(new THREE.Vector3( 0, 0, Math.PI / 2));

回答by Harun ERGUL

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);

回答by prahadeesh

Let's say meshToRotateneeds to be rotated by 90 degrees in X axis. Then do the following.

假设meshToRotate需要在 X 轴上旋转 90 度。然后执行以下操作。

var meshToRotate = new THREE.Mesh( geometry, material );

//Rotating mesh by 90 degree in X axis.     
meshToRotate.rotateX( Math.PI / 2 );

回答by Tib

Tested on r96, you can also use

在r96上测试过,你也可以使用

mesh.rotation.setFromVector3(new THREE.Vector3( Math.PI / 2, 0, 0));