Radiotomy commited on
Commit
a4e19f9
·
verified ·
1 Parent(s): b197de5

Only add mouth shapes after the region passes checks

Browse files
Files changed (1) hide show
  1. process.py +8 -6
process.py CHANGED
@@ -119,12 +119,16 @@ def add_face(arm, head, existing):
119
  h, depth, width = zmax - zmin, ymax - ymin, max(xs) - min(xs)
120
  # Front faces -Y after glTF import. Mouth: lower 15-40% of head, front 30%, middle 45% of width.
121
  z0, z1, yf = zmin + 0.15 * h, zmin + 0.40 * h, ymin + 0.30 * depth
122
- added, total = [], 0
123
  for o, idx, co in hv:
124
  sel = [(i, c) for i, c in zip(idx, co) if z0 <= c.z <= z1 and c.y <= yf and abs(c.x - xmid) <= 0.225 * width]
125
- if not sel:
126
- continue
127
- total += len(sel)
 
 
 
 
128
  if not o.data.shape_keys:
129
  o.shape_key_add(name="Basis", from_mix=False)
130
  inv = o.matrix_world.inverted().to_3x3()
@@ -134,8 +138,6 @@ def add_face(arm, head, existing):
134
  fall = 1.0 - (c.z - z0) / max(z1 - z0, 1e-6) # lower lip moves most
135
  k.data[i].co = o.data.vertices[i].co + inv @ Vector((0, 0, -amt * h * fall))
136
  added.append(o.name)
137
- if total < 20 or total > 8000:
138
- return {"status": "skipped", "reason": f"mouth region looked unreliable ({total} vertices)"}
139
  return {"status": "added", "confidence": "experimental", "shape_keys": ["jawOpen", "viseme_aa"], "vertices": total, "meshes": added}
140
 
141
 
 
119
  h, depth, width = zmax - zmin, ymax - ymin, max(xs) - min(xs)
120
  # Front faces -Y after glTF import. Mouth: lower 15-40% of head, front 30%, middle 45% of width.
121
  z0, z1, yf = zmin + 0.15 * h, zmin + 0.40 * h, ymin + 0.30 * depth
122
+ picks = []
123
  for o, idx, co in hv:
124
  sel = [(i, c) for i, c in zip(idx, co) if z0 <= c.z <= z1 and c.y <= yf and abs(c.x - xmid) <= 0.225 * width]
125
+ if sel:
126
+ picks.append((o, sel))
127
+ total = sum(len(s) for _, s in picks)
128
+ if total < 20 or total > 8000:
129
+ return {"status": "skipped", "reason": f"mouth region looked unreliable ({total} vertices)"}
130
+ added = []
131
+ for o, sel in picks:
132
  if not o.data.shape_keys:
133
  o.shape_key_add(name="Basis", from_mix=False)
134
  inv = o.matrix_world.inverted().to_3x3()
 
138
  fall = 1.0 - (c.z - z0) / max(z1 - z0, 1e-6) # lower lip moves most
139
  k.data[i].co = o.data.vertices[i].co + inv @ Vector((0, 0, -amt * h * fall))
140
  added.append(o.name)
 
 
141
  return {"status": "added", "confidence": "experimental", "shape_keys": ["jawOpen", "viseme_aa"], "vertices": total, "meshes": added}
142
 
143