GroundPrimitive

new Cesium.GroundPrimitive(options)

地面图元表示覆盖在 Scene 中的地形或 3D 瓦片上的几何图形。

图元将几何实例与描述完整着色(包括 MaterialRenderState)的 Appearance 结合使用。粗略来说,几何实例定义结构和位置,外观定义视觉特征。将几何和外观解耦允许我们混合搭配大多数组件,并独立添加新的几何或外观。

若要使用具有不同 PerInstanceColor 或除 PerInstanceColorAppearance 之外的材质的 GeometryInstance,需要支持 WEBGL_depth_texture 扩展。

纹理地面图元专为概念性图案设计,不用于精确将纹理映射到地形——对于该用例,请使用 SingleTileImageryProvider

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

支持的几何类型包括 CircleGeometryCorridorGeometryEllipseGeometryPolygonGeometryRectangleGeometry

Name Type Description
options object optional 包含以下属性的对象:
Name Type Default Description
geometryInstances Array | GeometryInstance optional 要渲染的几何实例。
appearance Appearance optional 用于渲染图元的外观。当 GeometryInstance 具有颜色属性时,默认使用扁平的 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 瓦片还是两者进行分类。
debugShowBoundingVolume boolean false optional 仅用于调试。确定是否显示此图元命令的边界球。
debugShowShadowVolume boolean false optional 仅用于调试。确定是否绘制图元中每个几何的阴影体。必须在创建时设为 true 才能在几何释放前创建阴影体,或 options.releaseGeometryInstance 必须为 false
Example:
// Example 1: Create primitive with a single instance
const rectangleInstance = new Cesium.GeometryInstance({
  geometry : new Cesium.RectangleGeometry({
    rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0)
  }),
  id : 'rectangle',
  attributes : {
    color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
  }
});
scene.primitives.add(new Cesium.GroundPrimitive({
  geometryInstances : rectangleInstance
}));

// Example 2: Batch instances
const color = new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5); // Both instances must have the same color.
const rectangleInstance = new Cesium.GeometryInstance({
  geometry : new Cesium.RectangleGeometry({
    rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0)
  }),
  id : 'rectangle',
  attributes : {
    color : color
  }
});
const ellipseInstance = new Cesium.GeometryInstance({
    geometry : new Cesium.EllipseGeometry({
        center : Cesium.Cartesian3.fromDegrees(-105.0, 40.0),
        semiMinorAxis : 300000.0,
        semiMajorAxis : 400000.0
    }),
    id : 'ellipse',
    attributes : {
        color : color
    }
});
scene.primitives.add(new Cesium.GroundPrimitive({
  geometryInstances : [rectangleInstance, ellipseInstance]
}));
See:

Members

readonly allowPicking : boolean

true 时,每个几何实例仅可通过 Scene#pick 拾取。当 false 时,可节省 GPU 内存。
Default Value: true
用于着色此图元的 Appearance。每个几何实例都使用相同的外观进行着色。某些外观(如 PerInstanceColorAppearance)允许为每个实例设置独特的属性。
Default Value: undefined

readonly asynchronous : boolean

确定几何实例是否将在 Web Worker 上创建和批处理。
Default Value: true
确定是对地形、3D 瓦片还是两者进行分类。
Default Value: ClassificationType.BOTH

readonly compressVertices : boolean

true 时,几何顶点会被压缩以节省内存。
Default Value: true

debugShowBoundingVolume : boolean

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

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

Default Value: false

debugShowShadowVolume : boolean

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

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

Default Value: false
使用此图元渲染的几何实例。如果在构造图元时 options.releaseGeometryInstancestrue,则此属性可能为 undefined

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

Default Value: undefined

readonly interleave : boolean

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

readonly releaseGeometryInstances : boolean

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

readonly vertexCacheOptimize : boolean

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

Methods

static Cesium.GroundPrimitive.initializeTerrainHeights()Promise.<void>

初始化最小和最大地形高度。仅当同步创建 GroundPrimitive 时需要调用此方法。
Returns:
当地形高度加载完成后将解析的 Promise。

static Cesium.GroundPrimitive.isSupported(scene)boolean

确定是否支持 GroundPrimitive 渲染。
Name Type Description
scene Scene 场景。
Returns:
如果支持 GroundPrimitive 则返回 true,否则返回 false

static Cesium.GroundPrimitive.supportsMaterials(scene)boolean

检查给定场景是否支持 GroundPrimitive 上的材质。 GroundPrimitive 上的材质需要支持 WEBGL_depth_texture 扩展。
Name Type Description
scene Scene 当前场景。
Returns:
当前场景是否支持 GroundPrimitive 上的材质。
Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.

Once an object is destroyed, it should not be used; calling any function other than isDestroyed will result in a DeveloperError exception. Therefore, assign the return value (undefined) to the object as done in the example.

Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
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);

isDestroyed()boolean

如果此对象已被销毁则返回 true,否则返回 false。

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

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

请勿直接调用此函数。此处仅记录场景渲染时可能传播的异常:

Throws:
  • DeveloperError : 对于同步 GroundPrimitive,必须调用 GroundPrimitive.initializeTerrainHeights() 并等待返回的 Promise 解析。
  • DeveloperError : 所有实例几何必须具有相同的 primitiveType。
  • DeveloperError : Appearance 和材质不能具有相同名称的 uniform。
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.