roamwright 0.4.0 → 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 +21 -14
- package/README.md +38 -42
- 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/bedding.js +141 -0
- package/geometry/builder-cells.js +50 -0
- package/geometry/builder-frame.js +48 -0
- package/geometry/builder.js +200 -177
- package/geometry/card-emblem.js +437 -0
- package/geometry/catenary-canvas.js +396 -0
- package/geometry/cell-mask.js +25 -0
- package/geometry/cloth-folds.js +143 -0
- package/geometry/crawl-shapes.js +71 -0
- package/geometry/creased-sheet.js +40 -35
- 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 +44 -39
- package/geometry/erosion.js +71 -45
- package/geometry/face-grid.js +85 -65
- 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 +187 -14
- 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 +57 -42
- package/geometry/hair-locks.js +42 -42
- package/geometry/hair-patch.js +24 -20
- package/geometry/hair-shell.js +43 -31
- package/geometry/head-presets.js +103 -0
- package/geometry/head-profile.js +26 -15
- package/geometry/head-shape.js +123 -95
- package/geometry/heightfield.js +50 -24
- 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/index-parts.js +2 -2
- package/geometry/instance-visibility.js +12 -12
- package/geometry/instances.js +17 -17
- 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 +11 -10
- package/geometry/outline-segments.js +74 -0
- package/geometry/part-ranges.js +38 -3
- package/geometry/path-field.js +98 -34
- package/geometry/placement.js +52 -52
- 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/point-buckets.js +50 -0
- package/geometry/primitives.js +117 -59
- 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/sagging-tube.js +27 -27
- package/geometry/sampled-surface.js +123 -77
- package/geometry/scatter-grid.js +49 -6
- package/geometry/sculpt.js +97 -93
- 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 +81 -34
- package/geometry/strata-field.js +131 -98
- package/geometry/strata-tiles.js +108 -94
- package/geometry/stream.js +96 -59
- package/geometry/swept-tube.js +124 -0
- package/geometry/terrain-chunks.js +216 -123
- package/geometry/terrain-extension.js +29 -13
- 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 +138 -2
- package/math/cell-edge.js +16 -16
- package/math/cell-key.js +6 -0
- package/math/circle-clearances.js +19 -0
- package/math/cloth-textures.js +6 -6
- package/math/cloud-textures.js +22 -26
- package/math/color.js +14 -14
- package/math/curve.js +26 -22
- package/math/lamp-texels.js +43 -0
- package/math/lit-share.js +22 -0
- package/math/mountain-ranges.js +379 -205
- package/math/noise.js +101 -49
- package/math/particle-noise.js +28 -28
- package/math/periodic.js +11 -5
- package/math/random.js +24 -15
- package/math/rectangles.js +58 -0
- package/math/rock-texture.js +22 -17
- package/math/scalar.js +5 -5
- package/math/surface-textures.js +74 -59
- 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 +27 -26
- package/motion/ballistic-arc.js +191 -0
- package/motion/biped-cycle.js +46 -0
- package/motion/biped-leg.js +40 -0
- package/motion/biped-posture.js +459 -0
- package/motion/biped-stride.js +226 -140
- package/motion/boat-sailing.js +214 -0
- package/motion/contact-transition.js +32 -0
- package/motion/crowd-alarms.js +72 -42
- 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 +126 -67
- package/motion/crowd-town.js +166 -0
- package/motion/crowd-water.js +143 -0
- package/motion/daily-clock.js +9 -9
- package/motion/deck-surface.js +40 -0
- 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/ground-lookahead.js +5 -5
- package/motion/instance-sight.js +15 -8
- package/motion/melee-contact.js +143 -0
- package/motion/moorings.js +48 -0
- package/motion/path-steering.js +358 -0
- package/motion/player.js +41 -32
- package/motion/quadruped.js +244 -168
- package/motion/spaces.js +90 -38
- 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 +133 -26
- package/motion/wind.js +58 -13
- package/package.json +33 -6
- 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/cart-track.js +92 -0
- package/rendering/caster-motion.js +6 -5
- package/rendering/cell-lod-options.js +46 -0
- package/rendering/cell-lod.js +754 -113
- package/rendering/cloth-material.js +140 -0
- package/rendering/cloud-dome.js +30 -30
- package/rendering/cloud-field.js +2 -2
- package/rendering/compilation-schedule.js +79 -14
- package/rendering/contact-shadows.js +7 -4
- package/rendering/context.js +57 -6
- 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 +62 -19
- package/rendering/crowd-update.js +419 -0
- package/rendering/crowd-visibility.js +107 -0
- package/rendering/crust.js +18 -12
- package/rendering/day-cycle-defaults.js +200 -0
- package/rendering/day-cycle.js +487 -0
- package/rendering/daylight.js +4 -6
- package/rendering/detail-range.js +29 -0
- package/rendering/dispose-meshes.js +18 -0
- package/rendering/dof.js +20 -13
- package/rendering/effects-frame.js +149 -0
- package/rendering/effects-water-rises.js +221 -0
- package/rendering/energy-stream.js +128 -0
- package/rendering/eye-adapt.js +14 -14
- package/rendering/facade-glass-material.js +105 -0
- package/rendering/far-shadow.js +89 -62
- 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 +82 -78
- package/rendering/garment-material.js +147 -51
- package/rendering/glow-lines.js +13 -13
- package/rendering/glsl-literal.js +19 -0
- package/rendering/ground-marks.js +316 -0
- package/rendering/hair-strands.js +45 -31
- package/rendering/height-haze.js +80 -33
- package/rendering/height-probe.js +164 -22
- package/rendering/house-kit-meshes.js +124 -0
- package/rendering/interior-bake.js +807 -0
- package/rendering/label-layout.js +56 -0
- package/rendering/label-range.js +41 -0
- 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 +71 -55
- package/rendering/light-points.js +21 -5
- package/rendering/local-lights.js +39 -8
- package/rendering/material-lod.js +49 -50
- 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 +135 -99
- package/rendering/particle-light-bursts.js +189 -0
- package/rendering/particles.js +212 -101
- package/rendering/pen-flocks.js +118 -0
- package/rendering/piece-batch.js +298 -11
- package/rendering/planar-reflection-options.js +159 -0
- package/rendering/planar-reflection.js +806 -103
- 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 +98 -31
- package/rendering/post.js +107 -87
- package/rendering/pressed-cover.js +135 -0
- package/rendering/prop-dig.js +136 -0
- package/rendering/rain-streaks.js +67 -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 +94 -37
- 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 +101 -44
- package/rendering/shadow-alignment.js +4 -4
- package/rendering/shadow-depth.js +47 -25
- package/rendering/ship-meshes.js +150 -0
- package/rendering/shot-cuts.js +68 -0
- package/rendering/sky-occlusion.js +56 -29
- package/rendering/sky-pmrem.js +216 -0
- package/rendering/sky.js +126 -54
- 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 +65 -26
- package/rendering/still-casters.js +77 -27
- package/rendering/strata-material.js +12 -12
- package/rendering/stream-flow.js +10 -10
- 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 +75 -44
- package/rendering/talus.js +15 -15
- package/rendering/terrain-rock.js +7 -7
- package/rendering/texture-fills.js +8 -8
- package/rendering/textures.js +28 -28
- package/rendering/tree-impostor.js +929 -0
- package/rendering/vehicle-train.js +92 -0
- package/rendering/viewport.js +67 -4
- package/rendering/wakes.js +24 -24
- package/rendering/water-material.js +304 -103
- package/rendering/waypoint-beacons.js +191 -0
- package/rendering/world-matrices.js +38 -40
- 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 +12 -4
- package/runtime/effect-sites.js +85 -0
- package/runtime/figure-orders.js +59 -0
- package/runtime/first-use.js +36 -28
- package/runtime/foley-script.js +124 -0
- package/runtime/foley-strides.js +333 -0
- package/runtime/frame-pacing.js +47 -0
- package/runtime/frame-yield.js +18 -0
- package/runtime/gpu-timing.js +15 -11
- package/runtime/grid-cache.js +16 -6
- package/runtime/grid-rows.js +44 -5
- package/runtime/hand-over.js +47 -24
- package/runtime/land-bake.js +78 -0
- package/runtime/lazy-sets.js +105 -0
- package/runtime/pool.js +73 -17
- package/runtime/quality-fit.js +60 -28
- package/runtime/region-pass-lay.js +40 -0
- package/runtime/region-pass.js +78 -0
- package/runtime/search.js +26 -22
- 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 +79 -30
- package/runtime/steady-frames.js +221 -0
- package/runtime/withdrawable-task.js +46 -0
- package/runtime/worker.js +7 -0
- package/scripts/app-parts.mjs +118 -0
- package/scripts/bake-revisions.mjs +81 -0
- package/scripts/browser-scripts.mjs +64 -0
- package/scripts/bundle.mjs +192 -0
- package/scripts/check-app.sh +26 -0
- package/scripts/eslint-config.mjs +119 -0
- package/scripts/format.sh +92 -0
- package/scripts/keep-builds.mjs +158 -0
- package/scripts/layers.mjs +112 -0
- package/scripts/lint.sh +49 -0
- package/scripts/module-graph.mjs +123 -0
- package/scripts/pre-commit.sh +38 -0
- package/scripts/serve.py +5 -3
- package/scripts/site.mjs +358 -0
- package/scripts/test-runner.sh +42 -0
- package/scripts/vendor.mjs +221 -0
- package/scripts/verify-publish.mjs +175 -0
- package/scripts/world.mk +59 -0
- package/tools/README.md +73 -0
- package/tools/contact-sheet.cjs +137 -0
- package/tools/cpu-profile.cjs +275 -0
- package/tools/cpu-profile.test.cjs +98 -0
- package/tools/first-draws.cjs +395 -0
- package/tools/flight-guard.cjs +482 -0
- package/tools/flight-guard.test.cjs +153 -0
- package/tools/flight-profile.cjs +145 -0
- package/tools/frame-bench.cjs +336 -0
- package/tools/frame-parts.cjs +365 -0
- package/tools/ios-sim.sh +145 -0
- package/tools/load-audit.cjs +201 -0
- package/tools/look-compare.cjs +304 -0
- package/tools/look-guard.cjs +407 -0
- package/tools/look-guard.test.cjs +93 -0
- package/tools/look-stats.cjs +185 -0
- package/tools/look-stats.test.cjs +71 -0
- package/tools/memory-audit.cjs +323 -0
- package/tools/page-driver.cjs +320 -0
- package/tools/page-driver.test.cjs +219 -0
- package/tools/program-census-report.cjs +191 -0
- package/tools/program-census.cjs +465 -0
- package/tools/program-census.test.cjs +332 -0
- package/tools/remote-runner.sh +265 -0
- package/tools/runners.test.cjs +59 -0
- package/tools/scene-audit-beat.cjs +344 -0
- package/tools/scene-audit-sheet.cjs +282 -0
- package/tools/scene-audit.cjs +471 -0
- package/tools/scene-audit.test.cjs +201 -0
- package/tools/scene-batch.cjs +219 -0
- package/tools/scene-bench.cjs +149 -0
- package/tools/scene-bench.test.cjs +33 -0
- package/tools/scene-run.cjs +443 -0
- package/tools/scene-run.test.cjs +94 -0
- package/tools/servers.sh +59 -0
- package/tools/shader-arrival.cjs +316 -0
- package/tools/shader-renewal.cjs +53 -0
- package/tools/shader-renewal.test.cjs +115 -0
- package/tools/speed-guard.cjs +258 -0
- package/tools/stills.cjs +492 -0
- package/tools/stills.test.cjs +49 -0
- package/tools/turns.sh +7 -0
- package/tools/yaml.cjs +158 -0
- package/examples/viaduct.css +0 -75
- package/rendering/light-shafts.js +0 -131
- package/rendering/road-surface.js +0 -63
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// A shrub grown from one root, from a form of plain numbers: woody stems that bend and fork, leaves at nodes along every twig,
|
|
2
|
+
// upright shoots and dry stalks, and a far version of a few lobes of leaf over the same outline. Also the small stem helpers the
|
|
3
|
+
// kit's trees share. Worker-safe.
|
|
4
|
+
import { clamp, lerp, TAU } from '../math/scalar.js';
|
|
5
|
+
import { C, TRS } from './primitives.js';
|
|
6
|
+
import { addLeafSpray, addShape, addLimb, shapeParts } from './foliage.js';
|
|
7
|
+
|
|
8
|
+
/** A point moved from `at` along `way` by `distance` metres. */
|
|
9
|
+
export const moved = (at, way, distance) => at.map((value, i) => value + way[i] * distance),
|
|
10
|
+
/** The point `part` (0..1) of the way from `from` to `to`. */
|
|
11
|
+
between = (from, to, part) => from.map((value, i) => value + (to[i] - value) * part),
|
|
12
|
+
/** The unit direction of `heading` round the upright and `tilt` from it, both in radians. */
|
|
13
|
+
direction = (heading, tilt) => [Math.sin(heading) * Math.sin(tilt), Math.cos(tilt), Math.cos(heading) * Math.sin(tilt)],
|
|
14
|
+
/** A twig's line `way`, turned a little towards the sky by `lift`. */
|
|
15
|
+
lifted = (way, lift) => [way[0], way[1] + lift, way[2]];
|
|
16
|
+
const dimmed = (tint, share) => (x, y, z, out) => {
|
|
17
|
+
tint(x, y, z, out);
|
|
18
|
+
out[0] *= share;
|
|
19
|
+
out[1] *= share;
|
|
20
|
+
out[2] *= share;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The shrub grower bound to a world's hash and the kit's tints.
|
|
25
|
+
* @param {object} o
|
|
26
|
+
* @param {Function} o.hash - A seeded integer hash (`createHash`), which picks and shades each leaf's green.
|
|
27
|
+
* @param {Function} o.barkTint - The kit's bark tint (`createPlantTints`).
|
|
28
|
+
* @param {Function} o.crownBlob - The kit's crown lump (`createPlantTints`).
|
|
29
|
+
* @returns {{shrubParts: Function}} `shrubParts(form, random)`: a shrub of `form` grown from the stream `random`, as
|
|
30
|
+
* `{ near, far }` sets of parts for `partsGeometry` (the form's fields are listed above the function).
|
|
31
|
+
*/
|
|
32
|
+
export function createShrubs({ hash: hash2, barkTint, crownBlob }) {
|
|
33
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
34
|
+
// A shrub grown from one root: what the brush of a cover, a thorn bush of dry hills and a ruin's scrub are made of. Its stems
|
|
35
|
+
// rise out of one root crown, bend and fork three times over from low down, and upright shoots leave them towards the light.
|
|
36
|
+
// Every twig carries a few leaves at each of several nodes along its outer length, standing out from it as a shoot's leaves
|
|
37
|
+
// do, so that near at hand it is woody below and leafy from a third of the way up, every leaf on a twig and none radiating
|
|
38
|
+
// from a bare point; its far version is the same outline in a few lobes of leaf.
|
|
39
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
40
|
+
const ROOT_UNDER = 0.04, // metres the root crown stands under the ground, so that a slope never shows its foot
|
|
41
|
+
ROOT_TOP = 0.05, // how high the root crown rises before its stems part
|
|
42
|
+
STEM_BENDS_AT = 0.55, // how far along its length a stem bends
|
|
43
|
+
LOW_FORK_LEAVES_AT = 0.6, // how far up a stem's lower length its first fork leaves it
|
|
44
|
+
HIGH_FORK_LEAVES_AT = 0.45, // and how far up its upper length its third fork leaves it
|
|
45
|
+
UPRIGHT = 1.45, // the most a stem or fork may lean from upright, in radians
|
|
46
|
+
SHOOT_LEAN = 0.55, // the most one of the upright shoots leans from upright, in radians
|
|
47
|
+
FAR_LOBE_SPANS = 2.6, // a far shrub's lobe of leaf, as a multiple of the leaf: it stands for a spray's leaves spread in depth
|
|
48
|
+
FAR_LOBE_GROWS = 1.14, // and this much larger still, so that the shrub's outline holds where one version gives way to the other
|
|
49
|
+
FAR_LOBE_BRIGHTENS = 1.2; // and this much brighter: a spray's leaves turn their faces to the light, where a lobe is shaded round
|
|
50
|
+
|
|
51
|
+
// The stems of a shrub grown from a count rather than laid out for it: [heading, length in metres, lean from upright in radians],
|
|
52
|
+
// each to its own side of the root, a golden angle (2.399) from the last, and of its own length and lean.
|
|
53
|
+
function stemPlan(count, random, lengths, leans) {
|
|
54
|
+
const stems = [];
|
|
55
|
+
for (let i = 0; i < count; i++)
|
|
56
|
+
stems.push([i * 2.399 + random() * 0.4, lerp(lengths[0], lengths[1], random()), lerp(leans[0], leans[1], random())]);
|
|
57
|
+
return stems;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The colour of a leaf by where it stands on a shrub: one of its `greens`, a different one from spray to spray; darker low down
|
|
61
|
+
// and within the crown than at its sunlit tips and its outer edge. `height` is how high the shrub rises and `reach` how far its
|
|
62
|
+
// crown spreads from its middle, in metres.
|
|
63
|
+
function shrubLeafTint(greens, height, reach) {
|
|
64
|
+
const palette = greens.map(hex => C(hex));
|
|
65
|
+
return (x, y, z, out) => {
|
|
66
|
+
const green = palette[(hash2(Math.round(x * 23), Math.round(z * 29) + Math.round(y * 19), 64) * palette.length) | 0],
|
|
67
|
+
up = clamp(y / height, 0, 1),
|
|
68
|
+
edge = clamp(Math.hypot(x, z) / reach, 0, 1),
|
|
69
|
+
shade = (0.72 + 0.4 * up) * (0.84 + 0.2 * edge) * (0.9 + 0.2 * hash2(Math.round(x * 41), Math.round(z * 43), 65));
|
|
70
|
+
out[0] = green[0] * shade;
|
|
71
|
+
out[1] = green[1] * shade;
|
|
72
|
+
out[2] = green[2] * shade;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// A shrub of `form` grown from the stream `random`: { near, far }, each a set of parts for partsGeometry. The form says:
|
|
77
|
+
// stems the stems as [heading, length, lean] (a clump every copy of a cover shares), or a count to
|
|
78
|
+
// grow them from `lengths` and `leans` (each [least, most])
|
|
79
|
+
// root the root crown's radius in metres; wood the sides of a stem (3 or 4)
|
|
80
|
+
// leaf the long leaf of a node, in metres; leaves the leaves at a node of a twig; splay the narrowest angle a
|
|
81
|
+
// leaf makes with its twig, in radians (a right angle: a flat fan square to the twig; about 1: leaves standing out
|
|
82
|
+
// from it, as a shoot's do)
|
|
83
|
+
// cluster further nodes of leaf gathered round each fork's end, where a shoot's leaves grow thickest
|
|
84
|
+
// crown upright shoots rising from the stems towards the light, leaf at two nodes along each
|
|
85
|
+
// heart nodes of leaf in shade low on the stems, which the upper ones part to show
|
|
86
|
+
// bark, greens, straw the wood, the leaves, and the dead wood and dry stalks (all sRGB)
|
|
87
|
+
// dead how many of the last stems stand bare and bleached; stalks dry stalks rising from the root
|
|
88
|
+
// far the lobes of its far version
|
|
89
|
+
function shrubParts(form, random) {
|
|
90
|
+
const near = shapeParts(),
|
|
91
|
+
far = shapeParts(),
|
|
92
|
+
stems = Array.isArray(form.stems) ? form.stems : stemPlan(form.stems, random, form.lengths, form.leans),
|
|
93
|
+
rise = Math.max(...stems.map(([, length, lean]) => length * Math.cos(lean))),
|
|
94
|
+
reach = Math.max(...stems.map(([, length, lean]) => length * Math.sin(lean))) + form.leaf * 1.6,
|
|
95
|
+
leaf = shrubLeafTint(form.greens, rise, reach),
|
|
96
|
+
strawLeaf = shrubLeafTint(form.strawLeaves ?? form.greens, rise, reach),
|
|
97
|
+
bark = barkTint(form.bark),
|
|
98
|
+
deadWood = barkTint(form.straw ?? form.bark),
|
|
99
|
+
tips = [];
|
|
100
|
+
// a node of leaf: the form's `leaves` leaves leaving a twig together at `at` and standing out round its line `way`, each a
|
|
101
|
+
// little its own way about it
|
|
102
|
+
const leafNode = (at, way, size, tint = leaf) =>
|
|
103
|
+
addLeafSpray(near, {
|
|
104
|
+
at,
|
|
105
|
+
facing: [way[0] + (random() - 0.5) * 0.5, way[1] + (random() - 0.5) * 0.4, way[2] + (random() - 0.5) * 0.5],
|
|
106
|
+
length: form.leaf * size,
|
|
107
|
+
leaves: form.leaves,
|
|
108
|
+
tint,
|
|
109
|
+
random,
|
|
110
|
+
splay: form.splay,
|
|
111
|
+
});
|
|
112
|
+
// leaf at nodes along a twig from `from` to `end`, further out the larger, as a shoot's leaves grow towards its tip
|
|
113
|
+
const leafNodes = (from, end, way, parts) => parts.forEach(part => leafNode(between(from, end, part), way, 0.75 + 0.25 * part));
|
|
114
|
+
// a short upright shoot from `from` on a stem, leaf at two nodes along it
|
|
115
|
+
const shoot = from => {
|
|
116
|
+
const way = direction(random() * TAU, random() * SHOOT_LEAN),
|
|
117
|
+
end = moved(from, way, rise * (0.22 + 0.3 * random()));
|
|
118
|
+
addLimb(near, from, end, form.root * 0.3, form.root * 0.12, 3, bark);
|
|
119
|
+
leafNodes(from, end, way, [0.55, 1]);
|
|
120
|
+
};
|
|
121
|
+
addLimb(near, [0, -ROOT_UNDER, 0], [0, ROOT_TOP, 0], form.root, form.root * 0.8, 5, bark); // the root crown
|
|
122
|
+
stems.forEach(([heading, length, lean], i) => {
|
|
123
|
+
const dead = i >= stems.length - (form.dead ?? 0), // the last stems stand dead: bare, and bleached by the sun
|
|
124
|
+
wood = dead ? deadWood : bark,
|
|
125
|
+
kink = moved([0, 0.01, 0], direction(heading, lean), length * STEM_BENDS_AT),
|
|
126
|
+
on = direction(heading + (random() - 0.5) * 0.8, Math.min(lean + 0.1 + random() * 0.45, UPRIGHT)),
|
|
127
|
+
tip = moved(kink, on, length * (1 - STEM_BENDS_AT)), // a stem bends on as it rises, a little aside and further from upright
|
|
128
|
+
thick = (0.012 + 0.01 * random()) * Math.sqrt(length / 0.8);
|
|
129
|
+
addLimb(near, [0, 0.01, 0], kink, thick, thick * 0.7, form.wood, wood);
|
|
130
|
+
addLimb(near, kink, tip, thick * 0.7, thick * 0.4, 3, wood);
|
|
131
|
+
tips.push(tip);
|
|
132
|
+
// three forks to alternating sides, the first low on the stem and the second from the bend, so that the leaves reach from
|
|
133
|
+
// a third of the way up it to beyond its tip and the shrub is a dome of leaf and not an umbrella of bare stems
|
|
134
|
+
for (const [from, side] of [
|
|
135
|
+
[between([0, 0.01, 0], kink, LOW_FORK_LEAVES_AT), -1],
|
|
136
|
+
[kink, 1],
|
|
137
|
+
[between(kink, tip, HIGH_FORK_LEAVES_AT), -1],
|
|
138
|
+
]) {
|
|
139
|
+
const fork = direction(heading + side * (0.5 + 0.45 * random()), Math.min(lean + (random() - 0.25) * 0.5, UPRIGHT)),
|
|
140
|
+
end = moved(from, fork, length * (0.36 + 0.22 * random()));
|
|
141
|
+
addLimb(near, from, end, thick * 0.42, thick * 0.16, 3, wood);
|
|
142
|
+
if (dead) continue;
|
|
143
|
+
// leaf at three nodes along the fork's outer length, as a shoot's leaves stand, and the cluster's further nodes at its end
|
|
144
|
+
leafNodes(from, end, fork, [0.4, 0.7, 1]);
|
|
145
|
+
for (let n = 0; n < form.cluster; n++)
|
|
146
|
+
leafNode(moved(end, [random() - 0.5, random() * 0.5, random() - 0.5], form.leaf * 1.2), fork, 0.9);
|
|
147
|
+
}
|
|
148
|
+
if (!dead) {
|
|
149
|
+
leafNodes(kink, tip, on, [0.35, 1]);
|
|
150
|
+
for (let n = 0; n < form.heart; n++)
|
|
151
|
+
leafNode(between([0, 0.01, 0], kink, 0.7 + 0.25 * random()), lifted(direction(heading, lean), 0.7), 0.85, dimmed(leaf, 0.6));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
// the upright shoots, spread over the stems' upper lengths
|
|
155
|
+
for (let n = 0; n < form.crown; n++) {
|
|
156
|
+
const [heading, length, lean] = stems[n % stems.length],
|
|
157
|
+
kink = moved([0, 0.01, 0], direction(heading, lean), length * STEM_BENDS_AT);
|
|
158
|
+
shoot(between(kink, tips[n % stems.length], random() * 0.8));
|
|
159
|
+
}
|
|
160
|
+
for (let n = 0; n < (form.stalks ?? 0); n++) {
|
|
161
|
+
// a dry stalk: a thin straw-coloured stem near upright, and three dry leaves at its top
|
|
162
|
+
const way = direction(random() * TAU, 0.12 + random() * 0.3),
|
|
163
|
+
top = moved([0, 0.02, 0], way, rise * (0.7 + 0.5 * random()));
|
|
164
|
+
addLimb(near, [0, 0.02, 0], top, 0.004, 0.002, 3, deadWood);
|
|
165
|
+
addLeafSpray(near, {
|
|
166
|
+
at: top,
|
|
167
|
+
facing: lifted(way, 0.5),
|
|
168
|
+
length: form.leaf * 0.55,
|
|
169
|
+
leaves: 3,
|
|
170
|
+
tint: strawLeaf,
|
|
171
|
+
random,
|
|
172
|
+
splay: form.splay,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// far off, where a leaf is thinner than a pixel, the shrub is a lobe of leaf over its crown and one over every other stem's
|
|
176
|
+
// tip, each a little larger than the spray it stands for
|
|
177
|
+
const over = form.far - 1,
|
|
178
|
+
stride = Math.max(1, Math.ceil((tips.length - 1) / over)),
|
|
179
|
+
wide = form.leaf * FAR_LOBE_SPANS * FAR_LOBE_GROWS,
|
|
180
|
+
lobe = (at, seed) =>
|
|
181
|
+
addShape(
|
|
182
|
+
far,
|
|
183
|
+
crownBlob(seed, 0),
|
|
184
|
+
TRS(at[0], at[1], at[2], wide, wide * 0.62, wide),
|
|
185
|
+
(x, y, z, out) => {
|
|
186
|
+
leaf(x * wide + at[0], y * wide * 0.62 + at[1], z * wide + at[2], out);
|
|
187
|
+
out[0] *= FAR_LOBE_BRIGHTENS;
|
|
188
|
+
out[1] *= FAR_LOBE_BRIGHTENS;
|
|
189
|
+
out[2] *= FAR_LOBE_BRIGHTENS;
|
|
190
|
+
},
|
|
191
|
+
1,
|
|
192
|
+
);
|
|
193
|
+
lobe([0, rise * 0.6, 0], 390);
|
|
194
|
+
for (let n = 0; n < over; n++) lobe(tips[Math.min(n * stride, tips.length - 1)], 391 + n);
|
|
195
|
+
return { near, far };
|
|
196
|
+
}
|
|
197
|
+
return { shrubParts };
|
|
198
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The colours and crown lumps every plant of the kit is made of: bark or stone mottled from place to place, an irregular crown
|
|
2
|
+
// lump, foliage darker underneath and inside, and the drift of a stand's colour from grove to grove. Worker-safe.
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { clamp, lerp } from '../math/scalar.js';
|
|
5
|
+
import { C } from './primitives.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The plant kit's tints bound to a world's noise and hash.
|
|
9
|
+
* @param {object} o
|
|
10
|
+
* @param {Function} o.fbm - Seeded fractal noise (`createNoise`), which shapes a crown lump.
|
|
11
|
+
* @param {Function} o.vnoise - Seeded value noise (`createNoise`), which drifts a stand's colour.
|
|
12
|
+
* @param {Function} o.hash - A seeded integer hash (`createHash`), which mottles bark and leaves.
|
|
13
|
+
* @returns {{barkTint: Function, crownBlob: Function, crownTint: Function, standColourDrift: Function}}
|
|
14
|
+
* `barkTint(hex)` and `crownTint(hex)`: a tint `(x, y, z, out)` writing a linear [r, g, b] for a vertex of a shape, the
|
|
15
|
+
* colour sRGB hex; `crownBlob(seed, detail = 1)`: a displaced icosahedron of radius about 0.5 m with smooth normals;
|
|
16
|
+
* `standColourDrift(x, z, brightnessShare, out, chromaStrength = 1)`: the warm and cool drift of a stand at world point
|
|
17
|
+
* (x, z) in metres and a tree's brightness (0..1 to 0.82..1.16), written into `out` as an [r, g, b] multiplier.
|
|
18
|
+
*/
|
|
19
|
+
export function createPlantTints({ fbm, vnoise, hash: hash2 }) {
|
|
20
|
+
const STAND_BROAD_SCALE = 256, // metres across hillside moisture and aspect shifts
|
|
21
|
+
STAND_GROVE_SCALE = 64, // metres across individual grove patches
|
|
22
|
+
TREE_BRIGHT_MIN = 0.82,
|
|
23
|
+
TREE_BRIGHT_MAX = 1.16;
|
|
24
|
+
|
|
25
|
+
// Bark or stone: a colour mottled a little from place to place.
|
|
26
|
+
function barkTint(hex) {
|
|
27
|
+
const c = C(hex);
|
|
28
|
+
return (x, y, z, o) => {
|
|
29
|
+
const k = 0.8 + 0.4 * hash2(Math.round(x * 9), Math.round(y * 5), 61);
|
|
30
|
+
o[0] = c[0] * k;
|
|
31
|
+
o[1] = c[1] * k;
|
|
32
|
+
o[2] = c[2] * k;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// An irregular crown lump: a displaced sphere with smooth normals.
|
|
36
|
+
function crownBlob(seed, detail = 1) {
|
|
37
|
+
const g = new THREE.IcosahedronGeometry(0.5, detail),
|
|
38
|
+
a = g.attributes.position.array,
|
|
39
|
+
nn = g.attributes.normal.array;
|
|
40
|
+
for (let i = 0; i < a.length; i += 3) {
|
|
41
|
+
const l = Math.hypot(a[i], a[i + 1], a[i + 2]),
|
|
42
|
+
dx = a[i] / l,
|
|
43
|
+
dy = a[i + 1] / l,
|
|
44
|
+
dz = a[i + 2] / l,
|
|
45
|
+
r = 0.5 * (0.7 + 0.6 * fbm(dx * 1.8 + seed * 3.1, dz * 1.8 + dy * 1.4 + seed, 2, 210));
|
|
46
|
+
a[i] = dx * r;
|
|
47
|
+
a[i + 1] = dy * r;
|
|
48
|
+
a[i + 2] = dz * r;
|
|
49
|
+
nn[i] = dx;
|
|
50
|
+
nn[i + 1] = dy;
|
|
51
|
+
nn[i + 2] = dz;
|
|
52
|
+
}
|
|
53
|
+
return g;
|
|
54
|
+
}
|
|
55
|
+
// Foliage: darker underneath and inside, lighter on top, mottled leaf by leaf.
|
|
56
|
+
function crownTint(hex) {
|
|
57
|
+
const c = C(hex);
|
|
58
|
+
return (x, y, z, o) => {
|
|
59
|
+
const l = Math.hypot(x, y, z) || 1,
|
|
60
|
+
k = (0.48 + 0.66 * ((y / l) * 0.5 + 0.5)) * (0.86 + 0.28 * hash2(Math.round(x * 20), Math.round(z * 20), 62));
|
|
61
|
+
o[0] = c[0] * k;
|
|
62
|
+
o[1] = c[1] * k;
|
|
63
|
+
o[2] = c[2] * k;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Writes natural stand-wide warm/cool green-gold drift (256 m and 64 m world-space noise) and per-tree brightness (0.82-1.16)
|
|
68
|
+
// into `out` ([r, g, b]) without drawing from placement RNG streams, so seeded tree layouts never move.
|
|
69
|
+
function standColourDrift(x, z, brightnessShare, out, chromaStrength = 1) {
|
|
70
|
+
const broad = vnoise(x / STAND_BROAD_SCALE, z / STAND_BROAD_SCALE, 419) * 2 - 1,
|
|
71
|
+
grove = vnoise(x / STAND_GROVE_SCALE, z / STAND_GROVE_SCALE, 421) * 2 - 1,
|
|
72
|
+
warmShift = (0.62 * broad + 0.38 * grove) * chromaStrength,
|
|
73
|
+
brightness = lerp(TREE_BRIGHT_MIN, TREE_BRIGHT_MAX, clamp(brightnessShare, 0, 1)) * (1 + 0.05 * grove);
|
|
74
|
+
out[0] = brightness * (1 + 0.14 * warmShift);
|
|
75
|
+
out[1] = brightness * (1 + 0.03 * warmShift);
|
|
76
|
+
out[2] = brightness * (1 - 0.11 * warmShift);
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
return { barkTint, crownBlob, crownTint, standColourDrift };
|
|
80
|
+
}
|