ViewTool.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * ViewTool.js
  3. *
  4. * @author realor
  5. */
  6. import { Tool } from './Tool.js'
  7. import { ObjectUtils } from '../utils/ObjectUtils.js'
  8. import * as THREE from '../lib/three.module.js'
  9. class ViewTool extends Tool {
  10. constructor(application, options) {
  11. super(application)
  12. this.name = 'view'
  13. this.label = 'tool.view.label'
  14. this.className = 'view'
  15. this.immediate = true
  16. this.x = 0 // degrees
  17. this.y = 0 // degrees
  18. this.z = 0 // degrees
  19. this.setOptions(options)
  20. }
  21. execute() {
  22. const application = this.application
  23. const container = application.container
  24. const aspect = container.clientWidth / container.clientHeight
  25. const camera = application.camera
  26. camera.rotation.x = THREE.MathUtils.degToRad(this.x)
  27. camera.rotation.y = THREE.MathUtils.degToRad(this.y)
  28. camera.rotation.z = THREE.MathUtils.degToRad(this.z)
  29. camera.updateMatrix()
  30. application.scene.updateMatrixWorld(true)
  31. ObjectUtils.zoomAll(camera, application.baseObject, aspect)
  32. application.notifyObjectsChanged(camera, this)
  33. }
  34. }
  35. export { ViewTool }