Class: PerInstanceColorAppearance

PerInstanceColorAppearance

new PerInstanceColorAppearance()

这允许使用同一个Primitive绘制多个几何体实例,每个实例都有不同的颜色,如下面第二个示例所示。

Name Type Default Description
options.flat Boolean false 可选

为true时,片段着色器中使用平面着色,这意味着不考虑光照。

options.faceForward Boolean !options.closed 可选

为true时,片段着色器会根据需要翻转表面法线,以确保法线面向观察者,避免出现暗点。当需要对几何体的两侧(如WallGeometry)进行着色时,这一点非常有用。

options.translucent Boolean true 可选

为 true 时,几何体将呈现半透明效果,因此PerInstanceColorAppearance#renderState 将启用 alpha 混合。

options.closed Boolean false 可选

为 true 时,几何体将被关闭,因此PerInstanceColorAppearance#renderState 将启用背面剔除。

options.vertexShaderSource String 可选

可选的 GLSL 顶点着色器源,用于覆盖默认的顶点着色器。

options.fragmentShaderSource String 可选

可选的 GLSL 片段着色器源,用于覆盖默认的片段着色器。

options.renderState RenderState 可选

可选的呈现状态,用于覆盖默认呈现状态。

Example
// A solid white line segment
var primitive = new SuperMap3D.Primitive({
  geometryInstances : new SuperMap3D.GeometryInstance({
    geometry : new SuperMap3D.SimplePolylineGeometry({
      positions : SuperMap3D.Cartesian3.fromDegreesArray([
        0.0, 0.0,
        5.0, 0.0
      ])
    }),
    attributes : {
      color : SuperMap3D.ColorGeometryInstanceAttribute.fromColor(new SuperMap3D.Color(1.0, 1.0, 1.0, 1.0))
    }
  }),
  appearance : new SuperMap3D.PerInstanceColorAppearance({
    flat : true,
    translucent : false
  })
});

// Two rectangles in a primitive, each with a different color
var instance = new SuperMap3D.GeometryInstance({
  geometry : new SuperMap3D.RectangleGeometry({
    rectangle : SuperMap3D.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0)
  }),
  attributes : {
    color : new SuperMap3D.Color(1.0, 0.0, 0.0, 0.5)
  }
});

var anotherInstance = new SuperMap3D.GeometryInstance({
  geometry : new SuperMap3D.RectangleGeometry({
    rectangle : SuperMap3D.Rectangle.fromDegrees(0.0, 40.0, 10.0, 50.0)
  }),
  attributes : {
    color : new SuperMap3D.Color(0.0, 0.0, 1.0, 0.5)
  }
});

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

Members

(static, constant) FLAT_VERTEX_FORMATVertexFormat

PerInstanceColorAppearance#flat为false时,所有PerInstanceColorAppearance实例兼容的VertexFormat这只需要一个位置属性。

(static, constant) VERTEX_FORMATVertexFormat

与所有PerInstanceColorAppearance实例兼容的VertexFormat顶点格式。这只需要位置和 st 属性。

readonly closedBoolean

为true时,几何体将处于关闭状态,因此PerInstanceColorAppearance#renderState 将启用背面剔除。如果查看器进入该几何体,它将不可见。

Default Value:
false

readonly faceForwardBoolean

为true时,片段着色器会根据需要翻转表面法线,以确保法线面向观察者,避免出现暗点。 当需要对几何体的两侧(如WallGeometry)进行着色时,这一点非常有用。

Default Value:
true

readonly flatBoolean

为true时,片段着色器中使用平面着色,这意味着不考虑光照。

Default Value:
false

readonly fragmentShaderSourceString

片段着色器的 GLSL 源代码。

materialMaterial

该属性是 Appearance 界面的一部分,但不会被 PerInstanceColorAppearance 使用,因为它使用的是完全自定义的片段着色器。

Default Value:
undefined

readonly renderStateObject

渲染几何体时使用的 WebGL 固定函数状态。

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

translucentBoolean

为 true 时,几何体将呈现半透明效果,因此PerInstanceColorAppearance#renderState 将启用 alpha 混合。

Default Value:
true

readonly vertexFormatVertexFormat

此外观实例兼容的 VertexFormat 顶点格式。一个几何体可以拥有更多顶点属性,并且仍然是兼容的,但可能要付出性能代价,但不能少。

readonly vertexShaderSourceString

顶点着色器的 GLSL 源代码。

Methods

getFragmentShaderSource(){String}

程序化创建完整的GLSL片段着色器源。对于PerInstanceColorAppearance来说,这是从PerInstanceColorAppearance#fragmentShaderSourcePerInstanceColorAppearance#flatPerInstanceColorAppearance#faceForward衍生而来。

Returns:
Type Description
String 完整的 GLSL 片段着色器源。

getRenderState(){Object}

创建一个呈现状态。这不是最终的呈现状态实例;相反,它可以包含与上下文中创建的呈现状态相同的呈现状态属性子集。

Returns:
Type Description
Object The render state.

isTranslucent(){Boolean}

根据 PerInstanceColorAppearance#translucent 确定几何体是否半透明。

Returns:
Type Description
Boolean 如果外观是半透明的,则为 true。