Rotating a custom geometry mesh around its center point

前端 未结 2 1043
感动是毒
感动是毒 2021-01-06 15:13

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

相关标签:
2条回答
  • 2021-01-06 15:38

    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.

    0 讨论(0)
  • 2021-01-06 15:39

    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

    0 讨论(0)
提交回复
热议问题