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 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 实例兼容的 VertexFormat, 当 PerInstanceColorAppearance#flattrue 时。 这仅要求有一个 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 固定功能状态。

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

true 时,几何体预计将呈现为半透明,因此 PerInstanceColorAppearance#renderState 启用了 alpha 混合。
Default Value: true
此外观实例兼容的 VertexFormat。 几何体可以具有更多的顶点属性并仍然兼容——但这可能会导致性能损失—— 但它不能少于。

readonly vertexShaderSource : string

顶点着色器的 GLSL 源代码。

Methods

getFragmentShaderSource()string

Returns:
完整的 GLSL 片段着色器源。
创建渲染状态。这不是最终的渲染状态实例;相反, 它可以包含一组与上下文中创建的渲染状态相同的渲染状态属性的子集。
Returns:
渲染状态。
根据 PerInstanceColorAppearance#translucent 确定几何体是否为半透明。
Returns:
true 如果外观是半透明的。
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.