@bitefoundry/retrieviewer 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ASSET-PROVENANCE.md +43 -0
- package/ASSETS-LICENSE.md +58 -0
- package/ATTRIBUTION.md +54 -0
- package/EMBEDDING.md +96 -0
- package/INSTALLING.md +126 -0
- package/LICENSE +16 -0
- package/LICENSE-CODE +21 -0
- package/PLUGIN.md +110 -0
- package/PUPPY-MEMORY.md +57 -0
- package/PUPPY-Q5-COMPARISON.md +73 -0
- package/README.md +86 -2
- package/RELEASING.md +70 -0
- package/THIRD-PARTY-NOTICES.md +17 -0
- package/TRADEMARKS.md +21 -0
- package/WINDOWS-COMPANION.md +113 -0
- package/braille.mjs +45 -0
- package/examples/bridge.py +62 -0
- package/examples/embed.mjs +15 -0
- package/examples/live.mjs +40 -0
- package/examples/plugin.mjs +21 -0
- package/integrations/opencode/runtime.mjs +195 -0
- package/integrations/opencode/tui.tsx +59 -0
- package/integrations/windows-overlay/Overlay.cs +259 -0
- package/integrations/windows-overlay/desktop.mjs +87 -0
- package/integrations/windows-overlay/protocol.mjs +39 -0
- package/integrations/windows-overlay/worker.mjs +60 -0
- package/locomotion-core.mjs +21 -0
- package/locomotion-puppy.animal +0 -0
- package/package.json +131 -4
- package/pet-q5-manifest.json +118 -0
- package/puppy-clean.mjs +51 -0
- package/puppy-companion-interactions-v3-q5.bin.gz +0 -0
- package/puppy-companion-interactions-v3.json +1 -0
- package/puppy-companion-life.mjs +182 -0
- package/puppy-companion-objects.mjs +30 -0
- package/puppy-companion-sprites.mjs +14 -0
- package/puppy-continuous.mjs +57 -0
- package/puppy-face.mjs +46 -0
- package/puppy-frame-predictive.mjs +147 -0
- package/puppy-frame-store.mjs +108 -0
- package/puppy-mouth-anchor.json +1 -0
- package/puppy-mouth-anchor.mjs +33 -0
- package/puppy-paper-actions-v9-q5.bin.gz +0 -0
- package/puppy-paper-actions-v9.json +1 -0
- package/puppy-paper-actions.mjs +48 -0
- package/puppy-paper-approach-q5.bin.gz +0 -0
- package/puppy-paper-approach.json +1 -0
- package/puppy-paper-area.mjs +15 -0
- package/puppy-paper-arrival-seat-q5.bin.gz +0 -0
- package/puppy-paper-arrival-seat.json +1 -0
- package/puppy-paper-behaviors-q5.bin.gz +0 -0
- package/puppy-paper-behaviors.json +1 -0
- package/puppy-paper-behaviors.mjs +8 -0
- package/puppy-paper-contact.mjs +103 -0
- package/puppy-paper-director.mjs +21 -0
- package/puppy-paper-paw-transport.mjs +76 -0
- package/puppy-paper-rear-gallop-q5.bin.gz +0 -0
- package/puppy-paper-rear-gallop.json +1 -0
- package/puppy-paper-seat-q5.bin.gz +0 -0
- package/puppy-paper-seat.json +14 -0
- package/puppy-paper-seat.mjs +13 -0
- package/puppy-paper-trick-timing.mjs +58 -0
- package/puppy-paper-world.mjs +108 -0
- package/puppy-paper.mjs +271 -0
- package/puppy-stable-meta.json +1606 -0
- package/puppy-stable.mjs +72 -0
- package/puppy-stride-meta.json +343 -0
- package/puppy-stride-tweens-q5.bin.gz +0 -0
- package/puppy-zoomies.mjs +27 -0
- package/puppy-zoomies30.mjs +12 -0
- package/retrieviewer-cli.mjs +94 -0
- package/retrieviewer-config.mjs +49 -0
- package/retrieviewer-install.mjs +157 -0
- package/retrieviewer-plugin.d.mts +44 -0
- package/retrieviewer-plugin.mjs +97 -0
- package/retrieviewer-stdio.mjs +38 -0
- package/retrieviewer.d.mts +85 -0
- package/retrieviewer.mjs +142 -0
- package/vendor/procedural-animals/LICENSE +21 -0
- package/vendor/procedural-animals/package.json +40 -0
- package/vendor/procedural-animals/src/animal.js +146 -0
- package/vendor/procedural-animals/src/bake.js +51 -0
- package/vendor/procedural-animals/src/build.js +81 -0
- package/vendor/procedural-animals/src/core/build/coatKit.js +121 -0
- package/vendor/procedural-animals/src/core/build/featherCards.js +189 -0
- package/vendor/procedural-animals/src/core/build/finEdges.js +85 -0
- package/vendor/procedural-animals/src/core/build/furSlope.js +115 -0
- package/vendor/procedural-animals/src/core/build/mesh.js +67 -0
- package/vendor/procedural-animals/src/core/build/pipeline.js +272 -0
- package/vendor/procedural-animals/src/core/build/seams.js +183 -0
- package/vendor/procedural-animals/src/core/build/warp.js +112 -0
- package/vendor/procedural-animals/src/core/build/weights.js +393 -0
- package/vendor/procedural-animals/src/core/math/vec.js +81 -0
- package/vendor/procedural-animals/src/core/motion/actions.js +800 -0
- package/vendor/procedural-animals/src/core/motion/bird.js +3063 -0
- package/vendor/procedural-animals/src/core/motion/birdActions.js +1059 -0
- package/vendor/procedural-animals/src/core/motion/common.js +158 -0
- package/vendor/procedural-animals/src/core/motion/index.js +22 -0
- package/vendor/procedural-animals/src/core/motion/quadruped.js +2875 -0
- package/vendor/procedural-animals/src/core/motion/snake.js +1594 -0
- package/vendor/procedural-animals/src/core/motion/spider.js +1810 -0
- package/vendor/procedural-animals/src/core/motion/swimmer.js +1047 -0
- package/vendor/procedural-animals/src/core/motion/swimmerActions.js +613 -0
- package/vendor/procedural-animals/src/core/render/animalObject.js +262 -0
- package/vendor/procedural-animals/src/core/render/coatMaterial.js +1301 -0
- package/vendor/procedural-animals/src/core/render/dqs.js +159 -0
- package/vendor/procedural-animals/src/core/render/eyes.js +676 -0
- package/vendor/procedural-animals/src/core/render/membranes.js +77 -0
- package/vendor/procedural-animals/src/core/render/skeleton.js +41 -0
- package/vendor/procedural-animals/src/core/rig/bird.js +327 -0
- package/vendor/procedural-animals/src/core/rig/quadruped.js +76 -0
- package/vendor/procedural-animals/src/core/rig/rig.js +79 -0
- package/vendor/procedural-animals/src/core/rig/snake.js +76 -0
- package/vendor/procedural-animals/src/core/rig/spider.js +110 -0
- package/vendor/procedural-animals/src/core/rig/swimmer.js +181 -0
- package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +53 -0
- package/vendor/procedural-animals/src/core/sdf/mesher.js +238 -0
- package/vendor/procedural-animals/src/core/sdf/sdf.js +263 -0
- package/vendor/procedural-animals/src/index.d.ts +98 -0
- package/vendor/procedural-animals/src/index.js +29 -0
- package/vendor/procedural-animals/src/registry.js +48 -0
- package/vendor/procedural-animals/src/species/bear/behaviour.js +463 -0
- package/vendor/procedural-animals/src/species/bear/claws.js +147 -0
- package/vendor/procedural-animals/src/species/bear/coat.js +726 -0
- package/vendor/procedural-animals/src/species/bear/index.js +139 -0
- package/vendor/procedural-animals/src/species/bear/motion.js +112 -0
- package/vendor/procedural-animals/src/species/bear/regions.js +78 -0
- package/vendor/procedural-animals/src/species/bear/rig.js +112 -0
- package/vendor/procedural-animals/src/species/bear/sculpt.js +272 -0
- package/vendor/procedural-animals/src/species/boar/behaviour.js +335 -0
- package/vendor/procedural-animals/src/species/boar/coat.js +372 -0
- package/vendor/procedural-animals/src/species/boar/index.js +110 -0
- package/vendor/procedural-animals/src/species/boar/motion.js +85 -0
- package/vendor/procedural-animals/src/species/boar/regions.js +88 -0
- package/vendor/procedural-animals/src/species/boar/rig.js +111 -0
- package/vendor/procedural-animals/src/species/boar/sculpt.js +285 -0
- package/vendor/procedural-animals/src/species/cat/behaviour.js +559 -0
- package/vendor/procedural-animals/src/species/cat/coat.js +841 -0
- package/vendor/procedural-animals/src/species/cat/index.js +211 -0
- package/vendor/procedural-animals/src/species/cat/motion.js +101 -0
- package/vendor/procedural-animals/src/species/cat/regions.js +82 -0
- package/vendor/procedural-animals/src/species/cat/rig.js +100 -0
- package/vendor/procedural-animals/src/species/cat/sculpt.js +266 -0
- package/vendor/procedural-animals/src/species/cat/whiskers.js +110 -0
- package/vendor/procedural-animals/src/species/cheetah/coat.js +427 -0
- package/vendor/procedural-animals/src/species/cheetah/index.js +51 -0
- package/vendor/procedural-animals/src/species/cheetah/joints.js +3 -0
- package/vendor/procedural-animals/src/species/cheetah/motion.js +77 -0
- package/vendor/procedural-animals/src/species/cheetah/regions.js +95 -0
- package/vendor/procedural-animals/src/species/cheetah/rig.js +66 -0
- package/vendor/procedural-animals/src/species/cheetah/sculpt.js +158 -0
- package/vendor/procedural-animals/src/species/chicken/coat.js +313 -0
- package/vendor/procedural-animals/src/species/chicken/coverts.js +320 -0
- package/vendor/procedural-animals/src/species/chicken/index.js +110 -0
- package/vendor/procedural-animals/src/species/chicken/motion.js +177 -0
- package/vendor/procedural-animals/src/species/chicken/regions.js +66 -0
- package/vendor/procedural-animals/src/species/chicken/rig.js +144 -0
- package/vendor/procedural-animals/src/species/chicken/sculpt.js +389 -0
- package/vendor/procedural-animals/src/species/chicken/wingLook.js +66 -0
- package/vendor/procedural-animals/src/species/chicken/wingStack.js +124 -0
- package/vendor/procedural-animals/src/species/cow/behaviour.js +521 -0
- package/vendor/procedural-animals/src/species/cow/coat.js +465 -0
- package/vendor/procedural-animals/src/species/cow/index.js +118 -0
- package/vendor/procedural-animals/src/species/cow/motion.js +81 -0
- package/vendor/procedural-animals/src/species/cow/regions.js +98 -0
- package/vendor/procedural-animals/src/species/cow/rig.js +116 -0
- package/vendor/procedural-animals/src/species/cow/sculpt.js +339 -0
- package/vendor/procedural-animals/src/species/crow/coat.js +145 -0
- package/vendor/procedural-animals/src/species/crow/index.js +70 -0
- package/vendor/procedural-animals/src/species/crow/joints.js +3 -0
- package/vendor/procedural-animals/src/species/crow/motion.js +101 -0
- package/vendor/procedural-animals/src/species/crow/regions.js +50 -0
- package/vendor/procedural-animals/src/species/crow/rig.js +83 -0
- package/vendor/procedural-animals/src/species/crow/sculpt.js +118 -0
- package/vendor/procedural-animals/src/species/deer/behaviour.js +513 -0
- package/vendor/procedural-animals/src/species/deer/coat.js +391 -0
- package/vendor/procedural-animals/src/species/deer/index.js +106 -0
- package/vendor/procedural-animals/src/species/deer/motion.js +97 -0
- package/vendor/procedural-animals/src/species/deer/regions.js +60 -0
- package/vendor/procedural-animals/src/species/deer/rig.js +124 -0
- package/vendor/procedural-animals/src/species/deer/sculpt.js +297 -0
- package/vendor/procedural-animals/src/species/dog/behaviour.js +521 -0
- package/vendor/procedural-animals/src/species/dog/coat.js +495 -0
- package/vendor/procedural-animals/src/species/dog/index.js +144 -0
- package/vendor/procedural-animals/src/species/dog/motion.js +118 -0
- package/vendor/procedural-animals/src/species/dog/regions.js +61 -0
- package/vendor/procedural-animals/src/species/dog/rig.js +129 -0
- package/vendor/procedural-animals/src/species/dog/sculpt.js +246 -0
- package/vendor/procedural-animals/src/species/eagle/coat.js +250 -0
- package/vendor/procedural-animals/src/species/eagle/index.js +76 -0
- package/vendor/procedural-animals/src/species/eagle/joints.js +3 -0
- package/vendor/procedural-animals/src/species/eagle/motion.js +137 -0
- package/vendor/procedural-animals/src/species/eagle/regions.js +57 -0
- package/vendor/procedural-animals/src/species/eagle/rig.js +107 -0
- package/vendor/procedural-animals/src/species/eagle/sculpt.js +137 -0
- package/vendor/procedural-animals/src/species/fish/coat.js +271 -0
- package/vendor/procedural-animals/src/species/fish/index.js +88 -0
- package/vendor/procedural-animals/src/species/fish/motion.js +92 -0
- package/vendor/procedural-animals/src/species/fish/regions.js +27 -0
- package/vendor/procedural-animals/src/species/fish/rig.js +143 -0
- package/vendor/procedural-animals/src/species/fish/sculpt.js +214 -0
- package/vendor/procedural-animals/src/species/fish/variants.js +126 -0
- package/vendor/procedural-animals/src/species/fox/behaviour.js +314 -0
- package/vendor/procedural-animals/src/species/fox/coat.js +444 -0
- package/vendor/procedural-animals/src/species/fox/index.js +120 -0
- package/vendor/procedural-animals/src/species/fox/motion.js +81 -0
- package/vendor/procedural-animals/src/species/fox/regions.js +59 -0
- package/vendor/procedural-animals/src/species/fox/rig.js +91 -0
- package/vendor/procedural-animals/src/species/fox/sculpt.js +202 -0
- package/vendor/procedural-animals/src/species/frog/behaviour.js +590 -0
- package/vendor/procedural-animals/src/species/frog/coat.js +305 -0
- package/vendor/procedural-animals/src/species/frog/index.js +97 -0
- package/vendor/procedural-animals/src/species/frog/motion.js +69 -0
- package/vendor/procedural-animals/src/species/frog/regions.js +46 -0
- package/vendor/procedural-animals/src/species/frog/rig.js +156 -0
- package/vendor/procedural-animals/src/species/frog/sculpt.js +240 -0
- package/vendor/procedural-animals/src/species/goat/behaviour.js +509 -0
- package/vendor/procedural-animals/src/species/goat/coat.js +590 -0
- package/vendor/procedural-animals/src/species/goat/index.js +149 -0
- package/vendor/procedural-animals/src/species/goat/motion.js +95 -0
- package/vendor/procedural-animals/src/species/goat/regions.js +98 -0
- package/vendor/procedural-animals/src/species/goat/rig.js +181 -0
- package/vendor/procedural-animals/src/species/goat/sculpt.js +547 -0
- package/vendor/procedural-animals/src/species/horse/coat.js +361 -0
- package/vendor/procedural-animals/src/species/horse/coatSeam.js +122 -0
- package/vendor/procedural-animals/src/species/horse/index.js +80 -0
- package/vendor/procedural-animals/src/species/horse/motion.js +245 -0
- package/vendor/procedural-animals/src/species/horse/regions.js +60 -0
- package/vendor/procedural-animals/src/species/horse/rig.js +117 -0
- package/vendor/procedural-animals/src/species/horse/sculpt.js +316 -0
- package/vendor/procedural-animals/src/species/horse/seamWeights.js +272 -0
- package/vendor/procedural-animals/src/species/lion/behaviour.js +509 -0
- package/vendor/procedural-animals/src/species/lion/coat.js +1016 -0
- package/vendor/procedural-animals/src/species/lion/index.js +111 -0
- package/vendor/procedural-animals/src/species/lion/motion.js +87 -0
- package/vendor/procedural-animals/src/species/lion/regions.js +106 -0
- package/vendor/procedural-animals/src/species/lion/rig.js +110 -0
- package/vendor/procedural-animals/src/species/lion/sculpt.js +384 -0
- package/vendor/procedural-animals/src/species/lion/whiskers.js +132 -0
- package/vendor/procedural-animals/src/species/pig/behaviour.js +575 -0
- package/vendor/procedural-animals/src/species/pig/coat.js +730 -0
- package/vendor/procedural-animals/src/species/pig/ears.js +242 -0
- package/vendor/procedural-animals/src/species/pig/index.js +161 -0
- package/vendor/procedural-animals/src/species/pig/motion.js +105 -0
- package/vendor/procedural-animals/src/species/pig/regions.js +100 -0
- package/vendor/procedural-animals/src/species/pig/rig.js +152 -0
- package/vendor/procedural-animals/src/species/pig/sculpt.js +382 -0
- package/vendor/procedural-animals/src/species/rabbit/behaviour.js +605 -0
- package/vendor/procedural-animals/src/species/rabbit/coat.js +285 -0
- package/vendor/procedural-animals/src/species/rabbit/index.js +85 -0
- package/vendor/procedural-animals/src/species/rabbit/motion.js +85 -0
- package/vendor/procedural-animals/src/species/rabbit/regions.js +48 -0
- package/vendor/procedural-animals/src/species/rabbit/rig.js +99 -0
- package/vendor/procedural-animals/src/species/rabbit/sculpt.js +148 -0
- package/vendor/procedural-animals/src/species/rat/behaviour.js +539 -0
- package/vendor/procedural-animals/src/species/rat/coat.js +341 -0
- package/vendor/procedural-animals/src/species/rat/index.js +111 -0
- package/vendor/procedural-animals/src/species/rat/motion.js +90 -0
- package/vendor/procedural-animals/src/species/rat/regions.js +92 -0
- package/vendor/procedural-animals/src/species/rat/rig.js +112 -0
- package/vendor/procedural-animals/src/species/rat/sculpt.js +163 -0
- package/vendor/procedural-animals/src/species/rat/whiskers.js +119 -0
- package/vendor/procedural-animals/src/species/shark/coat.js +383 -0
- package/vendor/procedural-animals/src/species/shark/index.js +104 -0
- package/vendor/procedural-animals/src/species/shark/motion.js +69 -0
- package/vendor/procedural-animals/src/species/shark/regions.js +34 -0
- package/vendor/procedural-animals/src/species/shark/rig.js +194 -0
- package/vendor/procedural-animals/src/species/shark/sculpt.js +343 -0
- package/vendor/procedural-animals/src/species/shark/variants.js +105 -0
- package/vendor/procedural-animals/src/species/sheep/behaviour.js +522 -0
- package/vendor/procedural-animals/src/species/sheep/coat.js +529 -0
- package/vendor/procedural-animals/src/species/sheep/index.js +152 -0
- package/vendor/procedural-animals/src/species/sheep/motion.js +86 -0
- package/vendor/procedural-animals/src/species/sheep/neck.js +41 -0
- package/vendor/procedural-animals/src/species/sheep/regions.js +62 -0
- package/vendor/procedural-animals/src/species/sheep/rig.js +163 -0
- package/vendor/procedural-animals/src/species/sheep/sculpt.js +542 -0
- package/vendor/procedural-animals/src/species/snake/coat.js +315 -0
- package/vendor/procedural-animals/src/species/snake/index.js +73 -0
- package/vendor/procedural-animals/src/species/snake/motion.js +51 -0
- package/vendor/procedural-animals/src/species/snake/regions.js +51 -0
- package/vendor/procedural-animals/src/species/snake/rig.js +108 -0
- package/vendor/procedural-animals/src/species/snake/sculpt.js +122 -0
- package/vendor/procedural-animals/src/species/spider/coat.js +279 -0
- package/vendor/procedural-animals/src/species/spider/index.js +78 -0
- package/vendor/procedural-animals/src/species/spider/motion.js +72 -0
- package/vendor/procedural-animals/src/species/spider/regions.js +87 -0
- package/vendor/procedural-animals/src/species/spider/rig.js +118 -0
- package/vendor/procedural-animals/src/species/spider/sculpt.js +182 -0
- package/vendor/procedural-animals/src/species/wolf/behaviour.js +160 -0
- package/vendor/procedural-animals/src/species/wolf/coat.js +749 -0
- package/vendor/procedural-animals/src/species/wolf/index.js +107 -0
- package/vendor/procedural-animals/src/species/wolf/motion.js +80 -0
- package/vendor/procedural-animals/src/species/wolf/regions.js +57 -0
- package/vendor/procedural-animals/src/species/wolf/rig.js +87 -0
- package/vendor/procedural-animals/src/species/wolf/sculpt.js +339 -0
- package/vendor/procedural-animals/src/worker.js +29 -0
|
@@ -0,0 +1,509 @@
|
|
|
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;
|