ReferenceNode.js 1.0 KB

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