roamwright 0.60.0 → 0.61.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.
@@ -1,164 +1,328 @@
1
+ /**
2
+ * Build animated poses of a domestic farm hen (standing, walking, pecking and settled) as static triangle geometries for instanced herds.
3
+ * @module
4
+ */
5
+
1
6
  import * as THREE from 'three';
2
- import { C, TRS, stick } from './primitives.js';
7
+ import { C, TRS } from './primitives.js';
3
8
  import { GB, geometryOf } from './builder.js';
4
- import { SHAPES } from './animal-shapes.js';
9
+ import { leaf, scatter, tube } from './animal-skin.js';
10
+ import { henHead, shadeHen as shade } from './animal-hen-head.js';
5
11
 
6
12
  // ════════════════════════════════════════════════════════════════════════
7
- // A hen of a yard, in metres, facing +z and standing on y 0: a deep, rounded body carried breast-high, a short tail fanned
8
- // upright behind, wings folded close; a neck of hackles to a small head with a horn beak, a red serrated comb and wattles;
9
- // feathered thighs, and bare yellow shanks to four toes that grip the ground. It is cast in still poses for a herd of the crowds
10
- // (motion/animal-herd-cast.js): its walk (the feet set down in turn, the head held still in the air while the body passes under it, then
11
- // thrust on), pecking at the ground (the head held low watching it, then driven down and forward to strike, the body leaning
12
- // with it), and settling down on its belly. Arithmetic only, so the pool's workers cast it.
13
+ // A hen of a yard, in metres, facing +z and standing on y 0: a deep, boat-shaped feathered body carried breast-high,
14
+ // an S-curved neck of layered hackles rising smoothly into a compact head with a two-part horn beak, a continuous red
15
+ // serrated comb and pendant wattles; smooth folded wings with dark primary tips, an upright fanned tail, feathered
16
+ // drumsticks, and slender tapered yellow shanks to four clawed toes that grip the ground. Cast in still poses for
17
+ // instanced crowds (motion/animal-herd-cast.js): arithmetic only, so workers can cast it.
13
18
  // ════════════════════════════════════════════════════════════════════════
14
19
  const COATS = {
15
- // body, hackles, tail, wing tips: a red-brown hen with golden hackles, a white one, a black one with a green sheen, a grey
16
- brown: [0x96522a, 0xc4883e, 0x4a3a2c, 0x6a3e22],
17
- white: [0xe6e2d6, 0xeeeadc, 0xdcd8cc, 0xcfcabc],
18
- black: [0x45464c, 0x4c5250, 0x3e4446, 0x404046],
19
- grey: [0x8a867c, 0xa8a090, 0x4a4640, 0x6a665e],
20
+ // body, hackles, tail, wing tips: red-brown with golden hackles, white, black with a green sheen, grey
21
+ brown: [0x8e4c26, 0xbc823a, 0x3b2d22, 0x5c341c],
22
+ white: [0xe4dfd2, 0xede8da, 0xd8d3c6, 0xcac5b6],
23
+ black: [0x3d3e44, 0x454c4a, 0x343b3e, 0x36363c],
24
+ grey: [0x848076, 0xa29a8a, 0x45413b, 0x625e56],
20
25
  },
21
- RED = 0xa81e1a, // comb and wattles
22
- HORN = 0xc89a48, // the beak
23
- SHANK = 0xd2aa3a, // the bare legs and toes
24
- EYE = 0x9a5a14,
25
- BODY_Y = 0.235, // the body's middle over the ground standing, metres
26
- PITCH = -0.18, // the body carried breast up, radians (about x, front down positive)
27
- NECK = [0, 0.075, 0.1], // where the neck leaves the body, in the body's frame
28
- HEAD = [0.36, 0.15], // the head's height and how far forward of the feet it is carried
29
- HIP = [0.042, -0.05, 0.005], // a hip in the body's frame (x to the side)
30
- THIGH = 0.1, // hip to hock, metres
31
- SHIN = 0.085, // hock to foot
32
- FOOT_X = 0.045, // a foot's way out to the side
26
+ CLAW = 0x564632, // dark horn toe tips
27
+ SHANK = 0xcda438, // the bare scaly legs and toes
28
+ BODY_Y = 0.228, // the body's middle over the ground standing, metres
29
+ PITCH = -0.16, // the body carried breast up, radians (about x, front down positive)
30
+ NECK_ROOT = [0, 0.042, 0.074], // where the neck emerges smoothly from the upper breast, in the body's frame
31
+ HEAD = [0.352, 0.148], // the head's height and how far forward of the feet it is carried
32
+ HIP = [0.042, -0.036, 0.004], // a hip in the body's frame (x to the side)
33
+ THIGH = 0.102, // hip to hock, metres
34
+ SHIN = 0.086, // hock to ankle
35
+ FOOT_X = 0.044, // a foot's way out to the side
33
36
  STEP_LENGTH = 0.11, // how far a foot passes back under the body while it stands
34
37
  DUTY = 0.62, // the share of a stride a foot is on the ground
35
38
  LIFT = 0.035, // how high a foot is carried
36
39
  BOB = 0.7, // the share of a step the head is held still in the air before it is thrust on
37
- // pecking: the body's pitch and how far it is lowered, and the head's height, reach and bow, standing, watching the ground
38
- // between strikes, and at the strike, beak to the ground
40
+ // pecking: the body's pitch and how far it is lowered, and the head's height, reach and bow
39
41
  STAND = { pitch: PITCH, drop: 0, head: [HEAD[0], HEAD[1], 0] },
40
- WATCH = { pitch: 0.04, drop: 0.004, head: [0.2, 0.19, 0.6] },
41
- STRIKE = { pitch: 0.38, drop: 0.012, head: [0.035, 0.215, 1.25] },
42
- PECK_STEPS = 8, // poses after standing in the peck's series: standing to watching over its first half, watching to the strike over its second
43
- SETTLE = { y: 0.125, head: [0.3, 0.12] }, // settled: the body's height, and the head drawn in
42
+ WATCH = { pitch: 0.04, drop: 0.004, head: [0.205, 0.19, 0.6] },
43
+ STRIKE = { pitch: 0.36, drop: 0.012, head: [0.038, 0.215, 1.25] },
44
+ PECK_STEPS = 8, // poses after standing in the peck's series
45
+ SETTLE = { y: 0.118, head: [0.292, 0.12] }, // settled: body height and head drawn in
44
46
  REST_STEPS = 4, // poses after standing in each rest's series
47
+ CHAIN = [0],
45
48
  _a = new THREE.Vector3(),
46
49
  _b = new THREE.Vector3(),
47
- _m = new THREE.Matrix4(),
48
- EGG = new THREE.IcosahedronGeometry(0.5, 1).translate(0, 0.5, 0), // a ball standing on its foot, laid between two points by stick
49
- BEAD = new THREE.IcosahedronGeometry(0.5, 0), // a ball of twenty faces, for what is a few millimetres across
50
- NECK_TUBE = new THREE.CylinderGeometry(0.27, 0.5, 1, 8, 2).translate(0, 0.5, 0); // a neck narrowing to the head
50
+ _h = new THREE.Vector3(),
51
+ _bodyM = new THREE.Matrix4(),
52
+ _m = new THREE.Matrix4();
51
53
 
52
54
  // The body's frame for a pose: up to its height, pitched and rolled.
53
- const bodyFrame = pose => new THREE.Matrix4().copy(TRS(0, pose.y, 0, 1, 1, 1, 0, pose.pitch, pose.roll));
54
- const inBody = (B, x, y, z) => new THREE.Vector3(x, y, z).applyMatrix4(B);
55
+ const bodyFrame = pose => _bodyM.copy(TRS(0, pose.y, 0, 1, 1, 1, 0, pose.pitch, pose.roll));
56
+ const inBody = (B, x, y, z, out) => out.set(x, y, z).applyMatrix4(B);
55
57
 
56
- // The body, breast, fluff, wings and tail, in the body's frame.
57
- function body(b, c) {
58
- const [main, hackle, tail, tip] = c.map(h => C(h));
59
- b.add(SHAPES.head, main, TRS(0, 0, -0.01, 0.16, 0.17, 0.27));
60
- b.add(
61
- SHAPES.head,
62
- hackle.map((v, i) => (v + main[i]) / 2),
63
- TRS(0, -0.015, 0.085, 0.14, 0.15, 0.15),
58
+ // Continuous feathered torso, close-folded wings with dark primary tips, and an upright fanned tail, all in the body's frame.
59
+ function body(b, cols) {
60
+ const [main, hackle, tailCol, tip] = cols;
61
+ // Boat-shaped torso from fluffy rump under the tail through the concave back saddle to the full rounded breast
62
+ tube(
63
+ b,
64
+ [
65
+ [0.008, -0.158, 0, 0, 0, 0],
66
+ [-0.006, -0.132, 0.062, 0.054, 0.062, 0, 2.05],
67
+ [-0.01, -0.072, 0.08, 0.062, 0.08, 0, 2.1],
68
+ [-0.004, 0.006, 0.082, 0.062, 0.084, 0, 2.1],
69
+ [0.004, 0.076, 0.072, 0.058, 0.072, 0, 2.05],
70
+ [0.008, 0.118, 0.046, 0.044, 0.044, 0, 2],
71
+ [0.008, 0.142, 0, 0, 0, 0],
72
+ ],
73
+ {
74
+ chain: CHAIN,
75
+ sub: 2,
76
+ around: 14,
77
+ coat: (col, x, y, z, nx, ny, nz, a, v) => {
78
+ // Golden/lighter hackle tint spills down the upper breast and shoulders; underbelly and rump fluff sit darker
79
+ const cape = Math.max(0, (v - 0.56) * 2.2) * (0.45 + 0.55 * Math.max(0, ny * 0.5 + 0.5));
80
+ const grain = 0.94 + 0.1 * scatter(Math.floor(v * 26) * 19 + Math.floor(a * 5));
81
+ const bell = ny < -0.25 ? 0.84 : 1;
82
+ shade(col, main, hackle, cape, grain * bell, 0);
83
+ },
84
+ },
64
85
  );
65
- b.add(SHAPES.sph, main, TRS(0, -0.035, -0.095, 0.15, 0.12, 0.15)); // the fluff under the tail
86
+ // Folded wings: almond-shaped feathered shields curving neatly along each flank, plus tucked primary tips
66
87
  for (const s of [-1, 1]) {
67
- b.add(
68
- SHAPES.sph,
69
- main.map(v => v * 0.85),
70
- TRS(s * 0.066, 0.012, -0.015, 0.035, 0.11, 0.2, 0, 0.08, s * 0.12),
88
+ tube(
89
+ b,
90
+ [
91
+ [0.006, -0.118, 0, 0, 0, 0, 2, -0.012],
92
+ [0.01, -0.095, 0.014, 0.028, 0.026, 0, 2.1, -0.002],
93
+ [0.014, -0.028, 0.024, 0.048, 0.052, 0, 2.15, 0.008],
94
+ [0.016, 0.042, 0.023, 0.044, 0.048, 0, 2.1, 0.004],
95
+ [0.018, 0.086, 0, 0, 0, 0, 2, -0.016],
96
+ ],
97
+ {
98
+ x: s * 0.068,
99
+ side: s,
100
+ chain: CHAIN,
101
+ sub: 2,
102
+ around: 10,
103
+ coat: (col, x, y, z, nx, ny, nz, a, v) => {
104
+ const tipMix = Math.max(0, (0.34 - v) * 2.4);
105
+ const bar = 0.93 + 0.1 * Math.sin(v * 28 + a * 2);
106
+ shade(col, main, tip, tipMix, 0.92 * bar, 0);
107
+ },
108
+ },
109
+ );
110
+ // Primary flight-feather tips emerging cleanly from under the rear edge of the folded wing
111
+ tube(
112
+ b,
113
+ [
114
+ [0.008, -0.148, 0, 0, 0, 0, 2, -0.01],
115
+ [0.006, -0.122, 0.011, 0.02, 0.018, 0, 2.2, -0.002],
116
+ [0.006, -0.086, 0.014, 0.022, 0.022, 0, 2.1, 0.002],
117
+ [0.006, -0.068, 0, 0, 0, 0, 2, -0.008],
118
+ ],
119
+ {
120
+ x: s * 0.062,
121
+ side: s,
122
+ chain: CHAIN,
123
+ sub: 1,
124
+ around: 8,
125
+ coat: col => shade(col, tip, tailCol, 0.35, 0.96, 0),
126
+ },
71
127
  );
72
- b.add(SHAPES.sph, tip, TRS(s * 0.06, -0.004, -0.12, 0.026, 0.05, 0.1, 0, 0.1, s * 0.1)); // the primaries, tucked under
73
128
  }
74
- // the tail: five feathers fanned upright and swept back
75
- for (let i = -2; i <= 2; i++) b.add(SHAPES.sph, tail, TRS(i * 0.012, 0.075, -0.15, 0.014, 0.12, 0.06, 0, -0.45, -i * 0.16));
76
- }
77
-
78
- // The head and its comb, wattles, beak and eyes, in the head's frame.
79
- function head(b, c) {
80
- const red = C(RED);
81
- b.add(SHAPES.sph, C(c[1]), TRS(0, 0, 0, 0.042, 0.048, 0.058));
82
- b.tv = 1;
83
- b.add(SHAPES.cone, C(HORN), TRS(0, -0.006, 0.024, 0.016, 0.028, 0.013, 0, Math.PI / 2 + 0.25));
84
- for (let i = 0; i < 4; i++) b.add(BEAD, red, TRS(0, 0.028 + 0.004 * Math.sin(i * 1.1), 0.022 - i * 0.014, 0.008, 0.024, 0.016));
85
- for (const s of [-1, 1]) {
86
- b.add(BEAD, red, TRS(s * 0.007, -0.032, 0.02, 0.01, 0.024, 0.016));
87
- b.add(BEAD, red, TRS(s * 0.021, -0.01, -0.006, 0.006, 0.012, 0.01)); // the earlobe
88
- b.tv = 2;
89
- b.add(BEAD, C(EYE), TRS(s * 0.019, 0.008, 0.012, 0.012, 0.012, 0.012));
90
- b.tv = 1;
129
+ // Upright fanned tail: seven overlapping double-sided feathers arranged in a hen's inverted-V tent (broad in profile, V-fan from behind)
130
+ const innerTail = tailCol.map(v => v * 0.86);
131
+ for (let i = -3; i <= 3; i++) {
132
+ const f = i / 3,
133
+ af = Math.abs(f),
134
+ len = 0.135 - af * 0.02,
135
+ wide = 0.042 - af * 0.004,
136
+ pitch = 0.96 - af * 0.24,
137
+ splay = f * 0.34,
138
+ // Feather spine rises up and back; its width runs across the side profile so the tail reads broad from the side and tapered from behind
139
+ up = [Math.sin(splay) * 0.36, Math.sin(pitch), -Math.cos(pitch)],
140
+ ul = Math.hypot(up[0], up[1], up[2]),
141
+ ux = up[0] / ul,
142
+ uy = up[1] / ul,
143
+ uz = up[2] / ul,
144
+ // Sideways normal tilts outward from the centreline in an inverted V
145
+ fx = f === 0 ? 0.96 : Math.sign(f) * 0.88,
146
+ fy = 0.28,
147
+ fz = 0.24 + af * 0.18,
148
+ across = [uy * fz - uz * fy, uz * fx - ux * fz, ux * fy - uy * fx],
149
+ al = Math.hypot(across[0], across[1], across[2]) || 1,
150
+ ax = across[0] / al,
151
+ ay = across[1] / al,
152
+ az = across[2] / al,
153
+ front = [ay * uz - az * uy, az * ux - ax * uz, ax * uy - ay * ux],
154
+ fl = Math.hypot(front[0], front[1], front[2]) || 1;
155
+ leaf(
156
+ b,
157
+ [i * 0.0045, 0.022 - af * 0.01, -0.126 + af * 0.01],
158
+ [ux, uy, uz],
159
+ [ax, ay, az],
160
+ [front[0] / fl, front[1] / fl, front[2] / fl],
161
+ len,
162
+ wide,
163
+ 0.06,
164
+ 0.88,
165
+ af > 0.7 ? tip : tailCol,
166
+ innerTail,
167
+ 0,
168
+ 0.12,
169
+ true,
170
+ );
91
171
  }
92
- b.tv = 0;
93
172
  }
94
173
 
95
- // The neck from where it leaves the body to the head, thick with hackles at its foot.
96
- function neck(b, c, from, to) {
97
- const col = C(c[1]),
98
- foot = [from.x, from.y - 0.03, from.z - 0.02];
99
- stick(b, foot, [to.x, to.y - 0.012, to.z - 0.012], 0.085, col, NECK_TUBE); // tapering into the back of the head
100
- stick(b, foot, [(from.x + to.x) / 2, (from.y + to.y) / 2, (from.z + to.z) / 2 - 0.01], 0.1, col, EGG); // the hackles' flare
174
+ // Smooth S-curved neck of layered hackles bridging the upper breast seamlessly to the back of the head.
175
+ function neck(b, cols, from, to) {
176
+ const [main, hackle] = cols,
177
+ dy = to.y - from.y,
178
+ dz = to.z - from.z,
179
+ // Stand upright -> graceful S-curve (belly of neck bows slightly back then forward to skull); pecking -> extends cleanly
180
+ sCurve = Math.max(0, Math.min(1, dy / 0.14)),
181
+ p0y = from.y - 0.024,
182
+ p0z = from.z - 0.018,
183
+ p4y = to.y - 0.006,
184
+ p4z = to.z - 0.014,
185
+ p1y = p0y + dy * 0.26,
186
+ p1z = p0z + dz * 0.24 - 0.004 * sCurve,
187
+ p2y = p0y + dy * 0.6,
188
+ p2z = p0z + dz * 0.54 - 0.014 * sCurve,
189
+ p3y = p0y + dy * 0.86,
190
+ p3z = p0z + dz * 0.82 - 0.006 * sCurve;
191
+ tube(
192
+ b,
193
+ [
194
+ [p0y - 0.018, p0z - 0.012, 0, 0, 0, 0],
195
+ [p0y, p0z, 0.056, 0.056, 0.058, 0, 2.05], // broad hackle cape merging seamlessly into shoulders and breast
196
+ [p1y, p1z, 0.044, 0.044, 0.046, 0, 2.05],
197
+ [p2y, p2z, 0.03, 0.031, 0.031, 0, 2],
198
+ [p3y, p3z, 0.022, 0.023, 0.022, 0, 2],
199
+ [p4y, p4z, 0.018, 0.019, 0.018, 0, 2],
200
+ ],
201
+ {
202
+ chain: CHAIN,
203
+ sub: 2,
204
+ around: 10,
205
+ coat: (col, x, y, z, nx, ny, nz, a, v) => {
206
+ // Blend smoothly from torso main plumage at the root into golden hackles up the neck
207
+ const hackleMix = Math.min(1, 0.3 + v * 0.9);
208
+ const grain = 0.94 + 0.1 * scatter(Math.floor(v * 20) * 13 + Math.floor(a * 4));
209
+ shade(col, main, hackle, hackleMix, grain, 0);
210
+ },
211
+ },
212
+ );
101
213
  }
102
214
 
103
- // A leg from its hip (in the world) to its foot at (x, lift, z): the thigh in feathers to the hock, which bends back, the bare
104
- // shank, and the toes: three spread ahead and one behind, curled while the foot is carried.
105
- function leg(b, c, hip, x, lift, z) {
106
- const foot = _b.set(x, lift + 0.012, z),
215
+ // A leg from its hip (in world space) to its foot at (x, lift, z): a smooth feathered drumstick blending from the belly
216
+ // down to the backward-bent hock, a slender tapered yellow shank, and four clawed toes gripping y = 0.
217
+ function leg(b, cols, hip, x, lift, z) {
218
+ const s = x < 0 ? -1 : 1,
219
+ foot = _b.set(x, lift + 0.01, z),
107
220
  dy = foot.y - hip.y,
108
221
  dz = foot.z - hip.z,
109
- d = Math.min(THIGH + SHIN - 0.002, Math.max(Math.abs(THIGH - SHIN) + 0.01, Math.hypot(dy, dz))),
110
- uy = dy / Math.hypot(dy, dz),
111
- uz = dz / Math.hypot(dy, dz),
222
+ dist = Math.hypot(dy, dz) || 1e-4,
223
+ d = Math.min(THIGH + SHIN - 0.002, Math.max(Math.abs(THIGH - SHIN) + 0.01, dist)),
224
+ uy = dy / dist,
225
+ uz = dz / dist,
112
226
  along = (THIGH * THIGH - SHIN * SHIN + d * d) / (2 * d),
113
227
  out = Math.sqrt(Math.max(0, THIGH * THIGH - along * along)),
114
- hock = [x, hip.y + uy * along - uz * out, hip.z + uz * along + uy * out], // bent back: a bird's hock is its ankle
115
- ankle = [x, hip.y + uy * d, hip.z + uz * d],
116
- curl = lift > 0.004 ? 0.7 : 0.12,
117
- yellow = C(SHANK);
118
- stick(
228
+ hockY = hip.y + uy * along - uz * out,
229
+ hockZ = hip.z + uz * along + uy * out, // bent back: a bird's hock is its ankle
230
+ ankleY = hip.y + uy * d,
231
+ ankleZ = hip.z + uz * d,
232
+ curl = lift > 0.004 ? 0.65 : 0.08,
233
+ main = cols[0],
234
+ tip = cols[3],
235
+ yellow = C(SHANK),
236
+ yellowDark = yellow.map(v => v * 0.84),
237
+ clawCol = C(CLAW);
238
+ // Feathered drumstick tapering cleanly from deep inside the lower flank down to the hock joint
239
+ const topY = hip.y + 0.036,
240
+ topZ = hip.z + 0.004,
241
+ leanIn = (hip.x - x) * s;
242
+ tube(
119
243
  b,
120
- [hip.x, hip.y + 0.02, hip.z],
121
- hock,
122
- 0.062,
123
- C(c[0]).map(v => v * 0.9),
124
- EGG,
244
+ [
245
+ [topY + 0.01, topZ, 0.022, 0.024, 0.024, 0, 2, leanIn - 0.006],
246
+ [topY - 0.006, topZ, 0.036, 0.038, 0.04, 0, 2.05, leanIn],
247
+ [(topY + hockY) * 0.5, (topZ + hockZ) * 0.5 + 0.004, 0.028, 0.03, 0.032, 0, 2, leanIn * 0.5],
248
+ [hockY + 0.018, hockZ + 0.004, 0.016, 0.017, 0.017, 0, 2, 0],
249
+ [hockY - 0.004, hockZ, 0.009, 0.009, 0.009, 0, 2, 0],
250
+ ],
251
+ {
252
+ x,
253
+ side: s,
254
+ chain: CHAIN,
255
+ sub: 1,
256
+ around: 10,
257
+ coat: (col, px, py, pz, nx, ny, nz, a, v) => shade(col, main, tip, v * 0.4, 0.9, 0),
258
+ },
125
259
  );
126
- b.tv = 1;
127
- stick(b, hock, ankle, 0.014, yellow);
260
+ // Bare scaly yellow shank from hock down to ankle
261
+ tube(
262
+ b,
263
+ [
264
+ [hockY + 0.004, hockZ, 0.0082, 0.0085, 0.0085, 0, 2],
265
+ [(hockY + ankleY) * 0.5, (hockZ + ankleZ) * 0.5, 0.0058, 0.0062, 0.0062, 0, 2],
266
+ [ankleY + 0.008, ankleZ, 0.0065, 0.0068, 0.0068, 0, 2],
267
+ [ankleY - 0.004, ankleZ, 0.008, 0.008, 0.008, 0, 2],
268
+ ],
269
+ {
270
+ x,
271
+ side: s,
272
+ chain: CHAIN,
273
+ sub: 1,
274
+ around: 8,
275
+ coat: (col, px, py, pz, nx, ny, nz, a, v) => shade(col, yellowDark, yellow, 0.5 + 0.5 * v, 1, 1),
276
+ },
277
+ );
278
+ // Four tapered toes with dark horn claws: three splayed ahead and one hallux behind
128
279
  for (const [turn, len] of [
129
- [-0.45, 0.048],
130
- [0, 0.055],
131
- [0.45, 0.048],
132
- [Math.PI, 0.024],
133
- ])
134
- stick(
280
+ [-0.44, 0.048],
281
+ [0, 0.056],
282
+ [0.44, 0.048],
283
+ [Math.PI, 0.026],
284
+ ]) {
285
+ const drop = Math.min(ankleY - 0.0025, len * Math.sin(curl)),
286
+ reach = len * Math.cos(curl);
287
+ b.M = _m.copy(TRS(x, ankleY, ankleZ, 1, 1, 1, turn));
288
+ tube(
135
289
  b,
136
- ankle,
137
- [x + Math.sin(turn) * len, Math.max(0.002, ankle[1] - len * Math.sin(curl)), ankle[2] + Math.cos(turn) * len * Math.cos(curl)],
138
- 0.008,
139
- yellow,
290
+ [
291
+ [0, 0, 0.0048, 0.0048, 0.0046, 0, 2],
292
+ [-drop * 0.65, reach * 0.55, 0.0036, 0.0036, 0.0034, 0, 2],
293
+ [-drop, reach * 0.88, 0.0024, 0.0024, 0.0022, 0, 2],
294
+ [-drop - 0.001, reach + 0.004, 0, 0, 0, 0],
295
+ ],
296
+ {
297
+ chain: CHAIN,
298
+ sub: 1,
299
+ around: 6,
300
+ coat: (col, px, py, pz, nx, ny, nz, a, v) => shade(col, yellow, clawCol, v > 0.78 ? (v - 0.78) * 4.5 : 0, 1, 1),
301
+ },
140
302
  );
141
- b.tv = 0;
303
+ }
304
+ b.M = null;
142
305
  }
143
306
 
144
- // A hen of coat c in pose p (henPose) as a plain geometry: its position, normal, colour and tag arrays.
307
+ // A hen of coat c in pose p as a plain geometry: its position, normal, colour and tag arrays.
145
308
  function henGeometry(c, p) {
146
309
  const b = new GB(),
147
- B = bodyFrame(p);
310
+ B = bodyFrame(p),
311
+ cols = c.map(h => C(h));
148
312
  b.tg = [];
149
313
  b.tv = 0;
150
314
  b.M = B;
151
- body(b, c);
315
+ body(b, cols);
152
316
  b.M = null;
153
- const from = inBody(B, ...NECK),
317
+ const from = inBody(B, NECK_ROOT[0], NECK_ROOT[1], NECK_ROOT[2], _h),
154
318
  to = _a.set(0, p.head[0], p.head[1]);
155
- neck(b, c, from, to);
319
+ neck(b, cols, from, to);
156
320
  b.M = _m.copy(TRS(0, p.head[0], p.head[1], 1, 1, 1, 0, p.head[2]));
157
- head(b, c);
321
+ henHead(b, cols);
158
322
  b.M = null;
159
323
  for (let k = 0; k < 2; k++) {
160
324
  const s = k ? 1 : -1;
161
- leg(b, c, inBody(B, s * HIP[0], HIP[1], HIP[2]), s * FOOT_X, p.feet[k][1], p.feet[k][0]);
325
+ leg(b, cols, inBody(B, s * HIP[0], HIP[1], HIP[2], _h), s * FOOT_X, p.feet[k][1], p.feet[k][0]);
162
326
  }
163
327
  const geo = geometryOf(b.parts(true));
164
328
  b.release();
@@ -198,8 +362,7 @@ function walking(phase) {
198
362
  return p;
199
363
  }
200
364
 
201
- // A rest at f (0 standing, 1 its full): pecking at the ground, or settled on its belly. The peck's poses lie evenly along the
202
- // way from standing to watching to the strike, so that its timing (a crowd's peck) alone gives it its ease.
365
+ // A rest at f (0 standing, 1 its full): pecking at the ground, or settled on its belly.
203
366
  function resting(rest, f) {
204
367
  const p = standing(),
205
368
  e = f * f * (3 - 2 * f);
@@ -220,7 +383,11 @@ function resting(rest, f) {
220
383
  return p;
221
384
  }
222
385
 
223
- // A hen of `coat` for a herd: its skins (the standing pose), a skin cast in the pose now set, and its rests and walk cast as `cast` says.
386
+ /**
387
+ * Create a hen pose caster for an instanced herd (`motion/animal-herd-cast.js`).
388
+ * @param {{ coat?: 'brown' | 'white' | 'black' | 'grey', moments: number, rests: string[] }} options
389
+ * @returns {{ skins: THREE.BufferGeometry[], skin: () => THREE.BufferGeometry, frames: (cast: () => unknown) => { rests: unknown[][], walk: { frames: unknown[], stride: number } } }}
390
+ */
224
391
  function henHerd({ coat, moments, rests }) {
225
392
  const c = COATS[coat] ?? COATS.brown;
226
393
  let pose = standing();
@@ -5,6 +5,7 @@ import { GB, geometryOf } from './builder.js';
5
5
  import { indexParts } from './index-parts.js';
6
6
  import { NO_ANIMAL_OPTIONS, animalNoise, presetOf } from './animal-options.js';
7
7
  import { tube } from './animal-skin.js';
8
+ import { haunchStations } from './animal-haunch.js';
8
9
  import { ear, eyeWithLids } from './animal-horse-face.js';
9
10
  import { MEALY, SLEEK, coatOf, codedCoat, skinOf } from './animal-horse-coat.js';
10
11
  import { forelock, hair } from './animal-horse-hair.js';
@@ -66,7 +67,8 @@ const HABITS = {
66
67
  ],
67
68
  };
68
69
 
69
- // Where the joints are, in withers heights: [y, z] in the body's upright plane.
70
+ // Where the joints are, in withers heights: [y, z] in the body's upright plane; how much narrower than the barrel the breast is;
71
+ // and the rump's section at the hips (the ring over them in trunkStations), for the thigh to hang inside (geometry/animal-haunch.js).
70
72
  function anatomy(p) {
71
73
  const carriage = lerp(0.35, 1.05, p.neck[2]),
72
74
  reach = 0.5 * p.neck[0],
@@ -82,16 +84,21 @@ function anatomy(p) {
82
84
  // the stifle high against the flank, a little ahead of the hoof; the gaskin sloping back from it to a hock under the
83
85
  // buttock at about the front knee's height; the cannon near upright and the pastern sloping forward to the hoof
84
86
  hip: [0.8, zH + 0.02],
85
- stifle: [0.63, zH + 0.13],
86
- hock: [0.37, zH - 0.1],
87
+ stifle: [0.62, zH + 0.14],
88
+ hock: [0.37, zH - 0.115],
87
89
  hindFetlock: [0.105, zH - 0.065],
88
90
  hindHoof: [0, zH - 0.02],
89
91
  neck,
90
92
  poll: [neck[0] + reach * Math.sin(carriage), neck[1] + reach * Math.cos(carriage)],
91
93
  dock: [0.95, zH - 0.19],
92
94
  hands: [1.09, zF - 0.05], // where a rider's hands hold the reins, over the withers
95
+ breast: z => lerp(1, p.chest ?? 1, sstep(zF - 0.3, zF, z)), // a mule narrow at the breast
96
+ rump: { y: 0.785, h: 0.207, w: 0.172 * p.girth, n: RUMP_SQUARE }, // the mule's narrow breast is forward of the hips
93
97
  };
94
98
  }
99
+ /** The squareness of the rump's sections (the rings from the croup to the loin): gently fuller than the barrel's so the rump's
100
+ * side flows smoothly into the thigh without flattening the rounded equine croup. */
101
+ const RUMP_SQUARE = 2.65;
95
102
 
96
103
  // The bones' joints and the hooves, in metres.
97
104
  function jointsAt(A, p, K, headAt) {
@@ -131,7 +138,7 @@ function jointsAt(A, p, K, headAt) {
131
138
  function trunkStations(A, p) {
132
139
  const g = p.girth,
133
140
  nt = p.neck[1],
134
- breast = z => lerp(1, p.chest ?? 1, sstep(zF - 0.3, zF, z)), // a mule narrow at the breast
141
+ breast = A.breast, // a mule narrow at the breast
135
142
  ring = (z, top, bottom, w, bone, sq = 2.25) => [
136
143
  (top + bottom) / 2,
137
144
  z,
@@ -143,11 +150,12 @@ function trunkStations(A, p) {
143
150
  ],
144
151
  mid = [(A.neck[0] + A.poll[0]) / 2 + 0.01, (A.neck[1] + A.poll[1]) / 2 - 0.01];
145
152
  return [
146
- [0.86, zH - 0.215, 0, 0, 0, 0],
147
- ring(zH - 0.185, 0.955, 0.7, 0.09, 0, 2.4),
148
- ring(zH - 0.08, 0.988, 0.615, 0.158, 0, 2.5),
149
- ring(zH + 0.06, 0.992, 0.598, 0.168, 0, 2.4),
150
- ring(zH + 0.22, 0.958, 0.582, 0.164, 0.5),
153
+ [0.828, zH - 0.228, 0, 0, 0, 0],
154
+ // the rump's sections stay smoothly rounded while carrying enough depth at the flank for the thigh to emerge cleanly
155
+ ring(zH - 0.185, 0.955, 0.7, 0.092, 0, 2.4),
156
+ ring(zH - 0.08, 0.988, 0.615, 0.158, 0, 2.6),
157
+ [A.rump.y, zH + 0.06, A.rump.w, A.rump.h, A.rump.h, 0, A.rump.n], // the rump's section the thigh hangs inside
158
+ ring(zH + 0.22, 0.958, 0.582, 0.164, 0.5, 2.5),
151
159
  ring(zH + 0.4, 0.938, 0.548, 0.174, 0.9),
152
160
  ring(zF - 0.2, 0.945, 0.54, 0.17, 1),
153
161
  ring(zF - 0.09, 0.985, 0.548, 0.158, 1),
@@ -161,6 +169,23 @@ function trunkStations(A, p) {
161
169
  ];
162
170
  }
163
171
 
172
+ // A hind leg's thigh, from the croup down to just above the hock, as level slices (geometry/animal-haunch.js): height, front edge,
173
+ // back edge, half-width, lean. Real proportions, in withers heights: the hip joint 0.80, the stifle 0.63 (at the flank fold,
174
+ // 0.11 ahead of the hip), the hock 0.37 (a third of the leg, 0.12 behind the hip); the buttock 0.19 behind the hip; the gaskin
175
+ // sweeps cleanly back along the tibia from the stifle to the point of the hock so the thigh never overhangs below the belly.
176
+ function thighOf(p) {
177
+ const g = p.girth ** 0.75,
178
+ t = p.bone ** 0.6;
179
+ return [
180
+ [0.94, zH + 0.06, zH - 0.13, 0, -0.06 * g, 2], // closed inside the upper croup
181
+ [0.85, zH + 0.1, zH - 0.17, 0.062 * g, -0.04 * g, 2], // upper quarter tucked smoothly inside croup
182
+ [0.74, zH + 0.142, zH - 0.185, 0.074 * g, -0.016 * g, 2], // rounded equine quarter flush-tangent with croup
183
+ [0.62, zH + 0.172, zH - 0.12, 0.063 * g, -0.006 * g, 2], // rounded stifle forward at the flank fold
184
+ [0.52, zH + 0.085, zH - 0.12, 0.044 * g, 0, 2], // muscular upper gaskin sloping back along the tibia
185
+ [0.44, zH - 0.025, zH - 0.14, 0.033 * t, 0, 2], // tapered lower gaskin / Achilles tendon above the hock
186
+ ];
187
+ }
188
+
164
189
  // A leg from the shoulder blade or the quarter down to the fetlock, then the pastern and the hoof.
165
190
  function leg(b, A, p, coat, q, s, hind) {
166
191
  const t = p.bone,
@@ -168,36 +193,30 @@ function leg(b, A, p, coat, q, s, hind) {
168
193
  f = LEGS[i],
169
194
  skin = skinOf(coat, i),
170
195
  mix = (P, Q, k, dz = 0) => [P[0] + (Q[0] - P[0]) * k, P[1] + (Q[1] - P[1]) * k + dz],
171
- at = (P, w, front, back, bone, lean = 0) => [P[0], P[1], w * t, front * t, back * t, bone, 2.2, lean];
196
+ at = (P, w, front, back, bone, lean = 0, level = 0) => [P[0], P[1], w * t, front * t, back * t, bone, 2.2, lean, level];
172
197
  const S = hind
173
198
  ? [
174
- [0.955, A.hip[1] - 0.02, 0, 0, 0, 0],
175
- [0.88, A.hip[1] - 0.03, 0.05, 0.12, 0.2, 0.2, 2, -0.045 * p.girth],
176
- // the quarter's back line, the hamstring, runs down unbroken from the buttock behind the stifle to the point of the hock
177
- at(mix(A.hip, A.stifle, 0.2, -0.02), 0.075, 0.11, 0.19, 1, -0.015),
178
- at(mix(A.hip, A.stifle, 0.7, -0.03), 0.068, 0.09, 0.18, 1),
179
- at(A.stifle, 0.055, 0.065, 0.15, 1.5),
180
- at(mix(A.stifle, A.hock, 0.45), 0.044, 0.05, 0.1, 2),
181
- at(mix(A.stifle, A.hock, 0.8), 0.03, 0.032, 0.05, 2),
182
- at(A.hock, 0.03, 0.036, 0.05, 2.5),
183
- at(mix(A.hock, A.hindFetlock, 0.25), 0.023, 0.025, 0.03, 3),
184
- at(mix(A.hock, A.hindFetlock, 0.8), 0.02, 0.022, 0.029, 3),
185
- at(A.hindFetlock, 0.027, 0.03, 0.036, 3),
186
- [A.hindFetlock[0] - 0.03, A.hindFetlock[1] + 0.01, 0, 0, 0, 3],
199
+ // the rounded quarter & gaskin (above), then the crisp backward-pointing hock and near-vertical cannon to the fetlock
200
+ ...haunchStations(thighOf(p), { x: A.hx, hip: A.hip[0], stifle: A.stifle[0], hock: A.hock[0] }, A.rump, q === 0),
201
+ at(A.hock, 0.03, 0.034, 0.052, 2.5, 0, 1),
202
+ at(mix(A.hock, A.hindFetlock, 0.3), 0.022, 0.024, 0.029, 3, 0, 0.4),
203
+ at(mix(A.hock, A.hindFetlock, 0.8), 0.019, 0.021, 0.028, 3),
204
+ at(A.hindFetlock, 0.026, 0.028, 0.034, 3),
205
+ [A.hindFetlock[0] + 0.01, A.hindFetlock[1] - 0.025, 0, 0, 0, 3],
187
206
  ]
188
207
  : [
189
- [0.985, zF - 0.06, 0, 0, 0, 0],
190
- [0.9, zF - 0.03, 0.03, 0.11, 0.1, 0, 2, -0.05 * p.girth],
191
- at(mix(A.shoulder, A.elbow, -0.1), 0.056, 0.07, 0.12, 0.5, -0.012),
192
- at(mix(A.shoulder, A.elbow, 0.55), 0.058, 0.07, 0.12, 1),
193
- at(A.elbow, 0.045, 0.066, 0.085, 1.5),
194
- at(mix(A.elbow, A.knee, 0.28), 0.042, 0.056, 0.056, 2),
195
- at(mix(A.elbow, A.knee, 0.78), 0.028, 0.03, 0.032, 2),
196
- at(A.knee, 0.033, 0.037, 0.034, 2.5),
197
- at(mix(A.knee, A.fetlock, 0.25), 0.022, 0.024, 0.028, 3),
198
- at(mix(A.knee, A.fetlock, 0.8), 0.02, 0.022, 0.028, 3),
199
- at(A.fetlock, 0.027, 0.03, 0.036, 3),
200
- [A.fetlock[0] - 0.03, A.fetlock[1] + 0.01, 0, 0, 0, 3],
208
+ [0.95, zF - 0.02, 0, 0, 0, 0, 2, -0.074 * p.girth],
209
+ [0.85, zF + 0.02, 0.046, 0.076, 0.084, 0.15, 2.05, -0.048 * p.girth],
210
+ at([0.72, zF + 0.052], 0.054, 0.06, 0.088, 0.55, -0.024 * p.girth),
211
+ at([0.625, zF + 0.024], 0.052, 0.056, 0.082, 1, -0.012 * p.girth),
212
+ at(A.elbow, 0.044, 0.052, 0.068, 1.5, -0.004),
213
+ at(mix(A.elbow, A.knee, 0.28), 0.04, 0.05, 0.052, 2),
214
+ at(mix(A.elbow, A.knee, 0.78), 0.027, 0.029, 0.031, 2),
215
+ at(A.knee, 0.031, 0.035, 0.033, 2.5),
216
+ at(mix(A.knee, A.fetlock, 0.25), 0.021, 0.023, 0.027, 3),
217
+ at(mix(A.knee, A.fetlock, 0.8), 0.019, 0.021, 0.027, 3),
218
+ at(A.fetlock, 0.026, 0.028, 0.034, 3),
219
+ [A.fetlock[0] - 0.025, A.fetlock[1] + 0.01, 0, 0, 0, 3],
201
220
  ];
202
221
  const x = s * (hind ? A.hx : A.sx),
203
222
  F = hind ? A.hindFetlock : A.fetlock,
@@ -223,12 +242,12 @@ function leg(b, A, p, coat, q, s, hind) {
223
242
  tube(
224
243
  b,
225
244
  [
226
- [F[0] + 0.02, F[1] - 0.006, 0, 0, 0, 0],
227
- [F[0], F[1], 0.025 * t, 0.028 * t, 0.03 * t, 0.4],
228
- [0.078, lerp(F[1], H[1], 0.45), 0.023 * t, 0.025 * t, 0.025 * t, 1],
229
- [0.054, lerp(F[1], H[1], 0.8), 0.034 * t, 0.037 * t, 0.035 * t, 1, 2.3],
230
- [0.028, H[1] - 0.004, 0.04 * t, 0.048 * t, 0.038 * t, 1, 2.6],
231
- [0.003, H[1], 0.046 * t, 0.056 * t, 0.042 * t, 1, 2.6],
245
+ [F[0] + 0.018, F[1] - 0.005, 0, 0, 0, 0],
246
+ [F[0], F[1], 0.025 * t, 0.027 * t, 0.031 * t, 0.35],
247
+ [0.076, lerp(F[1], H[1], 0.44), 0.023 * t, 0.024 * t, 0.025 * t, 0.95],
248
+ [0.054, lerp(F[1], H[1], 0.78), 0.031 * t, 0.033 * t, 0.03 * t, 1, 2.25],
249
+ [0.028, H[1] - 0.004, 0.037 * t, 0.044 * t, 0.035 * t, 1, 2.45],
250
+ [0.003, H[1] + 0.002, 0.042 * t, 0.05 * t, 0.039 * t, 1, 2.5],
232
251
  [0, H[1], 0, 0, 0, 1],
233
252
  ],
234
253
  {