Viewport.Selector.js 877 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. class Selector {
  2. constructor( editor ) {
  3. const signals = editor.signals;
  4. this.editor = editor;
  5. this.config = editor.config;
  6. this.signals = signals;
  7. // signals
  8. signals.intersectionsDetected.add( ( intersects ) => {
  9. if ( intersects.length > 0 ) {
  10. const object = intersects[ 0 ].object;
  11. if ( object.userData.object !== undefined ) {
  12. // helper
  13. this.select( object.userData.object );
  14. } else {
  15. this.select( object );
  16. }
  17. } else {
  18. this.select( null );
  19. }
  20. } );
  21. }
  22. select( object ) {
  23. if ( this.editor.selected === object ) return;
  24. let uuid = null;
  25. if ( object !== null ) {
  26. uuid = object.uuid;
  27. }
  28. this.editor.selected = object;
  29. this.config.setKey( 'selected', uuid );
  30. this.signals.objectSelected.dispatch( object );
  31. }
  32. deselect() {
  33. this.select( null );
  34. }
  35. }
  36. export { Selector };
粤ICP备19079148号