一种用于带有颜色属性的
GeometryInstance 实例的外观(appearance)。
这样,多个各自具有不同颜色的几何体实例就可以
使用同一个 Primitive 进行绘制,如下方第二个示例所示。
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
Object with the following properties:
|
Example:
// A solid white line segment
const primitive = new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.SimplePolylineGeometry({
positions : Cesium.Cartesian3.fromDegreesArray([
0.0, 0.0,
5.0, 0.0
])
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 1.0))
}
}),
appearance : new Cesium.PerInstanceColorAppearance({
flat : true,
translucent : false
})
});
// Two rectangles in a primitive, each with a different color
const instance = new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0)
}),
attributes : {
color : new Cesium.ColorGeometryInstanceAttribute(1.0, 0.0, 0.0, 0.5)
}
});
const anotherInstance = new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(0.0, 40.0, 10.0, 50.0)
}),
attributes : {
color : new Cesium.ColorGeometryInstanceAttribute(0.0, 0.0, 1.0, 0.5)
}
});
const rectanglePrimitive = new Cesium.Primitive({
geometryInstances : [instance, anotherInstance],
appearance : new Cesium.PerInstanceColorAppearance()
});
Members
static constant Cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT : VertexFormat
当
PerInstanceColorAppearance#flat 为 true 时,所有 PerInstanceColorAppearance 实例都兼容的 VertexFormat。
它只需要一个 position 属性。
static constant Cesium.PerInstanceColorAppearance.VERTEX_FORMAT : VertexFormat
当为
true 时,几何体应为闭合的,因此
PerInstanceColorAppearance#renderState 启用了背面剔除。
如果观察者进入几何体内部,它将不可见。
-
Default Value:
false
当为
true 时,片元着色器会按需翻转表面法线,
以确保法线朝向观察者,从而避免暗斑。当几何体的两侧都应
像 WallGeometry 那样被着色时,这很有用。
-
Default Value:
true
当为
true 时,在片元着色器中使用平面着色,
即不考虑光照。
-
Default Value:
false
片元着色器的 GLSL 源码。
此属性属于
Appearance 接口的一部分,但 PerInstanceColorAppearance 并未使用它,因为它使用了完全自定义的片元着色器。
-
Default Value:
undefined
渲染几何体时要使用的 WebGL 固定功能状态(fixed-function state)。
渲染状态可以在构造 PerInstanceColorAppearance 实例时显式定义,
也可以经由 PerInstanceColorAppearance#translucent
和 PerInstanceColorAppearance#closed 隐式设置。
当为
true 时,几何体应呈现为半透明,因此
PerInstanceColorAppearance#renderState 启用了 alpha 混合。
-
Default Value:
true
readonly vertexFormat : VertexFormat
此外观实例所兼容的
VertexFormat。
几何体可以拥有更多的顶点属性且仍然兼容——但这可能带来性能开销——但不能更少。
顶点着色器的 GLSL 源码。
Methods
以过程化方式创建完整的 GLSL 片元着色器源码。对于
PerInstanceColorAppearance,
它派生自 PerInstanceColorAppearance#fragmentShaderSource、PerInstanceColorAppearance#flat
和 PerInstanceColorAppearance#faceForward。
Returns:
完整的 GLSL 片元着色器源码。
创建一个渲染状态。这不是最终的渲染状态实例,而是
可以包含与上下文中创建的渲染状态相同的渲染状态属性子集。
Returns:
渲染状态。
根据
PerInstanceColorAppearance#translucent 判断几何体是否半透明。
Returns:
若外观为半透明则为
true。
