PerInstanceColorAppearance

new Cesium.PerInstanceColorAppearance(options)

带有颜色属性的GeometryInstance实例的外观。 这允许使用相同的Primitive绘制几个几何实例,每个实例使用不同的颜色,如下面的第二个示例所示。
Name Type Description
options Object optional 具有下列属性的对象:
Name Type Default Description
flat Boolean false optionaltrue时,在片段着色器中使用了平面着色,这意味着没有考虑到光照。
faceForward Boolean !options.closed optionaltrue时,片段着色器会根据需要翻转表面法线, 以确保法线面对观察者,避免出现黑斑。当几何图形的两侧都应像WallGeometry 一样着色时,这很有用。
translucent Boolean true optionaltrue时,几何图形应该是半透明的,因此 PerInstanceColorAppearance#renderState启用了alpha混合。
closed Boolean false optionaltrue时,几何图形将被关闭,因此PerInstanceColorAppearance#renderState启用了背面剔除。
vertexShaderSource String optional 可选的GLSL顶点着色器源覆盖默认的顶点着色器。
fragmentShaderSource String optional 可选的GLSL片段着色器源覆盖默认的片段着色器。
renderState RenderState optional 可选的渲染状态来覆盖默认的渲染状态。
Example:
// 一条白色的线段
var 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
  })
});

// 一个图元中有两个矩形,并且具有不同的颜色。
var 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)
  }
});

var 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)
  }
});

var rectanglePrimitive = new Cesium.Primitive({
  geometryInstances : [instance, anotherInstance],
  appearance : new Cesium.PerInstanceColorAppearance()
});

Members

staticconstantCesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT : VertexFormat

PerInstanceColorAppearance#flattrue时, 所有PerInstanceColorAppearance实例都兼容的VertexFormat。这只需要一个position属性。

staticconstantCesium.PerInstanceColorAppearance.VERTEX_FORMAT : VertexFormat

所有PerInstanceColorAppearance实例都兼容的VertexFormat。 这只需要position and normal 属性。

readonlyclosed : Boolean

true时,几何图形将被关闭,因此PerInstanceColorAppearance#renderState启用了后表面剔除。
Default Value: false

readonlyfaceForward : Boolean

true时,片段着色器会根据需要翻转表面法线, 以确保法线面对观察者,避免出现黑斑。当几何图形的两侧都应像WallGeometry 一样着色时,这很有用。
Default Value: true
true时,在片段着色器中使用了平面着色,这意味着没有考虑到光照。
Default Value: false

readonlyfragmentShaderSource : String

片段着色器的GLSL源代码。
此属性是Appearance接口的一部分,但PerInstanceColorAppearance不使用此属性,因为使用的是完全自定义的片段着色器。
Default Value: undefined

readonlyrenderState : Object

渲染几何图形时的WEBGL状态。

渲染状态可以在构造一个PerInstanceColorAppearance例时显式定义, 也可以通过PerInstanceColorAppearance#translucentPerInstanceColorAppearance#closed隐式设置。

true时,几何图形应该是半透明的,因此PerInstanceColorAppearance#renderState启用了alpha混合。
Default Value: true
与此外观实例兼容的VertexFormat。 几何图形可以有更多的顶点属性,而且仍然是兼容的——以潜在的性能成本为代价——但它不能有更少的顶点属性。

readonlyvertexShaderSource : String

顶点着色器的GLSL源代码。

Methods

getFragmentShaderSource()String

Returns:
完整的GLSL片段着色器。

getRenderState()Object

创建渲染状态。
Returns:
渲染状态。

isTranslucent()Boolean

确定几何图形是否是半透明 PerInstanceColorAppearance#translucent.
Returns:
如果是半透明,返回true。