@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,509 +0,0 @@
1
- // Lion behaviour layer for the quadruped engine (species.motion.hooks, see core/motion/actions.js).
2
- //
3
- // actions roar idle variant: a bout of 2 long moans then a run of grunts; the neck stretches,
4
- // head up and forward, jaw wide, the belly and flanks pump with every call
5
- // yawn huge gape showing the canines, head tipped up, eyes shut, ears back
6
- // attack stalk -> charge -> pounce -> grab: a crouched creep with the head low in line
7
- // with the back and the tail tip twitching, a short burst to a gallop, a leap
8
- // with the forelegs reaching out, then the forepaws grab high (the prey's
9
- // shoulders) while the hind feet stay down and the bite goes to the neck
10
- // (attackHit at the mouth). Played while running it skips the stalk.
11
- // eat lying sternal over the food between the forepaws, tearing jerks with a twist
12
- // death the core collapse, eased in over 0.45 s
13
- // pose the whisker fans sweep back and lift clear of the ground (and lie back when lying)
14
- // update the heavy walk (head low, a nod at each forefoot contact), lapping at ~1.8 Hz when
15
- // drinking, tail-tip flick bursts (irritated, lying, stalking), and the idle life: lions
16
- // rest ~20 h a day, so a lion left standing lies down (sphinx) after 12-27 s, later
17
- // stretches out on its side to sleep, and after a long sleep gets up again; roars and yawns now and
18
- // then, standing or lying. `animal.motion.idleVariants = false` turns the automatic
19
- // resting and calls off; `animal.motion.input.roar = true` asks for a roar.
20
- //
21
- // Posture lengths the engine multiplies by cfg.k (fwd, side, headRaise, neckReach) are given in
22
- // cheetah-reference units like the core's own actions.
23
- import * as THREE from 'three';
24
- import { clamp, lerp, smooth, TAU, tv, tqa, angDiff } from '../../core/motion/common.js';
25
- import { whiskerSamples, WHISKER_BASE_F, WHISKER_TIP_F } from './whiskers.js';
26
- import { fe } from './rig.js';
27
- import { mx, mxLeg, mxLegs, POSTURES } from '../../core/motion/actions.js';
28
-
29
- const sm = (w) => w * w * (3 - 2 * w);
30
- const _lat = new THREE.Vector3();
31
- const busy = (L) => L.oneshots.some((a) => !a.stopping && a.name !== 'hit');
32
-
33
- function S(e) {
34
- if (!e._lion) {
35
- e._lion = {
36
- idleT: 0, restAt: 12 + e.rand() * 15, variantIn: 9 + e.rand() * 8,
37
- auto: null, autoT: 0, nextIn: 30, lieT: 0,
38
- burst: 0, burstT: 0,
39
- };
40
- }
41
- return e._lion;
42
- }
43
-
44
- // ------------------------------------------------------------------------------------------------
45
- // roar: 2 long moans, then 8-14 grunts slowing down; v(t) is the vocal effort 0..1
46
- const ROAR = {
47
- kind: 'oneshot', fade: 0.6,
48
- start(inst, L) {
49
- const e = L.engine;
50
- inst.n = 8 + Math.floor(e.rand() * 7);
51
- inst.calls = [[0.7, 1.7], [2.2, 3.3]];
52
- let t = 3.9;
53
- for (let i = 0; i < inst.n; i++) { const d = 0.32 + 0.02 * i; inst.calls.push([t, t + d * 0.55]); t += d; }
54
- inst.dur = t + 0.6;
55
- e.emit('vocalize', { kind: 'roar' });
56
- },
57
- update(inst) { return inst.t >= inst.dur; },
58
- apply(P, w, inst) {
59
- const t = inst.t;
60
- let v = 0;
61
- for (const [a, b] of inst.calls) {
62
- if (t < a - 0.2 || t > b + 0.3) continue;
63
- const long = b - a > 0.5;
64
- v = Math.max(v, smooth(a - (long ? 0.2 : 0.06), a + (long ? 0.25 : 0.06), t) * (1 - smooth(b - (long ? 0.2 : 0.05), b + (long ? 0.3 : 0.12), t)) * (long ? 1 : 0.7));
65
- }
66
- const pose = smooth(0, 0.6, t) * (1 - smooth(inst.dur - 0.7, inst.dur, t)) * w;
67
- mx(P, 'lookW', 0, pose);
68
- // neck stretched forward, head up, nose up
69
- // (a wide gape, ~47 deg on the long moans: side_roar_male5; 0.65 rad read as a pant)
70
- mx(P, 'neckReach', 0.05, pose); mx(P, 'headRaise', 0.035, pose); mx(P, 'headPitch', -0.3 - 0.16 * v, pose);
71
- mx(P, 'jaw', 0.1 + 0.72 * v, pose); mx(P, 'jawOmega', 16, pose);
72
- // belly and flanks contract with every call (spine arches, chest drops a little)
73
- P.flex += 0.07 * v * pose;
74
- P.dropF += 0.06 * v * pose;
75
- mx(P, 'breathAmp', 0.2, pose);
76
- mx(P, 'earFlat', 0.35, pose); mx(P, 'earTwitch', 0, pose);
77
- mx(P, 'eyelid', 0.4 * v, pose);
78
- mx(P, 'tailLift', 0.12 * v, pose);
79
- },
80
- };
81
-
82
- // yawn: gape up to ~1 rad (the canines show), head tipped up and eyes closed
83
- const YAWN = {
84
- kind: 'oneshot', fade: 0.4,
85
- start(inst, L) { inst.dur = 3.4 + L.engine.rand() * 0.6; },
86
- update(inst) { return inst.t >= inst.dur; },
87
- apply(P, w, inst) {
88
- const t = inst.t, D = inst.dur;
89
- const open = smooth(0.35, 1.4, t) * (1 - smooth(D - 1.2, D - 0.35, t));
90
- const pose = smooth(0, 0.8, t) * (1 - smooth(D - 0.9, D, t)) * w;
91
- mx(P, 'lookW', 0, pose);
92
- mx(P, 'headPitch', -0.3 - 0.12 * open, pose); mx(P, 'headRaise', 0.02, pose); mx(P, 'neckReach', -0.015, pose);
93
- mx(P, 'jaw', 0.05 + 0.95 * open, pose); mx(P, 'jawOmega', 7, pose);
94
- mx(P, 'eyelid', 0.9 * open, pose);
95
- mx(P, 'earFlat', 0.7 * open, pose); mx(P, 'earTwitch', 0, pose);
96
- mx(P, 'breathAmp', 2.2, pose * open); mx(P, 'breathRate', 0.4, pose);
97
- },
98
- };
99
-
100
- // ------------------------------------------------------------------------------------------------
101
- // attack: stalk -> charge -> pounce -> grab and neck bite
102
- const T_STALK = 1.7, T_CHARGE = 1.1, T_GRAB = 1.2;
103
- const reachF = (P, e, x, fwd, up, target) => {
104
- // forepaws reach ahead (toward the target when given); up / fwd in leg lengths
105
- const cfg = e.cfg, fr = e.fr;
106
- for (let i = 0; i < 2; i++) {
107
- const leg = e.legs[i], Ld = leg.def, pl = P.legs[i];
108
- const tp = tv();
109
- if (target) tp.copy(target).addScaledVector(fr.Lf, Ld.s * Ld.cx * 1.3);
110
- else e.bodyToWorld(Ld.cx * Ld.s * 1.3, 0, cfg.zS + fwd * Ld.len, e.heading, e.pos, tp);
111
- tp.y = Math.max(tp.y, e.terrainH(tp.x, tp.z)) + up * Ld.len;
112
- pl.target.lerp(tp, x / Math.max(1e-3, pl.reach + x));
113
- mxLeg(P, i, 'reach', 1, x);
114
- }
115
- };
116
- const ATTACK = {
117
- kind: 'oneshot', airborne: true, fade: 0.25,
118
- start(inst, L) {
119
- const e = L.engine, cfg = e.cfg;
120
- inst.run = smooth(1.5, 4, e.speed / cfg.sk);
121
- inst.target = inst.opts.target ? inst.opts.target.clone() : null;
122
- inst.phase = inst.run > 0.5 ? 'charge' : 'stalk';
123
- inst.tPhase = 0;
124
- inst.v0 = e.speed;
125
- inst.vStalk = 0.45 * cfg.sq;
126
- inst.vCharge = Math.max(e.speed, 8.5 * cfg.sq);
127
- inst.dur = Infinity;
128
- inst.hit = false;
129
- inst.env = 1;
130
- },
131
- update(inst, dt, L) {
132
- const e = L.engine, cfg = e.cfg;
133
- const tp = inst.t - inst.tPhase;
134
- if (inst.target && (inst.phase === 'stalk' || inst.phase === 'charge')) e.wantHeading = Math.atan2(inst.target.x - e.pos.x, inst.target.z - e.pos.z);
135
- if (inst.phase === 'stalk') {
136
- // creep: speed eases up to the stalk speed and back down before the burst
137
- e.wantSpeed = inst.vStalk * (1 - smooth(T_STALK - 0.5, T_STALK, tp) * 0.5);
138
- if (tp >= T_STALK) { inst.phase = 'charge'; inst.tPhase = inst.t; inst.v0 = e.speed; }
139
- } else if (inst.phase === 'charge') {
140
- // burst: ~9 m/s^2 up to the charge speed, then leap (at the target's distance when given)
141
- e.wantSpeed = inst.vCharge;
142
- let leap = tp >= T_CHARGE && e.speed > 0.9 * inst.vCharge || tp > T_CHARGE + 0.6;
143
- if (inst.target) {
144
- const d = Math.hypot(inst.target.x - e.pos.x, inst.target.z - e.pos.z);
145
- leap = (tp > 0.35 && d < 0.55 * e.speed + 0.8 * cfg.legLen) || tp > 3;
146
- }
147
- if (leap) {
148
- const h = 0.32 * cfg.s, vy = Math.sqrt(2 * 9.81 * h);
149
- inst.T = (2 * vy) / 9.81;
150
- inst.phase = 'air'; inst.tPhase = inst.t;
151
- e.takeOff(vy, e.speed);
152
- }
153
- } else if (inst.phase === 'air') {
154
- if (tp > 3) e.touchDown();
155
- } else if (inst.phase === 'grab') {
156
- e.speedOverride = tp < 0.8 ? inst.vLand * Math.exp(-tp / 0.14) : null;
157
- if (!inst.hit && tp > 0.25) {
158
- inst.hit = true;
159
- const p = new THREE.Vector3().copy(cfg.mouthLocal).applyQuaternion(e.headPose.quaternion).add(e.headPose.position);
160
- const dir = inst.target ? inst.target.clone().sub(e.headPose.position).setY(0).normalize() : e.forward(e.heading, new THREE.Vector3());
161
- e.emit('attackHit', { position: p, direction: dir, style: 'pounce' });
162
- }
163
- if (tp >= T_GRAB) return true;
164
- }
165
- return false;
166
- },
167
- onLand(inst, L) {
168
- if (inst.phase !== 'air') return;
169
- const e = L.engine;
170
- inst.phase = 'grab'; inst.tPhase = inst.t;
171
- inst.vLand = e.speed; // the prey stops it: a hard brake, no run-out (see update)
172
- S(e).brake = true;
173
- },
174
- apply(P, w, inst, L) {
175
- const e = L.engine, t = inst.t, tp = t - inst.tPhase;
176
- const target = inst.target;
177
- if (target) { P.look = target; mx(P, 'lookW', 1, w); }
178
- mx(P, 'earTwitch', 0, w);
179
- // the stalking crouch: belly low, shoulders (scapulae) up, head low in line with the back, eyes
180
- // fixed forward, tail low and stiff; it eases in over the stalk and out over the first half
181
- // second of the charge (continuous across the switch)
182
- const crouch = (c) => {
183
- mx(P, 'dropF', 0.4, c); mx(P, 'dropH', 0.38, c);
184
- mx(P, 'headRaise', -0.1, c); mx(P, 'headPitch', -0.08, c); mx(P, 'neckReach', 0.03, c);
185
- mx(P, 'earFlat', -0.15, c);
186
- mx(P, 'tailLift', -0.25, c); mx(P, 'tailStiff', 1.3, c);
187
- mx(P, 'lookW', 0, c * (target ? 0 : 1));
188
- };
189
- if (inst.phase === 'stalk') {
190
- crouch(smooth(0, 0.6, tp) * w);
191
- } else if (inst.phase === 'charge') {
192
- const k = w * smooth(0, 0.4, tp + inst.run);
193
- mx(P, 'headRaise', -0.06, k); mx(P, 'earFlat', 0.45, k); mx(P, 'tailLift', 0.25, k);
194
- crouch((1 - smooth(0, 0.5, tp)) * (1 - inst.run) * w);
195
- } else if (inst.phase === 'air') {
196
- const x = clamp(tp / (inst.T || 0.5), 0, 1);
197
- const k0 = smooth(0, 0.12, tp) * w;
198
- mx(P, 'headRaise', -0.06, w); mx(P, 'tailLift', 0.25, w); // (the charge's carriage, carried on)
199
- mx(P, 'gaitW', 0, k0); mx(P, 'legGait', 0, k0);
200
- mxLeg(P, 2, 'tuck', 1, k0); mxLeg(P, 3, 'tuck', 1, k0);
201
- // (blended by the phase weight like every other posture value: set outright, the gait took the leg
202
- // back in one step when the grab faded, a 94 rad/s* pop of the metatarsus)
203
- for (const i of [2, 3]) P.legs[i].extend = lerp(P.legs[i].extend || 0, 1 - smooth(0, 0.4, x), k0);
204
- // (a reach out and a little up: 0.45 leg lengths up stretched the armpits > 3x)
205
- reachF(P, e, k0, 0.58, lerp(0.28, 0.18, x), null);
206
- const k1 = smooth(0, 0.2, tp) * w;
207
- mx(P, 'pitch', lerp(0.18, -0.12, x), k1);
208
- mx(P, 'jaw', 0.55, w * smooth(0.2, 0.7, x)); mx(P, 'jawOmega', 20, w);
209
- mx(P, 'earFlat', 0.7, w); mx(P, 'tailLift', 0.35, lerp(1, k1, 0.5 * (1 - inst.run)));
210
- mx(P, 'headRaise', 0.02, k1); mx(P, 'headPitch', -0.15, k1);
211
- } else if (inst.phase === 'grab') {
212
- // forepaws hook the prey's shoulders (high and ahead), hind feet planted, bite to the neck
213
- // (the flight pose carries over into the landing: tucked hind legs come down, the forepaws
214
- // go on reaching, and rise from the flight's reach to the grab)
215
- const land = 1 - smooth(0, 0.3, tp);
216
- const g = Math.max(land, smooth(0, 0.25, tp)) * (1 - smooth(T_GRAB - 0.7, T_GRAB, tp));
217
- const k = g * w;
218
- reachF(P, e, k, lerp(0.58, 0.48, 1 - land), lerp(0.18, 0.13, smooth(0, 0.35, tp)), null);
219
- mxLeg(P, 2, 'tuck', 1, land * w); mxLeg(P, 3, 'tuck', 1, land * w);
220
- for (const i of [2, 3]) P.legs[i].extend = lerp(P.legs[i].extend || 0, 0.8 * smooth(0, 0.3, tp), land * w);
221
- mx(P, 'legGait', 0, k); mx(P, 'gaitW', 0, k);
222
- const kr = w * smooth(0, 0.35, tp) * (1 - smooth(T_GRAB - 0.7, T_GRAB, tp));
223
- mx(P, 'pitch', -0.12, k);
224
- mx(P, 'headRaise', 0.02, w * land); mx(P, 'headPitch', -0.15, w * land); mx(P, 'tailLift', 0.35, w * land);
225
- mx(P, 'dropH', 0.3, kr); mx(P, 'dropF', -0.15, kr);
226
- mx(P, 'headRaise', 0.07, kr); mx(P, 'neckReach', 0.065, kr); mx(P, 'headPitch', -0.22, kr);
227
- // jaw: open on the grab, clamps shut on the neck and holds, then lets go
228
- const bite = smooth(0.15, 0.3, tp) * (1 - smooth(T_GRAB - 0.6, T_GRAB - 0.3, tp));
229
- mx(P, 'jaw', lerp(0.6, 0.22, bite), k); mx(P, 'jawOmega', 25, k);
230
- mx(P, 'earFlat', 0.7, k); mx(P, 'eyelid', 0.3 * bite, k);
231
- mx(P, 'tailLift', 0.3, k);
232
- }
233
- },
234
- };
235
-
236
- // death: the core collapse, eased in over 0.45 s instead of 0.25 s (a heavy body; a paw finishing its
237
- // swing inside a faster collapse snapped to the ground on some slopes)
238
- const DEATH = { ...POSTURES.death, kind: 'posture', fadeIn: 0.45 };
239
-
240
- // eat: lions eat lying sternal with the carcass between the forepaws (the standing
241
- // crouch read as a dog at a bowl). The sphinx lie (tune actions.lie) under the action's weight, then the
242
- // head down to the food at the forepaws: tearing jerks up and back with a twist, the jaw clamping (the core
243
- // eat's rhythm); the update hook keeps the head up over a long mane.
244
- const EAT = {
245
- kind: 'oneshot', fade: 1.3,
246
- start(inst, L) {
247
- inst.dur = inst.opts.loop ? Infinity : (inst.opts.duration ?? 7);
248
- inst.side = L.engine.rand() < 0.5 ? 1 : -1;
249
- },
250
- update(inst) { return inst.t >= inst.dur; },
251
- apply(P, w, inst, L) {
252
- const e = L.engine, t = inst.t;
253
- const tune = inst.tune;
254
- inst.tune = e.cfg.actions.lie || {};
255
- POSTURES.lie.apply(P, w, inst, L);
256
- inst.tune = tune;
257
- // (the head lowered and pitched down over the food by the neck, not placed at a ground target: the
258
- // core's reach target follows the forefeet's plants, which jump as the legs fold under a lying body)
259
- const hw = smooth(0.4, 1, w);
260
- const c = (t * 0.75) % 1;
261
- const jerk = smooth(0.35, 0.5, c) * (1 - smooth(0.6, 0.95, c));
262
- mx(P, 'headRaise', -0.06 + 0.03 * jerk, hw); mx(P, 'neckReach', 0.03, hw);
263
- mx(P, 'headPitch', 0.75 - 0.3 * jerk, hw);
264
- mx(P, 'headYaw', 0.2 * jerk * Math.sin(Math.floor(t * 0.75) * 2.3), hw);
265
- mx(P, 'lookW', 0, hw); mx(P, 'headOmega', 2.2, hw);
266
- mx(P, 'jaw', 0.05 + 0.3 * smooth(0, 0.15, c) * (1 - smooth(0.25, 0.4, c)), hw); mx(P, 'jawOmega', 12, hw);
267
- mx(P, 'earTwitch', 1.5, hw);
268
- mx(P, 'speedScale', 0, w);
269
- },
270
- };
271
-
272
- export const lionActions = { roar: ROAR, yawn: YAWN, attack: ATTACK, death: DEATH, eat: EAT };
273
-
274
- // ------------------------------------------------------------------------------------------------
275
- function update(P, dt, L) {
276
- const e = L.engine, st = S(e), cfg = e.cfg;
277
- const vn = e.speed / cfg.sq;
278
- // the pounce's brake owns the ground speed only while its grab runs
279
- if (st.brake && !L.oneshots.some((a) => a.name === 'attack' && a.phase === 'grab' && !a.stopping)) { e.speedOverride = null; st.brake = false; }
280
-
281
- // ---- a head lying on its side rests on the cheek and the mane: lift it by its half width beyond
282
- // what the core assumes (the core's heights were set for the cheetah's small head)
283
- // (0.19: the broad cheekbones and the pinna's broad base: the ear base 9 mm in the ground at 0.18)
284
- // (0.2: the flatter cheek plane let the head lie lower on its side, an ear tip 13-15 mm in the ground at 0.19)
285
- const headHW = (0.2 + 0.15 * (e.params.mane || 0)) * (e.params.juv ? 1.35 : 1) * cfg.s; // (cubs: the big ears, 1.2 left an ear 7 mm in the ground)
286
- for (const p of L.postures) {
287
- const lat = p.name === 'sleep' && p.tune.style === 'lateral', dead = p.name === 'death';
288
- if (!lat && !dead) continue;
289
- const pw = sm(clamp(p.w, 0, 1));
290
- const c = lat ? smooth(0.8, 2.0, p.t) * pw : smooth(0.3, 0.9, p.t) * pw;
291
- P.headPos.y += Math.max(0, headHW - (lat ? 0.085 : 0.092) * cfg.k) * c;
292
- // (the thick maned neck does not twist as far as the core rolls a cheetah's head)
293
- P.headRoll *= 1 - 0.4 * c;
294
- // dead: the jaw slack but closed (the core's 0.1 rad parted the lips, and the lower lip's rim drew a second black arc
295
- // round the white chin, a "double C" round a white plate)
296
- // and the head rolled a little less, so the side of the jaw rather than its white underside faces out
297
- if (dead) { mx(P, 'jaw', 0.02, c); P.headRoll *= 1 - 0.15 * c; }
298
- // the tail limp on the ground: at rest the tail's frame is the pelvis, rolled onto its side, so the core's ground pose
299
- // (a pitch toward the pelvis's down) and its side curl lay the tail out sideways at hip height, the tip raised (17-39 cm
300
- // in the air). Bend it from the root toward the ground instead (the pelvis's lateral axis, which points
301
- // up or down on a body lying on its side); the tail's ground contact lays it along the ground.
302
- if (e.fr && e.fr.qPel) {
303
- _lat.set(1, 0, 0).applyQuaternion(e.fr.qPel);
304
- const down = _lat.y < 0 ? 1 : -1, k = c * smooth(0.35, 0.75, Math.abs(_lat.y));
305
- P.tailSide *= 1 - k;
306
- mx(P, 'tailCurl', down * 1.6, k);
307
- mx(P, 'tailGround', 0.5, k);
308
- mx(P, 'tailIdle', 0, k);
309
- }
310
- // a maned neck is wider than the chest: on its side the body rests on the mane
311
- const neckHW = (0.19 + 0.13 * (e.params.mane || 0)) - 0.2; // (incl. the mane's locks)
312
- // (plus ~1.6 cm for every lion: the thick forearm of the lower foreleg lies under the flank; 1.2 cm left
313
- // a lioness 1.1-1.2 % S in the ground on her death)
314
- P.lift += ((Math.max(0, neckHW) + 0.016) / cfg.unit) * (lat ? smooth(0.8, 2.2, p.t) : smooth(0.3, 0.8, p.t)) * pw;
315
- }
316
-
317
- // ---- getting up: the legs leave their lying / fallen poses early (by the time the gait may
318
- // re-step a foot the posture no longer holds it up; the core's side pose lifted a paw that then
319
- // snapped to the ground as its step ended)
320
- for (const p of L.postures) {
321
- if (p.target > 0 || p.w >= 1) continue;
322
- const k = smooth(0.4, 0.8, p.w);
323
- for (const l of P.legs) { l.side *= k; l.spread *= k; }
324
- }
325
-
326
- // ---- turning at speed: the head stays nearly in line with the spine (the engine leads a turn with the
327
- // head by up to 0.5 rad for as long as the heading error lasts; in a heavy cat's slow, wide gallop turn
328
- // that held the neck at full twist for seconds). At the walk the head keeps its full lead.
329
- if (!e.input.follow) {
330
- const lead = clamp(e.yawRate * 0.22 + 0.5 * angDiff(e.heading, e.wantHeading ?? e.heading), -0.5, 0.5);
331
- P.headYaw -= 0.8 * lead * smooth(2.5, 7, vn) * P.gaitW;
332
- // (and it rolls with the leaning body: held level against a 30 deg lean the neck twisted 35-37 deg)
333
- P.headRoll += 0.8 * (e.bank ? e.bank.x : 0) * P.gaitW;
334
- }
335
-
336
- // ---- the heavy walk: head low (carriage table), a nod at each forefoot contact
337
- const walkW = smooth(0.15, 0.6, vn) * (1 - smooth(1.8, 2.6, vn)) * P.gaitW;
338
- if (walkW > 0.01) {
339
- const nod = 0.5 + 0.5 * Math.cos(2 * TAU * (e.phase - 0.27 - 0.06));
340
- P.headRaise -= 0.014 * nod * walkW;
341
- P.headPitch += 0.04 * nod * walkW;
342
- }
343
-
344
- // ---- eating / drinking: the head stays a little higher over a long mane (the bib under the neck)
345
- for (const a of L.oneshots) {
346
- if ((a.name !== 'eat' && a.name !== 'drink') || a.w <= 0) continue;
347
- // (the core's tearing jerk pulls the head up and back: the mane under a folded neck would dig
348
- // into the ground, so the head rises further and stays forward through the jerk)
349
- const c = (a.t * 0.75) % 1, jerk = a.name === 'eat' ? smooth(0.35, 0.5, c) * (1 - smooth(0.6, 0.95, c)) : 0;
350
- const k = sm(a.w) * P.headW;
351
- P.headPos.y += ((0.06 + 0.06 * jerk) * (e.params.mane || 0) + (a.name === 'drink' ? 0.045 : 0.045)) * cfg.s * k;
352
- P.headPos.addScaledVector(e.fr.F, 0.05 * jerk * cfg.s * k);
353
- }
354
-
355
- // ---- lapping (~1.8 laps / s, tongue curled back: the jaw drops a little each lap)
356
- for (const a of L.oneshots) {
357
- if (a.name !== 'drink' || a.w <= 0) continue;
358
- const w = sm(a.w);
359
- const lap = Math.max(0, Math.sin(a.t * 1.8 * TAU));
360
- mx(P, 'jaw', 0.06 + 0.12 * lap * lap, w);
361
- mx(P, 'earFlat', 0.15, w);
362
- }
363
-
364
- // ---- tail-tip flick bursts: while lying, stalking, and now and then when standing
365
- const lying = L.postures.some((p) => (p.name === 'lie' || p.name === 'sleep') && p.target > 0);
366
- const stalking = L.oneshots.some((a) => a.name === 'attack' && a.phase === 'stalk');
367
- st.burstT -= dt;
368
- if (st.burstT <= 0) {
369
- if (st.burst > 0) { st.burst--; st.burstT = 0.55 + e.rand() * 0.35; e.tail.flickT = 0; }
370
- else { st.burst = stalking ? 3 : e.rand() < (lying ? 0.5 : 0.3) ? 2 + Math.floor(e.rand() * 3) : 0; st.burstT = stalking ? 0.6 : 6 + e.rand() * 10; }
371
- }
372
- if (stalking) P.tailIdle = Math.max(P.tailIdle, 1);
373
-
374
- // ---- idle life: resting, roars, yawns
375
- const enabled = e.idleVariants !== false;
376
- if (e.input.roar) { e.input.roar = false; if (!busy(L)) L.play('roar'); }
377
- const still = L.idle.w > 0.97 && !L.postures.length && !busy(L) && !e.input.follow && !e.input.look;
378
- // the automatic rest ends when anything else takes over (the game moved it, played a posture)
379
- const cur = L.postures.find((p) => p.target > 0);
380
- if (st.auto && (!cur || cur.name !== st.auto)) st.auto = null;
381
- if (!enabled) { st.idleT = 0; return; }
382
- if (still) {
383
- st.idleT += dt;
384
- st.variantIn -= dt;
385
- if (st.idleT > st.restAt) {
386
- st.idleT = 0; st.restAt = 12 + e.rand() * 15;
387
- L.play('lie'); st.auto = 'lie'; st.autoT = 0; st.nextIn = 30 + e.rand() * 40;
388
- } else if (st.variantIn <= 0) {
389
- st.variantIn = 10 + e.rand() * 10;
390
- const r = e.rand();
391
- if (r < 0.3) L.play('roar'); else if (r < 0.6) L.play('yawn');
392
- }
393
- } else {
394
- st.idleT = Math.max(0, st.idleT - dt * 2);
395
- st.variantIn = Math.max(st.variantIn, 4);
396
- }
397
- if (st.auto && cur && cur.w >= 1) {
398
- st.autoT += dt;
399
- st.variantIn -= dt;
400
- if (st.autoT > st.nextIn) {
401
- st.autoT = 0;
402
- if (st.auto === 'lie') { if (e.rand() < 0.7) { L.play('sleep', { side: cur.side }); st.auto = 'sleep'; st.nextIn = 50 + e.rand() * 60; } else st.nextIn = 20 + e.rand() * 20; }
403
- else { L.play('stand'); st.auto = null; st.idleT = 0; } // wakes, gets up, and the cycle starts over
404
- } else if (st.auto === 'lie' && st.variantIn <= 0 && !busy(L)) {
405
- st.variantIn = 12 + e.rand() * 14;
406
- const r = e.rand();
407
- if (r < 0.25) L.play('roar'); else if (r < 0.65) L.play('yawn');
408
- }
409
- }
410
- }
411
-
412
- // ------------------------------------------------------------------------------------------------
413
- // pose: the whisker fans (whiskers.js) sweep back along the cheek and lift about their roots just enough
414
- // to stay out of the ground when the head lies on it (sleep, death, drinking with the chin down), the way
415
- // a cat lays its whiskers back against a surface (after the cat's hook), on fast critically damped springs.
416
- const _q = new THREE.Quaternion(), _q2 = new THREE.Quaternion(), _s1 = new THREE.Vector3(1, 1, 1);
417
- const _p = new THREE.Vector3(), _a = new THREE.Vector3(), _d = new THREE.Vector3(), _ax = new THREE.Vector3();
418
- const _w = Array.from({ length: 160 }, () => new THREE.Vector3());
419
- const WB = fe(...WHISKER_BASE_F), WT = fe(...WHISKER_TIP_F);
420
- function whiskerLocal(e, k) {
421
- const s = k ? -1 : 1, S = k ? 'R' : 'L';
422
- const i = e.sk.bones.indexOf(e.bone['whisker' + S]);
423
- const inv = e.sk.bind[i].clone().invert();
424
- const Jb = e.J['whiskerBase' + S], Jt = e.J['whiskerTip' + S];
425
- const kk = Jb.distanceTo(Jt) / Math.hypot(WT[0] - WB[0], WT[1] - WB[1], WT[2] - WB[2]);
426
- return [WT, ...whiskerSamples(e.params)].map((p) => new THREE.Vector3(Jb.x + (p[0] - WB[0]) * s * kk, Jb.y + (p[1] - WB[1]) * kk, Jb.z + (p[2] - WB[2]) * kk).applyMatrix4(inv));
427
- }
428
- // exact step of a critically damped spring x'' = -om^2 (x - target) - 2 om x'
429
- function crit(x, v, target, om, dt) {
430
- const d0 = x - target, B = v + om * d0, e = Math.exp(-om * dt);
431
- return [target + (d0 + B * dt) * e, (v - om * B * dt) * e];
432
- }
433
- const _lip = new THREE.Vector3();
434
- function pose(e, dt) {
435
- if (e.lod >= 2 || !e.bone.whiskerL) return;
436
- const st = S(e), cfg = e.cfg;
437
- // the upper lip's edge draws back and up as the jaw opens (a roar, a yawn, a snarl): the lip corners go back and
438
- // the upper canines show (the gape stayed a round "O" with the canines hidden behind the lip)
439
- const gape = smooth(0.1, 0.8, e.jaw ? e.jaw.x : 0);
440
- if (gape > 1e-4 && e.bone.lipL) {
441
- for (const S2 of ['L', 'R']) {
442
- const b = e.bone['lip' + S2];
443
- _lip.set(0, 0.013, -0.011).multiplyScalar(gape * cfg.s).applyQuaternion(e.headPose.quaternion);
444
- b.matrixWorld.elements[12] += _lip.x; b.matrixWorld.elements[13] += _lip.y; b.matrixWorld.elements[14] += _lip.z;
445
- }
446
- }
447
- if (!st.whisk) st.whisk = [{ back: 0, lift: 0, vb: 0, vl: 0 }, { back: 0, lift: 0, vb: 0, vl: 0 }];
448
- if (!st.wLocal) st.wLocal = [0, 1].map((k) => whiskerLocal(e, k));
449
- let lying = 0;
450
- for (const p of e.actionsLayer.postures) if (p.name === 'lie' || p.name === 'sleep' || p.name === 'death') lying = Math.max(lying, clamp(p.w, 0, 1));
451
- for (let k = 0; k < 2; k++) {
452
- const S2 = k ? 'R' : 'L', s = k ? -1 : 1;
453
- const bone = e.bone['whisker' + S2], W = st.whisk[k];
454
- const base = _p.setFromMatrixPosition(bone.matrixWorld);
455
- _q.setFromRotationMatrix(bone.matrixWorld);
456
- _a.set(0, 1, 0).applyQuaternion(e.headPose.quaternion);
457
- // (look ahead by the head's fall: a collapsing body drops the face fast)
458
- const vDown = W.y0 === undefined || dt <= 0 ? 0 : Math.max(0, (W.y0 - base.y) / dt);
459
- W.y0 = base.y;
460
- const margin = 0.018 * cfg.s + Math.min(0.12 * cfg.s, vDown * 0.2);
461
- const near = base.y - e.terrainH(base.x, base.z) < 0.2 * cfg.s + margin * 2;
462
- let needB = 0, needL = 0;
463
- if (near) {
464
- const pts = st.wLocal[k], nP = pts.length;
465
- for (let i = 0; i < nP; i++) _w[i].copy(pts[i]).applyMatrix4(bone.matrixWorld).sub(base);
466
- const clearAt = (phi) => {
467
- let worst = 0;
468
- _q2.setFromAxisAngle(_a, s * phi);
469
- for (let i = 0; i < nP; i++) {
470
- const q = _d.copy(_w[i]).applyQuaternion(_q2).add(base);
471
- worst = Math.min(worst, q.y - (e.terrainH(q.x, q.z) + margin));
472
- }
473
- return worst;
474
- };
475
- // the smallest sweep back that clears, interpolated between steps (continuous in the pose)
476
- let pw = clearAt(0);
477
- if (pw < 0) {
478
- needB = 1.7;
479
- for (let i = 1; i <= 8; i++) {
480
- const w = clearAt(i * 0.2125);
481
- if (w >= 0) { needB = (i - 1 + -pw / Math.max(1e-6, w - pw)) * 0.2125; break; }
482
- pw = w;
483
- }
484
- }
485
- const rest = clearAt(needB);
486
- if (rest < 0) needL = Math.asin(clamp(-rest / (0.08 * cfg.s), 0, 1)) * 1.2;
487
- }
488
- // lying, asleep or dead the fans lie back against the face (and fold out again as the lion gets up: the
489
- // head rolling upright swung the lower fan into the ground faster than the clearance could follow)
490
- needB = Math.max(needB, 1.3 * lying); needL = Math.max(needL, 0.45 * lying);
491
- // (rises at once, relaxes slowly: a collapsing head pauses and falls on, and a fan that swung back the
492
- // moment it looked clear dipped into the ground a few frames later)
493
- needB = Math.max(needB, W.back - 1.0 * dt); needL = Math.max(needL, W.lift - 1.0 * dt);
494
- // critically damped springs (fast, ~0.05 s), stepped exactly (stable at any frame rate): the fan never snaps
495
- [W.back, W.vb] = crit(W.back, W.vb, needB, 55, dt); W.back = Math.max(0, W.back);
496
- [W.lift, W.vl] = crit(W.lift, W.vl, needL, 55, dt); W.lift = Math.max(0, W.lift);
497
- if (W.back < 1e-4 && W.lift < 1e-4) continue;
498
- if (W.back > 1e-4) _q.premultiply(tqa(_a, s * W.back));
499
- if (W.lift > 1e-4) {
500
- const tip = _d.copy(st.wLocal[k][0]).applyMatrix4(bone.matrixWorld).sub(base).applyQuaternion(tqa(_a, s * W.back)).normalize();
501
- _ax.crossVectors(tip, THREE.Object3D.DEFAULT_UP);
502
- if (_ax.lengthSq() > 1e-8) _q.premultiply(tqa(_ax.normalize(), W.lift));
503
- }
504
- bone.matrixWorld.compose(base, _q, _s1);
505
- }
506
- }
507
-
508
- export const lionHooks = { actions: lionActions, update, pose };
509
- void mxLegs;