[page:Mesh] →

批处理网格([name])

[page:Mesh] 的特殊版本,支持多绘制批量渲染。如果您必须渲染大量具有相同材质但具有不同世界变换和几何形状的对象,请使用 [name]。使用 [name] 将帮助您减少绘制调用的数量,从而提高应用程序的整体渲染性能。

如果不支持 [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension] ,则使用性能较低的回调。

代码示例

const box = new THREE.BoxGeometry( 1, 1, 1 ); const sphere = new THREE.BoxGeometry( 1, 1, 1 ); const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); // initialize and add geometries into the batched mesh const batchedMesh = new BatchedMesh( 10, 5000, 10000, material ); const boxId = batchedMesh.addGeometry( box ); const sphereId = batchedMesh.addGeometry( sphere ); // position the geometries batchedMesh.setMatrixAt( boxId, boxMatrix ); batchedMesh.setMatrixAt( sphereId, sphereMatrix ); scene.add( batchedMesh );

例子

[example:webgl_mesh_batch WebGL / mesh / batch]

构造函数

[name]( [param:Integer maxInstanceCount], [param:Integer maxVertexCount], [param:Integer maxIndexCount], [param:Material material], )

[page:Integer maxInstanceCount] - 计划添加的单个几何体的最大数量。
[page:Integer maxVertexCount] - 所有几何体使用的最大顶点数。
[page:Integer maxIndexCount] - 所有几何图形使用的最大索引数。
[page:Material material] - [page:Material] 的一个实例。默认是新的 [page:MeshBasicMaterial]。

属性

有关常见属性,请参阅 [page:Mesh] 基类

[property:Box3 boundingBox]

该边界框包围了 [name] 的所有实例。可以用 [page:.computeBoundingBox]() 进行计算。默认为 `null`。

[property:Sphere boundingSphere]

该边界球包围了 [name] 的所有实例。可以用 [page:.computeBoundingSphere]() 进行计算。默认为 `null`。

[property:Boolean perObjectFrustumCulled]

如果为 true,则 [name] 内的各个对象将被视锥体剔除。默认为 `true`。

[property:Boolean sortObjects]

如果为 true,则对 [name] 中的各个对象进行排序以改善与过度绘制相关的工件。如果材质被标记为“透明”,则对象将从后到前渲染,如果没有,则它们从前到后渲染。默认为 `true`。

[property:Integer maxInstanceCount]

只读,[name] 中可以存储的单个几何体的最大数量。

[property:Boolean isBatchedMesh]

用于检查给定对象是否属于 [name] 类型的只读标志。

Methods

有关常用方法,请参阅 [page:Mesh] 基类。

[method:undefined computeBoundingBox]()

计算边界框,更新 [page:.boundingBox] 属性。
默认情况下不计算边界框。它们需要显式计算,否则就是 `null`。

[method:undefined computeBoundingSphere]()

计算边界球,更新 [page:.boundingSphere] 属性。
默认情况下不计算边界球。它们需要显式计算,否则就是 `null`。

[method:undefined dispose]()

释放该实例分配的GPU相关资源。每当您的应用程序中不再使用此实例时,请调用此方法。

[method:this setCustomSort]( [param:Function sortFunction] )

对渲染之前运行的函数进行排序。该函数需要一个要排序的项目列表和一个相机。列表中的对象包含一个“z”字段,用于执行深度排序。

[method:Matrix4 getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

[page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。

[page:Matrix4 matrix]: 这个 4x4 矩阵将被设置为定义实例的局部变换矩阵。

获取定义实例的局部变换矩阵。

[method:Boolean getVisibleAt]( [param:Integer index] )

[page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。

获取给定实例是否标记为“可见”。

[method:this setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

[page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。

[page:Matrix4 matrix]: 表示单个实例的局部变换的 4x4 矩阵。

将给定的局部变换矩阵设置为定义的实例。

[method:this setVisibleAt]( [param:Integer index], [param:Boolean visible] )

[page:Integer index]: 实例的索引。值必须在 [0, count] 范围内。

[page:Boolean visible]: 指示可见性状态的布尔值。

设置给定索引处对象的可见性。

[method:Integer addGeometry]( [param:BufferGeometry geometry], [param:Integer reservedVertexRange], [param:Integer reservedIndexRange] )

[page:BufferGeometry geometry]: 要添加到 [name] 中的几何体。

[page:Integer reservedVertexRange]: 可选参数,指定为添加的几何体保留的顶点缓冲区空间量。如果计划稍后在此索引处设置大于原始几何图形的新几何图形,则这是必要的。默认为给定几何顶点缓冲区的长度。

[page:Integer reservedIndexRange]: 可选参数,指定为添加的几何体保留的索引缓冲区空间量。如果计划稍后在此索引处设置大于原始几何图形的新几何图形,则这是必要的。默认为给定几何索引缓冲区的长度。

将给定几何体添加到 [name] 并返回引用它的关联索引。

[method:Integer setGeometryAt]( [param:Integer index], [param:BufferGeometry geometry] )

[page:Integer index]: 用该几何图形替换哪个几何图形索引。

[page:BufferGeometry geometry]: 在给定几何索引处替换的几何。

用提供的几何图形替换 `index` 的几何图形。如果索引处没有为几何体保留足够的空间,则会引发错误。

[method:Integer getInstanceCountAt]( [param:Integer index] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

Gets the instance count of the geometry at `index`. Returns `null` if instance counts are not configured.

[method:Integer setInstanceCountAt]( [param:Integer index], [param:Integer instanceCount ] )

[page:Integer index]: Which geometry index to configure an instance count for.

[page:Integer instanceCount]: The number of instances to render of the given geometry index.

Sets an instance count of the geometry at `index`.

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]