fvtt-canvas
This skill should be used when working with the Foundry canvas, PIXI.js rendering, canvas layers, placeable objects (tokens, tiles, drawings), render flags for performance, or canvas lifecycle hooks like canvasReady.
What this skill does
# Foundry VTT Canvas & PIXI.js
**Domain:** Foundry VTT Module/System Development
**Status:** Production-Ready
**Last Updated:** 2026-01-05
## Overview
The Foundry canvas is a WebGL-powered HTML5 canvas using PIXI.js for rendering. Understanding the layer architecture and PIXI basics is essential for visual customizations.
### When to Use This Skill
- Adding custom visual elements to the canvas
- Extending token/tile rendering
- Working with canvas layers
- Optimizing render performance
- Handling canvas lifecycle events
## Canvas Architecture
### Layer Hierarchy (Bottom to Top)
**Primary Group:**
- Background Layer - Scene backdrop
- Token Layer - Characters and creatures
- Tile Layer - Props and decorations
- Foreground Layer - Overlay images
- Weather Layer - Environmental effects
- Effects/Lighting - Vision and lighting
**Interface Group:**
- Walls Layer - Movement/sight blocking
- Sounds Layer - Audio zones
- Drawings Layer - User markup
- Templates Layer - Spell areas
- Notes Layer - Journal pins
- Controls Layer - Selection UI
- Grid Layer - Grid overlay
### Accessing Layers
```javascript
canvas.tokens // TokenLayer
canvas.tiles // TileLayer
canvas.drawings // DrawingsLayer
canvas.templates // TemplatesLayer
canvas.walls // WallsLayer
canvas.lighting // LightingLayer
canvas.sounds // SoundsLayer
canvas.notes // NotesLayer
canvas.grid // GridLayer
canvas.primary // PrimaryCanvasGroup
canvas.interface // InterfaceCanvasGroup
canvas.environment // EnvironmentCanvasGroup
```
## PIXI.js Basics
### Containers
Group objects together:
```javascript
const group = new PIXI.Container();
group.addChild(sprite1);
group.addChild(sprite2);
// Position the group (moves all children)
group.position.set(100, 100);
group.rotation = Math.PI / 4;
canvas.tokens.addChild(group);
```
### Sprites
Display images:
```javascript
const sprite = PIXI.Sprite.from("path/to/image.png");
// Use anchor for rotation center (0-1 percentage)
sprite.anchor.set(0.5); // Center
sprite.position.set(100, 100);
sprite.width = 50;
sprite.height = 50;
sprite.rotation = Math.PI / 4; // Radians
sprite.alpha = 0.8;
sprite.tint = 0xFF0000; // Red tint
```
### Graphics
Draw shapes programmatically:
```javascript
const graphics = new PIXI.Graphics();
// Filled rectangle
graphics.beginFill(0x0000FF, 0.5); // Blue, 50% alpha
graphics.drawRect(0, 0, 100, 100);
graphics.endFill();
// Stroked circle
graphics.lineStyle(2, 0xFF0000); // 2px red line
graphics.drawCircle(50, 50, 25);
// Polygon
graphics.beginFill(0x00FF00);
graphics.drawPolygon([0, 0, 50, 100, 100, 0]);
graphics.endFill();
canvas.drawings.addChild(graphics);
```
### Visual Effects
```javascript
// Transparency
sprite.alpha = 0.5;
// Color tint (multiply)
sprite.tint = 0xFF0000; // Red
sprite.tint = 0xFFFFFF; // No change (white)
// Blend modes
sprite.blendMode = PIXI.BLEND_MODES.ADD; // Glow effect
sprite.blendMode = PIXI.BLEND_MODES.MULTIPLY; // Darken
sprite.blendMode = PIXI.BLEND_MODES.SCREEN; // Lighten
// Filters (use sparingly - performance impact)
const blur = new PIXI.BlurFilter();
blur.blur = 10;
sprite.filters = [blur];
```
### Masking
```javascript
// Graphics mask
const mask = new PIXI.Graphics();
mask.beginFill(0xFFFFFF);
mask.drawCircle(50, 50, 50);
mask.endFill();
container.mask = mask;
container.addChild(contentToMask);
```
## Placeable Objects
### Common Placeables
- **Token** - Actor representation
- **Tile** - Static artwork
- **Drawing** - User shapes
- **Note** - Journal pin
- **Wall** - Blocking segment
- **AmbientLight** - Light source
- **AmbientSound** - Audio emitter
- **MeasuredTemplate** - Area indicator
### PlaceableObject Properties
```javascript
const token = canvas.tokens.get(tokenId);
token.document // TokenDocument
token.scene // Parent Scene
token.isOwner // Ownership check
// Permission checks
token.can("update")
token.can("delete")
token.can("control")
```
### PlaceableObject Methods
```javascript
// Control
token.control(); // Select
token.release(); // Deselect
await token.rotate(45); // Rotate by degrees
// Rendering
await token.draw(); // Full redraw
token.refresh(); // Incremental update
```
## Render Flags
Optimize updates by specifying what changed:
### Token Render Flags
```javascript
token.renderFlags.set({
refreshPosition: true, // X/Y changed
refreshSize: true, // Width/height changed
refreshRotation: true, // Angle changed
refreshBars: true, // HP bars changed
refreshEffects: true, // Status icons changed
refreshBorder: true, // Selection border
refreshVisibility: true, // Vision state
refreshElevation: true, // Z-axis display
refreshNameplate: true, // Name display
redraw: true // Complete redraw
});
```
### Why Use Render Flags
```javascript
// BAD - full redraw every time
token.draw();
token.draw();
token.draw();
// GOOD - batch incremental updates
token.renderFlags.set({ refreshPosition: true });
token.renderFlags.set({ refreshBars: true });
// Updates happen efficiently in next render cycle
```
## Canvas Lifecycle
### Initialization Order
```
init
→ setup
→ canvasConfig
→ canvasInit
→ ready
→ canvasReady
```
### Key Hooks
```javascript
// Canvas fully ready - safe to access all layers
Hooks.on("canvasReady", (canvas) => {
console.log("Scene:", canvas.scene.name);
console.log("Tokens:", canvas.tokens.placeables.length);
});
// Canvas being torn down
Hooks.on("canvasTearDown", (canvas) => {
// Clean up custom elements
});
// Canvas panned/zoomed
Hooks.on("canvasPan", (canvas, position) => {
console.log("New center:", position.x, position.y);
console.log("Scale:", position.scale);
});
```
### Waiting for Canvas
```javascript
// Promise-based
await canvas.ready;
// Hook-based
Hooks.once("canvasReady", () => {
// Safe to interact
});
```
## Common Patterns
### Add Custom Layer Element
```javascript
Hooks.on("canvasReady", () => {
const marker = new PIXI.Graphics();
marker.beginFill(0xFF0000);
marker.drawCircle(0, 0, 20);
marker.endFill();
marker.position.set(500, 500);
canvas.interface.addChild(marker);
});
```
### Extend Token Rendering
```javascript
class CustomToken extends Token {
async _draw() {
await super._draw();
// Add custom aura
const aura = new PIXI.Graphics();
aura.beginFill(0x00FF00, 0.2);
aura.drawCircle(0, 0, this.w);
aura.endFill();
this.addChildAt(aura, 0); // Behind token
}
}
// Register
CONFIG.Token.objectClass = CustomToken;
```
### Coordinate Conversion
```javascript
// Client (viewport) to canvas coordinates
const canvasCoords = canvas.canvasCoordinatesFromClient({
x: event.clientX,
y: event.clientY
});
// Canvas to client coordinates
const clientCoords = canvas.clientCoordinatesFromCanvas({
x: 500,
y: 500
});
```
### Pan and Zoom
```javascript
// Instant pan
await canvas.pan({ x: 1000, y: 1000 });
// Animated pan
await canvas.animatePan({
x: 1000,
y: 1000,
scale: 1.5,
duration: 1000
});
// Center on controlled token
await canvas.recenter();
```
## Common Pitfalls
### 1. Accessing Canvas Before Ready
```javascript
// WRONG - canvas not initialized
Hooks.on("init", () => {
canvas.tokens.placeables; // undefined!
});
// CORRECT - wait for canvasReady
Hooks.on("canvasReady", () => {
canvas.tokens.placeables; // works
});
```
### 2. Direct DOM Manipulation
```javascript
// WRONG - breaks PIXI rendering
element.style.transform = "rotate(45deg)";
// CORRECT - use PIXI properties
sprite.angle = 45; // degrees
sprite.rotation = Math.PI / 4; // radians
```
### 3. Wrong Canvas Group
```javascript
// WRONG - bypasses layer hierarchy
canvas.app.stage.addChild(myGraphics);
// CORRECT - add to appropriate group
canvas.interface.addChild(myGraphics);
```
### 4. Excessive Filters
```javascript
// Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.