Skip to content

armgit / raea

Public Imported from GitHub
0

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.

raea clothes: garments cut for a body of another build

shinyobjectz2fb97c51d20f
diff --git a/docs/character.feature b/docs/character.feature
index 67ded6a4..83475f83 100644
--- a/docs/character.feature
+++ b/docs/character.feature
@@ -658,6 +658,26 @@ Feature: The character SDK as one system: SOMA bodies, Kimodo motion, generated
# shape), so only small changes of build are right; and this is HG17's start, not its end.
Then a garment made once dresses SOMA bodies of different builds
+ @done
+ Scenario: CH42d. A woman's build, its joints moved with it, and garments cut for it
+ # 11-17, for THE GAMBIT's tram conductress. SOMA's shape components measured on the torso (per +2 sigma):
+ # component 0 is size and sex together (at -1 sigma 9.5 cm shorter, the shoulders 3.6 cm narrower, the bust
+ # 1 cm forward), 5 (+) and 7 (-) add bust and hip and narrow the shoulders at the same height, 3 (+) makes
+ # stockier. SHAPE=0:-1.8,5:1.5,7:-1.5,3:1 on the 175.8 cm template is a sturdy woman of 159 cm (shoulders 34,
+ # bust forward 3.3, waist 31, hips 38 cm across). tools/clothes/body.py now moves each joint with the skin it
+ # carries (the skin-weighted mean of its move, nearer vertices counting more; a limb joint takes its two
+ # segments' twist joints' skin, as SOMA hangs none on the elbow or knee itself), CUT moves with the neck, the
+ # eyes with the head. A garment is cut for her by her own measures (soma_measure.py, given the template's own
+ # reading, scales the values soma.yaml sets by hand: neck_w 18.5 where the template reads 10.8), her distance
+ # grid and her body (sew.sh GARMENT_MEASURES, GARMENT_SDF, SOMA_BODY). Found on the way: her elbow had stayed
+ # at the template's distance from her shoulder; sleeves lifted 7 cm as a top's torso is began with the
+ # under-seam inside her narrower arm and draped as two flaps beside it (drape_mlx.py: sleeves start round the
+ # arm, SLEEVE_LIFT 0.01); the drape's "stayed on" read the template's shoulder height (now scaled by the
+ # measures); a collar trim on a neckline GarmentCode can cut no higher than its fc_depth 0.3 was a ring round
+ # her collarbones (trims.py's collar "drop": its top closes at the throat). Not done: a shaped headless body's
+ # on-skin covers (boots) need its template twin cut at the same place; the build is chosen by hand.
+ Then a woman's figure is a SOMA build whose joints, garments and head join are her own
+
@done
Scenario: CH42c. A garment's colour is a picture in the body's own UVs
# 11-15. `wear` bakes each garment's colour as a 2048 px picture in the body's first UV set (spread to
diff --git a/tools/garments/drape_mlx.py b/tools/garments/drape_mlx.py
index 0079581c..842b1206 100644
--- a/tools/garments/drape_mlx.py
+++ b/tools/garments/drape_mlx.py
@@ -44,10 +44,14 @@ def body(p):
# the pieces, placed round the body, and the flat cut
LIFT_LOW = E("LIFT_LOW", 0.01) # skirts, trousers and waistbands start nearer their place than tops
+# sleeves and cuffs start round the arm, where GarmentCode places them: lifted as a top's torso is (to fall onto the
+# shoulders), a woman's narrower sleeve (SOMA's woman build, 11-17) began with its under-seam 2 cm below the arm's
+# centreline, inside the arm, and draped as two flaps beside it; its seams to the armhole close the 6 cm between
+SLEEVE_LIFT = E("SLEEVE_LIFT", 0.01)
X, F, FLAT, start = [], [], [], []
for piece in P["pieces"]:
start.append(len(X))
- lift = LIFT_LOW if piece["name"].startswith(("skirt", "wb", "pant", "level")) else LIFT
+ lift = LIFT_LOW if piece["name"].startswith(("skirt", "wb", "pant", "level")) else SLEEVE_LIFT if ("sleeve" in piece["name"] or "cuff" in piece["name"]) else LIFT
X += [(p[0] / 100, p[1] / 100 + lift, p[2] / 100 + SHIFT_Z) for p in piece["placed"]]
FLAT += [(q[0] / 100, q[1] / 100) for q in piece["flat"]]
F += [[start[-1] + i for i in f] for f in piece["faces"]]
@@ -157,9 +161,14 @@ if SMOOTH:
gap, strain = stats()
s, _ = body(Xm); inside = int(np.sum(np.array(s) < -0.001))
Xd = np.array(Xm)
-# stayed: a top still hangs from the shoulders (SOMA's are at 1.45 m), anything else from the waist (1.05 m)
+# stayed: a top still hangs from the shoulders (SOMA's are at 1.45 m), anything else from the waist (1.05 m); on a
+# body of another build (BODY_YAML's measures) both heights scale with its height to the base of the neck (SOMA's
+# 145.8 cm): the woman build's coat (11-17), at her neck at 1.35 m, read as slid off against 1.38
+build = 1.0
+if BODY_YAML:
+ _b = yaml.safe_load(open(BODY_YAML))["body"]; build = (_b["height"] - _b["head_l"]) / 145.77
has_top = any("torso" in p["name"] for p in P["pieces"])
-top_y = float(Xd[:, 1].max()); stayed = top_y > (1.38 if has_top else 0.95)
+top_y = float(Xd[:, 1].max()); stayed = top_y > (1.38 if has_top else 0.95) * build
# closed: no seam left open more than 2 cm anywhere (a cuff whose side seam never closed hangs open below the elbow,
# and passed on the 95th percentile alone: 23 of the first 139 lean drapes, 12 of them with cuffs)
closed = bool(gap.max() < 20)
diff --git a/tools/garments/sew.sh b/tools/garments/sew.sh
index b01d0080..a9471002 100755
--- a/tools/garments/sew.sh
+++ b/tools/garments/sew.sh
@@ -3,7 +3,9 @@
# base, settings changed by path, cut to SOMA, draped on the GPU and baked to a skinned glb. `raea clothes make` runs it.
# tools/garments/sew.sh OUT_DIR NAME "WORDS" [--plain] [--set PATH=VALUE]... [--colour #rrggbb]
# Needs GARMENTCODE, GARMENT_PY (README.md), GARMENT_MODEL (the words model, unless --plain) and GARMENT_SDF (the body
-# as a distance grid, sdf_igl.py); SOMA_BODY is the body it is baked on. Writes OUT_DIR/NAME/: design.yaml, NAME.glb,
+# as a distance grid, sdf_igl.py); SOMA_BODY is the body it is baked on, GARMENT_MEASURES its measurements in
+# GarmentCode's terms (soma_measure.py; soma.yaml, the template's, unless given: a body of another build, body.py
+# SHAPE=..., is cut for by its own, its distance grid and its body.glb). Writes OUT_DIR/NAME/: design.yaml, NAME.glb,
# NAME.drape.json, NAME.bake.json, caption.txt. Prints lines starting "sew: ". $0, about 30 s.
set -euo pipefail
T=$(cd "$(dirname "$0")" && pwd)
@@ -11,6 +13,7 @@ GC=${GARMENTCODE:?a GarmentCode clone, see tools/garments/README.md}
PY=${GARMENT_PY:?the venv python, see tools/garments/README.md}
SDF=${GARMENT_SDF:-$HOME/.cache/raea-garments/soma_sdf.npz}
BODY=${SOMA_BODY:-$HOME/.local/share/raea-models/soma/body/body.glb}
+MEAS=${GARMENT_MEASURES:-$T/soma.yaml}
OUT=${1:?out dir}; n=${2:?name}; words=${3:-}; shift 3 || true
PLAIN=0; SETS=(); COLOUR=
while [ $# -gt 0 ]; do
@@ -29,7 +32,7 @@ else
"$PY" -I "$T/garment_model.py" make "${GARMENT_MODEL:?the words model (garment_model.py train), or --plain}" "$words" "$d" > "$d/make.log"
fi
if [ ${#SETS[@]} -gt 0 ]; then "$PY" -I "$T/design.py" "$d/design.yaml" "$d/design.yaml" "${SETS[@]}" > /dev/null; fi
-pattern() { (cd "$T" && DESIGN="$d/design.yaml" GID=$n "$PY" -I sample_designs.py "$GC" "$T/soma.yaml" "$OUT" 1 1) 2>&1 | grep -E "^sample: " | cut -c1-200 || true; }
+pattern() { (cd "$T" && DESIGN="$d/design.yaml" GID=$n "$PY" -I sample_designs.py "$GC" "$MEAS" "$OUT" 1 1) 2>&1 | grep -E "^sample: " | cut -c1-200 || true; }
said=$(pattern)
# refused as decoded from words alone (a combination GarmentCode's checks don't allow): the training design nearest the words
if [ ! -f "$d/$n.panels.json" ] && [ "$PLAIN" = 0 ] && [ ${#SETS[@]} -eq 0 ] && [ -f "$d/nearest.yaml" ]; then
@@ -37,7 +40,7 @@ if [ ! -f "$d/$n.panels.json" ] && [ "$PLAIN" = 0 ] && [ ${#SETS[@]} -eq 0 ] &&
echo "sew: the design decoded from the words was refused; the nearest design known is used instead"
fi
[ -f "$d/$n.panels.json" ] || { echo "sew: FAILED the pattern can't be cut: ${said#sample: }" >&2; exit 1; }
-log=$( (cd "$T" && "$PY" -I drape_mlx.py "$SDF" "$d/$n.panels.json" "$d" 150 -0.064 "$T/soma.yaml") 2>&1 ) || { echo "sew: FAILED the drape: $(grep -vE '^\s*$' <<<"$log" | tail -1)" >&2; exit 1; }
+log=$( (cd "$T" && "$PY" -I drape_mlx.py "$SDF" "$d/$n.panels.json" "$d" 150 -0.064 "$MEAS") 2>&1 ) || { echo "sew: FAILED the drape: $(grep -vE '^\s*$' <<<"$log" | tail -1)" >&2; exit 1; }
"$PY" -I -c 'import json,sys; r=json.load(open(sys.argv[1])); g=r["seam_gap_mm"]; print("sew: draped in %.0f s: %s" % (r["seconds"], "it stayed on and every seam closed" if r["ok"] else "FAULT " + ("it slid off" if not r["stayed"] else "a seam is open or cloth is in the skin") + " (seam gap %.0f mm at most)" % g.get("max", 0)))' "$d/$n.drape.json"
COLOUR=$COLOUR "${RAEA_BIN:-raea}" blender run "$T/bake_batch.py" "$BODY" "$d" 2>&1 | grep -E '^bake|Error|Traceback' | sed 's/^bake: /sew: baked /'
[ -f "$d/$n.glb" ] || { echo "sew: FAILED no glb was baked" >&2; exit 1; }
diff --git a/tools/garments/soma_measure.py b/tools/garments/soma_measure.py
index f85fdf00..9047c9bb 100644
--- a/tools/garments/soma_measure.py
+++ b/tools/garments/soma_measure.py
@@ -1,5 +1,9 @@
# SOMA's body measured in GarmentCode's terms (docs/Body Measurements GarmentCode.pdf), in cm.
-# python soma_measure.py BODY.glb SKELETON.json NEUTRAL.yaml OUT.yaml
+# python soma_measure.py BODY.glb SKELETON.json NEUTRAL.yaml OUT.yaml [TEMPLATE_MEASURED.yaml]
+# TEMPLATE_MEASURED: this tool's own reading of the template body (the one NEUTRAL was written for). NEUTRAL holds a
+# few values set by hand where GarmentCode means something other than the tape (soma.yaml: neck_w 18.5 where the
+# template's neck reads 10.8, shoulder_w 35.5 for 32.2, bust 89.9 for 91.9); given it, a body of another build
+# (tools/clothes/body.py SHAPE=...) gets each such value scaled by its own reading over the template's.
# Girths are convex-hull perimeters of the torso's horizontal slice (a tape measure lies over hollows).
# The geodesic lengths (waist_line, bust lines) are read along the body's back or front midline profile.
# What isn't measured here is the neutral body's value scaled by height, and printed as such.
@@ -123,6 +127,11 @@ scale = m["height"] / neutral["height"]
for k, v in neutral.items():
if k not in m:
m[k] = v * scale; print(f"scaled from the neutral body: {k}")
+if len(sys.argv) > 5:
+ tm = yaml.safe_load(open(sys.argv[5]))["body"]
+ for k, v in neutral.items():
+ if k in tm and tm[k] and abs(v / tm[k] - 1) > 0.01 and k in m:
+ print(f"set by hand on the template, scaled: {k} {m[k]:.2f} -> {v * m[k] / tm[k]:.2f}"); m[k] = v * m[k] / tm[k]
for k in sorted(m): print(f"{k:22s} SOMA {m[k]:7.2f} neutral {neutral[k]:7.2f}")
yaml.safe_dump({"body": {k: round(float(v), 4) for k, v in sorted(m.items())}}, open(out, "w"))
print("wrote", out)