3ba86b2ea8
Bulk import of the working lanes that were living untracked on the PC. Content: - characters/ Lena/male body lanes, bakes, texture work, run logs - clothing/ garment pipeline, configs, gates, contract docs - garments/ MD-authored garment sources (.zprj/.zpac) - UAL-Lib/ Universal Animation Library 2 source (.blend/.fbx/.glb) - tools/ blender_bridge, iclone_bridge, md_bridge, tailor, glm_agent - docs/, plans/, dev/, .agents/plans/ Repo hygiene: - .gitattributes: LFS now covers .blend, .zprj, .zpac, .obj, .npy and the Reallusion .iAvatar/.ccAvatar/.ccRestore containers. Without this the ~3.8 GB in this commit would land as raw blobs. .png/.jpg are left out on purpose — ~250 are already tracked raw and converting them would rewrite every one without shrinking history. - .gitignore: exclude /accurig/ (~1 GB AccuRig program files, redistributable from Reallusion, nothing authored here) and /dev/null/ (git-lfs hook copies dropped by a `>/dev/null` redirect on Windows). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
# Stage 6f: fold melt in the crotch box, normal-deviation detector.
|
|
# The mesh has only 3 boundary verts (00_welded closed the slits) — the remaining flap and
|
|
# dotted seam lines are welded CREASES: positions locally smooth, normals kinked. Detect
|
|
# verts whose normal deviates > ANG_THR from the 5-iter smoothed normal field, grow, melt.
|
|
# blender --background --python 06f_fold_melt.py -- <in.blend> <out.blend>
|
|
import bpy, sys, time, math
|
|
import numpy as np
|
|
|
|
argv = sys.argv[sys.argv.index("--") + 1:]
|
|
BLEND, OUT = argv[0], argv[1]
|
|
t0 = time.time()
|
|
|
|
# optional box override: <bx> <z0> <z1> [ang_deg]
|
|
if len(argv) >= 5:
|
|
BX, BZ0, BZ1 = float(argv[2]), float(argv[3]), float(argv[4])
|
|
ANG_THR = math.radians(float(argv[5])) if len(argv) > 5 else math.radians(15.0)
|
|
else:
|
|
BX, BZ0, BZ1 = 0.075, 0.340, 0.480
|
|
ANG_THR = math.radians(15.0)
|
|
# navel stays: it is a real feature made of exactly the kind of kink this melts
|
|
NAVEL = lambda co: (np.abs(co[:, 0]) < 0.022) & (co[:, 2] > 0.495) & (co[:, 2] < 0.555) & (co[:, 1] < 0)
|
|
BOX = lambda co: (np.abs(co[:, 0]) < BX) & (co[:, 2] > BZ0) & (co[:, 2] < BZ1) & ~NAVEL(co)
|
|
MELT_ITERS = 150
|
|
|
|
|
|
def log(m):
|
|
print(f"[fold {time.time()-t0:6.1f}s] {m}", flush=True)
|
|
|
|
|
|
bpy.ops.wm.open_mainfile(filepath=BLEND)
|
|
ob = max([o for o in bpy.data.objects if o.type == 'MESH'],
|
|
key=lambda o: len(o.data.vertices))
|
|
me = ob.data
|
|
n_v = len(me.vertices)
|
|
co = np.empty(n_v * 3)
|
|
me.vertices.foreach_get("co", co)
|
|
co = co.reshape(-1, 3)
|
|
nrm = np.empty(n_v * 3)
|
|
me.vertices.foreach_get("normal", nrm)
|
|
nrm = nrm.reshape(-1, 3)
|
|
|
|
n_e = len(me.edges)
|
|
ev = np.empty(n_e * 2, dtype=np.int32)
|
|
me.edges.foreach_get("vertices", ev)
|
|
ev = ev.reshape(-1, 2)
|
|
order = np.concatenate([ev[:, 0], ev[:, 1]])
|
|
nbr = np.concatenate([ev[:, 1], ev[:, 0]])
|
|
srt = np.argsort(order, kind="stable")
|
|
o_s = order[srt]
|
|
n_s = nbr[srt]
|
|
ptr = np.searchsorted(o_s, np.arange(n_v + 1))
|
|
cnt = np.maximum(ptr[1:] - ptr[:-1], 1)
|
|
|
|
N = nrm.copy()
|
|
for _ in range(5):
|
|
acc = np.zeros_like(N)
|
|
np.add.at(acc, o_s, N[n_s])
|
|
N = acc / cnt[:, None]
|
|
N /= np.maximum(np.linalg.norm(N, axis=1, keepdims=True), 1e-12)
|
|
dot = np.clip((nrm * N).sum(axis=1), -1.0, 1.0)
|
|
ang = np.arccos(dot)
|
|
|
|
box = BOX(co)
|
|
hot = box & (ang > ANG_THR)
|
|
log(f"box {box.sum()}, folds {hot.sum()} (>{math.degrees(ANG_THR):.0f} deg)")
|
|
if hot.sum():
|
|
hc = co[hot]
|
|
log(f"fold cluster: x [{hc[:,0].min():+.4f}..{hc[:,0].max():+.4f}] "
|
|
f"y [{hc[:,1].min():+.4f}..{hc[:,1].max():+.4f}] "
|
|
f"z [{hc[:,2].min():+.4f}..{hc[:,2].max():+.4f}]")
|
|
m = hot.copy()
|
|
for _ in range(3):
|
|
h = m[ev[:, 0]] | m[ev[:, 1]]
|
|
m2 = m.copy()
|
|
m2[ev[:, 0]] |= h
|
|
m2[ev[:, 1]] |= h
|
|
m = m2
|
|
sidx = np.nonzero(m)[0]
|
|
Q = co.copy()
|
|
for _ in range(MELT_ITERS):
|
|
acc = np.zeros_like(Q)
|
|
np.add.at(acc, o_s, Q[n_s])
|
|
mean = acc / cnt[:, None]
|
|
Q[sidx] = 0.5 * Q[sidx] + 0.5 * mean[sidx]
|
|
d = np.linalg.norm(Q - co, axis=1)
|
|
log(f"melted {len(sidx)} fold verts, max move {d.max():.4f}")
|
|
me.vertices.foreach_set("co", Q.reshape(-1))
|
|
me.update()
|
|
if me.has_custom_normals:
|
|
vn = np.empty(n_v * 3, dtype=np.float32)
|
|
me.vertices.foreach_get("normal", vn)
|
|
me.normals_split_custom_set_from_vertices(vn.reshape(-1, 3))
|
|
else:
|
|
log("no folds found")
|
|
bpy.context.preferences.filepaths.save_version = 0 # no .blend1 autosave
|
|
bpy.ops.wm.save_as_mainfile(filepath=OUT)
|
|
log(f"WROTE {OUT}")
|
|
print("FOLD_DONE")
|