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: a garment draped over the garments under it

shinyobjectzcdcdee527d57
diff --git a/docs/character.feature b/docs/character.feature
index 83475f83..f168837c 100644
--- a/docs/character.feature
+++ b/docs/character.feature
@@ -674,8 +674,12 @@ Feature: The character SDK as one system: SOMA bodies, Kimodo motion, generated
# 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.
+ # her collarbones (trims.py's collar "drop": its top closes at the throat); her coat, cut and draped on the bare
+ # body, was narrower at its hem than her skirt there, which stood out through it with the edge hide_under cut
+ # showing (sdf_igl.py --under: the skirt, its waist and hem closed, inflated 3 mm and joined to the body's
+ # distance grid, so the coat drapes over it, 3.7 cm wider each side at the knee). On-skin covers made on the
+ # template's vertices (the black boots) wear on her full and headless bodies as they are, on her feet's own shape.
+ # Not done: 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
diff --git a/tools/garments/sdf_igl.py b/tools/garments/sdf_igl.py
index fafccc88..36974d4d 100644
--- a/tools/garments/sdf_igl.py
+++ b/tools/garments/sdf_igl.py
@@ -1,12 +1,23 @@
# SOMA's body as a signed distance grid for the GPU drape, signed by fast winding number (libigl) rather than by the
# nearest face's normal (sdf_build.py), which put "inside" patches in the air above the shoulders.
-# python sdf_igl.py BODY.glb OUT.npz [CELL_M]
+# python sdf_igl.py BODY.glb OUT.npz [CELL_M] [--under GARMENT.glb ...] [--under-thick M]
# Metres, glTF's frame (y up, +z ahead), negative inside; OUT holds origin, cell, sdf (nx, ny, nz), grad (nx, ny, nz, 3).
+# --under: garments already sewn on this body, made part of what the next one drapes over: each one's open edges
+# (a skirt's waist and hem, a trouser's waist and legs) capped so it closes round the body, inflated by its cloth's
+# thickness (--under-thick, 3 mm) and joined to the body. A coat sewn without it was cut and draped on the bare
+# body, so a skirt wider at the knee than the coat's hem stood out through it and its edge showed where hide_under
+# had cut its faces under the coat (THE GAMBIT's tram conductress, SOMA's woman build, 11-17).
import sys, time
import numpy as np, trimesh, igl
-glb, out = sys.argv[1:3]
-cell = float(sys.argv[3]) if len(sys.argv) > 3 else 0.007
+args = [a for a in sys.argv[1:]]
+under, thick = [], 0.003
+while "--under" in args:
+ i = args.index("--under"); under.append(args[i + 1]); del args[i:i + 2]
+if "--under-thick" in args:
+ i = args.index("--under-thick"); thick = float(args[i + 1]); del args[i:i + 2]
+glb, out = args[:2]
+cell = float(args[2]) if len(args) > 2 else 0.007
scene = trimesh.load(glb, process=False)
skin = max(scene.dump() if isinstance(scene, trimesh.Scene) else [scene], key=lambda m: len(m.vertices))
V = np.asarray(skin.vertices, float); F = np.asarray(skin.faces, np.int64)
@@ -16,6 +27,45 @@ n = np.ceil((hi - lo) / cell).astype(int) + 1
g = np.stack(np.meshgrid(*[lo[i] + cell * np.arange(n[i]) for i in range(3)], indexing="ij"), -1).reshape(-1, 3)
t0 = time.time()
S, _, _, _ = igl.signed_distance(g, V, F, sign_type=igl.SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER)
+
+
+def capped(path):
+ """the garment's meshes as one, welded, each open edge loop closed by a fan from its centre"""
+ sc = trimesh.load(path, force="scene")
+ m = trimesh.util.concatenate([g for g in sc.dump() if len(g.faces)])
+ m.merge_vertices(digits_vertex=5) # (a garment's pieces arrive split at seams and UV islands)
+ Vg, Fg = np.asarray(m.vertices, float), np.asarray(m.faces, np.int64)
+ E = np.sort(np.concatenate([Fg[:, [0, 1]], Fg[:, [1, 2]], Fg[:, [2, 0]]]), 1)
+ u, c = np.unique(E, axis=0, return_counts=True)
+ nxt = {}
+ for a, b in u[c == 1]:
+ nxt.setdefault(a, []).append(b); nxt.setdefault(b, []).append(a)
+ seen, caps, add = set(), [], []
+ for s in list(nxt):
+ if s in seen:
+ continue
+ loop, prev, cur = [s], None, s
+ seen.add(s)
+ while True:
+ nb = [x for x in nxt[cur] if x != prev and (x not in seen or (x == s and len(loop) > 2))]
+ if not nb:
+ break
+ prev, cur = cur, nb[0]
+ if cur == s:
+ break
+ loop.append(cur); seen.add(cur)
+ if len(loop) < 8: # (a pinhole: left)
+ continue
+ ci = len(Vg) + len(add); add.append(Vg[loop].mean(0))
+ caps += [[loop[k], loop[(k + 1) % len(loop)], ci] for k in range(len(loop))]
+ print(f"sdf: under {path.rsplit('/', 1)[-1]}: an edge of {len(loop)} vertices closed at y {Vg[loop, 1].mean():.3f}", flush=True)
+ return np.vstack([Vg] + ([np.array(add)] if add else [])), np.vstack([Fg] + ([np.array(caps)] if caps else []))
+
+
+for p in under:
+ Vu, Fu = capped(p)
+ Su, _, _, _ = igl.signed_distance(g, Vu, Fu, sign_type=igl.SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER)
+ S = np.minimum(S, Su - thick)
sdf = S.reshape(n).astype(np.float32)
grad = np.stack(np.gradient(sdf, cell), axis=-1).astype(np.float32)
np.savez_compressed(out, origin=lo.astype(np.float32), cell=np.float32(cell), sdf=sdf, grad=grad)