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,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect line segments for feature outlines and the subset that supports a surface
|
|
3
|
+
* highlight. Both maps are keyed by caller IDs. Each value is a flat array of
|
|
4
|
+
* segment endpoints [ax, ay, az, bx, by, bz, ...] in the caller's coordinate frame.
|
|
5
|
+
* Each recorder has independent state, suitable for building on a page or a worker.
|
|
6
|
+
* @param {number} ringSegments - Straight edges around a circular outline.
|
|
7
|
+
*/
|
|
8
|
+
export function createOutlineRecorder(ringSegments = 32) {
|
|
9
|
+
if (!Number.isInteger(ringSegments) || ringSegments < 3) throw new RangeError('A ring needs at least three segments');
|
|
10
|
+
const outlines = new Map(),
|
|
11
|
+
shines = new Map();
|
|
12
|
+
|
|
13
|
+
function segmentsFor(map, id) {
|
|
14
|
+
let segments = map.get(id);
|
|
15
|
+
if (!segments) map.set(id, (segments = []));
|
|
16
|
+
return segments;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Append an open path of [x, y, z] points. Repeat its first point to close it.
|
|
20
|
+
* Pass false to omit this path from the surface highlight. */
|
|
21
|
+
function path(id, points, shine = true) {
|
|
22
|
+
const edges = segmentsFor(outlines, id);
|
|
23
|
+
const highlighted = shine ? segmentsFor(shines, id) : null;
|
|
24
|
+
for (let i = 1; i < points.length; i++) {
|
|
25
|
+
edges.push(...points[i - 1], ...points[i]);
|
|
26
|
+
if (highlighted) highlighted.push(...points[i - 1], ...points[i]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Append a horizontal ring starting at +X and turning toward +Z. */
|
|
31
|
+
function ring(id, x, y, z, radius, shine = true) {
|
|
32
|
+
const points = [];
|
|
33
|
+
for (let i = 0; i <= ringSegments; i++) {
|
|
34
|
+
const angle = (i / ringSegments) * 2 * Math.PI;
|
|
35
|
+
points.push([x + Math.cos(angle) * radius, y, z + Math.sin(angle) * radius]);
|
|
36
|
+
}
|
|
37
|
+
path(id, points, shine);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Append a rectangle at each supplied height, using half-extents and a yaw in radians. */
|
|
41
|
+
function rectangle(id, x, z, halfX, halfZ, heights, yaw = 0, shine = true) {
|
|
42
|
+
const cos = Math.cos(yaw),
|
|
43
|
+
sin = Math.sin(yaw);
|
|
44
|
+
const corner = (u, v, y) => [x + u * cos + v * sin, y, z - u * sin + v * cos];
|
|
45
|
+
for (const y of heights) {
|
|
46
|
+
const first = corner(-halfX, -halfZ, y);
|
|
47
|
+
path(id, [first, corner(halfX, -halfZ, y), corner(halfX, halfZ, y), corner(-halfX, halfZ, y), first], shine);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Return ordered [id, segments] pairs in each channel, suitable for postMessage.
|
|
52
|
+
* The returned arrays belong to the caller. Existing references to the maps stay live. */
|
|
53
|
+
function drain() {
|
|
54
|
+
const record = { outlines: [...outlines], shines: [...shines] };
|
|
55
|
+
outlines.clear();
|
|
56
|
+
shines.clear();
|
|
57
|
+
return record;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Append a drained record without modifying or retaining its segment arrays. */
|
|
61
|
+
function merge(record) {
|
|
62
|
+
for (const [map, entries] of [
|
|
63
|
+
[outlines, record.outlines],
|
|
64
|
+
[shines, record.shines],
|
|
65
|
+
]) {
|
|
66
|
+
for (const [id, segments] of entries) {
|
|
67
|
+
const dest = segmentsFor(map, id);
|
|
68
|
+
for (let i = 0; i < segments.length; i++) dest.push(segments[i]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { outlines, shines, path, ring, rectangle, drain, merge };
|
|
74
|
+
}
|
package/geometry/part-ranges.js
CHANGED
|
@@ -16,3 +16,38 @@ export function joinParts(pieces) {
|
|
|
16
16
|
}
|
|
17
17
|
return joined;
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Insert separately built pieces into parallel geometry batches (for example, one per material).
|
|
22
|
+
* Each row of insertAt gives the offsets in the base batches where one piece belongs. The
|
|
23
|
+
* corresponding row of ends gives its exclusive ends in the added batches. Offsets count
|
|
24
|
+
* position components, as in joinParts. Rows are in insertion order and may repeat.
|
|
25
|
+
* A missing insertion row means the start of every batch. A null base batch is skipped.
|
|
26
|
+
* Use non-indexed vertex attributes with matching names, types and strides on both sides.
|
|
27
|
+
* Inputs retain ownership of their arrays. A batch with data on only one side reuses that side.
|
|
28
|
+
* @param {Array} base - Attribute records or null for excluded batches.
|
|
29
|
+
* @param {Array} added - Attribute records in the same batch order and layout.
|
|
30
|
+
* @param {Array} insertAt - One row per insertion.
|
|
31
|
+
* @param {Array} ends - Cumulative end offsets for the added pieces.
|
|
32
|
+
* @returns {Array} Attribute records in the original batch order.
|
|
33
|
+
*/
|
|
34
|
+
export function insertPartGroups(base, added, insertAt, ends) {
|
|
35
|
+
return base.map((parts, group) => {
|
|
36
|
+
if (!parts || !added[group].position.length) return parts;
|
|
37
|
+
if (!parts.position.length) return added[group];
|
|
38
|
+
if (parts.index || added[group].index) throw new TypeError('Mixed geometry batches must be non-indexed');
|
|
39
|
+
const pieces = [];
|
|
40
|
+
let baseStart = 0,
|
|
41
|
+
addedStart = 0;
|
|
42
|
+
for (let i = 0; i < ends.length; i++) {
|
|
43
|
+
const at = insertAt[i]?.[group] ?? 0;
|
|
44
|
+
const end = ends[i][group];
|
|
45
|
+
if (at > baseStart) pieces.push([parts, baseStart, at]);
|
|
46
|
+
if (end > addedStart) pieces.push([added[group], addedStart, end]);
|
|
47
|
+
baseStart = at;
|
|
48
|
+
addedStart = end;
|
|
49
|
+
}
|
|
50
|
+
if (baseStart < parts.position.length) pieces.push([parts, baseStart, parts.position.length]);
|
|
51
|
+
return joinParts(pieces);
|
|
52
|
+
});
|
|
53
|
+
}
|
package/geometry/path-field.js
CHANGED
|
@@ -5,6 +5,39 @@
|
|
|
5
5
|
|
|
6
6
|
import { clamp } from '../math/scalar.js';
|
|
7
7
|
|
|
8
|
+
/** Distance in world units from an X/Z point to a finite segment, including coincident endpoints.
|
|
9
|
+
* @param {number} x
|
|
10
|
+
* @param {number} z
|
|
11
|
+
* @param {[number, number]} start
|
|
12
|
+
* @param {[number, number]} end
|
|
13
|
+
*/
|
|
14
|
+
export function segmentDistance(x, z, start, end) {
|
|
15
|
+
const dx = end[0] - start[0],
|
|
16
|
+
dz = end[1] - start[1];
|
|
17
|
+
const px = x - start[0],
|
|
18
|
+
pz = z - start[1];
|
|
19
|
+
const fraction = clamp((px * dx + pz * dz) / (dx * dx + dz * dz || 1), 0, 1);
|
|
20
|
+
return Math.hypot(px - dx * fraction, pz - dz * fraction);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Test an X/Z point against an implicitly closed polygon using the even-odd rule.
|
|
24
|
+
* A horizontal scan includes its left crossing and excludes its right crossing.
|
|
25
|
+
* @param {[number, number][]} ring
|
|
26
|
+
* @param {number} x
|
|
27
|
+
* @param {number} z
|
|
28
|
+
*/
|
|
29
|
+
export function ringContains(ring, x, z) {
|
|
30
|
+
let inside = false;
|
|
31
|
+
for (let i = 0; i < ring.length; i++) {
|
|
32
|
+
const start = ring[i],
|
|
33
|
+
end = ring[(i + 1) % ring.length];
|
|
34
|
+
if (start[1] > z !== end[1] > z && x < ((end[0] - start[0]) * (z - start[1])) / (end[1] - start[1]) + start[0]) {
|
|
35
|
+
inside = !inside;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return inside;
|
|
39
|
+
}
|
|
40
|
+
|
|
8
41
|
/**
|
|
9
42
|
* @param {[number, number][]} line - Ordered X/Z points in world units.
|
|
10
43
|
* @returns {[number, number, number, number]} Bounds in the order [minX, maxX, minZ, maxZ].
|
|
@@ -71,7 +104,8 @@ function nearestPathPoint(path, x, z, reach, near) {
|
|
|
71
104
|
* @param {(t: number) => number} [valueFn] - Value at the normalized point index. Defaults to zero.
|
|
72
105
|
*/
|
|
73
106
|
function stampPath({ x0, z0, width, height, spacing }, points, radius, grid, valueGrid, valueFn) {
|
|
74
|
-
if (!(spacing > 0) || !Number.isFinite(spacing) || !Number.isFinite(radius) || radius < 0)
|
|
107
|
+
if (!(spacing > 0) || !Number.isFinite(spacing) || !Number.isFinite(radius) || radius < 0)
|
|
108
|
+
throw new RangeError('Expected positive spacing and a nonnegative radius');
|
|
75
109
|
const cellRadius = Math.ceil(radius / spacing);
|
|
76
110
|
for (let sampleIndex = 0; sampleIndex < points.length; sampleIndex++) {
|
|
77
111
|
const px = points[sampleIndex][0],
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build continuous planked wooden floors and decks that conform to sagged, cambered, or uneven height functions without radial gaps.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
function plankHash(a, b, seed) {
|
|
7
|
+
const raw = Math.sin(a * 127.1 + b * 311.7 + seed * 74.7) * 43758.5453123;
|
|
8
|
+
return raw - Math.floor(raw);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Lay parallel tongue-and-groove floorboards across a rectangular footprint, subdividing each board along its run so
|
|
13
|
+
* sagged bowls, settled rooms, or cambered decks stay watertight with bevelled dark seams and staggered butt joints.
|
|
14
|
+
*
|
|
15
|
+
* @param {Pick<import('./builder.js').GB, 'raw'>} builder - Destination geometry builder.
|
|
16
|
+
* @param {{xMin: number, xMax: number, zMin: number, zMax: number}} bounds - Floor rectangle in builder space (metres).
|
|
17
|
+
* @param {(x: number, z: number) => number} heightAt - Floor top height at `(x, z)` in metres.
|
|
18
|
+
* @param {{
|
|
19
|
+
* plankWidth?: number,
|
|
20
|
+
* lengthStep?: number,
|
|
21
|
+
* seamWidth?: number,
|
|
22
|
+
* seamDrop?: number,
|
|
23
|
+
* buttStride?: number,
|
|
24
|
+
* alongZ?: boolean,
|
|
25
|
+
* seed?: number,
|
|
26
|
+
* toneVariation?: number,
|
|
27
|
+
* color: ArrayLike<number>
|
|
28
|
+
* }} options - Plank dimensions, seam bevel depth, butt-joint spacing, orientation, and base linear RGB colour.
|
|
29
|
+
* @example
|
|
30
|
+
* ```js
|
|
31
|
+
* import { GeometryBuilder } from 'roamwright';
|
|
32
|
+
* import { buildPlankedFloor } from 'roamwright/geometry/planked-floor.js';
|
|
33
|
+
*
|
|
34
|
+
* const wood = new GeometryBuilder();
|
|
35
|
+
* buildPlankedFloor(wood, { xMin: -4, xMax: 4, zMin: -4, zMax: 4 }, (x, z) => -0.2 * Math.exp(-(x * x + z * z) * 0.1), {
|
|
36
|
+
* color: [0.35, 0.26, 0.18],
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function buildPlankedFloor(builder, bounds, heightAt, options) {
|
|
41
|
+
const alongZ = options.alongZ !== false,
|
|
42
|
+
acrossMin = alongZ ? bounds.xMin : bounds.zMin,
|
|
43
|
+
acrossMax = alongZ ? bounds.xMax : bounds.zMax,
|
|
44
|
+
runMin = alongZ ? bounds.zMin : bounds.xMin,
|
|
45
|
+
runMax = alongZ ? bounds.zMax : bounds.xMax,
|
|
46
|
+
plankPitch = Math.max(0.08, options.plankWidth ?? 0.26),
|
|
47
|
+
lengthStep = Math.max(0.12, options.lengthStep ?? 0.48),
|
|
48
|
+
seamHalf = Math.min(plankPitch * 0.2, (options.seamWidth ?? 0.014) * 0.5),
|
|
49
|
+
seamDrop = Math.max(0.002, options.seamDrop ?? 0.012),
|
|
50
|
+
buttStride = Math.max(1.2, options.buttStride ?? 3.1),
|
|
51
|
+
seed = options.seed ?? 17,
|
|
52
|
+
toneVariation = options.toneVariation ?? 0.16,
|
|
53
|
+
baseColor = options.color;
|
|
54
|
+
|
|
55
|
+
const plankCount = Math.max(1, Math.round((acrossMax - acrossMin) / plankPitch)),
|
|
56
|
+
stepAcross = (acrossMax - acrossMin) / plankCount,
|
|
57
|
+
runCount = Math.max(1, Math.ceil((runMax - runMin) / lengthStep)),
|
|
58
|
+
stepRun = (runMax - runMin) / runCount;
|
|
59
|
+
|
|
60
|
+
const evalPoint = (across, run, drop, out) => {
|
|
61
|
+
const x = alongZ ? across : run,
|
|
62
|
+
z = alongZ ? run : across;
|
|
63
|
+
out[0] = x;
|
|
64
|
+
out[1] = heightAt(x, z) - drop;
|
|
65
|
+
out[2] = z;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const evalNormal = (across, run, out) => {
|
|
69
|
+
const eps = 0.12,
|
|
70
|
+
x = alongZ ? across : run,
|
|
71
|
+
z = alongZ ? run : across,
|
|
72
|
+
hx0 = heightAt(x - eps, z),
|
|
73
|
+
hx1 = heightAt(x + eps, z),
|
|
74
|
+
hz0 = heightAt(x, z - eps),
|
|
75
|
+
hz1 = heightAt(x, z + eps),
|
|
76
|
+
nx = -(hx1 - hx0) / (2 * eps),
|
|
77
|
+
ny = 1,
|
|
78
|
+
nz = -(hz1 - hz0) / (2 * eps),
|
|
79
|
+
len = Math.hypot(nx, ny, nz) || 1;
|
|
80
|
+
out[0] = nx / len;
|
|
81
|
+
out[1] = ny / len;
|
|
82
|
+
out[2] = nz / len;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const p00 = [0, 0, 0],
|
|
86
|
+
p10 = [0, 0, 0],
|
|
87
|
+
p11 = [0, 0, 0],
|
|
88
|
+
p01 = [0, 0, 0],
|
|
89
|
+
n00 = [0, 1, 0],
|
|
90
|
+
n10 = [0, 1, 0],
|
|
91
|
+
n11 = [0, 1, 0],
|
|
92
|
+
n01 = [0, 1, 0];
|
|
93
|
+
|
|
94
|
+
const emitQuad = (u0, u1, v0, v1, drop0, drop1, color) => {
|
|
95
|
+
evalPoint(u0, v0, drop0, p00);
|
|
96
|
+
evalPoint(u1, v0, drop1, p10);
|
|
97
|
+
evalPoint(u1, v1, drop1, p11);
|
|
98
|
+
evalPoint(u0, v1, drop0, p01);
|
|
99
|
+
evalNormal(u0, v0, n00);
|
|
100
|
+
evalNormal(u1, v0, n10);
|
|
101
|
+
evalNormal(u1, v1, n11);
|
|
102
|
+
evalNormal(u0, v1, n01);
|
|
103
|
+
|
|
104
|
+
if (alongZ) {
|
|
105
|
+
// u = X (+X right), v = Z (+Z forward): (p00 -> p01 -> p11) has (+Z) x (+X) = +Y upward normal.
|
|
106
|
+
builder.raw(p00[0], p00[1], p00[2], n00[0], n00[1], n00[2], color[0], color[1], color[2]);
|
|
107
|
+
builder.raw(p01[0], p01[1], p01[2], n01[0], n01[1], n01[2], color[0], color[1], color[2]);
|
|
108
|
+
builder.raw(p11[0], p11[1], p11[2], n11[0], n11[1], n11[2], color[0], color[1], color[2]);
|
|
109
|
+
|
|
110
|
+
builder.raw(p00[0], p00[1], p00[2], n00[0], n00[1], n00[2], color[0], color[1], color[2]);
|
|
111
|
+
builder.raw(p11[0], p11[1], p11[2], n11[0], n11[1], n11[2], color[0], color[1], color[2]);
|
|
112
|
+
builder.raw(p10[0], p10[1], p10[2], n10[0], n10[1], n10[2], color[0], color[1], color[2]);
|
|
113
|
+
} else {
|
|
114
|
+
// u = Z (+Z), v = X (+X): (p00 -> p10 -> p11) has (+Z) x (+X) = +Y upward normal.
|
|
115
|
+
builder.raw(p00[0], p00[1], p00[2], n00[0], n00[1], n00[2], color[0], color[1], color[2]);
|
|
116
|
+
builder.raw(p10[0], p10[1], p10[2], n10[0], n10[1], n10[2], color[0], color[1], color[2]);
|
|
117
|
+
builder.raw(p11[0], p11[1], p11[2], n11[0], n11[1], n11[2], color[0], color[1], color[2]);
|
|
118
|
+
|
|
119
|
+
builder.raw(p00[0], p00[1], p00[2], n00[0], n00[1], n00[2], color[0], color[1], color[2]);
|
|
120
|
+
builder.raw(p11[0], p11[1], p11[2], n11[0], n11[1], n11[2], color[0], color[1], color[2]);
|
|
121
|
+
builder.raw(p01[0], p01[1], p01[2], n01[0], n01[1], n01[2], color[0], color[1], color[2]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const seamColor = [baseColor[0] * 0.36, baseColor[1] * 0.34, baseColor[2] * 0.32];
|
|
126
|
+
|
|
127
|
+
for (let p = 0; p < plankCount; p++) {
|
|
128
|
+
const uLeft = acrossMin + p * stepAcross,
|
|
129
|
+
uRight = uLeft + stepAcross,
|
|
130
|
+
uInnerLeft = uLeft + seamHalf,
|
|
131
|
+
uInnerRight = uRight - seamHalf,
|
|
132
|
+
buttPhase = plankHash(p, 11, seed) * buttStride;
|
|
133
|
+
|
|
134
|
+
for (let s = 0; s < runCount; s++) {
|
|
135
|
+
const v0 = runMin + s * stepRun,
|
|
136
|
+
v1 = v0 + stepRun,
|
|
137
|
+
boardIndex = Math.floor((v0 - runMin + buttPhase) / buttStride),
|
|
138
|
+
nextBoardIndex = Math.floor((v1 - runMin + buttPhase) / buttStride),
|
|
139
|
+
shade = 1 + (plankHash(p, boardIndex, seed) - 0.5) * 2 * toneVariation,
|
|
140
|
+
buttDarken = boardIndex !== nextBoardIndex ? 0.84 : 1,
|
|
141
|
+
plankColor = [baseColor[0] * shade * buttDarken, baseColor[1] * shade * buttDarken, baseColor[2] * shade * buttDarken];
|
|
142
|
+
|
|
143
|
+
// Left bevel into tongue-and-groove seam, main plank crown, and right bevel closing tightly against the neighbour.
|
|
144
|
+
emitQuad(uLeft, uInnerLeft, v0, v1, seamDrop, 0, seamColor);
|
|
145
|
+
emitQuad(uInnerLeft, uInnerRight, v0, v1, 0, 0, plankColor);
|
|
146
|
+
emitQuad(uInnerRight, uRight, v0, v1, 0, seamDrop, seamColor);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// An oak-like broadleaf about eight metres tall, near and far, and its arrays for a worker to hand over. Worker-safe.
|
|
2
|
+
import { clamp, lerp, TAU } from '../math/scalar.js';
|
|
3
|
+
import { mulberry32 } from '../math/random.js';
|
|
4
|
+
import { C, TRS } from './primitives.js';
|
|
5
|
+
import { addLimb, addShape, partsArrays, shapeParts } from './foliage.js';
|
|
6
|
+
import { between, direction, lifted, moved } from './plant-shrub.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The broadleaf bound to the kit's tints.
|
|
10
|
+
* @param {object} o
|
|
11
|
+
* @param {Function} o.barkTint - The kit's bark tint (`createPlantTints`).
|
|
12
|
+
* @param {Function} o.crownBlob - The kit's crown lump (`createPlantTints`).
|
|
13
|
+
* @param {Function} o.crownTint - The kit's foliage tint (`createPlantTints`).
|
|
14
|
+
* @returns {{broadleaf: Function, broadleafArrays: Function}} `broadleaf(far = false)`: the tree's parts for
|
|
15
|
+
* `partsGeometry`, its foot at the origin; `broadleafArrays()`: the near tree as transferable arrays (`partsArrays`).
|
|
16
|
+
*/
|
|
17
|
+
export function createBroadleaf({ barkTint, crownBlob, crownTint }) {
|
|
18
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
19
|
+
// The broadleaf of woods and meadows, an oak-like tree about eight metres tall. A grey-brown trunk, leaning a
|
|
20
|
+
// little and flared into roots at its foot, forks at three metres into scaffold boughs (one leaving lower and nearly level, as
|
|
21
|
+
// an old tree's lowest limb does) that rise and turn up towards the light; each bough carries branches and twigs to either
|
|
22
|
+
// side, and every branch and twig ends in a clump of leaves. Many clumps of different sizes, flat beneath where the leaves
|
|
23
|
+
// lie in layers, with shade and sky between them and the limbs showing through: a crown that reads as foliage on branches and
|
|
24
|
+
// never as a few round lumps. Lower and inner clumps are darker and cooler, the sunlit top lighter and warmer.
|
|
25
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
26
|
+
const BROAD_BARK = 0x6a5d4f, // grey-brown, as an oak's or a beech's bark weathers: never the red of fresh-cut wood
|
|
27
|
+
BROAD_GREENS = [0x3e5a2e, 0x4a6534, 0x35502a, 0x56703a, 0x2f4626, 0x4f6a3a],
|
|
28
|
+
BROAD_BOUGHS = 5, // scaffold boughs round the trunk, besides the leader rising up its middle
|
|
29
|
+
BROAD_CROWN_FOOT = 3.2, // metres: the height of the crown's lowest clumps
|
|
30
|
+
BROAD_CROWN_SPAN = 6, // and how far it rises above them
|
|
31
|
+
BROAD_CROWN_REACH = 4.4, // and how far it spreads from the trunk
|
|
32
|
+
CLUMP_UNDERSIDE = 0.7, // a clump's underside drawn in flatter than its top, as layered leaves are
|
|
33
|
+
FAR_CLUMP_GROWS = 1.15, // a far bough's single clump, beyond the spread of the clumps it stands for
|
|
34
|
+
ROSETTE_REACH = 0.65, // metres from a leaf rosette's heart to its long leaves' tips
|
|
35
|
+
ROSETTE_POINTS = 8, // leaves round a rosette, long and short by turns
|
|
36
|
+
CLUMP_RING = 3; // rosettes round the sides of each clump at a bough's or a branch's end
|
|
37
|
+
|
|
38
|
+
// A clump of leaves: a lumpy crown blob with a flatter underside.
|
|
39
|
+
function leafClump(seed, detail) {
|
|
40
|
+
const g = crownBlob(seed, detail),
|
|
41
|
+
a = g.attributes.position.array;
|
|
42
|
+
for (let i = 1; i < a.length; i += 3) if (a[i] < 0) a[i] *= CLUMP_UNDERSIDE;
|
|
43
|
+
return g;
|
|
44
|
+
}
|
|
45
|
+
// How light the foliage is at [x, y, z] in the tree: darker low and within the crown, lighter on its sunlit top and outer edge.
|
|
46
|
+
function broadLight(x, y, z) {
|
|
47
|
+
const up = clamp((y - BROAD_CROWN_FOOT) / BROAD_CROWN_SPAN, 0, 1),
|
|
48
|
+
out = clamp(Math.hypot(x, z) / BROAD_CROWN_REACH, 0, 1);
|
|
49
|
+
return 0.78 + 0.26 * up + 0.12 * out;
|
|
50
|
+
}
|
|
51
|
+
// Shades `tint`'s colour by `light`: the lit foliage a little warmer and yellower, the shaded a little bluer.
|
|
52
|
+
function lit(out, light) {
|
|
53
|
+
out[0] *= light * (1 + 0.18 * (light - 0.9));
|
|
54
|
+
out[1] *= light;
|
|
55
|
+
out[2] *= light * (1 - 0.18 * (light - 0.9));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// A rosette of leaves at `at`, facing `facing` (unit length): a ragged star of `points` leaves round a dark heart, long and short
|
|
59
|
+
// by turns, the long ones hanging, `reach` metres across from heart to tip. Its leaves are wide wedges sharing their edges, so it
|
|
60
|
+
// reads as a fan of foliage breaking a clump's outline (a narrow leaf alone, that far out, reads as a thorn). Written on both
|
|
61
|
+
// faces, so a material that draws front faces only shows it from either side. `colour` is its linear [r, g, b].
|
|
62
|
+
function addLeafRosette(parts, at, facing, reach, points, colour, random) {
|
|
63
|
+
const f = facing,
|
|
64
|
+
ref = Math.abs(f[1]) < 0.9 ? [0, 1, 0] : [1, 0, 0],
|
|
65
|
+
e1 = [ref[1] * f[2] - ref[2] * f[1], ref[2] * f[0] - ref[0] * f[2], ref[0] * f[1] - ref[1] * f[0]],
|
|
66
|
+
l1 = Math.hypot(e1[0], e1[1], e1[2]);
|
|
67
|
+
for (let i = 0; i < 3; i++) e1[i] /= l1;
|
|
68
|
+
const e2 = [f[1] * e1[2] - f[2] * e1[1], f[2] * e1[0] - f[0] * e1[2], f[0] * e1[1] - f[1] * e1[0]], // e1 × e2 = f: a turn from e1 to e2 runs counter-clockwise seen from the way it faces
|
|
69
|
+
turn = random() * TAU,
|
|
70
|
+
rim = [];
|
|
71
|
+
for (let k = 0; k < points; k++) {
|
|
72
|
+
const t = turn + ((k + (random() - 0.5) * 0.6) / points) * TAU,
|
|
73
|
+
long = k % 2 === 0,
|
|
74
|
+
out = [0, 1, 2].map(i => e1[i] * Math.cos(t) + e2[i] * Math.sin(t)),
|
|
75
|
+
span = reach * (long ? 0.85 + 0.3 * random() : 0.5 + 0.2 * random()),
|
|
76
|
+
lift = reach * (long ? -(0.12 + 0.3 * random()) : 0.08),
|
|
77
|
+
way = out.map((value, i) => f[i] + value * 0.8),
|
|
78
|
+
size = Math.hypot(way[0], way[1], way[2]);
|
|
79
|
+
rim.push({
|
|
80
|
+
p: at.map((value, i) => value + out[i] * span + f[i] * lift),
|
|
81
|
+
n: way.map(value => value / size),
|
|
82
|
+
shade: long ? 1.05 + 0.2 * random() : 0.75,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const heart = at.map((value, i) => value + f[i] * reach * 0.15),
|
|
86
|
+
put = (p, n, shade, side) => {
|
|
87
|
+
parts.p.push(p[0], p[1], p[2]);
|
|
88
|
+
parts.n.push(n[0] * side, n[1] * side, n[2] * side);
|
|
89
|
+
parts.c.push(colour[0] * shade, colour[1] * shade, colour[2] * shade);
|
|
90
|
+
parts.l.push(1);
|
|
91
|
+
};
|
|
92
|
+
for (let k = 0; k < points; k++) {
|
|
93
|
+
const a = rim[k],
|
|
94
|
+
b = rim[(k + 1) % points];
|
|
95
|
+
put(heart, f, 0.6, 1);
|
|
96
|
+
put(a.p, a.n, a.shade, 1);
|
|
97
|
+
put(b.p, b.n, b.shade, 1);
|
|
98
|
+
put(heart, f, 0.6, -1); // the back face, wound the other way
|
|
99
|
+
put(b.p, b.n, b.shade * 0.85, -1);
|
|
100
|
+
put(a.p, a.n, a.shade * 0.85, -1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Where the broadleaf's limbs, clumps and leaf sprays stand. `R` draws the shape both versions share; `fine` draws what only the
|
|
105
|
+
// near one carries (roots, twigs and their clumps, sprays), so the far tree keeps the near one's boughs and crown.
|
|
106
|
+
function broadleafPlan() {
|
|
107
|
+
const R = mulberry32(4242),
|
|
108
|
+
fine = mulberry32(4243),
|
|
109
|
+
rf = (least, most) => lerp(least, most, R()),
|
|
110
|
+
limbs = [], // [from, to, foot radius, tip radius, rank: 0 trunk, 1 bough, 2 branch, 3 twig or root]
|
|
111
|
+
clumps = [], // { at, size, flat, turn, hex, bough, rank: 1 a bough's or branch's end, 3 a twig's }
|
|
112
|
+
sprays = []; // { at, facing, hex }
|
|
113
|
+
// leaf sprays standing out of a clump's outer surface, so its outline breaks into leaves: one facing out and, unless `count`
|
|
114
|
+
// says one, one facing up
|
|
115
|
+
const spraysOver = (c, count = 2) => {
|
|
116
|
+
const aside = Math.hypot(c.at[0] - fork[0], c.at[2] - fork[2]) || 1,
|
|
117
|
+
outX = (c.at[0] - fork[0]) / aside,
|
|
118
|
+
outZ = (c.at[2] - fork[2]) / aside;
|
|
119
|
+
for (let k = 0; k < count; k++) {
|
|
120
|
+
const way = k ? [outX * 0.5, 0.87, outZ * 0.5] : [outX * 0.94, 0.34, outZ * 0.94]; // unit length, both
|
|
121
|
+
sprays.push({ at: moved(c.at, way, c.size * 0.4 * (k ? c.flat : 1)), facing: way, hex: c.hex });
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const leanWay = R() * TAU,
|
|
125
|
+
lean = rf(0.2, 0.4),
|
|
126
|
+
knee = [Math.sin(leanWay) * lean * 0.35, 1.5, Math.cos(leanWay) * lean * 0.35],
|
|
127
|
+
fork = [Math.sin(leanWay) * lean, 2.9, Math.cos(leanWay) * lean];
|
|
128
|
+
limbs.push([[0, -0.3, 0], knee, 0.42, 0.33, 0], [knee, fork, 0.33, 0.25, 0]);
|
|
129
|
+
for (let k = 0; k < 5; k++) {
|
|
130
|
+
// the root flare: buttresses running from the bole down and out into the ground
|
|
131
|
+
const a = (k + fine() * 0.6) * 1.257,
|
|
132
|
+
out = 0.75 + fine() * 0.35;
|
|
133
|
+
limbs.push([
|
|
134
|
+
[Math.cos(a) * 0.12, 0.9 + fine() * 0.3, Math.sin(a) * 0.12],
|
|
135
|
+
[Math.cos(a) * out, -0.28, Math.sin(a) * out],
|
|
136
|
+
0.2,
|
|
137
|
+
0.06,
|
|
138
|
+
3,
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
const clump = (at, size, bough, rank) =>
|
|
142
|
+
clumps.push({ at, size, flat: rf(0.7, 0.85), turn: R() * TAU, hex: BROAD_GREENS[(R() * BROAD_GREENS.length) | 0], bough, rank });
|
|
143
|
+
for (let i = 0; i <= BROAD_BOUGHS; i++) {
|
|
144
|
+
const leader = i === BROAD_BOUGHS,
|
|
145
|
+
low = i === 0, // the lowest limb leaves the trunk under the fork and reaches out nearly level
|
|
146
|
+
heading = (i / BROAD_BOUGHS) * TAU + rf(-0.4, 0.4),
|
|
147
|
+
tilt = leader ? rf(0.05, 0.25) : low ? rf(1.05, 1.2) : rf(0.55, 0.85),
|
|
148
|
+
length = leader ? rf(3.2, 3.8) : low ? rf(3.2, 3.8) : rf(3, 3.6),
|
|
149
|
+
from = low ? between(knee, fork, 0.6) : fork,
|
|
150
|
+
mid = moved(from, direction(heading, tilt), length * 0.5),
|
|
151
|
+
end = moved(mid, direction(heading + rf(-0.3, 0.3), tilt * 0.7), length * 0.5); // a bough turns up towards the light
|
|
152
|
+
limbs.push([from, mid, leader ? 0.15 : 0.17, 0.11, 1], [mid, end, 0.11, 0.06, 1]);
|
|
153
|
+
clump(end, rf(2.0, 2.6), i, 1);
|
|
154
|
+
clump(lifted(moved(mid, direction(heading, 1.2), 0.5), 0.4), rf(1.8, 2.3), i, 1); // leaves along the bough itself
|
|
155
|
+
if (leader) clump(lifted(end, 0.9), rf(2.4, 2.9), i, 1); // the crown's domed top
|
|
156
|
+
for (let j = 0; j < 3; j++) {
|
|
157
|
+
const at = j === 0 ? between(from, mid, 0.7) : j === 1 ? mid : between(mid, end, 0.6),
|
|
158
|
+
side = j % 2 ? 1 : -1,
|
|
159
|
+
way = heading + side * rf(0.6, 1.1),
|
|
160
|
+
// the first branch, low on the bough, reaches out level or a little down: the crown's skirt, so it is deep at its sides
|
|
161
|
+
// and not a table on a stem; the others rise
|
|
162
|
+
rise = j === 0 && !leader ? Math.min(tilt + rf(0.45, 0.7), 1.65) : Math.min(tilt + rf(-0.2, 0.35), 1.45),
|
|
163
|
+
reach = rf(1.4, 2.1) * (leader ? 0.8 : 1),
|
|
164
|
+
tip = moved(at, direction(way, rise), reach);
|
|
165
|
+
tip[1] += reach * (j === 0 ? 0.04 : 0.15); // a branch arches up at its end
|
|
166
|
+
limbs.push([at, tip, 0.06, 0.025, 2]);
|
|
167
|
+
clump(tip, rf(1.5, 2.1), i, 1);
|
|
168
|
+
spraysOver(clumps[clumps.length - 1]);
|
|
169
|
+
const twigFrom = between(at, tip, 0.45 + fine() * 0.2),
|
|
170
|
+
twig = moved(twigFrom, direction(way - side * (0.8 + 0.4 * fine()), rise * 0.8 + fine() * 0.3), 0.8 + 0.5 * fine());
|
|
171
|
+
limbs.push([twigFrom, twig, 0.025, 0.01, 3]);
|
|
172
|
+
clumps.push({
|
|
173
|
+
at: twig,
|
|
174
|
+
size: 1.1 + 0.4 * fine(),
|
|
175
|
+
flat: 0.65,
|
|
176
|
+
turn: fine() * TAU,
|
|
177
|
+
hex: BROAD_GREENS[(fine() * 6) | 0],
|
|
178
|
+
bough: i,
|
|
179
|
+
rank: 3,
|
|
180
|
+
});
|
|
181
|
+
spraysOver(clumps[clumps.length - 1], 1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (let k = 0; k < 3; k++) {
|
|
185
|
+
// the crown's heart, in shade: mass between the boughs, so the crown is not hollow where it is seen through
|
|
186
|
+
const a = k * 2.1 + fine();
|
|
187
|
+
clumps.push({
|
|
188
|
+
at: [fork[0] + Math.cos(a) * 0.9, 4.6 + k * 1.1, fork[2] + Math.sin(a) * 0.9],
|
|
189
|
+
size: 2.6 + 0.4 * fine(),
|
|
190
|
+
flat: 0.8,
|
|
191
|
+
turn: fine() * TAU,
|
|
192
|
+
hex: BROAD_GREENS[4],
|
|
193
|
+
bough: -1,
|
|
194
|
+
rank: 2,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
for (const c of clumps) {
|
|
198
|
+
if (c.rank !== 1) continue;
|
|
199
|
+
// a ring of rosettes round each clump's sides, facing out from its own middle, so its whole surface breaks into leaves
|
|
200
|
+
const turn = fine() * TAU;
|
|
201
|
+
for (let k = 0; k < CLUMP_RING; k++) {
|
|
202
|
+
const a = turn + (k / CLUMP_RING) * TAU + (fine() - 0.5) * 0.8,
|
|
203
|
+
rise = (fine() - 0.3) * 0.6,
|
|
204
|
+
way = [Math.cos(a) * Math.cos(rise), Math.sin(rise), Math.sin(a) * Math.cos(rise)];
|
|
205
|
+
sprays.push({
|
|
206
|
+
at: [c.at[0] + way[0] * c.size * 0.42, c.at[1] + way[1] * c.size * c.flat * 0.42, c.at[2] + way[2] * c.size * 0.42],
|
|
207
|
+
facing: way,
|
|
208
|
+
hex: c.hex,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return { limbs, clumps, sprays };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// A broadleaf: its near version, or with `far` its far one, which keeps the trunk and the boughs and gathers each bough's
|
|
216
|
+
// clumps into one, a fifth of the near tree's triangles.
|
|
217
|
+
function broadleaf(far = false) {
|
|
218
|
+
const parts = shapeParts(),
|
|
219
|
+
bark = barkTint(BROAD_BARK),
|
|
220
|
+
{ limbs, clumps, sprays } = broadleafPlan(),
|
|
221
|
+
sides = far ? [5, 3, 0, 0] : [8, 6, 4, 3];
|
|
222
|
+
for (const [from, to, foot, tip, rank] of limbs) if (sides[rank]) addLimb(parts, from, to, foot, tip, sides[rank], bark);
|
|
223
|
+
const putClump = (at, size, flat, turn, hex, seed, detail) => {
|
|
224
|
+
const tint = crownTint(hex);
|
|
225
|
+
addShape(
|
|
226
|
+
parts,
|
|
227
|
+
far ? crownBlob(seed, detail) : leafClump(seed, detail), // far off a flat underside reads as a mushroom's cap
|
|
228
|
+
TRS(at[0], at[1], at[2], size, size * flat, size, turn),
|
|
229
|
+
(x, y, z, out) => {
|
|
230
|
+
tint(x, y, z, out);
|
|
231
|
+
lit(out, broadLight(at[0] + x * size, at[1] + y * size * flat, at[2] + z * size)); // where this vertex stands in the tree, near enough
|
|
232
|
+
},
|
|
233
|
+
1,
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
if (far) {
|
|
237
|
+
for (let bough = 0; bough <= BROAD_BOUGHS; bough++) {
|
|
238
|
+
const own = clumps.filter(c => c.bough === bough && c.rank === 1),
|
|
239
|
+
at = [0, 1, 2].map(k => own.reduce((sum, c) => sum + c.at[k], 0) / own.length),
|
|
240
|
+
spread = Math.max(...own.map(c => Math.hypot(c.at[0] - at[0], c.at[2] - at[2]) + c.size * 0.5));
|
|
241
|
+
putClump(at, spread * 2 * FAR_CLUMP_GROWS, 0.8, own[0].turn, own[0].hex, 300 + bough, 0);
|
|
242
|
+
}
|
|
243
|
+
// and one great clump at the crown's heart, so that far off it is a dome and never a ring of lumps
|
|
244
|
+
const crown = clumps.filter(c => c.rank === 1),
|
|
245
|
+
heart = [0, 1, 2].map(k => crown.reduce((sum, c) => sum + c.at[k], 0) / crown.length);
|
|
246
|
+
putClump(heart, BROAD_CROWN_REACH * 1.5, 0.75, 0, BROAD_GREENS[4], 310, 0);
|
|
247
|
+
return parts;
|
|
248
|
+
}
|
|
249
|
+
clumps.forEach((c, n) => putClump(c.at, c.size, c.flat, c.turn, c.hex, 1 + n, c.rank === 1 ? 1 : 0));
|
|
250
|
+
const random = mulberry32(4244),
|
|
251
|
+
colour = [0, 0, 0];
|
|
252
|
+
sprays.forEach(({ at, facing, hex }) => {
|
|
253
|
+
const green = C(hex),
|
|
254
|
+
light = broadLight(at[0], at[1], at[2]) * 1.05;
|
|
255
|
+
colour[0] = green[0];
|
|
256
|
+
colour[1] = green[1];
|
|
257
|
+
colour[2] = green[2];
|
|
258
|
+
lit(colour, light);
|
|
259
|
+
addLeafRosette(parts, at, facing, ROSETTE_REACH, ROSETTE_POINTS, colour, random);
|
|
260
|
+
});
|
|
261
|
+
return parts;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// The broadleaf as the arrays of its geometry (foliage.js's partsArrays), for the pool's workers to hand over: the model is
|
|
265
|
+
// too large to build in one frame on a page that draws.
|
|
266
|
+
const broadleafArrays = () => partsArrays(broadleaf());
|
|
267
|
+
return { broadleaf, broadleafArrays };
|
|
268
|
+
}
|