Rotate camera around object with Three.js

前端 未结 4 455
忘掉有多难
忘掉有多难 2020-12-29 08:05

I\'m displaying an OBJ element with Three.js using WebGlRenderer, now I\'d like to allow users to rotate the camera around the object in any direction, I\'ve found this answ

4条回答
  •  悲&欢浪女
    2020-12-29 08:32

    Indeed, if you substitute 'camera' with the object of your choice, the object will rotate. But if there are other objects surrounding it (for example a grid on the floor), they will still stand still. That might be what you want, or it might look weird. (Imagine a chair rotating floating above the floor...?)

    I choose to override the center object from OrbitControls.JS from my code after initializing the Orbit Controls

    controls = new THREE.OrbitControls(camera, renderer.domElement);
    …
    controls.center =  new THREE.Vector3(
        chair.position.x,
        chair.position.y,
        chair.position.z
    );
    

    (disclaimer: I have the impression there are different versions of OrbitControls.js around, but I assume they all use this center-object)

提交回复
热议问题