地面基元表示覆盖在
Scene
中的地形或 3D 瓦片上的几何体。
基元将几何体实例与描述完整着色的 Appearance
组合在一起,包括
Material
和 RenderState
的 RenderState} 中。 粗略地说,geometry 实例定义了结构和位置,
和外观定义视觉特征。 解耦的几何图形和外观使我们能够混合
并匹配其中的大多数,并彼此独立地添加新的几何图形或外观。
要使用具有不同 PerInstanceColors 的 GeometryInstances,需要支持 WEBGL_depth_texture 扩展 或除 PerInstanceColorAppearance 之外的材质。
Textured GroundPrimitives 是为概念模式设计的,而不是用于精确映射的
纹理到地形 - 对于该用例,请使用 SingleTileImageryProvider
。
为了正确渲染,此功能需要 EXT_frag_depth WebGL 扩展。对于不支持此扩展的硬件,有 将在某些视角下渲染伪影。
有效的几何图形包括 CircleGeometry
、CorridorGeometry
、EllipseGeometry
、PolygonGeometry
和 RectangleGeometry
。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
对象,具有以下属性:
|
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
-
Default Value:
true
appearance : Appearance
用于对此基元进行着色的
Appearance
。每个几何体
实例以相同的外观进行着色。 一些外观,如
PerInstanceColorAppearance
允许为每个实例指定唯一性
性能。
-
Default Value:
undefined
确定是否将在 Web Worker 上创建和批处理 geometry 实例。
-
Default Value:
true
classificationType : ClassificationType
确定是否对地形、3D 瓦片或两者进行分类。
-
Default Value:
ClassificationType.BOTH
如果为
true
,则几何顶点将被压缩,这将节省内存。
-
Default Value:
true
此属性仅用于调试;它不用于生产用途,也未进行优化。
为基元中的每个绘制命令绘制边界球体。
-
Default Value:
false
此属性仅用于调试;它不用于生产用途,也未进行优化。
为基本体中的每个几何体绘制阴影体积。
-
Default Value:
false
readonly geometryInstances : Array|GeometryInstance
使用此基元渲染的几何体实例。 这可能会
如果
options.releaseGeometryInstances
为 undefined
在构造基元时为 true
。
在渲染基元后更改此属性不起作用。
-
Default Value:
undefined
确定几何体顶点属性是否交错,这可以略微提高渲染性能。
-
Default Value:
false
确定基元是否完整并准备好进行渲染。 如果此属性为
true,则基元将在下次
GroundPrimitive#update
时渲染
被调用。
如果为
true
,则基元不会保留对输入 geometryInstances
的引用以节省内存。
-
Default Value:
true
确定是否显示基元。 这会影响所有几何体
实例。
-
Default Value:
true
如果为
true
,则几何顶点将针对前顶点着色器缓存和后顶点着色器缓存进行优化。
-
Default Value:
true
Methods
初始化最小和最大地形高度。仅当您正在创建
GroundPrimitive 同步。
Returns:
一个 Promise,一旦地形高度被加载,它就会被解析。
确定是否支持 GroundPrimitive 渲染。
Name | Type | Description |
---|---|---|
scene |
Scene | 场景。 |
Returns:
true
(如果支持 GroundPrimitives);否则,返回 false
检查给定的场景是否支持 GroundPrimitives 上的材质。
GroundPrimitives 上的材质需要支持 WEBGL_depth_texture 扩展。
Name | Type | Description |
---|---|---|
scene |
Scene | 当前场景。 |
Returns:
当前场景是否支持 GroundPrimitives 上的材质。
销毁此对象持有的 WebGL 资源。 销毁对象允许确定性
释放 WebGL 资源,而不是依赖垃圾回收器来销毁这个对象。
一旦对象被销毁,就不应该使用它;调用
isDestroyed
将导致 DeveloperError
异常。 因此
将返回值 (undefined
) 分配给对象,如示例中所示。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
Example:
e = e && e.destroy();
See:
返回
GeometryInstance
的可修改的每实例属性。
Name | Type | Description |
---|---|---|
id |
* |
GeometryInstance 的 ID。 |
Returns:
属性格式的类型化数组,如果没有 id 的实例,则为 undefined。
Throws:
-
DeveloperError : must call update before calling getGeometryInstanceAttributes.
Example:
const attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);
如果此对象已销毁,则返回 true;否则为 false。
如果此对象已销毁,则不应使用;调用
isDestroyed
将导致 DeveloperError
异常。
Returns:
true
,如果此对象被销毁;否则为 false
。
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.