CenterSelectionTool.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * CenterTool.js
  3. *
  4. * @author realor
  5. */
  6. import { Tool } from './Tool.js'
  7. import { ObjectUtils } from '../utils/ObjectUtils.js'
  8. import { I18N } from '../i18n/I18N.js'
  9. class CenterSelectionTool extends Tool {
  10. constructor(application, options) {
  11. super(application)
  12. this.name = 'center_selection'
  13. this.label = 'tool.center_selection.label'
  14. this.help = 'tool.center_selection.help'
  15. this.className = 'center_selection'
  16. this.setOptions(options)
  17. this.immediate = true
  18. this.focusOnSelection = false
  19. this.setOptions(options)
  20. }
  21. execute() {
  22. const application = this.application
  23. let objects = application.selection.roots
  24. if (objects.length > 0) {
  25. if (this.focusOnSelection) {
  26. application.updateVisibility(application.baseObject, false)
  27. application.updateVisibility(objects, true)
  28. }
  29. const container = application.container
  30. const aspect = container.clientWidth / container.clientHeight
  31. const camera = application.camera
  32. application.scene.updateMatrixWorld(true)
  33. ObjectUtils.zoomAll(camera, objects, aspect, true)
  34. application.notifyObjectsChanged(camera, this)
  35. }
  36. }
  37. }
  38. export { CenterSelectionTool }