Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    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.

    A mesh instance is drawn through the layers it belongs to, and a camera draws only the layers listed in CameraComponent#layers. Components place their mesh instances by layer id, for example through RenderComponent#layers, and lights through LightComponent#layers; mesh instances you create yourself go in with addMeshInstances and out with removeMeshInstances.

    The application creates five layers, reachable by id from Scene#layers: LAYERID_WORLD for the scene itself, LAYERID_DEPTH, LAYERID_SKYBOX, LAYERID_IMMEDIATE for debug drawing and LAYERID_UI. Within a layer, opaque and transparent mesh instances are drawn as two separate parts, ordered by opaqueSortMode and transparentSortMode, and the composition decides where each part falls in the frame. Set enabled to false to skip a layer entirely, and use onEnable and onDisable to react to that.

    // Draw a set of mesh instances in a layer of their own, right after the world's opaque objects
    const layers = app.scene.layers;
    const layer = new Layer({ name: 'Overlay' });
    const world = layers.getLayerById(LAYERID_WORLD);
    layers.insert(layer, layers.getOpaqueIndex(world) + 1);
    layer.addMeshInstances(meshInstances);
    Index
    • 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

    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: string

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

    onDisable: Function

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

    • enabled was changed from true to false
    • decrementCounter was called and set the counter to zero.
    onEnable: Function

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

    • The layer is created with enabled set to true (which is the default value).
    • enabled was changed from false to true
    opaqueSortMode: number = SORTMODE_MATERIALMESH

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

    Defaults to SORTMODE_MATERIALMESH.

    transparentSortMode: number = SORTMODE_BACK2FRONT

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

    Defaults to SORTMODE_BACK2FRONT.

    • get clearColorBuffer(): boolean

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

      Returns boolean

    • set clearColorBuffer(val: boolean): void

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

      Parameters

      • val: boolean

      Returns void

    • get clearDepthBuffer(): boolean

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

      Returns boolean

    • set clearDepthBuffer(val: boolean): void

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

      Parameters

      • val: boolean

      Returns void

    • get clearStencilBuffer(): boolean

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

      Returns boolean

    • set clearStencilBuffer(val: boolean): void

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

      Parameters

      • val: boolean

      Returns void

    • get enabled(): boolean

      Gets the enabled state of the layer.

      Returns boolean

    • set enabled(val: boolean): void

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

      Parameters

      • val: boolean

      Returns void

    • Adds an array of mesh instances to this layer.

      Parameters

      • meshInstances: MeshInstance[]

        Array of MeshInstance.

      • OptionalskipShadowCasters: boolean

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

      Returns 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

      Returns void

    • Removes all cameras from this layer.

      Returns void

    • Removes all lights from this layer.

      Returns void

    • Removes all mesh instances from this layer.

      Parameters

      • OptionalskipShadowCasters: 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

    • Removes multiple mesh instances from this layer.

      Parameters

      • meshInstances: MeshInstance[]

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

      • OptionalskipShadowCasters: 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

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

      Parameters

      Returns void