BatchedMesh.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Mesh] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. A special version of [page:Mesh] with multi draw batch rendering support. Use
  14. [name] if you have to render a large number of objects with the same
  15. material but with different world transformations and geometry. The usage
  16. of [name] will help you to reduce the number of draw calls and thus
  17. improve the overall rendering performance in your application.
  18. <br/>
  19. <br/>
  20. If the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension] is
  21. not supported then a less performant callback is used.
  22. </p>
  23. <h2>Code Example</h2>
  24. <code>
  25. const box = new THREE.BoxGeometry( 1, 1, 1 );
  26. const sphere = new THREE.BoxGeometry( 1, 1, 1 );
  27. const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
  28. // initialize and add geometries into the batched mesh
  29. const batchedMesh = new BatchedMesh( 10, 5000, 10000, material );
  30. const boxId = batchedMesh.addGeometry( box );
  31. const sphereId = batchedMesh.addGeometry( sphere );
  32. // position the geometries
  33. batchedMesh.setMatrixAt( boxId, boxMatrix );
  34. batchedMesh.setMatrixAt( sphereId, sphereMatrix );
  35. scene.add( batchedMesh );
  36. </code>
  37. <h2>Examples</h2>
  38. <p>
  39. [example:webgl_mesh_batch WebGL / mesh / batch]<br />
  40. </p>
  41. <h2>Constructor</h2>
  42. <h3>
  43. [name](
  44. [param:Integer maxGeometryCount], [param:Integer maxVertexCount],
  45. [param:Integer maxIndexCount], [param:Material material],
  46. )
  47. </h3>
  48. <p>
  49. [page:Integer maxGeometryCount] - the max number of individual geometries planned to be added.<br />
  50. [page:Integer maxVertexCount] - the max number of vertices to be used by all geometries.<br />
  51. [page:Integer maxIndexCount] - the max number of indices to be used by all geometries.<br />
  52. [page:Material material] - an instance of [page:Material]. Default is a
  53. new [page:MeshBasicMaterial].<br />
  54. </p>
  55. <h2>Properties</h2>
  56. <p>See the base [page:Mesh] class for common properties.</p>
  57. <h3>[property:Box3 boundingBox]</h3>
  58. <p>
  59. This bounding box encloses all instances of the [name]. Can be calculated
  60. with [page:.computeBoundingBox](). Default is `null`.
  61. </p>
  62. <h3>[property:Sphere boundingSphere]</h3>
  63. <p>
  64. This bounding sphere encloses all instances of the [name]. Can be
  65. calculated with [page:.computeBoundingSphere](). Default is `null`.
  66. </p>
  67. <h3>[property:Boolean perObjectFrustumCulled]</h3>
  68. <p>
  69. If true then the individual objects within the [name] are frustum culled. Default is `true`.
  70. </p>
  71. <h3>[property:Boolean sortObjects]</h3>
  72. <p>
  73. If true then the individual objects within the [name] are sorted to improve overdraw-related artifacts.
  74. If the material is marked as "transparent" objects are rendered back to front and if not then they are
  75. rendered front to back. Default is `true`.
  76. </p>
  77. <h3>[property:Integer maxGeometryCount]</h3>
  78. <p>
  79. The maximum number of individual geometries that can be stored in the [name]. Read only.
  80. </p>
  81. <h3>[property:Boolean isBatchedMesh]</h3>
  82. <p>Read-only flag to check if a given object is of type [name].</p>
  83. <h2>Methods</h2>
  84. <p>See the base [page:Mesh] class for common methods.</p>
  85. <h3>[method:undefined computeBoundingBox]()</h3>
  86. <p>
  87. Computes the bounding box, updating [page:.boundingBox] attribute.<br />
  88. Bounding boxes aren't computed by default. They need to be explicitly
  89. computed, otherwise they are `null`.
  90. </p>
  91. <h3>[method:undefined computeBoundingSphere]()</h3>
  92. <p>
  93. Computes the bounding sphere, updating [page:.boundingSphere]
  94. attribute.<br />
  95. Bounding spheres aren't computed by default. They need to be explicitly
  96. computed, otherwise they are `null`.
  97. </p>
  98. <h3>[method:undefined dispose]()</h3>
  99. <p>
  100. Frees the GPU-related resources allocated by this instance. Call this
  101. method whenever this instance is no longer used in your app.
  102. </p>
  103. <h3>[method:this setCustomSort]( [param:Function sortFunction] )</h3>
  104. <p>
  105. Takes a sort a function that is run before render. The function takes a list of items to sort and a camera. The objects
  106. in the list include a "z" field to perform a depth-ordered sort with.
  107. </p>
  108. <h3>
  109. [method:undefined getColorAt]( [param:Integer index], [param:Color color] )
  110. </h3>
  111. <p>
  112. [page:Integer index]: The index of a geometry. Values have to be in the
  113. range [0, count].
  114. </p>
  115. <p>
  116. [page:Color color]: This color object will be set to the color of the
  117. defined geometry.
  118. </p>
  119. <p>Get the color of the defined geometry.</p>
  120. <h3>
  121. [method:Matrix4 getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )
  122. </h3>
  123. <p>
  124. [page:Integer index]: The index of an instance. Values have to be in the
  125. range [0, count].
  126. </p>
  127. <p>
  128. [page:Matrix4 matrix]: This 4x4 matrix will be set to the local
  129. transformation matrix of the defined instance.
  130. </p>
  131. <p>Get the local transformation matrix of the defined instance.</p>
  132. <h3>
  133. [method:Boolean getVisibleAt]( [param:Integer index] )
  134. </h3>
  135. <p>
  136. [page:Integer index]: The index of an instance. Values have to be in the
  137. range [0, count].
  138. </p>
  139. <p>Get whether the given instance is marked as "visible" or not.</p>
  140. <h3>
  141. [method:undefined setColorAt]( [param:Integer index], [param:Color color] )
  142. </h3>
  143. <p>
  144. [page:Integer index]: The index of a geometry. Values have to be in the
  145. range [0, count].
  146. </p>
  147. <p>[page:Color color]: The color of a single geometry.</p>
  148. <p>
  149. Sets the given color to the defined geometry.
  150. </p>
  151. <h3>
  152. [method:this setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )
  153. </h3>
  154. <p>
  155. [page:Integer index]: The index of an instance. Values have to be in the
  156. range [0, count].
  157. </p>
  158. <p>
  159. [page:Matrix4 matrix]: A 4x4 matrix representing the local transformation
  160. of a single instance.
  161. </p>
  162. <p>
  163. Sets the given local transformation matrix to the defined instance.
  164. </p>
  165. <h3>
  166. [method:this setVisibleAt]( [param:Integer index], [param:Boolean visible] )
  167. </h3>
  168. <p>
  169. [page:Integer index]: The index of an instance. Values have to be in the
  170. range [0, count].
  171. </p>
  172. <p>
  173. [page:Boolean visible]: A boolean value indicating the visibility state.
  174. </p>
  175. <p>
  176. Sets the visibility of the object at the given index.
  177. </p>
  178. <h3>
  179. [method:Integer addGeometry]( [param:BufferGeometry geometry], [param:Integer reservedVertexRange], [param:Integer reservedIndexRange] )
  180. </h3>
  181. <p>
  182. [page:BufferGeometry geometry]: The geometry to add into the [name].
  183. </p>
  184. <p>
  185. [page:Integer reservedVertexRange]: Optional parameter specifying the amount of vertex buffer space to reserve for the added geometry. This
  186. is necessary if it is planned to set a new geometry at this index at a later time that is larger than the original geometry. Defaults to
  187. the length of the given geometry vertex buffer.
  188. </p>
  189. <p>
  190. [page:Integer reservedIndexRange]: Optional parameter specifying the amount of index buffer space to reserve for the added geometry. This
  191. is necessary if it is planned to set a new geometry at this index at a later time that is larger than the original geometry. Defaults to
  192. the length of the given geometry index buffer.
  193. </p>
  194. <p>
  195. Adds the given geometry to the [name] and returns the associated index referring to it.
  196. </p>
  197. <h3>
  198. [method:Integer setGeometryAt]( [param:Integer index], [param:BufferGeometry geometry] )
  199. </h3>
  200. <p>
  201. [page:Integer index]: Which geometry index to replace with this geometry.
  202. </p>
  203. <p>
  204. [page:BufferGeometry geometry]: The geometry to substitute at the given geometry index.
  205. </p>
  206. <p>
  207. Replaces the geometry at `index` with the provided geometry. Throws an error if there is not enough space reserved for geometry at the index.
  208. </p>
  209. <h3>
  210. [method:Integer getInstanceCountAt]( [param:Integer index] )
  211. </h3>
  212. <p>
  213. [page:Integer index]: The index of an instance. Values have to be in the
  214. range [0, count].
  215. </p>
  216. <p>
  217. Gets the instance count of the geometry at `index`. Returns `null` if instance counts are not configured.
  218. </p>
  219. <h3>
  220. [method:Integer setInstanceCountAt]( [param:Integer index], [param:Integer instanceCount ] )
  221. </h3>
  222. <p>
  223. [page:Integer index]: Which geometry index to configure an instance count for.
  224. </p>
  225. <p>
  226. [page:Integer instanceCount]: The number of instances to render of the given geometry index.
  227. </p>
  228. <p>
  229. Sets an instance count of the geometry at `index`.
  230. </p>
  231. <h2>Source</h2>
  232. <p>
  233. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  234. </p>
  235. </body>
  236. </html>