GroundPrimitive 表示场景中覆盖在地形或 3D Tiles 上的几何。
图元将几何实例与描述完整着色(包括
Material 和 RenderState)的 Appearance 结合起来。粗略地说,几何实例定义了结构和位置,
而外观定义了视觉特征。将几何与外观解耦使我们能够混合搭配其中大部分,
并相互独立地添加新的几何或外观。
要使用具有不同 PerInstanceColors 或除 PerInstanceColorAppearance 之外材质的 GeometryInstances, 需要 WEBGL_depth_texture 扩展的支持。
带纹理的 GroundPrimitive 设计用于示意性(notional)图案,并非用于将纹理
精确地映射到地形——对于该用例,请使用 SingleTileImageryProvider。
为了正确渲染,此功能需要 EXT_frag_depth WebGL 扩展。对于不支持该扩展的硬件, 在某些视角下会出现渲染伪影(artifacts)。
有效几何包括 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 上创建并批处理。
-
Default Value:
true
classificationType : ClassificationType
确定地形、3D Tiles 或两者中哪些将被分类(classified)。
-
Default Value:
ClassificationType.BOTH
当为
true 时,几何顶点会被压缩,从而节省内存。
-
Default Value:
true
此属性仅用于调试;不适用于生产环境,也未经过优化。
绘制图元中每个绘制命令的包围球。
-
Default Value:
false
此属性仅用于调试;不适用于生产环境,也未经过优化。
绘制图元中每个几何的阴影体。
-
Default Value:
false
readonly geometryInstances : Array|GeometryInstance
使用此图元渲染的几何实例。如果图元在构造时
options.releaseGeometryInstances 为 true,则此属性可能为 undefined。
图元渲染后更改此属性无效。
-
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,在地形高度加载完成后 resolve。
确定是否支持 GroundPrimitive 渲染。
| Name | Type | Description |
|---|---|---|
scene |
Scene | 场景。 |
Returns:
如果支持 GroundPrimitives 则为
true;否则返回 false
检查给定的 Scene 是否支持 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 :必须在调用 getGeometryInstanceAttributes 之前先调用 update。
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 :对于同步的 GroundPrimitive,必须调用 GroundPrimitive.initializeTerrainHeights() 并等待返回的 promise resolve。
-
DeveloperError :所有实例几何必须具有相同的 primitiveType。
-
DeveloperError :Appearance 和材质具有同名的 uniform。
