BaseNode.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. getColor() {
  20. return ( this.getColorValueFromValue( this.value ) || '#777777' ) + 'BB';
  21. }
  22. serialize( data ) {
  23. super.serialize( data );
  24. delete data.width;
  25. }
  26. deserialize( data ) {
  27. delete data.width;
  28. super.deserialize( data );
  29. }
  30. setEditor( value ) {
  31. this.editor = value;
  32. return this;
  33. }
  34. getColorValueFromValue( value ) {
  35. if ( ! value ) return;
  36. if ( value.isMaterial === true ) {
  37. //return 'forestgreen';
  38. return '#228b22';
  39. } else if ( value.isObject3D === true ) {
  40. return '#ffa500';
  41. } else if ( value.isDataFile === true ) {
  42. return '#00ffff';
  43. }
  44. }
  45. add( element ) {
  46. element.onValid( ( source, target ) => this.onValidElement( source, target ) );
  47. return super.add( element );
  48. }
  49. }