@margoengine/rigging 0.1.0 → 1.0.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/dist/mtoon.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { r as e, t } from "./errors-D8rc8kzg.js";
5
5
  import { setMaterialDraw as n } from "@margoengine/gltf/material-draw";
6
6
  import { PBRDrawRun as r } from "@margoengine/gltf/pbr-model";
@@ -486,7 +486,7 @@ function R(e) {
486
486
  }
487
487
  return t;
488
488
  }
489
- var z = class a {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
489
+ var z = class a {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
490
490
  get materials() {
491
491
  return this.definitions;
492
492
  }
@@ -593,7 +593,7 @@ var z = class a {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url)
593
593
  for (let e of this.parts) e.primitive.material = e.body;
594
594
  this.unsubscribe = r.onDispose(() => this.dispose());
595
595
  }
596
- static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
596
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
597
597
  let n = new a(e, t);
598
598
  try {
599
599
  n.scene.use(n);
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { rotationBetween as e } from "./ik.js";
@@ -458,7 +458,7 @@ async function E(e, r, i = {}) {
458
458
  if (i.autoUpdate !== !1) {
459
459
  if (i.vrm) b = i.vrm.addPoseSource(S);
460
460
  else {
461
- let e = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
461
+ let e = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
462
462
  name: w,
463
463
  setup() {},
464
464
  onPreUpdate: S,
@@ -41,8 +41,10 @@ export interface PrepareRetargetOptions {
41
41
  /**
42
42
  * Turn the target's reference pose so each mapped limb bone (arms, hands, fingers, legs, feet) points the way its source
43
43
  * bone does at rest (default true): a T-pose source then drives an A-pose target into the same T-pose. The trunk, neck
44
- * and collarbones keep the target's own rest, since their directions are body layout, not pose. False keeps the
45
- * target's whole rest pose.
44
+ * and collarbones keep the target's own rest, since their directions are body layout, not pose. A source hand with no
45
+ * finger bones below it (a BVH End Site, an ASF or Xsens hand segment) is one rigid segment, so the target's hand and
46
+ * long fingers are laid straight along it, in line with the source forearm when the source has no finger base at all;
47
+ * thumbs keep the target's rest. False keeps the target's whole rest pose.
46
48
  */
47
49
  alignRest?: boolean;
48
50
  }
@@ -60,6 +62,11 @@ export interface PreparedRetarget {
60
62
  readonly to: SkeletonPreset;
61
63
  /** Humanoid bones the target has but the source does not (they stay at rest). */
62
64
  readonly unmapped: readonly HumanoidBone[];
65
+ /**
66
+ * Unmapped target bone names whose rest the alignment turned (fingers laid along a fingerless source hand). Retarget
67
+ * reads this as its `hold` option and keeps them at the aligned rest, so they do not stay in the target's own pose.
68
+ */
69
+ readonly hold: readonly string[];
63
70
  }
64
71
  /**
65
72
  * Maps a source skeleton's bones onto a target's by their presets (detected from the names unless given) and, by
package/dist/retarget.js CHANGED
@@ -246,18 +246,19 @@ function E(e, t, n = {}) {
246
246
  let a = C(e.names, r), o = C(t.names, i), s = {}, c = [];
247
247
  for (let e of t.names) s[e] = "";
248
248
  for (let [n, r] of o) {
249
- let i = a.get(n);
250
- i === void 0 ? c.push(n) : s[t.names[r]] = e.names[i];
249
+ let i = /^(left|right)(Index|Ring|Little)Proximal$/.exec(n)?.[1], o = a.get(n) ?? (i ? a.get(`${i}MiddleProximal`) : void 0);
250
+ o === void 0 ? c.push(n) : s[t.names[r]] = e.names[o];
251
251
  }
252
252
  if (!Object.values(s).some(Boolean)) throw RangeError(`Retarget maps no bones from ${r} to ${i}; check the presets`);
253
- let l = o.has("hips") && a.has("hips") ? t.names[o.get("hips")] : void 0;
253
+ let l = o.has("hips") && a.has("hips") ? t.names[o.get("hips")] : void 0, u = /* @__PURE__ */ new Set(), d = n.alignRest === !1 ? t : P(e, t, a, o, u), f = [...u].filter((e) => !s[t.names[e]]).map((e) => t.names[e]);
254
254
  return {
255
- target: n.alignRest === !1 ? t : M(e, t, a, o),
255
+ target: d,
256
256
  names: s,
257
257
  ...l ? { hip: l } : {},
258
258
  from: r,
259
259
  to: i,
260
- unmapped: c
260
+ unmapped: c,
261
+ hold: f
261
262
  };
262
263
  }
263
264
  function D(t, n) {
@@ -307,44 +308,67 @@ function j(e, t, n, a) {
307
308
  let v = Math.atan2(c(p, s(g, _)), c(g, _));
308
309
  return i(r(p, v), t);
309
310
  }
310
- function M(e, t, r, s) {
311
- let c = new Float64Array(t.rest), l = O(e, e.rest), u = _.filter((e) => s.has(e));
312
- for (let e of u) {
313
- if (y.has(e)) continue;
314
- let u = (v[e] ?? []).find((e) => s.has(e) && r.has(e));
315
- if (!u || !r.has(e)) continue;
316
- let d = s.get(e), f = s.get(u), p = r.get(e), m = r.get(u), h = O(t, c), g = [
311
+ var M = /^(left|right)(Hand|(Index|Middle|Ring|Little)(Proximal|Intermediate))$/;
312
+ function N(e, t, n, r) {
313
+ let i = M.exec(e)?.[1], a = v[e]?.[0];
314
+ if (!i || !a || !n.has(a)) return null;
315
+ let o = t.get(`${i}Hand`), s = t.get(`${i}MiddleProximal`), c = t.get(`${i}LowerArm`);
316
+ if (o === void 0) return null;
317
+ let [l, u] = s === void 0 ? c === void 0 ? [] : [c, o] : [o, s];
318
+ return l === void 0 || u === void 0 ? null : {
319
+ child: n.get(a),
320
+ want: [
317
321
  0,
318
322
  1,
319
323
  2
320
- ].map((e) => h.position[f][e] - h.position[d][e]), _ = [
324
+ ].map((e) => r[u][e] - r[l][e])
325
+ };
326
+ }
327
+ function P(e, t, r, s, c) {
328
+ let l = new Float64Array(t.rest), u = O(e, e.rest), d = _.filter((e) => s.has(e));
329
+ for (let e of d) {
330
+ if (y.has(e)) continue;
331
+ let d = (v[e] ?? []).find((e) => s.has(e) && r.has(e)), f, p;
332
+ if (d && r.has(e)) {
333
+ let t = r.get(e), n = r.get(d);
334
+ f = s.get(d), p = [
335
+ 0,
336
+ 1,
337
+ 2
338
+ ].map((e) => u.position[n][e] - u.position[t][e]);
339
+ } else {
340
+ let t = N(e, r, s, u.position);
341
+ if (!t) continue;
342
+ f = t.child, p = t.want;
343
+ }
344
+ let m = s.get(e), h = O(t, l), g = [
321
345
  0,
322
346
  1,
323
347
  2
324
- ].map((e) => l.position[m][e] - l.position[p][e]);
325
- if (Math.hypot(...g) < 1e-9 || Math.hypot(..._) < 1e-9) continue;
326
- let b = t.parents[d], x = b < 0 ? g : k(h.linear, b, g), S = b < 0 ? _ : k(h.linear, b, _);
327
- if (!x || !S) continue;
328
- let C = n(x, S);
348
+ ].map((e) => h.position[f][e] - h.position[m][e]);
349
+ if (Math.hypot(...g) < 1e-9 || Math.hypot(...p) < 1e-9) continue;
350
+ let _ = t.parents[m], b = _ < 0 ? g : k(h.linear, _, g), x = _ < 0 ? p : k(h.linear, _, p);
351
+ if (!b || !x) continue;
352
+ let S = n(b, x);
329
353
  if (e === "leftHand" || e === "rightHand") {
330
- let t = e === "leftHand" ? "left" : "right", n = A(t, s, h.position), i = A(t, r, l.position);
354
+ let t = e === "leftHand" ? "left" : "right", n = A(t, s, h.position), i = A(t, r, u.position);
331
355
  if (n && i) {
332
- let e = b < 0 ? n : k(h.linear, b, n), t = b < 0 ? i : k(h.linear, b, i);
333
- e && t && (C = j(o(x, C), C, e, t));
356
+ let e = _ < 0 ? n : k(h.linear, _, n), t = _ < 0 ? i : k(h.linear, _, i);
357
+ e && t && (S = j(o(b, S), S, e, t));
334
358
  }
335
359
  }
336
- let w = d * 10 + 3;
337
- c.set(a(i(C, [
338
- c[w],
339
- c[w + 1],
340
- c[w + 2],
341
- c[w + 3]
342
- ])), w);
360
+ let C = m * 10 + 3;
361
+ l.set(a(i(S, [
362
+ l[C],
363
+ l[C + 1],
364
+ l[C + 2],
365
+ l[C + 3]
366
+ ])), C), c.add(m);
343
367
  }
344
368
  return {
345
369
  names: t.names,
346
370
  parents: t.parents,
347
- rest: c
371
+ rest: l
348
372
  };
349
373
  }
350
374
  //#endregion