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

前端 未结 2 677
日久生厌
日久生厌 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;
    
        }
    
    }
    

提交回复
热议问题