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: seams pressed flat in the drape, a followed coat's skirt hides nothing, cover --over a sewn garment refused

shinyobjectz196fb8ddf569
diff --git a/tools/clothes/garment.py b/tools/clothes/garment.py
index 59beebb0..758bd677 100644
--- a/tools/clothes/garment.py
+++ b/tools/clothes/garment.py
@@ -340,6 +340,11 @@ def cover(out, spec, colour, stand_m, under=None):
rgb = [int(colour.lstrip("#")[k:k + 2], 16) / 255 for k in (0, 2, 4)]
ids = sorted(set(int(c) for c in cid[covered]))
stand = np.full(len(ids), max(stand_m, OFF))
+ if under and "stand" not in under:
+ # a sewn garment (raea clothes make) isn't laid on the skin's vertices, so there's no stand to go over: it
+ # crashed here (KeyError 'stand', 11-17, boots --over sewn trousers)
+ raise SystemExit(f"cover: --over {under.get('name')}: it is sewn, not laid on the skin; make this one without "
+ "--over and list it before the sewn one in `raea clothes wear`, which layers them in that order")
if under:
u = np.zeros(len(C)); u[under["vertices"]] = under["stand"]
stand = np.maximum(stand, u[ids] + THICK)
diff --git a/tools/garments/drape_mlx.py b/tools/garments/drape_mlx.py
index 842b1206..33594f70 100644
--- a/tools/garments/drape_mlx.py
+++ b/tools/garments/drape_mlx.py
@@ -67,6 +67,30 @@ edges = np.array(list(opp.keys()), np.int32)
bends = np.array([v for v in opp.values() if len(v) == 2], np.int32).reshape(-1, 2)
rest_e = np.linalg.norm(FLAT[edges[:, 0]] - FLAT[edges[:, 1]], axis=1)
rest_b = np.linalg.norm(FLAT[bends[:, 0]] - FLAT[bends[:, 1]], axis=1)
+# bends across the seams too, each at its two pieces laid flat across it: with none, a seam was a free hinge and the
+# stitch line stood out of the cloth as a fin (11-17: a greatcoat's centre front, 3 cm proud of the cloth beside it
+# from the chest to the hem, drawn as a crinkled line down its front once it moved). A pressed seam lies flat.
+if E("SEAM_BEND", 1):
+ mate = {}
+ for i, j in seams:
+ mate.setdefault(int(i), set()).add(int(j)); mate.setdefault(int(j), set()).add(int(i))
+ def off_line(o, i, j): # the flat distance of o from the line through i and j, in o's piece's cut
+ d = FLAT[j] - FLAT[i]; L = float(np.hypot(*d)) or 1e-9
+ return abs(float(d[0] * (FLAT[o][1] - FLAT[i][1]) - d[1] * (FLAT[o][0] - FLAT[i][0]))) / L
+ rim = {k: v[0] for k, v in opp.items() if len(v) == 1}
+ across, rest_x = [], []
+ for (i, i2), o in rim.items():
+ for j in mate.get(i, ()):
+ for j2 in mate.get(i2, ()):
+ k = (min(j, j2), max(j, j2))
+ if k in rim and k != (i, i2):
+ across.append((o, rim[k])); rest_x.append(off_line(o, i, i2) + off_line(rim[k], j, j2))
+ if across:
+ u = {}
+ for (a_, b_), r in zip(across, rest_x): u[(min(a_, b_), max(a_, b_))] = r
+ bends = np.concatenate([bends, np.array(list(u.keys()), np.int32).reshape(-1, 2)])
+ rest_b = np.concatenate([rest_b, np.array(list(u.values()), np.float32)])
+ print(f"drape: {len(u)} bends across the seams", flush=True)
cnt = np.bincount(np.concatenate([edges.ravel(), bends.ravel(), seams.ravel()]), minlength=n).astype(np.float32)[:, None]
# pins: one-sided planes on GarmentCode's labelled edges, what elastic, boning or the neck does in a real garment.
# A waistband (lower_interface) stays at or above the waist, a strapless top's edge at or above the armpit, a neckline
diff --git a/tools/garments/hide_under.py b/tools/garments/hide_under.py
index b5356688..c7136e66 100644
--- a/tools/garments/hide_under.py
+++ b/tools/garments/hide_under.py
@@ -6,7 +6,10 @@
# A body vertex is under cloth when a ray out along its normal meets a garment within REACH (6 cm); a face goes when
# its vertices and all their neighbours are under cloth (the edge of the cut stays, so no gap shows at a hem). A
# garment's vertex is under the garments outside it when a ray either way along its normal meets one within REACH
-# (cloth's normals are not all outward); NO_LAYERS=1 leaves garments whole.
+# (cloth's normals are not all outward); NO_LAYERS=1 leaves garments whole. FOLLOW=NAME,... names the garments the
+# cloth follower carries (raea sdk/body/tools/worn.ts): their cloth below the crotch swings off what it lies on at rest,
+# so it hides nothing (11-17: a greatcoat's skirt swung clear of the trousers it had hidden at rest, and the holes left
+# in them showed the coat's inside, ragged at the cut faces' edges).
import bpy, bmesh, sys, os
from mathutils import Vector
from mathutils.bvhtree import BVHTree
@@ -19,14 +22,29 @@ bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.gltf(filepath=body_glb)
skin = max((o for o in bpy.data.objects if o.type == "MESH"), key=lambda o: len(o.data.vertices))
keep = set(bpy.data.objects)
+FOLLOW = {n for n in os.environ.get("FOLLOW", "").split(",") if n}
+# the crotch, as the follower's garment reader takes it (sdk/body/tools/garment.ts readWorn: the thighs' joints, 8 cm down)
+arm = next((o for o in bpy.data.objects if o.type == "ARMATURE"), None)
+legs = [arm.matrix_world @ arm.data.bones[b].head_local for b in ("LeftLeg", "RightLeg", "thigh_l", "thigh_r") if arm and b in arm.data.bones]
+CROTCH = min(p.z for p in legs) - 0.08 if legs else None
+if FOLLOW and CROTCH is None: sys.exit("hide_under: FOLLOW given but the body has no thigh joints to find its crotch by")
+
+
+def cover(into, o, path):
+ """a garment's mesh added to what hides (in the world), less a followed garment's cloth below the crotch"""
+ t = bmesh.new(); t.from_object(o, bpy.context.evaluated_depsgraph_get()); t.transform(o.matrix_world)
+ if os.path.splitext(os.path.basename(path))[0] in FOLLOW:
+ bmesh.ops.delete(t, geom=[f for f in t.faces if all(v.co.z < CROTCH for v in f.verts)], context="FACES")
+ m = bpy.data.meshes.new("t"); t.to_mesh(m); t.free(); into.from_mesh(m)
+
+
dg = bpy.context.evaluated_depsgraph_get()
cb = bmesh.new()
for gpath in garments:
before = set(bpy.data.objects); bpy.ops.import_scene.gltf(filepath=gpath)
for o in set(bpy.data.objects) - before:
if o.type == "MESH":
- t = bmesh.new(); t.from_object(o, bpy.context.evaluated_depsgraph_get()); t.transform(o.matrix_world)
- m = bpy.data.meshes.new("t"); t.to_mesh(m); t.free(); cb.from_mesh(m)
+ cover(cb, o, gpath)
bvh = BVHTree.FromBMesh(cb)
W = skin.matrix_world; N = W.to_3x3()
bm = bmesh.new(); bm.from_mesh(skin.data); bm.verts.ensure_lookup_table()
@@ -62,8 +80,7 @@ if os.environ.get("NO_LAYERS") != "1":
for opath in garments[k + 1:]:
for o in load_mesh(opath):
if o.type == "MESH":
- t = bmesh.new(); t.from_object(o, bpy.context.evaluated_depsgraph_get()); t.transform(o.matrix_world)
- m = bpy.data.meshes.new("t"); t.to_mesh(m); t.free(); ob.from_mesh(m)
+ cover(ob, o, opath)
bpy.data.objects.remove(o)
elif o.type != "ARMATURE":
bpy.data.objects.remove(o)