ClassificationPrimitive

new Cesium.ClassificationPrimitive(options)

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

图元将几何图形实例与描述完整阴影的Appearance组合在一起,其中包括MaterialRenderState。 大致上,几何实例定义了结构和位置,外观定义了视觉特征。解耦几何和外观允许我们混合和匹配它们中的大多数,并独立地添加一个新的几何或外观。 在直接使用ClassificationPrimitive时,只支持在所有实例中使用相同颜色的PerInstanceColorAppearance。 当分类地形或3D Tiles使用GroundPrimitive代替时有完整的Appearance 支持。

为了正确的渲染,这个特性需要EXT_frag_depth WebGL扩展。对于不支持此扩展的硬件,将在某些视角渲染伪像(artifacts)。

有效的几何图形有BoxGeometryCylinderGeometryEllipsoidGeometryPolylineVolumeGeometrySphereGeometry

沿椭球表面的几何图形,如CircleGeometryCorridorGeometryEllipseGeometryPolygonGeometryRectangleGeometry, 如果是挤压体,也同样有效;否则,它们将不会被渲染。

Name Type Description
options Object optional 具有下列属性的对象:
Name Type Default Description
geometryInstances Array | GeometryInstance optional 要渲染的几何图形实例。它可以是单个实例,也可以是长度为1的数组。
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 确定图元是异步创建(true)还是阻塞直到准备就绪。
classificationType ClassificationType ClassificationType.BOTH optional 确定是否地形,3DTiles或两者都将被分类。
debugShowBoundingVolume Boolean false optional 只是用来调试,是否显示图元的包围球。
debugShowShadowVolume Boolean false optional 仅供调试。确定是否绘制了图元中每个几何图形的阴影体。 在创建体之前,必须是true,几何图形被释放或options.releaseGeometryInstance必须是false
See:

Members

readonlyallowPicking : Boolean

true时,每个几何体实例只能用Scene#pick来拾取。 当false时,节省GPU内存。
Default Value: true

readonlyasynchronous : Boolean

确定图元是异步创建(true)还是阻塞直到准备就绪。
Default Value: true
确定是否地形,3DTiles或两者都将被分类。
Default Value: ClassificationType.BOTH

readonlycompressVertices : Boolean

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

debugShowBoundingVolume : Boolean

此属性仅用于调试;它既不用于生产,也不是最优的。

为图元中的每个draw命令绘制边界球。

Default Value: false

debugShowShadowVolume : Boolean

此属性仅用于调试;它既不用于生产,也不是最优的。

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

Default Value: false

readonlygeometryInstances : Array|GeometryInstance

要渲染的几何图形实例。 如果构造图元时options.releaseGeometryInstances为true,则此属性为undefined

在图元渲染后更改此属性没有效果。

由于使用了渲染技术,所有几何实例必须是相同的颜色。如果存在不同颜色的实例,则在第一次呈现时将抛出DeveloperError

Default Value: undefined

readonlyinterleave : Boolean

true时,几何顶点属性是交错的,这可以略微提高渲染性能,但增加了加载时间。
Default Value: false

readonlyready : Boolean

确定图元是否完成并准备渲染, 如果此属性为true,则在下一次调用ClassificationPrimitive#update时将渲染图元。
获取在图元准备渲染时解析的promise。

readonlyreleaseGeometryInstances : Boolean

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

readonlyvertexCacheOptimize : Boolean

true时,几何顶点被优化为前后顶点着色器缓存。
Default Value: true

Methods

staticCesium.ClassificationPrimitive.isSupported(scene)Boolean

确定是否支持ClassificationPrimitive渲染。
Name Type Description
scene Scene 场景(Scene对象)。
Returns:
如果支持ClassificationPrimitives返回true。
销毁此对象持有的WebGL资源。

一旦对象被销毁,它将不能在使用;调用除isDestroyed之外的任何函数都会导致DeveloperError异常。 因此,将返回值(undefined)赋给对象,如示例所示。
Throws:
Example:
e = e && e.destroy();
See:

getGeometryInstanceAttributes(id)Object

返回 GeometryInstance 的每个实例的可修改属性。
Name Type Description
id * GeometryInstance的id.
Returns:
以属性格式表示的类型化数组;如果没有实例,则未定义类型。
Throws:
  • DeveloperError : 必须在调用getGeometryInstanceAttributes之前调用update。
Example:
var attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);

isDestroyed()Boolean

如果该对象没被销毁,返回false。

如果该对象已经被销毁,使用isDestroyed 会触发 DeveloperError 异常。
Returns:
false
See:
在 Viewer 或 CesiumWidget 渲染场景时调用至获取渲染该图元所需的绘制命令。

不要直接调用此函数。这只是为了列出渲染场景时可能出现的异常:

Throws:
  • DeveloperError : 所有几何实例必须具有相同的primaryType。
  • DeveloperError : 外观和材质具有相同名称的uniform。
  • DeveloperError : 并不是所有的几何图形实例都具有相同的颜色属性。