NodeRenderResources.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 {ModelExperimentalNode} runtimeNode The in-memory representation of the scene graph node.
  13. *
  14. * @private
  15. */
  16. export default 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 {ModelExperimental}
  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. *
  47. * @readonly
  48. *
  49. * @private
  50. */
  51. this.uniformMap = clone(modelRenderResources.uniformMap);
  52. /**
  53. * Options for configuring the alpha stage such as pass and alpha mode. Inherited from the model
  54. * render resources.
  55. *
  56. * @type {ModelAlphaOptions}
  57. * @readonly
  58. *
  59. * @private
  60. */
  61. this.alphaOptions = clone(modelRenderResources.alphaOptions);
  62. /**
  63. * An object storing options for creating a {@link RenderState}.
  64. * The pipeline stages simply set the options, the render state is created
  65. * when the {@link DrawCommand} is constructed. Inherited from the model
  66. * render resources.
  67. *
  68. * @type {Object}
  69. * @readonly
  70. *
  71. * @private
  72. */
  73. this.renderStateOptions = clone(modelRenderResources.renderStateOptions);
  74. // Other properties.
  75. /**
  76. * A reference to the runtime node
  77. *
  78. * @type {ModelExperimentalNode}
  79. * @readonly
  80. *
  81. * @private
  82. */
  83. this.runtimeNode = runtimeNode;
  84. /**
  85. * An array of objects describing vertex attributes that will eventually
  86. * be used to create a {@link VertexArray} for the draw command. Attributes
  87. * at the node level may be needed for extensions such as EXT_mesh_gpu_instancing.
  88. *
  89. * @type {Object[]}
  90. * @readonly
  91. *
  92. * @private
  93. */
  94. this.attributes = [];
  95. /**
  96. * The index to give to the next vertex attribute added to the attributes array. POSITION
  97. * takes index 0.
  98. *
  99. * @type {Number}
  100. * @readonly
  101. *
  102. * @private
  103. */
  104. this.attributeIndex = 1;
  105. /**
  106. * The set index to assign to feature ID vertex attribute(s) created from the offset/repeat in the feature ID attribute.
  107. *
  108. * @type {Number}
  109. * @readonly
  110. *
  111. * @private
  112. */
  113. this.featureIdVertexAttributeSetIndex = 0;
  114. /**
  115. * The number of instances. Default is 0, if instancing is not used.
  116. *
  117. * @type {Number}
  118. * @readonly
  119. *
  120. * @private
  121. */
  122. this.instanceCount = 0;
  123. /**
  124. * The component-wise maximum value of the translations of the instances.
  125. *
  126. * @type {Cartesian3}
  127. * @readonly
  128. *
  129. * @private
  130. */
  131. this.instancingTranslationMax = undefined;
  132. /**
  133. * The component-wise minimum value of the translations of the instances.
  134. *
  135. * @type {Cartesian3}
  136. * @readonly
  137. *
  138. * @private
  139. */
  140. this.instancingTranslationMin = undefined;
  141. }