BatchedMesh.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>BatchedMesh - 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">BatchedMesh</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>A special version of a mesh with multi draw batch rendering support. Use
  17. this class if you have to render a large number of objects with the same
  18. material but with different geometries or world transformations. The usage of
  19. <code>BatchedMesh</code> will help you to reduce the number of draw calls and thus improve the overall
  20. rendering performance in your application.</p></div>
  21. <h2>Code Example</h2>
  22. <div translate="no"><pre><code class="language-js">const box = new THREE.BoxGeometry( 1, 1, 1 );
  23. const sphere = new THREE.SphereGeometry( 1, 12, 12 );
  24. const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
  25. // initialize and add geometries into the batched mesh
  26. const batchedMesh = new BatchedMesh( 10, 5000, 10000, material );
  27. const boxGeometryId = batchedMesh.addGeometry( box );
  28. const sphereGeometryId = batchedMesh.addGeometry( sphere );
  29. // create instances of those geometries
  30. const boxInstancedId1 = batchedMesh.addInstance( boxGeometryId );
  31. const boxInstancedId2 = batchedMesh.addInstance( boxGeometryId );
  32. const sphereInstancedId1 = batchedMesh.addInstance( sphereGeometryId );
  33. const sphereInstancedId2 = batchedMesh.addInstance( sphereGeometryId );
  34. // position the geometries
  35. batchedMesh.setMatrixAt( boxInstancedId1, boxMatrix1 );
  36. batchedMesh.setMatrixAt( boxInstancedId2, boxMatrix2 );
  37. batchedMesh.setMatrixAt( sphereInstancedId1, sphereMatrix1 );
  38. batchedMesh.setMatrixAt( sphereInstancedId2, sphereMatrix2 );
  39. scene.add( batchedMesh );
  40. </code></pre></div>
  41. </header>
  42. <article>
  43. <div class="container-overview">
  44. <h2>Constructor</h2>
  45. <h3 class="name name-method" id="BatchedMesh" translate="no">new <a href="#BatchedMesh">BatchedMesh</a><span class="signature">( maxInstanceCount : <span class="param-type">number</span>, maxVertexCount : <span class="param-type">number</span>, maxIndexCount : <span class="param-type">number</span>, material : <span class="param-type"><a href="Material.html">Material</a> | Array.&lt;<a href="Material.html">Material</a>></span> )</span> </h3>
  46. <div class="method">
  47. <div class="description">
  48. <p>Constructs a new batched mesh.</p>
  49. </div>
  50. <table class="params">
  51. <tbody>
  52. <tr>
  53. <td class="name">
  54. <strong>maxInstanceCount</strong>
  55. </td>
  56. <td class="description last">
  57. <p>The maximum number of individual instances planned to be added and rendered.</p>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td class="name">
  62. <strong>maxVertexCount</strong>
  63. </td>
  64. <td class="description last">
  65. <p>The maximum number of vertices to be used by all unique geometries.</p>
  66. </td>
  67. </tr>
  68. <tr>
  69. <td class="name">
  70. <strong>maxIndexCount</strong>
  71. </td>
  72. <td class="description last">
  73. <p>The maximum number of indices to be used by all unique geometries</p>
  74. <p>Default is <code>maxVertexCount*2</code>.</p>
  75. </td>
  76. </tr>
  77. <tr>
  78. <td class="name">
  79. <strong>material</strong>
  80. </td>
  81. <td class="description last">
  82. <p>The mesh material.</p>
  83. </td>
  84. </tr>
  85. </tbody>
  86. </table>
  87. </div>
  88. </div>
  89. <h2 class="subsection-title">Properties</h2>
  90. <div class="member">
  91. <h3 class="name" id="boundingBox" translate="no">.<a href="#boundingBox">boundingBox</a><span class="type-signature"> : <a href="Box3.html">Box3</a></span> </h3>
  92. <div class="description">
  93. <p>The bounding box of the batched mesh. Can be computed via <a href="BatchedMesh.html#computeBoundingBox">BatchedMesh#computeBoundingBox</a>.</p>
  94. <p>Default is <code>null</code>.</p>
  95. </div>
  96. </div>
  97. <div class="member">
  98. <h3 class="name" id="boundingSphere" translate="no">.<a href="#boundingSphere">boundingSphere</a><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  99. <div class="description">
  100. <p>The bounding sphere of the batched mesh. Can be computed via <a href="BatchedMesh.html#computeBoundingSphere">BatchedMesh#computeBoundingSphere</a>.</p>
  101. <p>Default is <code>null</code>.</p>
  102. </div>
  103. </div>
  104. <div class="member">
  105. <h3 class="name" id="customSort" translate="no">.<a href="#customSort">customSort</a><span class="type-signature"> : function</span> </h3>
  106. <div class="description">
  107. <p>Takes a sort a function that is run before render. The function takes a list of instances to
  108. sort and a camera. The objects in the list include a &quot;z&quot; field to perform a depth-ordered
  109. sort with.</p>
  110. <p>Default is <code>null</code>.</p>
  111. </div>
  112. </div>
  113. <div class="member">
  114. <h3 class="name" id="instanceCount" translate="no">.<a href="#instanceCount">instanceCount</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  115. <div class="description">
  116. <p>The instance count.</p>
  117. </div>
  118. </div>
  119. <div class="member">
  120. <h3 class="name" id="isBatchedMesh" translate="no">.<a href="#isBatchedMesh">isBatchedMesh</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  121. <div class="description">
  122. <p>This flag can be used for type testing.</p>
  123. <p>Default is <code>true</code>.</p>
  124. </div>
  125. </div>
  126. <div class="member">
  127. <h3 class="name" id="maxInstanceCount" translate="no">.<a href="#maxInstanceCount">maxInstanceCount</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  128. <div class="description">
  129. <p>The maximum number of individual instances that can be stored in the batch.</p>
  130. </div>
  131. </div>
  132. <div class="member">
  133. <h3 class="name" id="perObjectFrustumCulled" translate="no">.<a href="#perObjectFrustumCulled">perObjectFrustumCulled</a><span class="type-signature"> : boolean</span> </h3>
  134. <div class="description">
  135. <p>When set ot <code>true</code>, the individual objects of a batch are frustum culled.</p>
  136. <p>Default is <code>true</code>.</p>
  137. </div>
  138. </div>
  139. <div class="member">
  140. <h3 class="name" id="sortObjects" translate="no">.<a href="#sortObjects">sortObjects</a><span class="type-signature"> : boolean</span> </h3>
  141. <div class="description">
  142. <p>When set to <code>true</code>, the individual objects of a batch are sorted to improve overdraw-related artifacts.
  143. If the material is marked as &quot;transparent&quot; objects are rendered back to front and if not then they are
  144. rendered front to back.</p>
  145. <p>Default is <code>true</code>.</p>
  146. </div>
  147. </div>
  148. <div class="member">
  149. <h3 class="name" id="unusedIndexCount" translate="no">.<a href="#unusedIndexCount">unusedIndexCount</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  150. <div class="description">
  151. <p>The number of unused indices.</p>
  152. </div>
  153. </div>
  154. <div class="member">
  155. <h3 class="name" id="unusedVertexCount" translate="no">.<a href="#unusedVertexCount">unusedVertexCount</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  156. <div class="description">
  157. <p>The number of unused vertices.</p>
  158. </div>
  159. </div>
  160. <h2 class="subsection-title">Methods</h2>
  161. <h3 class="name name-method" id="addGeometry" translate="no">.<a href="#addGeometry">addGeometry</a><span class="signature">( geometry : <span class="param-type"><a href="BufferGeometry.html">BufferGeometry</a></span>, reservedVertexCount : <span class="param-type">number</span>, reservedIndexCount : <span class="param-type">number</span> )</span><span class="type-signature"> : number</span> </h3>
  162. <div class="method">
  163. <div class="description">
  164. <p>Adds the given geometry to the batch and returns the associated
  165. geometry id referring to it to be used in other functions.</p>
  166. </div>
  167. <table class="params">
  168. <tbody>
  169. <tr>
  170. <td class="name">
  171. <strong>geometry</strong>
  172. </td>
  173. <td class="description last">
  174. <p>The geometry to add.</p>
  175. </td>
  176. </tr>
  177. <tr>
  178. <td class="name">
  179. <strong>reservedVertexCount</strong>
  180. </td>
  181. <td class="description last">
  182. <p>Optional parameter specifying the amount of
  183. vertex buffer space to reserve for the added geometry. This is necessary if it is planned
  184. to set a new geometry at this index at a later time that is larger than the original geometry.
  185. Defaults to the length of the given geometry vertex buffer.</p>
  186. <p>Default is <code>-1</code>.</p>
  187. </td>
  188. </tr>
  189. <tr>
  190. <td class="name">
  191. <strong>reservedIndexCount</strong>
  192. </td>
  193. <td class="description last">
  194. <p>Optional parameter specifying the amount of index
  195. buffer space to reserve for the added geometry. This is necessary if it is planned to set a
  196. new geometry at this index at a later time that is larger than the original geometry. Defaults to
  197. the length of the given geometry index buffer.</p>
  198. <p>Default is <code>-1</code>.</p>
  199. </td>
  200. </tr>
  201. </tbody>
  202. </table>
  203. <dl class="details">
  204. <dt class="tag-returns"><strong>Returns:</strong> The geometry ID.</dt>
  205. </dl>
  206. </div>
  207. <h3 class="name name-method" id="addInstance" translate="no">.<a href="#addInstance">addInstance</a><span class="signature">( geometryId : <span class="param-type">number</span> )</span><span class="type-signature"> : number</span> </h3>
  208. <div class="method">
  209. <div class="description">
  210. <p>Adds a new instance to the batch using the geometry of the given ID and returns
  211. a new id referring to the new instance to be used by other functions.</p>
  212. </div>
  213. <table class="params">
  214. <tbody>
  215. <tr>
  216. <td class="name">
  217. <strong>geometryId</strong>
  218. </td>
  219. <td class="description last">
  220. <p>The ID of a previously added geometry via <a href="BatchedMesh.html#addGeometry">BatchedMesh#addGeometry</a>.</p>
  221. </td>
  222. </tr>
  223. </tbody>
  224. </table>
  225. <dl class="details">
  226. <dt class="tag-returns"><strong>Returns:</strong> The instance ID.</dt>
  227. </dl>
  228. </div>
  229. <h3 class="name name-method" id="computeBoundingBox" translate="no">.<a href="#computeBoundingBox">computeBoundingBox</a><span class="signature">()</span> </h3>
  230. <div class="method">
  231. <div class="description">
  232. <p>Computes the bounding box, updating <a href="BatchedMesh.html#boundingBox">BatchedMesh#boundingBox</a>.
  233. Bounding boxes aren't computed by default. They need to be explicitly computed,
  234. otherwise they are <code>null</code>.</p>
  235. </div>
  236. </div>
  237. <h3 class="name name-method" id="computeBoundingSphere" translate="no">.<a href="#computeBoundingSphere">computeBoundingSphere</a><span class="signature">()</span> </h3>
  238. <div class="method">
  239. <div class="description">
  240. <p>Computes the bounding sphere, updating <a href="BatchedMesh.html#boundingSphere">BatchedMesh#boundingSphere</a>.
  241. Bounding spheres aren't computed by default. They need to be explicitly computed,
  242. otherwise they are <code>null</code>.</p>
  243. </div>
  244. </div>
  245. <h3 class="name name-method" id="deleteGeometry" translate="no">.<a href="#deleteGeometry">deleteGeometry</a><span class="signature">( geometryId : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  246. <div class="method">
  247. <div class="description">
  248. <p>Deletes the geometry defined by the given ID from this batch. Any instances referencing
  249. this geometry will also be removed as a side effect.</p>
  250. </div>
  251. <table class="params">
  252. <tbody>
  253. <tr>
  254. <td class="name">
  255. <strong>geometryId</strong>
  256. </td>
  257. <td class="description last">
  258. <p>The ID of the geometry to remove from the batch.</p>
  259. </td>
  260. </tr>
  261. </tbody>
  262. </table>
  263. <dl class="details">
  264. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  265. </dl>
  266. </div>
  267. <h3 class="name name-method" id="deleteInstance" translate="no">.<a href="#deleteInstance">deleteInstance</a><span class="signature">( instanceId : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  268. <div class="method">
  269. <div class="description">
  270. <p>Deletes an existing instance from the batch using the given ID.</p>
  271. </div>
  272. <table class="params">
  273. <tbody>
  274. <tr>
  275. <td class="name">
  276. <strong>instanceId</strong>
  277. </td>
  278. <td class="description last">
  279. <p>The ID of the instance to remove from the batch.</p>
  280. </td>
  281. </tr>
  282. </tbody>
  283. </table>
  284. <dl class="details">
  285. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  286. </dl>
  287. </div>
  288. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  289. <div class="method">
  290. <div class="description">
  291. <p>Frees the GPU-related resources allocated by this instance. Call this
  292. method whenever this instance is no longer used in your app.</p>
  293. </div>
  294. </div>
  295. <h3 class="name name-method" id="getBoundingBoxAt" translate="no">.<a href="#getBoundingBoxAt">getBoundingBoxAt</a><span class="signature">( geometryId : <span class="param-type">number</span>, target : <span class="param-type"><a href="Box3.html">Box3</a></span> )</span><span class="type-signature"> : <a href="Box3.html">Box3</a></span> </h3>
  296. <div class="method">
  297. <div class="description">
  298. <p>Returns the bounding box for the given geometry.</p>
  299. </div>
  300. <table class="params">
  301. <tbody>
  302. <tr>
  303. <td class="name">
  304. <strong>geometryId</strong>
  305. </td>
  306. <td class="description last">
  307. <p>The ID of the geometry to return the bounding box for.</p>
  308. </td>
  309. </tr>
  310. <tr>
  311. <td class="name">
  312. <strong>target</strong>
  313. </td>
  314. <td class="description last">
  315. <p>The target object that is used to store the method's result.</p>
  316. </td>
  317. </tr>
  318. </tbody>
  319. </table>
  320. <dl class="details">
  321. <dt class="tag-returns"><strong>Returns:</strong> The geometry's bounding box. Returns <code>null</code> if no geometry has been found for the given ID.</dt>
  322. </dl>
  323. </div>
  324. <h3 class="name name-method" id="getBoundingSphereAt" translate="no">.<a href="#getBoundingSphereAt">getBoundingSphereAt</a><span class="signature">( geometryId : <span class="param-type">number</span>, target : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  325. <div class="method">
  326. <div class="description">
  327. <p>Returns the bounding sphere for the given geometry.</p>
  328. </div>
  329. <table class="params">
  330. <tbody>
  331. <tr>
  332. <td class="name">
  333. <strong>geometryId</strong>
  334. </td>
  335. <td class="description last">
  336. <p>The ID of the geometry to return the bounding sphere for.</p>
  337. </td>
  338. </tr>
  339. <tr>
  340. <td class="name">
  341. <strong>target</strong>
  342. </td>
  343. <td class="description last">
  344. <p>The target object that is used to store the method's result.</p>
  345. </td>
  346. </tr>
  347. </tbody>
  348. </table>
  349. <dl class="details">
  350. <dt class="tag-returns"><strong>Returns:</strong> The geometry's bounding sphere. Returns <code>null</code> if no geometry has been found for the given ID.</dt>
  351. </dl>
  352. </div>
  353. <h3 class="name name-method" id="getColorAt" translate="no">.<a href="#getColorAt">getColorAt</a><span class="signature">( instanceId : <span class="param-type">number</span>, color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  354. <div class="method">
  355. <div class="description">
  356. <p>Returns the color of the defined instance.</p>
  357. </div>
  358. <table class="params">
  359. <tbody>
  360. <tr>
  361. <td class="name">
  362. <strong>instanceId</strong>
  363. </td>
  364. <td class="description last">
  365. <p>The ID of an instance to get the color of.</p>
  366. </td>
  367. </tr>
  368. <tr>
  369. <td class="name">
  370. <strong>color</strong>
  371. </td>
  372. <td class="description last">
  373. <p>The target object that is used to store the method's result.</p>
  374. </td>
  375. </tr>
  376. </tbody>
  377. </table>
  378. <dl class="details">
  379. <dt class="tag-returns"><strong>Returns:</strong> The instance's color.</dt>
  380. </dl>
  381. </div>
  382. <h3 class="name name-method" id="getGeometryIdAt" translate="no">.<a href="#getGeometryIdAt">getGeometryIdAt</a><span class="signature">( instanceId : <span class="param-type">number</span> )</span><span class="type-signature"> : number</span> </h3>
  383. <div class="method">
  384. <div class="description">
  385. <p>Returns the geometry ID of the defined instance.</p>
  386. </div>
  387. <table class="params">
  388. <tbody>
  389. <tr>
  390. <td class="name">
  391. <strong>instanceId</strong>
  392. </td>
  393. <td class="description last">
  394. <p>The ID of an instance to get the geometry ID of.</p>
  395. </td>
  396. </tr>
  397. </tbody>
  398. </table>
  399. <dl class="details">
  400. <dt class="tag-returns"><strong>Returns:</strong> The instance's geometry ID.</dt>
  401. </dl>
  402. </div>
  403. <h3 class="name name-method" id="getGeometryRangeAt" translate="no">.<a href="#getGeometryRangeAt">getGeometryRangeAt</a><span class="signature">( geometryId : <span class="param-type">number</span>, target : <span class="param-type">Object</span> )</span><span class="type-signature"> : Object</span> </h3>
  404. <div class="method">
  405. <div class="description">
  406. <p>Get the range representing the subset of triangles related to the attached geometry,
  407. indicating the starting offset and count, or <code>null</code> if invalid.</p>
  408. </div>
  409. <table class="params">
  410. <tbody>
  411. <tr>
  412. <td class="name">
  413. <strong>geometryId</strong>
  414. </td>
  415. <td class="description last">
  416. <p>The id of the geometry to get the range of.</p>
  417. </td>
  418. </tr>
  419. <tr>
  420. <td class="name">
  421. <strong>target</strong>
  422. </td>
  423. <td class="description last">
  424. <p>The target object that is used to store the method's result.</p>
  425. </td>
  426. </tr>
  427. </tbody>
  428. </table>
  429. <dl class="details">
  430. <dt class="tag-returns"><strong>Returns:</strong> The result object with range data.</dt>
  431. </dl>
  432. </div>
  433. <h3 class="name name-method" id="getMatrixAt" translate="no">.<a href="#getMatrixAt">getMatrixAt</a><span class="signature">( instanceId : <span class="param-type">number</span>, matrix : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="Matrix4.html">Matrix4</a></span> </h3>
  434. <div class="method">
  435. <div class="description">
  436. <p>Returns the local transformation matrix of the defined instance.</p>
  437. </div>
  438. <table class="params">
  439. <tbody>
  440. <tr>
  441. <td class="name">
  442. <strong>instanceId</strong>
  443. </td>
  444. <td class="description last">
  445. <p>The ID of an instance to get the matrix of.</p>
  446. </td>
  447. </tr>
  448. <tr>
  449. <td class="name">
  450. <strong>matrix</strong>
  451. </td>
  452. <td class="description last">
  453. <p>The target object that is used to store the method's result.</p>
  454. </td>
  455. </tr>
  456. </tbody>
  457. </table>
  458. <dl class="details">
  459. <dt class="tag-returns"><strong>Returns:</strong> The instance's local transformation matrix.</dt>
  460. </dl>
  461. </div>
  462. <h3 class="name name-method" id="getVisibleAt" translate="no">.<a href="#getVisibleAt">getVisibleAt</a><span class="signature">( instanceId : <span class="param-type">number</span> )</span><span class="type-signature"> : boolean</span> </h3>
  463. <div class="method">
  464. <div class="description">
  465. <p>Returns the visibility state of the defined instance.</p>
  466. </div>
  467. <table class="params">
  468. <tbody>
  469. <tr>
  470. <td class="name">
  471. <strong>instanceId</strong>
  472. </td>
  473. <td class="description last">
  474. <p>The ID of an instance to get the visibility state of.</p>
  475. </td>
  476. </tr>
  477. </tbody>
  478. </table>
  479. <dl class="details">
  480. <dt class="tag-returns"><strong>Returns:</strong> Whether the instance is visible or not.</dt>
  481. </dl>
  482. </div>
  483. <h3 class="name name-method" id="optimize" translate="no">.<a href="#optimize">optimize</a><span class="signature">()</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  484. <div class="method">
  485. <div class="description">
  486. <p>Repacks the sub geometries in BatchedMesh to remove any unused space remaining from
  487. previously deleted geometry, freeing up space to add new geometry.</p>
  488. </div>
  489. <dl class="details">
  490. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  491. </dl>
  492. </div>
  493. <h3 class="name name-method" id="setColorAt" translate="no">.<a href="#setColorAt">setColorAt</a><span class="signature">( instanceId : <span class="param-type">number</span>, color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  494. <div class="method">
  495. <div class="description">
  496. <p>Sets the given color to the defined instance.</p>
  497. </div>
  498. <table class="params">
  499. <tbody>
  500. <tr>
  501. <td class="name">
  502. <strong>instanceId</strong>
  503. </td>
  504. <td class="description last">
  505. <p>The ID of an instance to set the color of.</p>
  506. </td>
  507. </tr>
  508. <tr>
  509. <td class="name">
  510. <strong>color</strong>
  511. </td>
  512. <td class="description last">
  513. <p>The color to set the instance to.</p>
  514. </td>
  515. </tr>
  516. </tbody>
  517. </table>
  518. <dl class="details">
  519. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  520. </dl>
  521. </div>
  522. <h3 class="name name-method" id="setCustomSort" translate="no">.<a href="#setCustomSort">setCustomSort</a><span class="signature">( func : <span class="param-type">function</span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  523. <div class="method">
  524. <div class="description">
  525. <p>Takes a sort a function that is run before render. The function takes a list of instances to
  526. sort and a camera. The objects in the list include a &quot;z&quot; field to perform a depth-ordered sort with.</p>
  527. </div>
  528. <table class="params">
  529. <tbody>
  530. <tr>
  531. <td class="name">
  532. <strong>func</strong>
  533. </td>
  534. <td class="description last">
  535. <p>The custom sort function.</p>
  536. </td>
  537. </tr>
  538. </tbody>
  539. </table>
  540. <dl class="details">
  541. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  542. </dl>
  543. </div>
  544. <h3 class="name name-method" id="setGeometryAt" translate="no">.<a href="#setGeometryAt">setGeometryAt</a><span class="signature">( geometryId : <span class="param-type">number</span>, geometry : <span class="param-type"><a href="BufferGeometry.html">BufferGeometry</a></span> )</span><span class="type-signature"> : number</span> </h3>
  545. <div class="method">
  546. <div class="description">
  547. <p>Replaces the geometry at the given ID with the provided geometry. Throws an error if there
  548. is not enough space reserved for geometry. Calling this will change all instances that are
  549. rendering that geometry.</p>
  550. </div>
  551. <table class="params">
  552. <tbody>
  553. <tr>
  554. <td class="name">
  555. <strong>geometryId</strong>
  556. </td>
  557. <td class="description last">
  558. <p>The ID of the geometry that should be replaced with the given geometry.</p>
  559. </td>
  560. </tr>
  561. <tr>
  562. <td class="name">
  563. <strong>geometry</strong>
  564. </td>
  565. <td class="description last">
  566. <p>The new geometry.</p>
  567. </td>
  568. </tr>
  569. </tbody>
  570. </table>
  571. <dl class="details">
  572. <dt class="tag-returns"><strong>Returns:</strong> The geometry ID.</dt>
  573. </dl>
  574. </div>
  575. <h3 class="name name-method" id="setGeometryIdAt" translate="no">.<a href="#setGeometryIdAt">setGeometryIdAt</a><span class="signature">( instanceId : <span class="param-type">number</span>, geometryId : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  576. <div class="method">
  577. <div class="description">
  578. <p>Sets the geometry ID of the instance at the given index.</p>
  579. </div>
  580. <table class="params">
  581. <tbody>
  582. <tr>
  583. <td class="name">
  584. <strong>instanceId</strong>
  585. </td>
  586. <td class="description last">
  587. <p>The ID of the instance to set the geometry ID of.</p>
  588. </td>
  589. </tr>
  590. <tr>
  591. <td class="name">
  592. <strong>geometryId</strong>
  593. </td>
  594. <td class="description last">
  595. <p>The geometry ID to be use by the instance.</p>
  596. </td>
  597. </tr>
  598. </tbody>
  599. </table>
  600. <dl class="details">
  601. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  602. </dl>
  603. </div>
  604. <h3 class="name name-method" id="setGeometrySize" translate="no">.<a href="#setGeometrySize">setGeometrySize</a><span class="signature">( maxVertexCount : <span class="param-type">number</span>, maxIndexCount : <span class="param-type">number</span> )</span> </h3>
  605. <div class="method">
  606. <div class="description">
  607. <p>Resizes the available space in the batch's vertex and index buffer attributes to the provided sizes.
  608. If the provided arguments shrink the geometry buffers but there is not enough unused space at the
  609. end of the geometry attributes then an error is thrown.</p>
  610. </div>
  611. <table class="params">
  612. <tbody>
  613. <tr>
  614. <td class="name">
  615. <strong>maxVertexCount</strong>
  616. </td>
  617. <td class="description last">
  618. <p>The maximum number of vertices to be used by all unique geometries to resize to.</p>
  619. </td>
  620. </tr>
  621. <tr>
  622. <td class="name">
  623. <strong>maxIndexCount</strong>
  624. </td>
  625. <td class="description last">
  626. <p>The maximum number of indices to be used by all unique geometries to resize to.</p>
  627. </td>
  628. </tr>
  629. </tbody>
  630. </table>
  631. </div>
  632. <h3 class="name name-method" id="setInstanceCount" translate="no">.<a href="#setInstanceCount">setInstanceCount</a><span class="signature">( maxInstanceCount : <span class="param-type">number</span> )</span> </h3>
  633. <div class="method">
  634. <div class="description">
  635. <p>Resizes the necessary buffers to support the provided number of instances.
  636. If the provided arguments shrink the number of instances but there are not enough
  637. unused Ids at the end of the list then an error is thrown.</p>
  638. </div>
  639. <table class="params">
  640. <tbody>
  641. <tr>
  642. <td class="name">
  643. <strong>maxInstanceCount</strong>
  644. </td>
  645. <td class="description last">
  646. <p>The max number of individual instances that can be added and rendered by the batch.</p>
  647. </td>
  648. </tr>
  649. </tbody>
  650. </table>
  651. </div>
  652. <h3 class="name name-method" id="setMatrixAt" translate="no">.<a href="#setMatrixAt">setMatrixAt</a><span class="signature">( instanceId : <span class="param-type">number</span>, matrix : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  653. <div class="method">
  654. <div class="description">
  655. <p>Sets the given local transformation matrix to the defined instance.
  656. Negatively scaled matrices are not supported.</p>
  657. </div>
  658. <table class="params">
  659. <tbody>
  660. <tr>
  661. <td class="name">
  662. <strong>instanceId</strong>
  663. </td>
  664. <td class="description last">
  665. <p>The ID of an instance to set the matrix of.</p>
  666. </td>
  667. </tr>
  668. <tr>
  669. <td class="name">
  670. <strong>matrix</strong>
  671. </td>
  672. <td class="description last">
  673. <p>A 4x4 matrix representing the local transformation of a single instance.</p>
  674. </td>
  675. </tr>
  676. </tbody>
  677. </table>
  678. <dl class="details">
  679. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  680. </dl>
  681. </div>
  682. <h3 class="name name-method" id="setVisibleAt" translate="no">.<a href="#setVisibleAt">setVisibleAt</a><span class="signature">( instanceId : <span class="param-type">number</span>, visible : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="BatchedMesh.html">BatchedMesh</a></span> </h3>
  683. <div class="method">
  684. <div class="description">
  685. <p>Sets the visibility of the instance.</p>
  686. </div>
  687. <table class="params">
  688. <tbody>
  689. <tr>
  690. <td class="name">
  691. <strong>instanceId</strong>
  692. </td>
  693. <td class="description last">
  694. <p>The id of the instance to set the visibility of.</p>
  695. </td>
  696. </tr>
  697. <tr>
  698. <td class="name">
  699. <strong>visible</strong>
  700. </td>
  701. <td class="description last">
  702. <p>Whether the instance is visible or not.</p>
  703. </td>
  704. </tr>
  705. </tbody>
  706. </table>
  707. <dl class="details">
  708. <dt class="tag-returns"><strong>Returns:</strong> A reference to this batched mesh.</dt>
  709. </dl>
  710. </div>
  711. <h3 class="name name-method" id="validateGeometryId" translate="no">.<a href="#validateGeometryId">validateGeometryId</a><span class="signature">( geometryId : <span class="param-type">number</span> )</span> </h3>
  712. <div class="method">
  713. <div class="description">
  714. <p>Validates the geometry defined by the given ID.</p>
  715. </div>
  716. <table class="params">
  717. <tbody>
  718. <tr>
  719. <td class="name">
  720. <strong>geometryId</strong>
  721. </td>
  722. <td class="description last">
  723. <p>The geometry to validate.</p>
  724. </td>
  725. </tr>
  726. </tbody>
  727. </table>
  728. </div>
  729. <h3 class="name name-method" id="validateInstanceId" translate="no">.<a href="#validateInstanceId">validateInstanceId</a><span class="signature">( instanceId : <span class="param-type">number</span> )</span> </h3>
  730. <div class="method">
  731. <div class="description">
  732. <p>Validates the instance defined by the given ID.</p>
  733. </div>
  734. <table class="params">
  735. <tbody>
  736. <tr>
  737. <td class="name">
  738. <strong>instanceId</strong>
  739. </td>
  740. <td class="description last">
  741. <p>The instance to validate.</p>
  742. </td>
  743. </tr>
  744. </tbody>
  745. </table>
  746. </div>
  747. <h2 class="subsection-title">Source</h2>
  748. <p>
  749. <a href="https://github.com/mrdoob/three.js/blob/master/src/objects/BatchedMesh.js" translate="no" target="_blank" rel="noopener">src/objects/BatchedMesh.js</a>
  750. </p>
  751. </article>
  752. </section>
  753. <script src="../scripts/linenumber.js"></script>
  754. <script src="../scripts/page.js"></script>
  755. </body>
  756. </html>
粤ICP备19079148号