GroundPrimitive

new Cesium.GroundPrimitive(options)

地面原语表示在 Scene 中悬挂于地形或 3D Tiles 上的几何体。

原语将几何体实例与描述完整着色的 Appearance 结合在一起,包括 MaterialRenderState。大致而言,几何体实例定义了结构和位置, 而外观定义了视觉特征。解耦几何体和外观使我们能够自由混合 和匹配大多数内容,并独立添加新的几何体或外观。

使用具有不同 PerInstanceColors 或材料的 GeometryInstances 需要支持 WEBGL_depth_texture 扩展。

带纹理的 GroundPrimitives 是为概念图案设计的,旨在不精确地将 纹理映射到地形 - 对于该用例,请使用 SingleTileImageryProvider

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

有效几何体包括 CircleGeometryCorridorGeometryEllipseGeometryPolygonGeometryRectangleGeometry

Name Type Description
options object optional 包含以下属性的对象:
Name Type Default Description
geometryInstances Array | GeometryInstance optional 要渲染的几何体实例。
appearance Appearance optional 用于渲染原语的外观。默认情况下,当 GeometryInstances 具有颜色属性时,默认为平面 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 才能生效。
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 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

在原语渲染后更改此属性没有效果。

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:
如果支持 GroundPrimitives,则返回 true;否则返回 false

static Cesium.GroundPrimitive.supportsMaterials(scene)boolean

检查给定的场景是否支持 GroundPrimitives 上的材料。 GroundPrimitives 上的材料需要支持 WEBGL_depth_texture 扩展。
Name Type Description
scene Scene 当前场景。
Returns:
当前场景是否支持 GroundPrimitives 上的材料。
销毁此对象所持有的 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);

isDestroyed()boolean

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

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

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

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

Throws:
  • DeveloperError : 对于同步的 GroundPrimitive,必须调用 GroundPrimitive.initializeTerrainHeights() 并等待返回的 Promise 解析。
  • DeveloperError : 所有实例几何体必须具有相同的 primitiveType。
  • DeveloperError : Appearance 和 material 具有相同名称的 uniform。
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.