Scene
中的几何体。几何图形可以来自单个GeometryInstance
如下面的示例1所示,或从实例数组中,即使几何体来自不同的
几何类型,例如RectangleGeometry
和EllipsoidGeometry
,如代码示例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
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
具有以下属性的对象:
|
Examples:
// 1. Draw a translucent ellipse on the surface with a checkerboard pattern
var 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
var 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)
}
});
var 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()
}));
See:
Members
-
Default Value:
true
appearance : Appearance
Appearance
是用来给这个原始人着色的。每个几何体
实例以相同的外观着色。一些表象,比如
PerInstanceColorAppearance
允许给每个实例唯一
属性。-
Default Value:
undefined
-
Default Value:
true
true
时,几何体顶点被压缩,这将节省内存。-
Default Value:
true
true
时,渲染器截锥和水平面剔除基本体的命令
基于它们的边界体积。将此值设置为false
可获得较小的性能增益
如果手动剔除基本体。-
Default Value:
true
Draws the bounding sphere for each draw command in the primitive.
-
Default Value:
false
depthFailAppearance : Appearance
Appearance
曾在深度测试失败时给这个原始体着色。每个几何体
实例以相同的外观着色。一些表象,比如
PerInstanceColorAppearance
允许给每个实例唯一
属性。
When using an appearance that requires a color attribute, like PerInstanceColorAppearance, add a depthFailColor per-instance attribute instead.
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
options.releaseGeometryInstances
,则为undefined
构造原语时为true
。
Changing this property after the primitive is rendered has no effect.
-
Default Value:
undefined
-
Default Value:
false
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame
。
This property is only supported in 3D mode.
-
Default Value:
Matrix4.IDENTITY
Example:
var origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
Primitive#update
被称为。readonly readyPromise : Promise.<Primitive>
true
时,原语不保留对输入geometryInstances
的引用以节省内存。-
Default Value:
true
shadows : ShadowMode
-
Default Value:
ShadowMode.DISABLED
-
Default Value:
true
true
时,几何体顶点针对顶点前后着色器缓存进行了优化。-
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 :此对象已销毁,即调用destroy()。
Example:
e = e && e.destroy();
See:
GeometryInstance
的每个实例的可修改属性。Name | Type | Description |
---|---|---|
id |
* | GeometryInstance 的id。 |
Returns:
Throws:
-
DeveloperError :必须在调用getGeometryInstanceAttributes之前调用update。
Example:
var 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
;否则为false
。See:
Viewer
或CesiumWidget
将场景渲染到
获取渲染此基本体所需的draw命令。
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 :所有实例几何图形必须具有相同的基本类型。
-
DeveloperError :外观和材质具有相同名称的制服。
-
DeveloperError : Primitive.modelMatrix仅在3D模式下支持。
-
RuntimeError :使用逐实例属性渲染基本体需要顶点纹理获取支持。顶点纹理图像单元的最大数目必须大于零。