@margoengine/horses 0.1.0 → 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 -201
- package/NOTICE +4 -4
- package/README.md +348 -348
- package/dist/scene-scope-BIsfeY-W.js +3 -3
- package/dist/shared/settings.d.ts +89 -89
- package/package.json +86 -86
package/README.md
CHANGED
|
@@ -1,348 +1,348 @@
|
|
|
1
|
-
# @margoengine/horses
|
|
2
|
-
|
|
3
|
-
Horses built in code from published equine measurements. `addHorse(engine)` builds a riding horse, a cavalry remount or
|
|
4
|
-
a heavy draft horse to its breed group's proportions, with a coat, white markings, a mane and tail of hair cards shaded
|
|
5
|
-
as strand hair, a 37-joint rig and walk, trot, canter and gallop taken from equine biomechanics. Its gait follows its
|
|
6
|
-
speed, a stance hoof stays where it struck, and film time seeks exactly. A rider seat gives a person the saddle, stirrups
|
|
7
|
-
and reins and a hip that rides the horse's back; `addHorseCrowd` draws hundreds in one call.
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import {Engine} from 'margoengine';
|
|
11
|
-
import {addHorse} from 'margoengine/horses';
|
|
12
|
-
const engine = await Engine.create(document.querySelector('canvas')!);
|
|
13
|
-
const horse = await addHorse(engine, {type: 'cavalry', coat: 'bay', markings: {blaze: true}});
|
|
14
|
-
horse.speed = 4; // eases into a trot at 3 m/s^2
|
|
15
|
-
horse.advanceTime(1 / 30); // or horse.seek(12.5) for a film frame
|
|
16
|
-
console.log(horse.currentGait, horse.body.mass.toFixed(0)); // 'walk' as it sets off, 'trot' near 4 m/s; about 459 kg
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
An existing skinned horse can use the same controller through `skin`. Provide its loaded model in the same engine,
|
|
20
|
-
its fitted skeleton in metres facing +Z, and a function that applies the solved pose to its joint map. The controller
|
|
21
|
-
sets root position and yaw, attaches its skinning pass, and keeps the authored materials. The tightest of the four
|
|
22
|
-
fitted limbs determines whether the stride must shorten to keep the same speed at a quicker cadence. Fit the skeleton
|
|
23
|
-
in metres in a naturally bent stance so the package can measure extension in both directions. The caller owns the model.
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import type { Engine } from 'margoengine';
|
|
27
|
-
import { addHorse, type HorseSkin } from 'margoengine/horses';
|
|
28
|
-
|
|
29
|
-
export async function startImportedHorse(engine: Engine, skin: HorseSkin) {
|
|
30
|
-
const horse = await addHorse(engine, { skin });
|
|
31
|
-
horse.speed = 3;
|
|
32
|
-
horse.advanceTime(1);
|
|
33
|
-
return horse;
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
Pass `ground(x, z)` for an uneven path. The controller holds each stance hoof at its world-space landing point
|
|
38
|
-
through turns, then releases the horizontal correction over 0.18 seconds. It conforms the hoof to the local grade and
|
|
39
|
-
retains toe breakover and swing clearance. The back and saddle lean with the wider ground slope. Supply a stable,
|
|
40
|
-
continuous height field in metres for deterministic seeks. Jumps, large risers, and overhangs require separate route
|
|
41
|
-
planning. Limb reach and splay constraints still apply.
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
import type { Engine } from 'margoengine';
|
|
45
|
-
import { addHorse } from 'margoengine/horses';
|
|
46
|
-
|
|
47
|
-
export async function walkOnAGrade(engine: Engine) {
|
|
48
|
-
const horse = await addHorse(engine, { ground: (x, z) => 0.08 * z - 0.06 * x + 0.04 * Math.sin(2 * z) });
|
|
49
|
-
horse.gait = 'walk';
|
|
50
|
-
horse.speed = 1.4;
|
|
51
|
-
horse.seek(2.4);
|
|
52
|
-
return horse;
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
The terrain pass follows the world-space plant and continuous correction approach of [Kovar, Schreiner and Gleicher,
|
|
57
|
-
Footskate Cleanup for Motion Capture Editing (2002)](https://research.cs.wisc.edu/graphics/Papers/Gleicher/Mocap/cleanup.pdf).
|
|
58
|
-
Its separate support frames and trunk sampling draw on [Coros, Karpathy, Jones, Reveret and van de Panne,
|
|
59
|
-
Locomotion Skills for Simulated Quadrupeds (2011)](https://www.cs.ubc.ca/~van/papers/2011-TOG-quadruped/index.html)
|
|
60
|
-
and [Miller, Holden, Al-Ashqar, Dubach, Mitchell and Komura, Carpet Unrolling for Character Control on Uneven Terrain
|
|
61
|
-
(2015)](https://www.pure.ed.ac.uk/ws/portalfiles/portal/21937045/MIG_2015_paper_22.pdf).
|
|
62
|
-
|
|
63
|
-
## Anatomy (`./anatomy`)
|
|
64
|
-
|
|
65
|
-
| Group | Withers | Build | Weight |
|
|
66
|
-
| --- | --- | --- | --- |
|
|
67
|
-
| `riding` | 1.63 m (16 hh) | Thoroughbred: long legs, narrow chest | about 488 kg |
|
|
68
|
-
| `cavalry` | 1.57 m (15.2 hh) | remount: 15 to 16 hands, 950 to 1,200 lb | about 459 kg |
|
|
69
|
-
| `draft` | 1.75 m (17.1 hh) | Shire, Clydesdale, Percheron: deep chest, heavy bone | about 859 kg |
|
|
70
|
-
|
|
71
|
-
Every length is a ratio of the withers height: body length, croup, heart girth, chest depth and width, hip width, head
|
|
72
|
-
and neck, the heights of the elbow, knee, fetlocks, hip joint, stifle and hock, and the cannon circumference. Weight is
|
|
73
|
-
girth squared times length over 11,880 (Carroll and Huntington 1988). `withers` sets another height, `condition` (0.8 to
|
|
74
|
-
1.25) a lean or heavy horse.
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
import {handsToMetres, horseBody} from 'margoengine/horses/anatomy';
|
|
78
|
-
const shire = horseBody({type: 'draft', withers: handsToMetres(17.2)});
|
|
79
|
-
console.log(shire.withers.toFixed(3), shire.mass.toFixed(0)); // 1.778, about 900 kg
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Gaits (`./gaits`)
|
|
83
|
-
|
|
84
|
-
| Gait | Froude u^2/gh | Footfall (left lead) | Duty factor | Trunk |
|
|
85
|
-
| --- | --- | --- | --- | --- |
|
|
86
|
-
| walk | below 0.4 | LH, LF, RH, RF, a quarter stride apart | 0.75 to 0.6 | two rises a stride, 2.5 % of withers |
|
|
87
|
-
| trot | 0.4 to 2.4 | diagonal pairs, half a stride apart | 0.48 to 0.36 | two rises, 5 % (about 8 cm) |
|
|
88
|
-
| canter | 2.4 to 6.5 | RH; LH and RF; LF; suspension | 0.46 to 0.36 | one rise and a rock |
|
|
89
|
-
| gallop | above 6.5 | RH, LH, RF, LF; suspension | 0.32 to 0.22 | one rise and a rock |
|
|
90
|
-
|
|
91
|
-
Stride length is 2.3 h (u^2/gh)^0.3 with h the hip joint height (Alexander and Jayes 1983): a riding horse covers
|
|
92
|
-
1.6 m a stride at 1.6 m/s, 2.8 m at 4 m/s, 3.9 m at 7 m/s and 6.4 m at 16 m/s. Gait changes by Froude number, so a pony
|
|
93
|
-
trots sooner than a Shire. Footfall timing is Hildebrand (1965, 1977), trot and canter stance Clayton (1993, 1994), trunk
|
|
94
|
-
motion Buchner et al. (1996).
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
import {horseBody} from 'margoengine/horses/anatomy';
|
|
98
|
-
import {gaitFor, stride, hoovesDown} from 'margoengine/horses/gaits';
|
|
99
|
-
const body = horseBody();
|
|
100
|
-
const s = stride(body, 7); // a canter
|
|
101
|
-
console.log(gaitFor(body, 7), s.length.toFixed(2), s.duty.toFixed(2), hoovesDown(s, 0.95)); // canter 3.92 0.41 0
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## The model (`./model`)
|
|
105
|
-
|
|
106
|
-
`horseDocument(options)` returns the horse as a glTF 2.0 document and its buffers, for `parseGLTFAsync(engine, doc,
|
|
107
|
-
buffers)`; `horseGLB(options)` returns a `.glb` file. Five materials (`Coat` with vertex colours for points and markings,
|
|
108
|
-
`Hoof`, `Mane`, `Tail`, `Eye`), a skin of 37 joints (the fore limb swings from the scapula, the hind from the pelvis),
|
|
109
|
-
a `saddle` node on the trunk, and the clips `stand`, `walk`, `trot`, `canter` and `gallop`, each one stride long at its
|
|
110
|
-
speed (`speeds` sets them). A pair of planar inverse-kinematic solves places each elbow or stifle and then the
|
|
111
|
-
lower-leg hinge. The fore carpus stays nearly straight through loaded stance and flexes in early swing. The hind
|
|
112
|
-
hock folds on the opposite side of the limb and extends toward landing. Through late stance and lift-off the hoof
|
|
113
|
-
rolls about the toe and transitions continuously to the swing arc. The kinematics follow the swing and support
|
|
114
|
-
phases described in [The forelimb in walking horses, Hodson, Clayton and Lanovaz (2000)](https://pubmed.ncbi.nlm.nih.gov/10952376/),
|
|
115
|
-
[The hindlimb in walking horses, Hodson, Clayton and Lanovaz (2001)](https://doi.org/10.2746/042516401776767485), and
|
|
116
|
-
[Forelimb kinematics and net joint moments during the swing phase of the trot, Lanovaz, Clayton, Colborne and Schamhardt (1999)](https://doi.org/10.1111/j.2042-3306.1999.tb05225.x).
|
|
117
|
-
The gait curves are approximations of these patterns. `detail` 2, 1 or 0 gives about 11,000, 4,000 or 1,300 vertices.
|
|
118
|
-
|
|
119
|
-
The two forelegs straighten the carpus under weight, including if a skinned model's bind pose already bends it.
|
|
120
|
-
For a typical walk, the engine targets about 55 degrees of carpal fold, peaking near 76% of the full stride.
|
|
121
|
-
The fetlock drive follows at about 81%, and the elbow and coffin joint drive follow near 84%. The trot has a
|
|
122
|
-
larger carpal swing around 76 degrees and decelerates into landing. The angles and order follow [Hodson, Clayton
|
|
123
|
-
and Lanovaz, The Forelimb in Walking Horses: Kinematics and Ground Reaction Forces (2000)](https://doi.org/10.2746/042516400777032237),
|
|
124
|
-
[Clayton, Sha, Stick and Mullineaux, Three-Dimensional Carpal Kinematics of Trotting Horses
|
|
125
|
-
(2004)](https://doi.org/10.2746/0425164044848037), and the walking range summarized in [Jose L. Mendez-Angulo,
|
|
126
|
-
Effect of Water Level on Kinematics of Healthy Horses (2012), Table 1](https://conservancy.umn.edu/bitstreams/3a03b69d-656f-4f98-be2c-9706192aa746/download).
|
|
127
|
-
|
|
128
|
-
`fitHorseHooves` runs the leg solve directly for authored contact targets in model space. Pitch and roll are in
|
|
129
|
-
radians about +X and +Z, with zero as the default trunk slope. Each target applies its terrain angles to the base
|
|
130
|
-
hoof motion. The leg lengths and original bending sides are preserved. Turning the whole chain laterally is capped
|
|
131
|
-
at 0.35 radians. The live terrain controller uses this same method.
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
import { horseBody } from 'margoengine/horses/anatomy';
|
|
135
|
-
import { fitHorseHooves, horsePose, horseSkeleton, type HorseHoofTarget } from 'margoengine/horses/model';
|
|
136
|
-
|
|
137
|
-
const rig = horseSkeleton(horseBody());
|
|
138
|
-
const targets: HorseHoofTarget[] = rig.ground.map(([x, , z]) => ({
|
|
139
|
-
point: [x, 0.1 * z, z],
|
|
140
|
-
pitch: -Math.atan(0.1),
|
|
141
|
-
roll: 0,
|
|
142
|
-
}));
|
|
143
|
-
const standingOnTheGrade = fitHorseHooves(rig, horsePose(rig, null), targets, -Math.atan(0.1));
|
|
144
|
-
console.log(standingOnTheGrade.rotations.length); // 37
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Swing matches the planted hoof's local fore-aft velocity at lift-off and touchdown. During a gait change, the
|
|
148
|
-
controller matches hoof positions and short-term travel to select the incoming phase. The outgoing cadence eases out
|
|
149
|
-
as the new gait takes over. Timing comes from the support sequences in [*Symmetrical Gaits of Horses*, Milton Hildebrand
|
|
150
|
-
(1965)](https://pubmed.ncbi.nlm.nih.gov/5844074/). The contact and transition treatment draws on [*Footskate Cleanup for
|
|
151
|
-
Motion Capture Editing*, Lucas Kovar, John Schreiner and Michael Gleicher (2002)](https://graphics.cs.wisc.edu/Papers/2002/KSG02/)
|
|
152
|
-
and [*Automated Semi-Procedural Animation for Character Locomotion*, Rune Skovbo Johansen (2009)](https://runevision.com/thesis/rune_skovbo_johansen_thesis.pdf).
|
|
153
|
-
|
|
154
|
-
In a walk the fore fetlock yields as weight transfers and tucks relative to the cannon during swing.
|
|
155
|
-
The pose solver combines the cannon, pastern, and hoof at their local angles to maintain the planned sole path,
|
|
156
|
-
including the established departure from and return to the plant. It preserves segment lengths and leaves
|
|
157
|
-
the carpus and coffin flexion timed separately. References are [Hodson, Clayton and Lanovaz, *The Forelimb
|
|
158
|
-
in Walking Horses: 1. Kinematics and Ground Reaction Forces* (2000)](https://doi.org/10.2746/042516400777032237),
|
|
159
|
-
[Clayton, Hodson and Lanovaz, *The Forelimb in Walking Horses: 2. Net Joint Moments and Joint Powers*
|
|
160
|
-
(2000)](https://doi.org/10.2746/042516400777032174), and [Clayton, Sha, Stick and Elvin, *3D Kinematics of the
|
|
161
|
-
Equine Metacarpophalangeal Joint at Walk and Trot* (2007)](https://pubmed.ncbi.nlm.nih.gov/17546207/).
|
|
162
|
-
|
|
163
|
-
The scapula glides against the thorax through loading and swing. Both scapula translation channels are exported,
|
|
164
|
-
and the runtime solves the forelimbs from the changing attachment. The reference range for scapula glide is
|
|
165
|
-
[Lawson and Marlin, Preliminary Report Into the Function of the Shoulder Using a Novel Imaging Approach (2010)](https://doi.org/10.1111/j.2042-3306.2010.00289.x).
|
|
166
|
-
|
|
167
|
-
Three dock joints lead a stride-driven sway and five weighted hair joints follow with a phase lag.
|
|
168
|
-
Call `horse.flickTail(strength, side)` for a stronger swish at any gait. It lifts from the dock, sweeps toward
|
|
169
|
-
the chosen flank, and settles with a smaller return. The event is recorded on the timeline and survives `seek`.
|
|
170
|
-
Authored skins get the follow-through when their `applyPose` maps all eight tail joints. The measured separation
|
|
171
|
-
of the dock and trailing hair follows [Matherne, Cockerill, Zhou, Bellamkonda and Hu,
|
|
172
|
-
*Mammals Repel Mosquitoes with Their Tails* (2018)](https://doi.org/10.1242/jeb.178905). The flexible chain is a
|
|
173
|
-
kinematic approximation of bending and drag, informed by [Bertails, Audoly, Cani, Querleux, Leroy and
|
|
174
|
-
Lévêque, *Super-Helices for Predicting the Dynamics of Natural Hair* (2006)](https://doi.org/10.1145/1179352.1142012).
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
function swishOnTheWalk(horse: import('margoengine/horses').Horse) {
|
|
178
|
-
horse.gait = 'walk';
|
|
179
|
-
horse.speed = 1.5;
|
|
180
|
-
horse.advanceTime(2);
|
|
181
|
-
horse.flickTail(0.8, 'left');
|
|
182
|
-
horse.advanceTime(0.32);
|
|
183
|
-
return horse.pose;
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
| Option | Default |
|
|
188
|
-
| --- | --- |
|
|
189
|
-
| `type`, `withers`, `condition` | `'riding'`, the group mean, 1 |
|
|
190
|
-
| `coat` | `'bay'` (`bay`, `chestnut`, `black`, `grey`, `dun`, `brown`) |
|
|
191
|
-
| `markings` | none: `{socks: [LH, LF, RH, RF] heights in m, blaze: true}` |
|
|
192
|
-
| `maneLength`, `tailLength` | 0.11 and 0.55 times the withers height |
|
|
193
|
-
| `speeds` | each gait's preferred speed for this horse |
|
|
194
|
-
| `detail` | 2 |
|
|
195
|
-
| `atlas` | false: texture coordinates into the crowd coat atlas |
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
import {horseDocument, horseGLB} from 'margoengine/horses/model';
|
|
199
|
-
const {doc, clips} = horseDocument({type: 'draft', coat: 'grey', detail: 1});
|
|
200
|
-
console.log(clips.map((c) => c.name).join(' '), horseGLB({detail: 0}).byteLength > 0); // stand walk trot canter gallop true
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## `addHorse`
|
|
204
|
-
|
|
205
|
-
| Part | Default | Option |
|
|
206
|
-
| --- | --- | --- |
|
|
207
|
-
| Coat hair (`@margoengine/materials/hair` along the body and down the legs) | 400 strands, specular 0.45 | `coatHair` or `false` |
|
|
208
|
-
| Mane and tail hair | 1024 strands | `maneHair` or `false` |
|
|
209
|
-
| Skinning | dual quaternion | |
|
|
210
|
-
| Start | `[0, 0]`, heading 0 (facing +Z) | `position`, `heading`, `ground(x, z)` |
|
|
211
|
-
| Speed and turning | 3 m/s^2, 1.2 rad/s | `acceleration`, `turnRate` |
|
|
212
|
-
| Gait change cross-fade | 0.3 s | `fade` |
|
|
213
|
-
| Shadows | the scene's `Shadows`, if any | `shadows`, `occlusion` |
|
|
214
|
-
|
|
215
|
-
`horse.speed`, `horse.heading` and `horse.gait` (`'auto'` or a forced gait) are kept on the film timeline.
|
|
216
|
-
`advanceTime(dt)` steps a fixed 1/240 s clock; `seek(t)` replays every set from time 0, so a sought frame is the frame
|
|
217
|
-
playing reaches. The stride phase is the distance travelled over the clip's stride length, so hooves never slide when
|
|
218
|
-
the speed changes; the stride frequency at a speed other than the clip's is the clip's stride length over the speed.
|
|
219
|
-
|
|
220
|
-
## Rider seat (`./seat`)
|
|
221
|
-
|
|
222
|
-
`riderSeat({height, thigh, knee})` places a rider's hips, knees, ankles, stirrups and rein hands in the saddle's frame,
|
|
223
|
-
with Winter's segment lengths (thigh 0.245, shank 0.246 of standing height). `mountRider(horse, person.model)` seats a
|
|
224
|
-
`@margoengine/humans` person: every step the rider hip rides the saddle through a damped spring (9 Hz, damping 0.8: the
|
|
225
|
-
pelvis follows the saddle closely and a little behind, Bystroem et al. 2009, Muenz et al. 2014), and the rider's root is
|
|
226
|
-
placed so its hip joint sits there, taking 0.4 of the trunk's pitch. The person plays its own riding clip; the seat's
|
|
227
|
-
knees, stirrups and hands are the targets for its leg and arm IK.
|
|
228
|
-
|
|
229
|
-
```ts
|
|
230
|
-
import {riderSeat, SeatFollower} from 'margoengine/horses/seat';
|
|
231
|
-
const seat = riderSeat({height: 1.78, knee: (115 * Math.PI) / 180});
|
|
232
|
-
const hip = new SeatFollower({frequency: 9});
|
|
233
|
-
hip.step(1 / 240, [0, 1.62, 0.17]); // feed the saddle point each step
|
|
234
|
-
console.log(seat.stirrups[0][1] < 0, hip.position[1]); // true 1.62
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
## Crowds (`./crowd`)
|
|
238
|
-
|
|
239
|
-
`addHorseCrowd(engine, options)` bakes the crowd-detail horse into a bone texture and draws every horse in one
|
|
240
|
-
`SkinnedCrowd` call with a coat atlas, so each horse has its own coat (`coats`, dealt in turn), place, heading, gait and
|
|
241
|
-
stride phase. `update(horses)` takes any list of `{x, z, heading, speed, distance}`: the members of a
|
|
242
|
-
`@margoengine/navmesh/formations` `Army` fit. Near a gait boundary the two clips blend by Froude number.
|
|
243
|
-
`herd.saddles` holds each horse's seat frame (16 numbers, column-major: +Y out of the seat, +Z to the head), read back
|
|
244
|
-
on the CPU from the same bone texture the GPU skins with (`poseBone` of `@margoengine/animation/instanced-skin`), so a
|
|
245
|
-
rider placed there rides the back the GPU draws: within 1.1 mm of the model's own saddle, rising and falling 7.4 cm in
|
|
246
|
-
the trot. `saddleFrame(trunk, saddle, horse)` is the same sum for one horse; `@margoengine/armies` seats a crowd of
|
|
247
|
-
riders on it.
|
|
248
|
-
|
|
249
|
-
```ts
|
|
250
|
-
import {Engine} from 'margoengine';
|
|
251
|
-
import {Army} from 'margoengine/navmesh/formations';
|
|
252
|
-
import {addHorseCrowd} from 'margoengine/horses/crowd';
|
|
253
|
-
const engine = await Engine.create(document.querySelector('canvas')!);
|
|
254
|
-
const army = new Army();
|
|
255
|
-
army.add({count: 31, kind: 'cavalry', shape: 'wedge'}).march({speed: 6});
|
|
256
|
-
const herd = await addHorseCrowd(engine, {type: 'cavalry'});
|
|
257
|
-
army.advanceTime(1 / 30);
|
|
258
|
-
herd.update(army.members);
|
|
259
|
-
console.log(herd.count, herd.saddles[13].toFixed(2)); // 31, and the first horse's seat height, about 1.5
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
## Settings (`./settings`)
|
|
263
|
-
|
|
264
|
-
`HORSE_SETTINGS` holds every option above as slider rows on the shared shape (`@margoengine/sky/settings` is the
|
|
265
|
-
model). `speed`, `gait`, `acceleration`, `turnRate` and `fade` are live; the rest rebuild. `horseOptionsFromSettings`
|
|
266
|
-
returns the `addHorse` options, the live motion values and the `mountRider` options.
|
|
267
|
-
|
|
268
|
-
```ts
|
|
269
|
-
import {horseOptionsFromSettings} from 'margoengine/horses/settings';
|
|
270
|
-
const {options, motion} = horseOptionsFromSettings({type: 'draft', coat: 'grey', speed: 1.5});
|
|
271
|
-
console.log(options.type, motion.speed); // draft 1.5
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
## Limits
|
|
275
|
-
|
|
276
|
-
A stance hoof keeps within 3 cm of where it struck through every gait, type and clip speed from 0.8 to 1.25 times the
|
|
277
|
-
preferred one; the canter and gallop come closest. The legs move in the side plane only (no abduction), and the
|
|
278
|
-
gallop is the transverse gallop on the left lead. The mane and tail are cards, shaded as strands, not simulated hair.
|
|
279
|
-
Riders in a crowd ride `herd.saddles` through `@margoengine/armies`.
|
|
280
|
-
|
|
281
|
-
## Sources
|
|
282
|
-
|
|
283
|
-
Carroll and Huntington 1988 (Equine Vet. J. 20:41); Buchner et al. 1997 (J. Biomech. 30:653) and 1996 (Equine Vet. J.
|
|
284
|
-
28:71); Brooks et al. 2010 (Anim. Genet. 41 s2:159); Holmstroem et al. 1990 (Equine Vet. J. 22:186); Hildebrand 1965
|
|
285
|
-
(Science 150:701) and 1977 (J. Mammal. 58:131); Alexander and Jayes 1983 (J. Zool. 201:135); Alexander 1989 (Physiol.
|
|
286
|
-
Rev. 69:1199); Hoyt and Taylor 1981 (Nature 292:239); Heglund, Taylor and McMahon 1974 (Science 186:1112); Clayton 1993
|
|
287
|
-
(Acta Anat. 146:183) and 1994 (Equine Vet. J. 26:230); Back and Clayton, Equine Locomotion, 2013; Winter, Biomechanics
|
|
288
|
-
and Motor Control of Human Movement, 2009; Bystroem et al. 2009 (Equine Vet. J. 41:280); Muenz, Eckardt and Witte 2014
|
|
289
|
-
(Hum. Mov. Sci. 33:227); Kajiya and Kay 1989 (SIGGRAPH).
|
|
290
|
-
|
|
291
|
-
## Horse traction and gait
|
|
292
|
-
|
|
293
|
-
Use the same motion controller as `addHorse` without creating a scene. Turn rate depends on available hoof grip,
|
|
294
|
-
forward speed and current acceleration. Each support sample contributes to the local ground plane. Walking uphill
|
|
295
|
-
costs work per metre, so the same command gives a shorter, slower stride and can change the selected gait.
|
|
296
|
-
|
|
297
|
-
```ts
|
|
298
|
-
import { HorseMotion } from '@margoengine/horses';
|
|
299
|
-
import { horseBody } from '@margoengine/horses/anatomy';
|
|
300
|
-
|
|
301
|
-
const motion = new HorseMotion(horseBody()).setSupport({
|
|
302
|
-
ground: (_x, z) => 0.08 * z,
|
|
303
|
-
grip: 0.6,
|
|
304
|
-
loadMass: 65,
|
|
305
|
-
});
|
|
306
|
-
for (let step = 0; step < 240; step++) {
|
|
307
|
-
motion.step(1 / 240, { speed: 3.2, heading: 0.3, gait: 'auto' });
|
|
308
|
-
}
|
|
309
|
-
console.log(motion.speed, motion.bank, motion.strideCyclesAt());
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
`grip` defaults to 0.6, and `loadMass` is extra kilograms carried, with a zero default. The drive uses the horse's
|
|
313
|
-
own mass and `acceleration` to set available propulsive force. `bank` is the trunk angle about its forward axis,
|
|
314
|
-
and `sidewaysSpeed` is lateral slip in metres per second. `addHorse` uses the live duty factor and stride length
|
|
315
|
-
to hold the gait phase continuously when speed changes.
|
|
316
|
-
|
|
317
|
-
## Physical mane and tail
|
|
318
|
-
|
|
319
|
-
Use `addStrandHorse` for the same gait and skin with 11 simulated guides for the tail, mane
|
|
320
|
-
and forelock. The tail and mane react to the body's acceleration, gravity and the supplied
|
|
321
|
-
wind. The hair card transforms follow the native guide frames on the horse's 240 Hz clock.
|
|
322
|
-
|
|
323
|
-
```ts
|
|
324
|
-
import { Engine } from 'margoengine';
|
|
325
|
-
import { addStrandHorse } from 'margoengine/horses/strands';
|
|
326
|
-
import { BoundaryLayerWind } from 'margoengine/weather/boundary-layer';
|
|
327
|
-
|
|
328
|
-
const engine = await Engine.create(document.querySelector('canvas')!);
|
|
329
|
-
const wind = new BoundaryLayerWind({ speed: 8, roughness: 0.03, turbulence: false });
|
|
330
|
-
const horse = await addStrandHorse(engine, { coat: 'chestnut', strands: { wind } });
|
|
331
|
-
horse.speed = 4;
|
|
332
|
-
horse.advanceTime(1 / 30);
|
|
333
|
-
engine.render({ delta: 1 / 30 });
|
|
334
|
-
console.log(horse.strandSolver.sample(0, 7).position);
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
`seek(time)` replays the gait commands and native strand state together. `flickTail` drives the
|
|
338
|
-
dock and the following joints respond through the solve. Supply `strands.bed` for ground contact
|
|
339
|
-
and use the normal `ground` option to place the horse's hooves on that surface. The default
|
|
340
|
-
strand tier uses sequential `'rod'` projections at 240 Hz with 5/s damping. Select
|
|
341
|
-
`strands.rodSolve: 'direct'` for finely divided authored guides. `strands.fidelity: 'follow'` selects the
|
|
342
|
-
inextensible model. Both use animated barrel and neck capsules.
|
|
343
|
-
|
|
344
|
-
The default tail bundle uses 18 mm effective radius, 1150 kg/m³ effective density, 32 MPa Young
|
|
345
|
-
modulus and 83 mm drag width. The mane and forelock defaults are 4.5 mm, 1100 kg/m³, 60 MPa
|
|
346
|
-
and 27 mm respectively. Set `strands.tail` and `strands.mane` to fit the rig's bundle mass,
|
|
347
|
-
stiffness and drag. These are coarse guide properties. An authored `skin` supplies
|
|
348
|
-
`skeleton.strandChains` and uses `horseJointTranslation` when applying the pose.
|
|
1
|
+
# @margoengine/horses
|
|
2
|
+
|
|
3
|
+
Horses built in code from published equine measurements. `addHorse(engine)` builds a riding horse, a cavalry remount or
|
|
4
|
+
a heavy draft horse to its breed group's proportions, with a coat, white markings, a mane and tail of hair cards shaded
|
|
5
|
+
as strand hair, a 37-joint rig and walk, trot, canter and gallop taken from equine biomechanics. Its gait follows its
|
|
6
|
+
speed, a stance hoof stays where it struck, and film time seeks exactly. A rider seat gives a person the saddle, stirrups
|
|
7
|
+
and reins and a hip that rides the horse's back; `addHorseCrowd` draws hundreds in one call.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import {Engine} from 'margoengine';
|
|
11
|
+
import {addHorse} from 'margoengine/horses';
|
|
12
|
+
const engine = await Engine.create(document.querySelector('canvas')!);
|
|
13
|
+
const horse = await addHorse(engine, {type: 'cavalry', coat: 'bay', markings: {blaze: true}});
|
|
14
|
+
horse.speed = 4; // eases into a trot at 3 m/s^2
|
|
15
|
+
horse.advanceTime(1 / 30); // or horse.seek(12.5) for a film frame
|
|
16
|
+
console.log(horse.currentGait, horse.body.mass.toFixed(0)); // 'walk' as it sets off, 'trot' near 4 m/s; about 459 kg
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
An existing skinned horse can use the same controller through `skin`. Provide its loaded model in the same engine,
|
|
20
|
+
its fitted skeleton in metres facing +Z, and a function that applies the solved pose to its joint map. The controller
|
|
21
|
+
sets root position and yaw, attaches its skinning pass, and keeps the authored materials. The tightest of the four
|
|
22
|
+
fitted limbs determines whether the stride must shorten to keep the same speed at a quicker cadence. Fit the skeleton
|
|
23
|
+
in metres in a naturally bent stance so the package can measure extension in both directions. The caller owns the model.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import type { Engine } from 'margoengine';
|
|
27
|
+
import { addHorse, type HorseSkin } from 'margoengine/horses';
|
|
28
|
+
|
|
29
|
+
export async function startImportedHorse(engine: Engine, skin: HorseSkin) {
|
|
30
|
+
const horse = await addHorse(engine, { skin });
|
|
31
|
+
horse.speed = 3;
|
|
32
|
+
horse.advanceTime(1);
|
|
33
|
+
return horse;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Pass `ground(x, z)` for an uneven path. The controller holds each stance hoof at its world-space landing point
|
|
38
|
+
through turns, then releases the horizontal correction over 0.18 seconds. It conforms the hoof to the local grade and
|
|
39
|
+
retains toe breakover and swing clearance. The back and saddle lean with the wider ground slope. Supply a stable,
|
|
40
|
+
continuous height field in metres for deterministic seeks. Jumps, large risers, and overhangs require separate route
|
|
41
|
+
planning. Limb reach and splay constraints still apply.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import type { Engine } from 'margoengine';
|
|
45
|
+
import { addHorse } from 'margoengine/horses';
|
|
46
|
+
|
|
47
|
+
export async function walkOnAGrade(engine: Engine) {
|
|
48
|
+
const horse = await addHorse(engine, { ground: (x, z) => 0.08 * z - 0.06 * x + 0.04 * Math.sin(2 * z) });
|
|
49
|
+
horse.gait = 'walk';
|
|
50
|
+
horse.speed = 1.4;
|
|
51
|
+
horse.seek(2.4);
|
|
52
|
+
return horse;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The terrain pass follows the world-space plant and continuous correction approach of [Kovar, Schreiner and Gleicher,
|
|
57
|
+
Footskate Cleanup for Motion Capture Editing (2002)](https://research.cs.wisc.edu/graphics/Papers/Gleicher/Mocap/cleanup.pdf).
|
|
58
|
+
Its separate support frames and trunk sampling draw on [Coros, Karpathy, Jones, Reveret and van de Panne,
|
|
59
|
+
Locomotion Skills for Simulated Quadrupeds (2011)](https://www.cs.ubc.ca/~van/papers/2011-TOG-quadruped/index.html)
|
|
60
|
+
and [Miller, Holden, Al-Ashqar, Dubach, Mitchell and Komura, Carpet Unrolling for Character Control on Uneven Terrain
|
|
61
|
+
(2015)](https://www.pure.ed.ac.uk/ws/portalfiles/portal/21937045/MIG_2015_paper_22.pdf).
|
|
62
|
+
|
|
63
|
+
## Anatomy (`./anatomy`)
|
|
64
|
+
|
|
65
|
+
| Group | Withers | Build | Weight |
|
|
66
|
+
| --- | --- | --- | --- |
|
|
67
|
+
| `riding` | 1.63 m (16 hh) | Thoroughbred: long legs, narrow chest | about 488 kg |
|
|
68
|
+
| `cavalry` | 1.57 m (15.2 hh) | remount: 15 to 16 hands, 950 to 1,200 lb | about 459 kg |
|
|
69
|
+
| `draft` | 1.75 m (17.1 hh) | Shire, Clydesdale, Percheron: deep chest, heavy bone | about 859 kg |
|
|
70
|
+
|
|
71
|
+
Every length is a ratio of the withers height: body length, croup, heart girth, chest depth and width, hip width, head
|
|
72
|
+
and neck, the heights of the elbow, knee, fetlocks, hip joint, stifle and hock, and the cannon circumference. Weight is
|
|
73
|
+
girth squared times length over 11,880 (Carroll and Huntington 1988). `withers` sets another height, `condition` (0.8 to
|
|
74
|
+
1.25) a lean or heavy horse.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import {handsToMetres, horseBody} from 'margoengine/horses/anatomy';
|
|
78
|
+
const shire = horseBody({type: 'draft', withers: handsToMetres(17.2)});
|
|
79
|
+
console.log(shire.withers.toFixed(3), shire.mass.toFixed(0)); // 1.778, about 900 kg
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Gaits (`./gaits`)
|
|
83
|
+
|
|
84
|
+
| Gait | Froude u^2/gh | Footfall (left lead) | Duty factor | Trunk |
|
|
85
|
+
| --- | --- | --- | --- | --- |
|
|
86
|
+
| walk | below 0.4 | LH, LF, RH, RF, a quarter stride apart | 0.75 to 0.6 | two rises a stride, 2.5 % of withers |
|
|
87
|
+
| trot | 0.4 to 2.4 | diagonal pairs, half a stride apart | 0.48 to 0.36 | two rises, 5 % (about 8 cm) |
|
|
88
|
+
| canter | 2.4 to 6.5 | RH; LH and RF; LF; suspension | 0.46 to 0.36 | one rise and a rock |
|
|
89
|
+
| gallop | above 6.5 | RH, LH, RF, LF; suspension | 0.32 to 0.22 | one rise and a rock |
|
|
90
|
+
|
|
91
|
+
Stride length is 2.3 h (u^2/gh)^0.3 with h the hip joint height (Alexander and Jayes 1983): a riding horse covers
|
|
92
|
+
1.6 m a stride at 1.6 m/s, 2.8 m at 4 m/s, 3.9 m at 7 m/s and 6.4 m at 16 m/s. Gait changes by Froude number, so a pony
|
|
93
|
+
trots sooner than a Shire. Footfall timing is Hildebrand (1965, 1977), trot and canter stance Clayton (1993, 1994), trunk
|
|
94
|
+
motion Buchner et al. (1996).
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import {horseBody} from 'margoengine/horses/anatomy';
|
|
98
|
+
import {gaitFor, stride, hoovesDown} from 'margoengine/horses/gaits';
|
|
99
|
+
const body = horseBody();
|
|
100
|
+
const s = stride(body, 7); // a canter
|
|
101
|
+
console.log(gaitFor(body, 7), s.length.toFixed(2), s.duty.toFixed(2), hoovesDown(s, 0.95)); // canter 3.92 0.41 0
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## The model (`./model`)
|
|
105
|
+
|
|
106
|
+
`horseDocument(options)` returns the horse as a glTF 2.0 document and its buffers, for `parseGLTFAsync(engine, doc,
|
|
107
|
+
buffers)`; `horseGLB(options)` returns a `.glb` file. Five materials (`Coat` with vertex colours for points and markings,
|
|
108
|
+
`Hoof`, `Mane`, `Tail`, `Eye`), a skin of 37 joints (the fore limb swings from the scapula, the hind from the pelvis),
|
|
109
|
+
a `saddle` node on the trunk, and the clips `stand`, `walk`, `trot`, `canter` and `gallop`, each one stride long at its
|
|
110
|
+
speed (`speeds` sets them). A pair of planar inverse-kinematic solves places each elbow or stifle and then the
|
|
111
|
+
lower-leg hinge. The fore carpus stays nearly straight through loaded stance and flexes in early swing. The hind
|
|
112
|
+
hock folds on the opposite side of the limb and extends toward landing. Through late stance and lift-off the hoof
|
|
113
|
+
rolls about the toe and transitions continuously to the swing arc. The kinematics follow the swing and support
|
|
114
|
+
phases described in [The forelimb in walking horses, Hodson, Clayton and Lanovaz (2000)](https://pubmed.ncbi.nlm.nih.gov/10952376/),
|
|
115
|
+
[The hindlimb in walking horses, Hodson, Clayton and Lanovaz (2001)](https://doi.org/10.2746/042516401776767485), and
|
|
116
|
+
[Forelimb kinematics and net joint moments during the swing phase of the trot, Lanovaz, Clayton, Colborne and Schamhardt (1999)](https://doi.org/10.1111/j.2042-3306.1999.tb05225.x).
|
|
117
|
+
The gait curves are approximations of these patterns. `detail` 2, 1 or 0 gives about 11,000, 4,000 or 1,300 vertices.
|
|
118
|
+
|
|
119
|
+
The two forelegs straighten the carpus under weight, including if a skinned model's bind pose already bends it.
|
|
120
|
+
For a typical walk, the engine targets about 55 degrees of carpal fold, peaking near 76% of the full stride.
|
|
121
|
+
The fetlock drive follows at about 81%, and the elbow and coffin joint drive follow near 84%. The trot has a
|
|
122
|
+
larger carpal swing around 76 degrees and decelerates into landing. The angles and order follow [Hodson, Clayton
|
|
123
|
+
and Lanovaz, The Forelimb in Walking Horses: Kinematics and Ground Reaction Forces (2000)](https://doi.org/10.2746/042516400777032237),
|
|
124
|
+
[Clayton, Sha, Stick and Mullineaux, Three-Dimensional Carpal Kinematics of Trotting Horses
|
|
125
|
+
(2004)](https://doi.org/10.2746/0425164044848037), and the walking range summarized in [Jose L. Mendez-Angulo,
|
|
126
|
+
Effect of Water Level on Kinematics of Healthy Horses (2012), Table 1](https://conservancy.umn.edu/bitstreams/3a03b69d-656f-4f98-be2c-9706192aa746/download).
|
|
127
|
+
|
|
128
|
+
`fitHorseHooves` runs the leg solve directly for authored contact targets in model space. Pitch and roll are in
|
|
129
|
+
radians about +X and +Z, with zero as the default trunk slope. Each target applies its terrain angles to the base
|
|
130
|
+
hoof motion. The leg lengths and original bending sides are preserved. Turning the whole chain laterally is capped
|
|
131
|
+
at 0.35 radians. The live terrain controller uses this same method.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { horseBody } from 'margoengine/horses/anatomy';
|
|
135
|
+
import { fitHorseHooves, horsePose, horseSkeleton, type HorseHoofTarget } from 'margoengine/horses/model';
|
|
136
|
+
|
|
137
|
+
const rig = horseSkeleton(horseBody());
|
|
138
|
+
const targets: HorseHoofTarget[] = rig.ground.map(([x, , z]) => ({
|
|
139
|
+
point: [x, 0.1 * z, z],
|
|
140
|
+
pitch: -Math.atan(0.1),
|
|
141
|
+
roll: 0,
|
|
142
|
+
}));
|
|
143
|
+
const standingOnTheGrade = fitHorseHooves(rig, horsePose(rig, null), targets, -Math.atan(0.1));
|
|
144
|
+
console.log(standingOnTheGrade.rotations.length); // 37
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Swing matches the planted hoof's local fore-aft velocity at lift-off and touchdown. During a gait change, the
|
|
148
|
+
controller matches hoof positions and short-term travel to select the incoming phase. The outgoing cadence eases out
|
|
149
|
+
as the new gait takes over. Timing comes from the support sequences in [*Symmetrical Gaits of Horses*, Milton Hildebrand
|
|
150
|
+
(1965)](https://pubmed.ncbi.nlm.nih.gov/5844074/). The contact and transition treatment draws on [*Footskate Cleanup for
|
|
151
|
+
Motion Capture Editing*, Lucas Kovar, John Schreiner and Michael Gleicher (2002)](https://graphics.cs.wisc.edu/Papers/2002/KSG02/)
|
|
152
|
+
and [*Automated Semi-Procedural Animation for Character Locomotion*, Rune Skovbo Johansen (2009)](https://runevision.com/thesis/rune_skovbo_johansen_thesis.pdf).
|
|
153
|
+
|
|
154
|
+
In a walk the fore fetlock yields as weight transfers and tucks relative to the cannon during swing.
|
|
155
|
+
The pose solver combines the cannon, pastern, and hoof at their local angles to maintain the planned sole path,
|
|
156
|
+
including the established departure from and return to the plant. It preserves segment lengths and leaves
|
|
157
|
+
the carpus and coffin flexion timed separately. References are [Hodson, Clayton and Lanovaz, *The Forelimb
|
|
158
|
+
in Walking Horses: 1. Kinematics and Ground Reaction Forces* (2000)](https://doi.org/10.2746/042516400777032237),
|
|
159
|
+
[Clayton, Hodson and Lanovaz, *The Forelimb in Walking Horses: 2. Net Joint Moments and Joint Powers*
|
|
160
|
+
(2000)](https://doi.org/10.2746/042516400777032174), and [Clayton, Sha, Stick and Elvin, *3D Kinematics of the
|
|
161
|
+
Equine Metacarpophalangeal Joint at Walk and Trot* (2007)](https://pubmed.ncbi.nlm.nih.gov/17546207/).
|
|
162
|
+
|
|
163
|
+
The scapula glides against the thorax through loading and swing. Both scapula translation channels are exported,
|
|
164
|
+
and the runtime solves the forelimbs from the changing attachment. The reference range for scapula glide is
|
|
165
|
+
[Lawson and Marlin, Preliminary Report Into the Function of the Shoulder Using a Novel Imaging Approach (2010)](https://doi.org/10.1111/j.2042-3306.2010.00289.x).
|
|
166
|
+
|
|
167
|
+
Three dock joints lead a stride-driven sway and five weighted hair joints follow with a phase lag.
|
|
168
|
+
Call `horse.flickTail(strength, side)` for a stronger swish at any gait. It lifts from the dock, sweeps toward
|
|
169
|
+
the chosen flank, and settles with a smaller return. The event is recorded on the timeline and survives `seek`.
|
|
170
|
+
Authored skins get the follow-through when their `applyPose` maps all eight tail joints. The measured separation
|
|
171
|
+
of the dock and trailing hair follows [Matherne, Cockerill, Zhou, Bellamkonda and Hu,
|
|
172
|
+
*Mammals Repel Mosquitoes with Their Tails* (2018)](https://doi.org/10.1242/jeb.178905). The flexible chain is a
|
|
173
|
+
kinematic approximation of bending and drag, informed by [Bertails, Audoly, Cani, Querleux, Leroy and
|
|
174
|
+
Lévêque, *Super-Helices for Predicting the Dynamics of Natural Hair* (2006)](https://doi.org/10.1145/1179352.1142012).
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
function swishOnTheWalk(horse: import('margoengine/horses').Horse) {
|
|
178
|
+
horse.gait = 'walk';
|
|
179
|
+
horse.speed = 1.5;
|
|
180
|
+
horse.advanceTime(2);
|
|
181
|
+
horse.flickTail(0.8, 'left');
|
|
182
|
+
horse.advanceTime(0.32);
|
|
183
|
+
return horse.pose;
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| Option | Default |
|
|
188
|
+
| --- | --- |
|
|
189
|
+
| `type`, `withers`, `condition` | `'riding'`, the group mean, 1 |
|
|
190
|
+
| `coat` | `'bay'` (`bay`, `chestnut`, `black`, `grey`, `dun`, `brown`) |
|
|
191
|
+
| `markings` | none: `{socks: [LH, LF, RH, RF] heights in m, blaze: true}` |
|
|
192
|
+
| `maneLength`, `tailLength` | 0.11 and 0.55 times the withers height |
|
|
193
|
+
| `speeds` | each gait's preferred speed for this horse |
|
|
194
|
+
| `detail` | 2 |
|
|
195
|
+
| `atlas` | false: texture coordinates into the crowd coat atlas |
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
import {horseDocument, horseGLB} from 'margoengine/horses/model';
|
|
199
|
+
const {doc, clips} = horseDocument({type: 'draft', coat: 'grey', detail: 1});
|
|
200
|
+
console.log(clips.map((c) => c.name).join(' '), horseGLB({detail: 0}).byteLength > 0); // stand walk trot canter gallop true
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## `addHorse`
|
|
204
|
+
|
|
205
|
+
| Part | Default | Option |
|
|
206
|
+
| --- | --- | --- |
|
|
207
|
+
| Coat hair (`@margoengine/materials/hair` along the body and down the legs) | 400 strands, specular 0.45 | `coatHair` or `false` |
|
|
208
|
+
| Mane and tail hair | 1024 strands | `maneHair` or `false` |
|
|
209
|
+
| Skinning | dual quaternion | |
|
|
210
|
+
| Start | `[0, 0]`, heading 0 (facing +Z) | `position`, `heading`, `ground(x, z)` |
|
|
211
|
+
| Speed and turning | 3 m/s^2, 1.2 rad/s | `acceleration`, `turnRate` |
|
|
212
|
+
| Gait change cross-fade | 0.3 s | `fade` |
|
|
213
|
+
| Shadows | the scene's `Shadows`, if any | `shadows`, `occlusion` |
|
|
214
|
+
|
|
215
|
+
`horse.speed`, `horse.heading` and `horse.gait` (`'auto'` or a forced gait) are kept on the film timeline.
|
|
216
|
+
`advanceTime(dt)` steps a fixed 1/240 s clock; `seek(t)` replays every set from time 0, so a sought frame is the frame
|
|
217
|
+
playing reaches. The stride phase is the distance travelled over the clip's stride length, so hooves never slide when
|
|
218
|
+
the speed changes; the stride frequency at a speed other than the clip's is the clip's stride length over the speed.
|
|
219
|
+
|
|
220
|
+
## Rider seat (`./seat`)
|
|
221
|
+
|
|
222
|
+
`riderSeat({height, thigh, knee})` places a rider's hips, knees, ankles, stirrups and rein hands in the saddle's frame,
|
|
223
|
+
with Winter's segment lengths (thigh 0.245, shank 0.246 of standing height). `mountRider(horse, person.model)` seats a
|
|
224
|
+
`@margoengine/humans` person: every step the rider hip rides the saddle through a damped spring (9 Hz, damping 0.8: the
|
|
225
|
+
pelvis follows the saddle closely and a little behind, Bystroem et al. 2009, Muenz et al. 2014), and the rider's root is
|
|
226
|
+
placed so its hip joint sits there, taking 0.4 of the trunk's pitch. The person plays its own riding clip; the seat's
|
|
227
|
+
knees, stirrups and hands are the targets for its leg and arm IK.
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import {riderSeat, SeatFollower} from 'margoengine/horses/seat';
|
|
231
|
+
const seat = riderSeat({height: 1.78, knee: (115 * Math.PI) / 180});
|
|
232
|
+
const hip = new SeatFollower({frequency: 9});
|
|
233
|
+
hip.step(1 / 240, [0, 1.62, 0.17]); // feed the saddle point each step
|
|
234
|
+
console.log(seat.stirrups[0][1] < 0, hip.position[1]); // true 1.62
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Crowds (`./crowd`)
|
|
238
|
+
|
|
239
|
+
`addHorseCrowd(engine, options)` bakes the crowd-detail horse into a bone texture and draws every horse in one
|
|
240
|
+
`SkinnedCrowd` call with a coat atlas, so each horse has its own coat (`coats`, dealt in turn), place, heading, gait and
|
|
241
|
+
stride phase. `update(horses)` takes any list of `{x, z, heading, speed, distance}`: the members of a
|
|
242
|
+
`@margoengine/navmesh/formations` `Army` fit. Near a gait boundary the two clips blend by Froude number.
|
|
243
|
+
`herd.saddles` holds each horse's seat frame (16 numbers, column-major: +Y out of the seat, +Z to the head), read back
|
|
244
|
+
on the CPU from the same bone texture the GPU skins with (`poseBone` of `@margoengine/animation/instanced-skin`), so a
|
|
245
|
+
rider placed there rides the back the GPU draws: within 1.1 mm of the model's own saddle, rising and falling 7.4 cm in
|
|
246
|
+
the trot. `saddleFrame(trunk, saddle, horse)` is the same sum for one horse; `@margoengine/armies` seats a crowd of
|
|
247
|
+
riders on it.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import {Engine} from 'margoengine';
|
|
251
|
+
import {Army} from 'margoengine/navmesh/formations';
|
|
252
|
+
import {addHorseCrowd} from 'margoengine/horses/crowd';
|
|
253
|
+
const engine = await Engine.create(document.querySelector('canvas')!);
|
|
254
|
+
const army = new Army();
|
|
255
|
+
army.add({count: 31, kind: 'cavalry', shape: 'wedge'}).march({speed: 6});
|
|
256
|
+
const herd = await addHorseCrowd(engine, {type: 'cavalry'});
|
|
257
|
+
army.advanceTime(1 / 30);
|
|
258
|
+
herd.update(army.members);
|
|
259
|
+
console.log(herd.count, herd.saddles[13].toFixed(2)); // 31, and the first horse's seat height, about 1.5
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Settings (`./settings`)
|
|
263
|
+
|
|
264
|
+
`HORSE_SETTINGS` holds every option above as slider rows on the shared shape (`@margoengine/sky/settings` is the
|
|
265
|
+
model). `speed`, `gait`, `acceleration`, `turnRate` and `fade` are live; the rest rebuild. `horseOptionsFromSettings`
|
|
266
|
+
returns the `addHorse` options, the live motion values and the `mountRider` options.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import {horseOptionsFromSettings} from 'margoengine/horses/settings';
|
|
270
|
+
const {options, motion} = horseOptionsFromSettings({type: 'draft', coat: 'grey', speed: 1.5});
|
|
271
|
+
console.log(options.type, motion.speed); // draft 1.5
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Limits
|
|
275
|
+
|
|
276
|
+
A stance hoof keeps within 3 cm of where it struck through every gait, type and clip speed from 0.8 to 1.25 times the
|
|
277
|
+
preferred one; the canter and gallop come closest. The legs move in the side plane only (no abduction), and the
|
|
278
|
+
gallop is the transverse gallop on the left lead. The mane and tail are cards, shaded as strands, not simulated hair.
|
|
279
|
+
Riders in a crowd ride `herd.saddles` through `@margoengine/armies`.
|
|
280
|
+
|
|
281
|
+
## Sources
|
|
282
|
+
|
|
283
|
+
Carroll and Huntington 1988 (Equine Vet. J. 20:41); Buchner et al. 1997 (J. Biomech. 30:653) and 1996 (Equine Vet. J.
|
|
284
|
+
28:71); Brooks et al. 2010 (Anim. Genet. 41 s2:159); Holmstroem et al. 1990 (Equine Vet. J. 22:186); Hildebrand 1965
|
|
285
|
+
(Science 150:701) and 1977 (J. Mammal. 58:131); Alexander and Jayes 1983 (J. Zool. 201:135); Alexander 1989 (Physiol.
|
|
286
|
+
Rev. 69:1199); Hoyt and Taylor 1981 (Nature 292:239); Heglund, Taylor and McMahon 1974 (Science 186:1112); Clayton 1993
|
|
287
|
+
(Acta Anat. 146:183) and 1994 (Equine Vet. J. 26:230); Back and Clayton, Equine Locomotion, 2013; Winter, Biomechanics
|
|
288
|
+
and Motor Control of Human Movement, 2009; Bystroem et al. 2009 (Equine Vet. J. 41:280); Muenz, Eckardt and Witte 2014
|
|
289
|
+
(Hum. Mov. Sci. 33:227); Kajiya and Kay 1989 (SIGGRAPH).
|
|
290
|
+
|
|
291
|
+
## Horse traction and gait
|
|
292
|
+
|
|
293
|
+
Use the same motion controller as `addHorse` without creating a scene. Turn rate depends on available hoof grip,
|
|
294
|
+
forward speed and current acceleration. Each support sample contributes to the local ground plane. Walking uphill
|
|
295
|
+
costs work per metre, so the same command gives a shorter, slower stride and can change the selected gait.
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
import { HorseMotion } from '@margoengine/horses';
|
|
299
|
+
import { horseBody } from '@margoengine/horses/anatomy';
|
|
300
|
+
|
|
301
|
+
const motion = new HorseMotion(horseBody()).setSupport({
|
|
302
|
+
ground: (_x, z) => 0.08 * z,
|
|
303
|
+
grip: 0.6,
|
|
304
|
+
loadMass: 65,
|
|
305
|
+
});
|
|
306
|
+
for (let step = 0; step < 240; step++) {
|
|
307
|
+
motion.step(1 / 240, { speed: 3.2, heading: 0.3, gait: 'auto' });
|
|
308
|
+
}
|
|
309
|
+
console.log(motion.speed, motion.bank, motion.strideCyclesAt());
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`grip` defaults to 0.6, and `loadMass` is extra kilograms carried, with a zero default. The drive uses the horse's
|
|
313
|
+
own mass and `acceleration` to set available propulsive force. `bank` is the trunk angle about its forward axis,
|
|
314
|
+
and `sidewaysSpeed` is lateral slip in metres per second. `addHorse` uses the live duty factor and stride length
|
|
315
|
+
to hold the gait phase continuously when speed changes.
|
|
316
|
+
|
|
317
|
+
## Physical mane and tail
|
|
318
|
+
|
|
319
|
+
Use `addStrandHorse` for the same gait and skin with 11 simulated guides for the tail, mane
|
|
320
|
+
and forelock. The tail and mane react to the body's acceleration, gravity and the supplied
|
|
321
|
+
wind. The hair card transforms follow the native guide frames on the horse's 240 Hz clock.
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
import { Engine } from 'margoengine';
|
|
325
|
+
import { addStrandHorse } from 'margoengine/horses/strands';
|
|
326
|
+
import { BoundaryLayerWind } from 'margoengine/weather/boundary-layer';
|
|
327
|
+
|
|
328
|
+
const engine = await Engine.create(document.querySelector('canvas')!);
|
|
329
|
+
const wind = new BoundaryLayerWind({ speed: 8, roughness: 0.03, turbulence: false });
|
|
330
|
+
const horse = await addStrandHorse(engine, { coat: 'chestnut', strands: { wind } });
|
|
331
|
+
horse.speed = 4;
|
|
332
|
+
horse.advanceTime(1 / 30);
|
|
333
|
+
engine.render({ delta: 1 / 30 });
|
|
334
|
+
console.log(horse.strandSolver.sample(0, 7).position);
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
`seek(time)` replays the gait commands and native strand state together. `flickTail` drives the
|
|
338
|
+
dock and the following joints respond through the solve. Supply `strands.bed` for ground contact
|
|
339
|
+
and use the normal `ground` option to place the horse's hooves on that surface. The default
|
|
340
|
+
strand tier uses sequential `'rod'` projections at 240 Hz with 5/s damping. Select
|
|
341
|
+
`strands.rodSolve: 'direct'` for finely divided authored guides. `strands.fidelity: 'follow'` selects the
|
|
342
|
+
inextensible model. Both use animated barrel and neck capsules.
|
|
343
|
+
|
|
344
|
+
The default tail bundle uses 18 mm effective radius, 1150 kg/m³ effective density, 32 MPa Young
|
|
345
|
+
modulus and 83 mm drag width. The mane and forelock defaults are 4.5 mm, 1100 kg/m³, 60 MPa
|
|
346
|
+
and 27 mm respectively. Set `strands.tail` and `strands.mane` to fit the rig's bundle mass,
|
|
347
|
+
stiffness and drag. These are coarse guide properties. An authored `skin` supplies
|
|
348
|
+
`skeleton.strandChains` and uses `horseJointTranslation` when applying the pose.
|