Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(face): a skin piece lying half or more in the body's own mouth (filled and grown 2 px) is not a hand's — a tongue joined to a hand by a finger at the mouth's corner no longer stays over the layer
Soohong Kimef174cb97663
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c085882..70b2490 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,7 +19,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the- A clip's own mouth and sound finish before a requested line starts. The voice and layer then wait together for the first frame whose switch to the chosen rest is within the 1.4 jump line. Layer exit also uses that jump line.- Bakes check pack digests, changed pixels outside the weight, and composite jumps. Refused bakes retain their frames for inspection.- See [docs/face-parts.md](docs/face-parts.md) for the request, pack, player, commands, and limits.-- **Tests**: `tests/video/test_face_layer.py` uses `tests/talking_face.py` to check smile and neutral sets; clip entry set and rest; own-mouth timelines, including a close during voiced sound and refusal of a missing or never-closing timeline; a head 60 px from its place and tilted 3 degrees; hand, headset boom, and choker keeps; unchanged pixels outside the weight; synthetic cells keeping the key's colour under no coverage; digests and new-folder pack writes; the player flap against its original numpy rule and the pick against the draft Viterbi over every frame; a line waiting for a clip's own mouth and for a frame its layer can come on at; loop and post-greeting bakes with greeting frames unchanged byte for byte; and refusal of a changed pack.+- **Tests**: `tests/video/test_face_layer.py` uses `tests/talking_face.py` to check smile and neutral sets; clip entry set and rest; own-mouth timelines, including a close during voiced sound and refusal of a missing or never-closing timeline; a head 60 px from its place and tilted 3 degrees; hand, headset boom, and choker keeps; a tongue in the body's own open mouth, joined to a hand by a finger at its corner, covered by the layer; unchanged pixels outside the weight; synthetic cells keeping the key's colour under no coverage; digests and new-folder pack writes; the player flap against its original numpy rule and the pick against the draft Viterbi over every frame; a line waiting for a clip's own mouth and for a frame its layer can come on at; loop and post-greeting bakes with greeting frames unchanged byte for byte; and refusal of a changed pack.## v3.0.0 - Remove rig layer compositiondiff --git a/docs/face-parts.md b/docs/face-parts.mdindex 38bd905..b628731 100644--- a/docs/face-parts.md+++ b/docs/face-parts.md@@ -129,7 +129,7 @@ A sprite leaves out the weight's outermost 2 px, where the weight is under 0.1.Each body cell is copied with its anchor and a keep image for anything that must stay above the face layer. The keep contains the body's own dark grey and black reaching inward from the boundary, its lines in the feather, and a hand.-A hand differs from the reference face by more than 48 in any channel and reaches inward from outside the layer. The frame's light, warm skin is divided into pieces using drawn lines as walls. Teeth and white streaks do not count as skin. The piece that overlaps the reference's lower face most is the face. Other skin pieces touched by the outside piece belong to the hand, with their surrounding lines. A hand counts where at least 400 px lie on the weight's flat part above `band_bottom`.+A hand differs from the reference face by more than 48 in any channel and reaches inward from outside the layer. The frame's light, warm skin is divided into pieces using drawn lines as walls. Teeth and white streaks do not count as skin. The piece that overlaps the reference's lower face most is the face. Other skin pieces touched by the outside piece belong to the hand, with their surrounding lines. A skin piece that lies half or more inside the body's own mouth belongs to the mouth, even when a finger at the corner joins it to the hand, and the layer covers it. For this check, the body's own mouth line or opening is read like a talking frame's mouth, filled and grown 2 px. A hand counts where at least 400 px lie on the weight's flat part above `band_bottom`.The body's own open mouth is kept only where it meets a hand. The face's own skin is never counted as hand skin.diff --git a/sprite_gen/video/face_layer.py b/sprite_gen/video/face_layer.pyindex 62bd65c..837c5f3 100644--- a/sprite_gen/video/face_layer.py+++ b/sprite_gen/video/face_layer.py@@ -337,8 +337,9 @@ def hand_reach(body_ref: np.ndarray, reference: np.ndarray, w0: np.ndarray, geommost on the reference's own lower face is the face; any other skin piece a reaching piece touches is the hand's (apalm, a finger, the sleeve under it), with the lines round it (HAND_GROW px of the reaching piece). It is a handwhere HAND_MIN px or more of those skin pieces lie on the layer's flat part above the chin (`band_bottom`); grown- HAND_GROW px and feathered. A body's own mouth is not skin and is kept only where it meets a hand; the face's own- skin, however far its outline moves off the reference's, is never a hand's."""+ HAND_GROW px and feathered. A body's own mouth is not skin and is kept only where it meets a hand, and a skin piece+ lying half or more in it (a tongue) is not a hand's; the face's own skin, however far its outline moves off the+ reference's, is never a hand's."""near = parts_mod._dilate(w0 > 0, HAND_GROW + FEATHER)ys, xs = np.nonzero(near)x0, y0, x1, y1 = int(xs.min()), int(ys.min()), int(xs.max()) + 1, int(ys.max()) + 1@@ -357,8 +358,16 @@ def hand_reach(body_ref: np.ndarray, reference: np.ndarray, w0: np.ndarray, geomreturn np.zeros(w0.shape, np.float32)own = lower_face(reference, geom)[y0:y1, x0:x1]face = int(np.argmax(np.bincount(skin_lab[own & (skin_lab >= 0)], minlength=skin_sizes.size))) if (own & (skin_lab >= 0)).any() else -1- touched = np.unique(skin_lab[parts_mod._dilate(reaching, 2) & (skin_lab >= 0)])- hand_skin = np.isin(skin_lab, touched[touched != face])+ # the body's own mouth, filled: a tongue in it is light and warm too+ mouth = np.zeros(w0.shape, bool)+ line = mouth_line(body_ref, geom)+ if line is not None:+ mx0, my0, mx1, my1 = geom.mouth_box+ mouth[my0:my1, mx0:mx1] = parts_mod._dilate(fill_holes(line), 2)+ in_mouth = mouth[y0:y1, x0:x1]+ touched = [j for j in np.unique(skin_lab[parts_mod._dilate(reaching, 2) & (skin_lab >= 0)])+ if j != face and (in_mouth & (skin_lab == j)).sum() * 2 < skin_sizes[j]]+ hand_skin = np.isin(skin_lab, touched)inside = (sub_w > 0.98) & (np.arange(y0, y1)[:, None] < geom.band_bottom)if int((hand_skin & inside).sum()) < HAND_MIN:return np.zeros(w0.shape, np.float32)@@ -510,11 +519,9 @@ def hampel(rows: list[dict[str, Any]], cyclic: bool) -> list[dict[str, Any]]:# --- the mouth -----------------------------------------------------------------------------------------------------def mouth_reading(arr: np.ndarray, geom: Geometry) -> dict[str, Any] | None:- """How a mouth in reference coordinates smiles: the dark line or opening nearest the mouth point (DROP under the- box's skin, off the headset's grey), its corners its leftmost and rightmost pixels. `lift` is how far its top edge- in the middle third sits below the chord between the corners (px; + the corners turned up: a smile, - turned down:- an O or a pout); `height` the mean of its bottom less top there, plus one. None where no mouth line is found."""+def mouth_line(arr: np.ndarray, geom: Geometry) -> np.ndarray | None:+ """The mouth of a picture in reference coordinates, on `Geometry.mouth_box`: the dark line or opening nearest the+ mouth point (DROP under the box's skin, off the headset's grey). None where there is none."""x0, y0, x1, y1 = geom.mouth_boxa = arr[y0:y1, x0:x1]lum = luma(a)@@ -527,9 +534,17 @@ def mouth_reading(arr: np.ndarray, geom: Geometry) -> dict[str, Any] | None:yy, xx = np.mgrid[0:a.shape[0], 0:a.shape[1]]cx, cy = geom.mouth[0] - x0, geom.mouth[1] - y0near = m & ((xx - cx) ** 2 / 30 ** 2 + (yy - cy) ** 2 / 16 ** 2 < 1)- if not near.any():+ return reach(m, near) if near.any() else None+++def mouth_reading(arr: np.ndarray, geom: Geometry) -> dict[str, Any] | None:+ """How a mouth in reference coordinates smiles (`mouth_line`), its corners its leftmost and rightmost pixels.+ `lift` is how far its top edge in the middle third sits below the chord between the corners (px; + the corners+ turned up: a smile, - turned down: an O or a pout); `height` the mean of its bottom less top there, plus one. None+ where no mouth line is found."""+ g = mouth_line(arr, geom)+ if g is None:return None- g = reach(m, near)ys, xs = np.nonzero(g)if len(xs) < 6:return None