genenerateDrawGizmo2Dsystem

View sourcegenenerateDrawGizmo2Dsystem<T>(label: Constructor<T>): SystemFunc

Creates the canvas drawing system for a labelled Gizmo2D resource.

This is an ordinary system factory. It does not register a plugin or a system itself; Gizmo2DPlugin calls it and registers the returned function in AppSchedule.Update. The label is combined with Gizmo2D through typeidGeneric(Gizmo2D, [label]), so it must be the same constructor used when the gizmo resource was installed.

Each invocation looks up that resource, the Windows canvas resource, the first entity matching [EntityHandle, Window], and the first entity matching [GlobalTransform2D, RenderLists2D, Camera]. With the default WindowPlugin setup, this is the primary window entity. The query does not require the MainWindow marker, so applications that manage their own windows can provide any matching Window entity. Windows must contain a canvas for the entity, as provided by DOMWindowPlugin; the canvas must also expose a 2D rendering context. The camera must use an OrthographicProjection; gizmo positions are interpreted as world coordinates and transformed into canvas space using that camera.

The system returns without drawing when there is no matching window, camera, orthographic projection, canvas mapped to that window, or 2D context. These early returns leave the gizmo buffer unchanged. A labelled Gizmo2D resource and the Windows resource are required by the world; the factory does not install either one.

Before drawing, the system maps GizmoSettings to the canvas context: line width, cap, join, dash pattern, and dash offset. Entries in GizmoBuffer#positions and GizmoBuffer#colors are consumed in pairs as independent gradient lines. Entries in GizmoBuffer#polylinePositions and GizmoBuffer#polylineColors are consumed as adjacent pairs; the NaN sentinel written by Gizmo2D#polyline and Gizmo2D#polylineGradient prevents a segment from connecting separate polylines. Entries in GizmoBuffer#fillPositions are consumed as sentinel-delimited triangle strips. The first corresponding color in GizmoBuffer#fillColors is used for the entire strip. Entries in GizmoBuffer#texts and GizmoBuffer#fillTexts are rendered with their corresponding affine transforms, colors, and horizontal alignments after all shape geometry. Each entry also supplies its font size. After a successful draw, the buffer is cleared and the canvas state is restored. The returned SystemFunc accepts a world and returns undefined.

Examples

import { AppSchedule } from '@wimaengine/core'
import { genenerateDrawGizmo2Dsystem } from '@wimaengine/gizmo'

class PhysicsDebug {}
const drawPhysicsGizmo = genenerateDrawGizmo2Dsystem(PhysicsDebug)
app.registerSystem({ schedule: AppSchedule.Update, system: drawPhysicsGizmo })

Type Parameters

T

Parameters

NameDescriptionDefault
label——

Returns

A system that draws the labelled gizmo on the active canvas.