PerInstanceColorAppearance

new Cesium.PerInstanceColorAppearance(options)

一种用于带有颜色属性的 GeometryInstance 实例的外观(appearance)。 这样,多个各自具有不同颜色的几何体实例就可以 使用同一个 Primitive 进行绘制,如下方第二个示例所示。
Name Type Description
options object optional Object with the following properties:
Name Type Default Description
flat boolean false optional 当为 true 时,在片元着色器(fragment shader)中使用平面着色(flat shading),即不考虑光照。
faceForward boolean !options.closed optional 当为 true 时,片元着色器会按需翻转表面法线,以确保法线朝向观察者,从而避免暗斑。当几何体的两侧都应像 WallGeometry 那样被着色时,这很有用。
translucent boolean true optional 当为 true 时,几何体应呈现为半透明,因此 PerInstanceColorAppearance#renderState 启用了 alpha 混合。
closed boolean false optional 当为 true 时,几何体应为闭合的,因此 PerInstanceColorAppearance#renderState 启用了背面剔除。
vertexShaderSource string optional 用于覆盖默认顶点着色器的可选 GLSL 顶点着色器源码。
fragmentShaderSource string optional 用于覆盖默认片元着色器的可选 GLSL 片元着色器源码。
renderState object optional 用于覆盖默认渲染状态的可选渲染状态。
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#flattrue 时,所有 PerInstanceColorAppearance 实例都兼容的 VertexFormat。 它只需要一个 position 属性。

static constant Cesium.PerInstanceColorAppearance.VERTEX_FORMAT : VertexFormat

所有 PerInstanceColorAppearance 实例都兼容的 VertexFormat。它只需要 positionnormal 属性。
当为 true 时,几何体应为闭合的,因此 PerInstanceColorAppearance#renderState 启用了背面剔除。 如果观察者进入几何体内部,它将不可见。
Default Value: false
当为 true 时,片元着色器会按需翻转表面法线, 以确保法线朝向观察者,从而避免暗斑。当几何体的两侧都应 像 WallGeometry 那样被着色时,这很有用。
Default Value: true
当为 true 时,在片元着色器中使用平面着色, 即不考虑光照。
Default Value: false

readonly fragmentShaderSource : string

片元着色器的 GLSL 源码。
此属性属于 Appearance 接口的一部分,但 PerInstanceColorAppearance 并未使用它,因为它使用了完全自定义的片元着色器。
Default Value: undefined
渲染几何体时要使用的 WebGL 固定功能状态(fixed-function state)。

渲染状态可以在构造 PerInstanceColorAppearance 实例时显式定义, 也可以经由 PerInstanceColorAppearance#translucentPerInstanceColorAppearance#closed 隐式设置。

当为 true 时,几何体应呈现为半透明,因此 PerInstanceColorAppearance#renderState 启用了 alpha 混合。
Default Value: true
此外观实例所兼容的 VertexFormat。 几何体可以拥有更多的顶点属性且仍然兼容——但这可能带来性能开销——但不能更少。

readonly vertexShaderSource : string

顶点着色器的 GLSL 源码。

Methods

getFragmentShaderSource()string

以过程化方式创建完整的 GLSL 片元着色器源码。对于 PerInstanceColorAppearance, 它派生自 PerInstanceColorAppearance#fragmentShaderSourcePerInstanceColorAppearance#flatPerInstanceColorAppearance#faceForward
Returns:
完整的 GLSL 片元着色器源码。
创建一个渲染状态。这不是最终的渲染状态实例,而是 可以包含与上下文中创建的渲染状态相同的渲染状态属性子集。
Returns:
渲染状态。
根据 PerInstanceColorAppearance#translucent 判断几何体是否半透明。
Returns:
若外观为半透明则为 true
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。