ReferenceNode.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Node from '../core/Node.js';
  2. import UniformNode from '../core/UniformNode.js';
  3. import { NodeUpdateType } from '../core/constants.js';
  4. class ReferenceNode extends Node {
  5. constructor( property, uniformType, object = null ) {
  6. super();
  7. this.property = property;
  8. this.uniformType = uniformType;
  9. this.object = object;
  10. this.node = null;
  11. this.updateType = NodeUpdateType.Object;
  12. this.setNodeType( uniformType );
  13. }
  14. setNodeType( uniformType ) {
  15. this.node = new UniformNode( null, uniformType );
  16. this.nodeType = uniformType;
  17. if ( uniformType === 'color' ) {
  18. this.nodeType = 'vec3';
  19. } else if ( uniformType === 'texture' ) {
  20. this.nodeType = 'vec4';
  21. }
  22. }
  23. getNodeType() {
  24. return this.uniformType;
  25. }
  26. update( frame ) {
  27. const object = this.object !== null ? this.object : frame.object;
  28. const value = object[ this.property ];
  29. this.node.value = value;
  30. }
  31. generate( builder ) {
  32. return this.node.build( builder, this.getNodeType( builder ) );
  33. }
  34. }
  35. export default ReferenceNode;