找到你要的答案

Q:Set the rotation of an object at its axis three js

Q:设置一个对象的旋转轴三JS

I try to set the rotation of an object at it's own axis using:

object.rotateOnAxis(new THREE.Vector3(1,0,0) , Math.PI)

in the render function, but the object is rotating in every rendering. Is there a way to set the rotation at it's own axis like when using:

object.rotation.x = Math.PI

or

object.rotation.set(Math.PI,0,0)

to set the rotation at the world axis?

我试着用它自己的轴来设置物体的旋转:

object.rotateOnAxis(new THREE.Vect或3(1,0,0) , Math.PI)

在渲染函数中,但是对象在每个渲染中都是旋转的。是否有一种方法来设置旋转时自己的轴,如使用时:

object.rotation.x = Math.PI

object.rotation.set(Math.PI,0,0)

to set the rotation at the w或ld axis?

answer1: 回答1:

Just remove the following code from the render method.

object.rotateOnAxis(new THREE.Vector3(1,0,0) , Math.PI)

You could put it to the declaration of object. Surely, you could also set the rotation there (in render) but that would reduce the performance needlessly.

Simply put it outside the render function.

EDIT: You can simply use

object.rotation.x += rotationSpeed; 

in the render method to let it rotate.

只需从渲染方法中移除以下代码。

object.rotateOnAxis(new THREE.Vect或3(1,0,0) , Math.PI)

You could put it to the declaration of object. Surely, you could also set the rotation there (in render) but that would reduce the perf或mance needlessly.

简单地把它放在渲染函数之外。

编辑:你可以简单地使用

object.rotation.x += rotationSpeed; 

在渲染方法让它旋转。

answer2: 回答2:

If the rotation must take place at the render function that means that the model is changing rotation at every render. Simply find the rotation difference and apply it to the model using the code mentioned:

object.rotateOnAxis(new THREE.Vector3(1,0,0) , Math.PI);

Store the old rotation and the new rotation at variables and apply the difference:

var old_rotation = value1;
var new_rotation = value2;
var Drotation = value1-value2;

if the difference is negative or positive it shows the direction of the rotation so just apply:

object.rotateOnAxis(new THREE.Vector3(1,0,0) , Drotation);

UPDATE: The simplest way i found is:

object.rotateX(angle);
object.rotateY(angle);
object.rotateZ(angle);

this rotates the object around its axes :D

如果旋转必须发生在渲染函数,这意味着该模型正在改变在每次渲染旋转。只需找到旋转差异,并将其应用到模型中使用的代码提到:

object.rotateOnAxis(new THREE.Vect或3(1,0,0) , Math.PI);

St或e the old rotation and the new rotation at variables and apply the difference:

var old_rotation = value1;
var new_rotation = value2;
var Drotation = value1-value2;

if the difference is negative 或 positive it shows the direction of the rotation so just apply:

object.rotateOnAxis(new THREE.Vect或3(1,0,0) , Drotation);

UPDATE: The simplest way i found is:

object.rotateX(angle);
object.rotateY(angle);
object.rotateZ(angle);

这使物体绕其轴旋转:D

object  rotation  three.js