Skip to content

KBE3D / KBCore / Cesium / GroundPrimitive

类: GroundPrimitive

A ground primitive represents geometry draped over terrain or 3D Tiles in the Scene. <p> A primitive combines geometry instances with an Appearance that describes the full shading, including Material and RenderState. Roughly, the geometry instance defines the structure and placement, and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix and match most of them and add a new geometry or appearance independently of each other. </p> <p> Support for the WEBGL_depth_texture extension is required to use GeometryInstances with different PerInstanceColors or materials besides PerInstanceColorAppearance. </p> <p> Textured GroundPrimitives were designed for notional patterns and are not meant for precisely mapping textures to terrain - for that use case, use SingleTileImageryProvider. </p> <p> For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there will be rendering artifacts for some viewing angles. </p> <p> Valid geometries are CircleGeometry, CorridorGeometry, EllipseGeometry, PolygonGeometry, and RectangleGeometry. </p>

示例

ts
// 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]
}));

参数

Object with the following properties:

参数

The geometry instances to render.

参数

The appearance used to render the primitive. Defaults to a flat PerInstanceColorAppearance when GeometryInstances have a color attribute.

参数

Determines if this primitive will be shown.

参数

When <code>true</code>, geometry vertices are optimized for the pre and post-vertex-shader caches.

参数

When <code>true</code>, geometry vertex attributes are interleaved, which can slightly improve rendering performance but increases load time.

参数

When <code>true</code>, the geometry vertices are compressed, which will save memory.

参数

When <code>true</code>, the primitive does not keep a reference to the input <code>geometryInstances</code> to save memory.

参数

When <code>true</code>, each geometry instance will only be pickable with Scene#pick. When <code>false</code>, GPU memory is saved.

参数

Determines if the primitive will be created asynchronously or block until ready. If false initializeTerrainHeights() must be called first.

参数

Determines whether terrain, 3D Tiles or both will be classified.

参数

For debugging only. Determines if this primitive's commands' bounding spheres are shown.

参数

For debugging only. Determines if the shadow volume for each geometry in the primitive is drawn. Must be <code>true</code> on creation for the volumes to be created before the geometry is released or options.releaseGeometryInstance must be <code>false</code>.

属性

appearance

appearance: Appearance

The Appearance used to shade this primitive. Each geometry instance is shaded with the same appearance. Some appearances, like PerInstanceColorAppearance allow giving each instance unique properties.


geometryInstances

readonly geometryInstances: any[] | GeometryInstance

The geometry instances rendered with this primitive. This may be <code>undefined</code> if <code>options.releaseGeometryInstances</code> is <code>true</code> when the primitive is constructed. <p> Changing this property after the primitive is rendered has no effect. </p>


show

show: boolean

Determines if the primitive will be shown. This affects all geometry instances in the primitive.


classificationType

classificationType: ClassificationType

Determines whether terrain, 3D Tiles or both will be classified.


debugShowBoundingVolume

debugShowBoundingVolume: boolean

This property is for debugging only; it is not for production use nor is it optimized. <p> Draws the bounding sphere for each draw command in the primitive. </p>


debugShowShadowVolume

debugShowShadowVolume: boolean

This property is for debugging only; it is not for production use nor is it optimized. <p> Draws the shadow volume for each geometry in the primitive. </p>


vertexCacheOptimize

readonly vertexCacheOptimize: boolean

When <code>true</code>, geometry vertices are optimized for the pre and post-vertex-shader caches.


interleave

readonly interleave: boolean

Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.


releaseGeometryInstances

readonly releaseGeometryInstances: boolean

When <code>true</code>, the primitive does not keep a reference to the input <code>geometryInstances</code> to save memory.


allowPicking

readonly allowPicking: boolean

When <code>true</code>, each geometry instance will only be pickable with Scene#pick. When <code>false</code>, GPU memory is saved.


asynchronous

readonly asynchronous: boolean

Determines if the geometry instances will be created and batched on a web worker.


compressVertices

readonly compressVertices: boolean

When <code>true</code>, geometry vertices are compressed, which will save memory.


ready

readonly ready: boolean

Determines if the primitive is complete and ready to render. If this property is true, the primitive will be rendered the next time that GroundPrimitive#update is called.

方法

isSupported()

static isSupported(scene: Scene): boolean

Determines if GroundPrimitive rendering is supported.

参数

scene

Scene

The scene.

返回

boolean

true if GroundPrimitives are supported; otherwise, returns false


initializeTerrainHeights()

static initializeTerrainHeights(): Promise<void>

Initializes the minimum and maximum terrain heights. This only needs to be called if you are creating the GroundPrimitive synchronously.

返回

Promise<void>

A promise that will resolve once the terrain heights have been loaded.


supportsMaterials()

static supportsMaterials(scene: Scene): boolean

Checks if the given Scene supports materials on GroundPrimitives. Materials on GroundPrimitives require support for the WEBGL_depth_texture extension.

参数

scene

Scene

The current scene.

返回

boolean

Whether or not the current scene supports materials on GroundPrimitives.


update()

update(): void

Called when Viewer or CesiumWidget render the scene to get the draw commands needed to render this primitive. <p> Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered: </p>

返回

void


getGeometryInstanceAttributes()

getGeometryInstanceAttributes(id: any): any

Returns the modifiable per-instance attributes for a GeometryInstance.

参数

id

any

The id of the GeometryInstance.

返回

any

The typed array in the attribute's format or undefined if the is no instance with id.

示例

ts
const attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);

isDestroyed()

isDestroyed(): boolean

Returns true if this object was destroyed; otherwise, false. <p> If this object was destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception. </p>

返回

boolean

true if this object was destroyed; otherwise, false.


destroy()

destroy(): void

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. <p> Once an object is destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception. Therefore, assign the return value (<code>undefined</code>) to the object as done in the example. </p>

返回

void

示例

ts
e = e && e.destroy();

构造函数

构造函数

new GroundPrimitive(options?: { geometryInstances?: any[] | GeometryInstance; appearance?: Appearance; show?: boolean; vertexCacheOptimize?: boolean; interleave?: boolean; compressVertices?: boolean; releaseGeometryInstances?: boolean; allowPicking?: boolean; asynchronous?: boolean; classificationType?: ClassificationType; debugShowBoundingVolume?: boolean; debugShowShadowVolume?: boolean; }): GroundPrimitive

参数

options?
geometryInstances?

any[] | GeometryInstance

appearance?

Appearance

show?

boolean

vertexCacheOptimize?

boolean

interleave?

boolean

compressVertices?

boolean

releaseGeometryInstances?

boolean

allowPicking?

boolean

asynchronous?

boolean

classificationType?

ClassificationType

debugShowBoundingVolume?

boolean

debugShowShadowVolume?

boolean

返回

GroundPrimitive

KBE3D @3.0.0 Copyright © 2024-present KBE3D