@bitefoundry/retrieviewer 0.0.3 → 0.0.5
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 +11 -0
- package/ASSETS-LICENSE.md +2 -1
- package/ATTRIBUTION.md +6 -1
- package/COMFORT-ART.md +95 -0
- package/DESKTOP-PLATFORMS.md +6 -1
- package/INSTALLING.md +4 -0
- package/PLUGIN.md +13 -10
- package/PREREQUISITES.md +95 -0
- package/PUPPY-MEMORY.md +102 -1
- package/README.ko.md +116 -0
- package/README.md +121 -59
- package/RELEASING.md +33 -13
- package/THIRD-PARTY-NOTICES.md +5 -3
- package/braille.mjs +35 -9
- package/examples/live.mjs +2 -2
- package/integrations/linux-overlay/overlay.py +8 -2
- package/integrations/macos-overlay/overlay.jxa +9 -7
- package/integrations/opencode/runtime.mjs +4 -4
- package/integrations/opencode/tui.tsx +1 -1
- package/integrations/windows-overlay/Overlay.cs +7 -6
- package/integrations/windows-overlay/desktop.mjs +2 -1
- package/integrations/windows-overlay/protocol.mjs +13 -7
- package/integrations/windows-overlay/worker.mjs +1 -1
- package/package.json +34 -13
- package/puppy-comfort-sprites.mjs +33 -0
- package/puppy-companion-comfort-q5.bin.gz +0 -0
- package/puppy-companion-comfort.json +140 -0
- package/puppy-companion-life.mjs +58 -18
- package/puppy-companion-objects.mjs +12 -0
- package/puppy-companion-sprites.mjs +4 -2
- package/puppy-frame-predictive.mjs +15 -9
- package/puppy-frame-store.mjs +2 -2
- package/puppy-paper-actions.mjs +4 -2
- package/puppy-paper-behaviors.mjs +1 -1
- package/puppy-paper-contact.mjs +4 -2
- package/puppy-paper-seat.mjs +4 -2
- package/puppy-paper-world.mjs +14 -0
- package/puppy-paper.mjs +79 -21
- package/retrieviewer-cli.mjs +8 -6
- package/retrieviewer-plugin.d.mts +1 -1
- package/retrieviewer-plugin.mjs +1 -1
- package/retrieviewer.d.mts +12 -4
- package/retrieviewer.mjs +20 -14
- package/locomotion-core.mjs +0 -21
- package/locomotion-puppy.animal +0 -0
- package/vendor/procedural-animals/package.json +0 -40
- package/vendor/procedural-animals/src/animal.js +0 -146
- package/vendor/procedural-animals/src/bake.js +0 -51
- package/vendor/procedural-animals/src/build.js +0 -81
- package/vendor/procedural-animals/src/core/build/coatKit.js +0 -121
- package/vendor/procedural-animals/src/core/build/featherCards.js +0 -189
- package/vendor/procedural-animals/src/core/build/finEdges.js +0 -85
- package/vendor/procedural-animals/src/core/build/furSlope.js +0 -115
- package/vendor/procedural-animals/src/core/build/mesh.js +0 -67
- package/vendor/procedural-animals/src/core/build/pipeline.js +0 -272
- package/vendor/procedural-animals/src/core/build/seams.js +0 -183
- package/vendor/procedural-animals/src/core/build/warp.js +0 -112
- package/vendor/procedural-animals/src/core/build/weights.js +0 -393
- package/vendor/procedural-animals/src/core/math/vec.js +0 -81
- package/vendor/procedural-animals/src/core/motion/actions.js +0 -800
- package/vendor/procedural-animals/src/core/motion/bird.js +0 -3063
- package/vendor/procedural-animals/src/core/motion/birdActions.js +0 -1059
- package/vendor/procedural-animals/src/core/motion/common.js +0 -158
- package/vendor/procedural-animals/src/core/motion/index.js +0 -22
- package/vendor/procedural-animals/src/core/motion/quadruped.js +0 -2875
- package/vendor/procedural-animals/src/core/motion/snake.js +0 -1594
- package/vendor/procedural-animals/src/core/motion/spider.js +0 -1810
- package/vendor/procedural-animals/src/core/motion/swimmer.js +0 -1047
- package/vendor/procedural-animals/src/core/motion/swimmerActions.js +0 -613
- package/vendor/procedural-animals/src/core/render/animalObject.js +0 -262
- package/vendor/procedural-animals/src/core/render/coatMaterial.js +0 -1301
- package/vendor/procedural-animals/src/core/render/dqs.js +0 -159
- package/vendor/procedural-animals/src/core/render/eyes.js +0 -676
- package/vendor/procedural-animals/src/core/render/membranes.js +0 -77
- package/vendor/procedural-animals/src/core/render/skeleton.js +0 -41
- package/vendor/procedural-animals/src/core/rig/bird.js +0 -327
- package/vendor/procedural-animals/src/core/rig/quadruped.js +0 -76
- package/vendor/procedural-animals/src/core/rig/rig.js +0 -79
- package/vendor/procedural-animals/src/core/rig/snake.js +0 -76
- package/vendor/procedural-animals/src/core/rig/spider.js +0 -110
- package/vendor/procedural-animals/src/core/rig/swimmer.js +0 -181
- package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +0 -53
- package/vendor/procedural-animals/src/core/sdf/mesher.js +0 -238
- package/vendor/procedural-animals/src/core/sdf/sdf.js +0 -263
- package/vendor/procedural-animals/src/index.d.ts +0 -98
- package/vendor/procedural-animals/src/index.js +0 -29
- package/vendor/procedural-animals/src/registry.js +0 -48
- package/vendor/procedural-animals/src/species/bear/behaviour.js +0 -463
- package/vendor/procedural-animals/src/species/bear/claws.js +0 -147
- package/vendor/procedural-animals/src/species/bear/coat.js +0 -726
- package/vendor/procedural-animals/src/species/bear/index.js +0 -139
- package/vendor/procedural-animals/src/species/bear/motion.js +0 -112
- package/vendor/procedural-animals/src/species/bear/regions.js +0 -78
- package/vendor/procedural-animals/src/species/bear/rig.js +0 -112
- package/vendor/procedural-animals/src/species/bear/sculpt.js +0 -272
- package/vendor/procedural-animals/src/species/boar/behaviour.js +0 -335
- package/vendor/procedural-animals/src/species/boar/coat.js +0 -372
- package/vendor/procedural-animals/src/species/boar/index.js +0 -110
- package/vendor/procedural-animals/src/species/boar/motion.js +0 -85
- package/vendor/procedural-animals/src/species/boar/regions.js +0 -88
- package/vendor/procedural-animals/src/species/boar/rig.js +0 -111
- package/vendor/procedural-animals/src/species/boar/sculpt.js +0 -285
- package/vendor/procedural-animals/src/species/cat/behaviour.js +0 -559
- package/vendor/procedural-animals/src/species/cat/coat.js +0 -841
- package/vendor/procedural-animals/src/species/cat/index.js +0 -211
- package/vendor/procedural-animals/src/species/cat/motion.js +0 -101
- package/vendor/procedural-animals/src/species/cat/regions.js +0 -82
- package/vendor/procedural-animals/src/species/cat/rig.js +0 -100
- package/vendor/procedural-animals/src/species/cat/sculpt.js +0 -266
- package/vendor/procedural-animals/src/species/cat/whiskers.js +0 -110
- package/vendor/procedural-animals/src/species/cheetah/coat.js +0 -427
- package/vendor/procedural-animals/src/species/cheetah/index.js +0 -51
- package/vendor/procedural-animals/src/species/cheetah/joints.js +0 -3
- package/vendor/procedural-animals/src/species/cheetah/motion.js +0 -77
- package/vendor/procedural-animals/src/species/cheetah/regions.js +0 -95
- package/vendor/procedural-animals/src/species/cheetah/rig.js +0 -66
- package/vendor/procedural-animals/src/species/cheetah/sculpt.js +0 -158
- package/vendor/procedural-animals/src/species/chicken/coat.js +0 -313
- package/vendor/procedural-animals/src/species/chicken/coverts.js +0 -320
- package/vendor/procedural-animals/src/species/chicken/index.js +0 -110
- package/vendor/procedural-animals/src/species/chicken/motion.js +0 -177
- package/vendor/procedural-animals/src/species/chicken/regions.js +0 -66
- package/vendor/procedural-animals/src/species/chicken/rig.js +0 -144
- package/vendor/procedural-animals/src/species/chicken/sculpt.js +0 -389
- package/vendor/procedural-animals/src/species/chicken/wingLook.js +0 -66
- package/vendor/procedural-animals/src/species/chicken/wingStack.js +0 -124
- package/vendor/procedural-animals/src/species/cow/behaviour.js +0 -521
- package/vendor/procedural-animals/src/species/cow/coat.js +0 -465
- package/vendor/procedural-animals/src/species/cow/index.js +0 -118
- package/vendor/procedural-animals/src/species/cow/motion.js +0 -81
- package/vendor/procedural-animals/src/species/cow/regions.js +0 -98
- package/vendor/procedural-animals/src/species/cow/rig.js +0 -116
- package/vendor/procedural-animals/src/species/cow/sculpt.js +0 -339
- package/vendor/procedural-animals/src/species/crow/coat.js +0 -145
- package/vendor/procedural-animals/src/species/crow/index.js +0 -70
- package/vendor/procedural-animals/src/species/crow/joints.js +0 -3
- package/vendor/procedural-animals/src/species/crow/motion.js +0 -101
- package/vendor/procedural-animals/src/species/crow/regions.js +0 -50
- package/vendor/procedural-animals/src/species/crow/rig.js +0 -83
- package/vendor/procedural-animals/src/species/crow/sculpt.js +0 -118
- package/vendor/procedural-animals/src/species/deer/behaviour.js +0 -513
- package/vendor/procedural-animals/src/species/deer/coat.js +0 -391
- package/vendor/procedural-animals/src/species/deer/index.js +0 -106
- package/vendor/procedural-animals/src/species/deer/motion.js +0 -97
- package/vendor/procedural-animals/src/species/deer/regions.js +0 -60
- package/vendor/procedural-animals/src/species/deer/rig.js +0 -124
- package/vendor/procedural-animals/src/species/deer/sculpt.js +0 -297
- package/vendor/procedural-animals/src/species/dog/behaviour.js +0 -521
- package/vendor/procedural-animals/src/species/dog/coat.js +0 -495
- package/vendor/procedural-animals/src/species/dog/index.js +0 -144
- package/vendor/procedural-animals/src/species/dog/motion.js +0 -118
- package/vendor/procedural-animals/src/species/dog/regions.js +0 -61
- package/vendor/procedural-animals/src/species/dog/rig.js +0 -129
- package/vendor/procedural-animals/src/species/dog/sculpt.js +0 -246
- package/vendor/procedural-animals/src/species/eagle/coat.js +0 -250
- package/vendor/procedural-animals/src/species/eagle/index.js +0 -76
- package/vendor/procedural-animals/src/species/eagle/joints.js +0 -3
- package/vendor/procedural-animals/src/species/eagle/motion.js +0 -137
- package/vendor/procedural-animals/src/species/eagle/regions.js +0 -57
- package/vendor/procedural-animals/src/species/eagle/rig.js +0 -107
- package/vendor/procedural-animals/src/species/eagle/sculpt.js +0 -137
- package/vendor/procedural-animals/src/species/fish/coat.js +0 -271
- package/vendor/procedural-animals/src/species/fish/index.js +0 -88
- package/vendor/procedural-animals/src/species/fish/motion.js +0 -92
- package/vendor/procedural-animals/src/species/fish/regions.js +0 -27
- package/vendor/procedural-animals/src/species/fish/rig.js +0 -143
- package/vendor/procedural-animals/src/species/fish/sculpt.js +0 -214
- package/vendor/procedural-animals/src/species/fish/variants.js +0 -126
- package/vendor/procedural-animals/src/species/fox/behaviour.js +0 -314
- package/vendor/procedural-animals/src/species/fox/coat.js +0 -444
- package/vendor/procedural-animals/src/species/fox/index.js +0 -120
- package/vendor/procedural-animals/src/species/fox/motion.js +0 -81
- package/vendor/procedural-animals/src/species/fox/regions.js +0 -59
- package/vendor/procedural-animals/src/species/fox/rig.js +0 -91
- package/vendor/procedural-animals/src/species/fox/sculpt.js +0 -202
- package/vendor/procedural-animals/src/species/frog/behaviour.js +0 -590
- package/vendor/procedural-animals/src/species/frog/coat.js +0 -305
- package/vendor/procedural-animals/src/species/frog/index.js +0 -97
- package/vendor/procedural-animals/src/species/frog/motion.js +0 -69
- package/vendor/procedural-animals/src/species/frog/regions.js +0 -46
- package/vendor/procedural-animals/src/species/frog/rig.js +0 -156
- package/vendor/procedural-animals/src/species/frog/sculpt.js +0 -240
- package/vendor/procedural-animals/src/species/goat/behaviour.js +0 -509
- package/vendor/procedural-animals/src/species/goat/coat.js +0 -590
- package/vendor/procedural-animals/src/species/goat/index.js +0 -149
- package/vendor/procedural-animals/src/species/goat/motion.js +0 -95
- package/vendor/procedural-animals/src/species/goat/regions.js +0 -98
- package/vendor/procedural-animals/src/species/goat/rig.js +0 -181
- package/vendor/procedural-animals/src/species/goat/sculpt.js +0 -547
- package/vendor/procedural-animals/src/species/horse/coat.js +0 -361
- package/vendor/procedural-animals/src/species/horse/coatSeam.js +0 -122
- package/vendor/procedural-animals/src/species/horse/index.js +0 -80
- package/vendor/procedural-animals/src/species/horse/motion.js +0 -245
- package/vendor/procedural-animals/src/species/horse/regions.js +0 -60
- package/vendor/procedural-animals/src/species/horse/rig.js +0 -117
- package/vendor/procedural-animals/src/species/horse/sculpt.js +0 -316
- package/vendor/procedural-animals/src/species/horse/seamWeights.js +0 -272
- package/vendor/procedural-animals/src/species/lion/behaviour.js +0 -509
- package/vendor/procedural-animals/src/species/lion/coat.js +0 -1016
- package/vendor/procedural-animals/src/species/lion/index.js +0 -111
- package/vendor/procedural-animals/src/species/lion/motion.js +0 -87
- package/vendor/procedural-animals/src/species/lion/regions.js +0 -106
- package/vendor/procedural-animals/src/species/lion/rig.js +0 -110
- package/vendor/procedural-animals/src/species/lion/sculpt.js +0 -384
- package/vendor/procedural-animals/src/species/lion/whiskers.js +0 -132
- package/vendor/procedural-animals/src/species/pig/behaviour.js +0 -575
- package/vendor/procedural-animals/src/species/pig/coat.js +0 -730
- package/vendor/procedural-animals/src/species/pig/ears.js +0 -242
- package/vendor/procedural-animals/src/species/pig/index.js +0 -161
- package/vendor/procedural-animals/src/species/pig/motion.js +0 -105
- package/vendor/procedural-animals/src/species/pig/regions.js +0 -100
- package/vendor/procedural-animals/src/species/pig/rig.js +0 -152
- package/vendor/procedural-animals/src/species/pig/sculpt.js +0 -382
- package/vendor/procedural-animals/src/species/rabbit/behaviour.js +0 -605
- package/vendor/procedural-animals/src/species/rabbit/coat.js +0 -285
- package/vendor/procedural-animals/src/species/rabbit/index.js +0 -85
- package/vendor/procedural-animals/src/species/rabbit/motion.js +0 -85
- package/vendor/procedural-animals/src/species/rabbit/regions.js +0 -48
- package/vendor/procedural-animals/src/species/rabbit/rig.js +0 -99
- package/vendor/procedural-animals/src/species/rabbit/sculpt.js +0 -148
- package/vendor/procedural-animals/src/species/rat/behaviour.js +0 -539
- package/vendor/procedural-animals/src/species/rat/coat.js +0 -341
- package/vendor/procedural-animals/src/species/rat/index.js +0 -111
- package/vendor/procedural-animals/src/species/rat/motion.js +0 -90
- package/vendor/procedural-animals/src/species/rat/regions.js +0 -92
- package/vendor/procedural-animals/src/species/rat/rig.js +0 -112
- package/vendor/procedural-animals/src/species/rat/sculpt.js +0 -163
- package/vendor/procedural-animals/src/species/rat/whiskers.js +0 -119
- package/vendor/procedural-animals/src/species/shark/coat.js +0 -383
- package/vendor/procedural-animals/src/species/shark/index.js +0 -104
- package/vendor/procedural-animals/src/species/shark/motion.js +0 -69
- package/vendor/procedural-animals/src/species/shark/regions.js +0 -34
- package/vendor/procedural-animals/src/species/shark/rig.js +0 -194
- package/vendor/procedural-animals/src/species/shark/sculpt.js +0 -343
- package/vendor/procedural-animals/src/species/shark/variants.js +0 -105
- package/vendor/procedural-animals/src/species/sheep/behaviour.js +0 -522
- package/vendor/procedural-animals/src/species/sheep/coat.js +0 -529
- package/vendor/procedural-animals/src/species/sheep/index.js +0 -152
- package/vendor/procedural-animals/src/species/sheep/motion.js +0 -86
- package/vendor/procedural-animals/src/species/sheep/neck.js +0 -41
- package/vendor/procedural-animals/src/species/sheep/regions.js +0 -62
- package/vendor/procedural-animals/src/species/sheep/rig.js +0 -163
- package/vendor/procedural-animals/src/species/sheep/sculpt.js +0 -542
- package/vendor/procedural-animals/src/species/snake/coat.js +0 -315
- package/vendor/procedural-animals/src/species/snake/index.js +0 -73
- package/vendor/procedural-animals/src/species/snake/motion.js +0 -51
- package/vendor/procedural-animals/src/species/snake/regions.js +0 -51
- package/vendor/procedural-animals/src/species/snake/rig.js +0 -108
- package/vendor/procedural-animals/src/species/snake/sculpt.js +0 -122
- package/vendor/procedural-animals/src/species/spider/coat.js +0 -279
- package/vendor/procedural-animals/src/species/spider/index.js +0 -78
- package/vendor/procedural-animals/src/species/spider/motion.js +0 -72
- package/vendor/procedural-animals/src/species/spider/regions.js +0 -87
- package/vendor/procedural-animals/src/species/spider/rig.js +0 -118
- package/vendor/procedural-animals/src/species/spider/sculpt.js +0 -182
- package/vendor/procedural-animals/src/species/wolf/behaviour.js +0 -160
- package/vendor/procedural-animals/src/species/wolf/coat.js +0 -749
- package/vendor/procedural-animals/src/species/wolf/index.js +0 -107
- package/vendor/procedural-animals/src/species/wolf/motion.js +0 -80
- package/vendor/procedural-animals/src/species/wolf/regions.js +0 -57
- package/vendor/procedural-animals/src/species/wolf/rig.js +0 -87
- package/vendor/procedural-animals/src/species/wolf/sculpt.js +0 -339
- package/vendor/procedural-animals/src/worker.js +0 -29
|
@@ -1,590 +0,0 @@
|
|
|
1
|
-
// Frog behaviour layer for the quadruped engine (species.motion.hooks, see core/motion/actions.js):
|
|
2
|
-
//
|
|
3
|
-
// pose(engine, dt) after the engine's solve: the eyes retract into the head (blinks,
|
|
4
|
-
// swallowing, leaps), the throat pumps (buccal breathing) and balloons into
|
|
5
|
-
// the vocal sac (croak), the tongue flips out of the mouth (feeding strike)
|
|
6
|
-
// update(P, dt, layer) every frame over the action layer: automatic blinks, throat pumping rate,
|
|
7
|
-
// the head held still on the trunk (no neck), croaking bouts as an idle
|
|
8
|
-
// variant (males), long motionless sits
|
|
9
|
-
// actions hop (a single short hop), jump (the long jump: take-off extension, legs
|
|
10
|
-
// trailing fully extended in flight, forelimbs land first, then the body,
|
|
11
|
-
// then the hind legs fold forward into the sit), croak, blink, attack and eat
|
|
12
|
-
// (the tongue strike), sit (alert upright sit), lie (flattened crouch), sleep,
|
|
13
|
-
// drink (sits with its belly pressed down: frogs soak water through the skin),
|
|
14
|
-
// hit (flinch, eyes pulled in, then often hops away), death (limp, belly
|
|
15
|
-
// down, legs sprawled)
|
|
16
|
-
//
|
|
17
|
-
// All distances are frog metres at the reference size (bullfrog SVL 140 mm), multiplied by cfg.s;
|
|
18
|
-
// posture offsets that the engine multiplies by cfg.k (fwd, side, headRaise, neckReach) are divided by
|
|
19
|
-
// cfg.unit.
|
|
20
|
-
import * as THREE from 'three';
|
|
21
|
-
import { clamp, lerp, smooth, smin, TAU, tv, tqa } from '../../core/motion/common.js';
|
|
22
|
-
import { mx, mxLeg, ONESHOTS } from '../../core/motion/actions.js';
|
|
23
|
-
|
|
24
|
-
const PI = Math.PI;
|
|
25
|
-
const _q = new THREE.Quaternion(), _q2 = new THREE.Quaternion(), _s = new THREE.Vector3(1, 1, 1), _p = new THREE.Vector3();
|
|
26
|
-
const _X = new THREE.Vector3(1, 0, 0), _Y = new THREE.Vector3(0, 1, 0), _Z = new THREE.Vector3(0, 0, 1);
|
|
27
|
-
const bell = (t, a, b, c, d) => smooth(a, b, t) * (1 - smooth(c, d, t));
|
|
28
|
-
|
|
29
|
-
// eye retraction depth (m at size 1) and the tongue's extension (x its rest length)
|
|
30
|
-
const EYE_DROP = 0.0048;
|
|
31
|
-
const TONGUE_EXT = 1.9;
|
|
32
|
-
|
|
33
|
-
// per-engine behaviour state; `f` holds this frame's requests from the actions (reset after pose)
|
|
34
|
-
function B(e) {
|
|
35
|
-
if (!e._fb) {
|
|
36
|
-
e._fb = {
|
|
37
|
-
blinkWait: 2 + e.rand() * 4, blinkAge: -1, blink: 0,
|
|
38
|
-
pumpPh: 0, pumpRate: 1.6, pumpAmp: 1, sac: 0, retract: 0, tongueX: 0,
|
|
39
|
-
croakT: 12 + e.rand() * 20, idleT: 10 + e.rand() * 10,
|
|
40
|
-
f: { retract: 0, lid: 0, sac: 0, pump: 1, tongue: 0, flip: 0, aim: new THREE.Vector3(), aimW: 0 },
|
|
41
|
-
eyeLen: null,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return e._fb;
|
|
45
|
-
}
|
|
46
|
-
const busy = (L) => L.postures.length > 0 || L.oneshots.some((a) => !a.stopping);
|
|
47
|
-
|
|
48
|
-
// ------------------------------------------------------------------------------------------------
|
|
49
|
-
// pose: eyes, throat, tongue (runs after the engine wrote the head, jaw and the extra bones)
|
|
50
|
-
function pose(e, dt) {
|
|
51
|
-
const b = B(e), f = b.f, cfg = e.cfg, s = cfg.s;
|
|
52
|
-
const crowd = e.lod >= 2;
|
|
53
|
-
// eye retraction: the globes and lids sink into the head (blink, swallow, flight), lower lid rises
|
|
54
|
-
const want = clamp(Math.max(f.retract, b.blink), 0, 1);
|
|
55
|
-
b.retract += (want - b.retract) * (1 - Math.exp(-dt * 30));
|
|
56
|
-
if (b.retract > 1e-4) {
|
|
57
|
-
for (const S of ['L', 'R']) {
|
|
58
|
-
const eb = e.bone['eye' + S];
|
|
59
|
-
if (!eb) continue;
|
|
60
|
-
_q.setFromRotationMatrix(eb.matrixWorld);
|
|
61
|
-
_p.setFromMatrixPosition(eb.matrixWorld);
|
|
62
|
-
// down along the eye bone (the head's up) and a little back
|
|
63
|
-
_p.addScaledVector(tv(0, 1, 0).applyQuaternion(_q), -EYE_DROP * s * b.retract).addScaledVector(tv(0, 0, 1).applyQuaternion(_q), -0.0012 * s * b.retract);
|
|
64
|
-
eb.matrixWorld.compose(_p, _q, _s);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// throat: buccal pumping (the floor of the mouth rises and falls ~1.5 Hz) and the vocal sac
|
|
68
|
-
const th = e.bone.throat;
|
|
69
|
-
if (th) {
|
|
70
|
-
b.pumpPh += dt * TAU * b.pumpRate;
|
|
71
|
-
const pump = crowd ? 0 : (0.5 + 0.5 * Math.sin(b.pumpPh)) * b.pumpAmp * f.pump;
|
|
72
|
-
b.sac += (f.sac - b.sac) * (1 - Math.exp(-dt * (f.sac > b.sac ? 9 : 6)));
|
|
73
|
-
const sc = b.sac;
|
|
74
|
-
if (pump > 1e-4 || sc > 1e-4) {
|
|
75
|
-
_q.setFromRotationMatrix(th.matrixWorld);
|
|
76
|
-
_p.setFromMatrixPosition(th.matrixWorld);
|
|
77
|
-
// (bone Y points down and forward out of the head: the floor of the mouth drops along it)
|
|
78
|
-
_s.set(1 + 0.05 * pump + 0.35 * sc, 1 + 0.14 * pump + 0.8 * sc, 1 + 0.05 * pump + 0.3 * sc);
|
|
79
|
-
th.matrixWorld.compose(_p, _q, _s);
|
|
80
|
-
_s.set(1, 1, 1);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// tongue: flips forward out of the mouth about its front attachment and stretches
|
|
84
|
-
const tg = e.bone.tongue;
|
|
85
|
-
if (tg && (f.flip > 1e-4 || f.tongue > 1e-4)) {
|
|
86
|
-
_q.setFromRotationMatrix(tg.matrixWorld);
|
|
87
|
-
_p.setFromMatrixPosition(tg.matrixWorld);
|
|
88
|
-
const lat = tv(1, 0, 0).applyQuaternion(_q);
|
|
89
|
-
_q2.copy(tqa(lat, f.flip * PI)).multiply(_q);
|
|
90
|
-
// aim: once flipped out, the tongue turns toward the prey (default: just ahead of the mouth, never
|
|
91
|
-
// into the ground) and stretches to reach it
|
|
92
|
-
const L0 = e.J.tongueBase.distanceTo(e.J.tongueTip);
|
|
93
|
-
const hf = tv(0, 0, 1).applyQuaternion(e.headPose.quaternion);
|
|
94
|
-
hf.y = Math.min(hf.y, 0) - 0.25; hf.normalize();
|
|
95
|
-
const aim = tv().copy(_p).addScaledVector(hf, L0 * 2.2);
|
|
96
|
-
if (f.aimW > 0) {
|
|
97
|
-
// (prey the frog has already passed, or far off to the side, is out of the tongue's reach)
|
|
98
|
-
const to = tv().subVectors(f.aim, _p), dl = to.length();
|
|
99
|
-
const ok = smooth(0.35, 0.7, to.dot(hf) / Math.max(dl, 1e-6)) * f.aimW;
|
|
100
|
-
aim.lerp(f.aim, ok);
|
|
101
|
-
}
|
|
102
|
-
aim.y = Math.max(aim.y, e.terrainH(aim.x, aim.z) + 0.009 * s);
|
|
103
|
-
const want = tv().subVectors(aim, _p);
|
|
104
|
-
const dist = want.length();
|
|
105
|
-
want.multiplyScalar(1 / Math.max(dist, 1e-6));
|
|
106
|
-
const d1 = tv(0, 1, 0).applyQuaternion(_q2);
|
|
107
|
-
const k = smooth(0.5, 0.95, f.flip);
|
|
108
|
-
if (k > 0) {
|
|
109
|
-
// (bounded, about a stable axis: the tongue can only bend so far off the head's midline)
|
|
110
|
-
const ax = tv().crossVectors(d1, want);
|
|
111
|
-
const sn = ax.length(), ang = Math.atan2(sn, d1.dot(want));
|
|
112
|
-
if (sn > 1e-3) ax.multiplyScalar(1 / sn); else ax.copy(lat);
|
|
113
|
-
_q2.premultiply(tqa(ax, Math.min(ang, 1.0) * k));
|
|
114
|
-
}
|
|
115
|
-
const ext = clamp(dist / L0, 1, TONGUE_EXT);
|
|
116
|
-
_s.set(1 - 0.25 * f.tongue, 1 + (ext - 1) * f.tongue, 1 - 0.2 * f.tongue);
|
|
117
|
-
tg.matrixWorld.compose(_p, _q2, _s);
|
|
118
|
-
_s.set(1, 1, 1);
|
|
119
|
-
}
|
|
120
|
-
b.tongueX = f.tongue;
|
|
121
|
-
f.retract = 0; f.lid = 0; f.sac = 0; f.pump = 1; f.tongue = 0; f.flip = 0; f.aimW = 0;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// world position of the tongue tip (after pose)
|
|
125
|
-
function tongueTip(e, out) {
|
|
126
|
-
const tg = e.bone.tongue;
|
|
127
|
-
const J = e.J;
|
|
128
|
-
const L = J.tongueBase.distanceTo(J.tongueTip);
|
|
129
|
-
const el = tg.matrixWorld.elements;
|
|
130
|
-
return out.set(el[12] + el[4] * L, el[13] + el[5] * L, el[14] + el[6] * L);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ------------------------------------------------------------------------------------------------
|
|
134
|
-
// update: blinks, breathing, idle life
|
|
135
|
-
function update(P, dt, L) {
|
|
136
|
-
const e = L.engine, b = B(e), cfg = e.cfg;
|
|
137
|
-
const vn = e.speed / cfg.sq;
|
|
138
|
-
P.tailGround = 0; P.tailSide = 0; P.tailLift = 0;
|
|
139
|
-
// Foot placement: stance.sprawl turns the knees and elbows out (the IK poles); the feet themselves
|
|
140
|
-
// stand where the sitting bind pose puts them (the sprawl is sculpted), so the engine's extra sprawl
|
|
141
|
-
// width is taken back out: the resting frog is exactly its bind pose
|
|
142
|
-
for (const leg of e.legs) { const Ld = leg.def; leg.idleOff.x = -Ld.s * cfg.stance.sprawl * Ld.len * 0.35; }
|
|
143
|
-
if (!b.planted) {
|
|
144
|
-
// (a new frog starts with its feet at that placement: the engine planted them before this hook ran)
|
|
145
|
-
b.planted = true;
|
|
146
|
-
for (const leg of e.legs) if (leg.state === 'stance') { e.neutralContact(leg.def, 0, 0, leg.plant, leg); leg.contact.copy(leg.plant); }
|
|
147
|
-
}
|
|
148
|
-
// the resting sit: forelegs a little straighter, chest and head raised, the body sloping to the rump
|
|
149
|
-
mx(P, 'dropF', -0.3, L.idle.w); mx(P, 'headPitch', -0.05, L.idle.w);
|
|
150
|
-
// no neck: the head turns only a few degrees on the trunk and leads turns very little
|
|
151
|
-
P.headYaw -= 0.8 * clamp(e.yawRate * 0.22, -0.4, 0.4);
|
|
152
|
-
// automatic blinks: the eyes are pulled down into the head for ~0.3 s, the lower lid rises
|
|
153
|
-
const asleep = P.eyelid > 0.9;
|
|
154
|
-
if (!asleep && e.lod < 2) {
|
|
155
|
-
b.blinkWait -= dt;
|
|
156
|
-
if (b.blinkAge < 0 && b.blinkWait <= 0) { b.blinkAge = 0; b.blinkWait = 3 + e.rand() * 7; }
|
|
157
|
-
}
|
|
158
|
-
if (b.blinkAge >= 0) {
|
|
159
|
-
b.blinkAge += dt;
|
|
160
|
-
const t = b.blinkAge;
|
|
161
|
-
b.blink = t < 0.09 ? smooth(0, 0.09, t) : t < 0.16 ? 1 : 1 - smooth(0.16, 0.36, t);
|
|
162
|
-
if (t > 0.36) { b.blinkAge = -1; b.blink = 0; }
|
|
163
|
-
} else b.blink = 0;
|
|
164
|
-
P.eyelid = Math.max(P.eyelid, 0.85 * Math.max(b.blink, b.f.retract * 0.8));
|
|
165
|
-
// buccal pumping: ~1.5 Hz at rest, faster after exertion, none in flight
|
|
166
|
-
const air = e.air.active ? 1 : 0;
|
|
167
|
-
b.pumpRate = lerp(1.5, 2.6, smooth(0.2, 1.2, vn)) * (0.9 + 0.2 * Math.sin(e.time * 0.13));
|
|
168
|
-
b.pumpAmp = (1 - air) * (1 - 0.6 * smooth(0.2, 1.0, vn)) * (P.breathRate > 0.1 ? 1 : 0);
|
|
169
|
-
// hopping: the eyes half close / sink with every landing
|
|
170
|
-
if (P.gaitW > 0.5 && vn > 0.25 && e.legs[0].state === 'swing' && e.legs[2].state === 'swing') b.f.retract = Math.max(b.f.retract, 0.35);
|
|
171
|
-
// idle life: long motionless sits; males call in bouts
|
|
172
|
-
if (e.idleVariants !== false && L.idle.w > 0.98 && !busy(L) && !e.input.look && !e.input.follow) {
|
|
173
|
-
b.croakT -= dt;
|
|
174
|
-
if (b.croakT <= 0) {
|
|
175
|
-
b.croakT = 18 + e.rand() * 30;
|
|
176
|
-
if (e.params.sex === 'male' && e.params.age !== 'juvenile') L.play('croak');
|
|
177
|
-
}
|
|
178
|
-
} else if (busy(L)) b.croakT = Math.max(b.croakT, 6);
|
|
179
|
-
// any other action interrupts eating and croaking
|
|
180
|
-
if (L.oneshots.some((a) => !a.stopping && !['eat', 'croak', 'hit', 'blink'].includes(a.name))) for (const a of L.oneshots) if (a.name === 'eat' || a.name === 'croak') a.stopping = true;
|
|
181
|
-
// a startled frog often hops away
|
|
182
|
-
if (b.fleeAfter > 0) {
|
|
183
|
-
b.fleeAfter -= dt;
|
|
184
|
-
if (b.fleeAfter <= 0 && !busy(L)) L.play('hop', { distance: 0.35 });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// ------------------------------------------------------------------------------------------------
|
|
189
|
-
// Leaps: a real ballistic flight (engine.takeOff) with scripted foot paths in world space. The hind
|
|
190
|
-
// feet stay planted while the legs extend (knee, hip, then ankle) and push the body off; in flight
|
|
191
|
-
// the hind legs trail fully extended behind the body and the forelimbs reach forward; the body pitches
|
|
192
|
-
// nose down so the hands touch first, then the belly lands and the hind legs are drawn forward and
|
|
193
|
-
// folded back into the sit.
|
|
194
|
-
function leapDef(o) {
|
|
195
|
-
return {
|
|
196
|
-
kind: 'oneshot', airborne: true, fade: 0.08,
|
|
197
|
-
start(inst, L) {
|
|
198
|
-
const e = L.engine, cfg = e.cfg, s = cfg.s;
|
|
199
|
-
// (a frog's leap is a discrete act: from a hop it gathers and leaps like from the sit, keeping its speed)
|
|
200
|
-
inst.run = 0;
|
|
201
|
-
inst.v0 = e.speed;
|
|
202
|
-
inst.tc = lerp(o.crouch, 0.08, inst.run) * cfg.sq;
|
|
203
|
-
const h = (inst.opts.height ?? o.height) * s * lerp(1, 0.7, inst.run);
|
|
204
|
-
inst.vy = Math.sqrt(2 * 9.81 * h);
|
|
205
|
-
inst.T = (2 * inst.vy) / 9.81;
|
|
206
|
-
let dist = (inst.opts.distance ?? o.distance) * s;
|
|
207
|
-
if (inst.opts.target) { const t = inst.opts.target; dist = clamp(Math.hypot(t.x - e.pos.x, t.z - e.pos.z), 0.05 * s, dist * 2); }
|
|
208
|
-
inst.vh = Math.max(e.speed, lerp(dist / inst.T, e.speed, inst.run));
|
|
209
|
-
// push-off: the legs extend over tp (knee, hip, ankle) and launch the body
|
|
210
|
-
inst.tp = Math.min(o.push * cfg.sq, inst.tc * 0.7);
|
|
211
|
-
inst.LD = lerp(o.land, 0.2, inst.run) * cfg.sq; // landing: hands, belly, then the hind legs fold
|
|
212
|
-
inst.L0 = (inst.vy * inst.tp) / 2;
|
|
213
|
-
// (played while hopping: the frog first comes to a stop on all fours, then gathers and leaps)
|
|
214
|
-
inst.phase = e.speed / cfg.sq > 0.08 ? 'settle' : 'crouch';
|
|
215
|
-
inst.ts = 0;
|
|
216
|
-
inst.dur = Infinity;
|
|
217
|
-
inst.A = [0, 1, 2, 3].map(() => new THREE.Vector3());
|
|
218
|
-
inst.Bp = [0, 1, 2, 3].map(() => new THREE.Vector3());
|
|
219
|
-
inst.end = [0, 1, 2, 3].map(() => new THREE.Vector3());
|
|
220
|
-
inst.last = [0, 1, 2, 3].map(() => new THREE.Vector3());
|
|
221
|
-
},
|
|
222
|
-
update(inst, dt, L) {
|
|
223
|
-
inst.dt = dt;
|
|
224
|
-
const e = L.engine;
|
|
225
|
-
if (inst.phase === 'settle') {
|
|
226
|
-
// (all four feet down for a moment: the re-steps after stopping are done)
|
|
227
|
-
inst.still = e.speed < 0.02 * e.cfg.sq && e.legs.every((l) => l.state === 'stance') ? (inst.still || 0) + dt : 0;
|
|
228
|
-
if (inst.still > 0.35 || inst.t > 2) { inst.phase = 'crouch'; inst.ts = inst.t; inst.C = null; }
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
if (inst.phase === 'crouch' && inst.t - inst.ts >= inst.tc) {
|
|
232
|
-
inst.phase = 'air'; inst.tAir = inst.t;
|
|
233
|
-
{ const u = Math.max(0, inst.t - inst.ts - dt - (inst.tc - inst.tp)); inst.L0 = u <= inst.tp ? (inst.vy * u * u) / (2 * inst.tp) : inst.vy * (inst.tp / 2 + u - inst.tp); }
|
|
234
|
-
e.takeOff(inst.vy, inst.vh);
|
|
235
|
-
if (inst.run > 0.5) e.phase = ((-e.gait.f * inst.T) % 1 + 1) % 1;
|
|
236
|
-
const land = tv().copy(e.pos).addScaledVector(e.forward(e.heading, tv()), inst.vh * inst.T);
|
|
237
|
-
inst.P0 = e.pos.clone(); inst.Pl = land.clone(); inst.F = e.forward(e.heading, new THREE.Vector3()); inst.Lf = e.left(e.heading, new THREE.Vector3());
|
|
238
|
-
for (let i = 0; i < 4; i++) {
|
|
239
|
-
const Ld = e.legs[i].def;
|
|
240
|
-
inst.A[i].copy(inst.C ? inst.C[i] : e.legs[i].contact);
|
|
241
|
-
e.neutralContact(Ld, 0, 0, inst.Bp[i], e.legs[i]);
|
|
242
|
-
inst.Bp[i].sub(e.pos).add(land);
|
|
243
|
-
if (inst.run > 0.5) {
|
|
244
|
-
const g = e.gait, half = Math.min(e.speed * g.D / g.f * 0.5, Ld.leadMax);
|
|
245
|
-
if (!Ld.front) inst.Bp[i].addScaledVector(inst.F, half);
|
|
246
|
-
}
|
|
247
|
-
inst.Bp[i].y = e.terrainH(inst.Bp[i].x, inst.Bp[i].z);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
// after landing the frog slides a little on its belly and stops (a continuous braking: a sudden
|
|
251
|
-
// change of speed switched the head carriage in one frame)
|
|
252
|
-
if (inst.phase === 'land') {
|
|
253
|
-
e.speed *= Math.exp(-dt * 16);
|
|
254
|
-
// (the planted feet the landing hands back to are the sitting placement under the sliding body)
|
|
255
|
-
const lgw = 1 - smooth(0.35 * inst.LD, 0.95 * inst.LD, inst.t - inst.tLand);
|
|
256
|
-
if (lgw > 0.02) for (const leg of e.legs) if (leg.state === 'stance') { e.neutralContact(leg.def, 0, 0, leg.plant, leg); leg.contact.copy(leg.plant); }
|
|
257
|
-
}
|
|
258
|
-
if (inst.phase === 'land' && inst.t - inst.tLand > inst.LD) return true;
|
|
259
|
-
if (inst.phase === 'air' && inst.t - inst.tAir > 3) e.touchDown();
|
|
260
|
-
return false;
|
|
261
|
-
},
|
|
262
|
-
onLand(inst, L) {
|
|
263
|
-
inst.phase = 'land'; inst.tLand = inst.t;
|
|
264
|
-
const e = L.engine;
|
|
265
|
-
e.hipY.v *= 0.3; e.shY.v *= 0.4;
|
|
266
|
-
for (let i = 0; i < 4; i++) inst.end[i].copy(inst.last[i]);
|
|
267
|
-
},
|
|
268
|
-
apply(P, w, inst, L) {
|
|
269
|
-
const e = L.engine, cfg = e.cfg, s = cfg.s, b = B(e);
|
|
270
|
-
let t = inst.t;
|
|
271
|
-
if (inst.phase === 'settle') { mx(P, 'speedScale', 0, w); return; }
|
|
272
|
-
if (inst.phase === 'crouch') {
|
|
273
|
-
t -= inst.ts;
|
|
274
|
-
// a brief crouch, then the push: the forequarters rise first, the hind legs extend
|
|
275
|
-
const c = smooth(0, inst.tc, t) * (1 - inst.run * 0.7) * w;
|
|
276
|
-
const u0 = clamp(t - (inst.tc - inst.tp), 0, inst.tp), x = u0 / inst.tp;
|
|
277
|
-
mx(P, 'dropF', lerp(0.15, -0.3, x), c); mx(P, 'dropH', lerp(0.1, -0.2, x), c);
|
|
278
|
-
const r = smooth(lerp(0.2, 0, inst.run) * inst.tc, 0.9 * inst.tc, t) * w;
|
|
279
|
-
const push = (inst.vy * u0 * u0) / (2 * inst.tp);
|
|
280
|
-
// (the feet stay planted flat through the crouch; the scripted foot paths take over as the push
|
|
281
|
-
// starts: the forefeet leave with the body, the hind feet roll up onto their toes)
|
|
282
|
-
const rr = smooth(inst.tc - inst.tp - 0.1 * cfg.sq, inst.tc - 0.3 * inst.tp, t) * w;
|
|
283
|
-
// (the feet push from where they stood when the crouch began, whatever the gait does meanwhile)
|
|
284
|
-
if (!inst.C) inst.C = e.legs.map((l) => l.contact.clone());
|
|
285
|
-
for (let i = 0; i < 4; i++) { P.legs[i].target.copy(inst.C[i]); if (i < 2) P.legs[i].target.y += push * 0.9; mxLeg(P, i, 'reach', 1, rr); }
|
|
286
|
-
mx(P, 'pitch', o.pitch * 0.3 * x * (1 - 0.5 * inst.run), r);
|
|
287
|
-
mx(P, 'flex', -0.12 * x, r);
|
|
288
|
-
mx(P, 'gaitW', 0, r); mx(P, 'legGait', 0, r); mx(P, 'speedScale', 0, w * (1 - smooth(0, 0.2, x)));
|
|
289
|
-
P.lift += push * w;
|
|
290
|
-
if (inst.run < 0.5 && u0 > 0) e.speed = Math.max(e.speed, inst.vh * x);
|
|
291
|
-
b.f.retract = Math.max(b.f.retract, 0.6 * x * w);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
P.lift += inst.L0 * w * (inst.phase === 'land' ? 1 - smooth(0, 0.6 * inst.LD, t - inst.tLand) : 1);
|
|
295
|
-
const x = (t - inst.tAir + (inst.dt || 1 / 60)) / inst.T;
|
|
296
|
-
let hand = 0;
|
|
297
|
-
if (inst.phase === 'land') hand = smooth(0.0, 0.8 * inst.LD, t - inst.tLand);
|
|
298
|
-
const lg = inst.phase === 'land' ? 1 - smooth(0.35 * inst.LD, 0.95 * inst.LD, t - inst.tLand) : 1;
|
|
299
|
-
mx(P, 'gaitW', 0, w * lg); mx(P, 'legGait', 0, w * lg);
|
|
300
|
-
const lift = flightLift(inst, e) + inst.L0 * (1 - smooth(0.55, 0.95, x));
|
|
301
|
-
for (let i = 0; i < 4; i++) {
|
|
302
|
-
const pl = P.legs[i];
|
|
303
|
-
const p = inst.phase === 'land' ? landTarget(inst, e, i, hand) : pathAt(inst, e, i, x, lift);
|
|
304
|
-
pl.target.copy(p);
|
|
305
|
-
if (inst.phase === 'air') inst.last[i].copy(p);
|
|
306
|
-
mxLeg(P, i, 'reach', 1, w * lg);
|
|
307
|
-
}
|
|
308
|
-
const xp = clamp(x, 0, 1);
|
|
309
|
-
if (inst.phase === 'air') {
|
|
310
|
-
// stretched in flight: nose up off the ground, then down to land on the hands
|
|
311
|
-
mx(P, 'pitch', lerp(0.3, -0.28, smooth(0.1, 0.95, xp)) * o.pitch * (1 - 0.5 * inst.run), w);
|
|
312
|
-
mx(P, 'flex', -0.12 * Math.sin(PI * xp), w);
|
|
313
|
-
b.f.retract = Math.max(b.f.retract, 0.7 * w);
|
|
314
|
-
} else {
|
|
315
|
-
const xl = (t - inst.tLand) / inst.LD;
|
|
316
|
-
// hands, then belly: the chest takes the landing, the rump settles last
|
|
317
|
-
const a = Math.sin(PI * Math.min(1, xl * 1.4)) * (1 - xl) * w;
|
|
318
|
-
// (it settles into the sit before moving on)
|
|
319
|
-
mx(P, 'speedScale', 0, w * (1 - smooth(0.7, 1, xl)));
|
|
320
|
-
mx(P, 'dropF', 0.35, a); mx(P, 'dropH', 0.2, a);
|
|
321
|
-
mx(P, 'pitch', -0.28 * o.pitch * (1 - smooth(0, 0.6, xl)) * (1 - 0.5 * inst.run), w);
|
|
322
|
-
b.f.retract = Math.max(b.f.retract, 0.7 * (1 - smooth(0.3, 0.8, xl)) * w);
|
|
323
|
-
}
|
|
324
|
-
void s;
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
function landTarget(inst, e, i, hand) {
|
|
328
|
-
const p = tv().copy(inst.end[i]).sub(inst.Pl).add(e.pos).addScaledVector(inst.F, e.speed * (inst.dt || 1 / 60));
|
|
329
|
-
// (from the height the foot had at touchdown down to the ground, continuously)
|
|
330
|
-
const above = inst.end[i].y - e.terrainH(inst.end[i].x, inst.end[i].z);
|
|
331
|
-
// (toward the sitting placement under the body: the gait's own contact point jumps when a swing it
|
|
332
|
-
// was running lands)
|
|
333
|
-
const q = p.lerp(e.neutralContact(e.legs[i].def, 0, 0, tv(), e.legs[i]), hand);
|
|
334
|
-
q.y = e.terrainH(q.x, q.z) + Math.max(0, above) * (1 - smooth(0, 1, hand));
|
|
335
|
-
// the hind feet are drawn forward just clear of the ground (a step, not a drag)
|
|
336
|
-
if (i >= 2) q.y += Math.sin(PI * hand) * 0.01 * e.cfg.s * (1 - inst.run);
|
|
337
|
-
return q;
|
|
338
|
-
}
|
|
339
|
-
function flightLift(inst, e) {
|
|
340
|
-
if (!e.air.active) return 0;
|
|
341
|
-
const ta = e.air.t + (inst.dt || 1 / 60);
|
|
342
|
-
return Math.max(0, inst.vy * ta - 4.905 * ta * ta);
|
|
343
|
-
}
|
|
344
|
-
function pathAt(inst, e, i, x, lift) {
|
|
345
|
-
const front = i < 2, s = e.cfg.s, Ld = e.legs[i].def;
|
|
346
|
-
const A = inst.A[i], Bq = inst.Bp[i];
|
|
347
|
-
if (inst.run > 0.5) {
|
|
348
|
-
const c = tv().copy(e.legs[i].contact);
|
|
349
|
-
c.y += lift * (front ? 0.9 : 0.75 * smooth(0, 0.3, x));
|
|
350
|
-
const gy = (front ? e.fr.shC.y : e.fr.hipC.y) - (front ? 0.62 : 0.55) * Ld.len;
|
|
351
|
-
c.y = smin(c.y, gy, 0.05 * e.cfg.k);
|
|
352
|
-
return c;
|
|
353
|
-
}
|
|
354
|
-
const xb = clamp(x, 0, 1);
|
|
355
|
-
const Pb = tv().copy(inst.P0).lerp(inst.Pl, xb);
|
|
356
|
-
if (front) {
|
|
357
|
-
// forelimbs: leave with the body, reach forward and down, and meet the ground at the landing spot
|
|
358
|
-
const u = smooth(0.0, 0.92, x);
|
|
359
|
-
const rel = tv().subVectors(A, inst.P0).lerp(tv().subVectors(Bq, inst.Pl), u);
|
|
360
|
-
const p = tv().copy(Pb).add(rel).addScaledVector(inst.F, o.reachF * s * Math.sin(PI * u));
|
|
361
|
-
p.y = lerp(A.y, Bq.y, u) + lift * 0.9 * (1 - smooth(0.7, 1.0, x)) + Math.sin(PI * u) * o.arcF * s;
|
|
362
|
-
return p;
|
|
363
|
-
}
|
|
364
|
-
// hind limbs: planted until the body has left, then trailing fully extended behind the hip in
|
|
365
|
-
// line with the body; they swing forward and fold only in the last part of the flight
|
|
366
|
-
const hip = tv().copy(e.fr.hipC).addScaledVector(inst.Lf, Ld.s * Ld.cx * 0.6);
|
|
367
|
-
const back = tv().copy(inst.F).multiplyScalar(-1);
|
|
368
|
-
const ext = tv().copy(hip).addScaledVector(back, Ld.len * o.ext).addScaledVector(inst.Lf, Ld.s * 0.12 * Ld.len);
|
|
369
|
-
ext.y = hip.y - Ld.len * 0.28;
|
|
370
|
-
const land = tv().copy(Bq); land.y += lift * 0.6 + 0.02 * s;
|
|
371
|
-
const p = tv().copy(A).lerp(ext, smooth(0.0, 0.3, x)).lerp(land, smooth(o.fold, 1.0, x));
|
|
372
|
-
p.y = Math.max(p.y, e.terrainH(p.x, p.z) + 0.004 * s * smooth(0, 0.25, x));
|
|
373
|
-
return p;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// ------------------------------------------------------------------------------------------------
|
|
378
|
-
// The tongue strike: the mouth opens, the sticky tongue flips out forward (about its attachment at the
|
|
379
|
-
// front of the lower jaw) and stretches to the prey, and is pulled back in; the frog lunges a little.
|
|
380
|
-
// Returns the strike envelope pieces for apply(): jaw gape, tongue flip and extension.
|
|
381
|
-
function strikeAt(t, t0) {
|
|
382
|
-
const u = t - t0;
|
|
383
|
-
const gape = bell(u, -0.04, 0.02, 0.2, 0.28);
|
|
384
|
-
const flip = bell(u, 0.0, 0.07, 0.13, 0.22);
|
|
385
|
-
const ext = bell(u, 0.03, 0.08, 0.11, 0.2);
|
|
386
|
-
return { gape, flip, ext };
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const attack = {
|
|
390
|
-
kind: 'oneshot', fade: 0.1, needsStand: true,
|
|
391
|
-
start(inst, L) {
|
|
392
|
-
const e = L.engine;
|
|
393
|
-
inst.dur = 0.9; inst.hit = false; inst.t0 = 0.28;
|
|
394
|
-
inst.target = inst.opts.target ? inst.opts.target.clone() : null;
|
|
395
|
-
inst.run = smooth(0.3, 0.8, e.speed / e.cfg.sq);
|
|
396
|
-
},
|
|
397
|
-
update(inst, dt, L) {
|
|
398
|
-
const e = L.engine;
|
|
399
|
-
if (!inst.hit && inst.t >= inst.t0 + 0.09) {
|
|
400
|
-
inst.hit = true;
|
|
401
|
-
const p = tongueTip(e, new THREE.Vector3());
|
|
402
|
-
const dir = inst.target ? inst.target.clone().sub(e.headPose.position).normalize() : e.forward(e.heading, new THREE.Vector3());
|
|
403
|
-
e.emit('attackHit', { position: p, direction: dir, style: 'tongue' });
|
|
404
|
-
}
|
|
405
|
-
return inst.t >= inst.dur;
|
|
406
|
-
},
|
|
407
|
-
apply(P, w, inst, L) {
|
|
408
|
-
const e = L.engine, cfg = e.cfg, t = inst.t, b = B(e);
|
|
409
|
-
if (inst.target) { P.look = inst.target; mx(P, 'lookW', 1, w); }
|
|
410
|
-
// a short lunge: the forequarters rise and the body pitches toward the prey
|
|
411
|
-
const lunge = bell(t, 0.12, 0.3, 0.42, 0.75) * w * (1 - inst.run);
|
|
412
|
-
mx(P, 'fwd', 0.012 / cfg.unit, lunge); mx(P, 'dropF', -0.25, lunge); mx(P, 'pitch', -0.06, lunge);
|
|
413
|
-
const k = strikeAt(t, inst.t0);
|
|
414
|
-
mx(P, 'jaw', 0.42, k.gape * w); mx(P, 'jawOmega', 45, w);
|
|
415
|
-
b.f.flip = Math.max(b.f.flip, k.flip * w); b.f.tongue = Math.max(b.f.tongue, k.ext * w);
|
|
416
|
-
aimTongue(e, b, inst.target, w);
|
|
417
|
-
b.f.retract = Math.max(b.f.retract, 0.5 * bell(t, 0.2, 0.28, 0.4, 0.55) * w);
|
|
418
|
-
},
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
function aimTongue(e, b, target, w) {
|
|
422
|
-
if (!target || w <= 0) return;
|
|
423
|
-
b.f.aim.copy(target); b.f.aimW = 1;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// eat: the frog strikes at prey on the ground just ahead, swallows (eyes pulled in twice, pushing the
|
|
427
|
-
// food down) and pumps its throat
|
|
428
|
-
const eat = {
|
|
429
|
-
kind: 'oneshot', fade: 0.2,
|
|
430
|
-
start(inst) { inst.dur = inst.opts.loop ? Infinity : (inst.opts.duration ?? 2.6); inst.fade = 0.3; },
|
|
431
|
-
update(inst) { return inst.t >= inst.dur; },
|
|
432
|
-
apply(P, w, inst, L) {
|
|
433
|
-
const e = L.engine, cfg = e.cfg, b = B(e);
|
|
434
|
-
const t = inst.opts.loop ? inst.t % 2.6 : inst.t;
|
|
435
|
-
const lean = bell(t, 0.05, 0.3, 0.55, 0.9) * w;
|
|
436
|
-
mx(P, 'fwd', 0.01 / cfg.unit, lean); mx(P, 'dropF', 0.3, lean); mx(P, 'headPitch', 0.12, lean);
|
|
437
|
-
const k = strikeAt(t, 0.35);
|
|
438
|
-
mx(P, 'jaw', 0.45, k.gape * w); mx(P, 'jawOmega', 45, w);
|
|
439
|
-
b.f.flip = Math.max(b.f.flip, k.flip * w); b.f.tongue = Math.max(b.f.tongue, 0.7 * k.ext * w);
|
|
440
|
-
// prey on the ground a little ahead of the mouth
|
|
441
|
-
const hf = e.forward(e.heading, tv());
|
|
442
|
-
const pt = tv().copy(e.headPose.position).addScaledVector(hf, 0.1 * cfg.s);
|
|
443
|
-
pt.y = e.terrainH(pt.x, pt.z);
|
|
444
|
-
aimTongue(e, b, pt, 1);
|
|
445
|
-
// swallowing: the eyes sink into the head twice, the throat works
|
|
446
|
-
const gulp = Math.max(bell(t, 0.9, 1.05, 1.25, 1.45), bell(t, 1.6, 1.75, 1.95, 2.15));
|
|
447
|
-
b.f.retract = Math.max(b.f.retract, gulp * w);
|
|
448
|
-
mx(P, 'jaw', 0.05, bell(t, 0.7, 0.8, 2.2, 2.4) * w * 0.5);
|
|
449
|
-
b.f.pump = lerp(1, 1.8, bell(t, 0.8, 1.0, 2.2, 2.5) * w);
|
|
450
|
-
mx(P, 'lookW', 0, w);
|
|
451
|
-
},
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
// croak: the male bullfrog's call, a bout of 3-6 deep notes ("jug-o-rum"): with each note the vocal
|
|
455
|
-
// sac under the throat balloons and the flanks draw in, then it sits a moment with the sac deflating
|
|
456
|
-
const croak = {
|
|
457
|
-
kind: 'oneshot', fade: 0.4,
|
|
458
|
-
start(inst, L) {
|
|
459
|
-
const e = L.engine;
|
|
460
|
-
inst.notes = inst.opts.notes ?? 3 + Math.floor(e.rand() * 4);
|
|
461
|
-
inst.period = 0.95;
|
|
462
|
-
inst.dur = inst.opts.loop ? Infinity : 0.5 + inst.notes * inst.period + 0.6;
|
|
463
|
-
inst.said = -1;
|
|
464
|
-
},
|
|
465
|
-
update(inst, dt, L) {
|
|
466
|
-
const n = Math.floor((inst.t - 0.5) / inst.period);
|
|
467
|
-
if (inst.t > 0.5 && n > inst.said && (inst.opts.loop || n < inst.notes)) { inst.said = n; L.engine.emit('vocalize', { kind: 'croak' }); }
|
|
468
|
-
return inst.t >= inst.dur;
|
|
469
|
-
},
|
|
470
|
-
apply(P, w, inst, L) {
|
|
471
|
-
const e = L.engine, b = B(e), t = inst.t;
|
|
472
|
-
const on = smooth(0.2, 0.5, t) * (inst.opts.loop ? 1 : 1 - smooth(inst.dur - 0.7, inst.dur - 0.2, t));
|
|
473
|
-
const u = ((t - 0.5) % inst.period + inst.period) % inst.period;
|
|
474
|
-
const note = t > 0.5 ? smooth(0.0, 0.18, u) * (1 - smooth(0.55, 0.85, u)) : 0;
|
|
475
|
-
// the sac stays partly filled between notes
|
|
476
|
-
b.f.sac = Math.max(b.f.sac, (0.35 + 0.65 * note) * on * w);
|
|
477
|
-
b.f.pump = 0;
|
|
478
|
-
// sits up a little, head raised; the flanks contract as the air goes into the sac
|
|
479
|
-
mx(P, 'dropF', -0.25, on * w); mx(P, 'headPitch', -0.08, on * w);
|
|
480
|
-
mx(P, 'breathRate', 0.01, on * w); mx(P, 'breathAmp', 3, on * w);
|
|
481
|
-
e.breath = lerp(e.breath, -PI / 2, note * on * w * 0.2);
|
|
482
|
-
mx(P, 'lookW', 0, on * w);
|
|
483
|
-
},
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
// blink on demand (the automatic blinks run in update)
|
|
487
|
-
const blink = {
|
|
488
|
-
kind: 'oneshot', fade: 0.05,
|
|
489
|
-
start(inst) { inst.dur = 0.4; },
|
|
490
|
-
update(inst) { return inst.t >= inst.dur; },
|
|
491
|
-
apply(P, w, inst, L) { B(L.engine).f.retract = Math.max(B(L.engine).f.retract, bell(inst.t, 0, 0.09, 0.16, 0.36)); },
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
// sit (posture): the alert, upright sit: forelegs straight, chest and head high, eyes wide
|
|
495
|
-
const sit = {
|
|
496
|
-
kind: 'posture', fadeIn: 0.6, fadeOut: 0.5,
|
|
497
|
-
apply(P, w, inst, L) {
|
|
498
|
-
const e = L.engine;
|
|
499
|
-
mx(P, 'gaitW', 0, w); mx(P, 'legGait', 0, w);
|
|
500
|
-
mx(P, 'dropF', -0.55, w); mx(P, 'dropH', 0.1, w);
|
|
501
|
-
mx(P, 'headRaise', 0.004 / e.cfg.unit, w); mx(P, 'headPitch', -0.1, w);
|
|
502
|
-
},
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
// lie (posture): the flattened crouch: belly and chin pressed to the ground, legs folded tight
|
|
506
|
-
const lie = {
|
|
507
|
-
kind: 'posture', fadeIn: 0.8, fadeOut: 0.6,
|
|
508
|
-
apply(P, w, inst, L) {
|
|
509
|
-
const e = L.engine;
|
|
510
|
-
mx(P, 'gaitW', 0, w); mx(P, 'legGait', 0, w);
|
|
511
|
-
mx(P, 'dropF', 0.95, w); mx(P, 'dropH', 1.0, w); mx(P, 'groundW', 1, w);
|
|
512
|
-
mx(P, 'headRaise', -0.003 / e.cfg.unit, w); mx(P, 'headPitch', 0.08, w);
|
|
513
|
-
mx(P, 'breathRate', 0.7, w);
|
|
514
|
-
},
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
// sleep (posture): the crouch with the eyes pulled in and closed, slow breathing
|
|
518
|
-
const sleep = {
|
|
519
|
-
kind: 'posture', fadeIn: 1.2, fadeOut: 0.8,
|
|
520
|
-
apply(P, w, inst, L) {
|
|
521
|
-
lie.apply(P, w, inst, L);
|
|
522
|
-
const c = smooth(0.8, 2.2, inst.t) * w;
|
|
523
|
-
mx(P, 'eyelid', 1, c);
|
|
524
|
-
B(L.engine).f.retract = Math.max(B(L.engine).f.retract, 0.6 * c);
|
|
525
|
-
B(L.engine).f.pump = lerp(1, 0.5, c);
|
|
526
|
-
mx(P, 'breathRate', 0.5, c); mx(P, 'lookW', 0, c);
|
|
527
|
-
},
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
// drink (one-shot): frogs do not drink; they sit with the pelvic "seat patch" pressed to wet ground
|
|
531
|
-
const drink = {
|
|
532
|
-
kind: 'oneshot', fade: 0.6,
|
|
533
|
-
start(inst) { inst.dur = inst.opts.loop ? Infinity : (inst.opts.duration ?? 5); },
|
|
534
|
-
update(inst) { return inst.t >= inst.dur; },
|
|
535
|
-
apply(P, w, inst, L) {
|
|
536
|
-
mx(P, 'gaitW', 0, w);
|
|
537
|
-
mx(P, 'dropH', 1, w); mx(P, 'dropF', 0.2, w); mx(P, 'groundW', 1, w);
|
|
538
|
-
mx(P, 'eyelid', 0.3, w);
|
|
539
|
-
B(L.engine).f.pump = lerp(1, 0.6, w);
|
|
540
|
-
},
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
// hit: flinch (the eyes are pulled in, the body ducks), then often hops away
|
|
544
|
-
const hit = {
|
|
545
|
-
...ONESHOTS.hit,
|
|
546
|
-
kind: 'oneshot',
|
|
547
|
-
start(inst, L) {
|
|
548
|
-
inst.opts = { ...inst.opts, strength: (inst.opts.strength ?? 1) * 0.15 };
|
|
549
|
-
ONESHOTS.hit.start(inst, L);
|
|
550
|
-
if (L.engine.rand() < 0.5) B(L.engine).fleeAfter = 0.9;
|
|
551
|
-
},
|
|
552
|
-
apply(P, w, inst, L) {
|
|
553
|
-
const t = inst.t;
|
|
554
|
-
const k = smooth(0, 0.08, t) * Math.exp(-Math.max(0, t - 0.08) * 5) * w;
|
|
555
|
-
mx(P, 'roll', inst.lx * 0.12, k); mx(P, 'bend', -inst.lx * 0.15, k);
|
|
556
|
-
mx(P, 'dropF', 0.4, k); mx(P, 'dropH', 0.15, k);
|
|
557
|
-
mx(P, 'headPitch', 0.08, k);
|
|
558
|
-
B(L.engine).f.retract = Math.max(B(L.engine).f.retract, k);
|
|
559
|
-
},
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
// death (posture): goes limp: the body sinks flat onto its belly between its sprawled legs, the back
|
|
563
|
-
// straightens, head down, eyes half closed and pulled in, mouth slack
|
|
564
|
-
const death = {
|
|
565
|
-
kind: 'posture', fadeIn: 0.3, fadeOut: 1.6,
|
|
566
|
-
apply(P, w, inst, L) {
|
|
567
|
-
const e = L.engine, t = inst.t, cfg = e.cfg;
|
|
568
|
-
const sink = smooth(0, 0.5, t), spread = smooth(0.3, 1.4, t), cfgS = cfg.s;
|
|
569
|
-
void cfgS;
|
|
570
|
-
mx(P, 'gaitW', 0, w); mx(P, 'legGait', 0, w); mx(P, 'bodyOmega', 1.4, w);
|
|
571
|
-
mx(P, 'dropF', lerp(0.4, 1, sink), w); mx(P, 'dropH', lerp(0.3, 1, sink), w);
|
|
572
|
-
mx(P, 'groundW', 1, w);
|
|
573
|
-
mx(P, 'flex', -0.1 * spread, w); mx(P, 'headPitch', 0.15, w); mx(P, 'headLimp', 0.6, w);
|
|
574
|
-
mx(P, 'jaw', 0.08, sink * w); mx(P, 'eyelid', 0.6, sink * w);
|
|
575
|
-
mx(P, 'breathAmp', 0, w); mx(P, 'breathRate', 0, w); mx(P, 'lookW', 0, w);
|
|
576
|
-
const b = B(e); b.f.pump = 0; b.f.retract = Math.max(b.f.retract, 0.5 * sink * w);
|
|
577
|
-
// (the feet stay where they stood, flat on the ground: the limp body sinks between them, the legs
|
|
578
|
-
// folding out to the sides)
|
|
579
|
-
},
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
export const hooks = {
|
|
583
|
-
pose,
|
|
584
|
-
update,
|
|
585
|
-
actions: {
|
|
586
|
-
hop: leapDef({ height: 0.06, distance: 0.3, crouch: 0.16, push: 0.09, land: 0.34, pitch: 0.7, ext: 0.65, fold: 0.45, reachF: 0.01, arcF: 0.008 }),
|
|
587
|
-
jump: leapDef({ height: 0.22, distance: 1.0, crouch: 0.22, push: 0.12, land: 0.45, pitch: 1.0, ext: 0.55, fold: 0.62, reachF: 0.03, arcF: 0.01 }),
|
|
588
|
-
croak, blink, attack, eat, sit, lie, sleep, drink, hit, death,
|
|
589
|
-
},
|
|
590
|
-
};
|