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,122 @@
|
|
|
1
|
+
// Planted things meshed into cells for a level of detail: bins of trees by kind, boulders sharing one rock, and cells of ground
|
|
2
|
+
// cover by form. Each cell is an instanced mesh with, where the model has one, a far twin drawing the same copies, which a cell
|
|
3
|
+
// level of detail shows in its place (`createCellLod`).
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
import { geometryOf, releaseArray } from '../geometry/builder.js';
|
|
6
|
+
import { indexParts } from '../geometry/index-parts.js';
|
|
7
|
+
import { instancedMesh, instancedTwin } from '../geometry/instances.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A mesh to each bin of trees, with its far version when the kind has one.
|
|
11
|
+
* @param {Array<{kind: number, sparse?: boolean, matrices: Float32Array, colours: Float32Array}>} bins - The trees placed, a
|
|
12
|
+
* bin to each cell and kind: their instance matrices and linear colours.
|
|
13
|
+
* @param {{near: Array<THREE.BufferGeometry|null>, far: Array<THREE.BufferGeometry|null>, impostor: Array<object|null>}} shapes -
|
|
14
|
+
* Each form's near and far models and impostor descriptor, by form.
|
|
15
|
+
* @param {object} o
|
|
16
|
+
* @param {THREE.Material} o.material - What every tree is drawn with.
|
|
17
|
+
* @param {THREE.Object3D} o.group - Where the meshes are added.
|
|
18
|
+
* @param {Object<number, {form: number, near?: number}>} [o.drawnAs] - Kinds drawn with another kind's form, and the distance in
|
|
19
|
+
* metres within which their near version is shown, if not the level of detail's own.
|
|
20
|
+
* @param {Function} [o.sight] - `sight(mesh, form)`: told of every near mesh (a camera's line of sight, for one).
|
|
21
|
+
* @returns {Array<object>} The cells: `{ mesh, lo, impostor, full, cx, cy, cz, r, near }`.
|
|
22
|
+
*/
|
|
23
|
+
function meshTreeBins(bins, shapes, { material, group, drawnAs = {}, sight = () => {} }) {
|
|
24
|
+
const cells = [];
|
|
25
|
+
for (const { kind, sparse, matrices, colours } of bins) {
|
|
26
|
+
const alias = drawnAs[kind],
|
|
27
|
+
form = alias ? alias.form : kind,
|
|
28
|
+
im = instancedMesh(shapes.near[form], material, { matrices, colours });
|
|
29
|
+
im.name = 'tree:' + kind; // so a tool can find a kind of tree
|
|
30
|
+
im.castShadow = true;
|
|
31
|
+
im.receiveShadow = true;
|
|
32
|
+
im.matrixAutoUpdate = false;
|
|
33
|
+
im.computeBoundingSphere();
|
|
34
|
+
sight(im, form);
|
|
35
|
+
group.add(im);
|
|
36
|
+
let lo = null;
|
|
37
|
+
if (shapes.far[form]) {
|
|
38
|
+
lo = instancedTwin(shapes.far[form], material, im);
|
|
39
|
+
lo.receiveShadow = true;
|
|
40
|
+
lo.matrixAutoUpdate = false;
|
|
41
|
+
lo.visible = false;
|
|
42
|
+
group.add(lo);
|
|
43
|
+
}
|
|
44
|
+
cells.push({
|
|
45
|
+
mesh: im,
|
|
46
|
+
lo,
|
|
47
|
+
impostor: shapes.impostor[form],
|
|
48
|
+
full: sparse ? undefined : im.count,
|
|
49
|
+
cx: im.boundingSphere.center.x,
|
|
50
|
+
cy: im.boundingSphere.center.y,
|
|
51
|
+
cz: im.boundingSphere.center.z,
|
|
52
|
+
r: im.boundingSphere.radius,
|
|
53
|
+
near: alias ? alias.near : undefined,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return cells;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The boulders, all sharing one indexed rock: its UV seam and each vertex's own normal are kept, and each rock takes its
|
|
61
|
+
* instance's colour.
|
|
62
|
+
* @param {{matrices: Float32Array, colours: Float32Array}} boulders - Where each boulder lies and its linear colour.
|
|
63
|
+
* @param {object} o
|
|
64
|
+
* @param {THREE.BufferGeometry} o.rock - The rock's shape: position, normal and uv attributes, not indexed.
|
|
65
|
+
* @param {THREE.Material} o.material - What the boulders are drawn with (vertex colours read).
|
|
66
|
+
* @param {THREE.Object3D} o.group - Where the mesh is added.
|
|
67
|
+
* @returns {THREE.InstancedMesh} The boulders' mesh.
|
|
68
|
+
*/
|
|
69
|
+
function meshBoulders(boulders, { rock, material, group }) {
|
|
70
|
+
const { position, normal, uv } = rock.attributes;
|
|
71
|
+
const parts = indexParts({ position: position.array, normal: normal.array, uv: uv.array });
|
|
72
|
+
parts.color = new Float32Array(parts.position.length).fill(1); // each rock takes its instance's colour
|
|
73
|
+
const shape = geometryOf(parts);
|
|
74
|
+
shape.setAttribute('uv', new THREE.BufferAttribute(parts.uv, 2).onUpload(releaseArray));
|
|
75
|
+
const rim = instancedMesh(shape, material, boulders);
|
|
76
|
+
rim.castShadow = rim.receiveShadow = true;
|
|
77
|
+
rim.matrixAutoUpdate = false;
|
|
78
|
+
rim.computeBoundingSphere();
|
|
79
|
+
group.add(rim);
|
|
80
|
+
return rim;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A mesh to each cell of ground cover, with its far version.
|
|
85
|
+
* @param {Array<{form: number, matrices: Float32Array, colours: Float32Array}>} placed - The cover placed, a cell to each
|
|
86
|
+
* square and form.
|
|
87
|
+
* @param {Array<Array<THREE.BufferGeometry>>} models - Each form's `[near, far]` models.
|
|
88
|
+
* @param {object} o
|
|
89
|
+
* @param {THREE.Object3D} o.group - Where the meshes are added.
|
|
90
|
+
* @param {Function} o.materialOf - `materialOf(form)`: what a cell of the form is drawn with, asked once a cell.
|
|
91
|
+
* @param {Array<{sight?: boolean, layer?: number, near?: number}>} [o.forms] - What each form is, by form: whether `sight` is told
|
|
92
|
+
* of its meshes, the layer it is drawn on (0 by default), and the distance in metres within which its near version is shown, if
|
|
93
|
+
* not the level of detail's own.
|
|
94
|
+
* @param {Function} [o.sight] - `sight(mesh)`: told of the near mesh of every form that says so.
|
|
95
|
+
* @returns {Array<object>} The cells: `{ mesh, lo, full, cx, cz, r, near }`.
|
|
96
|
+
*/
|
|
97
|
+
function meshCoverCells(placed, models, { group, materialOf, forms = [], sight = () => {} }) {
|
|
98
|
+
const cells = [];
|
|
99
|
+
for (const { form, matrices, colours } of placed) {
|
|
100
|
+
const [near, far] = models[form],
|
|
101
|
+
kind = forms[form] ?? {},
|
|
102
|
+
material = materialOf(form),
|
|
103
|
+
mesh = instancedMesh(near, material, { matrices, colours });
|
|
104
|
+
mesh.computeBoundingSphere();
|
|
105
|
+
if (kind.sight) sight(mesh); // a bush, a hedge or a ledge of rock can stand between a lens and its subject
|
|
106
|
+
mesh.receiveShadow = true;
|
|
107
|
+
const lo = instancedTwin(far, material, mesh);
|
|
108
|
+
lo.receiveShadow = true;
|
|
109
|
+
lo.visible = false;
|
|
110
|
+
mesh.matrixAutoUpdate = lo.matrixAutoUpdate = false;
|
|
111
|
+
if (kind.layer) {
|
|
112
|
+
mesh.layers.set(kind.layer);
|
|
113
|
+
lo.layers.set(kind.layer);
|
|
114
|
+
}
|
|
115
|
+
group.add(mesh, lo);
|
|
116
|
+
const { center, radius } = mesh.boundingSphere;
|
|
117
|
+
cells.push({ mesh, lo, full: mesh.count, cx: center.x, cz: center.z, r: radius, near: kind.near });
|
|
118
|
+
}
|
|
119
|
+
return cells;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { meshBoulders, meshCoverCells, meshTreeBins };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Reeds: a clump of marsh stems, leaves and seed heads that bends in the wind, near and coarse, and beds of them as
|
|
2
|
+
// instanced cells for a level of detail.
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { GB } from '../geometry/builder.js';
|
|
5
|
+
import { C, TRS } from '../geometry/primitives.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Reed clumps and beds bound to a world's clock and wind.
|
|
9
|
+
* @param {object} o
|
|
10
|
+
* @param {{value: number}} o.uTime - The clock's uniform, in seconds.
|
|
11
|
+
* @param {{value: THREE.Vector3}} o.uWind - The wind's uniform: x and y the way it blows (any length), z its strength 0..1.
|
|
12
|
+
* @returns {{reedModels: Function, meshReedBeds: Function}} `reedModels(random)`: `{ geo, far, mat }`, the clump near
|
|
13
|
+
* and coarse (about 1.7 m tall at most) and the material that sways them; `meshReedBeds(group, beds, models)`: a near and a
|
|
14
|
+
* far instanced mesh to each bed of `[x, y, z, size, turn, shade]` rows, added to `group`, and the cells
|
|
15
|
+
* `{ mesh, lo, full, cx, cz, r }` for a level of detail.
|
|
16
|
+
*/
|
|
17
|
+
export function createReeds({ uTime, uWind }) {
|
|
18
|
+
const colour = new THREE.Color();
|
|
19
|
+
|
|
20
|
+
// A clump of marsh stems, leaves and seed heads, with a coarse version that bends in the same wind.
|
|
21
|
+
function reedModels(rng) {
|
|
22
|
+
const clump = new GB(),
|
|
23
|
+
coarse = new GB(),
|
|
24
|
+
leaf = new THREE.BufferGeometry();
|
|
25
|
+
leaf.setAttribute(
|
|
26
|
+
'position',
|
|
27
|
+
new THREE.Float32BufferAttribute(
|
|
28
|
+
[
|
|
29
|
+
0, 0, 0, 0.3, 0.24, 0.068, 0.32, 0.29, 0, 0, 0, 0, 0.32, 0.29, 0, 0.3, 0.24, -0.057, 0.3, 0.24, 0.068, 0.91, 0.2, 0, 0.32, 0.29,
|
|
30
|
+
0, 0.3, 0.24, -0.057, 0.32, 0.29, 0, 0.91, 0.2, 0,
|
|
31
|
+
],
|
|
32
|
+
3,
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
leaf.computeVertexNormals();
|
|
36
|
+
const stem = new THREE.CylinderGeometry(0.01, 0.016, 1, 4, 1, true).translate(0, 0.5, 0);
|
|
37
|
+
const seedHead = new THREE.IcosahedronGeometry(0.5, 0);
|
|
38
|
+
const stemFar = new THREE.PlaneGeometry(0.033, 1).translate(0, 0.5, 0);
|
|
39
|
+
const seedFar = new THREE.PlaneGeometry(0.88, 0.8);
|
|
40
|
+
const foliage = [0x69733e, 0x7a844e, 0x777249, 0x58683c];
|
|
41
|
+
for (let i = 0; i < 8; i++) {
|
|
42
|
+
const a = i * 2.399,
|
|
43
|
+
rad = Math.sqrt(rng()) * 0.54,
|
|
44
|
+
x = Math.sin(a) * rad,
|
|
45
|
+
z = Math.cos(a) * rad;
|
|
46
|
+
const h = 0.85 + rng() * 0.81,
|
|
47
|
+
lean = 0.025 + rng() * 0.19,
|
|
48
|
+
dx = Math.sin(a) * h * lean,
|
|
49
|
+
dz = Math.cos(a) * h * lean;
|
|
50
|
+
const stemTint = C(foliage[i % 4]);
|
|
51
|
+
clump.add(stem, stemTint, TRS(x, 0, z, 1, h, 1, a, lean, 0));
|
|
52
|
+
coarse.add(stemFar, stemTint, TRS(x, 0, z, 1, h, 1, a, lean, 0));
|
|
53
|
+
for (let j = 0; j < 3; j++) {
|
|
54
|
+
const t = 0.29 + j * 0.18,
|
|
55
|
+
l = 0.38 + rng() * 0.33;
|
|
56
|
+
const tint = C(foliage[(i + j + 1) % 4]);
|
|
57
|
+
clump.add(leaf, tint, TRS(x + dx * t, h * t, z + dz * t, l, l, l, a + j * 2.23));
|
|
58
|
+
if (j === 1) coarse.add(leaf, tint, TRS(x + dx * t, h * t, z + dz * t, l, l, l, a + j * 2.23));
|
|
59
|
+
}
|
|
60
|
+
if (i % 3 !== 1) {
|
|
61
|
+
const tint = C(i % 2 ? 0x65503a : 0x796745);
|
|
62
|
+
clump.add(seedHead, tint, TRS(x + dx, h * Math.cos(lean), z + dz, 0.052, 0.22, 0.055, a, lean, 0));
|
|
63
|
+
coarse.add(seedFar, tint, TRS(x + dx, h * Math.cos(lean), z + dz, 0.052, 0.22, 0.055, a, lean, 0));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const mat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.91, side: THREE.DoubleSide });
|
|
67
|
+
mat.onBeforeCompile = sh => {
|
|
68
|
+
sh.uniforms.uTime = uTime;
|
|
69
|
+
sh.uniforms.uWind = uWind;
|
|
70
|
+
sh.vertexShader = sh.vertexShader.replace('#include <common>', '#include <common>\nuniform float uTime; uniform vec3 uWind;').replace(
|
|
71
|
+
'#include <begin_vertex>',
|
|
72
|
+
`/* glsl */
|
|
73
|
+
#include <begin_vertex>
|
|
74
|
+
vec3 root = instanceMatrix[3].xyz;
|
|
75
|
+
vec2 down = uWind.xy / max(length(uWind.xy), 0.01); // the way the one wind blows
|
|
76
|
+
vec2 gust = down * (0.22 + 0.2 * uWind.z + 0.2 * sin(uTime * 1.74 + root.x * 0.18 + root.z * 0.15));
|
|
77
|
+
float flutter = 0.038 * sin(uTime * 4.2 + root.z * 0.47 + position.x * 8.3);
|
|
78
|
+
vec2 wind = gust + vec2(flutter, -flutter);
|
|
79
|
+
vec2 localWind = vec2(dot(wind, instanceMatrix[0].xz), dot(wind, instanceMatrix[2].xz));
|
|
80
|
+
transformed.xz += localWind * position.y * position.y * 0.35;`,
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
mat.customProgramCacheKey = () => 'land-shore-reeds-wind';
|
|
84
|
+
return { geo: clump.build(), far: coarse.build(), mat };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Each bed shares the near clumps' transforms, tints and bounds with its far mesh.
|
|
88
|
+
function meshReedBeds(group, beds, { geo, far, mat }) {
|
|
89
|
+
const cells = [];
|
|
90
|
+
for (const bed of beds) {
|
|
91
|
+
const mesh = new THREE.InstancedMesh(geo, mat, bed.length);
|
|
92
|
+
const lo = new THREE.InstancedMesh(far, mat, bed.length);
|
|
93
|
+
for (let i = 0; i < bed.length; i++) {
|
|
94
|
+
const [x, y, z, s, a, shade] = bed[i];
|
|
95
|
+
mesh.setMatrixAt(i, TRS(x, y, z, s, s, s, a));
|
|
96
|
+
mesh.setColorAt(i, colour.setRGB(shade, shade, shade * 0.95));
|
|
97
|
+
}
|
|
98
|
+
mesh.computeBoundingSphere();
|
|
99
|
+
mesh.boundingSphere.radius += 1;
|
|
100
|
+
lo.instanceMatrix = mesh.instanceMatrix;
|
|
101
|
+
lo.instanceColor = mesh.instanceColor;
|
|
102
|
+
lo.boundingSphere = mesh.boundingSphere;
|
|
103
|
+
lo.visible = false;
|
|
104
|
+
mesh.receiveShadow = lo.receiveShadow = true;
|
|
105
|
+
mesh.matrixAutoUpdate = lo.matrixAutoUpdate = false;
|
|
106
|
+
group.add(mesh, lo);
|
|
107
|
+
const { center, radius } = mesh.boundingSphere;
|
|
108
|
+
cells.push({ mesh, lo, full: bed.length, cx: center.x, cz: center.z, r: radius });
|
|
109
|
+
}
|
|
110
|
+
return cells;
|
|
111
|
+
}
|
|
112
|
+
return { meshReedBeds, reedModels };
|
|
113
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// Shade trees of courtyards, gardens, estates and village greens. A trunk forks into boughs, the boughs into branches and twigs,
|
|
2
|
+
// and the crown is made of leaf sprays set on them: flat, ragged fans of leaves lying in layers and lit from both sides, with
|
|
3
|
+
// shadow and sky between them, so that from a roof or from the air a crown reads as foliage on branches.
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
import { TAU } from '../math/scalar.js';
|
|
6
|
+
import { mulberry32 } from '../math/random.js';
|
|
7
|
+
import { C, TRS } from '../geometry/primitives.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The shade trees bound to a world's ground, group, leaf material and level of detail.
|
|
11
|
+
* @param {object} o
|
|
12
|
+
* @param {Function} o.ground - `ground(x, z)`: the ground's height in metres, for a tree planted without one.
|
|
13
|
+
* @param {THREE.Object3D} o.group - Where the trees' meshes are added.
|
|
14
|
+
* @param {Function} o.leafMaterial - Returns the material every tree is drawn with (vertex colours, an `aLeaf` attribute, both
|
|
15
|
+
* sides), made when the first trees are grown.
|
|
16
|
+
* @param {Function} o.standColourDrift - The kit's stand drift (`createPlantTints`).
|
|
17
|
+
* @param {Function} o.addCell - Takes each cell of trees, `{ mesh, lo, impostor, cx, cy, cz, r }`, for a level of detail.
|
|
18
|
+
* @returns {{buildShadeTrees: Function}} `buildShadeTrees(planted)`: grows the trees planted, `[x, z, size, y?]` each (two forms,
|
|
19
|
+
* each turned, stretched and tinted its own way, in cells of 120 m), and hands their cells to `addCell`.
|
|
20
|
+
*/
|
|
21
|
+
export function createShadeTrees({ ground: terrainHeight, group: worldGroup, leafMaterial, standColourDrift, addCell }) {
|
|
22
|
+
const FORM_SEEDS = [9371, 5113]; // two trees grown differently; each planting takes one, turned and stretched its own way
|
|
23
|
+
const CELL = 120; // trees are drawn in squares of this size, so those off screen are skipped and far ones take their light version
|
|
24
|
+
const BARK = C(0x4d3d2e),
|
|
25
|
+
GREENS = [0x4a6b33, 0x3d5c2c, 0x587838, 0x35522a, 0x66823f].map(hex => C(hex));
|
|
26
|
+
|
|
27
|
+
const newParts = () => ({ p: [], n: [], c: [], l: [] });
|
|
28
|
+
const add3 = (a, d, k) => [a[0] + d[0] * k, a[1] + d[1] * k, a[2] + d[2] * k];
|
|
29
|
+
const unit = v => {
|
|
30
|
+
const l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
31
|
+
return [v[0] / l, v[1] / l, v[2] / l];
|
|
32
|
+
};
|
|
33
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
34
|
+
// Two unit vectors square to d and to each other, so that u × v = d
|
|
35
|
+
function across(d) {
|
|
36
|
+
const u = unit(Math.abs(d[1]) < 0.9 ? cross([0, 1, 0], d) : cross([1, 0, 0], d));
|
|
37
|
+
return [u, cross(d, u)];
|
|
38
|
+
}
|
|
39
|
+
function vertex(G, p, n, col, shade, leaf) {
|
|
40
|
+
G.p.push(p[0], p[1], p[2]);
|
|
41
|
+
G.n.push(n[0], n[1], n[2]);
|
|
42
|
+
G.c.push(col[0] * shade, col[1] * shade, col[2] * shade);
|
|
43
|
+
G.l.push(leaf);
|
|
44
|
+
}
|
|
45
|
+
// A limb from a to b, tapering from radius ra to rb
|
|
46
|
+
function limb(G, a, b, ra, rb, sides, R) {
|
|
47
|
+
const [u, v] = across(unit(add3(b, a, -1)));
|
|
48
|
+
const ring = k => {
|
|
49
|
+
const t = (k / sides) * TAU;
|
|
50
|
+
return [u[0] * Math.cos(t) + v[0] * Math.sin(t), u[1] * Math.cos(t) + v[1] * Math.sin(t), u[2] * Math.cos(t) + v[2] * Math.sin(t)];
|
|
51
|
+
};
|
|
52
|
+
for (let k = 0; k < sides; k++) {
|
|
53
|
+
const n0 = ring(k),
|
|
54
|
+
n1 = ring(k + 1),
|
|
55
|
+
s0 = 0.78 + 0.4 * R(),
|
|
56
|
+
s1 = 0.78 + 0.4 * R();
|
|
57
|
+
const a0 = add3(a, n0, ra),
|
|
58
|
+
a1 = add3(a, n1, ra),
|
|
59
|
+
b0 = add3(b, n0, rb),
|
|
60
|
+
b1 = add3(b, n1, rb);
|
|
61
|
+
for (const [p, n, s] of [
|
|
62
|
+
[a0, n0, s0],
|
|
63
|
+
[a1, n1, s1],
|
|
64
|
+
[b1, n1, s1],
|
|
65
|
+
[a0, n0, s0],
|
|
66
|
+
[b1, n1, s1],
|
|
67
|
+
[b0, n0, s0],
|
|
68
|
+
])
|
|
69
|
+
vertex(G, p, n, BARK, s, 0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// A spray of leaves at `at`: a ragged star of leaves lying across `facing`, each point its own length, droop and tone, the heart dark.
|
|
73
|
+
// `shade` darkens the sprays deep in the crown.
|
|
74
|
+
function spray(G, at, facing, r, points, shade, R) {
|
|
75
|
+
const m = unit([facing[0] + (R() - 0.5) * 0.6, facing[1], facing[2] + (R() - 0.5) * 0.6]),
|
|
76
|
+
[e1, e2] = across(m),
|
|
77
|
+
green = GREENS[(R() * GREENS.length) | 0],
|
|
78
|
+
turn = R() * TAU,
|
|
79
|
+
rim = [];
|
|
80
|
+
for (let k = 0; k < points; k++) {
|
|
81
|
+
const t = turn + ((k + (R() - 0.5) * 0.6) / points) * TAU,
|
|
82
|
+
reach = r * (k % 2 ? 0.45 + 0.25 * R() : 0.8 + 0.5 * R()), // long and short by turns: the outline of leaves, not of a disc
|
|
83
|
+
out = [
|
|
84
|
+
e1[0] * Math.cos(t) + e2[0] * Math.sin(t),
|
|
85
|
+
e1[1] * Math.cos(t) + e2[1] * Math.sin(t),
|
|
86
|
+
e1[2] * Math.cos(t) + e2[2] * Math.sin(t),
|
|
87
|
+
],
|
|
88
|
+
lift = k % 2 ? 0.1 : -(0.1 + 0.4 * R()); // the long leaves hang, the short ones between them stand
|
|
89
|
+
rim.push({
|
|
90
|
+
p: add3(add3(at, out, reach), m, r * lift),
|
|
91
|
+
n: unit([
|
|
92
|
+
m[0] + out[0] * 0.9 + (R() - 0.5) * 0.5,
|
|
93
|
+
m[1] + out[1] * 0.9 + (R() - 0.5) * 0.5,
|
|
94
|
+
m[2] + out[2] * 0.9 + (R() - 0.5) * 0.5,
|
|
95
|
+
]),
|
|
96
|
+
s: shade * (k % 2 ? 0.62 + 0.2 * R() : 0.9 + 0.4 * R()),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const heart = add3(at, m, r * 0.16);
|
|
100
|
+
for (let k = 0; k < points; k++) {
|
|
101
|
+
const a = rim[k],
|
|
102
|
+
b = rim[(k + 1) % points];
|
|
103
|
+
vertex(G, heart, m, green, shade * 0.55, 1);
|
|
104
|
+
vertex(G, a.p, a.n, green, a.s, 1);
|
|
105
|
+
vertex(G, b.p, b.n, green, b.s, 1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// One tree. The near one has every twig and spray; the far one keeps the trunk, the boughs and fewer, larger sprays in the same places.
|
|
109
|
+
function growTree(seed, near) {
|
|
110
|
+
const R = mulberry32(seed),
|
|
111
|
+
fine = mulberry32(seed + 1), // what only the near tree has is drawn from its own numbers, so both grow the same limbs
|
|
112
|
+
rf = (a, b) => a + R() * (b - a),
|
|
113
|
+
G = newParts();
|
|
114
|
+
const dirOf = (az, el) => [Math.cos(az) * Math.cos(el), Math.sin(el), Math.sin(az) * Math.cos(el)];
|
|
115
|
+
const fork = [rf(-0.25, 0.25), rf(2.3, 3.0), rf(-0.25, 0.25)],
|
|
116
|
+
knee = [fork[0] * 0.2 + rf(-0.12, 0.12), fork[1] * 0.5, fork[2] * 0.2 + rf(-0.12, 0.12)],
|
|
117
|
+
trunkSides = near ? 8 : 5;
|
|
118
|
+
limb(G, [0, -0.45, 0], knee, 0.36, 0.26, trunkSides, fine);
|
|
119
|
+
limb(G, knee, fork, 0.26, 0.2, trunkSides, fine);
|
|
120
|
+
if (near)
|
|
121
|
+
for (let k = 0; k < 5; k++) {
|
|
122
|
+
const t = k * 1.26 + fine() * 0.5; // roots spreading at the foot
|
|
123
|
+
limb(G, [Math.cos(t) * 0.62, -0.3, Math.sin(t) * 0.62], [Math.cos(t) * 0.12, 0.8, Math.sin(t) * 0.12], 0.16, 0.1, 5, fine);
|
|
124
|
+
}
|
|
125
|
+
const heart = [fork[0], fork[1] + 2.2, fork[2]], // the middle of the crown: sprays face away from it
|
|
126
|
+
BOUGHS = 5;
|
|
127
|
+
const leaves = (at, r, deep) => {
|
|
128
|
+
const out = unit(add3(at, heart, -1)),
|
|
129
|
+
facing = [out[0] * 0.75, 0.55 + 0.45 * Math.max(out[1], 0), out[2] * 0.75],
|
|
130
|
+
shade = (deep ? 0.62 : 0.82) + 0.34 * Math.min(1, Math.max(0, (at[1] - fork[1]) / 4));
|
|
131
|
+
spray(G, at, facing, near ? r : r * 1.5, near ? 16 : 10, shade, fine);
|
|
132
|
+
};
|
|
133
|
+
for (let i = 0; i <= BOUGHS; i++) {
|
|
134
|
+
const leader = i === BOUGHS,
|
|
135
|
+
az = (i / BOUGHS) * TAU + rf(-0.35, 0.35),
|
|
136
|
+
el = leader ? rf(1.2, 1.45) : rf(0.42, 0.9),
|
|
137
|
+
len = leader ? rf(2.4, 3.0) : rf(2.4, 3.2),
|
|
138
|
+
dir = dirOf(az, el);
|
|
139
|
+
const mid = add3(fork, dir, len * 0.5),
|
|
140
|
+
end = add3(mid, unit([dir[0], dir[1] + 0.4, dir[2]]), len * 0.5); // a bough leaves the trunk low and turns up towards the light
|
|
141
|
+
limb(G, fork, mid, 0.14, 0.095, near ? 6 : 3, fine);
|
|
142
|
+
limb(G, mid, end, 0.095, 0.05, near ? 6 : 3, fine);
|
|
143
|
+
for (let j = 0; j < 3; j++) {
|
|
144
|
+
const from = j === 0 ? mid : j === 1 ? add3(mid, add3(end, mid, -1), 0.55) : end,
|
|
145
|
+
baz = az + (j - 1) * rf(0.7, 1.15) + rf(-0.2, 0.2),
|
|
146
|
+
bel = el * 0.55 + rf(0.0, 0.4),
|
|
147
|
+
tip = add3(from, dirOf(baz, bel), rf(1.2, 1.9) * (leader ? 0.8 : 1)),
|
|
148
|
+
size = rf(0.7, 0.95);
|
|
149
|
+
if (!near) {
|
|
150
|
+
leaves(tip, size, false);
|
|
151
|
+
leaves(add3(from, add3(tip, from, -1), 0.45), size * 0.9, true);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
limb(G, from, tip, 0.045, 0.02, 5, fine);
|
|
155
|
+
leaves(tip, size, false);
|
|
156
|
+
for (const drop of [0.4, 0.85]) leaves(add3(tip, [fine() - 0.5, -drop - 0.2 * fine(), fine() - 0.5], 0.95), size * 0.9, drop > 0.5); // layers under the first
|
|
157
|
+
leaves(add3(from, add3(tip, from, -1), 0.45), size * 0.85, true);
|
|
158
|
+
for (const part of [0.3, 0.6, 0.9]) {
|
|
159
|
+
const root = add3(from, add3(tip, from, -1), part), // twigs to either side, each with its spray
|
|
160
|
+
twig = add3(
|
|
161
|
+
root,
|
|
162
|
+
dirOf(baz + (part > 0.5 && part < 0.7 ? 1.3 : -1.2) + fine() * 0.4, bel * 0.6 + fine() * 0.5),
|
|
163
|
+
0.7 + 0.5 * fine(),
|
|
164
|
+
);
|
|
165
|
+
limb(G, root, twig, 0.02, 0.01, 3, fine);
|
|
166
|
+
leaves(twig, size * (0.7 + 0.25 * fine()), false);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
leaves(add3(end, [0, 0.25, 0], 1), rf(0.7, 0.95), false);
|
|
170
|
+
if (near)
|
|
171
|
+
for (const part of [0.15, 0.6])
|
|
172
|
+
leaves(add3(add3(mid, add3(end, mid, -1), part), [fine() - 0.5, 0.3, fine() - 0.5], 0.9), 0.8, true); // foliage along the bough itself
|
|
173
|
+
}
|
|
174
|
+
const g = new THREE.BufferGeometry();
|
|
175
|
+
g.setAttribute('position', new THREE.Float32BufferAttribute(G.p, 3));
|
|
176
|
+
g.setAttribute('normal', new THREE.Float32BufferAttribute(G.n, 3));
|
|
177
|
+
g.setAttribute('color', new THREE.Float32BufferAttribute(G.c, 3));
|
|
178
|
+
g.setAttribute('aLeaf', new THREE.Float32BufferAttribute(G.l, 1));
|
|
179
|
+
g.computeBoundingSphere();
|
|
180
|
+
return g;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// The two trees' near and far forms and the leaves' material, made when the first trees are grown and shared by every planting after
|
|
184
|
+
let grown = null;
|
|
185
|
+
function treeForms() {
|
|
186
|
+
return (grown ??= {
|
|
187
|
+
material: leafMaterial(),
|
|
188
|
+
forms: FORM_SEEDS.map(seed => ({ near: growTree(seed, true), far: growTree(seed, false) })),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// Grows the trees a pass planted ([x, z, size] each) and hands them to the tree cells (a level of detail shows the near or the
|
|
192
|
+
// far version of each square).
|
|
193
|
+
function buildShadeTrees(planted) {
|
|
194
|
+
if (!planted.length) return;
|
|
195
|
+
const { material: leafBothSides, forms } = treeForms(),
|
|
196
|
+
rng = mulberry32(7741),
|
|
197
|
+
cells = new Map(),
|
|
198
|
+
tint = new THREE.Color(),
|
|
199
|
+
drift = [1, 1, 1];
|
|
200
|
+
for (const [x, z, size, y] of planted) {
|
|
201
|
+
const form = (rng() * forms.length) | 0,
|
|
202
|
+
key = Math.floor(x / CELL) + ':' + Math.floor(z / CELL) + ':' + form;
|
|
203
|
+
let cell = cells.get(key);
|
|
204
|
+
if (!cell) cells.set(key, (cell = { form, trees: [] }));
|
|
205
|
+
cell.trees.push([x, z, size, y ?? terrainHeight(x, z), rng() * TAU, 0.9 + 0.25 * rng(), 0.84 + 0.3 * rng(), 0.92 + 0.16 * rng()]);
|
|
206
|
+
}
|
|
207
|
+
for (const { form, trees } of cells.values()) {
|
|
208
|
+
const near = new THREE.InstancedMesh(forms[form].near, leafBothSides, trees.length),
|
|
209
|
+
far = new THREE.InstancedMesh(forms[form].far, leafBothSides, trees.length);
|
|
210
|
+
trees.forEach(([x, z, size, y, turn, tall, light, warm], i) => {
|
|
211
|
+
standColourDrift(x, z, (light - 0.84) / 0.3, drift);
|
|
212
|
+
near.setMatrixAt(i, TRS(x, y - 0.1, z, size, size * tall, size, turn));
|
|
213
|
+
near.setColorAt(i, tint.setRGB(drift[0] * (0.94 + warm * 0.06), drift[1], drift[2] * 0.93));
|
|
214
|
+
});
|
|
215
|
+
far.instanceMatrix = near.instanceMatrix;
|
|
216
|
+
far.instanceColor = near.instanceColor;
|
|
217
|
+
near.computeBoundingSphere();
|
|
218
|
+
far.boundingSphere = near.boundingSphere;
|
|
219
|
+
far.visible = false;
|
|
220
|
+
for (const mesh of [near, far]) {
|
|
221
|
+
mesh.castShadow = mesh === near;
|
|
222
|
+
mesh.receiveShadow = true;
|
|
223
|
+
mesh.matrixAutoUpdate = false;
|
|
224
|
+
worldGroup.add(mesh);
|
|
225
|
+
}
|
|
226
|
+
const { center, radius } = near.boundingSphere;
|
|
227
|
+
addCell({
|
|
228
|
+
mesh: near,
|
|
229
|
+
lo: far,
|
|
230
|
+
impostor: { geometry: forms[form].near, silhouette: 'round', crownStart: 0.34, crownWidthScale: 1.15 },
|
|
231
|
+
cx: center.x,
|
|
232
|
+
cy: center.y,
|
|
233
|
+
cz: center.z,
|
|
234
|
+
r: radius,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return { buildShadeTrees };
|
|
239
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// A patch of grass tufts on a grid that follows the walker, in one draw call: each cell of the grid holds a tuft or none, as
|
|
2
|
+
// the caller's `place` says.
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { createScatterGrid } from '../geometry/scatter-grid.js';
|
|
5
|
+
import { TAU } from '../math/scalar.js';
|
|
6
|
+
import { TRS } from '../geometry/primitives.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The tuft patch bound to a world's camera, scene, spaces, quality and tuft.
|
|
10
|
+
* @param {object} o
|
|
11
|
+
* @param {THREE.Camera} o.camera - The camera the patch follows.
|
|
12
|
+
* @param {THREE.Object3D} o.scene - Where the patch's mesh is added (on layer 1).
|
|
13
|
+
* @param {Function} o.currentSpace - Returns the space the camera is in, compared with each patch's `home()`.
|
|
14
|
+
* @param {Function} o.density - Returns the cells from the walker to the patch's edge the quality allows (42 at most; 0 hides it).
|
|
15
|
+
* @param {Function} o.tuftGeometry - Returns a new tuft's geometry, a metre tall.
|
|
16
|
+
* @param {Function} o.tuftMaterial - `tuftMaterial(uCam, uR, ringed)`: the tufts' material, given the camera's and the
|
|
17
|
+
* patch's radius uniforms and whether the patch has more than one ring (an `aReach` attribute).
|
|
18
|
+
* @param {Function} o.hash - A seeded integer hash (`createHash`), which gives each cell its two numbers.
|
|
19
|
+
* @returns {{tuftPatch: Function}} `tuftPatch(home, ground, place, rings)` (described above).
|
|
20
|
+
*/
|
|
21
|
+
export function createTuftPatch({ camera, scene, currentSpace, density, tuftGeometry, tuftMaterial, hash: hash2 }) {
|
|
22
|
+
const HALF = 42, // cells from the walker to the patch's edge at the most (`density` scales it by quality level)
|
|
23
|
+
CELL = 1.3, // metres across a cell: a tuft to each
|
|
24
|
+
REFILL = 5, // metres the walker moves before the patch is filled again round them
|
|
25
|
+
OVER_GROUND = 45, // metres over the ground above which the patch is not drawn: from the air the ground's own colour stands for it
|
|
26
|
+
SEEDS = [301, 302]; // of the two numbers every cell has: where in the cell its tuft stands, and what it is like
|
|
27
|
+
const _colour = new THREE.Color();
|
|
28
|
+
// What `place` says of the tuft of the cell it was asked about.
|
|
29
|
+
const tuft = {
|
|
30
|
+
x: 0, // where it stands: the cell's own spot, unless `place` moves it
|
|
31
|
+
z: 0,
|
|
32
|
+
y: 0, // the height of its foot
|
|
33
|
+
wide: 1, // its width and its height, times the tuft's own
|
|
34
|
+
tall: 1,
|
|
35
|
+
r: 1, // its colour, linear
|
|
36
|
+
g: 1,
|
|
37
|
+
b: 1,
|
|
38
|
+
flower: 0, // what it flowers as (the tuft's aFlower), or 0
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// The default grid: one ring, a tuft to each 1.3 m, shrinking away at the patch's edge.
|
|
42
|
+
const ONE_RING = [{ cell: CELL, half: HALF, refill: REFILL }];
|
|
43
|
+
// A patch of tufts in the space `home`, whose ground is ground(x, z). place(x, z, h1, h2, ix, iz, tuft, cell) says whether a tuft
|
|
44
|
+
// stands in cell (ix, iz) at (x, z), and writes what it is like into `tuft`; h1 and h2 are the cell's two numbers, 0..1, and `cell`
|
|
45
|
+
// the cell's width in metres. `rings`: the patch's grids, each about the walker ({ cell: metres across a cell, half: cells from the
|
|
46
|
+
// walker to its edge at full density, refill: metres the walker moves before it is filled again }), finest first: a stand that is close
|
|
47
|
+
// near the eye and thins with distance, each ring's tufts shrinking away before its edge, as the next ring's grow, so that none appears or goes at a fill
|
|
48
|
+
// (the three together are within the one ring's copies). Returns the patch's update, to be called every frame: it fills a ring
|
|
49
|
+
// again when the walker has moved, and shows the patch only near the ground.
|
|
50
|
+
function tuftPatch(home, ground, place, rings = ONE_RING) {
|
|
51
|
+
const ringed = rings.length > 1,
|
|
52
|
+
uCam = { value: new THREE.Vector3() },
|
|
53
|
+
uR = { value: 70 },
|
|
54
|
+
geometry = tuftGeometry(),
|
|
55
|
+
capacity = rings.reduce((sum, ring) => sum + (2 * ring.half) ** 2, 0),
|
|
56
|
+
mesh = new THREE.InstancedMesh(geometry, tuftMaterial(uCam, uR, ringed), capacity),
|
|
57
|
+
flower = new THREE.InstancedBufferAttribute(new Float32Array(capacity), 1),
|
|
58
|
+
reach = ringed ? new THREE.InstancedBufferAttribute(new Float32Array(capacity * 2), 2) : null;
|
|
59
|
+
geometry.setAttribute('aFlower', flower);
|
|
60
|
+
if (reach) geometry.setAttribute('aReach', reach);
|
|
61
|
+
mesh.setColorAt(0, _colour.setRGB(1, 1, 1));
|
|
62
|
+
mesh.frustumCulled = false;
|
|
63
|
+
mesh.receiveShadow = true;
|
|
64
|
+
mesh.layers.set(1);
|
|
65
|
+
scene.add(mesh);
|
|
66
|
+
const buffers = rings.map(ring => {
|
|
67
|
+
const n = (ring.half * 2) ** 2;
|
|
68
|
+
return {
|
|
69
|
+
matrix: ringed ? new Float32Array(n * 16) : mesh.instanceMatrix.array,
|
|
70
|
+
colour: ringed ? new Float32Array(n * 3) : mesh.instanceColor.array,
|
|
71
|
+
flower: ringed ? new Float32Array(n) : flower.array,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
const updateGrid = createScatterGrid({
|
|
75
|
+
rings,
|
|
76
|
+
hash: hash2,
|
|
77
|
+
seeds: SEEDS,
|
|
78
|
+
fill(level, index, x, z, h1, h2, ix, iz, cell) {
|
|
79
|
+
tuft.x = x;
|
|
80
|
+
tuft.z = z;
|
|
81
|
+
if (!place(x, z, h1, h2, ix, iz, tuft, cell)) return false;
|
|
82
|
+
const buffer = buffers[level];
|
|
83
|
+
TRS(tuft.x, tuft.y, tuft.z, tuft.wide, tuft.tall, tuft.wide, h2 * TAU).toArray(buffer.matrix, index * 16);
|
|
84
|
+
_colour.setRGB(tuft.r, tuft.g, tuft.b).toArray(buffer.colour, index * 3);
|
|
85
|
+
buffer.flower[index] = tuft.flower;
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
finish(grids) {
|
|
89
|
+
let count = 0;
|
|
90
|
+
for (let level = 0; level < grids.length; level++) {
|
|
91
|
+
const grid = grids[level];
|
|
92
|
+
if (reach) {
|
|
93
|
+
const buffer = buffers[level];
|
|
94
|
+
mesh.instanceMatrix.array.set(buffer.matrix, count * 16);
|
|
95
|
+
mesh.instanceColor.array.set(buffer.colour, count * 3);
|
|
96
|
+
flower.array.set(buffer.flower, count);
|
|
97
|
+
for (let i = count; i < count + grid.count; i++) {
|
|
98
|
+
reach.array[i * 2] = grid.inner;
|
|
99
|
+
reach.array[i * 2 + 1] = grid.outer;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
count += grid.count;
|
|
103
|
+
}
|
|
104
|
+
mesh.count = count;
|
|
105
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
106
|
+
mesh.instanceColor.needsUpdate = true;
|
|
107
|
+
flower.needsUpdate = true;
|
|
108
|
+
if (reach) reach.needsUpdate = true;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
return () => {
|
|
112
|
+
const dense = Math.min(HALF, density());
|
|
113
|
+
mesh.visible =
|
|
114
|
+
dense > 0 && currentSpace() === home() && camera.position.y < ground(camera.position.x, camera.position.z) + OVER_GROUND;
|
|
115
|
+
if (!mesh.visible) return;
|
|
116
|
+
uCam.value.copy(camera.position);
|
|
117
|
+
uR.value = dense * CELL * 0.96;
|
|
118
|
+
updateGrid(camera.position.x, camera.position.z, dense / HALF);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return { tuftPatch };
|
|
122
|
+
}
|