BatchedMesh.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!DOCTYPE html>
  2. <html lang="zh">
  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. [page:Mesh] 的特殊版本,支持多绘制批量渲染。如果您必须渲染大量具有相同材质但具有不同世界变换和几何形状的对象,请使用 [name]。使用 [name] 将帮助您减少绘制调用的数量,从而提高应用程序的整体渲染性能。
  14. <br />
  15. <br />
  16. 如果不支持 [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension]
  17. ,则使用性能较低的回调。
  18. </p>
  19. <h2>代码示例</h2>
  20. <code>
  21. const box = new THREE.BoxGeometry( 1, 1, 1 );
  22. const sphere = new THREE.BoxGeometry( 1, 1, 1 );
  23. const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
  24. // initialize and add geometries into the batched mesh
  25. const batchedMesh = new BatchedMesh( 10, 5000, 10000, material );
  26. const boxId = batchedMesh.addGeometry( box );
  27. const sphereId = batchedMesh.addGeometry( sphere );
  28. // position the geometries
  29. batchedMesh.setMatrixAt( boxId, boxMatrix );
  30. batchedMesh.setMatrixAt( sphereId, sphereMatrix );
  31. scene.add( batchedMesh );
  32. </code>
  33. <h2>例子</h2>
  34. <p>
  35. [example:webgl_mesh_batch WebGL / mesh / batch]<br />
  36. </p>
  37. <h2>构造函数</h2>
  38. <h3>
  39. [name](
  40. [param:Integer maxInstanceCount], [param:Integer maxVertexCount],
  41. [param:Integer maxIndexCount], [param:Material material],
  42. )
  43. </h3>
  44. <p>
  45. [page:Integer maxInstanceCount] - 计划添加的单个几何体的最大数量。<br />
  46. [page:Integer maxVertexCount] - 所有几何体使用的最大顶点数。<br />
  47. [page:Integer maxIndexCount] - 所有几何图形使用的最大索引数。<br />
  48. [page:Material material] - [page:Material] 的一个实例。默认是新的 [page:MeshBasicMaterial]。<br />
  49. </p>
  50. <h2>属性</h2>
  51. <p>有关常见属性,请参阅 [page:Mesh] 基类</p>
  52. <h3>[property:Box3 boundingBox]</h3>
  53. <p>
  54. 该边界框包围了 [name] 的所有实例。可以用 [page:.computeBoundingBox]() 进行计算。默认为 `null`。
  55. </p>
  56. <h3>[property:Sphere boundingSphere]</h3>
  57. <p>
  58. 该边界球包围了 [name] 的所有实例。可以用 [page:.computeBoundingSphere]() 进行计算。默认为 `null`。
  59. </p>
  60. <h3>[property:Boolean perObjectFrustumCulled]</h3>
  61. <p>
  62. 如果为 true,则 [name] 内的各个对象将被视锥体剔除。默认为 `true`。
  63. </p>
  64. <h3>[property:Boolean sortObjects]</h3>
  65. <p>
  66. 如果为 true,则对 [name] 中的各个对象进行排序以改善与过度绘制相关的工件。如果材质被标记为“透明”,则对象将从后到前渲染,如果没有,则它们从前到后渲染。默认为 `true`。
  67. </p>
  68. <h3>[property:Integer maxInstanceCount]</h3>
  69. <p>
  70. 只读,[name] 中可以存储的单个几何体的最大数量。
  71. </p>
  72. <h3>[property:Boolean isBatchedMesh]</h3>
  73. <p>用于检查给定对象是否属于 [name] 类型的只读标志。</p>
  74. <h2>Methods</h2>
  75. <p>有关常用方法,请参阅 [page:Mesh] 基类。</p>
  76. <h3>[method:undefined computeBoundingBox]()</h3>
  77. <p>
  78. 计算边界框,更新 [page:.boundingBox] 属性。<br />
  79. 默认情况下不计算边界框。它们需要显式计算,否则就是 `null`。
  80. </p>
  81. <h3>[method:undefined computeBoundingSphere]()</h3>
  82. <p>
  83. 计算边界球,更新 [page:.boundingSphere] 属性。<br />
  84. 默认情况下不计算边界球。它们需要显式计算,否则就是 `null`。
  85. </p>
  86. <h3>[method:undefined dispose]()</h3>
  87. <p>
  88. 释放该实例分配的GPU相关资源。每当您的应用程序中不再使用此实例时,请调用此方法。
  89. </p>
  90. <h3>[method:this setCustomSort]( [param:Function sortFunction] )</h3>
  91. <p>
  92. 对渲染之前运行的函数进行排序。该函数需要一个要排序的项目列表和一个相机。列表中的对象包含一个“z”字段,用于执行深度排序。
  93. </p>
  94. <h3>
  95. [method:Matrix4 getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )
  96. </h3>
  97. <p>
  98. [page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。
  99. </p>
  100. <p>
  101. [page:Matrix4 matrix]: 这个 4x4 矩阵将被设置为定义实例的局部变换矩阵。
  102. </p>
  103. <p>获取定义实例的局部变换矩阵。</p>
  104. <h3>
  105. [method:Boolean getVisibleAt]( [param:Integer index] )
  106. </h3>
  107. <p>
  108. [page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。
  109. </p>
  110. <p>获取给定实例是否标记为“可见”。</p>
  111. <h3>
  112. [method:this setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )
  113. </h3>
  114. <p>
  115. [page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。
  116. </p>
  117. <p>
  118. [page:Matrix4 matrix]: 表示单个实例的局部变换的 4x4 矩阵。
  119. </p>
  120. <p>
  121. 将给定的局部变换矩阵设置为定义的实例。
  122. </p>
  123. <h3>
  124. [method:this setVisibleAt]( [param:Integer index], [param:Boolean visible] )
  125. </h3>
  126. <p>
  127. [page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。
  128. </p>
  129. <p>
  130. [page:Boolean visible]: 指示可见性状态的布尔值。
  131. </p>
  132. <p>
  133. 设置给定索引处对象的可见性。
  134. </p>
  135. <h3>
  136. [method:Integer addGeometry]( [param:BufferGeometry geometry], [param:Integer reservedVertexRange], [param:Integer
  137. reservedIndexRange] )
  138. </h3>
  139. <p>
  140. [page:BufferGeometry geometry]: 要添加到 [name] 中的几何体。
  141. </p>
  142. <p>
  143. [page:Integer reservedVertexRange]: 可选参数,指定为添加的几何体保留的顶点缓冲区空间量。如果计划稍后在此索引处设置大于原始几何图形的新几何图形,则这是必要的。默认为给定几何顶点缓冲区的长度。
  144. </p>
  145. <p>
  146. [page:Integer reservedIndexRange]: 可选参数,指定为添加的几何体保留的索引缓冲区空间量。如果计划稍后在此索引处设置大于原始几何图形的新几何图形,则这是必要的。默认为给定几何索引缓冲区的长度。
  147. </p>
  148. <p>
  149. 将给定几何体添加到 [name] 并返回引用它的关联索引。
  150. </p>
  151. <h3>
  152. [method:Integer setGeometryAt]( [param:Integer index], [param:BufferGeometry geometry] )
  153. </h3>
  154. <p>
  155. [page:Integer index]: 用该几何图形替换哪个几何图形索引。
  156. </p>
  157. <p>
  158. [page:BufferGeometry geometry]: 在给定几何索引处替换的几何。
  159. </p>
  160. <p>
  161. 用提供的几何图形替换 `index` 的几何图形。如果索引处没有为几何体保留足够的空间,则会引发错误。
  162. </p>
  163. <h3>
  164. [method:Integer getInstanceCountAt]( [param:Integer index] )
  165. </h3>
  166. <p>
  167. [page:Integer index]: The index of an instance. Values have to be in the
  168. range [0, count].
  169. </p>
  170. <p>
  171. Gets the instance count of the geometry at `index`. Returns `null` if instance counts are not configured.
  172. </p>
  173. <h3>
  174. [method:Integer setInstanceCountAt]( [param:Integer index], [param:Integer instanceCount ] )
  175. </h3>
  176. <p>
  177. [page:Integer index]: Which geometry index to configure an instance count for.
  178. </p>
  179. <p>
  180. [page:Integer instanceCount]: The number of instances to render of the given geometry index.
  181. </p>
  182. <p>
  183. Sets an instance count of the geometry at `index`.
  184. </p>
  185. <h2>源代码</h2>
  186. <p>
  187. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  188. </p>
  189. </body>
  190. </html>