gizai/figure
what each part of a made figure is (its head, ears, arms, legs, tail, wings, trunk), so its rig puts each joint in the part it moves and gives each vertex only its own part's joints. The figure is drawn from VIEWS sides as its colors and turns show it; SAM 3 finds each part's words in every view, and each vertex takes the part the views it faces most squarely see it in. A vertex no view sees takes its neighbours' part along the surface.
import * as Figure from "gizai/figure";Types
Finder
type Finder = (picture: Img.Image, texts: Vec<string>) => Vec<bytes> throws stringWhat SAM 3 finds in a picture: each text's pixels (255 where it finds it, else 0), a mask a text.
Rig
type Rig = { names: Vec<string>; parents: Vec<i64>; heads: Vec<f64>; joints: Vec<i64>; weights: Vec<f32>; }A rig as a model makes it: its joints' names, parents and places at rest (x, y, z each, as the mesh's), and each vertex's 4 joints and their weights.
names:Vec<string>parents:Vec<i64>heads:Vec<f64>joints:Vec<i64>weights:Vec<f32>
Functions
partsOf
function partsOf(positions: Vec<f32>, triangles: Vec<i64>, colors: Vec<f32>, find: Finder): bytes throws stringEach vertex's part (HEAD ... TRUNK, 0: none) of the figure of POSITIONS (x, y, z; y up) and TRIANGLES, its vertices' COLORS (r, g, b, 0..1), by SAM 3 (FIND) in its views.
Effects: fail, read, write, console, io, alloc.
constrained
function constrained(r: Rig, positions: Vec<f32>, parts: bytes): RigR on the figure of POSITIONS whose vertices are PARTS (partsOf): each vertex's weights only from joints of the segments its part may take (MAY), and none from a limb whose joints lie mostly in another part: a toy's long ears, which its learned rig gave the arms (their joints in them), move with its head; a joint it may not take gives its weight to its nearest ancestor it may. Its joints stay where they are (laid anew along a part, the vertices still bound to them swung about the new places and tore). A rig that is no humanoid's stays.
Effects: fail, read, write, console, io, alloc.
limbAstray
function limbAstray(names: Vec<string>, parents: Vec<i64>, heads: Vec<f64>, positions: Vec<f32>, parts: bytes): boolWhether the humanoid skeleton NAMES, PARENTS at HEADS (3 a joint, the figure's frame) has a limb that lies in another part of the figure of POSITIONS and PARTS than its own (a toy's arms in its long ears): a body fitted to it (MHR's) would carry that part with the limb. No for a skeleton that is no humanoid's.
Effects: fail, read, write, console, io, alloc.
Constants
HEAD
const HEAD: u64 = 1uThe head: the first of the parts, each a number in a mask of parts (0: none found).
EAR
const EAR: u64 = 2uAn ear.
ARM
const ARM: u64 = 3uAn arm.
LEG
const LEG: u64 = 4uA leg.
TAIL
const TAIL: u64 = 5uThe tail.
WING
const WING: u64 = 6uA wing.
TRUNK
const TRUNK: u64 = 7uThe trunk.