@bitefoundry/retrieviewer 0.0.3 → 0.0.4

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.
Files changed (254) hide show
  1. package/ASSET-PROVENANCE.md +6 -0
  2. package/ASSETS-LICENSE.md +2 -1
  3. package/ATTRIBUTION.md +6 -1
  4. package/COMFORT-ART.md +65 -0
  5. package/DESKTOP-PLATFORMS.md +6 -1
  6. package/PLUGIN.md +13 -10
  7. package/PREREQUISITES.md +95 -0
  8. package/PUPPY-MEMORY.md +102 -1
  9. package/README.ko.md +110 -0
  10. package/README.md +117 -59
  11. package/RELEASING.md +23 -12
  12. package/THIRD-PARTY-NOTICES.md +5 -3
  13. package/braille.mjs +35 -9
  14. package/examples/live.mjs +2 -2
  15. package/integrations/linux-overlay/overlay.py +2 -2
  16. package/integrations/macos-overlay/overlay.jxa +8 -6
  17. package/integrations/opencode/runtime.mjs +4 -4
  18. package/integrations/opencode/tui.tsx +1 -1
  19. package/integrations/windows-overlay/Overlay.cs +4 -4
  20. package/integrations/windows-overlay/protocol.mjs +11 -7
  21. package/package.json +34 -13
  22. package/puppy-comfort-sprites.mjs +25 -0
  23. package/puppy-companion-comfort-q5.bin.gz +0 -0
  24. package/puppy-companion-comfort.json +77 -0
  25. package/puppy-companion-life.mjs +49 -16
  26. package/puppy-companion-objects.mjs +12 -0
  27. package/puppy-frame-predictive.mjs +15 -9
  28. package/puppy-frame-store.mjs +2 -2
  29. package/puppy-paper-world.mjs +14 -0
  30. package/puppy-paper.mjs +65 -14
  31. package/retrieviewer-plugin.d.mts +1 -1
  32. package/retrieviewer-plugin.mjs +1 -1
  33. package/retrieviewer.d.mts +10 -4
  34. package/retrieviewer.mjs +20 -14
  35. package/locomotion-core.mjs +0 -21
  36. package/locomotion-puppy.animal +0 -0
  37. package/vendor/procedural-animals/package.json +0 -40
  38. package/vendor/procedural-animals/src/animal.js +0 -146
  39. package/vendor/procedural-animals/src/bake.js +0 -51
  40. package/vendor/procedural-animals/src/build.js +0 -81
  41. package/vendor/procedural-animals/src/core/build/coatKit.js +0 -121
  42. package/vendor/procedural-animals/src/core/build/featherCards.js +0 -189
  43. package/vendor/procedural-animals/src/core/build/finEdges.js +0 -85
  44. package/vendor/procedural-animals/src/core/build/furSlope.js +0 -115
  45. package/vendor/procedural-animals/src/core/build/mesh.js +0 -67
  46. package/vendor/procedural-animals/src/core/build/pipeline.js +0 -272
  47. package/vendor/procedural-animals/src/core/build/seams.js +0 -183
  48. package/vendor/procedural-animals/src/core/build/warp.js +0 -112
  49. package/vendor/procedural-animals/src/core/build/weights.js +0 -393
  50. package/vendor/procedural-animals/src/core/math/vec.js +0 -81
  51. package/vendor/procedural-animals/src/core/motion/actions.js +0 -800
  52. package/vendor/procedural-animals/src/core/motion/bird.js +0 -3063
  53. package/vendor/procedural-animals/src/core/motion/birdActions.js +0 -1059
  54. package/vendor/procedural-animals/src/core/motion/common.js +0 -158
  55. package/vendor/procedural-animals/src/core/motion/index.js +0 -22
  56. package/vendor/procedural-animals/src/core/motion/quadruped.js +0 -2875
  57. package/vendor/procedural-animals/src/core/motion/snake.js +0 -1594
  58. package/vendor/procedural-animals/src/core/motion/spider.js +0 -1810
  59. package/vendor/procedural-animals/src/core/motion/swimmer.js +0 -1047
  60. package/vendor/procedural-animals/src/core/motion/swimmerActions.js +0 -613
  61. package/vendor/procedural-animals/src/core/render/animalObject.js +0 -262
  62. package/vendor/procedural-animals/src/core/render/coatMaterial.js +0 -1301
  63. package/vendor/procedural-animals/src/core/render/dqs.js +0 -159
  64. package/vendor/procedural-animals/src/core/render/eyes.js +0 -676
  65. package/vendor/procedural-animals/src/core/render/membranes.js +0 -77
  66. package/vendor/procedural-animals/src/core/render/skeleton.js +0 -41
  67. package/vendor/procedural-animals/src/core/rig/bird.js +0 -327
  68. package/vendor/procedural-animals/src/core/rig/quadruped.js +0 -76
  69. package/vendor/procedural-animals/src/core/rig/rig.js +0 -79
  70. package/vendor/procedural-animals/src/core/rig/snake.js +0 -76
  71. package/vendor/procedural-animals/src/core/rig/spider.js +0 -110
  72. package/vendor/procedural-animals/src/core/rig/swimmer.js +0 -181
  73. package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +0 -53
  74. package/vendor/procedural-animals/src/core/sdf/mesher.js +0 -238
  75. package/vendor/procedural-animals/src/core/sdf/sdf.js +0 -263
  76. package/vendor/procedural-animals/src/index.d.ts +0 -98
  77. package/vendor/procedural-animals/src/index.js +0 -29
  78. package/vendor/procedural-animals/src/registry.js +0 -48
  79. package/vendor/procedural-animals/src/species/bear/behaviour.js +0 -463
  80. package/vendor/procedural-animals/src/species/bear/claws.js +0 -147
  81. package/vendor/procedural-animals/src/species/bear/coat.js +0 -726
  82. package/vendor/procedural-animals/src/species/bear/index.js +0 -139
  83. package/vendor/procedural-animals/src/species/bear/motion.js +0 -112
  84. package/vendor/procedural-animals/src/species/bear/regions.js +0 -78
  85. package/vendor/procedural-animals/src/species/bear/rig.js +0 -112
  86. package/vendor/procedural-animals/src/species/bear/sculpt.js +0 -272
  87. package/vendor/procedural-animals/src/species/boar/behaviour.js +0 -335
  88. package/vendor/procedural-animals/src/species/boar/coat.js +0 -372
  89. package/vendor/procedural-animals/src/species/boar/index.js +0 -110
  90. package/vendor/procedural-animals/src/species/boar/motion.js +0 -85
  91. package/vendor/procedural-animals/src/species/boar/regions.js +0 -88
  92. package/vendor/procedural-animals/src/species/boar/rig.js +0 -111
  93. package/vendor/procedural-animals/src/species/boar/sculpt.js +0 -285
  94. package/vendor/procedural-animals/src/species/cat/behaviour.js +0 -559
  95. package/vendor/procedural-animals/src/species/cat/coat.js +0 -841
  96. package/vendor/procedural-animals/src/species/cat/index.js +0 -211
  97. package/vendor/procedural-animals/src/species/cat/motion.js +0 -101
  98. package/vendor/procedural-animals/src/species/cat/regions.js +0 -82
  99. package/vendor/procedural-animals/src/species/cat/rig.js +0 -100
  100. package/vendor/procedural-animals/src/species/cat/sculpt.js +0 -266
  101. package/vendor/procedural-animals/src/species/cat/whiskers.js +0 -110
  102. package/vendor/procedural-animals/src/species/cheetah/coat.js +0 -427
  103. package/vendor/procedural-animals/src/species/cheetah/index.js +0 -51
  104. package/vendor/procedural-animals/src/species/cheetah/joints.js +0 -3
  105. package/vendor/procedural-animals/src/species/cheetah/motion.js +0 -77
  106. package/vendor/procedural-animals/src/species/cheetah/regions.js +0 -95
  107. package/vendor/procedural-animals/src/species/cheetah/rig.js +0 -66
  108. package/vendor/procedural-animals/src/species/cheetah/sculpt.js +0 -158
  109. package/vendor/procedural-animals/src/species/chicken/coat.js +0 -313
  110. package/vendor/procedural-animals/src/species/chicken/coverts.js +0 -320
  111. package/vendor/procedural-animals/src/species/chicken/index.js +0 -110
  112. package/vendor/procedural-animals/src/species/chicken/motion.js +0 -177
  113. package/vendor/procedural-animals/src/species/chicken/regions.js +0 -66
  114. package/vendor/procedural-animals/src/species/chicken/rig.js +0 -144
  115. package/vendor/procedural-animals/src/species/chicken/sculpt.js +0 -389
  116. package/vendor/procedural-animals/src/species/chicken/wingLook.js +0 -66
  117. package/vendor/procedural-animals/src/species/chicken/wingStack.js +0 -124
  118. package/vendor/procedural-animals/src/species/cow/behaviour.js +0 -521
  119. package/vendor/procedural-animals/src/species/cow/coat.js +0 -465
  120. package/vendor/procedural-animals/src/species/cow/index.js +0 -118
  121. package/vendor/procedural-animals/src/species/cow/motion.js +0 -81
  122. package/vendor/procedural-animals/src/species/cow/regions.js +0 -98
  123. package/vendor/procedural-animals/src/species/cow/rig.js +0 -116
  124. package/vendor/procedural-animals/src/species/cow/sculpt.js +0 -339
  125. package/vendor/procedural-animals/src/species/crow/coat.js +0 -145
  126. package/vendor/procedural-animals/src/species/crow/index.js +0 -70
  127. package/vendor/procedural-animals/src/species/crow/joints.js +0 -3
  128. package/vendor/procedural-animals/src/species/crow/motion.js +0 -101
  129. package/vendor/procedural-animals/src/species/crow/regions.js +0 -50
  130. package/vendor/procedural-animals/src/species/crow/rig.js +0 -83
  131. package/vendor/procedural-animals/src/species/crow/sculpt.js +0 -118
  132. package/vendor/procedural-animals/src/species/deer/behaviour.js +0 -513
  133. package/vendor/procedural-animals/src/species/deer/coat.js +0 -391
  134. package/vendor/procedural-animals/src/species/deer/index.js +0 -106
  135. package/vendor/procedural-animals/src/species/deer/motion.js +0 -97
  136. package/vendor/procedural-animals/src/species/deer/regions.js +0 -60
  137. package/vendor/procedural-animals/src/species/deer/rig.js +0 -124
  138. package/vendor/procedural-animals/src/species/deer/sculpt.js +0 -297
  139. package/vendor/procedural-animals/src/species/dog/behaviour.js +0 -521
  140. package/vendor/procedural-animals/src/species/dog/coat.js +0 -495
  141. package/vendor/procedural-animals/src/species/dog/index.js +0 -144
  142. package/vendor/procedural-animals/src/species/dog/motion.js +0 -118
  143. package/vendor/procedural-animals/src/species/dog/regions.js +0 -61
  144. package/vendor/procedural-animals/src/species/dog/rig.js +0 -129
  145. package/vendor/procedural-animals/src/species/dog/sculpt.js +0 -246
  146. package/vendor/procedural-animals/src/species/eagle/coat.js +0 -250
  147. package/vendor/procedural-animals/src/species/eagle/index.js +0 -76
  148. package/vendor/procedural-animals/src/species/eagle/joints.js +0 -3
  149. package/vendor/procedural-animals/src/species/eagle/motion.js +0 -137
  150. package/vendor/procedural-animals/src/species/eagle/regions.js +0 -57
  151. package/vendor/procedural-animals/src/species/eagle/rig.js +0 -107
  152. package/vendor/procedural-animals/src/species/eagle/sculpt.js +0 -137
  153. package/vendor/procedural-animals/src/species/fish/coat.js +0 -271
  154. package/vendor/procedural-animals/src/species/fish/index.js +0 -88
  155. package/vendor/procedural-animals/src/species/fish/motion.js +0 -92
  156. package/vendor/procedural-animals/src/species/fish/regions.js +0 -27
  157. package/vendor/procedural-animals/src/species/fish/rig.js +0 -143
  158. package/vendor/procedural-animals/src/species/fish/sculpt.js +0 -214
  159. package/vendor/procedural-animals/src/species/fish/variants.js +0 -126
  160. package/vendor/procedural-animals/src/species/fox/behaviour.js +0 -314
  161. package/vendor/procedural-animals/src/species/fox/coat.js +0 -444
  162. package/vendor/procedural-animals/src/species/fox/index.js +0 -120
  163. package/vendor/procedural-animals/src/species/fox/motion.js +0 -81
  164. package/vendor/procedural-animals/src/species/fox/regions.js +0 -59
  165. package/vendor/procedural-animals/src/species/fox/rig.js +0 -91
  166. package/vendor/procedural-animals/src/species/fox/sculpt.js +0 -202
  167. package/vendor/procedural-animals/src/species/frog/behaviour.js +0 -590
  168. package/vendor/procedural-animals/src/species/frog/coat.js +0 -305
  169. package/vendor/procedural-animals/src/species/frog/index.js +0 -97
  170. package/vendor/procedural-animals/src/species/frog/motion.js +0 -69
  171. package/vendor/procedural-animals/src/species/frog/regions.js +0 -46
  172. package/vendor/procedural-animals/src/species/frog/rig.js +0 -156
  173. package/vendor/procedural-animals/src/species/frog/sculpt.js +0 -240
  174. package/vendor/procedural-animals/src/species/goat/behaviour.js +0 -509
  175. package/vendor/procedural-animals/src/species/goat/coat.js +0 -590
  176. package/vendor/procedural-animals/src/species/goat/index.js +0 -149
  177. package/vendor/procedural-animals/src/species/goat/motion.js +0 -95
  178. package/vendor/procedural-animals/src/species/goat/regions.js +0 -98
  179. package/vendor/procedural-animals/src/species/goat/rig.js +0 -181
  180. package/vendor/procedural-animals/src/species/goat/sculpt.js +0 -547
  181. package/vendor/procedural-animals/src/species/horse/coat.js +0 -361
  182. package/vendor/procedural-animals/src/species/horse/coatSeam.js +0 -122
  183. package/vendor/procedural-animals/src/species/horse/index.js +0 -80
  184. package/vendor/procedural-animals/src/species/horse/motion.js +0 -245
  185. package/vendor/procedural-animals/src/species/horse/regions.js +0 -60
  186. package/vendor/procedural-animals/src/species/horse/rig.js +0 -117
  187. package/vendor/procedural-animals/src/species/horse/sculpt.js +0 -316
  188. package/vendor/procedural-animals/src/species/horse/seamWeights.js +0 -272
  189. package/vendor/procedural-animals/src/species/lion/behaviour.js +0 -509
  190. package/vendor/procedural-animals/src/species/lion/coat.js +0 -1016
  191. package/vendor/procedural-animals/src/species/lion/index.js +0 -111
  192. package/vendor/procedural-animals/src/species/lion/motion.js +0 -87
  193. package/vendor/procedural-animals/src/species/lion/regions.js +0 -106
  194. package/vendor/procedural-animals/src/species/lion/rig.js +0 -110
  195. package/vendor/procedural-animals/src/species/lion/sculpt.js +0 -384
  196. package/vendor/procedural-animals/src/species/lion/whiskers.js +0 -132
  197. package/vendor/procedural-animals/src/species/pig/behaviour.js +0 -575
  198. package/vendor/procedural-animals/src/species/pig/coat.js +0 -730
  199. package/vendor/procedural-animals/src/species/pig/ears.js +0 -242
  200. package/vendor/procedural-animals/src/species/pig/index.js +0 -161
  201. package/vendor/procedural-animals/src/species/pig/motion.js +0 -105
  202. package/vendor/procedural-animals/src/species/pig/regions.js +0 -100
  203. package/vendor/procedural-animals/src/species/pig/rig.js +0 -152
  204. package/vendor/procedural-animals/src/species/pig/sculpt.js +0 -382
  205. package/vendor/procedural-animals/src/species/rabbit/behaviour.js +0 -605
  206. package/vendor/procedural-animals/src/species/rabbit/coat.js +0 -285
  207. package/vendor/procedural-animals/src/species/rabbit/index.js +0 -85
  208. package/vendor/procedural-animals/src/species/rabbit/motion.js +0 -85
  209. package/vendor/procedural-animals/src/species/rabbit/regions.js +0 -48
  210. package/vendor/procedural-animals/src/species/rabbit/rig.js +0 -99
  211. package/vendor/procedural-animals/src/species/rabbit/sculpt.js +0 -148
  212. package/vendor/procedural-animals/src/species/rat/behaviour.js +0 -539
  213. package/vendor/procedural-animals/src/species/rat/coat.js +0 -341
  214. package/vendor/procedural-animals/src/species/rat/index.js +0 -111
  215. package/vendor/procedural-animals/src/species/rat/motion.js +0 -90
  216. package/vendor/procedural-animals/src/species/rat/regions.js +0 -92
  217. package/vendor/procedural-animals/src/species/rat/rig.js +0 -112
  218. package/vendor/procedural-animals/src/species/rat/sculpt.js +0 -163
  219. package/vendor/procedural-animals/src/species/rat/whiskers.js +0 -119
  220. package/vendor/procedural-animals/src/species/shark/coat.js +0 -383
  221. package/vendor/procedural-animals/src/species/shark/index.js +0 -104
  222. package/vendor/procedural-animals/src/species/shark/motion.js +0 -69
  223. package/vendor/procedural-animals/src/species/shark/regions.js +0 -34
  224. package/vendor/procedural-animals/src/species/shark/rig.js +0 -194
  225. package/vendor/procedural-animals/src/species/shark/sculpt.js +0 -343
  226. package/vendor/procedural-animals/src/species/shark/variants.js +0 -105
  227. package/vendor/procedural-animals/src/species/sheep/behaviour.js +0 -522
  228. package/vendor/procedural-animals/src/species/sheep/coat.js +0 -529
  229. package/vendor/procedural-animals/src/species/sheep/index.js +0 -152
  230. package/vendor/procedural-animals/src/species/sheep/motion.js +0 -86
  231. package/vendor/procedural-animals/src/species/sheep/neck.js +0 -41
  232. package/vendor/procedural-animals/src/species/sheep/regions.js +0 -62
  233. package/vendor/procedural-animals/src/species/sheep/rig.js +0 -163
  234. package/vendor/procedural-animals/src/species/sheep/sculpt.js +0 -542
  235. package/vendor/procedural-animals/src/species/snake/coat.js +0 -315
  236. package/vendor/procedural-animals/src/species/snake/index.js +0 -73
  237. package/vendor/procedural-animals/src/species/snake/motion.js +0 -51
  238. package/vendor/procedural-animals/src/species/snake/regions.js +0 -51
  239. package/vendor/procedural-animals/src/species/snake/rig.js +0 -108
  240. package/vendor/procedural-animals/src/species/snake/sculpt.js +0 -122
  241. package/vendor/procedural-animals/src/species/spider/coat.js +0 -279
  242. package/vendor/procedural-animals/src/species/spider/index.js +0 -78
  243. package/vendor/procedural-animals/src/species/spider/motion.js +0 -72
  244. package/vendor/procedural-animals/src/species/spider/regions.js +0 -87
  245. package/vendor/procedural-animals/src/species/spider/rig.js +0 -118
  246. package/vendor/procedural-animals/src/species/spider/sculpt.js +0 -182
  247. package/vendor/procedural-animals/src/species/wolf/behaviour.js +0 -160
  248. package/vendor/procedural-animals/src/species/wolf/coat.js +0 -749
  249. package/vendor/procedural-animals/src/species/wolf/index.js +0 -107
  250. package/vendor/procedural-animals/src/species/wolf/motion.js +0 -80
  251. package/vendor/procedural-animals/src/species/wolf/regions.js +0 -57
  252. package/vendor/procedural-animals/src/species/wolf/rig.js +0 -87
  253. package/vendor/procedural-animals/src/species/wolf/sculpt.js +0 -339
  254. package/vendor/procedural-animals/src/worker.js +0 -29
@@ -1,521 +0,0 @@
1
- // Cow behaviour layer for the quadruped engine (species.motion.hooks, see core/motion/actions.js):
2
- //
3
- // update(P, dt, layer) every frame over the action layer: the walk's head bob, rumination (chewing
4
- // the cud with a sideways grinding jaw, 40-60 chews per bolus at ~1 Hz, one
5
- // side per bolus; while idle standing and above all while lying), fly swishes
6
- // of the tail, ear flicks, automatic idle variants (nose licks, a moo now and
7
- // then), grazing with the tongue, the bull's charge steering
8
- // pose(engine, dt) after the engine's solve: the jaw's lateral grinding, the tongue (out of the
9
- // mouth: wrapping grass, licking the nostrils), fast ear flicks
10
- // actions attack (bull: paws the ground, then charges head down and tosses; cow: the
11
- // sideways "cow kick" with one hind leg, or { kick: 'back' }), lick (nose),
12
- // chew (ruminate), moo, swish, shake (head shake), lie / sleep (sternal, rising
13
- // hind end first; sleep: head turned back)
14
- //
15
- // Distances are cow metres at the reference size (x cfg.s); posture offsets the engine multiplies by
16
- // cfg.k (fwd, side, headRaise, neckReach) are divided by cfg.unit.
17
- import * as THREE from 'three';
18
- import { clamp, lerp, smooth, TAU, tv, tqa, angDiff } from '../../core/motion/common.js';
19
- import { mx, mxLeg, ONESHOTS, POSTURES } from '../../core/motion/actions.js';
20
-
21
- const _m = new THREE.Matrix4(), _m2 = new THREE.Matrix4(), _q = new THREE.Quaternion(), _q2 = new THREE.Quaternion();
22
- const _v = new THREE.Vector3(), _s = new THREE.Vector3();
23
- const _pv = new THREE.Vector3();
24
-
25
- // per-engine behaviour state
26
- function B(e) {
27
- if (!e._cow) {
28
- const idx = (n) => e.sk.bones.indexOf(e.bone[n]);
29
- const J = e.J;
30
- const iJaw = idx('jaw'), iTg = idx('tongue');
31
- const tDir = J.tongueTip.clone().sub(J.tongueBase).normalize();
32
- const hz = J.nose.clone().sub(J.occiput).normalize();
33
- const hy = hz.clone().cross(new THREE.Vector3(1, 0, 0)).normalize();
34
- e._cow = {
35
- idleT: 0, lickT: 8 + e.rand() * 10, mooT: 40 + e.rand() * 60, swishT: 2 + e.rand() * 4, swishAge: 9, swishAmp: 0.6,
36
- chew: { on: false, t: 0, next: 3 + e.rand() * 4, ph: 0, side: 1, chews: 0, bolus: 50, pause: 0, force: 0 },
37
- chewW: 0, jawLat: 0, jawLatV: 0,
38
- flick: [{ t: 9, dur: 0.3, amp: 0 }, { t: 9, dur: 0.3, amp: 0 }], flickT: 1.5 + e.rand() * 3,
39
- tg: { ext: 0, up: 0, yaw: 0, curl: 0 }, tgT: { ext: 0, up: 0, yaw: 0, curl: 0 }, tgV: { ext: 0, up: 0, yaw: 0, curl: 0 },
40
- charge: null, shakeR: 0, shakeY: 0,
41
- // bind data for the tongue (final, warped + scaled space)
42
- iJaw, iTg, invJaw: iJaw >= 0 ? e.sk.bind[iJaw].clone().invert() : null, bindTg: iTg >= 0 ? e.sk.bind[iTg].clone() : null,
43
- tgRel: iTg >= 0 && iJaw >= 0 ? e.sk.bind[iJaw].clone().invert().multiply(e.sk.bind[iTg]) : null,
44
- tDir, hy, hz, lat: new THREE.Vector3(1, 0, 0),
45
- mouth: J.jawTip.clone().lerp(J.nose, 0.12), // the mouth opening: pivot of the tongue
46
- tLen: J.tongueTip.distanceTo(J.tongueBase),
47
- earAxis: [0, 1].map((k) => { const S = k === 0 ? 'L' : 'R'; return J['earTip' + S].clone().sub(J['earBase' + S]).normalize(); }),
48
- earLen: J.earTipL.distanceTo(J.earBaseL),
49
- };
50
- }
51
- return e._cow;
52
- }
53
- const busy = (L) => L.oneshots.some((a) => !a.stopping && a.name !== 'swish' && a.name !== 'chew');
54
- const find = (L, n) => L.oneshots.find((a) => a.name === n && a.w > 0);
55
-
56
- // ------------------------------------------------------------------------------------------------
57
- // update: gait style, rumination, idle life
58
- function update(P, dt, L) {
59
- const e = L.engine, cfg = e.cfg, b = B(e), u = 1 / cfg.unit;
60
- const vn = e.speed / cfg.sq, g = e.gait;
61
- // ---- walk: the head and neck bob once per forelimb stance (twice per stride), low amplitude
62
- const walkW = smooth(0.15, 0.6, vn) * (1 - smooth(1.5, 2.0, vn)) * P.gaitW;
63
- if (walkW > 0.001 && g) {
64
- const ph = e.phase - g.off[0];
65
- const c = 0.5 + 0.5 * Math.cos(4 * Math.PI * (ph - 0.1));
66
- P.headRaise -= 0.05 * u * walkW * c;
67
- P.headPitch += 0.05 * walkW * (c - 0.5);
68
- }
69
-
70
- // ---- idle bookkeeping
71
- const idleW = L.idle.w;
72
- const lying = L.postures.find((p) => (p.name === 'lie') && p.target > 0 && p.w > 0.95);
73
- const resting = L.postures.find((p) => (p.name === 'lie' || p.name === 'sleep') && p.target > 0 && p.w > 0.95);
74
- const calm = (idleW > 0.9 && !L.postures.length && !busy(L)) || (!!lying && !busy(L));
75
-
76
- // ---- dead on its side: the sideways ears laid back along the neck (not into the ground), the
77
- // head on its cheek
78
- for (const p of L.postures) {
79
- if (p.name !== 'death') continue;
80
- const w = p.w * p.w * (3 - 2 * p.w) * smooth(0.3, 0.9, p.t);
81
- mx(P, 'earFlat', 1, w); mx(P, 'earTwitch', 0, w);
82
- P.headPos.y += 0.08 * cfg.s * w;
83
- // a horned head cannot lie flat on its cheek: it rests on the ground-side horn and the jaw, rolled
84
- // less (0.9 rad instead of the engine's 1.3) with the occiput higher by about the horn's reach
85
- // below it (without this the engine's clearance could keep either the horn or the jaw out of the
86
- // ground, not both: a Highland's jaw 20-27 mm and a Hereford's 21-32 mm deep)
87
- if (e.params.horns) {
88
- const hw = p.w * smooth(0.35, 1.0, p.t);
89
- mx(P, 'headRoll', p.side * 0.9, hw);
90
- P.headPos.y += 0.1 * cfg.s * hw;
91
- }
92
- // the long cannons are spread out from under the falling body early, so the lower foreleg does
93
- // not fold into the ground under the chest
94
- const sp = smooth(0.35, 0.9, p.t) * p.w;
95
- for (let i = 0; i < 4; i++) P.legs[i].spread = Math.max(P.legs[i].spread, sp);
96
- // the long tail follows the rolling rump stiffly while it falls (a loose one is slapped onto the
97
- // ground by the roll and kinks at the contact)
98
- mx(P, 'tailStiff', 1.6, (1 - smooth(1.0, 1.6, p.t)) * p.w);
99
- }
100
-
101
- // ---- rumination: bouts of chewing the cud (mostly lying, often standing idle)
102
- const ch = b.chew;
103
- if (ch.force > 0) ch.force -= dt;
104
- const wantChew = ch.force > 0 || calm;
105
- if (wantChew) {
106
- ch.next -= dt;
107
- if (ch.next <= 0) {
108
- ch.on = !ch.on;
109
- ch.next = ch.on ? (lying ? 50 + e.rand() * 60 : 25 + e.rand() * 30) : (lying ? 4 + e.rand() * 5 : 8 + e.rand() * 12);
110
- if (ch.on) { ch.chews = 0; ch.bolus = 40 + Math.floor(e.rand() * 20); ch.side = e.rand() < 0.5 ? -1 : 1; ch.pause = 0; }
111
- }
112
- if (ch.force > 0 && !ch.on) { ch.on = true; ch.chews = 0; ch.pause = 0; ch.next = Math.max(ch.next, ch.force); }
113
- } else { ch.on = false; ch.next = Math.min(ch.next, 2 + e.rand()); }
114
- let chewing = ch.on && wantChew;
115
- if (chewing && ch.pause > 0) { ch.pause -= dt; chewing = false; }
116
- b.chewW = clamp(b.chewW + (chewing ? dt * 2.5 : -dt * 3), 0, 1);
117
- const cw = b.chewW * b.chewW * (3 - 2 * b.chewW);
118
- if (b.chewW > 0) {
119
- const rate = 1.05; // chews per second
120
- const prev = ch.ph;
121
- ch.ph += dt * rate * (0.4 + 0.6 * cw);
122
- if (Math.floor(ch.ph) !== Math.floor(prev)) {
123
- ch.chews++;
124
- if (ch.chews >= ch.bolus) { ch.chews = 0; ch.bolus = 40 + Math.floor(e.rand() * 20); ch.side = -ch.side; ch.pause = 3 + e.rand() * 2; }
125
- }
126
- const c = ch.ph % 1;
127
- // grinding: the jaw drops, swings to the chewing side, closes, and grinds back across
128
- const open = 0.5 - 0.5 * Math.cos(TAU * c);
129
- mx(P, 'jaw', 0.02 + 0.075 * open, cw); mx(P, 'jawOmega', 22, cw);
130
- b.jawLatT = ch.side * 0.06 * Math.sin(TAU * c + 0.9) * cw;
131
- } else b.jawLatT = 0;
132
-
133
- // ---- grazing: bite cycle with the tongue wrapping the grass (the built-in 'eat' holds the head)
134
- const eat = find(L, 'eat');
135
- const tg = b.tgT; // (targets: set by the actions and here, consumed and cleared by pose)
136
- if (eat) {
137
- const w = eat.w * eat.w * (3 - 2 * eat.w);
138
- const c = (eat.t * 0.9) % 1;
139
- const open = smooth(0.0, 0.1, c) * (1 - smooth(0.32, 0.44, c));
140
- const chew2 = Math.max(0, Math.sin(TAU * 2 * (c - 0.45) / 0.55)) * smooth(0.45, 0.5, c);
141
- mx(P, 'jaw', 0.05 + 0.2 * open + 0.06 * chew2, w);
142
- const side = Math.floor(eat.t * 0.9) % 2 ? 1 : -1;
143
- const out = smooth(0.04, 0.18, c) * (1 - smooth(0.26, 0.4, c));
144
- tg.ext += 0.75 * out * w;
145
- tg.up += -0.35 * out * w; // tip down toward the sward
146
- tg.yaw += side * 0.45 * smooth(0.12, 0.3, c) * out * w; // sweeps round the tuft
147
- tg.curl += 0.6 * smooth(0.18, 0.32, c) * out * w;
148
- b.jawLatT += 0.03 * side * chew2 * w;
149
- }
150
-
151
- // ---- idle variants: nose licks, now and then a moo
152
- if (calm && idleW > 0.9 && !L.postures.length) {
153
- b.lickT -= dt; b.mooT -= dt;
154
- if (b.lickT <= 0) { b.lickT = 14 + e.rand() * 20; if (!b.chew.on || e.rand() < 0.3) L.play('lick'); }
155
- if (b.mooT <= 0) { b.mooT = 60 + e.rand() * 90; L.play('moo'); }
156
- b.shakeT = (b.shakeT ?? 12 + e.rand() * 20) - dt;
157
- if (b.shakeT <= 0) { b.shakeT = 20 + e.rand() * 30; L.play('shake'); }
158
- }
159
-
160
- // ---- fly swish: bursts of tail lashing (standing, walking slowly, lying)
161
- const swishOk = (idleW > 0.5 || vn < 1.4 || resting) && !L.postures.some((p) => p.name === 'death');
162
- if (swishOk) {
163
- b.swishT -= dt;
164
- if (b.swishT <= 0) { b.swishT = 3 + e.rand() * 8; b.swishAge = 0; b.swishAmp = 0.45 + 0.4 * e.rand(); }
165
- }
166
- const sw = find(L, 'swish');
167
- if (sw && sw.t < 0.05) { b.swishAge = 0; b.swishAmp = 0.9; }
168
- b.swishAge += dt;
169
- const sa = Math.sin(Math.PI * clamp(b.swishAge / 2.2, 0, 1));
170
- if (sa > 0.001) { P.tailWag = Math.max(P.tailWag, b.swishAmp * sa * (resting ? 0.5 : 1)); mx(P, 'tailLift', 0.12, sa * 0.5); }
171
-
172
- // ---- ear flicks (against flies): one ear at a time, fast
173
- b.flickT -= dt;
174
- if (b.flickT <= 0) {
175
- b.flickT = 1.2 + e.rand() * 4;
176
- const k = e.rand() < 0.5 ? 0 : 1, f = b.flick[k];
177
- if (f.t > f.dur) { f.t = 0; f.dur = 0.22 + 0.12 * e.rand(); f.amp = (0.35 + 0.35 * e.rand()) * (e.rand() < 0.5 ? 1 : -1) * (1 - P.eyelid * 0.8); }
178
- }
179
- for (const f of b.flick) f.t += dt;
180
-
181
- // ---- bull charge steering (attack)
182
- const cg = b.charge;
183
- if (cg) {
184
- if (cg.run) {
185
- e.wantSpeed = Math.max(e.wantSpeed, cg.speed * smooth(0, 0.5, cg.tRun));
186
- e.wantHeading = cg.heading;
187
- } else if (cg.brake) e.wantSpeed = Math.min(e.wantSpeed, 0);
188
- }
189
- }
190
-
191
- // ------------------------------------------------------------------------------------------------
192
- // pose: jaw grinding, tongue, ear flicks (after the engine wrote every bone)
193
- function pose(e, dt) {
194
- const b = B(e);
195
- if (e.lod === 2) {
196
- // crowd tier: no grinding jaw, tongue, head shake or ear flicks (not visible, and cheap)
197
- b.tgT.ext = b.tgT.up = b.tgT.yaw = b.tgT.curl = 0; b.shakeR = b.shakeY = 0;
198
- return;
199
- }
200
- // jaw: critically damped spring on the lateral grinding angle
201
- const om = 26;
202
- b.jawLatV += (om * om * ((b.jawLatT || 0) - b.jawLat) - 2 * om * b.jawLatV) * dt;
203
- b.jawLat += b.jawLatV * dt;
204
- // tongue springs
205
- let tongueOut = false;
206
- for (const k of ['ext', 'up', 'yaw', 'curl']) {
207
- const o2 = 16;
208
- b.tgV[k] += (o2 * o2 * (b.tgT[k] - b.tg[k]) - 2 * o2 * b.tgV[k]) * dt;
209
- b.tg[k] += b.tgV[k] * dt;
210
- if (Math.abs(b.tg[k]) > 1e-4) tongueOut = true;
211
- b.tgT[k] = 0;
212
- }
213
- const jaw = e.bone.jaw, tongue = e.bone.tongue;
214
- if (!jaw) return;
215
- const moveJaw = Math.abs(b.jawLat) > 1e-5;
216
- if (moveJaw) {
217
- // swing the jaw sideways about the head's dorsal axis through the hinge
218
- _q.setFromRotationMatrix(e.bone.head.matrixWorld).multiply(_q2.copy(e.bindQ.head).invert());
219
- const axis = _v.copy(b.hy).applyQuaternion(_q).normalize();
220
- const hinge = _pv.setFromMatrixPosition(jaw.matrixWorld);
221
- _q2.setFromRotationMatrix(jaw.matrixWorld);
222
- _q2.premultiply(tqa(axis, b.jawLat));
223
- _s.set(1, 1, 1);
224
- jaw.matrixWorld.compose(hinge, _q2, _s);
225
- }
226
- if (tongue && b.tgRel) {
227
- if (moveJaw || tongueOut) tongue.matrixWorld.multiplyMatrices(jaw.matrixWorld, b.tgRel);
228
- if (tongueOut) {
229
- // X (bind space): slide out along the tongue, then turn about the mouth opening: up / down
230
- // (about the lateral axis), sideways (about the dorsal axis) and curl
231
- const t = b.tg, s = e.cfg.s;
232
- const X = _m.makeTranslation(b.tDir.x * t.ext * 0.13 * s, b.tDir.y * t.ext * 0.13 * s, b.tDir.z * t.ext * 0.13 * s);
233
- const piv = b.mouth;
234
- _q.setFromAxisAngle(b.hy, t.yaw).multiply(tqa(b.lat, -t.up - t.curl * 0.5));
235
- _m2.makeTranslation(-piv.x, -piv.y, -piv.z);
236
- const R = new THREE.Matrix4().makeRotationFromQuaternion(_q);
237
- R.multiply(_m2); R.premultiply(_m2.makeTranslation(piv.x, piv.y, piv.z));
238
- X.premultiply(R);
239
- // world = jaw * inv(bindJaw) * X * bindTongue
240
- tongue.matrixWorld.multiplyMatrices(jaw.matrixWorld, b.invJaw).multiply(X).multiply(b.bindTg);
241
- }
242
- }
243
- // head shake: rotate the head and everything riding on it about the occiput (roll about the
244
- // head's long axis, a little yaw). (It runs after the engine's ground clearance: faded out as the
245
- // occiput comes down toward the ground, a head lowered to graze or resting on the ground.)
246
- if (b.shakeR || b.shakeY) {
247
- const head = e.bone.head;
248
- const piv = _pv.setFromMatrixPosition(head.matrixWorld);
249
- const kc = smooth(0.35, 0.6, (piv.y - e.terrainH(piv.x, piv.z)) / e.cfg.s);
250
- _q.setFromRotationMatrix(head.matrixWorld).multiply(_q2.copy(e.bindQ.head).invert());
251
- const ax = _v.copy(b.hz).applyQuaternion(_q).normalize();
252
- _q2.setFromAxisAngle(ax, b.shakeR * kc).premultiply(tqa(tv(0, 1, 0), b.shakeY * kc));
253
- _m.makeTranslation(-piv.x, -piv.y, -piv.z).premultiply(_m2.makeRotationFromQuaternion(_q2)).premultiply(new THREE.Matrix4().makeTranslation(piv.x, piv.y, piv.z));
254
- for (const n of ['head', 'jaw', 'tongue', 'earL', 'earR']) { const bn = e.bone[n]; if (bn) bn.matrixWorld.premultiply(_m); }
255
- b.shakeR = b.shakeY = 0;
256
- }
257
- // ear flicks (none when dead; faded out as the ear tip nears the ground: the flick runs after the
258
- // engine's ground clearance, and an ear on the ground side of a head lying on its side, sleeping or
259
- // grazing, would be swung into it)
260
- if (e.lod < 2 && e.actionsLayer.posture !== 'dead') {
261
- for (let k = 0; k < 2; k++) {
262
- const f = b.flick[k];
263
- if (f.t > f.dur || !f.amp) continue;
264
- const bone = k === 0 ? e.bone.earL : e.bone.earR;
265
- if (!bone) continue;
266
- const base = _pv.setFromMatrixPosition(bone.matrixWorld);
267
- _q2.setFromRotationMatrix(bone.matrixWorld);
268
- const along = _v.set(0, 1, 0).applyQuaternion(_q2);
269
- const tx = base.x + along.x * b.earLen, tz = base.z + along.z * b.earLen;
270
- const clear = smooth(0.12, 0.3, (base.y + along.y * b.earLen - e.terrainH(tx, tz)) / e.cfg.s);
271
- if (clear <= 0) continue;
272
- const x = f.t / f.dur, a = f.amp * Math.sin(Math.PI * x) * Math.sin(Math.PI * x) * clear;
273
- const axis = tv().crossVectors(along, tv(0, 1, 0));
274
- if (axis.lengthSq() < 1e-8) continue;
275
- _q2.premultiply(tqa(axis.normalize(), a)).premultiply(tqa(along, a * 0.8));
276
- bone.matrixWorld.compose(base, _q2, _s.set(1, 1, 1));
277
- }
278
- }
279
- }
280
-
281
- // ------------------------------------------------------------------------------------------------
282
- // actions
283
-
284
- // lick: the tongue comes out and up into one nostril, then the other
285
- const lick = {
286
- kind: 'oneshot', fade: 0.25,
287
- start(inst, L) { inst.dur = 2.4; inst.side = L.engine.rand() < 0.5 ? 1 : -1; },
288
- update(inst) { return inst.t >= inst.dur; },
289
- apply(P, w, inst, L) {
290
- const b = B(L.engine), t = inst.t;
291
- const out = smooth(0.15, 0.45, t) * (1 - smooth(1.85, 2.25, t));
292
- mx(P, 'jaw', 0.14, out * w); mx(P, 'jawOmega', 18, w);
293
- mx(P, 'headPitch', -0.08, out * w);
294
- const tg = b.tgT;
295
- tg.ext += 0.85 * out * w;
296
- tg.up += 1.05 * smooth(0.35, 0.65, t) * (1 - smooth(1.7, 2.05, t)) * w;
297
- const sweep = lerp(inst.side, -inst.side, smooth(0.95, 1.35, t));
298
- tg.yaw += 0.32 * sweep * smooth(0.45, 0.7, t) * (1 - smooth(1.6, 1.9, t)) * w;
299
- tg.curl += 0.25 * out * w;
300
- },
301
- };
302
-
303
- // shake: a quick head shake against flies (the head rolls and yaws about 3 times a second, the
304
- // ears flap with it)
305
- const shake = {
306
- kind: 'oneshot', fade: 0.15,
307
- start(inst, L) { inst.dur = 1.3; inst.dir = L.engine.rand() < 0.5 ? 1 : -1; },
308
- update(inst) { return inst.t >= inst.dur; },
309
- apply(P, w, inst, L) {
310
- const t = inst.t, env = smooth(0.0, 0.15, t) * (1 - smooth(0.8, 1.25, t)) * w;
311
- const osc = Math.sin(TAU * 3.1 * t) * inst.dir;
312
- // (too fast for the head's carriage springs: applied to the head's bones in pose())
313
- const b = B(L.engine);
314
- b.shakeR += 0.42 * osc * env; b.shakeY += 0.16 * osc * env;
315
- P.headPitch += 0.08 * env;
316
- mx(P, 'earFlat', 0.35 + 0.35 * osc, env); mx(P, 'earTwitch', 0, env); mx(P, 'eyelid', 0.5, env);
317
- },
318
- };
319
-
320
- // chew: a bout of rumination on demand (the automatic idle does it by itself)
321
- const chew = {
322
- kind: 'oneshot', fade: 0.3,
323
- start(inst, L) { inst.dur = inst.opts.loop ? Infinity : (inst.opts.duration ?? 12); const c = B(L.engine).chew; c.force = Math.min(inst.dur, 1e6); c.on = true; c.next = Math.max(c.next, 1); c.pause = 0; },
324
- update(inst, dt, L) { if (inst.t >= inst.dur) { B(L.engine).chew.force = 0; return true; } return false; },
325
- apply() {},
326
- };
327
-
328
- // swish: one burst of tail lashing
329
- const swish = {
330
- kind: 'oneshot', fade: 0.2,
331
- start(inst) { inst.dur = 2.2; },
332
- update(inst) { return inst.t >= inst.dur; },
333
- apply() {},
334
- };
335
-
336
- // moo: the head stretches forward and up, the mouth opens and the jaw trembles
337
- const moo = {
338
- kind: 'oneshot', fade: 0.35,
339
- start(inst) { inst.dur = 2.4; inst.said = false; },
340
- update(inst, dt, L) {
341
- if (!inst.said && inst.t > 0.45) { inst.said = true; L.engine.emit('vocalize', { kind: 'moo', position: L.engine.headPose.position.clone() }); }
342
- return inst.t >= inst.dur;
343
- },
344
- apply(P, w, inst, L) {
345
- const u = 1 / L.engine.cfg.unit, t = inst.t;
346
- const k = smooth(0.1, 0.55, t) * (1 - smooth(1.8, 2.35, t)) * w;
347
- mx(P, 'neckReach', 0.12 * u, k); mx(P, 'headRaise', 0.12 * u, k); mx(P, 'headPitch', -0.62, k);
348
- mx(P, 'jaw', 0.28 + 0.04 * Math.sin(t * 40), k * smooth(0.4, 0.6, t)); mx(P, 'jawOmega', 20, w);
349
- mx(P, 'lookW', 0, k); mx(P, 'earFlat', 0.3, k);
350
- },
351
- };
352
-
353
- // attack. Bull (or { style: 'charge' }): threat with the head low, paws the ground with one
354
- // forefoot (three scrapes, dirt thrown back), then charges head down and butts / tosses at the
355
- // target. Cow (or { style: 'kick' }): the "cow kick", one hind leg sweeping forward and out to the
356
- // side; { kick: 'back' } kicks straight back.
357
- const attack = {
358
- kind: 'oneshot', fade: 0.18, needsStand: true,
359
- start(inst, L) {
360
- const e = L.engine, b = B(e);
361
- const bull = (e.params.bull || 0) >= 0.5;
362
- inst.run = smooth(1.2, 3.5, e.speed / e.cfg.sq);
363
- // (a running cow does not kick: she butts with the head on the move, like a bull)
364
- inst.style = inst.opts.style || (inst.opts.kick ? 'kick' : bull || inst.run > 0.3 ? 'charge' : 'kick');
365
- inst.target = inst.opts.target ? inst.opts.target.clone() : null;
366
- inst.hit = false;
367
- if (inst.style === 'charge') {
368
- inst.paw = inst.run < 0.3 && inst.opts.paw !== false;
369
- inst.tPaw = inst.paw ? 2.3 : 0.2;
370
- inst.pawLeg = e.rand() < 0.5 ? 0 : 1;
371
- let h = e.heading;
372
- if (inst.target) h = Math.atan2(inst.target.x - e.pos.x, inst.target.z - e.pos.z);
373
- const dist = inst.target ? Math.hypot(inst.target.x - e.pos.x, inst.target.z - e.pos.z) : 5 * e.cfg.s;
374
- inst.speed = clamp(dist * 0.9, 3.5, 6.5) * e.cfg.sq;
375
- inst.tRun = clamp(dist / (inst.speed * 0.8) + 0.6, 1.4, 3.2);
376
- b.charge = { run: false, brake: false, heading: h, speed: inst.speed, tRun: 0 };
377
- inst.dur = inst.tPaw + inst.tRun + 1.3;
378
- inst.hitAt = inst.tPaw + inst.tRun;
379
- inst.scrapes = [false, false, false];
380
- } else {
381
- inst.back = inst.opts.kick === 'back';
382
- inst.leg = 2 + (e.rand() < 0.5 ? 0 : 1);
383
- if (inst.target) {
384
- const lx = (inst.target.x - e.pos.x) * Math.cos(e.heading) - (inst.target.z - e.pos.z) * Math.sin(e.heading);
385
- inst.leg = lx > 0 ? 2 : 3;
386
- }
387
- inst.dur = 1.25; inst.hitAt = 0.52;
388
- }
389
- },
390
- update(inst, dt, L) {
391
- const e = L.engine, b = B(e);
392
- if (inst.style === 'charge') {
393
- const cg = b.charge;
394
- if (cg) {
395
- if (inst.target) cg.heading = Math.atan2(inst.target.x - e.pos.x, inst.target.z - e.pos.z) * 0.0 + cg.heading; // (committed once it runs)
396
- cg.run = inst.t >= inst.tPaw && inst.t < inst.hitAt + 0.15;
397
- cg.brake = inst.t >= inst.hitAt + 0.15;
398
- if (cg.run) cg.tRun += dt;
399
- // look at the target during the threat
400
- }
401
- if (inst.paw) {
402
- for (let j = 0; j < 3; j++) {
403
- const tt = 0.55 + j * 0.55 + 0.32;
404
- if (!inst.scrapes[j] && inst.t >= tt) {
405
- inst.scrapes[j] = true;
406
- const leg = e.legs[inst.pawLeg];
407
- e.emit('footstep', { foot: leg.def.key, position: leg.plant.clone(), speed: 0, strength: 0.8, paw: true });
408
- }
409
- }
410
- }
411
- if (!inst.hit && inst.t >= inst.hitAt) this.strike(inst, L);
412
- if (inst.t >= inst.dur) { b.charge = null; return true; }
413
- return false;
414
- }
415
- if (!inst.hit && inst.t >= inst.hitAt) this.strike(inst, L);
416
- return inst.t >= inst.dur;
417
- },
418
- strike(inst, L) {
419
- const e = L.engine;
420
- inst.hit = true;
421
- let p, dir;
422
- if (inst.style === 'charge') {
423
- p = new THREE.Vector3().copy(e.headPose.position);
424
- dir = e.forward(e.heading, new THREE.Vector3());
425
- } else {
426
- const leg = e.legs[inst.leg];
427
- p = leg.contact.clone();
428
- dir = inst.back ? e.forward(e.heading, new THREE.Vector3()).negate() : e.left(e.heading, new THREE.Vector3()).multiplyScalar(leg.def.s).addScaledVector(e.forward(e.heading, new THREE.Vector3()), 0.5).normalize();
429
- }
430
- e.emit('attackHit', { position: p, direction: dir, style: inst.style === 'charge' ? 'butt' : 'kick' });
431
- },
432
- apply(P, w, inst, L) {
433
- const e = L.engine, cfg = e.cfg, u = 1 / cfg.unit, s = cfg.s, t = inst.t;
434
- if (inst.target) { P.look = inst.target; mx(P, 'lookW', 1, w); }
435
- if (inst.style === 'charge') {
436
- // head low, forehead / horns forward, ears back
437
- const low = smooth(0, 0.5, t) * (1 - smooth(inst.hitAt + 0.05, inst.hitAt + 0.9, t));
438
- mx(P, 'headRaise', -0.2 * u, low * w); mx(P, 'headPitch', 0.3, low * w); mx(P, 'neckReach', 0.04 * u, low * w);
439
- mx(P, 'earFlat', 0.7, low * w); mx(P, 'tailLift', 0.3, low * w);
440
- // toss: the head swings up at the hit
441
- const toss = smooth(inst.hitAt - 0.1, inst.hitAt + 0.12, t) * (1 - smooth(inst.hitAt + 0.25, inst.hitAt + 0.8, t));
442
- mx(P, 'headPitch', -0.35, toss * w); mx(P, 'headRaise', 0.02 * u, toss * w);
443
- if (inst.paw && t < inst.tPaw) {
444
- // pawing: one forefoot lifts, reaches forward and scrapes back along the ground
445
- const k = smooth(0.35, 0.55, t) * (1 - smooth(inst.tPaw - 0.4, inst.tPaw - 0.1, t)) * w;
446
- mx(P, 'legGait', 0, k); mx(P, 'gaitW', 0, k);
447
- const i = inst.pawLeg, leg = e.legs[i];
448
- const c = clamp((t - 0.55) / 0.55, 0, 3);
449
- const ph = c - Math.floor(c);
450
- const on = c < 3 ? 1 : 0;
451
- // path: lift and reach forward (0 - 0.4), touch down ahead (0.45), scrape back (0.45 - 0.9)
452
- const fwd = on * (ph < 0.45 ? smooth(0, 0.4, ph) : 1 - smooth(0.45, 0.9, ph)) * 0.2 * s;
453
- const up = on * (ph < 0.45 ? Math.sin(Math.PI * clamp(ph / 0.45, 0, 1)) * 0.12 * s : 0.004 * s);
454
- const tp = tv().copy(leg.plant).addScaledVector(e.forward(e.heading, tv()), fwd - 0.03 * s * on);
455
- tp.y += up;
456
- P.legs[i].target.copy(tp);
457
- mxLeg(P, i, 'reach', 1, k);
458
- mx(P, 'side', -leg.def.s * 0.02 * u, k); mx(P, 'dropF', 0.04, k);
459
- }
460
- } else {
461
- const i = inst.leg, leg = e.legs[i], Ld = leg.def, pl = P.legs[i];
462
- const lift = smooth(0.08, 0.3, t) * (1 - smooth(0.78, 1.15, t));
463
- const sweep = smooth(0.3, 0.52, t) * (1 - smooth(0.62, 0.95, t));
464
- // weight onto the other three legs
465
- mx(P, 'side', -Ld.s * 0.035 * u, lift * w); mx(P, 'roll', Ld.s * 0.04, lift * w);
466
- mx(P, 'legGait', 0, lift * w); mx(P, 'gaitW', 0, lift * w);
467
- mx(P, 'earFlat', 0.6, lift * w); mx(P, 'headYaw', Ld.s * 0.25, lift * w);
468
- const base = tv().copy(leg.plant);
469
- let tp;
470
- if (inst.back) tp = e.bodyToWorld(Ld.cx * Ld.s, 0, cfg.zH - Ld.len * 0.55, e.heading, e.pos, tv());
471
- else tp = e.bodyToWorld(Ld.s * (Ld.cx + Ld.len * 0.28), 0, cfg.zH + Ld.len * 0.12, e.heading, e.pos, tv());
472
- tp.y = e.terrainH(tp.x, tp.z) + Ld.len * (inst.back ? 0.35 : 0.3);
473
- const mid = tv().copy(base).lerp(tp, 0.35); mid.y = base.y + Ld.len * 0.22;
474
- const q = tv().copy(base).lerp(mid, smooth(0, 1, lift)).lerp(tp, sweep);
475
- pl.target.copy(q);
476
- mxLeg(P, i, 'reach', 1, lift * w);
477
- }
478
- },
479
- };
480
-
481
- // sleep: lying sternal with the head turned back along the flank / resting beside the forelegs
482
- // Getting up hind end first: the built-in lie lowers the forequarters last (target reached only as
483
- // the posture's weight reaches 0), and its lagging spring would still hold the knees down when the
484
- // posture is removed (a pop). Getting up runs on a remapped weight that finishes 0.3 of the fade
485
- // early and a longer fade, so both ends have settled before the posture ends.
486
- const rise = (w, inst) => (inst.target > 0 ? w : smooth(0.3, 1, w));
487
- const lie = {
488
- kind: 'posture', fadeIn: 1.3, fadeOut: 1.6,
489
- apply(P, w, inst, L) { POSTURES.lie.apply(P, rise(w, inst), inst, L); },
490
- };
491
-
492
- const sleep = {
493
- kind: 'posture', fadeIn: 1.3, fadeOut: 1.7,
494
- apply(P, w0, inst, L) {
495
- const w = rise(w0, inst);
496
- POSTURES.sleep.apply(P, w, inst, L);
497
- const c = smooth(1.0, 3.0, inst.t) * w;
498
- mx(P, 'roll', inst.side * 0.1, c); mx(P, 'bend', inst.side * 0.35, c);
499
- // the long head, already carried nose-down, rests on its cheek beside the forelegs instead of
500
- // being pushed into the ground: occiput higher, nose less tucked
501
- P.headPos.y += 0.2 * L.engine.cfg.s * c;
502
- P.headPitch -= 0.45 * c;
503
- },
504
- };
505
-
506
- // hit: the engine's stagger, head up, tail clamped
507
- const hit = {
508
- ...ONESHOTS.hit,
509
- kind: 'oneshot',
510
- apply(P, w, inst, L) {
511
- ONESHOTS.hit.apply(P, w, inst, L);
512
- mx(P, 'headPitch', -0.25, w * smooth(0.1, 0.3, inst.t) * (1 - smooth(0.5, 0.75, inst.t)));
513
- },
514
- };
515
-
516
- export const behaviour = {
517
- update,
518
- pose,
519
- actions: { attack, lick, chew, moo, swish, shake, lie, sleep, hit },
520
- };
521
- void angDiff;