@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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Scott Campbell
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Margo Engine
2
+ Copyright 2026 Scott Campbell
3
+
4
+ This product includes Margo Engine (https://margoengine.com) by Scott Campbell.
package/README.md CHANGED
@@ -1,3 +1,348 @@
1
- # Temporary Holding Version
1
+ # @margoengine/horses
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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.
@@ -0,0 +1,75 @@
1
+ /** Breed group: a draft horse, a cavalry remount or a riding horse. */
2
+ export type HorseType = 'draft' | 'cavalry' | 'riding';
3
+ /** Every horse type, in panel order. */
4
+ export declare const HORSE_TYPES: readonly HorseType[];
5
+ /** Proportions of one breed group: `withers` in metres, every other length as a ratio of it. */
6
+ export interface HorseProportions {
7
+ /** Height at the withers, metres. */
8
+ readonly withers: number;
9
+ /** Point of shoulder to point of buttock. */
10
+ readonly bodyLength: number;
11
+ /** Height at the top of the croup. */
12
+ readonly croup: number;
13
+ /** Heart girth, the circumference just behind the elbows. */
14
+ readonly girth: number;
15
+ /** Withers to sternum, the depth of the chest. */
16
+ readonly chestDepth: number;
17
+ /** Width across the points of the shoulders. */
18
+ readonly chestWidth: number;
19
+ /** Width across the points of the hips. */
20
+ readonly hipWidth: number;
21
+ /** Poll to the top lip. */
22
+ readonly headLength: number;
23
+ /** Poll to the withers along the crest. */
24
+ readonly neckLength: number;
25
+ /** Height of the elbow joint. */
26
+ readonly elbow: number;
27
+ /** Height of the carpus (the knee). */
28
+ readonly knee: number;
29
+ /** Height of the fore fetlock joint. */
30
+ readonly foreFetlock: number;
31
+ /** Height of the hip joint. */
32
+ readonly hipJoint: number;
33
+ /** Height of the stifle. */
34
+ readonly stifle: number;
35
+ /** Height of the point of the hock. */
36
+ readonly hock: number;
37
+ /** Height of the hind fetlock joint. */
38
+ readonly hindFetlock: number;
39
+ /** Fore cannon circumference just below the knee. */
40
+ readonly cannon: number;
41
+ /** Length of the tail dock (the bone). */
42
+ readonly dock: number;
43
+ }
44
+ /**
45
+ * Published proportions per breed group. The withers heights are the group means (riding 16 hands, cavalry 15.2,
46
+ * draft 17.1); the ratios give each group its build: the draft horse's deeper chest, wider barrel, shorter legs for its
47
+ * height and heavier cannon.
48
+ */
49
+ export declare const HORSE_PROPORTIONS: Readonly<Record<HorseType, HorseProportions>>;
50
+ /** One horse in metres: the proportions times its withers height, and its weight. */
51
+ export interface HorseBody extends HorseProportions {
52
+ readonly type: HorseType;
53
+ /** Body weight in kilograms from girth and length (Carroll and Huntington 1988). */
54
+ readonly mass: number;
55
+ }
56
+ /** Options of {@link horseBody}. */
57
+ export interface HorseBodyOptions {
58
+ /** Breed group. Default `'riding'`. */
59
+ type?: HorseType;
60
+ /** Height at the withers in metres, 1.2 to 2.1. Default the group's mean. */
61
+ withers?: number;
62
+ /** Multiplies the girth and the body widths, 0.8 to 1.25: a lean or a heavy horse. Default 1. */
63
+ condition?: number;
64
+ }
65
+ /** A height in hands (4 inches each, the decimal digit being inches: 15.2 hh is 15 hands 2 inches) in metres. */
66
+ export declare function handsToMetres(hands: number): number;
67
+ /** Weight in kilograms from heart girth and body length in metres (Carroll and Huntington 1988). */
68
+ export declare function horseMass(girth: number, bodyLength: number): number;
69
+ /**
70
+ * A horse's measurements in metres for its type, withers height and condition.
71
+ * @example
72
+ * const body = horseBody({type: 'cavalry'}); // body.withers 1.57, body.mass about 455 kg
73
+ * @throws TypeError for an unknown type; RangeError for a withers height or condition out of range.
74
+ */
75
+ export declare function horseBody(options?: HorseBodyOptions): HorseBody;