@flighthq/skeleton2d-formats 0.3.0-next.1032.e2b99fc → 0.3.0-next.1162.e90e518

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.
@@ -1,4 +1,5 @@
1
1
  export * from './dragonBonesParse';
2
2
  export * from './skeletonDetect';
3
+ export * from './spineBinaryParse';
3
4
  export * from './spineParse';
4
5
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
package/dist/contract.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './dragonBonesParse';
2
2
  export * from './skeletonDetect';
3
+ export * from './spineBinaryParse';
3
4
  export * from './spineParse';
4
5
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"dragonBonesParse.d.ts","sourceRoot":"","sources":["../src/dragonBonesParse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AA6BlC,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,GAAG,IAAI,CA6BhH"}
1
+ {"version":3,"file":"dragonBonesParse.d.ts","sourceRoot":"","sources":["../src/dragonBonesParse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAMV,gBAAgB,EAGhB,gBAAgB,EAKjB,MAAM,0BAA0B,CAAC;AAiClC,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAkChH"}
@@ -1,6 +1,7 @@
1
+ import { createAnimationChannel, createAnimationClip, createAnimationTrack } from '@flighthq/animation/contract';
1
2
  import { reportImportDiagnostic } from '@flighthq/importdiagnostics/contract';
2
3
  import { createSkeleton2D } from '@flighthq/skeleton2d/contract';
3
- import { ImportDiagnosticSeverity, MeshAttachment2DKind, RegionAttachment2DKind, TransformMode2D, } from '@flighthq/types/contract';
4
+ import { AnimationInterpolationLinear, AnimationInterpolationStep, ImportDiagnosticSeverity, MeshAttachment2DKind, RegionAttachment2DKind, Skeleton2DAnimationPath, } from '@flighthq/types/contract';
4
5
  // Parses a DragonBones `.json` skeleton document (text) into a Skeleton2DImport. Tolerant and best-effort,
5
6
  // mirroring parseSpineSkeleton: a malformed / non-DragonBones document returns the sentinel `null`, and a
6
7
  // recognized document with unmodeled pieces yields best-effort data plus `ImportDiagnostic` Skip crumbs.
@@ -10,14 +11,16 @@ import { ImportDiagnosticSeverity, MeshAttachment2DKind, RegionAttachment2DKind,
10
11
  // Spine in ways the charter (open-direction 4) records: an `armature` container (multiple armatures
11
12
  // possible), a nested `transform` block with `skX`/`skY` (or newer `rotate`/`skew`) skew angles rather than
12
13
  // Spine's flat fields, bones NOT guaranteed parent-before-child (so they are topologically sorted here), a
13
- // four-boolean inheritance model (inheritRotation/Scale/Reflection/Translation) mapped onto Flight's
14
- // five-value TransformMode2D (two inexpressible combinations Skip-crumbed), and slots whose shown attachment
14
+ // four-boolean inheritance model (inheritRotation/Scale/Reflection/Translation) mapped straight onto Flight's
15
+ // vendor-neutral TransformInherit2D (every combination expressible — no gap), and slots whose shown attachment
15
16
  // is a `displayIndex` into a per-slot display list (so that list is position-preserving — see
16
17
  // parseDragonBonesDefaultSkin). Image displays become region attachments; unweighted AND weighted mesh
17
18
  // displays become mesh attachments (weighted via bonePose/slotPose → Skin2D offsets with the topo-sort
18
- // bone-index remap — see parseDragonBonesWeightedMesh); armature/bounding-box/path displays, shared and
19
- // legacy-weighted meshes, additional armatures, alternate skins, and animation are recognized-but-unmodeled
20
- // and Skip-crumbed (frame timelines are next).
19
+ // bone-index remap — see parseDragonBonesWeightedMesh). Each `animation` becomes an @flighthq/animation
20
+ // clip of RELATIVE bone deltas built from the frame-based translate/rotate/scale timelines (see
21
+ // parseDragonBonesAnimations). Armature/bounding-box/path displays, shared and legacy-weighted meshes,
22
+ // additional armatures, alternate skins, IK constraints, and the non-bone timelines are recognized-but-
23
+ // unmodeled and Skip-crumbed.
21
24
  export function parseDragonBonesSkeleton(json, diagnostics) {
22
25
  let doc;
23
26
  try {
@@ -38,13 +41,19 @@ export function parseDragonBonesSkeleton(json, diagnostics) {
38
41
  if (first === null || typeof first !== 'object')
39
42
  return null;
40
43
  const armature = first;
41
- const bones = parseDragonBonesBones(armature.bone, diagnostics);
44
+ const { bones, rawIndexToOutput } = parseDragonBonesBones(armature.bone, diagnostics);
42
45
  const boneIndexByName = buildBoneIndexByName(bones);
43
- const remapBoneIndex = buildDragonBonesBoneRemap(armature.bone, boneIndexByName);
44
- const skin = parseDragonBonesDefaultSkin(armature.skin, remapBoneIndex, diagnostics);
45
- const slots = parseDragonBonesSlots(armature.slot, boneIndexByName, skin, diagnostics);
46
- skipCrumbDragonBonesGroup(diagnostics, armature.animation, 'dragonbones.animation-unsupported');
47
- return { animations: [], skeleton: createSkeleton2D(bones, slots) };
46
+ const remapBoneIndex = buildDragonBonesBoneRemap(rawIndexToOutput);
47
+ const slotOrder = buildDragonBonesSlotOrder(armature.slot);
48
+ const { skins, table } = parseDragonBonesSkins(armature.skin, slotOrder, remapBoneIndex, diagnostics);
49
+ const slots = parseDragonBonesSlots(armature.slot, boneIndexByName, table, diagnostics);
50
+ const frameRate = dragonBonesFrameRate(armature, doc);
51
+ const animations = parseDragonBonesAnimations(armature.animation, boneIndexByName, frameRate, diagnostics);
52
+ skipCrumbDragonBonesGroup(diagnostics, armature.ik, 'dragonbones.ik-constraint-unsupported');
53
+ const skeleton = createSkeleton2D(bones, slots);
54
+ if (skins.length > 0)
55
+ skeleton.skins = skins;
56
+ return { animations, skeleton };
48
57
  }
49
58
  // Rebuilds the bone-name → output-index lookup from the (already topologically sorted) bone array, so slot
50
59
  // `parent` references and future weighted-mesh bone indices resolve to the FINAL emitted position rather
@@ -60,20 +69,236 @@ function buildBoneIndexByName(bones) {
60
69
  }
61
70
  // Maps a DragonBones armature-FILE-ORDER bone index (the space weighted-mesh `weights`/`bonePose` reference
62
71
  // bones in) to the FINAL topo-sorted OUTPUT bone index — the read-integrity axis-12 remap the topo-sort
63
- // makes necessary, resolved through the bone's name so it is drop-safe. Returns -1 for an out-of-range or
64
- // unnamed/unresolvable raw index.
65
- function buildDragonBonesBoneRemap(rawBones, boneIndexByName) {
66
- const names = [];
67
- if (Array.isArray(rawBones)) {
68
- for (const entry of rawBones) {
69
- const name = entry !== null && typeof entry === 'object' ? entry.name : undefined;
70
- names.push(typeof name === 'string' ? name : null);
72
+ // makes necessary. Backed by the identity-preserving `rawIndexToOutput` table built during emit (NOT
73
+ // reconstructed by name, which would collide duplicate names). Returns -1 for an out-of-range or dropped
74
+ // raw index; callers must treat -1 as an unresolved influence and drop it, never emit it as a bone index.
75
+ function buildDragonBonesBoneRemap(rawIndexToOutput) {
76
+ return (rawBoneIndex) => rawBoneIndex >= 0 && rawBoneIndex < rawIndexToOutput.length ? rawIndexToOutput[rawBoneIndex] : -1;
77
+ }
78
+ // Builds one AnimationClip per DragonBones `animation` from its per-bone frame timelines. DragonBones bone
79
+ // timelines are RELATIVE to the setup pose exactly as Spine's are — `translateFrame` x/y are offsets (default
80
+ // 0), `rotateFrame` rotate/skew are angle offsets in degrees (default 0), `scaleFrame` x/y are multipliers
81
+ // (default 1) — so clips are emitted as those raw deltas and `applyAnimationClipToSkeleton2D` composes them
82
+ // onto the setup pose per frame (add / multiply, keyed by `path`). Keeping deltas relative is what lets a
83
+ // mixer blend clips as `setup + Σ wᵢ·deltaᵢ`.
84
+ //
85
+ // The one structural difference from Spine is the TIME AXIS: Spine keys carry absolute `time` in seconds,
86
+ // while DragonBones keys carry a `duration` in FRAMES and the armature carries the `frameRate` — so times are
87
+ // the running duration sum ÷ frameRate (see dragonBonesFrameTimes). The clip's own duration comes from the
88
+ // animation's declared `duration` (also in frames), which may outlast the last keyframe when the animation
89
+ // holds. Slot, FFD (deform), IK, and z-order timelines, and the legacy combined `frame` bone timeline, are
90
+ // recognized-but-unmodeled and Skip-crumbed. A timeline naming a bone this armature does not have is dropped
91
+ // best-effort and Recover-crumbed once for the whole document.
92
+ function parseDragonBonesAnimations(raw, boneIndexByName, frameRate, diagnostics) {
93
+ const animations = [];
94
+ if (!Array.isArray(raw))
95
+ return animations;
96
+ let unresolvedBones = 0;
97
+ for (const entry of raw) {
98
+ if (entry === null || typeof entry !== 'object')
99
+ continue;
100
+ const animation = entry;
101
+ const channels = [];
102
+ if (Array.isArray(animation.bone)) {
103
+ for (const rawTimeline of animation.bone) {
104
+ if (rawTimeline === null || typeof rawTimeline !== 'object')
105
+ continue;
106
+ const timeline = rawTimeline;
107
+ const boneIndex = typeof timeline.name === 'string' ? (boneIndexByName.get(timeline.name) ?? -1) : -1;
108
+ if (boneIndex < 0) {
109
+ unresolvedBones++;
110
+ continue;
111
+ }
112
+ parseDragonBonesBoneTimeline(channels, timeline, boneIndex, frameRate, diagnostics);
113
+ }
71
114
  }
115
+ skipCrumbDragonBonesGroup(diagnostics, animation.slot, 'dragonbones.slot-timeline-unsupported');
116
+ skipCrumbDragonBonesGroup(diagnostics, animation.ffd, 'dragonbones.deform-timeline-unsupported');
117
+ skipCrumbDragonBonesGroup(diagnostics, animation.ik, 'dragonbones.ik-timeline-unsupported');
118
+ skipCrumbDragonBonesGroup(diagnostics, animation.zOrder, 'dragonbones.zorder-timeline-unsupported');
119
+ const duration = numberOr(animation.duration, 0) / frameRate;
120
+ animations.push({
121
+ clip: createAnimationClip(channels, Number.isFinite(duration) && duration > 0 ? duration : undefined),
122
+ name: typeof animation.name === 'string' ? animation.name : DEFAULT_DRAGONBONES_ANIMATION_NAME,
123
+ });
72
124
  }
73
- return (rawBoneIndex) => {
74
- const name = rawBoneIndex >= 0 && rawBoneIndex < names.length ? names[rawBoneIndex] : null;
75
- return name !== null ? (boneIndexByName.get(name) ?? -1) : -1;
76
- };
125
+ if (unresolvedBones > 0) {
126
+ reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Recover, 'dragonbones.animation-bone-unresolved', 'parseDragonBonesSkeleton', { bones: unresolvedBones });
127
+ }
128
+ return animations;
129
+ }
130
+ // Adds one DragonBones bone timeline's channels to `channels`. The three frame lists are independent — each
131
+ // carries its own durations, so each gets its own time axis — which is why they are built separately rather
132
+ // than zipped onto one shared key list.
133
+ function parseDragonBonesBoneTimeline(channels, timeline, boneIndex, frameRate, diagnostics) {
134
+ addDragonBonesVectorChannel(channels, timeline.translateFrame, boneIndex, Skeleton2DAnimationPath.Translation, frameRate, diagnostics);
135
+ addDragonBonesRotateChannels(channels, timeline.rotateFrame, boneIndex, frameRate, diagnostics);
136
+ addDragonBonesVectorChannel(channels, timeline.scaleFrame, boneIndex, Skeleton2DAnimationPath.Scale, frameRate, diagnostics);
137
+ skipCrumbDragonBonesGroup(diagnostics, timeline.frame, 'dragonbones.legacy-bone-frame-unsupported');
138
+ }
139
+ // Adds a two-component bone channel (`translateFrame` → Translation, `scaleFrame` → Scale) whose per-frame
140
+ // values are DragonBones' `x`/`y`. The omitted-value default is the path's IDENTITY delta — 0 for a
141
+ // translation offset, 1 for a scale multiplier — so an absent field composes to "unchanged from setup".
142
+ function addDragonBonesVectorChannel(channels, raw, boneIndex, path, frameRate, diagnostics) {
143
+ const frames = dragonBonesFrames(raw, diagnostics);
144
+ if (frames.length === 0)
145
+ return;
146
+ const fallback = path === Skeleton2DAnimationPath.Scale ? 1 : 0;
147
+ const values = [];
148
+ for (const frame of frames)
149
+ values.push(numberOr(frame.x, fallback), numberOr(frame.y, fallback));
150
+ addDragonBonesBoneChannel(channels, dragonBonesFrameTimes(frames, frameRate), values, 2, dragonBonesInterpolation(frames, diagnostics), boneIndex, path);
151
+ }
152
+ // Adds the channels a DragonBones `rotateFrame` list drives. One frame list feeds TWO Flight paths, because
153
+ // DragonBones packs both angles of its Transform into it: `rotate` → Rotation, and `skew` → Shear as
154
+ // (shearX 0, shearY skew), the same split the setup-pose transform uses (parseDragonBonesBoneTransform).
155
+ // The Shear channel is emitted only when some frame actually skews, so the common no-skew rig does not pay
156
+ // for a channel of zeroes on every bone.
157
+ //
158
+ // `rotate` is UNWRAPPED across the sequence, replicating ObjectDataParser._parseBoneRotateFrame: each frame
159
+ // after the first is re-expressed as the previous frame's angle plus the shortest signed step to the authored
160
+ // angle, and a nonzero `clockwise` on the previous frame adds that many whole turns (consuming one turn per
161
+ // frame that already passes the previous angle). This is a correctness requirement, not a fidelity nicety —
162
+ // authored angles are wrapped, so 170° followed by −170° must tween the authored 20° step rather than the
163
+ // 340° long way round through zero. Angles stay in degrees throughout (Flight's authoring layer), so
164
+ // DragonBones' 2π turn is 360.
165
+ function addDragonBonesRotateChannels(channels, raw, boneIndex, frameRate, diagnostics) {
166
+ const frames = dragonBonesFrames(raw, diagnostics);
167
+ if (frames.length === 0)
168
+ return;
169
+ const times = dragonBonesFrameTimes(frames, frameRate);
170
+ const interpolation = dragonBonesInterpolation(frames, diagnostics);
171
+ const rotations = [];
172
+ const shears = [];
173
+ let skewed = false;
174
+ let previousRotation = 0;
175
+ let previousClockwise = 0;
176
+ for (let i = 0; i < frames.length; i++) {
177
+ const frame = frames[i];
178
+ let rotation = numberOr(frame.rotate, 0);
179
+ // `times[i] !== 0` is DragonBones' own `frameStart !== 0` guard: the frame at the sequence origin is
180
+ // taken as authored and anchors the unwrap; every later frame is unwrapped against the one before it.
181
+ if (times[i] !== 0) {
182
+ if (previousClockwise === 0) {
183
+ rotation = previousRotation + normalizeDegrees(rotation - previousRotation);
184
+ }
185
+ else {
186
+ if (previousClockwise > 0 ? rotation >= previousRotation : rotation <= previousRotation) {
187
+ previousClockwise = previousClockwise > 0 ? previousClockwise - 1 : previousClockwise + 1;
188
+ }
189
+ rotation += 360 * previousClockwise;
190
+ }
191
+ }
192
+ previousClockwise = numberOr(frame.clockwise, 0) | 0;
193
+ previousRotation = rotation;
194
+ const skew = numberOr(frame.skew, 0);
195
+ if (skew !== 0)
196
+ skewed = true;
197
+ rotations.push(rotation);
198
+ shears.push(0, skew);
199
+ }
200
+ addDragonBonesBoneChannel(channels, times, rotations, 1, interpolation, boneIndex, Skeleton2DAnimationPath.Rotation);
201
+ if (skewed) {
202
+ addDragonBonesBoneChannel(channels, times, shears, 2, interpolation, boneIndex, Skeleton2DAnimationPath.Shear);
203
+ }
204
+ }
205
+ // The shared tail of every bone-channel builder: wraps the extracted keys in an AnimationTrack bound to
206
+ // (`boneIndex`, `path`). `times` is COPIED because one frame list can feed two channels (rotate → Rotation +
207
+ // Shear) and an AnimationTrack owns its buffers — sharing one array would silently alias the two tracks.
208
+ function addDragonBonesBoneChannel(channels, times, values, components, interpolation, boneIndex, path) {
209
+ const track = createAnimationTrack({ components, interpolation, times: times.slice(), values });
210
+ channels.push(createAnimationChannel(track, { boneIndex, path }));
211
+ }
212
+ // The keyframe time axis of one frame list. DragonBones authors each frame's `duration` in FRAMES (default 1
213
+ // — its parser's own fallback), so a key's time is the running sum of the durations BEFORE it divided by the
214
+ // armature's frame rate. A negative duration is clamped to 0, keeping the times ascending as AnimationTrack
215
+ // requires; a zero duration leaves two keys at one instant, which sampling already handles (the later key
216
+ // wins) so it needs no collapsing.
217
+ function dragonBonesFrameTimes(frames, frameRate) {
218
+ const times = [];
219
+ let elapsedFrames = 0;
220
+ for (const frame of frames) {
221
+ times.push(elapsedFrames / frameRate);
222
+ elapsedFrames += Math.max(0, numberOr(frame.duration, 1));
223
+ }
224
+ return times;
225
+ }
226
+ // Normalizes a raw frame list so the TIME AXIS survives malformed input: a non-object entry becomes an empty
227
+ // frame (all-default values, the default one-frame duration) rather than being dropped, because dropping it
228
+ // would swallow its duration and pull every later keyframe earlier — the same read-integrity discipline the
229
+ // display list and the bone array use.
230
+ function dragonBonesFrames(raw, diagnostics) {
231
+ if (!Array.isArray(raw))
232
+ return [];
233
+ const frames = [];
234
+ let recovered = 0;
235
+ for (const entry of raw) {
236
+ if (entry !== null && typeof entry === 'object') {
237
+ frames.push(entry);
238
+ }
239
+ else {
240
+ frames.push(EMPTY_DRAGONBONES_FRAME);
241
+ recovered++;
242
+ }
243
+ }
244
+ if (recovered > 0) {
245
+ reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Recover, 'dragonbones.malformed-frame-recovered', 'parseDragonBonesSkeleton', { frames: recovered });
246
+ }
247
+ return frames;
248
+ }
249
+ // One AnimationTrack carries a single interpolation, so a DragonBones frame list is Step only when EVERY
250
+ // tweening segment is a no-tween frame, and Linear otherwise. Only frames before the last one open a segment
251
+ // — DragonBones gives the final frame TweenType.None itself — so a trailing frame's easing never decides the
252
+ // track. Quadratic (`tweenEasing` ≠ 0) and bezier (`curve`) easings are recognized-but-unmodeled: they
253
+ // collapse to Linear and Skip-crumb once per frame list.
254
+ function dragonBonesInterpolation(frames, diagnostics) {
255
+ let stepped = true;
256
+ let approximated = 0;
257
+ for (let i = 0; i + 1 < frames.length; i++) {
258
+ const frame = frames[i];
259
+ if (!isDragonBonesFrameStepped(frame))
260
+ stepped = false;
261
+ if ('curve' in frame)
262
+ approximated++;
263
+ else {
264
+ const easing = frame.tweenEasing;
265
+ if (typeof easing === 'number' && easing !== 0 && easing !== DRAGONBONES_NO_TWEEN)
266
+ approximated++;
267
+ }
268
+ }
269
+ if (approximated > 0) {
270
+ reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Skip, 'dragonbones.tween-easing-unsupported', 'parseDragonBonesSkeleton', { frames: approximated });
271
+ }
272
+ return stepped ? AnimationInterpolationStep : AnimationInterpolationLinear;
273
+ }
274
+ // Whether a frame holds its value to the next key instead of tweening. DragonBones spells "no tween" as
275
+ // `tweenEasing: null` (what its exporter writes) or the sentinel 100; an ABSENT `tweenEasing` means linear,
276
+ // not stepped. A `curve` is tested first because a bezier always tweens, matching its parser's branch order.
277
+ function isDragonBonesFrameStepped(frame) {
278
+ if ('curve' in frame)
279
+ return false;
280
+ if (!('tweenEasing' in frame))
281
+ return false;
282
+ const easing = frame.tweenEasing;
283
+ return easing === null || easing === DRAGONBONES_NO_TWEEN;
284
+ }
285
+ // The frame rate the armature's frame-based timelines convert through: the armature's own `frameRate`, else
286
+ // the document's, else DragonBones' 24 default. A missing, zero, or non-finite rate would divide every
287
+ // keyframe time into Infinity or NaN, so it falls back rather than propagating a poisoned time axis.
288
+ function dragonBonesFrameRate(armature, doc) {
289
+ const armatureRate = numberOr(armature.frameRate, 0);
290
+ if (Number.isFinite(armatureRate) && armatureRate > 0)
291
+ return armatureRate;
292
+ const documentRate = numberOr(doc.frameRate, 0);
293
+ if (Number.isFinite(documentRate) && documentRate > 0)
294
+ return documentRate;
295
+ return DEFAULT_DRAGONBONES_FRAME_RATE;
296
+ }
297
+ // The shortest signed representation of an angle delta, in (−180, 180] — DragonBones' Transform
298
+ // .normalizeRadian expressed in the authoring layer's degrees.
299
+ function normalizeDegrees(degrees) {
300
+ const wrapped = (degrees + 180) % 360;
301
+ return wrapped + (wrapped > 0 ? -180 : 180);
77
302
  }
78
303
  // Maps a DragonBones slot ColorTransform to a packed RGBA int (Slot2D.color). DragonBones color is the
79
304
  // multiply channels aM/rM/gM/bM (0–100 percent) plus additive offsets aO/rO/gO/bO. Only the multiply tint
@@ -95,40 +320,49 @@ function parseDragonBonesColor(raw, diagnostics) {
95
320
  }
96
321
  return ((r << 24) | (g << 16) | (b << 8) | a) >>> 0;
97
322
  }
98
- // The default skin's per-slot display table: slotName → the ordered list of that slot's displays
99
- // (attachments), addressed by `displayIndex`. DragonBones names its default skin "default" (or leaves it
100
- // empty); alternate named skins are the skin-set feature and are Skip-crumbed. The display list is
101
- // POSITIONALLY REFERENCED by displayIndex, so an unmodeled/malformed display holds its slot as `null` (never
102
- // dropped) — mirroring the DragonBones runtime's own addDisplay(slot, null) — so indices stay aligned.
103
- function parseDragonBonesDefaultSkin(raw, remapBoneIndex, diagnostics) {
323
+ // The armature's skins. DragonBones names its base skin "default" (or leaves it empty) and any others are
324
+ // alternates; all of them become the rig's wardrobe. Returns BOTH the wardrobe and the default skin's
325
+ // per-slot display table, because the two are addressed differently: the wardrobe keys attachments by NAME
326
+ // (what `setSkeleton2DSkin` writes), while a slot's setup attachment is a `displayIndex` POSITION into its
327
+ // display list. The display list is therefore position-preserving — an unmodeled or malformed display holds
328
+ // its slot as `null` rather than being dropped, mirroring the DragonBones runtime's own addDisplay(slot,
329
+ // null) — so indices stay aligned even though the wardrobe skips those entries.
330
+ function parseDragonBonesSkins(raw, slotOrder, remapBoneIndex, diagnostics) {
104
331
  const table = new Map();
332
+ const skins = [];
105
333
  if (!Array.isArray(raw))
106
- return table;
107
- let alternateSkins = 0;
334
+ return { skins, table };
108
335
  for (const rawSkin of raw) {
109
336
  if (rawSkin === null || typeof rawSkin !== 'object')
110
337
  continue;
111
338
  const skin = rawSkin;
112
- const skinName = typeof skin.name === 'string' && skin.name.length > 0 ? skin.name : 'default';
113
- if (skinName !== 'default') {
114
- alternateSkins++;
115
- continue;
116
- }
339
+ const skinName = typeof skin.name === 'string' && skin.name.length > 0 ? skin.name : DEFAULT_DRAGONBONES_SKIN_NAME;
117
340
  if (!Array.isArray(skin.slot))
118
341
  continue;
342
+ const attachments = [];
119
343
  for (const rawSlot of skin.slot) {
120
344
  if (rawSlot === null || typeof rawSlot !== 'object')
121
345
  continue;
122
346
  const slot = rawSlot;
123
- if (typeof slot.name === 'string') {
124
- table.set(slot.name, parseDragonBonesDisplayList(slot.display, remapBoneIndex, diagnostics));
347
+ if (typeof slot.name !== 'string')
348
+ continue;
349
+ const displays = parseDragonBonesDisplayList(slot.display, remapBoneIndex, diagnostics);
350
+ if (skinName === DEFAULT_DRAGONBONES_SKIN_NAME)
351
+ table.set(slot.name, displays);
352
+ const slotIndex = slotOrder.get(slot.name) ?? -1;
353
+ if (slotIndex < 0)
354
+ continue;
355
+ for (const display of displays) {
356
+ // An unnamed display cannot be addressed by a wardrobe change, so it stays positional-only.
357
+ const displayName = display?.name;
358
+ if (display !== null && typeof displayName === 'string') {
359
+ attachments.push({ attachment: display, name: displayName, slotIndex });
360
+ }
125
361
  }
126
362
  }
363
+ skins.push({ attachments, name: skinName });
127
364
  }
128
- if (alternateSkins > 0) {
129
- reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Skip, 'dragonbones.alternate-skin-unsupported', 'parseDragonBonesSkeleton', { skins: alternateSkins });
130
- }
131
- return table;
365
+ return { skins, table };
132
366
  }
133
367
  // Parses one DragonBones display into an Attachment2D, or `null` (holding its displayIndex slot) for a
134
368
  // malformed entry or an unmodeled type. DragonBones omits `type` for an image display (the default).
@@ -220,8 +454,15 @@ function parseDragonBonesWeightedMesh(display, remapBoneIndex, diagnostics) {
220
454
  }
221
455
  const rawBoneIndex = weights[iW++] | 0;
222
456
  const weight = weights[iW++];
457
+ // The influence pair is consumed above, so every early-out below keeps the flat stream aligned. Drop
458
+ // (recover) an influence that: targets no output bone (remap −1 — never emit −1, the deformer would
459
+ // index the world buffer from a negative offset and produce NaNs); references a bone this mesh's bind
460
+ // pose omits (ordinal −1); has a degenerate bind matrix (det 0); or would overflow the Uint16 count
461
+ // (an influence past the representable maximum, which would wrap influenceCounts and break the
462
+ // deformer's `influences.length === 4 × Σ influenceCounts` invariant).
463
+ const outputBone = remapBoneIndex(rawBoneIndex);
223
464
  const ordinal = findBonePoseOrdinal(bonePose, usedBoneCount, rawBoneIndex);
224
- if (ordinal < 0) {
465
+ if (outputBone < 0 || ordinal < 0 || realCount >= MAX_INFLUENCES_PER_VERTEX) {
225
466
  recovered = true;
226
467
  continue;
227
468
  }
@@ -245,7 +486,7 @@ function parseDragonBonesWeightedMesh(display, remapBoneIndex, diagnostics) {
245
486
  const id = ba * inv;
246
487
  const itx = (bc * bty - bd * btx) * inv;
247
488
  const ity = (bb * btx - ba * bty) * inv;
248
- influences.push(remapBoneIndex(rawBoneIndex), ia * sx + ic * sy + itx, ib * sx + id * sy + ity, weight);
489
+ influences.push(outputBone, ia * sx + ic * sy + itx, ib * sx + id * sy + ity, weight);
249
490
  realCount++;
250
491
  }
251
492
  influenceCounts[v] = realCount;
@@ -316,6 +557,23 @@ function parseDragonBonesSlots(raw, boneIndexByName, skin, diagnostics) {
316
557
  }
317
558
  return slots;
318
559
  }
560
+ // The draw-order position of each named slot, needed before the skins are read so a skin entry can record
561
+ // the slot INDEX it dresses rather than a name the runtime would have to resolve on every wardrobe change.
562
+ function buildDragonBonesSlotOrder(raw) {
563
+ const order = new Map();
564
+ if (!Array.isArray(raw))
565
+ return order;
566
+ let index = 0;
567
+ for (const entry of raw) {
568
+ if (entry === null || typeof entry !== 'object')
569
+ continue;
570
+ const name = entry.name;
571
+ if (typeof name === 'string')
572
+ order.set(name, index);
573
+ index++;
574
+ }
575
+ return order;
576
+ }
319
577
  function boolOr(value, fallback) {
320
578
  return typeof value === 'boolean' ? value : fallback;
321
579
  }
@@ -375,10 +633,16 @@ function parseDragonBonesBoneTransform(raw) {
375
633
  // emitted set — the invariant `computeSkeleton2DWorldTransforms` and `validateSkeleton2D` require. Bones whose
376
634
  // parent never resolves (a dangling reference or a cycle) are emitted last as roots and Skip-crumbed.
377
635
  function parseDragonBonesBones(raw, diagnostics) {
378
- if (!Array.isArray(raw))
379
- return [];
636
+ const rawArray = Array.isArray(raw) ? raw : [];
637
+ // rawIndexToOutput[fileOrderIndex] = the bone's final output index (-1 for a dropped/malformed raw entry).
638
+ // Carrying each raw entry's IDENTITY through to its output position — rather than reconstructing the map
639
+ // by name — is what keeps weighted-mesh bone references correct when two bones share a name (a name-based
640
+ // remap is last-write-wins, so both would collide onto one output bone). Parent links still resolve by
641
+ // name, which is DragonBones' own reference model.
642
+ const rawIndexToOutput = new Array(rawArray.length).fill(-1);
380
643
  const pending = [];
381
- for (const entry of raw) {
644
+ for (let ri = 0; ri < rawArray.length; ri++) {
645
+ const entry = rawArray[ri];
382
646
  if (entry === null || typeof entry !== 'object')
383
647
  continue;
384
648
  const b = entry;
@@ -393,11 +657,12 @@ function parseDragonBonesBones(raw, diagnostics) {
393
657
  scaleY: transform.scaleY,
394
658
  shearX: 0,
395
659
  shearY: transform.shearY,
396
- transformMode: dragonBonesTransformMode(b, diagnostics),
660
+ transformMode: dragonBonesTransformMode(b),
397
661
  x: transform.x,
398
662
  y: transform.y,
399
663
  },
400
664
  parentName: typeof b.parent === 'string' ? b.parent : null,
665
+ rawIndex: ri,
401
666
  });
402
667
  }
403
668
  const bones = [];
@@ -411,6 +676,7 @@ function parseDragonBonesBones(raw, diagnostics) {
411
676
  entry.bone.parentIndex = entry.parentName === null ? -1 : indexByName.get(entry.parentName);
412
677
  if (typeof entry.bone.name === 'string')
413
678
  indexByName.set(entry.bone.name, bones.length);
679
+ rawIndexToOutput[entry.rawIndex] = bones.length;
414
680
  bones.push(entry.bone);
415
681
  pending.splice(i, 1);
416
682
  advanced = true;
@@ -426,39 +692,23 @@ function parseDragonBonesBones(raw, diagnostics) {
426
692
  entry.bone.parentIndex = -1;
427
693
  if (typeof entry.bone.name === 'string')
428
694
  indexByName.set(entry.bone.name, bones.length);
695
+ rawIndexToOutput[entry.rawIndex] = bones.length;
429
696
  bones.push(entry.bone);
430
697
  }
431
698
  }
432
- return bones;
433
- }
434
- // Maps DragonBones' four inheritance booleans onto Flight's five-value TransformMode2D. Position always
435
- // inherits in Flight (the local origin is placed by the parent), so `inheritTranslation:false` is
436
- // unmodeled and Skip-crumbed. Two rotation/scale/reflection combinations have no TransformMode2D — keeping
437
- // rotation+scale while stripping reflection, and keeping scale+reflection while stripping rotation — and are
438
- // Skip-crumbed, falling back to the closest mode.
439
- function dragonBonesTransformMode(bone, diagnostics) {
440
- const inheritRotation = boolOr(bone.inheritRotation, true);
441
- const inheritScale = boolOr(bone.inheritScale, true);
442
- const inheritReflection = boolOr(bone.inheritReflection, true);
443
- if (!boolOr(bone.inheritTranslation, true)) {
444
- reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Skip, 'dragonbones.inherit-translation-unsupported', 'parseDragonBonesSkeleton', { bones: 1 });
445
- }
446
- if (inheritRotation && inheritScale) {
447
- if (inheritReflection)
448
- return TransformMode2D.Normal;
449
- skipCrumbUnmappedInheritMode(diagnostics);
450
- return TransformMode2D.Normal;
451
- }
452
- if (!inheritRotation && !inheritScale)
453
- return TransformMode2D.OnlyTranslation;
454
- if (inheritRotation && !inheritScale) {
455
- return inheritReflection ? TransformMode2D.NoScale : TransformMode2D.NoScaleOrReflection;
456
- }
457
- // !inheritRotation && inheritScale — NoRotationOrReflection also strips reflection, so keeping it is unmapped.
458
- if (!inheritReflection)
459
- return TransformMode2D.NoRotationOrReflection;
460
- skipCrumbUnmappedInheritMode(diagnostics);
461
- return TransformMode2D.NoRotationOrReflection;
699
+ return { bones, rawIndexToOutput };
700
+ }
701
+ // Maps DragonBones' four independent inheritance booleans straight to the vendor-neutral TransformInherit2D
702
+ // (all default true = Normal). Every combination is now expressible — the two rotation/scale/reflection
703
+ // combos that had no value in the old five-mode enum, and `inheritTranslation:false` — so nothing is
704
+ // Skip-crumbed here; the factoring of the inherit axes removed the per-vendor gap.
705
+ function dragonBonesTransformMode(bone) {
706
+ return {
707
+ reflection: boolOr(bone.inheritReflection, true),
708
+ rotation: boolOr(bone.inheritRotation, true),
709
+ scale: boolOr(bone.inheritScale, true),
710
+ translation: boolOr(bone.inheritTranslation, true),
711
+ };
462
712
  }
463
713
  function numberOr(value, fallback) {
464
714
  return typeof value === 'number' ? value : fallback;
@@ -474,7 +724,19 @@ function skipCrumbDragonBonesGroup(diagnostics, raw, kind) {
474
724
  if (count > 0)
475
725
  reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Skip, kind, 'parseDragonBonesSkeleton', { count });
476
726
  }
477
- function skipCrumbUnmappedInheritMode(diagnostics) {
478
- reportImportDiagnostic(diagnostics, ImportDiagnosticSeverity.Skip, 'dragonbones.inherit-mode-unmapped', 'parseDragonBonesSkeleton', { bones: 1 });
479
- }
727
+ // DragonBones' own fallbacks: an unnamed animation is "default", and a document that declares no frame rate
728
+ // runs at 24fps.
729
+ const DEFAULT_DRAGONBONES_ANIMATION_NAME = 'default';
730
+ const DEFAULT_DRAGONBONES_FRAME_RATE = 24;
731
+ // DragonBones' name for the base skin; an unnamed skin is that one.
732
+ const DEFAULT_DRAGONBONES_SKIN_NAME = 'default';
733
+ // The `tweenEasing` sentinel DragonBones uses for "hold this value to the next key" alongside a literal null.
734
+ const DRAGONBONES_NO_TWEEN = 100;
735
+ // Stands in for a malformed keyframe so the frame list keeps its length and its time axis. Read-only: every
736
+ // lookup through it falls back to the field's default.
737
+ const EMPTY_DRAGONBONES_FRAME = {};
738
+ // Skin2D stores per-vertex influence counts in a Uint16Array, so a vertex cannot carry more influences than
739
+ // this without wrapping the count (and breaking `influences.length === 4 × Σ influenceCounts`). No real rig
740
+ // approaches it; the cap only guards adversarial input.
741
+ const MAX_INFLUENCES_PER_VERTEX = 0xffff;
480
742
  //# sourceMappingURL=dragonBonesParse.js.map