roamwright 0.20.1 → 0.55.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.yaml +12 -0
- package/CONTRIBUTING.md +19 -14
- package/README.md +35 -16
- package/examples/animals.html +49 -0
- package/examples/animals.js +209 -0
- package/examples/crowds.html +50 -0
- package/examples/crowds.js +268 -0
- package/examples/effects.html +53 -0
- package/examples/effects.js +343 -0
- package/examples/figure-motion.html +55 -0
- package/examples/figure-motion.js +265 -0
- package/examples/figure.html +49 -0
- package/examples/figure.js +238 -0
- package/examples/fliers.html +53 -0
- package/examples/fliers.js +292 -0
- package/examples/fortification.html +54 -0
- package/examples/fortification.js +288 -0
- package/examples/house-kit.html +48 -0
- package/examples/house-kit.js +175 -0
- package/examples/index.html +26 -16
- package/examples/island.html +48 -0
- package/examples/island.js +134 -52
- package/examples/land.html +54 -0
- package/examples/land.js +392 -0
- package/examples/props-and-plants.html +53 -0
- package/examples/props-and-plants.js +275 -0
- package/examples/rooms.html +48 -0
- package/examples/rooms.js +242 -0
- package/examples/ships.html +51 -0
- package/examples/ships.js +235 -0
- package/examples/showcase.css +320 -0
- package/examples/small-world-land.js +151 -0
- package/examples/small-world-life.js +160 -0
- package/examples/small-world-town.js +127 -0
- package/examples/small-world.html +57 -0
- package/examples/small-world.js +226 -0
- package/examples/soundscape.html +138 -0
- package/examples/soundscape.js +467 -0
- package/examples/stage-kits.js +300 -0
- package/examples/stage.js +374 -0
- package/examples/towns.html +50 -0
- package/examples/towns.js +325 -0
- package/examples/viaduct-camera.js +8 -4
- package/examples/viaduct-landscape.js +28 -17
- package/examples/viaduct.html +45 -43
- package/examples/viaduct.js +68 -92
- package/geometry/animal-camel-body.js +410 -0
- package/geometry/animal-camel-head.js +118 -0
- package/geometry/animal-canine-body.js +361 -0
- package/geometry/animal-canine-breeds.js +316 -0
- package/geometry/animal-canine-head.js +337 -0
- package/geometry/animal-cattle-body.js +391 -0
- package/geometry/animal-cattle-coat.js +42 -0
- package/geometry/animal-cattle-head.js +152 -0
- package/geometry/animal-hen.js +248 -0
- package/geometry/animal-horse-body.js +446 -0
- package/geometry/animal-horse-bridle.js +171 -0
- package/geometry/animal-horse-coat.js +68 -0
- package/geometry/animal-horse-face.js +162 -0
- package/geometry/animal-horse-hair.js +304 -0
- package/geometry/animal-horse-head.js +133 -0
- package/geometry/animal-horse-tack.js +157 -0
- package/geometry/animal-options.js +59 -0
- package/geometry/animal-shapes.js +21 -0
- package/geometry/animal-skin.js +390 -0
- package/geometry/builder-cells.js +10 -2
- package/geometry/builder-frame.js +2 -1
- package/geometry/builder.js +15 -4
- package/geometry/card-emblem.js +437 -0
- package/geometry/catenary-canvas.js +396 -0
- package/geometry/cloth-folds.js +143 -0
- package/geometry/crawl-shapes.js +71 -0
- package/geometry/creased-sheet.js +7 -2
- package/geometry/crowd-dress.js +315 -0
- package/geometry/crowd-far.js +174 -0
- package/geometry/crowd-look.js +42 -0
- package/geometry/crowd-weld.js +218 -0
- package/geometry/ear.js +9 -4
- package/geometry/erosion.js +7 -4
- package/geometry/face-grid.js +26 -6
- package/geometry/field-map.js +59 -0
- package/geometry/figure-arms.js +339 -0
- package/geometry/figure-beard.js +250 -0
- package/geometry/figure-body.js +297 -0
- package/geometry/figure-bow.js +105 -0
- package/geometry/figure-cloak.js +189 -0
- package/geometry/figure-clothes.js +337 -0
- package/geometry/figure-face-grids.js +75 -0
- package/geometry/figure-gear.js +446 -0
- package/geometry/figure-hair-far.js +151 -0
- package/geometry/figure-hair-hangs.js +108 -0
- package/geometry/figure-hair-patch.js +66 -0
- package/geometry/figure-hair.js +320 -0
- package/geometry/figure-hands.js +321 -0
- package/geometry/figure-head-features.js +280 -0
- package/geometry/figure-head.js +375 -0
- package/geometry/figure-headwear.js +223 -0
- package/geometry/figure-legs.js +231 -0
- package/geometry/figure-limbs.js +39 -0
- package/geometry/figure-sculpt.js +82 -0
- package/geometry/figure-skin.js +97 -0
- package/geometry/figure-skirts.js +303 -0
- package/geometry/figure-trunk.js +411 -0
- package/geometry/flier-corvid-body.js +322 -0
- package/geometry/flier-corvid-wings.js +154 -0
- package/geometry/flier-long-body.js +195 -0
- package/geometry/flier-shapes.js +219 -0
- package/geometry/flier-soaring-bird.js +84 -0
- package/geometry/foliage.js +177 -4
- package/geometry/fort-city-walls.js +479 -0
- package/geometry/fort-gate-approach.js +233 -0
- package/geometry/fort-great-walls.js +280 -0
- package/geometry/fort-keep.js +297 -0
- package/geometry/fort-parts.js +261 -0
- package/geometry/fort-polyline.js +261 -0
- package/geometry/fort-portal.js +96 -0
- package/geometry/fort-ring-wall.js +267 -0
- package/geometry/fort-seawall.js +104 -0
- package/geometry/fort-terrace-gates.js +323 -0
- package/geometry/fort-terrace-plan.js +250 -0
- package/geometry/fort-terrace-wall.js +345 -0
- package/geometry/garment-tags.js +11 -3
- package/geometry/grid-gather.js +69 -0
- package/geometry/grid-sample.js +185 -0
- package/geometry/hair-gathers.js +19 -4
- package/geometry/hair-locks.js +1 -1
- package/geometry/hair-patch.js +6 -2
- package/geometry/hair-shell.js +14 -2
- package/geometry/head-presets.js +103 -0
- package/geometry/head-profile.js +13 -2
- package/geometry/head-shape.js +51 -23
- package/geometry/heightfield.js +26 -9
- package/geometry/horizon-angles.js +166 -0
- package/geometry/house-kit-body.js +195 -0
- package/geometry/house-kit-courtyard-parts.js +340 -0
- package/geometry/house-kit-courtyard-roof.js +223 -0
- package/geometry/house-kit-courtyard.js +409 -0
- package/geometry/house-kit-cut.js +29 -0
- package/geometry/house-kit-extras.js +192 -0
- package/geometry/house-kit-forms.js +298 -0
- package/geometry/house-kit-frame.js +74 -0
- package/geometry/house-kit-marks.js +93 -0
- package/geometry/house-kit-openings.js +193 -0
- package/geometry/house-kit-palette.js +54 -0
- package/geometry/house-kit-pool.js +71 -0
- package/geometry/house-kit-roofs.js +151 -0
- package/geometry/house-kit.js +202 -0
- package/geometry/instances.js +4 -4
- package/geometry/lamp-wash.js +65 -0
- package/geometry/land-clearings.js +83 -0
- package/geometry/land-ditches.js +290 -0
- package/geometry/land-dry-basin.js +327 -0
- package/geometry/land-dunes.js +150 -0
- package/geometry/land-earthworks.js +432 -0
- package/geometry/land-edge.js +292 -0
- package/geometry/land-mound-faces.js +349 -0
- package/geometry/land-near-relief.js +102 -0
- package/geometry/land-sheet.js +220 -0
- package/geometry/land-town-ground.js +256 -0
- package/geometry/land-waters.js +228 -0
- package/geometry/land-wildness.js +123 -0
- package/geometry/lathed-vessel.js +293 -0
- package/geometry/outline-grid.js +5 -4
- package/geometry/outline-segments.js +74 -0
- package/geometry/part-ranges.js +35 -0
- package/geometry/path-field.js +35 -1
- package/geometry/planked-floor.js +149 -0
- package/geometry/plant-broadleaf.js +268 -0
- package/geometry/plant-shrub.js +198 -0
- package/geometry/plant-tints.js +80 -0
- package/geometry/plant-trees.js +453 -0
- package/geometry/plant-tussock.js +107 -0
- package/geometry/primitives.js +65 -23
- package/geometry/prop-battlefield.js +69 -0
- package/geometry/prop-camp.js +175 -0
- package/geometry/prop-door.js +26 -0
- package/geometry/prop-harbour.js +105 -0
- package/geometry/prop-haycock.js +60 -0
- package/geometry/prop-sacks.js +74 -0
- package/geometry/prop-sheaf.js +68 -0
- package/geometry/prop-street.js +69 -0
- package/geometry/prop-tents.js +396 -0
- package/geometry/prop-tombs.js +80 -0
- package/geometry/prop-trade.js +393 -0
- package/geometry/prop-vehicles.js +218 -0
- package/geometry/props.js +58 -0
- package/geometry/room-arcade.js +134 -0
- package/geometry/room-dome.js +188 -0
- package/geometry/room-flames.js +138 -0
- package/geometry/room-frame.js +106 -0
- package/geometry/room-furniture.js +260 -0
- package/geometry/room-hearth.js +98 -0
- package/geometry/room-kit.js +59 -0
- package/geometry/room-openings.js +142 -0
- package/geometry/room-stairs.js +180 -0
- package/geometry/room-surfaces.js +272 -0
- package/geometry/sampled-surface.js +24 -10
- package/geometry/scatter-grid.js +6 -3
- package/geometry/sculpt.js +5 -1
- package/geometry/ship-fittings.js +350 -0
- package/geometry/ship-hull.js +460 -0
- package/geometry/ship-kit.js +208 -0
- package/geometry/ship-lines.js +69 -0
- package/geometry/ship-oars.js +150 -0
- package/geometry/ship-presets.js +131 -0
- package/geometry/ship-rig.js +374 -0
- package/geometry/ship-sails.js +148 -0
- package/geometry/shore-grid.js +5 -1
- package/geometry/strata-field.js +44 -11
- package/geometry/strata-tiles.js +20 -6
- package/geometry/stream.js +32 -17
- package/geometry/swept-tube.js +124 -0
- package/geometry/terrain-chunks.js +139 -51
- package/geometry/terrain-extension.js +24 -8
- package/geometry/town-courtyard-inn.js +272 -0
- package/geometry/town-ground.js +76 -0
- package/geometry/town-houses.js +343 -0
- package/geometry/town-lights.js +254 -0
- package/geometry/town-lots.js +172 -0
- package/geometry/town-plan.js +370 -0
- package/geometry/town-works.js +465 -0
- package/geometry/village-layout.js +181 -0
- package/geometry/village-yards.js +167 -0
- package/geometry/wall-runs.js +64 -0
- package/index.js +139 -3
- package/math/cloud-textures.js +3 -7
- package/math/curve.js +5 -1
- package/math/lamp-texels.js +43 -0
- package/math/lit-share.js +22 -0
- package/math/mountain-ranges.js +177 -54
- package/math/periodic.js +6 -0
- package/math/rectangles.js +8 -2
- package/math/rock-texture.js +17 -12
- package/math/surface-textures.js +24 -9
- package/math/wandering-path.js +40 -0
- package/math/ways.js +120 -0
- package/motion/action-dynamics.js +398 -0
- package/motion/animal-bearing.js +247 -0
- package/motion/animal-canine-bearing.js +178 -0
- package/motion/animal-canine-cast.js +131 -0
- package/motion/animal-cattle-cast.js +64 -0
- package/motion/animal-herd-cast.js +154 -0
- package/motion/animal-horse-still.js +161 -0
- package/motion/animal-troop-cast.js +43 -0
- package/motion/arm-reach.js +3 -2
- package/motion/ballistic-arc.js +182 -2
- package/motion/biped-cycle.js +4 -2
- package/motion/biped-leg.js +4 -1
- package/motion/biped-posture.js +459 -0
- package/motion/biped-stride.js +142 -32
- package/motion/boat-sailing.js +214 -0
- package/motion/cast-actors.js +379 -0
- package/motion/cast-manager.js +321 -0
- package/motion/contact-transition.js +5 -6
- package/motion/crowd-alarms.js +36 -6
- package/motion/crowd-attention.js +108 -0
- package/motion/crowd-beasts.js +203 -0
- package/motion/crowd-camp.js +295 -0
- package/motion/crowd-figure.js +100 -0
- package/motion/crowd-herd.js +86 -0
- package/motion/crowd-hold.js +130 -0
- package/motion/crowd-pose.js +296 -0
- package/motion/crowd-poses.js +481 -0
- package/motion/crowd-routine.js +44 -14
- package/motion/crowd-town.js +166 -0
- package/motion/crowd-water.js +143 -0
- package/motion/deck-surface.js +4 -2
- package/motion/figure-acts.js +411 -0
- package/motion/figure-arms.js +437 -0
- package/motion/figure-blade-slide.js +149 -0
- package/motion/figure-body-place.js +180 -0
- package/motion/figure-bones.js +118 -0
- package/motion/figure-bow-draw.js +70 -0
- package/motion/figure-fingers.js +215 -0
- package/motion/figure-gaze.js +205 -0
- package/motion/figure-gestures.js +452 -0
- package/motion/figure-grip.js +134 -0
- package/motion/figure-head.js +287 -0
- package/motion/figure-legs.js +264 -0
- package/motion/figure-links.js +293 -0
- package/motion/figure-locomotion.js +391 -0
- package/motion/figure-mount-up.js +180 -0
- package/motion/figure-mount.js +201 -0
- package/motion/figure-pose-frame.js +375 -0
- package/motion/figure-pose-table.js +156 -0
- package/motion/figure-pose.js +343 -0
- package/motion/figure-seat.js +267 -0
- package/motion/figure-sway.js +125 -0
- package/motion/flier-corvid-pose.js +74 -0
- package/motion/flier-flight-air.js +122 -0
- package/motion/flier-flight-echelon.js +164 -0
- package/motion/flier-flight-roost.js +131 -0
- package/motion/flier-swarm-flight.js +252 -0
- package/motion/formation.js +193 -0
- package/motion/instance-sight.js +8 -1
- package/motion/melee-contact.js +143 -0
- package/motion/moorings.js +48 -0
- package/motion/path-steering.js +358 -0
- package/motion/player.js +7 -6
- package/motion/quadruped.js +109 -33
- package/motion/spaces.js +58 -6
- package/motion/speech-cadence.js +304 -0
- package/motion/vessel-motion.js +57 -0
- package/motion/walk-grid.js +235 -0
- package/motion/weather.js +70 -12
- package/motion/wind.js +27 -1
- package/package.json +46 -4
- package/rendering/alpha-mips.js +340 -0
- package/rendering/animal-camel-figure.js +29 -0
- package/rendering/animal-canine-figure.js +59 -0
- package/rendering/animal-cattle-figure.js +36 -0
- package/rendering/animal-horse-figure.js +49 -0
- package/rendering/atmosphere.js +86 -0
- package/rendering/camera-track.js +156 -0
- package/rendering/{road-surface.js → cart-track.js} +40 -11
- package/rendering/cast-stage.js +299 -0
- package/rendering/caster-motion.js +2 -1
- package/rendering/cell-lod-options.js +46 -0
- package/rendering/cell-lod.js +665 -80
- package/rendering/cloth-material.js +140 -0
- package/rendering/cloud-dome.js +2 -2
- package/rendering/compilation-schedule.js +18 -10
- package/rendering/contact-shadows.js +5 -2
- package/rendering/context.js +47 -8
- package/rendering/crowd-batches.js +420 -0
- package/rendering/crowd-herd.js +198 -0
- package/rendering/crowd-rig.js +132 -0
- package/rendering/crowd-skinning.js +52 -9
- package/rendering/crowd-update.js +419 -0
- package/rendering/crowd-visibility.js +107 -0
- package/rendering/day-cycle-defaults.js +200 -0
- package/rendering/day-cycle.js +487 -0
- package/rendering/daylight.js +1 -3
- package/rendering/detail-range.js +6 -5
- package/rendering/dof.js +11 -4
- package/rendering/effects-frame.js +149 -0
- package/rendering/effects-water-rises.js +221 -0
- package/rendering/energy-stream.js +128 -0
- package/rendering/facade-glass-material.js +105 -0
- package/rendering/far-shadow.js +81 -54
- package/rendering/field-surface.js +138 -0
- package/rendering/figure-shield.js +105 -0
- package/rendering/figure-skeleton.js +329 -0
- package/rendering/fire-light-watch.js +197 -0
- package/rendering/fire-pools.js +148 -0
- package/rendering/flame-sources.js +86 -0
- package/rendering/flier-bird-looks.js +97 -0
- package/rendering/flier-corvid-figure.js +67 -0
- package/rendering/flier-long-body-company.js +169 -0
- package/rendering/flier-swarm.js +186 -0
- package/rendering/flocks.js +6 -2
- package/rendering/garment-material.js +145 -49
- package/rendering/glsl-literal.js +19 -0
- package/rendering/ground-marks.js +316 -0
- package/rendering/hair-strands.js +38 -24
- package/rendering/height-haze.js +80 -33
- package/rendering/height-probe.js +15 -3
- package/rendering/house-kit-meshes.js +124 -0
- package/rendering/interior-bake.js +807 -0
- package/rendering/label-layout.js +13 -3
- package/rendering/label-range.js +5 -2
- package/rendering/lamp-light-map.js +159 -0
- package/rendering/lamp-maps.js +62 -0
- package/rendering/lamp-wash.js +51 -0
- package/rendering/light-budget.js +19 -3
- package/rendering/light-points.js +21 -5
- package/rendering/local-lights.js +27 -7
- package/rendering/material-lod.js +5 -6
- package/rendering/memory-estimate.js +84 -0
- package/rendering/moored-fleet.js +186 -0
- package/rendering/nameplate-groups.js +84 -0
- package/rendering/nameplates.js +386 -0
- package/rendering/part-costs.js +104 -0
- package/rendering/particle-bursts.js +386 -0
- package/rendering/particle-emitters.js +61 -25
- package/rendering/particle-light-bursts.js +189 -0
- package/rendering/particles.js +134 -34
- package/rendering/pen-flocks.js +118 -0
- package/rendering/piece-batch.js +282 -6
- package/rendering/planar-reflection-options.js +159 -0
- package/rendering/planar-reflection.js +780 -77
- package/rendering/plant-cells.js +122 -0
- package/rendering/plant-reeds.js +113 -0
- package/rendering/plant-shade-trees.js +239 -0
- package/rendering/plant-tuft-patch.js +122 -0
- package/rendering/post-shaders.js +84 -21
- package/rendering/post.js +39 -19
- package/rendering/pressed-cover.js +135 -0
- package/rendering/prop-dig.js +136 -0
- package/rendering/room-light.js +250 -0
- package/rendering/room-materials.js +78 -0
- package/rendering/room-space.js +111 -0
- package/rendering/scene-lights.js +106 -0
- package/rendering/sea-shaders.js +83 -26
- package/rendering/settlement-approach.js +226 -0
- package/rendering/settlement-dissolve.js +89 -0
- package/rendering/settlement-quarter-warm.js +55 -0
- package/rendering/settlement-quarter.js +477 -0
- package/rendering/settlement-switch.js +42 -0
- package/rendering/settlement-town.js +110 -0
- package/rendering/shader-warmup.js +80 -36
- package/rendering/shadow-depth.js +40 -18
- package/rendering/ship-meshes.js +150 -0
- package/rendering/shot-cuts.js +68 -0
- package/rendering/sky-occlusion.js +42 -15
- package/rendering/sky-pmrem.js +216 -0
- package/rendering/sky.js +112 -50
- package/rendering/smoke-shadows.js +201 -0
- package/rendering/stage-framing.js +182 -0
- package/rendering/stage-lights.js +46 -39
- package/rendering/stain-material.js +74 -0
- package/rendering/static-point-shadow.js +62 -23
- package/rendering/still-casters.js +77 -27
- package/rendering/strata-material.js +2 -2
- package/rendering/street-lamps.js +166 -0
- package/rendering/sunbeam-motes.js +670 -0
- package/rendering/surface-light.js +65 -6
- package/rendering/surface-material.js +306 -0
- package/rendering/surface-projection.js +32 -0
- package/rendering/surface-snippets.js +314 -0
- package/rendering/taa.js +49 -18
- package/rendering/tree-impostor.js +929 -0
- package/rendering/vehicle-train.js +92 -0
- package/rendering/viewport.js +67 -4
- package/rendering/water-material.js +270 -82
- package/rendering/waypoint-beacons.js +191 -0
- package/rendering/world-matrices.js +0 -2
- package/ruff.toml +20 -0
- package/runtime/cue-cursor.js +21 -0
- package/runtime/device-quality.js +13 -2
- package/runtime/device.js +73 -0
- package/runtime/diagnostic-log.js +11 -3
- package/runtime/effect-sites.js +85 -0
- package/runtime/figure-orders.js +59 -0
- package/runtime/first-use.js +8 -5
- package/runtime/foley-script.js +124 -0
- package/runtime/foley-strides.js +333 -0
- package/runtime/frame-pacing.js +18 -4
- package/runtime/frame-yield.js +18 -0
- package/runtime/gpu-timing.js +8 -4
- package/runtime/grid-cache.js +16 -6
- package/runtime/grid-rows.js +5 -5
- package/runtime/hand-over.js +7 -2
- package/runtime/land-bake.js +78 -0
- package/runtime/lazy-sets.js +105 -0
- package/runtime/pool.js +17 -3
- package/runtime/quality-fit.js +59 -27
- package/runtime/region-pass-lay.js +40 -0
- package/runtime/region-pass.js +78 -0
- package/runtime/search.js +6 -2
- package/runtime/settlement-reach.js +42 -0
- package/runtime/sound-calls.js +113 -0
- package/runtime/sound-impacts.js +297 -0
- package/runtime/sound-voices.js +194 -0
- package/runtime/soundscape.js +282 -0
- package/runtime/spatial-audio.js +69 -20
- package/runtime/steady-frames.js +221 -0
- package/runtime/withdrawable-task.js +19 -8
- package/scripts/app-parts.mjs +118 -0
- package/scripts/bake-revisions.mjs +81 -0
- package/scripts/browser-scripts.mjs +64 -0
- package/scripts/bundle.mjs +192 -0
- package/scripts/check-app.sh +26 -0
- package/scripts/eslint-config.mjs +119 -0
- package/scripts/format.sh +92 -0
- package/scripts/keep-builds.mjs +158 -0
- package/scripts/layers.mjs +112 -0
- package/scripts/lint.sh +49 -0
- package/scripts/module-graph.mjs +123 -0
- package/scripts/pre-commit.sh +38 -0
- package/scripts/serve.py +5 -3
- package/scripts/site.mjs +358 -0
- package/scripts/test-runner.sh +42 -0
- package/scripts/vendor.mjs +221 -0
- package/scripts/verify-publish.mjs +175 -0
- package/scripts/world.mk +59 -0
- package/tools/README.md +73 -0
- package/tools/contact-sheet.cjs +137 -0
- package/tools/cpu-profile.cjs +275 -0
- package/tools/cpu-profile.test.cjs +98 -0
- package/tools/first-draws.cjs +395 -0
- package/tools/flight-guard.cjs +482 -0
- package/tools/flight-guard.test.cjs +153 -0
- package/tools/flight-profile.cjs +145 -0
- package/tools/frame-bench.cjs +336 -0
- package/tools/frame-parts.cjs +365 -0
- package/tools/ios-sim.sh +145 -0
- package/tools/load-audit.cjs +201 -0
- package/tools/look-compare.cjs +304 -0
- package/tools/look-guard.cjs +407 -0
- package/tools/look-guard.test.cjs +93 -0
- package/tools/look-stats.cjs +185 -0
- package/tools/look-stats.test.cjs +71 -0
- package/tools/memory-audit.cjs +323 -0
- package/tools/page-driver.cjs +320 -0
- package/tools/page-driver.test.cjs +219 -0
- package/tools/program-census-report.cjs +191 -0
- package/tools/program-census.cjs +465 -0
- package/tools/program-census.test.cjs +332 -0
- package/tools/remote-runner.sh +265 -0
- package/tools/runners.test.cjs +59 -0
- package/tools/scene-audit-beat.cjs +344 -0
- package/tools/scene-audit-sheet.cjs +282 -0
- package/tools/scene-audit.cjs +471 -0
- package/tools/scene-audit.test.cjs +201 -0
- package/tools/scene-batch.cjs +219 -0
- package/tools/scene-bench.cjs +149 -0
- package/tools/scene-bench.test.cjs +33 -0
- package/tools/scene-run.cjs +443 -0
- package/tools/scene-run.test.cjs +94 -0
- package/tools/servers.sh +59 -0
- package/tools/shader-arrival.cjs +316 -0
- package/tools/shader-renewal.cjs +53 -0
- package/tools/shader-renewal.test.cjs +115 -0
- package/tools/speed-guard.cjs +258 -0
- package/tools/stills.cjs +492 -0
- package/tools/stills.test.cjs +49 -0
- package/tools/turns.sh +7 -0
- package/tools/yaml.cjs +158 -0
- package/examples/viaduct.css +0 -75
- package/rendering/light-shafts.js +0 -131
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vessels moored in a harbour, drawn as instances of their kinds: near the viewer each in full, plank by plank, further off
|
|
3
|
+
* as her light hull, all in a few draw calls. Each rides the water at her berth, lifting, rolling and snubbing at her lines, each
|
|
4
|
+
* in her own time. A fishing boat puts out to her ground offshore and lies there at anchor through her hours, home after: she
|
|
5
|
+
* goes, and comes back, while neither her berth nor her ground is in sight, or when the clock is turned.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { geometryOf } from '../geometry/builder.js';
|
|
10
|
+
import { oneOf } from '../geometry/ship-kit.js';
|
|
11
|
+
import { mulberry32 } from '../math/random.js';
|
|
12
|
+
import { twinMaterial } from './material-lod.js';
|
|
13
|
+
|
|
14
|
+
const _m = new THREE.Matrix4(),
|
|
15
|
+
_q = new THREE.Quaternion(),
|
|
16
|
+
_e = new THREE.Euler(),
|
|
17
|
+
_p = new THREE.Vector3(),
|
|
18
|
+
_s = new THREE.Vector3(),
|
|
19
|
+
_c = new THREE.Color(),
|
|
20
|
+
GROUND = [320, 480], // metres out from her quay to a fishing boat's ground: the least, and how much further it may lie
|
|
21
|
+
ABREAST = 260, // metres either way along the shore her ground may lie off her berth
|
|
22
|
+
SOUNDING = 25, // metres between the soundings on her way out, which must all find deep water
|
|
23
|
+
TRIES = 8; // grounds tried for a boat before she is kept at her quay
|
|
24
|
+
|
|
25
|
+
// A fishing boat's ground: open water out from her berth, reached on a straight way over deep water (`deep(x, z)`), with her
|
|
26
|
+
// day's rank (when she puts out and comes home among the others); null if none is found.
|
|
27
|
+
function groundOf(b, deep) {
|
|
28
|
+
const R = mulberry32(Math.round(b.x * 7 + b.z * 13)),
|
|
29
|
+
[ox, oz] = b.out;
|
|
30
|
+
for (let t = 0; t < TRIES; t++) {
|
|
31
|
+
const out = GROUND[0] + R() * GROUND[1],
|
|
32
|
+
along = (R() - 0.5) * 2 * ABREAST,
|
|
33
|
+
x = b.x + ox * out - oz * along,
|
|
34
|
+
z = b.z + oz * out + ox * along,
|
|
35
|
+
steps = Math.ceil(Math.hypot(x - b.x, z - b.z) / SOUNDING);
|
|
36
|
+
let open = true;
|
|
37
|
+
for (let i = 2; i <= steps && open; i++) open = deep(b.x + ((x - b.x) * i) / steps, b.z + ((z - b.z) * i) / steps);
|
|
38
|
+
if (open) return { x, z, ry: R() * Math.PI * 2, rank: R() };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
// Shows `count` instances of one level of a fleet's meshes (they share their matrices and tints), bounded where they lie now
|
|
43
|
+
function showLevel(meshes, count) {
|
|
44
|
+
for (const m of meshes) {
|
|
45
|
+
m.count = count;
|
|
46
|
+
m.visible = count > 0;
|
|
47
|
+
if (count) m.computeBoundingSphere();
|
|
48
|
+
}
|
|
49
|
+
meshes[0].instanceMatrix.needsUpdate = meshes[0].instanceColor.needsUpdate = true;
|
|
50
|
+
}
|
|
51
|
+
// Runs the work on the page, when no worker pool is given.
|
|
52
|
+
const runHere = (job, inputOf, here) => Promise.resolve().then(here);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Makes a harbour's fleet: the vessels moored (motion/moorings.js) raised as instances, and ridden each frame.
|
|
56
|
+
*
|
|
57
|
+
* @param {object} options
|
|
58
|
+
* @param {ReturnType<typeof import('../geometry/ship-kit.js').createShipKit>} options.kit - The ship kit.
|
|
59
|
+
* @param {ReturnType<typeof import('../motion/moorings.js').createMoorings>} options.moorings - Where the berths are noted.
|
|
60
|
+
* @param {{ wood: THREE.Material, glass: THREE.Material }} options.materials - Her timber (and rope) and her lanterns' panes,
|
|
61
|
+
* read when the fleet is raised; their tinted twins are drawn. Her canvas has a plain material of its own.
|
|
62
|
+
* @param {(job: string, inputOf: () => object, here: () => object) => Promise<object>} [options.runOrHere] - Runs a job on a
|
|
63
|
+
* worker pool, or `here()` on the page (as `createPool().runOrHere`). The page by default.
|
|
64
|
+
* @param {string} [options.job] - The pool's job that answers `{ spec, far }` with `kit.fleetShipParts(spec, far)`.
|
|
65
|
+
* @param {(rank: number) => boolean} [options.isOut] - Whether a fishing boat of the rank (0 first out and first home) is out
|
|
66
|
+
* now. Never, by default.
|
|
67
|
+
* @param {(x: number, y: number, z: number, size: number) => boolean} [options.inSight] - Whether a vessel there, `size` metres
|
|
68
|
+
* long, may be in sight: she only puts out or comes home unseen.
|
|
69
|
+
* @param {number} [options.near] - Metres within which a vessel is drawn in full.
|
|
70
|
+
* @param {number} [options.still] - Metres beyond which she is drawn lying still.
|
|
71
|
+
* @returns {{ raise: (parent: THREE.Object3D, R: () => number, deep?: (x: number, z: number) => boolean) => Promise<void>,
|
|
72
|
+
* update: (time: number, cameraX: number, cameraZ: number, turned: boolean) => void }} raise puts every vessel moored so far
|
|
73
|
+
* into `parent` as instances, two shades of each kind drawn from R, and clears the moorings (deep(x, z): whether water there
|
|
74
|
+
* is deep enough for a fishing boat's ground; without it, every boat stays at her berth); the promise is kept once they ride
|
|
75
|
+
* at their berths. update places each this frame: `time` in seconds, `turned` when the clock has jumped.
|
|
76
|
+
*/
|
|
77
|
+
export function createMooredFleet({
|
|
78
|
+
kit,
|
|
79
|
+
moorings,
|
|
80
|
+
materials,
|
|
81
|
+
runOrHere = runHere,
|
|
82
|
+
job = 'fleet ship',
|
|
83
|
+
isOut = () => false,
|
|
84
|
+
inSight = () => true,
|
|
85
|
+
near: NEAR = 170,
|
|
86
|
+
still: STILL = 400,
|
|
87
|
+
}) {
|
|
88
|
+
let sailcloth = null; // canvas for instances: a plain cloth, since one shaded by where its vertices lie would not follow them
|
|
89
|
+
const clothMaterial = () => (sailcloth ??= new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }));
|
|
90
|
+
const fleets = []; // what has been raised: { near: meshes, far: meshes, berths }
|
|
91
|
+
|
|
92
|
+
// One level of detail of a kind as instanced meshes sharing one set of matrices and tints: timber, rope and iron, canvas,
|
|
93
|
+
// and her lanterns' panes (lit at night, near and far alike: what shows of a harbour after dark).
|
|
94
|
+
function instances(parts, far, count, parent) {
|
|
95
|
+
const matrices = new THREE.InstancedBufferAttribute(new Float32Array(count * 16), 16),
|
|
96
|
+
tints = new THREE.InstancedBufferAttribute(new Float32Array(count * 3), 3),
|
|
97
|
+
out = [];
|
|
98
|
+
for (const [arrays, mat, shadow] of [
|
|
99
|
+
[parts.wood, twinMaterial(materials.wood, 'tinted'), !far],
|
|
100
|
+
[parts.rope, twinMaterial(materials.wood, 'tinted'), false],
|
|
101
|
+
[parts.furl, clothMaterial(), !far],
|
|
102
|
+
[parts.glass, twinMaterial(materials.glass, 'tinted'), false],
|
|
103
|
+
]) {
|
|
104
|
+
if (!arrays) continue;
|
|
105
|
+
const m = new THREE.InstancedMesh(geometryOf(arrays), mat, count);
|
|
106
|
+
m.instanceMatrix = matrices;
|
|
107
|
+
m.instanceColor = tints;
|
|
108
|
+
m.castShadow = shadow;
|
|
109
|
+
m.receiveShadow = true;
|
|
110
|
+
m.matrixAutoUpdate = false;
|
|
111
|
+
m.count = 0;
|
|
112
|
+
m.name = far ? 'fleet far' : 'fleet near';
|
|
113
|
+
if (arrays === parts.rope) m.layers.set(1); // a water mirror on layer 0 leaves out the rigging
|
|
114
|
+
parent.add(m);
|
|
115
|
+
out.push(m);
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
// A vessel of the spec moored in a fleet, near or `far`, as arrays: the promise of them, from the pool's workers or the page.
|
|
120
|
+
const shipArrays = (spec, far) =>
|
|
121
|
+
runOrHere(
|
|
122
|
+
job,
|
|
123
|
+
() => ({ spec, far }),
|
|
124
|
+
() => kit.fleetShipParts(spec, far),
|
|
125
|
+
);
|
|
126
|
+
function raise(parent, R, deep = null) {
|
|
127
|
+
const kinds = [];
|
|
128
|
+
for (const { spec, berths } of moorings.moored.values()) {
|
|
129
|
+
for (const b of berths) {
|
|
130
|
+
b.sea = deep && b.out ? groundOf(b, deep) : null;
|
|
131
|
+
b.atSea = false;
|
|
132
|
+
}
|
|
133
|
+
const near = shipArrays(oneOf(spec, R), false),
|
|
134
|
+
far = shipArrays(oneOf(spec, R), true);
|
|
135
|
+
kinds.push(Promise.all([near, far]).then(([nearParts, farParts]) => ({ berths, nearParts, farParts })));
|
|
136
|
+
}
|
|
137
|
+
moorings.moored.clear();
|
|
138
|
+
return Promise.all(kinds).then(raised => {
|
|
139
|
+
for (const { berths, nearParts, farParts } of raised)
|
|
140
|
+
fleets.push({
|
|
141
|
+
near: instances(nearParts, false, berths.length, parent),
|
|
142
|
+
far: instances(farParts, true, berths.length, parent),
|
|
143
|
+
berths,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// Puts a fishing boat out or brings her home as the hour has it, out of sight.
|
|
148
|
+
function keepHours(b, turned) {
|
|
149
|
+
const out = isOut(b.sea.rank);
|
|
150
|
+
if (out === b.atSea) return;
|
|
151
|
+
const size = 12 * b.k;
|
|
152
|
+
if (turned || (!inSight(b.x, b.y, b.z, size) && !inSight(b.sea.x, b.y, b.sea.z, size))) b.atSea = out;
|
|
153
|
+
}
|
|
154
|
+
function update(t, cx, cz, turned) {
|
|
155
|
+
for (let i = 0; i < fleets.length; i++) {
|
|
156
|
+
const f = fleets[i];
|
|
157
|
+
let near = 0,
|
|
158
|
+
far = 0;
|
|
159
|
+
for (let k = 0; k < f.berths.length; k++) {
|
|
160
|
+
const b = f.berths[k];
|
|
161
|
+
if (b.sea) keepHours(b, turned);
|
|
162
|
+
const at = b.atSea ? b.sea : b, // where she lies: her berth, or her ground
|
|
163
|
+
d2 = (at.x - cx) ** 2 + (at.z - cz) ** 2,
|
|
164
|
+
full = d2 < NEAR * NEAR,
|
|
165
|
+
meshes = full ? f.near : f.far,
|
|
166
|
+
index = full ? near++ : far++,
|
|
167
|
+
ride = d2 < STILL * STILL ? 1 : 0,
|
|
168
|
+
w = t * 0.8 + b.ph;
|
|
169
|
+
// she lifts to the swell, rolls a little more than she pitches, and her lines check her as she swings
|
|
170
|
+
_e.set(
|
|
171
|
+
ride * Math.sin(w * 1.3) * 0.008,
|
|
172
|
+
at.ry + ride * Math.sin(w * 0.23) * 0.02,
|
|
173
|
+
ride * (Math.sin(w) * 0.022 + Math.sin(w * 1.9 + 1) * 0.008),
|
|
174
|
+
'YXZ',
|
|
175
|
+
);
|
|
176
|
+
_m.compose(_p.set(at.x, b.y + ride * Math.sin(w * 1.1 + 2) * 0.045, at.z), _q.setFromEuler(_e), _s.setScalar(b.k));
|
|
177
|
+
meshes[0].setMatrixAt(index, _m);
|
|
178
|
+
meshes[0].setColorAt(index, _c.setScalar(b.tone));
|
|
179
|
+
}
|
|
180
|
+
showLevel(f.near, near);
|
|
181
|
+
showLevel(f.far, far);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return { raise, update };
|
|
186
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared nameplate anchors for crowds, formations, or flocks: each named group attaches
|
|
3
|
+
* one anchor record and offers its members each frame so the nearest visible standing
|
|
4
|
+
* member carries the group's single nameplate.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const DEFAULT_HEAD_CLEARANCE = 0.35; // metres above member top where the label attaches
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a manager for group nameplate anchors bound to a label fade range, camera, and
|
|
12
|
+
* frame counter. Zero allocations per frame in `considerMember`.
|
|
13
|
+
*
|
|
14
|
+
* @param {object} config
|
|
15
|
+
* @param {{ far: number, selection: () => { accept: Function, distance: Function } }} config.labelRange - Label visibility range (`createLabelRange`).
|
|
16
|
+
* @param {() => THREE.Camera} config.getCamera - Returns the active camera.
|
|
17
|
+
* @param {() => number} config.getFrame - Returns the current frame counter.
|
|
18
|
+
* @param {number} [config.headClearance=0.35] - Vertical offset (metres) above a member's height for frustum testing.
|
|
19
|
+
* @returns {{ groupList: object[], attachGroup: (group: object, def: object) => object, considerMember: (anchor: object, x: number, y: number, z: number, height: number) => void, clearGroups: () => void }}
|
|
20
|
+
*/
|
|
21
|
+
export function createNameplateGroups({ labelRange, getCamera, getFrame, headClearance = DEFAULT_HEAD_CLEARANCE }) {
|
|
22
|
+
const groupList = [];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Attaches a shared nameplate anchor record to `group` using metadata `def` (`{ name, sub, color, plateScale? }`).
|
|
26
|
+
* Stores the anchor on `group.bodyPlate` and registers it in `groupList`.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} group - Crowd or flock object receiving the anchor.
|
|
29
|
+
* @param {object} def - Group nameplate definition.
|
|
30
|
+
* @returns {object} The passed `group` for chaining.
|
|
31
|
+
*/
|
|
32
|
+
function attachGroup(group, def) {
|
|
33
|
+
// Keep one monomorphic shape matching cast actor nameplate fields so rendering/nameplates.js shares one hot path.
|
|
34
|
+
const anchor = {
|
|
35
|
+
bodyDef: def,
|
|
36
|
+
range: labelRange.far,
|
|
37
|
+
selection: labelRange.selection(),
|
|
38
|
+
x: 0,
|
|
39
|
+
y: 0,
|
|
40
|
+
z: 0,
|
|
41
|
+
height: 0,
|
|
42
|
+
dist: Infinity,
|
|
43
|
+
sx: 0,
|
|
44
|
+
sy: 0,
|
|
45
|
+
ph: 0,
|
|
46
|
+
want: 0,
|
|
47
|
+
plate: null,
|
|
48
|
+
plateH: 1,
|
|
49
|
+
plateOnCard: false,
|
|
50
|
+
plateA: 0,
|
|
51
|
+
plateBeside: false,
|
|
52
|
+
};
|
|
53
|
+
groupList.push(anchor);
|
|
54
|
+
group.bodyPlate = anchor;
|
|
55
|
+
return group;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Offers a member's resolved world position to its group's anchor; retains the nearest
|
|
60
|
+
* member whose label point falls inside the camera frustum for the current frame.
|
|
61
|
+
*
|
|
62
|
+
* @param {object} anchor - Group anchor (`group.bodyPlate`).
|
|
63
|
+
* @param {number} x - Member world X (metres).
|
|
64
|
+
* @param {number} y - Member base world Y (metres).
|
|
65
|
+
* @param {number} z - Member world Z (metres).
|
|
66
|
+
* @param {number} height - Member height (metres).
|
|
67
|
+
*/
|
|
68
|
+
function considerMember(anchor, x, y, z, height) {
|
|
69
|
+
if (!anchor.selection.accept(getFrame(), getCamera(), x, y + height * 0.5, z, y + height + headClearance)) return;
|
|
70
|
+
anchor.x = x;
|
|
71
|
+
anchor.y = y;
|
|
72
|
+
anchor.z = z;
|
|
73
|
+
anchor.height = height;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Removes all registered group anchors.
|
|
78
|
+
*/
|
|
79
|
+
function clearGroups() {
|
|
80
|
+
groupList.length = 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { groupList, attachGroup, considerMember, clearGroups };
|
|
84
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distance-faded, collision-free floating nameplates for cast actors and named crowd groups:
|
|
3
|
+
* wraps long subtitles onto two lines, renders crisp canvas textures at a paced per-frame
|
|
4
|
+
* budget, defers `renderer.initTexture` uploads by one frame to avoid GPU stalls, avoids HUD
|
|
5
|
+
* regions and neighbouring labels (with shoulder fallback), and smoothly fades opacity.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { clamp, sstep } from '../math/scalar.js';
|
|
10
|
+
import { createLabelLayout } from './label-layout.js';
|
|
11
|
+
|
|
12
|
+
/** Default title and subtitle canvas font strings. */
|
|
13
|
+
export const DEFAULT_PLATE_FONTS = Object.freeze({
|
|
14
|
+
name: '600 44px "Iowan Old Style","Palatino Linotype",Palatino,"Book Antiqua",Georgia,serif',
|
|
15
|
+
sub: '500 36px system-ui,-apple-system,"Segoe UI",Roboto,sans-serif',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/** Default radial backdrop gradient stops behind plate lettering. */
|
|
19
|
+
export const DEFAULT_PLATE_BACKDROP = Object.freeze([
|
|
20
|
+
[0, 'rgba(4,9,11,.78)'],
|
|
21
|
+
[0.55, 'rgba(4,9,11,.44)'],
|
|
22
|
+
[1, 'rgba(4,9,11,0)'],
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const DEFAULT_PLATES_PER_FRAME = 2;
|
|
26
|
+
const DEFAULT_PLATE_SCREEN = 0.031; // plate height as a fraction of viewport height
|
|
27
|
+
const DEFAULT_PLATE_MIN_PX = 36; // minimum plate height in CSS pixels for phone legibility
|
|
28
|
+
const DEFAULT_FIGURE_TO_PLATE = Object.freeze([0.9, 1.6]); // figure-height / plate-height fade range
|
|
29
|
+
const PLATE_CANVAS_WIDTH = 512;
|
|
30
|
+
const PLATE_CANVAS_WIDE = 4; // canvas width in plate-height units
|
|
31
|
+
const LETTER_MARGIN = 0.3; // horizontal padding around measured lettering, in plate heights
|
|
32
|
+
const TEXT_MOST = 3.9; // estimated text width in plate heights before canvas measurement
|
|
33
|
+
const DEFAULT_HEAD_CLEARANCE = 0.35; // metres above actor/group top
|
|
34
|
+
const DEFAULT_SHOULDER_RATIO = 0.72; // fraction of actor height for side-of-shoulder fallback
|
|
35
|
+
const _v = new THREE.Vector3(); // module scratch for synchronous screen projection
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Splits a long subtitle onto two balanced lines at the space closest to its midpoint,
|
|
39
|
+
* stripping a trailing or leading separator token (`'·'` by default) at the break point.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} subtitle - Subtitle string.
|
|
42
|
+
* @param {(text: string) => number} measureWidth - Returns pixel width of a line in the subtitle font.
|
|
43
|
+
* @param {number} [maxWidth=480] - Maximum single-line width (canvas pixels) before wrapping.
|
|
44
|
+
* @param {string} [separator='·'] - Inline separator stripped at line breaks when present.
|
|
45
|
+
* @returns {[string, string]} Primary line and optional second line (`''` when unwrapped).
|
|
46
|
+
*/
|
|
47
|
+
export function wrapSubtitle(subtitle, measureWidth, maxWidth = 480, separator = '·') {
|
|
48
|
+
let l1 = subtitle,
|
|
49
|
+
l2 = '';
|
|
50
|
+
if (measureWidth(subtitle) > maxWidth) {
|
|
51
|
+
let best = -1,
|
|
52
|
+
bestWidth = 1e9;
|
|
53
|
+
for (let i = subtitle.indexOf(' '); i > 0; i = subtitle.indexOf(' ', i + 1)) {
|
|
54
|
+
const w = Math.max(measureWidth(subtitle.slice(0, i)), measureWidth(subtitle.slice(i + 1)));
|
|
55
|
+
if (w < bestWidth) {
|
|
56
|
+
bestWidth = w;
|
|
57
|
+
best = i;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (best > 0) {
|
|
61
|
+
l1 = subtitle.slice(0, best);
|
|
62
|
+
l2 = subtitle.slice(best + 1);
|
|
63
|
+
if (separator) {
|
|
64
|
+
const trail = ' ' + separator;
|
|
65
|
+
const lead = separator + ' ';
|
|
66
|
+
if (l1.endsWith(trail)) l1 = l1.slice(0, -trail.length);
|
|
67
|
+
if (l2.startsWith(lead)) l2 = l2.slice(lead.length);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [l1, l2];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Renders a two-tier nameplate (title and one- or two-line subtitle over a soft radial
|
|
76
|
+
* backdrop) onto a canvas and reports its aspect ratio and measured lettering width.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} name - Primary title text.
|
|
79
|
+
* @param {string} subtitle - Secondary descriptor text.
|
|
80
|
+
* @param {string} subColor - CSS colour string for the subtitle line(s).
|
|
81
|
+
* @param {object} [options]
|
|
82
|
+
* @param {{ name: string, sub: string }} [options.fonts=DEFAULT_PLATE_FONTS] - Canvas font strings.
|
|
83
|
+
* @param {string} [options.nameColor='#f3ecd9'] - CSS colour string for the title text.
|
|
84
|
+
* @param {ReadonlyArray<[number, string]>} [options.backdropStops=DEFAULT_PLATE_BACKDROP] - Radial gradient colour stops.
|
|
85
|
+
* @param {string} [options.shadowColor='rgba(0,0,0,.95)'] - Text drop shadow colour.
|
|
86
|
+
* @param {number} [options.shadowBlur=7] - Text drop shadow blur radius (canvas pixels).
|
|
87
|
+
* @param {string} [options.separator='·'] - Separator stripped at wrap boundaries.
|
|
88
|
+
* @param {() => HTMLCanvasElement} [options.createCanvas] - Canvas factory (defaults to `document.createElement('canvas')`).
|
|
89
|
+
* @returns {{ canvas: HTMLCanvasElement, plateH: number, plateWide: number }}
|
|
90
|
+
*/
|
|
91
|
+
export function renderNameplateCanvas(
|
|
92
|
+
name,
|
|
93
|
+
subtitle,
|
|
94
|
+
subColor,
|
|
95
|
+
{
|
|
96
|
+
fonts = DEFAULT_PLATE_FONTS,
|
|
97
|
+
nameColor = '#f3ecd9',
|
|
98
|
+
backdropStops = DEFAULT_PLATE_BACKDROP,
|
|
99
|
+
shadowColor = 'rgba(0,0,0,.95)',
|
|
100
|
+
shadowBlur = 7,
|
|
101
|
+
separator = '·',
|
|
102
|
+
createCanvas = () => document.createElement('canvas'),
|
|
103
|
+
} = {},
|
|
104
|
+
) {
|
|
105
|
+
const canvas = createCanvas(),
|
|
106
|
+
g = canvas.getContext('2d');
|
|
107
|
+
g.font = fonts.sub;
|
|
108
|
+
const [l1, l2] = wrapSubtitle(subtitle, text => g.measureText(text).width, 480, separator);
|
|
109
|
+
const heightPx = l2 ? 164 : 128;
|
|
110
|
+
canvas.width = PLATE_CANVAS_WIDTH;
|
|
111
|
+
canvas.height = heightPx;
|
|
112
|
+
const grd = g.createRadialGradient(256, heightPx / 2, 8, 256, heightPx / 2, 250);
|
|
113
|
+
for (let i = 0; i < backdropStops.length; i++) grd.addColorStop(backdropStops[i][0], backdropStops[i][1]);
|
|
114
|
+
g.save();
|
|
115
|
+
g.translate(0, heightPx / 2);
|
|
116
|
+
g.scale(1, heightPx / PLATE_CANVAS_WIDTH);
|
|
117
|
+
g.translate(0, -heightPx / 2);
|
|
118
|
+
g.fillStyle = grd;
|
|
119
|
+
g.fillRect(0, heightPx / 2 - 256, PLATE_CANVAS_WIDTH, PLATE_CANVAS_WIDTH);
|
|
120
|
+
g.restore();
|
|
121
|
+
g.textAlign = 'center';
|
|
122
|
+
g.textBaseline = 'middle';
|
|
123
|
+
g.shadowColor = shadowColor;
|
|
124
|
+
g.shadowBlur = shadowBlur;
|
|
125
|
+
let widest = 0;
|
|
126
|
+
const fit = (text, font, y, color, max) => {
|
|
127
|
+
g.font = font;
|
|
128
|
+
const w = g.measureText(text).width;
|
|
129
|
+
widest = Math.max(widest, Math.min(w, max));
|
|
130
|
+
g.save();
|
|
131
|
+
g.translate(256, y);
|
|
132
|
+
if (w > max) g.scale(max / w, 1);
|
|
133
|
+
g.fillStyle = color;
|
|
134
|
+
g.fillText(text, 0, 0);
|
|
135
|
+
g.fillText(text, 0, 0);
|
|
136
|
+
g.restore();
|
|
137
|
+
};
|
|
138
|
+
fit(name, fonts.name, 42, nameColor, 490);
|
|
139
|
+
fit(l1, fonts.sub, 95, subColor, 496);
|
|
140
|
+
if (l2) fit(l2, fonts.sub, 131, subColor, 496);
|
|
141
|
+
return {
|
|
142
|
+
canvas,
|
|
143
|
+
plateH: heightPx / 128,
|
|
144
|
+
plateWide: (widest / canvas.width) * PLATE_CANVAS_WIDE,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates a zero-allocation per-frame nameplate controller managing sprite creation,
|
|
150
|
+
* deferred GPU texture initialization, screen-space deconfliction, and smooth opacity fading
|
|
151
|
+
* for cast actors and shared group anchors.
|
|
152
|
+
*
|
|
153
|
+
* @param {object} config
|
|
154
|
+
* @param {THREE.PerspectiveCamera} config.camera - Active camera.
|
|
155
|
+
* @param {{ initTexture: (texture: THREE.Texture) => void }} config.renderer - Renderer used to upload canvas textures on the following frame.
|
|
156
|
+
* @param {{ far: number, opacity: (distance: number, limit?: number) => number }} config.labelRange - Label distance fade curve (`createLabelRange`).
|
|
157
|
+
* @param {object[]} config.actors - Dense cast actor array.
|
|
158
|
+
* @param {object[]} [config.groups=[]] - Dense group nameplate anchor array (`createNameplateGroups().groupList`).
|
|
159
|
+
* @param {() => number} config.getViewportWidth - Returns viewport width in CSS pixels.
|
|
160
|
+
* @param {() => number} config.getViewportHeight - Returns viewport height in CSS pixels.
|
|
161
|
+
* @param {() => number} config.getFrame - Returns current frame counter.
|
|
162
|
+
* @param {() => boolean} [config.isActive] - Returns true when nameplates should be shown (e.g. not on title screen).
|
|
163
|
+
* @param {(left: number, top: number, right: number, bottom: number) => boolean} [config.blocked] - Returns true when a screen box overlaps HUD controls.
|
|
164
|
+
* @param {(sprite: THREE.Sprite) => void} [config.onSpriteCreated] - Called once per newly created nameplate sprite (e.g. to place it in a full-res overlay pass).
|
|
165
|
+
* @param {(actor: object) => any} [config.getActorKey] - Deduplication key for actors sharing a name.
|
|
166
|
+
* @param {(actor: object) => [string, string, string]} [config.getActorPlate] - Returns `[name, subtitle, subColor]` when creating an actor's plate canvas.
|
|
167
|
+
* @param {(actor: object) => boolean} [config.isActorEligible] - Returns true when an actor may carry a plate this frame.
|
|
168
|
+
* @param {(group: object) => any} [config.getGroupKey] - Deduplication key for shared group anchors.
|
|
169
|
+
* @param {(group: object) => [string, string, string]} [config.getGroupPlate] - Returns `[name, subtitle, subColor]` when creating a group's plate canvas.
|
|
170
|
+
* @param {(group: object) => number} [config.getGroupScale] - Scale multiplier for a group's plate height.
|
|
171
|
+
* @param {{ name: string, sub: string }} [config.fonts=DEFAULT_PLATE_FONTS] - Canvas font strings.
|
|
172
|
+
* @param {string} [config.nameColor='#f3ecd9'] - Title CSS colour.
|
|
173
|
+
* @param {ReadonlyArray<[number, string]>} [config.backdropStops=DEFAULT_PLATE_BACKDROP] - Backdrop gradient stops.
|
|
174
|
+
* @param {string} [config.separator='·'] - Subtitle wrap separator.
|
|
175
|
+
* @param {number} [config.platesPerFrame=2] - Maximum new plate canvases rendered in one frame.
|
|
176
|
+
* @param {number} [config.capacity=64] - Maximum simultaneous placed plates in layout.
|
|
177
|
+
* @param {number} [config.margin=6] - Viewport edge margin (CSS pixels).
|
|
178
|
+
* @param {number} [config.screenShare=0.031] - Plate height as a fraction of viewport height.
|
|
179
|
+
* @param {number} [config.minPx=36] - Minimum plate height (CSS pixels).
|
|
180
|
+
* @param {readonly [number, number]} [config.figureToPlate=[0.9, 1.6]] - Figure-to-plate height ratio fade band.
|
|
181
|
+
* @param {number} [config.headClearance=0.35] - Vertical offset above head (metres).
|
|
182
|
+
* @param {number} [config.shoulderRatio=0.72] - Vertical fraction of actor height for side-shoulder fallback.
|
|
183
|
+
* @param {number} [config.renderOrder=20] - Sprite `renderOrder`.
|
|
184
|
+
* @param {number} [config.anisotropy=4] - Canvas texture anisotropy.
|
|
185
|
+
* @param {number} [config.fadeRate=8] - Opacity ease rate (1/s).
|
|
186
|
+
* @param {() => HTMLCanvasElement} [config.createCanvas] - Optional canvas factory for headless tests.
|
|
187
|
+
* @returns {{ onPlates: (left: number, top: number, right: number, bottom: number) => boolean, updatePlates: (dt: number) => void }}
|
|
188
|
+
*/
|
|
189
|
+
export function createNameplates({
|
|
190
|
+
camera,
|
|
191
|
+
renderer,
|
|
192
|
+
labelRange,
|
|
193
|
+
actors,
|
|
194
|
+
groups = [],
|
|
195
|
+
getViewportWidth,
|
|
196
|
+
getViewportHeight,
|
|
197
|
+
getFrame,
|
|
198
|
+
isActive = () => true,
|
|
199
|
+
blocked = () => false,
|
|
200
|
+
onSpriteCreated = null,
|
|
201
|
+
getActorKey = a => a.def.name,
|
|
202
|
+
getActorPlate = a => [a.def.name, a.def.sub || '', '#d8c8a8'],
|
|
203
|
+
isActorEligible = a => a.group.visible && a.pose !== 'dead',
|
|
204
|
+
getGroupKey = b => b.bodyDef,
|
|
205
|
+
getGroupPlate = b => [b.bodyDef.name, b.bodyDef.sub, b.bodyDef.color],
|
|
206
|
+
getGroupScale = b => b.bodyDef.plateScale ?? 1,
|
|
207
|
+
fonts = DEFAULT_PLATE_FONTS,
|
|
208
|
+
nameColor = '#f3ecd9',
|
|
209
|
+
backdropStops = DEFAULT_PLATE_BACKDROP,
|
|
210
|
+
separator = '·',
|
|
211
|
+
platesPerFrame = DEFAULT_PLATES_PER_FRAME,
|
|
212
|
+
capacity = 64,
|
|
213
|
+
margin = 6,
|
|
214
|
+
screenShare = DEFAULT_PLATE_SCREEN,
|
|
215
|
+
minPx = DEFAULT_PLATE_MIN_PX,
|
|
216
|
+
figureToPlate = DEFAULT_FIGURE_TO_PLATE,
|
|
217
|
+
headClearance = DEFAULT_HEAD_CLEARANCE,
|
|
218
|
+
shoulderRatio = DEFAULT_SHOULDER_RATIO,
|
|
219
|
+
renderOrder = 20,
|
|
220
|
+
anisotropy = 4,
|
|
221
|
+
fadeRate = 8,
|
|
222
|
+
createCanvas = () => document.createElement('canvas'),
|
|
223
|
+
}) {
|
|
224
|
+
const drawnLast = [];
|
|
225
|
+
const placements = createLabelLayout({ capacity, margin, blocked });
|
|
226
|
+
const plateOrder = [];
|
|
227
|
+
const named = new Set();
|
|
228
|
+
const view = { on: false, H: 0, W: 0, proj: 0, platePx: 0 };
|
|
229
|
+
const canvasStyle = { fonts, nameColor, backdropStops, separator, createCanvas };
|
|
230
|
+
|
|
231
|
+
const aboveHead = a => a.y + a.height + headClearance;
|
|
232
|
+
const shoulderHeight = a => a.y + a.height * shoulderRatio;
|
|
233
|
+
|
|
234
|
+
function makePlate(a, name, sub, color) {
|
|
235
|
+
const { canvas, plateH, plateWide } = renderNameplateCanvas(name, sub, color, canvasStyle);
|
|
236
|
+
a.plateH = plateH;
|
|
237
|
+
a.plateWide = plateWide;
|
|
238
|
+
const tex = new THREE.CanvasTexture(canvas);
|
|
239
|
+
tex.colorSpace = THREE.SRGBColorSpace;
|
|
240
|
+
tex.anisotropy = anisotropy;
|
|
241
|
+
const sp = new THREE.Sprite(
|
|
242
|
+
new THREE.SpriteMaterial({ map: tex, transparent: true, depthWrite: false, depthTest: true, fog: false, opacity: 0 }),
|
|
243
|
+
);
|
|
244
|
+
sp.renderOrder = renderOrder;
|
|
245
|
+
sp.visible = false;
|
|
246
|
+
if (onSpriteCreated) onSpriteCreated(sp);
|
|
247
|
+
a.plate = sp;
|
|
248
|
+
drawnLast.push(a);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function toCard() {
|
|
252
|
+
for (let i = 0; i < drawnLast.length; i++) {
|
|
253
|
+
const a = drawnLast[i];
|
|
254
|
+
renderer.initTexture(a.plate.material.map);
|
|
255
|
+
a.plateOnCard = true;
|
|
256
|
+
}
|
|
257
|
+
drawnLast.length = 0;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function onScreen(a, y) {
|
|
261
|
+
a.deep = Math.max(-_v.set(a.x, y, a.z).applyMatrix4(camera.matrixWorldInverse).z, 0.01);
|
|
262
|
+
_v.set(a.x, y, a.z).project(camera);
|
|
263
|
+
if (!(_v.z > -1 && _v.z < 1 && _v.x > -1.15 && _v.x < 1.15 && _v.y > -1.1 && _v.y < 1.2)) return false;
|
|
264
|
+
a.sx = (_v.x * 0.5 + 0.5) * view.W;
|
|
265
|
+
a.sy = (-_v.y * 0.5 + 0.5) * view.H;
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function wantActors() {
|
|
270
|
+
const { platePx, proj } = view;
|
|
271
|
+
for (let i = 0; i < actors.length; i++) {
|
|
272
|
+
const a = actors[i];
|
|
273
|
+
let want = 0;
|
|
274
|
+
if (view.on && isActorEligible(a) && a.dist < a.range && (onScreen(a, aboveHead(a)) || onScreen(a, shoulderHeight(a)))) {
|
|
275
|
+
const figurePx = (a.height / a.dist) * proj;
|
|
276
|
+
a.ph = clamp((a.deep * platePx) / proj, 0.02, 3.6);
|
|
277
|
+
want = labelRange.opacity(a.dist, a.range) * sstep(figureToPlate[0], figureToPlate[1], figurePx / platePx);
|
|
278
|
+
if (want > 0.01) plateOrder.push(a);
|
|
279
|
+
}
|
|
280
|
+
a.want = want;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function wantGroups() {
|
|
285
|
+
const frame = getFrame();
|
|
286
|
+
for (let i = 0; i < groups.length; i++) {
|
|
287
|
+
const b = groups[i];
|
|
288
|
+
b.dist = b.selection.distance(frame);
|
|
289
|
+
b.want = 0;
|
|
290
|
+
if (!view.on || b.dist >= b.range || !onScreen(b, aboveHead(b))) continue;
|
|
291
|
+
b.ph = ((b.deep * view.platePx) / view.proj) * getGroupScale(b);
|
|
292
|
+
b.want = labelRange.opacity(b.dist);
|
|
293
|
+
if (b.want > 0.01) plateOrder.push(b);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function placePlate(a, isGroup) {
|
|
298
|
+
const hpx = (a.ph / a.deep) * view.proj,
|
|
299
|
+
tall = hpx * (a.plateH || 1),
|
|
300
|
+
width = hpx * ((a.plateWide ?? TEXT_MOST) + LETTER_MARGIN);
|
|
301
|
+
let dx = 0,
|
|
302
|
+
beside = false,
|
|
303
|
+
bottom = NaN;
|
|
304
|
+
if (onScreen(a, aboveHead(a))) bottom = placements.place(a.sx, a.sy, width, tall, tall * 2, hpx * 0.12);
|
|
305
|
+
if (!Number.isFinite(bottom)) {
|
|
306
|
+
if (isGroup || !onScreen(a, shoulderHeight(a))) return false;
|
|
307
|
+
beside = true;
|
|
308
|
+
const clearance = Math.max(8, (a.height * 0.18 * view.proj) / a.deep);
|
|
309
|
+
dx = width / 2 + clearance;
|
|
310
|
+
const foot = a.sy + tall / 2;
|
|
311
|
+
bottom = placements.place(a.sx + dx, foot, width, tall);
|
|
312
|
+
if (!Number.isFinite(bottom)) {
|
|
313
|
+
dx = -dx;
|
|
314
|
+
bottom = placements.place(a.sx + dx, foot, width, tall);
|
|
315
|
+
}
|
|
316
|
+
if (!Number.isFinite(bottom)) return false;
|
|
317
|
+
}
|
|
318
|
+
a.plateBeside = beside;
|
|
319
|
+
a.ph = (hpx * a.deep) / view.proj;
|
|
320
|
+
if (a.plate) a.plate.center.set(0.5 - dx / (hpx * PLATE_CANVAS_WIDE), (bottom - a.sy) / tall);
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function showPlate(a, k) {
|
|
325
|
+
if (!a.plate) return;
|
|
326
|
+
a.plateA = a.dist >= a.range ? 0 : a.plateA + ((a.want || 0) - a.plateA) * k;
|
|
327
|
+
if (a.plateA < 0.015) {
|
|
328
|
+
if (a.plate.visible) a.plate.visible = false;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const sp = a.plate,
|
|
332
|
+
hk = a.plateH || 1;
|
|
333
|
+
sp.visible = true;
|
|
334
|
+
sp.material.opacity = a.plateA;
|
|
335
|
+
sp.position.set(a.x, a.plateBeside ? shoulderHeight(a) : aboveHead(a), a.z);
|
|
336
|
+
sp.scale.set(a.ph * PLATE_CANVAS_WIDE, a.ph * hk, 1);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function updatePlates(dt) {
|
|
340
|
+
const H = getViewportHeight();
|
|
341
|
+
view.on = isActive();
|
|
342
|
+
view.H = H;
|
|
343
|
+
view.W = getViewportWidth();
|
|
344
|
+
view.proj = H / (2 * Math.tan((camera.fov * Math.PI) / 360));
|
|
345
|
+
view.platePx = Math.max(screenShare * H, minPx);
|
|
346
|
+
placements.reset(view.W, H);
|
|
347
|
+
toCard();
|
|
348
|
+
plateOrder.length = 0;
|
|
349
|
+
wantActors();
|
|
350
|
+
wantGroups();
|
|
351
|
+
for (let i = 1; i < plateOrder.length; i++) {
|
|
352
|
+
const a = plateOrder[i];
|
|
353
|
+
let j = i - 1;
|
|
354
|
+
while (j >= 0 && plateOrder[j].dist > a.dist) {
|
|
355
|
+
plateOrder[j + 1] = plateOrder[j];
|
|
356
|
+
j--;
|
|
357
|
+
}
|
|
358
|
+
plateOrder[j + 1] = a;
|
|
359
|
+
}
|
|
360
|
+
let made = 0;
|
|
361
|
+
named.clear();
|
|
362
|
+
for (let i = 0; i < plateOrder.length; i++) {
|
|
363
|
+
const a = plateOrder[i],
|
|
364
|
+
isGroup = !!a.bodyDef,
|
|
365
|
+
key = isGroup ? getGroupKey(a) : getActorKey(a);
|
|
366
|
+
if (named.has(key)) {
|
|
367
|
+
a.want = 0;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (!a.plate && made < platesPerFrame) {
|
|
371
|
+
const [name, sub, color] = isGroup ? getGroupPlate(a) : getActorPlate(a);
|
|
372
|
+
makePlate(a, name, sub, color);
|
|
373
|
+
made++;
|
|
374
|
+
}
|
|
375
|
+
if (placePlate(a, isGroup)) {
|
|
376
|
+
named.add(key);
|
|
377
|
+
if (!a.plateOnCard) a.want = 0;
|
|
378
|
+
} else a.want = 0;
|
|
379
|
+
}
|
|
380
|
+
const k = Math.min(1, dt * fadeRate);
|
|
381
|
+
for (let i = 0; i < actors.length; i++) showPlate(actors[i], k);
|
|
382
|
+
for (let i = 0; i < groups.length; i++) showPlate(groups[i], k);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return { onPlates: placements.overlaps, updatePlates };
|
|
386
|
+
}
|