Skip to content

PixelCommand ​

One change to a pixel document: its pixels, UV regions or normal map settings. A document emits commands for local edits, undo and redo, and applies commands from peers. A headless PixelDocumentState applies the same commands.

ts
type PixelCommand = (
  | { action: "stroke"; metadata: { color: RGBA8; positions: Vec2[] } }
  | { action: "resized"; metadata: { size: Vec2 } }
  | { action: "texture-replaced"; metadata: { size: Vec2; pixels: string } }
  | { action: "global-fill"; metadata: { fromColor: RGBA8; toColor: RGBA8 } }
  | { action: "select-edit"; metadata: { positions: Vec2[]; colors: RGBA8[] } }
  | { action: "palette-color-changed"; metadata: { index: number; color: RGBA8 } }
  | { action: "uv-region-created"; metadata: { region: UVRegionData } }
  | { action: "uv-region-deleted"; metadata: { id: string } }
  | { action: "uv-region-moved"; metadata: { id: string; face: UVSlot | null; rect: SelectionRect } }
  | { action: "uv-region-state-changed"; metadata: { region: UVRegionData } }
  | { action: "uv-region-rotated"; metadata: UVRegionRotation }
  | NormalMapCommand
);

type PixelCommandAction = PixelCommand["action"];

texture-replaced carries base64 RGBA8 bytes. Normal map commands are listed in NormalMapConfig.

PixelDocumentCommand ​

ts
type PixelDocumentCommand = /* the same variants, with texture bytes in memory */;

function toPixelCommand(command: PixelDocumentCommand): PixelCommand;
function toPixelDocumentCommand(command: PixelCommand): PixelDocumentCommand;

PixelDocumentCommand is the in-memory form: texture-replaced holds its bytes as a Uint8ClampedArray. Document changes, history steps and PixelDocumentState.apply() use it. The two functions convert between the forms; every other variant is returned as is.

Applying ​

ActionEffect
strokepaints color at positions
resizedresizes the texture, restoring retained pixels
texture-replacedreplaces the size and every pixel
global-fillrepaints every pixel of fromColor with toColor
select-editpaints each position with its own color
palette-color-changedreplaces one saved palette color; index must be 0–9 and all RGBA channels must be integer bytes
uv-region-createdadds the region, or replaces it when its id exists
uv-region-deletedremoves the region and its normal map zone
uv-region-movedmoves the region, or the slot of a free region, kept inside the texture; an unknown slot is ignored
uv-region-state-changedreplaces an existing region
uv-region-rotatedreplaces an existing region, or one slot's geometry

Commands for a missing region are ignored.