# graphics3d/toon/meshbuilder (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/graphics3d/toon/meshbuilder/

Building toon 3D models. (MeshBuilder and basic shapes of vanilla.js graphics3d/toon/meshbuilder.js)
- Builds the vertex array used to draw toon 3D (single-color clay-like material with outlines). It came from the in-board 3D of webgame-rimminer. (Same form as the three.js basic geometries)
- Shapes are built in their own coordinates with the center at the origin. When a part is added, position, rotation and scale are multiplied in and it is put into one lump.
- One vertex is position 3, normal 3, color 3 (sRGB), material 2 (glow strength, unlit), pattern 4 (pattern number, pattern color).
  The meaning of the pattern number and color is decided by the shader that draws it. (0 means no pattern)
- Texture coordinates (UV) are stored separately, 2 per vertex, in uv_data outside the vertex array. If even one vertex was given a UV, the rest are filled with 0. (uvs of a shape, add_triangles_with_uvs)
- The second UV is stored the same way in uv1_data. (uvs1 of a shape, uvs1 of add_triangles_with_uvs, TEXCOORD_1 of GLB, for things that read a second unwrap such as the angel ring)
  (0, 0) is the top left of the image. (Same as glTF) A box is 0 ~ 1 per face, a sphere is 0 ~ 1 by longitude and latitude.
- A material range (material_ranges) is the span of body vertex indices that holds one material. The GLB reader stores one per primitive. (Material name, extras, textures, index_start and index_count of ToonDrawOptions)
- The outline is a shell pushed out by the same thickness at every point of the part. Since only its back faces are drawn, it is stored separately. (inverted hull)
- Triangle winding is fixed by looking at the vertex normals so the outside becomes the front face. (Back-face culling and the outline rely on winding)

## ToonGeometry (struct) (Clone, Debug, Default)

Basic shape. (positions centered at the origin, normals, vertex indices)
- uvs are two texture coordinates per point. (only boxes and spheres build them, none if empty)

Example: See the point, triangle and texture coordinate counts of a box shape

```rust
use vanilla::create_box_geometry;

let geometry = create_box_geometry(1.0, 2.0, 3.0);
assert_eq!(geometry.positions.len(), 24 * 3);
assert_eq!(geometry.normals.len(), geometry.positions.len());
assert_eq!(geometry.indices.len(), 36);
assert_eq!(geometry.uvs.len(), 24 * 2);
assert!(geometry.uvs1.is_empty());
```

- `pub positions: Vec<f64>` (field, since 0.4.0): Three position values per point.
  - returns Vec<f64>
- `pub normals: Vec<f64>` (field, since 0.4.0): Three unit normal values per point.
  - returns Vec<f64>
- `pub indices: Vec<u32>` (field, since 0.4.0): Three point indices per triangle.
  - returns Vec<u32>
- `pub uvs: Vec<f64>` (field, since 0.4.0): Two texture coordinates per point. (Only boxes and spheres build them, empty means none)
  - returns Vec<f64>
- `pub uvs1: Vec<f64>` (field, since 0.4.0): Two second UV texture coordinates per point. (none if empty)
  - returns Vec<f64>

## ToonPartOptions (struct) (Clone, Copy, Debug, Default)

Options for adding a part. (emissive, unlit, whether it has an outline and its width)

Example: Glowing eyes and a shadow plate without outline

```rust
use std::f64::consts::PI;
use vanilla::{create_cylinder_geometry, create_sphere_geometry, Matrix4, MeshBuilder, ToonPartOptions};

let mut builder = MeshBuilder::new();
builder.add_part(&create_sphere_geometry(0.5, 24, 16, PI), &Matrix4::create_translation(0.0, 0.5, 0.0), "#f0e0d0", ToonPartOptions { outline_width: 0.03, ..ToonPartOptions::default() });
builder.add_part(&create_sphere_geometry(0.06, 10, 8, PI), &Matrix4::create_translation(0.15, 0.6, 0.45), "#40ffff", ToonPartOptions { glow: 2.0, is_unlit: true, has_outline: false, ..ToonPartOptions::default() });
let outline_index_count = builder.get_outline_index_count();
builder.add_part(&create_cylinder_geometry(0.5, 0.5, 0.01, 24), &Matrix4::create_translation(0.0, 0.005, 0.0), "#202020", ToonPartOptions { has_outline: false, ..ToonPartOptions::default() });
assert_eq!(builder.get_outline_index_count(), outline_index_count);
```

- `pub glow: f64` (field, since 0.4.0): Emissive strength. (first material slot of the vertex, 0 for no emission)
  - returns f64
- `pub is_unlit: bool` (field, since 0.4.0): Unlit. (second material slot of the vertex, its own color without shading)
  - returns bool
- `pub has_outline: bool` (field, since 0.4.0): Whether to store an outline shell.
  - returns bool
- `pub outline_width: f64` (field, since 0.4.0): Outline width. (default DEFAULT_OUTLINE_WIDTH)
  - returns f64

## ToonQuad (struct) (Clone, Copy, Debug)

One quad. (four points in perimeter order, outward face normal)

Example: Outline shells on the top and side faces of one block

```rust
use vanilla::{MeshBuilder, ToonQuad};

let mut builder = MeshBuilder::new();
let quads = [
	ToonQuad { corners: [[0.0, 1.0, 0.0], [1.0, 1.0, 0.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0]], normal: [0.0, 1.0, 0.0] },
	ToonQuad { corners: [[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0]], normal: [0.0, 0.0, 1.0] },
];
for quad in quads.iter() {
	builder.add_quad(quad.corners, quad.normal, [0.5, 0.4, 0.3], 0.0, None, false);
}
builder.add_quad_shell(&quads, 0.02);
assert_eq!(builder.get_index_count(), 12);
assert_eq!(builder.get_outline_index_count(), 12);
```

- `pub corners: [[f64; 3]; 4]` (field, since 0.4.0): Four points. ([x, y, z], in order around)
  - returns [[f64; 3]; 4]
- `pub normal: [f64; 3]` (field, since 0.4.0): Outward normal of the face. ([x, y, z])
  - returns [f64; 3]

## ToonMeshArrays (struct) (Clone, Debug, Default)

The built arrays. (body, outline shell, joint indices and weights, skeleton)

Example: See the sizes of the body and outline shell in the built arrays

```rust
use vanilla::{create_box_geometry, Matrix4, MeshBuilder, ToonPartOptions, VERTEX_FLOAT_COUNT};

let mut builder = MeshBuilder::new();
builder.add_part(&create_box_geometry(1.0, 1.0, 1.0), &Matrix4::create_identity(), "#ff8844", ToonPartOptions::default());
let arrays = builder.read_arrays();
assert_eq!(arrays.vertex_data.len() / VERTEX_FLOAT_COUNT, 24);
assert_eq!(arrays.index_data.len(), 36);
assert_eq!(arrays.outline_vertex_data.len(), arrays.outline_base_data.len());
assert_eq!(arrays.uv_data.len(), 24 * 2);
assert!(arrays.skeleton.is_none());
```

- `pub vertex_data: Vec<f32>` (field, since 0.4.0): Body vertices. (VERTEX_FLOAT_COUNT each)
  - returns Vec<f32>
- `pub index_data: Vec<u32>` (field, since 0.4.0): Three vertex indices per body triangle.
  - returns Vec<u32>
- `pub outline_vertex_data: Vec<f32>` (field, since 0.4.0): Outline shell positions. (3 each)
  - returns Vec<f32>
- `pub outline_index_data: Vec<u32>` (field, since 0.4.0): Three point indices per outline shell triangle.
  - returns Vec<u32>
- `pub outline_base_data: Vec<f32>` (field, since 0.4.0): Body position before pushing, per outline shell point. (3 each, a received shell keeps its position as is)
  - returns Vec<f32>
- `pub skin_data: Vec<f32>` (field, since 0.4.0): Four joint indices and four weights per vertex. (skinned models only, SKIN_FLOAT_COUNT each)
  - returns Vec<f32>
- `pub outline_skin_data: Vec<f32>` (field, since 0.4.0): Four joint indices and four weights per outline shell point.
  - returns Vec<f32>
- `pub skeleton: Option<ToonSkeleton>` (field, since 0.4.0): Skeleton. (filled by read_glb_arrays, None for MeshBuilder)
  - returns Option<ToonSkeleton>
- `pub inner_outline_ranges: Vec<(usize, usize)>` (field, since 0.4.0): Spans of the GLB's inner shell and inner body. ((start, count) pairs, filled by read_glb_arrays)
  - returns Vec<(usize, usize)>
- `pub inner_body_ranges: Vec<(usize, usize)>` (field, since 0.4.0): Span holding the inner body. ((start, count) pairs, body vertex indices, filled by read_glb_arrays)
  - returns Vec<(usize, usize)>
- `pub uv_data: Vec<f32>` (field, since 0.4.0): Two texture coordinates per vertex. (empty if no vertex was given UVs)
  - returns Vec<f32>
- `pub uv1_data: Vec<f32>` (field, since 0.4.0): Two second UV texture coordinates per vertex. (Empty if no vertex was given a second UV)
  - returns Vec<f32>
- `pub material_ranges: Vec<ToonMaterialRange>` (field, since 0.4.0): Material ranges. (per GLB primitive)
  - returns Vec<ToonMaterialRange>

## ToonMaterialRange (struct) (Clone, Debug, Default)

Material range. (span of body vertex indices holding one material, the GLB reader stores one per primitive)
- name material name, material_index material index (None if absent), node_name node name, extras material extras, alpha_mode "OPAQUE" | "MASK" | "BLEND", alpha_cutoff (the MASK threshold)
- base_color_factor and emissive_factor are linear colors. base_color_image and emissive_image are indices into read_glb_images. (None if absent)
- To paint separate regions within a part (accent color regions, display panels), pick them by material name or extras and draw only that region with index_start and index_count of ToonDrawOptions.

Example: Store one region as a named material range

```rust
use vanilla::{create_box_geometry, Matrix4, MeshBuilder, ToonMaterialRange, ToonPartOptions};

let mut builder = MeshBuilder::new();
builder.add_part(&create_box_geometry(1.0, 1.0, 1.0), &Matrix4::create_identity(), "#909090", ToonPartOptions::default());
let screen_start = builder.get_index_count();
builder.add_part(&create_box_geometry(0.6, 0.4, 0.02), &Matrix4::create_translation(0.0, 0.1, 0.51), "#102030", ToonPartOptions { has_outline: false, ..ToonPartOptions::default() });
let screen_count = builder.get_index_count() - screen_start;
builder.add_material_range(ToonMaterialRange { name: String::from("screen"), index_start: screen_start, index_count: screen_count, ..ToonMaterialRange::default() });
let arrays = builder.read_arrays();
let screen_range = arrays.material_ranges.iter().find(|material_range| material_range.name == "screen").unwrap();
assert_eq!((screen_range.index_start, screen_range.index_count), (36, 36));
```

- `pub name: String` (field, since 0.4.0): Material name. (Empty text if none)
  - returns String
- `pub material_index: Option<usize>` (field, since 0.4.0): Material order. (None if the primitive has no material)
  - returns Option<usize>
- `pub node_name: String` (field, since 0.4.0): Name of the node that holds the primitive. (Empty text if none)
  - returns String
- `pub index_start: usize` (field, since 0.4.0): Where this material starts among the body vertex indices. (index_start of ToonDrawOptions)
  - returns usize
- `pub index_count: usize` (field, since 0.4.0): Number of vertex indices holding this material. (index_count of ToonDrawOptions)
  - returns usize
- `pub extras: Value` (field, since 0.4.0): Material extras. (Empty object if none)
  - returns Value
- `pub alpha_mode: String` (field, since 0.4.0): glTF alphaMode. ("OPAQUE", "MASK", "BLEND", "OPAQUE" if absent in the GLB)
  - returns String
- `pub alpha_cutoff: f64` (field, since 0.4.0): Threshold of MASK. (0.5 if absent in the GLB)
  - returns f64
- `pub base_color_factor: [f64; 4]` (field, since 0.4.0): Base color factor. (Linear [r, g, b, a], 1 if absent in the GLB)
  - returns [f64; 4]
- `pub emissive_factor: [f64; 3]` (field, since 0.4.0): Emissive color. (Linear [r, g, b], 0 if absent in the GLB)
  - returns [f64; 3]
- `pub base_color_image: Option<usize>` (field, since 0.4.0): Image order of the base color texture. (Order in read_glb_images, None if none)
  - returns Option<usize>
- `pub emissive_image: Option<usize>` (field, since 0.4.0): Image order of the emissive texture. (Order in read_glb_images, None if none)
  - returns Option<usize>
- `pub has_uv: bool` (field, since 0.4.0): Whether this primitive has texture coordinates.
  - returns bool

## ToonMeshPiece (struct) (Clone, Copy, Debug)

One piece to join. (arrays and offset passed to MeshBuilder::combine, the original { arrays, offset })

Example: Move three rock pieces and join them into one array

```rust
use vanilla::{create_faceted_chunk_geometry, Matrix4, MeshBuilder, ToonMeshPiece, ToonPartOptions};

let mut builder = MeshBuilder::new();
builder.add_part(&create_faceted_chunk_geometry(0.4, &[1.0, 0.8, 1.1, 0.9], [1.0, 0.7, 1.0]), &Matrix4::create_identity(), "#8a8070", ToonPartOptions::default());
let rock_arrays = builder.read_arrays();
let pieces = [
	ToonMeshPiece { arrays: &rock_arrays, offset: [0.0, 0.0, 0.0] },
	ToonMeshPiece { arrays: &rock_arrays, offset: [1.2, 0.0, 0.3] },
	ToonMeshPiece { arrays: &rock_arrays, offset: [-0.8, 0.0, 1.0] },
];
let combined_arrays = MeshBuilder::combine(&pieces);
assert_eq!(combined_arrays.index_data.len(), rock_arrays.index_data.len() * 3);
assert_eq!(combined_arrays.outline_index_data.len(), rock_arrays.outline_index_data.len() * 3);
```

- `pub arrays: &'a ToonMeshArrays` (field, since 0.4.0): Arrays to join. (Result of read_arrays or read_glb_arrays)
  - returns &'a ToonMeshArrays
- `pub offset: [f64; 3]` (field, since 0.4.0): Offset to add to positions. ([x, y, z])
  - returns [f64; 3]

## MeshBuilder (struct) (Default)

Builder for one model chunk.

Example: Note down the span that holds the wheel region

```rust
use std::f64::consts::PI;
use vanilla::{create_box_geometry, create_cylinder_geometry, create_part_matrix, Matrix4, MeshBuilder, ToonPartOptions};

let mut builder = MeshBuilder::new();
builder.add_part(&create_box_geometry(1.2, 0.4, 0.6), &Matrix4::create_translation(0.0, 0.4, 0.0), "#c04040", ToonPartOptions::default());
let wheel_start = builder.get_index_count();
builder.add_part(&create_cylinder_geometry(0.2, 0.2, 0.1, 16), &create_part_matrix(None, [0.4, 0.2, 0.35], Some([PI / 2.0, 0.0, 0.0]), None), "#303030", ToonPartOptions::default());
let wheel_count = builder.get_index_count() - wheel_start;
assert_eq!(wheel_start, 36);
assert!(wheel_count > 0);
```

Example: Build several parts into one mesh and draw only one region of the body

```rust
use std::f64::consts::PI;
use vanilla::{create_rounded_box_geometry, create_sphere_geometry, Camera3D, Matrix4, MeshBuilder, ToonDrawOptions, ToonPartOptions, ToonRenderer, Vector3};

fn draw_lamp(gl: &vanilla::GlContext, renderer: &mut ToonRenderer, camera: &mut Camera3D) {
	let mut builder = MeshBuilder::new();
	builder.add_part(&create_rounded_box_geometry(1.0, 0.5, 0.6, 3, 0.1), &Matrix4::create_translation(0.0, 0.25, 0.0), "#d0d8e0", ToonPartOptions::default());
	let lamp_start = builder.get_index_count();
	builder.add_part(&create_sphere_geometry(0.12, 12, 8, PI), &Matrix4::create_translation(0.5, 0.35, 0.0), "#ffe080", ToonPartOptions { glow: 1.5, is_unlit: true, ..ToonPartOptions::default() });
	let lamp_count = builder.get_index_count() - lamp_start;
	let Some(mesh) = renderer.create_mesh(gl, &builder.read_arrays()) else {
		return;
	};
	camera.set_perspective(0.8, 0.1, 100.0);
	camera.look_at(Vector3::create(1.5, 1.2, 2.0), Vector3::create(0.0, 0.2, 0.0), Vector3::create(0.0, 1.0, 0.0));
	renderer.begin_frame_with_camera(gl, camera);
	renderer.draw_mesh(gl, &mesh, &Matrix4::create_identity(), ToonDrawOptions { index_start: 0, index_count: lamp_start, ..ToonDrawOptions::default() });
	renderer.draw_mesh(gl, &mesh, &Matrix4::create_identity(), ToonDrawOptions { index_start: lamp_start, index_count: lamp_count, tint_color: [1.0, 0.5, 0.5, 1.0], has_outline: false, ..ToonDrawOptions::default() });
	renderer.end_frame(gl);
}
```

- `pub fn new() -> MeshBuilder` (constructor, since 0.4.0): Constructor.
  - returns MeshBuilder: An empty MeshBuilder.
- `pub fn is_empty(&self) -> bool` (method, since 0.4.0): Whether it is empty.
  - returns bool: true if the body has no triangles.
- `pub fn get_index_count(&self) -> usize` (method, since 0.4.0): Number of body vertex indices stored so far. (read before and after a part when drawing that part's body span separately)
  - returns usize: Number of body vertex indices. (Length of index_data)
- `pub fn get_outline_index_count(&self) -> usize` (method, since 0.4.0): Number of outline shell vertex indices stored so far.
  - returns usize: Number of outline shell vertex indices. (Length of outline_index_data)
- `pub fn add_part(&mut self, geometry: &ToonGeometry, matrix: &Matrix4, color_text: &str, options: ToonPartOptions)` (method, since 0.4.0): Adds one part. (stores the shape multiplied by the matrix, and with an outline also stores a shell pushed out per point)
  - `geometry` &ToonGeometry: Shape. (uvs and uvs1 may be empty)
  - `matrix` &Matrix4: Position, rotation and scale matrix to multiply into the shape.
  - `color_text` &str: "#rrggbb"
  - `options` ToonPartOptions: Glow, unlit, whether to have an outline and its thickness. (ToonPartOptions::default() has an outline)
- `pub fn add_quad(&mut self, corners: [[f64; 3]; 4], normal: [f64; 3], color: [f64; 3], pattern: f64, pattern_color: Option<[f64; 3]>, is_unlit: bool)` (method, since 0.4.0): Adds one quad. (faces like block terrain and floors, four points in perimeter order, no outline)
  - `corners` [[f64; 3]; 4]: Four points [x, y, z]
  - `normal` [f64; 3]: [x, y, z]
  - `color` [f64; 3]: [r, g, b] sRGB.
  - `pattern` f64: Pattern number. (meaning decided by the shader, 0 means none)
  - `pattern_color` Option<[f64; 3]>: [r, g, b] pattern color. (None if none)
  - `is_unlit` bool: Unlit.
- `pub fn add_quad_shell(&mut self, quads: &[ToonQuad], outline_width: f64)` (method, since 0.4.0): Stores the outline shell of quads. (like terrain chunks built from faces)
  - For each vertex at the same position, the distinct face normals are added once each and normalized, and it is pushed that way by the width.
  - `quads` &[ToonQuad]: Quad faces. (Four points and an outward normal)
  - `outline_width` f64: Shell thickness. (Length in vertex coordinates)
- `pub fn add_triangles(&mut self, positions: &[f64], normals: &[f64], indices: &[u32], matrix: &Matrix4, color: [f64; 3], glow: f64, is_unlit: bool, joints: Option<&[f64]>, weights: Option<&[f64]>)` (method, since 0.4.0): Stores triangles of a loaded model. (one GLB primitive, winding kept as is)
  - `positions` &[f64]: [x, y, z] per vertex.
  - `normals` &[f64]: [x, y, z] normal per vertex.
  - `indices` &[u32]: Three vertex indices per triangle.
  - `matrix` &Matrix4: Matrix to multiply into the vertices.
  - `color` [f64; 3]: [r, g, b] sRGB.
  - `glow` f64: Glow strength. (Multiplied by the base color and added, 0 means none)
  - `is_unlit` bool: Unlit.
  - `joints` Option<&[f64]>: Four joint indices per vertex. (None if none)
  - `weights` Option<&[f64]>: Four weights per vertex.
- `pub fn add_triangles_with_uvs(&mut self, positions: &[f64], normals: &[f64], indices: &[u32], matrix: &Matrix4, color: [f64; 3], glow: f64, is_unlit: bool, joints: Option<&[f64]>, weights: Option<&[f64]>, uvs: Option<&[f64]>, uvs1: Option<&[f64]>)` (method, since 0.4.0): Stores the triangles of a loaded model along with texture coordinates. (uvs, uvs1 are two per vertex, the last two optional arguments of the original addTriangles)
  - `positions` &[f64]: [x, y, z] per vertex.
  - `normals` &[f64]: [x, y, z] normal per vertex.
  - `indices` &[u32]: Three vertex indices per triangle.
  - `matrix` &Matrix4: Matrix to multiply into the vertices.
  - `color` [f64; 3]: [r, g, b] sRGB.
  - `glow` f64: Glow strength. (Multiplied by the base color and added, 0 means none)
  - `is_unlit` bool: Unlit.
  - `joints` Option<&[f64]>: Four joint indices per vertex. (None if none)
  - `weights` Option<&[f64]>: Four weights per vertex.
  - `uvs` Option<&[f64]>: Two texture coordinates per vertex. (None if none)
  - `uvs1` Option<&[f64]>: Two second texture coordinates per vertex. (None if none)
- `pub fn add_material_range(&mut self, material_range: ToonMaterialRange)` (method, since 0.4.0): Stores a material range. (span of body vertex indices, the GLB reader stores one per primitive)
  - `material_range` ToonMaterialRange: Span of body vertex indices. (Copied into material_ranges of read_arrays)
- `pub fn add_outline_triangles(&mut self, positions: &[f64], indices: &[u32], matrix: &Matrix4, joints: Option<&[f64]>, weights: Option<&[f64]>)` (method, since 0.4.0): Stores the outline shell of a loaded model. (already inflated, winding kept as is)
  - `positions` &[f64]: [x, y, z] per vertex of an already inflated shell.
  - `indices` &[u32]: Three vertex indices per triangle. (Winding is stored as is)
  - `matrix` &Matrix4: Matrix to multiply into the vertices.
  - `joints` Option<&[f64]>: Four joint indices per vertex. (None if none)
  - `weights` Option<&[f64]>: Four weights per vertex. (None if none)
- `pub fn add_triangle_shell(&mut self, positions: &[f64], normals: &[f64], indices: &[u32], matrix: &Matrix4, outline_width: f64, joints: Option<&[f64]>, weights: Option<&[f64]>)` (method, since 0.4.0): Builds an outline shell from a loaded model's body. (same computation as add_part's outline, winding kept as is, joint indices and weights taken from the body as is)
  - If several primitives are concatenated and passed at once, points at the same position across primitives are pushed together too.
  - `positions` &[f64]: [x, y, z] per body vertex.
  - `normals` &[f64]: [x, y, z] normal per body vertex.
  - `indices` &[u32]: Three vertex indices per triangle.
  - `matrix` &Matrix4: Matrix to multiply into the vertices.
  - `outline_width` f64: Shell thickness. (Length after the matrix is applied)
  - `joints` Option<&[f64]>: Four joint indices per vertex. (None if none)
  - `weights` Option<&[f64]>: Four weights per vertex. (None if none)
- `pub fn read_arrays(&self) -> ToonMeshArrays` (method, since 0.4.0): The built arrays.
  - returns ToonMeshArrays: Arrays copied from everything stored so far. (skeleton is None, UV is two per vertex only when some vertex was given one)
- `pub fn read_outline_offsets(world_positions: &[f64], world_normals: &[f64], outline_width: f64) -> Vec<f64>` (static, since 0.4.0): Push amount per point of the outline shell. (points at the same position are pushed together)
  - Points at the same position (sharp edges, seams, poles) are pushed together toward the sum of their distinct normals, each added once, so the shell does not split open.
  - At edges, pushes further so it stays the width away from each adjoining face. (divided by the smallest cosine between that direction and the face normals, not lowered below 0.85)
  - `world_positions` &[f64]: Vertex positions with the matrix applied. (3 each)
  - `world_normals` &[f64]: Unit normal.
  - `outline_width` f64: Shell thickness.
  - returns Vec<f64>: [x, y, z] to push out per point. (3 each)
- `pub fn combine(piece_list: &[ToonMeshPiece]) -> ToonMeshArrays` (static, since 0.4.0): Translates several built arrays and joins them into one array. (static pieces into one mesh, no rotation or scaling, the original MeshBuilder.combine)
  - Arrays and offset per piece. Adds the offset to positions and the previous pieces' vertex count to indices. The outline shell, the shell reference positions and the inner ranges are also translated and joined.
  - Skeletons are not joined. Even a piece with a skeleton becomes a static body in its rest pose.
  - `piece_list` &[ToonMeshPiece]: Pieces to join. (Arrays and offset)
  - returns ToonMeshArrays: The form of read_arrays. (skeleton is None)

## Functions and constants

- `pub const VERTEX_FLOAT_COUNT: usize = 15` (field, since 0.4.0): Number of values per vertex. (position 3, normal 3, color 3, material 2, pattern 4)
  - returns usize
- `pub const SKIN_FLOAT_COUNT: usize = 8` (field, since 0.4.0): Number of values stored separately per vertex for models with a skeleton. (joint indices 4, weights 4)
  - returns usize
- `pub const DEFAULT_OUTLINE_WIDTH: f64 = 0.02` (field, since 0.4.0): Default outline width.
  - returns f64
- `pub fn read_color_values(color_text: &str) -> [f64; 3]` (method, since 0.4.0): Color string to three sRGB numbers. ("#rrggbb" → [r, g, b], 0 ~ 1)
  - `color_text` &str: "#rrggbb" color text.
  - returns [f64; 3]: [r, g, b] sRGB. (0 ~ 1, white if it cannot be read)
- `pub fn create_part_matrix(parent_matrix: Option<&Matrix4>, position: [f64; 3], rotation: Option<[f64; 3]>, scale: Option<[f64; 3]>) -> Matrix4` (method, since 0.4.0): Builds a transform matrix from position, rotation and scale. (multiplied after the parent matrix, rotation uses three.js default order XYZ)
  - `parent_matrix` Option<&Matrix4>: Parent matrix. (None means identity)
  - `position` [f64; 3]: [x, y, z]
  - `rotation` Option<[f64; 3]>: [x, y, z] radians. (None means no rotation)
  - `scale` Option<[f64; 3]>: [x, y, z] (None means no scaling)
  - returns Matrix4: Parent x translation x rotation x scale matrix. (New matrix)
- `pub fn create_box_geometry(width: f64, height: f64, depth: f64) -> ToonGeometry` (method, since 0.4.0): Box. (separate vertices per face so edges are sharp)
  - `width` f64: X axis length.
  - `height` f64: Y axis length.
  - `depth` f64: Z axis length.
  - returns ToonGeometry: { positions, normals, indices, uvs } shape. (UV 0 ~ 1 per face)
- `pub fn create_rounded_box_geometry(width: f64, height: f64, depth: f64, segments: u32, radius: f64) -> ToonGeometry` (method, since 0.4.0): Rounded box. (lays a grid on each face and pushes out from an inner box by the radius)
  - `width` f64: X axis length.
  - `height` f64: Y axis length.
  - `depth` f64: Z axis length.
  - `segments` u32: Number of segments in the rounded parts. (1 if less than 1)
  - `radius` f64: Corner radius. (If larger than the half length, that axis is fully rounded)
  - returns ToonGeometry: { positions, normals, indices } shape.
- `pub fn create_cylinder_geometry(radius_top: f64, radius_bottom: f64, height: f64, radial_segments: u32) -> ToonGeometry` (method, since 0.4.0): Cylinder. (a funnel if the top and bottom radii differ, a cone if the top is 0, includes top and bottom caps)
  - `radius_top` f64: Top radius. (0 makes a cone)
  - `radius_bottom` f64: Bottom radius.
  - `height` f64: Height. (Center at the origin)
  - `radial_segments` u32: Number of segments around.
  - returns ToonGeometry: { positions, normals, indices } shape.
- `pub fn create_sphere_geometry(radius: f64, width_segments: u32, height_segments: u32, theta_length: f64) -> ToonGeometry` (method, since 0.4.0): Sphere. (from the top down to theta_length, π/2 gives the upper hemisphere)
  - `radius` f64: Radius.
  - `width_segments` u32: Number of longitude segments.
  - `height_segments` u32: Number of latitude segments.
  - `theta_length` f64: Angle to cut from the top. (Radians, π makes a full sphere)
  - returns ToonGeometry: { positions, normals, indices, uvs } shape. (UV 0 ~ 1 by longitude and latitude)
- `pub fn create_lathe_geometry(points: &[[f64; 2]], segments: u32) -> ToonGeometry` (method, since 0.4.0): Lathe. (revolves the profile points [x, y] around the Y axis, normals from the profile slope)
  - `points` &[[f64; 2]]: Profile points [x, y]. (From bottom to top)
  - `segments` u32: Number of segments around.
  - returns ToonGeometry: { positions, normals, indices } shape.
- `pub fn create_capsule_geometry(radius: f64, length: f64, cap_segments: u32, radial_segments: u32) -> ToonGeometry` (method, since 0.4.0): Capsule. (hemispheres on the top and bottom of a middle cylinder of length length, total height is length + two radii)
  - `radius` f64: Radius.
  - `length` f64: Length of the middle cylinder. (Without the hemispheres)
  - `cap_segments` u32: Number of latitude segments of one hemisphere.
  - `radial_segments` u32: Number of segments around.
  - returns ToonGeometry: { positions, normals, indices } shape.
- `pub fn create_torus_geometry(radius: f64, tube: f64, radial_segments: u32, tubular_segments: u32, arc: f64) -> ToonGeometry` (method, since 0.4.0): Torus. (a ring lying on the XY plane, only as far as arc)
  - `radius` f64: Radius of the ring.
  - `tube` f64: Radius of the tube.
  - `radial_segments` u32: Segments around the tube.
  - `tubular_segments` u32: Segments around the ring.
  - `arc` f64: Angle to go around the ring. (Radians, 2π makes a full ring)
  - returns ToonGeometry: { positions, normals, indices } shape.
- `pub fn create_octahedron_geometry(radius: f64) -> ToonGeometry` (method, since 0.4.0): Octahedron. (separate vertices per face for an angular crystal)
  - `radius` f64: From the center to a vertex.
  - returns ToonGeometry: { positions, normals, indices } shape.
- `pub fn create_faceted_chunk_geometry(radius: f64, vertex_scales: &[f64], axis_scale: [f64; 3]) -> ToonGeometry` (method, since 0.4.0): Faceted rock. (each of the twelve icosahedron vertices is stretched or shrunk, a cut stone with separate vertices per face, the original createFacetedChunkGeometry)
  - vertex_scales are radius multipliers for the twelve vertices. If short, they repeat from the start, and 1 if empty. axis_scale is the [x, y, z] multiplier.
  - `radius` f64: Base radius.
  - `vertex_scales` &[f64]: Radius multipliers of the twelve vertices. (Repeats from the start if short, 1 if empty)
  - `axis_scale` [f64; 3]: [x, y, z] multiplier.
  - returns ToonGeometry: { positions, normals, indices }
- `pub fn read_normal_matrix(elements: &[f64; 16]) -> [f64; 9]` (method, since 0.4.0): 3x3 to multiply normals by. (transpose of the inverse of the matrix's upper-left 3x3, row order)
  - `elements` &[f64; 16]: Elements of a Matrix4.
  - returns [f64; 9]: Nine numbers of the 3x3 to multiply into normals. (Row order, identity if the determinant is near 0)
