Rotate camera around object with Three.js

前端 未结 4 465
忘掉有多难
忘掉有多难 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:48

    This is what you want: http://threejs.org/examples/misc_controls_orbit.html

    Include the orbit controls (after you have downloaded them):

    
    

    Setup the variable:

    var controls;
    

    Attach the controls to the camera and add a listener:

    controls = new THREE.OrbitControls( camera );
    controls.addEventListener( 'change', render );
    

    and in your animate function update the controls:

    controls.update();
    

    [Update] controls.autoRotate = true; (tested in v73. Recent versions of OrbitControls.js has added this control.)

提交回复
热议问题