threepipe
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PointerLockControlsPlugin.md 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---
  2. prev:
  3. text: 'DeviceOrientationControlsPlugin'
  4. link: './DeviceOrientationControlsPlugin'
  5. next:
  6. text: 'ThreeFirstPersonControlsPlugin'
  7. link: './ThreeFirstPersonControlsPlugin'
  8. ---
  9. # PointerLockControlsPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#pointer-lock-controls-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/PointerLockControlsPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/PointerLockControlsPlugin.html)
  14. PointerLockControlsPlugin adds support for using PointerLockControls from three.js. It works similar to controls in first person shooter, captures the mouse pointer and uses it to look around with the camera.
  15. After the plugin is added, it adds support for setting `pointerLock` as the key in `scene.mainCamera.controlMode`.
  16. Sample Usage
  17. ```typescript
  18. import {ThreeViewer, PointerLockControlsPlugin, Mesh2} from 'threepipe'
  19. const viewer = new ThreeViewer({...})
  20. viewer.addPluginSync(PointerLockControlsPlugin)
  21. // after some user action
  22. viewer.scene.mainCamera.controlsMode = 'pointerLock'
  23. // listen to lock/unlock events
  24. viewer.scene.mainCamera.controls?.addEventListener('lock', ()=> console.log('pointer locked'))
  25. viewer.scene.mainCamera.controls?.addEventListener('unlock', ()=> console.log('pointer unlocked'))
  26. // switch back to default orbit controls
  27. viewer.scene.mainCamera.controlsMode = 'orbit'
  28. ```