Rotating a custom geometry mesh around its center point

荒凉一梦 提交于 2019-12-19 03:59:25

问题


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?

Fiddle : http://jsfiddle.net/tezcancirakoglu/Ldt7z

In the sample code, object is rotating around Scenes X axis. I need to rotate it around its center point.

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.


回答1:


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

updated fiddle: 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




回答2:


You can use the center of the bounding box, which would basically be the 'average' of your vertices but it is not guaranteed to fall onto the red cube.



来源:https://stackoverflow.com/questions/14413492/rotating-a-custom-geometry-mesh-around-its-center-point

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!