@rig-c/core 2.68.0 → 2.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/cli/shared.ts CHANGED
@@ -41,6 +41,7 @@ import { FOLDS_FILE } from '../folds.ts';
41
41
  import { DRAWN_ALPHA, PASS_THROUGH_FILE, PASS_THROUGH_RUN } from '../passthrough.ts';
42
42
  import { SEAM_FILE } from '../seam.ts';
43
43
  import { OVERLAPS_FILE } from '../overlaps.ts';
44
+ import { DEFAULT_SHEET_FORMAT, SHEET_FORMATS, SHEET_MANIFEST_FILE, SHEET_MANIFEST_SPEC, SHEET_PADDING, SHEET_PAGE_SIZE, type SheetFormat } from '../sheet.ts';
44
45
  import { readViewportBox, ViewportError } from '../viewportpin.ts';
45
46
  import { parseJsonWithPosition } from '../json-position.ts';
46
47
  import { RUNG_IDS } from '../ladder.ts';
@@ -151,7 +152,7 @@ export { PACKAGE_ROOT, readPackageMeta, readVersion };
151
152
  * needs a value` (issue #328). `CLI10`/`CLI11` in `selftest.ts` now hold the two
152
153
  * halves together by reading `--help` rather than by naming a flag.
153
154
  */
154
- const BOOLEAN_FLAGS = new Set(['all', 'all-frames', 'all-bones', 'help', 'copy-images', 'again', 'pack', 'copy', 'geometry', 'folds', 'overlaps', 'accept-skeleton-differences', 'keep-pages', 'dim']);
155
+ const BOOLEAN_FLAGS = new Set(['all', 'all-frames', 'all-bones', 'help', 'copy-images', 'again', 'pack', 'copy', 'geometry', 'folds', 'overlaps', 'sheet', 'accept-skeleton-differences', 'keep-pages', 'dim']);
155
156
 
156
157
  /**
157
158
  * The flags a command is allowed to spell more than once.
@@ -1078,6 +1079,15 @@ const FLAG_MEANINGS: Record<string, string> = {
1078
1079
  'pair per set: the lowest and the highest angle in degrees, the span, and the frame each was first reached on. Read on the frames\' own ' +
1079
1080
  'grid, so a peak between two frames is not read. A reading, not a gate: nothing is written. An unknown bone, a bone against itself, ' +
1080
1081
  'a malformed list and a pair named twice are refused by name, and so is a bone with no direction on a frame (a world matrix of zero)',
1082
+ sheet:
1083
+ `also pack each rendered set's frames over a transparent [0, 0, 0, 0] canvas into deterministic RGBA8 sprite sheet page(s) ` +
1084
+ `(\`sheet.png\`, \`sheet2.png\`, …; max edge ${SHEET_PAGE_SIZE}, padding ${SHEET_PADDING} with clamped edge extrusion, trimmed to alpha > 0 ` +
1085
+ 'with a 1x1 transparent sentinel for empty frames), a shared TexturePacker-style JSON-Hash table per page (`sheet.json`, `sheet2.json`, …; ' +
1086
+ `\`anchor\` at world (0, 0)), and \`${SHEET_MANIFEST_FILE}\` (\`${SHEET_MANIFEST_SPEC}\`) ` +
1087
+ 'in each set directory; diagnostic `f####.png` and `contact.png` stay over opaque `BACKGROUND` unchanged',
1088
+ 'sheet-format':
1089
+ `the table format \`render --sheet\` writes beside each sheet page (default \`${DEFAULT_SHEET_FORMAT}\`, verified against pixi.js@8.22.0 and phaser@3.90.0 by tools/sheet_readers.ts; known formats: ${SHEET_FORMATS.join(', ')}). ` +
1090
+ 'Takes --sheet',
1081
1091
  'viewport-from':
1082
1092
  "draw on an earlier render's grid exactly — the box, the scale and the pixel size its frames.json records (the file, or the " +
1083
1093
  'directory `render --out` wrote it into) — so a world point lands on the same pixel in both renders. A slot that reaches past ' +
@@ -1285,6 +1295,7 @@ const FLAG_VALUES: Record<string, string> = {
1285
1295
  'pass-through': '<cloth>:<leg>[,<cloth>:<leg>…]',
1286
1296
  seam: '<slot>:<slot>[,<slot>:<slot>…]',
1287
1297
  'angle-range': '<bone>:<relative-to>[,…]',
1298
+ 'sheet-format': 'json-hash',
1288
1299
  'viewport-from': '<frames.json|dir>',
1289
1300
  reference: '<dir|skeleton.json>',
1290
1301
  'reference-atlas': '<path>',
@@ -1753,9 +1764,15 @@ export const COMMANDS: CommandDoc[] = [
1753
1764
  'rigc render … --overlaps (which slot each frame drew over which, by name, with an outline plate)',
1754
1765
  'rigc render … --angle-range <bone>:<relative-to>[,…] (how far a bone turns against another, per animation)',
1755
1766
  'rigc render … --viewport <x,y,w,h> | --viewport-from <frames.json> (a box given, not fitted: two renders on one pixel grid)',
1767
+ 'rigc render … --sheet [--sheet-format json-hash] [--page-edges pot|free] (deterministic sprite sheets + JSON hash table + sheet-manifest.json per set)',
1756
1768
  ],
1757
- flags: ['candidate', 'atlas', 'animation', 'skin', 'slot', 'hide', 'fps', 'max', 'viewport', 'viewport-from', 'geometry', 'folds', 'pass-through', 'seam', 'overlaps', 'angle-range', 'environment', 'poser', 'out'],
1769
+ flags: ['candidate', 'atlas', 'animation', 'skin', 'slot', 'hide', 'fps', 'max', 'viewport', 'viewport-from', 'geometry', 'folds', 'pass-through', 'seam', 'overlaps', 'angle-range', 'sheet', 'sheet-format', 'page-edges', 'environment', 'poser', 'out'],
1758
1770
  overrides: {
1771
+ 'page-edges': {
1772
+ meaning:
1773
+ `what each sprite sheet page's edges may be, --sheet only (default ${DEFAULT_PAGE_EDGES}, max edge ${SHEET_PAGE_SIZE}, padding ${SHEET_PADDING}): ` +
1774
+ 'pot is a power of two on both; free chooses the smallest-area rectangle up to the max edge that holds the trimmed frames',
1775
+ },
1759
1776
  out: {
1760
1777
  value: '<dir>',
1761
1778
  meaning:
@@ -2252,6 +2269,17 @@ export function readPageEdges(flags: Record<string, string>): PageEdges {
2252
2269
  return found;
2253
2270
  }
2254
2271
 
2272
+ /**
2273
+ * Read `--sheet-format`, or its default — `json-hash` (issue #1560).
2274
+ */
2275
+ export function readSheetFormat(flags: Record<string, string>): SheetFormat {
2276
+ const raw = flags['sheet-format'];
2277
+ if (raw === undefined) return DEFAULT_SHEET_FORMAT;
2278
+ const found = SHEET_FORMATS.find((f) => f === raw);
2279
+ if (!found) throw new UsageError(`--sheet-format ${JSON.stringify(raw)}; known formats: ${SHEET_FORMATS.join(', ')}`);
2280
+ return found;
2281
+ }
2282
+
2255
2283
  /**
2256
2284
  * Read `--pack-shape`, or its default — `rect` (issue #1099).
2257
2285
  *
@@ -3,7 +3,7 @@
3
3
  * refusal — the writer a command uses for a document too large to trust to
4
4
  * `console.log` (issue #1487).
5
5
  *
6
- * ⚖️ Why not `console.log`: on Bun 1.2.0, the declared minimum, one ~322 KB
6
+ * ⚖️ Why not `console.log`: on Bun 1.2.0 (then the declared minimum), one ~322 KB
7
7
  * line with non-ASCII in it came out 330,634 bytes for 330,632, a stray
8
8
  * `\xe2\x00` at a 64 KiB chunk boundary — to a file, a pipe and a slow pipe
9
9
  * alike. And on a stdout whose pipe is non-blocking (a parent set `O_NONBLOCK`
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The promised renderer reads for checked consumers (issue #1561).
3
+ *
4
+ * This entry registers no Spine side. Rigc builds use the official candidate
5
+ * chooser and core poser; inputs needing Spine are refused by SpineRuntimeError
6
+ * unless the consumer has explicitly loaded rig-c/render. That entry keeps its
7
+ * eager runtime import and registers the same implementation this seam uses.
8
+ * Only the agreed reads, their types and their existing failure classes belong
9
+ * here. The broader implementation module is not the public contract.
10
+ */
11
+ export {
12
+ loadCandidate,
13
+ throughPoser,
14
+ sampleAnimation,
15
+ sampleSetupPose,
16
+ pageFor,
17
+ projector,
18
+ rasterisePiece,
19
+ renderFrame,
20
+ CandidateAtlasError,
21
+ CandidatePairError,
22
+ PoserChoiceError,
23
+ SlotSubsetError,
24
+ } from './render_shared.ts';
25
+ export { SpineRuntimeError } from './spine_side.ts';
26
+ export { CoreInputError } from './core/index.ts';
27
+ export type {
28
+ Candidate,
29
+ SkeletonFacts,
30
+ PoserChoice,
31
+ PoserName,
32
+ MakeCorePoser,
33
+ Poser,
34
+ Posed,
35
+ PoseSource,
36
+ PoseOptions,
37
+ DrawOptions,
38
+ SkinRoster,
39
+ SlotSubset,
40
+ Frame,
41
+ BoneSnapshot,
42
+ AttachmentPose,
43
+ AttachmentRest,
44
+ Piece,
45
+ PieceCommon,
46
+ PieceTexture,
47
+ UvWindow,
48
+ Quad,
49
+ Mesh,
50
+ ClipSource,
51
+ Viewport,
52
+ EmitPixel,
53
+ } from './render_shared.ts';
54
+ export type { Plate, RGBA } from '../tools/plate.ts';
55
+ export type { EnvironmentStep, EnvironmentChange } from './environment.ts';
@@ -97,6 +97,8 @@ export { choosePosers, pairRefusal, regionKey };
97
97
 
98
98
  /** Opaque, and light: both of rung 3's parts are dark slate, so is every ground. */
99
99
  export const BACKGROUND: RGBA = [232, 232, 232, 255];
100
+ /** Transparent canvas for `render --sheet`, leaving diagnostic `f####.png` and `contact.png` on `BACKGROUND`. */
101
+ export const TRANSPARENT_BACKGROUND: RGBA = [0, 0, 0, 0];
100
102
  /** Padding around the union bounding box, as a fraction of its long side. */
101
103
  export const PAD = 0.04;
102
104
  /**
@@ -221,6 +223,23 @@ export interface FrameSet {
221
223
  plates: number;
222
224
  moving: Array<{ under: string; over: string; frames: number; most: { index: number; px: number } }>;
223
225
  };
226
+ /**
227
+ * The spritesheet export, when `render --sheet` asked for it (issue #1560):
228
+ * the set's manifest file, the table format, the page-edge policy, how many
229
+ * pages were written, how many frames were packed, and how many of them were
230
+ * empty (`1x1` transparent sentinel).
231
+ *
232
+ * ⭐ Absent unless asked for, for `skin`'s reason in `FramesSidecar`: a render
233
+ * without the flag stays the bytes it always was.
234
+ */
235
+ sheet?: {
236
+ manifest: string;
237
+ format: 'json-hash';
238
+ pageEdges: 'pot' | 'free';
239
+ pages: number;
240
+ frames: number;
241
+ emptyFrames: number;
242
+ };
224
243
  }
225
244
 
226
245
  export interface FramesSidecar {
package/src/seam.ts CHANGED
@@ -290,7 +290,7 @@ function weightsIn(triangles: readonly number[], xy: ArrayLike<number>, t: numbe
290
290
  * the triangle the point is least outside of (the largest smallest weight, the
291
291
  * lowest index on a tie). `null` when every triangle has collapsed in `from`.
292
292
  */
293
- function carry(triangles: readonly number[], from: ArrayLike<number>, to: ArrayLike<number>, id: number, qx: number, qy: number): [number, number] | null {
293
+ export function carry(triangles: readonly number[], from: ArrayLike<number>, to: ArrayLike<number>, id: number, qx: number, qy: number): [number, number] | null {
294
294
  let best = id;
295
295
  let w = id >= 0 ? weightsIn(triangles, from, id, qx, qy) : null;
296
296
  if (w === null) {
@@ -309,7 +309,11 @@ function carry(triangles: readonly number[], from: ArrayLike<number>, to: ArrayL
309
309
  }
310
310
  if (w === null || best < 0) return null;
311
311
  const [a, b, c] = [triangles[3 * best], triangles[3 * best + 1], triangles[3 * best + 2]];
312
- return [w[0] * to[2 * a] + w[1] * to[2 * b] + w[2] * to[2 * c], w[0] * to[2 * a + 1] + w[1] * to[2 * b + 1] + w[2] * to[2 * c + 1]];
312
+ // #1568: stationary and translated pieces must carry without barycentric round-trip drift.
313
+ const dxa = to[2 * a] - from[2 * a], dya = to[2 * a + 1] - from[2 * a + 1];
314
+ const dxb = to[2 * b] - from[2 * b], dyb = to[2 * b + 1] - from[2 * b + 1];
315
+ const dxc = to[2 * c] - from[2 * c], dyc = to[2 * c + 1] - from[2 * c + 1];
316
+ return [qx + dxc + w[0] * (dxa - dxc) + w[1] * (dxb - dxc), qy + dyc + w[0] * (dya - dyc) + w[1] * (dyb - dyc)];
313
317
  }
314
318
 
315
319
  /** The convex hull of `points`, counter-clockwise, collinear points dropped (Andrew's monotone chain). */