# GroundPrimitive

#### new Cesium.GroundPrimitive(options)
Scene/GroundPrimitive.js 116

A ground primitive represents geometry draped over terrain or 3D Tiles in the `Scene`.

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.

Support for the WEBGL_depth_texture extension is required to use GeometryInstances with different PerInstanceColors or materials besides PerInstanceColorAppearance.

Textured GroundPrimitives were designed for notional patterns and are not meant for precisely mapping textures to terrain - for that use case, use `SingleTileImageryProvider`.

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.

Valid geometries are `CircleGeometry`, `CorridorGeometry`, `EllipseGeometry`, `PolygonGeometry`, and `RectangleGeometry`.

Name | Type | Description
--- | --- | ---
`options` | Object | optional Object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`geometryInstances` | Array | GeometryInstance |  | optional The geometry instances to render.
`appearance` | Appearance |  | optional The appearance used to render the primitive. Defaults to a flat PerInstanceColorAppearance when GeometryInstances have a color attribute.
`show` | Boolean | `true` | optional Determines if this primitive will be shown.
`vertexCacheOptimize` | Boolean | `false` | optional When `true`, geometry vertices are optimized for the pre and post-vertex-shader caches.
`interleave` | Boolean | `false` | optional When `true`, geometry vertex attributes are interleaved, which can slightly improve rendering performance but increases load time.
`compressVertices` | Boolean | `true` | optional When `true`, the geometry vertices are compressed, which will save memory.
`releaseGeometryInstances` | Boolean | `true` | optional When `true`, the primitive does not keep a reference to the input `geometryInstances` to save memory.
`allowPicking` | Boolean | `true` | optional When `true`, each geometry instance will only be pickable with `Scene#pick`. When `false`, GPU memory is saved.
`asynchronous` | Boolean | `true` | optional Determines if the primitive will be created asynchronously or block until ready. If false initializeTerrainHeights() must be called first.
`classificationType` | ClassificationType | `ClassificationType.BOTH` | optional Determines whether terrain, 3D Tiles or both will be classified.
`debugShowBoundingVolume` | Boolean | `false` | optional For debugging only. Determines if this primitive's commands' bounding spheres are shown.
`debugShowShadowVolume` | Boolean | `false` | optional For debugging only. Determines if the shadow volume for each geometry in the primitive is drawn. Must be `true` on creation for the volumes to be created before the geometry is released or options.releaseGeometryInstance must be `false`.
`swipeEnabled` | Boolean | `false` | optional 开启卷帘对比分析
`swipeInverse` | Number | `0` | optional 单独控制该图层是否进行反转。小于0不反转，大于0时反转，等于0失效。该属性的控制优先级高于`Scene#swipeController`中的inverse属性.若要取消该属性对本图层的独立控制需要将该属性置为0。

##### Example:

    // Example 1: Create primitive with a single instance
    var 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
    var color = new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5); // Both instances must have the same color.
    var 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
      }
    });
    var 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:

- Primitive
- ClassificationPrimitive
- GeometryInstance
- Appearance

### Members

#### readonly allowPicking : Boolean
Scene/GroundPrimitive.js 302

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

Default Value: `true`

#### appearance : Appearance
Scene/GroundPrimitive.js 146

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.

Default Value: `undefined`

#### readonly asynchronous : Boolean
Scene/GroundPrimitive.js 318

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

Default Value: `true`

#### classificationType : ClassificationType
Scene/GroundPrimitive.js 178

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

Default Value: `ClassificationType.BOTH`

#### readonly compressVertices : Boolean
Scene/GroundPrimitive.js 334

When `true`, geometry vertices are compressed, which will save memory.

Default Value: `true`

#### debugShowBoundingVolume : Boolean
Scene/GroundPrimitive.js 189

This property is for debugging only; it is not for production use nor is it optimized.

Draws the bounding sphere for each draw command in the primitive.

Default Value: `false`

#### debugShowShadowVolume : Boolean
Scene/GroundPrimitive.js 201

This property is for debugging only; it is not for production use nor is it optimized.

Draws the shadow volume for each geometry in the primitive.

Default Value: `false`

#### readonly geometryInstances : Array|GeometryInstance
Scene/GroundPrimitive.js 161

The geometry instances rendered with this primitive. This may be `undefined` if `options.releaseGeometryInstances` is `true` when the primitive is constructed.

Changing this property after the primitive is rendered has no effect.

Default Value: `undefined`

#### readonly interleave : Boolean
Scene/GroundPrimitive.js 270

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

Default Value: `false`

#### readonly ready : Boolean
Scene/GroundPrimitive.js 350

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.

#### readonly readyPromise : Promise.<GroundPrimitive>
Scene/GroundPrimitive.js 362

Gets a promise that resolves when the primitive is ready to render.

#### readonly releaseGeometryInstances : Boolean
Scene/GroundPrimitive.js 286

When `true`, the primitive does not keep a reference to the input `geometryInstances` to save memory.

Default Value: `true`

#### show : Boolean
Scene/GroundPrimitive.js 170

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

Default Value: `true`

#### swipeEnabled : Boolean
Scene/GroundPrimitive.js 374

开启卷帘对比分析

Default Value: `false`

#### swipeInverse : Number
Scene/GroundPrimitive.js 394

单独控制该图层是否进行反转，小于0不反转，大于0时反转，等于0失效。该属性的控制优先级高于`Scene#swipeController`中的inverse属性.若要取消该属性对本图层的独立控制需要将该属性置为0.

Default Value: `0`

#### readonly vertexCacheOptimize : Boolean
Scene/GroundPrimitive.js 254

When `true`, geometry vertices are optimized for the pre and post-vertex-shader caches.

Default Value: `true`

### Methods

#### static Cesium.GroundPrimitive.initializeTerrainHeights() → Promise.<void>
Scene/GroundPrimitive.js 620

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

##### Returns:

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

#### static Cesium.GroundPrimitive.isSupported(scene) → Boolean
Scene/GroundPrimitive.js 416

Determines if GroundPrimitive rendering is supported.

Name | Type | Description
--- | --- | ---
`scene` | Scene | The scene.

##### Returns:

`true` if GroundPrimitives are supported; otherwise, returns `false`

#### static Cesium.GroundPrimitive.supportsMaterials(scene) → Boolean
Scene/GroundPrimitive.js 892

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

Name | Type | Description
--- | --- | ---
`scene` | Scene | The current scene.

##### Returns:

Whether or not the current scene supports materials on GroundPrimitives.

#### destroy()
Scene/GroundPrimitive.js 869

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:

- GroundPrimitive#isDestroyed

#### getGeometryInstanceAttributes(id) → Object
Scene/GroundPrimitive.js 829

Returns the modifiable per-instance attributes for a `GeometryInstance`.

Name | Type | Description
--- | --- | ---
`id` | * | The id of the `GeometryInstance`.

##### Returns:

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

##### Throws:

- DeveloperError : must call update before calling getGeometryInstanceAttributes.

##### Example:

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

#### isDestroyed() → Boolean
Scene/GroundPrimitive.js 849

Returns true if this object was destroyed; otherwise, false.

If this object was destroyed, it should not be used; calling any function other than `isDestroyed` will result in a `DeveloperError` exception.

##### Returns:

`true` if this object was destroyed; otherwise, `false`.

##### See:

- GroundPrimitive#destroy

#### update()
Scene/GroundPrimitive.js 636

Called when `Viewer` or `CesiumWidget` render the scene to get the draw commands needed to render this primitive.

Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:

##### Throws:

- DeveloperError : For synchronous GroundPrimitive, you must call GroundPrimitive.initializeTerrainHeights() and wait for the returned promise to resolve.
- DeveloperError : All instance geometries must have the same primitiveType.
- DeveloperError : Appearance and material have a uniform with the same name.