spine-rigc 1.5.3 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/mesh.ts CHANGED
@@ -42,6 +42,7 @@
42
42
  * Everything here is pure and integer-stable: same manifest in, same floats out
43
43
  * (assertion A18 recompiles and compares bytes).
44
44
  */
45
+ import type { ModelBinding, ModelVertices } from './model.ts';
45
46
 
46
47
  export interface MeshSpecInput {
47
48
  /** Polygon in part-local pixels, y down, in manifest order. */
@@ -1567,44 +1568,52 @@ export function buildContourMesh(input: ContourSpecInput): MeshGeometry {
1567
1568
  };
1568
1569
  }
1569
1570
 
1570
- /** One bone a weighted vertex can bind to: its index, and its world inverse. */
1571
+ /**
1572
+ * One bone a weighted vertex can bind to: its NAME, and its world inverse.
1573
+ *
1574
+ * It carried the bone's index into the emitted bone array until issue #917; the
1575
+ * index is the Spine emitter's now (`emitVertices` in `src/emit_spine.ts`), so a
1576
+ * binding made here names its bone and survives a bone inserted ahead of it.
1577
+ */
1571
1578
  export interface MeshBoneRef {
1572
- index: number;
1579
+ name: string;
1573
1580
  /** Spine world point -> this bone's local space, at the setup pose. */
1574
1581
  toBind: (worldX: number, worldY: number) => [number, number];
1575
1582
  }
1576
1583
 
1577
1584
  /**
1578
- * Weighted-mesh `vertices` encoding: per vertex, boneCount then
1579
- * (boneIndex, bindX, bindY, weight) repeated.
1585
+ * Bind a generated mesh's vertices to their bones by name: per vertex, one
1586
+ * `{ bone, x, y, weight }` per influence, `x, y` the vertex in that bone's LOCAL
1587
+ * setup space and `weight` on the generator's grid (`r6`).
1580
1588
  *
1581
1589
  * Bind coordinates are in each bone's LOCAL space, so a rotated bone needs a real
1582
1590
  * inverse transform — see `src/transform.ts` for why the old "world minus origin"
1583
1591
  * shortcut had to go and what it would have failed like.
1584
1592
  *
1585
- * The encoding is chosen by a length comparison alone, so
1586
- * there is no field that says "weighted" — get the run lengths wrong and the
1587
- * loader reads weights as coordinates without a word.
1593
+ * Returned as the model's `ModelVertices`, weighted, and not as Spine's run: the
1594
+ * run's bone INDEX is written by the Spine emitter at emission (issue #917), and
1595
+ * the encoding it chooses by a length comparison alone is said here outright.
1596
+ * The caller puts the numbers on the float32 grid, as it did the run's.
1588
1597
  */
1589
- export function encodeWeightedVertices(
1598
+ export function bindWeightedVertices(
1590
1599
  geometry: MeshGeometry,
1591
1600
  /** Part-local pixel -> Spine world. */
1592
1601
  toWorld: (x: number, y: number) => [number, number],
1593
1602
  bones: { anchor: MeshBoneRef; controls: MeshBoneRef[] },
1594
- ): number[] {
1595
- const out: number[] = [];
1603
+ ): Extract<ModelVertices, { weighted: true }> {
1604
+ const bindings: ModelBinding[][] = [];
1596
1605
  geometry.points.forEach(([px, py], i) => {
1597
1606
  const [wx, wy] = toWorld(px, py);
1598
- const vw = geometry.weights[i];
1599
- out.push(vw.length);
1600
- for (const { bone, control, weight } of vw) {
1607
+ const vertex: ModelBinding[] = [];
1608
+ for (const { bone, control, weight } of geometry.weights[i]) {
1601
1609
  const ref = bone === 'anchor' ? bones.anchor : bones.controls[control ?? 0];
1602
1610
  if (!ref) throw new MeshError(`vertex ${i} binds to control bone ${control ?? 0}, which the rig does not have`);
1603
1611
  const [bx, by] = ref.toBind(wx, wy);
1604
- out.push(ref.index, bx, by, r6(weight));
1612
+ vertex.push({ bone: ref.name, x: bx, y: by, weight: r6(weight) });
1605
1613
  }
1614
+ bindings.push(vertex);
1606
1615
  });
1607
- return out;
1616
+ return { weighted: true, bindings };
1608
1617
  }
1609
1618
 
1610
1619
  // ---------------------------------------------------------------------------