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).

Extends

  • ElementEventDispatcher

Extended by

Implements

  • SerializerableDelegatedAsReference
  • MaterialState
  • ElementsWithGPUResource

Properties

isDynamicShape

isDynamicShape: boolean

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

Deprecated


isVolumeRendering

isVolumeRendering: boolean

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

Deprecated


name

name: string

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


id

id: number

Unique number for this material instance.


transparent

transparent: boolean

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

Default Value

false

Implementation of

MaterialState.transparent


visible

visible: boolean

Defines whether this material is visible.

Default Value

true

Implementation of

MaterialState.visible


programId

programId: number

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


side

side: Side

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

Implementation of

MaterialState.side


blending

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.

Default Value

NormalBlending

Implementation of

MaterialState.blending


blendSrc

blendSrc: BlendingFactor

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

Default Value

SrcAlphaFactor

Implementation of

MaterialState.blendSrc


blendDst

blendDst: BlendingFactor

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

Default Value

OneMinusSrcAlpha

Implementation of

MaterialState.blendDst


blendEquation

blendEquation: BlendingEquation

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

Default Value

Add

Implementation of

MaterialState.blendEquation


blendSrcAlpha

blendSrcAlpha: Nullable<BlendingFactor>

The transparency of the blendSrc.

Implementation of

MaterialState.blendSrcAlpha


blendDstAlpha

blendDstAlpha: Nullable<BlendingFactor>

The transparency of the blendDst.

Implementation of

MaterialState.blendDstAlpha


blendEquationAlpha

blendEquationAlpha: Nullable<BlendingEquation>

The transparency of the blendEquation.

Implementation of

MaterialState.blendEquationAlpha


stencilWrite

stencilWrite: boolean

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

Default Value

false

Implementation of

MaterialState.stencilWrite


stencilWriteMask

stencilWriteMask: number

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

Default Value

0xFF

Implementation of

MaterialState.stencilWriteMask


stencilFuncMask

stencilFuncMask: number

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

Default Value

0xFF

Implementation of

MaterialState.stencilFuncMask


stencilFunc

stencilFunc: StencilFunc

The stencil comparison function to use.

Default Value

AlwaysStencilFunc

Implementation of

MaterialState.stencilFunc


stencilRef

stencilRef: number

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

Default Value

0

Implementation of

MaterialState.stencilRef


stencilFail

stencilFail: StencilOp

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

Default Value

KeepStencilOp

Implementation of

MaterialState.stencilFail


stencilZFail

stencilZFail: StencilOp

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

Default Value

KeepStencilOp

Implementation of

MaterialState.stencilZFail


stencilZPass

stencilZPass: StencilOp

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

Default Value

KeepStencilOp

Implementation of

MaterialState.stencilZPass


depthFunc

depthFunc: DepthModes

Which depth function to use.

Default Value

LessEqualDepth

Implementation of

MaterialState.depthFunc


depthTest

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.

Default Value

true

Implementation of

MaterialState.depthTest


depthWrite

depthWrite: boolean

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

Default Value

true

Implementation of

MaterialState.depthWrite


colorWrite

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.

Default Value

true

Implementation of

MaterialState.colorWrite


colorWriteMasks

colorWriteMasks: [boolean, boolean, boolean, boolean]

Implementation of

MaterialState.colorWriteMasks


polygonOffset

polygonOffset: boolean

Whether to use polygon offset.

Default Value

false

Implementation of

MaterialState.polygonOffset


polygonOffsetFactor

polygonOffsetFactor: number

Sets the polygon offset factor.

Default Value

0

Implementation of

MaterialState.polygonOffsetFactor


polygonOffsetUnits

polygonOffsetUnits: number

Sets the polygon offset units.

Default Value

0

Implementation of

MaterialState.polygonOffsetUnits


premultipliedAlpha

premultipliedAlpha: boolean

Whether to premultiply the alpha (transparency) value.

Default Value

false

Implementation of

MaterialState.premultipliedAlpha


onBeforeRender?

optional onBeforeRender?: (renderer) => void

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

Parameters

renderer

Renderer

instance of renderer for engine.

Returns

void


colorWriteMask

colorWriteMask: [boolean, boolean, boolean, boolean]


userData

readonly userData: Record<keyof any, any>

Inherited from

ElementEventDispatcher.userData


_uuid

_uuid: any

Inherited from

ElementEventDispatcher._uuid


uuid

uuid: string

Inherited from

ElementEventDispatcher.uuid


_listeners

_listeners: Map<Symbol, Listener<never>[]>

Inherited from

ElementEventDispatcher._listeners

Accessors

businessTag

Get Signature

get businessTag(): string

Returns

string

Set Signature

set businessTag(v): void

Parameters
v

string

Returns

void

Inherited from

ElementEventDispatcher.businessTag

Methods

getComponents()

getComponents(): readonly ShaderComponent[]

Returns

readonly ShaderComponent[]


deleteComponent()

deleteComponent(index): void

Parameters

index

number

Returns

void


addComponent()

addComponent(c, index?): void

Parameters

c

ShaderComponent

index?

number

Returns

void


refreshInstanceInBuilding()

refreshInstanceInBuilding(enable): void

Parameters

enable

boolean

Returns

void


setColorWriteMasks()

setColorWriteMasks(r, g, b, a): void

Parameters

r

boolean

g

boolean

b

boolean

a

boolean

Returns

void


notifyMaterialPropertyChanged()

notifyMaterialPropertyChanged(): void

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

Returns

void


getUUID()

getUUID(): string

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

Returns

string

Implementation of

SerializerableDelegatedAsReference.getUUID


className()

abstract className(): string

The name of instance’s class.

Returns

string

Implementation of

SerializerableDelegatedAsReference.className


clone()

abstract clone(): Material

abstract function to clone each instance of the class

Returns

Material


copy()

abstract copy(other): void

abstract function to copy a same type material instance

Parameters

other

Material

Returns

void


setValues()

setValues(values?): 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" | "getSerializeData" | "equals" | "g" | "r" | "b" | "isColor" | "getHex">>, string | number | Readonly<Pick<ReadonlyMarked<Color>, "_readonly_mark" | "cloneReadonly" | "clone" | "getSerializeData" | "equals" | "g" | "r" | "b" | "isColor" | "getHex">>>>

Returns

void


notifyRecompileShader()

notifyRecompileShader(): void

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

Returns

void


copyBase()

copyBase(other): void

Copy basic properties from other material.

Parameters

other

Material

the source of copied data

Returns

void


freeGPU()

freeGPU(): void

Make engine clear the current material’s data in Ubo.

Returns

void

Implementation of

ElementsWithGPUResource.freeGPU


serialize()

serialize(ctx): any

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

Implementation of

SerializerableDelegatedAsReference.serialize


deserialize()

deserialize(ctx): void

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

Implementation of

SerializerableDelegatedAsReference.deserialize


destroyAllResourcesOwned()

destroyAllResourcesOwned(): void

Returns

void

Overrides

ElementEventDispatcher.destroyAllResourcesOwned


freeAllGpuResourceOwned()

freeAllGpuResourceOwned(): void

Returns

void

Overrides

ElementEventDispatcher.freeAllGpuResourceOwned


markBusinessTag()

markBusinessTag(v): this

Parameters

v

string

Returns

this

Inherited from

ElementEventDispatcher.markBusinessTag


isDestroyed()

isDestroyed(): boolean

Returns

boolean

Inherited from

ElementEventDispatcher.isDestroyed


destroy()

destroy(): void

Returns

void

Inherited from

ElementEventDispatcher.destroy


validate()

validate(): void

Returns

void

Inherited from

ElementEventDispatcher.validate


on()

on<T>(_type, _listener): void

Adds a listener to an event type.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

void

Inherited from

ElementEventDispatcher.on


once()

once<T>(_type, _listener): void

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

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

void

Inherited from

ElementEventDispatcher.once


has()

has<T>(_type, _listener): boolean

Checks if listener is added to an event type.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

boolean

Inherited from

ElementEventDispatcher.has


off()

off<T>(_type, _listener): void

Removes a listener from listening list.

Type Parameters

T

T

Parameters

_type

EventType<T>

_listener

Listener<T>

Returns

void

Inherited from

ElementEventDispatcher.off


emit()

Call Signature

emit(type): void

Active the event and call the registered listener.

Parameters
type

EventType<never>

Returns

void

Inherited from

ElementEventDispatcher.emit

Call Signature

emit<T>(type, payload): void

Type Parameters
T

T

Parameters
type

EventType<T>

payload

T

Returns

void

Inherited from

ElementEventDispatcher.emit


clearAllListeners()

clearAllListeners(): void

Removes all listeners from listening list.

Returns

void

Inherited from

ElementEventDispatcher.clearAllListeners