Gizmo2D

View source

Provides a labelled world resource for immediate-mode two-dimensional debug drawing.

The generic label is part of the resource’s type ID, so use the same constructor when retrieving it; different labels produce separate gizmo resources. The constructor is exposed as Gizmo2D#type for code that needs to inspect the label.

The resource keeps its current drawing transform, collects transformed line and polyline vertices in Gizmo2D#buffer, and uses Gizmo2D#settings for line width, cap, join, and dash behavior. Use Gizmo2D#reset, Gizmo2D#setTransform, and the transform helpers to position subsequent shapes; use primitive helpers such as Gizmo2D#line, Gizmo2D#arc, and Gizmo2D#grid to append geometry. Drawing clears the buffer only after a successful draw; missing window or canvas resources leave the buffer intact.

Examples

import { Color } from '@wimaengine/color'
import { Gizmo2D } from '@wimaengine/gizmo'
import { typeidGeneric } from '@wimaengine/type'

class PhysicsDebug {}

function drawPhysicsDebug(world) {
  const gizmo = world.getResourceByTypeId(
    typeidGeneric(Gizmo2D, [PhysicsDebug])
  )

  gizmo.reset().translate(10, 10).circle(2, Color.RED)
}

Constructor


Properties


Methods


setTransform(matrix: Affine2): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
matrix——

transform(matrix: Affine2): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
matrix——

compose(translation: Vector2, orientation: Rotary, scale: Vector2): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
translation——
orientation——
scale——

text(value: string, color: Color, align: number, size: number): Gizmo2D<T>

View source

Draws stroked text at the current transform’s origin.

Parameters

NameDescriptionDefault
value——
color—Color.WHITE
align—GizmoTextAlign.Left
size—16

line(start: Vector2, end: Vector2, color: Color): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
start—...
end—...
color—Color.WHITE

lineGradient(start: Vector2, end: Vector2, colorStart: Color, colorEnd: Color): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
start——
end——
colorStart——
colorEnd——

fillText(value: string, color: Color, align: number, size: number): Gizmo2D<T>

View source

Draws filled text at the current transform’s origin.

Parameters

NameDescriptionDefault
value——
color—Color.WHITE
align—GizmoTextAlign.Left
size—16

polyline(points: Vector2[], color: Color): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
points——
color——

polylineGradient(points: [Vector2, Color][]): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
points——

sector(arcStart: number, arcEnd: number, radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>

View source

Draws a sector outline from the origin.

Parameters

NameDescriptionDefault
arcStart——
arcEnd——
radiusX—1
radiusY—1
color—...
resolution—32

fillSector(arcStart: number, arcEnd: number, radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>

View source

Draws a filled sector from the origin.

Parameters

NameDescriptionDefault
arcStart——
arcEnd——
radiusX—1
radiusY—1
color—...
resolution—32

polygon(vertices: Vector2[], color: Color): Gizmo2D<T>

View source

Draws a closed polygon outline.

Parameters

NameDescriptionDefault
vertices——
color—Color.WHITE

fillPolygon(vertices: Vector2[], color: Color): Gizmo2D<T>

View source

Draws a filled convex polygon.

Parameters

NameDescriptionDefault
vertices——
color—Color.WHITE

capsule(radius: number, halfLength: number, color: Color, resolution: number): Gizmo2D<T>

View source

Draws a capsule centered on the origin and aligned to the local Y axis.

Parameters

NameDescriptionDefault
radius—1
halfLength—1
color—Color.WHITE
resolution—16

fillCapsule(radius: number, halfLength: number, color: Color, resolution: number): Gizmo2D<T>

View source

Draws a filled capsule centered on the origin and aligned to the local Y axis.

Parameters

NameDescriptionDefault
radius—1
halfLength—1
color—Color.WHITE
resolution—16

fillTriangle(base: number, height: number, baseRatio?: number, color: Color): Gizmo2D<T>

View source

Draws a filled triangle.

Parameters

NameDescriptionDefault
base—1
height—1
baseRatio?—0
color—Color.WHITE

arrow(direction: Vector2, length: number, color: Color): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
direction—...
length—1
color—...

grid(cellCount: Vector2, spacing: Vector2, color: Color, drawEdges: BVector2): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
cellCount—...
spacing—...
color—Color.WHITE
drawEdges—...

fillCircle(radius: number, color: Color, resolution: number): Gizmo2D<T>

View source

Draws a filled circle.

Parameters

NameDescriptionDefault
radius——
color——
resolution—32

rect(halfWidth: number, halfHeight: number, color: Color): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
halfWidth——
halfHeight——
color——

fillRect(halfWidth: number, halfHeight: number, color: Color): Gizmo2D<T>

View source

Draws a filled rectangle centered on the origin.

Parameters

NameDescriptionDefault
halfWidth——
halfHeight——
color——

ellipse(radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>

View source

Parameters

NameDescriptionDefault
radiusX——
radiusY——
color——
resolution—32

fillEllipse(radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>

View source

Draws a filled ellipse.

Parameters

NameDescriptionDefault
radiusX——
radiusY——
color——
resolution—32