InstancedMesh.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>InstancedMesh - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Object3D.html">Object3D</a> → <a href="Mesh.html">Mesh</a> → </p>
  13. <h1 translate="no">InstancedMesh</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>A special version of a mesh with instanced rendering support. Use
  17. this class if you have to render a large number of objects with the same
  18. geometry and material(s) but with different world transformations. The usage
  19. of 'InstancedMesh' will help you to reduce the number of draw calls and thus
  20. improve the overall rendering performance in your application.</p></div>
  21. </header>
  22. <article>
  23. <div class="container-overview">
  24. <h2>Constructor</h2>
  25. <h3 class="name name-method" id="InstancedMesh" translate="no">new <a href="#InstancedMesh">InstancedMesh</a><span class="signature">( geometry : <span class="param-type"><a href="BufferGeometry.html">BufferGeometry</a></span>, material : <span class="param-type"><a href="Material.html">Material</a> | Array.&lt;<a href="Material.html">Material</a>></span>, count : <span class="param-type">number</span> )</span> </h3>
  26. <div class="method">
  27. <div class="description">
  28. <p>Constructs a new instanced mesh.</p>
  29. </div>
  30. <table class="params">
  31. <tbody>
  32. <tr>
  33. <td class="name">
  34. <strong>geometry</strong>
  35. </td>
  36. <td class="description last">
  37. <p>The mesh geometry.</p>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td class="name">
  42. <strong>material</strong>
  43. </td>
  44. <td class="description last">
  45. <p>The mesh material.</p>
  46. </td>
  47. </tr>
  48. <tr>
  49. <td class="name">
  50. <strong>count</strong>
  51. </td>
  52. <td class="description last">
  53. <p>The number of instances.</p>
  54. </td>
  55. </tr>
  56. </tbody>
  57. </table>
  58. </div>
  59. </div>
  60. <h2 class="subsection-title">Properties</h2>
  61. <div class="member">
  62. <h3 class="name" id="boundingBox" translate="no">.<a href="#boundingBox">boundingBox</a><span class="type-signature"> : <a href="Box3.html">Box3</a></span> </h3>
  63. <div class="description">
  64. <p>The bounding box of the instanced mesh. Can be computed via <a href="InstancedMesh.html#computeBoundingBox">InstancedMesh#computeBoundingBox</a>.</p>
  65. <p>Default is <code>null</code>.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="boundingSphere" translate="no">.<a href="#boundingSphere">boundingSphere</a><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  70. <div class="description">
  71. <p>The bounding sphere of the instanced mesh. Can be computed via <a href="InstancedMesh.html#computeBoundingSphere">InstancedMesh#computeBoundingSphere</a>.</p>
  72. <p>Default is <code>null</code>.</p>
  73. </div>
  74. </div>
  75. <div class="member">
  76. <h3 class="name" id="count" translate="no">.<a href="#count">count</a><span class="type-signature"> : number</span> </h3>
  77. <div class="description">
  78. <p>The number of instances.</p>
  79. </div>
  80. <dl class="details">
  81. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Mesh.html#count">Mesh#count</a></dt>
  82. </dl>
  83. </div>
  84. <div class="member">
  85. <h3 class="name" id="instanceColor" translate="no">.<a href="#instanceColor">instanceColor</a><span class="type-signature"> : <a href="InstancedBufferAttribute.html">InstancedBufferAttribute</a></span> </h3>
  86. <div class="description">
  87. <p>Represents the color of all instances. You have to set its
  88. <a href="BufferAttribute.html#needsUpdate">BufferAttribute#needsUpdate</a> flag to true if you modify instanced data
  89. via <a href="InstancedMesh.html#setColorAt">InstancedMesh#setColorAt</a>.</p>
  90. <p>Default is <code>null</code>.</p>
  91. </div>
  92. </div>
  93. <div class="member">
  94. <h3 class="name" id="instanceMatrix" translate="no">.<a href="#instanceMatrix">instanceMatrix</a><span class="type-signature"> : <a href="InstancedBufferAttribute.html">InstancedBufferAttribute</a></span> </h3>
  95. <div class="description">
  96. <p>Represents the local transformation of all instances. You have to set its
  97. <a href="BufferAttribute.html#needsUpdate">BufferAttribute#needsUpdate</a> flag to true if you modify instanced data
  98. via <a href="InstancedMesh.html#setMatrixAt">InstancedMesh#setMatrixAt</a>.</p>
  99. </div>
  100. </div>
  101. <div class="member">
  102. <h3 class="name" id="isInstancedMesh" translate="no">.<a href="#isInstancedMesh">isInstancedMesh</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  103. <div class="description">
  104. <p>This flag can be used for type testing.</p>
  105. <p>Default is <code>true</code>.</p>
  106. </div>
  107. </div>
  108. <div class="member">
  109. <h3 class="name" id="morphTexture" translate="no">.<a href="#morphTexture">morphTexture</a><span class="type-signature"> : <a href="DataTexture.html">DataTexture</a></span> </h3>
  110. <div class="description">
  111. <p>Represents the morph target weights of all instances. You have to set its
  112. <a href="Texture.html#needsUpdate">Texture#needsUpdate</a> flag to true if you modify instanced data
  113. via <a href="InstancedMesh.html#setMorphAt">InstancedMesh#setMorphAt</a>.</p>
  114. <p>Default is <code>null</code>.</p>
  115. </div>
  116. </div>
  117. <div class="member">
  118. <h3 class="name" id="previousInstanceMatrix" translate="no">.<a href="#previousInstanceMatrix">previousInstanceMatrix</a><span class="type-signature"> : <a href="InstancedBufferAttribute.html">InstancedBufferAttribute</a></span> </h3>
  119. <div class="description">
  120. <p>Represents the local transformation of all instances of the previous frame.
  121. Required for computing velocity. Maintained in <a href="InstanceNode.html">InstanceNode</a>.</p>
  122. <p>Default is <code>null</code>.</p>
  123. </div>
  124. </div>
  125. <h2 class="subsection-title">Methods</h2>
  126. <h3 class="name name-method" id="computeBoundingBox" translate="no">.<a href="#computeBoundingBox">computeBoundingBox</a><span class="signature">()</span> </h3>
  127. <div class="method">
  128. <div class="description">
  129. <p>Computes the bounding box of the instanced mesh, and updates <a href="InstancedMesh.html#boundingBox">InstancedMesh#boundingBox</a>.
  130. The bounding box is not automatically computed by the engine; this method must be called by your app.
  131. You may need to recompute the bounding box if an instance is transformed via <a href="InstancedMesh.html#setMatrixAt">InstancedMesh#setMatrixAt</a>.</p>
  132. </div>
  133. </div>
  134. <h3 class="name name-method" id="computeBoundingSphere" translate="no">.<a href="#computeBoundingSphere">computeBoundingSphere</a><span class="signature">()</span> </h3>
  135. <div class="method">
  136. <div class="description">
  137. <p>Computes the bounding sphere of the instanced mesh, and updates <a href="InstancedMesh.html#boundingSphere">InstancedMesh#boundingSphere</a>
  138. The engine automatically computes the bounding sphere when it is needed, e.g., for ray casting or view frustum culling.
  139. You may need to recompute the bounding sphere if an instance is transformed via <a href="InstancedMesh.html#setMatrixAt">InstancedMesh#setMatrixAt</a>.</p>
  140. </div>
  141. </div>
  142. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  143. <div class="method">
  144. <div class="description">
  145. <p>Frees the GPU-related resources allocated by this instance. Call this
  146. method whenever this instance is no longer used in your app.</p>
  147. </div>
  148. </div>
  149. <h3 class="name name-method" id="getColorAt" translate="no">.<a href="#getColorAt">getColorAt</a><span class="signature">( index : <span class="param-type">number</span>, color : <span class="param-type"><a href="Color.html">Color</a></span> )</span> </h3>
  150. <div class="method">
  151. <div class="description">
  152. <p>Gets the color of the defined instance.</p>
  153. </div>
  154. <table class="params">
  155. <tbody>
  156. <tr>
  157. <td class="name">
  158. <strong>index</strong>
  159. </td>
  160. <td class="description last">
  161. <p>The instance index.</p>
  162. </td>
  163. </tr>
  164. <tr>
  165. <td class="name">
  166. <strong>color</strong>
  167. </td>
  168. <td class="description last">
  169. <p>The target object that is used to store the method's result.</p>
  170. </td>
  171. </tr>
  172. </tbody>
  173. </table>
  174. </div>
  175. <h3 class="name name-method" id="getMatrixAt" translate="no">.<a href="#getMatrixAt">getMatrixAt</a><span class="signature">( index : <span class="param-type">number</span>, matrix : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span> </h3>
  176. <div class="method">
  177. <div class="description">
  178. <p>Gets the local transformation matrix of the defined instance.</p>
  179. </div>
  180. <table class="params">
  181. <tbody>
  182. <tr>
  183. <td class="name">
  184. <strong>index</strong>
  185. </td>
  186. <td class="description last">
  187. <p>The instance index.</p>
  188. </td>
  189. </tr>
  190. <tr>
  191. <td class="name">
  192. <strong>matrix</strong>
  193. </td>
  194. <td class="description last">
  195. <p>The target object that is used to store the method's result.</p>
  196. </td>
  197. </tr>
  198. </tbody>
  199. </table>
  200. </div>
  201. <h3 class="name name-method" id="getMorphAt" translate="no">.<a href="#getMorphAt">getMorphAt</a><span class="signature">( index : <span class="param-type">number</span>, object : <span class="param-type"><a href="Mesh.html">Mesh</a></span> )</span> </h3>
  202. <div class="method">
  203. <div class="description">
  204. <p>Gets the morph target weights of the defined instance.</p>
  205. </div>
  206. <table class="params">
  207. <tbody>
  208. <tr>
  209. <td class="name">
  210. <strong>index</strong>
  211. </td>
  212. <td class="description last">
  213. <p>The instance index.</p>
  214. </td>
  215. </tr>
  216. <tr>
  217. <td class="name">
  218. <strong>object</strong>
  219. </td>
  220. <td class="description last">
  221. <p>The target object that is used to store the method's result.</p>
  222. </td>
  223. </tr>
  224. </tbody>
  225. </table>
  226. </div>
  227. <h3 class="name name-method" id="setColorAt" translate="no">.<a href="#setColorAt">setColorAt</a><span class="signature">( index : <span class="param-type">number</span>, color : <span class="param-type"><a href="Color.html">Color</a></span> )</span> </h3>
  228. <div class="method">
  229. <div class="description">
  230. <p>Sets the given color to the defined instance. Make sure you set the <code>needsUpdate</code> flag of
  231. <a href="InstancedMesh.html#instanceColor">InstancedMesh#instanceColor</a> to <code>true</code> after updating all the colors.</p>
  232. </div>
  233. <table class="params">
  234. <tbody>
  235. <tr>
  236. <td class="name">
  237. <strong>index</strong>
  238. </td>
  239. <td class="description last">
  240. <p>The instance index.</p>
  241. </td>
  242. </tr>
  243. <tr>
  244. <td class="name">
  245. <strong>color</strong>
  246. </td>
  247. <td class="description last">
  248. <p>The instance color.</p>
  249. </td>
  250. </tr>
  251. </tbody>
  252. </table>
  253. </div>
  254. <h3 class="name name-method" id="setMatrixAt" translate="no">.<a href="#setMatrixAt">setMatrixAt</a><span class="signature">( index : <span class="param-type">number</span>, matrix : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span> </h3>
  255. <div class="method">
  256. <div class="description">
  257. <p>Sets the given local transformation matrix to the defined instance. Make sure you set the <code>needsUpdate</code> flag of
  258. <a href="InstancedMesh.html#instanceMatrix">InstancedMesh#instanceMatrix</a> to <code>true</code> after updating all the colors.</p>
  259. </div>
  260. <table class="params">
  261. <tbody>
  262. <tr>
  263. <td class="name">
  264. <strong>index</strong>
  265. </td>
  266. <td class="description last">
  267. <p>The instance index.</p>
  268. </td>
  269. </tr>
  270. <tr>
  271. <td class="name">
  272. <strong>matrix</strong>
  273. </td>
  274. <td class="description last">
  275. <p>The local transformation.</p>
  276. </td>
  277. </tr>
  278. </tbody>
  279. </table>
  280. </div>
  281. <h3 class="name name-method" id="setMorphAt" translate="no">.<a href="#setMorphAt">setMorphAt</a><span class="signature">( index : <span class="param-type">number</span>, object : <span class="param-type"><a href="Mesh.html">Mesh</a></span> )</span> </h3>
  282. <div class="method">
  283. <div class="description">
  284. <p>Sets the morph target weights to the defined instance. Make sure you set the <code>needsUpdate</code> flag of
  285. <a href="InstancedMesh.html#morphTexture">InstancedMesh#morphTexture</a> to <code>true</code> after updating all the influences.</p>
  286. </div>
  287. <table class="params">
  288. <tbody>
  289. <tr>
  290. <td class="name">
  291. <strong>index</strong>
  292. </td>
  293. <td class="description last">
  294. <p>The instance index.</p>
  295. </td>
  296. </tr>
  297. <tr>
  298. <td class="name">
  299. <strong>object</strong>
  300. </td>
  301. <td class="description last">
  302. <p>A mesh which <code>morphTargetInfluences</code> property containing the morph target weights
  303. of a single instance.</p>
  304. </td>
  305. </tr>
  306. </tbody>
  307. </table>
  308. </div>
  309. <h2 class="subsection-title">Source</h2>
  310. <p>
  311. <a href="https://github.com/mrdoob/three.js/blob/master/src/objects/InstancedMesh.js" translate="no" target="_blank" rel="noopener">src/objects/InstancedMesh.js</a>
  312. </p>
  313. </article>
  314. </section>
  315. <script src="../scripts/linenumber.js"></script>
  316. <script src="../scripts/page.js"></script>
  317. </body>
  318. </html>
粤ICP备19079148号