Switch threejs controls ( from TrackBall to FlyControls and vice versa)

前端 未结 2 670
日久生厌
日久生厌 2020-12-05 21:21

What I am trying to achieve is to have two control modes, a free \"flying\" one, and an object-centered one (trackball) and with a button press seamlessly switch between the

相关标签:
2条回答
  • 2020-12-05 21:58

    What about something like this?

    function onClick() {
    
        var prevCamera = camera;
    
        camera = new THREE.PerspectiveCamera(...);
        camera.position.copy( prevCamera.position );
        camera.rotation.copy( prevCamera.rotation );
    
        var MODE = { TRACKBALL: 0, FLY: 1 };
    
        switch( mode ) {
    
            case MODE.FLY:
    
                controls = new THREE.TrackballControls( camera );
    
                mode = MODE.TRACKBALL;
    
                break;
    
            case MODE.TRACKBALL:
    
                controls = new THREE.FlyControls( camera );
    
                mode = MODE.FLY;
    
                break;
    
        }
    
    }
    
    0 讨论(0)
  • 2020-12-05 22:19

    Making a new camera is the easiest way to unbind all the keyboard/mouse events that were setup with the previous controls. If you don't do this you'll have orbitcontrols events fire with fly mode on.

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