CacheNode.js 768 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Node, { addNodeClass } from './Node.js';
  2. import NodeCache from './NodeCache.js';
  3. import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
  4. class CacheNode extends Node {
  5. constructor( node, cache = new NodeCache() ) {
  6. super();
  7. this.isCacheNode = true;
  8. this.node = node;
  9. this.cache = cache;
  10. }
  11. getNodeType( builder ) {
  12. return this.node.getNodeType( builder );
  13. }
  14. build( builder, ...params ) {
  15. const previousCache = builder.getCache();
  16. builder.setCache( this.cache );
  17. const data = this.node.build( builder, ...params );
  18. builder.setCache( previousCache );
  19. return data;
  20. }
  21. }
  22. export default CacheNode;
  23. export const cache = nodeProxy( CacheNode );
  24. addNodeElement( 'cache', cache );
  25. addNodeClass( CacheNode );