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,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a kind of small light is: its linear colour, its strength at night in candela, the share of that it keeps by day, how
|
|
3
|
+
* it flickers (0 steady, 1 a fire, 2 a lantern's wick) and whether it lays a pool on the ground where no real light lights it
|
|
4
|
+
* (`createFirePools`). A world passes its own table to `createFlameSources` to add kinds of its own.
|
|
5
|
+
*/
|
|
6
|
+
export const FLAME_KINDS = {
|
|
7
|
+
fire: { col: [1, 0.54, 0.23], power: 60, day: 0.13, flicker: 1, pool: true },
|
|
8
|
+
brazier: { col: [1, 0.5, 0.2], power: 40, day: 0.1, flicker: 1, pool: true },
|
|
9
|
+
lantern: { col: [1, 0.68, 0.36], power: 7, day: 0, flicker: 2, pool: false },
|
|
10
|
+
glow: { col: [0.7, 0.75, 1], power: 40, day: 1, flicker: 0, pool: false }, // a steady light that is as strong by day
|
|
11
|
+
flash: { col: [0.7, 0.75, 1], power: 40, day: 0.15, flicker: 0, pool: false }, // a brief burst: by day the sun all but drowns it
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Makes the records `createLightBudget` chooses among, one of one shape for every fire, brazier, lantern and flash that lights
|
|
16
|
+
* what is round it. A site (any object with x, y, z in metres) says its kind and, if it wants, its strength (`light`: a number
|
|
17
|
+
* of `lightUnit`s; a fire is otherwise as strong as its flames are big, by `size`), its height over the site (`lift`), its colour
|
|
18
|
+
* (`tint`: three numbers), that it lays no pool (`pool: false`), the space it is in (`space`), and, for one that dies away by
|
|
19
|
+
* itself, when it was lit (`born`, seconds of the caller's clock) and for how long (`life`).
|
|
20
|
+
*
|
|
21
|
+
* @param {object} [options]
|
|
22
|
+
* @param {Record<string, { col: number[], power: number, day: number, flicker: number, pool: boolean }>} [options.kinds=FLAME_KINDS]
|
|
23
|
+
* @param {number} [options.poolSpread=1.3] A pool's radius, in metres, over the square root of its flame's strength in candela.
|
|
24
|
+
* @param {number} [options.lightUnit=30] Candela: a site's own strength (`light`) is in these, the light of a small fire.
|
|
25
|
+
* @param {number} [options.sizeOne=0.6] Metres: a fire whose flames are this size has its kind's own strength; a smaller or
|
|
26
|
+
* larger fire less or more.
|
|
27
|
+
* @param {string} [options.space='world'] The space of a site that names none.
|
|
28
|
+
* @returns {{ sourceOf: (site: object, kind: string, lift: number) => object, flicker: (source: object, t: number) => number,
|
|
29
|
+
* hourShare: (source: object, night: number) => number }}
|
|
30
|
+
*/
|
|
31
|
+
export function createFlameSources({ kinds = FLAME_KINDS, poolSpread = 1.3, lightUnit = 30, sizeOne = 0.6, space = 'world' } = {}) {
|
|
32
|
+
/**
|
|
33
|
+
* The record of a site: `kind` is the kind it is unless the site names its own (`site.kind`), `lift` the height of its light
|
|
34
|
+
* over the site unless the site names its own (`site.lift`).
|
|
35
|
+
*/
|
|
36
|
+
function sourceOf(site, kind, lift) {
|
|
37
|
+
const k = kinds[site.kind ?? kind],
|
|
38
|
+
sized = kind === 'fire' && site.size ? Math.min(1.8, Math.max(0.25, site.size / sizeOne)) : 1,
|
|
39
|
+
power = typeof site.light === 'number' ? site.light * lightUnit : k.power * sized,
|
|
40
|
+
tint = site.tint ?? k.col;
|
|
41
|
+
return {
|
|
42
|
+
space: site.space || space,
|
|
43
|
+
x: site.x,
|
|
44
|
+
y: site.y + (site.lift ?? lift),
|
|
45
|
+
z: site.z,
|
|
46
|
+
base: site.y, // the site's own height: where its flames are
|
|
47
|
+
r: tint[0],
|
|
48
|
+
g: tint[1],
|
|
49
|
+
b: tint[2],
|
|
50
|
+
power,
|
|
51
|
+
day: k.day,
|
|
52
|
+
flicker: k.flicker,
|
|
53
|
+
phase: (Math.abs(site.x * 0.37 + site.z * 0.23) % 6.283) + 0.5,
|
|
54
|
+
reach: Math.min(40, Math.max(10, Math.sqrt(power) * 5)), // metres: where its real light is cut off
|
|
55
|
+
pool: k.pool && site.pool !== false ? 1 : 0, // 1: it may lay a pool, not yet placed; 2: placed; 0: none
|
|
56
|
+
poolR: Math.sqrt(power) * poolSpread,
|
|
57
|
+
poolY: 0, // where its pool lies, and the ground's slope there
|
|
58
|
+
nx: 0,
|
|
59
|
+
nz: 0,
|
|
60
|
+
on: 1, // the share of its strength it gives: a flash dies away
|
|
61
|
+
born: site.born ?? 0,
|
|
62
|
+
life: site.life ?? 0, // seconds, or 0: it burns until it is taken away
|
|
63
|
+
pick: -1, // the round of choosing that last chose it for a real light
|
|
64
|
+
held: -1, // the real light that holds it, or -1
|
|
65
|
+
score: 0, // how much light it throws on what is in view, as last reckoned
|
|
66
|
+
share: 0, // how far up that light is faded: its pool fades out as the light fades in
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* How bright a flame is now, as a share of its strength: a few smooth waves, never a new random value each frame (which reads
|
|
72
|
+
* as shaking). `t` in seconds.
|
|
73
|
+
*/
|
|
74
|
+
function flicker(source, t) {
|
|
75
|
+
const p = source.phase;
|
|
76
|
+
if (source.flicker === 1)
|
|
77
|
+
return 0.8 + 0.2 * (0.5 * Math.sin(t * 7.1 + p) + 0.3 * Math.sin(t * 12.7 + p * 1.7) + 0.2 * Math.sin(t * 19.3 + p * 2.9));
|
|
78
|
+
if (source.flicker === 2) return 0.93 + 0.07 * (0.6 * Math.sin(t * 5.3 + p) + 0.4 * Math.sin(t * 8.9 + p * 2));
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The share of its strength a flame gives at this hour (`night`: 0 by day, 1 at night) and as `on` has it. */
|
|
83
|
+
const hourShare = (source, night) => source.on * (source.day + (1 - source.day) * night);
|
|
84
|
+
|
|
85
|
+
return { sourceOf, flicker, hourShare };
|
|
86
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { SHOULDER, WRIST } from './flocks.js';
|
|
2
|
+
|
|
3
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
4
|
+
// Looks of common birds for a flock (`createFlock`'s `look`): a crow, a gull and a vulture.
|
|
5
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Looks of a flock's birds. A wing's rows run across it from the leading edge to the trailing one [x, y, z of the front, x, y, z
|
|
9
|
+
* of the back], the arm out to the wrist and the hand out to the tip; its fingers are the outer primaries' tips, notched apart
|
|
10
|
+
* [x, z where one leaves the wing, and how far its tip lies out and forward of there]; tail: how far back its middle reaches and
|
|
11
|
+
* how wide its end is. colours (linear) of the body, the head, the arm, the hand and the wingtips (beyond `tips` out), or none for
|
|
12
|
+
* a bird of the flock's one colour; under: the arm's and the hand's colours on the wing's under face, where they differ from the
|
|
13
|
+
* upper (the tips are the same on both). beat: its wingbeats a second; gloss: its plumage's roughness, where it differs from the
|
|
14
|
+
* flock's. soar: a bird that rides the air on held wings and seldom beats them; silent: one that does not call.
|
|
15
|
+
*/
|
|
16
|
+
export const BIRD_LOOKS = {
|
|
17
|
+
crow: {
|
|
18
|
+
arm: [
|
|
19
|
+
[SHOULDER, 0.02, 0.28, SHOULDER, 0.02, -0.22],
|
|
20
|
+
[0.48, 0.05, 0.32, 0.48, 0.03, -0.36],
|
|
21
|
+
[WRIST, 0.04, 0.3, WRIST, 0.02, -0.34],
|
|
22
|
+
],
|
|
23
|
+
hand: [
|
|
24
|
+
[WRIST, 0.04, 0.3, WRIST, 0.02, -0.34],
|
|
25
|
+
[1.15, 0.03, 0.2, 1.1, 0.01, -0.36],
|
|
26
|
+
[1.45, 0.02, 0.06, 1.38, 0, -0.24],
|
|
27
|
+
[1.62, 0, -0.08, 1.62, 0, -0.08],
|
|
28
|
+
],
|
|
29
|
+
fingers: [
|
|
30
|
+
[1.32, -0.2, 0.02, -0.22],
|
|
31
|
+
[1.44, -0.14, 0.02, -0.2],
|
|
32
|
+
[1.54, -0.1, 0.02, -0.16],
|
|
33
|
+
],
|
|
34
|
+
tail: [1.08, 0.2],
|
|
35
|
+
beat: 3.4, // wingbeats a second
|
|
36
|
+
gloss: 0.45, // roughness: a crow's black is glossy, and the sky and the sun shine on it
|
|
37
|
+
},
|
|
38
|
+
// long, narrow, pointed wings of a pale grey above and near white beneath, black tipped; a white body and a short square tail
|
|
39
|
+
gull: {
|
|
40
|
+
arm: [
|
|
41
|
+
[SHOULDER, 0.02, 0.24, SHOULDER, 0.02, -0.16],
|
|
42
|
+
[0.48, 0.05, 0.26, 0.48, 0.03, -0.22],
|
|
43
|
+
[WRIST, 0.04, 0.24, WRIST, 0.02, -0.2],
|
|
44
|
+
],
|
|
45
|
+
hand: [
|
|
46
|
+
[WRIST, 0.04, 0.24, WRIST, 0.02, -0.2],
|
|
47
|
+
[1.2, 0.03, 0.13, 1.16, 0.01, -0.17],
|
|
48
|
+
[1.55, 0.01, 0.0, 1.5, 0, -0.11],
|
|
49
|
+
[1.86, 0, -0.14, 1.86, 0, -0.14],
|
|
50
|
+
],
|
|
51
|
+
fingers: [],
|
|
52
|
+
tail: [0.84, 0.17],
|
|
53
|
+
beat: 2.8,
|
|
54
|
+
colours: {
|
|
55
|
+
body: [0.86, 0.86, 0.84],
|
|
56
|
+
head: [0.9, 0.9, 0.88],
|
|
57
|
+
arm: [0.5, 0.53, 0.57],
|
|
58
|
+
hand: [0.5, 0.53, 0.57],
|
|
59
|
+
tip: [0.03, 0.03, 0.035],
|
|
60
|
+
},
|
|
61
|
+
under: { arm: [0.92, 0.92, 0.91], hand: [0.85, 0.86, 0.87] },
|
|
62
|
+
tips: 1.42,
|
|
63
|
+
},
|
|
64
|
+
// broad, deep wings, the hand spread into long fingers; a short tail; dark brown, the bare head and neck pale; it soars
|
|
65
|
+
vulture: {
|
|
66
|
+
arm: [
|
|
67
|
+
[SHOULDER, 0.02, 0.3, SHOULDER, 0.02, -0.34],
|
|
68
|
+
[0.48, 0.05, 0.34, 0.48, 0.03, -0.5],
|
|
69
|
+
[WRIST, 0.04, 0.32, WRIST, 0.02, -0.48],
|
|
70
|
+
],
|
|
71
|
+
hand: [
|
|
72
|
+
[WRIST, 0.04, 0.32, WRIST, 0.02, -0.48],
|
|
73
|
+
[1.12, 0.03, 0.26, 1.1, 0.01, -0.46],
|
|
74
|
+
[1.3, 0.02, 0.2, 1.3, 0, -0.38],
|
|
75
|
+
],
|
|
76
|
+
fingers: [
|
|
77
|
+
[1.27, 0.16, 0.38, -0.05],
|
|
78
|
+
[1.3, 0.06, 0.4, -0.12],
|
|
79
|
+
[1.3, -0.05, 0.38, -0.18],
|
|
80
|
+
[1.3, -0.16, 0.31, -0.22],
|
|
81
|
+
[1.28, -0.27, 0.22, -0.23],
|
|
82
|
+
[1.24, -0.35, 0.14, -0.22],
|
|
83
|
+
],
|
|
84
|
+
tail: [0.86, 0.26],
|
|
85
|
+
beat: 2,
|
|
86
|
+
colours: {
|
|
87
|
+
body: [0.075, 0.055, 0.04],
|
|
88
|
+
head: [0.42, 0.3, 0.26],
|
|
89
|
+
arm: [0.1, 0.075, 0.055],
|
|
90
|
+
hand: [0.04, 0.032, 0.026],
|
|
91
|
+
tip: [0.03, 0.025, 0.02],
|
|
92
|
+
},
|
|
93
|
+
tips: 9,
|
|
94
|
+
soar: true,
|
|
95
|
+
silent: true,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { GB } from '../geometry/builder.js';
|
|
3
|
+
import {
|
|
4
|
+
CORVID_LOOK,
|
|
5
|
+
CORVID_NECK,
|
|
6
|
+
CORVID_SHOULDER,
|
|
7
|
+
CORVID_SIT,
|
|
8
|
+
CORVID_TALL,
|
|
9
|
+
corvidBody,
|
|
10
|
+
corvidHead,
|
|
11
|
+
corvidPalette,
|
|
12
|
+
} from '../geometry/flier-corvid-body.js';
|
|
13
|
+
import { foldedCorvidWing, spreadCorvidWing } from '../geometry/flier-corvid-wings.js';
|
|
14
|
+
|
|
15
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
16
|
+
// A large corvid as a figure of its own (a raven that hops, looks about and takes wing): the body in one mesh, the head and the
|
|
17
|
+
// two wings on pivots of their own, which `corvidPose` moves. Each wing pivot holds the wing folded and the wing spread, one of
|
|
18
|
+
// them shown at a time.
|
|
19
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
20
|
+
|
|
21
|
+
// A mesh of what one builder drew, in the material given, its surfaces tagged (glossy plumage, horn, the eyes).
|
|
22
|
+
function meshOf(build, mat) {
|
|
23
|
+
const b = new GB();
|
|
24
|
+
b.tg = [];
|
|
25
|
+
build(b);
|
|
26
|
+
const m = new THREE.Mesh(b.build(true), mat);
|
|
27
|
+
m.castShadow = true;
|
|
28
|
+
return m;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A corvid figure, nose to +z, its feet at the origin.
|
|
33
|
+
*
|
|
34
|
+
* @param {object} options
|
|
35
|
+
* @param {typeof CORVID_LOOK} [options.look=CORVID_LOOK]
|
|
36
|
+
* @param {THREE.Material} options.material A figure material that reads the vertices' colours and surface tags (no bones).
|
|
37
|
+
* @returns {{ group: THREE.Group, armL: THREE.Group, armR: THREE.Group, head: THREE.Group, height: number }} `armL` and `armR`
|
|
38
|
+
* are the wings' pivots (each [folded, spread]), `head` the head's, and `height` the bird's in metres.
|
|
39
|
+
*/
|
|
40
|
+
export function createCorvidFigure({ look = CORVID_LOOK, material: mat }) {
|
|
41
|
+
const { coat, horn, tip } = corvidPalette(look),
|
|
42
|
+
g = new THREE.Group(),
|
|
43
|
+
neck = new THREE.Group(),
|
|
44
|
+
wings = [];
|
|
45
|
+
g.add(meshOf(b => corvidBody(b, coat, horn, tip, null, true), mat));
|
|
46
|
+
neck.position.set(CORVID_NECK[0], CORVID_NECK[1], CORVID_NECK[2]);
|
|
47
|
+
neck.rotation.order = 'YXZ';
|
|
48
|
+
neck.add(meshOf(b => corvidHead(b, coat, horn, tip), mat));
|
|
49
|
+
g.add(neck);
|
|
50
|
+
const toShoulder = new THREE.Matrix4();
|
|
51
|
+
for (const s of [-1, 1]) {
|
|
52
|
+
const pivot = new THREE.Group(),
|
|
53
|
+
folded = meshOf(b => {
|
|
54
|
+
b.M = toShoulder.makeTranslation(-s * CORVID_SHOULDER[0], -CORVID_SHOULDER[1] - CORVID_SIT, -CORVID_SHOULDER[2]);
|
|
55
|
+
foldedCorvidWing(b, s, coat, tip);
|
|
56
|
+
b.M = null;
|
|
57
|
+
}, mat),
|
|
58
|
+
spread = meshOf(b => spreadCorvidWing(b, s, coat, tip), mat);
|
|
59
|
+
spread.visible = false;
|
|
60
|
+
pivot.position.set(s * CORVID_SHOULDER[0], CORVID_SHOULDER[1], CORVID_SHOULDER[2]);
|
|
61
|
+
pivot.add(folded, spread);
|
|
62
|
+
g.add(pivot);
|
|
63
|
+
wings.push(pivot);
|
|
64
|
+
}
|
|
65
|
+
g.scale.setScalar(look.height || 1);
|
|
66
|
+
return { group: g, armL: wings[0], armR: wings[1], head: neck, height: CORVID_TALL * (look.height || 1) };
|
|
67
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { geometryOf } from '../geometry/builder.js';
|
|
3
|
+
import { placeBankedAt, placement } from '../geometry/placement.js';
|
|
4
|
+
import { LONG_FLIER_TAIL } from '../geometry/flier-long-body.js';
|
|
5
|
+
import { detailLens, withinDetailRange } from './detail-range.js';
|
|
6
|
+
import { bindFlierShape, flierShapeGeometry } from './flier-swarm.js';
|
|
7
|
+
|
|
8
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
9
|
+
// A company of long-bodied four-winged fliers (`geometry/flier-long-body.js`) as instanced meshes: the bodies near and far (one
|
|
10
|
+
// nearer than `near` is drawn with its legs, its rider's limbs and a tail of many segments, one further off with the lighter
|
|
11
|
+
// version), the clear wings of all of them in one mesh of their own. The vertex shaders beat the wings, the fore pair and the
|
|
12
|
+
// hind pair out of step as a dragonfly's are, with the whirr's blur left to the glass of the wings, and sway the long tail in
|
|
13
|
+
// slow waves.
|
|
14
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* How the wings beat: `rate` beats a second, `swing` how far (radians), `lag` the hind pair's lag behind the fore pair (radians),
|
|
18
|
+
* and `glide` how far a gliding flier holds its wings raised (radians).
|
|
19
|
+
*/
|
|
20
|
+
export const LONG_FLIER_BEAT = { rate: 5.5, swing: 0.5, lag: 1.7, glide: 0.06 };
|
|
21
|
+
/** How the tail sways: `rate` waves a second, `wave` radians along a metre of it, `reach` metres a metre [up, across]. */
|
|
22
|
+
export const LONG_FLIER_SWAY = { rate: 1.3, wave: 0.65, reach: [0.05, 0.035] };
|
|
23
|
+
|
|
24
|
+
// The wings: each turns about its hinge on the thorax's top; aFlap is the flier's [phase, beat strength], and a gliding flier
|
|
25
|
+
// holds its wings out level, a little raised.
|
|
26
|
+
const wingsShader = beat => /* glsl */ `
|
|
27
|
+
{
|
|
28
|
+
float side = sign(transformed.x), hinge = abs(transformed.x) - aW, b = aFlap.y;
|
|
29
|
+
float lag = transformed.z > 0.1 ? 0.0 : ${beat.lag.toFixed(2)};
|
|
30
|
+
float a = b * ${beat.swing.toFixed(2)} * sin(uTime * ${(beat.rate * 6.2832).toFixed(3)} + aFlap.x - lag) + (1.0 - b) * ${beat.glide.toFixed(2)};
|
|
31
|
+
transformed.x = side * (hinge + aW * cos(a));
|
|
32
|
+
transformed.y += aW * sin(a);
|
|
33
|
+
}`;
|
|
34
|
+
// The tail: each point behind its root swings by how far along it lies, the wave running down it to the tip.
|
|
35
|
+
const tailShader = sway => /* glsl */ `
|
|
36
|
+
if (transformed.z < ${LONG_FLIER_TAIL.from.toFixed(2)}) {
|
|
37
|
+
float u = ${LONG_FLIER_TAIL.from.toFixed(2)} - transformed.z, w = uTime * ${(sway.rate * 6.2832).toFixed(3)} + aPhase - u * ${sway.wave.toFixed(2)};
|
|
38
|
+
transformed.y += sin(w) * ${sway.reach[0].toFixed(3)} * u;
|
|
39
|
+
transformed.x += sin(w * 0.7 + 1.3) * ${sway.reach[1].toFixed(3)} * u;
|
|
40
|
+
}`;
|
|
41
|
+
|
|
42
|
+
function patched(mat, key, time, head, body) {
|
|
43
|
+
mat.onBeforeCompile = sh => {
|
|
44
|
+
sh.uniforms.uTime = time;
|
|
45
|
+
sh.vertexShader = sh.vertexShader
|
|
46
|
+
.replace('#include <common>', '#include <common>\nuniform float uTime;\n' + head)
|
|
47
|
+
.replace('#include <begin_vertex>', '#include <begin_vertex>' + body);
|
|
48
|
+
};
|
|
49
|
+
mat.customProgramCacheKey = () => key;
|
|
50
|
+
return mat;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// An instanced mesh of `geo` for n, drawn whatever the camera sees (the company moves), with a dynamic attribute `name` of `size`.
|
|
54
|
+
function instanced(geo, mat, n, name, size) {
|
|
55
|
+
const attr = new THREE.InstancedBufferAttribute(new Float32Array(n * size), size).setUsage(THREE.DynamicDrawUsage);
|
|
56
|
+
geo.setAttribute(name, attr);
|
|
57
|
+
const mesh = new THREE.InstancedMesh(geo, mat, n);
|
|
58
|
+
mesh.frustumCulled = false;
|
|
59
|
+
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
|
|
60
|
+
mesh.count = 0;
|
|
61
|
+
return { mesh, attr };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A company of `count` long-bodied fliers, made from their shapes' arrays (`longFlierArrays`, on a worker or here).
|
|
66
|
+
*
|
|
67
|
+
* @param {object} options
|
|
68
|
+
* @param {number} options.count
|
|
69
|
+
* @param {{ near: object, far: object, wings: object }} options.shapes
|
|
70
|
+
* @param {{ value: number }} options.time The clock uniform, in seconds.
|
|
71
|
+
* @param {(camera: THREE.Camera) => number} [options.lens=detailLens] How much nearer the camera's lens brings things, for the
|
|
72
|
+
* near body's range.
|
|
73
|
+
* @param {[number, number]} [options.near=[154, 166]] Metres through a lens of 1 where the near body is taken up and let go.
|
|
74
|
+
* @param {typeof LONG_FLIER_BEAT} [options.beat=LONG_FLIER_BEAT]
|
|
75
|
+
* @param {typeof LONG_FLIER_SWAY} [options.sway=LONG_FLIER_SWAY]
|
|
76
|
+
* @param {string} [options.key='long-flier'] Tells its two programs apart from others (`customProgramCacheKey`: key + ':body',
|
|
77
|
+
* key + ':wings').
|
|
78
|
+
* @returns {{ group: THREE.Group, place: Function, draw: (camera: THREE.Camera) => void }} `place(i, pose, beat)` sets flier i for
|
|
79
|
+
* this frame (pose: { x, y, z, ry, rx, rz } as `placeBankedAt` reads it; beat: 0 gliding to 1 beating hard); `draw(camera)` hands
|
|
80
|
+
* the frame's places to the card once every flier is placed.
|
|
81
|
+
*/
|
|
82
|
+
export function createLongFlierCompany({
|
|
83
|
+
count: n,
|
|
84
|
+
shapes,
|
|
85
|
+
time,
|
|
86
|
+
lens = detailLens,
|
|
87
|
+
near: nearRange = [154, 166],
|
|
88
|
+
beat = LONG_FLIER_BEAT,
|
|
89
|
+
sway = LONG_FLIER_SWAY,
|
|
90
|
+
key = 'long-flier',
|
|
91
|
+
}) {
|
|
92
|
+
const chitin = () =>
|
|
93
|
+
patched(
|
|
94
|
+
new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.32, metalness: 0.2 }),
|
|
95
|
+
key + ':body',
|
|
96
|
+
time,
|
|
97
|
+
'attribute float aPhase;',
|
|
98
|
+
tailShader(sway),
|
|
99
|
+
),
|
|
100
|
+
bodyMat = chitin(),
|
|
101
|
+
near = instanced(geometryOf(shapes.near), bodyMat, n, 'aPhase', 1),
|
|
102
|
+
far = instanced(geometryOf(shapes.far), bodyMat, n, 'aPhase', 1),
|
|
103
|
+
wingMat = patched(
|
|
104
|
+
new THREE.MeshStandardMaterial({
|
|
105
|
+
vertexColors: true,
|
|
106
|
+
roughness: 0.18,
|
|
107
|
+
metalness: 0.35,
|
|
108
|
+
transparent: true,
|
|
109
|
+
opacity: 0.3,
|
|
110
|
+
depthWrite: false,
|
|
111
|
+
side: THREE.DoubleSide,
|
|
112
|
+
}),
|
|
113
|
+
key + ':wings',
|
|
114
|
+
time,
|
|
115
|
+
'attribute float aW; attribute vec2 aFlap;',
|
|
116
|
+
wingsShader(beat),
|
|
117
|
+
),
|
|
118
|
+
wings = instanced(flierShapeGeometry(bindFlierShape(shapes.wings)), wingMat, n, 'aFlap', 2),
|
|
119
|
+
all = [near, far, wings],
|
|
120
|
+
group = new THREE.Group(),
|
|
121
|
+
nearShown = new Array(n).fill(undefined), // indexed by flier, independent of the compacted draw slots
|
|
122
|
+
poses = new Float32Array(n * 7), // each flier's x, y, z, ry, rx, rz, beat for this frame
|
|
123
|
+
place = placement();
|
|
124
|
+
near.mesh.castShadow = far.mesh.castShadow = false; // seen against the sky, high over the ground their shadow would not reach
|
|
125
|
+
wings.mesh.renderOrder = 1;
|
|
126
|
+
group.add(near.mesh, far.mesh, wings.mesh);
|
|
127
|
+
const set = (i, pose, strength) => {
|
|
128
|
+
const o = i * 7;
|
|
129
|
+
poses[o] = pose.x;
|
|
130
|
+
poses[o + 1] = pose.y;
|
|
131
|
+
poses[o + 2] = pose.z;
|
|
132
|
+
poses[o + 3] = pose.ry;
|
|
133
|
+
poses[o + 4] = pose.rx;
|
|
134
|
+
poses[o + 5] = pose.rz;
|
|
135
|
+
poses[o + 6] = strength;
|
|
136
|
+
};
|
|
137
|
+
const draw = camera => {
|
|
138
|
+
const magnification = lens(camera);
|
|
139
|
+
let nn = 0,
|
|
140
|
+
nf = 0;
|
|
141
|
+
for (let i = 0; i < n; i++) {
|
|
142
|
+
const o = i * 7,
|
|
143
|
+
d2 = (poses[o] - camera.position.x) ** 2 + (poses[o + 1] - camera.position.y) ** 2 + (poses[o + 2] - camera.position.z) ** 2,
|
|
144
|
+
isNear = (nearShown[i] = withinDetailRange(d2, nearShown[i], magnification, nearRange)),
|
|
145
|
+
body = isNear ? near : far,
|
|
146
|
+
slot = body === near ? nn++ : nf++;
|
|
147
|
+
place.x = poses[o];
|
|
148
|
+
place.y = poses[o + 1];
|
|
149
|
+
place.z = poses[o + 2];
|
|
150
|
+
place.ry = poses[o + 3];
|
|
151
|
+
place.rx = poses[o + 4];
|
|
152
|
+
place.rz = poses[o + 5];
|
|
153
|
+
place.s = 1;
|
|
154
|
+
placeBankedAt(body.mesh.instanceMatrix.array, slot * 16, place);
|
|
155
|
+
placeBankedAt(wings.mesh.instanceMatrix.array, i * 16, place);
|
|
156
|
+
body.attr.array[slot] = i * 2.39;
|
|
157
|
+
wings.attr.array[i * 2] = i * 1.71;
|
|
158
|
+
wings.attr.array[i * 2 + 1] = poses[o + 6];
|
|
159
|
+
}
|
|
160
|
+
near.mesh.count = nn;
|
|
161
|
+
far.mesh.count = nf;
|
|
162
|
+
wings.mesh.count = n;
|
|
163
|
+
for (let k = 0; k < all.length; k++) {
|
|
164
|
+
all[k].mesh.instanceMatrix.needsUpdate = true;
|
|
165
|
+
all[k].attr.needsUpdate = true;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return { group, place: set, draw };
|
|
169
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { releaseArray, sphereOf } from '../geometry/builder.js';
|
|
3
|
+
import { createCrawlFlight, createSwarmFlight } from '../motion/flier-swarm-flight.js';
|
|
4
|
+
|
|
5
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
6
|
+
// A swarm of small fliers or ground crawlers as one instanced mesh: flying manners beat wings in the vertex shader via
|
|
7
|
+
// `createSwarmFlight`, while `manner: 'crawl'` drives ground-following instanced loops via `createCrawlFlight`; and the binding
|
|
8
|
+
// of a flier's shape (the arrays of `geometry/flier-shapes.js`) to the graphics card, shared by every swarm of a kind.
|
|
9
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
10
|
+
const SHAPE = { position: 3, normal: 3, color: 3, aW: 1 }; // a flier's shape: its arrays and the numbers to a vertex of each
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* How a kind of flier beats its wings: `beat` beats a second, `swing` how far each wing swings at most (radians), and `cup` the
|
|
14
|
+
* share of its length a wing is cupped down at rest. The default is a moth's.
|
|
15
|
+
*/
|
|
16
|
+
export const SWARM_WINGS = { beat: 14, swing: 0.9, cup: 0.1 };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Wingbeat preset for a small fast-beating fly.
|
|
20
|
+
*/
|
|
21
|
+
export const FLY_WINGS = { beat: 40, swing: 0.6, cup: 0.05 };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The attributes of a flier's shape from its arrays, with its bounding sphere [x, y, z, r]: shared by every swarm or company of the
|
|
25
|
+
* kind, and each array let go on the page once it is on the graphics card.
|
|
26
|
+
*
|
|
27
|
+
* @param {{ position: Float32Array, normal: Float32Array, color: Float32Array, aW: Float32Array }} arrays
|
|
28
|
+
* @returns {object} The bound attributes, and `sphere`.
|
|
29
|
+
*/
|
|
30
|
+
export function bindFlierShape(arrays) {
|
|
31
|
+
const attributes = { sphere: sphereOf(arrays.position) };
|
|
32
|
+
for (const name in SHAPE) attributes[name] = new THREE.BufferAttribute(arrays[name], SHAPE[name]).onUpload(releaseArray);
|
|
33
|
+
return attributes;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A geometry of a bound flier shape (`bindFlierShape`), for one swarm or company to add instanced attributes of its own to.
|
|
38
|
+
*
|
|
39
|
+
* @param {object} attributes
|
|
40
|
+
* @returns {THREE.BufferGeometry}
|
|
41
|
+
*/
|
|
42
|
+
export function flierShapeGeometry(attributes) {
|
|
43
|
+
const g = new THREE.BufferGeometry(),
|
|
44
|
+
[x, y, z, r] = attributes.sphere;
|
|
45
|
+
for (const name in SHAPE) g.setAttribute(name, attributes[name]);
|
|
46
|
+
g.boundingSphere = new THREE.Sphere(new THREE.Vector3(x, y, z), r);
|
|
47
|
+
return g;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The bound shapes of a world's kinds of flier, each made once: on a worker pool the first time it is asked for (a promise until it
|
|
52
|
+
* comes), or on the page where there is no pool or its job failed.
|
|
53
|
+
*
|
|
54
|
+
* @param {object} options
|
|
55
|
+
* @param {(kind: string) => object} options.build A kind's arrays, made on the page (`flierArrays(...)`).
|
|
56
|
+
* @param {() => boolean} [options.pooled] Whether a worker pool is there to build on.
|
|
57
|
+
* @param {(job: string, kind: string) => Promise<object>} [options.run] Runs a job on the pool, resolving to the kind's arrays.
|
|
58
|
+
* @param {string} [options.job='swarm shape'] The pool's job that builds a kind.
|
|
59
|
+
* @returns {(kind: string) => object | Promise<object>} A kind's bound shape, or the promise of it.
|
|
60
|
+
*/
|
|
61
|
+
export function createFlierShapes({ build, pooled = () => false, run = null, job = 'swarm shape' }) {
|
|
62
|
+
const shapes = {};
|
|
63
|
+
return kind => {
|
|
64
|
+
const here = () => (shapes[kind] = bindFlierShape(build(kind)));
|
|
65
|
+
if (!shapes[kind]) shapes[kind] = pooled() ? run(job, kind).then(arrays => (shapes[kind] = bindFlierShape(arrays)), here) : here();
|
|
66
|
+
return shapes[kind];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The vertex shader's beat: each wing turns about its hinge, the hinge where |x| less its weight lies; a resting flier (beat below 0)
|
|
71
|
+
// holds its wings folded close down its sides, drawn in to a share FOLD of their reach as a bat's are.
|
|
72
|
+
const BEAT = /* glsl */ `
|
|
73
|
+
if (aW > 0.0) {
|
|
74
|
+
float side = sign(transformed.x), hinge = abs(transformed.x) - aW, b = aFlap.y;
|
|
75
|
+
float a = b >= 0.0 ? b * uSwing * sin(uTime * uBeat * 6.2832 + aFlap.x) - (1.0 - b) * uCup : -1.45;
|
|
76
|
+
float reach = b >= 0.0 ? aW : aW * FOLD;
|
|
77
|
+
transformed.x = side * (hinge + reach * cos(a));
|
|
78
|
+
transformed.y += reach * sin(a);
|
|
79
|
+
}`;
|
|
80
|
+
|
|
81
|
+
// The swarm's material: vertex colours, its wings beaten in the vertex shader, and the light it catches from a lamp close by
|
|
82
|
+
// (`glow`, a share of the lamp's colour added to what it gives off).
|
|
83
|
+
function swarmMaterial(wings, time) {
|
|
84
|
+
const mat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.75, side: THREE.DoubleSide }),
|
|
85
|
+
glow = { value: new THREE.Color(0, 0, 0) };
|
|
86
|
+
mat.onBeforeCompile = sh => {
|
|
87
|
+
sh.uniforms.uTime = time;
|
|
88
|
+
sh.uniforms.uGlow = glow;
|
|
89
|
+
sh.uniforms.uBeat = { value: wings.beat };
|
|
90
|
+
sh.uniforms.uSwing = { value: wings.swing };
|
|
91
|
+
sh.uniforms.uCup = { value: wings.cup };
|
|
92
|
+
sh.vertexShader = sh.vertexShader
|
|
93
|
+
.replace(
|
|
94
|
+
'#include <common>',
|
|
95
|
+
`#include <common>
|
|
96
|
+
attribute float aW; attribute vec2 aFlap; uniform float uTime, uBeat, uSwing, uCup;
|
|
97
|
+
const float FOLD = 0.3;`,
|
|
98
|
+
)
|
|
99
|
+
.replace('#include <begin_vertex>', '#include <begin_vertex>' + BEAT);
|
|
100
|
+
sh.fragmentShader = sh.fragmentShader
|
|
101
|
+
.replace('#include <common>', '#include <common>\nuniform vec3 uGlow;')
|
|
102
|
+
.replace('#include <emissivemap_fragment>', '#include <emissivemap_fragment>\ntotalEmissiveRadiance += uGlow * diffuseColor.rgb;');
|
|
103
|
+
};
|
|
104
|
+
mat.customProgramCacheKey = () => 'swarm'; // every kind draws with one program: its beat is the material's own uniforms
|
|
105
|
+
return { mat, glow };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A swarm of small fliers or ground crawlers as one instanced mesh (`createSwarmFlight` says how flying manners move;
|
|
110
|
+
* `manner: 'crawl'` drives ground-following loops via `createCrawlFlight`).
|
|
111
|
+
*
|
|
112
|
+
* @param {object} options
|
|
113
|
+
* @param {object | Promise<object>} [options.shape] For flying manners: the kind's bound shape (`createFlierShapes`), or the
|
|
114
|
+
* promise of it (none is drawn till it comes).
|
|
115
|
+
* @param {typeof SWARM_WINGS} [options.wings=SWARM_WINGS] For flying manners: how the kind beats its wings.
|
|
116
|
+
* @param {{ value: number }} [options.time] For flying manners: the clock uniform, in seconds.
|
|
117
|
+
* @param {number} options.count
|
|
118
|
+
* @param {string} options.manner A flying manner (`hover`, `cloud`, `jitter`, `dart`, `hop`) or `'crawl'`.
|
|
119
|
+
* @param {Float32Array | number[]} [options.anchors] For flying manners: anchor positions `[x, y, z, ...]`.
|
|
120
|
+
* @param {number} [options.spread=1]
|
|
121
|
+
* @param {() => number} [options.random] For flying manners: seeded `[0, 1)` RNG stream.
|
|
122
|
+
* @param {[number, number] | null} [options.bow=null] For `'hop'`: arc bow heading `[x, z]`.
|
|
123
|
+
* @param {THREE.BufferGeometry} [options.geometry] For `'crawl'`: creature geometry.
|
|
124
|
+
* @param {THREE.Material} [options.material] For `'crawl'`: instanced material.
|
|
125
|
+
* @param {THREE.Object3D | null} [options.parent=null] Optional parent group to attach the mesh to.
|
|
126
|
+
* @param {number} [options.size=1] For `'crawl'`: creature uniform scale.
|
|
127
|
+
* @param {number} [options.pace=1] For `'crawl'`: ground speed in metres per second.
|
|
128
|
+
* @param {number} [options.seed=1] For `'crawl'`: deterministic seed.
|
|
129
|
+
* @param {(a: number, b: number, salt: number) => number} [options.hash] For `'crawl'`: deterministic 2D hash function.
|
|
130
|
+
* @param {boolean} [options.castShadow=true] For `'crawl'`: whether instances cast shadows.
|
|
131
|
+
* @returns {{ mesh: THREE.InstancedMesh, update: Function, glow?: THREE.Color }}
|
|
132
|
+
*/
|
|
133
|
+
export function createSwarm({
|
|
134
|
+
shape,
|
|
135
|
+
wings = SWARM_WINGS,
|
|
136
|
+
time,
|
|
137
|
+
count: n,
|
|
138
|
+
manner,
|
|
139
|
+
anchors,
|
|
140
|
+
spread = 1,
|
|
141
|
+
random,
|
|
142
|
+
bow = null,
|
|
143
|
+
geometry = null,
|
|
144
|
+
material = null,
|
|
145
|
+
parent = null,
|
|
146
|
+
size = 1,
|
|
147
|
+
pace = 1,
|
|
148
|
+
seed = 1,
|
|
149
|
+
hash = null,
|
|
150
|
+
castShadow = true,
|
|
151
|
+
}) {
|
|
152
|
+
if (manner === 'crawl') {
|
|
153
|
+
const flight = createCrawlFlight({ count: n, size, pace, seed, ...(hash ? { hash } : {}) }),
|
|
154
|
+
mesh = new THREE.InstancedMesh(geometry, material, n);
|
|
155
|
+
mesh.castShadow = castShadow;
|
|
156
|
+
mesh.frustumCulled = false; // creatures move across the ground and bounds move with them
|
|
157
|
+
mesh.visible = false;
|
|
158
|
+
if (parent) parent.add(mesh);
|
|
159
|
+
const update = (t, cx, cz, radius, ground) => {
|
|
160
|
+
flight.place(t, cx, cz, radius, ground, mesh.instanceMatrix.array);
|
|
161
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
162
|
+
};
|
|
163
|
+
return { mesh, update };
|
|
164
|
+
}
|
|
165
|
+
const flight = createSwarmFlight({ count: n, manner, anchors, spread, random, bow }),
|
|
166
|
+
flap = new THREE.InstancedBufferAttribute(flight.flap, 2).setUsage(THREE.DynamicDrawUsage),
|
|
167
|
+
{ mat, glow } = swarmMaterial(wings, time),
|
|
168
|
+
mesh = new THREE.InstancedMesh(new THREE.BufferGeometry(), mat, n);
|
|
169
|
+
mesh.frustumCulled = false;
|
|
170
|
+
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
|
|
171
|
+
if (parent) parent.add(mesh);
|
|
172
|
+
const take = attributes => {
|
|
173
|
+
mesh.geometry = flierShapeGeometry(attributes).setAttribute('aFlap', flap);
|
|
174
|
+
mesh.count = n;
|
|
175
|
+
};
|
|
176
|
+
if (shape instanceof Promise) {
|
|
177
|
+
mesh.count = 0;
|
|
178
|
+
shape.then(take);
|
|
179
|
+
} else take(shape);
|
|
180
|
+
const update = t => {
|
|
181
|
+
flight.place(t, mesh.instanceMatrix.array);
|
|
182
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
183
|
+
flap.needsUpdate = true;
|
|
184
|
+
};
|
|
185
|
+
return { mesh, update, glow: glow.value };
|
|
186
|
+
}
|
package/rendering/flocks.js
CHANGED
|
@@ -32,7 +32,10 @@ export function birdGeometry(birdStyle) {
|
|
|
32
32
|
wingWeights.push(w, w, w);
|
|
33
33
|
if (!col) return;
|
|
34
34
|
const under = birdStyle.under?.[part],
|
|
35
|
-
up = Math.sign(
|
|
35
|
+
up = Math.sign(
|
|
36
|
+
(secondPoint[2] - firstPoint[2]) * (thirdPoint[0] - firstPoint[0]) -
|
|
37
|
+
(secondPoint[0] - firstPoint[0]) * (thirdPoint[2] - firstPoint[2]),
|
|
38
|
+
);
|
|
36
39
|
for (const p of [firstPoint, secondPoint, thirdPoint]) {
|
|
37
40
|
const tip = part !== 'body' && part !== 'head' && Math.abs(p[0]) > birdStyle.tips;
|
|
38
41
|
K.push(...(tip ? col.tip : col[part]));
|
|
@@ -85,7 +88,8 @@ export function birdGeometry(birdStyle) {
|
|
|
85
88
|
tri(la, ta, tb, w, w === 1 ? 'arm' : 'hand');
|
|
86
89
|
tri(la, tb, lb, w, w === 1 ? 'arm' : 'hand');
|
|
87
90
|
}
|
|
88
|
-
for (const [x, z, dx, dz] of birdStyle.fingers)
|
|
91
|
+
for (const [x, z, dx, dz] of birdStyle.fingers)
|
|
92
|
+
tri(X(x - 0.07, 0.01, z + 0.05), X(x + 0.05, 0.01, z + 0.04), X(x + dx, 0, z + dz), 2, 'tip');
|
|
89
93
|
}
|
|
90
94
|
const geometry = new THREE.BufferGeometry();
|
|
91
95
|
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|