threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceOrientationControlsPlugin.md 1.5KB

пре 1 година
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---
  2. prev:
  3. text: 'Object3DGeneratorPlugin'
  4. link: './Object3DGeneratorPlugin'
  5. next:
  6. text: 'PointerLockControlsPlugin'
  7. link: './PointerLockControlsPlugin'
  8. ---
  9. # DeviceOrientationControlsPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#device-orientation-controls-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/DeviceOrientationControlsPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/DeviceOrientationControlsPlugin.html)
  14. DeviceOrientationControlsPlugin enables controlling the main camera rotation in the scene with device orientation. This only works on devices which have a gyroscope(but can also be emulated in devtools in chrome).
  15. After the plugin is added, it adds support for setting `deviceOrientation` as the key in `scene.mainCamera.controlMode`.
  16. When the controls is started (for the first time), the current camera rotation is and the device orientation is saved and used as reference. To reset the saved device orientation, call `resetView` in the controls.
  17. Sample Usage
  18. ```typescript
  19. import {ThreeViewer, DeviceOrientationControlsPlugin, Mesh2} from 'threepipe'
  20. const viewer = new ThreeViewer({...})
  21. viewer.addPluginSync(DeviceOrientationControlsPlugin)
  22. // after some user action
  23. viewer.scene.mainCamera.controlsMode = 'deviceOrientation'
  24. // to reset the saved device orientation
  25. viewer.scene.mainCamera.controls.resetView()
  26. // switch back to default orbit controls
  27. viewer.scene.mainCamera.controlsMode = 'orbit'
  28. ```