Mirror Engine
V7
How To
Mirror Engine Logo

Mirror Engine API


Mirror Engine API / Layer

Class: Layer

A Layer represents a renderable subset of the scene. It can contain a list of mesh instances, lights and cameras, their render settings and also defines custom callbacks before, after or during rendering. Layers are organized inside LayerComposition in a desired order.

Constructors

new Layer()

new Layer(options: any): Layer

Create a new Layer instance.

Parameters

options

any = {}

Object for passing optional arguments. These arguments are the same as properties of the Layer.

Returns

Layer

Properties

id

id: number

A unique ID of the layer. Layer IDs are stored inside ModelComponent#layers, RenderComponent#layers, CameraComponent#layers, LightComponent#layers and ElementComponent#layers instead of names. Can be used in LayerComposition#getLayerById.


name

name: string

Name of the layer. Can be used in LayerComposition#getLayerByName.


onDisable

onDisable: Function

Custom function that is called after the layer has been disabled. This happens when:

  • Layer#enabled was changed from true to false
  • Layer#decrementCounter was called and set the counter to zero.

onEnable

onEnable: Function

Custom function that is called after the layer has been enabled. This happens when:

  • The layer is created with Layer#enabled set to true (which is the default value).
  • Layer#enabled was changed from false to true
  • Layer#incrementCounter was called and incremented the counter above zero.

Useful for allocating resources this layer will use (e.g. creating render targets).


opaqueSortMode

opaqueSortMode: number

Defines the method used for sorting opaque (that is, not semi-transparent) mesh instances before rendering. Can be:

Defaults to SORTMODE_MATERIALMESH.


transparentSortMode

transparentSortMode: number

Defines the method used for sorting semi-transparent mesh instances before rendering. Can be:

Defaults to SORTMODE_BACK2FRONT.

clearColorBuffer

Get Signature

get clearColorBuffer(): boolean

Gets whether the camera will clear the color buffer when it renders this layer.

Returns

boolean

Set Signature

set clearColorBuffer(val: boolean): void

Sets whether the camera will clear the color buffer when it renders this layer.

Parameters
val

boolean

Returns

void


clearDepthBuffer

Get Signature

get clearDepthBuffer(): boolean

Gets whether the camera will clear the depth buffer when it renders this layer.

Returns

boolean

Set Signature

set clearDepthBuffer(val: boolean): void

Sets whether the camera will clear the depth buffer when it renders this layer.

Parameters
val

boolean

Returns

void


clearStencilBuffer

Get Signature

get clearStencilBuffer(): boolean

Gets whether the camera will clear the stencil buffer when it renders this layer.

Returns

boolean

Set Signature

set clearStencilBuffer(val: boolean): void

Sets whether the camera will clear the stencil buffer when it renders this layer.

Parameters
val

boolean

Returns

void


enabled

Get Signature

get enabled(): boolean

Gets the enabled state of the layer.

Returns

boolean

Set Signature

set enabled(val: boolean): void

Sets the enabled state of the layer. Disabled layers are skipped. Defaults to true.

Parameters
val

boolean

Returns

void

Methods

addCamera()

addCamera(camera: CameraComponent): void

Adds a camera to this layer.

Parameters

camera

CameraComponent

A CameraComponent.

Returns

void


addLight()

addLight(light: LightComponent): void

Adds a light to this layer.

Parameters

light

LightComponent

A LightComponent.

Returns

void


addMeshInstances()

addMeshInstances(meshInstances: MeshInstance[], skipShadowCasters?: boolean): void

Adds an array of mesh instances to this layer.

Parameters

meshInstances

MeshInstance[]

Array of MeshInstance.

skipShadowCasters?

boolean

Set it to true if you don't want these mesh instances to cast shadows in this layer. Defaults to false.

Returns

void


addShadowCasters()

addShadowCasters(meshInstances: MeshInstance[]): void

Adds an array of mesh instances to this layer, but only as shadow casters (they will not be rendered anywhere, but only cast shadows on other objects).

Parameters

meshInstances

MeshInstance[]

Array of MeshInstance.

Returns

void


clearCameras()

clearCameras(): void

Removes all cameras from this layer.

Returns

void


clearLights()

clearLights(): void

Removes all lights from this layer.

Returns

void


clearMeshInstances()

clearMeshInstances(skipShadowCasters?: boolean): void

Removes all mesh instances from this layer.

Parameters

skipShadowCasters?

boolean = false

Set it to true if you want to continue the existing mesh instances to cast shadows. Defaults to false, which removes shadow casters as well.

Returns

void


removeCamera()

removeCamera(camera: CameraComponent): void

Removes a camera from this layer.

Parameters

camera

CameraComponent

A CameraComponent.

Returns

void


removeLight()

removeLight(light: LightComponent): void

Removes a light from this layer.

Parameters

light

LightComponent

A LightComponent.

Returns

void


removeMeshInstances()

removeMeshInstances(meshInstances: MeshInstance[], skipShadowCasters?: boolean): void

Removes multiple mesh instances from this layer.

Parameters

meshInstances

MeshInstance[]

Array of MeshInstance. If they were added to this layer, they will be removed.

skipShadowCasters?

boolean

Set it to true if you want to still cast shadows from removed mesh instances or if they never did cast shadows before. Defaults to false.

Returns

void


removeShadowCasters()

removeShadowCasters(meshInstances: MeshInstance[]): void

Removes multiple mesh instances from the shadow casters list of this layer, meaning they will stop casting shadows.

Parameters

meshInstances

MeshInstance[]

Array of MeshInstance. If they were added to this layer, they will be removed.

Returns

void

Mirror Engine Logo