BufferPrimitiveCollection

存储在 ArrayBuffer 中的图元集合,用于性能和内存优化。

为了充分利用包含 "N" 个图元的 BufferPrimitiveCollection 的性能, 请注意避免分配 "N" 个任何相关 JavaScript 对象的实例。BufferPrimitiveColorCartesian3 等对象在使用大型集合时都可以重用, 使用享元模式

abstract new Cesium.BufferPrimitiveCollection(options)

Name Type Description
options object
Name Type Default Description
modelMatrix Matrix4 Matrix4.IDENTITY optional 将几何体从模型坐标变换到世界坐标。
primitiveCountMax number BufferPrimitiveCollection.DEFAULT_CAPACITY optional
vertexCountMax number BufferPrimitiveCollection.DEFAULT_CAPACITY optional
show boolean true optional
positionDatatype ComponentDatatype ComponentDatatype.DOUBLE optional
allowPicking boolean false optionaltrue 时,图元可使用 Scene#pick 进行拾取。当 false 时,内存和初始化成本更低。
debugShowBoundingVolume boolean false optional
Experimental

此功能尚未最终确定,可能会在不遵循 Cesium 标准弃用政策的情况下进行更改。

See:

Members

static constant Cesium.BufferPrimitiveCollection.DEFAULT_CAPACITY : number

新集合上缓冲区的默认容量。元素数量: 顶点缓冲区中的顶点数,图元缓冲区中的图元数等。 此值是任意的,且集合无法调整大小, 因此在可用时应在集合构造函数中提供特定的每缓冲容量。
Default Value: Matrix4.IDENTITY
集合中所有图元的局部包围体积,包括 显示和隐藏的图元。
集合中所有图元的世界包围体积,包括 显示和隐藏的图元。
此集合拥有的缓冲区的总字节长度。包括由 primitiveCountMax 分配的任何未使用空间,即使尚未在该空间中添加图元。

debugShowBoundingVolume : boolean

此属性仅用于调试;不用于生产环境,也未进行优化。

绘制图元中每个绘制命令的包围球。

Default Value: false
将几何体从模型坐标变换到世界坐标。
Default Value: Matrix4.IDENTITY

readonly primitiveCount : number

集合中的图元数。必须 <= primitiveCountMax

readonly primitiveCountMax : number

此集合可包含的最大图元数。必须 >= primitiveCount
Default Value: BufferPrimitiveCollection.DEFAULT_CAPACITY
确定此集合中的图元是否显示。
Default Value: true
集合中的顶点数。必须 <= vertexCountMax

readonly vertexCountMax : number

此集合可包含的最大顶点数。必须 >= vertexCount
Default Value: BufferPrimitiveCollection.DEFAULT_CAPACITY

Methods

static Cesium.BufferPrimitiveCollection.clone(collection, result)

将此集合的内容复制到结果集合。 结果集合不调整大小,必须包含足够的空间以容纳源集合中的所有图元。 结果集合中的现有图元将被覆盖。

在为已达到容量的集合分配更多空间, 并将图元高效转移到新集合时非常有用。

Name Type Description
collection BufferPrimitiveCollection.<T>
result BufferPrimitiveCollection.<T>
Example:
const result = new BufferPrimitiveCollection({ ... }); // 分配更大的 'result' 集合
BufferPrimitiveCollection.clone(collection, result);   // 将 'collection' 中的图元复制到 'result'
向集合添加新图元,并指定选项。 BufferPrimitive 实例链接到新图元,使用 'result' 参数(如果提供), 否则使用新实例。对于重复调用,建议重用单个 BufferPrimitive 实例, 而不是在每次调用时分配新实例。
Name Type Description
options BufferPrimitiveOptions
result BufferPrimitive
Returns:
销毁集合及其 GPU 资源。
将给定的 BufferPrimitive 作为此集合中指定索引处图元的视图, 用于读/写图元属性。当遍历大型集合时,建议在循环中重用 同一个 BufferPrimitive 实例 — 将现有实例重新绑定到不同的图元很廉价, 并且避免了为每个对象分配内存中的对象。
Name Type Description
index number
result BufferPrimitive
Returns:
作为 'result' 参数传递的 BufferPrimitive 实例, 现在已绑定到指定的图元索引。
Example:
const primitive = new BufferPrimitive();
for (let i = 0; i < collection.primitiveCount; i++) {
  collection.get(i, primitive);
  primitive.setColor(Color.RED);
}
返回此对象是否已销毁;如果未销毁,则返回 false。
Returns:
如果此对象已销毁,则返回 true;否则返回 false。

sort(sortFn, result)Uint32Array

对集合的图元进行排序。 由于排序会更改图元的索引(但不更改特征 ID), 该函数还会返回一个数组,映射从先前索引到新索引。 当重复排序时,可以重用该数组并将其作为 'result' 参数传递给每次调用。
Name Type Description
sortFn function
result Uint32Array
Returns:
从先前索引到新索引的映射。
返回表示该集合的可 JSON 序列化的数组。此编码 不具有内存效率,通常应用于调试和测试。
Returns:
可 JSON 序列化的对象列表,集合中每个图元一个。
Example:
console.table(collection.toJSON());
Name Type Description
frameState object
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.