问题描述
当我们在场景中添加一个 CustomGeometry 并定义顶点而不设置位置时,我们如何让它围绕自己的中心点旋转?
When we add a CustomGeometry to the scene with defining vertices and not setting the position, how can we get it to rotate around its own center point?
小提琴:http://jsfiddle.net/tezcancirakoglu/Ldt7z
Fiddle : http://jsfiddle.net/tezcancirakoglu/Ldt7z
在示例代码中,对象围绕场景 X 轴旋转.我需要围绕它的中心点旋转它.
In the sample code, object is rotating around Scenes X axis. I need to rotate it around its center point.
提示:红色立方体网格是旋转对象的初始中心点.我需要围绕红色立方体的 x 轴旋转它...我尝试了很多但还是失败了.
Hint: The red cube mesh is the initial centerpoint of the object which is rotating. I need to rotate it around x axis of red cube... I tried alot but failed anyway.
推荐答案
一种解决方案是平移网格几何体,并通过改变网格位置来进行补偿,如下所示:
One solution is to translate the mesh geometry, and compensate by changing the mesh position, like so:
var offset = objMesh.centroid.clone();
objMesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation( -offset.x, -offset.y, -offset.z ) );
objMesh.position.copy( objMesh.centroid );
更新小提琴:http://jsfiddle.net/Ldt7z/165/
附言你不需要在运行之前保存你的小提琴.没有理由有这么多版本.
P.S. You do not need to save your fiddle before running it. There is no reason to have so many versions.
three.js r.55
three.js r.55
这篇关于围绕其中心点旋转自定义几何网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!