Three.js - Rotating a object around certain axis

后端 未结 2 1808
自闭症患者
自闭症患者 2021-01-24 03:15

I\'ve used THREE={REVISION:\"68\"}

I\'ve already done rotation (OBJECT_X) by axis \"z\"http://jsfiddle.net/eVkgs/39/

When I change position OBJECT_X

相关标签:
2条回答
  • 2021-01-24 03:56

    An object will rotate around its origin in its local coordinate system. If you want to shift the origin, then you have to translate the geometry itself. Here is the pattern to follow:

    geometry.translate( dx, dy, dz );
    

    You can now create a mesh from the geometry, and set the mesh position:

    mesh.position.set( x, y, z );
    

    If you rotate the mesh, it will rotate around its new origin, and the mesh will be located at the point ( x, y, z ).

    three.js r.84

    0 讨论(0)
  • 2021-01-24 03:57

    I solved this problem this way

    I created the ObjectControls module for ThreeJS that allows you to rotate a single OBJECT (or a Group), and not the SCENE

    Include the libary:

    then

    var controls = new THREE.ObjectControls(camera, renderer.domElement, yourMesh);

    You can find here a live demo here: https://albertopiras.github.io/threeJS-object-controls/

    Here is the repo: https://github.com/albertopiras/threeJS-object-controls.

    I hope this helps

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