THREE.js如何计算3D圆上的旋转位置?

时间:2022-05-23 04:42:34

As represented in the image below, I have a THREE.Scene with a simple cube. Attached to the cube is a CANNON.Body for Physics (represented in the green wireframe).

如下图所示,我有一个带有简单立方体的THREE.Scene。连接到立方体的是CANNON.Body for Physics(以绿色线框表示)。

The CANNON.Body is offset from the cube by a couple of units. For rotation, this offset will be the radius.

CANNON.Body从立方体偏移了几个单位。对于旋转,此偏移将是半径。

When I rotate the cube, I want the CANNON.Body to rotate around the cube based on the angle and radius. On the right hand side of the image, I rotated the cube with an angle of 45 degrees (I also have radians available). However, the CANNON.Body does not rotate around the cube, only around it's own center. I need it to rotate around the cube for all axes x, y and z.

当我旋转立方体时,我希望CANNON.Body根据角度和半径围绕立方体旋转。在图像的右侧,我以45度的角度旋转立方体(我也有弧度可用)。但是,CANNON.Body不会围绕立方体旋转,只围绕它自己的中心。我需要它围绕立方体旋转所有轴x,y和z。

Is there a built-in function in THREE.js or should I use my own mathematical equation for this? If so, what would that be?

THREE.js中是否有内置函数,或者我应该使用自己的数学方程式?如果是这样,会是什么?

THREE.js如何计算3D圆上的旋转位置?

Thanks!

P.S. I've seen solutions for pure THREE.js Scene's where the geometry is translated to manipulate the pivot point. Since I don't have geometry in my CANNON.Body, this will not be possible.

附:我已经看到了纯THREE.js场景的解决方案,其中几何体被转换为操纵枢轴点。由于我的CANNON.Body中没有几何体,所以这是不可能的。

1 个解决方案

#1


0  

I never worked with cannonjs, but was it possible to just add the Cube and the Rigid Body in a Three.Group?

我从未使用过cannonjs,但是可以在Three.Group中添加Cube和Rigid Body吗?

Like

var rigidBody = new CANNON.Body(); // whatever it is for cannon
var model = new THREE.Group();

// your model goes here
model.add(new THREE.Mesh(
  new THREE.BoxGeometry(1,1,1), 
  new THREE.MeshStandardMaterial()
));

model.add(rigidBody);
scene.add(model);

This way, if you rotate the parent element model, the rigidbody should update the same way.

这样,如果旋转父元素模型,刚体应该以相同的方式更新。

#1


0  

I never worked with cannonjs, but was it possible to just add the Cube and the Rigid Body in a Three.Group?

我从未使用过cannonjs,但是可以在Three.Group中添加Cube和Rigid Body吗?

Like

var rigidBody = new CANNON.Body(); // whatever it is for cannon
var model = new THREE.Group();

// your model goes here
model.add(new THREE.Mesh(
  new THREE.BoxGeometry(1,1,1), 
  new THREE.MeshStandardMaterial()
));

model.add(rigidBody);
scene.add(model);

This way, if you rotate the parent element model, the rigidbody should update the same way.

这样,如果旋转父元素模型,刚体应该以相同的方式更新。