BufferPrimitiveCollection
Cesium v1.147 · 中文

用于 ArrayBuffer 存储的实体集合,旨在优化性能和内存使用。

要充分利用包含“N”个实体的 BufferPrimitiveCollection 的性能优势,请 注意避免为任何相关 JavaScript 对象分配 “N” 个实例。 BufferPrimitive, Color、Cartesian3 及其他对象在处理大量集合时均可被复用, 使用 flyweight pattern。

abstract new Cesium.BufferPrimitiveCollection(options)

Name Type Description
options BufferPrimitiveCollectionOptions optional
Experimental

This 该特性尚未定稿,可能根据 Cesium 的标准弃用政策进行变更。

See:

Members

static constant Cesium.BufferPrimitiveCollection.DEFAULT_CAPACITY : number

新集合中缓冲区的默认容量。即元素的数量: 顶点缓冲区中的顶点数量,primitive中的primitive数量。 缓冲区等。该值具有任意性,集合无法调整大小, 因此应针对每个缓冲区的容量在集合中指定。 构造函数可用时。

protected readonly _boundingVolume : BoundingSphere

protected readonly _boundingVolumeAutoUpdate : boolean

protected readonly _modelMatrix : Matrix4

将几何图形从模型坐标转换为世界坐标。
Default Value: Matrix4.IDENTITY
确定集合中的基体如何与场景混合。 必须为 BlendOption.OPAQUE 或 BlendOption.TRANSLUCENT; BlendOption.OPAQUE_AND_TRANSLUCENT 不受支持。

BlendOption.OPAQUE 禁用混合并写入深度,因此基体 相互遮挡以及其背后的几何图形。 BlendOption.TRANSLUCENT 使用 alpha 混合基体而不写入深度,因此通过 非顺序依赖的半透明效果来解析它们。

Default Value: BlendOption.TRANSLUCENT

readonly boundingVolume : BoundingSphere

包含于集合中的所有基体的世界空间边界体积,包括 显示和隐藏的基体。
该集合拥有的缓冲区的总字节长度。包括任何未使用的 由 primitiveCountMax 分配的空间,即使尚未添加任何基体。 该空间内也没有任何基体。

debugShowBoundingVolume : boolean

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

为原语中的每个绘制命令绘制边界球体。

Default Value: false
确定该集合覆盖哪些表面,以及 作为独立几何图形进行绘制。覆盖式绘制要求该集合 已添加到 Scene#primitives。
Default Value: HeightReference.NONE
将几何图形从模型坐标转换为世界坐标的变换。
Default Value: Matrix4.IDENTITY

readonly positionDatatype : ComponentDatatype

用于存储位置值的组件数据类型。

readonly positionNormalized : boolean

当 true 时,整数位置值被视为归一化 值,其中完整的整数范围对应 [-1, 1](有符号)或 [0, 1] (无符号)。

readonly primitiveCount : number

集合中基体的数量。必须 <= primitiveCountMax。

readonly primitiveCountMax : number

该集合能包含的最大基体数量。必须 >= primitiveCount。
Default Value: BufferPrimitiveCollection.DEFAULT_CAPACITY
决定该集合中的原语是否会被显示。
Default Value: true
集合中顶点的数量。必须 <= vertexCountMax。
该集合能包含的最大顶点数量。必须 >= vertexCount。
Default Value: BufferPrimitiveCollection.DEFAULT_CAPACITY

Methods

static Cesium.BufferPrimitiveCollection.clone(collection, result, predicate)

将此集合的内容复制到结果集合中。 结果集合不会调整大小,并且必须拥有足够的空间来容纳源集合中的所有基本实体。 结果集合将覆盖原集合中的现有基本实体。 原集合将被覆盖。

当集合达到其容量并需要高效地将特征转移到新集合时,使用此功能可以分配更多空间。

通过从“集合”复制到“结果”的控件,可以高效地转移特征。

Name Type Description
collection BufferPrimitiveCollection.<T>
result BufferPrimitiveCollection.<T>
predicate function optional 如果提供参数,只有返回 true 的基本实体会被复制。存活的实体会被压缩到连续索引中。
Example:
const result = new BufferPrimitiveCollection({ ... }); // 分配更大的“结果”集合
BufferPrimitiveCollection.clone(collection, result);   // 将“集合”中的基本实体复制到“结果”中

static Cesium.BufferPrimitiveCollection.fromCollection(collection, options, predicate) → BufferPrimitiveCollection.<T>

调整大小的缓冲区必须足够大以容纳所有基本实体。

集合级别的状态(模型矩阵、混合选项、选择、边界体积模式等)会被保留,但GPU资源不会:源集合 保留其渲染器资源的所有权,因此调用者负责在不再需要时调用 BufferPrimitiveCollection#destroy 来释放源集合的GPU资源。

当不再需要时,源集合的GPU资源将被释放。

const grown = BufferPrimitiveCollection.fromCollection(collection, { primitiveCountMax: collection.primitiveCountMax * 2, calling BufferPrimitiveCollection#destroy on the source once it is no collection.destroy(); // 释放源集合的GPU资源
Name Type Description
collection BufferPrimitiveCollection.<T> Source collection to copy.
options BufferPrimitiveCollectionOptions optional Constructor options to override. Omitted options are inherited from the source collection.
predicate function optional When provided, only primitives for which this returns true are copied. Surviving primitives are compacted into contiguous indices.
Returns:
Examples:
// 在删除隐藏实体时扩展集合。
const compacted = BufferPrimitiveCollection.fromCollection(
collection,
});
{ primitiveCountMax: collection.primitiveCountMax * 2 },
(primitive) => primitive.show,
要复制的源集合。
要覆盖的构造函数选项。未提供的选项从源集合继承。
如果提供参数,只有返回 <code>true</code> 的基本实体会被复制。存活的实体会被压缩到连续索引中。
(primitive) => primitive.show,
);
向集合中添加一个新的原始体,并指定选项。一个 BufferPrimitive 实例与新的原始体关联,如果提供 'result' 参数则使用该参数,否则使用新实例。对于重复调用, the 'result' argument if given, or a new instance if not. For repeated 最好重用同一个 BufferPrimitive 实例,而不是每次调用时都分配新实例。 将范围 [offset, offset + count) 内的原始体标记为 'dirty',将在下次渲染时更新。
Name Type Description
options BufferPrimitiveOptions
result BufferPrimitive
Returns:
Destroys collection and its GPU resources.
将给定的 BufferPrimitive 作为对当前集合中指定索引的 原始体的视图,用于读取/写入原始体属性时使用。当遍历大型集合时,最好在整个循环中使用 properties. When iterating over a large collection, prefer to reuse 同一个 BufferPrimitive 实例——重新绑定 现有实例到不同原始体是高效的,并且避免了为每个对象分配内存对象。 const primitive = new BufferPrimitive();
Name Type Description
index number
result BufferPrimitive
Returns:
The BufferPrimitive instance passed as the 'result' 参数传递的 BufferPrimitive 实例,现在绑定到指定的原始体索引。
Example:
for (let i = 0; i < collection.primitiveCount; i++) {
collection.get(i, primitive);
primitive.setColor(Color.RED);
将作为
}
如果此对象被销毁则返回 true;否则返回 false。
Returns:
True 如果此对象被销毁则返回 true;否则返回 false。

abstract setPositions(positions, primitiveOffset, primitiveCount)

在指定的基体范围内更新顶点位置。对于 对多个基体仅更新位置的情况,`setPositions()` 更 高效于单独更新每个基体。 参数 `positions` 必须包含与 目标基体范围相同的顶点总数;该方法不能添加或移除顶点。
Name Type Description
positions TypedArray
primitiveOffset number
primitiveCount number

sort(sortFn, result) → Uint32Array

对集合中的原语进行排序。 由于排序会改变集合中原语的索引(但不改变特征 ID), 该函数还返回一个数组,将之前的 索引映射到新索引。当反复排序时,该数组可以被复用,并 作为每次调用的 ‘result’ 参数传递。
Name Type Description
sortFn function
result Uint32Array
Returns:
Mapping 从之前的索引到新的索引。
返回表示集合的 JSON 可序列化数组。这种编码方式 不节省内存,通常用于调试和 测试。
Returns:
List 每个集合中有一个用于 JSON 序列化的可序列化对象。 该集合中primitive的数量。
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.