Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
CH49: worn pieces across periods and genres (a futuristic motorcycle helmet, a Victorian top hat, a Roman legionary's helmet, sci-fi armour), and the keyed fit made to hold them. The colour decides what is body, not the distance: a helmet's crown within the cut of the skull was cut through, showing the skin. A separate piece hugging the skin all over (the soles, never drawn) is dropped, as is one mostly magenta and a shadowed hand's dark magenta. Each piece rides one bone whole, the one nearest its centre, never a neck bone, a midline bone when it crosses the middle: before, a helmet split across head and neck and a breastplate rode the right arm. CH48: the data engine resumes (samples only the designs short of N, skips draped ones), a rejected design leaves no folder, and a failed drape is one line instead of a traceback that stopped the run
shinyobjectzaf1a2c419944
diff --git a/docs/character.feature b/docs/character.featureindex 394bfe3c..fe95ad72 100644--- a/docs/character.feature+++ b/docs/character.feature@@ -740,5 +740,16 @@ Feature: The character SDK as one system: SOMA bodies, Kimodo motion, generated# glasses ride Head (CH21). It differs from the rejected picture-measured clothes: those painted cloth onto# the skin from four separate pictures that never agreed; here one picture is made 3D whole, and only rigid# things are kept, so nothing has to fold.+ # 11-15, built as tools/garments/wear.sh (README "Worn hard pieces"): a knight's plate armour (full: the+ # dressed surface kept whole, set 4 mm off the skin) and four keyed pieces across periods and genres, a+ # futuristic motorcycle helmet, a Victorian top hat, a Roman legionary's helmet and sci-fi armour, about 5+ # cents and 5 minutes each. Keyed: the mannequin is drawn magenta and the colour decides what is body, not the+ # distance (a helmet's crown sits within the cut of the skull and was being cut through); a separate piece+ # that hugs the skin all over (the soles, which the drawing never shows) is dropped; each piece rides one bone+ # whole, the one nearest its centre, never a neck bone, and a midline bone when it crosses the middle (so the+ # breastplate rides the chest, not the arm under its shoulder plates, and a belt with thigh plates the hips).+ # Open: the back is Idol's guess from one front three-quarter view (the sci-fi armour's back comes out dark),+ # so a back view drawn to match is next; the surface is lumpy at Idol's 4 mm; a full suit's hands and feet+ # copy SOMA's bare shape.Then words make a helmet, a hat or armour that SOMA wears and moves withAnd each piece is its own part on the bone it covers, so pieces mix with sewn garments as layersdiff --git a/tools/garments/README.md b/tools/garments/README.mdindex 7b1e8299..cc11b324 100644--- a/tools/garments/README.md+++ b/tools/garments/README.md@@ -45,10 +45,13 @@ made 3D by Idol on this machine, laid on SOMA and split by bone:- `wear_mannequin.py`: SOMA at rest from three-quarters ahead, its camera written down (`KEY=1`: magenta)- `wear_fit.py`: Idol's mesh turned, sized and placed onto SOMA (turn searched, then refined against the skin), bare body- cut (by distance, or by the magenta key), what is kept lifted off the skin, each face given its nearest bone+ cut (full: by distance; keyed: by the magenta, so a crown tight on the skull stays), what is kept lifted off the skin.+ Full: each face goes to its nearest bone. Keyed: each separate piece rides one bone whole, the one nearest its centre+ (never a neck bone; a midline bone for a piece across the middle), and pieces that hug the skin all over are dropped- `wear_bake.py`: each piece weighted wholly to its bone on SOMA's armature, Idol's colours made linear, one glb + a picture-About 5 cents (the picture) and 5 minutes (Idol) a piece. Faults so far: the surface is as lumpy as Idol's 4 mm mesh;+About 5 cents (the picture) and 5 minutes (Idol) a piece. Faults so far: the back is Idol's guess from the one view;+the surface is as lumpy as Idol's 4 mm mesh;a full suit's hands and feet copy SOMA's bare shape when the drawn gauntlets don't match its hand pose.For training data at scale, `LEAN=1 tools/garments/engine.sh OUT N SEED` keeps each design's settings, caption, drapediff --git a/tools/garments/engine.sh b/tools/garments/engine.shindex 807c9a10..2aa56d1a 100755--- a/tools/garments/engine.sh+++ b/tools/garments/engine.sh@@ -15,12 +15,17 @@ BODY=${SOMA_BODY:-$HOME/.local/share/raea-models/soma/body/body.glb}RAEA=${RAEA:-raea}OUT=${1:?out dir}; N=${2:?count}; SEED=${3:-1}[ -f "$DATA/soma_sdf.npz" ] || "$PY" -I "$T/sdf_igl.py" "$BODY" "$DATA/soma_sdf.npz"-(cd "$T" && "$PY" -I sample_designs.py "$GC" "$T/soma.yaml" "$OUT" "$N" "$SEED") | grep --line-buffered -v rejected+# run again on the same OUT, it resumes: only the designs short of N are sampled, and draped ones are skipped+mkdir -p "$OUT"+HAVE=$(find "$OUT" -mindepth 2 -maxdepth 2 -name design.yaml | wc -l | tr -d ' ')+[ "$HAVE" -ge "$N" ] || (cd "$T" && "$PY" -I sample_designs.py "$GC" "$T/soma.yaml" "$OUT" "$((N - HAVE))" "$((SEED + HAVE))") | grep --line-buffered -v rejectedfor d in "$OUT"/g*/; don=$(basename "$d")[ -f "$d/$n.drape.json" ] && continue- (cd "$T" && "$PY" -I drape_mlx.py "$DATA/soma_sdf.npz" "$d/$n.panels.json" "$d" 150 -0.064 "$T/soma.yaml") \- | grep --line-buffered -E '^drape: \{|Error|Traceback' || echo "drape: $n failed"+ [ -f "$d/$n.panels.json" ] || { echo "drape: $n skipped: no panels.json (not a design)"; continue; }+ # a failed drape is one line (its last), not a traceback: one bad design does not stop the run+ log=$( (cd "$T" && "$PY" -I drape_mlx.py "$DATA/soma_sdf.npz" "$d/$n.panels.json" "$d" 150 -0.064 "$T/soma.yaml") 2>&1 ) && grep -E '^drape: \{' <<<"$log" \+ || echo "drape: $n failed: $(grep -vE '^\s*$' <<<"$log" | tail -1 | sed 's/Traceback/trace/')"[ "${LEAN:-0}" = 1 ] && [ -f "$d/$n.drape.json" ] && rm -f "${d:?}${n:?}.panels.json"done[ "${LEAN:-0}" = 1 ] && exit 0diff --git a/tools/garments/sample_designs.py b/tools/garments/sample_designs.pyindex 7c643b32..cda44c04 100644--- a/tools/garments/sample_designs.py+++ b/tools/garments/sample_designs.py@@ -48,12 +48,13 @@ while made < N and tries < N * 20:tries += 1d = sampler.randomize()gid = "g" + "".join(random.choices(string.ascii_lowercase + string.digits, k=8))+ folder = out / gidtry:assert_param_combinations(d)garment = MetaGarment(gid, body, d)garment.assert_total_length()if garment.is_self_intersecting(): raise ValueError("self-intersecting panels")- folder = out / gid; folder.mkdir(parents=True, exist_ok=True)+ folder.mkdir(parents=True, exist_ok=True)pattern = garment.assembly()pattern.serialize(folder, tag="", to_subfolder=False, with_3d=False, with_text=False, view_ids=False, with_printable=False)box = BoxMesh(next(folder.glob(f"{gid}*specification.json")), 1.0); box.load()@@ -80,5 +81,7 @@ while made < N and tries < N * 20:print(f"sample: {gid} {sum(len(p['flat']) for p in pieces)} vertices, {len(pieces)} pieces: {caption(d)}", flush=True)except BaseException as e: # GarmentCode's IncorrectElementConfiguration is a BaseExceptionif isinstance(e, KeyboardInterrupt): raise+ # a design rejected after its pattern was written leaves no folder behind (one with no panels.json is not a design)+ if folder.is_dir() and not (folder / "design.yaml").exists(): __import__("shutil").rmtree(folder)print(f"sample: rejected ({type(e).__name__}: {str(e)[:80]})", flush=True)print(f"sample: {made} designs from {tries} tries -> {out}")diff --git a/tools/garments/wear_fit.py b/tools/garments/wear_fit.pyindex eb8dfa0c..75164197 100644--- a/tools/garments/wear_fit.py+++ b/tools/garments/wear_fit.py@@ -3,7 +3,8 @@# face within CUT metres of the skin or inside it), small crumbs are dropped, and each face is given to the bone it lies# nearest, so each piece can ride that bone rigidly.# python -I tools/garments/wear_fit.py IDOL.glb SOMA_BODY.glb SOMA_SKELETON.json OUT.npz [CUT=0.006] [LIFT=0] [KEY=0]-# KEY=1: the mannequin was drawn magenta (wear_mannequin.py KEY=1), so faces that come back magenta are bare body and go.+# KEY=1: the mannequin was drawn magenta (wear_mannequin.py KEY=1), so faces that come back magenta are bare body and go,+# and each piece left rides one bone whole.# CUT: faces nearer the skin than this are the body and go (a negative CUT keeps the whole dressed surface: a full suit).# LIFT: what is kept and lies nearer the skin than this is set out to it along the skin's normal, so a close-fitting# piece covers the body instead of meeting it.@@ -96,15 +97,30 @@ except Exception:cols = np.full((len(Q), 3), 0.6)keyed = 0if KEY:- # magenta: red and blue high, green well under both (a garment's purple or pink keeps more green, or less red)- mag = (np.minimum(cols[:, 0], cols[:, 2]) > 0.25) & (cols[:, 1] < 0.55 * np.minimum(cols[:, 0], cols[:, 2])) & (np.abs(cols[:, 0] - cols[:, 2]) < 0.35)+ # magenta: red and blue over green, green well under both (a garment's purple or pink keeps more green, or less+ # red), in shadow as well as lit (a hand in shade comes back as dark as 0.2, 0, 0.19)+ mag = (np.minimum(cols[:, 0], cols[:, 2]) > 0.08) & (cols[:, 1] < 0.55 * np.minimum(cols[:, 0], cols[:, 2])) & (np.abs(cols[:, 0] - cols[:, 2]) < 0.35)bare = mag[F].sum(1) >= 2- keyed = int((keepf & bare).sum()); keepf &= ~bare-# crumbs dropped: pieces under 0.5 per cent of what is kept+ # the colour decides, not the distance: a piece sitting tight on the skin (a helmet's crown on the skull, a hat's+ # band on the brow) lies within CUT of it and is kept, set out by LIFT; only a face near the skin with any magenta+ # tint at a corner (the bare edge where the colour bleeds) goes with the keyed ones+ tint = (cols[:, 1] < 0.8 * np.minimum(cols[:, 0], cols[:, 2]))+ keyed = int(bare.sum()); keepf = ~bare & ~(~keepf & tint[F].any(1))+# crumbs dropped: pieces under 0.5 per cent of what is kept, and with KEY a piece mostly magenta (a finger's edge whose+# corners fell either side of the colour test)faces_kept = F[keepf]lab = trimesh.graph.connected_component_labels(trimesh.graph.face_adjacency(faces_kept), node_count=len(faces_kept))sizes = np.bincount(lab)-faces_kept = faces_kept[sizes[lab] >= 0.005 * len(faces_kept)]+good = sizes[lab] >= 0.005 * len(faces_kept)+if KEY:+ magf = np.bincount(lab, weights=mag[faces_kept].mean(1), minlength=len(sizes)) / sizes+ good &= magf[lab] < 0.5+ # and a piece that hugs the skin all over is skin the drawing never showed (the soles of the feet, grey from Idol),+ # not something worn: nine tenths of its corners within 1 cm of the skin (the soles come back 4 to 9 mm under it;+ # a helmet, a breastplate, a belt sit 3 to 10 cm out at the median)+ hug = np.array([np.quantile(sd[faces_kept[lab == l]], 0.9) < max(2.5 * CUT, 0.01) for l in range(len(sizes))])+ good &= ~hug[lab]+faces_kept, lab = faces_kept[good], lab[good]used = np.unique(faces_kept)remap = -np.ones(len(Q), int); remap[used] = np.arange(len(used))V, Fo, C = Q[used], remap[faces_kept], cols[used]@@ -123,6 +139,21 @@ def seg_d(P, a, b):return np.linalg.norm(P - (a + t[:, None] * ab), axis=1)D = np.stack([seg_d(V, a, b) for _, a, b in segs], 1)bone = np.array([segs[i][0] for i in D.argmin(1)])+if KEY:+ # a piece that leaves skin bare is hard and moves as one: each rides the bone nearest its centre (a helmet split+ # between the head and the neck would shear when the head turns; the bone most of a breastplate lies nearest can+ # be an arm, under its shoulder plates, and a belt's the leg its thigh plate hangs over). Nothing hard rides a neck+ # bone alone (a helmet's cheek guards ride the head, a gorget the chest), and a piece across the middle of the body+ # rides a bone down its middle (a belt the hips, not a leg).+ vlab = np.zeros(len(V), int); vlab[Fo.ravel()] = np.repeat(lab, 3)+ tri = V[Fo]; area = 0.5 * np.linalg.norm(np.cross(tri[:, 1] - tri[:, 0], tri[:, 2] - tri[:, 0]), axis=1)+ riders = [s for s in segs if not names[s[0]].startswith("Neck")]+ middle = [s for s in riders if not names[s[0]].startswith(("Left", "Right"))]+ for l in np.unique(lab):+ f = lab == l; xs = tri[f][..., 0]+ c = (tri[f].mean(1) * area[f, None]).sum(0) / max(area[f].sum(), 1e-12)+ pool = middle if xs.min() < -0.05 and xs.max() > 0.05 else riders+ bone[vlab == l] = pool[int(np.argmin([seg_d(c[None], a, b)[0] for _, a, b in pool]))][0]# a face goes to the bone most of its corners have, so pieces are whole facesfb = bone[Fo]fbone = np.where(fb[:, 1] == fb[:, 2], fb[:, 1], fb[:, 0])