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
package/rendering/cell-lod.js
CHANGED
|
@@ -1,117 +1,275 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
+
import { createTreeImpostorBatch, createTreeImpostorMaterial, hashCoords2D } from './tree-impostor.js';
|
|
3
|
+
import { resolveCellLodOptions } from './cell-lod-options.js';
|
|
4
|
+
|
|
5
|
+
const TIER_HIDDEN = 0;
|
|
6
|
+
const TIER_NEAR = 1;
|
|
7
|
+
const TIER_FAR = 2;
|
|
8
|
+
const TIER_IMPOSTOR = 3;
|
|
9
|
+
|
|
10
|
+
const MODE_NONE = 0;
|
|
11
|
+
const MODE_ALL_FAR = 1;
|
|
12
|
+
const MODE_ALL_IMPOSTOR = 2;
|
|
13
|
+
const MODE_MIXED = 3;
|
|
2
14
|
|
|
3
15
|
/**
|
|
4
16
|
* Level of detail for scattered things laid out in cells (trees, scrub, rocks, reeds). Each cell has a detailed instanced mesh for
|
|
5
|
-
* near and, most of them, a low-detail instanced copy for far
|
|
6
|
-
* be a draw call in every pass, so the far copies are batched:
|
|
7
|
-
*
|
|
8
|
-
* cell's first `count` (the far thinning), read from a small table written each frame. What is drawn is exactly what the cells drew
|
|
9
|
-
* one by one, and a batch none of whose cells shows is hidden, so no pass runs its vertices only to drop them.
|
|
17
|
+
* near and, most of them, a low-detail instanced copy for far (plus optional 8-heading billboard impostors beyond the far mesh).
|
|
18
|
+
* Hundreds of far cells hold a handful of instances each, and each would be a draw call in every pass, so the far copies are batched:
|
|
19
|
+
* one instanced mesh per kind and square of ground.
|
|
10
20
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
21
|
+
* Each shadow-casting far batch mesh sets `mesh.userData.partShown = true` to mark that inactive instances are culled by its
|
|
22
|
+
* `customDepthMaterial` / `customDistanceMaterial` (or packed dynamically in `compact` mode), so external depth passes (such as
|
|
23
|
+
* sky-occlusion renderers) can recognise partially populated batches.
|
|
14
24
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
25
|
+
* When `instanceJitter > 0` or `impostorAtlas` is supplied, cells opt into per-instance hashed handover distances (`near -> far -> impostor`)
|
|
26
|
+
* so each tree transitions at its own deterministic jittered distance and no hard LOD ring ever shows. `update` also accepts
|
|
27
|
+
* `{ lensScale, holdHandover, farDistance, impostorDistance }` so narrow-FOV camera shots promote background stands and hold active
|
|
28
|
+
* LOD tiers steady between cuts. See `DEFAULT_CELL_LOD_OPTIONS` (`rendering/cell-lod-options.js`) for every option and its units.
|
|
29
|
+
*
|
|
30
|
+
* @param {Partial<import('./cell-lod-options.js').DEFAULT_CELL_LOD_OPTIONS>} [options] Cell-LOD configuration overrides.
|
|
20
31
|
*/
|
|
21
|
-
export function createCellLod(
|
|
32
|
+
export function createCellLod(options = {}) {
|
|
33
|
+
const {
|
|
34
|
+
square,
|
|
35
|
+
compact,
|
|
36
|
+
tableWidth,
|
|
37
|
+
thinFrom,
|
|
38
|
+
thinTo,
|
|
39
|
+
thinImpostors,
|
|
40
|
+
jitter,
|
|
41
|
+
defaultJitter,
|
|
42
|
+
nearHysteresis,
|
|
43
|
+
farHysteresis,
|
|
44
|
+
impostorHysteresis,
|
|
45
|
+
farDistanceShare,
|
|
46
|
+
impostorDistanceShare,
|
|
47
|
+
impostorLensCap,
|
|
48
|
+
impostorAtlas,
|
|
49
|
+
impostorSquare,
|
|
50
|
+
} = resolveCellLodOptions(options);
|
|
22
51
|
const table = { data: null, tex: null },
|
|
23
52
|
shown = { value: null }, // the table, as the uniform the far materials and the far shadow body share
|
|
24
|
-
batches = []
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
batches = [],
|
|
54
|
+
members = [],
|
|
55
|
+
impostorBatches = [],
|
|
56
|
+
impostorMembers = [];
|
|
57
|
+
let activeAtlas = impostorAtlas,
|
|
58
|
+
sharedImpostorMaterial = null,
|
|
59
|
+
drawEnds = null,
|
|
60
|
+
dirty = null,
|
|
61
|
+
impDirty = null,
|
|
62
|
+
depth = null,
|
|
63
|
+
distanceMaterial = null,
|
|
64
|
+
perInstanceTable = false,
|
|
65
|
+
hasSnapshot = false;
|
|
27
66
|
|
|
28
67
|
// Hides, in the vertex shader, a copy whose cell is not showing its far copy or that lies past the cell's `count`.
|
|
29
|
-
function hideUnshown(
|
|
30
|
-
|
|
31
|
-
|
|
68
|
+
function hideUnshown(shader) {
|
|
69
|
+
shader.uniforms.uFarShown = shown;
|
|
70
|
+
shader.vertexShader = shader.vertexShader
|
|
32
71
|
.replace('#include <common>', '#include <common>\nattribute vec2 aFar; uniform sampler2D uFarShown;')
|
|
33
72
|
.replace(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
73
|
+
/void\s+main\s*\(\s*(?:void)?\s*\)\s*\{/,
|
|
74
|
+
match => `${match}
|
|
75
|
+
if (aFar.y >= texelFetch(uFarShown, ivec2(int(aFar.x) % ${tableWidth}, int(aFar.x) / ${tableWidth}), 0).r) {
|
|
76
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
77
|
+
return;
|
|
78
|
+
}`,
|
|
38
79
|
);
|
|
39
80
|
}
|
|
81
|
+
|
|
40
82
|
// A far copy's material: the cell's own, cloned once per material, with its own patch kept and the hiding added.
|
|
41
83
|
function farMaterial(base, cache) {
|
|
42
84
|
if (cache.has(base)) return cache.get(base);
|
|
43
|
-
const
|
|
85
|
+
const material = base.clone(),
|
|
44
86
|
inner = base.onBeforeCompile,
|
|
45
87
|
key = base.customProgramCacheKey();
|
|
46
|
-
|
|
47
|
-
inner.call(base,
|
|
48
|
-
hideUnshown(
|
|
88
|
+
material.onBeforeCompile = (shader, r) => {
|
|
89
|
+
inner.call(base, shader, r);
|
|
90
|
+
hideUnshown(shader);
|
|
49
91
|
};
|
|
50
|
-
|
|
51
|
-
cache.set(base,
|
|
52
|
-
return
|
|
92
|
+
material.customProgramCacheKey = () => key + ':far-batch';
|
|
93
|
+
cache.set(base, material);
|
|
94
|
+
return material;
|
|
53
95
|
}
|
|
96
|
+
|
|
54
97
|
// The shadow body of far copies that cast: the far shape itself, hidden as in the picture, so a cell casts what it shows.
|
|
55
98
|
function depthMaterial() {
|
|
56
99
|
if (depth) return depth;
|
|
57
|
-
depth = new THREE.MeshDepthMaterial(
|
|
58
|
-
|
|
59
|
-
|
|
100
|
+
depth = new THREE.MeshDepthMaterial();
|
|
101
|
+
if (!compact) {
|
|
102
|
+
depth.onBeforeCompile = hideUnshown;
|
|
103
|
+
depth.customProgramCacheKey = () => 'far-batch-depth';
|
|
104
|
+
}
|
|
60
105
|
return depth;
|
|
61
106
|
}
|
|
62
107
|
|
|
63
|
-
|
|
64
|
-
function
|
|
65
|
-
|
|
108
|
+
// Extracts immutable source attributes and deterministic per-instance world-space hashes once per cell.
|
|
109
|
+
function ensureInstanceMetadata(cell, at) {
|
|
110
|
+
if (at.px) return;
|
|
111
|
+
const srcMat = at.sourceMatrix.array,
|
|
112
|
+
total = at.total,
|
|
113
|
+
px = new Float32Array(total),
|
|
114
|
+
py = new Float32Array(total),
|
|
115
|
+
pz = new Float32Array(total),
|
|
116
|
+
hNear = new Float32Array(total),
|
|
117
|
+
hFar = new Float32Array(total),
|
|
118
|
+
hImp = new Float32Array(total);
|
|
119
|
+
for (let k = 0; k < total; k++) {
|
|
120
|
+
const mOff = k * 16,
|
|
121
|
+
x = srcMat[mOff + 12],
|
|
122
|
+
y = srcMat[mOff + 13],
|
|
123
|
+
z = srcMat[mOff + 14],
|
|
124
|
+
ix = Math.round(x * 13),
|
|
125
|
+
iz = Math.round(z * 13);
|
|
126
|
+
px[k] = x;
|
|
127
|
+
py[k] = y;
|
|
128
|
+
pz[k] = z;
|
|
129
|
+
hNear[k] = hashCoords2D(ix, iz, 101 + k);
|
|
130
|
+
hFar[k] = hashCoords2D(ix, iz, 307 + k);
|
|
131
|
+
hImp[k] = hashCoords2D(ix, iz, 613 + k);
|
|
132
|
+
}
|
|
133
|
+
at.px = px;
|
|
134
|
+
at.py = py;
|
|
135
|
+
at.pz = pz;
|
|
136
|
+
at.hNear = hNear;
|
|
137
|
+
at.hFar = hFar;
|
|
138
|
+
at.hImp = hImp;
|
|
139
|
+
at.tiers = new Uint8Array(total);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Where a cell lies and how far it is drawn, kept on it in a record of one shape.
|
|
143
|
+
function lodOf(cell) {
|
|
144
|
+
if (cell.lod) return cell.lod;
|
|
145
|
+
// A cell whose near object is not instanced (a group, or one mesh on its own) has no copies to hand over one by one: it
|
|
146
|
+
// keeps no source matrices, and update shows it whole or not at all, by distance.
|
|
147
|
+
const sourceMatrix = cell.mesh?.instanceMatrix ?? null,
|
|
148
|
+
sourceColor = sourceMatrix ? (cell.mesh.instanceColor ?? null) : null;
|
|
149
|
+
cell.lod = {
|
|
150
|
+
cx: cell.cx,
|
|
151
|
+
cy: cell.cy ?? 0,
|
|
152
|
+
cz: cell.cz,
|
|
153
|
+
r: cell.r,
|
|
154
|
+
until: cell.until ?? Infinity,
|
|
155
|
+
near: cell.near ?? Infinity,
|
|
156
|
+
batch: cell.farBatch ?? -1,
|
|
157
|
+
impBatch: cell.impBatch ?? -1,
|
|
158
|
+
species: typeof cell.impostor === 'number' ? cell.impostor : -1,
|
|
159
|
+
sourceMatrix,
|
|
160
|
+
sourceColor,
|
|
161
|
+
total: sourceMatrix ? sourceMatrix.count : 0,
|
|
162
|
+
px: null,
|
|
163
|
+
py: null,
|
|
164
|
+
pz: null,
|
|
165
|
+
hNear: null,
|
|
166
|
+
hFar: null,
|
|
167
|
+
hImp: null,
|
|
168
|
+
tiers: null,
|
|
169
|
+
nearMatrix: null,
|
|
170
|
+
nearColor: null,
|
|
171
|
+
loMatrix: null,
|
|
172
|
+
loColor: null,
|
|
173
|
+
mode: MODE_NONE,
|
|
174
|
+
activeLimit: 0,
|
|
175
|
+
nearCount: 0,
|
|
176
|
+
farCount: 0,
|
|
177
|
+
impCount: 0,
|
|
178
|
+
};
|
|
179
|
+
return cell.lod;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Batches the far copies of `cellList` (taken out of their parents) into `parent` and, when an `impostorAtlas`
|
|
184
|
+
* is configured, builds spatial impostor batches for cells tagged with an `impostor` species index.
|
|
185
|
+
*
|
|
186
|
+
* @param {Array<object>} cellList Cells to batch.
|
|
187
|
+
* @param {THREE.Object3D} parent Group receiving the merged far and impostor batches.
|
|
188
|
+
* @param {object} [batchOptions]
|
|
189
|
+
* @param {object} [batchOptions.impostorAtlas] Optional atlas overriding `options.impostorAtlas`.
|
|
190
|
+
* @returns {Array<THREE.InstancedMesh>} The created far batch meshes.
|
|
191
|
+
*/
|
|
192
|
+
function batch(cellList, parent, batchOptions = {}) {
|
|
193
|
+
if (batchOptions.impostorAtlas) activeAtlas = batchOptions.impostorAtlas;
|
|
194
|
+
hasSnapshot = false;
|
|
195
|
+
|
|
196
|
+
const cells = cellList.filter(cell => cell.lo && cell.lo.isInstancedMesh),
|
|
66
197
|
groups = new Map(),
|
|
67
|
-
materials = new Map()
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
198
|
+
materials = new Map(),
|
|
199
|
+
anyImpostor = Boolean(activeAtlas) && cellList.some(cell => typeof cell.impostor === 'number' && cell.impostor >= 0);
|
|
200
|
+
|
|
201
|
+
perInstanceTable = !compact && (jitter > 0 || anyImpostor);
|
|
202
|
+
let totalFarSlots = cells.length;
|
|
203
|
+
if (perInstanceTable) {
|
|
204
|
+
totalFarSlots = 0;
|
|
205
|
+
for (let i = 0; i < cells.length; i++) {
|
|
206
|
+
cells[i].farOffset = totalFarSlots;
|
|
207
|
+
totalFarSlots += cells[i].lo.instanceMatrix.count;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
table.data = new Float32Array(tableWidth * Math.max(1, Math.ceil(totalFarSlots / tableWidth)));
|
|
212
|
+
if (!compact && cells.length) {
|
|
213
|
+
table.tex = new THREE.DataTexture(table.data, tableWidth, table.data.length / tableWidth, THREE.RedFormat, THREE.FloatType);
|
|
214
|
+
table.tex.needsUpdate = true;
|
|
215
|
+
shown.value = table.tex;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
cells.forEach((cell, slot) => {
|
|
219
|
+
lodOf(cell);
|
|
220
|
+
const lo = cell.lo,
|
|
74
221
|
key = [
|
|
75
222
|
lo.geometry.uuid,
|
|
76
223
|
lo.material.uuid,
|
|
77
224
|
lo.layers.mask,
|
|
78
225
|
lo.receiveShadow,
|
|
79
|
-
|
|
80
|
-
Math.floor(
|
|
81
|
-
Math.floor(
|
|
226
|
+
cell.mesh.castShadow,
|
|
227
|
+
Math.floor(cell.cx / square),
|
|
228
|
+
Math.floor(cell.cz / square),
|
|
82
229
|
].join('|');
|
|
83
|
-
let
|
|
84
|
-
if (!
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
230
|
+
let group = groups.get(key);
|
|
231
|
+
if (!group) groups.set(key, (group = { lo, casts: cell.mesh.castShadow, cells: [] }));
|
|
232
|
+
group.cells.push(cell);
|
|
233
|
+
cell.far = slot;
|
|
234
|
+
cell.farN = lo.instanceMatrix.count;
|
|
235
|
+
cell.lo = null;
|
|
89
236
|
lo.removeFromParent();
|
|
90
237
|
});
|
|
238
|
+
|
|
91
239
|
for (const { lo, casts, cells: list } of groups.values()) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (lo.instanceColor) mesh.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(n * 3), 3);
|
|
240
|
+
const instanceCount = list.reduce((total, cell) => total + cell.farN, 0),
|
|
241
|
+
geometry = new THREE.BufferGeometry();
|
|
242
|
+
for (const name in lo.geometry.attributes) geometry.setAttribute(name, lo.geometry.attributes[name]);
|
|
243
|
+
geometry.setIndex(lo.geometry.index);
|
|
244
|
+
geometry.boundingSphere = lo.geometry.boundingSphere;
|
|
245
|
+
geometry.boundingBox = lo.geometry.boundingBox;
|
|
246
|
+
const ids = compact ? null : new Float32Array(instanceCount * 2),
|
|
247
|
+
mesh = new THREE.InstancedMesh(geometry, compact ? lo.material : farMaterial(lo.material, materials), instanceCount);
|
|
248
|
+
if (lo.instanceColor) mesh.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(instanceCount * 3), 3);
|
|
102
249
|
let at = 0;
|
|
103
|
-
for (const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
250
|
+
for (const cell of list) {
|
|
251
|
+
const rec = lodOf(cell);
|
|
252
|
+
cell.farBatch = batches.length;
|
|
253
|
+
cell.farStart = at;
|
|
254
|
+
rec.batch = cell.farBatch;
|
|
255
|
+
const src = rec.sourceMatrix.array,
|
|
256
|
+
col = rec.sourceColor?.array;
|
|
257
|
+
mesh.instanceMatrix.array.set(src.subarray(0, cell.farN * 16), at * 16);
|
|
258
|
+
if (col && mesh.instanceColor) mesh.instanceColor.array.set(col.subarray(0, cell.farN * 3), at * 3);
|
|
259
|
+
if (ids) {
|
|
260
|
+
for (let i = 0; i < cell.farN; i++) {
|
|
261
|
+
ids[(at + i) * 2] = perInstanceTable ? cell.farOffset + i : cell.far;
|
|
262
|
+
ids[(at + i) * 2 + 1] = perInstanceTable ? 0.5 : i;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
at += cell.farN;
|
|
266
|
+
}
|
|
267
|
+
if (ids) geometry.setAttribute('aFar', new THREE.InstancedBufferAttribute(ids, 2));
|
|
268
|
+
if (compact) {
|
|
269
|
+
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
|
|
270
|
+
mesh.instanceColor?.setUsage(THREE.DynamicDrawUsage);
|
|
271
|
+
members.push(list);
|
|
272
|
+
}
|
|
115
273
|
mesh.layers.mask = lo.layers.mask;
|
|
116
274
|
mesh.receiveShadow = lo.receiveShadow;
|
|
117
275
|
mesh.castShadow = casts; // as the near copies do
|
|
@@ -119,66 +277,549 @@ export function createCellLod({ square = 500, tableWidth = 64, thinFrom = 0.45,
|
|
|
119
277
|
mesh.customDepthMaterial = depthMaterial();
|
|
120
278
|
if (!distanceMaterial) {
|
|
121
279
|
distanceMaterial = new THREE.MeshDistanceMaterial();
|
|
122
|
-
|
|
123
|
-
|
|
280
|
+
if (!compact) {
|
|
281
|
+
distanceMaterial.onBeforeCompile = hideUnshown;
|
|
282
|
+
distanceMaterial.customProgramCacheKey = () => 'far-batch-distance';
|
|
283
|
+
}
|
|
124
284
|
}
|
|
125
285
|
mesh.customDistanceMaterial = distanceMaterial;
|
|
126
|
-
mesh.userData.partShown = true;
|
|
286
|
+
mesh.userData.partShown = true;
|
|
127
287
|
}
|
|
128
288
|
mesh.matrixAutoUpdate = false;
|
|
129
289
|
mesh.computeBoundingSphere();
|
|
130
290
|
parent.add(mesh);
|
|
131
291
|
batches.push(mesh);
|
|
132
292
|
}
|
|
133
|
-
|
|
293
|
+
drawEnds = new Int32Array(batches.length);
|
|
294
|
+
if (compact) dirty = new Uint8Array(batches.length).fill(1);
|
|
295
|
+
|
|
296
|
+
// Build spatial billboard impostor batches for cells tagged with `cell.impostor`.
|
|
297
|
+
if (activeAtlas) {
|
|
298
|
+
const impSquares = new Map();
|
|
299
|
+
let maxTreeSpan = 16;
|
|
300
|
+
for (const s of activeAtlas.species) {
|
|
301
|
+
maxTreeSpan = Math.max(maxTreeSpan, s.height, s.width * s.crownWidthScale);
|
|
302
|
+
}
|
|
303
|
+
for (const cell of cellList) {
|
|
304
|
+
if (typeof cell.impostor !== 'number' || cell.impostor < 0) continue;
|
|
305
|
+
const rec = lodOf(cell);
|
|
306
|
+
rec.species = cell.impostor;
|
|
307
|
+
ensureInstanceMetadata(cell, rec);
|
|
308
|
+
if (cell.farN === undefined) cell.farN = rec.total;
|
|
309
|
+
const sqKey = `${Math.floor(rec.cx / impostorSquare)}:${Math.floor(rec.cz / impostorSquare)}`;
|
|
310
|
+
let group = impSquares.get(sqKey);
|
|
311
|
+
if (!group) impSquares.set(sqKey, (group = []));
|
|
312
|
+
group.push(cell);
|
|
313
|
+
}
|
|
314
|
+
if (impSquares.size) {
|
|
315
|
+
sharedImpostorMaterial ??= createTreeImpostorMaterial(activeAtlas);
|
|
316
|
+
for (const list of impSquares.values()) {
|
|
317
|
+
let capacity = 0,
|
|
318
|
+
minX = Infinity,
|
|
319
|
+
maxX = -Infinity,
|
|
320
|
+
minY = Infinity,
|
|
321
|
+
maxY = -Infinity,
|
|
322
|
+
minZ = Infinity,
|
|
323
|
+
maxZ = -Infinity;
|
|
324
|
+
for (const cell of list) {
|
|
325
|
+
const rec = cell.lod;
|
|
326
|
+
capacity += rec.total;
|
|
327
|
+
minX = Math.min(minX, rec.cx - rec.r);
|
|
328
|
+
maxX = Math.max(maxX, rec.cx + rec.r);
|
|
329
|
+
minY = Math.min(minY, rec.cy - rec.r);
|
|
330
|
+
maxY = Math.max(maxY, rec.cy + rec.r);
|
|
331
|
+
minZ = Math.min(minZ, rec.cz - rec.r);
|
|
332
|
+
maxZ = Math.max(maxZ, rec.cz + rec.r);
|
|
333
|
+
}
|
|
334
|
+
const center = new THREE.Vector3((minX + maxX) * 0.5, (minY + maxY) * 0.5, (minZ + maxZ) * 0.5),
|
|
335
|
+
radius = Math.hypot(maxX - minX, maxY - minY, maxZ - minZ) * 0.5 + maxTreeSpan * 2,
|
|
336
|
+
impBatch = createTreeImpostorBatch(activeAtlas, {
|
|
337
|
+
capacity,
|
|
338
|
+
material: sharedImpostorMaterial,
|
|
339
|
+
bounds: new THREE.Sphere(center, radius),
|
|
340
|
+
});
|
|
341
|
+
const impIndex = impostorBatches.length;
|
|
342
|
+
for (const cell of list) {
|
|
343
|
+
cell.impBatch = impIndex;
|
|
344
|
+
cell.lod.impBatch = impIndex;
|
|
345
|
+
}
|
|
346
|
+
parent.add(impBatch.mesh);
|
|
347
|
+
impostorBatches.push(impBatch);
|
|
348
|
+
impostorMembers.push(list);
|
|
349
|
+
}
|
|
350
|
+
impDirty = new Uint8Array(impostorBatches.length).fill(1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
134
354
|
return batches;
|
|
135
355
|
}
|
|
136
356
|
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
357
|
+
// Packs visible far instances of `batchIndex` from each cell's immutable `sourceMatrix` / `sourceColor`.
|
|
358
|
+
function packVisible(batchIndex) {
|
|
359
|
+
const mesh = batches[batchIndex],
|
|
360
|
+
dstMat = mesh.instanceMatrix.array,
|
|
361
|
+
dstCol = mesh.instanceColor?.array ?? null;
|
|
362
|
+
let end = 0;
|
|
363
|
+
for (const cell of members[batchIndex]) {
|
|
364
|
+
const rec = cell.lod;
|
|
365
|
+
if (!rec || !rec.farCount) continue;
|
|
366
|
+
const srcMat = rec.sourceMatrix.array,
|
|
367
|
+
srcCol = rec.sourceColor?.array ?? null;
|
|
368
|
+
if (rec.mode === MODE_ALL_FAR) {
|
|
369
|
+
const count = Math.min(rec.farCount, cell.farN);
|
|
370
|
+
dstMat.set(srcMat.subarray(0, count * 16), end * 16);
|
|
371
|
+
if (dstCol) {
|
|
372
|
+
if (srcCol) dstCol.set(srcCol.subarray(0, count * 3), end * 3);
|
|
373
|
+
else dstCol.fill(0, end * 3, (end + count) * 3);
|
|
374
|
+
}
|
|
375
|
+
end += count;
|
|
376
|
+
} else if (rec.mode === MODE_MIXED) {
|
|
377
|
+
const limit = Math.min(rec.activeLimit, cell.farN),
|
|
378
|
+
tiers = rec.tiers;
|
|
379
|
+
for (let k = 0; k < limit; k++) {
|
|
380
|
+
if (tiers[k] !== TIER_FAR) continue;
|
|
381
|
+
const mOff = k * 16,
|
|
382
|
+
dOff = end * 16;
|
|
383
|
+
for (let e = 0; e < 16; e++) dstMat[dOff + e] = srcMat[mOff + e];
|
|
384
|
+
if (dstCol) {
|
|
385
|
+
const cOff = k * 3,
|
|
386
|
+
dcOff = end * 3;
|
|
387
|
+
if (srcCol) {
|
|
388
|
+
dstCol[dcOff] = srcCol[cOff];
|
|
389
|
+
dstCol[dcOff + 1] = srcCol[cOff + 1];
|
|
390
|
+
dstCol[dcOff + 2] = srcCol[cOff + 2];
|
|
391
|
+
} else {
|
|
392
|
+
dstCol[dcOff] = dstCol[dcOff + 1] = dstCol[dcOff + 2] = 0;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
end++;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
mesh.count = end;
|
|
400
|
+
if (!end) return;
|
|
401
|
+
for (const attribute of [mesh.instanceMatrix, mesh.instanceColor]) {
|
|
402
|
+
if (!attribute) continue;
|
|
403
|
+
attribute.clearUpdateRanges();
|
|
404
|
+
attribute.addUpdateRange(0, end * attribute.itemSize);
|
|
405
|
+
attribute.needsUpdate = true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Packs visible billboard impostor instances of `impBatchIndex` from each member cell.
|
|
410
|
+
function packImpostorVisible(impBatchIndex) {
|
|
411
|
+
const impBatch = impostorBatches[impBatchIndex];
|
|
412
|
+
let end = 0;
|
|
413
|
+
for (const cell of impostorMembers[impBatchIndex]) {
|
|
414
|
+
const rec = cell.lod;
|
|
415
|
+
if (!rec || !rec.impCount) continue;
|
|
416
|
+
const srcMat = rec.sourceMatrix.array,
|
|
417
|
+
srcCol = rec.sourceColor?.array ?? null,
|
|
418
|
+
species = rec.species,
|
|
419
|
+
hashes = rec.hImp,
|
|
420
|
+
limit = rec.activeLimit;
|
|
421
|
+
if (rec.mode === MODE_ALL_IMPOSTOR) {
|
|
422
|
+
for (let k = 0; k < limit; k++) {
|
|
423
|
+
impBatch.setFromMatrix(end++, srcMat, k * 16, srcCol, k * 3, species, hashes[k]);
|
|
424
|
+
}
|
|
425
|
+
} else if (rec.mode === MODE_MIXED) {
|
|
426
|
+
const tiers = rec.tiers;
|
|
427
|
+
for (let k = 0; k < limit; k++) {
|
|
428
|
+
if (tiers[k] !== TIER_IMPOSTOR) continue;
|
|
429
|
+
impBatch.setFromMatrix(end++, srcMat, k * 16, srcCol, k * 3, species, hashes[k]);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
impBatch.commit(end);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Updates `cell.mesh` (and optional unbatched `cell.lo`) when `rec` uses per-instance hashed handovers.
|
|
437
|
+
function syncUnbatchedMeshes(cell, rec, limit, nearChanged, farChanged) {
|
|
438
|
+
if (rec.nearCount === 0) {
|
|
439
|
+
if (cell.mesh.instanceMatrix !== rec.sourceMatrix) {
|
|
440
|
+
cell.mesh.instanceMatrix = rec.sourceMatrix;
|
|
441
|
+
if (rec.sourceColor) cell.mesh.instanceColor = rec.sourceColor;
|
|
442
|
+
}
|
|
443
|
+
cell.mesh.count = limit;
|
|
444
|
+
cell.mesh.visible = false;
|
|
445
|
+
} else if (rec.nearCount === limit && rec.mode !== MODE_MIXED) {
|
|
446
|
+
if (cell.mesh.instanceMatrix !== rec.sourceMatrix) {
|
|
447
|
+
cell.mesh.instanceMatrix = rec.sourceMatrix;
|
|
448
|
+
if (rec.sourceColor) cell.mesh.instanceColor = rec.sourceColor;
|
|
449
|
+
}
|
|
450
|
+
cell.mesh.count = limit;
|
|
451
|
+
cell.mesh.visible = true;
|
|
452
|
+
} else {
|
|
453
|
+
if (!rec.nearMatrix) {
|
|
454
|
+
rec.nearMatrix = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 16), 16).setUsage(THREE.DynamicDrawUsage);
|
|
455
|
+
if (rec.sourceColor) {
|
|
456
|
+
rec.nearColor = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 3), 3).setUsage(THREE.DynamicDrawUsage);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (nearChanged || cell.mesh.instanceMatrix !== rec.nearMatrix) {
|
|
460
|
+
const srcMat = rec.sourceMatrix.array,
|
|
461
|
+
srcCol = rec.sourceColor?.array ?? null,
|
|
462
|
+
dstMat = rec.nearMatrix.array,
|
|
463
|
+
dstCol = rec.nearColor?.array ?? null,
|
|
464
|
+
tiers = rec.tiers;
|
|
465
|
+
let out = 0;
|
|
466
|
+
for (let k = 0; k < limit; k++) {
|
|
467
|
+
if (tiers[k] !== TIER_NEAR) continue;
|
|
468
|
+
const mOff = k * 16,
|
|
469
|
+
dOff = out * 16;
|
|
470
|
+
for (let e = 0; e < 16; e++) dstMat[dOff + e] = srcMat[mOff + e];
|
|
471
|
+
if (dstCol && srcCol) {
|
|
472
|
+
dstCol[out * 3] = srcCol[k * 3];
|
|
473
|
+
dstCol[out * 3 + 1] = srcCol[k * 3 + 1];
|
|
474
|
+
dstCol[out * 3 + 2] = srcCol[k * 3 + 2];
|
|
475
|
+
}
|
|
476
|
+
out++;
|
|
477
|
+
}
|
|
478
|
+
rec.nearMatrix.clearUpdateRanges();
|
|
479
|
+
rec.nearMatrix.addUpdateRange(0, out * 16);
|
|
480
|
+
rec.nearMatrix.needsUpdate = true;
|
|
481
|
+
if (rec.nearColor) {
|
|
482
|
+
rec.nearColor.clearUpdateRanges();
|
|
483
|
+
rec.nearColor.addUpdateRange(0, out * 3);
|
|
484
|
+
rec.nearColor.needsUpdate = true;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
cell.mesh.instanceMatrix = rec.nearMatrix;
|
|
488
|
+
if (rec.nearColor) cell.mesh.instanceColor = rec.nearColor;
|
|
489
|
+
cell.mesh.count = rec.nearCount;
|
|
490
|
+
cell.mesh.visible = true;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (cell.lo) {
|
|
494
|
+
if (!cell.lo.instanceMatrix) {
|
|
495
|
+
// A far object that is not instanced cannot show a chosen share of the copies: its near mesh shows them all.
|
|
496
|
+
cell.lo.visible = false;
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (rec.farCount === 0) {
|
|
500
|
+
cell.lo.visible = false;
|
|
501
|
+
} else if (rec.farCount === limit && rec.mode === MODE_ALL_FAR) {
|
|
502
|
+
if (cell.lo.instanceMatrix !== rec.sourceMatrix) {
|
|
503
|
+
cell.lo.instanceMatrix = rec.sourceMatrix;
|
|
504
|
+
if (rec.sourceColor) cell.lo.instanceColor = rec.sourceColor;
|
|
505
|
+
}
|
|
506
|
+
cell.lo.count = limit;
|
|
507
|
+
cell.lo.visible = true;
|
|
508
|
+
} else {
|
|
509
|
+
if (!rec.loMatrix) {
|
|
510
|
+
rec.loMatrix = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 16), 16).setUsage(THREE.DynamicDrawUsage);
|
|
511
|
+
if (rec.sourceColor) {
|
|
512
|
+
rec.loColor = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 3), 3).setUsage(THREE.DynamicDrawUsage);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (farChanged || cell.lo.instanceMatrix !== rec.loMatrix) {
|
|
516
|
+
const srcMat = rec.sourceMatrix.array,
|
|
517
|
+
srcCol = rec.sourceColor?.array ?? null,
|
|
518
|
+
dstMat = rec.loMatrix.array,
|
|
519
|
+
dstCol = rec.loColor?.array ?? null,
|
|
520
|
+
tiers = rec.tiers;
|
|
521
|
+
let out = 0;
|
|
522
|
+
for (let k = 0; k < limit; k++) {
|
|
523
|
+
if (tiers[k] !== TIER_FAR) continue;
|
|
524
|
+
const mOff = k * 16,
|
|
525
|
+
dOff = out * 16;
|
|
526
|
+
for (let e = 0; e < 16; e++) dstMat[dOff + e] = srcMat[mOff + e];
|
|
527
|
+
if (dstCol && srcCol) {
|
|
528
|
+
dstCol[out * 3] = srcCol[k * 3];
|
|
529
|
+
dstCol[out * 3 + 1] = srcCol[k * 3 + 1];
|
|
530
|
+
dstCol[out * 3 + 2] = srcCol[k * 3 + 2];
|
|
531
|
+
}
|
|
532
|
+
out++;
|
|
533
|
+
}
|
|
534
|
+
rec.loMatrix.clearUpdateRanges();
|
|
535
|
+
rec.loMatrix.addUpdateRange(0, out * 16);
|
|
536
|
+
rec.loMatrix.needsUpdate = true;
|
|
537
|
+
if (rec.loColor) {
|
|
538
|
+
rec.loColor.clearUpdateRanges();
|
|
539
|
+
rec.loColor.addUpdateRange(0, out * 3);
|
|
540
|
+
rec.loColor.needsUpdate = true;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
cell.lo.instanceMatrix = rec.loMatrix;
|
|
544
|
+
if (rec.loColor) cell.lo.instanceColor = rec.loColor;
|
|
545
|
+
cell.lo.count = rec.farCount;
|
|
546
|
+
cell.lo.visible = true;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
141
550
|
|
|
142
551
|
/**
|
|
143
|
-
* Each frame: near cells show their detailed mesh, far ones their batched copy
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
552
|
+
* Each frame: near cells show their detailed mesh, far ones their batched copy (and optional billboard impostors beyond).
|
|
553
|
+
*
|
|
554
|
+
* @param {Array<object>} cells Cell list.
|
|
555
|
+
* @param {number} cx Camera world X.
|
|
556
|
+
* @param {number} cz Camera world Z.
|
|
557
|
+
* @param {number} distance Metres past which standard cells are culled.
|
|
558
|
+
* @param {number} detail Metres within which the detailed `near` mesh is drawn.
|
|
559
|
+
* @param {number} density Share of instances kept (`0..1`).
|
|
560
|
+
* @param {number} [cy] Optional camera world Y to include altitude in the `near -> far` distance.
|
|
561
|
+
* @param {number} [rangeScale=1] Quality multiplier scaling all thresholds and cell radii.
|
|
562
|
+
* @param {object} [updateOptions]
|
|
563
|
+
* @param {number} [updateOptions.lensScale=1] Perspective magnification (`detailLens(camera, refFov)`) scaling LOD handover distances.
|
|
564
|
+
* @param {boolean} [updateOptions.holdHandover=false] When `true`, locks active LOD tiers during a held scene shot until the next cut.
|
|
565
|
+
* @param {number} [updateOptions.farDistance] Metres at which impostor-enabled cells hand over `far -> impostor` (defaults to `distance * 0.3`).
|
|
566
|
+
* @param {number} [updateOptions.impostorDistance] Metres past which impostor-enabled cells cull (defaults to `distance * 2.2`).
|
|
147
567
|
*/
|
|
148
|
-
function update(cells, cx, cz, distance, detail, density, cy, rangeScale = 1) {
|
|
568
|
+
function update(cells, cx, cz, distance, detail, density, cy, rangeScale = 1, updateOptions) {
|
|
569
|
+
const lensScale = Math.max(0.25, updateOptions?.lensScale ?? 1),
|
|
570
|
+
holdHandover = Boolean(updateOptions?.holdHandover);
|
|
571
|
+
if (sharedImpostorMaterial) {
|
|
572
|
+
sharedImpostorMaterial.userData.impostorUniforms.uImpLens.value.x = 1 / lensScale;
|
|
573
|
+
}
|
|
574
|
+
if (holdHandover && hasSnapshot) return;
|
|
575
|
+
|
|
149
576
|
let changed = false;
|
|
150
|
-
if (
|
|
577
|
+
if (drawEnds) drawEnds.fill(0);
|
|
578
|
+
const hasOptions = updateOptions !== undefined,
|
|
579
|
+
baseFarToImp = updateOptions?.farDistance ?? distance * farDistanceShare,
|
|
580
|
+
baseImpMax = updateOptions?.impostorDistance ?? distance * impostorDistanceShare,
|
|
581
|
+
impLensBoost = Math.max(1, Math.min(lensScale, impostorLensCap));
|
|
582
|
+
|
|
151
583
|
for (let i = 0; i < cells.length; i++) {
|
|
152
|
-
const
|
|
153
|
-
at = lodOf(
|
|
584
|
+
const cell = cells[i],
|
|
585
|
+
at = lodOf(cell),
|
|
154
586
|
dx = cx - at.cx,
|
|
155
587
|
dz = cz - at.cz,
|
|
156
588
|
horizontalSq = dx * dx + dz * dz,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
589
|
+
rawHorizDist = Math.sqrt(horizontalSq),
|
|
590
|
+
detailDistance = rawHorizDist / rangeScale - at.r,
|
|
591
|
+
hasFar = cell.far !== undefined || Boolean(cell.lo?.instanceMatrix),
|
|
592
|
+
hasImp = at.impBatch >= 0 && at.species >= 0;
|
|
593
|
+
|
|
594
|
+
if (!at.sourceMatrix) {
|
|
595
|
+
// A whole object (a group or one mesh on its own): shown while it is within range, as it always was.
|
|
596
|
+
const maxDist = Math.min(distance * (lensScale > 1 ? Math.min(lensScale, impostorLensCap) : 1), at.until);
|
|
597
|
+
cell.mesh.visible = detailDistance < maxDist;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Preserve 100% identical behaviour for non-jittered, non-impostor cells.
|
|
602
|
+
if (!hasImp && jitter === 0) {
|
|
603
|
+
const maxDist = Math.min(distance * (lensScale > 1 ? Math.min(lensScale, impostorLensCap) : 1), at.until),
|
|
604
|
+
vis = detailDistance < maxDist,
|
|
605
|
+
nearDistance = cy === undefined ? detailDistance : Math.sqrt(horizontalSq + (cy - at.cy) ** 2) / rangeScale - at.r,
|
|
606
|
+
nearThreshold = Math.min(detail, at.near) * lensScale,
|
|
607
|
+
hi = !hasFar || nearDistance < nearThreshold;
|
|
608
|
+
cell.mesh.visible = vis && hi;
|
|
609
|
+
if (cell.lo) cell.lo.visible = vis && !hi;
|
|
610
|
+
let count = cell.farN ?? at.total;
|
|
611
|
+
if (cell.full !== undefined) {
|
|
612
|
+
count = Math.max(1, (cell.full * (detailDistance < distance * thinFrom ? 1 : thinTo) * density) | 0);
|
|
613
|
+
cell.mesh.count = count;
|
|
614
|
+
if (cell.lo) cell.lo.count = count;
|
|
615
|
+
}
|
|
616
|
+
if (cell.far !== undefined) {
|
|
617
|
+
const v = vis && !hi ? count : 0;
|
|
618
|
+
at.farCount = v;
|
|
619
|
+
at.mode = v > 0 ? MODE_ALL_FAR : MODE_NONE;
|
|
620
|
+
if (v > 0) drawEnds[at.batch] = Math.max(drawEnds[at.batch], cell.farStart + Math.min(cell.farN, v));
|
|
621
|
+
if (!perInstanceTable) {
|
|
622
|
+
if (table.data[cell.far] !== v) {
|
|
623
|
+
table.data[cell.far] = v;
|
|
624
|
+
if (compact) dirty[at.batch] = 1;
|
|
625
|
+
changed = true;
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
const limit = Math.min(cell.farN, v);
|
|
629
|
+
for (let k = 0; k < cell.farN; k++) {
|
|
630
|
+
const show = k < limit ? 1 : 0,
|
|
631
|
+
tIdx = cell.farOffset + k;
|
|
632
|
+
if (table.data[tIdx] !== show) {
|
|
633
|
+
table.data[tIdx] = show;
|
|
634
|
+
changed = true;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
176
638
|
}
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// Per-instance hashed handover path (`near -> far -> impostor`).
|
|
643
|
+
ensureInstanceMetadata(cell, at);
|
|
644
|
+
const total = at.total,
|
|
645
|
+
// Impostors cost 2 triangles each, so impostor-backed forest cells keep full canopy density unless thinImpostors is set.
|
|
646
|
+
thinShare = (!hasImp || thinImpostors) && cell.full !== undefined && detailDistance >= distance * thinFrom ? thinTo : 1,
|
|
647
|
+
limit = cell.full !== undefined ? Math.max(1, Math.min(total, (cell.full * thinShare * density) | 0)) : total;
|
|
648
|
+
|
|
649
|
+
const worldNearEdge = Math.min(detail, at.near) * lensScale * rangeScale,
|
|
650
|
+
worldFarEdge = (hasImp ? baseFarToImp * lensScale : Math.min(distance * Math.max(1, lensScale), at.until)) * rangeScale,
|
|
651
|
+
worldImpEdge = (hasImp ? Math.min(baseImpMax * impLensBoost, at.until) : worldFarEdge) * rangeScale,
|
|
652
|
+
effJitter = jitter > 0 ? jitter : defaultJitter,
|
|
653
|
+
nearMin = worldNearEdge > 0 ? worldNearEdge * (1 - effJitter) - nearHysteresis * lensScale : -Infinity,
|
|
654
|
+
nearMax = worldNearEdge > 0 ? worldNearEdge * (1 + effJitter) + nearHysteresis * lensScale : -Infinity,
|
|
655
|
+
farMin = hasFar ? worldFarEdge * (1 - effJitter) - farHysteresis * lensScale : nearMin,
|
|
656
|
+
farMax = hasFar ? worldFarEdge * (1 + effJitter) + farHysteresis * lensScale : nearMax,
|
|
657
|
+
impMin = hasImp ? worldImpEdge * (1 - effJitter * 0.5) - impostorHysteresis : farMin,
|
|
658
|
+
impMax = hasImp ? worldImpEdge * (1 + effJitter * 0.5) + impostorHysteresis : farMax;
|
|
659
|
+
|
|
660
|
+
const cellDist3D = cy === undefined ? rawHorizDist : Math.sqrt(horizontalSq + (cy - at.cy) ** 2),
|
|
661
|
+
prevMode = at.mode,
|
|
662
|
+
prevNear = at.nearCount,
|
|
663
|
+
prevFar = at.farCount,
|
|
664
|
+
prevImp = at.impCount,
|
|
665
|
+
prevLimit = at.activeLimit;
|
|
666
|
+
|
|
667
|
+
let nextMode = MODE_NONE,
|
|
668
|
+
nearCount = 0,
|
|
669
|
+
farCount = 0,
|
|
670
|
+
impCount = 0,
|
|
671
|
+
nearChanged = prevLimit !== limit,
|
|
672
|
+
farChanged = prevLimit !== limit,
|
|
673
|
+
impChanged = prevLimit !== limit;
|
|
674
|
+
|
|
675
|
+
if (rawHorizDist - at.r > impMax) {
|
|
676
|
+
// Entire cell lies past outer visibility range.
|
|
677
|
+
nextMode = MODE_NONE;
|
|
678
|
+
if (prevMode !== MODE_NONE) {
|
|
679
|
+
at.tiers.fill(TIER_HIDDEN, 0, limit);
|
|
680
|
+
nearChanged = prevNear > 0;
|
|
681
|
+
farChanged = prevFar > 0;
|
|
682
|
+
impChanged = prevImp > 0;
|
|
683
|
+
}
|
|
684
|
+
} else if ((!hasFar && !hasImp) || (worldNearEdge > 0 && cellDist3D + at.r < nearMin)) {
|
|
685
|
+
// Entire cell is strictly within `near`.
|
|
686
|
+
nextMode = MODE_NONE;
|
|
687
|
+
nearCount = limit;
|
|
688
|
+
if (prevNear !== limit || prevMode !== MODE_NONE) {
|
|
689
|
+
at.tiers.fill(TIER_NEAR, 0, limit);
|
|
690
|
+
nearChanged = true;
|
|
691
|
+
farChanged = prevFar > 0;
|
|
692
|
+
impChanged = prevImp > 0;
|
|
693
|
+
}
|
|
694
|
+
} else if (hasFar && cellDist3D - at.r > nearMax && rawHorizDist + at.r < farMin) {
|
|
695
|
+
// Entire cell is strictly within `far`.
|
|
696
|
+
nextMode = MODE_ALL_FAR;
|
|
697
|
+
farCount = limit;
|
|
698
|
+
if (prevMode !== MODE_ALL_FAR || prevFar !== limit) {
|
|
699
|
+
at.tiers.fill(TIER_FAR, 0, limit);
|
|
700
|
+
nearChanged = prevNear > 0;
|
|
701
|
+
farChanged = true;
|
|
702
|
+
impChanged = prevImp > 0;
|
|
703
|
+
}
|
|
704
|
+
} else if (hasImp && (hasFar ? rawHorizDist - at.r > farMax : cellDist3D - at.r > nearMax) && rawHorizDist + at.r < impMin) {
|
|
705
|
+
// Entire cell is strictly within `impostor`.
|
|
706
|
+
nextMode = MODE_ALL_IMPOSTOR;
|
|
707
|
+
impCount = limit;
|
|
708
|
+
if (prevMode !== MODE_ALL_IMPOSTOR || prevImp !== limit) {
|
|
709
|
+
at.tiers.fill(TIER_IMPOSTOR, 0, limit);
|
|
710
|
+
nearChanged = prevNear > 0;
|
|
711
|
+
farChanged = prevFar > 0;
|
|
712
|
+
impChanged = true;
|
|
713
|
+
}
|
|
714
|
+
} else {
|
|
715
|
+
// Straddling cell: evaluate each instance against its own hashed handover distances with hysteresis.
|
|
716
|
+
nextMode = MODE_MIXED;
|
|
717
|
+
const px = at.px,
|
|
718
|
+
py = at.py,
|
|
719
|
+
pz = at.pz,
|
|
720
|
+
hNear = at.hNear,
|
|
721
|
+
hFar = at.hFar,
|
|
722
|
+
hImp = at.hImp,
|
|
723
|
+
tiers = at.tiers,
|
|
724
|
+
nearHyst = nearHysteresis * lensScale,
|
|
725
|
+
farHyst = farHysteresis * lensScale;
|
|
726
|
+
|
|
727
|
+
for (let k = 0; k < limit; k++) {
|
|
728
|
+
const ix = cx - px[k],
|
|
729
|
+
iz = cz - pz[k],
|
|
730
|
+
d2Sq = ix * ix + iz * iz,
|
|
731
|
+
d3Sq = cy === undefined ? d2Sq : d2Sq + (cy - py[k]) * (cy - py[k]),
|
|
732
|
+
was = tiers[k];
|
|
733
|
+
|
|
734
|
+
let tier = TIER_HIDDEN;
|
|
735
|
+
if (worldNearEdge > 0) {
|
|
736
|
+
const myNear = worldNearEdge * (1 + effJitter * (2 * hNear[k] - 1)) + (was === TIER_NEAR ? nearHyst : -nearHyst);
|
|
737
|
+
if (myNear > 0 && d3Sq < myNear * myNear) tier = TIER_NEAR;
|
|
738
|
+
}
|
|
739
|
+
if (tier === TIER_HIDDEN && hasFar) {
|
|
740
|
+
const myFar = worldFarEdge * (1 + effJitter * (2 * hFar[k] - 1)) + (was === TIER_FAR ? farHyst : -farHyst);
|
|
741
|
+
if (myFar > 0 && d2Sq < myFar * myFar) tier = TIER_FAR;
|
|
742
|
+
}
|
|
743
|
+
if (tier === TIER_HIDDEN && hasImp) {
|
|
744
|
+
const myImp =
|
|
745
|
+
worldImpEdge * (1 + effJitter * 0.5 * (2 * hImp[k] - 1)) + (was === TIER_IMPOSTOR ? impostorHysteresis : -impostorHysteresis);
|
|
746
|
+
if (myImp > 0 && d2Sq < myImp * myImp) tier = TIER_IMPOSTOR;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (tier !== was) {
|
|
750
|
+
tiers[k] = tier;
|
|
751
|
+
if (was === TIER_NEAR || tier === TIER_NEAR) nearChanged = true;
|
|
752
|
+
if (was === TIER_FAR || tier === TIER_FAR) farChanged = true;
|
|
753
|
+
if (was === TIER_IMPOSTOR || tier === TIER_IMPOSTOR) impChanged = true;
|
|
754
|
+
}
|
|
755
|
+
if (tier === TIER_NEAR) nearCount++;
|
|
756
|
+
else if (tier === TIER_FAR) farCount++;
|
|
757
|
+
else if (tier === TIER_IMPOSTOR) impCount++;
|
|
758
|
+
}
|
|
759
|
+
if (farCount === limit) nextMode = MODE_ALL_FAR;
|
|
760
|
+
else if (impCount === limit) nextMode = MODE_ALL_IMPOSTOR;
|
|
761
|
+
else if (nearCount === limit || (nearCount === 0 && farCount === 0 && impCount === 0)) nextMode = MODE_NONE;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
at.mode = nextMode;
|
|
765
|
+
at.activeLimit = limit;
|
|
766
|
+
at.nearCount = nearCount;
|
|
767
|
+
at.farCount = farCount;
|
|
768
|
+
at.impCount = impCount;
|
|
769
|
+
|
|
770
|
+
syncUnbatchedMeshes(cell, at, limit, nearChanged, farChanged);
|
|
771
|
+
|
|
772
|
+
if (cell.far !== undefined) {
|
|
773
|
+
if (farCount > 0) drawEnds[at.batch] = Math.max(drawEnds[at.batch], cell.farStart + Math.min(cell.farN, limit));
|
|
774
|
+
if (compact) {
|
|
775
|
+
if (farChanged || prevMode !== nextMode) dirty[at.batch] = 1;
|
|
776
|
+
} else if (perInstanceTable) {
|
|
777
|
+
const tiers = at.tiers,
|
|
778
|
+
cap = Math.min(cell.farN, limit);
|
|
779
|
+
for (let k = 0; k < cell.farN; k++) {
|
|
780
|
+
const show = k < cap && (nextMode === MODE_ALL_FAR || tiers[k] === TIER_FAR) ? 1 : 0,
|
|
781
|
+
tIdx = cell.farOffset + k;
|
|
782
|
+
if (table.data[tIdx] !== show) {
|
|
783
|
+
table.data[tIdx] = show;
|
|
784
|
+
changed = true;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (hasImp && (impChanged || prevMode !== nextMode)) {
|
|
791
|
+
impDirty[at.impBatch] = 1;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
void hasOptions;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
if (changed && table.tex) table.tex.needsUpdate = true;
|
|
798
|
+
for (let i = 0; i < batches.length; i++) {
|
|
799
|
+
if (!compact) {
|
|
800
|
+
batches[i].count = drawEnds[i];
|
|
801
|
+
batches[i].visible = drawEnds[i] > 0;
|
|
802
|
+
} else {
|
|
803
|
+
if (dirty[i]) {
|
|
804
|
+
packVisible(i);
|
|
805
|
+
dirty[i] = 0;
|
|
806
|
+
}
|
|
807
|
+
batches[i].visible = batches[i].count > 0;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
for (let i = 0; i < impostorBatches.length; i++) {
|
|
811
|
+
if (impDirty[i]) {
|
|
812
|
+
packImpostorVisible(i);
|
|
813
|
+
impDirty[i] = 0;
|
|
177
814
|
}
|
|
178
815
|
}
|
|
179
|
-
|
|
180
|
-
|
|
816
|
+
hasSnapshot = true;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** Clears held handover state so the next `update` recomputes immediately even if `holdHandover` is set. */
|
|
820
|
+
function resetHandover() {
|
|
821
|
+
hasSnapshot = false;
|
|
181
822
|
}
|
|
182
823
|
|
|
183
|
-
return { batch, update, batches };
|
|
824
|
+
return { batch, update, batches, impostorBatches, resetHandover };
|
|
184
825
|
}
|