spine-parts 2.24.0 → 2.25.1
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/docs/AUTHORING.md +40 -0
- package/docs/STABILITY.md +45 -0
- package/package.json +1 -1
- package/src/assemble.ts +19 -6
- package/src/build.ts +48 -13
- package/src/check.ts +17 -17
- package/src/cutmaterialio.ts +5 -4
- package/src/depthworkflow.ts +6 -6
- package/src/diffcomponents.ts +2 -2
- package/src/meshdraft.ts +2 -2
- package/src/parts.ts +80 -10
- package/src/propose.ts +2 -2
- package/src/sheet.ts +3 -3
- package/src/sourcecover.ts +131 -0
package/docs/AUTHORING.md
CHANGED
|
@@ -798,6 +798,44 @@ existing geometry refusal and its message.
|
|
|
798
798
|
Region take entries accept the same optional `crop` and use this transport before
|
|
799
799
|
selecting the seeded component on the target run canvas.
|
|
800
800
|
|
|
801
|
+
### Source projection cover (`source_cover.json`, issue #1158)
|
|
802
|
+
|
|
803
|
+
Every assemble writes `source_cover.json` beside `parts.json`, under spec
|
|
804
|
+
`rig-parts-source-cover/1`. Its `sets` array contains the primary (`set: null`)
|
|
805
|
+
and every evaluated alternate, including empty readings. Reusing an output
|
|
806
|
+
replaces this single file, including its previous alternate inventory.
|
|
807
|
+
|
|
808
|
+
The stage is `source-projection-input`, after run preparation, ghost cleanup
|
|
809
|
+
and placement on the rig grid, before projection changes RGB. The predicate
|
|
810
|
+
counts a part's own alpha above 8 where another source owns the pixel at alpha
|
|
811
|
+
at least 250 and is in front. When both sources are planned, their plan ranks
|
|
812
|
+
settle front order. Otherwise the run's draw order does. Each `covered_by` row
|
|
813
|
+
names the owning source, whether it is planned, and `pixels.count` with sorted
|
|
814
|
+
native rig `[y, left, right-exclusive]` spans. A part's
|
|
815
|
+
`held_under_cover_px` counts own support protected by the keep mask separately,
|
|
816
|
+
so that support is excluded from scalar-owner rows.
|
|
817
|
+
|
|
818
|
+
Each set binds its painting and input manifests or PSDs by SHA-256, lists source
|
|
819
|
+
layers with depth, draw order, plan rank and planned/extend consumers, and names
|
|
820
|
+
input-layer identity, preparation and verified taken-layer provenance.
|
|
821
|
+
Generated layers without a same-name input entry have `input_layer: null`.
|
|
822
|
+
Unplanned sources remain listed even when they supply zero cover. An
|
|
823
|
+
extend-only source can be consumed while its plan rank remains -1.
|
|
824
|
+
`parts` describes the evaluated source plan, restricted to covered parts for
|
|
825
|
+
alternate sets. Source-only cut and limb dependencies remain in `sources`.
|
|
826
|
+
A covered derived cut or segment without its own layer row uses `source_of` to
|
|
827
|
+
name its parent's complete projection-input reading, before partitioning.
|
|
828
|
+
On the primary, a cut piece without its own layer is reported under its parent's row.
|
|
829
|
+
`output_assets` maps evaluated and inherited parts to exported image filenames,
|
|
830
|
+
with hidden or filtered assets mapped to null. `inherited_parts` references the
|
|
831
|
+
primary with `set: null`; inherited assets have no independently evaluated
|
|
832
|
+
alternate row. `hidden_parts` lists hidden assets.
|
|
833
|
+
|
|
834
|
+
Direct projection-input cover does not predict downstream changes. In
|
|
835
|
+
particular, an owner can suppress projection core eligibility while leaving a
|
|
836
|
+
part clear, and later merges, fringes and painting edges can change other
|
|
837
|
+
parts. This report observes the existing owner without changing assembly.
|
|
838
|
+
|
|
801
839
|
### Owner coverage transfers (`painting_allocation.json`, issue #1146)
|
|
802
840
|
|
|
803
841
|
Under `assemble.project: "visible"`, assemble writes `painting_allocation.json`
|
|
@@ -8303,3 +8341,5 @@ resolved relative to the config directory, including images declared relative
|
|
|
8303
8341
|
to the requirements file. Enumeration leaves both parsed inputs unchanged.
|
|
8304
8342
|
Rig/parts-directory inputs (including seam PNGs) and separately supplied CLI
|
|
8305
8343
|
inputs remain the caller's responsibility when relocating a check.
|
|
8344
|
+
|
|
8345
|
+
Programmatic consumers can enumerate declared assemble PNGs with `partsFileReferences` from `@rig-c/parts/src/parts.ts`, as specified in [STABILITY](STABILITY.md#programmatic-parts-file-references).
|
package/docs/STABILITY.md
CHANGED
|
@@ -56,6 +56,37 @@ files nor changes its inputs. Inputs that resolve from the rig or parts director
|
|
|
56
56
|
(seam and `cut_material` part images, `cut_material_sources.json`) are not listed,
|
|
57
57
|
because the caller already carries that directory with the check.
|
|
58
58
|
|
|
59
|
+
## Programmatic parts file references
|
|
60
|
+
|
|
61
|
+
`@rig-c/parts/src/parts.ts` exports `partsFileReferences(dir: string):
|
|
62
|
+
PartsFileReference[]` and the `PartsFileReference` type. `dir` holds the assemble
|
|
63
|
+
output's `parts.json`. Each row has `path: string`, relative to that directory,
|
|
64
|
+
and `role: 'part' | 'alternate' | 'depth' | 'painting' | 'figure_mask'`. The paths use `/`.
|
|
65
|
+
The complete output-reference fields and their roles are below.
|
|
66
|
+
|
|
67
|
+
| Field | Relative path | Role |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| `parts[].name` | `parts/<name>.png` | `part` |
|
|
70
|
+
| `alternates[].name` with `records[].name` | `parts/<set>_<name>.png` | `alternate` |
|
|
71
|
+
| Base or alternate record `depth.image` | `parts/<depth.image>` | `depth` |
|
|
72
|
+
| `painting_in_rig.path` | Exactly `painting_in_rig.png` | `painting` |
|
|
73
|
+
| Base or alternate `scene.figure_mask` | Exactly `figure_rig.png` | `figure_mask` |
|
|
74
|
+
|
|
75
|
+
Painting and figure masks sit beside the manifest. Shared base/alternate scene
|
|
76
|
+
references collapse to one row. Depth source provenance filenames and
|
|
77
|
+
`taken_layers` donor directories/input names are historical identity receipts
|
|
78
|
+
and are omitted. There is no separate attachment field.
|
|
79
|
+
Rows are sorted by path, then role, in UTF-16 code-unit order, with duplicate path/role pairs
|
|
80
|
+
collapsed. A path with several roles retains each role. Every PNG that
|
|
81
|
+
parts.json references is listed. A listed file missing on disk is the consumer's
|
|
82
|
+
refusal. Unreferenced extras are outside the identity. Historical source
|
|
83
|
+
provenance is retained in the manifest and is outside the output-file identity. The function reads and validates
|
|
84
|
+
only the manifest, using the production readers' path resolvers. A missing manifest
|
|
85
|
+
refuses with `PARTS_FILE_PRESENT`, malformed JSON with `PARTS_IS_JSON`, and
|
|
86
|
+
invalid fields with the same named rules as `readParts`. It never opens,
|
|
87
|
+
hashes or decodes PNGs and preserves the manifest reader's named refusals.
|
|
88
|
+
Legacy manifests may omit alternates, depth and painting declarations.
|
|
89
|
+
|
|
59
90
|
## Commands and flags
|
|
60
91
|
|
|
61
92
|
Exit codes are part of the interface: **0** the command did what it says, **1** it
|
|
@@ -286,6 +317,20 @@ every number) are AUTHORING §3's tables, and the loader refuses any other by na
|
|
|
286
317
|
|
|
287
318
|
## Files this package writes
|
|
288
319
|
|
|
320
|
+
### Source cover report
|
|
321
|
+
|
|
322
|
+
`assemble` and the assemble stage of `build` always write `source_cover.json`
|
|
323
|
+
beside `parts.json`, with spec `rig-parts-source-cover/1`. `stage`, `predicate`
|
|
324
|
+
and `sets` declare projection-input cover. Each set includes its painting hash,
|
|
325
|
+
rig grid, hash-bound inputs, effective source inventory, evaluated part rows,
|
|
326
|
+
inherited primary references, hidden parts and output asset mappings. Cover
|
|
327
|
+
rows carry owning source identity, planned membership and native pixel counts
|
|
328
|
+
and spans. A derived alternate row's optional `source_of` names its parent
|
|
329
|
+
source-plan reading before partitioning. Held-under-cover support is separate.
|
|
330
|
+
Empty readings remain explicit.
|
|
331
|
+
The report measures direct cover before projection and downstream processing.
|
|
332
|
+
The field semantics are documented in AUTHORING's source projection cover entry.
|
|
333
|
+
|
|
289
334
|
### Head-crop preflight stdout
|
|
290
335
|
|
|
291
336
|
`head-crop-preflight` writes one JSON object followed by a newline on success,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spine-parts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.1",
|
|
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": {
|
package/src/assemble.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sourceCoverRun, type SourceCoverReading } from './sourcecover.ts';
|
|
1
2
|
import { paintingReceivers, rawPaintingOwner } from './paintingowner.ts';
|
|
2
3
|
import { hiddenExtentProblems, type HiddenExtentDeclaration, type HiddenExtentSource } from './hiddenextent.ts';
|
|
3
4
|
import { headBoxInside } from './headbox.ts';
|
|
@@ -120,7 +121,7 @@ import { PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
|
120
121
|
import { CORE_ALPHA, figuresPhrase, implausibleRules, type Layer, type LayerFigures, layerFigures, type LayerSet, NEAR_WHITE_MIN, OPAQUE_ALPHA_ABOVE, ruleSummary } from './layers.ts';
|
|
121
122
|
import { padToSquare, squarePad } from './inputs.ts';
|
|
122
123
|
import type { MotionSeamDeclaration } from './motionseams.ts';
|
|
123
|
-
import { type CapRecord, type LimbRecord, PAINTING_RUN, type PartRecord, type PartsFile, type RecompositeRecord, type SceneRecord, type SingleRunPad } from './parts.ts';
|
|
124
|
+
import { type CapRecord, type LimbRecord, FIGURE_MASK_FILE, PAINTING_RUN, type PartRecord, type PartsFile, type RecompositeRecord, type SceneRecord, type SingleRunPad } from './parts.ts';
|
|
124
125
|
import { assignCrossedLimbs, assignOverlappingHands, type BonePlace, bonePlaces, capBox, coveredRadius, type CutPlacement, featherWeight, halfWidthAbout, inDisc, jointLine, type JointLine, jointOffsets, limbPolyline, limbRun, luma601, nearestLimb, nearestOnLine, offLineFigure, pastJoint, placeCut, polylineDist2, segmentOf } from './limbs.ts';
|
|
125
126
|
import {
|
|
126
127
|
alphaComposite,
|
|
@@ -2298,9 +2299,10 @@ export function pixelOwners(rigLayers: readonly Raster[], rank: readonly number[
|
|
|
2298
2299
|
* masks mark own-layer art under a subset set's actual cover (alpha above 8);
|
|
2299
2300
|
* those pixels are occluded, outside every projection core, and never recoloured.
|
|
2300
2301
|
*/
|
|
2301
|
-
export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, run: Run, rule: ProjectRule = DEFAULT_PROJECT_RULE, rank: readonly number[] | null = null, keep: ReadonlyArray<Mask | null> | null = null, changed?: (layer: number, rigPixel: number) => void): ProjectionStats[] {
|
|
2302
|
+
export function projectSource(rigLayers: Raster[], srcr: Raster, frame: Frame, run: Run, rule: ProjectRule = DEFAULT_PROJECT_RULE, rank: readonly number[] | null = null, keep: ReadonlyArray<Mask | null> | null = null, changed?: (layer: number, rigPixel: number) => void, observeOwners?: (owner: ArrayLike<number>) => void): ProjectionStats[] {
|
|
2302
2303
|
const { W, H } = frame;
|
|
2303
2304
|
const owner = pixelOwners(rigLayers, rank);
|
|
2305
|
+
observeOwners?.(owner);
|
|
2304
2306
|
const inFront = (o: number, i: number): boolean => frontOf(o, i, rank);
|
|
2305
2307
|
let win: Mask | null = null;
|
|
2306
2308
|
if (run === 'head') {
|
|
@@ -3355,7 +3357,7 @@ export function measureRecomposite(can: Raster, srcr: Raster, parts: PlacedPart[
|
|
|
3355
3357
|
}
|
|
3356
3358
|
|
|
3357
3359
|
/** The figure mask's file name, beside the recomposite (issue #242): `recomposite_rig.png` -> `figure_rig.png`. */
|
|
3358
|
-
export
|
|
3360
|
+
export { FIGURE_MASK_FILE } from './parts.ts';
|
|
3359
3361
|
|
|
3360
3362
|
/**
|
|
3361
3363
|
* The figure of a scene painting (issue #242): per rig pixel, 1 where any
|
|
@@ -4725,6 +4727,8 @@ export function softOcclusionLine(r: SoftOcclusionReading): string {
|
|
|
4725
4727
|
}
|
|
4726
4728
|
|
|
4727
4729
|
export interface AssembleResult {
|
|
4730
|
+
/** Direct projection-input cover; separate from final output visibility. */
|
|
4731
|
+
sourceCover: SourceCoverReading;
|
|
4728
4732
|
/** Compressed per-pixel classification, present only when requested. */
|
|
4729
4733
|
stageMap?: StageMap;
|
|
4730
4734
|
/** The already-resampled opaque painting used by this assembly. */
|
|
@@ -5097,6 +5101,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5097
5101
|
const valueBaselines = new Map<string, ValueBaseline | null>();
|
|
5098
5102
|
// Extend-only rasters are still projected/merged, but are never emitted as own sources.
|
|
5099
5103
|
const readKeys = new Set(sourcePlan.map(([, run, tag]) => `${run}:${tag}`));
|
|
5104
|
+
const sourceCover: SourceCoverReading = { sources: [], parts: [] };
|
|
5100
5105
|
const rig = new Map<string, Raster>();
|
|
5101
5106
|
const stats = new Map<string, ProjectionStats>();
|
|
5102
5107
|
const ghost: Record<string, number> = {};
|
|
@@ -5188,7 +5193,13 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5188
5193
|
valueBaselines.set(key, raw === null ? null : compactValueBaseline(raw));
|
|
5189
5194
|
return ids;
|
|
5190
5195
|
});
|
|
5191
|
-
const st = projectSource(rigLayers, srcr, frame, run, projectRule, rank, keep, (i, p) => { if (writes[i] !== null) (writes[i] as Int32Array)[p] = AW.sourceProjection; }
|
|
5196
|
+
const st = projectSource(rigLayers, srcr, frame, run, projectRule, rank, keep, (i, p) => { if (writes[i] !== null) (writes[i] as Int32Array)[p] = AW.sourceProjection; }, owners => {
|
|
5197
|
+
if (targets !== undefined && beforeTake === null) return;
|
|
5198
|
+
const reading = sourceCoverRun(run, set, run === 'full' ? fullPadded : depthHeadInput,
|
|
5199
|
+
rigLayers, rank, sourcePlan, extend, owners, (o, i) => frontOf(o, i, rank), keep);
|
|
5200
|
+
sourceCover.sources.push(...reading.sources);
|
|
5201
|
+
sourceCover.parts.push(...reading.parts);
|
|
5202
|
+
});
|
|
5192
5203
|
writes.forEach((ids, i) => { if (ids !== null) layerWriters.set(`${run}:${layers[i].tag}`, ids); });
|
|
5193
5204
|
writes.length = 0;
|
|
5194
5205
|
layers.forEach((l, i) => {
|
|
@@ -6038,8 +6049,8 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
6038
6049
|
});
|
|
6039
6050
|
refuseIfAny(empty);
|
|
6040
6051
|
const placed: PlacedPart[] = order.map((d) => ('plan' in d ? planned[d.plan] : 'cut' in d ? cutPlaced[d.cut] : 'limb' in d ? limbPlaced[d.limb] : cut[d.patch]) as PlacedPart);
|
|
6041
|
-
const artFiles = new
|
|
6042
|
-
for (const p of placed) if (p.record.depth !== undefined && artFiles.has(p.record.depth.image)) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: p.record.depth.image, detail:
|
|
6052
|
+
const artFiles = new Map<string, string>(); for (const p of placed) { const k = `${p.record.name}.png`.toLowerCase(), prev = artFiles.get(k); if (prev !== undefined) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: `${p.record.name}.png`, detail: `part "${prev}" ("${prev}.png") and part "${p.record.name}" ("${p.record.name}.png") collides with a part artwork filename; choose noncolliding part names before sheet emission` }]); artFiles.set(k, p.record.name); }
|
|
6053
|
+
for (const p of placed) if (p.record.depth !== undefined && artFiles.has(p.record.depth.image.toLowerCase())) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: p.record.depth.image, detail: `part "${p.record.name}" sheet "${p.record.depth.image}" and part "${artFiles.get(p.record.depth.image.toLowerCase())}" ("${artFiles.get(p.record.depth.image.toLowerCase())}.png") collides with a part artwork filename; choose noncolliding part names before sheet emission` }]);
|
|
6043
6054
|
|
|
6044
6055
|
|
|
6045
6056
|
const regionSupport = new Map<string, Mask>();
|
|
@@ -6123,7 +6134,9 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
6123
6134
|
const supportSilhouette = opaqueSource && visibleFigure === undefined ? silhouette ?? figureSilhouette(srcr, supportPainted) : null;
|
|
6124
6135
|
const supportFigure = visibleFigure ?? (supportSilhouette === null ? undefined : newMask(W, H));
|
|
6125
6136
|
if (supportFigure !== undefined && supportSilhouette !== null) for (let p = 0; p < supportPainted.length; p++) supportFigure.data[p] = supportSilhouette.data[p] & supportPainted[p];
|
|
6137
|
+
sourceCover.parts.sort((a, b) => sourcePlan.findIndex(([name]) => name === a.part) - sourcePlan.findIndex(([name]) => name === b.part));
|
|
6126
6138
|
return {
|
|
6139
|
+
sourceCover,
|
|
6127
6140
|
...(softOcclusion.length === 0 ? {} : { softOcclusion }),
|
|
6128
6141
|
...(!single ? { cropClipped: cropClippedLines(plan, extend, (run, tag) => rig.get(`${run}:${tag}`) ?? null, frame) } : {}),
|
|
6129
6142
|
paintingInRig: srcr,
|
package/src/build.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SOURCE_COVER_FILE, sourceCoverReport, type SourceCoverSet } from './sourcecover.ts';
|
|
1
2
|
import { STAGE_MAP_FILE } from './provenance.ts';
|
|
2
3
|
import { withoutCheckRows } from './checkrow.ts';
|
|
3
4
|
import { readSetupFigureMask } from './setupfiguremask.ts';
|
|
@@ -63,7 +64,7 @@ import { setFocusProblems } from './setfocus.ts';
|
|
|
63
64
|
*/
|
|
64
65
|
import { createHash } from 'node:crypto';
|
|
65
66
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
66
|
-
import { basename, dirname, join, resolve } from 'node:path';
|
|
67
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
67
68
|
import { type AnimFrame, EncodeError, encodeApng, encodeIndexedApng, INDEXED_DEFAULTS } from './apng.ts';
|
|
68
69
|
import { assemble, type AssembleResult, cutLines, type ExcludedCount, excludedLines, setExclusions, islandLines, setIslandSources, type IslandCount, hiddenLines, SINGLE_RUN_FACE_TAGS, singleRunHeadBox, softOcclusionLine, driftLine, limbLines, FIGURE_MASK_FILE, figuresLine, groundWarning, holeKindsLine, holeLines, measurePinholes, measureRecomposite, pinholeProblems, pinholesLine, type ProjectRule, recomposite, recompositeRecord, scenePhrase, type SeamRule, sourceInRig, stageFields, uncoveredLine } from './assemble.ts';
|
|
69
70
|
import { allocationClause, type Reducer, stageBClause, unboundedClause } from './automesh.ts';
|
|
@@ -103,7 +104,7 @@ import { CONTROL_SUFFIX, withAnimations } from './motion.ts';
|
|
|
103
104
|
import type { PaletteError } from './palette.ts';
|
|
104
105
|
import { type LayerSet, readLayers } from './layers.ts';
|
|
105
106
|
import { placeBoneEntriesForSkeleton, poseBoneEntriesForDrawn, REGISTER_OFFSET_BAR, REGISTER_SCALE_BAR, registeredWithinBar, registerSkeleton, SKELETON_LIMB_BONES, skeletonDrawnLength, skeletonLimbJoints } from './limbs.ts';
|
|
106
|
-
import { type AlternatePartsRecord, PAINTING_IN_RIG_FILE, FRONT_SUFFIX, type PartRecord, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
|
|
107
|
+
import { type AlternatePartsRecord, PAINTING_IN_RIG_FILE, FRONT_SUFFIX, type PartRecord, partImageReference, depthImageReference, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
|
|
107
108
|
import { encodePngBytes, readPng, writePng } from './raster/png.ts';
|
|
108
109
|
import type { Raster } from './raster/types.ts';
|
|
109
110
|
import { type Mask, newMask } from './raster/types.ts';
|
|
@@ -337,6 +338,23 @@ export function frontOrdered<T extends { record: { name: string } }>(items: read
|
|
|
337
338
|
return out;
|
|
338
339
|
}
|
|
339
340
|
|
|
341
|
+
/** Bind the pure owner reading to the exact stage inputs. */
|
|
342
|
+
function sourceCoverSet(result: AssembleResult, set: string | null, painting: string,
|
|
343
|
+
runs: ReturnType<typeof readRuns>): SourceCoverSet {
|
|
344
|
+
const inputs: SourceCoverSet['inputs'] = [];
|
|
345
|
+
for (const run of (runs.single ? ['full'] : ['full', 'head']) as Array<'full' | 'head'>) {
|
|
346
|
+
const layers = runs[run];
|
|
347
|
+
inputs.push({ run, file: basename(layers.source),
|
|
348
|
+
sha256: createHash('sha256').update(readFileSync(layers.source)).digest('hex'),
|
|
349
|
+
layers: layers.layers.map(layer => ({ layer: layer.name,
|
|
350
|
+
image: layer.file === null ? null : relative(dirname(layers.source), layer.file).split(sep).join('/') })) });
|
|
351
|
+
}
|
|
352
|
+
return { set, painting_sha256: createHash('sha256').update(readFileSync(painting)).digest('hex'),
|
|
353
|
+
grid: result.parts.rig_size, inputs, ...result.sourceCover,
|
|
354
|
+
inherited_parts: [], hidden_parts: [],
|
|
355
|
+
output_assets: result.parts.parts.map(part => ({ part: part.name, image: `${part.name}.png` })) };
|
|
356
|
+
}
|
|
357
|
+
|
|
340
358
|
/** Read, assemble, and write only after every refusal has had its chance. Throws a PartsError on a refusal, having written nothing. */
|
|
341
359
|
export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs, log: Log): AssembleResult {
|
|
342
360
|
const requirementsFile = input.requirements === undefined ? null : readRequirements(input.requirements);
|
|
@@ -371,6 +389,8 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
371
389
|
const result = assemble({ allocationEvent: input.allocationEvent === undefined ? undefined : event => input.allocationEvent!(event, null), source: src, full: runs.full, head: runs.head, depth: cfg.depth, depthBase: dirname(resolve(input.config)), ...fields, under, ...(declaredFigure === undefined ? {} : { declaredFigure }),
|
|
372
390
|
...((cfg.assemble.take ?? []).some(t => 'part' in t) ? { regionTake: { full: takenRuns.full, head: takenRuns.head, targets: (cfg.assemble.take ?? []).flatMap(t => 'part' in t ? [t.part] : []) } } : {}), ...(caps === undefined ? {} : { caps }), seamRule: seam, projectRule: project });
|
|
373
391
|
|
|
392
|
+
const sourceCoverSets = [sourceCoverSet(result, null, input.source, read)];
|
|
393
|
+
|
|
374
394
|
// Issue #454: alternate painting sets, assembled before any file is written.
|
|
375
395
|
const configDir = dirname(resolve(input.config));
|
|
376
396
|
const cliAlts = input.alts ?? [];
|
|
@@ -776,6 +796,21 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
776
796
|
const altCan = recomposite(fullSetPlaced, rW, rH);
|
|
777
797
|
altRecomposite = recompositeRecord(measureRecomposite(altCan, altSrcRig, fullSetPlaced));
|
|
778
798
|
}
|
|
799
|
+
const coverSet = sourceCoverSet(altRes, alt.name, alt.source, altRuns);
|
|
800
|
+
const sourceRows = altRes.sourceCover.parts;
|
|
801
|
+
coverSet.parts = keptRecords.flatMap(record => {
|
|
802
|
+
const direct = sourceRows.find(row => row.part === record.name);
|
|
803
|
+
if (direct !== undefined) return [direct];
|
|
804
|
+
const parent = record.cut_from ?? record.limb?.of;
|
|
805
|
+
const reading = sourceRows.find(row => row.part === parent);
|
|
806
|
+
return reading === undefined ? [] : [{ ...reading, part: record.name, source_of: reading.part }];
|
|
807
|
+
});
|
|
808
|
+
coverSet.inherited_parts = baseSlots.filter(name => !coveredSet.has(name) && !hidesSet.has(name)).map(part => ({ part, set: null }));
|
|
809
|
+
coverSet.hidden_parts = [...hidesSet];
|
|
810
|
+
coverSet.output_assets = [...new Set([...altRes.parts.parts.map(part => part.name), ...baseSlots])].map(name => ({ part: name,
|
|
811
|
+
image: hidesSet.has(name) ? null : keptRecords.some(record => record.name === name)
|
|
812
|
+
? `${alt.name}_${name}.png` : !coveredSet.has(name) && baseSlots.includes(name) ? `${name}.png` : null }));
|
|
813
|
+
sourceCoverSets.push(coverSet);
|
|
779
814
|
const alternateAllocation = altRes.paintingEdges?.allocation;
|
|
780
815
|
if (alternateAllocation !== undefined) {
|
|
781
816
|
allocationReports.push({
|
|
@@ -786,9 +821,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
786
821
|
source: { painting_sha256: createHash('sha256').update(readFileSync(alt.source)).digest('hex') },
|
|
787
822
|
stage: 'paintingEdges after piece guarding and restoration',
|
|
788
823
|
membership: 'pre-filter-alternate-assembly',
|
|
789
|
-
output_assets:
|
|
790
|
-
image: hidesSet.has(name) ? null : keptRecords.some(record => record.name === name)
|
|
791
|
-
? `${alt.name}_${name}.png` : !coveredSet.has(name) ? `${name}.png` : null })),
|
|
824
|
+
output_assets: coverSet.output_assets,
|
|
792
825
|
inherited_parts: baseSlots.filter(name => !coveredSet.has(name) && !hidesSet.has(name)),
|
|
793
826
|
hidden_parts: [...hidesSet],
|
|
794
827
|
...alternateAllocation,
|
|
@@ -833,20 +866,21 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
833
866
|
];
|
|
834
867
|
const assetIndices = new Map<string, number>();
|
|
835
868
|
emittedAssets.forEach((file, index) => {
|
|
836
|
-
const previous = assetIndices.get(file);
|
|
869
|
+
const previous = assetIndices.get(file.toLowerCase());
|
|
837
870
|
if (previous !== undefined) {
|
|
838
871
|
altProblems.push({
|
|
839
872
|
code: 'DEPTH_SHEET_UNAMBIGUOUS',
|
|
840
873
|
object: file,
|
|
841
|
-
detail: `output assets[${previous}] and [${index}] require the same filename; choose distinct base, alternate and sheet names`,
|
|
874
|
+
detail: `output assets[${previous}] ("${emittedAssets[previous]}") and [${index}] ("${file}") require the same filename; choose distinct base, alternate and sheet names`,
|
|
842
875
|
});
|
|
843
876
|
} else {
|
|
844
|
-
assetIndices.set(file, index);
|
|
877
|
+
assetIndices.set(file.toLowerCase(), index);
|
|
845
878
|
}
|
|
846
879
|
});
|
|
847
880
|
const outputFiles = new Set([
|
|
848
881
|
outs.partsJson, outs.recomposite, outs.errorMap,
|
|
849
882
|
join(dirname(outs.partsJson), PAINTING_ALLOCATION_FILE),
|
|
883
|
+
join(dirname(outs.partsJson), SOURCE_COVER_FILE),
|
|
850
884
|
join(dirname(outs.partsJson), PAINTING_IN_RIG_FILE),
|
|
851
885
|
join(dirname(outs.partsJson), SUPPORT_DOMAINS_FILE),
|
|
852
886
|
join(dirname(outs.partsJson), CUT_MATERIAL_SOURCES),
|
|
@@ -897,6 +931,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
897
931
|
sha256: createHash('sha256').update(paintingBytes).digest('hex'), resample: 'lanczos3-rgb-opaque' };
|
|
898
932
|
writeFileSync(join(dirname(outs.partsJson), PAINTING_IN_RIG_FILE), paintingBytes);
|
|
899
933
|
writeParts(outs.partsJson, result.parts);
|
|
934
|
+
writeFileSync(join(dirname(outs.partsJson), SOURCE_COVER_FILE), JSON.stringify(sourceCoverReport(sourceCoverSets), null, 2) + '\n');
|
|
900
935
|
const stageMapPath = join(dirname(outs.partsJson), STAGE_MAP_FILE);
|
|
901
936
|
if (result.stageMap === undefined) rmSync(stageMapPath, { force: true });
|
|
902
937
|
else writeFileSync(stageMapPath, JSON.stringify(result.stageMap) + '\n');
|
|
@@ -1591,16 +1626,16 @@ export function readRigInputs(config: string, partsDir: string): RigInputs {
|
|
|
1591
1626
|
const images = new Map<string, Raster>();
|
|
1592
1627
|
const depthProblems: Problem[] = [];
|
|
1593
1628
|
for (const p of parts.parts) {
|
|
1594
|
-
const png = join(partsDir,
|
|
1629
|
+
const png = join(partsDir, partImageReference(p).path);
|
|
1595
1630
|
if (existsSync(png)) images.set(p.name, readPng(png));
|
|
1596
|
-
if (p.depth !== undefined && images.has(p.name)) { try { images.set(p.depth.image, readSourceDepth(join(partsDir,
|
|
1631
|
+
if (p.depth !== undefined && images.has(p.name)) { try { images.set(p.depth.image, readSourceDepth(join(partsDir, depthImageReference(p.depth).path), images.get(p.name) as Raster, null).pixels); } catch (error) { if (error instanceof PartsError) depthProblems.push(...error.problems); else throw error; } }
|
|
1597
1632
|
}
|
|
1598
1633
|
for (const alt of parts.alternates ?? []) {
|
|
1599
1634
|
for (const p of alt.records) {
|
|
1600
1635
|
const attName = `${alt.name}_${p.name}`;
|
|
1601
|
-
const png = join(partsDir,
|
|
1636
|
+
const png = join(partsDir, partImageReference(p, alt.name).path);
|
|
1602
1637
|
if (existsSync(png)) images.set(attName, readPng(png));
|
|
1603
|
-
if (p.depth !== undefined && images.has(attName)) { try { images.set(p.depth.image, readSourceDepth(join(partsDir,
|
|
1638
|
+
if (p.depth !== undefined && images.has(attName)) { try { images.set(p.depth.image, readSourceDepth(join(partsDir, depthImageReference(p.depth).path), images.get(attName) as Raster, null).pixels); } catch (error) { if (error instanceof PartsError) depthProblems.push(...error.problems); else throw error; } }
|
|
1604
1639
|
}
|
|
1605
1640
|
}
|
|
1606
1641
|
refuseIfAny(depthProblems);
|
|
@@ -2533,7 +2568,7 @@ export interface BuildRunners {
|
|
|
2533
2568
|
}
|
|
2534
2569
|
|
|
2535
2570
|
/** Every path `build` writes under `--out`, relative — and so every path it clears first. */
|
|
2536
|
-
export const BUILD_OWNS: readonly string[] = ['parts', 'parts.json', PAINTING_IN_RIG_FILE, 'recomposite_rig.png', ERROR_MAP_FILE, 'rig', 'check', 'idle.gif', 'idle.png', 'idle-indexed.png'];
|
|
2571
|
+
export const BUILD_OWNS: readonly string[] = ['parts', 'parts.json', SOURCE_COVER_FILE, PAINTING_IN_RIG_FILE, 'recomposite_rig.png', ERROR_MAP_FILE, 'rig', 'check', 'idle.gif', 'idle.png', 'idle-indexed.png'];
|
|
2537
2572
|
|
|
2538
2573
|
export type BuildStage = 'assemble' | 'rig' | 'check' | 'loop' | 'artifact';
|
|
2539
2574
|
|
package/src/check.ts
CHANGED
|
@@ -145,7 +145,7 @@ import {
|
|
|
145
145
|
type ChainEdge,
|
|
146
146
|
type WorldBox,
|
|
147
147
|
} from './instruments.ts';
|
|
148
|
-
import { type AlternatePartsRecord, FRONT_SUFFIX, type LimbRecord, type PartRecord, type PartsFile, readParts } from './parts.ts';
|
|
148
|
+
import { type AlternatePartsRecord, FRONT_SUFFIX, type LimbRecord, partImageReference, type PartRecord, type PartsFile, readParts } from './parts.ts';
|
|
149
149
|
import { ARM_SPLIT_MIGRATION, poseRigBonesForDrawn, type RigBone, SETS_FILE, writtenShares } from './rig.ts';
|
|
150
150
|
import { TURN_BONE, turnConstraintName, turnTwin } from './turn.ts';
|
|
151
151
|
import { ROOT_BONE, loadConfigWithBytes, type Point } from './config.ts';
|
|
@@ -706,7 +706,7 @@ export function readCheckInputs(rigDir: string, partsHome?: string, sourcePath?:
|
|
|
706
706
|
}
|
|
707
707
|
if (parts !== null) {
|
|
708
708
|
for (const p of parts.parts) {
|
|
709
|
-
const png = join(
|
|
709
|
+
const png = join(home, partImageReference(p).path);
|
|
710
710
|
if (!existsSync(png)) {
|
|
711
711
|
problems.push({ code: 'CHECK_PART_PNG_PRESENT', object: `part "${p.name}"`, detail: `${png} does not exist; parts.json lists it` });
|
|
712
712
|
continue;
|
|
@@ -718,7 +718,7 @@ export function readCheckInputs(rigDir: string, partsHome?: string, sourcePath?:
|
|
|
718
718
|
}
|
|
719
719
|
for (const alt of parts.alternates ?? []) {
|
|
720
720
|
for (const r of alt.records) {
|
|
721
|
-
const png = join(
|
|
721
|
+
const png = join(home, partImageReference(r, alt.name).path);
|
|
722
722
|
if (!existsSync(png)) {
|
|
723
723
|
problems.push({ code: 'CHECK_PART_PNG_PRESENT', object: `set "${alt.name}" part "${r.name}"`, detail: `${png} does not exist; parts.json lists it` });
|
|
724
724
|
continue;
|
|
@@ -1382,7 +1382,7 @@ export function resolvePlacedAlpha(placements: readonly ReferencePlacement[], pa
|
|
|
1382
1382
|
const readRaw = (png: string): Raster => {
|
|
1383
1383
|
const hit = rawCache.get(png);
|
|
1384
1384
|
if (hit !== undefined) return hit;
|
|
1385
|
-
const img = readPng(join(partsDir,
|
|
1385
|
+
const img = readPng(join(dirname(partsDir), png));
|
|
1386
1386
|
rawCache.set(png, img);
|
|
1387
1387
|
return img;
|
|
1388
1388
|
};
|
|
@@ -1512,7 +1512,7 @@ export function setPlacements(parts: PartsFile, alt: AlternatePartsRecord, slotO
|
|
|
1512
1512
|
}
|
|
1513
1513
|
}
|
|
1514
1514
|
}
|
|
1515
|
-
const entry: PlacedIslandEntry = { name: islSlot, png: p.
|
|
1515
|
+
const entry: PlacedIslandEntry = { name: islSlot, png: partImageReference(p).path, box: p, islandIndex: k, islandCount: islandSlots.length, at };
|
|
1516
1516
|
if (!reordered) {
|
|
1517
1517
|
const list = inlineIslands.get(p.name) ?? [];
|
|
1518
1518
|
list.push(entry);
|
|
@@ -1543,11 +1543,11 @@ export function setPlacements(parts: PartsFile, alt: AlternatePartsRecord, slotO
|
|
|
1543
1543
|
const rec = byName.get(name);
|
|
1544
1544
|
const islandSlots = rec === undefined ? partIslandSlots(name, slotOrder) : [name];
|
|
1545
1545
|
if (islandSlots.length > 1) {
|
|
1546
|
-
out.push({ name, png:
|
|
1546
|
+
out.push({ name, png: partImageReference(base).path, box: base, islandIndex: 0, islandCount: islandSlots.length });
|
|
1547
1547
|
for (const isl of inlineIslands.get(name) ?? []) pushIsland(isl);
|
|
1548
1548
|
return;
|
|
1549
1549
|
}
|
|
1550
|
-
out.push({ name, png: rec === undefined ?
|
|
1550
|
+
out.push({ name, png: rec === undefined ? partImageReference(base).path : partImageReference(rec, alt.name).path, box: rec ?? base });
|
|
1551
1551
|
};
|
|
1552
1552
|
const baseOf = new Map(parts.parts.map((p) => [p.name, p]));
|
|
1553
1553
|
for (const p of parts.parts) {
|
|
@@ -1861,7 +1861,7 @@ export function seamDrawingSignature(input: {
|
|
|
1861
1861
|
/** File-only rig-image padding checks after the parts loader has validated each PNG against its record. */
|
|
1862
1862
|
export function boundaryColourSizeProblems(inp: CheckInputs): Problem[] {
|
|
1863
1863
|
if (inp.parts === null) return [];
|
|
1864
|
-
const records = new
|
|
1864
|
+
const records = new Map(inp.parts.parts.map(p => [p.name, p]));
|
|
1865
1865
|
const imagesDir = typeof inp.rig.images === 'string' ? resolve(inp.rigDir, inp.rig.images) : join(inp.rigDir, 'images');
|
|
1866
1866
|
const problems: Problem[] = [];
|
|
1867
1867
|
const seen = new Set<string>();
|
|
@@ -1874,9 +1874,9 @@ export function boundaryColourSizeProblems(inp: CheckInputs): Problem[] {
|
|
|
1874
1874
|
if (!seamImageSource(source) || seen.has(source.image)) continue;
|
|
1875
1875
|
const image = source.image;
|
|
1876
1876
|
seen.add(image);
|
|
1877
|
-
const name = image.replace(/\.png$/, '');
|
|
1878
|
-
const partPng = join(inp.partsDir,
|
|
1879
|
-
if (
|
|
1877
|
+
const name = image.replace(/\.png$/, ''), record = records.get(name);
|
|
1878
|
+
const partPng = record === undefined ? '' : join(dirname(inp.partsDir), partImageReference(record).path), rigPng = join(imagesDir, image);
|
|
1879
|
+
if (record === undefined || !existsSync(partPng) || !existsSync(rigPng)) continue;
|
|
1880
1880
|
let src: Raster, rigImg: Raster;
|
|
1881
1881
|
try { src = readPng(partPng); rigImg = readPng(rigPng); }
|
|
1882
1882
|
catch { continue; }
|
|
@@ -6664,7 +6664,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
6664
6664
|
const parts = ready.parts;
|
|
6665
6665
|
seams = take(() => resolveSeams(file, parts === null ? null : parts.parts.map((p) => p.name), ready.noParts, (n) => {
|
|
6666
6666
|
const rec = (parts as PartsFile).parts.find((p) => p.name === n) as PartRecord;
|
|
6667
|
-
return placedArt(rec.x, rec.y, readPng(join(ready.partsDir,
|
|
6667
|
+
return placedArt(rec.x, rec.y, readPng(join(dirname(ready.partsDir), partImageReference(rec).path)));
|
|
6668
6668
|
}));
|
|
6669
6669
|
}
|
|
6670
6670
|
if (wb !== null) take(() => resolveWindBand(wb, ready));
|
|
@@ -6678,7 +6678,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
6678
6678
|
// Read source support before rendering; no output/sidecar for undeclared builds.
|
|
6679
6679
|
if (reqFile?.cut_material !== undefined && (set !== undefined || allSets)) refuseIfAny([{code: 'CHECK_CUT_MATERIAL_MEASURED', object: 'cut_material', detail: 'source evidence binds base assembly only; run check on its base parts without --set/--all-sets; alternate-set coverage requires its own original source instrument'}]);
|
|
6680
6680
|
const cutMaterialProblems: Problem[] = [];
|
|
6681
|
-
const cutMaterial = reqFile?.cut_material === undefined ? null : checkJointMaterial(reqFile.cut_material, inp.parts, name => readPng(join(inp.partsDir,
|
|
6681
|
+
const cutMaterial = reqFile?.cut_material === undefined ? null : checkJointMaterial(reqFile.cut_material, inp.parts, name => readPng(join(dirname(inp.partsDir), partImageReference((inp.parts as PartsFile).parts.find(p => p.name === name) as PartRecord).path)), cutMaterialProblems, inp.parts === null ? undefined : readMaterialSources(dirname(inp.partsDir), inp.parts));
|
|
6682
6682
|
// A measured material failure is a check bar; unavailable data is a refusal.
|
|
6683
6683
|
const rigcEntry = readRigcEntry(requireRigcVersion(rigc));
|
|
6684
6684
|
/**
|
|
@@ -7035,7 +7035,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7035
7035
|
const png = (name: string): Raster => {
|
|
7036
7036
|
const hit = pngs.get(name);
|
|
7037
7037
|
if (hit !== undefined) return hit;
|
|
7038
|
-
const r = readPng(join(inp.partsDir,
|
|
7038
|
+
const r = readPng(join(dirname(inp.partsDir), partImageReference(parts.parts.find((p) => p.name === name) as PartRecord).path));
|
|
7039
7039
|
pngs.set(name, r);
|
|
7040
7040
|
return r;
|
|
7041
7041
|
};
|
|
@@ -8333,7 +8333,7 @@ function tipLine(inp: FullInputs, geometryPath: string, frames: number, problems
|
|
|
8333
8333
|
const rises = excepted.rises.includes(p.name);
|
|
8334
8334
|
const rests = excepted.rests.includes(p.name);
|
|
8335
8335
|
const [rootHalf, tipHalf] = rises ? ['lower', 'upper'] : ['upper', 'lower'];
|
|
8336
|
-
const art = placedArt(p.x, p.y, readPng(join(inp.partsDir,
|
|
8336
|
+
const art = placedArt(p.x, p.y, readPng(join(dirname(inp.partsDir), partImageReference(p).path)));
|
|
8337
8337
|
const shown = poses.map((f) => f.get(p.name) ?? null);
|
|
8338
8338
|
const w = halfTravels(art, p, inp.stage, shown, rises ? 'up' : 'down');
|
|
8339
8339
|
// Issue #987: the halves are read in the frame of the bone the part hangs from; the world reading rides beside them.
|
|
@@ -8862,7 +8862,7 @@ export function stillLine(inp: FullInputs, idle: FrameSet, geo: IdleGeometry | n
|
|
|
8862
8862
|
const H = inp.parts.rig_size[1];
|
|
8863
8863
|
const W = inp.parts.rig_size[0];
|
|
8864
8864
|
const poses = attachmentPoses(geometryPath, idle.written);
|
|
8865
|
-
const top = topmostIndex(inp.parts, (i) => readPng(join(inp.partsDir,
|
|
8865
|
+
const top = topmostIndex(inp.parts, (i) => readPng(join(dirname(inp.partsDir), partImageReference(inp.parts.parts[i]).path)));
|
|
8866
8866
|
const index = new Map(inp.parts.parts.map((p, i) => [p.name, i]));
|
|
8867
8867
|
const record = new Map(inp.parts.parts.map((p) => [p.name, p]));
|
|
8868
8868
|
const slots = (Array.isArray(inp.rig.slots) ? inp.rig.slots : []).filter(isRecord).map((sl) => ({ name: String(sl.name), bone: typeof sl.bone === 'string' ? sl.bone : undefined }));
|
|
@@ -8872,7 +8872,7 @@ export function stillLine(inp: FullInputs, idle: FrameSet, geo: IdleGeometry | n
|
|
|
8872
8872
|
let a = arts.get(name);
|
|
8873
8873
|
if (a === undefined) {
|
|
8874
8874
|
const p = record.get(name) as PartRecord;
|
|
8875
|
-
a = placedArt(p.x, p.y, readPng(join(inp.partsDir,
|
|
8875
|
+
a = placedArt(p.x, p.y, readPng(join(dirname(inp.partsDir), partImageReference(p).path)));
|
|
8876
8876
|
arts.set(name, a);
|
|
8877
8877
|
}
|
|
8878
8878
|
return a;
|
package/src/cutmaterialio.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { edgeLength } from './length.ts';
|
|
6
6
|
import { canonicalInward, CUT_MATERIAL_SOURCES, CUT_MATERIAL_SPEC, type MaterialSource, type Point } from './cutmaterial.ts';
|
|
7
|
-
import type
|
|
7
|
+
import { partImageReference, type PartsFile } from './parts.ts';
|
|
8
8
|
import { refuseIfAny } from './errors.ts';
|
|
9
9
|
const sha=(data:Uint8Array|string):string=>createHash('sha256').update(data).digest('hex');
|
|
10
10
|
const hash=(path:string):string=>sha(readFileSync(path));
|
|
@@ -15,7 +15,7 @@ export function writeMaterialSources(partsPath:string,partsDir:string,parts:Part
|
|
|
15
15
|
const emitted=sources.filter(s=>parts.parts.some(p=>p.name===s.part));
|
|
16
16
|
writeFileSync(join(dirname(partsPath),CUT_MATERIAL_SOURCES),JSON.stringify({
|
|
17
17
|
spec:CUT_MATERIAL_SPEC,parts_sha256:hash(partsPath),
|
|
18
|
-
images:parts.parts.map(p=>({part:p.name,sha256:hash(join(partsDir
|
|
18
|
+
images:parts.parts.map(p=>({part:p.name,sha256:hash(join(dirname(partsDir),partImageReference(p).path))})),
|
|
19
19
|
sources_sha256:sha(JSON.stringify(emitted)),sources:emitted,
|
|
20
20
|
},null,2)+'\n');
|
|
21
21
|
}
|
|
@@ -32,10 +32,11 @@ export function readMaterialSources(home:string,parts:PartsFile):MaterialSource[
|
|
|
32
32
|
if(raw.images.length!==parts.parts.length)return fail('image bindings do not cover every emitted base part');
|
|
33
33
|
const seen=new Set<string>();
|
|
34
34
|
for(const binding of raw.images){
|
|
35
|
-
|
|
35
|
+
const part=record(binding)&&typeof binding.part==='string'?parts.parts.find(p=>p.name===binding.part):undefined;
|
|
36
|
+
if(!record(binding)||typeof binding.part!=='string'||!digest(binding.sha256)||seen.has(binding.part)||part===undefined)return fail('image bindings require each named base part exactly once and its SHA-256');
|
|
36
37
|
if(Object.keys(binding).some(k=>!['part','sha256'].includes(k)))return fail('image binding has an unknown field');
|
|
37
38
|
seen.add(binding.part);
|
|
38
|
-
const file=join(home,
|
|
39
|
+
const file=join(home,partImageReference(part).path);
|
|
39
40
|
if(!existsSync(file)||hash(file)!==binding.sha256)return fail(`source-edge binding for part "${binding.part}" differs from its emitted PNG`);
|
|
40
41
|
}
|
|
41
42
|
const sources=new Set<string>();
|
package/src/depthworkflow.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
|
8
8
|
import { loadConfigAndAnimations, parseConfig } from './config.ts';
|
|
9
9
|
import { depthReading, readSourceDepth } from './depthsheets.ts';
|
|
10
10
|
import { alphaSupport, depthMapFail as fail, floatBox, integrateNormals, mapToSheet, readNumericMap, type NumericMap } from './depthmaps.ts';
|
|
11
|
-
import { readParts } from './parts.ts';
|
|
11
|
+
import { depthImageReference, partImageReference, readParts } from './parts.ts';
|
|
12
12
|
import { readPartSet } from './propose.ts';
|
|
13
13
|
import { decodePngBytes, encodePngBytes } from './raster/png.ts';
|
|
14
14
|
import { resize } from './raster/resize.ts';
|
|
@@ -98,7 +98,7 @@ function preparedParts(partsDir: string, recipe: DepthRecipe): { manifest: Prepa
|
|
|
98
98
|
}
|
|
99
99
|
if (!alphaSupport(art).some(Boolean)) fail('DEPTH_MAP_SUPPORT', part.name, 'has no alpha>=128 pixels; a supported part is required');
|
|
100
100
|
const bytes = encodePngBytes(input), file = `${part.name}.png`; images.set(file, bytes);
|
|
101
|
-
parts.push({ part: part.name, crop: [part.x, part.y, part.w, part.h], sourceSha256: hash(readFileSync(join(partsDir,
|
|
101
|
+
parts.push({ part: part.name, crop: [part.x, part.y, part.w, part.h], sourceSha256: hash(readFileSync(join(partsDir, partImageReference(part).path))), input: file, inputSha256: hash(bytes), size: [art.width, art.height], upscaled: [w, h], upscale, padding: pad, inputSize: [input.width, input.height] });
|
|
102
102
|
}
|
|
103
103
|
return { manifest: { spec: 'rig-parts-depth-inputs/1', partsSha256: hash(readFileSync(join(partsDir, 'parts.json'))), recipeSha256: hash(text(recipe)), background: 128, alpha: 128, parts }, images };
|
|
104
104
|
}
|
|
@@ -185,12 +185,12 @@ export function applyDepth(input: { parts: string; manifest: string; config: str
|
|
|
185
185
|
};
|
|
186
186
|
collect(input.parts, '');
|
|
187
187
|
for (const p of file.parts) {
|
|
188
|
-
const name = p.name, bytes = readFileSync(join(input.parts,
|
|
188
|
+
const name = p.name, bytes = readFileSync(join(input.parts, partImageReference(p).path)), art = decodePngBytes(bytes, name), rec = recs.find(r => r.name === name) as Obj;
|
|
189
189
|
writes.set(`${name}.png`, bytes);
|
|
190
190
|
const declaration = Object.hasOwn(recipe.parts, name) ? recipe.parts[name] : undefined;
|
|
191
191
|
if (declaration === undefined) {
|
|
192
|
-
if (recipe.clear.includes(name)) { if (p.depth !== undefined) retained.delete(
|
|
193
|
-
else if (p.depth !== undefined) {
|
|
192
|
+
if (recipe.clear.includes(name)) { if (p.depth !== undefined) retained.delete(depthImageReference(p.depth).path); delete rec.depth; }
|
|
193
|
+
else if (p.depth !== undefined) { const depthPath = join(input.parts, depthImageReference(p.depth).path); readSourceDepth(depthPath, art, null); writes.set(p.depth.image, readFileSync(depthPath)); }
|
|
194
194
|
continue;
|
|
195
195
|
}
|
|
196
196
|
const g = recipe.groups[declaration.group], target = declaration.group === 'head' ? turn : object(turn.body, 'config.turn.body');
|
|
@@ -213,7 +213,7 @@ export function applyDepth(input: { parts: string; manifest: string; config: str
|
|
|
213
213
|
const { sheet, reading } = mapToSheet(values, art, declaration.median, declaration.relief, g.near, g.zScale, name), image = `${name}_depth.png`, sheetBytes = encodePngBytes(sheet);
|
|
214
214
|
if (file.parts.some(p => `${p.name}.png` === image)) fail('DEPTH_GROUP_BINDING', name, `sheet filename ${image} collides with artwork; use noncolliding part names`);
|
|
215
215
|
writes.set(image, sheetBytes);
|
|
216
|
-
if (p.depth !== undefined) retained.delete(
|
|
216
|
+
if (p.depth !== undefined) retained.delete(depthImageReference(p.depth).path);
|
|
217
217
|
rec.depth = { image, near: g.near, zScale: g.zScale, sources: [{ from: p.from, image: basename(declaration.map), sha256: hash(mapBytes), crop: [0, 0, art.width, art.height], reading: depthReading(sheet, art, null) }] };
|
|
218
218
|
rows.push({ part: name, group: declaration.group, source: declaration.source, frame: declaration.frame, sourceSha256: prepared.sourceSha256, mapSha256: hash(mapBytes), inputSha256: prepared.inputSha256, sheetSha256: hash(sheetBytes), median: declaration.median, relief: declaration.relief, near: g.near, zScale: g.zScale, pivot: g.pivot, ...reading, sign: normal?.sign ?? 1, ...(normal === undefined ? {} : { integration: { stride: 2, iterations: normal.iterations, residual: normal.residual, coreMinusRim: normal.coreMinusRim, maxIterations: 3000, atol: 1e-6, btol: 1e-6 } }) });
|
|
219
219
|
}
|
package/src/diffcomponents.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { readFileSync, writeFileSync } from 'node:fs';
|
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { COVERED_ALPHA, ERROR_LIMIT, coveredMask, errorMask, holeBorders, type PlacedPart } from './assemble.ts';
|
|
6
6
|
import { PartsError, type Problem } from './errors.ts';
|
|
7
|
-
import { readParts } from './parts.ts';
|
|
7
|
+
import { partImageReference, readParts } from './parts.ts';
|
|
8
8
|
import { connectedComponents } from './raster/components.ts';
|
|
9
9
|
import { decodePngBytes } from './raster/png.ts';
|
|
10
10
|
import { newMask, type Raster } from './raster/types.ts';
|
|
@@ -184,7 +184,7 @@ export function diffComponentsCommand(args: string[]): void {
|
|
|
184
184
|
};
|
|
185
185
|
const partsPath = flags.get('--parts')!;
|
|
186
186
|
const parts = readParts(partsPath);
|
|
187
|
-
const placed = parts.parts.map(record => ({ record, image: diffPng(bytes(join(dirname(partsPath),
|
|
187
|
+
const placed = parts.parts.map(record => ({ record, image: diffPng(bytes(join(dirname(partsPath), partImageReference(record).path)).bytes, record.name) }));
|
|
188
188
|
const stack = bytes(flags.get('--stack')!), painting = bytes(flags.get('--painting')!);
|
|
189
189
|
const reference = diffPng(painting.bytes, painting.path);
|
|
190
190
|
if (parts.rig_size[0] !== reference.width || parts.rig_size[1] !== reference.height) inputFailure('parts.rig_size', `is ${parts.rig_size[0]}x${parts.rig_size[1]}; painting ${reference.width}x${reference.height} is required, with no resampling`);
|
package/src/meshdraft.ts
CHANGED
|
@@ -72,7 +72,7 @@ import { PartsError, type Problem, problemLine } from './errors.ts';
|
|
|
72
72
|
import { IDLE_FPS } from './motion.ts';
|
|
73
73
|
import { type ContourBridges, FAINT_ALPHA } from './contour.ts';
|
|
74
74
|
import { ART_ALPHA, DUST_MAX_PX, DUST_MAX_SHARE, isDust, dustOf, type DustReading } from './mesh.ts';
|
|
75
|
-
import { type PartsFile, readParts } from './parts.ts';
|
|
75
|
+
import { partImageReference, type PartsFile, readParts } from './parts.ts';
|
|
76
76
|
import { readPng } from './raster/png.ts';
|
|
77
77
|
import type { Raster } from './raster/types.ts';
|
|
78
78
|
import { buildRig, type IdleKeys, type MeshAttachment, rigJsonText, type RigSpec } from './rig.ts';
|
|
@@ -852,7 +852,7 @@ export function meshDraftStage(input: MeshDraftInput, rigc: RigcRunner, checkBin
|
|
|
852
852
|
if ('code' in rules) throw new PartsError([rules]);
|
|
853
853
|
const images = new Map<string, Raster>();
|
|
854
854
|
for (const p of parts.parts) {
|
|
855
|
-
const png = join(input.parts,
|
|
855
|
+
const png = join(input.parts, partImageReference(p).path);
|
|
856
856
|
if (existsSync(png)) images.set(p.name, readPng(png));
|
|
857
857
|
}
|
|
858
858
|
log(`rig-parts mesh-draft: ${cfg.key}, figure ${rules.height} px (rows ${rules.top}..${rules.bottom}): tolerance and margin T = max(1, round(${rules.height} / ${TOLERANCE_FIGURE_DIVISOR})) = ${rules.tolerance}, spacing and longest outline edge S = round(${rules.height} / ${FIGURE_GRID_DIVISOR}) = ${rules.spacing}`);
|
package/src/parts.ts
CHANGED
|
@@ -369,6 +369,7 @@ export interface AlternatePartsRecord {
|
|
|
369
369
|
registration?: { offset: [number, number]; scale: number };
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
export const FIGURE_MASK_FILE = 'figure_rig.png';
|
|
372
373
|
export const PAINTING_IN_RIG_FILE = 'painting_in_rig.png';
|
|
373
374
|
export interface PaintingInRig {
|
|
374
375
|
path: typeof PAINTING_IN_RIG_FILE;
|
|
@@ -600,7 +601,48 @@ export function writeParts(path: string, file: PartsFile): void {
|
|
|
600
601
|
writeFileSync(path, text);
|
|
601
602
|
}
|
|
602
603
|
|
|
603
|
-
|
|
604
|
+
/** A declared PNG path relative to the directory holding parts.json. */
|
|
605
|
+
export interface PartsFileReference {
|
|
606
|
+
path: string;
|
|
607
|
+
role: 'part' | 'alternate' | 'depth' | 'painting' | 'figure_mask';
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** Shared with the PNG readers, including their alternate attachment names. */
|
|
611
|
+
export function partImageReference(part: PartRecord, set?: string): PartsFileReference {
|
|
612
|
+
return { path: `parts/${set === undefined ? part.name : `${set}_${part.name}`}.png`, role: set === undefined ? 'part' : 'alternate' };
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export function depthImageReference(depth: PartDepthReference): PartsFileReference {
|
|
616
|
+
return { path: `parts/${depth.image}`, role: 'depth' };
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function paintingImageReference(painting: PaintingInRig): PartsFileReference {
|
|
620
|
+
return { path: painting.path, role: 'painting' };
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** Read the manifest without opening, hashing or decoding its PNG references. */
|
|
624
|
+
export function partsFileReferences(dir: string): PartsFileReference[] {
|
|
625
|
+
const file = readPartsManifest(join(dir, 'parts.json'));
|
|
626
|
+
const references: PartsFileReference[] = [];
|
|
627
|
+
const addScene = (scene: SceneRecord | undefined): void => {
|
|
628
|
+
if (scene !== undefined) references.push({ path: scene.figure_mask, role: 'figure_mask' });
|
|
629
|
+
};
|
|
630
|
+
addScene(file.scene);
|
|
631
|
+
if (file.painting_in_rig !== undefined) references.push(paintingImageReference(file.painting_in_rig));
|
|
632
|
+
const add = (part: PartRecord, set?: string): void => {
|
|
633
|
+
references.push(partImageReference(part, set));
|
|
634
|
+
if (part.depth !== undefined) references.push(depthImageReference(part.depth));
|
|
635
|
+
};
|
|
636
|
+
for (const part of file.parts) add(part);
|
|
637
|
+
for (const alternate of file.alternates ?? []) {
|
|
638
|
+
addScene(alternate.scene);
|
|
639
|
+
for (const part of alternate.records) add(part, alternate.name);
|
|
640
|
+
}
|
|
641
|
+
const unique = new Map(references.map(reference => [`${reference.path}\0${reference.role}`, reference]));
|
|
642
|
+
return [...unique.values()].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : a.role < b.role ? -1 : a.role > b.role ? 1 : 0);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function readPartsManifest(path: string): PartsFile {
|
|
604
646
|
if (!existsSync(path)) refuseIfAny([{ code: 'PARTS_FILE_PRESENT', object: path, detail: 'no such file; --parts names the directory holding parts.json and parts/ (work/rig from assemble --out work, or out from build --out out)' }]);
|
|
605
647
|
let raw: unknown;
|
|
606
648
|
try {
|
|
@@ -608,10 +650,14 @@ export function readParts(path: string): PartsFile {
|
|
|
608
650
|
} catch (err) {
|
|
609
651
|
refuseIfAny([{ code: 'PARTS_IS_JSON', object: path, detail: `does not parse as JSON: ${(err as Error).message}` }]);
|
|
610
652
|
}
|
|
611
|
-
|
|
653
|
+
return checkParts(raw, path);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export function readParts(path: string): PartsFile {
|
|
657
|
+
const file = readPartsManifest(path);
|
|
612
658
|
const declared = file.painting_in_rig;
|
|
613
659
|
if (declared !== undefined) {
|
|
614
|
-
const imagePath = join(dirname(path), declared.path);
|
|
660
|
+
const imagePath = join(dirname(path), paintingImageReference(declared).path);
|
|
615
661
|
const problems: Problem[] = [];
|
|
616
662
|
const fail = (code: string, detail: string): void => { problems.push({ code, object: imagePath, detail }); };
|
|
617
663
|
let bytes: Uint8Array | undefined;
|
|
@@ -641,6 +687,14 @@ function checkPaintingExtensionCount(r: Record<string, unknown>, label: string,
|
|
|
641
687
|
else if (!Number.isSafeInteger(r.opaque_px) || (n as number) > (r.opaque_px as number)) fail('PARTS_COUNTS_ADD_UP', label + ' painting_extension_px', `is ${show(n)}; at most opaque_px ${show(r.opaque_px)} is required`);
|
|
642
688
|
}
|
|
643
689
|
|
|
690
|
+
function checkFigureMask(value: unknown, object: string, fail: (code: string, object: string, detail: string) => void): void {
|
|
691
|
+
if (value !== FIGURE_MASK_FILE) fail('PARTS_FIELD_TYPE', object, `is ${show(value)}; exactly "${FIGURE_MASK_FILE}" is required`);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function isPartName(value: unknown): value is string {
|
|
695
|
+
return typeof value === 'string' && value !== '' && !/[\\/]/.test(value) && !value.startsWith('.');
|
|
696
|
+
}
|
|
697
|
+
|
|
644
698
|
function show(v: unknown): string {
|
|
645
699
|
return v === undefined ? 'absent' : JSON.stringify(v);
|
|
646
700
|
}
|
|
@@ -723,7 +777,7 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
723
777
|
}
|
|
724
778
|
if ('parts' in o && !(Array.isArray(o.parts) && o.parts.length > 0)) fail('PARTS_FIELD_TYPE', `${path} field "parts"`, `is ${show(o.parts)}; a non-empty array is required`);
|
|
725
779
|
if (Array.isArray(o.parts)) {
|
|
726
|
-
const seen = new Map<string, number>();
|
|
780
|
+
const seen = new Map<string, { index: number; name: string }>();
|
|
727
781
|
o.parts.forEach((p, i) => {
|
|
728
782
|
const at = `${path} parts[${i}]`;
|
|
729
783
|
if (typeof p !== 'object' || p === null || Array.isArray(p)) {
|
|
@@ -740,10 +794,10 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
740
794
|
if (held.length > 0 && held.length < VISIBILITY_KEYS.length) {
|
|
741
795
|
fail('PARTS_FIELD_PRESENT', `${label} fields ${VISIBILITY_KEYS.map((k) => `"${k}"`).join(', ')}`, `only ${held.join(', ')} present; all three (assemble writes them) or none (the reference's record) is required`);
|
|
742
796
|
}
|
|
743
|
-
if (
|
|
797
|
+
if (!isPartName(r.name)) {
|
|
744
798
|
fail('PARTS_FIELD_TYPE', `${label} field "name"`, `is ${show(r.name)}; a file-name-safe part name is required`);
|
|
745
|
-
} else if (seen.has(r.name)) fail('PARTS_NAME_UNIQUE', label, `appears at parts[${seen.get(r.name)}] and parts[${i}]`);
|
|
746
|
-
else seen.set(r.name, i);
|
|
799
|
+
} else if (seen.has(r.name.toLowerCase())) fail('PARTS_NAME_UNIQUE', label, `appears at parts[${seen.get(r.name.toLowerCase())!.index}] ("${seen.get(r.name.toLowerCase())!.name}") and parts[${i}] ("${r.name}")`);
|
|
800
|
+
else seen.set(r.name.toLowerCase(), { index: i, name: r.name });
|
|
747
801
|
const from = typeof r.from === 'string' ? readFrom(r.from) : null;
|
|
748
802
|
if (from === null) fail('PARTS_FROM_KNOWN', `${label} field "from"`, `is ${show(r.from)}; "<full|head>:<v3 tag>", "<full|head>:author:<label>" for a layer the author made, or "painting:<the part's own name>" for a patch, is required`);
|
|
749
803
|
else if (from.run === 'painting' && from.patch !== r.name) {
|
|
@@ -842,7 +896,7 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
842
896
|
for (const k of Object.keys(r)) if (!(SCENE_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${path} scene key "${k}"`, `is not a scene field; known: ${SCENE_KEYS.join(', ')}`);
|
|
843
897
|
for (const k of SCENE_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${path} scene field "${k}"`, 'is absent and required');
|
|
844
898
|
for (const k of ['figure_alpha_above', 'figure_px'] as const) if (k in r && !(Number.isInteger(r[k]) && (r[k] as number) >= 0)) fail('PARTS_FIELD_TYPE', `${path} scene field "${k}"`, `is ${show(r[k])}; a non-negative integer is required`);
|
|
845
|
-
if ('figure_mask' in r
|
|
899
|
+
if ('figure_mask' in r) checkFigureMask(r.figure_mask, `${path} scene field "figure_mask"`, fail);
|
|
846
900
|
if (!('recomposite' in o)) fail('PARTS_FIELD_PRESENT', `${path} field "recomposite"`, 'is absent; a scene block says how the recomposite block beside it was measured, so it is required with one');
|
|
847
901
|
}
|
|
848
902
|
}
|
|
@@ -858,9 +912,19 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
858
912
|
if (Array.isArray(o.alternates)) {
|
|
859
913
|
// Issue #620: a set record's cap is a cap, so it is held to the base records' rule; the object names the set and the part.
|
|
860
914
|
o.alternates.forEach((a, i) => {
|
|
861
|
-
if (typeof a !== 'object' || a === null || Array.isArray(a))
|
|
915
|
+
if (typeof a !== 'object' || a === null || Array.isArray(a)) {
|
|
916
|
+
fail('PARTS_FIELD_TYPE', `${path} alternates[${i}]`, `is ${show(a)}; an alternate set object is required`);
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
862
919
|
const set = a as Record<string, unknown>;
|
|
863
920
|
const at = `${path} alternates[${i}]${typeof set.name === 'string' ? ` (set "${set.name}")` : ''}`;
|
|
921
|
+
if (!isPartName(set.name)) fail('PARTS_FIELD_TYPE', `${at} field "name"`, `is ${show(set.name)}; a file-name-safe set name is required`);
|
|
922
|
+
if (!Array.isArray(set.records)) fail('PARTS_FIELD_TYPE', `${at} field "records"`, `is ${show(set.records)}; an array of alternate part records is required`);
|
|
923
|
+
if ('scene' in set) {
|
|
924
|
+
const scene = set.scene;
|
|
925
|
+
if (typeof scene !== 'object' || scene === null || Array.isArray(scene)) fail('PARTS_FIELD_TYPE', `${at} field "scene"`, `is ${show(scene)}; an object is required`);
|
|
926
|
+
else checkFigureMask((scene as Record<string, unknown>).figure_mask, `${at} scene field "figure_mask"`, fail);
|
|
927
|
+
}
|
|
864
928
|
if ('cut_ownership' in set) checkOwnership(set.cut_ownership, `${at} cut_ownership`, fail);
|
|
865
929
|
if ('base_anchor' in set) {
|
|
866
930
|
const names = new Set(Array.isArray(set.records) ? set.records.flatMap(v => typeof v === 'object' && v !== null && typeof v.name === 'string' ? [v.name] : []) : []);
|
|
@@ -903,8 +967,14 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
903
967
|
if (!Array.isArray(set.records)) return;
|
|
904
968
|
if (set.records.some((p) => typeof p === 'object' && p !== null && !Array.isArray(p) && typeof p.limb === 'object' && p.limb !== null && ('hybrid' in p.limb || 'band' in p.limb))) checkLimbRecords(set.records, `${at} `, fail, false);
|
|
905
969
|
set.records.forEach((p, j) => {
|
|
906
|
-
if (typeof p !== 'object' || p === null || Array.isArray(p))
|
|
970
|
+
if (typeof p !== 'object' || p === null || Array.isArray(p)) {
|
|
971
|
+
fail('PARTS_FIELD_TYPE', `${at} records[${j}]`, `is ${show(p)}; a part object is required`);
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
907
974
|
const r = p as Record<string, unknown>;
|
|
975
|
+
const recordAt = `${at} records[${j}]`;
|
|
976
|
+
if (!isPartName(r.name)) fail('PARTS_FIELD_TYPE', `${recordAt} field "name"`, `is ${show(r.name)}; a file-name-safe part name is required`);
|
|
977
|
+
if ('depth' in r) problems.push(...partDepthProblems(r.depth, `${recordAt} depth`));
|
|
908
978
|
const part817 = typeof r.name === 'string' ? `part "${r.name}"` : `records[${j}]`;
|
|
909
979
|
if ('provenance' in r) checkProvenance(r.provenance, r.opaque_px, `${at} ${part817} provenance`, fail, 'depth' in r);
|
|
910
980
|
checkPaintingExtensionCount(r, `${at} ${part817}`, fail);
|
package/src/propose.ts
CHANGED
|
@@ -140,7 +140,7 @@ import { PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
|
140
140
|
import { GRID } from './contour.ts';
|
|
141
141
|
import { eyeLineDegrees, type FrameFeature, headAxes, type HeadAxes, headFrame, type HeadFrame } from './headframe.ts';
|
|
142
142
|
import { type LayerSet, OPAQUE_ALPHA_ABOVE } from './layers.ts';
|
|
143
|
-
import { PAINTING_RUN, type PartRecord, type PartsFile, readParts } from './parts.ts';
|
|
143
|
+
import { PAINTING_RUN, type PartRecord, type PartsFile, partImageReference, readParts } from './parts.ts';
|
|
144
144
|
import { connectedComponents } from './raster/components.ts';
|
|
145
145
|
import { dilate, morphGradient } from './raster/morph.ts';
|
|
146
146
|
import { readPng } from './raster/png.ts';
|
|
@@ -922,7 +922,7 @@ export function readPartSet(dir: string): PartSet {
|
|
|
922
922
|
const problems: Problem[] = [];
|
|
923
923
|
const images = new Map<string, Raster>();
|
|
924
924
|
for (const p of file.parts) {
|
|
925
|
-
const png = join(dir,
|
|
925
|
+
const png = join(dir, partImageReference(p).path);
|
|
926
926
|
if (!existsSync(png)) {
|
|
927
927
|
problems.push({ code: 'PROPOSE_PNG_PRESENT', object: `part "${p.name}"`, detail: `${png} does not exist; parts.json names it` });
|
|
928
928
|
continue;
|
package/src/sheet.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { basename, dirname, join } from 'node:path';
|
|
|
21
21
|
import { drawText, GLYPH_H } from '@rig-c/core/font5x7';
|
|
22
22
|
import { type Problem, refuseIfAny } from './errors.ts';
|
|
23
23
|
import { type LayerSet, OPAQUE_ALPHA_ABOVE, readLayers } from './layers.ts';
|
|
24
|
-
import { readParts } from './parts.ts';
|
|
24
|
+
import { partImageReference, readParts } from './parts.ts';
|
|
25
25
|
import { alphaComposite } from './raster/composite.ts';
|
|
26
26
|
import { readPng } from './raster/png.ts';
|
|
27
27
|
import { resize } from './raster/resize.ts';
|
|
@@ -109,11 +109,11 @@ export function buildSheet(tiles: Tile[], cols: number, cell: number): Raster {
|
|
|
109
109
|
export function tilesFrom(path: string): Tile[] {
|
|
110
110
|
if (basename(path) === 'parts.json') {
|
|
111
111
|
const parts = readParts(path);
|
|
112
|
-
const dir =
|
|
112
|
+
const dir = dirname(path);
|
|
113
113
|
const problems: Problem[] = [];
|
|
114
114
|
const tiles: Tile[] = [];
|
|
115
115
|
for (const p of parts.parts) {
|
|
116
|
-
const png = join(dir,
|
|
116
|
+
const png = join(dir, partImageReference(p).path);
|
|
117
117
|
if (!existsSync(png)) {
|
|
118
118
|
problems.push({ code: 'SHEET_PNG_PRESENT', object: `part "${p.name}"`, detail: `${png} does not exist; parts.json names it` });
|
|
119
119
|
continue;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/** Direct source-projection cover, observed before projection changes RGB.
|
|
2
|
+
* Counts belong to effective run layers, before cuts, merges and edge writes.
|
|
3
|
+
*/
|
|
4
|
+
import type { Extend, PlanEntry, Run } from './config.ts';
|
|
5
|
+
import { CORE_ALPHA, OPAQUE_ALPHA_ABOVE, type LayerSet } from './layers.ts';
|
|
6
|
+
import type { Mask, Raster } from './raster/types.ts';
|
|
7
|
+
import type { TakenLayerSource } from './takesource.ts';
|
|
8
|
+
|
|
9
|
+
export const SOURCE_COVER_FILE = 'source_cover.json';
|
|
10
|
+
export const SOURCE_COVER_SPEC = 'rig-parts-source-cover/1';
|
|
11
|
+
|
|
12
|
+
export interface SourceCoverLayer {
|
|
13
|
+
source: string;
|
|
14
|
+
run: Run;
|
|
15
|
+
layer: string;
|
|
16
|
+
depth_median: number | null;
|
|
17
|
+
draw_order: number;
|
|
18
|
+
plan_rank: number;
|
|
19
|
+
planned_parts: string[];
|
|
20
|
+
extend_parts: string[];
|
|
21
|
+
/** Null for a generated layer with no same-name input entry. */
|
|
22
|
+
input_layer: string | null;
|
|
23
|
+
prepared: boolean;
|
|
24
|
+
taken_layers: readonly TakenLayerSource[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SourceCoverPart {
|
|
28
|
+
part: string;
|
|
29
|
+
/** Parent source-plan reading attributed to a derived alternate part. */
|
|
30
|
+
source_of?: string;
|
|
31
|
+
source: string;
|
|
32
|
+
support_px: number;
|
|
33
|
+
/** Original own support held by keep, excluded from scalar-owner rows. */
|
|
34
|
+
held_under_cover_px: number;
|
|
35
|
+
covered_by: Array<{
|
|
36
|
+
source: string;
|
|
37
|
+
planned: boolean;
|
|
38
|
+
pixels: { count: number; spans: Array<[number, number, number]> };
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SourceCoverReading {
|
|
43
|
+
sources: SourceCoverLayer[];
|
|
44
|
+
parts: SourceCoverPart[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SourceCoverSet extends SourceCoverReading {
|
|
48
|
+
set: string | null;
|
|
49
|
+
painting_sha256: string;
|
|
50
|
+
grid: [number, number];
|
|
51
|
+
inputs: Array<{
|
|
52
|
+
run: Run;
|
|
53
|
+
file: string;
|
|
54
|
+
sha256: string;
|
|
55
|
+
layers: Array<{ layer: string; image: string | null }>;
|
|
56
|
+
}>;
|
|
57
|
+
inherited_parts: Array<{ part: string; set: null }>;
|
|
58
|
+
hidden_parts: string[];
|
|
59
|
+
output_assets: Array<{ part: string; image: string | null }>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function sourceCoverReport(sets: SourceCoverSet[]) {
|
|
63
|
+
return {
|
|
64
|
+
spec: SOURCE_COVER_SPEC,
|
|
65
|
+
stage: 'source-projection-input',
|
|
66
|
+
predicate: {
|
|
67
|
+
own_alpha_above: OPAQUE_ALPHA_ABOVE,
|
|
68
|
+
owner_alpha_at_least: CORE_ALPHA,
|
|
69
|
+
front: 'plan rank when both layers are planned; run draw order otherwise',
|
|
70
|
+
held_under_cover: 'keep support excluded from covered_by',
|
|
71
|
+
coordinates: 'native rig [y, left, right-exclusive]',
|
|
72
|
+
},
|
|
73
|
+
sets,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Reads the already-computed owner. Never changes a raster, mask or owner. */
|
|
78
|
+
export function sourceCoverRun(
|
|
79
|
+
run: Run, set: LayerSet, original: LayerSet, images: readonly Raster[],
|
|
80
|
+
ranks: readonly number[], plan: readonly PlanEntry[], extend: readonly Extend[],
|
|
81
|
+
owners: ArrayLike<number>, inFront: (owner: number, layer: number) => boolean,
|
|
82
|
+
keep: ReadonlyArray<Mask | null> | null,
|
|
83
|
+
): SourceCoverReading {
|
|
84
|
+
const sources: SourceCoverLayer[] = set.layers.map((layer, i) => {
|
|
85
|
+
const input = original.layers.find(candidate => candidate.name === layer.name);
|
|
86
|
+
return {
|
|
87
|
+
source: `${run}:${layer.name}`, run, layer: layer.name,
|
|
88
|
+
depth_median: layer.depth, draw_order: layer.drawOrder, plan_rank: ranks[i],
|
|
89
|
+
planned_parts: plan.filter(([, r, tag]) => r === run && tag === layer.name).map(([part]) => part),
|
|
90
|
+
extend_parts: extend.filter(entry => entry.run === run && entry.tag === layer.name).map(entry => entry.part),
|
|
91
|
+
input_layer: input?.name ?? null,
|
|
92
|
+
prepared: input === undefined || input.left !== layer.left || input.top !== layer.top ||
|
|
93
|
+
input.pixels.width !== layer.pixels.width || input.pixels.height !== layer.pixels.height ||
|
|
94
|
+
input.pixels.data.length !== layer.pixels.data.length ||
|
|
95
|
+
(input.pixels.data !== layer.pixels.data && !input.pixels.data.every((value, pixel) => value === layer.pixels.data[pixel])),
|
|
96
|
+
taken_layers: layer.takenLayers ?? [],
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const parts: SourceCoverPart[] = plan.filter(([, r]) => r === run).map(([part, , tag]) => {
|
|
100
|
+
const layer = set.layers.findIndex(candidate => candidate.name === tag);
|
|
101
|
+
const image = images[layer];
|
|
102
|
+
const cover = new Map<number, SourceCoverPart['covered_by'][number]['pixels']>();
|
|
103
|
+
let support = 0;
|
|
104
|
+
let held = 0;
|
|
105
|
+
for (let p = 0; p < owners.length; p++) {
|
|
106
|
+
if (image.data[p * 4 + 3] <= OPAQUE_ALPHA_ABOVE) continue;
|
|
107
|
+
support++;
|
|
108
|
+
if (keep?.[layer]?.data[p] === 1) { held++; continue; }
|
|
109
|
+
const owner = owners[p];
|
|
110
|
+
if (owner < 0 || owner === layer || !inFront(owner, layer)) continue;
|
|
111
|
+
let pixels = cover.get(owner);
|
|
112
|
+
if (pixels === undefined) {
|
|
113
|
+
pixels = { count: 0, spans: [] };
|
|
114
|
+
cover.set(owner, pixels);
|
|
115
|
+
}
|
|
116
|
+
pixels.count++;
|
|
117
|
+
const x = p % image.width;
|
|
118
|
+
const y = Math.floor(p / image.width);
|
|
119
|
+
const last = pixels.spans[pixels.spans.length - 1];
|
|
120
|
+
if (last !== undefined && last[0] === y && last[2] === x) last[2]++;
|
|
121
|
+
else pixels.spans.push([y, x, x + 1]);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
part, source: `${run}:${tag}`, support_px: support, held_under_cover_px: held,
|
|
125
|
+
covered_by: [...cover].sort(([a], [b]) => a - b).map(([owner, pixels]) => ({
|
|
126
|
+
source: sources[owner].source, planned: ranks[owner] >= 0, pixels,
|
|
127
|
+
})),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
return { sources, parts };
|
|
131
|
+
}
|