Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor
Accept near-full alpha as opaque in mask-only imports
shinshin86a363588df094
diff --git a/tools/build-sprites.py b/tools/build-sprites.pyindex 5e1e123..9267bf8 100644--- a/tools/build-sprites.py+++ b/tools/build-sprites.py@@ -80,6 +80,9 @@ RING_LEVEL = 48# patch. The tint is measured just inside the mask edge, where the skin should be unchanged.TINT_BAND = 10MAX_TINT = 24+# Pixels compared for those checks. Some illustrations are exported with the skin slightly+# below full alpha (253 in the sample), so "opaque" cannot mean exactly 255.+OPAQUE_ALPHA = 240def grey(image):@@ -91,7 +94,7 @@ def grey(image):def mask_only(name, variant, source, region):"""Return the variant aligned to the source, or raise with the reason it differs."""- opaque = source[..., 3] == 255+ opaque = source[..., 3] >= OPAQUE_ALPHA(dx, dy), response = cv2.phaseCorrelate(grey(source), grey(variant), cv2.createHanningWindow(source.shape[1::-1], cv2.CV_32F))diff --git a/tools/test_agent_tools.py b/tools/test_agent_tools.pyindex 8c40700..4bdcd56 100644--- a/tools/test_agent_tools.py+++ b/tools/test_agent_tools.py@@ -180,6 +180,8 @@ class AgentToolsTest(unittest.TestCase):texture = rng.integers(60, 200, (100, 100, 3), dtype=np.uint8)source = np.dstack([texture, np.full((100, 100), 255, np.uint8)])source[:, :6, 3] = 0+ # Skin a little below full alpha, as some illustrations are exported.+ source[:, 6:, 3] = 253Image.fromarray(source).save(self.project / "source.png")variants = self.project / "variants"variants.mkdir()@@ -209,7 +211,7 @@ class AgentToolsTest(unittest.TestCase):x, y, w, h = json.loads((self.project / "built/sprites/sprites.json").read_text())["layers"]["eyes_sad_0"]with Image.open(self.project / "built/sprites/eyes_sad_0.png") as image:sprite = np.array(image.convert("RGBA")).astype(int)- solid = sprite[..., 3] == 255+ solid = sprite[..., 3] >= 250solid[25 - y : 36 - y, 15 - x : 26 - x] = Falseself.assertTrue(solid.any())self.assertLess(np.abs(sprite[..., :3] - source[y : y + h, x : x + w, :3])[solid].mean(), 1)