spine-rigc 1.8.0 → 1.9.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/cli.ts +2 -2
- package/docs/AUTHORING.md +3 -3
- package/package.json +1 -1
- package/src/assertions/bodies/a04.ts +40 -0
- package/src/assertions/bodies/a06.ts +195 -0
- package/src/assertions/bodies/a08.ts +76 -0
- package/src/assertions/bodies/a13.ts +51 -0
- package/src/assertions/bodies/a14.ts +35 -0
- package/src/assertions/bodies/a15.ts +97 -0
- package/src/assertions/bodies/a19.ts +295 -0
- package/src/assertions/bodies/a20.ts +122 -0
- package/src/assertions/bodies/a21.ts +190 -0
- package/src/assertions/bodies/a22.ts +39 -0
- package/src/assertions/bodies/a23.ts +255 -0
- package/src/assertions/bodies/a27.ts +33 -0
- package/src/assertions/bodies/a28.ts +70 -0
- package/src/assertions/bodies/a33.ts +110 -0
- package/src/assertions/bodies/a36.ts +81 -0
- package/src/assertions/bodies/a37.ts +77 -0
- package/src/assertions/bodies/a38.ts +73 -0
- package/src/assertions/bodies/a41.ts +83 -0
- package/src/assertions/bodies/a42.ts +97 -0
- package/src/assertions/bodies/a44.ts +23 -0
- package/src/assertions/bodies/a47.ts +59 -0
- package/src/assertions/bodies/a48.ts +83 -0
- package/src/assertions/constraint_words.ts +177 -0
- package/src/assertions/facts/animated_bones.ts +28 -0
- package/src/assertions/facts/atlas_regions.ts +52 -0
- package/src/assertions/facts/constraints.ts +131 -0
- package/src/assertions/facts/linked_meshes.ts +38 -0
- package/src/assertions/facts/mesh_attachments.ts +71 -0
- package/src/assertions/facts/region_joins.ts +34 -0
- package/src/assertions/facts/skin_entries.ts +4 -2
- package/src/assertions/facts/skin_members.ts +53 -0
- package/src/assertions/facts/skin_meshes.ts +49 -0
- package/src/assertions/facts/stage.ts +24 -0
- package/src/assertions/facts/vertex_polygons.ts +53 -0
- package/src/assertions/mesh_kinds.ts +56 -0
- package/src/assertions/model/animated_bones.ts +30 -0
- package/src/assertions/model/atlas_regions.ts +76 -0
- package/src/assertions/model/constraints.ts +207 -0
- package/src/assertions/model/given.ts +45 -0
- package/src/assertions/model/index.ts +130 -13
- package/src/assertions/model/linked_meshes.ts +24 -0
- package/src/assertions/model/mesh_attachments.ts +90 -0
- package/src/assertions/model/parse.ts +2 -0
- package/src/assertions/model/region_joins.ts +59 -0
- package/src/assertions/model/skin_entries.ts +2 -1
- package/src/assertions/model/skin_members.ts +62 -0
- package/src/assertions/model/skin_meshes.ts +90 -0
- package/src/assertions/model/stage.ts +28 -0
- package/src/assertions/model/vertex_polygons.ts +71 -0
- package/src/assertions/region_lookups.ts +61 -0
- package/src/check.ts +8 -6
- package/src/compile.ts +145 -38
- package/src/core/index.ts +154 -24
- package/src/deformstructure.ts +16 -7
- package/src/emit_spine.ts +21 -41
- package/src/keyorder.ts +40 -0
- package/src/model.ts +183 -20
- package/src/render.ts +66 -25
- package/src/render_core.ts +41 -13
- package/src/validate.ts +601 -2328
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model side's supply of `MeshFacts` (issue #1025, step 4c of #380): the
|
|
3
|
+
* document's mesh and linked-mesh records, in the file's walk order, with the
|
|
4
|
+
* geometry and the weights the runtime holds after its parse.
|
|
5
|
+
*
|
|
6
|
+
* Every value is the document's, through a function rigc already runs:
|
|
7
|
+
*
|
|
8
|
+
* - **The order** is `fileOrderedEntries` (`./skin_entries.ts`), the skins
|
|
9
|
+
* put in the file's order by the emitter's `editorSkinOrder`.
|
|
10
|
+
* - **A binding's bone** is the index the emitter writes for its name,
|
|
11
|
+
* `boneIndexOf` over the document's bones (`src/emit_spine.ts`), and its
|
|
12
|
+
* weight the float32 the runtime stores a vertex array in (`Math.fround`,
|
|
13
|
+
* `src/model.ts`'s 🔸).
|
|
14
|
+
* - **A link's geometry is its source's**: its vertices are the core's
|
|
15
|
+
* `sourceOfDoc`, its `uvs` and triangles the core's `drawWalkOf(...).meshOf`
|
|
16
|
+
* — the two lookups the core poses a linked mesh through — and its hull
|
|
17
|
+
* the source record's, read where those two read it.
|
|
18
|
+
* - **The counts the parser derives**: `worldVerticesLength` is the length
|
|
19
|
+
* of `uvs` (the length the parser hands its vertex reader for a mesh), and
|
|
20
|
+
* `hullLength` twice the record's `hull`, which the parser reads at the
|
|
21
|
+
* mesh row's default of the parser-default table when the key is absent
|
|
22
|
+
* (`PARSER_DEFAULTS` in `src/keyorder.ts`, which the selftest holds to the
|
|
23
|
+
* parser row by row).
|
|
24
|
+
*
|
|
25
|
+
* `encoding` is empty on every entry: the document states the weighted form
|
|
26
|
+
* outright and names bones, so the clauses about the flat run have no subject
|
|
27
|
+
* here (`../facts/mesh_attachments.ts`'s 🔒).
|
|
28
|
+
*
|
|
29
|
+
* Links nothing from the runtime.
|
|
30
|
+
*/
|
|
31
|
+
import { boneIndexOf } from '../../emit_spine.ts';
|
|
32
|
+
import { drawWalkOf, shownRow, sourceOfDoc } from '../../core/index.ts';
|
|
33
|
+
import { PARSER_DEFAULTS } from '../../keyorder.ts';
|
|
34
|
+
import type { ModelVertices } from '../../model.ts';
|
|
35
|
+
import type { MeshBinding, MeshEntry, MeshFacts } from '../facts/mesh_attachments.ts';
|
|
36
|
+
import { fileOrderedEntries } from './skin_entries.ts';
|
|
37
|
+
import type { ReadDocument } from './parse.ts';
|
|
38
|
+
|
|
39
|
+
/** The parser's reading of a mesh with no `hull` key, off the parser-default table. */
|
|
40
|
+
function hullDefault(): number {
|
|
41
|
+
const stated = PARSER_DEFAULTS['mesh attachment']?.hull;
|
|
42
|
+
if (typeof stated !== 'number') throw new Error('internal: the parser-default table has no number for a mesh attachment\'s hull');
|
|
43
|
+
return stated;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function modelMeshFacts(read: ReadDocument): MeshFacts {
|
|
47
|
+
const { doc } = read;
|
|
48
|
+
const indexOf = boneIndexOf(doc.bones);
|
|
49
|
+
const sourceVertices = sourceOfDoc(doc);
|
|
50
|
+
const walk = drawWalkOf(doc, []);
|
|
51
|
+
const slotBone = new Map(doc.slots.map((s) => [s.name, s.bone]));
|
|
52
|
+
const meshes: MeshEntry[] = [];
|
|
53
|
+
for (const entry of fileOrderedEntries(read)) {
|
|
54
|
+
const g = entry.record.geometry;
|
|
55
|
+
if (g === undefined || (g.kind !== 'mesh' && g.kind !== 'linkedmesh')) continue;
|
|
56
|
+
const where = `skin "${entry.skin}" slot "${entry.slot}" placeholder "${entry.placeholder}"`;
|
|
57
|
+
let vertices: ModelVertices;
|
|
58
|
+
let uvs: readonly number[];
|
|
59
|
+
let triangles: readonly number[];
|
|
60
|
+
let hull: number | undefined;
|
|
61
|
+
if (g.kind === 'mesh') {
|
|
62
|
+
({ vertices, uvs, triangles, hull } = g);
|
|
63
|
+
} else {
|
|
64
|
+
// `readModel` resolves every link to a mesh or refuses the document, so a miss here is this module's defect.
|
|
65
|
+
const found = sourceVertices(g.skin, g.slot, g.source);
|
|
66
|
+
const drawn = walk.meshOf(g.skin, g.slot, g.source);
|
|
67
|
+
if (typeof found === 'string' || drawn === undefined) throw new Error(`internal: ${where} is a link the reader returned without a source mesh: ${typeof found === 'string' ? found : 'no uvs'}`);
|
|
68
|
+
vertices = found;
|
|
69
|
+
({ uvs, triangles } = drawn);
|
|
70
|
+
const source = doc.skins.find((k) => k.name === g.skin)?.attachments[g.slot]?.[g.source]?.geometry;
|
|
71
|
+
hull = source?.kind === 'mesh' ? source.hull : undefined;
|
|
72
|
+
}
|
|
73
|
+
const weights: MeshBinding[][] | null = vertices.weighted ? vertices.bindings.map((influences) => influences.map((b) => ({ bone: indexOf(b.bone), weight: Math.fround(b.weight) }))) : null;
|
|
74
|
+
meshes.push({
|
|
75
|
+
name: shownRow(entry).name,
|
|
76
|
+
skin: entry.skin,
|
|
77
|
+
slot: entry.slot,
|
|
78
|
+
slotBone: slotBone.get(entry.slot) ?? '',
|
|
79
|
+
placeholder: entry.placeholder,
|
|
80
|
+
link: g.kind === 'linkedmesh' ? { source: g.source } : null,
|
|
81
|
+
triangles,
|
|
82
|
+
worldVerticesLength: uvs.length,
|
|
83
|
+
regionUVs: uvs,
|
|
84
|
+
hullLength: 2 * (hull ?? hullDefault()),
|
|
85
|
+
weights,
|
|
86
|
+
encoding: [],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { bones: doc.bones.map((b) => b.name), meshes };
|
|
90
|
+
}
|
|
@@ -55,6 +55,8 @@ export const MODEL_PARSE_KIND: Readonly<Record<string, AssertionKind>> = {
|
|
|
55
55
|
|
|
56
56
|
/** What the region rule SKIPs with when the reader refused the document. */
|
|
57
57
|
export const SKIP_NO_MODEL_DOCUMENT = `the reader refused the document, so there is no record to resolve (${A00_MODEL_READ} owns that failure)`;
|
|
58
|
+
/** What A08 SKIPs with on the model side over a `rigc-compiled/1` document, which states no pages to read region names off (issue #1025, cut 4c-1). */
|
|
59
|
+
export const SKIP_NO_MODEL_PAGES = 'the document is a rigc-compiled/1 document, which states no pages, so there are no region names to join against';
|
|
58
60
|
/** What the region rule SKIPs with when no record resolves through a region. */
|
|
59
61
|
export const SKIP_NO_REGION_RECORD = 'no record of the document resolves through an atlas region';
|
|
60
62
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model side's supply of `RegionJoinFacts` (issue #1025, step 4c of
|
|
3
|
+
* #380): the document's region names and every lookup a skin record makes.
|
|
4
|
+
*
|
|
5
|
+
* - **The region names** are the document's `pages` regions, page by page in
|
|
6
|
+
* order — `pagesOfAtlas` writes them from the atlas text `build` wrote, by the
|
|
7
|
+
* reader `PKR01` holds to spine-core's, so they are the atlas's regions in its
|
|
8
|
+
* order, each name as the atlas spells it. A `rigc-compiled/1` document states
|
|
9
|
+
* no pages, and the registry skips A08 on it by name rather than reading that
|
|
10
|
+
* as an atlas that declares no region (`./index.ts`).
|
|
11
|
+
* - **The lookups** walk the document's skins as the file lays them: the skins
|
|
12
|
+
* by the emitter's `editorSkinOrder`, a skin's slot keys by its
|
|
13
|
+
* `editorSlotKeyOrder` (both `src/compile.ts`, the functions `emitSkins` is
|
|
14
|
+
* handed) — NOT the draw order `./skin_entries.ts` walks, because A08 walks the
|
|
15
|
+
* file's keys and the loaded skins do not — and a slot's records in its
|
|
16
|
+
* table's order. A record of a kind that resolves a region (`CORE_REGION_KINDS`:
|
|
17
|
+
* region, mesh, linked mesh) joins under its `name`, else its placeholder,
|
|
18
|
+
* through its `path`, else that name; a `sequence` makes the lookups
|
|
19
|
+
* `attachmentRegionLookups` makes of the Spine file's, called on the
|
|
20
|
+
* document's own sequence record.
|
|
21
|
+
*
|
|
22
|
+
* Links nothing from the runtime.
|
|
23
|
+
*/
|
|
24
|
+
import { editorSkinOrder, editorSlotKeyOrder } from '../../compile.ts';
|
|
25
|
+
import { CORE_REGION_KINDS } from '../../core/index.ts';
|
|
26
|
+
import type { SkinTableEntry } from '../../model.ts';
|
|
27
|
+
import type { RegionJoinFacts } from '../facts/region_joins.ts';
|
|
28
|
+
import { attachmentRegionLookups, type AttachmentRegionJoin } from '../region_lookups.ts';
|
|
29
|
+
import { isObj, type Json } from '../values.ts';
|
|
30
|
+
import type { ReadDocument } from './parse.ts';
|
|
31
|
+
|
|
32
|
+
/** The joins, with the skins and their slot keys put in order by `skins` and `slotKeys` — the emitter's unless the selftest asks what the document's own order would print. */
|
|
33
|
+
export function modelRegionJoinsWith(
|
|
34
|
+
read: ReadDocument,
|
|
35
|
+
skins: <T extends { name: string }>(list: readonly T[]) => T[] = editorSkinOrder,
|
|
36
|
+
slotKeys: <T>(table: Record<string, T>) => Record<string, T> = editorSlotKeyOrder,
|
|
37
|
+
): RegionJoinFacts {
|
|
38
|
+
const pages = read.doc.pages;
|
|
39
|
+
const regionNames = pages === null ? null : pages.flatMap((page) => page.regions.map((region) => region.name));
|
|
40
|
+
const stated = (Array.isArray(read.json.skins) ? read.json.skins.filter(isObj) : []).filter((skin): skin is Json & { name: string } => typeof skin.name === 'string');
|
|
41
|
+
const joins: AttachmentRegionJoin[] = [];
|
|
42
|
+
for (const skin of skins(stated)) {
|
|
43
|
+
if (!isObj(skin.attachments)) continue;
|
|
44
|
+
for (const [slot, table] of Object.entries(slotKeys(skin.attachments))) {
|
|
45
|
+
if (!isObj(table)) continue;
|
|
46
|
+
for (const [placeholder, record] of Object.entries(table)) {
|
|
47
|
+
if (!isObj(record) || !CORE_REGION_KINDS.has(record.kind as SkinTableEntry['kind'])) continue;
|
|
48
|
+
const name = typeof record.name === 'string' ? record.name : placeholder;
|
|
49
|
+
const path = typeof record.path === 'string' ? record.path : name;
|
|
50
|
+
joins.push({ skin: skin.name, slot, placeholder, name, lookups: attachmentRegionLookups(record.sequence, path) });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { regionNames, joins };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function modelRegionJoins(read: ReadDocument): RegionJoinFacts {
|
|
58
|
+
return modelRegionJoinsWith(read);
|
|
59
|
+
}
|
|
@@ -52,7 +52,8 @@ export function modelSkinEntries(read: ReadDocument, order: SkinOrder = editorSk
|
|
|
52
52
|
const geometry = entry.record.geometry;
|
|
53
53
|
// `readModel` reads every region record's geometry or refuses the document, so a record without one is this module's defect.
|
|
54
54
|
if (geometry?.kind !== 'region') throw new Error(`internal: skin "${entry.skin}" slot "${entry.slot}" placeholder "${entry.placeholder}" is a region record the reader returned without its geometry`);
|
|
55
|
-
|
|
55
|
+
const shown = shownRow(entry);
|
|
56
|
+
regionAttachments.push({ name: shown.name, width: geometry.region.width, height: geometry.region.height, path: shown.path as string });
|
|
56
57
|
}
|
|
57
58
|
return { regionAttachments, clippingCount };
|
|
58
59
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model side's supply of `SkinMemberFacts` (issue #1025, step 4c of
|
|
3
|
+
* #380): the bones, the constraints and each skin's lists, read off the
|
|
4
|
+
* document and joined the way the runtime's loader joins them.
|
|
5
|
+
*
|
|
6
|
+
* - **Bones**: the document's `bones` in order, each with its `skinRequired`
|
|
7
|
+
* as stated (absent is not required) and its parent entry.
|
|
8
|
+
* - **Constraints**: the document's `constraints` in order — update order, the
|
|
9
|
+
* order the emitter writes them in — each skin-required exactly when it
|
|
10
|
+
* states `skin: true`, the field the emitter writes through unchanged.
|
|
11
|
+
* - **Skins**: in the emitter's order (`editorSkinOrder`, `src/compile.ts`); a
|
|
12
|
+
* skin's bones as it lists them, each the FIRST bone of that name; its
|
|
13
|
+
* constraints kind by kind in the emitter's key order
|
|
14
|
+
* (`RIG_SKIN_CONSTRAINT_KEYS`, which `emitSkins` walks), each the first
|
|
15
|
+
* constraint of that kind and name — the object the loader finds, and the
|
|
16
|
+
* same object `constraints` holds, so a body asking whether one is listed
|
|
17
|
+
* asks by identity. `readModel` refuses a skin listing a constraint of a
|
|
18
|
+
* kind and name the document lacks; a bone name it lacks is this module's to
|
|
19
|
+
* refuse, by name.
|
|
20
|
+
*
|
|
21
|
+
* Links nothing from the runtime.
|
|
22
|
+
*/
|
|
23
|
+
import { editorSkinOrder } from '../../compile.ts';
|
|
24
|
+
import { RIG_SKIN_CONSTRAINT_KEYS } from '../../rig.ts';
|
|
25
|
+
import type { MemberBone, MemberConstraint, MemberSkin, SkinMemberFacts } from '../facts/skin_members.ts';
|
|
26
|
+
import { isObj } from '../values.ts';
|
|
27
|
+
import type { ReadDocument } from './parse.ts';
|
|
28
|
+
|
|
29
|
+
export function modelSkinMembers(read: ReadDocument): SkinMemberFacts {
|
|
30
|
+
const doc = read.doc;
|
|
31
|
+
const bones: MemberBone[] = [];
|
|
32
|
+
const boneByName = new Map<string, MemberBone>();
|
|
33
|
+
for (const bone of doc.bones) {
|
|
34
|
+
const parent = bone.parent === undefined ? null : boneByName.get(bone.parent);
|
|
35
|
+
if (parent === undefined) throw new Error(`internal: bone "${bone.name}" names parent "${bone.parent}", which the reader accepted and no earlier bone is`);
|
|
36
|
+
const entry: MemberBone = { name: bone.name, skinRequired: bone.skinRequired === true, parent };
|
|
37
|
+
bones.push(entry);
|
|
38
|
+
if (!boneByName.has(bone.name)) boneByName.set(bone.name, entry);
|
|
39
|
+
}
|
|
40
|
+
const constraints: Array<MemberConstraint & { kind: string }> = [];
|
|
41
|
+
const stated = Array.isArray(read.json.constraints) ? read.json.constraints.filter(isObj) : [];
|
|
42
|
+
for (const constraint of stated) {
|
|
43
|
+
constraints.push({ name: String(constraint.name), kind: String(constraint.kind), skinRequired: constraint.skin === true });
|
|
44
|
+
}
|
|
45
|
+
const skins: MemberSkin[] = editorSkinOrder(doc.skins).map((skin) => {
|
|
46
|
+
const listedBones = skin.bones.map((name) => {
|
|
47
|
+
const found = boneByName.get(name);
|
|
48
|
+
if (found === undefined) throw new Error(`skin "${skin.name}" lists bone "${name}", which is not a bone of the document`);
|
|
49
|
+
return found;
|
|
50
|
+
});
|
|
51
|
+
const listedConstraints: MemberConstraint[] = [];
|
|
52
|
+
for (const kind of RIG_SKIN_CONSTRAINT_KEYS) {
|
|
53
|
+
for (const name of skin.constraints[kind]) {
|
|
54
|
+
const found = constraints.find((c) => c.kind === kind && c.name === name);
|
|
55
|
+
if (found === undefined) throw new Error(`internal: skin "${skin.name}" lists ${kind} constraint "${name}", which the reader accepted and the document does not hold`);
|
|
56
|
+
listedConstraints.push(found);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { name: skin.name, bones: listedBones, constraints: listedConstraints };
|
|
60
|
+
});
|
|
61
|
+
return { skins, bones, constraints };
|
|
62
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model side's supply of `SkinMeshFacts` (issue #1025, step 4c of #380):
|
|
3
|
+
* every mesh and linked-mesh record of every skin, read off the document in the
|
|
4
|
+
* file's walk order.
|
|
5
|
+
*
|
|
6
|
+
* - **The order** is `fileOrderedEntries`'s (`./skin_entries.ts`): the skins by
|
|
7
|
+
* the emitter's `editorSkinOrder`, the slots in the document's slot order, a
|
|
8
|
+
* slot's records in its table's order — the walk the selftest measures equal
|
|
9
|
+
* to spine-core's `getAttachments()`.
|
|
10
|
+
* - **A linked mesh's geometry is its source's**, read through the core's own
|
|
11
|
+
* joins rather than a copy of them: the vertices through `sourceOfDoc` and
|
|
12
|
+
* the UVs and triangles through the draw walk's `meshOf` (`drawWalkOf`), both
|
|
13
|
+
* in `src/core/index.ts`; and its `width` and `height` are the source
|
|
14
|
+
* record's too, the two numbers `setSourceMesh` overwrites the link's own
|
|
15
|
+
* with. `readModel` refuses a link whose source does not resolve, so a miss
|
|
16
|
+
* here is this module's defect.
|
|
17
|
+
* - **The bones a mesh's weights name** are its bindings' bone names, in the
|
|
18
|
+
* bindings' order — the document states a weighted vertex by bone NAME, and
|
|
19
|
+
* the Spine file's index run is the emitter's encoding of exactly that list.
|
|
20
|
+
* - **`worldVerticesLength`** is two per vertex: `2 · bindings.length` for a
|
|
21
|
+
* weighted mesh, `xy.length` for a plain one — the derivation
|
|
22
|
+
* `src/deformstructure.ts` already makes for the deform survey.
|
|
23
|
+
* - **`width` and `height`** are the record's, off the document's JSON: the
|
|
24
|
+
* core's geometry reader keeps a mesh's vertices, UVs and triangles and not
|
|
25
|
+
* its size, which no pose reads.
|
|
26
|
+
*
|
|
27
|
+
* Links nothing from the runtime.
|
|
28
|
+
*/
|
|
29
|
+
import { drawWalkOf, shownRow, sourceOfDoc } from '../../core/index.ts';
|
|
30
|
+
import type { ModelVertices } from '../../model.ts';
|
|
31
|
+
import type { MeshEntry, SkinMeshFacts } from '../facts/skin_meshes.ts';
|
|
32
|
+
import { isObj } from '../values.ts';
|
|
33
|
+
import type { ReadDocument } from './parse.ts';
|
|
34
|
+
import { fileOrderedEntries } from './skin_entries.ts';
|
|
35
|
+
|
|
36
|
+
/** A record's own `width` and `height` as the document states them, found by skin (the first of that name, as a link resolves its skin), slot and placeholder. */
|
|
37
|
+
function statedSize(read: ReadDocument, skin: string, slot: string, placeholder: string): { width: number; height: number } {
|
|
38
|
+
const skins = Array.isArray(read.json.skins) ? read.json.skins : [];
|
|
39
|
+
const found = skins.find((k: unknown) => isObj(k) && k.name === skin);
|
|
40
|
+
const table = isObj(found) && isObj(found.attachments) ? found.attachments[slot] : undefined;
|
|
41
|
+
const record = isObj(table) ? table[placeholder] : undefined;
|
|
42
|
+
if (!isObj(record) || typeof record.width !== 'number' || typeof record.height !== 'number') {
|
|
43
|
+
throw new Error(`internal: skin "${skin}" slot "${slot}" placeholder "${placeholder}" is a mesh record the document states no width and height for`);
|
|
44
|
+
}
|
|
45
|
+
return { width: record.width, height: record.height };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function modelSkinMeshes(read: ReadDocument): SkinMeshFacts {
|
|
49
|
+
const doc = read.doc;
|
|
50
|
+
const sourceVertices = sourceOfDoc(doc);
|
|
51
|
+
const walk = drawWalkOf(doc, []);
|
|
52
|
+
const slotBone = new Map(doc.slots.map((slot) => [slot.name, slot.bone] as const));
|
|
53
|
+
const meshes: MeshEntry[] = [];
|
|
54
|
+
for (const entry of fileOrderedEntries(read)) {
|
|
55
|
+
if (entry.record.kind !== 'mesh' && entry.record.kind !== 'linkedmesh') continue;
|
|
56
|
+
const g = entry.record.geometry;
|
|
57
|
+
let vertices: ModelVertices;
|
|
58
|
+
let uvs: number[];
|
|
59
|
+
let triangles: number[];
|
|
60
|
+
let size: { width: number; height: number };
|
|
61
|
+
if (g?.kind === 'mesh') {
|
|
62
|
+
({ vertices, uvs, triangles } = g);
|
|
63
|
+
size = statedSize(read, entry.skin, entry.slot, entry.placeholder);
|
|
64
|
+
} else if (g?.kind === 'linkedmesh') {
|
|
65
|
+
const source = sourceVertices(g.skin, g.slot, g.source);
|
|
66
|
+
const drawn = walk.meshOf(g.skin, g.slot, g.source);
|
|
67
|
+
if (typeof source === 'string' || drawn === undefined) throw new Error(`internal: skin "${entry.skin}" slot "${entry.slot}" placeholder "${entry.placeholder}": ${typeof source === 'string' ? source : 'its source draws no mesh'}, and the reader accepted it`);
|
|
68
|
+
vertices = source;
|
|
69
|
+
({ uvs, triangles } = drawn);
|
|
70
|
+
size = statedSize(read, g.skin, g.slot, g.source);
|
|
71
|
+
} else {
|
|
72
|
+
// `readModel` reads every mesh and link record's geometry or refuses the document, so a record without one is this module's defect.
|
|
73
|
+
throw new Error(`internal: skin "${entry.skin}" slot "${entry.slot}" placeholder "${entry.placeholder}" is a ${entry.record.kind} record the reader returned without its geometry`);
|
|
74
|
+
}
|
|
75
|
+
const bone = slotBone.get(entry.slot);
|
|
76
|
+
if (bone === undefined) throw new Error(`internal: skin "${entry.skin}" names slot "${entry.slot}", which the reader accepted and the document does not hold`);
|
|
77
|
+
meshes.push({
|
|
78
|
+
name: shownRow(entry).name,
|
|
79
|
+
slot: entry.slot,
|
|
80
|
+
slotBone: bone,
|
|
81
|
+
triangles,
|
|
82
|
+
width: size.width,
|
|
83
|
+
height: size.height,
|
|
84
|
+
regionUVs: uvs,
|
|
85
|
+
worldVerticesLength: vertices.weighted ? 2 * vertices.bindings.length : vertices.xy.length,
|
|
86
|
+
weightBones: vertices.weighted ? vertices.bindings.flatMap((vertex) => vertex.map((binding) => binding.bone)) : [],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { meshes };
|
|
90
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model side's supply of `StageFacts` (issue #1025, step 4c of #380): the
|
|
3
|
+
* stage a `rigc-compiled/3` document states (`stated.stage`, issue #1026), or,
|
|
4
|
+
* for a `/2` or `/1` document, which does not, the stage its caller gives.
|
|
5
|
+
* A `/3` document given one anyway is refused (`refuseGivenBeside`).
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ A caller that gives no stage at all is refused by name rather than read as
|
|
8
|
+
* "the skeleton declares none": those are two different statements, and only
|
|
9
|
+
* the second is one the caller made. A stage stated as `null` IS that second
|
|
10
|
+
* statement, and reads as both extents absent, the way the runtime loads a
|
|
11
|
+
* header with neither key.
|
|
12
|
+
*
|
|
13
|
+
* Links nothing from the runtime.
|
|
14
|
+
*/
|
|
15
|
+
import type { StageFacts } from '../facts/stage.ts';
|
|
16
|
+
import { refuseGivenBeside, type ModelGiven } from './given.ts';
|
|
17
|
+
import type { ReadDocument } from './parse.ts';
|
|
18
|
+
|
|
19
|
+
export function modelStage(read: ReadDocument, given: ModelGiven | undefined): StageFacts {
|
|
20
|
+
refuseGivenBeside(read, given);
|
|
21
|
+
// The document's own statement (issue #1026): `null` is a skeleton that declares none, read as both extents absent.
|
|
22
|
+
if (read.doc.stated !== null) {
|
|
23
|
+
const stage = read.doc.stated.stage;
|
|
24
|
+
return { width: stage?.width, height: stage?.height };
|
|
25
|
+
}
|
|
26
|
+
if (given === undefined) throw new Error(`the caller gave no stage; a ${read.doc.spec} document does not state one, so the model side cannot read it`);
|
|
27
|
+
return { width: given.stage?.width, height: given.stage?.height };
|
|
28
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model side's supply of `PolygonFacts` (issue #1025, step 4c of #380):
|
|
3
|
+
* the document's bounding boxes, clipping attachments and paths, and the
|
|
4
|
+
* clip ends it states.
|
|
5
|
+
*
|
|
6
|
+
* - **The polygons** in the loaded walk's order, `fileOrderedEntries`
|
|
7
|
+
* (`./skin_entries.ts`). A polygon's `worldVerticesLength` is twice the
|
|
8
|
+
* `vertexCount` the record states — the number the emitter copies into the
|
|
9
|
+
* file, which the parser doubles into the length it reads the vertices to
|
|
10
|
+
* (`readVertices`); the selftest compares it with spine-core's on every
|
|
11
|
+
* call. A path's `closed` and `lengths` are the core's reading of the record
|
|
12
|
+
* (`readGeometry`: `closed` absent reads the parser's `false`).
|
|
13
|
+
* - **The clip ends** in the order the file spells them: the skins by the
|
|
14
|
+
* emitter's `editorSkinOrder`, each skin's slot keys by its
|
|
15
|
+
* `editorSlotKeyOrder` (both `src/compile.ts`, the functions `emitSkins` is
|
|
16
|
+
* handed), each slot's records in table order — every clipping record that
|
|
17
|
+
* states an `end`, with the `end` as it states it.
|
|
18
|
+
*
|
|
19
|
+
* `encoding` is empty on every polygon: the document states the weighted
|
|
20
|
+
* form outright, so a run's decode has no subject here.
|
|
21
|
+
*
|
|
22
|
+
* Links nothing from the runtime.
|
|
23
|
+
*/
|
|
24
|
+
import { editorSkinOrder, editorSlotKeyOrder } from '../../compile.ts';
|
|
25
|
+
import { shownRow } from '../../core/index.ts';
|
|
26
|
+
import type { ClipEnd, PolygonEntry, PolygonFacts } from '../facts/vertex_polygons.ts';
|
|
27
|
+
import { isObj, type Json } from '../values.ts';
|
|
28
|
+
import { fileOrderedEntries } from './skin_entries.ts';
|
|
29
|
+
import type { ReadDocument } from './parse.ts';
|
|
30
|
+
|
|
31
|
+
/** The document's own record of one skin entry, as the JSON spells it. */
|
|
32
|
+
export function documentRecord(read: ReadDocument, skin: string, slot: string, placeholder: string): Json {
|
|
33
|
+
const skins = Array.isArray(read.json.skins) ? read.json.skins.filter(isObj) : [];
|
|
34
|
+
const table = skins.find((s) => s.name === skin)?.attachments;
|
|
35
|
+
const record = isObj(table) && isObj(table[slot]) ? (table[slot] as Json)[placeholder] : undefined;
|
|
36
|
+
if (!isObj(record)) throw new Error(`internal: skin "${skin}" slot "${slot}" placeholder "${placeholder}" is a record the reader returned and the document does not spell`);
|
|
37
|
+
return record;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Every record of the document in the order the Spine file spells it: skins, then each skin's slot keys, then the slot's table. */
|
|
41
|
+
export function fileSpelledEntries(read: ReadDocument): Array<{ skin: string; slot: string; placeholder: string; record: Json }> {
|
|
42
|
+
const out: Array<{ skin: string; slot: string; placeholder: string; record: Json }> = [];
|
|
43
|
+
for (const skin of editorSkinOrder(read.doc.skins)) {
|
|
44
|
+
for (const [slot, table] of Object.entries(editorSlotKeyOrder(skin.attachments))) {
|
|
45
|
+
for (const placeholder of Object.keys(table)) out.push({ skin: skin.name, slot, placeholder, record: documentRecord(read, skin.name, slot, placeholder) });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const WHAT: Readonly<Record<string, string>> = { boundingbox: 'bounding box', clipping: 'clipping attachment', path: 'path' };
|
|
52
|
+
|
|
53
|
+
export function modelPolygonFacts(read: ReadDocument): PolygonFacts {
|
|
54
|
+
const polygons: PolygonEntry[] = [];
|
|
55
|
+
for (const entry of fileOrderedEntries(read)) {
|
|
56
|
+
const g = entry.record.geometry;
|
|
57
|
+
if (g === undefined || (g.kind !== 'boundingbox' && g.kind !== 'clipping' && g.kind !== 'path')) continue;
|
|
58
|
+
const stated = documentRecord(read, entry.skin, entry.slot, entry.placeholder).vertexCount;
|
|
59
|
+
polygons.push({
|
|
60
|
+
what: `${WHAT[g.kind]} "${shownRow(entry).name}"`,
|
|
61
|
+
worldVerticesLength: typeof stated === 'number' ? stated * 2 : Number.NaN,
|
|
62
|
+
path: g.kind === 'path' ? { closed: g.closed, lengths: g.lengths } : null,
|
|
63
|
+
encoding: [],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const clipEnds: ClipEnd[] = [];
|
|
67
|
+
for (const { slot, placeholder, record } of fileSpelledEntries(read)) {
|
|
68
|
+
if (record.kind === 'clipping' && record.end !== undefined) clipEnds.push({ placeholder, slot, end: record.end });
|
|
69
|
+
}
|
|
70
|
+
return { polygons, clipEnds, slots: read.doc.slots.map((s) => s.name) };
|
|
71
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The region names one skin entry will make a loader look up (issue #1025,
|
|
3
|
+
* step 4c of #380) — moved here from `src/validate.ts` unchanged, because A08's
|
|
4
|
+
* body now runs on both sides and the model side links nothing from the
|
|
5
|
+
* runtime. `src/validate.ts` re-exports both names, so nothing that imported
|
|
6
|
+
* them from there moves.
|
|
7
|
+
*/
|
|
8
|
+
import { frameRegionName } from '../core/uvs.ts';
|
|
9
|
+
import { isObj } from './values.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The atlas region names one raw skin entry will make the loader look up — or
|
|
13
|
+
* `null` when the file states a sequence this walk cannot predict.
|
|
14
|
+
*
|
|
15
|
+
* ⚠️ Measured against the loader rather than reasoned out, because a join that
|
|
16
|
+
* merely looks right is the thing A08 exists to refuse. `readSequence`
|
|
17
|
+
* (`dist/SkeletonJson.js:641-649`) turns an absent or null `sequence` into
|
|
18
|
+
* `new Sequence(1, false)` — one lookup, at the bare path — and a present one
|
|
19
|
+
* into `new Sequence(count ?? 0, true)`, so a sequence map with no `count`
|
|
20
|
+
* looks up nothing at all. Each frame's name is the core's `frameRegionName`
|
|
21
|
+
* (`src/core/uvs.ts`): `start + i`, left-padded with zeros to `digits`, after
|
|
22
|
+
* the path (issue #1015). `PS127` records what the loader asks for and compares,
|
|
23
|
+
* and the core suite holds the frame names to `Sequence.getPath` over 7,680
|
|
24
|
+
* cases.
|
|
25
|
+
*
|
|
26
|
+
* Nothing in `examples/` carries a `sequence` (measured: 0 occurrences across
|
|
27
|
+
* all twelve editor exports), so without this the assertion would have read a
|
|
28
|
+
* sequence's base path as a region name and refused correct foreign data —
|
|
29
|
+
* `A21_MESH_RIM_PINNED`'s old `|| 'ring'` default, one file over.
|
|
30
|
+
*/
|
|
31
|
+
export function attachmentRegionLookups(sequence: unknown, path: string): string[] | null {
|
|
32
|
+
if (sequence === undefined || sequence === null) return [path];
|
|
33
|
+
if (!isObj(sequence)) return null;
|
|
34
|
+
const whole = (value: unknown, fallback: number): number | null => {
|
|
35
|
+
if (value === undefined) return fallback;
|
|
36
|
+
return typeof value === 'number' && Number.isInteger(value) ? value : null;
|
|
37
|
+
};
|
|
38
|
+
const count = whole(sequence.count, 0);
|
|
39
|
+
const start = whole(sequence.start, 1);
|
|
40
|
+
const digits = whole(sequence.digits, 0);
|
|
41
|
+
if (count === null || start === null || digits === null || count < 0) return null;
|
|
42
|
+
const series = { count, start, digits, setup: 0 };
|
|
43
|
+
const lookups: string[] = [];
|
|
44
|
+
for (let i = 0; i < count; i++) lookups.push(frameRegionName(path, series, i));
|
|
45
|
+
return lookups;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** One skin entry's join onto the atlas, as the loader will perform it. */
|
|
49
|
+
export interface AttachmentRegionJoin {
|
|
50
|
+
skin: string;
|
|
51
|
+
slot: string;
|
|
52
|
+
placeholder: string;
|
|
53
|
+
/** The attachment's own name — the entry's `name` when it states one, else the placeholder. */
|
|
54
|
+
name: string;
|
|
55
|
+
/**
|
|
56
|
+
* Every atlas region name the loader will ask this atlas for, in the order it
|
|
57
|
+
* asks. Empty for a `sequence` with no `count`, and `null` for a sequence map
|
|
58
|
+
* this walk will not guess at.
|
|
59
|
+
*/
|
|
60
|
+
lookups: string[] | null;
|
|
61
|
+
}
|
package/src/check.ts
CHANGED
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
66
66
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
67
67
|
import {
|
|
68
|
-
atlasScales,
|
|
69
68
|
BACKGROUND,
|
|
70
69
|
frameGeometry,
|
|
71
70
|
PROTOCOL_FPS,
|
|
@@ -1615,11 +1614,14 @@ export function checkAgainstFrames(options: CheckOptions): CheckReport {
|
|
|
1615
1614
|
);
|
|
1616
1615
|
}
|
|
1617
1616
|
|
|
1618
|
-
//
|
|
1619
|
-
//
|
|
1620
|
-
//
|
|
1621
|
-
//
|
|
1622
|
-
|
|
1617
|
+
// The candidate's `scale:` lines as its facts read them: off its atlas, or —
|
|
1618
|
+
// a build posed from a `rigc-compiled/3` document — off the pages the
|
|
1619
|
+
// document states (issue #1026), so a build drawn with its atlas gone reports
|
|
1620
|
+
// them as it does with the atlas there. `null` when neither was read (issue
|
|
1621
|
+
// #1020): a `/2` or `/1` document states where each region sits and not the
|
|
1622
|
+
// `scale:` line, so with its atlas gone the report says the line was not read
|
|
1623
|
+
// rather than that none was declared.
|
|
1624
|
+
const candidateScales = facts.atlasScales === null ? null : [...facts.atlasScales];
|
|
1623
1625
|
if (substitution === null) {
|
|
1624
1626
|
// ⭐ Named at the top of every report rather than only when it is measured.
|
|
1625
1627
|
// Issue #171's finding was not that the floor was mis-measured; it was that
|