Viewport.SelectionHelper.js 901 B

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