@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,176 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { Engine } from '@margoengine/core';
3
+ import type { PBRModel } from '@margoengine/gltf/pbr-model';
4
+ import type { Animation } from '@margoengine/animation';
5
+ import type { MaterialInstallation } from '@margoengine/materials';
6
+ import type { HairOptions } from '@margoengine/materials/hair';
7
+ import type { HorseBody } from './anatomy.js';
8
+ import { type Gait } from './gaits.js';
9
+ import { type HorseClip, type HorseModelOptions, type HorsePose, type HorseSkeleton } from './model.js';
10
+ /** Anything a horse can join for shadows or ambient occlusion: `Shadows`, a `GTAO` pass, a scene's `parts`. */
11
+ export interface HorseReceiver {
12
+ add(source: never, ...rest: never[]): unknown;
13
+ }
14
+ /** An artist's skinned horse posed by the package's runtime gait controller. The caller owns the model. */
15
+ export interface HorseSkin {
16
+ /** Loaded skinned glTF in the same engine and in metres, facing +Z. */
17
+ readonly model: PBRModel;
18
+ /** Native or fitted skeleton in the rig's model space. */
19
+ readonly skeleton: HorseSkeleton;
20
+ /** Apply the solved model-space pose to the skin's joints. Root placement and yaw are applied by the controller. */
21
+ applyPose(pose: HorsePose): void;
22
+ }
23
+ /** Options of {@link addHorse}. Every one is optional; the defaults give a bay riding horse standing at the origin. */
24
+ export interface HorseOptions extends HorseModelOptions {
25
+ /** Use an existing skinned horse and preserve its materials. Default builds a procedural horse. */
26
+ readonly skin?: HorseSkin;
27
+ /** Starting position on the ground, `[x, z]`. Default `[0, 0]`. */
28
+ position?: readonly [number, number];
29
+ /** Starting heading in radians about +Y, 0 facing +Z. Default 0. */
30
+ heading?: number;
31
+ /** Ground height in metres. Fits and plants individual hooves on the supplied surface. Default flat ground at 0. */
32
+ ground?: (x: number, z: number) => number;
33
+ /** Most the speed changes per second, m/s^2. Default 3 (a riding horse reaches a gallop in about 4 s). */
34
+ acceleration?: number;
35
+ /** Most the heading turns per second, radians, before the available hoof grip further limits it. Default 1.2. */
36
+ turnRate?: number;
37
+ /** Hoof to ground friction coefficient. Default 0.6. */
38
+ grip?: number;
39
+ /** Mass carried by the horse in kg. Default zero. Reduces acceleration for the same driving force. */
40
+ loadMass?: number;
41
+ /** Seconds a gait change cross-fades. Default 0.3. */
42
+ fade?: number;
43
+ /** Strand hair on the coat (along the body and down the legs), or false. Default `{strands: 400, specular: 0.45}`. */
44
+ coatHair?: HairOptions | false;
45
+ /** Strand hair on the mane and tail cards, or false. Default `{strands: 1024}`. */
46
+ maneHair?: HairOptions | false;
47
+ /** Shadows to cast into, or false. Default the `Shadows` attached to the scene, if any. */
48
+ shadows?: HorseReceiver | false;
49
+ /** An ambient occlusion pass to join. Default none. */
50
+ occlusion?: HorseReceiver | false;
51
+ }
52
+ /** Terrain and carried-load controls for a standalone HorseMotion. */
53
+ export type HorseSupportOptions = Pick<HorseOptions, 'ground' | 'grip' | 'loadMass'>;
54
+ /** The horse's place and rider seat in world space at the current time. */
55
+ export interface HorseFrame {
56
+ readonly position: readonly [number, number, number];
57
+ readonly heading: number;
58
+ /** The saddle seat point in world space. */
59
+ readonly saddle: readonly [number, number, number];
60
+ /** The trunk's world rotation (quaternion): yaw, then the trunk's pitch. */
61
+ readonly saddleRotation: readonly [number, number, number, number];
62
+ }
63
+ /** What {@link addHorse} returns. Dispose it (or use `using`) to take the horse off the engine. */
64
+ export interface Horse {
65
+ readonly model: PBRModel;
66
+ readonly animation: Animation;
67
+ readonly materials: MaterialInstallation | undefined;
68
+ readonly body: HorseBody;
69
+ readonly skeleton: HorseSkeleton;
70
+ readonly clips: readonly HorseClip[];
71
+ /** Film time in seconds. */
72
+ readonly time: number;
73
+ /** The speed asked for, m/s; the horse eases to it at `acceleration`. */
74
+ speed: number;
75
+ /** The heading asked for, radians; the horse turns to it at `turnRate`. */
76
+ heading: number;
77
+ /** Force a gait (a collected canter, an extended walk) or `'auto'` to follow the speed. Default `'auto'`. */
78
+ gait: Gait | 'auto';
79
+ /** The speed now, m/s. */
80
+ readonly currentSpeed: number;
81
+ /** The gait now, or `'stand'`. */
82
+ readonly currentGait: Gait | 'stand';
83
+ /** Metres travelled since time 0. */
84
+ readonly distance: number;
85
+ /** The pose now. */
86
+ readonly pose: HorsePose;
87
+ /** Position, heading and the saddle now. */
88
+ frame(): HorseFrame;
89
+ /** Flicks the tail from the current film time. Strength defaults to 1 and side to left. */
90
+ flickTail(strength?: number, side?: 'left' | 'right'): void;
91
+ /** Moves film time forward by `delta` seconds (fixed 1/240 s steps inside). */
92
+ advanceTime(delta: number): this;
93
+ /** Jumps to film time `time`, replaying every speed, heading and gait set since 0: the same as playing up to it. */
94
+ seek(time: number): this;
95
+ /** Called after every fixed step with the step length (a rider's seat follows here). Returns the remover. */
96
+ onStep(step: (dt: number, horse: Horse) => void, reset?: () => void): () => void;
97
+ /** Adds a post-step pose solver before skinning. Returns the remover. */
98
+ onPose(modify: (pose: HorsePose, horse: Horse) => HorsePose): () => void;
99
+ dispose(): void;
100
+ [Symbol.dispose](): void;
101
+ }
102
+ /** Pose blend: `t` of `b` over `a`. */
103
+ export declare function blendPoses(a: HorsePose, b: HorsePose, t: number): HorsePose;
104
+ /**
105
+ * The motion state of one horse, stepped on a fixed clock: speed easing, turning, the odometer, the gait with a fade
106
+ * and the stride phase of each gait. Shared by {@link addHorse} and usable alone (a pure simulation).
107
+ */
108
+ export declare class HorseMotion {
109
+ readonly body: HorseBody;
110
+ readonly options: {
111
+ position?: readonly [number, number];
112
+ heading?: number;
113
+ acceleration?: number;
114
+ turnRate?: number;
115
+ fade?: number;
116
+ };
117
+ speed: number;
118
+ heading: number;
119
+ x: number;
120
+ z: number;
121
+ distance: number;
122
+ gait: Gait | 'stand';
123
+ previous: Gait | 'stand';
124
+ /** Left or right slip velocity in m/s relative to heading. */
125
+ sidewaysSpeed: number;
126
+ /** True when the requested shear exceeds the available grip. */
127
+ slipping: boolean;
128
+ /** Bank of the trunk about its forward axis, radians. */
129
+ bank: number;
130
+ private cycleTravel;
131
+ private support;
132
+ /** Fade from `previous` to `gait`, 0 to 1. */
133
+ fade: number;
134
+ /** Odometer reading where each gait's phase is 0. */
135
+ private readonly start;
136
+ constructor(body: HorseBody, options?: {
137
+ position?: readonly [number, number];
138
+ heading?: number;
139
+ acceleration?: number;
140
+ turnRate?: number;
141
+ fade?: number;
142
+ });
143
+ /** Configure terrain, hoof grip and carried kilograms for subsequent steps. */
144
+ setSupport(options: HorseSupportOptions): this;
145
+ /** Four independently sampled hoof support elevations summarized at this body frame. */
146
+ supportHeight(x?: number, z?: number, heading?: number): number;
147
+ private driven;
148
+ /** The gait a speed asks for, with 5 percent hysteresis around each boundary so a steady speed never flickers. */
149
+ pick(speed: number, forced: Gait | 'auto'): Gait | 'stand';
150
+ /** Speed after one acceleration-limited step toward the target, in metres per second. */
151
+ speedAfter(dt: number, target: number): number;
152
+ step(dt: number, target: {
153
+ speed: number;
154
+ heading: number;
155
+ gait: Gait | 'auto';
156
+ }): void;
157
+ /** Continuous stride cycles from travel at the current speed and the actual length of each stride. */
158
+ strideCyclesAt(distance?: number): number;
159
+ /** Stride phase 0 to 1 of a gait whose clip covers `strideLength` metres a stride. */
160
+ phase(gait: Gait, strideLength: number): number;
161
+ /** The phase at another odometer reading (a display time between fixed steps). */
162
+ phaseAt(gait: Gait, strideLength: number, distance: number): number;
163
+ }
164
+ /**
165
+ * Builds a horse and puts it in the engine's scene: a measured body for its breed group, coat, markings, mane and tail,
166
+ * strand hair shading, dual quaternion skinning and gaits that follow `horse.speed`. Resolves to a {@link Horse}.
167
+ * @example
168
+ * const horse = await addHorse(engine, {type: 'cavalry', coat: 'bay'});
169
+ * horse.speed = 4; // eases into a trot
170
+ * horse.advanceTime(1 / 30); // or seek(12.5) for a film frame
171
+ * @throws TypeError or RangeError for bad options.
172
+ */
173
+ export declare function addHorse(engine: Engine, options?: HorseOptions): Promise<Horse>;
174
+ export type { HorseBody, HorseBodyOptions, HorseType } from './anatomy.js';
175
+ export type { Gait } from './gaits.js';
176
+ export type { HorseClip, HorseCoat, HorseMarkings, HorseModelOptions, HorsePose, HorseSkeleton } from './model.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { t as HorseMotion, n as addHorse, r as blendPoses } from "./src-CAiGrBte.js";