Canvas2DMaterialPlugin

View source

ExtendsPlugin

Connects one Material asset type to one Canvas2DFunction draw function for Canvas 2D rendering.

Examples

import { App } from '@wimaengine/app'
import { AssetPlugin } from '@wimaengine/asset'
import { Material } from '@wimaengine/render-core'
import {
  Canvas2DMaterialPlugin,
  Canvas2DRendererPlugin
} from '@wimaengine/render-canvas2d'

class OutlineMaterial extends Material {}
const drawOutline = (ctx, material, mesh, textures) => {
  // Draw `mesh` using `material` and the shared `textures` cache.
}

new App()
  .registerPlugin(new AssetPlugin({ asset: OutlineMaterial }))
  .registerPlugin(new Canvas2DRendererPlugin())
  .registerPlugin(new Canvas2DMaterialPlugin({
    material: OutlineMaterial,
    update: drawOutline
  }))
  .run()

Constructor


Properties


readonlyupdate: Canvas2DFunction<T>

View source

Canvas 2D draw callback used for each opaque item of T.

The callback follows Canvas2DFunction.

readonlymaterial: Constructor<T>

View source

Constructor for the Material asset type rendered by this plugin.

The plugin uses this constructor to identify the material type it handles.

Methods


register(app: App): void

View source

Connects this material type to its Canvas 2D draw callback for an app.

Matching opaque items are drawn through Canvas2DMaterialPlugin#update using Canvas2DFunction.

Parameters

NameDescriptionDefault
app

App receiving this material renderer.

—

requires(): TypeId[]

View source

Returns the plugin IDs required by this Canvas 2D material renderer.

The IDs are returned in this order: typeid(CorePlugin), typeid(Canvas2DRendererPlugin), typeid(RenderCorePlugin), typeid(Transform2DPlugin), and typeid(WindowPlugin). The app validates these IDs through Plugin#requires; it does not install missing dependencies.

Returns

Required plugin type IDs.

name(): TypeId

View source

Returns this instance’s generic plugin identity.

The value is typeidGeneric(Canvas2DMaterialPlugin, [this.material]). The material constructor is part of the identity; the update callback is not, so instances configured with the same material constructor receive the same plugin ID even when their callbacks differ.

Returns

Generic ID for this material asset type.