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>
110 lines
2.9 KiB
Python
110 lines
2.9 KiB
Python
# Stage 6h: bi-harmonic membrane over the located flap sphere. Melting (06g) barely dented
|
|
# the fold — layered flaps are locally smooth and resist neighbour-averaging. Replace instead:
|
|
# excise the sphere, solve the rim-anchored membrane (same method that healed the gusset).
|
|
# blender --background --python 06h_flap_membrane.py -- <in.blend> <out.blend> <cx> <cy> <cz> <r>
|
|
import bpy, sys, time
|
|
import numpy as np
|
|
|
|
argv = sys.argv[sys.argv.index("--") + 1:]
|
|
BLEND, OUT = argv[0], argv[1]
|
|
CTR = np.array([float(argv[2]), float(argv[3]), float(argv[4])])
|
|
R = float(argv[5])
|
|
t0 = time.time()
|
|
|
|
|
|
def log(m):
|
|
print(f"[flap {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)
|
|
|
|
n_e = len(me.edges)
|
|
ev0 = np.empty(n_e * 2, dtype=np.int32)
|
|
me.edges.foreach_get("vertices", ev0)
|
|
ev0 = ev0.reshape(-1, 2)
|
|
|
|
|
|
def grow_edges(mask, rings, ev):
|
|
m = mask.copy()
|
|
for _ in range(rings):
|
|
hit = m[ev[:, 0]] | m[ev[:, 1]]
|
|
m2 = m.copy()
|
|
m2[ev[:, 0]] |= hit
|
|
m2[ev[:, 1]] |= hit
|
|
m = m2
|
|
return m
|
|
|
|
|
|
sph = np.linalg.norm(co - CTR, axis=1) < R
|
|
free_m = grow_edges(sph, 1, ev0)
|
|
collar = grow_edges(free_m, 2, ev0) & ~free_m
|
|
S = np.nonzero(free_m | collar)[0]
|
|
in_S = np.zeros(n_v, dtype=bool)
|
|
in_S[S] = True
|
|
glb = np.full(n_v, -1, dtype=np.int64)
|
|
glb[S] = np.arange(len(S))
|
|
se = ev0[in_S[ev0].all(axis=1)]
|
|
a_ = glb[se[:, 0]]
|
|
b_ = glb[se[:, 1]]
|
|
deg = np.zeros(len(S))
|
|
np.add.at(deg, a_, 1.0)
|
|
np.add.at(deg, b_, 1.0)
|
|
free = free_m[S]
|
|
log(f"sphere {sph.sum()} -> free {free.sum()}, collar {(~free).sum()}")
|
|
|
|
|
|
def Ls(X):
|
|
out = deg[:, None] * X
|
|
np.add.at(out, a_, -X[b_])
|
|
np.add.at(out, b_, -X[a_])
|
|
return out
|
|
|
|
|
|
def A_op(U):
|
|
X = np.zeros((len(S), 3))
|
|
X[free] = U
|
|
return Ls(Ls(X))[free]
|
|
|
|
|
|
Xc = np.zeros((len(S), 3))
|
|
Xc[~free] = co[S[~free]]
|
|
rhs = -Ls(Ls(Xc))[free]
|
|
U = co[S[free]].copy()
|
|
r = rhs - A_op(U)
|
|
p = r.copy()
|
|
rs = (r * r).sum()
|
|
rs0 = rs
|
|
for it in range(120000):
|
|
Ap = A_op(p)
|
|
al = rs / max((p * Ap).sum(), 1e-30)
|
|
U += al * p
|
|
r -= al * Ap
|
|
rs2 = (r * r).sum()
|
|
if rs2 < 1e-18 or rs2 < rs0 * 1e-14:
|
|
break
|
|
p = r + (rs2 / rs) * p
|
|
rs = rs2
|
|
co_new = co.copy()
|
|
co_new[S[free]] = U
|
|
d = np.linalg.norm(co_new - co, axis=1)
|
|
log(f"membrane: {free.sum()} verts (CG {it} iters, rel {rs2/max(rs0,1e-30):.2e}), "
|
|
f"max move {d.max():.4f}")
|
|
|
|
me.vertices.foreach_set("co", co_new.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))
|
|
bpy.context.preferences.filepaths.save_version = 0 # no .blend1 autosave
|
|
bpy.ops.wm.save_as_mainfile(filepath=OUT)
|
|
log(f"WROTE {OUT}")
|
|
print("FLAP_DONE")
|