@margoengine/horses 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1503 @@
1
+ import { GAITS as e, hoofPhase as t, preferredSpeed as n, stride as r, trunkMotion as i } from "./gaits.js";
2
+ import { horseBody as a } from "./anatomy.js";
3
+ //#region src/clip-plan.ts
4
+ function o(e, t) {
5
+ let n = (e, t) => {
6
+ let n = t.slice(0, -1).map((t) => e.joints[t].rest), r = n[0], i = n.at(-1), a = n.slice(1).reduce((e, t, r) => e + Math.hypot(t[1] - n[r][1], t[2] - n[r][2]), 0);
7
+ return Math.sqrt(Math.max(0, a ** 2 - (r[1] - i[1]) ** 2)) - Math.abs(r[2] - i[2]);
8
+ }, r = Math.min(1, ...e.legs.map((r, i) => n(e, r) / n(t, t.legs[i])));
9
+ if (!(r > 0)) throw RangeError("Use a horse skeleton with all four legs bent in the rest pose");
10
+ return r;
11
+ }
12
+ function s(t, i, a = 1) {
13
+ let o = [{
14
+ name: "stand",
15
+ speed: 0,
16
+ strideLength: 0,
17
+ duration: 4,
18
+ duty: 1
19
+ }], s = [null];
20
+ for (let c of e) {
21
+ let e = i?.[c] ?? n(t, c);
22
+ if (!(e > 0 && Number.isFinite(e))) throw RangeError(`Horse speeds.${c} needs a finite speed above 0 m/s`);
23
+ let l = r(t, e, c), u = {
24
+ ...l,
25
+ length: l.length * a,
26
+ duration: l.duration * a
27
+ };
28
+ s.push(u), o.push({
29
+ name: c,
30
+ speed: e,
31
+ strideLength: u.length,
32
+ duration: u.duration,
33
+ duty: u.duty
34
+ });
35
+ }
36
+ return {
37
+ clips: o,
38
+ strides: s
39
+ };
40
+ }
41
+ //#endregion
42
+ //#region ../shared/glb.js
43
+ var c = 1179937895, l = 1313821514, u = 5130562, d = {
44
+ LH: [
45
+ "pelvisL",
46
+ "thighL",
47
+ "gaskinL",
48
+ "hindCannonL",
49
+ "hindPasternL",
50
+ "hindHoofL"
51
+ ],
52
+ LF: [
53
+ "scapulaL",
54
+ "armL",
55
+ "forearmL",
56
+ "foreCannonL",
57
+ "forePasternL",
58
+ "foreHoofL"
59
+ ],
60
+ RH: [
61
+ "pelvisR",
62
+ "thighR",
63
+ "gaskinR",
64
+ "hindCannonR",
65
+ "hindPasternR",
66
+ "hindHoofR"
67
+ ],
68
+ RF: [
69
+ "scapulaR",
70
+ "armR",
71
+ "forearmR",
72
+ "foreCannonR",
73
+ "forePasternR",
74
+ "foreHoofR"
75
+ ]
76
+ }, f = [
77
+ "tail1",
78
+ "tail2",
79
+ "tail3",
80
+ "tailHair1",
81
+ "tailHair2",
82
+ "tailHair3",
83
+ "tailHair4",
84
+ "tailHair5"
85
+ ];
86
+ function p(e, t, n) {
87
+ if (!e || !(e.withers > 0)) throw TypeError("horseSkeleton needs a horseBody()");
88
+ let r = e.withers, i = e.bodyLength, a = t ?? .55 * r, o = [], s = (e, t, n) => {
89
+ o.push({
90
+ name: e,
91
+ parent: t === null ? -1 : o.findIndex((e) => e.name === t),
92
+ rest: n
93
+ });
94
+ };
95
+ if (!(a > 0 && Number.isFinite(a))) throw RangeError("Horse tail length must be finite and positive");
96
+ s("root", null, [
97
+ 0,
98
+ 0,
99
+ 0
100
+ ]), s("body", "root", [
101
+ 0,
102
+ r - e.chestDepth / 2,
103
+ 0
104
+ ]);
105
+ let c = [
106
+ 0,
107
+ .79 * r,
108
+ .47 * i
109
+ ], l = m(e);
110
+ s("neck1", "body", c), s("neck2", "neck1", [
111
+ 0,
112
+ (c[1] + l[1]) / 2,
113
+ (c[2] + l[2]) / 2
114
+ ]), s("head", "neck2", l), s("tail1", "body", [
115
+ 0,
116
+ .94 * r,
117
+ -.5 * i - .02 * r
118
+ ]), s("tail2", "tail1", [
119
+ 0,
120
+ .94 * r - .45 * e.dock,
121
+ -.5 * i - .02 * r - .25 * e.dock
122
+ ]), s("tail3", "tail2", [
123
+ 0,
124
+ .94 * r - .9 * e.dock,
125
+ -.5 * i - .02 * r - .4 * e.dock
126
+ ]);
127
+ let u = [], p = [];
128
+ for (let t of [
129
+ "LH",
130
+ "LF",
131
+ "RH",
132
+ "RF"
133
+ ]) {
134
+ let n = t[0] === "L" ? 1 : -1, a = d[t], c = o.length;
135
+ if (t[1] === "F") {
136
+ let t = n * .08 * r, o = .31 * i;
137
+ s(a[0], "body", [
138
+ t * .8,
139
+ .9 * r,
140
+ .27 * i
141
+ ]), s(a[1], a[0], [
142
+ t,
143
+ .64 * r,
144
+ .5 * i - .03 * r
145
+ ]), s(a[2], a[1], [
146
+ t,
147
+ e.elbow,
148
+ o
149
+ ]), s(a[3], a[2], [
150
+ t,
151
+ e.knee,
152
+ o
153
+ ]), s(a[4], a[3], [
154
+ t,
155
+ e.foreFetlock,
156
+ o
157
+ ]), s(a[5], a[4], [
158
+ t,
159
+ .045 * r,
160
+ o + .08 * r
161
+ ]), p.push([
162
+ t,
163
+ 0,
164
+ o + .095 * r
165
+ ]);
166
+ } else {
167
+ let t = n * .09 * r;
168
+ s(a[0], "body", [
169
+ t * .6,
170
+ .95 * r,
171
+ -.18 * i
172
+ ]), s(a[1], a[0], [
173
+ t,
174
+ e.hipJoint,
175
+ -.3 * i
176
+ ]), s(a[2], a[1], [
177
+ t,
178
+ e.stifle,
179
+ -.17 * i
180
+ ]), s(a[3], a[2], [
181
+ t,
182
+ e.hock,
183
+ -.37 * i
184
+ ]), s(a[4], a[3], [
185
+ t,
186
+ e.hindFetlock,
187
+ -.35 * i
188
+ ]), s(a[5], a[4], [
189
+ t,
190
+ .045 * r,
191
+ -.35 * i + .075 * r
192
+ ]), p.push([
193
+ t,
194
+ 0,
195
+ -.35 * i + .09 * r
196
+ ]);
197
+ }
198
+ u.push(a.map((e, t) => c + t));
199
+ }
200
+ let h = o.find((e) => e.name === "tail3").rest;
201
+ for (let e = 3; e < f.length; e++) {
202
+ let t = (e - 2) / (f.length - 3);
203
+ s(f[e], f[e - 1], [
204
+ 0,
205
+ h[1] - .92 * a * t,
206
+ h[2] - a * (.18 * t + .08 * t * t)
207
+ ]);
208
+ }
209
+ let x = n === void 0 ? void 0 : [];
210
+ if (x && n !== void 0) {
211
+ if (!(n > 0 && Number.isFinite(n))) throw RangeError("Pass a finite positive mane length in metres.");
212
+ x.push(f.map((e) => o.findIndex((t) => t.name === e)));
213
+ for (let t = 0; t < g + _; t++) {
214
+ let r = y(e, n, t), i = [], a = r.parent;
215
+ for (let e = 0; e <= v; e++) {
216
+ let n = `maneGuide${t}_${e}`;
217
+ i.push(o.length), s(n, a, b(r.root, r.direction, r.bend, r.length, e / v)), a = n;
218
+ }
219
+ x.push(i);
220
+ }
221
+ }
222
+ let S = new Map(o.map((e, t) => [e.name, t]));
223
+ return {
224
+ body: e,
225
+ joints: o,
226
+ legs: u,
227
+ ground: p,
228
+ saddle: [
229
+ 0,
230
+ r - .01 * r,
231
+ .1 * i
232
+ ],
233
+ ...x ? { strandChains: x } : {},
234
+ index(e) {
235
+ let t = S.get(e);
236
+ if (t === void 0) throw RangeError(`No horse joint "${e}"; use a name from the skeleton's joints`);
237
+ return t;
238
+ }
239
+ };
240
+ }
241
+ function m(e) {
242
+ let t = e.withers, n = e.bodyLength, r = e.neckLength;
243
+ return [
244
+ 0,
245
+ .79 * t + .62 * r,
246
+ .47 * n + .5 * r
247
+ ];
248
+ }
249
+ var h = [
250
+ 0,
251
+ -Math.sin(50 * Math.PI / 180),
252
+ Math.cos(50 * Math.PI / 180)
253
+ ], g = 8, _ = 2, v = 4;
254
+ function y(e, t, n) {
255
+ let r = e.withers, i = m(e);
256
+ if (n >= g) return {
257
+ parent: "head",
258
+ root: [
259
+ (n - g - .5) * .025 * r,
260
+ i[1] + .07 * r,
261
+ i[2] + .01 * r
262
+ ],
263
+ direction: [
264
+ 0,
265
+ h[1] + .2 * h[2],
266
+ h[2] - .2 * h[1]
267
+ ],
268
+ bend: [
269
+ 0,
270
+ -.15,
271
+ .05
272
+ ],
273
+ length: 1.1 * t
274
+ };
275
+ let a = (n + .5) / g, o = q([
276
+ 0,
277
+ r,
278
+ .3 * e.bodyLength
279
+ ], i, a);
280
+ return {
281
+ parent: a < .42 ? "neck1" : a < .82 ? "neck2" : "head",
282
+ root: [
283
+ -.01 * r,
284
+ o[1] + .06 * r * a - .01 * r,
285
+ o[2]
286
+ ],
287
+ direction: [
288
+ -.45,
289
+ -.89,
290
+ 0
291
+ ],
292
+ bend: [
293
+ -.1,
294
+ -.05,
295
+ -.05
296
+ ],
297
+ length: t
298
+ };
299
+ }
300
+ function b(e, t, n, r, i) {
301
+ return [
302
+ e[0] + t[0] * r * i + n[0] * i * i * r,
303
+ e[1] + t[1] * r * i + n[1] * i * i * r,
304
+ e[2] + t[2] * r * i + n[2] * i * i * r
305
+ ];
306
+ }
307
+ var x = (e) => [
308
+ Math.sin(e / 2),
309
+ 0,
310
+ 0,
311
+ Math.cos(e / 2)
312
+ ], S = (e) => [
313
+ 0,
314
+ 0,
315
+ Math.sin(e / 2),
316
+ Math.cos(e / 2)
317
+ ], C = ([e, t, n, r]) => [
318
+ -e,
319
+ -t,
320
+ -n,
321
+ r
322
+ ], w = (e, t) => [
323
+ e[0] + t[0],
324
+ e[1] + t[1],
325
+ e[2] + t[2]
326
+ ], T = (e, t) => [
327
+ e[0] - t[0],
328
+ e[1] - t[1],
329
+ e[2] - t[2]
330
+ ], E = (e, t) => [
331
+ e[3] * t[0] + e[0] * t[3] + e[1] * t[2] - e[2] * t[1],
332
+ e[3] * t[1] - e[0] * t[2] + e[1] * t[3] + e[2] * t[0],
333
+ e[3] * t[2] + e[0] * t[1] - e[1] * t[0] + e[2] * t[3],
334
+ e[3] * t[3] - e[0] * t[0] - e[1] * t[1] - e[2] * t[2]
335
+ ], D = (e, t) => {
336
+ let [n, r, i, a] = e, o = 2 * (r * t[2] - i * t[1]), s = 2 * (i * t[0] - n * t[2]), c = 2 * (n * t[1] - r * t[0]);
337
+ return [
338
+ t[0] + a * o + (r * c - i * s),
339
+ t[1] + a * s + (i * o - n * c),
340
+ t[2] + a * c + (n * s - r * o)
341
+ ];
342
+ }, O = (e, t) => Math.atan2(t, e);
343
+ function k(e, t, n) {
344
+ let r = t.jointTranslations?.get(n);
345
+ if (r) return [...r];
346
+ let i = e.joints[n], a = e.joints[i.parent];
347
+ if (!a) return [...i.rest];
348
+ let o = i.name === "body" ? t.bodyOffset : i.name === "scapulaL" ? t.scapulaOffsets?.[0] : i.name === "scapulaR" ? t.scapulaOffsets?.[1] : void 0;
349
+ return [
350
+ 0,
351
+ 1,
352
+ 2
353
+ ].map((e) => i.rest[e] - a.rest[e] + (o?.[e] ?? 0));
354
+ }
355
+ function A(e, t) {
356
+ let n = [], r = [];
357
+ return e.joints.forEach((i, a) => {
358
+ let o = t.rotations[a];
359
+ if (i.parent < 0) {
360
+ n.push([...i.rest]), r.push(o);
361
+ return;
362
+ }
363
+ let s = D(r[i.parent], k(e, t, a)), c = n[i.parent];
364
+ n.push([
365
+ c[0] + s[0],
366
+ c[1] + s[1],
367
+ c[2] + s[2]
368
+ ]), r.push(E(r[i.parent], o));
369
+ }), n;
370
+ }
371
+ function j(e, t) {
372
+ let n = [];
373
+ return e.joints.forEach((e, r) => n.push(e.parent < 0 ? t.rotations[r] : E(n[e.parent], t.rotations[r]))), n;
374
+ }
375
+ function M(e, t) {
376
+ let n = A(e, t), r = j(e, t);
377
+ return e.legs.map((t, i) => {
378
+ let a = t[t.length - 1], o = e.joints[a], s = e.ground[i], c = D(r[a], [
379
+ s[0] - o.rest[0],
380
+ s[1] - o.rest[1],
381
+ s[2] - o.rest[2]
382
+ ]);
383
+ return [
384
+ n[a][0] + c[0],
385
+ n[a][1] + c[1],
386
+ n[a][2] + c[2]
387
+ ];
388
+ });
389
+ }
390
+ function N(e, t) {
391
+ let n = A(e, t), r = j(e, t), i = e.index("body"), a = e.joints[i].rest, o = D(r[i], [
392
+ e.saddle[0] - a[0],
393
+ e.saddle[1] - a[1],
394
+ e.saddle[2] - a[2]
395
+ ]);
396
+ return {
397
+ position: [
398
+ n[i][0] + o[0],
399
+ n[i][1] + o[1],
400
+ n[i][2] + o[2]
401
+ ],
402
+ rotation: r[i]
403
+ };
404
+ }
405
+ var P = (e) => Math.atan2(Math.sin(e), Math.cos(e)), F = (e, t, n) => Math.min(n, Math.max(t, e));
406
+ function I(e, t, n, r, i, a, o, s, c) {
407
+ let l = Math.hypot(e[1] - t[1], e[2] - t[2]), u = Math.max(o, l - a, i - l), d = Math.min(s, l + a), f = F(c, u + Math.min(Math.max(0, d - u) / 3, a * .075), d), p = O(e[1] - t[1], e[2] - t[2]), m = P(O(n - t[1], r - t[2]) - p), h = (e) => Math.acos(F((l * l + f * f - e * e) / (2 * l * f), -1, 1)), g = p + F(m, h(i), h(a));
408
+ return [t[1] + Math.cos(g) * f, t[2] + Math.sin(g) * f];
409
+ }
410
+ function L(e, t) {
411
+ return e < t ? ie(e / t) : 1 - ie((e - t) / (1 - t));
412
+ }
413
+ function ee(e, t, n) {
414
+ return e.gait === "walk" ? F((t - e.duty) / (1 - e.duty), .23, .78) : n;
415
+ }
416
+ function te(e) {
417
+ let t = .19, n = Math.min(e, 1 - e), r = n / t, i = (n < t ? t * (r ** 3 - .5 * r ** 4) : n - .5 * t) / .81;
418
+ return e <= .5 ? i : 1 - i;
419
+ }
420
+ function R(e, t) {
421
+ let n = .065, r = e.length * e.duty, i = -e.length * (1 - e.duty), a = (r - n * i) / .935, o = (e) => {
422
+ if (e >= n) return n * (i + a) / 2 + (e - n) * a;
423
+ let t = e / n;
424
+ return i * e + (a - i) * n * (t ** 3 - .5 * t ** 4);
425
+ };
426
+ return t <= .5 ? o(t) : r - o(1 - t);
427
+ }
428
+ function z(e, t, n, r, i) {
429
+ let a = t[1] - e[1], o = t[2] - e[2], s = Math.min(n + r - 1e-6, Math.max(Math.abs(n - r) + 1e-6, Math.hypot(a, o))), c = O(a, o) + i * Math.acos(Math.min(1, Math.max(-1, (n * n + s * s - r * r) / (2 * n * s)))), l = e[1] + n * Math.cos(c), u = e[2] + n * Math.sin(c);
430
+ return [c, O(t[1] - l, t[2] - u)];
431
+ }
432
+ var ne = .8, re = .04, ie = (e) => e * e * (3 - 2 * e), B = (e, t) => Math.hypot(t[1] - e[1], t[2] - e[2]), V = (e, t) => O(t[1] - e[1], t[2] - e[2]);
433
+ function ae(e, t, n, r, i, a, o, s = o ? -1 : 1) {
434
+ let c = B(e[0], e[1]), l = B(e[1], e[2]), u = B(e[2], e[3]), d = B(e[3], e[4]), f = Math.sqrt(c ** 2 + l ** 2 + 2 * c * l * Math.cos(.3)), [p, m] = I(t, n, r, i, Math.abs(c - l) + 1e-6, f, Math.abs(u - d) + 1e-6, u + d - 1e-6, a), [h, g] = z(t, [
435
+ 0,
436
+ p,
437
+ m
438
+ ], c, l, o ? -1 : 1), [_, v] = z([
439
+ 0,
440
+ t[1] + c * Math.cos(h) + l * Math.cos(g),
441
+ t[2] + c * Math.sin(h) + l * Math.sin(g)
442
+ ], n, u, d, s);
443
+ return [
444
+ h - V(e[0], e[1]),
445
+ g - V(e[1], e[2]),
446
+ _ - V(e[2], e[3]),
447
+ v - V(e[3], e[4])
448
+ ];
449
+ }
450
+ function oe(e, t, n, r) {
451
+ let i = n ? r * t.duty : t.duty + r * (1 - t.duty), a = n ? Math.sin(Math.PI * r) ** 2 : 0;
452
+ return [
453
+ 0,
454
+ e * (t.gait === "walk" ? .011 : t.gait === "trot" ? .017 : .019) * a,
455
+ e * .0245 * Math.cos(2 * Math.PI * (i - .06))
456
+ ];
457
+ }
458
+ function H(e, n, r = 0, a = 0, o = 1) {
459
+ if (!(o >= 0 && o <= 1)) throw RangeError("Use a horse pose amplitude from 0 to 1");
460
+ let s = e.body, c = s.withers, l = e.joints, u = l.map(() => [
461
+ 0,
462
+ 0,
463
+ 0,
464
+ 1
465
+ ]), d = .002 * c * Math.sin(2 * Math.PI * a / 4), p = n ? i(s, n, r) : {
466
+ rise: d,
467
+ pitch: 0,
468
+ nod: 0
469
+ }, m = {
470
+ rise: p.rise * o + d * (1 - o),
471
+ pitch: p.pitch * o,
472
+ nod: p.nod * o
473
+ }, h = e.index("body"), g = l[h].rest, _ = m.pitch;
474
+ u[h] = x(_);
475
+ let v = [[
476
+ 0,
477
+ 0,
478
+ 0
479
+ ], [
480
+ 0,
481
+ 0,
482
+ 0
483
+ ]], y = g[1] + m.rise, b = (e) => {
484
+ let t = e[1] - y, n = e[2] - g[2], r = Math.cos(-_), i = Math.sin(-_);
485
+ return [
486
+ e[0],
487
+ g[1] + t * r - n * i,
488
+ g[2] + t * i + n * r
489
+ ];
490
+ };
491
+ e.legs.forEach((i, a) => {
492
+ let s = a === 1 || a === 3, d = s && n?.gait === "walk", f = i.map((e) => l[e].rest), p = e.ground[a], m, h = 0, g = 0, y = 0, S = 0, C = 0, E = 0, k = i.length, A = [
493
+ 0,
494
+ f[k - 1][1] - f[k - 2][1],
495
+ f[k - 1][2] - f[k - 2][2]
496
+ ], j = [
497
+ 0,
498
+ p[1] - f[k - 1][1],
499
+ p[2] - f[k - 1][2]
500
+ ], M = 0, N = s ? .035 : Math.abs(P(V(f[3], f[4]) - V(f[2], f[3]))), I = N, z = s ? .64 : .49;
501
+ if (!n) m = [
502
+ p[0],
503
+ 0,
504
+ p[2]
505
+ ];
506
+ else {
507
+ let e = t(n, a, r), i = n.length * n.duty * o;
508
+ if (e.stance) {
509
+ m = [
510
+ p[0],
511
+ 0,
512
+ p[2] + i / 2 - i * e.t
513
+ ];
514
+ let t = d ? L(Math.min(1, e.t / ne), .34 / (n.duty * ne)) : s ? L(e.t, .5) : Math.sin(Math.PI * e.t);
515
+ g = (d ? .26 : n.gait === "walk" ? .12 : n.gait === "trot" ? .25 : .32) * t, e.t > .8 && (y = z * ie((e.t - ne) / .19999999999999996)), I += (s ? .025 : .04) * Math.sin(Math.PI * e.t) ** 2 + (s ? .19 : .31) * y;
516
+ } else if (m = [
517
+ p[0],
518
+ 0,
519
+ p[2] - i / 2 + R(n, e.t) * o
520
+ ], M = n.pattern.lift[+!s] * c * Math.sin(Math.PI * e.t) ** 2, y = z * (1 - ie(Math.min(1, e.t / .37))), s) {
521
+ let t = (n.gait === "walk" ? 55 : n.gait === "trot" ? 76 : 82) * Math.PI / 180, r = ee(n, .76, .4), i = z * .19, a = e.t < r, s = a ? e.t / r : (1 - e.t) / (1 - r), l = d ? te(s) : ie(s), u = N + (a ? i : 0);
522
+ I = u + (t - u) * l;
523
+ let f = L(e.t, ee(n, .81, .5));
524
+ h = (d ? .56 : .72) * f, d && (E = f * o);
525
+ let p = L(e.t, ee(n, .84, .51));
526
+ S = .095 * p, C = .07 * c * p;
527
+ } else h = .57 * L(e.t, .47), I += .56 * L(e.t, .38) + .31 * y;
528
+ s && (v[a === 1 ? 0 : 1] = oe(c * o, n, e.stance, e.t)), M *= o, g *= o, h *= o, S *= o, C *= o, y *= o, I = N + (I - N) * o;
529
+ }
530
+ let H = b(m), U = -_ - g + h + y, se = -_ + y + (s ? h - S : .9 * h), W = [
531
+ 0,
532
+ 0,
533
+ re * c
534
+ ], ce = x(se), le = D(ce, j), G = D(ce, W), K = y / z, q = D(x(U), A), ue = [
535
+ H[0],
536
+ H[1] - K * G[1] + M,
537
+ H[2] - K * (G[2] - W[2])
538
+ ], de = T(T(ue, le), q), J = f[0], Y = s ? v[a === 1 ? 0 : 1] : void 0, X = Y ? [
539
+ J[0],
540
+ J[1] + Y[1],
541
+ J[2] + Y[2]
542
+ ] : [...J], fe = P(O(H[1] - X[1], H[2] - X[2]) - O(p[1] - X[1], p[2] - X[2])), Z = B(f[2], f[3]), pe = B(f[3], f[4]), me = Math.cos((s ? .5 : .7) * fe), he = Math.sin((s ? .5 : .7) * fe), ge = f[2][1] - J[1], _e = f[2][2] - J[2], Q = ae(f, X, de, X[1] + ge * me - _e * he + .18 * C, X[2] + ge * he + _e * me - C, Math.sqrt(Z * Z + pe * pe + 2 * Z * pe * Math.cos(I)), s);
543
+ if (E > 0) {
544
+ let e = V(f[3], f[4]), t = P(V(f[4], f[5]) - e), n = P(U - Q[3]), r = n + (F(t + .8, .15, .52) - t - n) * E, i = se - U, a = w([
545
+ 0,
546
+ f[4][1] - f[3][1],
547
+ f[4][2] - f[3][2]
548
+ ], w(D(x(r), A), D(x(r + i), j))), o = Math.hypot(a[1], a[2]), s = I + P(O(a[1], a[2]) - e), c = Math.sqrt(Z * Z + o * o + 2 * Z * o * Math.cos(s)), l = w(X, w(D(x(Q[0]), T(f[1], f[0])), D(x(Q[1]), T(f[2], f[1]))));
549
+ Q = ae([...f.slice(0, 4), w(f[3], a)], X, ue, l[1], l[2], c, !0, s < 0 ? 1 : -1), U = Q[3] + r, se = U + i;
550
+ }
551
+ Q.push(U, se), Q.forEach((e, t) => u[i[t]] = x(e - (t ? Q[t - 1] : 0)));
552
+ }), u[e.index("neck1")] = x(.6 * m.nod - .5 * _), u[e.index("head")] = x(.4 * m.nod - .3 * _);
553
+ let C = n ? Math.min(.9, .05 * n.speed) * o : 0;
554
+ for (let t = 0; t < f.length; t++) {
555
+ let i = t / (f.length - 1), s = .024 * (1 - .65 * i) * Math.sin(2 * Math.PI * (a - .1 * i) / 4), c = .044 * (1 - .82 * i) * Math.sin(2 * Math.PI * (r - .19 * i)), l = n ? s * (1 - o) + c * o : s, d = C * (t < 3 ? 1 / (1 + .8 * t) : .1 * (1 - .55 * i));
556
+ u[e.index(f[t])] = E(x(d), S(l));
557
+ }
558
+ return {
559
+ rotations: u,
560
+ bodyOffset: [
561
+ 0,
562
+ m.rise,
563
+ 0
564
+ ],
565
+ scapulaOffsets: v
566
+ };
567
+ }
568
+ function U(e, t, n, r = 0, i = 0) {
569
+ if (n.length !== e.legs.length || !Number.isFinite(r) || !Number.isFinite(i)) throw RangeError("Pass one target per hoof and finite trunk angles in radians");
570
+ let a = A(e, t), o = j(e, t), s = t.rotations.slice(), c = e.index("body"), l = a[c], u = C(o[c]), d = E(E(S(i), x(r)), o[c]), f = C(d);
571
+ return s[c] = E(C(o[e.joints[c].parent]), d), e.legs.forEach((r, i) => {
572
+ let c = n[i];
573
+ if (!c || c.point.length !== 3 || !c.point.every(Number.isFinite) || !Number.isFinite(c.pitch) || !Number.isFinite(c.roll)) throw RangeError("Pass a finite XYZ point and finite slope angles for each hoof");
574
+ let p = i % 2 == 1, m = r.map((t) => e.joints[t].rest), h = E(S(c.roll), x(c.pitch)), g = E(h, o[r[5]]), _ = E(h, o[r[4]]), v = D(g, T(e.ground[i], m[5])), y = D(_, T(m[5], m[4])), b = D(f, T(T(T(c.point, v), y), l)), A = k(e, t, r[0]), j = T(b, A), M = m[4][0] - m[0][0], N = -Math.sqrt(Math.max(0, j[0] ** 2 + j[1] ** 2 - M ** 2)), P = S(F(O(-j[1], j[0]) - O(-N, M), -.35, .35)), I = w(A, D(C(P), j)), L = D(u, T(a[r[2]], l)), ee = D(u, T(a[r[4]], l)), te = ae(m, A, I, L[1], L[2], B(L, ee), p);
575
+ s[r[0]] = E(P, x(te[0]));
576
+ for (let e = 1; e < 4; e++) s[r[e]] = x(te[e] - te[e - 1]);
577
+ let R = E(E(d, P), x(te[3]));
578
+ s[r[4]] = E(C(R), _), s[r[5]] = E(C(_), g);
579
+ }), {
580
+ ...t,
581
+ rotations: s
582
+ };
583
+ }
584
+ function se(e, t, n, r = 1, i = 1) {
585
+ if (!Number.isFinite(n) || !(r >= 0 && r <= 1) || i !== -1 && i !== 1) throw RangeError("Horse tail flick needs finite time, strength 0 to 1 and side -1 or 1");
586
+ if (n <= 0 || n >= .94 || r === 0) return t;
587
+ let a = t.rotations.slice();
588
+ for (let t = 0; t < f.length; t++) {
589
+ let o = t / (f.length - 1), s = (n - .161 * o) / .77;
590
+ if (s <= 0 || s >= 1) continue;
591
+ let c = s < .69 ? L(s / .69, .42 + .1 * o) : 0, l = s > .69 ? L((s - .69) / .31, .45) : 0, u = t === 0 ? .34 : t < 3 ? .11 : .095, d = i * r * u * (c - (t < 3 ? .16 : .24) * l), p = r * c * (t < 3 ? .15 / (t + 1) : -.027), m = e.index(f[t]);
592
+ a[m] = E(a[m], E(x(p), S(d)));
593
+ }
594
+ return {
595
+ ...t,
596
+ rotations: a
597
+ };
598
+ }
599
+ var W = [
600
+ "bay",
601
+ "chestnut",
602
+ "black",
603
+ "grey",
604
+ "dun",
605
+ "brown"
606
+ ], ce = {
607
+ bay: {
608
+ body: [
609
+ .22,
610
+ .085,
611
+ .03
612
+ ],
613
+ points: [
614
+ .018,
615
+ .014,
616
+ .012
617
+ ],
618
+ mane: [
619
+ .015,
620
+ .012,
621
+ .01
622
+ ]
623
+ },
624
+ chestnut: {
625
+ body: [
626
+ .3,
627
+ .1,
628
+ .03
629
+ ],
630
+ points: [
631
+ .26,
632
+ .085,
633
+ .026
634
+ ],
635
+ mane: [
636
+ .34,
637
+ .12,
638
+ .04
639
+ ]
640
+ },
641
+ black: {
642
+ body: [
643
+ .02,
644
+ .018,
645
+ .017
646
+ ],
647
+ points: [
648
+ .016,
649
+ .014,
650
+ .013
651
+ ],
652
+ mane: [
653
+ .012,
654
+ .011,
655
+ .01
656
+ ]
657
+ },
658
+ grey: {
659
+ body: [
660
+ .5,
661
+ .5,
662
+ .48
663
+ ],
664
+ points: [
665
+ .22,
666
+ .22,
667
+ .21
668
+ ],
669
+ mane: [
670
+ .42,
671
+ .42,
672
+ .4
673
+ ]
674
+ },
675
+ dun: {
676
+ body: [
677
+ .42,
678
+ .27,
679
+ .12
680
+ ],
681
+ points: [
682
+ .02,
683
+ .016,
684
+ .013
685
+ ],
686
+ mane: [
687
+ .018,
688
+ .014,
689
+ .012
690
+ ]
691
+ },
692
+ brown: {
693
+ body: [
694
+ .08,
695
+ .035,
696
+ .016
697
+ ],
698
+ points: [
699
+ .017,
700
+ .013,
701
+ .011
702
+ ],
703
+ mane: [
704
+ .014,
705
+ .011,
706
+ .01
707
+ ]
708
+ }
709
+ }, le = [
710
+ .75,
711
+ .74,
712
+ .7
713
+ ], G = class {
714
+ constructor(e, t = !1) {
715
+ this.material = e, this.doubleSided = t, this.positions = [], this.uvs = [], this.colors = [], this.joints = [], this.weights = [], this.indices = [];
716
+ }
717
+ vertex(e, t, n, r) {
718
+ this.positions.push(e[0], e[1], e[2]), this.uvs.push(t[0], t[1]), this.colors.push(n[0], n[1], n[2]);
719
+ let i = r.slice(0, 4), a = i.reduce((e, [, t]) => e + t, 0) || 1;
720
+ for (let e = 0; e < 4; e++) this.joints.push(i[e]?.[0] ?? 0), this.weights.push((i[e]?.[1] ?? 0) / a);
721
+ return this.positions.length / 3 - 1;
722
+ }
723
+ get count() {
724
+ return this.positions.length / 3;
725
+ }
726
+ grid(e, t, n, r, i = !1) {
727
+ let a = r ? n : n - 1;
728
+ for (let r = 0; r < t - 1; r++) for (let t = 0; t < a; t++) {
729
+ let a = e + r * n + t, o = e + r * n + (t + 1) % n, s = a + n, c = o + n;
730
+ i ? this.indices.push(a, o, s, o, c, s) : this.indices.push(a, s, o, o, s, c);
731
+ }
732
+ }
733
+ normals() {
734
+ let e = new Float32Array(this.positions.length), t = this.positions;
735
+ for (let n = 0; n < this.indices.length; n += 3) {
736
+ let r = this.indices[n] * 3, i = this.indices[n + 1] * 3, a = this.indices[n + 2] * 3, o = t[i] - t[r], s = t[i + 1] - t[r + 1], c = t[i + 2] - t[r + 2], l = t[a] - t[r], u = t[a + 1] - t[r + 1], d = t[a + 2] - t[r + 2], f = s * d - c * u, p = c * l - o * d, m = o * u - s * l;
737
+ for (let t of [
738
+ r,
739
+ i,
740
+ a
741
+ ]) e[t] = e[t] + f, e[t + 1] = e[t + 1] + p, e[t + 2] = e[t + 2] + m;
742
+ }
743
+ for (let t = 0; t < e.length; t += 3) {
744
+ let n = Math.hypot(e[t], e[t + 1], e[t + 2]) || 1;
745
+ e[t] = e[t] / n, e[t + 1] = e[t + 1] / n, e[t + 2] = e[t + 2] / n;
746
+ }
747
+ return e;
748
+ }
749
+ };
750
+ function K(e, t) {
751
+ let n = e.length, r = Math.min(n - 2, Math.max(0, Math.floor(t))), i = t - r, a = e[Math.max(0, r - 1)], o = e[r], s = e[r + 1], c = e[Math.min(n - 1, r + 2)];
752
+ return .5 * (2 * o + (-a + s) * i + (2 * a - 5 * o + 4 * s - c) * i * i + (-a + 3 * o - 3 * s + c) * i * i * i);
753
+ }
754
+ var q = (e, t, n) => [
755
+ e[0] + (t[0] - e[0]) * n,
756
+ e[1] + (t[1] - e[1]) * n,
757
+ e[2] + (t[2] - e[2]) * n
758
+ ];
759
+ function ue(e, t, n) {
760
+ let r = [
761
+ n[0] - t[0],
762
+ n[1] - t[1],
763
+ n[2] - t[2]
764
+ ], i = [
765
+ e[0] - t[0],
766
+ e[1] - t[1],
767
+ e[2] - t[2]
768
+ ], a = r[0] ** 2 + r[1] ** 2 + r[2] ** 2, o = a > 0 ? Math.min(1, Math.max(0, (i[0] * r[0] + i[1] * r[1] + i[2] * r[2]) / a)) : 0;
769
+ return Math.hypot(i[0] - r[0] * o, i[1] - r[1] * o, i[2] - r[2] * o);
770
+ }
771
+ function de(e, t) {
772
+ let n = W.indexOf(e), r = [
773
+ "body",
774
+ "points",
775
+ "mane",
776
+ "hoof"
777
+ ].indexOf(t);
778
+ if (n < 0 || r < 0) throw RangeError("coatAtlasUV needs a coat from HORSE_COATS and a row");
779
+ return [(n + .5) / W.length, (r + .5) / 4];
780
+ }
781
+ function J() {
782
+ let e = W.length, t = new Uint8Array(e * 4 * 4), n = (e) => Math.round(255 * (e <= .0031308 ? 12.92 * e : 1.055 * e ** (1 / 2.4) - .055));
783
+ return W.forEach((r, i) => {
784
+ let a = ce[r];
785
+ [
786
+ a.body,
787
+ a.points,
788
+ a.mane,
789
+ [
790
+ .05,
791
+ .045,
792
+ .04
793
+ ]
794
+ ].forEach((r, a) => {
795
+ let o = ((3 - a) * e + i) * 4;
796
+ t[o] = n(r[0]), t[o + 1] = n(r[1]), t[o + 2] = n(r[2]), t[o + 3] = 255;
797
+ });
798
+ }), {
799
+ data: t,
800
+ width: e,
801
+ height: 4
802
+ };
803
+ }
804
+ function Y(e = {}) {
805
+ let t = a(e), n = t.withers, r = t.bodyLength, i = e.coat ?? "bay", o = ce[i], c = e.detail ?? 2, l = e.atlas === !0, u = e.markings ?? {}, d = e.maneLength ?? .11 * n, m = e.tailLength ?? .55 * n;
806
+ if (!o || !Object.hasOwn(ce, i)) throw TypeError(`horseDocument coat must be one of ${W.join(", ")}`);
807
+ if (c !== 0 && c !== 1 && c !== 2) throw RangeError("horseDocument detail must be 0, 1 or 2");
808
+ if (!(d >= .02 && d <= .8)) throw RangeError("horseDocument maneLength must be 0.02 to 0.8 m");
809
+ if (!(m >= .1 && m <= 1.6)) throw RangeError("horseDocument tailLength must be 0.1 to 1.6 m");
810
+ let _ = p(t, m, e.strandRig ? d : void 0), v = u.socks ?? [
811
+ 0,
812
+ 0,
813
+ 0,
814
+ 0
815
+ ];
816
+ if (!Array.isArray(v) || v.length !== 4 || v.some((e) => !(e >= 0 && e <= n))) throw RangeError("horseDocument markings.socks must be four heights in metres, 0 to the withers height");
817
+ let y = [
818
+ 12,
819
+ 20,
820
+ 36
821
+ ][c], x = [
822
+ 2,
823
+ 4,
824
+ 7
825
+ ][c], S = _.joints, C = (e) => S[_.index(e)].rest, w = (e) => _.index(e), T = new G("Coat"), E = new G("Hoof"), D = new G("Mane", !0), O = new G("Tail", !0), A = new G("Eye"), j = (e) => de(i, e), M = (e) => e.map((e) => {
826
+ let i = w(e), a = S.findIndex((t) => t.parent === i && !t.name.startsWith("tail") == !e.startsWith("tail")), o = S[i].rest, s = e === "body" ? [
827
+ 0,
828
+ o[1],
829
+ .4 * r
830
+ ] : e === "head" ? [
831
+ 0,
832
+ o[1] + h[1] * t.headLength,
833
+ o[2] + h[2] * t.headLength
834
+ ] : a >= 0 ? S[a].rest : [
835
+ o[0],
836
+ o[1] - .1 * n,
837
+ o[2]
838
+ ];
839
+ return {
840
+ i,
841
+ a: e === "body" ? [
842
+ 0,
843
+ o[1],
844
+ -.4 * r
845
+ ] : o,
846
+ b: s
847
+ };
848
+ }), N = (e, t, n) => {
849
+ let r = t.map((t) => ({
850
+ i: t.i,
851
+ d: ue(e, t.a, t.b)
852
+ })).sort((e, t) => e.d - t.d);
853
+ if (r.length < 2) return [[r[0].i, 1]];
854
+ let i = Math.max(0, 1 - (r[1].d - r[0].d) / n) * .5;
855
+ return [[r[0].i, 1 - i], [r[1].i, i]];
856
+ }, P = n - t.chestDepth, F = Math.max(.1 * n, t.girth / Math.PI - t.chestDepth / 2), I = t.hipWidth / 2, L = t.chestWidth / 2, ee = [
857
+ [
858
+ -.5 * r - .035 * n,
859
+ .95 * n,
860
+ .89 * n,
861
+ .03 * n
862
+ ],
863
+ [
864
+ -.5 * r + .01 * n,
865
+ .975 * n,
866
+ .66 * n,
867
+ I * .62
868
+ ],
869
+ [
870
+ -.42 * r,
871
+ .995 * n,
872
+ .6 * n,
873
+ I * .92
874
+ ],
875
+ [
876
+ -.3 * r,
877
+ n,
878
+ P + .03 * n,
879
+ I
880
+ ],
881
+ [
882
+ -.15 * r,
883
+ .975 * n,
884
+ P + .01 * n,
885
+ F * .98
886
+ ],
887
+ [
888
+ 0,
889
+ .962 * n,
890
+ P - .012 * n,
891
+ F * 1.03
892
+ ],
893
+ [
894
+ .15 * r,
895
+ .98 * n,
896
+ P - .005 * n,
897
+ F
898
+ ],
899
+ [
900
+ .27 * r,
901
+ 1 * n,
902
+ P + .01 * n,
903
+ L + .01 * n
904
+ ],
905
+ [
906
+ .38 * r,
907
+ .965 * n,
908
+ P + .05 * n,
909
+ L
910
+ ],
911
+ [
912
+ .47 * r,
913
+ .9 * n,
914
+ .64 * n,
915
+ L * .82
916
+ ]
917
+ ], te = C("neck1"), R = C("head"), z = ee.map(([e, t, n, r]) => ({
918
+ c: [
919
+ 0,
920
+ (t + n) / 2,
921
+ e
922
+ ],
923
+ hh: (t - n) / 2,
924
+ hw: r
925
+ }));
926
+ for (let e of [
927
+ .25,
928
+ .5,
929
+ .75,
930
+ 1
931
+ ]) {
932
+ let t = q(te, R, e);
933
+ z.push({
934
+ c: t,
935
+ hh: .14 * n * (1 - e) + .07 * n * e,
936
+ hw: .092 * n * (1 - e) + .05 * n * e
937
+ });
938
+ }
939
+ let ne = (e, t, r, i, a, o, s = "body") => {
940
+ let c = (t.length - 1) * x + 1, u = e.count, d = t.map((e) => e.c[1]), f = t.map((e) => e.c[2]), p = t.map((e) => e.hh), m = t.map((e) => e.hw);
941
+ for (let u = 0; u < c; u++) {
942
+ let h = u / x, g = [
943
+ 0,
944
+ K(d, h),
945
+ K(f, h)
946
+ ], _ = .01, v = K(d, Math.min(t.length - 1, h + _)) - K(d, Math.max(0, h - _)), b = K(f, Math.min(t.length - 1, h + _)) - K(f, Math.max(0, h - _)), S = Math.hypot(v, b) || 1, C = [b / S, -v / S], w = Math.max(.005, K(p, h)), T = Math.max(.005, K(m, h)), E = u === 0 || u === c - 1 ? .02 : 1;
947
+ for (let t = 0; t < y; t++) {
948
+ let d = 2 * Math.PI * t / y, f = Math.cos(d), p = Math.sin(d), m = Math.sign(f) * Math.abs(f) ** .8, h = Math.sign(p) * Math.abs(p) ** .8, _ = [
949
+ T * m * E,
950
+ g[1] + C[0] * w * h * E,
951
+ g[2] + C[1] * w * h * E
952
+ ], v = u / (c - 1), b = l ? j(s) : [i + (a - i) * v, t / y];
953
+ e.vertex(_, b, o(_, v, t), N(_, r, .08 * n));
954
+ }
955
+ }
956
+ e.grid(u, c, y, !0, !0);
957
+ }, re = i === "dun";
958
+ ne(T, z, M([
959
+ "body",
960
+ "neck1",
961
+ "neck2",
962
+ "head",
963
+ "thighL",
964
+ "thighR",
965
+ "armL",
966
+ "armR"
967
+ ]), 0, .8, (e) => re && Math.abs(e[0]) < .018 * n && e[1] > .9 * n && e[2] < .3 * r ? o.mane : o.body);
968
+ let ie = [
969
+ [
970
+ -.1,
971
+ .05,
972
+ .04,
973
+ 0
974
+ ],
975
+ [
976
+ 0,
977
+ .075,
978
+ .05,
979
+ 0
980
+ ],
981
+ [
982
+ .2,
983
+ .092,
984
+ .06,
985
+ -.018
986
+ ],
987
+ [
988
+ .42,
989
+ .068,
990
+ .05,
991
+ -.01
992
+ ],
993
+ [
994
+ .68,
995
+ .052,
996
+ .04,
997
+ 0
998
+ ],
999
+ [
1000
+ .88,
1001
+ .05,
1002
+ .041,
1003
+ -.004
1004
+ ],
1005
+ [
1006
+ 1,
1007
+ .026,
1008
+ .026,
1009
+ -.008
1010
+ ]
1011
+ ], B = [h[2], -h[1]];
1012
+ ne(T, ie.map(([e, r, i, a]) => ({
1013
+ c: [
1014
+ 0,
1015
+ R[1] + h[1] * e * t.headLength + B[0] * a * n,
1016
+ R[2] + h[2] * e * t.headLength + B[1] * a * n
1017
+ ],
1018
+ hh: r * n,
1019
+ hw: i * n
1020
+ })), M(["head"]), .8, 1, (e, t, r) => u.blaze === !0 && t > .25 && t < .95 && Math.abs(e[0]) < .0125 * n && Math.sin(2 * Math.PI * r / y) > 0 ? le : t > .84 ? o.points.map((e, t) => (e + o.body[t]) / 2) : o.body), _.legs.forEach((e, r) => {
1021
+ let i = r === 1 || r === 3, a = [...e.map((e) => S[e].rest), _.ground[r]], s = i ? [
1022
+ [.05, .06],
1023
+ [.085, .065],
1024
+ [.062, .036],
1025
+ [t.cannon / (2 * Math.PI) / n + .004, t.cannon / (2 * Math.PI) / n],
1026
+ [.03, .024],
1027
+ [.03, .037]
1028
+ ] : [
1029
+ [.05, .08],
1030
+ [.11, .075],
1031
+ [.058, .038],
1032
+ [t.cannon / (2 * Math.PI) / n + .006, t.cannon / (2 * Math.PI) / n + .002],
1033
+ [.03, .024],
1034
+ [.03, .037]
1035
+ ], c = v[r], u = e.length;
1036
+ for (let r = 0; r < u; r++) {
1037
+ let d = r === u - 1, f = d ? E : T, p = a[r], m = a[r + 1], h = m[1] - p[1], g = m[2] - p[2], _ = Math.hypot(h, g) || 1, v = [g / _, -h / _], b = r === 0 ? x + 1 : x, S = f.count, C = r === 0 ? w("body") : e[r - 1];
1038
+ for (let a = 0; a < b + +!!d; a++) {
1039
+ let m = Math.min(1, a / (b - 1 || 1)), _ = p[1] + h * m, x = p[2] + g * m, S = (s[r][0] + (s[r][1] - s[r][0]) * m) * n * (a === b ? .02 : 1), w = r >= u - 3 && r <= u - 2 && m < .15 ? 1.25 - m : 1, T = m < .15 ? .5 * (1 - m / .15) : 0;
1040
+ for (let a = 0; a < y; a++) {
1041
+ let s = 2 * Math.PI * a / y, u = [
1042
+ p[0] + Math.cos(s) * S * w * (i ? .92 : 1),
1043
+ _ + v[0] * Math.sin(s) * S * w,
1044
+ x + v[1] * Math.sin(s) * S * w
1045
+ ], h = u[1] < (i ? t.knee : t.hock) - .02 * n, g = d ? c > 0 ? [
1046
+ .32,
1047
+ .27,
1048
+ .2
1049
+ ] : [
1050
+ .05,
1051
+ .045,
1052
+ .04
1053
+ ] : u[1] < c ? le : h ? o.points : o.body, b = l ? j(d ? "hoof" : h ? "points" : "body") : [m, a / y];
1054
+ f.vertex(u, b, g, T > 0 ? [[e[r], 1 - T], [C, T]] : [[e[r], 1]]);
1055
+ }
1056
+ }
1057
+ f.grid(S, b + +!!d, y, !0, !0);
1058
+ }
1059
+ });
1060
+ let V = w("head");
1061
+ for (let e of [1, -1]) {
1062
+ let r = [
1063
+ e * .035 * n,
1064
+ R[1] + .05 * n,
1065
+ R[2] - .01 * n
1066
+ ], i = [
1067
+ e * .05 * n,
1068
+ r[1] + .09 * n,
1069
+ r[2] + .025 * n
1070
+ ], a = Math.max(6, Math.ceil(y / 3)), s = T.count;
1071
+ for (let e = 0; e <= 3; e++) {
1072
+ let t = e / 3, s = q(r, i, t), c = .022 * n * (1 - t) + .001;
1073
+ for (let e = 0; e < a; e++) {
1074
+ let t = 2 * Math.PI * e / a, n = [
1075
+ s[0] + Math.cos(t) * c,
1076
+ s[1],
1077
+ s[2] + Math.sin(t) * c * .7
1078
+ ];
1079
+ T.vertex(n, l ? j("body") : [.9, e / a], o.body, [[V, 1]]);
1080
+ }
1081
+ }
1082
+ T.grid(s, 4, a, !0);
1083
+ let c = q(R, [
1084
+ 0,
1085
+ R[1] + h[1] * t.headLength,
1086
+ R[2] + h[2] * t.headLength
1087
+ ], .24), u = [
1088
+ e * .052 * n,
1089
+ c[1] + .012 * n,
1090
+ c[2]
1091
+ ], d = .016 * n, f = Math.max(8, y / 2), p = A.count;
1092
+ for (let t = 0; t <= 6; t++) for (let n = 0; n < f; n++) {
1093
+ let r = Math.PI * t / 6, i = 2 * Math.PI * n / f, a = [
1094
+ e * Math.cos(r),
1095
+ Math.sin(r) * Math.cos(i),
1096
+ Math.sin(r) * Math.sin(i)
1097
+ ];
1098
+ A.vertex([
1099
+ u[0] + a[0] * d,
1100
+ u[1] + a[1] * d,
1101
+ u[2] + a[2] * d
1102
+ ], l ? j("mane") : [n / f, t / 6], [
1103
+ .02,
1104
+ .015,
1105
+ .012
1106
+ ], [[V, 1]]);
1107
+ }
1108
+ A.grid(p, 7, f, !0, e < 0);
1109
+ }
1110
+ let ae = (e, t, n, r, i, a, o, s, u, d = c === 0 ? 2 : 4) => {
1111
+ let f = e.count;
1112
+ for (let c = 0; c <= d; c++) {
1113
+ let f = c / d, p = b(t, n, o, i, f), m = a * (1 - .6 * f);
1114
+ for (let t of [0, 1]) {
1115
+ let n = (t - .5) * m;
1116
+ e.vertex([
1117
+ p[0] + r[0] * n,
1118
+ p[1] + r[1] * n,
1119
+ p[2] + r[2] * n
1120
+ ], l ? j("mane") : [t, f], u, s(f, p));
1121
+ }
1122
+ }
1123
+ e.grid(f, d + 1, 2, !1);
1124
+ }, oe = [
1125
+ 8,
1126
+ 20,
1127
+ 36
1128
+ ][c], U = w("neck1"), se = w("neck2"), J = (e, t) => {
1129
+ let n = _.strandChains[e + 1], r = t * (n.length - 1), i = Math.min(n.length - 2, Math.floor(r)), a = r - i;
1130
+ return [[n[i], 1 - a], [n[i + 1], a]];
1131
+ };
1132
+ for (let e = 0; e < oe; e++) {
1133
+ let i = (e + .5) / oe, a = q([
1134
+ 0,
1135
+ C("body")[1] + t.chestDepth / 2,
1136
+ .3 * r
1137
+ ], R, i);
1138
+ ae(D, [
1139
+ -.01 * n,
1140
+ a[1] + .06 * n * i - .01 * n,
1141
+ a[2]
1142
+ ], [
1143
+ -.45,
1144
+ -.89,
1145
+ 0
1146
+ ], [
1147
+ 0,
1148
+ .3,
1149
+ .95
1150
+ ], d * (.8 + .4 * Math.sin(e * 12.9898) ** 2), r * .6 / oe * 1.8, [
1151
+ -.1,
1152
+ -.05,
1153
+ -.05
1154
+ ], (e) => _.strandChains ? J(Math.floor(i * g), e) : i < .5 ? [[U, 1 - i], [se, i]] : [[se, 1.5 - i], [V, i - .5]], o.mane);
1155
+ }
1156
+ for (let e = 0; e < [
1157
+ 2,
1158
+ 4,
1159
+ 6
1160
+ ][c]; e++) {
1161
+ let t = (e / 5 - .5) * .04 * n;
1162
+ ae(D, [
1163
+ t,
1164
+ R[1] + .07 * n,
1165
+ R[2] + .01 * n
1166
+ ], [
1167
+ 0,
1168
+ h[1] + .2 * h[2],
1169
+ h[2] - .2 * h[1]
1170
+ ], [
1171
+ 1,
1172
+ 0,
1173
+ 0
1174
+ ], d * 1.1, .03 * n, [
1175
+ 0,
1176
+ -.15,
1177
+ .05
1178
+ ], (e) => _.strandChains ? J(g + Number(t > 0), e) : [[V, 1]], o.mane);
1179
+ }
1180
+ let Y = [
1181
+ 10,
1182
+ 24,
1183
+ 44
1184
+ ][c], X = C("tail1"), fe = C("tail3"), Z = f.map(w);
1185
+ for (let e = 0; e < Y; e++) {
1186
+ let t = e * 7 % Y / Y, r = q(X, fe, .15 + .8 * t), i = 2 * Math.PI * (e * .618 % 1), a = .18, s = [
1187
+ Math.cos(i) * a,
1188
+ -1,
1189
+ -.25 + Math.sin(i) * a * .6
1190
+ ], l = Math.hypot(...s), u = m * (1 - .45 * t) * (.85 + .3 * Math.sin(e * 78.233) ** 2);
1191
+ ae(O, r, [
1192
+ s[0] / l,
1193
+ s[1] / l,
1194
+ s[2] / l
1195
+ ], [
1196
+ Math.cos(i + Math.PI / 2),
1197
+ 0,
1198
+ Math.sin(i + Math.PI / 2)
1199
+ ], u, .045 * n, [
1200
+ Math.cos(i) * .08,
1201
+ 0,
1202
+ -.06
1203
+ ], (e, t) => {
1204
+ let n = Z.findIndex((e) => S[e].rest[1] < t[1]);
1205
+ if (n === 0) return [[Z[0], 1]];
1206
+ if (n < 0) return [[Z[Z.length - 1], 1]];
1207
+ let r = Z[n - 1], i = Z[n], a = S[r].rest[1], o = (a - t[1]) / (a - S[i].rest[1]);
1208
+ return [[r, 1 - o], [i, o]];
1209
+ }, o.mane, [
1210
+ 3,
1211
+ 6,
1212
+ 10
1213
+ ][c]);
1214
+ }
1215
+ let { clips: pe, strides: me } = s(t, e.speeds), he = [], ge = [], _e = [], Q = (e, t, n, r = {}, i) => {
1216
+ he.push(new Uint8Array(e.buffer, e.byteOffset, e.byteLength)), ge.push({
1217
+ buffer: he.length - 1,
1218
+ byteLength: e.byteLength,
1219
+ ...i ? { target: i } : {}
1220
+ });
1221
+ let a = {
1222
+ SCALAR: 1,
1223
+ VEC2: 2,
1224
+ VEC3: 3,
1225
+ VEC4: 4,
1226
+ MAT4: 16
1227
+ }[t];
1228
+ return _e.push({
1229
+ bufferView: ge.length - 1,
1230
+ componentType: n,
1231
+ count: e.length / a,
1232
+ type: t,
1233
+ ...r
1234
+ }), _e.length - 1;
1235
+ }, ve = [
1236
+ {
1237
+ name: "Coat",
1238
+ pbrMetallicRoughness: {
1239
+ baseColorFactor: [
1240
+ 1,
1241
+ 1,
1242
+ 1,
1243
+ 1
1244
+ ],
1245
+ metallicFactor: 0,
1246
+ roughnessFactor: .62
1247
+ }
1248
+ },
1249
+ {
1250
+ name: "Hoof",
1251
+ pbrMetallicRoughness: {
1252
+ baseColorFactor: [
1253
+ 1,
1254
+ 1,
1255
+ 1,
1256
+ 1
1257
+ ],
1258
+ metallicFactor: 0,
1259
+ roughnessFactor: .55
1260
+ }
1261
+ },
1262
+ {
1263
+ name: "Mane",
1264
+ doubleSided: !0,
1265
+ pbrMetallicRoughness: {
1266
+ baseColorFactor: [
1267
+ 1,
1268
+ 1,
1269
+ 1,
1270
+ 1
1271
+ ],
1272
+ metallicFactor: 0,
1273
+ roughnessFactor: .5
1274
+ }
1275
+ },
1276
+ {
1277
+ name: "Tail",
1278
+ doubleSided: !0,
1279
+ pbrMetallicRoughness: {
1280
+ baseColorFactor: [
1281
+ 1,
1282
+ 1,
1283
+ 1,
1284
+ 1
1285
+ ],
1286
+ metallicFactor: 0,
1287
+ roughnessFactor: .5
1288
+ }
1289
+ },
1290
+ {
1291
+ name: "Eye",
1292
+ pbrMetallicRoughness: {
1293
+ baseColorFactor: [
1294
+ 1,
1295
+ 1,
1296
+ 1,
1297
+ 1
1298
+ ],
1299
+ metallicFactor: 0,
1300
+ roughnessFactor: .08
1301
+ }
1302
+ }
1303
+ ], ye = [
1304
+ T,
1305
+ E,
1306
+ D,
1307
+ O,
1308
+ A
1309
+ ], be = ye.map((e, t) => {
1310
+ let n = new Float32Array(e.positions), r = [
1311
+ Infinity,
1312
+ Infinity,
1313
+ Infinity
1314
+ ], i = [
1315
+ -Infinity,
1316
+ -Infinity,
1317
+ -Infinity
1318
+ ];
1319
+ for (let e = 0; e < n.length; e += 3) for (let t = 0; t < 3; t++) r[t] = Math.min(r[t], n[e + t]), i[t] = Math.max(i[t], n[e + t]);
1320
+ return {
1321
+ attributes: {
1322
+ POSITION: Q(n, "VEC3", 5126, {
1323
+ min: r,
1324
+ max: i
1325
+ }, 34962),
1326
+ NORMAL: Q(e.normals(), "VEC3", 5126, {}, 34962),
1327
+ TEXCOORD_0: Q(new Float32Array(e.uvs), "VEC2", 5126, {}, 34962),
1328
+ COLOR_0: Q(new Float32Array(e.colors), "VEC3", 5126, {}, 34962),
1329
+ JOINTS_0: Q(new Uint16Array(e.joints), "VEC4", 5123, {}, 34962),
1330
+ WEIGHTS_0: Q(new Float32Array(e.weights), "VEC4", 5126, {}, 34962)
1331
+ },
1332
+ indices: Q(new Uint32Array(e.indices), "SCALAR", 5125, {}, 34963),
1333
+ material: t
1334
+ };
1335
+ }), xe = new Float32Array(S.length * 16);
1336
+ S.forEach((e, t) => {
1337
+ xe.set([
1338
+ 1,
1339
+ 0,
1340
+ 0,
1341
+ 0,
1342
+ 0,
1343
+ 1,
1344
+ 0,
1345
+ 0,
1346
+ 0,
1347
+ 0,
1348
+ 1,
1349
+ 0,
1350
+ -e.rest[0],
1351
+ -e.rest[1],
1352
+ -e.rest[2],
1353
+ 1
1354
+ ], t * 16);
1355
+ });
1356
+ let $ = S.map((e) => {
1357
+ let t = e.parent >= 0 ? S[e.parent].rest : [
1358
+ 0,
1359
+ 0,
1360
+ 0
1361
+ ];
1362
+ return {
1363
+ name: e.name,
1364
+ translation: [
1365
+ e.rest[0] - t[0],
1366
+ e.rest[1] - t[1],
1367
+ e.rest[2] - t[2]
1368
+ ],
1369
+ children: []
1370
+ };
1371
+ });
1372
+ S.forEach((e, t) => e.parent >= 0 && $[e.parent].children.push(t));
1373
+ let Se = C("body"), Ce = $.length;
1374
+ $.push({
1375
+ name: "saddle",
1376
+ translation: [
1377
+ _.saddle[0] - Se[0],
1378
+ _.saddle[1] - Se[1],
1379
+ _.saddle[2] - Se[2]
1380
+ ]
1381
+ }), $[w("body")].children.push(Ce);
1382
+ for (let e of $) e.children?.length === 0 && delete e.children;
1383
+ let we = $.length;
1384
+ $.push({
1385
+ name: "horse",
1386
+ mesh: 0,
1387
+ skin: 0
1388
+ });
1389
+ let Te = {
1390
+ joints: S.map((e, t) => t),
1391
+ inverseBindMatrices: Q(xe, "MAT4", 5126),
1392
+ skeleton: 0
1393
+ }, Ee = pe.map((e, t) => {
1394
+ let n = me[t], r = n ? [
1395
+ 16,
1396
+ 24,
1397
+ 32
1398
+ ][c] : 8, i = new Float32Array(r + 1), a = S.map(() => new Float32Array((r + 1) * 4)), o = [
1399
+ "body",
1400
+ "scapulaL",
1401
+ "scapulaR"
1402
+ ].map((e) => ({
1403
+ joint: w(e),
1404
+ values: new Float32Array((r + 1) * 3)
1405
+ }));
1406
+ for (let t = 0; t <= r; t++) {
1407
+ let s = t / r;
1408
+ i[t] = s * e.duration;
1409
+ let c = n ? H(_, n, s) : H(_, null, 0, s * e.duration);
1410
+ c.rotations.forEach((e, n) => a[n].set(e, t * 4));
1411
+ for (let { joint: e, values: n } of o) n.set(k(_, c, e), t * 3);
1412
+ }
1413
+ let s = Q(i, "SCALAR", 5126, {
1414
+ min: [0],
1415
+ max: [e.duration]
1416
+ }), l = [], u = [];
1417
+ S.forEach((e, t) => {
1418
+ t !== 0 && (l.push({
1419
+ input: s,
1420
+ output: Q(a[t], "VEC4", 5126)
1421
+ }), u.push({
1422
+ sampler: l.length - 1,
1423
+ target: {
1424
+ node: t,
1425
+ path: "rotation"
1426
+ }
1427
+ }));
1428
+ });
1429
+ for (let { joint: e, values: t } of o) l.push({
1430
+ input: s,
1431
+ output: Q(t, "VEC3", 5126)
1432
+ }), u.push({
1433
+ sampler: l.length - 1,
1434
+ target: {
1435
+ node: e,
1436
+ path: "translation"
1437
+ }
1438
+ });
1439
+ return {
1440
+ name: e.name,
1441
+ samplers: l,
1442
+ channels: u,
1443
+ extras: {
1444
+ speed: e.speed,
1445
+ strideLength: e.strideLength,
1446
+ duty: e.duty
1447
+ }
1448
+ };
1449
+ });
1450
+ return {
1451
+ doc: {
1452
+ asset: {
1453
+ version: "2.0",
1454
+ generator: "@margoengine/horses"
1455
+ },
1456
+ scene: 0,
1457
+ scenes: [{ nodes: [0, we] }],
1458
+ nodes: $,
1459
+ meshes: [{
1460
+ name: "horse",
1461
+ primitives: be
1462
+ }],
1463
+ skins: [Te],
1464
+ materials: ve,
1465
+ animations: Ee,
1466
+ accessors: _e,
1467
+ bufferViews: ge,
1468
+ buffers: he.map((e) => ({ byteLength: e.byteLength })),
1469
+ extras: { horse: {
1470
+ type: t.type,
1471
+ withers: t.withers,
1472
+ mass: t.mass,
1473
+ coat: i
1474
+ } }
1475
+ },
1476
+ buffers: he,
1477
+ body: t,
1478
+ skeleton: _,
1479
+ clips: pe,
1480
+ vertices: ye.reduce((e, t) => e + t.count, 0)
1481
+ };
1482
+ }
1483
+ function X(e = {}) {
1484
+ let { doc: t, buffers: n } = Y(e), r = 0, i = n.map((e) => {
1485
+ let t = r;
1486
+ return r += e.byteLength + 3 & -4, t;
1487
+ }), a = new Uint8Array(r);
1488
+ n.forEach((e, t) => a.set(e, i[t]));
1489
+ let o = {
1490
+ ...t,
1491
+ buffers: [{ byteLength: r }],
1492
+ bufferViews: t.bufferViews.map((e, t) => ({
1493
+ ...e,
1494
+ buffer: 0,
1495
+ byteOffset: i[t]
1496
+ }))
1497
+ }, s = new TextEncoder().encode(JSON.stringify(o)), d = new Uint8Array(s.length + 3 & -4).fill(32);
1498
+ d.set(s);
1499
+ let f = new Uint8Array(28 + d.length + a.length), p = new DataView(f.buffer);
1500
+ return p.setUint32(0, c, !0), p.setUint32(4, 2, !0), p.setUint32(8, f.length, !0), p.setUint32(12, d.length, !0), p.setUint32(16, l, !0), f.set(d, 20), p.setUint32(20 + d.length, a.length, !0), p.setUint32(24 + d.length, u, !0), f.set(a, 28 + d.length), f;
1501
+ }
1502
+ //#endregion
1503
+ export { o as _, de as a, X as c, p as d, se as f, s as g, N as h, J as i, k as l, A as m, ce as n, U as o, M as p, W as r, Y as s, ne as t, H as u };