Scene
中的几何体。 几何体可以来自单个 GeometryInstance
(如下面的示例 1 所示)或实例数组,即使几何体来自不同的
几何类型,例如 RectangleGeometry
和 EllipsoidGeometry
,如代码示例 2 所示。
基元将几何体实例与描述完整着色的 Appearance
组合在一起,包括
Material
和 RenderState
的 RenderState} 中。 粗略地说,geometry 实例定义了结构和位置,
和外观定义视觉特征。 解耦的几何图形和外观使我们能够混合
并匹配其中的大多数,并彼此独立地添加新的几何图形或外观。
将多个实例组合到一个基元中称为批处理,可显著提高静态数据的性能。
实例可以单独选取;Scene#pick
返回其 GeometryInstance#id
。 用
每个实例的外观(如 PerInstanceColorAppearance
),每个实例也可以具有唯一的颜色。
Geometry
可以在 Web Worker 或主线程上创建和批处理。前两个示例
显示将使用几何描述在 Web Worker 上创建的几何。第三个示例
演示如何通过显式调用 createGeometry
方法在主线程上创建几何图形。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
对象,具有以下属性:
|
Examples:
// 1. Draw a translucent ellipse on the surface with a checkerboard pattern
const instance = new Cesium.GeometryInstance({
geometry : new Cesium.EllipseGeometry({
center : Cesium.Cartesian3.fromDegrees(-100.0, 20.0),
semiMinorAxis : 500000.0,
semiMajorAxis : 1000000.0,
rotation : Cesium.Math.PI_OVER_FOUR,
vertexFormat : Cesium.VertexFormat.POSITION_AND_ST
}),
id : 'object returned when this instance is picked and to get/set per-instance attributes'
});
scene.primitives.add(new Cesium.Primitive({
geometryInstances : instance,
appearance : new Cesium.EllipsoidSurfaceAppearance({
material : Cesium.Material.fromType('Checkerboard')
})
}));
// 2. Draw different instances each with a unique color
const rectangleInstance = new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0),
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}),
id : 'rectangle',
attributes : {
color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
}
});
const ellipsoidInstance = new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),
vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL
}),
modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),
id : 'ellipsoid',
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
}
});
scene.primitives.add(new Cesium.Primitive({
geometryInstances : [rectangleInstance, ellipsoidInstance],
appearance : new Cesium.PerInstanceColorAppearance()
}));
// 3. Create the geometry on the main thread.
scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : Cesium.EllipsoidGeometry.createGeometry(new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),
vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL
})),
modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),
id : 'ellipsoid',
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
}
}),
appearance : new Cesium.PerInstanceColorAppearance(),
asynchronous : false
}));
See:
Members
-
Default Value:
true
appearance : Appearance
Appearance
。每个几何体
实例以相同的外观进行着色。 一些外观,如
PerInstanceColorAppearance
允许为每个实例指定唯一性
性能。
-
Default Value:
undefined
-
Default Value:
true
true
,则几何顶点将被压缩,这将节省内存。
-
Default Value:
true
true
,则渲染器视锥体会剔除,Horizon 会剔除基元的命令
基于其边界体积。 将此设置为 false
可略微提高性能
如果要手动剔除基元。
-
Default Value:
true
为基元中的每个绘制命令绘制边界球体。
-
Default Value:
false
depthFailAppearance : Appearance
Appearance
用于在深度测试失败时对此基元进行着色。每个几何体
实例以相同的外观进行着色。 一些外观,如
PerInstanceColorAppearance
允许为每个实例指定唯一性
性能。
当使用需要 color 属性的外观(如 PerInstanceColorAppearance)时, 请改为添加 depthFailColor 每个实例属性。
需要 EXT_frag_depth WebGL 扩展才能正确呈现。如果该扩展不受支持,则 可能存在伪影。
-
Default Value:
undefined
readonly geometryInstances : Array.<GeometryInstance>|GeometryInstance
options.releaseGeometryInstances
为 undefined
在构造基元时为 true
。
在渲染基元后更改此属性不起作用。
-
Default Value:
undefined
-
Default Value:
false
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame
提供。
此属性仅在 3D 模式下受支持。
-
Default Value:
Matrix4.IDENTITY
Example:
const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
Primitive#update
时呈现
被调用。
Example:
// Wait for a primitive to become ready before accessing attributes
const removeListener = scene.postRender.addEventListener(() => {
if (!frustumPrimitive.ready) {
return;
}
const attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
removeListener();
});
true
,则基元不会保留对输入 geometryInstances
的引用以节省内存。
-
Default Value:
true
-
Default Value:
ShadowMode.DISABLED
-
Default Value:
true
true
,则几何顶点将针对前顶点着色器缓存和后顶点着色器缓存进行优化。
-
Default Value:
true
Methods
一旦对象被销毁,就不应该使用它;调用
isDestroyed
将导致 DeveloperError
异常。 因此
将返回值 (undefined
) 分配给对象,如示例中所示。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
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);
attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(100.0, 10000.0);
attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(Cartesian3.IDENTITY);
如果此对象已销毁,则不应使用;调用
isDestroyed
将导致 DeveloperError
异常。
Returns:
true
,如果此对象被销毁;否则为 false
。
See:
Throws:
-
DeveloperError : All instance geometries must have the same primitiveType.
-
DeveloperError : Appearance and material have a uniform with the same name.
-
DeveloperError : Primitive.modelMatrix is only supported in 3D mode.
-
RuntimeError : Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.