# graphics3d/toon/toondrawqueue (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/graphics3d/toon/toondrawqueue/

Toon draw queue. (holds the models to draw in a frame, then draws them in order with ToonRenderer)

Example: One frame with shadows, screen-space outline and transparent things through the draw queue

```js
import { ToonRenderer, ToonDrawQueue, ToonScreenOutline, MeshBuilder, createSphereGeometry, ShadowMap, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const builder = new MeshBuilder();
builder.addPart(createSphereGeometry(0.5, 32, 20), Matrix4.createIdentity(), "#f0e8e0", { hasOutline: false });
const ballMesh = renderer.createMesh(builder.readArrays());
const shadowMap = new ShadowMap(webGL2RenderingContext, 1024);
shadowMap.updateLightMatrix(Vector3.create(0, 0, 0), Vector3.create(-0.4, -1, -0.3), 5, 0.5, 30);
renderer.setShadow(shadowMap, 1);
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(0, 2, 5), Vector3.create(0, 0.5, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
queue.addMesh(ballMesh, Matrix4.createTranslation(0, 0.5, 0), { lineId: 1 });
queue.addMesh(ballMesh, Matrix4.createTranslation(1.2, 0.5, 0), { lineId: 2, alpha: 0.5 });
queue.drawShadows(renderer, shadowMap);
queue.draw(renderer, camera);
```

## ToonDrawItem

A retained draw item. (Holds the mesh, model matrix and options and remembers the resolved options; add it with ToonDrawQueue.addItem every frame)
- Same shape as Unity's MeshRenderer and Unreal's primitive component. Once built and held, the draw queue does not compare or resolve the options object every frame.
  Build one per part for models with many parts. (indexStart, indexCount of the material range in the options)
- The options object is held as given. (Not copied) After changing options, the item needs a dirty mark to resolve again:
  setOption(name, value) and setOptions(newOptions) mark it themselves. Call markDirty() after changing values of the options object in place (including numbers of a tint array).
- The model matrix is copied. Pass changes with setModelMatrix. (Pass a matrix changed in place again, do not change the held matrix)
  Items with no change (mesh, matrix, options) are not compared by the shadow cache (ShadowUpdateMode.onChange) either. (Compared when there are joint matrices)
- Draws the same image as addMesh. The options are the same as addMesh's. (ToonRenderer.drawMesh options plus castsShadow, group, isDepthPrepassed, lineId, hasScreenOutline, hasCreaseLine)

Example: Mark only when the options change

```js
import { ToonDrawItem, Matrix4 } from "./vanilla.js";
const options = { tintColor: [1, 1, 1, 1], lineId: 7 };
const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), options);
drawItem.setOption("emissiveIntensity", 0.5);
options.tintColor[0] = 0.5;
drawItem.markDirty();
```

- `constructor(mesh, modelMatrix, options = {})` (constructor, since 0.4.0): Constructor.
  - `mesh` object | null: Result of ToonRenderer.createMesh.
  - `modelMatrix` Matrix4: Model matrix. (Copied)
  - `options` object: Options, same as ToonDrawQueue.addMesh.
- `getMesh()` (method, since 0.4.0): Returns the mesh.
  - returns object | null: Mesh.
- `setMesh(mesh)` (method, since 0.4.0): Changes the mesh. (Options unchanged)
  - `mesh` object | null: Result of ToonRenderer.createMesh.

  Example: Change the mesh

  ```js
  import { ToonDrawItem, Matrix4 } from "./vanilla.js";
  const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), {});
  drawItem.setMesh(null);
  ```

- `getModelMatrix()` (method, since 0.4.0): Returns the model matrix. (The held one, read only, use setModelMatrix to change it)
  - returns Matrix4: Model matrix.
- `setModelMatrix(modelMatrix)` (method, since 0.4.0): Changes the model matrix. (Copies the values, the same values do not count as a change)
  - `modelMatrix` Matrix4: Model matrix. (Copied)

  Example: Change the model matrix

  ```js
  import { ToonDrawItem, Matrix4 } from "./vanilla.js";
  const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), {});
  drawItem.setModelMatrix(Matrix4.createTranslation(1, 0, 0));
  ```

- `getOptions()` (method, since 0.4.0): Returns the options. (The held object, call markDirty after changing it in place)
  - returns object: Draw options.
- `setOptions(options)` (method, since 0.4.0): Changes the options. (Holds the new options object and marks dirty)
  - `options` object: Options, same as ToonDrawQueue.addMesh.

  Example: Replace the options

  ```js
  import { ToonDrawItem, Matrix4 } from "./vanilla.js";
  const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), { lineId: 1 });
  drawItem.setOptions({ lineId: 1, alpha: 0.5 });
  ```

- `setOption(name, value)` (method, since 0.4.0): Changes one option. (Sets the option on the held options object and marks dirty, undefined removes it)
  - `name` string: Name of the option. (tintColor, emissiveIntensity, alpha and the like)
  - `value` any: Value. (undefined removes the option to use the default)

  Example: Change the tint

  ```js
  import { ToonDrawItem, Matrix4 } from "./vanilla.js";
  const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), { lineId: 1 });
  drawItem.setOption("tintColor", [1, 0.6, 0.6, 1]);
  ```

- `markDirty()` (method, since 0.4.0): Marks dirty. (Call after changing values of the options object in place, the options are resolved again the next time it is added)

  Example: Mark after changing in place

  ```js
  import { ToonDrawItem, Matrix4 } from "./vanilla.js";
  const options = { tintColor: [1, 1, 1, 1] };
  const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), options);
  options.tintColor[1] = 0.5;
  drawItem.markDirty();
  ```

- `isDirty()` (method, since 0.4.0): Whether it is marked dirty.
  - returns boolean: true when the options will be resolved again the next time it is added.

## ToonDrawQueue

Toon draw queue. (Holds the models to draw in a frame, then draws them in order with ToonRenderer)
- Order: (line target of the screen-space outline) → stage beforeOpaque → opaque bodies → afterOpaque → outline shells of opaque things → screen-space outline → afterOutline
  → transparent things (farthest from the camera first, depth not written) → afterTransparent.
  Outlines are drawn together after all bodies to switch programs less, and transparent things are blended last from the farthest so what is behind shows through.
- Opaque things (bodies, outline shells, shadow depth) are drawn sorted by material, model and base color texture. (Ties keep the order they were added, so state changes less, like the Unity SRP Batcher)
  The depth test (LEQUAL) keeps the nearest one, so the screen is the same as in the added order. Only faces at exactly the same depth (overlapping planes) show the order, because the one drawn later wins.
  Merge such things into one model or offset their depth. Transparent things are drawn as before, farthest first in the added order.
- Transparent things: those whose alpha or tintColor alpha at draw time is below 1, or whose blendMode is not alpha. Their outline shells are drawn with them too (hasOutline).
- Groups: transparent things with the same options.group are sorted as one lump by the middle depth (average of the members) and drawn in the order they were added.
  If even one member of a group has options.isDepthPrepassed, that lump draws depth first and then paints color only on pixels with the same depth (LEQUAL).
  A hologram made of several overlapping parts shows through as one lump instead of being doubly bright. Lumps are drawn farthest first so they show through each other.
- Screen-space outline: if setScreenOutline(ToonScreenOutline) is given, draw draws opaque things into the line target before the bodies and blends it after the outline shells.
  The ID is options.lineId (the order added + 1 if not given, for instances instances[i].lineId and for instance buffers the layout's instanceLineId slot comes first), and per model options.hasScreenOutline and options.hasCreaseLine turn it off and on.
  Transparent things are not drawn into the line target. If there is a screen rectangle (ToonRenderer.setScreenRect), that rectangle is used as the drawing area of the line target.
- Ambient occlusion: with setPostProcess(ToonPostProcess) and setAmbientOcclusion turned on in the post process, it is computed after the line target and before bodies, set on the renderer and cleared after endFrame. (without outlines, only the line target is drawn, without lines)
- Stage callbacks: callback(renderer, webGL2RenderingContext) of addPass(stage, callback) is called at that point. After the call, the renderer sets the frame's draw state again.
- Instance batches (addMeshInstanced) draw body and outline shell at once if opaque, and if transparent are sorted as one lump by the center of the instance positions.
  They are culled per instance and uploaded each time they are drawn. (The body, shadows and line target each upload the same array) Long-lived ones share a buffer uploaded once with addMeshInstanceBuffer.
- Instance buffers (addMeshInstanceBuffer) follow the form of Unity's Graphics.RenderMeshInstanced with GraphicsBuffer and Godot's MultiMesh. They are culled as a whole by the bounds of the entire buffer and not uploaded again.
- Shadows: drawShadows(renderer, shadowMap) draws only opaque things whose castsShadow is not false into the sun's shadow depth. Call it before draw.
  It follows setUpdateMode(ShadowUpdateMode) of the shadow target. The default onChange does not redraw when the lights and casters are unchanged, bakes the ones that stay still and draws only the moving ones on top. (The screen is the same as drawing every frame)
  For point light and spotlight shadows, drawLocalShadows(renderer, shadowAtlas) draws the same things per atlas tile. (Set on the renderer with setLocalShadows)
- Use: every frame clear() → addMesh / addMeshInstanced / addMeshInstanceBuffer / addPass → (drawShadows) → draw(renderer, camera) or drawWithMatrices(renderer, view matrix, projection matrix)
  draw calls renderer.beginFrameWithCamera(camera) and endFrame by itself. drawWithMatrices calls beginFrameWithMatrices. (Orthographic or raw matrix camera)
  The screen rectangle (ToonRenderer.setScreenRect) is set before that. clear empties all added models and stage callbacks. (The screen-space outline is kept)
- What is added are references to matrices and options. Do not change them until draw is called.

Example: Decide the outline form per model

```js
import { ToonRenderer, ToonDrawQueue, ToonScreenOutline, MeshBuilder, createBoxGeometry, createFacetedChunkGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const renderer = new ToonRenderer(webGL2RenderingContext);
const floorBuilder = new MeshBuilder();
floorBuilder.addPart(createBoxGeometry(8, 0.2, 8), Matrix4.createTranslation(0, -0.1, 0), "#708090", { hasOutline: false });
const floorMesh = renderer.createMesh(floorBuilder.readArrays());
const gemBuilder = new MeshBuilder();
gemBuilder.addPart(createFacetedChunkGeometry(0.5, [1, 0.9, 1.1], [1, 1, 1]), Matrix4.createTranslation(0, 0.5, 0), "#a0c0ff", { hasOutline: false });
const gemMesh = renderer.createMesh(gemBuilder.readArrays());
const camera = new Camera3D();
camera.setPerspective(0.8, 0.1, 100);
camera.lookAt(Vector3.create(0, 2, 4), Vector3.create(0, 0.4, 0), Vector3.create(0, 1, 0));
const queue = new ToonDrawQueue();
queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
queue.addMesh(floorMesh, Matrix4.createIdentity(), { lineId: 1, hasScreenOutline: false });
queue.addMesh(gemMesh, Matrix4.createIdentity(), { lineId: 2, hasCreaseLine: false });
queue.draw(renderer, camera);
```

- `constructor()` (constructor, since 0.4.0): Constructor.
- `clear()` (method, since 0.4.0): Clear. (Before adding each frame, also clears stage callbacks, the screen-space outline is kept)
- `getItemCount()` (method, since 0.4.0): Returns the queued count.
  - returns number: Number of added models and instance batches.
- `setScreenOutline(screenOutline)` (method, since 0.4.0): Hand over the screen-space outline. (draw draws the line target and blends it after the outline shells, null hands over nothing)
  - `screenOutline` object | null: ToonScreenOutline or null.

  Example: Hand the screen-space outline to the draw queue

  ```js
  import { ToonDrawQueue, ToonScreenOutline } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const queue = new ToonDrawQueue();
  const outline = new ToonScreenOutline(webGL2RenderingContext);
  outline.setWidth(2.5);
  queue.setScreenOutline(outline);
  ```

- `getScreenOutline()` (method, since 0.4.0): Return the handed-over screen-space outline. (null if none)
  - returns object | null: ToonScreenOutline or null.
- `setPostProcess(postProcess)` (method, since 0.4.0): Hands over the toon post process. (if ambient occlusion is on, draw computes it after the line target and before bodies, sets it on the renderer and clears it after endFrame, null hands over nothing)
  - Uses the screen outline's line target if there is one, otherwise draws only normals and depth with the post process prepass (getAmbientOcclusionPrepass).
  - `postProcess` object | null: ToonPostProcess or null.

  Example: Outlines and ambient occlusion together

  ```js
  import { ToonDrawQueue, ToonScreenOutline, ToonPostProcess } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const postProcess = new ToonPostProcess(webGL2RenderingContext, 640, 360, { depthBits: 24 });
  postProcess.setAmbientOcclusion(true, 0.5, 0.5, 0.5);
  const queue = new ToonDrawQueue();
  queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
  queue.setPostProcess(postProcess);
  ```

- `getPostProcess()` (method, since 0.4.0): Returns the handed-over toon post process. (null if none)
  - returns object | null: ToonPostProcess or null.
- `addPass(stage, callback)` (method, since 0.4.0): Adds a stage callback. (Calls callback(renderer, webGL2RenderingContext) at the ToonDrawStage position, in the order added)
  - `stage` string: ToonDrawStage.
  - `callback` Function: Receives (renderer, webGL2RenderingContext). After the call, the renderer sets the frame's draw state again.
- `addMesh(mesh, modelMatrix, options = EMPTY_OPTIONS)` (method, since 0.4.0): Queues a single model. (Not queued if null)
  - `mesh` object | null: Result of ToonRenderer.createMesh.
  - `modelMatrix` Matrix4: Model matrix. (Do not change it until draw)
  - `options` object: Form of ToonRenderer.drawMesh plus castsShadow (default true), group, isDepthPrepassed, lineId, hasScreenOutline (default true), hasCreaseLine (default true).
- `createItem(mesh, modelMatrix, options = {})` (method, since 0.4.0): Builds a retained draw item. (Build once, hold it and add it with addItem every frame, same as new ToonDrawItem)
  - `mesh` object | null: Result of ToonRenderer.createMesh.
  - `modelMatrix` Matrix4: Model matrix. (Copied and held, change it with the item's setModelMatrix)
  - `options` object: Options, same as addMesh. (Held, call markDirty or setOption after changing)
  - returns ToonDrawItem: Draw item.

  Example: Build an item per part once and add it every frame

  ```js
  import { ToonRenderer, ToonDrawQueue, MeshBuilder, createBoxGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const renderer = new ToonRenderer(webGL2RenderingContext);
  const builder = new MeshBuilder();
  builder.addPart(createBoxGeometry(1, 1, 1), Matrix4.createIdentity(), "#c08060");
  const boxMesh = renderer.createMesh(builder.readArrays());
  const camera = new Camera3D();
  camera.setPerspective(0.8, 0.1, 100);
  camera.lookAt(Vector3.create(0, 2, 4), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const queue = new ToonDrawQueue();
  const boxItem = queue.createItem(boxMesh, Matrix4.createTranslation(0, 0.5, 0), { tintColor: [1, 0.8, 0.8, 1], lineId: 1 });
  queue.clear();
  queue.addItem(boxItem);
  queue.draw(renderer, camera);
  boxItem.setOption("tintColor", [0.8, 1, 0.8, 1]);
  ```

- `addItem(drawItem)` (method, since 0.4.0): Adds a retained draw item. (Same place as addMesh, uses the options resolved before when not marked dirty)
  - Does not compare or resolve the options object every frame. After changing options call the item's markDirty, setOption or setOptions. (Unity MeshRenderer, Unreal primitive component shape)
  - Items with no change are not compared by the shadow cache (onChange) either. Pass a changed matrix with setModelMatrix.
  - `drawItem` ToonDrawItem: Result of createItem or new ToonDrawItem.

  Example: Add a retained item

  ```js
  import { ToonDrawQueue, ToonDrawItem, Matrix4 } from "./vanilla.js";
  const queue = new ToonDrawQueue();
  const drawItem = new ToonDrawItem(null, Matrix4.createIdentity(), { lineId: 3 });
  queue.clear();
  queue.addItem(drawItem);
  ```

- `addMeshInstanced(mesh, instances, options = EMPTY_OPTIONS)` (method, since 0.4.0): Queues multiple instances of the same model. (GPU instancing, not queued if empty or null)
  - `mesh` object | null: Result of ToonRenderer.createMesh.
  - `instances` Array<object>: Array of { modelMatrix, tintColor, lineId (optional) }.
  - `options` object: Same as addMesh.
- `addMeshInstanceBuffer(mesh, instanceBuffer, instanceCount, options = EMPTY_OPTIONS)` (method, since 0.4.0): Adds many of the same model with a persistent instance buffer. (The body, outline shell, shadows and line target share one GPU buffer and do not upload it again)
  - Build the buffer with ToonRenderer.createInstanceBuffer and change it with updateInstanceBuffer or updateInstanceBufferRange. Culled as a whole by the bounds of the entire buffer.
  - The line ID of each instance is the layout's instanceLineId slot, otherwise options.lineId (the order added + 1 if not given).
  - The shadow cache (ShadowUpdateMode.onChange) learns of changes through the buffer's generation.
  - `mesh` object | null: Result of ToonRenderer.createMesh.
  - `instanceBuffer` object | null: The result of ToonRenderer.createInstanceBuffer.
  - `instanceCount` number: Number of instances to draw. (Clipped if it exceeds the number in the buffer, not added if 0 or less)
  - `options` object: Same as addMesh.

  Example: Draw the miner's rock field with a buffer uploaded once and change only one

  ```js
  import { ToonRenderer, ToonDrawQueue, ToonScreenOutline, MeshBuilder, createOctahedronGeometry, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const renderer = new ToonRenderer(webGL2RenderingContext);
  const builder = new MeshBuilder();
  builder.addPart(createOctahedronGeometry(0.3), Matrix4.createIdentity(), "#a89880");
  const rockMesh = renderer.createMesh(builder.readArrays());
  const instanceLayout = renderer.createInstanceLayout([{ name: "instanceMatrix", size: 16 }, { name: "instanceTint", size: 4 }, { name: "instanceLineId", size: 1 }]);
  const floatCount = instanceLayout.getFloatCount();
  const data = new Float32Array(floatCount * 25);
  for (let index = 0; index < 25; ++index) {
  	data.set(Matrix4.createTranslation(index % 5 - 2, 0, Math.floor(index / 5) - 2).getElements(), index * floatCount);
  	data.set([1, 1, 1, 1, 1 + index], index * floatCount + 16);
  }
  const instanceBuffer = renderer.createInstanceBuffer(instanceLayout, data, "dynamic");
  const camera = new Camera3D();
  camera.setPerspective(0.8, 0.1, 50);
  camera.lookAt(Vector3.create(0, 5, 6), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const queue = new ToonDrawQueue();
  queue.setScreenOutline(new ToonScreenOutline(webGL2RenderingContext));
  queue.addMeshInstanceBuffer(rockMesh, instanceBuffer, 25);
  queue.draw(renderer, camera);
  const brokenRock = data.slice(12 * floatCount, 13 * floatCount);
  brokenRock.set([0.5, 0.5, 0.5, 1], 16);
  renderer.updateInstanceBufferRange(instanceBuffer, 12, brokenRock);
  queue.draw(renderer, camera);
  ```

- `isTransparentOptions(options)` (method, since 0.4.0): Whether the shape to draw is translucent. (alpha or the tint's alpha is less than 1, or the blend mode is not straight alpha)
  - `options` object: Draw options.
  - returns boolean: true if transparent.
- `drawShadows(renderer, shadowMap)` (method, since 0.4.0): Draws shadow depth. (Only opaque ones whose castsShadow is not false, restores the previous framebuffer and viewport)
  - `renderer` object: ToonRenderer.
  - `shadowMap` object: ShadowMap.
- `drawLocalShadows(renderer, shadowAtlas)` (method, since 0.4.0): Draw point light and spotlight shadow depth. (Opaque things whose castsShadow is not false, per atlas tile, the previous framebuffer and viewport are restored)
  - `renderer` object: ToonRenderer.
  - `shadowAtlas` object: ShadowAtlas. (One on which updateLights was called)

  Example: Bake and receive point light shadows

  ```js
  import { ToonRenderer, ToonDrawQueue, MeshBuilder, createBoxGeometry, createSphereGeometry, ShadowAtlas, Camera3D, Matrix4, Vector3 } from "./vanilla.js";
  const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
  const renderer = new ToonRenderer(webGL2RenderingContext);
  const builder = new MeshBuilder();
  builder.addPart(createBoxGeometry(4, 0.2, 4), Matrix4.createTranslation(0, -0.1, 0), "#8090a0", { hasOutline: false });
  builder.addPart(createSphereGeometry(0.5, 24, 16), Matrix4.createTranslation(0, 0.5, 0), "#f0e0d0", { hasOutline: false });
  const mesh = renderer.createMesh(builder.readArrays());
  renderer.setPointLights([{ position: [1, 2, 1], color: [1, 0.85, 0.6], intensity: 4, range: 8, castsShadow: true }]);
  const shadowAtlas = new ShadowAtlas(webGL2RenderingContext, 1024);
  shadowAtlas.updateLights(renderer.getLightSet().getPointLights());
  renderer.setLocalShadows(shadowAtlas, 1);
  const camera = new Camera3D();
  camera.setPerspective(0.8, 0.1, 50);
  camera.lookAt(Vector3.create(0, 3, 5), Vector3.create(0, 0, 0), Vector3.create(0, 1, 0));
  const queue = new ToonDrawQueue();
  queue.addMesh(mesh, Matrix4.createIdentity());
  queue.drawLocalShadows(renderer, shadowAtlas);
  queue.draw(renderer, camera);
  ```

- `draw(renderer, camera)` (method, since 0.4.0): Draw what was added. (Starts with the line target if there is a screen-space outline, calls beginFrameWithCamera and endFrame by itself)
  - `renderer` object: ToonRenderer.
  - `camera` object: Camera3D.
- `drawWithMatrices(renderer, viewMatrix, projectionMatrix)` (method, since 0.4.0): Draws the queued items with view and projection matrices. (Without Camera3D, calls beginFrameWithMatrices and endFrame itself)
  - `renderer` object: ToonRenderer.
  - `viewMatrix` Matrix4: View matrix.
  - `projectionMatrix` Matrix4: Projection matrix.
- `drawLineIds(renderer, viewMatrix, projectionMatrix)` (method, since 0.4.0): Draw the line target of the screen-space outline. (Does nothing if none was handed over, opaque things only, uses the screen rectangle as the drawing area if there is one)
  - `renderer` object: ToonRenderer.
  - `viewMatrix` Matrix4: View matrix.
  - `projectionMatrix` Matrix4: Projection matrix.
- `runPasses(renderer, stage)` (method, since 0.4.0): Calls the callbacks of one stage. (Re-applies the frame's draw state after calling)
  - `renderer` object: ToonRenderer.
  - `stage` string: ToonDrawStage.
- `drawStages(renderer, readDepth)` (method, since 0.4.0): Draws per stage. (Between beginFrame and endFrame, readDepth(position) is the view depth from the camera)
  - `renderer` object: ToonRenderer.
  - `readDepth` Function: Returns the view depth of ({ x, y, z }).
- `drawItem(renderer, item, options)` (method, since 0.4.0): Draws one item. (A single model uses drawMesh, an instance group uses drawMeshInstanced, an instance buffer uses drawMeshInstanceBuffer)
  - `renderer` object: ToonRenderer.
  - `item` object: One added item.
  - `options` object: Draw options to use this time.

## ToonDrawStage (enum)

Stages of the draw queue. (Where addPass callbacks are called)
- beforeOpaque: before opaque bodies. (Planar mirror reflection, sky)
- afterOpaque: after opaque bodies, before outline shells.
- afterOutline: after outline shells and the screen-space outline, before transparent things.
- afterTransparent: after transparent things. (Effects)

Example: Draw the sky after the opaque things

```js
import { ToonDrawQueue, ToonDrawStage } from "./vanilla.js";
const queue = new ToonDrawQueue();
queue.addPass(ToonDrawStage.afterOpaque, (renderer, webGL2RenderingContext) => {
	webGL2RenderingContext.depthMask(false);
});
```

- `beforeOpaque` = `beforeOpaque`: Before opaque bodies.
- `afterOpaque` = `afterOpaque`: After opaque bodies, before outline shells.
- `afterOutline` = `afterOutline`: After outline shells and the screen-space outline, before transparent things.
- `afterTransparent` = `afterTransparent`: After transparent things.
