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 optionaltrue 时,几何体顶点针对顶点着色器前后缓存进行了优化。
interleave boolean false optionaltrue 时,几何体顶点属性是交错的,这可以稍微提高渲染性能,但会增加加载时间。
compressVertices boolean true optionaltrue 时,几何体顶点被压缩,这将节省内存。
releaseGeometryInstances boolean true optionaltrue 时,该原语不会保留对输入 geometryInstances 的引用以节省内存。
allowPicking boolean true optionaltrue 时,每个几何体实例仅可通过 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

确定几何体实例是否将在 Web Worker 中创建和批处理。
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
与该原语一起渲染的几何体实例。如果在构造原语时 options.releaseGeometryInstancestrue 则可能为 undefined

在原语渲染后更改此属性将无效。

由于使用的渲染技术,所有几何体实例必须具有相同的颜色。 如果存在颜色不同的实例,将在第一次尝试渲染时抛出 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 : 并非所有几何体实例都有相同的颜色属性。
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.