ReferenceNode.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Node from '../core/Node.js';
  2. import FloatNode from '../inputs/FloatNode.js';
  3. import Vector2Node from '../inputs/Vector2Node.js';
  4. import Vector3Node from '../inputs/Vector3Node.js';
  5. import Vector4Node from '../inputs/Vector4Node.js';
  6. import ColorNode from '../inputs/ColorNode.js';
  7. import TextureNode from '../inputs/TextureNode.js';
  8. import { NodeUpdateType } from '../core/constants.js';
  9. class ReferenceNode extends Node {
  10. constructor( property, inputType, object = null ) {
  11. super();
  12. this.property = property;
  13. this.inputType = inputType;
  14. this.object = object;
  15. this.node = null;
  16. this.updateType = NodeUpdateType.Object;
  17. this.setNodeType( inputType );
  18. }
  19. setNodeType( inputType ) {
  20. let node = null;
  21. let nodeType = inputType;
  22. if ( nodeType === 'float' ) {
  23. node = new FloatNode();
  24. } else if ( nodeType === 'vec2' ) {
  25. node = new Vector2Node( null );
  26. } else if ( nodeType === 'vec3' ) {
  27. node = new Vector3Node( null );
  28. } else if ( nodeType === 'vec4' ) {
  29. node = new Vector4Node( null );
  30. } else if ( nodeType === 'color' ) {
  31. node = new ColorNode( null );
  32. nodeType = 'vec3';
  33. } else if ( nodeType === 'texture' ) {
  34. node = new TextureNode();
  35. nodeType = 'vec4';
  36. }
  37. this.node = node;
  38. this.nodeType = nodeType;
  39. this.inputType = inputType;
  40. }
  41. getNodeType() {
  42. return this.inputType;
  43. }
  44. update( frame ) {
  45. const object = this.object !== null ? this.object : frame.object;
  46. const value = object[ this.property ];
  47. this.node.value = value;
  48. }
  49. generate( builder ) {
  50. return this.node.build( builder, this.getNodeType( builder ) );
  51. }
  52. }
  53. export default ReferenceNode;