ThreeJS camera.lookAt() has no effect, is there something I'm doing wrong?

前端 未结 6 490
半阙折子戏
半阙折子戏 2021-02-05 02:13

In Three.js, I want a camera to be pointed at a point in 3D space.

For this purpose, I tried using the camera.lookAt function like so:

camer         


        
6条回答
  •  耶瑟儿~
    2021-02-05 02:43

    I figured it out. To prevent THREE.TrackballControls or THREE.OrbitControls from overriding camera.lookAt upon initialization, you need to change the line that sets the control's target property to equal the sum of the camera.position vector and the camera.getWorldDirection() vector, instead of how it's currently implemented using a new THREE.Vector3() (which defaults to (0, 0, 0)).

    So, for THREE.TrackballControls, change line 39 to:

    this.target = new THREE.Vector3().addVectors(/*new line for readability*/
        object.position, object.getWorldDirection());
    

    Same goes for THREE.OrbitControls, on line 36. I actaully haven't tested it on TrackballControls.js but it does work on OrbitControls.js. Hope this helps.

提交回复
热议问题