RenderObject.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. let id = 0;
  2. export default class RenderObject {
  3. constructor( nodes, geometries, renderer, object, material, scene, camera, lightsNode ) {
  4. this._nodes = nodes;
  5. this._geometries = geometries;
  6. this.id = id ++;
  7. this.renderer = renderer;
  8. this.object = object;
  9. this.material = material;
  10. this.scene = scene;
  11. this.camera = camera;
  12. this.lightsNode = lightsNode;
  13. this.geometry = object.geometry;
  14. this.attributes = null;
  15. this.context = null;
  16. this.pipeline = null;
  17. this._materialVersion = - 1;
  18. this._materialCacheKey = '';
  19. }
  20. getNodeBuilder() {
  21. return this._nodes.getForRender( this );
  22. }
  23. getBindings() {
  24. return this.getNodeBuilder().getBindings();
  25. }
  26. getIndex() {
  27. return this._geometries.getIndex( this );
  28. }
  29. getChainArray() {
  30. return [ this.object, this.material, this.scene, this.camera, this.lightsNode ];
  31. }
  32. getAttributes() {
  33. if ( this.attributes !== null ) return this.attributes;
  34. const nodeAttributes = this.getNodeBuilder().getAttributesArray();
  35. const geometry = this.geometry;
  36. const attributes = [];
  37. for ( const nodeAttribute of nodeAttributes ) {
  38. attributes.push( nodeAttribute.node && nodeAttribute.node.attribute ? nodeAttribute.node.attribute : geometry.getAttribute( nodeAttribute.name ) );
  39. }
  40. this.attributes = attributes;
  41. return attributes;
  42. }
  43. getCacheKey() {
  44. const { material, scene, lightsNode } = this;
  45. if ( material.version !== this._materialVersion ) {
  46. this._materialVersion = material.version;
  47. this._materialCacheKey = material.customProgramCacheKey();
  48. }
  49. const cacheKey = [];
  50. cacheKey.push( 'material:' + this._materialCacheKey );
  51. cacheKey.push( 'nodes:' + this._nodes.getCacheKey( scene, lightsNode ) );
  52. return '{' + cacheKey.join( ',' ) + '}';
  53. }
  54. }