ClassificationPrimitive

new Cesium.ClassificationPrimitive(options)

分类图元表示 Scene 中要突出显示的包围几何体体积。

图元将几何实例与 Appearance 结合,描述完整的着色,包括 MaterialRenderState。粗略地说,几何实例定义结构和位置, 而外观定义视觉特征。解耦几何和外观允许我们混合 搭配大多数它们,并独立添加新的几何或外观。 当直接使用 ClassificationPrimitive 时,目前仅支持在所有实例中具有相同颜色的 PerInstanceColorAppearance。 对地形或 3D Tiles 进行分类时,如需完整的 Appearance 支持,请改用 GroundPrimitive

为了正确渲染,此功能需要 EXT_frag_depth WebGL 扩展。对于不支持此扩展的硬件, 某些视角会出现渲染伪影。

有效的几何体包括 BoxGeometryCylinderGeometryEllipsoidGeometryPolylineVolumeGeometrySphereGeometry

跟随椭球体表面的几何体(如 CircleGeometryCorridorGeometryEllipseGeometryPolygonGeometryRectangleGeometry) 在作为拉伸体时也有效;否则将不会被渲染。

Name Type Description
options object optional 具有以下属性的对象:
Name Type Default Description
geometryInstances Array | GeometryInstance optional 要渲染的几何实例。可以是单个实例或长度为一的数组。
appearance Appearance optional 用于渲染图元的外观。当几何实例具有颜色属性时,默认为 PerInstanceColorAppearance。
show boolean true optional 确定是否显示此图元。
vertexCacheOptimize boolean false optional 当为 true 时,几何顶点针对顶点着色器前后的缓存进行优化。
interleave boolean false optional 当为 true 时,几何顶点属性被交错,可以稍微提高渲染性能但会增加加载时间。
compressVertices boolean true optional 当为 true 时,几何顶点被压缩,将节省内存。
releaseGeometryInstances boolean true optional 当为 true 时,图元不保留对输入 geometryInstances 的引用以节省内存。
allowPicking boolean true optional 当为 true 时,每个几何实例只能通过 Scene#pick 进行拾取。当为 false 时,可节省 GPU 内存。
asynchronous boolean true optional 确定图元是异步创建还是阻塞直到就绪。如果为 false,必须先调用 initializeTerrainHeights()。
classificationType ClassificationType ClassificationType.BOTH optional 确定是对地形、3D Tiles 还是两者进行分类。
debugShowBoundingVolume boolean false optional 仅用于调试。确定是否显示此图元命令的包围球。
debugShowShadowVolume boolean false optional 仅用于调试。确定是否绘制图元中每个几何体的阴影体。必须在创建时设为 true, 才能在几何体释放之前创建体积,或者 options.releaseGeometryInstance 必须为 false
See:

Members

readonly allowPicking : boolean

当为 true 时,每个几何实例只能通过 Scene#pick 进行拾取。当为 false 时,可节省 GPU 内存。
Default Value: true

readonly asynchronous : boolean

确定是否在工作线程上创建和批处理几何实例。
Default Value: true
确定是对地形、3D Tiles 还是两者进行分类。
Default Value: ClassificationType.BOTH

readonly compressVertices : boolean

当为 true 时,几何顶点被压缩,将节省内存。
Default Value: true

debugShowBoundingVolume : boolean

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

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

Default Value: false

debugShowShadowVolume : boolean

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

绘制图元中每个几何体的阴影体。

Default Value: false
使用此图元渲染的几何实例。这可能 为 undefined(如果在构建图元时 options.releaseGeometryInstancestrue)。

在图元渲染后更改此属性无效。

由于使用的渲染技术,所有几何实例必须具有相同的颜色。 如果存在颜色不同的实例,在首次尝试渲染时将抛出 DeveloperError

Default Value: undefined
确定几何顶点属性是否交错,可以稍微提高渲染性能。
Default Value: false
确定图元是否已完成并准备好渲染。如果此属性为 true,则下次调用 ClassificationPrimitive#update 时将渲染图元。

readonly releaseGeometryInstances : boolean

当为 true 时,图元不保留对输入 geometryInstances 的引用以节省内存。
Default Value: true
确定是否显示图元。这会影响图元中的所有几何实例。
Default Value: true

readonly vertexCacheOptimize : boolean

当为 true 时,几何顶点针对顶点着色器前后的缓存进行优化。
Default Value: true

Methods

static Cesium.ClassificationPrimitive.isSupported(scene)boolean

确定是否支持 ClassificationPrimitive 渲染。
Name Type Description
scene Scene 场景。
Returns:
如果支持 ClassificationPrimitives 则返回 true;否则返回 false
销毁此对象持有的 WebGL 资源。销毁对象允许确定性 释放 WebGL 资源,而不是依赖垃圾回收器来销毁此对象。

对象销毁后不应再使用;调用除 isDestroyed 之外的任何函数都将导致 DeveloperError 异常。因此, 如示例所示,将返回值(undefined)赋给该对象。

Throws:
Example:
e = e && e.destroy();
See:

getGeometryInstanceAttributes(id)object

返回 GeometryInstance 的可修改的每个实例属性。
Name Type Description
id * GeometryInstance 的 id。
Returns:
属性格式的类型的数组,如果没有具有该 id 的实例则返回 undefined。
Throws:
  • DeveloperError : 必须在调用 getGeometryInstanceAttributes 之前调用 update。
Example:
const attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);
如果此对象已被销毁则返回 true;否则返回 false。

如果此对象已被销毁,则不应使用它;调用除 isDestroyed 之外的任何函数都将导致 DeveloperError 异常。

Returns:
如果此对象已被销毁则返回 true;否则返回 false
See:
ViewerCesiumWidget 渲染场景时调用, 以获取渲染此图元所需的绘制命令。

不要直接调用此函数。此处文档仅用于 列出渲染场景时可能传播的异常:

Throws:
  • DeveloperError : 所有实例几何体必须具有相同的 primitiveType。
  • DeveloperError : 外观和材质具有相同名称的 uniform。
  • DeveloperError : 并非所有几何实例都具有相同的颜色属性。
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.