roamwright 0.60.0 → 0.61.1

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.
@@ -58,12 +58,12 @@ function muzzledFace(H, p) {
58
58
  [-0.012 * k, nose + 0.012 * k, 0, 0, 0, 0],
59
59
  ];
60
60
  H.jaw = [
61
- [-0.045 * k, 0.07 * k, 0, 0, 0, 0],
62
- [-0.052 * k, 0.1 * k, 0.074 * wide, 0.02 * k, 0.04 * k, 0.25],
63
- [-0.052 * k, stop - 0.03 * k, 0.046 * snout, 0.016 * k, 0.036 * k * deep, 1],
64
- [-0.046 * k, stop + 0.5 * muzzle, 0.038 * snout, 0.014 * k, 0.028 * k * deep, 1],
65
- [-0.043 * k, stop + 0.88 * muzzle, 0.032 * snout, 0.012 * k, 0.021 * k * deep, 1],
66
- [-0.041 * k, stop + 0.96 * muzzle, 0, 0, 0, 1],
61
+ [-0.036 * k, 0.075 * k, 0, 0, 0, 0],
62
+ [-0.042 * k, 0.105 * k, 0.072 * wide, 0.022 * k, 0.034 * k, 0.25],
63
+ [-0.041 * k, stop - 0.02 * k, 0.045 * snout, 0.018 * k, 0.03 * k * deep, 1],
64
+ [-0.036 * k, stop + 0.5 * muzzle, 0.037 * snout, 0.016 * k, 0.024 * k * deep, 1],
65
+ [-0.033 * k, stop + 0.86 * muzzle, 0.03 * snout, 0.013 * k, 0.018 * k * deep, 1],
66
+ [-0.031 * k, stop + 0.94 * muzzle, 0, 0, 0, 1],
67
67
  ];
68
68
  H.eye = [0.089 * wide, 0.03 * k, stop - 0.052 * k]; // the middle of its socket (x to the right)
69
69
  H.ball = {
@@ -74,14 +74,14 @@ function muzzledFace(H, p) {
74
74
  pupilAt: [0.0052 * k, 0.0035 * k],
75
75
  };
76
76
  H.socket = { axis: 0, size: k, depth: 1, brow: 1 }; // the socket sinks towards the middle of the head, by measures of this size; depth and brow: how deep it is and how high its ridge
77
- H.rim = [0.034 * k, 0.018 * k]; // the dark rim round an eye: from where it begins to where it is full
78
- H.noseTip = [0, -0.006 * k, nose + 0.003 * k, 0.06 * snout, 0.046 * k, 0.034 * k];
77
+ H.rim = [0.03 * k, 0.017 * k]; // the dark rim round an eye: from where it begins to where it is full
78
+ H.noseTip = [0, -0.006 * k, nose + 0.003 * k, 0.058 * snout, 0.044 * k, 0.034 * k];
79
79
  H.noseColour = BLACK;
80
80
  H.pads = null;
81
- H.iris = 0xa87420;
82
- H.mouth = [-0.03 * k, -0.04 * k]; // the height of the upper teeth and the lower
83
- H.ear = [0.082 * wide, 0.05 * k, 0.03 * k]; // the right ear's root
84
- H.hinge = [0, -0.036 * k, 0.1 * k]; // the jaw's
81
+ H.iris = p.darkEye ? 0x161210 : 0x8a5e1e;
82
+ H.mouth = [-0.028 * k, -0.036 * k]; // the height of the upper teeth and the lower
83
+ H.ear = [0.08 * wide, 0.052 * k, 0.035 * k]; // the right ear's root
84
+ H.hinge = [0, -0.032 * k, 0.1 * k]; // the jaw's
85
85
  H.lip = [0, 0, stop + 0.4 * muzzle]; // the lips' bone
86
86
  return H;
87
87
  }
@@ -181,11 +181,11 @@ function head(b, H, p, L, coat, detail, twoFaced) {
181
181
  fur:
182
182
  detail === NEAR &&
183
183
  ((out, x, y, z, nx, ny) => {
184
- // the cheeks' ruff, behind and below the jaw's hinge
185
- const len = p.fur * p.ruff * 0.065 * sstep(0.15 * k, 0.06 * k, z) * sstep(0.45, -0.1, ny);
184
+ // Soft cheek ruff behind and below the jaw hinge, capped so shaggy breeds never shoot long spikes off the face.
185
+ const len = Math.min(0.05, p.fur * p.ruff * 0.052) * sstep(0.15 * k, 0.06 * k, z) * sstep(0.45, -0.1, ny);
186
186
  if (len < 0.02) return false;
187
187
  out[0] = len;
188
- out[1] = 0.45;
188
+ out[1] = 0.35;
189
189
  out[2] = len * 0.3;
190
190
  out[3] = 2;
191
191
  return true;
@@ -239,18 +239,19 @@ function pad(b, H, skin, s) {
239
239
  }
240
240
 
241
241
  // An ear by its kind: pricked, tipped over, folded, hanging, a bear's round one, or a cat's upright triangle facing forwards.
242
- function ear(b, H, p, coat, s, twoFaced) {
242
+ function ear(b, H, p, coat, s) {
243
243
  const [kind, size] = p.ear,
244
244
  k = H.size,
245
245
  base = [s * H.ear[0], H.ear[1], H.ear[2]],
246
246
  hang = kind === 'drop',
247
247
  cat = kind === 'cat',
248
- up = hang ? [s * 0.78, -0.6, -0.15] : cat ? [s * 0.34, 0.93, -0.12] : [s * 0.3, 0.92, -0.25],
249
- front = hang ? [s * 0.55, 0.75, 0.35] : cat ? [s * 0.3, 0.02, 0.95] : [s * 0.45, 0.12, 0.88],
248
+ round = kind === 'round',
249
+ up = hang ? [s * 0.65, -0.72, 0.12] : cat ? [s * 0.34, 0.93, -0.12] : round ? [s * 0.42, 0.88, 0.12] : [s * 0.28, 0.93, -0.15],
250
+ front = hang ? [s * 0.6, 0.55, 0.58] : cat ? [s * 0.3, 0.02, 0.95] : [s * 0.38, 0.12, 0.91],
250
251
  across = [up[1] * front[2] - up[2] * front[1], up[2] * front[0] - up[0] * front[2], up[0] * front[1] - up[1] * front[0]],
251
- len = (kind === 'round' ? 0.075 : hang ? 0.16 : cat ? 0.18 : 0.115) * k * size,
252
- wide = (kind === 'round' ? 0.1 : cat ? 0.16 : 0.09) * k * size,
253
- fold = kind === 'half' ? 0.62 : kind === 'fold' ? 0.4 : 1,
252
+ len = (round ? 0.09 : hang ? 0.165 : cat ? 0.18 : kind === 'fold' ? 0.148 : 0.124) * k * size,
253
+ wide = (round ? 0.108 : cat ? 0.16 : kind === 'fold' ? 0.108 : 0.095) * k * size,
254
+ fold = kind === 'half' ? 0.62 : kind === 'fold' ? 0.48 : 1,
254
255
  col = [0, 0, 0, 0];
255
256
  coat(HEAD)(col, base[0], base[1] + 0.04, base[2], 0, 1, 0);
256
257
  b.tv = col[3];
@@ -262,13 +263,13 @@ function ear(b, H, p, coat, s, twoFaced) {
262
263
  front,
263
264
  len,
264
265
  wide,
265
- kind === 'round' ? 0.5 : cat ? 0.22 : 0.3,
266
+ round ? 0.55 : cat ? 0.22 : 0.34,
266
267
  fold,
267
268
  col,
268
- [col[0] * 0.5 + 0.04, col[1] * 0.45 + 0.02, col[2] * 0.45 + 0.02],
269
+ [col[0] * 0.55 + 0.06, col[1] * 0.48 + 0.04, col[2] * 0.46 + 0.04],
269
270
  s < 0 ? BONE.earL : BONE.earR,
270
271
  cat ? 1 : 0,
271
- twoFaced,
272
+ true, // always draw both ear faces so figures on single-sided materials never lose their ears from the front
272
273
  );
273
274
  }
274
275
 
@@ -330,7 +331,7 @@ function teeth(b, H, p, L) {
330
331
  b.add(
331
332
  SHAPES.sph,
332
333
  C(L.tongue ?? 0x7a2a30),
333
- TRS(0, low + 0.004 * k, stop + 0.42 * muzzle, 0.04 * snout, 0.012 * k, 0.9 * muzzle + 0.05 * k),
334
+ TRS(0, low + 0.006 * k, stop + 0.34 * muzzle, 0.036 * snout, 0.01 * k, 0.72 * muzzle + 0.03 * k),
334
335
  );
335
336
  }
336
337
 
@@ -0,0 +1,374 @@
1
+ import * as THREE from 'three';
2
+ import { lerp, sstep } from '../math/scalar.js';
3
+ import { GB } from './builder.js';
4
+ import { C } from './primitives.js';
5
+ import { tube } from './animal-skin.js';
6
+ import { haunchStations } from './animal-haunch.js';
7
+ import { NO_ANIMAL_OPTIONS, animalNoise } from './animal-options.js';
8
+ import { BONE, LEGS, makeRig } from '../motion/quadruped.js';
9
+ import { catHead, catHeadPlan } from './animal-cat-head.js';
10
+
11
+ // ════════════════════════════════════════════════════════════════════════
12
+ // A house cat (Felis catus) on the four-legged skeleton (motion/quadruped.js), laid out in withers heights: 1.42 model units,
13
+ // so a caller scaling by 0.175 gets a cat 25 cm at the shoulder and 46 cm from nose to rump. Real proportions, in withers
14
+ // heights W (25 cm), measured from the skeleton and side photographs: 1.8 from the nose to the rump, the head a fifth of it (0.35
15
+ // W; animal-cat-head.js); a short thick neck (0.3 W) carrying it level; the body deep and narrow (the chest 0.28 W wide), the
16
+ // brisket at 0.48 and the belly at half the shoulder, the waist tucked up to 0.62 behind the ribs and the loins rising to a round
17
+ // rump at 1.04; the
18
+ // forelegs under the shoulder blade (the shoulder joint 0.76, the elbow 0.50 against the chest, the wrist 0.14); the hind legs
19
+ // with the hip at 0.80, the stifle 0.55 forward under the belly, the hock 0.30 well up and back and the metatarsus sloping
20
+ // forward to the paw; the paws round and a little wider than the leg; the tail 1.05 W long, thick at the root.
21
+ // ════════════════════════════════════════════════════════════════════════
22
+ const WITHERS = 1.42,
23
+ NEAR = 2,
24
+ SLEEK = 0.52,
25
+ zF = 0.4, // where the fore paws stand along the body
26
+ zH = -0.68, // and the hind ones: a supple feline back, ~1.08 between shoulders and rump
27
+ RINGS = {
28
+ trunk: [
29
+ [10, 2],
30
+ [16, 2],
31
+ [20, 3],
32
+ ],
33
+ leg: [
34
+ [6, 1],
35
+ [8, 2],
36
+ [10, 2],
37
+ ],
38
+ tail: [
39
+ [6, 1],
40
+ [8, 2],
41
+ [8, 2],
42
+ ],
43
+ };
44
+
45
+ // Light, placed feline gait: smooth direct-register four-beat walk, agile trot, and springy bound; paired hind legs keep
46
+ // stifle and hock aligned naturally.
47
+ const CAT_HABITS = {
48
+ fore: { follow: 0.85, heel3: 0.25, fold3: 0.8, heel4: 0.65, fold4: 0.75, sink: 0, glide: 0.16 },
49
+ hind: { follow: 0.55, heel3: 0.25, fold3: 0.28, heel4: 0.65, fold4: 0.65, sink: 0, glide: 0, paired: true, thigh: 0.48 },
50
+ crouch: 0.04,
51
+ gaits: [
52
+ [0.08, 0.46, 0.72, [0.25, 0.75, 0, 0.5], 0.012, 0.055, 0.03],
53
+ [0.52, 0.62, 0.65, [0.25, 0.75, 0, 0.5], 0.016, 0.075, 0.045],
54
+ [0.85, 0.66, 0.48, [0.5, 0, 0, 0.5], 0.045, 0.1, 0.06],
55
+ [1.6, 0.78, 0.34, [0.5, 0.6, 0, 0.1], 0.09, 0.18, 0.32],
56
+ [3.0, 0.88, 0.25, [0.5, 0.6, 0, 0.1], 0.11, 0.22, 0.42],
57
+ ],
58
+ };
59
+
60
+ // Where the joints are, in withers heights: [y, z] in the body's upright plane; and the chest's and the rump's sections where
61
+ // the shoulder and the thigh hang inside them (the rings over them in catTrunk; geometry/animal-haunch.js).
62
+ const A = {
63
+ zF,
64
+ zH,
65
+ sx: 0.072,
66
+ hx: 0.072,
67
+ shoulder: [0.76, zF + 0.05],
68
+ elbow: [0.5, zF - 0.04],
69
+ wrist: [0.14, zF - 0.01],
70
+ knuckle: [0.045, zF + 0.018],
71
+ pad: [0, zF + 0.045],
72
+ hip: [0.8, zH + 0.12],
73
+ stifle: [0.53, zH + 0.26],
74
+ hock: [0.29, zH - 0.062],
75
+ heel: [0.045, zH + 0.01],
76
+ hindPad: [0, zH + 0.045],
77
+ neck: [0.88, zF + 0.1],
78
+ poll: [1.13, zF + 0.22],
79
+ tail: [
80
+ [0.98, zH - 0.08],
81
+ [0.9, zH - 0.41],
82
+ [0.79, zH - 0.74],
83
+ [0.7, zH - 1.04],
84
+ ],
85
+ chest: { y: 0.735, h: 0.235, w: 0.132, n: 2.2 },
86
+ rump: { y: 0.825, h: 0.2, w: 0.142, n: 2.4 },
87
+ };
88
+
89
+ // A hind leg's thigh as rounded slices (geometry/animal-haunch.js): height, front edge, back edge, half-width, lean, squareness,
90
+ // level. Plump, muscled feline thigh emerging smoothly from the rounded rump down to the forward stifle, then tapering into a
91
+ // crisp backward-sloping gaskin and Achilles curve to the elevated hock.
92
+ const THIGH = [
93
+ [0.94, A.hip[1] + 0.04, A.hip[1] - 0.12, 0, -0.05, 2], // closed inside the upper rump
94
+ [0.83, A.hip[1] + 0.085, A.hip[1] - 0.175, 0.066, -0.026, 2], // rounded upper haunch filling smoothly under the tail root
95
+ [0.69, A.hip[1] + 0.125, A.hip[1] - 0.165, 0.07, -0.016, 2], // plump rounded feline thigh & buttock emerging tangentially from rump
96
+ [A.stifle[0], A.stifle[1] + 0.032, lerp(A.hip[1] - 0.145, A.stifle[1] - 0.09, 0.46), 0.049, -0.004, 2], // smooth rounded stifle
97
+ [
98
+ lerp(A.stifle[0], A.hock[0], 0.4),
99
+ lerp(A.stifle[1], A.hock[1], 0.45) + 0.029,
100
+ lerp(A.stifle[1] - 0.11, A.hock[1] - 0.04, 0.5),
101
+ 0.033,
102
+ 0,
103
+ 2,
104
+ ], // muscular feline gaskin sloping clearly back along the tibia
105
+ [lerp(A.stifle[0], A.hock[0], 0.76), lerp(A.stifle[1], A.hock[1], 0.8) + 0.023, A.hock[1] - 0.034, 0.024, 0, 2], // slender Achilles
106
+ ];
107
+ // A foreleg's shoulder as level slices: supple feline shoulder blade on the narrow ribs, muscular upper arm to the elbow
108
+ // against the brisket, tapering smoothly into a slender forearm.
109
+ const SHOULDER = [
110
+ [0.93, zF + 0.03, zF - 0.09, 0, -0.042], // closed inside the chest
111
+ [0.85, zF + 0.085, zF - 0.095, 0.04, -0.026],
112
+ [0.74, zF + 0.095, zF - 0.095, 0.044, -0.012], // shoulder joint
113
+ [0.61, zF + 0.06, zF - 0.085, 0.042, -0.004], // muscular upper arm
114
+ [A.elbow[0] + 0.01, A.elbow[1] + 0.048, A.elbow[1] - 0.05, 0.038, 0], // elbow tucked against the chest
115
+ [0.32, lerp(A.elbow[1], A.wrist[1], 0.5) + 0.034, lerp(A.elbow[1], A.wrist[1], 0.5) - 0.038, 0.032, 0], // forearm
116
+ ];
117
+
118
+ // Short sleek coat with soft mackerel tabby markings along back, flanks, forehead and tail, and pale bib, belly, chin and paws.
119
+ function catCoatOf(L, fbm) {
120
+ const c1 = C(L.c1 ?? 0xb8a68a),
121
+ c2 = C(L.c2 ?? 0x5a4636),
122
+ pale =
123
+ L.c3 !== undefined
124
+ ? C(L.c3)
125
+ : [Math.min(0.92, c1[0] * 0.52 + 0.38), Math.min(0.92, c1[1] * 0.52 + 0.35), Math.min(0.9, c1[2] * 0.52 + 0.3)],
126
+ seed = ((L.c1 ?? 17) % 89) + 5;
127
+ return region => (col, x, y, z, nx, ny) => {
128
+ let stripe = 0,
129
+ light = 0;
130
+ if (region === 0) {
131
+ const dorsal = sstep(0.065, 0.015, Math.abs(x)) * sstep(0.45, 0.88, ny),
132
+ bars = sstep(0.44, 0.88, Math.sin(z * 26 + fbm(z * 5, y * 5, 2, seed) * 2.2) * 0.5 + 0.5) * sstep(-0.04, 0.65, ny);
133
+ stripe = Math.max(dorsal * 0.52, bars * 0.24);
134
+ // the pale belly, and the bib under the short neck
135
+ light = Math.max(sstep(-0.18, -0.8, ny) * 0.68, sstep(0.3, 0.45, z) * sstep(0.95, 0.58, y) * 0.5);
136
+ } else if (region === 1) {
137
+ // the forehead's stripes (in the head's own frame: z from the poll)
138
+ stripe = sstep(0.05, 0.012, Math.abs(x)) * sstep(0.42, 0.85, ny) * sstep(0.16, 0.02, z) * 0.45;
139
+ light = sstep(-0.18, -0.75, ny) * 0.55;
140
+ } else if (region === 2) {
141
+ // the legs: faint bars above, pale toes
142
+ stripe = sstep(0.4, 0.86, Math.sin(z * 60 + y * 20) * 0.5 + 0.5) * sstep(0.1, 0.3, y) * 0.3;
143
+ light = sstep(0.09, 0.03, y) * 0.6;
144
+ } else {
145
+ // the tail: rings along it, dark at the tip (it descends from the rump)
146
+ const along = 1.0 - y;
147
+ stripe = Math.max(
148
+ sstep(0.32, 0.78, Math.sin(along * 36) * 0.5 + 0.5) * sstep(0.1, 0.22, along) * 0.3,
149
+ sstep(0.5, 0.62, along) * 0.58,
150
+ );
151
+ }
152
+ const fine = 0.94 + 0.12 * fbm(z * 14 + x * 9, y * 14, 2, seed + 3);
153
+ for (let i = 0; i < 3; i++) {
154
+ let v = lerp(c1[i], c2[i] * 0.85, stripe);
155
+ v = lerp(v, pale[i], light * (1 - stripe * 0.35));
156
+ col[i] = v * fine;
157
+ }
158
+ col[3] = SLEEK;
159
+ };
160
+ }
161
+
162
+ function catJointsAt(H, headAt) {
163
+ const K = WITHERS,
164
+ at = (x, q) => [x * K, q[0] * K, q[1] * K],
165
+ mid = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t],
166
+ joints = [];
167
+ joints[BONE.root] = at(0, [0.8, (zF + zH) / 2]);
168
+ joints[BONE.hips] = at(0, [0.86, zH + 0.3]);
169
+ joints[BONE.chest] = at(0, [0.82, zF - 0.2]);
170
+ joints[BONE.neck] = at(0, A.neck);
171
+ joints[BONE.neck2] = at(0, mid(A.neck, A.poll, 0.5));
172
+ joints[BONE.head] = at(0, A.poll);
173
+ joints[BONE.jaw] = headAt(...H.hinge);
174
+ joints[BONE.earL] = headAt(-H.ear.base[0], H.ear.base[1], H.ear.base[2]);
175
+ joints[BONE.earR] = headAt(...H.ear.base);
176
+ joints[BONE.lip] = headAt(...H.lip);
177
+ [-1, 1].forEach((s, i) => {
178
+ const f = LEGS[i],
179
+ h = LEGS[i + 2];
180
+ joints[f] = at(s * A.sx, A.shoulder);
181
+ joints[f + 1] = at(s * A.sx, A.elbow);
182
+ joints[f + 2] = at(s * A.sx, A.wrist);
183
+ joints[f + 3] = at(s * A.sx, A.knuckle);
184
+ joints[h] = at(s * A.hx, A.hip);
185
+ joints[h + 1] = at(s * A.hx, A.stifle);
186
+ joints[h + 2] = at(s * A.hx, A.hock);
187
+ joints[h + 3] = at(s * A.hx, A.heel);
188
+ });
189
+ // the tail's bones along its rest curve, back and down from the rump
190
+ A.tail.forEach((p, i) => (joints[BONE.tail + i] = at(0, p)));
191
+ joints[BONE.crest] = at(0, [1.0, zF]);
192
+ const feet = [at(-A.sx, A.pad), at(A.sx, A.pad), at(-A.hx, A.hindPad), at(A.hx, A.hindPad)];
193
+ return { joints, feet };
194
+ }
195
+
196
+ // The trunk from the round rump over the tucked waist and lithe deep chest (brisket at half the shoulder), then the sleek neck
197
+ // meeting the occiput cleanly below the crown so there is no hump behind the ears.
198
+ function catTrunk(b, coat, detail) {
199
+ const { chest, rump } = A,
200
+ ring = (z, top, bottom, w, bone, sq = 2.15) => [(top + bottom) / 2, z, w, (top - bottom) / 2, (top - bottom) / 2, bone, sq];
201
+ tube(
202
+ b,
203
+ [
204
+ [0.85, zH - 0.16, 0, 0, 0, 0],
205
+ ring(zH - 0.11, 0.99, 0.71, 0.085, 0, 2.15),
206
+ ring(zH - 0.02, 1.02, 0.64, 0.134, 0, 2.3), // the round rump, highest behind the shoulders
207
+ [rump.y, zH + 0.11, rump.w, rump.h, rump.h, 0.15, rump.n], // the rump's section the thigh hangs inside
208
+ ring(zH + 0.3, 0.985, 0.6, 0.12, 0.5, 2.15), // supple tucked waist behind the ribs
209
+ ring(zH + 0.54, 0.97, 0.505, 0.136, 0.85, 2.15), // lithe feline ribcage, belly at half the shoulder
210
+ ring(zF - 0.28, 0.97, 0.495, 0.136, 0.92, 2.15),
211
+ [chest.y, zF - 0.08, chest.w, chest.h, chest.h, 1, chest.n], // deep narrow chest (brisket at 0.50)
212
+ ring(zF + 0.05, 0.975, 0.6, 0.11, 1.35, 2.1), // smooth breast-to-neck rise
213
+ [0.88, zF + 0.14, 0.094, 0.092, 0.098, 2.2, 2.08], // mid-neck
214
+ [0.96, zF + 0.2, 0.084, 0.08, 0.084, 3.2, 2.05], // upper neck entering occiput below crown
215
+ [1.01, zF + 0.25, 0.072, 0.068, 0.068, 3.9, 2.05], // seated inside back of skull
216
+ [1.01, zF + 0.28, 0, 0, 0, 4],
217
+ ],
218
+ {
219
+ chain: [BONE.hips, BONE.chest, BONE.neck, BONE.neck2, BONE.head],
220
+ around: RINGS.trunk[detail][0],
221
+ sub: RINGS.trunk[detail][1],
222
+ coat: coat(0),
223
+ },
224
+ );
225
+ }
226
+
227
+ // A leg as one skin: the shoulder or the thigh (level slices, geometry/animal-haunch.js) from inside the body, then the lower
228
+ // leg across its path, and a neat compact round cat paw.
229
+ function catLeg(b, coat, detail, s, hind) {
230
+ const f = LEGS[(hind ? 2 : 0) + (s > 0 ? 1 : 0)],
231
+ mix = (P, Q, k) => [P[0] + (Q[0] - P[0]) * k, P[1] + (Q[1] - P[1]) * k],
232
+ at = (P, w, front, back, bone, level = 0) => [P[0], P[1], w, front, back, bone, 2.1, 0, level],
233
+ lower = hind ? A.hock : A.wrist,
234
+ end = hind ? A.heel : A.knuckle,
235
+ S = hind
236
+ ? [
237
+ ...haunchStations(THIGH, { x: A.hx, hip: A.hip[0], stifle: A.stifle[0], hock: A.hock[0] }, A.rump, detail === 0),
238
+ at(lower, 0.024, 0.025, 0.04, 2.5, 1), // crisp backward-pointing hock bending cleanly into the metatarsus
239
+ at(mix(lower, end, 0.52), 0.022, 0.023, 0.025, 3, 0.4),
240
+ at(end, 0.027, 0.028, 0.028, 3),
241
+ [end[0] + 0.008, end[1] - 0.024, 0, 0, 0, 3],
242
+ ]
243
+ : [
244
+ ...haunchStations(SHOULDER, { x: A.sx, hip: A.shoulder[0], stifle: A.elbow[0], hock: A.wrist[0] }, A.chest, detail === 0),
245
+ at(lower, 0.026, 0.026, 0.028, 2.5, 1), // slender feline wrist
246
+ at(mix(lower, end, 0.5), 0.026, 0.026, 0.027, 3, 0.4),
247
+ at(end, 0.029, 0.029, 0.028, 3),
248
+ [end[0] + 0.008, end[1] - 0.024, 0, 0, 0, 3],
249
+ ];
250
+ const x = s * (hind ? A.hx : A.sx),
251
+ z = end[1];
252
+ tube(b, S, {
253
+ x,
254
+ side: s,
255
+ chain: [hind ? BONE.hips : BONE.chest, f, f + 1, f + 2],
256
+ around: RINGS.leg[detail][0],
257
+ sub: RINGS.leg[detail][1],
258
+ coat: coat(2),
259
+ lay: 1,
260
+ });
261
+ // Neat compact round cat paw resting on y = 0, slightly wider than the slender leg, with soft toe contours.
262
+ tube(
263
+ b,
264
+ [
265
+ [0.024, z - 0.028, 0, 0, 0, 0],
266
+ [0.024, z - 0.01, 0.038, 0.024, 0.024, 0, 2.1],
267
+ [0.022, z + 0.022, 0.046, 0.022, 0.022, 0, 2.15],
268
+ [0.018, z + 0.056, 0.042, 0.018, 0.018, 0, 2.15],
269
+ [0.012, z + 0.062, 0, 0, 0, 0],
270
+ ],
271
+ {
272
+ x,
273
+ side: s,
274
+ chain: [f + 3],
275
+ around: RINGS.leg[detail][0],
276
+ sub: RINGS.leg[detail][1],
277
+ coat: coat(2),
278
+ warp: (Q, q, a, v) => {
279
+ const toe = Math.abs(Math.sin(((Q[q] - x) / 0.046) * Math.PI * 2)),
280
+ part = sstep(0.55, 0.9, v) * (1 - toe) * 0.18;
281
+ Q[q + 1] = Math.max(0, Q[q + 1] - (Q[q + 1] - 0.005) * part);
282
+ },
283
+ },
284
+ );
285
+ }
286
+
287
+ // The tail, as long as the body and plush along its length, lying back and down from the rump in a soft curve at rest (the
288
+ // bearing raises it with a gentle hook when standing); its hair lies towards the tip.
289
+ function catTail(b, coat, detail) {
290
+ const [t0, t1, t2, t3] = A.tail,
291
+ mid = (P, Q, t) => [lerp(P[0], Q[0], t), lerp(P[1], Q[1], t)],
292
+ r = u => 0.048 * (1 - 0.36 * u * u), // plush even feline tail, softly tapered only at the tip
293
+ ring = (p, u, bone) => [...p, r(u), r(u), r(u), bone];
294
+ tube(
295
+ b,
296
+ [
297
+ [t0[0] - 0.02, t0[1] + 0.04, 0, 0, 0, 0], // closed inside the rump
298
+ ring(t0, 0, 0.4),
299
+ ring(mid(t0, t1, 0.5), 0.25, 1),
300
+ ring(t1, 0.5, 1.5),
301
+ ring(mid(t1, t2, 0.5), 0.75, 2),
302
+ ring(t2, 1, 2.5),
303
+ ring(t3, 1.2, 3),
304
+ [t3[0] - 0.03, t3[1] - 0.06, 0, 0, 0, 3],
305
+ ],
306
+ {
307
+ chain: [BONE.hips, BONE.tail, BONE.tail + 1, BONE.tail + 2],
308
+ around: RINGS.tail[detail][0],
309
+ sub: RINGS.tail[detail][1],
310
+ coat: coat(3),
311
+ lay: 1,
312
+ },
313
+ );
314
+ }
315
+
316
+ function catPlan(L) {
317
+ const H = catHeadPlan(L.head ?? 1),
318
+ HM = new THREE.Matrix4()
319
+ .makeTranslation(0, A.poll[0] * WITHERS, A.poll[1] * WITHERS)
320
+ .multiply(new THREE.Matrix4().makeRotationX(H.droop))
321
+ .multiply(new THREE.Matrix4().makeScale(WITHERS, WITHERS, WITHERS));
322
+ return { H, HM };
323
+ }
324
+
325
+ function catParts(L, H, HM, detail, options) {
326
+ const b = new GB(),
327
+ coat = catCoatOf(L, animalNoise(options).fbm);
328
+ b.sk = [];
329
+ b.sk2 = [];
330
+ b.skw = [];
331
+ b.tg = [];
332
+ b.M = new THREE.Matrix4().makeScale(WITHERS, WITHERS, WITHERS);
333
+ catTrunk(b, coat, detail);
334
+ for (const s of [-1, 1]) {
335
+ catLeg(b, coat, detail, s, false);
336
+ catLeg(b, coat, detail, s, true);
337
+ }
338
+ catTail(b, coat, detail);
339
+ b.M = HM;
340
+ catHead(b, H, L, coat, detail);
341
+ b.M = null;
342
+ return b.parts(true);
343
+ }
344
+
345
+ /**
346
+ * A house cat's skeleton and head plan (motion/animal-cat-bearing.js poses it; rendering/animal-canine-figure.js binds it when
347
+ * `look.breed === 'cat'`).
348
+ * @param {{ head?: number, tilt?: number }} [L={}] Optional head scale or tilt.
349
+ * @returns {{ rig: object, H: object, HM: THREE.Matrix4, joints: number[][] }}
350
+ */
351
+ function catRig(L = {}) {
352
+ const { H, HM } = catPlan(L),
353
+ headAt = (x, y, z) => new THREE.Vector3(x, y, z).applyMatrix4(HM).toArray(),
354
+ { joints, feet } = catJointsAt(H, headAt),
355
+ rig = makeRig(joints, feet, CAT_HABITS);
356
+ rig.isCat = true;
357
+ rig.breed = { head: H.size, leer: 0, tilt: L.tilt ?? 0 };
358
+ return { rig, H, HM, joints };
359
+ }
360
+
361
+ /**
362
+ * The arrays of a house cat's two skinned meshes, `[far, near]`, as `geometryOf` (geometry/builder.js) takes them. Arithmetic
363
+ * only, so a worker pool can build them off the main thread.
364
+ * @param {{ c1?: number, c2?: number, c3?: number, eye?: number | number[], head?: number }} [L={}] Coat and eye colours.
365
+ * @param {number} [near=2] Near mesh detail: 2 figure, 1 herd middle skin, 0 far skin for both.
366
+ * @param {import('./animal-options.js').AnimalKitOptions} [options]
367
+ */
368
+ function catBodies(L = {}, near = NEAR, options = NO_ANIMAL_OPTIONS) {
369
+ const { H, HM } = catPlan(L),
370
+ far = catParts(L, H, HM, 0, options);
371
+ return [far, near ? catParts(L, H, HM, near, options) : far];
372
+ }
373
+
374
+ export { CAT_HABITS, WITHERS as CAT_WITHERS, catBodies, catRig };