Class: Material

Material

new Material()

材质通过漫反射、镜面反射、法线、发射和 alpha 组件的组合来定义表面外观。 这些值是通过一个名为 Fabric 的 JSON 架构指定的,该架构会被解析并组装成 glsl 着色器代码,以了解有关 Fabric 的更多详情。

Base material types and their uniforms:

  • Color
    • color: rgba 颜色对象。
  • Image
    • image:影像的路径。
    • repeat:具有 x 和 y 值的对象,指定重复影像的次数。
  • DiffuseMap
    • image:影像的路径。
    • channels:三个字符串,包含 r、g、b 和 a 的任意组合,用于选择所需的影像通道。
    • repeat:具有 x 和 y 值的对象,指定重复影像的次数。
  • AlphaMap
    • image:影像的路径。
    • channel: One character string containing r, g, b, or a for selecting the desired image channel.
    • repeat: Object with x and y values specifying the number of times to repeat the image.
  • SpecularMap
    • image:影像的路径。
    • channel:一个包含 r、g、b 或 a 的字符串,用于选择所需的影像通道。
    • repeat:具有 x 和 y 值的对象,指定重复影像的次数。
  • EmissionMap
    • image:影像的路径。
    • channels:三个字符串,包含 r、g、b 和 a 的任意组合,用于选择所需的影像通道。
    • repeat:具有 x 和 y 值的对象,指定重复影像的次数。
  • BumpMap
    • image:影像的路径。
    • channel:一个包含 r、g、b 或 a 的字符串,用于选择所需的影像通道。
    • repeat:具有 x 和 y 值的对象,指定重复影像的次数。
    • strength: 凹凸强度值介于 0.0 和 1.0 之间,其中 0.0 是最小值,1.0 是最大值。
  • NormalMap
    • image:影像的路径。
    • channels:三个字符串,包含 r、g、b 和 a 的任意组合,用于选择所需的影像通道。
    • repeat:具有 x 和 y 值的对象,指定重复影像的次数。
    • strength:法线强度值介于 0.0 和 1.0 之间,其中 0.0 是最小值,1.0 是最大值。
  • Grid
    • color:整个材质的 rgba 颜色对象。
    • cellAlpha:网格线之间的单元格的 Alpha 值。这将与 color.alpha 结合使用。
    • lineCount:具有 x 和 y 值的对象,分别指定列数和行数。
    • lineThickness:具有 x 和 y 值的对象,指定网格线的粗细(在可用的情况下以像素为单位)。
    • lineOffset:具有 x 和 y 值的对象,指定网格线的偏移量(范围为 0 到 1)。
  • Stripe
    • horizontal:确定条纹是水平还是垂直的布尔值。
    • evenColor:条纹第一种颜色的 rgba 颜色对象。
    • oddColor:条纹第二种颜色的 rgba 颜色对象。
    • offset:控制在图案中的哪个点开始绘制的数字;其中 0.0 是偶数颜色的开始,1.0 是奇数颜色的开始,2.0 再次是偶数颜色,以及介于两者之间的任何倍数或分数值。
    • repeat:控制条纹总数的数字,一半亮一半暗。
  • Checkerboard
    • lightColor:rgba颜色对象,用于checkerboard的光照交替颜色。
    • darkColor:checkerboard棋盘的深色交替颜色的rgba颜色对象。
    • repeat具有 x 和 y 值的对象,分别指定列数和行数。
  • Dot
    • lightColor点颜色的 rgba 颜色对象。
    • darkColor:背景颜色的 rgba 颜色对象。
    • repeat:具有 x 和 y 值的对象,分别指定点的列数和行数。
  • Water
    • baseWaterColor: rgba 颜色对象水的基色。
    • blendColor:从水混合到非水区域时使用的 rgba 颜色对象。
    • specularMap:用于指示水域的单通道纹理。
    • normalMap:水法线扰动的法线贴图。
    • frequency:控制波数的数字。
    • animationSpeed:控制水的动画速度的数字。
    • amplitude:控制水波振幅的数字。
    • specularIntensity:控制镜面反射强度的数字。
  • RimLighting
    • color:漫反射颜色和 alpha。
    • rimColor:边缘的漫反射颜色和 alpha。
    • width: 确定轮辋宽度的数字。
  • Fade
    • fadeInColor:time漫反射颜色和 alpha。
    • fadeOutColor:从 time 到 maximumDistance 距离的漫反射颜色和 alpha。
    • maximumDistance:介于 0.0 和 1.0 之间的数字,其中 fadeInColor 变为 fadeOutColor 。值 0.0 使整个材质的颜色为 fadeOutColor ,值 1.0 使整个材质的颜色为 fadeInColor
    • repeat:如果淡入淡出应该环绕纹理坐标,则为 true。
    • fadeDirection:具有 x 和 y 值的对象,指定淡入淡出是否应在 x 和 y 方向。
    • time: 对象的 x 和 y 值在 fadeInColor 位置的 0.0 和 1.0 之间。
  • PolylineArrow
    • color:漫反射颜色和 alpha。
  • PolylineDash
    • color:线条的颜色。
    • gapColor:线条中间隙的颜色。
    • dashLength:以像素为单位的虚线长度。
    • dashPattern:线条的 16 位点画图案。
  • PolylineGlow
    • color:线上发光的颜色和最大 alpha。
    • glowPower:发光强度,占总线宽的百分比(小于 1.0)。
  • PolylineOutline
    • color:线内部的漫反射颜色和 alpha。
    • outlineColor:轮廓的漫反射颜色和 alpha。
    • outlineWidth:轮廓的宽度(以像素为单位)。
Name Type Default Description
options.strict Boolean false 可选

针对通常会被忽略的问题(包括未使用的变量或材质)抛出错误。

options.translucent Boolean | function true 可选

为 true 或函数返回 true 时,使用此材质的几何体将呈现半透明效果。

options.fabric Object

用于生成材质的JSON。

options.diffuse Color

漫反射

options.specular Color

高光

options.ambient Color

环境光

options.shiness Number

光泽度

Throws:
  • fabric: uniform的类型无效。

    Type
    DeveloperError
  • fabric: uniforms and materials 不能共享相同的属性。

    Type
    DeveloperError
  • fabric: 不能在同一部分中包含源和组件。

    Type
    DeveloperError
  • fabric: 属性名称无效。它应该是 'type', 'materials', 'uniforms', 'components', or 'source'.

    Type
    DeveloperError
  • fabric: 属性名称无效。它应该是 'diffuse', 'specular', 'shininess', 'normal', 'emission', or 'alpha'.

    Type
    DeveloperError
  • strict: 着色器源不使用字符串。

    Type
    DeveloperError
  • strict: 着色器源不使用统一。

    Type
    DeveloperError
  • strict: 着色器源不使用材质。

    Type
    DeveloperError
Example
// Create a color material with fromType:
polygon.material = SuperMap3D.Material.fromType('Color');
polygon.material.uniforms.color = new SuperMap3D.Color(1.0, 1.0, 0.0, 1.0);

// Create the default material:
polygon.material = new SuperMap3D.Material();

// Create a color material with full Fabric notation:
polygon.material = new SuperMap3D.Material({
    fabric : {
        type : 'Color',
        uniforms : {
            color : new SuperMap3D.Color(1.0, 1.0, 0.0, 1.0)
        }
    }
});

Members

static AdvancedWaterTypeString

获取高级水面材质的名称。

Example
Material({
  fabric: {
      type: Material.AdvancedWaterType,//水面材质设置类型
      uniforms: {
          uWaterColor: new Cartesian4(0, 0.627451, 0.913725, 1.0),//水面颜色
          uWaterBrightness: 0.7,//水面亮度
      }
  }
})

(static, readonly) AlphaMapTypeString

获取alpha贴图材质的名称。

(static, readonly) AspectRampMaterialTypeString

Gets the name of the aspect ramp material.

(static, readonly) BumpMapTypeString

获取凹凸贴图材质的名称。

(static, readonly) CheckerboardTypeString

获取checkerboard材质的名称。

(static, readonly) ColorTypeString

获取颜色材质的名称。

static DefaultCubeMapIdString

获取或设置默认立方体贴图纹理统一变量的值。

static DefaultImageIdString

获取或设置默认纹理统一变量的值。

(static, readonly) DiffuseMapTypeString

获取漫反射贴图材质的名称。

(static, readonly) DotTypeString

获取点状材质的名称。

(static, readonly) ElevationContourTypeString

Gets the name of the elevation contour material.

(static, readonly) ElevationRampTypeString

Gets the name of the elevation contour material.

(static, readonly) EmissionColorTypeString

获取自发光颜色材质的名称。

(static, readonly) EmissionMapTypeString

获取自发光贴图材质的名称。

(static, readonly) FadeTypeString

获取渐变材质的名称。

(static, readonly) GridTypeString

获取网格材质的名称。

(static, readonly) ImageTypeString

获取图像材质的名称。

(static, readonly) NormalMapTypeString

获取法线贴图材质的名称。

(static, readonly) PbrTypeString

获取PBR材质的名称。

(static, readonly) PolylineArrowTypeString

获取折线箭头材质的名称。

(static, readonly) PolylineDashTypeString

获取折线(虚线)发光材质的名称。

(static, readonly) PolylineGlowTypeString

获取折线发光材质的名称。

(static, readonly) PolylineOutlineTypeString

获取折线轮廓材质的名称。

(static, readonly) RimLightingTypeString

获取边缘光照材质的名称。

(static, readonly) SlopeRampMaterialTypeString

Gets the name of the slope ramp material.

(static, readonly) SpecularMapTypeString

获取镜面贴图材质的名称。

(static, readonly) StripeTypeString

获取条纹材质的名称。

(static, readonly) WaterTypeString

获取基础水面材质的名称。

materialsObject

将子材质名称映射到Material对象。

Default Value:
undefined

shaderSourceString

这种材质的GLSL着色器源代码。

Default Value:
undefined

translucentBoolean function

为 true 时或函数返回 true 时,几何体将显示为半透明。

Default Value:
undefined

typeString

材质类型。可以是现有类型,也可以是新类型。如果没有在 "fabric"中指定类型,类型就是一个 GUID。

Default Value:
undefined

uniformsObject

将统一变量名称映射到它们的值。

Default Value:
undefined

Methods

static fromType(type, uniforms){Material}

使用现有材质类型创建新材质。

Shorthand for: new Material({fabric : {type : type}});

Name Type Description
type String

基础材质类型。

uniforms Object 可选

覆盖默认统一的变量。

Throws:

这种材质类型不存在。

Type
DeveloperError
Returns:
Type Description
Material 新的材质对象。
Example
var material = SuperMap3D.Material.fromType('Color', {
    color : new SuperMap3D.Color(1.0, 0.0, 0.0, 1.0)
});

destroy(){undefined}

销毁此对象持有的 WebGL 资源。销毁对象可以确定性地释放 WebGL 资源,而不是依赖垃圾回收器来销毁该对象。

一旦对象被销毁,就不得再使用;调用 isDestroyed 以外的任何函数都将导致 DeveloperError 异常。 因此,请按照示例中的方法将返回值(undefined)赋值给对象。

See:
Throws:

该对象已被销毁,即 destroy() 被调用。

Type
DeveloperError
Returns:
Type Description
undefined
Example
material = material && material.destroy();

isDestroyed(){Boolean}

如果此对象被销毁则返回true,否则为false。

如果该对象已被销毁,则不应使用;调用除isDestroyed 以外的函数将导致 DeveloperError 异常。

See:
Returns:
Type Description
Boolean 如果该对象已被销毁,则为 true;否则为 false。

isTranslucent()

获取此材质是否是半透明的。

Returns:
如果该材质是半透明的,则为True,否则为false。