@rig-c/parts 2.43.0 → 2.45.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/README.md +2 -0
- package/cli.ts +141 -36
- package/docs/AUTHORING.md +541 -70
- package/docs/DEPTH.md +44 -3
- package/docs/MIGRATION.md +2 -0
- package/docs/STABILITY.md +357 -39
- package/package.json +1 -1
- package/src/boundarydepth.ts +113 -0
- package/src/check.ts +296 -78
- package/src/cloth.ts +14 -3
- package/src/config.ts +78 -11
- package/src/configwrite.ts +3 -3
- package/src/diffdrafts.ts +593 -0
- package/src/editedparts.ts +11 -2
- package/src/externalreceipt.ts +130 -0
- package/src/maskvalues.ts +21 -0
- package/src/outputpaths.ts +40 -0
- package/src/parts.ts +14 -5
- package/src/plate.ts +2 -6
- package/src/propose.ts +165 -8
- package/src/receiptproducer.ts +41 -0
- package/src/remesh-api.ts +33 -0
- package/src/remesh.ts +197 -19
- package/src/remeshdelta.ts +143 -30
- package/src/rig.ts +95 -21
- package/src/runstamp.ts +16 -0
- package/src/scene.ts +440 -54
- package/src/sceneclips.ts +198 -0
- package/src/turn.ts +24 -3
- package/tools/edited-part-cli.ts +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rig-c/parts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.45.0",
|
|
4
4
|
"description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Opt-in scalar boundary projection. No sheet, anchor or art is rewritten. */
|
|
2
|
+
import { extendDepthSilhouette, sampleDepthFloat, type PartDepthReference } from './depthsheets.ts';
|
|
3
|
+
import type { Problem } from './errors.ts';
|
|
4
|
+
import type { Raster } from './raster/types.ts';
|
|
5
|
+
|
|
6
|
+
export type BoundaryDepths = Record<string, { neighbour: string; band: string }>;
|
|
7
|
+
type Part = { name: string; x: number; y: number; w: number; h: number; depth?: PartDepthReference };
|
|
8
|
+
type Point = readonly [number, number];
|
|
9
|
+
type Edge = readonly [Point, Point];
|
|
10
|
+
|
|
11
|
+
/** Alpha support is the union of closed native pixel cells with alpha > 0.
|
|
12
|
+
* Projection is onto shared cell edges, not an inferred seam width. Distinct
|
|
13
|
+
* equidistant projections contribute once each, with their arithmetic mean.
|
|
14
|
+
* Outside the band the original extended target sample is returned exactly.
|
|
15
|
+
*/
|
|
16
|
+
export function boundaryDepthSamplers(
|
|
17
|
+
declarations: BoundaryDepths | undefined,
|
|
18
|
+
parts: readonly Part[],
|
|
19
|
+
images: ReadonlyMap<string, Raster>,
|
|
20
|
+
roles: Readonly<Record<string, string>>,
|
|
21
|
+
prefix: string,
|
|
22
|
+
): { samplers: Map<string, (x: number, y: number) => number>; problems: Problem[] } {
|
|
23
|
+
const samplers = new Map<string, (x: number, y: number) => number>();
|
|
24
|
+
const problems: Problem[] = [], result = { samplers, problems };
|
|
25
|
+
if (declarations === undefined || Object.keys(declarations).length === 0) return result;
|
|
26
|
+
const records = new Map(parts.map(p => [p.name, p]));
|
|
27
|
+
const fail = (target: string, detail: string): void => {
|
|
28
|
+
problems.push({ code: 'RIG_TURN_BOUNDARY_DEPTH', object: `${prefix}.boundaryDepths.${target}`, detail });
|
|
29
|
+
};
|
|
30
|
+
const support = (p: Part, art: Raster, x: number, y: number): boolean => {
|
|
31
|
+
const u = x - p.x, v = y - p.y;
|
|
32
|
+
return Number.isInteger(u) && Number.isInteger(v) && u >= 0 && v >= 0 && u < p.w && v < p.h && art.data[(v * art.width + u) * 4 + 3] > 0;
|
|
33
|
+
};
|
|
34
|
+
const contains = (p: Part, art: Raster, x: number, y: number): boolean => {
|
|
35
|
+
for (const u of new Set([Math.floor(x), Math.ceil(x) - 1])) for (const v of new Set([Math.floor(y), Math.ceil(y) - 1])) if (support(p, art, u, v)) return true;
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
const cyclic = new Set<string>();
|
|
39
|
+
for (const target of Object.keys(declarations)) {
|
|
40
|
+
const seen = new Set<string>();
|
|
41
|
+
for (let next: string | undefined = target; next !== undefined; next = declarations[next]?.neighbour) {
|
|
42
|
+
if (seen.has(next)) { fail(target, `cycle reaches "${next}"; remove reciprocal or cyclic boundary declarations`); cyclic.add(target); break; }
|
|
43
|
+
seen.add(next);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const [target, declaration] of Object.entries(declarations)) {
|
|
47
|
+
const startProblems = problems.length;
|
|
48
|
+
const p = records.get(target), n = records.get(declaration.neighbour), b = records.get(declaration.band);
|
|
49
|
+
for (const [field, record] of [['target', p], ['neighbour', n], ['band', b]] as const) if (record === undefined) fail(target, `${field} "${field === 'target' ? target : declaration[field]}" names no parts.json part; use an exact existing part name`);
|
|
50
|
+
if (p !== undefined && n !== undefined && (target === n.name || roles[target] !== 'surface' || roles[n.name] !== 'surface')) fail(target, `"${target}" and neighbour "${n.name}" require different surface parts in this same turn group`);
|
|
51
|
+
const pa = p === undefined ? undefined : images.get(p.name), na = n === undefined ? undefined : images.get(n.name), ba = b === undefined ? undefined : images.get(b.name);
|
|
52
|
+
const ps = p?.depth === undefined ? undefined : images.get(p.depth.image), ns = n?.depth === undefined ? undefined : images.get(n.depth.image);
|
|
53
|
+
if (p !== undefined && n !== undefined && b !== undefined && (pa === undefined || na === undefined || ba === undefined || ps === undefined || ns === undefined || p.depth === undefined || n.depth === undefined)) fail(target, `target "${target}", neighbour "${n.name}" and band "${b.name}" require resolved art and both original surface sheets`);
|
|
54
|
+
if (p?.depth !== undefined && n?.depth !== undefined && (p.depth.near !== n.depth.near || p.depth.zScale !== n.depth.zScale)) fail(target, `neighbour "${n.name}" requires the target's near and zScale in this turn group`);
|
|
55
|
+
const edges: Edge[] = [];
|
|
56
|
+
let overlap = false;
|
|
57
|
+
const canAbut = p !== undefined && n !== undefined && pa !== undefined && na !== undefined;
|
|
58
|
+
if (canAbut) {
|
|
59
|
+
for (let y = p.y; y < p.y + p.h; y++) for (let x = p.x; x < p.x + p.w; x++) {
|
|
60
|
+
if (!support(p, pa, x, y)) continue;
|
|
61
|
+
if (support(n, na, x, y)) overlap = true;
|
|
62
|
+
if (support(n, na, x - 1, y)) edges.push([[x, y], [x, y + 1]]);
|
|
63
|
+
if (support(n, na, x + 1, y)) edges.push([[x + 1, y], [x + 1, y + 1]]);
|
|
64
|
+
if (support(n, na, x, y - 1)) edges.push([[x, y], [x + 1, y]]);
|
|
65
|
+
if (support(n, na, x, y + 1)) edges.push([[x, y + 1], [x + 1, y + 1]]);
|
|
66
|
+
}
|
|
67
|
+
if (overlap || edges.length === 0) fail(target, `neighbour "${n.name}" does not abut without overlap along opaque pixel-cell edges; declare an abutting surface`);
|
|
68
|
+
}
|
|
69
|
+
// Containment depends on target/band art, not on neighbour depth or abutment.
|
|
70
|
+
// Report the first outside cell once; the remaining declarations still run.
|
|
71
|
+
if (p !== undefined && b !== undefined && pa !== undefined && ba !== undefined) {
|
|
72
|
+
let count = 0, outside = false;
|
|
73
|
+
for (let y = b.y; y < b.y + b.h; y++) for (let x = b.x; x < b.x + b.w; x++) if (support(b, ba, x, y)) {
|
|
74
|
+
count++;
|
|
75
|
+
if (!outside && !support(p, pa, x, y)) { fail(target, `band "${b.name}" has support outside target "${target}" at [${x},${y}]; require contained alpha support`); outside = true; }
|
|
76
|
+
}
|
|
77
|
+
// A missing shared edge cannot establish whether an otherwise valid band
|
|
78
|
+
// reaches it; retain the abutment failure instead of cascading a refusal.
|
|
79
|
+
if (n !== undefined && (count === 0 || (canAbut && !overlap && edges.length > 0 && !edges.some(([a, z]) => contains(b, ba, (a[0] + z[0]) / 2, (a[1] + z[1]) / 2))))) fail(target, `band "${b.name}" is empty or does not reach the shared boundary with "${n.name}"; require a nonempty boundary-reaching band`);
|
|
80
|
+
}
|
|
81
|
+
// Cycles prevent sampler emission, not independent declaration checks.
|
|
82
|
+
if (cyclic.has(target) || problems.length > startProblems || p === undefined || n === undefined || b === undefined || pa === undefined || na === undefined || ba === undefined || ps === undefined || ns === undefined || p.depth === undefined || n.depth === undefined) continue;
|
|
83
|
+
const original = extendDepthSilhouette(ps, pa), neighbour = extendDepthSilhouette(ns, na);
|
|
84
|
+
const seeds: Point[] = [];
|
|
85
|
+
for (let y = p.y; y < p.y + p.h; y++) for (let x = p.x; x < p.x + p.w; x++) if (support(p, pa, x, y)) seeds.push([x + 0.5, y + 0.5]);
|
|
86
|
+
samplers.set(target, (x, y) => {
|
|
87
|
+
const rawX = x, rawY = y;
|
|
88
|
+
// Transparent silhouette/PAD samples inherit their nearest opaque target
|
|
89
|
+
// cell, just as the original scalar extension does. This also retains
|
|
90
|
+
// boundary ownership when setup float encoding lands just outside art.
|
|
91
|
+
if (!contains(p, pa, x, y)) {
|
|
92
|
+
let nearest = Infinity;
|
|
93
|
+
for (const q of seeds) {
|
|
94
|
+
const d = (q[0] - rawX) ** 2 + (q[1] - rawY) ** 2;
|
|
95
|
+
if (d < nearest) { nearest = d; x = q[0]; y = q[1]; }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!contains(b, ba, x, y)) return sampleDepthFloat(original, rawX - p.x, rawY - p.y);
|
|
99
|
+
let distance = Infinity;
|
|
100
|
+
const closest = new Map<string, Point>();
|
|
101
|
+
for (const [a, z] of edges) {
|
|
102
|
+
const q: Point = [Math.max(a[0], Math.min(z[0], x)), Math.max(a[1], Math.min(z[1], y))];
|
|
103
|
+
const d = (q[0] - x) ** 2 + (q[1] - y) ** 2;
|
|
104
|
+
if (d < distance) { closest.clear(); distance = d; }
|
|
105
|
+
if (d === distance) closest.set(`${q[0]},${q[1]}`, q);
|
|
106
|
+
}
|
|
107
|
+
let sum = 0;
|
|
108
|
+
for (const q of closest.values()) sum += sampleDepthFloat(neighbour, q[0] - n.x, q[1] - n.y);
|
|
109
|
+
return sum / closest.size;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|