BaseNode.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { ObjectNode } from '../../libs/flow.module.js';
  2. export const onNodeValidElement = ( inputElement, outputElement ) => {
  3. const outputObject = outputElement.getObject();
  4. if ( ! outputObject || ! outputObject.isNode ) {
  5. return false;
  6. }
  7. };
  8. export class BaseNode extends ObjectNode {
  9. constructor( name, inputLength, value = null, width = 300 ) {
  10. const getObjectCallback = ( /*output = null*/ ) => {
  11. return this.value;
  12. };
  13. super( name, inputLength, getObjectCallback, width );
  14. this.setOutputColor( this.getColorValueFromValue( value ) );
  15. this.editor = null;
  16. this.value = value;
  17. this.onValidElement = onNodeValidElement;
  18. }
  19. serialize( data ) {
  20. super.serialize( data );
  21. delete data.width;
  22. }
  23. deserialize( data ) {
  24. delete data.width;
  25. super.deserialize( data );
  26. }
  27. setEditor( value ) {
  28. this.editor = value;
  29. return this;
  30. }
  31. getColorValueFromValue( value ) {
  32. if ( ! value ) return;
  33. if ( value.isMaterial === true ) {
  34. return 'forestgreen';
  35. } else if ( value.isObject3D === true ) {
  36. return 'orange';
  37. } else if ( value instanceof File ) {
  38. return 'aqua';
  39. }
  40. }
  41. add( element ) {
  42. element.onValid( ( source, target ) => this.onValidElement( source, target ) );
  43. return super.add( element );
  44. }
  45. }