Material

A base class for all materials with some abstract functions. Materials describe the appearance of the objects. They are defined in a (mostly) renderer-independent way, so you don't have to rewrite materials if you decide to use a different renderer. The following properties and methods are inherited by all other material types (although they may have different defaults).

Core Interface

A base class for all materials with some abstract functions. Materials describe the appearance of the objects. They are defined in a (mostly) renderer-independent way, so you don't have to rewrite materials if you decide to use a different renderer. The following properties and methods are inherited by all other material types (although they may have different defaults).

interface Material {
getComponents(): readonly ShaderComponent[];
deleteComponent(index: number): void;
addComponent(c: ShaderComponent, index?: number): void;
isDynamicShape: boolean;
isVolumeRendering: boolean;
name: string;
id: number;
transparent: boolean;
visible: boolean;
programId: number;
refreshInstanceInBuilding(enable: boolean): void;
side: Side;
blending: Blending;
blendSrc: BlendingFactor;
blendDst: BlendingFactor;
blendEquation: BlendingEquation;
blendSrcAlpha: Nullable<BlendingFactor>;
blendDstAlpha: Nullable<BlendingFactor>;
blendEquationAlpha: Nullable<BlendingEquation>;
stencilWrite: boolean;
stencilWriteMask: number;
stencilFuncMask: number;
stencilFunc: StencilFunc;
stencilRef: number;
stencilFail: StencilOp;
stencilZFail: StencilOp;
stencilZPass: StencilOp;
depthFunc: DepthModes;
depthTest: boolean;
depthWrite: boolean;
colorWrite: boolean;
colorWriteMasks: [boolean, boolean, boolean, boolean];
setColorWriteMasks(r: boolean, g: boolean, b: boolean, a: boolean): void;
polygonOffset: boolean;
polygonOffsetFactor: number;
polygonOffsetUnits: number;
premultipliedAlpha: boolean;
onBeforeRender?: (renderer: Renderer) => void;
notifyMaterialPropertyChanged(): void;
colorWriteMask: [boolean, boolean, boolean, boolean];
getUUID(): string;
className(): string;
clone(): Material;
copy(other: Material): void;
setValues(
values?: Partial<
SubTypeMap<
Pick<
Material,
| "transparent"
| "visible"
| "side"
| "blending"
| "blendSrc"
| "blendDst"
| "blendEquation"
| "blendSrcAlpha"
| "blendDstAlpha"
| "blendEquationAlpha"
| "depthFunc"
| "depthTest"
| "depthWrite"
| "colorWrite"
| "polygonOffset"
| "polygonOffsetFactor"
| "polygonOffsetUnits"
| "stencilWriteMask"
| "stencilFunc"
| "stencilRef"
| "stencilFuncMask"
| "stencilFail"
| "stencilZFail"
| "stencilZPass"
| "stencilWrite",
>,
Readonly<
Pick<
ReadonlyMarked<Color>,

| "_readonly_mark"
| "cloneReadonly"
| "clone"
| "equals"
| "getSerializeData"
| "g"
| "r"
| "b"
| "isColor"
| "getHex",
>,
>,
| string
| number
| Readonly<
Pick<
ReadonlyMarked<Color>,

| "_readonly_mark"
| "cloneReadonly"
| "clone"
| "equals"
| "getSerializeData"
| "g"
| "r"
| "b"
| "isColor"
| "getHex",
>,
>,
>,
>,
): void;
notifyRecompileShader(): void;
copyBase(other: Material): void;
freeGPU(): void;
serialize(ctx: Serializer): any;
deserialize(ctx: Deserializer): void;
destroyAllResourcesOwned(): void;
freeAllGpuResourceOwned(): void;
userData: Record<keyof any, any>;
markBusinessTag(v: string): this;
get businessTag(): string;
set businessTag(v: string): void;
isDestroyed(): boolean;
destroy(): void;
validate(): void;
_uuid: any;
uuid: string;
_listeners: Map<Symbol, Listener<never>[]>;
on<T>(_type: EventType<T>, _listener: Listener<T>): void;
once<T>(_type: EventType<T>, _listener: Listener<T>): void;
has<T>(_type: EventType<T>, _listener: Listener<T>): boolean;
off<T>(_type: EventType<T>, _listener: Listener<T>): void;
emit(type: EventType<never>): void;
emit<T>(type: EventType<T>, payload: T): void;
clearAllListeners(): void;
}

Hierarchy

Implements

  • SerializerableDelegatedAsReference
  • MaterialState
  • ElementsWithGPUResource

Properties

isDynamicShape: boolean

Mark this shape of this material is largely affect by shader. Hint the engine that pick, culling is disabled

isVolumeRendering: boolean

Mark this material uses volume like rendering technology. Hint the engine that some effect is disabled

name: string

Optional name of the object (doesn't need to be unique). Default is an empty string.

id: number

Unique number for this material instance.

transparent: boolean

If use transparent effect, this value must be set to true to enable blending.

visible: boolean

Defines whether this material is visible.

programId: number

The id of shader program which this material shader belongs to.

side: Side

Set which side of the object will be seen on screen.

blending: Blending

Which blending to use when displaying objects with this material. This must be set to CustomBlending to use custom blendSrc , blendDst or blendEquation . See the blending mode constants for all possible values. Default is NormalBlending.

blendSrc: BlendingFactor

Blending source. Default is SrcAlphaFactor. See the source factors constants for all possible values.

blendDst: BlendingFactor

Blending destination. Default is OneMinusSrcAlphaFactor. See the destination factors constants for all possible values.

blendEquation: BlendingEquation

Blending equation to use when applying blending. Default is AddEquation. See the blending equation constants for all possible values.

blendSrcAlpha: Nullable<BlendingFactor>

The transparency of the blendSrc .

blendDstAlpha: Nullable<BlendingFactor>

The transparency of the blendDst .

blendEquationAlpha: Nullable<BlendingEquation>

The transparency of the blendEquation .

stencilWrite: boolean

Whether rendering this material has any effect on the stencil buffer.

stencilWriteMask: number

The bit mask to use when writing to the stencil buffer.

stencilFuncMask: number

The bit mask to use when comparing against the stencil buffer.

stencilFunc: StencilFunc

The stencil comparison function to use.

stencilRef: number

The value to use when performing stencil comparisons or stencil operations.

stencilFail: StencilOp

Which stencil operation to perform when the comparison function returns false.

stencilZFail: StencilOp

Which stencil operation to perform when the comparison function returns true but the depth test fails.

stencilZPass: StencilOp

Which stencil operation to perform when the comparison function returns true and the depth test passes.

depthFunc: DepthModes

Which depth function to use.

depthTest: boolean

Whether to have depth test enabled when rendering this material. If this is set to false, this object's occluding relationship will depend on Object3D.renderOrder| renderOrder.

depthWrite: boolean

Whether rendering this material has any effect on the depth buffer.

colorWrite: boolean

Whether to render the material's color. This can be used in conjunction with a Object3D.renderOrder| renderOrder property to create invisible objects that occlude other objects.

colorWriteMasks: [boolean, boolean, boolean, boolean]
polygonOffset: boolean

Whether to use polygon offset.

polygonOffsetFactor: number

Sets the polygon offset factor.

polygonOffsetUnits: number

Sets the polygon offset units.

premultipliedAlpha: boolean

Whether to premultiply the alpha (transparency) value.

An optionally overriding method for extents to get data from renderer before update uniforms.

    • (renderer: Renderer): void
    • Parameters

      • renderer: Renderer

        instance of renderer for engine.

      Returns void

colorWriteMask: [boolean, boolean, boolean, boolean]
userData: Record<keyof any, any>
_uuid: any
uuid: string
_listeners: Map<Symbol, Listener<never>[]>

Accessors

  • get businessTag(): string

    Returns string

  • set businessTag(v: string): void

    Parameters

    • v: string

    Returns void

Methods

  • Returns readonly ShaderComponent[]

  • Parameters

    • index: number

    Returns void

  • Parameters

    • c: ShaderComponent
    • index: number

    Returns void

  • Parameters

    • enable: boolean

    Returns void

  • Parameters

    • r: boolean
    • g: boolean
    • b: boolean
    • a: boolean

    Returns void

  • When user change the material property manually, this method need to use to refresh data.

    Returns void

  • UUID of this material instance. This gets automatically assigned, so this shouldn't be edited.

    Returns string

  • The name of instance's class.

    Returns string

  • abstract function to clone each instance of the class

    Returns Material

  • abstract function to copy a same type material instance

    Parameters

    Returns void

  • Sets the properties with the given values. In extents class, this method need to override in extended material for corresponding parameters.

    Parameters

    • values: Partial<
      SubTypeMap<
      Pick<
      Material,
      | "transparent"
      | "visible"
      | "side"
      | "blending"
      | "blendSrc"
      | "blendDst"
      | "blendEquation"
      | "blendSrcAlpha"
      | "blendDstAlpha"
      | "blendEquationAlpha"
      | "depthFunc"
      | "depthTest"
      | "depthWrite"
      | "colorWrite"
      | "polygonOffset"
      | "polygonOffsetFactor"
      | "polygonOffsetUnits"
      | "stencilWriteMask"
      | "stencilFunc"
      | "stencilRef"
      | "stencilFuncMask"
      | "stencilFail"
      | "stencilZFail"
      | "stencilZPass"
      | "stencilWrite",
      >,
      Readonly<
      Pick<
      ReadonlyMarked<Color>,

      | "_readonly_mark"
      | "cloneReadonly"
      | "clone"
      | "equals"
      | "getSerializeData"
      | "g"
      | "r"
      | "b"
      | "isColor"
      | "getHex",
      >,
      >,
      | string
      | number
      | Readonly<
      Pick<
      ReadonlyMarked<Color>,

      | "_readonly_mark"
      | "cloneReadonly"
      | "clone"
      | "equals"
      | "getSerializeData"
      | "g"
      | "r"
      | "b"
      | "isColor"
      | "getHex",
      >,
      >,
      >,
      >

    Returns void

  • Reset the key of shader and force engine to compile shader again.

    Returns void

  • Copy basic properties from other material.

    Parameters

    • other: Material

      the source of copied data

    Returns void

  • Make engine clear the current material's data in Ubo.

    Returns void

  • Store the attributes of this class into string as serializing format.

    Parameters

    • ctx: Serializer

      this parameter has not supported external Serializer yet. It may cause that this method can not be used directly.

    Returns any

  • Parse the data for this class from string according to serializing format.

    Parameters

    • ctx: Deserializer

      this parameter has not supported external Deserializer yet. It may cause that this method can not be used directly.

    Returns void

  • Returns void

  • Returns void

  • Parameters

    • v: string

    Returns this

  • Returns boolean

  • Returns void

  • Returns void

  • Adds a listener to an event type.

    Type Parameters

    • T

    Parameters

    • _type: EventType<T>
    • _listener: Listener<T>

    Returns void

  • Only active the listener one times and then off it| it.

    Type Parameters

    • T

    Parameters

    • _type: EventType<T>
    • _listener: Listener<T>

    Returns void

  • Checks if listener is added to an event type.

    Type Parameters

    • T

    Parameters

    • _type: EventType<T>
    • _listener: Listener<T>

    Returns boolean

  • Removes a listener from listening list.

    Type Parameters

    • T

    Parameters

    • _type: EventType<T>
    • _listener: Listener<T>

    Returns void

  • Active the event and call the registered listener.

    Parameters

    • type: EventType<never>

    Returns void

  • Type Parameters

    • T

    Parameters

    • type: EventType<T>
    • payload: T

    Returns void

  • Removes all listeners from listening list.

    Returns void