// A fox, generated and RIGGED — built with antics-modelkit from npm.
//
// The other three models in this set are assemblies of named parts. This one is
// the opposite case and the one the kit exists for: a single continuous skin over
// an eighteen-bone skeleton, where the weights fall out of the sweeps for free.
// Every vertex is born on a ring, a ring knows where it sits along its limb, and
// that parameter IS the weight — no weight painting anywhere.
//
// So it walks. `anim.js` drives the same skeleton from a distance-driven phase,
// which is why the demo beside this can send it somewhere and have the gait keep
// up rather than skate.
//
// 1 unit = 1 metre. A fox stands about 0.40m at the shoulder.
import * as THREE from "three";
import { limb, merge, rigTree, bindTo, tint, paint, facet, patch, sweep, stitch, spine, weightsFor, sit } from "antics-modelkit";
import { palette } from "antics-modelkit/style";

const TAU = Math.PI * 2;

/** An ellipsoid — a skull, a muzzle, an ear root, a paw. */
const blob = (rx, ry, rz, at, nu = 9, nv = 7) => patch(nu, nv, (u, v) => {
  const a = u * TAU, p = v * Math.PI;
  return {
    x: at[0] + Math.cos(a) * Math.sin(p) * rx,
    y: at[1] + Math.cos(p) * ry,
    z: at[2] + Math.sin(a) * Math.sin(p) * rz,
  };
}, { flip: true });

/** A flat triangle-ish ear, which is most of what says FOX at any distance. */
// `flip` is a coin toss you resolve by being TOLD, and the kit's own
// `preview --winding` told: the ears were the only faces in the whole animal that
// needed double-siding to be seen, which is what inside-out looks like when the
// shape is too thin for the error to read as a hole.
//
// `splay` is how far the ear leans out as it rises. It is a fraction of the
// ear's own width so a narrower ear does not silently stand up straighter.
const ear = (at, sx, h, w, splay = 0.45) => patch(5, 4, (u, v) => {
  const a = u * TAU;
  const taper = 1 - v;
  return {
    x: at[0] + Math.cos(a) * w * taper * 0.5 + sx * v * w * splay,
    y: at[1] + v * h,
    z: at[2] + Math.sin(a) * w * taper * 0.28 - v * h * 0.16,
  };
});

// ── THE SKULL ─────────────────────────────────────────────────────────────
//
// A FOX'S HEAD IS A WEDGE, and a ball with ears stuck on it is a bear cub. Head
// on, the animal is a diamond: a narrow crown, its widest line at the temples
// just under the ear roots, and a hard taper from there down into the muzzle. An
// ellipsoid has none of that — it is as wide at the jaw as at the brow, so there
// are no cheeks for the face to sit on and the muzzle reads as glued to the front
// of a sphere rather than tapered out of a head.
//
// So the cranium is a PROFILE OF HALF-WIDTHS rather than a radius, and everything
// that lives on the head is placed against that same profile instead of against
// three coordinates that happened to be true of the old shape. Three coordinates
// is how the eyes ended up buried inside the last skull.
const SKULL = {
  h: 0.054, // half-height, crown to under-jaw
  w: 0.066, // half-width at the temples — the widest the animal gets above the neck
  d: 0.060, // half-depth
  // Where down the skull that widest line falls, 0 at the crown and 1 at the jaw.
  // 0.375 is 3/8, which is a ring of the patch below — so the crease lands ON an
  // edge loop and stays a crease. Off the grid it gets averaged into a bulge.
  brow: 0.375,
  n: 2.5, // cross-section: 2 is an ellipse, higher flattens the cheek into a plane
};

/** Half-width and half-depth of the cranium at t — 0 at the crown, 1 under the jaw. */
const skullSpan = (t) => [
  // Width: the diamond. Up fast off the crown, down slowly to the jaw, meeting in
  // a crease at the temple that `facet` keeps as the cheekbone.
  SKULL.w * (t < SKULL.brow
    ? Math.sqrt(t / SKULL.brow)
    : ((1 - t) / (1 - SKULL.brow)) ** 0.85),
  // Depth: round. In profile a skull IS an egg — only the front view is a diamond,
  // and making both of them diamonds gives you an axe head.
  SKULL.d * Math.sin(t * Math.PI) ** 0.75,
];

const skull = (at) => patch(13, 9, (u, v) => {
  const a = u * TAU;
  const [rx, rz] = skullSpan(v);
  const c = Math.cos(a), s = Math.sin(a);
  const k = (Math.abs(c) ** SKULL.n + Math.abs(s) ** SKULL.n) ** (-1 / SKULL.n);
  return {
    x: at[0] + c * rx * k,
    y: at[1] + SKULL.h * Math.cos(v * Math.PI),
    z: at[2] + s * rz * k,
  };
}, { flip: true });

/** How far out a point sits in skull units: at most 1 is inside the cranium. */
const inSkull = (at, x, y, z) => {
  const dy = (y - at[1]) / SKULL.h;
  if (Math.abs(dy) >= 1) return Infinity;
  const [rx, rz] = skullSpan(Math.acos(dy) / Math.PI);
  return (Math.abs(x - at[0]) / rx) ** SKULL.n + (Math.abs(z - at[2]) / rz) ** SKULL.n;
};

/**
 * A point ON the cranium along a direction from its centre, plus `out` metres.
 *
 * The old skull was an ellipsoid, so a surface point was direction times the
 * three radii and the file said so. This one has no radii to multiply by — the
 * only honest way to ask where the surface is, is to walk out until you leave.
 */
const onSkull = (at, dir, out = 0) => {
  const d = dir.clone().normalize();
  let lo = 0, hi = 0.25;
  for (let i = 0; i < 48; i++) {
    const m = (lo + hi) / 2;
    if (inSkull(at, at[0] + d.x * m, at[1] + d.y * m, at[2] + d.z * m) <= 1) lo = m; else hi = m;
  }
  return [at[0] + d.x * (lo + out), at[1] + d.y * (lo + out), at[2] + d.z * (lo + out)];
};

// ── THE SKELETON ──────────────────────────────────────────────────────────
//
// Along +Z IS FORWARD. The kit's convention is that a model faces +Z, and a
// quadruped built the other way renders perfectly from every angle that does not
// show which way it is going — then walks the road tail-first. It is cheaper to
// build it facing the right way once than to negate an angle everywhere after.
export const JOINTS = [
  "spine", "chest", "neck", "head", "hips", "tailA", "tailB",
  "shoulderL", "kneeFL", "pawFL", "shoulderR", "kneeFR", "pawFR",
  "hipL", "hockBL", "pawBL", "hipR", "hockBR", "pawBR",
];
const J = Object.fromEntries(JOINTS.map((n, i) => [n, i]));

// A FOX IS ITS LEG-TO-BARREL RATIO, and getting it wrong makes a spider or a
// dachshund rather than a fox. The belly has to clear the ground by more than the
// body is deep, or the eye stops reading columns holding a body up and starts
// reading limbs coming off its sides. Barrel radius 0.085 on a spine at 0.335
// leaves 0.25 of visible leg under a 0.17 body: a ratio of 1.47.
// MEASURED AGAINST THE ANIMAL. A red fox is about 0.38m at the withers on a
// 0.65m head-and-body — a length-to-height ratio near 1.7. At 0.435 high on 0.67
// long that came to 1.54, and an animal too tall for its length reads as leggy
// however correct its legs are: the giraffe was the neck, and this is the rest.
const BARREL = 0.085;
/** The barrel's radius at the haunch and the chest — what a limb root must hide inside. */
const BODY = 0.092;
const SPINE_Y = 0.300;
const AT = {
  hips: [0, SPINE_Y - 0.004, -0.17], spine: [0, SPINE_Y, -0.02], chest: [0, SPINE_Y - 0.008, 0.13],
  neck: [0, SPINE_Y + 0.030, 0.215], head: [0, SPINE_Y + 0.058, 0.300],
  tailA: [0, SPINE_Y + 0.008, -0.255], tailB: [0, 0.120, -0.60],
  // THE LEG STARTS INSIDE THE BODY, which is both what anatomy does and what
  // gives a gait its headroom: the joint is up under the shoulder, hidden by the
  // barrel, and the leg you SEE runs from the belly down.
  //
  // And the middle joint sits BACK OFF THE LINE. Three collinear joints make a
  // leg exactly as long as the gap it spans, so it is already straight standing
  // still and can only shorten. The carpus in front goes back a little, the hock
  // behind a lot — and the hock sits LOW, at about a third of the leg, because a
  // backward bend halfway up a leg is a bird, not a fox.
  shoulderL: [0.048, SPINE_Y - 0.02, 0.115], kneeFL: [0.058, 0.128, 0.128], pawFL: [0.060, 0.028, 0.112],
  shoulderR: [-0.048, SPINE_Y - 0.02, 0.115], kneeFR: [-0.058, 0.128, 0.128], pawFR: [-0.060, 0.028, 0.112],
  hipL: [0.042, SPINE_Y - 0.025, -0.155], hockBL: [0.058, 0.112, -0.205], pawBL: [0.062, 0.028, -0.15],
  hipR: [-0.042, SPINE_Y - 0.025, -0.155], hockBR: [-0.058, 0.112, -0.205], pawBR: [-0.062, 0.028, -0.15],
};

function fox({ coat = 0xc4622c, belly = 0xf3e8da, sock = 0x332b26, tip = 0xf4efe6 } = {}) {
  const V = (a) => new THREE.Vector3(...AT[a]);

  /**
   * ONE SWEEP DOWN A WHOLE CHAIN, not a tube per bone.
   *
   * Built bone by bone, a body is four separate tubes butted end to end and you
   * can SEE every join — the radii step, the caps show through, and the animal
   * reads as sections of hosepipe. A single sweep down the whole chain has no
   * joins to see, and `weightsFor` is exactly what makes it riggable: it remaps a
   * position along the run onto the pair of GLOBAL joints that own it, so the
   * surface still bends at the neck and the waist.
   *
   * `radius(t)` gets 0..1 along the whole chain, which is the only frame in which
   * a chest swell and a loin tuck can be described as one profile.
   */
  const chain = (names, radius, radial = 12, steps = 7, caps = false) => {
    const pts = names.map(V);
    let total = 0;
    const stations = [0];
    for (let i = 1; i < pts.length; i++) { total += pts[i].distanceTo(pts[i - 1]); stations.push(total); }
    const bone = weightsFor(stations, total, { joints: names.map((n) => J[n]) });
    // A RADIUS PER NAMED JOINT, not per fraction of the run. The profile used to be
    // control points at hand-typed fractions — 0.53 for the chest — and the run's
    // length changes the moment any joint moves, so lowering the neck silently slid
    // the deepest point of the chest back into the loin. Say it where the anatomy
    // is and let the stations decide where that falls.
    const at = Array.isArray(radius)
      ? (t) => {
        const d = t * total;
        let i = 0;
        while (i < stations.length - 2 && d > stations[i + 1]) i++;
        const u = Math.max(0, Math.min(1, (d - stations[i]) / (stations[i + 1] - stations[i])));
        return radius[i] + (radius[i + 1] - radius[i]) * (u * u * (3 - 2 * u));
      }
      : radius;
    return stitch(sweep(spine(pts, steps * (pts.length - 1)), at, radial), { bone, caps });
  };

  // THE BODY, nose to tail-root, as one surface. The profile is where the animal
  // is: a deep chest at a third, a tucked loin behind it, a slim neck and a skull.
  // FROM THE HIPS, not from the tail root. Reaching back to tailA made the body
  // and the brush occupy the same run, and the two swells added into one fat lump
  // over the hindquarters — the tail read as a rump rather than as a tail. The
  // body ends where the tail begins.
  // FROM THE TAIL ROOT, so the body has no open end pointing backwards, and with
  // a radius named at every joint: tail root, haunch, loin, chest, neck, skull.
  const body = chain(
    ["tailA", "hips", "spine", "chest", "neck", "head"],
    [0.048, BODY, 0.082, BODY, 0.056, 0.050],
  );

  // A BRUSH IS LONG. At 0.29 long and 0.09 thick it was as fat as it was long and
  // sat on the hindquarters as a lump — the give-away that a tail is a sausage is
  // that its thickness is a large fraction of its length. A fox's is about as long
  // as its body and a third as thick as the body is deep.
  const brush = chain(["hips", "tailA", "tailB"], (t) => (
    0.054 + 0.020 * Math.sin(Math.PI * Math.min(1, t * 0.85 + 0.12)) - 0.030 * t * t
  ), 12, 9);

  // A LEG IS ONE SURFACE TOO, hip through hock to paw, so the knee has no seam.
  // Radii named at the joints, so the knee is a smooth station rather than a
  // linear switch at t = 0.5 — which put a crease exactly where the leg bends.
  const leg = (a, b, c, r0, r1, r2) => chain([a, b, c], [r0, r1, r2], 9, 6, true);

  // COUNTERSHADING, PAINTED rather than glued on. A separate white blob for the
  // belly is a lozenge stuck to a lozenge; every animal's underside grades into
  // its back, and a vertex colour does that for nothing. `under` is how far below
  // the body's own centreline a vertex sits, so it follows the shape.
  const shade = (geo, mid, spread) => paint(geo, (v) => {
    const k = Math.max(0, Math.min(1, (mid - v.y) / spread));
    const c = new THREE.Color(coat).lerp(new THREE.Color(belly), k * k * (3 - 2 * k));
    return c;
  });

  // EVERY LIMB ROOT MUST BE BURIED, and this refuses to build if one is not.
  //
  // Three rounds were spent on legs that "poked out" and I checked the wrong
  // quantity twice: a ring's CENTRE being inside the barrel says nothing, because
  // a ring has a radius and it is centre + radius that emerges. Measured, the
  // shoulder stood 10.7mm proud of the flank and the hip 24.4mm — an open sweep
  // end in plain sight, which from below is a flat facet with the leg's inside
  // showing through it.
  //
  // No check in the kit can see this: the asset is one skin, so there are no two
  // parts to be apart, and an open tube end is not bad winding. It is arithmetic
  // the author has to do, so the author's file does it.
  const buried = (name, root, r) => {
    const [x, y] = AT[root];
    // The barrel is a circle of radius BODY about the spine at this z; solve its
    // half-width at the root's own height rather than at the centreline.
    const spineY = SPINE_Y + (root.startsWith("hip") ? -0.004 : -0.008);
    const half = Math.sqrt(Math.max(0, BODY * BODY - (spineY - y) ** 2));
    if (Math.abs(x) + r > half - 0.004) {
      throw new Error(
        `${name}: the limb root ring reaches ${(Math.abs(x) + r).toFixed(4)} from the centreline ` +
        `but the body is only ${half.toFixed(4)} wide at that height — the open end of the sweep ` +
        `would show through the flank. Move the root inboard or make it thinner.`);
    }
  };
  buried("foreleg", "shoulderL", 0.032);
  buried("hind leg", "hipL", 0.038);

  // AN EAR ROOT IS A LIMB ROOT, and the same mistake was waiting here made the
  // same way. The base of an ear is an open ring — a disc-shaped hole facing down
  // with nothing across it — and it sat 37mm out from the centreline on a skull
  // only 38mm wide at that height. Its CENTRE was inside, which is the quantity
  // that is easy to check and means nothing; five of its eight edge points were
  // out in the air, the furthest at twice the skull's radius. So the ear did not
  // touch the head at all. That is what "the ears are not connected" is: not a
  // seam or a shading fault but a triangle hovering over a gap you can see the
  // background through.
  //
  // A ring has a radius. Sample the ring.
  const rooted = (name, base, w, margin = 0.004) => {
    for (let i = 0; i < 24; i++) {
      const a = (i / 24) * TAU;
      const x = base[0] + Math.cos(a) * (w * 0.5 + margin);
      const z = base[2] + Math.sin(a) * (w * 0.28 + margin);
      const k = inSkull(AT.head, x, base[1], z);
      if (k > 1) {
        throw new Error(
          `${name}: its base ring leaves the cranium at x=${x.toFixed(3)}, z=${z.toFixed(3)} — ` +
          `${k.toFixed(2)} out where 1.00 is the surface. The open end of the ear would show as ` +
          `a gap between the ear and the head. Root it lower, further in, or narrower.`);
      }
    }
  };
  // Set as WIDE as the check allows, because that is what the front view is
  // about: a fox's ears come off the corners of its head, and a pair rooted
  // safely near the centreline gives you a cat.
  const EAR_W = 0.050, INNER_W = 0.036;
  const EAR_L = (sx) => [sx * 0.031, AT.head[1] + 0.026, AT.head[2] - 0.012];
  const INNER_L = (sx) => [sx * 0.031, AT.head[1] + 0.030, AT.head[2] - 0.004];
  rooted("ear", EAR_L(1), EAR_W);
  rooted("inner ear", INNER_L(1), INNER_W);

  const parts = [
    shade(body, SPINE_Y - 0.028, 0.070),
    paint(brush, (v) => {
      // The white tip is a LENGTH along the brush, not a separate lump.
      const t = Math.max(0, Math.min(1, (AT.tailA[2] - v.z) / (AT.tailA[2] - AT.tailB[2] + 0.06)));
      return new THREE.Color(coat).lerp(new THREE.Color(tip), Math.min(1, Math.max(0, (t - 0.66) / 0.26)) ** 1.1);
    }),

    // Legs: coat at the top grading into a dark sock, again as one surface.
    ...[["L", "FL"], ["R", "FR"]].map(([sd, f]) =>
      paint(leg(`shoulder${sd}`, `knee${f}`, `paw${f}`, 0.032, 0.024, 0.017),
        (v) => new THREE.Color(coat).lerp(new THREE.Color(sock),
          Math.max(0, Math.min(1, (0.20 - v.y) / 0.06))))),
    ...[["L", "BL"], ["R", "BR"]].map(([sd, bk]) =>
      paint(leg(`hip${sd}`, `hock${bk}`, `paw${bk}`, 0.038, 0.026, 0.017),
        (v) => new THREE.Color(coat).lerp(new THREE.Color(sock),
          Math.max(0, Math.min(1, (0.20 - v.y) / 0.06))))),

    // SHOULDERS AND HAUNCHES, because a leg that meets a barrel with nothing
    // between them is a cylinder pushed into a drum. Nothing is open here — the
    // leg's top ring is buried well inside the body — so this is not the hole the
    // skull and the rump were: it is a missing TRANSITION, and it reads as a
    // sudden slice because the first band of the leg that clears the barrel has a
    // hard silhouette edge and no mass leading into it.
    //
    // Bound to the limb's own joint rather than to the spine, so the mass swings
    // with the leg — a haunch that stayed behind while the thigh moved would be
    // worse than none. The haunch is much the larger of the two: on a fox the
    // hindquarter is the strongest thing in the silhouette after the brush.
    ...["L", "R"].flatMap((sd) => {
      const sx = sd === "L" ? 1 : -1;
      const sh = AT[`shoulder${sd}`], hp = AT[`hip${sd}`];
      return [
        tint(bindTo(blob(0.030, 0.050, 0.046, [sx * 0.046, sh[1] - 0.020, sh[2] - 0.004], 9, 7),
          J[`shoulder${sd}`]), coat),
        tint(bindTo(blob(0.036, 0.062, 0.056, [sx * 0.046, hp[1] - 0.026, hp[2] - 0.012], 9, 7),
          J[`hip${sd}`]), coat),
      ];
    }),

    // Paws, at the END of each chain — at the joint, not where a foot looks like
    // it should be, which is how a walk cycle ends up on stilts.
    ...["FL", "FR", "BL", "BR"].map((pw) =>
      tint(bindTo(blob(0.023, 0.018, 0.031, [AT[`paw${pw}`][0], 0.020, AT[`paw${pw}`][2] + 0.008], 8, 5), J[`paw${pw}`]), sock)),

    // THE SKULL ITSELF, which the rewrite to continuous sweeps dropped while
    // leaving this comment describing it. The body chain ENDS at the head joint
    // and stitch does not cap a sweep, so where the cranium should be there was an
    // open ring — the muzzle, eyes and chin floating in front of a hole. From
    // three-quarters the muzzle and the neck cover it; from low and in front you
    // look straight into the head. A part that is missing cannot be reported by
    // any check here: nothing knows it was meant to exist.
    // A FACE IS COUNTERSHADED TOO, and this file already knew that — it says so
    // over the body, and then hung the head's white on as three separate lumps.
    // They sat proud of the muzzle at exactly mouth height, so head on the fox
    // had a white bar across its face: it was grinning at you with a full set of
    // teeth. A blob of the wrong colour in the wrong place is not a marking, it
    // is a feature you did not model, and the eye finds it before anything else.
    //
    // So the muzzle's underside GRADES, the same way the belly does, and the
    // chin, the two cheek tufts and the grin all leave together.
    shade(bindTo(skull(AT.head), J.head), AT.head[1] - 0.038, 0.022),
    // Then the furniture that rides it: a muzzle wedge, a nose and ears.
    shade(bindTo(blob(0.032, 0.028, 0.048, [0, AT.head[1] - 0.016, AT.head[2] + 0.058], 9, 6), J.head),
      AT.head[1] - 0.030, 0.024),
    // The nose, at the muzzle's TIP — derived from the muzzle's own centre and
    // half-depth, so it cannot end up inside the face it belongs to.
    tint(bindTo(blob(0.017, 0.014, 0.015, [0, AT.head[1] - 0.022, AT.head[2] + 0.100], 7, 5), J.head), 0x241d1b),
    // A CHIN AND TWO CHEEK TUFTS, not one wide disc under the skull. At 124mm
    // across it reached past the cheeks and read as a white smear under the eye —
    // a marking in the wrong place is worse than no marking, because the eye goes
    // to it first. A fox's white runs under the muzzle and flares back at the jaw.
    // The ears, rooted at the temple where the skull is widest — checked above.
    ...[1, -1].map((sx) => tint(bindTo(ear(EAR_L(sx), sx, 0.098, EAR_W), J.head), coat)),
    ...[1, -1].map((sx) => tint(bindTo(ear(INNER_L(sx), sx, 0.056, INNER_W, 0.40), J.head), 0x3a2a24)),

    // EYES SIT ON THE SKULL, NOT IN IT. Placed by three coordinates that looked
    // about right, they landed 45mm from the head's centre inside a skull of
    // radius 55 — buried, and the fox had no face at all while every part was
    // present and correct. A point on a surface is a DIRECTION times the radius,
    // so that is how it is written: pick where to look from, then step out.
    // ...and the radii it stepped out by were the OLD skull's, so the moment the
    // cranium stopped being an ellipsoid they were three numbers about a shape
    // that no longer exists. `onSkull` walks out until it leaves the surface,
    // whatever the surface happens to be.
    ...[1, -1].flatMap((sx) => {
      // Forward off the temple, not out on it. On the old narrow ball this
      // direction put the eyes on the front of the face; on a skull half as wide
      // again the same numbers walk them out onto the cheekbone corners, staring
      // sideways. The head got wider, so the look has to get more forward.
      const dir = new THREE.Vector3(sx * 0.58, 0.28, 0.80);
      const on = (_r, extra = 0) => onSkull(AT.head, dir, extra);
      return [
        // A dark socket under the eye reads as depth at any size; the eye itself
        // stands proud of it so it catches a highlight.
        tint(bindTo(blob(0.016, 0.014, 0.012, on(0, -0.004), 7, 5), J.head), 0x4a2a1c),
        tint(bindTo(blob(0.011, 0.011, 0.010, on(0, 0.004), 7, 6), J.head), 0x17110f),
      ];
    }),
  ];

  const spec = [
    { name: "spine", parent: null, at: AT.spine },
    { name: "chest", parent: "spine", at: AT.chest },
    { name: "neck", parent: "chest", at: AT.neck },
    { name: "head", parent: "neck", at: AT.head },
    { name: "hips", parent: "spine", at: AT.hips },
    { name: "tailA", parent: "hips", at: AT.tailA },
    { name: "tailB", parent: "tailA", at: AT.tailB },
    { name: "shoulderL", parent: "chest", at: AT.shoulderL },
    { name: "kneeFL", parent: "shoulderL", at: AT.kneeFL },
    { name: "pawFL", parent: "kneeFL", at: AT.pawFL },
    { name: "shoulderR", parent: "chest", at: AT.shoulderR },
    { name: "kneeFR", parent: "shoulderR", at: AT.kneeFR },
    { name: "pawFR", parent: "kneeFR", at: AT.pawFR },
    { name: "hipL", parent: "hips", at: AT.hipL },
    { name: "hockBL", parent: "hipL", at: AT.hockBL },
    { name: "pawBL", parent: "hockBL", at: AT.pawBL },
    { name: "hipR", parent: "hips", at: AT.hipR },
    { name: "hockBR", parent: "hipR", at: AT.hockBR },
    { name: "pawBR", parent: "hockBR", at: AT.pawBR },
  ];
  // PARENT BEFORE CHILD, and the order above is the order rigTree enforces — it
  // makes bone 0 the root so joint order, inverse-bind order and the JOINTS_0
  // index space are one order with no inference anywhere.
  // FACETED, like everything else in this set. Smooth-shaded, a low-poly animal
  // reads as an under-detailed smooth model rather than a deliberate one — the
  // arcade cabinet, the kart and the stall are all crisp planes, and the fox was
  // the only thing in the catalogue apologising for its polygon count.
  return rigTree(spec, undefined, facet(merge(parts)));
}

export const vulpin = () => {
  const r = fox();
  return {
    category: "character",
    // ONE PART, ONE SKIN. The GLB writer emits a fresh bone set per skinned part,
    // so a figure split across parts exports several skeletons and only one of
    // them would ever be posed.
    parts: [{ name: "fox", geometry: sit(r.mesh.geometry), skin: r.skin, roughness: 0.82 }],
    anchors: { head: AT.head, tail: AT.tailB, back: [0, SPINE_Y + BARREL, -0.02] },
  };
};
