ReferenceNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import Node, { addNodeClass } from '../core/Node.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. import { uniform } from '../core/UniformNode.js';
  4. import { texture } from './TextureNode.js';
  5. import { nodeObject, getConstNodeType } from '../shadernode/ShaderNode.js';
  6. class ReferenceNode extends Node {
  7. constructor( property, uniformType, object = null ) {
  8. super();
  9. this.property = property;
  10. this.uniformType = uniformType;
  11. this.object = object;
  12. this.node = null;
  13. this.updateType = NodeUpdateType.OBJECT;
  14. this.setNodeType( uniformType );
  15. }
  16. setNodeType( uniformType ) {
  17. let node = null;
  18. if ( uniformType === 'texture' ) {
  19. node = texture( null );
  20. } else {
  21. node = uniform( uniformType );
  22. }
  23. this.node = node;
  24. }
  25. getNodeType( builder ) {
  26. return this.node.getNodeType( builder );
  27. }
  28. update( frame ) {
  29. const object = this.object !== null ? this.object : frame.object;
  30. const property = this.property;
  31. this.node.value = object[ property ];
  32. }
  33. construct( /*builder*/ ) {
  34. return this.node;
  35. }
  36. }
  37. export default ReferenceNode;
  38. export const reference = ( name, nodeOrType, object ) => nodeObject( new ReferenceNode( name, getConstNodeType( nodeOrType ), object ) );
  39. addNodeClass( ReferenceNode );