roamwright 0.20.1 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.yaml +12 -0
- package/CONTRIBUTING.md +19 -14
- package/README.md +35 -16
- package/examples/animals.html +49 -0
- package/examples/animals.js +209 -0
- package/examples/crowds.html +50 -0
- package/examples/crowds.js +268 -0
- package/examples/effects.html +53 -0
- package/examples/effects.js +343 -0
- package/examples/figure-motion.html +55 -0
- package/examples/figure-motion.js +265 -0
- package/examples/figure.html +49 -0
- package/examples/figure.js +238 -0
- package/examples/fliers.html +53 -0
- package/examples/fliers.js +292 -0
- package/examples/fortification.html +54 -0
- package/examples/fortification.js +288 -0
- package/examples/house-kit.html +48 -0
- package/examples/house-kit.js +175 -0
- package/examples/index.html +26 -16
- package/examples/island.html +48 -0
- package/examples/island.js +134 -52
- package/examples/land.html +54 -0
- package/examples/land.js +392 -0
- package/examples/props-and-plants.html +53 -0
- package/examples/props-and-plants.js +275 -0
- package/examples/rooms.html +48 -0
- package/examples/rooms.js +242 -0
- package/examples/ships.html +51 -0
- package/examples/ships.js +235 -0
- package/examples/showcase.css +320 -0
- package/examples/small-world-land.js +151 -0
- package/examples/small-world-life.js +160 -0
- package/examples/small-world-town.js +127 -0
- package/examples/small-world.html +57 -0
- package/examples/small-world.js +226 -0
- package/examples/soundscape.html +138 -0
- package/examples/soundscape.js +467 -0
- package/examples/stage-kits.js +300 -0
- package/examples/stage.js +374 -0
- package/examples/towns.html +50 -0
- package/examples/towns.js +325 -0
- package/examples/viaduct-camera.js +8 -4
- package/examples/viaduct-landscape.js +28 -17
- package/examples/viaduct.html +45 -43
- package/examples/viaduct.js +68 -92
- package/geometry/animal-camel-body.js +410 -0
- package/geometry/animal-camel-head.js +118 -0
- package/geometry/animal-canine-body.js +361 -0
- package/geometry/animal-canine-breeds.js +316 -0
- package/geometry/animal-canine-head.js +337 -0
- package/geometry/animal-cattle-body.js +391 -0
- package/geometry/animal-cattle-coat.js +42 -0
- package/geometry/animal-cattle-head.js +152 -0
- package/geometry/animal-hen.js +248 -0
- package/geometry/animal-horse-body.js +446 -0
- package/geometry/animal-horse-bridle.js +171 -0
- package/geometry/animal-horse-coat.js +68 -0
- package/geometry/animal-horse-face.js +162 -0
- package/geometry/animal-horse-hair.js +304 -0
- package/geometry/animal-horse-head.js +133 -0
- package/geometry/animal-horse-tack.js +157 -0
- package/geometry/animal-options.js +59 -0
- package/geometry/animal-shapes.js +21 -0
- package/geometry/animal-skin.js +390 -0
- package/geometry/builder-cells.js +10 -2
- package/geometry/builder-frame.js +2 -1
- package/geometry/builder.js +15 -4
- package/geometry/card-emblem.js +437 -0
- package/geometry/catenary-canvas.js +396 -0
- package/geometry/cloth-folds.js +143 -0
- package/geometry/crawl-shapes.js +71 -0
- package/geometry/creased-sheet.js +7 -2
- package/geometry/crowd-dress.js +315 -0
- package/geometry/crowd-far.js +174 -0
- package/geometry/crowd-look.js +42 -0
- package/geometry/crowd-weld.js +218 -0
- package/geometry/ear.js +9 -4
- package/geometry/erosion.js +7 -4
- package/geometry/face-grid.js +26 -6
- package/geometry/field-map.js +59 -0
- package/geometry/figure-arms.js +339 -0
- package/geometry/figure-beard.js +250 -0
- package/geometry/figure-body.js +297 -0
- package/geometry/figure-bow.js +105 -0
- package/geometry/figure-cloak.js +189 -0
- package/geometry/figure-clothes.js +337 -0
- package/geometry/figure-face-grids.js +75 -0
- package/geometry/figure-gear.js +446 -0
- package/geometry/figure-hair-far.js +151 -0
- package/geometry/figure-hair-hangs.js +108 -0
- package/geometry/figure-hair-patch.js +66 -0
- package/geometry/figure-hair.js +320 -0
- package/geometry/figure-hands.js +321 -0
- package/geometry/figure-head-features.js +280 -0
- package/geometry/figure-head.js +375 -0
- package/geometry/figure-headwear.js +223 -0
- package/geometry/figure-legs.js +231 -0
- package/geometry/figure-limbs.js +39 -0
- package/geometry/figure-sculpt.js +82 -0
- package/geometry/figure-skin.js +97 -0
- package/geometry/figure-skirts.js +303 -0
- package/geometry/figure-trunk.js +411 -0
- package/geometry/flier-corvid-body.js +322 -0
- package/geometry/flier-corvid-wings.js +154 -0
- package/geometry/flier-long-body.js +195 -0
- package/geometry/flier-shapes.js +219 -0
- package/geometry/flier-soaring-bird.js +84 -0
- package/geometry/foliage.js +177 -4
- package/geometry/fort-city-walls.js +479 -0
- package/geometry/fort-gate-approach.js +233 -0
- package/geometry/fort-great-walls.js +280 -0
- package/geometry/fort-keep.js +297 -0
- package/geometry/fort-parts.js +261 -0
- package/geometry/fort-polyline.js +261 -0
- package/geometry/fort-portal.js +96 -0
- package/geometry/fort-ring-wall.js +267 -0
- package/geometry/fort-seawall.js +104 -0
- package/geometry/fort-terrace-gates.js +323 -0
- package/geometry/fort-terrace-plan.js +250 -0
- package/geometry/fort-terrace-wall.js +345 -0
- package/geometry/garment-tags.js +11 -3
- package/geometry/grid-gather.js +69 -0
- package/geometry/grid-sample.js +185 -0
- package/geometry/hair-gathers.js +19 -4
- package/geometry/hair-locks.js +1 -1
- package/geometry/hair-patch.js +6 -2
- package/geometry/hair-shell.js +14 -2
- package/geometry/head-presets.js +103 -0
- package/geometry/head-profile.js +13 -2
- package/geometry/head-shape.js +51 -23
- package/geometry/heightfield.js +26 -9
- package/geometry/horizon-angles.js +166 -0
- package/geometry/house-kit-body.js +195 -0
- package/geometry/house-kit-courtyard-parts.js +340 -0
- package/geometry/house-kit-courtyard-roof.js +223 -0
- package/geometry/house-kit-courtyard.js +409 -0
- package/geometry/house-kit-cut.js +29 -0
- package/geometry/house-kit-extras.js +192 -0
- package/geometry/house-kit-forms.js +298 -0
- package/geometry/house-kit-frame.js +74 -0
- package/geometry/house-kit-marks.js +93 -0
- package/geometry/house-kit-openings.js +193 -0
- package/geometry/house-kit-palette.js +54 -0
- package/geometry/house-kit-pool.js +71 -0
- package/geometry/house-kit-roofs.js +151 -0
- package/geometry/house-kit.js +202 -0
- package/geometry/instances.js +4 -4
- package/geometry/lamp-wash.js +65 -0
- package/geometry/land-clearings.js +83 -0
- package/geometry/land-ditches.js +290 -0
- package/geometry/land-dry-basin.js +327 -0
- package/geometry/land-dunes.js +150 -0
- package/geometry/land-earthworks.js +432 -0
- package/geometry/land-edge.js +292 -0
- package/geometry/land-mound-faces.js +349 -0
- package/geometry/land-near-relief.js +102 -0
- package/geometry/land-sheet.js +220 -0
- package/geometry/land-town-ground.js +256 -0
- package/geometry/land-waters.js +228 -0
- package/geometry/land-wildness.js +123 -0
- package/geometry/lathed-vessel.js +293 -0
- package/geometry/outline-grid.js +5 -4
- package/geometry/outline-segments.js +74 -0
- package/geometry/part-ranges.js +35 -0
- package/geometry/path-field.js +35 -1
- package/geometry/planked-floor.js +149 -0
- package/geometry/plant-broadleaf.js +268 -0
- package/geometry/plant-shrub.js +198 -0
- package/geometry/plant-tints.js +80 -0
- package/geometry/plant-trees.js +453 -0
- package/geometry/plant-tussock.js +107 -0
- package/geometry/primitives.js +65 -23
- package/geometry/prop-battlefield.js +69 -0
- package/geometry/prop-camp.js +175 -0
- package/geometry/prop-door.js +26 -0
- package/geometry/prop-harbour.js +105 -0
- package/geometry/prop-haycock.js +60 -0
- package/geometry/prop-sacks.js +74 -0
- package/geometry/prop-sheaf.js +68 -0
- package/geometry/prop-street.js +69 -0
- package/geometry/prop-tents.js +396 -0
- package/geometry/prop-tombs.js +80 -0
- package/geometry/prop-trade.js +393 -0
- package/geometry/prop-vehicles.js +218 -0
- package/geometry/props.js +58 -0
- package/geometry/room-arcade.js +134 -0
- package/geometry/room-dome.js +188 -0
- package/geometry/room-flames.js +138 -0
- package/geometry/room-frame.js +106 -0
- package/geometry/room-furniture.js +260 -0
- package/geometry/room-hearth.js +98 -0
- package/geometry/room-kit.js +59 -0
- package/geometry/room-openings.js +142 -0
- package/geometry/room-stairs.js +180 -0
- package/geometry/room-surfaces.js +272 -0
- package/geometry/sampled-surface.js +24 -10
- package/geometry/scatter-grid.js +6 -3
- package/geometry/sculpt.js +5 -1
- package/geometry/ship-fittings.js +350 -0
- package/geometry/ship-hull.js +460 -0
- package/geometry/ship-kit.js +208 -0
- package/geometry/ship-lines.js +69 -0
- package/geometry/ship-oars.js +150 -0
- package/geometry/ship-presets.js +131 -0
- package/geometry/ship-rig.js +374 -0
- package/geometry/ship-sails.js +148 -0
- package/geometry/shore-grid.js +5 -1
- package/geometry/strata-field.js +44 -11
- package/geometry/strata-tiles.js +20 -6
- package/geometry/stream.js +32 -17
- package/geometry/swept-tube.js +124 -0
- package/geometry/terrain-chunks.js +139 -51
- package/geometry/terrain-extension.js +24 -8
- package/geometry/town-courtyard-inn.js +272 -0
- package/geometry/town-ground.js +76 -0
- package/geometry/town-houses.js +343 -0
- package/geometry/town-lights.js +254 -0
- package/geometry/town-lots.js +172 -0
- package/geometry/town-plan.js +370 -0
- package/geometry/town-works.js +465 -0
- package/geometry/village-layout.js +181 -0
- package/geometry/village-yards.js +167 -0
- package/geometry/wall-runs.js +64 -0
- package/index.js +134 -3
- package/math/cloud-textures.js +3 -7
- package/math/curve.js +5 -1
- package/math/lamp-texels.js +43 -0
- package/math/lit-share.js +22 -0
- package/math/mountain-ranges.js +177 -54
- package/math/periodic.js +6 -0
- package/math/rectangles.js +8 -2
- package/math/rock-texture.js +17 -12
- package/math/surface-textures.js +24 -9
- package/math/wandering-path.js +40 -0
- package/math/ways.js +120 -0
- package/motion/action-dynamics.js +398 -0
- package/motion/animal-bearing.js +247 -0
- package/motion/animal-canine-bearing.js +178 -0
- package/motion/animal-canine-cast.js +131 -0
- package/motion/animal-cattle-cast.js +64 -0
- package/motion/animal-herd-cast.js +154 -0
- package/motion/animal-horse-still.js +161 -0
- package/motion/animal-troop-cast.js +43 -0
- package/motion/arm-reach.js +3 -2
- package/motion/ballistic-arc.js +182 -2
- package/motion/biped-cycle.js +4 -2
- package/motion/biped-leg.js +4 -1
- package/motion/biped-posture.js +459 -0
- package/motion/biped-stride.js +142 -32
- package/motion/boat-sailing.js +214 -0
- package/motion/contact-transition.js +5 -6
- package/motion/crowd-alarms.js +36 -6
- package/motion/crowd-attention.js +108 -0
- package/motion/crowd-beasts.js +203 -0
- package/motion/crowd-camp.js +295 -0
- package/motion/crowd-figure.js +100 -0
- package/motion/crowd-herd.js +86 -0
- package/motion/crowd-hold.js +130 -0
- package/motion/crowd-pose.js +296 -0
- package/motion/crowd-poses.js +481 -0
- package/motion/crowd-routine.js +44 -14
- package/motion/crowd-town.js +166 -0
- package/motion/crowd-water.js +143 -0
- package/motion/deck-surface.js +4 -2
- package/motion/figure-acts.js +411 -0
- package/motion/figure-arms.js +437 -0
- package/motion/figure-blade-slide.js +149 -0
- package/motion/figure-body-place.js +180 -0
- package/motion/figure-bones.js +118 -0
- package/motion/figure-bow-draw.js +70 -0
- package/motion/figure-fingers.js +215 -0
- package/motion/figure-gaze.js +205 -0
- package/motion/figure-gestures.js +452 -0
- package/motion/figure-grip.js +134 -0
- package/motion/figure-head.js +287 -0
- package/motion/figure-legs.js +264 -0
- package/motion/figure-links.js +293 -0
- package/motion/figure-locomotion.js +391 -0
- package/motion/figure-mount-up.js +180 -0
- package/motion/figure-mount.js +201 -0
- package/motion/figure-pose-frame.js +375 -0
- package/motion/figure-pose-table.js +156 -0
- package/motion/figure-pose.js +343 -0
- package/motion/figure-seat.js +267 -0
- package/motion/figure-sway.js +125 -0
- package/motion/flier-corvid-pose.js +74 -0
- package/motion/flier-flight-air.js +122 -0
- package/motion/flier-flight-echelon.js +164 -0
- package/motion/flier-flight-roost.js +131 -0
- package/motion/flier-swarm-flight.js +252 -0
- package/motion/formation.js +193 -0
- package/motion/instance-sight.js +8 -1
- package/motion/melee-contact.js +143 -0
- package/motion/moorings.js +48 -0
- package/motion/path-steering.js +358 -0
- package/motion/player.js +7 -6
- package/motion/quadruped.js +109 -33
- package/motion/spaces.js +58 -6
- package/motion/speech-cadence.js +304 -0
- package/motion/vessel-motion.js +57 -0
- package/motion/walk-grid.js +235 -0
- package/motion/weather.js +70 -12
- package/motion/wind.js +27 -1
- package/package.json +27 -4
- package/rendering/alpha-mips.js +340 -0
- package/rendering/animal-camel-figure.js +29 -0
- package/rendering/animal-canine-figure.js +59 -0
- package/rendering/animal-cattle-figure.js +36 -0
- package/rendering/animal-horse-figure.js +49 -0
- package/rendering/atmosphere.js +86 -0
- package/rendering/camera-track.js +156 -0
- package/rendering/{road-surface.js → cart-track.js} +40 -11
- package/rendering/caster-motion.js +2 -1
- package/rendering/cell-lod-options.js +46 -0
- package/rendering/cell-lod.js +665 -80
- package/rendering/cloth-material.js +140 -0
- package/rendering/cloud-dome.js +2 -2
- package/rendering/compilation-schedule.js +18 -10
- package/rendering/contact-shadows.js +5 -2
- package/rendering/context.js +47 -8
- package/rendering/crowd-batches.js +420 -0
- package/rendering/crowd-herd.js +198 -0
- package/rendering/crowd-rig.js +132 -0
- package/rendering/crowd-skinning.js +52 -9
- package/rendering/crowd-update.js +419 -0
- package/rendering/crowd-visibility.js +107 -0
- package/rendering/day-cycle-defaults.js +200 -0
- package/rendering/day-cycle.js +487 -0
- package/rendering/daylight.js +1 -3
- package/rendering/detail-range.js +6 -5
- package/rendering/dof.js +11 -4
- package/rendering/effects-frame.js +149 -0
- package/rendering/effects-water-rises.js +221 -0
- package/rendering/energy-stream.js +128 -0
- package/rendering/facade-glass-material.js +105 -0
- package/rendering/far-shadow.js +81 -54
- package/rendering/field-surface.js +138 -0
- package/rendering/figure-shield.js +105 -0
- package/rendering/figure-skeleton.js +329 -0
- package/rendering/fire-light-watch.js +197 -0
- package/rendering/fire-pools.js +148 -0
- package/rendering/flame-sources.js +86 -0
- package/rendering/flier-bird-looks.js +97 -0
- package/rendering/flier-corvid-figure.js +67 -0
- package/rendering/flier-long-body-company.js +169 -0
- package/rendering/flier-swarm.js +186 -0
- package/rendering/flocks.js +6 -2
- package/rendering/garment-material.js +145 -49
- package/rendering/glsl-literal.js +19 -0
- package/rendering/ground-marks.js +316 -0
- package/rendering/hair-strands.js +38 -24
- package/rendering/height-haze.js +80 -33
- package/rendering/height-probe.js +15 -3
- package/rendering/house-kit-meshes.js +124 -0
- package/rendering/interior-bake.js +807 -0
- package/rendering/label-layout.js +13 -3
- package/rendering/label-range.js +5 -2
- package/rendering/lamp-light-map.js +159 -0
- package/rendering/lamp-maps.js +62 -0
- package/rendering/lamp-wash.js +51 -0
- package/rendering/light-budget.js +19 -3
- package/rendering/light-points.js +21 -5
- package/rendering/local-lights.js +27 -7
- package/rendering/material-lod.js +5 -6
- package/rendering/memory-estimate.js +84 -0
- package/rendering/moored-fleet.js +186 -0
- package/rendering/part-costs.js +104 -0
- package/rendering/particle-bursts.js +386 -0
- package/rendering/particle-emitters.js +61 -25
- package/rendering/particle-light-bursts.js +189 -0
- package/rendering/particles.js +134 -34
- package/rendering/pen-flocks.js +118 -0
- package/rendering/piece-batch.js +282 -6
- package/rendering/planar-reflection-options.js +159 -0
- package/rendering/planar-reflection.js +780 -77
- package/rendering/plant-cells.js +122 -0
- package/rendering/plant-reeds.js +113 -0
- package/rendering/plant-shade-trees.js +239 -0
- package/rendering/plant-tuft-patch.js +122 -0
- package/rendering/post-shaders.js +84 -21
- package/rendering/post.js +39 -19
- package/rendering/pressed-cover.js +135 -0
- package/rendering/prop-dig.js +136 -0
- package/rendering/room-light.js +250 -0
- package/rendering/room-materials.js +78 -0
- package/rendering/room-space.js +111 -0
- package/rendering/scene-lights.js +106 -0
- package/rendering/sea-shaders.js +83 -26
- package/rendering/settlement-approach.js +226 -0
- package/rendering/settlement-dissolve.js +89 -0
- package/rendering/settlement-quarter-warm.js +55 -0
- package/rendering/settlement-quarter.js +477 -0
- package/rendering/settlement-switch.js +42 -0
- package/rendering/settlement-town.js +110 -0
- package/rendering/shader-warmup.js +80 -36
- package/rendering/shadow-depth.js +40 -18
- package/rendering/ship-meshes.js +150 -0
- package/rendering/shot-cuts.js +68 -0
- package/rendering/sky-occlusion.js +42 -15
- package/rendering/sky-pmrem.js +216 -0
- package/rendering/sky.js +112 -50
- package/rendering/smoke-shadows.js +201 -0
- package/rendering/stage-framing.js +182 -0
- package/rendering/stage-lights.js +46 -39
- package/rendering/stain-material.js +74 -0
- package/rendering/static-point-shadow.js +62 -23
- package/rendering/still-casters.js +77 -27
- package/rendering/strata-material.js +2 -2
- package/rendering/street-lamps.js +166 -0
- package/rendering/sunbeam-motes.js +670 -0
- package/rendering/surface-light.js +65 -6
- package/rendering/surface-material.js +306 -0
- package/rendering/surface-projection.js +32 -0
- package/rendering/surface-snippets.js +314 -0
- package/rendering/taa.js +49 -18
- package/rendering/tree-impostor.js +929 -0
- package/rendering/vehicle-train.js +92 -0
- package/rendering/viewport.js +67 -4
- package/rendering/water-material.js +270 -82
- package/rendering/waypoint-beacons.js +191 -0
- package/rendering/world-matrices.js +0 -2
- package/ruff.toml +20 -0
- package/runtime/cue-cursor.js +21 -0
- package/runtime/device-quality.js +13 -2
- package/runtime/device.js +73 -0
- package/runtime/diagnostic-log.js +11 -3
- package/runtime/effect-sites.js +85 -0
- package/runtime/figure-orders.js +59 -0
- package/runtime/first-use.js +8 -5
- package/runtime/foley-script.js +124 -0
- package/runtime/foley-strides.js +333 -0
- package/runtime/frame-pacing.js +18 -4
- package/runtime/frame-yield.js +18 -0
- package/runtime/gpu-timing.js +8 -4
- package/runtime/grid-cache.js +16 -6
- package/runtime/grid-rows.js +5 -5
- package/runtime/hand-over.js +7 -2
- package/runtime/land-bake.js +78 -0
- package/runtime/lazy-sets.js +105 -0
- package/runtime/pool.js +17 -3
- package/runtime/quality-fit.js +59 -27
- package/runtime/region-pass-lay.js +40 -0
- package/runtime/region-pass.js +78 -0
- package/runtime/search.js +6 -2
- package/runtime/settlement-reach.js +42 -0
- package/runtime/sound-calls.js +113 -0
- package/runtime/sound-impacts.js +297 -0
- package/runtime/sound-voices.js +194 -0
- package/runtime/soundscape.js +282 -0
- package/runtime/spatial-audio.js +69 -20
- package/runtime/steady-frames.js +221 -0
- package/runtime/withdrawable-task.js +19 -8
- package/scripts/app-parts.mjs +118 -0
- package/scripts/bake-revisions.mjs +81 -0
- package/scripts/browser-scripts.mjs +64 -0
- package/scripts/bundle.mjs +192 -0
- package/scripts/check-app.sh +26 -0
- package/scripts/eslint-config.mjs +119 -0
- package/scripts/format.sh +92 -0
- package/scripts/keep-builds.mjs +158 -0
- package/scripts/layers.mjs +112 -0
- package/scripts/lint.sh +49 -0
- package/scripts/module-graph.mjs +123 -0
- package/scripts/pre-commit.sh +38 -0
- package/scripts/serve.py +5 -3
- package/scripts/site.mjs +358 -0
- package/scripts/test-runner.sh +42 -0
- package/scripts/vendor.mjs +221 -0
- package/scripts/verify-publish.mjs +175 -0
- package/scripts/world.mk +59 -0
- package/tools/README.md +73 -0
- package/tools/contact-sheet.cjs +137 -0
- package/tools/cpu-profile.cjs +275 -0
- package/tools/cpu-profile.test.cjs +98 -0
- package/tools/first-draws.cjs +395 -0
- package/tools/flight-guard.cjs +482 -0
- package/tools/flight-guard.test.cjs +153 -0
- package/tools/flight-profile.cjs +145 -0
- package/tools/frame-bench.cjs +336 -0
- package/tools/frame-parts.cjs +365 -0
- package/tools/ios-sim.sh +145 -0
- package/tools/load-audit.cjs +201 -0
- package/tools/look-compare.cjs +304 -0
- package/tools/look-guard.cjs +407 -0
- package/tools/look-guard.test.cjs +93 -0
- package/tools/look-stats.cjs +185 -0
- package/tools/look-stats.test.cjs +71 -0
- package/tools/memory-audit.cjs +323 -0
- package/tools/page-driver.cjs +320 -0
- package/tools/page-driver.test.cjs +219 -0
- package/tools/program-census-report.cjs +191 -0
- package/tools/program-census.cjs +465 -0
- package/tools/program-census.test.cjs +332 -0
- package/tools/remote-runner.sh +265 -0
- package/tools/runners.test.cjs +59 -0
- package/tools/scene-audit-beat.cjs +344 -0
- package/tools/scene-audit-sheet.cjs +282 -0
- package/tools/scene-audit.cjs +471 -0
- package/tools/scene-audit.test.cjs +201 -0
- package/tools/scene-batch.cjs +219 -0
- package/tools/scene-bench.cjs +149 -0
- package/tools/scene-bench.test.cjs +33 -0
- package/tools/scene-run.cjs +443 -0
- package/tools/scene-run.test.cjs +94 -0
- package/tools/servers.sh +59 -0
- package/tools/shader-arrival.cjs +316 -0
- package/tools/shader-renewal.cjs +53 -0
- package/tools/shader-renewal.test.cjs +115 -0
- package/tools/speed-guard.cjs +258 -0
- package/tools/stills.cjs +492 -0
- package/tools/stills.test.cjs +49 -0
- package/tools/turns.sh +7 -0
- package/tools/yaml.cjs +158 -0
- package/examples/viaduct.css +0 -75
- package/rendering/light-shafts.js +0 -131
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locomotion: how a person (or a beast) goes over the ground. A walk is asked for as a place and a time to be there (newMove);
|
|
3
|
+
* this module curves the path gently out of the actor's initial heading, skirts stationary people within personal space while
|
|
4
|
+
* still arriving on exact mark and duration, turns them at the rate a person turns, measures the ground they really covered
|
|
5
|
+
* (their speed along and across their facing, and the slope underfoot), and gives the stride solver (biped-stride.js) the
|
|
6
|
+
* figure's rig, which banks into turns, dips on push-off and settles on halts, and plants feet across flat ground, stairs, and
|
|
7
|
+
* slopes. Lengths in the stride are figure units (a figure of full size is 1.9 high; multiply by its scale for metres); places
|
|
8
|
+
* and speeds are metres and metres a second.
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { createCloakState, resetCloakState } from './action-dynamics.js';
|
|
12
|
+
import { createBipedStride } from './biped-stride.js';
|
|
13
|
+
import {
|
|
14
|
+
createCurvedPath,
|
|
15
|
+
createMomentumState,
|
|
16
|
+
planCurvedPath,
|
|
17
|
+
resetMomentumState,
|
|
18
|
+
sampleCurvedPath,
|
|
19
|
+
stepLocomotionMomentum,
|
|
20
|
+
} from './path-steering.js';
|
|
21
|
+
import { cycleDelta } from '../math/periodic.js';
|
|
22
|
+
import { TAU, clamp } from '../math/scalar.js';
|
|
23
|
+
import { ANKLE, BALL, HIPS as HIP, SHANK, THIGH } from './figure-bones.js';
|
|
24
|
+
|
|
25
|
+
const TURN_RATE = 4.6, // radians a second someone turns on the spot, at most
|
|
26
|
+
TURN_EASE = 7, // how firmly a turn closes on its mark
|
|
27
|
+
TURN_SPRING = 10, // and how fast it gathers
|
|
28
|
+
TURN_FIRST = 0.58, // the share of a turn made on the spot before curving into the first step
|
|
29
|
+
RAMP = 0.55, // seconds to reach a walk's pace, and to come out of it
|
|
30
|
+
RAMP_SHARE = 0.35, // of a short walk, at most this share each
|
|
31
|
+
TURN_SHARE = 0.22, // and at most this share spent turning before setting off
|
|
32
|
+
PLAIN_MOVE = 0.6, // a move shorter than this in seconds is a shift, not a walk
|
|
33
|
+
ROLLING = 0.5; // metres a second above which a new walk carries on from the old one without a halt
|
|
34
|
+
const TELEPORT = 1.6, // metres in one frame treated as a new placement
|
|
35
|
+
SLOPE_SPAN = 0.45, // metres behind and ahead of a walker between which the ground's rise is measured
|
|
36
|
+
BODY_RADIUS = 0.32, // metres a walker keeps from what it may not walk through
|
|
37
|
+
HEEL = 0.055; // the heel behind the ankle, in figure units
|
|
38
|
+
/**
|
|
39
|
+
* The pace and the feet of a person's walk and run, as biped-stride.js takes them (its `foot` and `pace`): the engine's own,
|
|
40
|
+
* which a world may pass changed (createFigureLocomotion's `stride`).
|
|
41
|
+
* @type {{foot: object, pace: object}}
|
|
42
|
+
*/
|
|
43
|
+
const FIGURE_STRIDE = {
|
|
44
|
+
foot: {
|
|
45
|
+
heelStrike: [0.3, 0.1],
|
|
46
|
+
pushOff: [0.62, 0.8],
|
|
47
|
+
flatAt: 0.16,
|
|
48
|
+
riseAt: 0.5,
|
|
49
|
+
reverseRoll: 0.5,
|
|
50
|
+
response: 26,
|
|
51
|
+
toeReleaseHeight: 0.05,
|
|
52
|
+
sampleAhead: 0.17,
|
|
53
|
+
edgeSlope: 0.6,
|
|
54
|
+
maxSlopeAngle: 0.5,
|
|
55
|
+
groundResponse: [30, 13],
|
|
56
|
+
snapHeight: 1,
|
|
57
|
+
stairSlope: 0.25,
|
|
58
|
+
treadRange: [0.22, 0.5],
|
|
59
|
+
stairMemory: 0.8,
|
|
60
|
+
stairResponse: 3,
|
|
61
|
+
stepClearance: [0.55, 0.16],
|
|
62
|
+
settleSpeed: 1.5,
|
|
63
|
+
settleLift: 0.05,
|
|
64
|
+
},
|
|
65
|
+
pace: {
|
|
66
|
+
baseStep: 0.4,
|
|
67
|
+
stepGain: 0.22,
|
|
68
|
+
maxStep: 1.75,
|
|
69
|
+
walkDuty: 0.54,
|
|
70
|
+
runDuty: 0.27,
|
|
71
|
+
runFrom: 2.7,
|
|
72
|
+
runFull: 3.5,
|
|
73
|
+
runDip: -0.012,
|
|
74
|
+
runBob: 0.03,
|
|
75
|
+
walkLift: 0.085,
|
|
76
|
+
runLift: 0.4,
|
|
77
|
+
hipResponse: 18,
|
|
78
|
+
idleRate: 1.4,
|
|
79
|
+
runLean: 0.2,
|
|
80
|
+
hipTurn: [0.075, 0.13],
|
|
81
|
+
hipDrop: 0.05,
|
|
82
|
+
armLag: 0.04,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* How a robe shortens a stride: its length, its lift and the hips' swing, as shares of an unrobed one.
|
|
87
|
+
* @type {number[]}
|
|
88
|
+
*/
|
|
89
|
+
const ROBED_STRIDE = [0.62, 0.5, 0.6];
|
|
90
|
+
/**
|
|
91
|
+
* Metres a second, taken over a whole move, that nobody is sent faster than: a person afoot, a rider, and any other kind by
|
|
92
|
+
* name (a kind not named is not held back).
|
|
93
|
+
* @type {Object<string, number>}
|
|
94
|
+
*/
|
|
95
|
+
const TOP_PACE = { afoot: 4.6, mounted: 9.5 };
|
|
96
|
+
const FLAT = () => 0,
|
|
97
|
+
NOTHING_IN_THE_WAY = () => false,
|
|
98
|
+
NO_CREATURES = {};
|
|
99
|
+
/**
|
|
100
|
+
* The locomotion of a world's people and beasts. An actor's `x`, `z`, `yaw`, `fixY` (a height a scene holds it at, or
|
|
101
|
+
* null to stand on the ground), `move`, `turn`, `spin`, `speed`, `fwd`, `side`, `slope`, `px`, `pz`, `y` and its stride's
|
|
102
|
+
* `feet`, `hip` and `footGround` are read and written; `kind`, `mount`, `pose`, `seed`, `robe`, `active`, `space`,
|
|
103
|
+
* `primary`, `link` and `hosting` are read.
|
|
104
|
+
* @param {object} [options]
|
|
105
|
+
* @param {function(number, number): number} [options.ground] - The ground's height (metres) at (x, z); flat at 0 by default.
|
|
106
|
+
* @param {function(number, number, number): boolean} [options.collide] - Whether a circle of a radius (metres) at (x, z) meets
|
|
107
|
+
* what may not be walked through (a wall, a stall); nothing, by default.
|
|
108
|
+
* @param {Object<string, number>} [options.topPace] - TOP_PACE, or a world's own.
|
|
109
|
+
* @param {string[]} [options.leggedKinds] - The kinds that walk on legs, turn to face the way and step round people: people
|
|
110
|
+
* ('human') by default. Others glide where they are sent, facing the way.
|
|
111
|
+
* @param {Object<string, {flier?: boolean}>} [options.creatures] - A world's creatures by kind: a flier killed in the air falls
|
|
112
|
+
* faster and faster.
|
|
113
|
+
* @param {{foot: object, pace: object}} [options.stride] - The stride's tuning (FIGURE_STRIDE, or a world's own).
|
|
114
|
+
* @param {number[]} [options.robed] - ROBED_STRIDE, or a world's own.
|
|
115
|
+
* @returns {object} newMove(a, x, z, dur, y, how): a move for actor a to (x, z), to be there in dur seconds (at height y if
|
|
116
|
+
* given), to set as `a.move`; how.back: without turning to face the way (a step back, a sidestep); how.on: another walk
|
|
117
|
+
* follows at once, so this one does not slow to a halt; how.after: seconds before it begins; how.ride: carried there by
|
|
118
|
+
* something that moves (a boat, a wagon), keeping time with it and standing still. travel(a, dt): each frame, takes a along
|
|
119
|
+
* its move and through its turn, sets its height and measures the ground it covered. faceTo(a, yaw): turns it to face a
|
|
120
|
+
* heading, at the rate a person turns. motionOf(a): its steering, momentum and cloak state. stride(a, dt, size, lean, sink,
|
|
121
|
+
* hipZ, stanceL, stanceR, free, list): the stride solver for its legs (biped-stride.js).
|
|
122
|
+
*/
|
|
123
|
+
function createFigureLocomotion({
|
|
124
|
+
ground = FLAT,
|
|
125
|
+
collide = NOTHING_IN_THE_WAY,
|
|
126
|
+
topPace = TOP_PACE,
|
|
127
|
+
leggedKinds = ['human'],
|
|
128
|
+
creatures = NO_CREATURES,
|
|
129
|
+
stride: tuning = FIGURE_STRIDE,
|
|
130
|
+
robed = ROBED_STRIDE,
|
|
131
|
+
} = {}) {
|
|
132
|
+
const legged = new Set(leggedKinds);
|
|
133
|
+
// Per-actor steering, momentum, and cloak state kept outside actor instances so V8 hidden classes remain monomorphic.
|
|
134
|
+
const motionStates = new WeakMap(),
|
|
135
|
+
knownActors = [],
|
|
136
|
+
seenActors = new WeakSet();
|
|
137
|
+
|
|
138
|
+
function registerActor(a) {
|
|
139
|
+
if (!seenActors.has(a) && legged.has(a.kind)) {
|
|
140
|
+
seenActors.add(a);
|
|
141
|
+
knownActors.push(a);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function motionOf(a) {
|
|
146
|
+
let ms = motionStates.get(a);
|
|
147
|
+
if (!ms) {
|
|
148
|
+
ms = {
|
|
149
|
+
path: createCurvedPath(),
|
|
150
|
+
momentum: createMomentumState(),
|
|
151
|
+
cloak: createCloakState(),
|
|
152
|
+
sideSigned: 0,
|
|
153
|
+
groundWas: NaN, // the height stood at a frame ago
|
|
154
|
+
};
|
|
155
|
+
motionStates.set(a, ms);
|
|
156
|
+
}
|
|
157
|
+
return ms;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const flier = a => {
|
|
161
|
+
const creature = creatures[a.kind];
|
|
162
|
+
return !!(creature && creature.flier);
|
|
163
|
+
};
|
|
164
|
+
function isStationaryObstacle(other, self) {
|
|
165
|
+
return (
|
|
166
|
+
other !== self &&
|
|
167
|
+
other.active &&
|
|
168
|
+
other.space === self.space &&
|
|
169
|
+
!(other.primary && other.primary.inScene) &&
|
|
170
|
+
other.speed < 0.25 &&
|
|
171
|
+
!other.move &&
|
|
172
|
+
other.pose !== 'dead' &&
|
|
173
|
+
other.pose !== 'lie' &&
|
|
174
|
+
other.pose !== 'prone' &&
|
|
175
|
+
!other.link &&
|
|
176
|
+
(!self.hosting || self.hosting.subject !== other)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function canPassHere(x, z) {
|
|
181
|
+
return !collide(x, z, BODY_RADIUS);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const _planOpts = {
|
|
185
|
+
backwards: false,
|
|
186
|
+
carried: false,
|
|
187
|
+
rolling: false,
|
|
188
|
+
mounted: false,
|
|
189
|
+
canPass: canPassHere,
|
|
190
|
+
},
|
|
191
|
+
_sampleOpts = {
|
|
192
|
+
personalRadius: 0.75,
|
|
193
|
+
seed: 0.5,
|
|
194
|
+
isObstacle: isStationaryObstacle,
|
|
195
|
+
canPass: canPassHere,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const solveStride = createBipedStride({
|
|
199
|
+
ground,
|
|
200
|
+
rig: { hipHeight: HIP, thigh: THIGH, shin: SHANK, ankleHeight: ANKLE, ballOffset: BALL, heelOffset: HEEL },
|
|
201
|
+
foot: tuning.foot,
|
|
202
|
+
pace: tuning.pace,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
function stride(a, dt, h, lean, sink, hipZ, stanceL, stanceR, free, list) {
|
|
206
|
+
return solveStride(
|
|
207
|
+
a,
|
|
208
|
+
dt,
|
|
209
|
+
h,
|
|
210
|
+
lean,
|
|
211
|
+
sink,
|
|
212
|
+
hipZ,
|
|
213
|
+
stanceL,
|
|
214
|
+
stanceR,
|
|
215
|
+
free,
|
|
216
|
+
list,
|
|
217
|
+
a.robe ? robed[0] : 1,
|
|
218
|
+
a.robe ? robed[1] : 1,
|
|
219
|
+
a.robe ? robed[2] : 1,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// The share of the way covered at share k of the time, with a ramp up over the first `into` and down over the last `out` of it.
|
|
224
|
+
function paced(k, into, out) {
|
|
225
|
+
const top = 1 / (1 - into / 2 - out / 2);
|
|
226
|
+
if (k < into) return (top * k * k) / (2 * into);
|
|
227
|
+
if (k > 1 - out) return 1 - (top * (1 - k) * (1 - k)) / (2 * out);
|
|
228
|
+
return top * (k - into / 2);
|
|
229
|
+
}
|
|
230
|
+
// A walk for actor a to (x, z), to be there in dur seconds, at height y if given. how.back: without turning to face the way
|
|
231
|
+
// (a step back, a sidestep); how.on: another walk follows at once, so this one does not slow to a halt; how.after: seconds
|
|
232
|
+
// before it begins; how.ride: carried there by something that moves (a boat, a wagon), keeping time with it and standing still.
|
|
233
|
+
function newMove(a, x, z, dur, y, how) {
|
|
234
|
+
registerActor(a);
|
|
235
|
+
const metres = Math.hypot(x - a.x, z - a.z),
|
|
236
|
+
ride = !!(how && how.ride),
|
|
237
|
+
// Nobody is carried over the ground faster than their legs, or their horse's, could take them: a script that allows too
|
|
238
|
+
// little time for the way is given the time the way takes at a hard run or a gallop, and its mover arrives late. (Asked for
|
|
239
|
+
// 150 m in 4 s, a rider crossed the picture at 40 m/s.)
|
|
240
|
+
most = ride ? Infinity : a.kind === 'human' ? (a.mount ? topPace.mounted : topPace.afoot) : (topPace[a.kind] ?? Infinity),
|
|
241
|
+
span = Math.max(0.01, dur, metres / most),
|
|
242
|
+
far = metres > 0.2,
|
|
243
|
+
legs = legged.has(a.kind),
|
|
244
|
+
back = !!(how && how.back),
|
|
245
|
+
walk = legs && far && span >= PLAIN_MOVE && !ride,
|
|
246
|
+
rolling = a.speed > ROLLING,
|
|
247
|
+
ms = motionOf(a);
|
|
248
|
+
let wait = (how && how.after) || 0;
|
|
249
|
+
if (far && !ride && !back) {
|
|
250
|
+
const to = Math.atan2(x - a.x, z - a.z);
|
|
251
|
+
if (legs) {
|
|
252
|
+
a.turn = to;
|
|
253
|
+
if (walk && !rolling) wait += Math.min((Math.abs(turnBetween(a.yaw, to)) / TURN_RATE) * TURN_FIRST, span * TURN_SHARE);
|
|
254
|
+
} else a.yaw = to;
|
|
255
|
+
}
|
|
256
|
+
_planOpts.backwards = back || !walk;
|
|
257
|
+
_planOpts.carried = ride;
|
|
258
|
+
_planOpts.rolling = rolling;
|
|
259
|
+
_planOpts.mounted = !!a.mount;
|
|
260
|
+
planCurvedPath(a.x, a.z, x, z, a.yaw, _planOpts, ms.path);
|
|
261
|
+
|
|
262
|
+
const ramp = walk ? Math.min(RAMP / (span - wait), RAMP_SHARE) : 0;
|
|
263
|
+
return {
|
|
264
|
+
x0: a.x,
|
|
265
|
+
z0: a.z,
|
|
266
|
+
y0: a.fixY,
|
|
267
|
+
x1: x,
|
|
268
|
+
z1: z,
|
|
269
|
+
y1: y === undefined ? a.fixY : y,
|
|
270
|
+
t: 0,
|
|
271
|
+
dur: span,
|
|
272
|
+
wait,
|
|
273
|
+
walk,
|
|
274
|
+
ride,
|
|
275
|
+
back,
|
|
276
|
+
customFace: false,
|
|
277
|
+
into: rolling ? 0 : ramp,
|
|
278
|
+
out: how && how.on ? 0 : ramp,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
// Turns actor a to face yaw, at the rate a person turns.
|
|
282
|
+
function faceTo(a, yaw) {
|
|
283
|
+
a.turn = yaw;
|
|
284
|
+
if (a.move) a.move.customFace = true;
|
|
285
|
+
}
|
|
286
|
+
// The rise of the ground actor a is crossing, per metre gone, this frame. On open ground it is read over a body's length,
|
|
287
|
+
// from a pace behind to a pace ahead, so that a stone or a rut underfoot is not taken for a hill: read from one frame's two
|
|
288
|
+
// centimetres instead, uneven ground gave slopes of a half and more, and everyone crossing a plain walked in a crouch with
|
|
289
|
+
// short high steps. Held at a height (a deck, a roof, a stair a script climbs), it is how far that height has changed.
|
|
290
|
+
function riseUnder(a, dx, dz, gone, y, teleported, ms) {
|
|
291
|
+
const was = ms ? ms.groundWas : y;
|
|
292
|
+
if (ms) ms.groundWas = y;
|
|
293
|
+
if (gone <= 0.004 || teleported) return 0;
|
|
294
|
+
if (a.fixY !== null) return Number.isNaN(was) ? 0 : clamp((y - was) / gone, -1, 1);
|
|
295
|
+
const ux = (dx / gone) * SLOPE_SPAN,
|
|
296
|
+
uz = (dz / gone) * SLOPE_SPAN;
|
|
297
|
+
return clamp((ground(a.x + ux, a.z + uz) - ground(a.x - ux, a.z - uz)) / (2 * SLOPE_SPAN), -1, 1);
|
|
298
|
+
}
|
|
299
|
+
// Each frame: takes actor a along its walk and through its turn, sets its height, and measures the ground it really covered
|
|
300
|
+
// (a.speed, and for people a.fwd along their facing and a.side across it, which the legs step to).
|
|
301
|
+
function travel(a, dt) {
|
|
302
|
+
registerActor(a);
|
|
303
|
+
const ms = a.kind === 'human' ? motionOf(a) : null;
|
|
304
|
+
if (ms && a.feet === null && Number.isNaN(a.hip)) {
|
|
305
|
+
resetMomentumState(ms.momentum);
|
|
306
|
+
resetCloakState(ms.cloak);
|
|
307
|
+
ms.sideSigned = 0;
|
|
308
|
+
}
|
|
309
|
+
const m = a.move;
|
|
310
|
+
let pace = 0;
|
|
311
|
+
if (m) {
|
|
312
|
+
m.t += dt;
|
|
313
|
+
const k = clamp((m.t - m.wait) / (m.dur - m.wait), 0, 1),
|
|
314
|
+
e = m.walk ? paced(k, m.into, m.out) : flier(a) && a.pose === 'dead' ? k * k : k * k * (3 - 2 * k); // a flier killed in the air falls faster and faster
|
|
315
|
+
if (m.walk && !m.ride && !m.back && ms) {
|
|
316
|
+
_sampleOpts.seed = a.seed;
|
|
317
|
+
const sample = sampleCurvedPath(ms.path, e, a.mount ? null : knownActors, a, dt, _sampleOpts);
|
|
318
|
+
a.x = sample.x;
|
|
319
|
+
a.z = sample.z;
|
|
320
|
+
if (k > 0 && k < 0.97 && !m.customFace) a.turn = sample.heading;
|
|
321
|
+
} else {
|
|
322
|
+
a.x = m.x0 + (m.x1 - m.x0) * e;
|
|
323
|
+
a.z = m.z0 + (m.z1 - m.z0) * e;
|
|
324
|
+
}
|
|
325
|
+
if (m.y1 !== null && m.y1 !== undefined) {
|
|
326
|
+
const from = m.y0 ?? ground(m.x0, m.z0);
|
|
327
|
+
a.fixY = from + (m.y1 - from) * e;
|
|
328
|
+
}
|
|
329
|
+
pace = k < 1 && !m.ride ? Math.hypot(m.x1 - m.x0, m.z1 - m.z0) / m.dur : 0;
|
|
330
|
+
if (m.ride) {
|
|
331
|
+
// carried: no ground is covered on foot
|
|
332
|
+
a.px = a.x;
|
|
333
|
+
a.pz = a.z;
|
|
334
|
+
}
|
|
335
|
+
if (k >= 1) a.move = null;
|
|
336
|
+
}
|
|
337
|
+
if (!Number.isNaN(a.turn)) {
|
|
338
|
+
const left = turnBetween(a.yaw, a.turn),
|
|
339
|
+
rate = a.mount ? TURN_RATE * 0.5 : TURN_RATE;
|
|
340
|
+
a.spin += (clamp(left * TURN_EASE, -rate, rate) - a.spin) * Math.min(1, dt * TURN_SPRING);
|
|
341
|
+
a.yaw += Math.abs(a.spin * dt) > Math.abs(left) ? left : a.spin * dt;
|
|
342
|
+
if (Math.abs(left) < 0.004 && Math.abs(a.spin) < 0.08) {
|
|
343
|
+
a.yaw = a.turn;
|
|
344
|
+
a.turn = NaN;
|
|
345
|
+
a.spin = 0;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const y = a.fixY !== null ? a.fixY : ground(a.x, a.z),
|
|
349
|
+
dx = a.x - a.px,
|
|
350
|
+
dz = a.z - a.pz,
|
|
351
|
+
gone = Math.sqrt(dx * dx + dz * dz);
|
|
352
|
+
if (a.kind !== 'human') a.speed = pace;
|
|
353
|
+
else if (dt > 1e-4) {
|
|
354
|
+
// people are measured, so that whatever moves them (a walk, a blow that drives them back, a duel's circling) moves their feet
|
|
355
|
+
const k = Math.min(1, dt * 14),
|
|
356
|
+
teleported = gone > TELEPORT,
|
|
357
|
+
still = teleported || gone < 1e-5,
|
|
358
|
+
sy = Math.sin(a.yaw),
|
|
359
|
+
cy = Math.cos(a.yaw),
|
|
360
|
+
sideRaw = still ? 0 : (dx * cy - dz * sy) / dt;
|
|
361
|
+
if (teleported && ms) {
|
|
362
|
+
resetMomentumState(ms.momentum);
|
|
363
|
+
resetCloakState(ms.cloak);
|
|
364
|
+
ms.sideSigned = 0;
|
|
365
|
+
}
|
|
366
|
+
a.speed += ((still ? 0 : gone / dt) - a.speed) * k;
|
|
367
|
+
a.fwd += ((still ? 0 : (dx * sy + dz * cy) / dt) - a.fwd) * k;
|
|
368
|
+
a.side += (Math.abs(sideRaw) - a.side) * k;
|
|
369
|
+
a.slope += (riseUnder(a, dx, dz, gone, y, teleported, ms) - a.slope) * Math.min(1, dt * 5);
|
|
370
|
+
if (ms) {
|
|
371
|
+
ms.sideSigned += (sideRaw - ms.sideSigned) * k;
|
|
372
|
+
stepLocomotionMomentum(ms.momentum, a.fwd, ms.sideSigned, a.spin, dt);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
a.px = a.x;
|
|
376
|
+
a.pz = a.z;
|
|
377
|
+
a.y = y;
|
|
378
|
+
}
|
|
379
|
+
return { faceTo, motionOf, newMove, stride, travel };
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* The smallest turn from one heading to another, in radians (to the left is more).
|
|
383
|
+
* @param {number} from - Radians.
|
|
384
|
+
* @param {number} to - Radians.
|
|
385
|
+
* @returns {number} Radians, between -π and π.
|
|
386
|
+
*/
|
|
387
|
+
function turnBetween(from, to) {
|
|
388
|
+
return cycleDelta(from, to, TAU);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export { FIGURE_STRIDE, ROBED_STRIDE, TOP_PACE, createFigureLocomotion, turnBetween };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Getting into the saddle and down from it. A rider mounts from the near side: turns to the horse, sets the near foot in the stirrup
|
|
3
|
+
* with both hands on the saddle, rises on that leg until they stand in the stirrup, leaning over the horse's back, swings the
|
|
4
|
+
* far leg over the croup and settles into the seat; getting down is the same the other way round. The horse stands in the
|
|
5
|
+
* world meanwhile, not carried by its rider's figure, and a rider who has got down leaves it standing there (`a.beside`) until
|
|
6
|
+
* they mount again or the scene ends.
|
|
7
|
+
*
|
|
8
|
+
* The way up is a row of moments (KEYS, at the shares AT of the whole), each a place beside or over the horse and the limbs'
|
|
9
|
+
* angles there; between them the figure eases from one to the next. Before the rider is astride (ASTRIDE_FROM) the figure is
|
|
10
|
+
* posed as someone on foot, after it as a rider (figure-pose.js), and these moments are laid over either as far as `hold`
|
|
11
|
+
* says: wholly through the middle, where the one gives way to the other, not at all at the ends. Lengths are metres beside
|
|
12
|
+
* the horse and figure units in the body; angles radians.
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import { TAU, clamp, lerp, sstep } from '../math/scalar.js';
|
|
16
|
+
import { TRUNK } from './figure-pose-table.js';
|
|
17
|
+
import { saddleHips } from './figure-seat.js';
|
|
18
|
+
import { carryHorse, standHorse } from './figure-mount.js';
|
|
19
|
+
|
|
20
|
+
const UP_TAKES = 2.7, // seconds to mount, and to get down
|
|
21
|
+
DOWN_TAKES = 2.3,
|
|
22
|
+
ASTRIDE_FROM = 0.45, // the share of the way up from which the rider is in the saddle's keeping
|
|
23
|
+
AT = [0, 0.2, 0.45, 0.7, 0.88, 1], // on the ground; a foot in the stirrup; standing in it; a leg over the croup; coming down into the seat; seated
|
|
24
|
+
KEYS = {
|
|
25
|
+
side: [-0.62, -0.6, -0.38, -0.12, 0, 0], // to the near side of the horse's middle (less is nearer side)
|
|
26
|
+
ahead: [0.12, 0.12, 0.08, 0.02, 0, 0], // forward of the saddle
|
|
27
|
+
turn: [1.2, 1.2, 0.95, 0.3, 0, 0], // turned toward the horse from the way it faces
|
|
28
|
+
up: [0, 0, 0.3, 0.24, 0.05, 0], // metres the figure is lifted: above its standing height, then above its seat
|
|
29
|
+
lean: [0, 0.12, 0.38, 0.3, 0.1, 0], // the trunk forward, over the horse's back
|
|
30
|
+
thighL: [0, -1.3, -0.3, -0.75, -1.1, -1.1], // the near leg: up to the stirrup, straightening as it lifts the body, then bent astride
|
|
31
|
+
kneeL: [0, 1.45, 0.4, 0.9, 0.9, 0.9],
|
|
32
|
+
outL: [0, 0, -0.05, -0.3, -0.5, -0.55],
|
|
33
|
+
thighR: [0, 0.05, 0.3, 0.75, -0.5, -1.1], // the far leg: pushing off, trailing, swung back and out over the croup, down astride
|
|
34
|
+
kneeR: [0, 0.1, 0.25, 0.5, 0.8, 0.9],
|
|
35
|
+
outR: [0, 0, 0.1, 1.3, 0.9, 0.55],
|
|
36
|
+
hold: [0, 1, 1, 1, 0.5, 0], // how far these moments are laid over the pose under them, and the hands on the saddle
|
|
37
|
+
hands: [0, 1, 1, 1, 0.4, 0],
|
|
38
|
+
},
|
|
39
|
+
HANDS = { arm: [-1.05, -0.9], fore: [-0.7, -0.85], out: 0.14 }, // both hands on the saddle, the near one on the pommel: upper arms and elbows [near, far], and how far out
|
|
40
|
+
TRAILING_FOOT = 0.25, // the far foot hangs a little while it is in the air
|
|
41
|
+
FOOT_BENDS = [-0.8, 1.2],
|
|
42
|
+
COMES_TO = 0.2; // the share of the way up over which a rider who stood elsewhere beside the horse comes to the stirrup
|
|
43
|
+
|
|
44
|
+
// A row of KEYS at share u of the way up: a curve through its moments that does not halt at each (Catmull and Rom's).
|
|
45
|
+
function keyed(row, u) {
|
|
46
|
+
let i = 0;
|
|
47
|
+
while (i < AT.length - 2 && u >= AT[i + 1]) i++;
|
|
48
|
+
const t = (u - AT[i]) / (AT[i + 1] - AT[i]),
|
|
49
|
+
before = row[Math.max(0, i - 1)],
|
|
50
|
+
from = row[i],
|
|
51
|
+
to = row[i + 1],
|
|
52
|
+
after = row[Math.min(AT.length - 1, i + 2)];
|
|
53
|
+
return from + 0.5 * t * (to - before + t * (2 * before - 5 * from + 4 * to - after + t * (3 * (from - to) + after - before)));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The rider gets down: the horse stays where it stands.
|
|
57
|
+
* @param {object} a - A mounted actor (`mount`); `mounting` is set while it lasts.
|
|
58
|
+
*/
|
|
59
|
+
function getDown(a) {
|
|
60
|
+
if (!a.mount || a.mounting) return;
|
|
61
|
+
const horse = a.mount;
|
|
62
|
+
a.steed ??= horse;
|
|
63
|
+
standHorse(a, horse);
|
|
64
|
+
horse.x = a.x;
|
|
65
|
+
horse.z = a.z;
|
|
66
|
+
horse.yaw = a.yaw;
|
|
67
|
+
a.move = null;
|
|
68
|
+
a.mounting = { u: 1, up: false, side: 0, ahead: 0, turn: 0, side0: 0, ahead0: 0, turn0: 0 };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The rider mounts the horse that stands beside them (`a.beside`), from wherever beside it they are.
|
|
72
|
+
* @param {object} a - The actor; `mounting` is set while it lasts.
|
|
73
|
+
*/
|
|
74
|
+
function getUp(a) {
|
|
75
|
+
const horse = a.beside;
|
|
76
|
+
if (!horse || a.mounting) return;
|
|
77
|
+
const cy = Math.cos(horse.yaw),
|
|
78
|
+
sy = Math.sin(horse.yaw),
|
|
79
|
+
dx = a.x - horse.x,
|
|
80
|
+
dz = a.z - horse.z,
|
|
81
|
+
turn = a.yaw - horse.yaw;
|
|
82
|
+
a.mounting = {
|
|
83
|
+
u: 0,
|
|
84
|
+
up: true,
|
|
85
|
+
side: 0,
|
|
86
|
+
ahead: 0,
|
|
87
|
+
turn: 0,
|
|
88
|
+
side0: dx * cy - dz * sy,
|
|
89
|
+
ahead0: dx * sy + dz * cy,
|
|
90
|
+
turn0: turn - Math.round(turn / TAU) * TAU,
|
|
91
|
+
};
|
|
92
|
+
// from here on the rider's place is the horse's, and the figure is set beside it
|
|
93
|
+
a.x = a.px = horse.x;
|
|
94
|
+
a.z = a.pz = horse.z;
|
|
95
|
+
a.yaw = horse.yaw;
|
|
96
|
+
a.turn = NaN;
|
|
97
|
+
a.move = null;
|
|
98
|
+
}
|
|
99
|
+
// The way is done: in the saddle the figure carries the horse again; on the ground the rider's place is where they stand.
|
|
100
|
+
function finish(a, m) {
|
|
101
|
+
a.mounting = null;
|
|
102
|
+
if (m.up) carryHorse(a, a.mount);
|
|
103
|
+
else {
|
|
104
|
+
const cy = Math.cos(a.yaw),
|
|
105
|
+
sy = Math.sin(a.yaw);
|
|
106
|
+
a.x = a.px = a.x + m.side * cy + m.ahead * sy;
|
|
107
|
+
a.z = a.pz = a.z - m.side * sy + m.ahead * cy;
|
|
108
|
+
a.yaw += m.turn;
|
|
109
|
+
a.turn = NaN;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* One frame of the way up or down, laid over the figure as the frame's steps have posed it (after the arms are placed, before
|
|
114
|
+
* the body is): the legs, the feet, the hands on the saddle, the trunk's lean and the figure's height.
|
|
115
|
+
* @param {object} a - The actor.
|
|
116
|
+
* @param {object} w - The frame's work record (figure-pose.js).
|
|
117
|
+
* @param {number} dt - Seconds since the last frame.
|
|
118
|
+
*/
|
|
119
|
+
function mounting(a, w, dt) {
|
|
120
|
+
const m = a.mounting;
|
|
121
|
+
if (!m) return;
|
|
122
|
+
if (a.pose === 'dead') {
|
|
123
|
+
a.mounting = null; // killed on the way: the body falls where it is, and the horse stands (figure-mount.js)
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
m.u = clamp(m.u + (m.up ? dt / UP_TAKES : -dt / DOWN_TAKES), 0, 1);
|
|
127
|
+
const u = m.u,
|
|
128
|
+
astride = u >= ASTRIDE_FROM;
|
|
129
|
+
if (astride && !a.mount) {
|
|
130
|
+
a.mount = a.beside; // the saddle takes its rider,
|
|
131
|
+
a.beside = null;
|
|
132
|
+
} else if (!astride && a.mount) {
|
|
133
|
+
a.beside = a.mount; // or lets them go
|
|
134
|
+
a.mount = null;
|
|
135
|
+
}
|
|
136
|
+
const horse = a.mount || a.beside,
|
|
137
|
+
hold = clamp(keyed(KEYS.hold, u), 0, 1),
|
|
138
|
+
hands = clamp(keyed(KEYS.hands, u), 0, 1),
|
|
139
|
+
come = m.up ? sstep(0, COMES_TO, u) : 1,
|
|
140
|
+
thighL = keyed(KEYS.thighL, u),
|
|
141
|
+
kneeL = keyed(KEYS.kneeL, u),
|
|
142
|
+
lean = keyed(KEYS.lean, u) - a.cur[TRUNK];
|
|
143
|
+
m.side = lerp(m.side0, keyed(KEYS.side, u), come);
|
|
144
|
+
m.ahead = lerp(m.ahead0, keyed(KEYS.ahead, u), come);
|
|
145
|
+
m.turn = lerp(m.turn0, keyed(KEYS.turn, u), come);
|
|
146
|
+
w.lean = lerp(w.lean, lean, hold);
|
|
147
|
+
w.rise = lerp(w.rise, saddleHips(horse, w.size) * sstep(ASTRIDE_FROM, 1, u) + keyed(KEYS.up, u) / w.size, hold);
|
|
148
|
+
a.legL.rotation.x = lerp(a.legL.rotation.x, thighL, hold);
|
|
149
|
+
a.shinL.rotation.x = lerp(a.shinL.rotation.x, kneeL, hold);
|
|
150
|
+
a.legL.rotation.z = lerp(a.legL.rotation.z, keyed(KEYS.outL, u), hold);
|
|
151
|
+
a.legR.rotation.x = lerp(a.legR.rotation.x, keyed(KEYS.thighR, u), hold);
|
|
152
|
+
a.shinR.rotation.x = lerp(a.shinR.rotation.x, keyed(KEYS.kneeR, u), hold);
|
|
153
|
+
a.legR.rotation.z = lerp(a.legR.rotation.z, keyed(KEYS.outR, u), hold);
|
|
154
|
+
// the near sole lies level in the stirrup; the far foot hangs
|
|
155
|
+
a.footL.rotation.x = lerp(a.footL.rotation.x, clamp(-(a.cur[TRUNK] + w.lean + thighL + kneeL), FOOT_BENDS[0], FOOT_BENDS[1]), hold);
|
|
156
|
+
a.footR.rotation.x = lerp(a.footR.rotation.x, TRAILING_FOOT, hold);
|
|
157
|
+
a.armL.rotation.x = lerp(a.armL.rotation.x, HANDS.arm[0], hands);
|
|
158
|
+
a.armR.rotation.x = lerp(a.armR.rotation.x, HANDS.arm[1], hands);
|
|
159
|
+
a.armL.rotation.z = lerp(a.armL.rotation.z, HANDS.out, hands);
|
|
160
|
+
a.armR.rotation.z = lerp(a.armR.rotation.z, -HANDS.out, hands);
|
|
161
|
+
a.foreL.rotation.x = lerp(a.foreL.rotation.x, HANDS.fore[0], hands);
|
|
162
|
+
a.foreR.rotation.x = lerp(a.foreR.rotation.x, HANDS.fore[1], hands);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Sets the figure beside or over its horse once the body is placed, and ends the way when it is done.
|
|
166
|
+
* @param {object} a - The actor.
|
|
167
|
+
*/
|
|
168
|
+
function placeMounting(a) {
|
|
169
|
+
const m = a.mounting;
|
|
170
|
+
if (!m) return;
|
|
171
|
+
const g = a.group,
|
|
172
|
+
cy = Math.cos(a.yaw),
|
|
173
|
+
sy = Math.sin(a.yaw);
|
|
174
|
+
g.position.x += m.side * cy + m.ahead * sy;
|
|
175
|
+
g.position.z += -m.side * sy + m.ahead * cy;
|
|
176
|
+
g.rotation.y += m.turn;
|
|
177
|
+
if (m.up ? m.u >= 1 : m.u <= 0) finish(a, m);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { getDown, getUp, mounting, placeMounting };
|