Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
docs: the smooth keys for a turned body and breath timing — `chest_x`, `chest_bias` as the peak's move, `chest_bias_y`, `chest_flat`, `breath_peaks` — in docs/breathing.md and the CHANGELOG
Soohong Kim4568b04d8eba
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f9cb656..e7a4355 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the**Upgrading from 2.45.3: Nothing that ran before gives other bytes.**Breathe without `mode` (or `mode: "pixel"`) is the same warp, the same bytes, and the same normalized sidecar.Its default did not change.+All new values at 0 or omitted bake the same bytes as before.`video-follow` and `video-follow-inspect` still run under those names and give the same files.Their records and file names on disk did not change.The record is still written under `follow`.@@ -26,26 +27,36 @@ Moving the written names to `sway` is a later change made together with the toolThe chest breathes from its centre.It uses a round (cos^2) weight on the body axis at `chest_y` of the body below the neck.The weight is `chest_rx` x torso half width wide, and `chest_ry` x the body below the neck tall.- The chest centre rises by `depth` x basis rows at the in-breath and puffs out by `depth_x`.+ The chest centre rises by `depth` x basis rows at the in-breath and puffs out by `depth_x` from P (not from the ellipse centre).Two shoulder weights, on either side just below the neck, rise by `shoulder` x the chest's rise.They rise `shoulder_lag` of a breath later.The neck and the collar beside it hold still.Whole rows do not move.- For a turned body: `chest_tilt` (degrees, clockwise on screen), `chest_bias` (-0.9 to 0.9, negative = the screen's left breathes more), and `chest_dir` (degrees from straight up, negative = up-left).+ For a figure whose body axis is pulled to one side (for example by long hair), the chest is not on the axis: `chest_x` moves the chest ellipse's centre off the body axis, in torso half widths (-1 to 1).+ The shoulders stay where they were (relative to the body axis).+ For a turned body: `chest_tilt` (degrees, clockwise on screen) and `chest_dir` (degrees from straight up, negative = up-left).+ `chest_bias` moves the chest weight's peak P along the chest ellipse's long axis, as a share of its horizontal half width (-0.9 to 0.9, negative is the screen's left).+ `chest_bias_y` moves the peak P across the long axis, as a share of the vertical half height (-0.9 to 0.9, positive is down).+ The weight falls from P to the ellipse's rim along the ray from P through each point, so the near side falls off over a short distance and the far side over a long one.+ P must stay inside the ellipse: `chest_bias` and `chest_bias_y` together at most 0.9 of the radii (refused otherwise).+ `chest_flat` is the share of the way from the peak P to the rim that rises in full (0 to 0.9).These default to 0; at 0, nothing changes.One breath is a bump from rest (in-breath 40 %, out 60 %).A cell at phase 0 is the source byte for byte.Seams and joins between loops are untouched.`breaths` is a whole number.- Refused, never silently clamped: `lag` on smooth (it would move the first cell), a stretch past the per-row strain cap (0.25) or a fold, opaque pixels pushed off the canvas, out-of-range values, and shape keys on a pixel row.+ `breath_peaks` is a list of cells where each in-breath peaks, for timing the breath from outside (for example to keep the breath's peaks off a big hand movement in the clip).+ The breath count is the number of peaks (`breaths`, if given, must match).+ The first cell stays at rest and the loop closes at rest: breaths are separated by rests at cell 0, between two peaks where the out-breath has taken 60 % of the gap and the next in-breath 40 %, and at the loop's end.+ Refused, never silently clamped: `lag` on smooth (it would move the first cell), a stretch past the per-row strain cap (0.25) or a fold, opaque pixels pushed off the canvas, out-of-range values, `chest_bias` and `chest_bias_y` together past 0.9 of the radii, a peak at cell 0, peaks not increasing or closer than two cells, a last peak within one cell of the loop's end, mismatched `breaths`, and shape keys or `breath_peaks` on a pixel row.With the default shape nothing leaves the canvas.A figure cut by the frame at its sides or bottom is not refused.- Defaults: `depth` 0.0085 (about 0.5 % of the frame height on a bust illustration), `depth_x` 0.028, `chest_y` 0.31, `chest_rx` 0.83, `chest_ry` 0.28, `shoulder` 0.5, `shoulder_lag` 0.08, and `chest_tilt`, `chest_bias`, and `chest_dir` 0.+ Defaults: `depth` 0.0085 (about 0.5 % of the frame height on a bust illustration), `depth_x` 0.028, `chest_y` 0.31, `chest_rx` 0.83, `chest_ry` 0.28, `shoulder` 0.5, `shoulder_lag` 0.08, and `chest_tilt`, `chest_bias`, `chest_bias_y`, `chest_dir`, `chest_x`, and `chest_flat` 0.Performance is about 0.2 s per 960 px frame.- **New: `sprite-gen breathe <frames> <out>` lays the Breathe layer over a folder of loop frames outside curation.**This lays the Breathe layer (either mode) over a folder of loop frames that is not a curation run, such as a video loop's cells.- It takes the sidecar's values through the same checks and the same bake: `--mode`, `--depth`, `--depth-x`, `--breaths`, `--lag`, and `--rigid-row`.- It also takes the smooth shape flags: `--chest-y`, `--chest-rx`, `--chest-ry`, `--shoulder`, `--shoulder-lag`, `--chest-tilt`, `--chest-bias`, and `--chest-dir`.+ It takes the sidecar's values through the same checks and the same bake: `--mode`, `--depth`, `--depth-x`, `--breaths`, `--breath-peaks` (for example `--breath-peaks 30,102`), `--lag`, and `--rigid-row`.+ It also takes the smooth shape flags: `--chest-y`, `--chest-rx`, `--chest-ry`, `--shoulder`, `--shoulder-lag`, `--chest-tilt`, `--chest-bias`, `--chest-bias-y`, `--chest-dir`, `--chest-x`, and `--chest-flat`.The same values give the same bytes as a curation bake.It writes the frames under their names and `breathe.json` (config, phases, the anatomy used) into a new folder all at once.It refuses the source folder or a folder that is not empty.diff --git a/docs/breathing.md b/docs/breathing.mdindex 5203201..593ea7c 100644--- a/docs/breathing.md+++ b/docs/breathing.md@@ -13,34 +13,43 @@ Breathe 레이어는 큐레이션 사이드카의 행마다 `states.<state>.breasmooth 모드의 고정 영역과 동작 방식은 다음과 같다.- 머리와 강체 경계(해부학 측정이 찾은 목 라인) 위의 모든 픽셀은 모든 셀에서 바이트 단위로 제자리를 유지한다. 인물 하단 역시 제자리에 고정된다.- rigid row, body axis, torso half width, basis rows로 이루어진 pixel 모드의 자동 해부학 측정에 강체 경계상의 목 너비를 추가해 사용한다. 모든 측정은 행의 첫 셀에서 한 번만 수행되며 해당 셀의 배치가 행 전체에 그대로 쓰인다. 비디오 셀 사이에서 정수리가 1픽셀 흔들려도 경계는 움직이지 않는다.-- 가슴은 목 아래 몸통의 `chest_y` 지점, 몸통 중심축에 위치한 원형 가중치(cos^2)를 중심으로 호흡한다. 가중치 너비는 몸통 반폭의 `chest_rx`배, 높이는 목 아래 몸통 높이의 `chest_ry`배다. 들숨 시 가슴 중심은 기준 행의 `depth`배만큼 상승하고, 가슴 중심에서 바깥쪽으로 `depth_x`만큼 부풀어 오른다.+- 가슴은 목 아래 몸통의 `chest_y` 지점, 몸통 중심축에 위치한 원형 가중치(cos^2)를 중심으로 호흡한다. 가중치 너비는 몸통 반폭의 `chest_rx`배, 높이는 목 아래 몸통 높이의 `chest_ry`배다. 들숨 시 가슴 중심은 기준 행의 `depth`배만큼 상승하고, 가슴 타원 중심이 아닌 정점 P에서 바깥쪽으로 `depth_x`만큼 부풀어 오른다.- 목 바로 아래 중심축 양쪽에 위치한 원형 어깨 가중치 두 개는 가슴 상승량의 `shoulder`배만큼, 가슴보다 `shoulder_lag` 호흡 주기만큼 늦게 올라간다. 측정된 너비 안쪽의 목과 목과 어깨 사이의 칼라(collar)는 움직이지 않는다. 행 전체가 통째로 오르내리지 않는다.-- 한 번의 호흡은 정지 상태에서 솟아오르는 형태다 (들숨 40%, 날숨 60%). 위상 0의 셀이 원본과 바이트 단위로 일치하므로 루프의 이음매와 루프 간 연결부가 온전히 유지된다. `breaths`는 1부터 8까지의 정수로 루프 길이에 정확히 맞춘다.+- 한 번의 호흡은 정지 상태에서 솟아오르는 형태다 (들숨 40%, 날숨 60%). 위상 0의 셀이 원본과 바이트 단위로 일치하므로 루프의 이음매와 루프 간 연결부가 온전히 유지된다. `breaths`는 1부터 8까지의 정수로 루프 길이에 정확히 맞춘다. 외부에서 호흡 타이밍을 맞추기 위해(예: 클립 내 큰 손 동작을 피하려는 경우) 각 들숨이 정점에 도달하는 셀 목록인 `breath_peaks`를 지정할 수 있다. 호흡 횟수는 정점의 개수가 되며, `breaths`를 함께 지정할 경우 일치해야 한다. 첫 셀은 정지 상태를 유지하고 루프는 정지 상태로 끝난다. 호흡은 셀 0, 두 정점 사이에서 날숨이 간격의 60%를 차지하고 다음 들숨이 40%를 차지하는 지점, 루프 끝의 정지 상태로 구분된다.-몸이 한쪽으로 돌아간 경우 다음 세 키를 조절한다.+몸이 한쪽으로 돌아간 경우 다음 키들을 조절한다.- `chest_tilt`: 가슴 가중치를 회전한다 (도 단위, 화면 기준 시계 방향).-- `chest_bias`: 가슴 한쪽이 더 크게 숨쉬도록 조절한다 (-0.9에서 0.9까지, 음수는 화면 왼쪽).+- `chest_bias`: 가슴 타원 장축을 따라 가중치 정점 P를 가로 반폭의 비율로 이동한다 (-0.9에서 0.9까지, 음수는 화면 왼쪽). 가중치는 P에서 각 점을 지나는 반직선을 따라 타원 가장자리로 떨어지므로, 가까운 쪽은 짧은 거리에 걸쳐 떨어지고 먼 쪽은 긴 거리에 걸쳐 떨어진다. 가슴 또한 타원 중심이 아닌 P에서 바깥쪽으로 부풀어 오른다.+- `chest_bias_y`: 장축의 수직 방향으로 정점 P를 세로 반높이의 비율로 이동한다 (-0.9에서 0.9까지, 양수는 아래쪽). 정점 P는 타원 내부에 머물러야 하므로, `chest_bias`와 `chest_bias_y`를 합쳐 반지름의 최대 0.9까지만 허용된다 (그렇지 않으면 거부).- `chest_dir`: 가슴 이동 방향을 수직에서 회전한다 (도 단위, 음수는 위쪽 왼쪽 방향).-- 왼쪽을 바라보는 몸체에는 음수 값을 사용한다. 세 키의 기본값은 모두 0이며, 0일 때는 아무 변화가 없다.+- `chest_x`: 몸통 중심축에서 가슴 타원의 중심을 몸통 반폭 단위로 이동한다 (-1에서 1까지). 긴 머리 등으로 인해 몸통 중심축이 한쪽으로 쏠린 인물의 경우 가슴이 중심축 위에 위치하지 않는다. 어깨는 몸통 중심축 기준 기존 위치를 유지한다.+- `chest_flat`: 정점 P에서 가장자리까지 완전히 상승하는 구간의 비율이다 (0에서 0.9까지).+- 왼쪽을 바라보는 몸체에는 음수 값을 사용한다. 이들 키의 기본값은 모두 0이며, 새 값들이 0이거나 생략되면 기존과 동일한 바이트를 출력하고 아무 변화가 없다.사이드카 키와 기본값, 허용 범위는 다음과 같다.| 키 | 기본값 | 허용 범위 | 설명 ||---|---|---|---|| `depth` | 0.0085 | 0.005에서 0.20 | 들숨 시 가슴 중심 상승 배율 (흉상 일러스트 기준 프레임 높이의 약 0.5%) |-| `depth_x` | 0.028 | 0에서 0.20 | 가슴 중심에서 바깥쪽으로 부풀어 오르는 폭 |+| `depth_x` | 0.028 | 0에서 0.20 | 정점 P에서 바깥쪽으로 부풀어 오르는 폭 || `chest_y` | 0.31 | 0.05에서 0.95 | 목 아래 몸통 기준 가슴 중심 세로 위치 || `chest_rx` | 0.83 | 0.2에서 3.0 | 몸통 반폭 대비 가슴 가중치 가로 배율 || `chest_ry` | 0.28 | 0.05에서 1.5 | 목 아래 몸통 높이 대비 가슴 가중치 세로 배율 || `shoulder` | 0.5 | 0에서 1.5 | 가슴 상승량 대비 어깨 상승 배율 || `shoulder_lag` | 0.08 | 0에서 0.3 | 가슴 대비 어깨 상승 지연 주기 || `chest_tilt` | 0 | -60에서 60 | 가슴 가중치 회전 각도 (도 단위, 시계 방향) |-| `chest_bias` | 0 | -0.9에서 0.9 | 한쪽 가슴 호흡 편향 (-0.9에서 0.9, 음수는 화면 왼쪽) |+| `chest_bias` | 0 | -0.9에서 0.9 | 가슴 타원 장축 방향 정점 P 이동 (가로 반폭 비율, 음수는 화면 왼쪽) |+| `chest_bias_y` | 0 | -0.9에서 0.9 | 장축 수직 방향 정점 P 이동 (세로 반높이 비율, 양수는 아래쪽) || `chest_dir` | 0 | -90에서 90 | 가슴 이동 방향 각도 (도 단위, 음수는 위쪽 왼쪽) |+| `chest_x` | 0 | -1에서 1 | 몸통 중심축 기준 가슴 타원 중심 이동 (몸통 반폭 단위) |+| `chest_flat` | 0 | 0에서 0.9 | 정점 P에서 가장자리까지 완전히 상승하는 구간 비율 || `breaths` | - | 1에서 8 | 루프에 들어맞는 정수 호흡 횟수 |+| `breath_peaks` | - | - | 각 들숨 정점 셀 목록 (외부 타이밍 조절용) |거부 조건은 다음과 같다.-- 허용 범위를 벗어난 값은 무시되지 않고 거부된다. pixel 행에 smooth 전용 형상 키(`chest_y`, `chest_rx`, `chest_ry`, `shoulder`, `shoulder_lag`, `chest_tilt`, `chest_bias`, `chest_dir`)를 지정해도 무시되지 않고 거부된다.+- 허용 범위를 벗어난 값은 무시되지 않고 거부된다. pixel 행에 smooth 전용 형상 키(`chest_y`, `chest_rx`, `chest_ry`, `shoulder`, `shoulder_lag`, `chest_tilt`, `chest_bias`, `chest_bias_y`, `chest_dir`, `chest_x`, `chest_flat`)나 `breath_peaks`를 지정해도 무시되지 않고 거부된다.+- 정점 P는 타원 내부에 머물러야 하므로, `chest_bias`와 `chest_bias_y`를 합쳐 반지름의 0.9를 초과하면 거부된다.+- `breath_peaks`에 셀 0의 정점이 포함되거나, 정점이 증가하는 순서가 아니거나, 정점 간격이 2셀보다 가깝거나, 마지막 정점이 루프 끝에서 1셀 이내인 경우 거부된다. `breaths`가 함께 지정되었으나 정점 개수와 일치하지 않는 경우도 거부된다.- smooth 모드에 `lag`(pixel 모드의 진행파)를 지정하면 첫 셀을 움직이게 되므로 무시되지 않고 거부된다.- 행별 변형 한도(0.25)를 넘는 신장, 접히는(fold) 변위장, 불투명 픽셀이 캔버스 밖으로 밀려나는 경우는 조용히 한도 내로 자르지 않고 즉시 거부한다.- 기본 형상에서는 가슴 가중치가 몸체 내부에서 0으로 떨어지므로, 인물이 화면 가장자리나 하단에서 잘려 있어도 거부되지 않으며 픽셀이 손실되지 않는다.@@ -49,7 +58,7 @@ smooth 모드의 고정 영역과 동작 방식은 다음과 같다.비디오 루프 셀처럼 큐레이션 실행이 아닌 프레임 폴더를 처리할 때는 독립 명령어를 사용한다.```bash-sprite-gen breathe <frames> <out> [--mode pixel|smooth] [--depth D] [--depth-x D] [--breaths N] [--lag L] [--rigid-row R] [--chest-y ...] [--chest-rx ...] [--chest-ry ...] [--shoulder ...] [--shoulder-lag ...] [--chest-tilt ...] [--chest-bias ...] [--chest-dir ...]+sprite-gen breathe <frames> <out> [--mode pixel|smooth] [--depth D] [--depth-x D] [--breaths N] [--breath-peaks ...] [--lag L] [--rigid-row R] [--chest-y ...] [--chest-rx ...] [--chest-ry ...] [--shoulder ...] [--shoulder-lag ...] [--chest-tilt ...] [--chest-bias ...] [--chest-bias-y ...] [--chest-dir ...] [--chest-x ...] [--chest-flat ...]````<frames>`는 파일 이름 순서대로 재생되는 PNG 프레임 폴더다. 사이드카와 동일한 검증과 베이크 처리를 거치므로 같은 값이면 동일한 바이트를 출력한다. 변환된 프레임들을 원본과 동일한 이름으로 저장하고, 적용된 설정과 위상 및 해부학 측정값을 담은 `breathe.json`을 새 폴더에 한 번에 작성한다. 원본 폴더를 덮어쓰거나 비어 있지 않은 폴더를 지정하면 쓰기를 거부한다.