Scene。几何形状可以来自单个 . The geometry can be from a single GeometryInstance
如下面的示例 1 所示,或者来自实例数组,即使几何图形来自不同的几何类型,例如 as shown in example 1 below, or from an array of instances, even if the geometry is from different geometry types, e.g., an RectangleGeometry 和一个 and an EllipsoidGeometry 如代码示例 2 所示。 as shown in Code Example 2.
基元将几何实例与 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.
将多个实例组合成一个原语称为批处理,可显着提高静态数据的性能。可以单独选取实例; Combining multiple instances into one primitive is called batching, and significantly improves performance for static data. Instances can be individually picked; Scene#pick 返回他们的 returns their GeometryInstance#id。使用每个实例的外观,例如 . Using per-instance appearances like PerInstanceColorAppearance,每个实例也可以有唯一的颜色。 , each instance can also have a unique color.
Geometry 可以在网络工作者或主线程上创建和批处理。前两个示例显示了将使用几何描述在 Web Worker 上创建的几何。第三个示例展示了如何通过显式调用在主线程上创建几何图形 can either be created and batched on a web worker or the main thread. The first two examples show geometry that will be created on a web worker by using the descriptions of the geometry. The third example shows how to create the geometry on the main thread by explicitly calling the createGeometry method.
| 名称 Name | 类型 Type | 说明 Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选 optional
具有以下属性的对象: Object with the following properties:
|
示例: 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
true,每个几何实例只能通过以下方式选取 , each geometry instance will only be pickable with Scene#pick。当 . When false,节省了GPU内存。 * , GPU memory is saved. *
-
默认值: Default Value:
true
appearance : Appearance
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
-
默认值: Default Value:
true
true,几何顶点被压缩,这将节省内存。 , geometry vertices are compressed, which will save memory.
-
默认值: Default Value:
true
true,渲染器视锥体剔除和地平线剔除基元的命令基于其边界体积。将其设置为 , the renderer frustum culls and horizon culls the primitive's commands based on their bounding volume. Set this to false 如果您手动剔除基元,则会获得较小的性能提升。 for a small performance gain if you are manually culling the primitive.
-
默认值: Default Value:
true
Draws the bounding sphere for each draw command in the primitive.
-
默认值: Default Value:
false
depthFailAppearance : Appearance
Appearance 用于在深度测试失败时对该图元进行着色。每个几何体实例都具有相同外观的阴影。有些外表,比如 used to shade this primitive when it fails the depth test. Each geometry instance is shaded with the same appearance. Some appearances, like
PerInstanceColorAppearance 允许赋予每个实例独特的属性。 allow giving each instance unique properties.
当使用需要颜色属性的外观(例如 PerInstanceColorAppearance)时,请改为添加每个实例的 depthFailColor 属性。 When using an appearance that requires a color attribute, like PerInstanceColorAppearance, add a depthFailColor per-instance attribute instead.
需要 EXT_frag_depth WebGL 扩展才能正确渲染。如果不支持扩展,则可能会出现工件。 Requires the EXT_frag_depth WebGL extension to render properly. If the extension is not supported, there may be artifacts.
-
默认值: Default Value:
undefined
readonly geometryInstances : Array.<GeometryInstance>|GeometryInstance
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
-
默认值: Default Value:
false
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame.
此属性仅在 3D 模式下受支持。 This property is only supported in 3D mode.
-
默认值: Default Value:
Matrix4.IDENTITY
示例: Example:
const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
Primitive#update
被称为。 is called.
示例: 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,原语不保留对输入的引用 , the primitive does not keep a reference to the input geometryInstances 以节省内存。 to save memory.
-
默认值: Default Value:
true
-
默认值: Default Value:
ShadowMode.DISABLED
-
默认值: Default Value:
true
true,几何顶点针对顶点着色器前和后的缓存进行了优化。 , geometry vertices are optimized for the pre and post-vertex-shader caches.
-
默认值: Default Value:
true
方法 Methods
一旦对象被销毁,就不应再使用;调用除 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 |
* |
的 ID The id of the GeometryInstance. |
返回: Returns:
抛出: Throws:
-
DeveloperError :必须在调用 getGeometryInstanceAttributes 之前调用 update。 : 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);
attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(100.0, 10000.0);
attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(Cartesian3.IDENTITY);
如果该对象被破坏,则不应使用它;调用除 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:
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 :所有实例几何图形必须具有相同的primitiveType。 : All instance geometries must have the same primitiveType.
-
DeveloperError :外观和材质具有同名统一。 : Appearance and material have a uniform with the same name.
-
DeveloperError :Primitive.modelMatrix 仅在 3D 模式下受支持。 : 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.
