NodeRenderResources.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import Check from "../../Core/Check.js";
  2. import clone from "../../Core/clone.js";
  3. /**
  4. * A model is made up of one or more nodes in the scene graph. Some details
  5. * such as instancing are computed on a per-node basis. This class provides
  6. * a place to store such details. It also inherits some properties from
  7. * the model render resources.
  8. *
  9. * @constructor
  10. *
  11. * @param {ModelRenderResources} modelRenderResources The model resources to inherit
  12. * @param {ModelRuntimeNode} runtimeNode The in-memory representation of the scene graph node.
  13. *
  14. * @private
  15. */
  16. function NodeRenderResources(modelRenderResources, runtimeNode) {
  17. //>>includeStart('debug', pragmas.debug);
  18. Check.typeOf.object("modelRenderResources", modelRenderResources);
  19. Check.typeOf.object("runtimeNode", runtimeNode);
  20. //>>includeEnd('debug');
  21. // Properties inherited from the ModelRenderResources.
  22. /**
  23. * A reference to the model. Inherited from the model render resources.
  24. *
  25. * @type {Model}
  26. * @readonly
  27. *
  28. * @private
  29. */
  30. this.model = modelRenderResources.model;
  31. /**
  32. * An object used to build a shader incrementally. This is cloned from the
  33. * model render resources because each node can compute a different shader.
  34. *
  35. * @type {ShaderBuilder}
  36. * @readonly
  37. *
  38. * @private
  39. */
  40. this.shaderBuilder = modelRenderResources.shaderBuilder.clone();
  41. /**
  42. * A dictionary mapping uniform name to functions that return the uniform
  43. * values. Inherited from the model render resources.
  44. *
  45. * @type {Object<string, Function>}
  46. * @readonly
  47. *
  48. * @private
  49. */
  50. this.uniformMap = clone(modelRenderResources.uniformMap);
  51. /**
  52. * Options for configuring the alpha stage such as pass and alpha cutoff.
  53. * Inherited from the model render resources.
  54. *
  55. * @type {ModelAlphaOptions}
  56. * @readonly
  57. *
  58. * @private
  59. */
  60. this.alphaOptions = clone(modelRenderResources.alphaOptions);
  61. /**
  62. * An object storing options for creating a {@link RenderState}.
  63. * The pipeline stages simply set the options, the render state is created
  64. * when the {@link DrawCommand} is constructed. Inherited from the model
  65. * render resources.
  66. *
  67. * @type {object}
  68. * @readonly
  69. *
  70. * @private
  71. */
  72. this.renderStateOptions = clone(
  73. modelRenderResources.renderStateOptions,
  74. true
  75. );
  76. /**
  77. * Whether the model has a silhouette. This value indicates what draw commands
  78. * are needed. Inherited from the model render resources.
  79. *
  80. * @type {boolean}
  81. * @readonly
  82. *
  83. * @private
  84. */
  85. this.hasSilhouette = modelRenderResources.hasSilhouette;
  86. /**
  87. * Whether the model is part of a tileset that uses the skipLevelOfDetail
  88. * optimization. This value indicates what draw commands are needed.
  89. * Inherited from the model render resources.
  90. *
  91. * @type {boolean}
  92. * @readonly
  93. *
  94. * @private
  95. */
  96. this.hasSkipLevelOfDetail = modelRenderResources.hasSkipLevelOfDetail;
  97. // Other properties.
  98. /**
  99. * A reference to the runtime node
  100. *
  101. * @type {ModelRuntimeNode}
  102. * @readonly
  103. *
  104. * @private
  105. */
  106. this.runtimeNode = runtimeNode;
  107. /**
  108. * An array of objects describing vertex attributes that will eventually
  109. * be used to create a {@link VertexArray} for the draw command. Attributes
  110. * at the node level may be needed for extensions such as EXT_mesh_gpu_instancing.
  111. *
  112. * @type {Object[]}
  113. * @readonly
  114. *
  115. * @private
  116. */
  117. this.attributes = [];
  118. /**
  119. * The index to give to the next vertex attribute added to the attributes array.
  120. * POSITION takes index 0.
  121. *
  122. * @type {number}
  123. *
  124. * @private
  125. */
  126. this.attributeIndex = 1;
  127. /**
  128. * The set index to assign to feature ID vertex attribute(s) created from the
  129. * offset/repeat in the feature ID attribute.
  130. *
  131. * @type {number}
  132. * @default 0
  133. *
  134. * @private
  135. */
  136. this.featureIdVertexAttributeSetIndex = 0;
  137. /**
  138. * The number of instances. This value is set by InstancingPipelineStage.
  139. *
  140. * @type {number}
  141. * @default 0
  142. *
  143. * @private
  144. */
  145. this.instanceCount = 0;
  146. }
  147. export default NodeRenderResources;