@margoengine/horses 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ //#region src/anatomy.ts
2
+ var e = [
3
+ "riding",
4
+ "cavalry",
5
+ "draft"
6
+ ], t = {
7
+ riding: {
8
+ withers: 1.63,
9
+ bodyLength: 1.03,
10
+ croup: 1,
11
+ girth: 1.14,
12
+ chestDepth: .45,
13
+ chestWidth: .25,
14
+ hipWidth: .33,
15
+ headLength: .37,
16
+ neckLength: .56,
17
+ elbow: .56,
18
+ knee: .31,
19
+ foreFetlock: .16,
20
+ hipJoint: .66,
21
+ stifle: .52,
22
+ hock: .37,
23
+ hindFetlock: .17,
24
+ cannon: .125,
25
+ dock: .3
26
+ },
27
+ cavalry: {
28
+ withers: 1.57,
29
+ bodyLength: 1.03,
30
+ croup: 1,
31
+ girth: 1.17,
32
+ chestDepth: .46,
33
+ chestWidth: .27,
34
+ hipWidth: .34,
35
+ headLength: .37,
36
+ neckLength: .55,
37
+ elbow: .55,
38
+ knee: .3,
39
+ foreFetlock: .16,
40
+ hipJoint: .65,
41
+ stifle: .51,
42
+ hock: .36,
43
+ hindFetlock: .17,
44
+ cannon: .13,
45
+ dock: .3
46
+ },
47
+ draft: {
48
+ withers: 1.75,
49
+ bodyLength: 1.06,
50
+ croup: 1,
51
+ girth: 1.34,
52
+ chestDepth: .5,
53
+ chestWidth: .31,
54
+ hipWidth: .37,
55
+ headLength: .4,
56
+ neckLength: .52,
57
+ elbow: .51,
58
+ knee: .29,
59
+ foreFetlock: .15,
60
+ hipJoint: .64,
61
+ stifle: .49,
62
+ hock: .35,
63
+ hindFetlock: .16,
64
+ cannon: .16,
65
+ dock: .3
66
+ }
67
+ };
68
+ function n(e) {
69
+ if (!(e > 0) || !Number.isFinite(e)) throw RangeError("handsToMetres needs a positive height in hands");
70
+ let t = Math.floor(e), n = Math.round((e - t) * 10);
71
+ if (n > 3) throw RangeError("handsToMetres: the digit after the point is inches, 0 to 3 (15.2 is 15 hands 2 inches)");
72
+ return (t * 4 + n) * .0254;
73
+ }
74
+ function r(e, t) {
75
+ if (!(e > 0) || !(t > 0)) throw RangeError("horseMass needs a positive girth and body length in metres");
76
+ return (e * 100) ** 2 * (t * 100) / 11880;
77
+ }
78
+ function i(n = {}) {
79
+ let i = n.type ?? "riding", a = t[i];
80
+ if (!a || !Object.hasOwn(t, i)) throw TypeError(`horseBody type must be one of ${e.join(", ")}`);
81
+ let o = n.withers ?? a.withers, s = n.condition ?? 1;
82
+ if (!(o >= 1.2 && o <= 2.1)) throw RangeError("horseBody withers must be 1.2 to 2.1 metres");
83
+ if (!(s >= .8 && s <= 1.25)) throw RangeError("horseBody condition must be 0.8 to 1.25");
84
+ let c = { type: i };
85
+ for (let [e, t] of Object.entries(a)) c[e] = e === "withers" ? o : t * o;
86
+ return c.girth *= s, c.chestWidth *= s, c.hipWidth *= s, c.mass = r(c.girth, c.bodyLength), Object.freeze(c);
87
+ }
88
+ //#endregion
89
+ export { t as HORSE_PROPORTIONS, e as HORSE_TYPES, n as handsToMetres, i as horseBody, r as horseMass };
@@ -0,0 +1,10 @@
1
+ import type { HorseBody } from './anatomy.js';
2
+ import { type Gait, type Stride } from './gaits.js';
3
+ import type { HorseClip, HorseSkeleton } from './model.js';
4
+ /** Reduce stride length for the tightest authored limb while preserving world speed and ground-relative cadence. */
5
+ export declare function strideReachScale(skeleton: HorseSkeleton, nominal: HorseSkeleton): number;
6
+ /** Shared clip metadata for generated horses and runtime rigs. */
7
+ export declare function horseClipPlan(body: HorseBody, speeds?: Partial<Record<Gait, number>>, reachScale?: number): {
8
+ clips: HorseClip[];
9
+ strides: (Stride | null)[];
10
+ };
@@ -0,0 +1,76 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { Engine } from '@margoengine/core';
3
+ import type { BoneBake, SkinnedCrowd } from '@margoengine/animation/instanced-skin';
4
+ import { type HorseClip, type HorseCoat, type HorseModelOptions, type HorseSkeleton } from './model.js';
5
+ import type { HorseBody } from './anatomy.js';
6
+ /** One horse for {@link HorseCrowd.update}: an Army member fits. */
7
+ export interface CrowdHorse {
8
+ readonly x: number;
9
+ readonly z: number;
10
+ /** Radians about +Y, 0 facing +Z. */
11
+ readonly heading: number;
12
+ /** Ground speed, m/s. */
13
+ readonly speed: number;
14
+ /** Metres travelled since time 0. */
15
+ readonly distance: number;
16
+ /** Ground height; default the crowd's `ground`. */
17
+ readonly y?: number;
18
+ }
19
+ /** Options of {@link addHorseCrowd}. */
20
+ export interface HorseCrowdOptions extends Pick<HorseModelOptions, 'type' | 'withers' | 'condition' | 'speeds'> {
21
+ /** Coats to deal out, horse by horse in turn. Default bay, brown, chestnut, black, grey, dun. */
22
+ coats?: readonly HorseCoat[];
23
+ /** Bake rate, frames a second. Default 30. */
24
+ fps?: number;
25
+ /** Ground height under a point. Default flat at 0. */
26
+ ground?: (x: number, z: number) => number;
27
+ /** Most horses, 1 to 65536. Default 1024. */
28
+ capacity?: number;
29
+ }
30
+ /** What {@link addHorseCrowd} returns. */
31
+ export interface HorseCrowd {
32
+ readonly crowd: SkinnedCrowd;
33
+ readonly bake: BoneBake;
34
+ readonly body: HorseBody;
35
+ readonly clips: readonly HorseClip[];
36
+ /** Horses drawn now. */
37
+ readonly count: number;
38
+ /** The clip and blend a horse at this speed and distance draws, as `SkinnedCrowd` instance fields. */
39
+ pose(speed: number, distance: number): {
40
+ clip: number;
41
+ offset: number;
42
+ blendClip: number;
43
+ blendOffset: number;
44
+ blend: number;
45
+ };
46
+ /** Places every horse: one per entry, in order, and their saddles. Horses past the list are hidden. */
47
+ update(horses: readonly CrowdHorse[]): this;
48
+ /**
49
+ * The seat frame of every horse drawn, 16 numbers each (column-major, world space): +Y up out of the saddle, +Z
50
+ * toward the head, the origin the lowest point of the seat as the bone texture poses it now. Written by `update`.
51
+ */
52
+ readonly saddles: Float32Array;
53
+ /** The rig the bake follows: `skeleton.index('body')` is the trunk bone the saddle rides. */
54
+ readonly skeleton: HorseSkeleton;
55
+ dispose(): void;
56
+ [Symbol.dispose](): void;
57
+ }
58
+ /**
59
+ * The seat frame of one horse in the world (16 numbers, column-major) from its trunk bone's skinning matrix (12 numbers,
60
+ * the rows of the 3x4, as `@margoengine/animation/instanced-skin` `poseBone` gives it), the saddle's rest point in the
61
+ * model (`skeleton.saddle`) and where the horse stands.
62
+ */
63
+ export declare function saddleFrame(trunk: ArrayLike<number>, saddle: readonly [number, number, number] | readonly number[], horse: {
64
+ readonly x: number;
65
+ readonly y: number;
66
+ readonly z: number;
67
+ readonly heading: number;
68
+ }, out?: Float32Array, at?: number): Float32Array;
69
+ /**
70
+ * Builds a crowd of horses: one bake, one draw, a coat each.
71
+ * @example
72
+ * const herd = await addHorseCrowd(engine, {type: 'cavalry'});
73
+ * herd.update(army.members); // after army.advanceTime(dt)
74
+ * @throws TypeError or RangeError for bad options.
75
+ */
76
+ export declare function addHorseCrowd(engine: Engine, options?: HorseCrowdOptions): Promise<HorseCrowd>;
package/dist/crowd.js ADDED
@@ -0,0 +1,172 @@
1
+ import { t as e } from "./scene-scope-BIsfeY-W.js";
2
+ import { GAITS as t, GAIT_PATTERNS as n, froude as r } from "./gaits.js";
3
+ import { i, r as a, s as o } from "./model-D2H9-6oj.js";
4
+ //#region src/crowd.ts
5
+ var s = .12;
6
+ function c(e, t, n, r = /* @__PURE__ */ new Float32Array(16), i = 0) {
7
+ let a = e, [o, s, c] = t, l = Math.cos(n.heading), u = Math.sin(n.heading), d = a[0] * o + a[1] * s + a[2] * c + a[3], f = a[4] * o + a[5] * s + a[6] * c + a[7], p = a[8] * o + a[9] * s + a[10] * c + a[11];
8
+ for (let e = 0; e < 3; e++) {
9
+ let t = a[e], n = a[4 + e], o = a[8 + e], s = Math.hypot(t, n, o) || 1;
10
+ r[i + e * 4] = (l * t + u * o) / s, r[i + e * 4 + 1] = n / s, r[i + e * 4 + 2] = (-u * t + l * o) / s, r[i + e * 4 + 3] = 0;
11
+ }
12
+ return r[i + 12] = n.x + l * d + u * p, r[i + 13] = n.y + f, r[i + 14] = n.z - u * d + l * p, r[i + 15] = 1, r;
13
+ }
14
+ async function l(l, u = {}) {
15
+ let d = u.coats ?? [
16
+ "bay",
17
+ "brown",
18
+ "chestnut",
19
+ "black",
20
+ "grey",
21
+ "dun"
22
+ ], f = u.fps ?? 30, p = u.ground ?? (() => 0), m = u.capacity ?? 1024;
23
+ if (!Array.isArray(d) || !d.length || d.some((e) => !a.includes(e))) throw TypeError(`addHorseCrowd coats must be a list of ${a.join(", ")}`);
24
+ if (!(f >= 10 && f <= 120)) throw RangeError("addHorseCrowd fps must be 10 to 120");
25
+ if (!(Number.isInteger(m) && m >= 1 && m <= 65536)) throw RangeError("addHorseCrowd capacity must be 1 to 65536");
26
+ if (typeof p != "function") throw TypeError("addHorseCrowd ground must be a function (x, z) => height");
27
+ let h = e(l), [{ parseGLTFAsync: g }, { Animation: _ }, { bakeBones: v, SkinnedCrowd: y, poseBone: b }, { Texture: x }] = await Promise.all([
28
+ import("@margoengine/gltf/pbr"),
29
+ import("@margoengine/animation"),
30
+ import("@margoengine/animation/instanced-skin"),
31
+ import("@margoengine/materials")
32
+ ]), S = o({
33
+ ...u,
34
+ coat: "bay",
35
+ detail: 0,
36
+ atlas: !0
37
+ }), C = await h.run(() => g(l, S.doc, S.buffers)), w = new _(C), T = v(w, { fps: f });
38
+ w.dispose?.(), C.dispose?.();
39
+ let E = new x(i(), {
40
+ mipmaps: !1,
41
+ colorSpace: "srgb"
42
+ }), D = class extends y {
43
+ dispose() {
44
+ let e = this.disposed;
45
+ super.dispose(), e || E.dispose?.();
46
+ }
47
+ }, O = h.run(() => {
48
+ let e = new D(T, {
49
+ map: E,
50
+ roughness: .6
51
+ });
52
+ return l.use(e), e;
53
+ }), k = new Map(S.clips.map((e, t) => [e.name, t])), A = a.indexOf("bay"), j = 0, M = new Float32Array(m * 16), N = S.skeleton.index("body"), P = /* @__PURE__ */ new Float32Array(12);
54
+ if (!(N >= 0 && N < T.bones)) throw RangeError("addHorseCrowd needs the trunk bone in the bake; bake the horse of horseDocument");
55
+ let F = { matrix: [
56
+ 0,
57
+ 0,
58
+ 0,
59
+ 0,
60
+ 0,
61
+ 0,
62
+ 0,
63
+ 0,
64
+ 0,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 0,
69
+ -1e6,
70
+ 0,
71
+ 1
72
+ ] }, I = (e, t, n) => {
73
+ let r = S.clips[k.get(e)];
74
+ if (e === "stand") return {
75
+ clip: k.get("stand"),
76
+ offset: n % r.duration
77
+ };
78
+ let i = t / r.strideLength;
79
+ return {
80
+ clip: k.get(e),
81
+ offset: (i - Math.floor(i)) * r.duration
82
+ };
83
+ }, L = (e, i) => {
84
+ if (!(e >= 0) || !Number.isFinite(i)) throw RangeError("A crowd horse needs a speed of 0 or more and a finite distance");
85
+ if (e < .05) {
86
+ let e = I("stand", 0, i);
87
+ return {
88
+ clip: e.clip,
89
+ offset: e.offset,
90
+ blendClip: e.clip,
91
+ blendOffset: e.offset,
92
+ blend: 0
93
+ };
94
+ }
95
+ let a = r(S.body, e), o = "gallop";
96
+ for (let e of t) if (a < n[e].froude[1]) {
97
+ o = e;
98
+ break;
99
+ }
100
+ let c = I(o, i, 0), l = n[o].froude[1], u = t.indexOf(o), d = t[u + 1], f = 0, p = c;
101
+ return d && a > l * .88 && (p = I(d, i, 0), f = .5 * ((a - l * .88) / (l * s))), {
102
+ clip: c.clip,
103
+ offset: c.offset,
104
+ blendClip: p.clip,
105
+ blendOffset: p.offset,
106
+ blend: Math.min(.5, f)
107
+ };
108
+ }, R = !1, z = () => {
109
+ R || (R = !0, O.dispose?.());
110
+ }, B = {
111
+ crowd: O,
112
+ bake: T,
113
+ body: S.body,
114
+ clips: S.clips,
115
+ saddles: M,
116
+ skeleton: S.skeleton,
117
+ get count() {
118
+ return j;
119
+ },
120
+ pose: L,
121
+ update(e) {
122
+ if (!Array.isArray(e) && !(e && typeof e.length == "number")) throw TypeError("HorseCrowd update needs a list of {x, z, heading, speed, distance}");
123
+ if (e.length > m) throw RangeError(`HorseCrowd holds ${m} horses; raise capacity`);
124
+ for (let t = 0; t < e.length; t++) {
125
+ let n = e[t], r = Math.cos(n.heading), i = Math.sin(n.heading), o = n.y ?? p(n.x, n.z), s = L(n.speed, n.distance), l = a.indexOf(d[t % d.length]), u = {
126
+ matrix: [
127
+ r,
128
+ 0,
129
+ -i,
130
+ 0,
131
+ 0,
132
+ 1,
133
+ 0,
134
+ 0,
135
+ i,
136
+ 0,
137
+ r,
138
+ 0,
139
+ n.x,
140
+ o,
141
+ n.z,
142
+ 1
143
+ ],
144
+ clip: s.clip,
145
+ offset: s.offset,
146
+ speed: 0,
147
+ blendClip: s.blendClip,
148
+ blendOffset: s.blendOffset,
149
+ blendSpeed: 0,
150
+ blend: s.blend,
151
+ uvTransform: {
152
+ offset: [(l - A) / a.length, 0],
153
+ scale: [1, 1]
154
+ }
155
+ };
156
+ t < j ? O.set(t, u) : O.add(u), b(T, u, N, 0, P), c(P, S.skeleton.saddle, {
157
+ x: n.x,
158
+ y: o,
159
+ z: n.z,
160
+ heading: n.heading
161
+ }, M, t * 16);
162
+ }
163
+ for (let t = e.length; t < j; t++) O.set(t, F);
164
+ return j = Math.max(j, e.length), B;
165
+ },
166
+ dispose: z,
167
+ [Symbol.dispose]: z
168
+ };
169
+ return B;
170
+ }
171
+ //#endregion
172
+ export { l as addHorseCrowd, c as saddleFrame };
@@ -0,0 +1,39 @@
1
+ import type { HorseBody } from './anatomy.js';
2
+ type Ground = (x: number, z: number) => number;
3
+ type Footprint = Pick<HorseBody, 'bodyLength' | 'chestWidth' | 'hipWidth'>;
4
+ export interface HorseSurface {
5
+ /** Mean support height, m. */
6
+ readonly height: number;
7
+ /** Change in height over forward distance. */
8
+ readonly forward: number;
9
+ /** Change in height over rightward distance. */
10
+ readonly right: number;
11
+ }
12
+ export declare const LEVEL_SURFACE: HorseSurface;
13
+ /** Samples each side of the hind and fore support footprint independently. */
14
+ export declare function horseSurface(body: Footprint, ground: Ground | undefined, x: number, z: number, heading: number): HorseSurface;
15
+ interface HorseDriveState {
16
+ readonly speed: number;
17
+ readonly sidewaysSpeed: number;
18
+ readonly heading: number;
19
+ }
20
+ interface HorseDrive {
21
+ readonly strength: number;
22
+ readonly mass: number;
23
+ readonly grip: number;
24
+ readonly turnRate: number;
25
+ }
26
+ interface HorseCommand {
27
+ readonly speed: number;
28
+ readonly heading: number;
29
+ }
30
+ /** A reduced traction-circle drive for a horse's authored controller. All accelerations are SI. */
31
+ export declare function advanceHorseDrive(state: HorseDriveState, command: HorseCommand, surface: HorseSurface, drive: HorseDrive, dt: number): {
32
+ speed: number;
33
+ heading: number;
34
+ sidewaysSpeed: number;
35
+ lateralAcceleration: number;
36
+ normalGravity: number;
37
+ slipping: boolean;
38
+ };
39
+ export {};
@@ -0,0 +1,93 @@
1
+ import type { HorseBody } from './anatomy.js';
2
+ /** The four natural gaits. */
3
+ export type Gait = 'walk' | 'trot' | 'canter' | 'gallop';
4
+ /** Every gait, slowest first. */
5
+ export declare const GAITS: readonly Gait[];
6
+ /** A hoof: left or right, hind or fore. */
7
+ export type Hoof = 'LH' | 'LF' | 'RH' | 'RF';
8
+ /** The four hooves in the order every per-hoof array uses. */
9
+ export declare const HOOVES: readonly Hoof[];
10
+ /** Footfall pattern of one gait (left lead for canter and gallop). */
11
+ export interface GaitPattern {
12
+ /** Phase of the stride, 0 to 1, at which each hoof strikes the ground, in {@link HOOVES} order. */
13
+ readonly strike: readonly [number, number, number, number];
14
+ /** Froude numbers u^2/gh where the gait starts and ends. */
15
+ readonly froude: readonly [number, number];
16
+ /** Duty factor (stance time over stride time) at the slow and fast end of the gait. */
17
+ readonly duty: readonly [number, number];
18
+ /** Froude number of the gait's preferred speed, where its clip is baked. */
19
+ readonly preferred: number;
20
+ /** Trunk rises and falls this many times a stride. */
21
+ readonly bounces: 1 | 2;
22
+ /** Trunk vertical motion, peak to peak, as a ratio of withers height. */
23
+ readonly rise: number;
24
+ /** Trunk pitch, peak to peak, radians (the rocking of the canter and gallop). */
25
+ readonly pitch: number;
26
+ /** Swing hoof lift, fore and hind, as a ratio of withers height. */
27
+ readonly lift: readonly [number, number];
28
+ /** Head and neck nod, peak to peak, radians. */
29
+ readonly nod: number;
30
+ }
31
+ /**
32
+ * The published patterns. Walk: lateral sequence, each fore hoof a quarter stride after the hind of its side, duty 0.75
33
+ * to 0.6, never fewer than two hooves down. Trot: diagonal pairs half a stride apart, duty 0.48 to 0.36, two short
34
+ * suspensions. Canter (left lead): trailing hind, the diagonal pair (leading hind just before trailing fore), leading
35
+ * fore, one suspension. Gallop (left lead, transverse): trailing hind, leading hind, trailing fore, leading fore, one
36
+ * long suspension.
37
+ */
38
+ export declare const GAIT_PATTERNS: Readonly<Record<Gait, GaitPattern>>;
39
+ /** Standard gravity, m/s^2. */
40
+ export declare const GRAVITY = 9.80665;
41
+ /** Froude number u^2/gh of a speed for this horse (h its hip joint height). */
42
+ export declare function froude(body: Pick<HorseBody, 'hipJoint'>, speed: number): number;
43
+ /** The speed in m/s of a Froude number for this horse. */
44
+ export declare function speedAtFroude(body: Pick<HorseBody, 'hipJoint'>, fr: number): number;
45
+ /** The gait a horse takes at this speed (by Froude number, so a pony changes gait sooner than a Shire). */
46
+ export declare function gaitFor(body: Pick<HorseBody, 'hipJoint'>, speed: number): Gait;
47
+ /** The gait's preferred speed for this horse, m/s: where its clip is baked. */
48
+ export declare function preferredSpeed(body: Pick<HorseBody, 'hipJoint'>, gait: Gait): number;
49
+ /** Stride length in metres at this speed: lambda = 2.3 h (u^2/gh)^0.3 (Alexander and Jayes 1983). 0 at rest. */
50
+ export declare function strideLength(body: Pick<HorseBody, 'hipJoint'>, speed: number): number;
51
+ /** Strides per second at this speed: speed over stride length. */
52
+ export declare function strideFrequency(body: Pick<HorseBody, 'hipJoint'>, speed: number): number;
53
+ /** Everything one stride needs: the gait, the timing and the reach. */
54
+ export interface Stride {
55
+ readonly gait: Gait;
56
+ readonly speed: number;
57
+ /** Metres covered in one stride. */
58
+ readonly length: number;
59
+ /** Seconds per stride. */
60
+ readonly duration: number;
61
+ /** Stance time over stride time, the same for all four hooves. */
62
+ readonly duty: number;
63
+ /** Strike phase of each hoof in {@link HOOVES} order. */
64
+ readonly strike: readonly [number, number, number, number];
65
+ readonly pattern: GaitPattern;
66
+ }
67
+ /**
68
+ * The stride at this speed. `gait` forces a gait (a slow canter, a fast walk); left out it follows the speed.
69
+ * @throws RangeError for a speed that is not finite and positive.
70
+ */
71
+ export declare function stride(body: HorseBody, speed: number, gait?: Gait): Stride;
72
+ /**
73
+ * Where a hoof is in its cycle at stride phase `phase` (0 to 1): `stance` true while it bears weight, and `t` running 0
74
+ * to 1 through the stance or through the swing.
75
+ */
76
+ export declare function hoofPhase(s: Pick<Stride, 'duty' | 'strike'>, hoof: number, phase: number): {
77
+ stance: boolean;
78
+ t: number;
79
+ };
80
+ /** How many hooves are on the ground at this phase. */
81
+ export declare function hoovesDown(s: Pick<Stride, 'duty' | 'strike'>, phase: number): number;
82
+ /** Trunk motion at a stride phase: height offset (m), pitch (radians, nose down positive) and head nod (radians). */
83
+ export interface TrunkMotion {
84
+ readonly rise: number;
85
+ readonly pitch: number;
86
+ readonly nod: number;
87
+ }
88
+ /**
89
+ * The trunk's rise and pitch at stride phase `phase`: lowest at mid-support, `bounces` cycles a stride, peak to peak
90
+ * rise reference times the withers height. A shorter duty concentrates support in less time and increases
91
+ * the spring excursion. The canter and gallop rock as the hind legs push.
92
+ */
93
+ export declare function trunkMotion(body: HorseBody, s: Stride, phase: number): TrunkMotion;
package/dist/gaits.js ADDED
@@ -0,0 +1,165 @@
1
+ import { pow as e } from "@margoengine/math/pinned";
2
+ //#region src/gaits.ts
3
+ var t = [
4
+ "walk",
5
+ "trot",
6
+ "canter",
7
+ "gallop"
8
+ ], n = [
9
+ "LH",
10
+ "LF",
11
+ "RH",
12
+ "RF"
13
+ ], r = {
14
+ walk: {
15
+ strike: [
16
+ 0,
17
+ .25,
18
+ .5,
19
+ .75
20
+ ],
21
+ froude: [0, .4],
22
+ duty: [.75, .6],
23
+ preferred: .24,
24
+ bounces: 2,
25
+ rise: .025,
26
+ pitch: .02,
27
+ lift: [.08, .07],
28
+ nod: .12
29
+ },
30
+ trot: {
31
+ strike: [
32
+ 0,
33
+ .5,
34
+ .5,
35
+ 0
36
+ ],
37
+ froude: [.4, 2.4],
38
+ duty: [.48, .36],
39
+ preferred: 1.5,
40
+ bounces: 2,
41
+ rise: .05,
42
+ pitch: .015,
43
+ lift: [.17, .13],
44
+ nod: .03
45
+ },
46
+ canter: {
47
+ strike: [
48
+ .24,
49
+ .5,
50
+ 0,
51
+ .28
52
+ ],
53
+ froude: [2.4, 6.5],
54
+ duty: [.46, .36],
55
+ preferred: 4.6,
56
+ bounces: 1,
57
+ rise: .065,
58
+ pitch: .14,
59
+ lift: [.18, .15],
60
+ nod: .16
61
+ },
62
+ gallop: {
63
+ strike: [
64
+ .11,
65
+ .47,
66
+ 0,
67
+ .36
68
+ ],
69
+ froude: [6.5, 40],
70
+ duty: [.32, .22],
71
+ preferred: 18,
72
+ bounces: 1,
73
+ rise: .055,
74
+ pitch: .1,
75
+ lift: [.22, .18],
76
+ nod: .2
77
+ }
78
+ }, i = 9.80665, a = (e) => {
79
+ let t = e?.hipJoint;
80
+ if (!(t > 0) || !Number.isFinite(t)) throw TypeError("Gait functions need a horseBody() (its hipJoint height)");
81
+ return t;
82
+ }, o = (e) => {
83
+ if (!(e >= 0) || !Number.isFinite(e)) throw RangeError("A gait speed must be a finite number of metres per second, 0 or more");
84
+ return e;
85
+ };
86
+ function s(e, t) {
87
+ let n = o(t);
88
+ return n * n / (i * a(e));
89
+ }
90
+ function c(e, t) {
91
+ if (!(t >= 0) || !Number.isFinite(t)) throw RangeError("speedAtFroude needs a finite Froude number, 0 or more");
92
+ return Math.sqrt(t * i * a(e));
93
+ }
94
+ function l(e, n) {
95
+ let i = s(e, n);
96
+ for (let e of t) if (i < r[e].froude[1]) return e;
97
+ return "gallop";
98
+ }
99
+ function u(e, n) {
100
+ let i = r[n];
101
+ if (!i) throw TypeError(`Unknown gait; use one of ${t.join(", ")}`);
102
+ return c(e, i.preferred);
103
+ }
104
+ function d(t, n) {
105
+ let r = s(t, n);
106
+ return r === 0 ? 0 : 2.3 * a(t) * e(r, .3);
107
+ }
108
+ function f(e, t) {
109
+ let n = d(e, t);
110
+ return n === 0 ? 0 : t / n;
111
+ }
112
+ function p(e, t) {
113
+ let [n, r] = e.froude, i = Math.min(1, Math.max(0, (t - n) / (r - n)));
114
+ return e.duty[0] + (e.duty[1] - e.duty[0]) * i;
115
+ }
116
+ function m(e, n, i = l(e, n)) {
117
+ if (!(n > 0)) throw RangeError("stride needs a speed above 0 m/s; a standing horse has no stride");
118
+ let a = r[i];
119
+ if (!a) throw TypeError(`Unknown gait; use one of ${t.join(", ")}`);
120
+ let o = p(a, s(e, n)), c = d(e, n);
121
+ return {
122
+ gait: i,
123
+ speed: n,
124
+ length: c,
125
+ duration: c / n,
126
+ duty: o,
127
+ strike: a.strike,
128
+ pattern: a
129
+ };
130
+ }
131
+ var h = (e) => e - Math.floor(e);
132
+ function g(e, t, n) {
133
+ let r = h(n - e.strike[t]);
134
+ return r < e.duty ? {
135
+ stance: !0,
136
+ t: r / e.duty
137
+ } : {
138
+ stance: !1,
139
+ t: (r - e.duty) / (1 - e.duty)
140
+ };
141
+ }
142
+ function _(e, t) {
143
+ let n = 0;
144
+ for (let r = 0; r < 4; r++) g(e, r, t).stance && n++;
145
+ return n;
146
+ }
147
+ function v(e) {
148
+ if (e.pattern.bounces === 2) return h(e.strike[0] + e.duty / 2);
149
+ let t = 0, n = 0;
150
+ for (let r = 0; r < 4; r++) {
151
+ let i = 2 * Math.PI * (e.strike[r] + e.duty / 2);
152
+ t += Math.cos(i), n += Math.sin(i);
153
+ }
154
+ return h(Math.atan2(n, t) / (2 * Math.PI));
155
+ }
156
+ function y(e, t, n) {
157
+ let r = v(t), i = t.pattern.bounces, a = 2 * Math.PI * i * (n - r), o = p(t.pattern, t.pattern.preferred);
158
+ return {
159
+ rise: -(t.pattern.rise * e.withers * o / (2 * t.duty)) * Math.cos(a),
160
+ pitch: t.pattern.pitch / 2 * Math.sin(2 * Math.PI * (n - r)),
161
+ nod: t.pattern.nod / 2 * Math.cos(a + .6)
162
+ };
163
+ }
164
+ //#endregion
165
+ export { t as GAITS, r as GAIT_PATTERNS, i as GRAVITY, n as HOOVES, s as froude, l as gaitFor, g as hoofPhase, _ as hoovesDown, u as preferredSpeed, c as speedAtFroude, m as stride, f as strideFrequency, d as strideLength, y as trunkMotion };
@@ -0,0 +1,14 @@
1
+ import { type HorsePose, type HorseSkeleton } from './model.js';
2
+ type PathFrame = {
3
+ x: number;
4
+ z: number;
5
+ heading: number;
6
+ bank?: number;
7
+ };
8
+ /** Evaluates the four contact points in world space and remembers plants between fixed steps. */
9
+ export declare function horseGrounding(skeleton: HorseSkeleton, ground: (x: number, z: number) => number): {
10
+ advance: (frame: PathFrame, time: number, support: readonly boolean[], readPose: () => HorsePose, swingDuration: number) => void;
11
+ fit: (frame: PathFrame, rootHeight: number, time: number, pose: HorsePose) => HorsePose;
12
+ reset(): void;
13
+ };
14
+ export {};