English中文

BufferPrimitiveCollection

ArrayBuffer 存储中保存的原语集合,用于性能和内存优化。 Collection of primitives held in ArrayBuffer storage for performance and memory optimization.

为了获得使用包含“N”个基元的 BufferPrimitiveCollection 的全部性能优势,请小心避免分配任何相关 JavaScript 对象的“N”个实例。 To get the full performance benefit of using a BufferPrimitiveCollection containing "N" primitives, be careful to avoid allocating "N" instances of any related JavaScript object. BufferPrimitive, Color, Cartesian3,并且在处理大型集合时,其他对象都可以重用,使用 , and other objects can all be reused when working with large collections, using the flyweight pattern.

abstract new Cesium.BufferPrimitiveCollection(options)

名称 Name 类型 Type 说明 Description
options object
名称 Name 类型 Type 默认值 Default 说明 Description
modelMatrix Matrix4 Matrix4.IDENTITY 可选 optional 将几何体从模型转换为世界坐标。 Transforms geometry from model to world coordinates.
primitiveCountMax number BufferPrimitiveCollection.DEFAULT_CAPACITY 可选 optional
vertexCountMax number BufferPrimitiveCollection.DEFAULT_CAPACITY 可选 optional
show boolean true 可选 optional
positionDatatype ComponentDatatype ComponentDatatype.DOUBLE 可选 optional
allowPicking boolean false 可选 optional When true,基元可以选择 , primitives are pickable with Scene#pick。当 . When false,内存和初始化成本较低。 , memory and initialization cost are lower.
debugShowBoundingVolume boolean false 可选 optional
实验性 Experimental

此功能不是最终版本,可能会在没有 Cesium 标准弃用政策的情况下进行更改。 This feature is not final and is subject to change without Cesium's standard deprecation policy.

另见: See:

成员 Members

集合中所有图元的局部包围体,包括显示的和隐藏的图元。 Local bounding volume for all primitives in the collection, including both shown and hidden primitives.
集合中所有图元的世界边界体积,包括显示的和隐藏的图元。 World bounding volume for all primitives in the collection, including both shown and hidden primitives.
该集合拥有的缓冲区的总字节长度。包括分配的任何未使用空间 Total byte length of buffers owned by this collection. Includes any unused space allocated by primitiveCountMax,即使该空间中尚未添加任何基元。 , even if no primitives have yet been added in that space.

debugShowBoundingVolume : boolean

该属性仅用于调试;它不适合生产用途,也没有经过优化。 This property is for debugging only; it is not for production use nor is it optimized.

Draws the bounding sphere for each draw command in the primitive.

默认值: Default Value: false

readonly DEFAULT_CAPACITY : number

新集合的缓冲区的默认容量。元素数量:顶点缓冲区中的顶点数、图元缓冲区中的图元数量等。该值是任意的,并且集合无法调整大小,因此应在集合构造函数中提供特定的每个缓冲区容量(如果可用)。 Default capacity of buffers on new collections. A quantity of elements: number of vertices in the vertex buffer, primitives in the primitive buffer, etc. This value is arbitrary, and collections cannot be resized, so specific per-buffer capacities should be provided in the collection constructor when available.
将几何体从模型转换为世界坐标。 Transforms geometry from model to world coordinates.
默认值: Default Value: Matrix4.IDENTITY

readonly primitiveCount : number

集合中的基元数量。必须是 Number of primitives in collection. Must be <= primitiveCountMax.

readonly primitiveCountMax : number

该集合可以包含的最大基元数。必须 >= Maximum number of primitives this collection can contain. Must be >= primitiveCount.
默认值: Default Value: BufferPrimitiveCollection.DEFAULT_CAPACITY
确定是否显示该集合中的基元。 Determines if primitives in this collection will be shown.
默认值: Default Value: true
集合中的顶点数。必须是 Number of vertices in collection. Must be <= vertexCountMax.

readonly vertexCountMax : number

该集合可以包含的最大顶点数。必须 >= Maximum number of vertices this collection can contain. Must be >= vertexCount.
默认值: Default Value: BufferPrimitiveCollection.DEFAULT_CAPACITY

方法 Methods

static Cesium.BufferPrimitiveCollection.clone(collection, result)

将此集合的内容复制到结果集合中。结果集合不会调整大小,并且必须包含足够的空间来容纳源集合中的所有基元。结果集合中的现有基元将被覆盖。 Duplicates the contents of this collection into the result collection. Result collection is not resized, and must contain enough space for all primitives in the source collection. Existing primitives in the result collection will be overwritten.

当为已达到其容量的集合分配更多空间以及有效地将功能转移到新集合时非常有用。 Useful when allocating more space for a collection that has reached its capacity, and efficiently transferring features to the new collection.

名称 Name 类型 Type 说明 Description
collection BufferPrimitiveCollection.<T>
result BufferPrimitiveCollection.<T>
示例: Example:
const result = new BufferPrimitiveCollection({ ... }); // allocate larger 'result' collection
BufferPrimitiveCollection.clone(collection, result);   // copy primitives from 'collection' into 'result'
使用指定的选项将新基元添加到集合中。一个 Adds a new primitive to the collection, with the specified options. A BufferPrimitive 实例链接到新的原语,如果给定则使用“结果”参数,如果没有则使用新实例。对于重复调用,最好重用单个 BufferPrimitive 实例,而不是在每次调用时分配一个新实例。 instance is linked to the new primitive, using the 'result' argument if given, or a new instance if not. For repeated calls, prefer to reuse a single BufferPrimitive instance rather than allocating a new instance on each call.
名称 Name 类型 Type 说明 Description
options BufferPrimitiveOptions
result BufferPrimitive
返回: Returns:
破坏集合及其 GPU 资源。 Destroys collection and its GPU resources.
使得给定的 Makes the given BufferPrimitive 给定索引处此集合的基元的视图,供读取/写入基元属性时使用。当迭代大型集合时,最好在整个循环中重用相同的 BufferPrimitive 实例 - 将现有实例重新绑定到不同的基元很便宜,并且避免为每个对象分配内存中的对象。 a view onto this collection's primitive at the given index, for use when reading/writing primitive properties. When iterating over a large collection, prefer to reuse the same BufferPrimitive instance throughout the loop — rebinding an existing instance to a different primitive is cheap, and avoids allocating in-memory objects for every object.
名称 Name 类型 Type 说明 Description
index number
result BufferPrimitive
返回: Returns:
作为“结果”参数传递的 BufferPrimitive 实例现在绑定到指定的基元索引。 The BufferPrimitive instance passed as the 'result' argument, now bound to the specified primitive index.
示例: Example:
const primitive = new BufferPrimitive();
for (let i = 0; i < collection.primitiveCount; i++) {
  collection.get(i, primitive);
  primitive.setColor(Color.RED);
}
如果该对象被销毁则返回 true;否则为假。 Returns true if this object was destroyed; otherwise, false.
返回: Returns:
如果该对象被销毁,则为 True;否则为假。 True if this object was destroyed; otherwise, false.

sort(sortFn, result)Uint32Array

对集合的基元进行排序。由于排序会更改集合中图元的索引(但不会更改要素 ID),因此该函数还会返回从先前索引到新索引的数组映射。重复排序时,可以重用该数组并将其作为每次调用的“结果”参数传递。 Sorts primitives of the collection. Because sorting changes the indices (but not the feature IDs) of primitives in the collection, the function also returns an array mapping from previous index to new index. When sorting repeatedly, the array can be reused and passed as the 'result' argument for each call.
名称 Name 类型 Type 说明 Description
sortFn function
result Uint32Array
返回: Returns:
从先前索引到新索引的映射。 Mapping from previous index to new index.
返回表示集合的 JSON 可序列化数组。这种编码不节省内存,通常应该用于调试和测试。 Returns a JSON-serializable array representing the collection. This encoding is not memory-efficient, and should generally be used for debugging and testing.
返回: Returns:
JSON 可序列化对象的列表,一个对应集合中的每个基元。 List of JSON-serializable objects, one for each primitive in the collection.
示例: 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.