@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +347 -2
- package/dist/anatomy.d.ts +75 -0
- package/dist/anatomy.js +89 -0
- package/dist/clip-plan.d.ts +10 -0
- package/dist/crowd.d.ts +76 -0
- package/dist/crowd.js +172 -0
- package/dist/drive.d.ts +39 -0
- package/dist/gaits.d.ts +93 -0
- package/dist/gaits.js +165 -0
- package/dist/grounding.d.ts +14 -0
- package/dist/index.d.ts +176 -0
- package/dist/index.js +1 -0
- package/dist/model-D2H9-6oj.js +1503 -0
- package/dist/model.d.ts +159 -0
- package/dist/model.js +1 -0
- package/dist/scene-scope-BIsfeY-W.js +42 -0
- package/dist/seat.d.ts +93 -0
- package/dist/seat.js +164 -0
- package/dist/settings.d.ts +29 -0
- package/dist/settings.js +126 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/src-CAiGrBte.js +531 -0
- package/dist/strands.d.ts +30 -0
- package/dist/strands.js +135 -0
- package/package.json +84 -4
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type HorseBody, type HorseBodyOptions } from './anatomy.js';
|
|
2
|
+
import { type Gait, type Stride } from './gaits.js';
|
|
3
|
+
type V3 = [number, number, number];
|
|
4
|
+
/** One joint of the rig: its name, parent index (-1 for the root) and rest position in model space. */
|
|
5
|
+
export interface HorseJoint {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly parent: number;
|
|
8
|
+
readonly rest: readonly [number, number, number];
|
|
9
|
+
}
|
|
10
|
+
/** The rig of one horse: joints in parent-first order, and the leg chains by hoof. */
|
|
11
|
+
export interface HorseSkeleton {
|
|
12
|
+
readonly body: HorseBody;
|
|
13
|
+
readonly joints: readonly HorseJoint[];
|
|
14
|
+
/**
|
|
15
|
+
* Joint indices of each leg, top to bottom, LH LF RH RF: hind thigh, gaskin, cannon, pastern, hoof; fore scapula,
|
|
16
|
+
* arm, forearm, cannon, pastern, hoof. The hoof is always last.
|
|
17
|
+
*/
|
|
18
|
+
readonly legs: readonly (readonly number[])[];
|
|
19
|
+
/** Where each hoof touches the ground standing, model space, LH LF RH RF. */
|
|
20
|
+
readonly ground: readonly (readonly [number, number, number])[];
|
|
21
|
+
/** The saddle seat point (lowest point of the seat, behind the withers), model space at rest. */
|
|
22
|
+
readonly saddle: readonly [number, number, number];
|
|
23
|
+
/** Tail, mane and forelock joint chains when built with the physical strand rig. The tail is first. */
|
|
24
|
+
readonly strandChains?: readonly (readonly number[])[];
|
|
25
|
+
/** Index of a joint by name. */
|
|
26
|
+
index(name: string): number;
|
|
27
|
+
}
|
|
28
|
+
/** The rig for a body: joint rest positions from its measurements. */
|
|
29
|
+
export declare function horseSkeleton(body: HorseBody, tailLength?: number, maneLength?: number): HorseSkeleton;
|
|
30
|
+
/** A pose: each joint's local rotation (quaternion x, y, z, w) and the body joint's offset from rest. */
|
|
31
|
+
export interface HorsePose {
|
|
32
|
+
readonly rotations: readonly (readonly [number, number, number, number])[];
|
|
33
|
+
/** Added to the body joint's rest translation. */
|
|
34
|
+
readonly bodyOffset: readonly [number, number, number];
|
|
35
|
+
/** Per-joint local translations authored by a pose solver, in metres. */
|
|
36
|
+
readonly jointTranslations?: ReadonlyMap<number, readonly [number, number, number]>;
|
|
37
|
+
/** Left and right scapula displacement on the thorax, in the body's local frame. */
|
|
38
|
+
readonly scapulaOffsets?: readonly [Readonly<V3>, Readonly<V3>];
|
|
39
|
+
}
|
|
40
|
+
/** A joint's local translation in a pose, including the shoulder blades' slide on the thorax. */
|
|
41
|
+
export declare function horseJointTranslation(skeleton: HorseSkeleton, pose: HorsePose, index: number): V3;
|
|
42
|
+
/** Each joint's model-space position in a pose (forward kinematics), as [x, y, z] per joint. */
|
|
43
|
+
export declare function poseJoints(skeleton: HorseSkeleton, pose: HorsePose): [number, number, number][];
|
|
44
|
+
/** Where each hoof's ground point is in a pose, model space, LH LF RH RF. */
|
|
45
|
+
export declare function poseHooves(skeleton: HorseSkeleton, pose: HorsePose): [number, number, number][];
|
|
46
|
+
/** The saddle seat in a pose: its position and the trunk's rotation (model space). */
|
|
47
|
+
export declare function poseSaddle(skeleton: HorseSkeleton, pose: HorsePose): {
|
|
48
|
+
position: [number, number, number];
|
|
49
|
+
rotation: [number, number, number, number];
|
|
50
|
+
};
|
|
51
|
+
/** Stance fraction where breakover starts. */
|
|
52
|
+
export declare const BREAKOVER = 0.8;
|
|
53
|
+
/**
|
|
54
|
+
* The pose at stride phase `phase` (0 to 1) of a stride, or the standing pose at `time` seconds when `s` is null. The
|
|
55
|
+
* root stays at the origin: in a stride the ground moves backward under the horse at `s.speed`, so a stance hoof keeps
|
|
56
|
+
* still once the root moves forward at that speed. `amplitude` (0–1, default 1) scales the gait toward standing
|
|
57
|
+
* while solving the hoof targets, including at the reduced stride lengths of a start or stop.
|
|
58
|
+
* @throws RangeError if amplitude is outside 0–1.
|
|
59
|
+
*/
|
|
60
|
+
export declare function horsePose(skeleton: HorseSkeleton, s: Stride | null, phase?: number, time?: number, amplitude?: number): HorsePose;
|
|
61
|
+
/** One hoof's contact goal in model space, with terrain pitch and roll in radians. */
|
|
62
|
+
export interface HorseHoofTarget {
|
|
63
|
+
readonly point: Readonly<V3>;
|
|
64
|
+
readonly pitch: number;
|
|
65
|
+
readonly roll: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Fits a gait pose to contact points in LH, LF, RH, RF order. Shoulder and hip splay is capped at 0.35 radians.
|
|
69
|
+
* Each leg retains its six joint lengths and its original bending side. Reachable goals are solved exactly.
|
|
70
|
+
* The trunk leans with the supplied ground plane while retaining the underlying gait and tail motion.
|
|
71
|
+
*/
|
|
72
|
+
export declare function fitHorseHooves(skeleton: HorseSkeleton, pose: HorsePose, targets: readonly HorseHoofTarget[], pitch?: number, roll?: number): HorsePose;
|
|
73
|
+
/**
|
|
74
|
+
* Layers one timed swat over a horse pose. The dock starts the turn and the hair follows with increasing delay.
|
|
75
|
+
* `seconds` is time since the swat began. `strength` is 0–1. `side` is +1 left or -1 right.
|
|
76
|
+
* @throws RangeError for a non-finite time, invalid strength, or invalid side.
|
|
77
|
+
*/
|
|
78
|
+
export declare function horseTailFlick(skeleton: HorseSkeleton, pose: HorsePose, seconds: number, strength?: number, side?: -1 | 1): HorsePose;
|
|
79
|
+
/** A coat colour. */
|
|
80
|
+
export type HorseCoat = 'bay' | 'chestnut' | 'black' | 'grey' | 'dun' | 'brown';
|
|
81
|
+
/** Every coat, in panel order. */
|
|
82
|
+
export declare const HORSE_COATS: readonly HorseCoat[];
|
|
83
|
+
/** Linear RGB of a coat's body, points (lower legs, muzzle), mane and tail. */
|
|
84
|
+
export interface CoatColors {
|
|
85
|
+
readonly body: readonly [number, number, number];
|
|
86
|
+
readonly points: readonly [number, number, number];
|
|
87
|
+
readonly mane: readonly [number, number, number];
|
|
88
|
+
}
|
|
89
|
+
/** The coats. Bay, dun and brown have black points, mane and tail; a dun carries a dorsal stripe. */
|
|
90
|
+
export declare const COAT_COLORS: Readonly<Record<HorseCoat, CoatColors>>;
|
|
91
|
+
/** White markings. */
|
|
92
|
+
export interface HorseMarkings {
|
|
93
|
+
/** Height of a white sock on each leg in metres (0 none), LH LF RH RF. Default none. */
|
|
94
|
+
socks?: readonly [number, number, number, number];
|
|
95
|
+
/** A white blaze down the face. Default false. */
|
|
96
|
+
blaze?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** Options of {@link horseDocument}. */
|
|
99
|
+
export interface HorseModelOptions extends HorseBodyOptions {
|
|
100
|
+
/** The coat. Default `'bay'`. */
|
|
101
|
+
coat?: HorseCoat;
|
|
102
|
+
/** White markings. Default none. */
|
|
103
|
+
markings?: HorseMarkings;
|
|
104
|
+
/** Mane hair length in metres. Default 0.11 times the withers height (a pulled mane). */
|
|
105
|
+
maneLength?: number;
|
|
106
|
+
/** Add skinnable mane and forelock chains for the optional strand driver. Default false. */
|
|
107
|
+
strandRig?: boolean;
|
|
108
|
+
/** Tail hair length in metres from the dock. Default 0.55 times the withers height (to the hocks). */
|
|
109
|
+
tailLength?: number;
|
|
110
|
+
/** Speeds in m/s at which each gait's clip is baked. Default each gait's preferred speed for this horse. */
|
|
111
|
+
speeds?: Partial<Record<Gait, number>>;
|
|
112
|
+
/** Mesh detail: 2 film close-up, 1 middle, 0 far crowd. Default 2. */
|
|
113
|
+
detail?: 0 | 1 | 2;
|
|
114
|
+
/**
|
|
115
|
+
* For a `bakeBones` crowd: texture coordinates point into a coat atlas (one column per coat, rows for body,
|
|
116
|
+
* points, mane and hoof) instead of running along the hair. Default false.
|
|
117
|
+
*/
|
|
118
|
+
atlas?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** One baked clip: its gait (or `'stand'`), speed, stride length, duration and duty factor. */
|
|
121
|
+
export interface HorseClip {
|
|
122
|
+
readonly name: Gait | 'stand';
|
|
123
|
+
readonly speed: number;
|
|
124
|
+
readonly strideLength: number;
|
|
125
|
+
readonly duration: number;
|
|
126
|
+
readonly duty: number;
|
|
127
|
+
}
|
|
128
|
+
/** A horse as a glTF document and its binary buffers, for `parseGLTFAsync(engine, doc, buffers)`. */
|
|
129
|
+
export interface HorseDocument {
|
|
130
|
+
readonly doc: Record<string, unknown>;
|
|
131
|
+
readonly buffers: Uint8Array[];
|
|
132
|
+
readonly body: HorseBody;
|
|
133
|
+
readonly skeleton: HorseSkeleton;
|
|
134
|
+
/** The baked clips, in the document's animation order. */
|
|
135
|
+
readonly clips: readonly HorseClip[];
|
|
136
|
+
/** Vertex count of all primitives. */
|
|
137
|
+
readonly vertices: number;
|
|
138
|
+
}
|
|
139
|
+
/** Atlas texture coordinates for a crowd: column per coat, rows body, points, mane, hoof (centres of 4 x 6 cells). */
|
|
140
|
+
export declare function coatAtlasUV(coat: HorseCoat, row: 'body' | 'points' | 'mane' | 'hoof'): [number, number];
|
|
141
|
+
/** The coat atlas as RGBA8 pixels (sRGB), 6 coats wide and 4 rows high, for a crowd's `map`. */
|
|
142
|
+
export declare function coatAtlas(): {
|
|
143
|
+
data: Uint8Array;
|
|
144
|
+
width: number;
|
|
145
|
+
height: number;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The horse as a glTF 2.0 document with a skinned mesh in five materials (`Coat`, `Hoof`, `Mane`, `Tail`, `Eye`), a
|
|
149
|
+
* 37-joint rig, a `saddle` node on the trunk, and the clips `stand`, `walk`, `trot`, `canter` and `gallop` (left
|
|
150
|
+
* lead), each one stride long at its speed. Load it with `parseGLTFAsync(engine, doc, buffers)` from
|
|
151
|
+
* `@margoengine/gltf/pbr`, or take {@link horseGLB}.
|
|
152
|
+
* @example
|
|
153
|
+
* const {doc, buffers, clips} = horseDocument({type: 'draft', coat: 'grey'});
|
|
154
|
+
* @throws TypeError or RangeError for bad options.
|
|
155
|
+
*/
|
|
156
|
+
export declare function horseDocument(options?: HorseModelOptions): HorseDocument;
|
|
157
|
+
/** The horse of {@link horseDocument} as one GLB file (one binary buffer), for `loadGLTF` or a download. */
|
|
158
|
+
export declare function horseGLB(options?: HorseModelOptions): Uint8Array;
|
|
159
|
+
export {};
|
package/dist/model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as BREAKOVER, n as COAT_COLORS, r as HORSE_COATS, i as coatAtlas, a as coatAtlasUV, o as fitHorseHooves, s as horseDocument, c as horseGLB, l as horseJointTranslation, u as horsePose, d as horseSkeleton, f as horseTailFlick, p as poseHooves, m as poseJoints, h as poseSaddle } from "./model-D2H9-6oj.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
|
|
4
|
+
//#region ../shared/scene-scope.js
|
|
5
|
+
var e = 0, t = (t, n) => {
|
|
6
|
+
let r = n + e++;
|
|
7
|
+
for (; t.plugins?.has(r);) r += ":";
|
|
8
|
+
return r;
|
|
9
|
+
};
|
|
10
|
+
function n(e) {
|
|
11
|
+
let n;
|
|
12
|
+
if (typeof e?.sceneOf == "function") {
|
|
13
|
+
for (let t of e.plugins?.values() ?? []) if (n = e.sceneOf(t)) break;
|
|
14
|
+
if (!n) {
|
|
15
|
+
let r = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
16
|
+
name: t(e, "scene-scope:"),
|
|
17
|
+
setup() {
|
|
18
|
+
n = e.sceneOf(r);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
e.use(r), e.removePlugin(r.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return r(e, n);
|
|
25
|
+
}
|
|
26
|
+
function r(e, n) {
|
|
27
|
+
return {
|
|
28
|
+
scene: n,
|
|
29
|
+
run(r) {
|
|
30
|
+
if (!n) return r();
|
|
31
|
+
let i, a = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
32
|
+
name: t(e, "scene-scope:"),
|
|
33
|
+
setup() {
|
|
34
|
+
i = r();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return n.use(a), n.removePlugin(a.name), i;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { n as t };
|
package/dist/seat.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { Horse } from './index.js';
|
|
3
|
+
/** Options of {@link riderSeat}. */
|
|
4
|
+
export interface RiderSeatOptions {
|
|
5
|
+
/** Rider standing height in metres, 1.4 to 2.1. Default 1.75. */
|
|
6
|
+
height?: number;
|
|
7
|
+
/** Thigh angle forward of vertical, radians. Default 0.7 (40 degrees, a general purpose seat). */
|
|
8
|
+
thigh?: number;
|
|
9
|
+
/** Knee angle between thigh and shank, radians. Default 1.92 (110 degrees). */
|
|
10
|
+
knee?: number;
|
|
11
|
+
/** Half the width of the horse and saddle under the knee, metres. Default 0.21 times the withers height. */
|
|
12
|
+
halfWidth?: number;
|
|
13
|
+
/** Withers height of the horse, metres (for the default halfWidth). Default 1.63. */
|
|
14
|
+
withers?: number;
|
|
15
|
+
}
|
|
16
|
+
/** The seat in the saddle's frame (metres; +Y up, +Z forward, +X the horse's left), left then right. */
|
|
17
|
+
export interface RiderSeat {
|
|
18
|
+
/** The rider's hip joint centre (mid point of the two hip joints). */
|
|
19
|
+
readonly hip: readonly [number, number, number];
|
|
20
|
+
readonly hips: readonly [readonly [number, number, number], readonly [number, number, number]];
|
|
21
|
+
readonly knees: readonly [readonly [number, number, number], readonly [number, number, number]];
|
|
22
|
+
readonly ankles: readonly [readonly [number, number, number], readonly [number, number, number]];
|
|
23
|
+
/** Where the stirrup treads hang, under the balls of the feet. */
|
|
24
|
+
readonly stirrups: readonly [readonly [number, number, number], readonly [number, number, number]];
|
|
25
|
+
/** Where the hands hold the reins, over the withers. */
|
|
26
|
+
readonly hands: readonly [readonly [number, number, number], readonly [number, number, number]];
|
|
27
|
+
/** Segment lengths used, metres. */
|
|
28
|
+
readonly thighLength: number;
|
|
29
|
+
readonly shankLength: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Where a rider's joints go in the saddle for a rider height and seat. Pure: the same numbers every call.
|
|
33
|
+
* @example
|
|
34
|
+
* const seat = riderSeat({height: 1.78, knee: (115 * Math.PI) / 180});
|
|
35
|
+
* @throws RangeError for a height, angle or width out of range.
|
|
36
|
+
*/
|
|
37
|
+
export declare function riderSeat(options?: RiderSeatOptions): RiderSeat;
|
|
38
|
+
/** Options of {@link SeatFollower}. */
|
|
39
|
+
export interface SeatFollowerOptions {
|
|
40
|
+
/** Natural frequency of the rider's give, Hz. Default 9. */
|
|
41
|
+
frequency?: number;
|
|
42
|
+
/** Damping ratio. Default 0.8. */
|
|
43
|
+
damping?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The rider's hip riding the saddle point: a damped spring (critically near) per axis, stepped on fixed steps. Feed it
|
|
47
|
+
* the saddle point every step; read `position`.
|
|
48
|
+
*/
|
|
49
|
+
export declare class SeatFollower {
|
|
50
|
+
readonly position: [number, number, number];
|
|
51
|
+
readonly velocity: [number, number, number];
|
|
52
|
+
private started;
|
|
53
|
+
private readonly w;
|
|
54
|
+
private readonly z;
|
|
55
|
+
constructor(options?: SeatFollowerOptions);
|
|
56
|
+
/** Forgets the state: the next step starts on the saddle. */
|
|
57
|
+
reset(): void;
|
|
58
|
+
step(dt: number, target: readonly number[]): readonly [number, number, number];
|
|
59
|
+
}
|
|
60
|
+
/** Anything with a scene root to place: a `@margoengine/humans` Person's `model`, any loaded model. */
|
|
61
|
+
export interface RiderModel {
|
|
62
|
+
readonly root: {
|
|
63
|
+
setPosition(p: readonly number[]): unknown;
|
|
64
|
+
setQuaternion(q: readonly number[]): unknown;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Options of {@link mountRider}. */
|
|
68
|
+
export interface MountOptions extends RiderSeatOptions, SeatFollowerOptions {
|
|
69
|
+
/** Height of the rider model's hip joint above its origin in the riding pose, metres. Default 0.53 x height (Winter 2009). */
|
|
70
|
+
hipHeight?: number;
|
|
71
|
+
/** How much of the horse's trunk pitch the rider's trunk takes, 0 to 1. Default 0.4 (riders stay near upright). */
|
|
72
|
+
pitchShare?: number;
|
|
73
|
+
}
|
|
74
|
+
/** What {@link mountRider} returns. */
|
|
75
|
+
export interface Mount {
|
|
76
|
+
readonly seat: RiderSeat;
|
|
77
|
+
/** The rider's hip in world space now. */
|
|
78
|
+
readonly hip: readonly [number, number, number];
|
|
79
|
+
/** World positions of the seat's points now (stirrups, hands, knees), from the horse's frame. */
|
|
80
|
+
world(point: readonly number[]): [number, number, number];
|
|
81
|
+
dispose(): void;
|
|
82
|
+
[Symbol.dispose](): void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Seats a rider on a horse from {@link addHorse}: every fixed step the rider's hip rides the saddle through a
|
|
86
|
+
* {@link SeatFollower}, and the rider model's root is placed so its hip joint sits there, facing the horse's way with
|
|
87
|
+
* part of the trunk's pitch. The rider plays its own riding clip (a `@margoengine/humans` person: `person.play('ride')`);
|
|
88
|
+
* {@link Mount.seat} gives the knee, stirrup and rein targets for its leg and arm IK.
|
|
89
|
+
* @example
|
|
90
|
+
* const mount = mountRider(horse, person.model, {height: 1.78});
|
|
91
|
+
* @throws TypeError for a horse or rider of the wrong shape; RangeError for bad options.
|
|
92
|
+
*/
|
|
93
|
+
export declare function mountRider(horse: Horse, rider: RiderModel, options?: MountOptions): Mount;
|
package/dist/seat.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
//#region src/seat.ts
|
|
2
|
+
function e(e = {}) {
|
|
3
|
+
let t = e.height ?? 1.75, n = e.thigh ?? .7, r = e.knee ?? 1.92, i = e.withers ?? 1.63, a = e.halfWidth ?? .21 * i;
|
|
4
|
+
if (!(t >= 1.4 && t <= 2.1)) throw RangeError("riderSeat height must be 1.4 to 2.1 metres");
|
|
5
|
+
if (!(n >= .2 && n <= 1.2)) throw RangeError("riderSeat thigh must be 0.2 to 1.2 radians forward of vertical");
|
|
6
|
+
if (!(r >= 1.4 && r <= 2.6)) throw RangeError("riderSeat knee must be 1.4 to 2.6 radians");
|
|
7
|
+
if (!(a >= .1 && a <= .5)) throw RangeError("riderSeat halfWidth must be 0.1 to 0.5 metres");
|
|
8
|
+
if (!(i >= 1.2 && i <= 2.1)) throw RangeError("riderSeat withers must be 1.2 to 2.1 metres");
|
|
9
|
+
let o = .245 * t, s = .246 * t, c = .0955 * t * .5, l = .055 * t, u = (e) => {
|
|
10
|
+
let i = [
|
|
11
|
+
e * c,
|
|
12
|
+
l,
|
|
13
|
+
0
|
|
14
|
+
], u = e * (a + .06), d = Math.abs(u - i[0]), f = Math.sqrt(Math.max(0, o * o - d * d)), p = [
|
|
15
|
+
u,
|
|
16
|
+
l - f * Math.cos(n),
|
|
17
|
+
f * Math.sin(n)
|
|
18
|
+
], m = n - (Math.PI - r), h = [
|
|
19
|
+
u - e * .01,
|
|
20
|
+
p[1] - s * Math.cos(m),
|
|
21
|
+
p[2] + s * Math.sin(m)
|
|
22
|
+
];
|
|
23
|
+
return {
|
|
24
|
+
hip: i,
|
|
25
|
+
knee: p,
|
|
26
|
+
ankle: h,
|
|
27
|
+
stirrup: [
|
|
28
|
+
h[0],
|
|
29
|
+
h[1] - .045 * t,
|
|
30
|
+
h[2] + .075 * t
|
|
31
|
+
],
|
|
32
|
+
hand: [
|
|
33
|
+
e * .055 * t,
|
|
34
|
+
.17 * t,
|
|
35
|
+
.21 * t
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
}, d = u(1), f = u(-1);
|
|
39
|
+
return {
|
|
40
|
+
hip: [
|
|
41
|
+
0,
|
|
42
|
+
l,
|
|
43
|
+
0
|
|
44
|
+
],
|
|
45
|
+
hips: [d.hip, f.hip],
|
|
46
|
+
knees: [d.knee, f.knee],
|
|
47
|
+
ankles: [d.ankle, f.ankle],
|
|
48
|
+
stirrups: [d.stirrup, f.stirrup],
|
|
49
|
+
hands: [d.hand, f.hand],
|
|
50
|
+
thighLength: o,
|
|
51
|
+
shankLength: s
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var t = class {
|
|
55
|
+
constructor(e = {}) {
|
|
56
|
+
this.position = [
|
|
57
|
+
0,
|
|
58
|
+
0,
|
|
59
|
+
0
|
|
60
|
+
], this.velocity = [
|
|
61
|
+
0,
|
|
62
|
+
0,
|
|
63
|
+
0
|
|
64
|
+
], this.started = !1;
|
|
65
|
+
let t = e.frequency ?? 9, n = e.damping ?? .8;
|
|
66
|
+
if (!(t >= 1 && t <= 60)) throw RangeError("SeatFollower frequency must be 1 to 60 Hz");
|
|
67
|
+
if (!(n >= .2 && n <= 3)) throw RangeError("SeatFollower damping must be 0.2 to 3");
|
|
68
|
+
this.w = 2 * Math.PI * t, this.z = n;
|
|
69
|
+
}
|
|
70
|
+
reset() {
|
|
71
|
+
this.started = !1;
|
|
72
|
+
}
|
|
73
|
+
step(e, t) {
|
|
74
|
+
if (!this.started) {
|
|
75
|
+
for (let e = 0; e < 3; e++) this.position[e] = t[e], this.velocity[e] = 0;
|
|
76
|
+
return this.started = !0, this.position;
|
|
77
|
+
}
|
|
78
|
+
for (let n = 0; n < 3; n++) {
|
|
79
|
+
let r = this.w * this.w * (t[n] - this.position[n]) - 2 * this.z * this.w * this.velocity[n];
|
|
80
|
+
this.velocity[n] += r * e, this.position[n] += this.velocity[n] * e;
|
|
81
|
+
}
|
|
82
|
+
return this.position;
|
|
83
|
+
}
|
|
84
|
+
}, n = (e, t) => {
|
|
85
|
+
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]);
|
|
86
|
+
return [
|
|
87
|
+
t[0] + a * o + (r * c - i * s),
|
|
88
|
+
t[1] + a * s + (i * o - n * c),
|
|
89
|
+
t[2] + a * c + (n * s - r * o)
|
|
90
|
+
];
|
|
91
|
+
};
|
|
92
|
+
function r(r, i, a = {}) {
|
|
93
|
+
if (!r || typeof r.onStep != "function" || typeof r.frame != "function") throw TypeError("mountRider needs a horse from addHorse");
|
|
94
|
+
if (!i?.root || typeof i.root.setPosition != "function" || typeof i.root.setQuaternion != "function") throw TypeError("mountRider needs a rider model with a root (a loaded model, or a person.model)");
|
|
95
|
+
let o = a.height ?? 1.75, s = e({
|
|
96
|
+
withers: r.body.withers,
|
|
97
|
+
...a
|
|
98
|
+
}), c = new t(a), l = a.hipHeight ?? .53 * o, u = a.pitchShare ?? .4;
|
|
99
|
+
if (!(l > 0 && l < 1.5)) throw RangeError("mountRider hipHeight must be 0 to 1.5 metres");
|
|
100
|
+
if (!(u >= 0 && u <= 1)) throw RangeError("mountRider pitchShare must be 0 to 1");
|
|
101
|
+
let d = () => {
|
|
102
|
+
let e = r.frame(), t = [
|
|
103
|
+
0,
|
|
104
|
+
Math.sin(e.heading / 2),
|
|
105
|
+
0,
|
|
106
|
+
Math.cos(e.heading / 2)
|
|
107
|
+
], a = [
|
|
108
|
+
0,
|
|
109
|
+
-t[1],
|
|
110
|
+
0,
|
|
111
|
+
t[3]
|
|
112
|
+
], o = [
|
|
113
|
+
a[3] * e.saddleRotation[0] + a[0] * e.saddleRotation[3] + a[1] * e.saddleRotation[2] - a[2] * e.saddleRotation[1],
|
|
114
|
+
0,
|
|
115
|
+
0,
|
|
116
|
+
a[3] * e.saddleRotation[3] - a[0] * e.saddleRotation[0] - a[1] * e.saddleRotation[1] - a[2] * e.saddleRotation[2]
|
|
117
|
+
], s = 2 * Math.atan2(o[0], o[3]) * u, d = [
|
|
118
|
+
t[3] * Math.sin(s / 2) + 0,
|
|
119
|
+
t[1] * Math.cos(s / 2),
|
|
120
|
+
-t[1] * Math.sin(s / 2),
|
|
121
|
+
t[3] * Math.cos(s / 2)
|
|
122
|
+
], f = c.position, p = n(d, [
|
|
123
|
+
0,
|
|
124
|
+
-l,
|
|
125
|
+
0
|
|
126
|
+
]);
|
|
127
|
+
i.root.setPosition([
|
|
128
|
+
f[0] + p[0],
|
|
129
|
+
f[1] + p[1],
|
|
130
|
+
f[2] + p[2]
|
|
131
|
+
]), i.root.setQuaternion(d);
|
|
132
|
+
}, f = () => {
|
|
133
|
+
let e = r.frame(), t = n(e.saddleRotation, s.hip);
|
|
134
|
+
return [
|
|
135
|
+
e.saddle[0] + t[0],
|
|
136
|
+
e.saddle[1] + t[1],
|
|
137
|
+
e.saddle[2] + t[2]
|
|
138
|
+
];
|
|
139
|
+
}, p = r.onStep((e) => {
|
|
140
|
+
c.step(e, f()), d();
|
|
141
|
+
}, () => c.reset());
|
|
142
|
+
c.step(0, f()), d();
|
|
143
|
+
let m = !1, h = () => {
|
|
144
|
+
m || (m = !0, p());
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
seat: s,
|
|
148
|
+
get hip() {
|
|
149
|
+
return [...c.position];
|
|
150
|
+
},
|
|
151
|
+
world(e) {
|
|
152
|
+
let t = r.frame(), i = n(t.saddleRotation, e);
|
|
153
|
+
return [
|
|
154
|
+
t.saddle[0] + i[0],
|
|
155
|
+
t.saddle[1] + i[1],
|
|
156
|
+
t.saddle[2] + i[2]
|
|
157
|
+
];
|
|
158
|
+
},
|
|
159
|
+
dispose: h,
|
|
160
|
+
[Symbol.dispose]: h
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
export { t as SeatFollower, r as mountRider, e as riderSeat };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type SettingRow } from './shared/settings.js';
|
|
2
|
+
import type { HorseOptions } from './index.js';
|
|
3
|
+
import type { Gait } from './gaits.js';
|
|
4
|
+
import type { MountOptions } from './seat.js';
|
|
5
|
+
/** One value of a setting. */
|
|
6
|
+
export type HorseSettingValue = number | string;
|
|
7
|
+
/** Values by setting name; a name left out keeps the default. */
|
|
8
|
+
export type HorseSettingValues = Readonly<Record<string, HorseSettingValue>>;
|
|
9
|
+
/** One control: the shared row shape. */
|
|
10
|
+
export interface HorseSetting extends SettingRow {
|
|
11
|
+
readonly default: HorseSettingValue;
|
|
12
|
+
}
|
|
13
|
+
/** Every horse and seat control, in panel order. */
|
|
14
|
+
export declare const HORSE_SETTINGS: readonly HorseSetting[];
|
|
15
|
+
/** Every horse setting at its default, as a fresh object to edit. */
|
|
16
|
+
export declare function horseSettingDefaults(): Record<string, HorseSettingValue>;
|
|
17
|
+
/**
|
|
18
|
+
* The `addHorse` options, the live motion values and the `mountRider` options the given values make. Only the names
|
|
19
|
+
* given are set.
|
|
20
|
+
* @throws TypeError for an unknown name; RangeError for a value out of range.
|
|
21
|
+
*/
|
|
22
|
+
export declare function horseOptionsFromSettings(values: HorseSettingValues): {
|
|
23
|
+
options: HorseOptions;
|
|
24
|
+
motion: {
|
|
25
|
+
speed?: number;
|
|
26
|
+
gait?: Gait | 'auto';
|
|
27
|
+
};
|
|
28
|
+
mount: MountOptions;
|
|
29
|
+
};
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { r as e } from "./model-D2H9-6oj.js";
|
|
2
|
+
import { HORSE_TYPES as t } from "./anatomy.js";
|
|
3
|
+
//#region ../shared/settings.js
|
|
4
|
+
var n = (e, t, n) => typeof e == "number" && e >= t && e <= n, r = (e, t, r) => Array.isArray(e) && e.length === 3 && e.every((e) => n(e, t, r)), i = (e) => e.stopKey ?? "elevation", a = (e, t, n, r, i, a, o, s, c = !0) => ({
|
|
5
|
+
name: e,
|
|
6
|
+
group: t,
|
|
7
|
+
kind: "number",
|
|
8
|
+
default: n,
|
|
9
|
+
min: r,
|
|
10
|
+
max: i,
|
|
11
|
+
step: a,
|
|
12
|
+
unit: o,
|
|
13
|
+
about: s,
|
|
14
|
+
live: c
|
|
15
|
+
}), o = (e, t, n, r, i = !0) => ({
|
|
16
|
+
name: e,
|
|
17
|
+
group: t,
|
|
18
|
+
kind: "choice",
|
|
19
|
+
default: n[0],
|
|
20
|
+
choices: n,
|
|
21
|
+
unit: "",
|
|
22
|
+
about: r,
|
|
23
|
+
live: i
|
|
24
|
+
});
|
|
25
|
+
function s(e) {
|
|
26
|
+
return Array.isArray(e) ? typeof e[0] == "object" ? e.map((e) => ({
|
|
27
|
+
...e,
|
|
28
|
+
color: [...e.color]
|
|
29
|
+
})) : [...e] : e;
|
|
30
|
+
}
|
|
31
|
+
function c(e) {
|
|
32
|
+
return Object.fromEntries(e.map((e) => [e.name, s(e.default)]));
|
|
33
|
+
}
|
|
34
|
+
var l = (e) => new Map(e.map((e) => [e.name, e]));
|
|
35
|
+
function u(e, t, a) {
|
|
36
|
+
let o = e.min ?? -Infinity, s = e.max ?? Infinity, c;
|
|
37
|
+
if (t === null) c = !!e.nullable;
|
|
38
|
+
else if (e.kind === "number") c = n(t, o, s);
|
|
39
|
+
else if (e.kind === "color") c = r(t, o, s);
|
|
40
|
+
else if (e.kind === "choice") c = e.choices.includes(t);
|
|
41
|
+
else {
|
|
42
|
+
let a = i(e);
|
|
43
|
+
c = Array.isArray(t) && t.length >= 2 && t.length <= 8 && t.every((e, i) => typeof e == "object" && !!e && n(e[a], o, s) && r(e.color, 0, 1) && (i === 0 || e[a] > t[i - 1][a]));
|
|
44
|
+
}
|
|
45
|
+
if (c) return;
|
|
46
|
+
let l = e.nullable ? e.weather ? ` or null (follow the weather's ${e.weather})` : " or null" : "", u = e.kind === "number" ? `a number from ${o} to ${s}${l}` : e.kind === "color" ? `three numbers from ${o} to ${s} (linear RGB)${l}` : e.kind === "choice" ? e.choices.map((e) => `'${e}'`).join(" or ") + l : `2 to 8 stops {${i(e)}, color}, ${i(e)} ${o} to ${s} rising, colours 0 to 1${l}`;
|
|
47
|
+
throw RangeError(`Invalid ${a} setting ${e.name}; use ${u}`);
|
|
48
|
+
}
|
|
49
|
+
function d(e, t, n, r = `the rows in @margoengine/${n}/settings`) {
|
|
50
|
+
let i = e instanceof Map ? e : l(e);
|
|
51
|
+
for (let e of Object.keys(t)) {
|
|
52
|
+
let a = i.get(e);
|
|
53
|
+
if (!a) throw TypeError(`Unknown ${n} setting ${e}; use a name from ${r}`);
|
|
54
|
+
u(a, t[e], n);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/settings.ts
|
|
59
|
+
var f = [
|
|
60
|
+
o("type", "horse", [...t], "Breed group: riding (Thoroughbred build), cavalry remount or heavy draft.", !1),
|
|
61
|
+
a("withers", "horse", 0, 0, 2.1, .01, "m", "Height at the withers; 0 keeps the breed group mean.", !1),
|
|
62
|
+
a("condition", "horse", 1, .8, 1.25, .01, "", "Girth and widths: lean below 1, heavy above.", !1),
|
|
63
|
+
o("coat", "coat", [...e], "Coat colour; bay, brown and dun have black points, mane and tail.", !1),
|
|
64
|
+
o("blaze", "coat", ["no", "yes"], "A white blaze down the face.", !1),
|
|
65
|
+
a("socks", "coat", 0, 0, .6, .01, "m", "Height of white socks on the hind legs.", !1),
|
|
66
|
+
a("maneLength", "coat", 0, 0, .8, .01, "m", "Mane hair length; 0 keeps the default (a pulled mane).", !1),
|
|
67
|
+
a("tailLength", "coat", 0, 0, 1.6, .01, "m", "Tail hair length from the dock; 0 keeps the default (to the hocks).", !1),
|
|
68
|
+
o("detail", "coat", [
|
|
69
|
+
"2",
|
|
70
|
+
"1",
|
|
71
|
+
"0"
|
|
72
|
+
], "Mesh detail: 2 close-up, 1 middle, 0 far crowd.", !1),
|
|
73
|
+
a("speed", "motion", 0, 0, 25, .1, "m/s", "Ground speed; the gait follows it by Froude number."),
|
|
74
|
+
o("gait", "motion", [
|
|
75
|
+
"auto",
|
|
76
|
+
"walk",
|
|
77
|
+
"trot",
|
|
78
|
+
"canter",
|
|
79
|
+
"gallop"
|
|
80
|
+
], "Force a gait, or auto to follow the speed."),
|
|
81
|
+
a("acceleration", "motion", 3, .1, 12, .1, "m/s2", "Most the speed changes per second."),
|
|
82
|
+
a("turnRate", "motion", 1.2, .1, 6, .05, "rad/s", "Most the heading turns per second."),
|
|
83
|
+
a("fade", "motion", .3, 0, 2, .01, "s", "Cross-fade length of a gait change."),
|
|
84
|
+
a("riderHeight", "seat", 1.75, 1.4, 2.1, .01, "m", "Rider standing height: sets thigh and shank length.", !1),
|
|
85
|
+
a("thigh", "seat", .7, .2, 1.2, .01, "rad", "Rider thigh angle forward of vertical.", !1),
|
|
86
|
+
a("knee", "seat", 1.92, 1.4, 2.6, .01, "rad", "Rider knee angle: longer stirrups open it.", !1),
|
|
87
|
+
a("followFrequency", "seat", 9, 1, 60, .5, "Hz", "How stiffly the rider hip rides the saddle.", !1),
|
|
88
|
+
a("followDamping", "seat", .8, .2, 3, .05, "", "Damping of the rider hip on the saddle.", !1),
|
|
89
|
+
a("pitchShare", "seat", .4, 0, 1, .01, "", "How much of the trunk pitch the rider takes.", !1)
|
|
90
|
+
], p = l(f);
|
|
91
|
+
function m() {
|
|
92
|
+
return c(f);
|
|
93
|
+
}
|
|
94
|
+
function h(e) {
|
|
95
|
+
d(p, e, "horses", "the rows in @margoengine/horses/settings");
|
|
96
|
+
let t = e, n = {}, r = {}, i = {};
|
|
97
|
+
if ("type" in t && (n.type = t.type), "withers" in t && t.withers > 0) {
|
|
98
|
+
if (t.withers < 1.2) throw RangeError("horses withers must be 0 (the group mean) or 1.2 to 2.1 m");
|
|
99
|
+
n.withers = t.withers;
|
|
100
|
+
}
|
|
101
|
+
if ("condition" in t && (n.condition = t.condition), "coat" in t && (n.coat = t.coat), "blaze" in t || "socks" in t) {
|
|
102
|
+
let e = t.socks ?? 0;
|
|
103
|
+
n.markings = {
|
|
104
|
+
blaze: t.blaze === "yes",
|
|
105
|
+
socks: [
|
|
106
|
+
e,
|
|
107
|
+
0,
|
|
108
|
+
e,
|
|
109
|
+
0
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
"maneLength" in t && t.maneLength > 0 && (n.maneLength = Math.max(.02, t.maneLength)), "tailLength" in t && t.tailLength > 0 && (n.tailLength = Math.max(.1, t.tailLength)), "detail" in t && (n.detail = Number(t.detail));
|
|
114
|
+
for (let e of [
|
|
115
|
+
"acceleration",
|
|
116
|
+
"turnRate",
|
|
117
|
+
"fade"
|
|
118
|
+
]) e in t && (n[e] = t[e]);
|
|
119
|
+
return "speed" in t && (i.speed = t.speed), "gait" in t && (i.gait = t.gait), "riderHeight" in t && (r.height = t.riderHeight), "thigh" in t && (r.thigh = t.thigh), "knee" in t && (r.knee = t.knee), "followFrequency" in t && (r.frequency = t.followFrequency), "followDamping" in t && (r.damping = t.followDamping), "pitchShare" in t && (r.pitchShare = t.pitchShare), {
|
|
120
|
+
options: n,
|
|
121
|
+
motion: i,
|
|
122
|
+
mount: r
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { f as HORSE_SETTINGS, h as horseOptionsFromSettings, m as horseSettingDefaults };
|