PointsEditor.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { LabelElement } from '../../libs/flow.module.js';
  2. import { Object3DEditor } from './Object3DEditor.js';
  3. import { Points } from 'three';
  4. export class PointsEditor extends Object3DEditor {
  5. constructor( points = null ) {
  6. if ( points === null ) {
  7. points = new Points();
  8. }
  9. super( points, 'Points' );
  10. this.material = null;
  11. this.defaultMaterial = null;
  12. this._initMaterial();
  13. this.updateDefault();
  14. this.restoreDefault();
  15. this.update();
  16. }
  17. get points() {
  18. return this.value;
  19. }
  20. _initMaterial() {
  21. const materialElement = new LabelElement( 'Material' ).setInputColor( 'forestgreen' ).setInput( 1 );
  22. materialElement.onValid( ( source, target, stage ) => {
  23. const object = target.getObject();
  24. if ( object && object.isMaterial !== true ) {
  25. if ( stage === 'dragged' ) {
  26. const name = target.node.getName();
  27. this.editor.tips.error( `"${name}" is not a Material.` );
  28. }
  29. return false;
  30. }
  31. } ).onConnect( () => {
  32. this.material = materialElement.getLinkedObject() || this.defaultMaterial;
  33. this.update();
  34. } );
  35. this.add( materialElement );
  36. }
  37. update() {
  38. super.update();
  39. const points = this.points;
  40. if ( points ) {
  41. points.material = this.material || this.defaultMaterial;
  42. }
  43. }
  44. updateDefault() {
  45. super.updateDefault();
  46. this.defaultMaterial = this.points.material;
  47. }
  48. restoreDefault() {
  49. super.restoreDefault();
  50. this.points.material = this.defaultMaterial;
  51. }
  52. }