InstancedMesh.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 instanced rendering support. Use
  14. [name] if you have to render a large number of objects with the same
  15. geometry and material(s) but with different world transformations. 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. </p>
  19. <h2>Examples</h2>
  20. <p>
  21. [example:webgl_instancing_dynamic WebGL / instancing / dynamic]<br />
  22. [example:webgl_instancing_performance WebGL / instancing / performance]<br />
  23. [example:webgl_instancing_scatter WebGL / instancing / scatter]<br />
  24. [example:webgl_instancing_raycast WebGL / instancing / raycast]
  25. </p>
  26. <h2>Constructor</h2>
  27. <h3>
  28. [name]( [param:BufferGeometry geometry], [param:Material material],
  29. [param:Integer count] )
  30. </h3>
  31. <p>
  32. [page:BufferGeometry geometry] - an instance of [page:BufferGeometry].<br />
  33. [page:Material material] — a single or an array of
  34. [page:Material]. Default is a new [page:MeshBasicMaterial].<br />
  35. [page:Integer count] - the number of instances.<br />
  36. </p>
  37. <h2>Properties</h2>
  38. <p>See the base [page:Mesh] class for common properties.</p>
  39. <h3>[property:Box3 boundingBox]</h3>
  40. <p>
  41. This bounding box encloses all instances of the [name]. Can be calculated
  42. with [page:.computeBoundingBox](). Default is `null`.
  43. </p>
  44. <h3>[property:Sphere boundingSphere]</h3>
  45. <p>
  46. This bounding sphere encloses all instances of the [name]. Can be
  47. calculated with [page:.computeBoundingSphere](). Default is `null`.
  48. </p>
  49. <h3>[property:Integer count]</h3>
  50. <p>
  51. The number of instances. The `count` value passed into the constructor
  52. represents the maximum number of instances of this mesh. You can change
  53. the number of instances at runtime to an integer value in the range [0, count].
  54. </p>
  55. <p>
  56. If you need more instances than the original count value, you have to
  57. create a new [name].
  58. </p>
  59. <h3>[property:InstancedBufferAttribute instanceColor]</h3>
  60. <p>
  61. Represents the colors of all instances. `null` by default. You have to set
  62. its [page:BufferAttribute.needsUpdate needsUpdate] flag to true if you
  63. modify instanced data via [page:.setColorAt]().
  64. </p>
  65. <h3>[property:InstancedBufferAttribute instanceMatrix]</h3>
  66. <p>
  67. Represents the local transformation of all instances. You have to set its
  68. [page:BufferAttribute.needsUpdate needsUpdate] flag to true if you modify
  69. instanced data via [page:.setMatrixAt]().
  70. </p>
  71. <h3>[property:DataTexture morphTexture]</h3>
  72. <p>
  73. Represents the morph target weights of all instances. You have to set its
  74. [page:Texture.needsUpdate needsUpdate] flag to true if you modify
  75. instanced data via [page:.setMorphAt]().
  76. </p>
  77. <h3>[property:Boolean isInstancedMesh]</h3>
  78. <p>Read-only flag to check if a given object is of type [name].</p>
  79. <h2>Methods</h2>
  80. <p>See the base [page:Mesh] class for common methods.</p>
  81. <h3>[method:undefined computeBoundingBox]()</h3>
  82. <p>
  83. Computes the bounding box of the instanced mesh, and updates the [page:.boundingBox] attribute.
  84. The bounding box is not computed by the engine; it must be computed by your app.
  85. You may need to recompute the bounding box if an instance is transformed via [page:.setMatrixAt]().
  86. </p>
  87. <h3>[method:undefined computeBoundingSphere]()</h3>
  88. <p>
  89. Computes the bounding sphere of the instanced mesh, and updates the [page:.boundingSphere] attribute.
  90. The engine automatically computes the bounding sphere when it is needed, e.g., for ray casting or view frustum culling.
  91. You may need to recompute the bounding sphere if an instance is transformed via [page:.setMatrixAt]().
  92. </p>
  93. <h3>[method:undefined dispose]()</h3>
  94. <p>
  95. Frees the GPU-related resources allocated by this instance. Call this
  96. method whenever this instance is no longer used in your app.
  97. </p>
  98. <h3>
  99. [method:undefined getColorAt]( [param:Integer index], [param:Color color] )
  100. </h3>
  101. <p>
  102. [page:Integer index]: The index of an instance. Values have to be in the
  103. range [0, count].
  104. </p>
  105. <p>
  106. [page:Color color]: This color object will be set to the color of the
  107. defined instance.
  108. </p>
  109. <p>Get the color of the defined instance.</p>
  110. <h3>
  111. [method:undefined getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )
  112. </h3>
  113. <p>
  114. [page:Integer index]: The index of an instance. Values have to be in the
  115. range [0, count].
  116. </p>
  117. <p>
  118. [page:Matrix4 matrix]: This 4x4 matrix will be set to the local
  119. transformation matrix of the defined instance.
  120. </p>
  121. <p>Get the local transformation matrix of the defined instance.</p>
  122. <h3>
  123. [method:undefined getMorphAt]( [param:Integer index], [param:Mesh mesh] )
  124. </h3>
  125. <p>
  126. [page:Integer index]: The index of an instance. Values have to be in the
  127. range [0, count].
  128. </p>
  129. <p>
  130. [page:Mesh mesh]: The [page:Mesh.morphTargetInfluences .morphTargetInfluences] property of this mesh will be filled with the morph target weights of the defined instance.
  131. </p>
  132. <p>Get the morph target weights of the defined instance.</p>
  133. <h3>
  134. [method:undefined setColorAt]( [param:Integer index], [param:Color color] )
  135. </h3>
  136. <p>
  137. [page:Integer index]: The index of an instance. Values have to be in the
  138. range [0, count].
  139. </p>
  140. <p>[page:Color color]: The color of a single instance.</p>
  141. <p>
  142. Sets the given color to the defined instance. Make sure you set
  143. [page:.instanceColor][page:BufferAttribute.needsUpdate .needsUpdate] to
  144. true after updating all the colors.
  145. </p>
  146. <h3>
  147. [method:undefined setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )
  148. </h3>
  149. <p>
  150. [page:Integer index]: The index of an instance. Values have to be in the
  151. range [0, count].
  152. </p>
  153. <p>
  154. [page:Matrix4 matrix]: A 4x4 matrix representing the local transformation
  155. of a single instance.
  156. </p>
  157. <p>
  158. Sets the given local transformation matrix to the defined instance. Make
  159. sure you set [page:.instanceMatrix][page:BufferAttribute.needsUpdate .needsUpdate]
  160. to true after updating all the matrices.
  161. </p>
  162. <h3>
  163. [method:undefined setMorphAt]( [param:Integer index], [param:Mesh mesh] )
  164. </h3>
  165. <p>
  166. [page:Integer index]: The index of an instance. Values have to be in the
  167. range [0, count].
  168. </p>
  169. <p>
  170. [page:Mesh mesh]: A mesh with [page:Mesh.morphTargetInfluences .morphTargetInfluences] property containing the morph target weights
  171. of a single instance.
  172. </p>
  173. <p>
  174. Sets the morph target weights to the defined instance. Make
  175. sure you set [page:.morphTexture][page:Texture.needsUpdate .needsUpdate]
  176. to true after updating all the influences.
  177. </p>
  178. <h2>Source</h2>
  179. <p>
  180. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  181. </p>
  182. </body>
  183. </html>