WebGPUNodes.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import WebGPUNodeBuilder from './WebGPUNodeBuilder.js';
  2. import NodeFrame from '../../nodes/core/NodeFrame.js';
  3. class WebGPUNodes {
  4. constructor( renderer ) {
  5. this.renderer = renderer;
  6. this.nodeFrame = new NodeFrame();
  7. this.builders = new WeakMap();
  8. }
  9. get( object, lightNode ) {
  10. let nodeBuilder = this.builders.get( object );
  11. if ( nodeBuilder === undefined ) {
  12. nodeBuilder = new WebGPUNodeBuilder( object, this.renderer, lightNode ).build();
  13. this.builders.set( object, nodeBuilder );
  14. }
  15. return nodeBuilder;
  16. }
  17. remove( object ) {
  18. this.builders.delete( object );
  19. }
  20. updateFrame() {
  21. this.nodeFrame.update();
  22. }
  23. update( object, camera, lightNode ) {
  24. const renderer = this.renderer;
  25. const material = object.material;
  26. const nodeBuilder = this.get( object, lightNode );
  27. const nodeFrame = this.nodeFrame;
  28. nodeFrame.material = material;
  29. nodeFrame.camera = camera;
  30. nodeFrame.object = object;
  31. nodeFrame.renderer = renderer;
  32. for ( const node of nodeBuilder.updateNodes ) {
  33. nodeFrame.updateNode( node );
  34. }
  35. }
  36. dispose() {
  37. this.builders = new WeakMap();
  38. }
  39. }
  40. export default WebGPUNodes;