WebGPURenderObject.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. export default class WebGPURenderObject {
  2. constructor( renderer, nodes, object, material, scene, camera, lightsNode ) {
  3. this.renderer = renderer;
  4. this.nodes = nodes;
  5. this.object = object;
  6. this.material = material;
  7. this.scene = scene;
  8. this.camera = camera;
  9. this.lightsNode = lightsNode;
  10. this.geometry = object.geometry;
  11. this.attributes = null;
  12. this._materialVersion = - 1;
  13. this._materialCacheKey = '';
  14. }
  15. getAttributes() {
  16. if ( this.attributes !== null ) return this.attributes;
  17. const nodeAttributes = this.nodes.get( this ).getAttributesArray();
  18. const geometry = this.geometry;
  19. const attributes = [];
  20. for ( const nodeAttribute of nodeAttributes ) {
  21. attributes.push( nodeAttribute.node && nodeAttribute.node.attribute ? nodeAttribute.node.attribute : geometry.getAttribute( nodeAttribute.name ) );
  22. }
  23. this.attributes = attributes;
  24. return attributes;
  25. }
  26. getCacheKey() {
  27. const { material, scene, lightsNode } = this;
  28. if ( material.version !== this._materialVersion ) {
  29. this._materialVersion = material.version;
  30. this._materialCacheKey = material.customProgramCacheKey();
  31. }
  32. const cacheKey = [];
  33. cacheKey.push( 'material:' + this._materialCacheKey );
  34. cacheKey.push( 'nodes:' + this.nodes.getCacheKey( scene, lightsNode ) );
  35. return '{' + cacheKey.join( ',' ) + '}';
  36. }
  37. }