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,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedural catenary-sagged canvas sheets and grounded contact-occlusion helpers for static geometry builders.
|
|
3
|
+
* Pure typed-array math with zero Three.js dependency so Web Workers and Node tests can call it directly.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { dim } from '../math/color.js';
|
|
8
|
+
import { clamp, lerp, TAU } from '../math/scalar.js';
|
|
9
|
+
import { sampleSurface } from './sampled-surface.js';
|
|
10
|
+
|
|
11
|
+
function panelNoise(index, seed) {
|
|
12
|
+
const raw = Math.sin(index * 127.1 + seed * 311.7) * 43758.5453123;
|
|
13
|
+
return raw - Math.floor(raw);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function bilinearPoint(corners, u, v, out) {
|
|
17
|
+
const [topLeft, topRight, bottomRight, bottomLeft] = corners;
|
|
18
|
+
const topX = lerp(topLeft[0], topRight[0], u);
|
|
19
|
+
const topY = lerp(topLeft[1], topRight[1], u);
|
|
20
|
+
const topZ = lerp(topLeft[2], topRight[2], u);
|
|
21
|
+
const bottomX = lerp(bottomLeft[0], bottomRight[0], u);
|
|
22
|
+
const bottomY = lerp(bottomLeft[1], bottomRight[1], u);
|
|
23
|
+
const bottomZ = lerp(bottomLeft[2], bottomRight[2], u);
|
|
24
|
+
out[0] = lerp(topX, bottomX, v);
|
|
25
|
+
out[1] = lerp(topY, bottomY, v);
|
|
26
|
+
out[2] = lerp(topZ, bottomZ, v);
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sheetNormal(corners, out) {
|
|
31
|
+
const [topLeft, topRight, , bottomLeft] = corners;
|
|
32
|
+
const ux = topRight[0] - topLeft[0];
|
|
33
|
+
const uy = topRight[1] - topLeft[1];
|
|
34
|
+
const uz = topRight[2] - topLeft[2];
|
|
35
|
+
const vx = bottomLeft[0] - topLeft[0];
|
|
36
|
+
const vy = bottomLeft[1] - topLeft[1];
|
|
37
|
+
const vz = bottomLeft[2] - topLeft[2];
|
|
38
|
+
const nx = vy * uz - vz * uy;
|
|
39
|
+
const ny = vz * ux - vx * uz;
|
|
40
|
+
const nz = vx * uy - vy * ux;
|
|
41
|
+
const length = Math.hypot(nx, ny, nz) || 1;
|
|
42
|
+
out[0] = nx / length;
|
|
43
|
+
out[1] = ny / length;
|
|
44
|
+
out[2] = nz / length;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Append a subdivided canvas sheet stretched between four corner anchors `[topLeft, topRight, bottomRight, bottomLeft]`.
|
|
50
|
+
* Applies natural gravity catenary sag, optional wind/pressure belly, scalloped tension along edges, and stitched panel
|
|
51
|
+
* seam darkening encoded in vertex colours.
|
|
52
|
+
*
|
|
53
|
+
* @param {Pick<import('./builder.js').GB, 'raw'>} builder - Destination geometry builder.
|
|
54
|
+
* @param {Array<ArrayLike<number>>} corners - Four `[x, y, z]` anchors in `[topLeft, topRight, bottomRight, bottomLeft]` order.
|
|
55
|
+
* @param {{
|
|
56
|
+
* columns?: number,
|
|
57
|
+
* rows?: number,
|
|
58
|
+
* sag?: number,
|
|
59
|
+
* edgeSagU?: number,
|
|
60
|
+
* edgeSagV?: number,
|
|
61
|
+
* ridgeSag?: number,
|
|
62
|
+
* sagDir?: ArrayLike<number>,
|
|
63
|
+
* belly?: number,
|
|
64
|
+
* bellyDir?: ArrayLike<number>,
|
|
65
|
+
* scallopU?: number,
|
|
66
|
+
* scallopV?: number,
|
|
67
|
+
* scallopCountU?: number,
|
|
68
|
+
* scallopCountV?: number,
|
|
69
|
+
* panelsU?: number,
|
|
70
|
+
* panelsV?: number,
|
|
71
|
+
* seamDarken?: number,
|
|
72
|
+
* panelVariation?: number,
|
|
73
|
+
* hemDarken?: number,
|
|
74
|
+
* reefBands?: number[],
|
|
75
|
+
* reefDarken?: number,
|
|
76
|
+
* seed?: number,
|
|
77
|
+
* color: ArrayLike<number> | ((u: number, v: number) => ArrayLike<number>),
|
|
78
|
+
* flip?: boolean,
|
|
79
|
+
* back?: boolean | ArrayLike<number>,
|
|
80
|
+
* }} options - Subdivision, sag, tension scalloping, panel seam shading, and linear RGB colour options.
|
|
81
|
+
*/
|
|
82
|
+
export function catenaryCanvas(builder, corners, options) {
|
|
83
|
+
if (!Array.isArray(corners) || corners.length !== 4) {
|
|
84
|
+
throw new RangeError('catenaryCanvas expects four [x, y, z] corner anchors');
|
|
85
|
+
}
|
|
86
|
+
const columns = Math.max(1, Math.round(options.columns ?? 8));
|
|
87
|
+
const rows = Math.max(1, Math.round(options.rows ?? 6));
|
|
88
|
+
const sag = options.sag ?? 0.12;
|
|
89
|
+
const edgeSagU = options.edgeSagU ?? 0.25;
|
|
90
|
+
const edgeSagV = options.edgeSagV ?? 0.15;
|
|
91
|
+
const ridgeSag = options.ridgeSag ?? 0;
|
|
92
|
+
const sagDir = options.sagDir ?? [0, -1, 0];
|
|
93
|
+
const belly = options.belly ?? 0;
|
|
94
|
+
const scallopU = options.scallopU ?? 0;
|
|
95
|
+
const scallopV = options.scallopV ?? 0;
|
|
96
|
+
const scallopCountU = Math.max(1, Math.round(options.scallopCountU ?? 1));
|
|
97
|
+
const scallopCountV = Math.max(1, Math.round(options.scallopCountV ?? 1));
|
|
98
|
+
const panelsU = Math.max(1, Math.round(options.panelsU ?? 1));
|
|
99
|
+
const panelsV = Math.max(1, Math.round(options.panelsV ?? 1));
|
|
100
|
+
const seamDarken = clamp(options.seamDarken ?? 0.14, 0, 0.7);
|
|
101
|
+
const panelVariation = clamp(options.panelVariation ?? 0.06, 0, 0.35);
|
|
102
|
+
const hemDarken = clamp(options.hemDarken ?? 0.08, 0, 0.6);
|
|
103
|
+
const reefBands = options.reefBands ?? null;
|
|
104
|
+
const reefDarken = clamp(options.reefDarken ?? 0.12, 0, 0.6);
|
|
105
|
+
const seed = options.seed ?? 17;
|
|
106
|
+
const baseColor = options.color;
|
|
107
|
+
const colorIsFn = typeof baseColor === 'function';
|
|
108
|
+
const flip = !!options.flip;
|
|
109
|
+
const back = options.back ?? false;
|
|
110
|
+
|
|
111
|
+
const bellyAxis = options.bellyDir ? [options.bellyDir[0], options.bellyDir[1], options.bellyDir[2]] : sheetNormal(corners, [0, 1, 0]);
|
|
112
|
+
const bellyLen = Math.hypot(bellyAxis[0], bellyAxis[1], bellyAxis[2]) || 1;
|
|
113
|
+
bellyAxis[0] /= bellyLen;
|
|
114
|
+
bellyAxis[1] /= bellyLen;
|
|
115
|
+
bellyAxis[2] /= bellyLen;
|
|
116
|
+
|
|
117
|
+
const sagLen = Math.hypot(sagDir[0], sagDir[1], sagDir[2]) || 1;
|
|
118
|
+
const sagX = sagDir[0] / sagLen;
|
|
119
|
+
const sagY = sagDir[1] / sagLen;
|
|
120
|
+
const sagZ = sagDir[2] / sagLen;
|
|
121
|
+
|
|
122
|
+
// Approximate horizontal and vertical edge directions for inward tension scalloping.
|
|
123
|
+
const [topLeft, topRight, bottomRight, bottomLeft] = corners;
|
|
124
|
+
const widthVec = [
|
|
125
|
+
(topRight[0] - topLeft[0] + bottomRight[0] - bottomLeft[0]) * 0.5,
|
|
126
|
+
(topRight[1] - topLeft[1] + bottomRight[1] - bottomLeft[1]) * 0.5,
|
|
127
|
+
(topRight[2] - topLeft[2] + bottomRight[2] - bottomLeft[2]) * 0.5,
|
|
128
|
+
];
|
|
129
|
+
const heightVec = [
|
|
130
|
+
(bottomLeft[0] - topLeft[0] + bottomRight[0] - topRight[0]) * 0.5,
|
|
131
|
+
(bottomLeft[1] - topLeft[1] + bottomRight[1] - topRight[1]) * 0.5,
|
|
132
|
+
(bottomLeft[2] - topLeft[2] + bottomRight[2] - topRight[2]) * 0.5,
|
|
133
|
+
];
|
|
134
|
+
const widthLen = Math.hypot(widthVec[0], widthVec[1], widthVec[2]) || 1;
|
|
135
|
+
const heightLen = Math.hypot(heightVec[0], heightVec[1], heightVec[2]) || 1;
|
|
136
|
+
const unitU = [widthVec[0] / widthLen, widthVec[1] / widthLen, widthVec[2] / widthLen];
|
|
137
|
+
const unitV = [heightVec[0] / heightLen, heightVec[1] / heightLen, heightVec[2] / heightLen];
|
|
138
|
+
|
|
139
|
+
const pointScratch = [0, 0, 0];
|
|
140
|
+
const pointAt = (u, v) => {
|
|
141
|
+
bilinearPoint(corners, u, v, pointScratch);
|
|
142
|
+
const arcU = Math.sin(u * Math.PI);
|
|
143
|
+
const arcV = Math.sin(v * Math.PI);
|
|
144
|
+
|
|
145
|
+
// Natural catenary approximation: hangs between corner anchors and deepens toward the unsupported center.
|
|
146
|
+
const drop = sag * (arcU * arcV + edgeSagU * arcU * (1 - arcV) + edgeSagV * arcV * (1 - arcU)) + ridgeSag * arcU * (1 - v);
|
|
147
|
+
pointScratch[0] += sagX * drop;
|
|
148
|
+
pointScratch[1] += sagY * drop;
|
|
149
|
+
pointScratch[2] += sagZ * drop;
|
|
150
|
+
|
|
151
|
+
if (belly !== 0) {
|
|
152
|
+
const puff = belly * arcU * Math.sin(Math.min(1, v * 1.12) * Math.PI * 0.78);
|
|
153
|
+
pointScratch[0] += bellyAxis[0] * puff;
|
|
154
|
+
pointScratch[1] += bellyAxis[1] * puff;
|
|
155
|
+
pointScratch[2] += bellyAxis[2] * puff;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Scalloped tension pulls the free side and foot edges slightly inward between corner lashings.
|
|
159
|
+
if (scallopU !== 0) {
|
|
160
|
+
const pull = scallopU * Math.abs(Math.sin(v * Math.PI * scallopCountU));
|
|
161
|
+
const sideBias = 1 - 2 * u; // +1 on left edge (pulls toward +U), -1 on right edge (pulls toward -U)
|
|
162
|
+
pointScratch[0] += unitU[0] * pull * sideBias;
|
|
163
|
+
pointScratch[1] += unitU[1] * pull * sideBias;
|
|
164
|
+
pointScratch[2] += unitU[2] * pull * sideBias;
|
|
165
|
+
}
|
|
166
|
+
if (scallopV !== 0) {
|
|
167
|
+
const pull = scallopV * Math.abs(Math.sin(u * Math.PI * scallopCountV)) * v;
|
|
168
|
+
pointScratch[0] -= unitV[0] * pull;
|
|
169
|
+
pointScratch[1] -= unitV[1] * pull;
|
|
170
|
+
pointScratch[2] -= unitV[2] * pull;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return pointScratch;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Blend vertex colours so stitched seams, panel shading, and reef bands read cleanly without extra geometry.
|
|
177
|
+
const seamHalfU = 0.5 / Math.max(columns, 1);
|
|
178
|
+
const seamHalfV = 0.5 / Math.max(rows, 1);
|
|
179
|
+
const colorAt = (u, v) => {
|
|
180
|
+
const rawColor = colorIsFn ? baseColor(u, v) : baseColor;
|
|
181
|
+
let shade = 1;
|
|
182
|
+
|
|
183
|
+
if (panelsU > 1) {
|
|
184
|
+
const panelPos = u * panelsU;
|
|
185
|
+
const panelIndex = Math.min(panelsU - 1, Math.floor(panelPos));
|
|
186
|
+
shade *= 1 + (panelNoise(panelIndex, seed) - 0.5) * 2 * panelVariation;
|
|
187
|
+
if (seamDarken > 0 && u > 0.001 && u < 0.999) {
|
|
188
|
+
const distToSeam = Math.abs(panelPos - Math.round(panelPos)) / panelsU;
|
|
189
|
+
if (distToSeam <= seamHalfU * 0.85) {
|
|
190
|
+
const weight = 1 - distToSeam / (seamHalfU * 0.85);
|
|
191
|
+
shade *= 1 - seamDarken * weight;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (panelsV > 1) {
|
|
197
|
+
const rowPos = v * panelsV;
|
|
198
|
+
const rowIndex = Math.min(panelsV - 1, Math.floor(rowPos));
|
|
199
|
+
shade *= 1 + (panelNoise(rowIndex + 37, seed) - 0.5) * panelVariation;
|
|
200
|
+
if (seamDarken > 0 && v > 0.001 && v < 0.999) {
|
|
201
|
+
const distToSeam = Math.abs(rowPos - Math.round(rowPos)) / panelsV;
|
|
202
|
+
if (distToSeam <= seamHalfV * 0.85) {
|
|
203
|
+
const weight = 1 - distToSeam / (seamHalfV * 0.85);
|
|
204
|
+
shade *= 1 - seamDarken * 0.85 * weight;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (reefBands && reefBands.length > 0 && reefDarken > 0) {
|
|
210
|
+
for (let i = 0; i < reefBands.length; i++) {
|
|
211
|
+
const dist = Math.abs(v - reefBands[i]);
|
|
212
|
+
if (dist <= seamHalfV * 1.1) {
|
|
213
|
+
shade *= 1 - reefDarken * (1 - dist / (seamHalfV * 1.1));
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (hemDarken > 0) {
|
|
220
|
+
// Subtle darkening near the lower hem where dust and shadow gather.
|
|
221
|
+
shade *= 1 - hemDarken * v * v;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return [clamp(rawColor[0] * shade, 0, 1), clamp(rawColor[1] * shade, 0, 1), clamp(rawColor[2] * shade, 0, 1)];
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
sampleSurface(builder, columns, rows, pointAt, colorAt, { blend: true, flip, back });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Append a low vertex-darkened contact-occlusion skirt hugging the base of a prop (barrel, crate, chest, tent, or post)
|
|
232
|
+
* so its lower edge seats firmly into sand, wood, or stone with natural ambient occlusion.
|
|
233
|
+
*
|
|
234
|
+
* @param {Pick<import('./builder.js').GB, 'raw'>} builder - Destination geometry builder.
|
|
235
|
+
* @param {{
|
|
236
|
+
* x?: number,
|
|
237
|
+
* y?: number,
|
|
238
|
+
* z?: number,
|
|
239
|
+
* shape?: 'round' | 'rect',
|
|
240
|
+
* radiusX?: number,
|
|
241
|
+
* radiusZ?: number,
|
|
242
|
+
* width?: number,
|
|
243
|
+
* depth?: number,
|
|
244
|
+
* height?: number,
|
|
245
|
+
* flare?: number,
|
|
246
|
+
* segments?: number,
|
|
247
|
+
* yaw?: number,
|
|
248
|
+
* color: ArrayLike<number>,
|
|
249
|
+
* bottomFactor?: number,
|
|
250
|
+
* }} options - Footprint shape, dimensions in metres, base darkening multiplier, and upper linear RGB colour.
|
|
251
|
+
*/
|
|
252
|
+
export function contactShadowSkirt(builder, options) {
|
|
253
|
+
const cx = options.x ?? 0;
|
|
254
|
+
const cy = options.y ?? 0;
|
|
255
|
+
const cz = options.z ?? 0;
|
|
256
|
+
const shape = options.shape ?? 'round';
|
|
257
|
+
const height = Math.max(0.005, options.height ?? 0.08);
|
|
258
|
+
const flare = Math.max(0, options.flare ?? 0.02);
|
|
259
|
+
const yaw = options.yaw ?? 0;
|
|
260
|
+
const cosYaw = Math.cos(yaw);
|
|
261
|
+
const sinYaw = Math.sin(yaw);
|
|
262
|
+
const topColor = options.color;
|
|
263
|
+
const bottomFactor = clamp(options.bottomFactor ?? 0.44, 0.05, 1);
|
|
264
|
+
const bottomColor = dim(topColor, bottomFactor);
|
|
265
|
+
|
|
266
|
+
const ring = [];
|
|
267
|
+
if (shape === 'rect') {
|
|
268
|
+
const halfWidth = Math.max(0.01, (options.width ?? (options.radiusX ?? 0.5) * 2) * 0.5);
|
|
269
|
+
const halfDepth = Math.max(0.01, (options.depth ?? (options.radiusZ ?? halfWidth) * 2) * 0.5);
|
|
270
|
+
ring.push(
|
|
271
|
+
[-halfWidth, halfDepth, -1, 1],
|
|
272
|
+
[halfWidth, halfDepth, 1, 1],
|
|
273
|
+
[halfWidth, -halfDepth, 1, -1],
|
|
274
|
+
[-halfWidth, -halfDepth, -1, -1],
|
|
275
|
+
);
|
|
276
|
+
} else {
|
|
277
|
+
const segments = Math.max(6, Math.round(options.segments ?? 12));
|
|
278
|
+
const rx = Math.max(0.01, options.radiusX ?? (options.width ?? 0.6) * 0.5);
|
|
279
|
+
const rz = Math.max(0.01, options.radiusZ ?? (options.depth ?? rx * 2) * 0.5);
|
|
280
|
+
for (let i = 0; i < segments; i++) {
|
|
281
|
+
// Step counter-clockwise when viewed from +Y so every skirt face winds outward.
|
|
282
|
+
const angle = -(i / segments) * TAU;
|
|
283
|
+
const ca = Math.cos(angle);
|
|
284
|
+
const sa = Math.sin(angle);
|
|
285
|
+
ring.push([ca * rx, sa * rz, ca, sa]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const rotatePoint = (lx, lz) => [cx + lx * cosYaw + lz * sinYaw, cz - lx * sinYaw + lz * cosYaw];
|
|
290
|
+
const count = ring.length;
|
|
291
|
+
|
|
292
|
+
for (let i = 0; i < count; i++) {
|
|
293
|
+
const [ax, az, anx, anz] = ring[i];
|
|
294
|
+
const [bx, bz, bnx, bnz] = ring[(i + 1) % count];
|
|
295
|
+
const aOutLen = Math.hypot(anx, anz) || 1;
|
|
296
|
+
const bOutLen = Math.hypot(bnx, bnz) || 1;
|
|
297
|
+
const [aTopX, aTopZ] = rotatePoint(ax, az);
|
|
298
|
+
const [bTopX, bTopZ] = rotatePoint(bx, bz);
|
|
299
|
+
const [aBotX, aBotZ] = rotatePoint(ax + (anx / aOutLen) * flare, az + (anz / aOutLen) * flare);
|
|
300
|
+
const [bBotX, bBotZ] = rotatePoint(bx + (bnx / bOutLen) * flare, bz + (bnz / bOutLen) * flare);
|
|
301
|
+
|
|
302
|
+
const edgeX = bTopX - aTopX;
|
|
303
|
+
const edgeZ = bTopZ - aTopZ;
|
|
304
|
+
let nx = -edgeZ;
|
|
305
|
+
let nz = edgeX;
|
|
306
|
+
const nLen = Math.hypot(nx, nz) || 1;
|
|
307
|
+
nx /= nLen;
|
|
308
|
+
nz /= nLen;
|
|
309
|
+
// Ensure face normals point outward away from the prop center.
|
|
310
|
+
if (nx * ((aTopX + bTopX) * 0.5 - cx) + nz * ((aTopZ + bTopZ) * 0.5 - cz) < 0) {
|
|
311
|
+
nx = -nx;
|
|
312
|
+
nz = -nz;
|
|
313
|
+
}
|
|
314
|
+
const ny = 0.25;
|
|
315
|
+
const normDiv = Math.hypot(nx, ny, nz) || 1;
|
|
316
|
+
nx /= normDiv;
|
|
317
|
+
const nyUnit = ny / normDiv;
|
|
318
|
+
nz /= normDiv;
|
|
319
|
+
|
|
320
|
+
// Emit outward-facing quad with darkened foot and smooth blend to prop colour at the upper edge.
|
|
321
|
+
builder.raw(aBotX, cy, aBotZ, nx, nyUnit, nz, bottomColor[0], bottomColor[1], bottomColor[2]);
|
|
322
|
+
builder.raw(bBotX, cy, bBotZ, nx, nyUnit, nz, bottomColor[0], bottomColor[1], bottomColor[2]);
|
|
323
|
+
builder.raw(bTopX, cy + height, bTopZ, nx, nyUnit, nz, topColor[0], topColor[1], topColor[2]);
|
|
324
|
+
|
|
325
|
+
builder.raw(aBotX, cy, aBotZ, nx, nyUnit, nz, bottomColor[0], bottomColor[1], bottomColor[2]);
|
|
326
|
+
builder.raw(bTopX, cy + height, bTopZ, nx, nyUnit, nz, topColor[0], topColor[1], topColor[2]);
|
|
327
|
+
builder.raw(aTopX, cy + height, aTopZ, nx, nyUnit, nz, topColor[0], topColor[1], topColor[2]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Append a soft ground contact-shadow pad beneath a prop.
|
|
333
|
+
* In `'uv'` mode (2 triangles), vertex colours encode `(u, v, pattern)` for alpha-blended decal shaders.
|
|
334
|
+
* In `'shaded'` mode, emits a radial vertex-shaded pad darkening from `outerColor` at the rim to `innerColor` at the center.
|
|
335
|
+
*
|
|
336
|
+
* @param {Pick<import('./builder.js').GB, 'raw'>} builder - Destination geometry builder.
|
|
337
|
+
* @param {{
|
|
338
|
+
* x?: number,
|
|
339
|
+
* y?: number,
|
|
340
|
+
* z?: number,
|
|
341
|
+
* width?: number,
|
|
342
|
+
* depth?: number,
|
|
343
|
+
* yaw?: number,
|
|
344
|
+
* mode?: 'uv' | 'shaded',
|
|
345
|
+
* pattern?: number,
|
|
346
|
+
* segments?: number,
|
|
347
|
+
* innerColor?: ArrayLike<number>,
|
|
348
|
+
* outerColor?: ArrayLike<number>,
|
|
349
|
+
* }} [options] - Pad position, footprint dimensions in metres, yaw in radians, and encoding mode.
|
|
350
|
+
*/
|
|
351
|
+
export function contactShadowPad(builder, options = {}) {
|
|
352
|
+
const cx = options.x ?? 0;
|
|
353
|
+
const cy = options.y ?? 0.015;
|
|
354
|
+
const cz = options.z ?? 0;
|
|
355
|
+
const halfWidth = Math.max(0.02, (options.width ?? 1.0) * 0.5);
|
|
356
|
+
const halfDepth = Math.max(0.02, (options.depth ?? options.width ?? 1.0) * 0.5);
|
|
357
|
+
const yaw = options.yaw ?? 0;
|
|
358
|
+
const cosYaw = Math.cos(yaw);
|
|
359
|
+
const sinYaw = Math.sin(yaw);
|
|
360
|
+
const mode = options.mode ?? 'uv';
|
|
361
|
+
|
|
362
|
+
const toWorld = (lx, lz) => [cx + lx * cosYaw + lz * sinYaw, cz - lx * sinYaw + lz * cosYaw];
|
|
363
|
+
|
|
364
|
+
if (mode === 'uv') {
|
|
365
|
+
const pattern = options.pattern ?? 1;
|
|
366
|
+
const [ax, az] = toWorld(-halfWidth, halfDepth);
|
|
367
|
+
const [bx, bz] = toWorld(halfWidth, halfDepth);
|
|
368
|
+
const [cxp, czp] = toWorld(halfWidth, -halfDepth);
|
|
369
|
+
const [dx, dz] = toWorld(-halfWidth, -halfDepth);
|
|
370
|
+
|
|
371
|
+
builder.raw(ax, cy, az, 0, 1, 0, 0, 1, pattern);
|
|
372
|
+
builder.raw(bx, cy, bz, 0, 1, 0, 1, 1, pattern);
|
|
373
|
+
builder.raw(cxp, cy, czp, 0, 1, 0, 1, 0, pattern);
|
|
374
|
+
|
|
375
|
+
builder.raw(ax, cy, az, 0, 1, 0, 0, 1, pattern);
|
|
376
|
+
builder.raw(cxp, cy, czp, 0, 1, 0, 1, 0, pattern);
|
|
377
|
+
builder.raw(dx, cy, dz, 0, 1, 0, 0, 0, pattern);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const segments = Math.max(6, Math.round(options.segments ?? 12));
|
|
382
|
+
const innerColor = options.innerColor ?? [0.05, 0.045, 0.04];
|
|
383
|
+
const outerColor = options.outerColor ?? [0.22, 0.2, 0.17];
|
|
384
|
+
|
|
385
|
+
for (let i = 0; i < segments; i++) {
|
|
386
|
+
const a0 = (i / segments) * TAU;
|
|
387
|
+
const a1 = ((i + 1) / segments) * TAU;
|
|
388
|
+
const [x0, z0] = toWorld(Math.cos(a0) * halfWidth, Math.sin(a0) * halfDepth);
|
|
389
|
+
const [x1, z1] = toWorld(Math.cos(a1) * halfWidth, Math.sin(a1) * halfDepth);
|
|
390
|
+
|
|
391
|
+
// Counter-clockwise when viewed from +Y so the face normal points straight up.
|
|
392
|
+
builder.raw(cx, cy, cz, 0, 1, 0, innerColor[0], innerColor[1], innerColor[2]);
|
|
393
|
+
builder.raw(x1, cy, z1, 0, 1, 0, outerColor[0], outerColor[1], outerColor[2]);
|
|
394
|
+
builder.raw(x0, cy, z0, 0, 1, 0, outerColor[0], outerColor[1], outerColor[2]);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How cloth lies on a body: the fields of folds a loft is given by whoever builds a sleeve, a trouser leg, a tunic's body or a
|
|
3
|
+
* skirt.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { TAU, clamp, sstep } from '../math/scalar.js';
|
|
7
|
+
|
|
8
|
+
// How cloth lies on a body. Each field of folds is { relief, tight }: what stands out of a garment's surface at a height y and
|
|
9
|
+
// an angle a round it (metres, never less than 0: cloth stands off what it lies on and folds outward), which is the relief a
|
|
10
|
+
// loft is given (figure-sculpt.js, o.relief) by whoever builds a sleeve, a trouser leg, a tunic's body or a skirt; and how
|
|
11
|
+
// gathered the cloth is there (0 to 1), which is its crease (o.crease), drawn as finer folds by its material. Cloth folds
|
|
12
|
+
// where it is pushed together (the inside of an elbow, behind a knee, a sleeve stacked on its cuff), pouches over what holds
|
|
13
|
+
// it in (a belt, a boot's top, a bracer) and falls in long shallow folds where it hangs free. Plain arithmetic, for the pool's
|
|
14
|
+
// workers; each field is drawn from a run of chances of the person's own (`rand`), so that no two sleeves crease alike.
|
|
15
|
+
|
|
16
|
+
// Folds round a limb where its cloth is pushed together: ridges `wave` metres apart about the height `at`, dying away over
|
|
17
|
+
// `span` metres ([below, above]), `deep` metres at the angle `side` where the joint closes and `round` of that on the far side;
|
|
18
|
+
// the ridges lean (`lean` waves lower on the far side) and wander, and each stands out more here and less there.
|
|
19
|
+
function creases({ at, span, wave, deep, side = Math.PI / 2, round = 0.4, lean = 0.35 }, rand) {
|
|
20
|
+
const [below, above] = span,
|
|
21
|
+
p0 = rand() * TAU,
|
|
22
|
+
p1 = rand() * TAU,
|
|
23
|
+
p2 = rand() * TAU,
|
|
24
|
+
p3 = rand() * TAU,
|
|
25
|
+
// how much of the folds a height and an angle have
|
|
26
|
+
tight = (y, a) => {
|
|
27
|
+
const t = y < at ? (at - y) / below : (y - at) / above;
|
|
28
|
+
return t >= 1 ? 0 : (1 - t * t) * (1 - t * t) * (round + (1 - round) * (0.5 + 0.5 * Math.cos(a - side)));
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
tight,
|
|
32
|
+
relief: (y, a) => {
|
|
33
|
+
const share = tight(y, a);
|
|
34
|
+
if (!share) return 0;
|
|
35
|
+
const far = 0.5 - 0.5 * Math.cos(a - side),
|
|
36
|
+
phase = (y - at) / wave + lean * far + 0.16 * Math.sin(a + p1) + 0.09 * Math.sin(2 * a + p2);
|
|
37
|
+
return deep * share * (0.75 + 0.25 * Math.sin(3 * a + p3)) * (0.5 + 0.5 * Math.cos(TAU * phase + p0));
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Cloth held in at the height `at` and hanging over it from above (`up` 1: a sleeve over its cuff, a trouser leg over a boot's
|
|
42
|
+
// top, a tunic over its belt) or standing out under it (`up` -1): it stands out `out` metres a third of the way along the
|
|
43
|
+
// `tall` metres it takes to lie flat again, a little more here than there round the limb.
|
|
44
|
+
const POUCH_TIGHT = 0.7; // how gathered the cloth of a pouch is at its fullest
|
|
45
|
+
function pouch({ at, tall, out, up = 1 }, rand) {
|
|
46
|
+
const p0 = rand() * TAU,
|
|
47
|
+
p1 = rand() * TAU,
|
|
48
|
+
full = y => {
|
|
49
|
+
const t = ((y - at) * up) / tall;
|
|
50
|
+
return t <= 0 || t >= 1 ? 0 : 6.75 * t * (1 - t) * (1 - t);
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
tight: y => POUCH_TIGHT * full(y),
|
|
54
|
+
relief: (y, a) => out * full(y) * (0.8 + 0.14 * Math.sin(2 * a + p0) + 0.06 * Math.sin(5 * a + p1)),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Cloth hanging free between the heights `from` and `to` (either order: it begins at `from`): `n` shallow folds round it, `deep`
|
|
58
|
+
// metres at their fullest (reached `full` of the way along, 1 the far end), wandering a little as they fall.
|
|
59
|
+
function falls({ from, to, n, deep, full = 1 }, rand) {
|
|
60
|
+
const p0 = rand() * TAU,
|
|
61
|
+
p1 = rand() * TAU,
|
|
62
|
+
p2 = rand() * TAU,
|
|
63
|
+
turns = 2 + 2 * rand();
|
|
64
|
+
return {
|
|
65
|
+
tight: () => 0,
|
|
66
|
+
relief: (y, a) => {
|
|
67
|
+
const t = (y - from) / (to - from);
|
|
68
|
+
if (t <= 0 || t >= 1) return 0;
|
|
69
|
+
const fold = 0.5 + 0.5 * Math.cos(n * a + p0 + 0.5 * Math.sin(turns * t * Math.PI + p1) + 0.3 * Math.sin(a + p2));
|
|
70
|
+
return deep * sstep(0, full, t) * sstep(1, Math.min(0.999, full + 0.5 * (1 - full)), t) * fold * fold;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// The folds of cloth that hangs, round it: `n` of them, unevenly spaced and some fuller than others, each 1 where it stands
|
|
75
|
+
// out and 0 in the hollow beside it, swaying a little as they fall (t: how far down the cloth, 0 to 1).
|
|
76
|
+
function pipes(n, rand) {
|
|
77
|
+
const p0 = rand() * TAU,
|
|
78
|
+
p1 = rand() * TAU,
|
|
79
|
+
p2 = rand() * TAU,
|
|
80
|
+
p3 = rand() * TAU,
|
|
81
|
+
p4 = rand() * TAU,
|
|
82
|
+
sway = 0.25 + 0.35 * rand();
|
|
83
|
+
return (a, t = 0) => {
|
|
84
|
+
const wave = 0.5 + 0.5 * Math.cos(a * n + p0 + 0.55 * Math.sin(a + p1) + 0.3 * Math.sin(2 * a + p2) + sway * Math.sin(3 * t + p4));
|
|
85
|
+
return wave * (0.7 + 0.3 * Math.sin(3 * a + p3));
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// Cloth that is nowhere gathered: the crease of a garment that has no folds of its own (a far body's, a collar).
|
|
89
|
+
const SMOOTH = () => 0;
|
|
90
|
+
// Several fields as one, lying flat above the height `over` (coming in over `ease` metres under it): where the garment is
|
|
91
|
+
// sewn to the rest (a sleeve at its shoulder, a trouser leg at the hips).
|
|
92
|
+
function folded(fields, over = Infinity, ease = 0.03) {
|
|
93
|
+
const sewn = y => clamp((over - y) / ease, 0, 1);
|
|
94
|
+
return {
|
|
95
|
+
relief: (y, a) => {
|
|
96
|
+
if (y >= over) return 0;
|
|
97
|
+
let out = 0;
|
|
98
|
+
for (let i = 0; i < fields.length; i++) out += fields[i].relief(y, a);
|
|
99
|
+
return out * sewn(y);
|
|
100
|
+
},
|
|
101
|
+
tight: (y, a) => {
|
|
102
|
+
if (y >= over) return 0;
|
|
103
|
+
let most = 0;
|
|
104
|
+
for (let i = 0; i < fields.length; i++) most = Math.max(most, fields[i].tight(y, a));
|
|
105
|
+
return most * sewn(y);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const RING_GAP = 0.004; // the least height between two rings (metres)
|
|
110
|
+
// Rows of numbers that begin with a height, from the highest down, with more rows between them (each number between its
|
|
111
|
+
// neighbours' by the height) so that no two are further apart than `step` between the heights `from` and `to` of each band
|
|
112
|
+
// ([from, to, step]): the rings folds need where the cloth creases.
|
|
113
|
+
function refined(rows, bands) {
|
|
114
|
+
const out = [];
|
|
115
|
+
for (let i = 0; i < rows.length; i++) {
|
|
116
|
+
out.push(rows[i]);
|
|
117
|
+
const a = rows[i],
|
|
118
|
+
b = rows[i + 1];
|
|
119
|
+
if (!b) break;
|
|
120
|
+
const heights = [];
|
|
121
|
+
for (const [from, to, step] of bands) {
|
|
122
|
+
const top = Math.min(a[0], from),
|
|
123
|
+
end = Math.max(b[0], to);
|
|
124
|
+
if (top - end < step * 0.5) continue;
|
|
125
|
+
// whole steps from the band's own top, so that a band crossing several rows is evenly ringed
|
|
126
|
+
for (let y = from - Math.ceil((from - top) / step - 1e-9) * step; y > end + step * 0.35; y -= step)
|
|
127
|
+
if (y < a[0] - step * 0.35) heights.push(y);
|
|
128
|
+
}
|
|
129
|
+
heights.sort((p, q) => q - p);
|
|
130
|
+
let last = a[0];
|
|
131
|
+
for (const y of heights) {
|
|
132
|
+
if (last - y < RING_GAP) continue; // two bands' rings at nearly one height
|
|
133
|
+
last = y;
|
|
134
|
+
const t = (a[0] - y) / (a[0] - b[0]),
|
|
135
|
+
row = a.map((v, k) => (typeof v === 'number' && typeof b[k] === 'number' ? v + (b[k] - v) * t : v));
|
|
136
|
+
row[0] = y;
|
|
137
|
+
out.push(row);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { SMOOTH, creases, falls, folded, pipes, pouch, refined };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small ground-crawling creature geometries for instanced crawling swarms (`createSwarm({ manner: 'crawl', ... })`), facing +z
|
|
3
|
+
* in metres and built from shared unit shapes.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { GB } from './builder.js';
|
|
8
|
+
import { TRS, plainUnitShapes } from './primitives.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default beetle linear colours: `shell` (wing cases, head, legs) and `sheen` (thorax gloss).
|
|
12
|
+
*/
|
|
13
|
+
export const BEETLE_LOOK = {
|
|
14
|
+
shell: [0.02, 0.022, 0.03],
|
|
15
|
+
sheen: [0.03, 0.06, 0.09],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Default rat linear colours: `coat` (body and head), `dark` (haunch), and `bare` (ears, feet, tail).
|
|
20
|
+
*/
|
|
21
|
+
export const RAT_LOOK = {
|
|
22
|
+
coat: [0.06, 0.05, 0.042],
|
|
23
|
+
dark: [0.035, 0.03, 0.026],
|
|
24
|
+
bare: [0.3, 0.2, 0.17],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A thumb-sized beetle facing +z: wing cases, thorax, head, and six legs.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} [shapes=plainUnitShapes()] Unit shapes library providing `sph`.
|
|
31
|
+
* @param {typeof BEETLE_LOOK} [look=BEETLE_LOOK] Linear vertex colours.
|
|
32
|
+
* @returns {import('three').BufferGeometry}
|
|
33
|
+
*/
|
|
34
|
+
export function beetleGeometry(shapes = plainUnitShapes(), look = BEETLE_LOOK) {
|
|
35
|
+
const b = new GB(),
|
|
36
|
+
{ shell, sheen } = look;
|
|
37
|
+
b.add(shapes.sph, shell, TRS(0, 0.012, -0.012, 0.034, 0.024, 0.046));
|
|
38
|
+
b.add(shapes.sph, sheen, TRS(0, 0.012, 0.016, 0.028, 0.02, 0.022));
|
|
39
|
+
b.add(shapes.sph, shell, TRS(0, 0.01, 0.032, 0.016, 0.012, 0.014));
|
|
40
|
+
for (const side of [-1, 1])
|
|
41
|
+
for (let k = 0; k < 3; k++)
|
|
42
|
+
b.box(side * 0.022, 0, 0.018 - k * 0.018, 0.022, 0.004, 0.004, shell, side * (0.5 - k * 0.5), 0, side * 0.5);
|
|
43
|
+
return b.build();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A ground rat facing +z: body, haunch, head with snout and ears, four feet, and a segmented bare tail.
|
|
48
|
+
*
|
|
49
|
+
* @param {object} [shapes=plainUnitShapes()] Unit shapes library providing `sph`, `cone6`, `cyl6`.
|
|
50
|
+
* @param {typeof RAT_LOOK} [look=RAT_LOOK] Linear vertex colours.
|
|
51
|
+
* @returns {import('three').BufferGeometry}
|
|
52
|
+
*/
|
|
53
|
+
export function ratGeometry(shapes = plainUnitShapes(), look = RAT_LOOK) {
|
|
54
|
+
const b = new GB(),
|
|
55
|
+
{ coat, dark, bare } = look;
|
|
56
|
+
b.add(shapes.sph, coat, TRS(0, 0.035, 0, 0.075, 0.07, 0.15));
|
|
57
|
+
b.add(shapes.sph, dark, TRS(0, 0.035, -0.06, 0.085, 0.078, 0.11));
|
|
58
|
+
b.add(shapes.sph, coat, TRS(0, 0.045, 0.085, 0.05, 0.048, 0.07));
|
|
59
|
+
b.add(shapes.cone6, coat, TRS(0, 0.04, 0.105, 0.03, 0.05, 0.03, 0, Math.PI / 2));
|
|
60
|
+
for (const side of [-1, 1]) {
|
|
61
|
+
b.add(shapes.sph, bare, TRS(side * 0.022, 0.075, 0.075, 0.022, 0.024, 0.008));
|
|
62
|
+
for (const fore of [-1, 1]) b.box(side * 0.035, 0, fore * 0.05, 0.014, 0.03, 0.02, bare);
|
|
63
|
+
}
|
|
64
|
+
for (let k = 0; k < 5; k++)
|
|
65
|
+
b.add(
|
|
66
|
+
shapes.cyl6,
|
|
67
|
+
bare,
|
|
68
|
+
TRS(Math.sin(k * 0.9) * 0.012, 0.022 - k * 0.003, -0.12 - k * 0.036, 0.012 - k * 0.0018, 0.04, 0.012 - k * 0.0018, 0, Math.PI / 2),
|
|
69
|
+
);
|
|
70
|
+
return b.build();
|
|
71
|
+
}
|
|
@@ -5,12 +5,16 @@ import { sstep } from '../math/scalar.js';
|
|
|
5
5
|
* RGB triples. Corner normals are area weighted over adjoining faces whose cosine is at least `crease` (default −1).
|
|
6
6
|
* Pass `wrap` for a closed column seam, `inside` to reverse winding, and `tint, slopeFrom, slopeTo` for optional
|
|
7
7
|
* upward-facing color. Degenerate triangles emit no vertices.
|
|
8
|
+
*
|
|
9
|
+
* `columns: [from, to]` shapes only the cells of those columns (counted along each row from 0, `to` exclusive), so a
|
|
10
|
+
* sheet too large for one frame is shaped a band at a time with a yield between bands. Every corner's normal is still
|
|
11
|
+
* summed over the faces of the whole grid, exactly as when the sheet is shaped whole, so no seam shows where bands meet.
|
|
8
12
|
*/
|
|
9
13
|
export function creasedSheet(
|
|
10
14
|
builder,
|
|
11
15
|
rows,
|
|
12
16
|
tones,
|
|
13
|
-
{ wrap = false, inside = false, crease = -1, tint = null, slopeFrom = 0, slopeTo = 1 } = {},
|
|
17
|
+
{ wrap = false, inside = false, crease = -1, tint = null, slopeFrom = 0, slopeTo = 1, columns = null } = {},
|
|
14
18
|
) {
|
|
15
19
|
if (rows.length < 2 || rows[0].length < 2) return;
|
|
16
20
|
const rowSegments = rows.length - 1,
|
|
@@ -98,8 +102,9 @@ export function creasedSheet(
|
|
|
98
102
|
tone[2] + (tint ? (tint[2] - tone[2]) * lay : 0),
|
|
99
103
|
);
|
|
100
104
|
};
|
|
105
|
+
const [firstColumn, pastColumn] = columns ?? [0, columnSegments];
|
|
101
106
|
for (let j = 0; j < rowSegments; j++)
|
|
102
|
-
for (let i =
|
|
107
|
+
for (let i = firstColumn; i < pastColumn; i++) {
|
|
103
108
|
const at = (j * columnSegments + i) * 6,
|
|
104
109
|
i1 = next(i);
|
|
105
110
|
// Both triangles share the top-left to bottom-right diagonal. Reverse their winding for an inside surface.
|