roamwright 0.20.1 → 0.55.1
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 +139 -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/cast-actors.js +379 -0
- package/motion/cast-manager.js +321 -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 +46 -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/cast-stage.js +299 -0
- 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/nameplate-groups.js +84 -0
- package/rendering/nameplates.js +386 -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
package/geometry/hair-patch.js
CHANGED
|
@@ -7,7 +7,8 @@ const POINT = 10, // numbers to a point: its place, its normal, its colour, and
|
|
|
7
7
|
|
|
8
8
|
// Emit each shared vertex once per strand band, correcting the winding from the supplied normals.
|
|
9
9
|
function packHairPatch(points, triangles, emitVertex) {
|
|
10
|
-
const bands = new Map(),
|
|
10
|
+
const bands = new Map(),
|
|
11
|
+
corners = [];
|
|
11
12
|
let vertexCount = 0;
|
|
12
13
|
for (let t = 0; t < triangles.length; t += 3) {
|
|
13
14
|
const firstOffset = triangles[t] * POINT,
|
|
@@ -25,7 +26,10 @@ function packHairPatch(points, triangles, emitVertex) {
|
|
|
25
26
|
(uz * vx - ux * vz) * (points[firstOffset + 4] + points[secondOffset + 4] + points[thirdOffset + 4]) +
|
|
26
27
|
(ux * vy - uy * vx) * (points[firstOffset + 5] + points[secondOffset + 5] + points[thirdOffset + 5]);
|
|
27
28
|
let put = bands.get(band);
|
|
28
|
-
if (!put) {
|
|
29
|
+
if (!put) {
|
|
30
|
+
put = new Map();
|
|
31
|
+
bands.set(band, put);
|
|
32
|
+
}
|
|
29
33
|
for (const pointOffset of faces < 0 ? [firstOffset, thirdOffset, secondOffset] : [firstOffset, secondOffset, thirdOffset]) {
|
|
30
34
|
let v = put.get(pointOffset);
|
|
31
35
|
if (v === undefined) {
|
package/geometry/hair-shell.js
CHANGED
|
@@ -25,7 +25,8 @@ const _o = new THREE.Vector3(),
|
|
|
25
25
|
// Returns at(direction, lift, out, outward): the point of the mass at a direction from the head's middle, raised off it by lift
|
|
26
26
|
// (metres), and the way out there; and full(direction): how much of its fullness the mass has at a direction, 0 to 1.
|
|
27
27
|
function massOf({ skull, scale, inHair, drop = 0, lumps = 0, lumpy = 5, tucked = null }) {
|
|
28
|
-
const full = direction =>
|
|
28
|
+
const full = direction =>
|
|
29
|
+
(EDGE + (1 - EDGE) * sstep(-0.01, RISE, inHair(direction.x, direction.y, direction.z))) * (tucked ? 1 - TUCK * tucked(direction) : 1),
|
|
29
30
|
swell = direction =>
|
|
30
31
|
lumps *
|
|
31
32
|
(Math.sin(direction.x * lumpy * 2.3 + direction.y * lumpy * 1.3) * Math.sin(direction.z * lumpy * 2.1 - direction.y * lumpy * 1.7) +
|
|
@@ -82,7 +83,18 @@ function createHairShells(sculptMesh) {
|
|
|
82
83
|
at = Math.round(directions[q] * 2e4) + ',' + Math.round(directions[q + 1] * 2e4) + ',' + Math.round(directions[q + 2] * 2e4);
|
|
83
84
|
let v = known.get(at);
|
|
84
85
|
if (v === undefined) {
|
|
85
|
-
v = add(
|
|
86
|
+
v = add(
|
|
87
|
+
positions[q],
|
|
88
|
+
positions[q + 1],
|
|
89
|
+
positions[q + 2],
|
|
90
|
+
normals[q],
|
|
91
|
+
normals[q + 1],
|
|
92
|
+
normals[q + 2],
|
|
93
|
+
directions[q],
|
|
94
|
+
directions[q + 1],
|
|
95
|
+
directions[q + 2],
|
|
96
|
+
mass.inHair(directions[q], directions[q + 1], directions[q + 2]),
|
|
97
|
+
);
|
|
86
98
|
known.set(at, v);
|
|
87
99
|
}
|
|
88
100
|
numbered[i] = v;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kinds of human head a figure's face is varied from (`HEAD_PRESETS`: man, woman, heavy, skull), and the skull that caps,
|
|
3
|
+
* helmets, hoods and hair lie over (`SKULL`). A world adds heads of its own peoples beside these (figure-body.js, `heads`).
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { headFn } from './head-shape.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Kinds of head, as how strongly each feature is drawn; a figure's own face is one of these varied by its seed and look.
|
|
10
|
+
* jaw 0..1 the breadth at the jaw's angle; chin, chinW its jut and breadth; nose its reach, noseW, noseL, bridge (a hump, or a
|
|
11
|
+
* dip below 0); brow the ridge; socket how deep the eyes sit; cheek the cheekbones; hollow the cheeks under them; lips their
|
|
12
|
+
* fullness; mouthW; eye how far the lids open; tilt the outer corners raised; slope the forehead leaning back; fold the crease
|
|
13
|
+
* from nose to mouth; wide and tall: the whole head's breadth and height; age and fat 0..1; scar: a seam from [x, y] to [x, y]
|
|
14
|
+
* (millimetres from the head's middle, x to the person's left), then its width and how far its middle bows down; dead: a dried
|
|
15
|
+
* face, with pits for eyes; oneEye: the two eyes healed over and one large faceted eye in the middle of the brow, under a
|
|
16
|
+
* jutting ridge. The shape itself is head-shape.js's `headFn`.
|
|
17
|
+
* @type {Record<string, object>}
|
|
18
|
+
*/
|
|
19
|
+
const HEAD_PRESETS = {
|
|
20
|
+
man: {
|
|
21
|
+
jaw: 0.55,
|
|
22
|
+
chin: 1,
|
|
23
|
+
chinW: 1,
|
|
24
|
+
nose: 1,
|
|
25
|
+
noseW: 1,
|
|
26
|
+
noseL: 1,
|
|
27
|
+
bridge: 0.25,
|
|
28
|
+
brow: 1,
|
|
29
|
+
socket: 1,
|
|
30
|
+
cheek: 1,
|
|
31
|
+
hollow: 0.35,
|
|
32
|
+
lips: 0.88,
|
|
33
|
+
mouthW: 1,
|
|
34
|
+
eye: 0.94,
|
|
35
|
+
tilt: 0,
|
|
36
|
+
slope: 1,
|
|
37
|
+
fold: 1,
|
|
38
|
+
},
|
|
39
|
+
woman: {
|
|
40
|
+
jaw: 0.2,
|
|
41
|
+
chin: 0.7,
|
|
42
|
+
chinW: 0.84,
|
|
43
|
+
nose: 0.86,
|
|
44
|
+
noseW: 0.88,
|
|
45
|
+
noseL: 0.96,
|
|
46
|
+
bridge: -0.25,
|
|
47
|
+
brow: 0.3,
|
|
48
|
+
socket: 0.8,
|
|
49
|
+
cheek: 1.12,
|
|
50
|
+
hollow: 0.1,
|
|
51
|
+
lips: 1.22,
|
|
52
|
+
mouthW: 0.93,
|
|
53
|
+
eye: 1.06,
|
|
54
|
+
tilt: 0.35,
|
|
55
|
+
slope: 0.3,
|
|
56
|
+
fold: 0.6,
|
|
57
|
+
},
|
|
58
|
+
heavy: {
|
|
59
|
+
jaw: 1,
|
|
60
|
+
chin: 1.35,
|
|
61
|
+
chinW: 1.25,
|
|
62
|
+
nose: 1.05,
|
|
63
|
+
noseW: 1.3,
|
|
64
|
+
noseL: 1,
|
|
65
|
+
bridge: 0.5,
|
|
66
|
+
brow: 1.8,
|
|
67
|
+
socket: 1.3,
|
|
68
|
+
cheek: 1.3,
|
|
69
|
+
hollow: 0.4,
|
|
70
|
+
lips: 0.8,
|
|
71
|
+
mouthW: 1.1,
|
|
72
|
+
eye: 0.88,
|
|
73
|
+
tilt: 0,
|
|
74
|
+
slope: 1.6,
|
|
75
|
+
fold: 1.4,
|
|
76
|
+
},
|
|
77
|
+
skull: {
|
|
78
|
+
dead: 1,
|
|
79
|
+
jaw: 0.45,
|
|
80
|
+
chin: 0.9,
|
|
81
|
+
chinW: 0.9,
|
|
82
|
+
nose: 0.2,
|
|
83
|
+
noseW: 0.9,
|
|
84
|
+
noseL: 0.8,
|
|
85
|
+
bridge: 0,
|
|
86
|
+
brow: 1.7,
|
|
87
|
+
socket: 2.1,
|
|
88
|
+
cheek: 1.7,
|
|
89
|
+
hollow: 2.6,
|
|
90
|
+
lips: 0,
|
|
91
|
+
mouthW: 1.05,
|
|
92
|
+
eye: 1.3,
|
|
93
|
+
tilt: 0,
|
|
94
|
+
slope: 1.2,
|
|
95
|
+
fold: 0,
|
|
96
|
+
age: 1,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** The skull caps and hair are laid over: a man's head with its forehead leaning back less. */
|
|
101
|
+
const SKULL = headFn({ ...HEAD_PRESETS.man, slope: 0.65 });
|
|
102
|
+
|
|
103
|
+
export { HEAD_PRESETS, SKULL };
|
package/geometry/head-profile.js
CHANGED
|
@@ -14,7 +14,15 @@ function curve(points) {
|
|
|
14
14
|
for (let i = 0; i < pointCount; i++) {
|
|
15
15
|
const previousSlope = slope[i - 1],
|
|
16
16
|
nextSlope = slope[i];
|
|
17
|
-
tangent.push(
|
|
17
|
+
tangent.push(
|
|
18
|
+
i === 0
|
|
19
|
+
? nextSlope
|
|
20
|
+
: i === pointCount - 1
|
|
21
|
+
? previousSlope
|
|
22
|
+
: previousSlope * nextSlope <= 0
|
|
23
|
+
? 0
|
|
24
|
+
: (2 * previousSlope * nextSlope) / (previousSlope + nextSlope),
|
|
25
|
+
);
|
|
18
26
|
}
|
|
19
27
|
const exact = x => {
|
|
20
28
|
if (x <= coordinates[0]) return values[0];
|
|
@@ -26,7 +34,10 @@ function curve(points) {
|
|
|
26
34
|
t2 = t * t,
|
|
27
35
|
t3 = t2 * t;
|
|
28
36
|
return (
|
|
29
|
-
values[i] * (2 * t3 - 3 * t2 + 1) +
|
|
37
|
+
values[i] * (2 * t3 - 3 * t2 + 1) +
|
|
38
|
+
tangent[i] * h * (t3 - 2 * t2 + t) +
|
|
39
|
+
values[i + 1] * (3 * t2 - 2 * t3) +
|
|
40
|
+
tangent[i + 1] * h * (t3 - t2)
|
|
30
41
|
);
|
|
31
42
|
};
|
|
32
43
|
return sampled(exact, coordinates[0], coordinates[pointCount - 1]);
|
package/geometry/head-shape.js
CHANGED
|
@@ -23,13 +23,36 @@ const MM = 0.001,
|
|
|
23
23
|
WOUND_DEEP = 4.5, // millimetres a fresh wound's torn flesh lies below the skin round it,
|
|
24
24
|
WOUND_SWELL = 2.2, // and how far the bruised skin at its edges swells;
|
|
25
25
|
HEALED_DEEP = 2.4, // once healed (faceFeatures.healed), how far the scar lies sunk where the flesh was torn, and how high its edges and
|
|
26
|
-
HEALED_RIDGE = 0.9
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
HEALED_RIDGE = 0.9; // the cords of scar tissue across it stand
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Where a wound has torn the nose away, the opening into the skull's nose left in its place: a pear-shaped hollow down the
|
|
30
|
+
* middle of the face. A head's `noseHole` feature may change any of these. Millimetres from the head's middle (the eyes' level).
|
|
31
|
+
* @typedef {object} NoseHole
|
|
32
|
+
* @property {number} top - The height its top lies at.
|
|
33
|
+
* @property {number} foot - The height its foot lies at.
|
|
34
|
+
* @property {number} wide - Its half width at the foot.
|
|
35
|
+
* @property {number} deep - How deep it sinks, fresh.
|
|
36
|
+
* @property {number} dark - How dark it is within (0 to 1), fresh.
|
|
37
|
+
* @property {number} healedDeep - How deep it sinks once healed.
|
|
38
|
+
* @property {number} healedDark - How dark it is within once healed.
|
|
39
|
+
*/
|
|
40
|
+
/** The default {@link NoseHole}. */
|
|
41
|
+
export const NOSE_HOLE = Object.freeze({ top: -19, foot: -46, wide: 9.5, deep: 6, dark: 0.78, healedDeep: 3.5, healedDark: 0.6 });
|
|
42
|
+
/**
|
|
43
|
+
* A single large eye in the middle of the brow in place of two (whose sockets are closed over), under a jutting ridge: a
|
|
44
|
+
* creature's or a giant's. A head's `oneEye` feature is `true` (or 1) for this shape, or an object that changes any of it.
|
|
45
|
+
* Millimetres from the head's middle.
|
|
46
|
+
* @typedef {object} OneEye
|
|
47
|
+
* @property {number} y - The height of the eye's middle.
|
|
48
|
+
* @property {number} r - The radius of its ball.
|
|
49
|
+
* @property {number} wide - Half the width of its lids' opening.
|
|
50
|
+
* @property {number} high - Half the height of its lids' opening.
|
|
51
|
+
* @property {number} out - How far its ball stands out of the brow.
|
|
52
|
+
* @property {number} ridge - How far the ridge over it juts.
|
|
53
|
+
*/
|
|
54
|
+
/** The default {@link OneEye}. */
|
|
55
|
+
export const ONE_EYE = Object.freeze({ y: 16.5, r: 17.5, wide: 16.5, high: 10.5, out: 7, ridge: 7 });
|
|
33
56
|
|
|
34
57
|
// A soft rise of that width about a point, and one about a point of the face. Far from the point it is nothing, and is not
|
|
35
58
|
// worked out: a head asks for these some hundred thousand times.
|
|
@@ -64,7 +87,9 @@ const _slice = { x: 0, z: 0 },
|
|
|
64
87
|
|
|
65
88
|
// The surface of a head with the given features, as a function of a direction from its middle: sampleHead(direction, outPoint, channels). Channels: lips,
|
|
66
89
|
// shade, warmth (cheeks, nose), where a beard grows on cheeks and jaw, brow, where a moustache grows, the chin's tuft, a scar. A fine head has open lids and a mouth that can open (its grid lays rows
|
|
67
|
-
// along their edges); a plain one, for the far mesh and for coarse sculpts, has them closed and painted.
|
|
90
|
+
// along their edges); a plain one, for the far mesh and for coarse sculpts, has them closed and painted. Among the features,
|
|
91
|
+
// `oneEye` gives the head one eye in the middle of the brow ({@link OneEye}), and `noseHole` changes the opening a wound across
|
|
92
|
+
// the nose leaves ({@link NoseHole}).
|
|
68
93
|
function headFn(features = {}, fine = false) {
|
|
69
94
|
const faceFeatures = { jaw: 0.5, lips: 1, cheek: 1, mouthW: 1, brow: 1, socket: 1, hollow: 0, chin: 1, nose: 1, bridge: 0, ...features };
|
|
70
95
|
const age = faceFeatures.age || 0,
|
|
@@ -125,14 +150,16 @@ function headFn(features = {}, fine = false) {
|
|
|
125
150
|
lidR = ballR + 1.3,
|
|
126
151
|
innerX = eyeX - 14.5,
|
|
127
152
|
outerX = eyeX + 14,
|
|
128
|
-
one = !!faceFeatures.oneEye, //
|
|
153
|
+
one = !!faceFeatures.oneEye, // one eye in the middle of the brow, the two sockets closed over (ONE_EYE)
|
|
154
|
+
oneEye = typeof faceFeatures.oneEye === 'object' ? { ...ONE_EYE, ...faceFeatures.oneEye } : ONE_EYE,
|
|
155
|
+
noseHole = faceFeatures.noseHole ? { ...NOSE_HOLE, ...faceFeatures.noseHole } : NOSE_HOLE,
|
|
129
156
|
opening = one ? 0 : (faceFeatures.eye ?? 1),
|
|
130
157
|
tilt = faceFeatures.tilt ?? 0;
|
|
131
158
|
slice(eyeY, Math.asin(eyeX / width(eyeY)) * 0.93, _slice);
|
|
132
159
|
const eyeZ = _slice.z - 14.4 - (faceFeatures.deep ?? 0);
|
|
133
|
-
slice(
|
|
134
|
-
const oneZ = _slice.z +
|
|
135
|
-
oneLid =
|
|
160
|
+
slice(oneEye.y, 0, _slice);
|
|
161
|
+
const oneZ = _slice.z + oneEye.out - oneEye.r, // where the middle of the one eye's ball is
|
|
162
|
+
oneLid = oneEye.r + 1.3;
|
|
136
163
|
const corner = t => eyeY - 1.9 + (1.5 + 1.6 * tilt) * t,
|
|
137
164
|
upperLid = t => corner(t) + 5.4 * opening * Math.pow(4 * Math.pow(t, 0.85) * (1 - Math.pow(t, 0.85)), 0.72),
|
|
138
165
|
lowerLid = t => corner(t) - 3.9 * opening * Math.pow(4 * Math.pow(t, 1.15) * (1 - Math.pow(t, 1.15)), 0.8);
|
|
@@ -288,15 +315,15 @@ function headFn(features = {}, fine = false) {
|
|
|
288
315
|
if (one) {
|
|
289
316
|
// the one eye: a ridge jutting over it and sloping away to the temples, the lids wrapped round the ball, and within
|
|
290
317
|
// their opening the skin falls back behind the ball
|
|
291
|
-
const dy = y -
|
|
292
|
-
ridgeY =
|
|
318
|
+
const dy = y - oneEye.y,
|
|
319
|
+
ridgeY = oneEye.y + oneEye.high + 5.5 - 0.006 * ax * ax,
|
|
293
320
|
ball = oneLid * oneLid - ax * ax - dy * dy,
|
|
294
|
-
r = Math.hypot(ax /
|
|
295
|
-
out +=
|
|
321
|
+
r = Math.hypot(ax / oneEye.wide, dy / oneEye.high);
|
|
322
|
+
out += oneEye.ridge * bump(y, ridgeY, y > ridgeY ? 7 : 3.6) * sstep(56, 36, ax);
|
|
296
323
|
if (ball > 0) out = smoothMax(out, oneZ + Math.sqrt(ball) - _slice.z, 1.6);
|
|
297
324
|
shade -= 0.22 * bump(r, 1, 0.14) + 0.12 * bump(y, ridgeY - 5, 3) * sstep(30, 10, ax);
|
|
298
325
|
if (r < 1) {
|
|
299
|
-
const within = (1 - r) *
|
|
326
|
+
const within = (1 - r) * oneEye.high; // millimetres inside the lids' edge
|
|
300
327
|
out -= fine ? 1.4 * sstep(0, 0.4, within) + 10 * sstep(0.4, 2.2, within) : 0;
|
|
301
328
|
shade = fine ? lerp(shade, 0.3, sstep(0, 0.6, within)) : shade * (1 - 0.8 * sstep(0, 1.2, within));
|
|
302
329
|
}
|
|
@@ -327,7 +354,8 @@ function headFn(features = {}, fine = false) {
|
|
|
327
354
|
// the nose: a ridge down the middle of the face to a rounded tip, wings beside it and the nostrils beneath
|
|
328
355
|
const noseY = 12 + (y - 12) / noseLong;
|
|
329
356
|
if (noseY < 17 && noseY > -52) {
|
|
330
|
-
const reach =
|
|
357
|
+
const reach =
|
|
358
|
+
NOSE_OUT(noseY) * (1 + (faceFeatures.nose - 1) * sstep(8, -6, noseY)) + 2.2 * faceFeatures.bridge * bump(noseY, -8, 11),
|
|
331
359
|
t = ax / (NOSE_WIDE(noseY) * (1 + (noseWide - 1) * sstep(-5, -35, noseY))),
|
|
332
360
|
tip = bump(noseY, -36, 7);
|
|
333
361
|
const torn = 1 - Math.max(0.85 * raw, noseLost * sstep(-6, -16, noseY)); // what a wound has torn away of the nose
|
|
@@ -342,11 +370,11 @@ function headFn(features = {}, fine = false) {
|
|
|
342
370
|
shade -= 0.2 * bump(ax, 0, 12) * bump(noseY, -49.6, 2.2) + 0.08 * bump(ax, alaX + 6 * noseWide, 1.6) * bump(noseY, -40, 5);
|
|
343
371
|
if (noseLost > 0) {
|
|
344
372
|
// the nose gone: the opening it covered, narrow under the bone and widening to its foot, sunk and dark within
|
|
345
|
-
const { top, foot, wide } =
|
|
373
|
+
const { top, foot, wide } = noseHole,
|
|
346
374
|
half = wide * (0.35 + 0.65 * sstep(top, foot + 6, noseY)) * noseWide,
|
|
347
375
|
hole = noseLost * sstep(top + 2, top - 4, noseY) * sstep(foot - 2, foot + 3, noseY) * sstep(1, 0.55, ax / half);
|
|
348
|
-
out -= hole * (faceFeatures.healed ?
|
|
349
|
-
shade *= 1 - hole * (faceFeatures.healed ?
|
|
376
|
+
out -= hole * (faceFeatures.healed ? noseHole.healedDeep : noseHole.deep);
|
|
377
|
+
shade *= 1 - hole * (faceFeatures.healed ? noseHole.healedDark : noseHole.dark);
|
|
350
378
|
raw = Math.max(raw, hole); // coloured as the wound round it is, raw or scarred
|
|
351
379
|
}
|
|
352
380
|
warm += 0.5 * tip * bump(ax, 0, 13);
|
|
@@ -437,7 +465,7 @@ function headFn(features = {}, fine = false) {
|
|
|
437
465
|
ch[4] = brow;
|
|
438
466
|
ch[5] = moustache;
|
|
439
467
|
ch[6] = tuft;
|
|
440
|
-
ch[7] = scar || raw; // a head has an old scar or a fresh wound:
|
|
468
|
+
ch[7] = scar || raw; // a head has an old scar or a fresh wound: its features say which (`healed`), and the caller colours it
|
|
441
469
|
}
|
|
442
470
|
};
|
|
443
471
|
|
|
@@ -490,7 +518,7 @@ function headFn(features = {}, fine = false) {
|
|
|
490
518
|
upper: t => upperLid(t) * MM,
|
|
491
519
|
};
|
|
492
520
|
sampleHead.mouth = { x: mouthX * MM, y: SEAM * MM };
|
|
493
|
-
sampleHead.one = one ? { y:
|
|
521
|
+
sampleHead.one = one ? { y: oneEye.y * MM, z: oneZ * MM, r: oneEye.r * MM, wide: oneEye.wide * MM } : null; // the one eye's ball, if so
|
|
494
522
|
sampleHead.browLine = x => browLine(x / MM) * MM;
|
|
495
523
|
sampleHead.scar = (x, y) => (faceFeatures.scar ? scarAt(x / MM, y / MM)[1] : 0); // how much of a scar there is at a point (metres)
|
|
496
524
|
return sampleHead;
|
package/geometry/heightfield.js
CHANGED
|
@@ -18,12 +18,13 @@ export function heightfieldSampler(geometry, outside) {
|
|
|
18
18
|
const depth = positions.getZ(rows * (columns + 1)) - z0;
|
|
19
19
|
if (!(width > 0 && depth > 0)) throw new RangeError('Expected a regular heightfield in the X/Z plane');
|
|
20
20
|
return (x, z) => {
|
|
21
|
-
const gridX = (x - x0) / width * columns;
|
|
22
|
-
const gridZ = (z - z0) / depth * rows;
|
|
21
|
+
const gridX = ((x - x0) / width) * columns;
|
|
22
|
+
const gridZ = ((z - z0) / depth) * rows;
|
|
23
23
|
if (gridX < 0 || gridZ < 0 || gridX > columns || gridZ > rows) return outside?.(x, z);
|
|
24
24
|
const col = Math.min(Math.floor(gridX), columns - 1);
|
|
25
25
|
const row = Math.min(Math.floor(gridZ), rows - 1);
|
|
26
|
-
const columnFraction = gridX - col,
|
|
26
|
+
const columnFraction = gridX - col,
|
|
27
|
+
rowFraction = gridZ - row;
|
|
27
28
|
const cornerIndex = row * (columns + 1) + col;
|
|
28
29
|
const farLeft = positions.getY(cornerIndex + columns + 1);
|
|
29
30
|
const nearRight = positions.getY(cornerIndex + 1);
|
|
@@ -40,13 +41,23 @@ export function heightfieldSampler(geometry, outside) {
|
|
|
40
41
|
// attributes with the supplied height function and returns its geometry. Call during construction.
|
|
41
42
|
export function refineHeightfield(base, { x, z, cells, subdivisions, height, createPatch }) {
|
|
42
43
|
const { widthSegments: columns, heightSegments: rows } = base.parameters;
|
|
43
|
-
if (
|
|
44
|
-
|
|
44
|
+
if (
|
|
45
|
+
!(
|
|
46
|
+
Number.isInteger(cells) &&
|
|
47
|
+
cells > 0 &&
|
|
48
|
+
cells <= Math.min(columns, rows) &&
|
|
49
|
+
Number.isInteger(subdivisions) &&
|
|
50
|
+
subdivisions >= 2 &&
|
|
51
|
+
Number.isFinite(x) &&
|
|
52
|
+
Number.isFinite(z)
|
|
53
|
+
)
|
|
54
|
+
) {
|
|
45
55
|
throw new RangeError('Invalid heightfield patch dimensions or position');
|
|
46
56
|
}
|
|
47
57
|
if (!base.index || base.index.count !== rows * columns * 6) throw new TypeError('Expected an indexed PlaneGeometry');
|
|
48
58
|
const positions = base.getAttribute('position');
|
|
49
|
-
const x0 = positions.getX(0),
|
|
59
|
+
const x0 = positions.getX(0),
|
|
60
|
+
z0 = positions.getZ(0);
|
|
50
61
|
const dx = (positions.getX(columns) - x0) / columns;
|
|
51
62
|
const dz = (positions.getZ(rows * (columns + 1)) - z0) / rows;
|
|
52
63
|
const col = Math.round((x - x0) / dx - cells / 2);
|
|
@@ -55,10 +66,16 @@ export function refineHeightfield(base, { x, z, cells, subdivisions, height, cre
|
|
|
55
66
|
throw new RangeError('Heightfield patch extends past the base grid');
|
|
56
67
|
}
|
|
57
68
|
const coarse = heightfieldSampler(base, height);
|
|
58
|
-
const cx = x0 + (col + cells / 2) * dx,
|
|
59
|
-
|
|
69
|
+
const cx = x0 + (col + cells / 2) * dx,
|
|
70
|
+
cz = z0 + (row + cells / 2) * dz;
|
|
71
|
+
const width = cells * dx,
|
|
72
|
+
depth = cells * dz;
|
|
60
73
|
const patch = createPatch({
|
|
61
|
-
x: cx,
|
|
74
|
+
x: cx,
|
|
75
|
+
z: cz,
|
|
76
|
+
width,
|
|
77
|
+
depth,
|
|
78
|
+
segments: cells * subdivisions,
|
|
62
79
|
height(px, pz) {
|
|
63
80
|
const weight = Math.min((width / 2 - Math.abs(px - cx)) / dx, (depth / 2 - Math.abs(pz - cz)) / dz);
|
|
64
81
|
if (weight >= 1) return height(px, pz);
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Precomputes 8-azimuth terrain horizon elevation angles (by default out to 740 m) for km-scale low-sun mountain shadows.
|
|
3
|
+
* Pure math/geometry helper safe to run inside Web Workers with zero Three.js dependencies.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { clamp } from '../math/scalar.js';
|
|
8
|
+
|
|
9
|
+
const MAX_HORIZON_RAD = Math.PI * 0.45;
|
|
10
|
+
const AZIMUTH_DIRS = Array.from({ length: 8 }, (_, k) => {
|
|
11
|
+
const angle = (k * Math.PI) / 4;
|
|
12
|
+
return [Math.cos(angle), Math.sin(angle)];
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sample distances for {@link bakeHorizonAngles}: `count` distances growing evenly by ratio from four grid spacings out to
|
|
17
|
+
* `reach`, so that a finer grid looks at nearer ground first and every grid sees as far.
|
|
18
|
+
*
|
|
19
|
+
* @param {number} spacing Metres between grid samples.
|
|
20
|
+
* @param {object} [options]
|
|
21
|
+
* @param {number} [options.reach=740] The farthest distance looked along, in metres.
|
|
22
|
+
* @param {number} [options.count=15] How many distances.
|
|
23
|
+
* @returns {number[]} Distances in metres, nearest first, rounded to a tenth of a metre.
|
|
24
|
+
*/
|
|
25
|
+
export function horizonSteps(spacing, { reach = 740, count = 15 } = {}) {
|
|
26
|
+
const first = Math.min(4 * spacing, reach),
|
|
27
|
+
ratio = count > 1 ? (reach / first) ** (1 / (count - 1)) : 1;
|
|
28
|
+
return Array.from({ length: count }, (_, i) => Math.round(first * ratio ** i * 10) / 10);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Bakes 8-azimuth horizon elevation angles on a heightfield grid into a compact `Uint8Array(stride * rows * 8)`.
|
|
33
|
+
* Channels 3 and 7 (`.w` of `aHorizon0` and `aHorizon1`) are stored inverted (`255 - byte`) so any secondary
|
|
34
|
+
* mesh lacking those attributes receives WebGL's default `(0, 0, 0, 1)`, decoding to `0` (`0 rad` flat horizon).
|
|
35
|
+
*
|
|
36
|
+
* @param {Float32Array} heights Row-major heightfield (`stride * rows`).
|
|
37
|
+
* @param {number} stride Columns per row.
|
|
38
|
+
* @param {number} rows Number of rows.
|
|
39
|
+
* @param {number} spacing Metres between grid samples.
|
|
40
|
+
* @param {object} [options]
|
|
41
|
+
* @param {number[]} [options.steps] Sample distances in metres along each azimuth; by default {@link horizonSteps} of the spacing.
|
|
42
|
+
* @param {number} [options.coarse=2] Coarse grid stride (`1` full grid, `2` half-grid bilinearly upsampled for fast worker bakes).
|
|
43
|
+
* @returns {Uint8Array} Packed 8-byte-per-vertex horizon buffer.
|
|
44
|
+
*/
|
|
45
|
+
export function bakeHorizonAngles(heights, stride, rows, spacing, { steps = horizonSteps(spacing), coarse = 2 } = {}) {
|
|
46
|
+
const stepStride = Math.max(1, coarse | 0),
|
|
47
|
+
cw = Math.floor((stride - 1) / stepStride) + 1,
|
|
48
|
+
ch = Math.floor((rows - 1) / stepStride) + 1,
|
|
49
|
+
invSpacing = 1 / spacing,
|
|
50
|
+
maxCol = stride - 1,
|
|
51
|
+
maxRow = rows - 1,
|
|
52
|
+
stepCount = steps.length,
|
|
53
|
+
gridSteps = new Float32Array(stepCount),
|
|
54
|
+
invDists = new Float32Array(stepCount);
|
|
55
|
+
|
|
56
|
+
for (let s = 0; s < stepCount; s++) {
|
|
57
|
+
gridSteps[s] = steps[s] * invSpacing;
|
|
58
|
+
invDists[s] = 1 / Math.max(steps[s], 0.5);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const coarseAngles = new Float32Array(cw * ch * 8);
|
|
62
|
+
|
|
63
|
+
for (let cj = 0; cj < ch; cj++) {
|
|
64
|
+
const j = Math.min(cj * stepStride, maxRow),
|
|
65
|
+
rowOffset = j * stride;
|
|
66
|
+
for (let ci = 0; ci < cw; ci++) {
|
|
67
|
+
const i = Math.min(ci * stepStride, maxCol),
|
|
68
|
+
h0 = heights[rowOffset + i],
|
|
69
|
+
dst = (cj * cw + ci) * 8;
|
|
70
|
+
for (let dirIdx = 0; dirIdx < 8; dirIdx++) {
|
|
71
|
+
const dx = AZIMUTH_DIRS[dirIdx][0],
|
|
72
|
+
dz = AZIMUTH_DIRS[dirIdx][1];
|
|
73
|
+
let maxRise = 0;
|
|
74
|
+
for (let s = 0; s < stepCount; s++) {
|
|
75
|
+
const gDist = gridSteps[s],
|
|
76
|
+
fx = i + dx * gDist,
|
|
77
|
+
fz = j + dz * gDist;
|
|
78
|
+
if (fx < 0 || fx > maxCol || fz < 0 || fz > maxRow) break;
|
|
79
|
+
const ix = fx | 0,
|
|
80
|
+
iz = fz | 0,
|
|
81
|
+
ix1 = ix < maxCol ? ix + 1 : ix,
|
|
82
|
+
iz1 = iz < maxRow ? iz + 1 : iz,
|
|
83
|
+
tx = fx - ix,
|
|
84
|
+
tz = fz - iz,
|
|
85
|
+
r0 = iz * stride,
|
|
86
|
+
r1 = iz1 * stride,
|
|
87
|
+
h00 = heights[r0 + ix],
|
|
88
|
+
h10 = heights[r0 + ix1],
|
|
89
|
+
h01 = heights[r1 + ix],
|
|
90
|
+
h11 = heights[r1 + ix1],
|
|
91
|
+
hSample = (h00 + (h10 - h00) * tx) * (1 - tz) + (h01 + (h11 - h01) * tx) * tz,
|
|
92
|
+
rise = (hSample - h0) * invDists[s];
|
|
93
|
+
if (rise > maxRise) maxRise = rise;
|
|
94
|
+
}
|
|
95
|
+
coarseAngles[dst + dirIdx] = maxRise > 0 ? clamp(Math.atan(maxRise) / MAX_HORIZON_RAD, 0, 1) : 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const out = new Uint8Array(stride * rows * 8);
|
|
101
|
+
const maxCi = cw - 1,
|
|
102
|
+
maxCj = ch - 1;
|
|
103
|
+
|
|
104
|
+
for (let j = 0; j < rows; j++) {
|
|
105
|
+
const fy = j / stepStride,
|
|
106
|
+
cj0 = Math.min(fy | 0, maxCj),
|
|
107
|
+
cj1 = Math.min(cj0 + 1, maxCj),
|
|
108
|
+
ty = clamp(fy - cj0, 0, 1);
|
|
109
|
+
for (let i = 0; i < stride; i++) {
|
|
110
|
+
const fx = i / stepStride,
|
|
111
|
+
ci0 = Math.min(fx | 0, maxCi),
|
|
112
|
+
ci1 = Math.min(ci0 + 1, maxCi),
|
|
113
|
+
tx = clamp(fx - ci0, 0, 1),
|
|
114
|
+
k00 = (cj0 * cw + ci0) * 8,
|
|
115
|
+
k10 = (cj0 * cw + ci1) * 8,
|
|
116
|
+
k01 = (cj1 * cw + ci0) * 8,
|
|
117
|
+
k11 = (cj1 * cw + ci1) * 8,
|
|
118
|
+
dst = (j * stride + i) * 8;
|
|
119
|
+
for (let d = 0; d < 8; d++) {
|
|
120
|
+
const v0 = coarseAngles[k00 + d] + (coarseAngles[k10 + d] - coarseAngles[k00 + d]) * tx,
|
|
121
|
+
v1 = coarseAngles[k01 + d] + (coarseAngles[k11 + d] - coarseAngles[k01 + d]) * tx,
|
|
122
|
+
byte = Math.round(clamp(v0 + (v1 - v0) * ty, 0, 1) * 255);
|
|
123
|
+
out[dst + d] = d === 3 || d === 7 ? 255 - byte : byte;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Vertex shader declarations for decoding 8-azimuth horizon shadows into `vHorizonSun`. */
|
|
132
|
+
export const HORIZON_SUN_VERTEX_PARS = `/* glsl */
|
|
133
|
+
attribute vec4 aHorizon0, aHorizon1;
|
|
134
|
+
uniform vec4 uHorizonLight;
|
|
135
|
+
varying float vHorizonSun;
|
|
136
|
+
float sampleHorizonSector(int idx, vec4 h0, vec4 h1) {
|
|
137
|
+
if (idx == 0) return h0.x;
|
|
138
|
+
if (idx == 1) return h0.y;
|
|
139
|
+
if (idx == 2) return h0.z;
|
|
140
|
+
if (idx == 3) return 1.0 - h0.w;
|
|
141
|
+
if (idx == 4) return h1.x;
|
|
142
|
+
if (idx == 5) return h1.y;
|
|
143
|
+
if (idx == 6) return h1.z;
|
|
144
|
+
return 1.0 - h1.w;
|
|
145
|
+
}
|
|
146
|
+
float computeHorizonSun(vec4 h0, vec4 h1, vec4 light) {
|
|
147
|
+
if (light.w <= 0.001) return 1.0;
|
|
148
|
+
float az = atan(light.z, light.x);
|
|
149
|
+
float sector = mod(az * 1.27323954 + 8.0, 8.0);
|
|
150
|
+
int s0 = int(floor(sector));
|
|
151
|
+
int s1 = (s0 + 1) % 8;
|
|
152
|
+
float frac = sector - float(s0);
|
|
153
|
+
float horizonElev = mix(sampleHorizonSector(s0, h0, h1), sampleHorizonSector(s1, h0, h1), frac) * ${MAX_HORIZON_RAD.toFixed(5)};
|
|
154
|
+
float sunElev = asin(clamp(light.y, -1.0, 1.0));
|
|
155
|
+
float vis = smoothstep(horizonElev - 0.022, horizonElev + 0.026, sunElev);
|
|
156
|
+
return mix(1.0, vis, light.w);
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
export const HORIZON_SUN_VERTEX = `/* glsl */
|
|
161
|
+
vHorizonSun = computeHorizonSun(aHorizon0, aHorizon1, uHorizonLight);
|
|
162
|
+
`;
|
|
163
|
+
|
|
164
|
+
export const HORIZON_SUN_FRAGMENT_PARS = `/* glsl */
|
|
165
|
+
varying float vHorizonSun;
|
|
166
|
+
`;
|