Scene 中的地形或 3D 瓦片上的几何图形。
图元将几何实例与描述完整着色(包括 Material 和 RenderState)的 Appearance 结合使用。粗略来说,几何实例定义结构和位置,外观定义视觉特征。将几何和外观解耦允许我们混合搭配大多数组件,并独立添加新的几何或外观。
若要使用具有不同 PerInstanceColor 或除 PerInstanceColorAppearance 之外的材质的 GeometryInstance,需要支持 WEBGL_depth_texture 扩展。
纹理地面图元专为概念性图案设计,不用于精确将纹理映射到地形——对于该用例,请使用 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
-
Default Value:
true
classificationType : ClassificationType
-
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
GroundPrimitive#update 时将渲染该图元。
true 时,图元不会保留输入 geometryInstances 的引用以节省内存。
-
Default Value:
true
-
Default Value:
true
true 时,几何顶点会针对顶点着色器前后的缓存进行优化。
-
Default Value:
true
Methods
Returns:
| Name | Type | Description |
|---|---|---|
scene |
Scene | 场景。 |
Returns:
true,否则返回 false
| Name | Type | Description |
|---|---|---|
scene |
Scene | 当前场景。 |
Returns:
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:
GeometryInstance 的可修改逐实例属性。
| Name | Type | Description |
|---|---|---|
id |
* |
GeometryInstance 的 id。 |
Returns:
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 之外的任何函数都会导致 DeveloperError 异常。
Returns:
true,否则返回 false。
Throws:
-
DeveloperError : 对于同步 GroundPrimitive,必须调用 GroundPrimitive.initializeTerrainHeights() 并等待返回的 Promise 解析。
-
DeveloperError : 所有实例几何必须具有相同的 primitiveType。
-
DeveloperError : Appearance 和材质不能具有相同名称的 uniform。
