roamwright 0.20.1 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (516) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +19 -14
  3. package/README.md +35 -16
  4. package/examples/animals.html +49 -0
  5. package/examples/animals.js +209 -0
  6. package/examples/crowds.html +50 -0
  7. package/examples/crowds.js +268 -0
  8. package/examples/effects.html +53 -0
  9. package/examples/effects.js +343 -0
  10. package/examples/figure-motion.html +55 -0
  11. package/examples/figure-motion.js +265 -0
  12. package/examples/figure.html +49 -0
  13. package/examples/figure.js +238 -0
  14. package/examples/fliers.html +53 -0
  15. package/examples/fliers.js +292 -0
  16. package/examples/fortification.html +54 -0
  17. package/examples/fortification.js +288 -0
  18. package/examples/house-kit.html +48 -0
  19. package/examples/house-kit.js +175 -0
  20. package/examples/index.html +26 -16
  21. package/examples/island.html +48 -0
  22. package/examples/island.js +134 -52
  23. package/examples/land.html +54 -0
  24. package/examples/land.js +392 -0
  25. package/examples/props-and-plants.html +53 -0
  26. package/examples/props-and-plants.js +275 -0
  27. package/examples/rooms.html +48 -0
  28. package/examples/rooms.js +242 -0
  29. package/examples/ships.html +51 -0
  30. package/examples/ships.js +235 -0
  31. package/examples/showcase.css +320 -0
  32. package/examples/small-world-land.js +151 -0
  33. package/examples/small-world-life.js +160 -0
  34. package/examples/small-world-town.js +127 -0
  35. package/examples/small-world.html +57 -0
  36. package/examples/small-world.js +226 -0
  37. package/examples/soundscape.html +138 -0
  38. package/examples/soundscape.js +467 -0
  39. package/examples/stage-kits.js +300 -0
  40. package/examples/stage.js +374 -0
  41. package/examples/towns.html +50 -0
  42. package/examples/towns.js +325 -0
  43. package/examples/viaduct-camera.js +8 -4
  44. package/examples/viaduct-landscape.js +28 -17
  45. package/examples/viaduct.html +45 -43
  46. package/examples/viaduct.js +68 -92
  47. package/geometry/animal-camel-body.js +410 -0
  48. package/geometry/animal-camel-head.js +118 -0
  49. package/geometry/animal-canine-body.js +361 -0
  50. package/geometry/animal-canine-breeds.js +316 -0
  51. package/geometry/animal-canine-head.js +337 -0
  52. package/geometry/animal-cattle-body.js +391 -0
  53. package/geometry/animal-cattle-coat.js +42 -0
  54. package/geometry/animal-cattle-head.js +152 -0
  55. package/geometry/animal-hen.js +248 -0
  56. package/geometry/animal-horse-body.js +446 -0
  57. package/geometry/animal-horse-bridle.js +171 -0
  58. package/geometry/animal-horse-coat.js +68 -0
  59. package/geometry/animal-horse-face.js +162 -0
  60. package/geometry/animal-horse-hair.js +304 -0
  61. package/geometry/animal-horse-head.js +133 -0
  62. package/geometry/animal-horse-tack.js +157 -0
  63. package/geometry/animal-options.js +59 -0
  64. package/geometry/animal-shapes.js +21 -0
  65. package/geometry/animal-skin.js +390 -0
  66. package/geometry/builder-cells.js +10 -2
  67. package/geometry/builder-frame.js +2 -1
  68. package/geometry/builder.js +15 -4
  69. package/geometry/card-emblem.js +437 -0
  70. package/geometry/catenary-canvas.js +396 -0
  71. package/geometry/cloth-folds.js +143 -0
  72. package/geometry/crawl-shapes.js +71 -0
  73. package/geometry/creased-sheet.js +7 -2
  74. package/geometry/crowd-dress.js +315 -0
  75. package/geometry/crowd-far.js +174 -0
  76. package/geometry/crowd-look.js +42 -0
  77. package/geometry/crowd-weld.js +218 -0
  78. package/geometry/ear.js +9 -4
  79. package/geometry/erosion.js +7 -4
  80. package/geometry/face-grid.js +26 -6
  81. package/geometry/field-map.js +59 -0
  82. package/geometry/figure-arms.js +339 -0
  83. package/geometry/figure-beard.js +250 -0
  84. package/geometry/figure-body.js +297 -0
  85. package/geometry/figure-bow.js +105 -0
  86. package/geometry/figure-cloak.js +189 -0
  87. package/geometry/figure-clothes.js +337 -0
  88. package/geometry/figure-face-grids.js +75 -0
  89. package/geometry/figure-gear.js +446 -0
  90. package/geometry/figure-hair-far.js +151 -0
  91. package/geometry/figure-hair-hangs.js +108 -0
  92. package/geometry/figure-hair-patch.js +66 -0
  93. package/geometry/figure-hair.js +320 -0
  94. package/geometry/figure-hands.js +321 -0
  95. package/geometry/figure-head-features.js +280 -0
  96. package/geometry/figure-head.js +375 -0
  97. package/geometry/figure-headwear.js +223 -0
  98. package/geometry/figure-legs.js +231 -0
  99. package/geometry/figure-limbs.js +39 -0
  100. package/geometry/figure-sculpt.js +82 -0
  101. package/geometry/figure-skin.js +97 -0
  102. package/geometry/figure-skirts.js +303 -0
  103. package/geometry/figure-trunk.js +411 -0
  104. package/geometry/flier-corvid-body.js +322 -0
  105. package/geometry/flier-corvid-wings.js +154 -0
  106. package/geometry/flier-long-body.js +195 -0
  107. package/geometry/flier-shapes.js +219 -0
  108. package/geometry/flier-soaring-bird.js +84 -0
  109. package/geometry/foliage.js +177 -4
  110. package/geometry/fort-city-walls.js +479 -0
  111. package/geometry/fort-gate-approach.js +233 -0
  112. package/geometry/fort-great-walls.js +280 -0
  113. package/geometry/fort-keep.js +297 -0
  114. package/geometry/fort-parts.js +261 -0
  115. package/geometry/fort-polyline.js +261 -0
  116. package/geometry/fort-portal.js +96 -0
  117. package/geometry/fort-ring-wall.js +267 -0
  118. package/geometry/fort-seawall.js +104 -0
  119. package/geometry/fort-terrace-gates.js +323 -0
  120. package/geometry/fort-terrace-plan.js +250 -0
  121. package/geometry/fort-terrace-wall.js +345 -0
  122. package/geometry/garment-tags.js +11 -3
  123. package/geometry/grid-gather.js +69 -0
  124. package/geometry/grid-sample.js +185 -0
  125. package/geometry/hair-gathers.js +19 -4
  126. package/geometry/hair-locks.js +1 -1
  127. package/geometry/hair-patch.js +6 -2
  128. package/geometry/hair-shell.js +14 -2
  129. package/geometry/head-presets.js +103 -0
  130. package/geometry/head-profile.js +13 -2
  131. package/geometry/head-shape.js +51 -23
  132. package/geometry/heightfield.js +26 -9
  133. package/geometry/horizon-angles.js +166 -0
  134. package/geometry/house-kit-body.js +195 -0
  135. package/geometry/house-kit-courtyard-parts.js +340 -0
  136. package/geometry/house-kit-courtyard-roof.js +223 -0
  137. package/geometry/house-kit-courtyard.js +409 -0
  138. package/geometry/house-kit-cut.js +29 -0
  139. package/geometry/house-kit-extras.js +192 -0
  140. package/geometry/house-kit-forms.js +298 -0
  141. package/geometry/house-kit-frame.js +74 -0
  142. package/geometry/house-kit-marks.js +93 -0
  143. package/geometry/house-kit-openings.js +193 -0
  144. package/geometry/house-kit-palette.js +54 -0
  145. package/geometry/house-kit-pool.js +71 -0
  146. package/geometry/house-kit-roofs.js +151 -0
  147. package/geometry/house-kit.js +202 -0
  148. package/geometry/instances.js +4 -4
  149. package/geometry/lamp-wash.js +65 -0
  150. package/geometry/land-clearings.js +83 -0
  151. package/geometry/land-ditches.js +290 -0
  152. package/geometry/land-dry-basin.js +327 -0
  153. package/geometry/land-dunes.js +150 -0
  154. package/geometry/land-earthworks.js +432 -0
  155. package/geometry/land-edge.js +292 -0
  156. package/geometry/land-mound-faces.js +349 -0
  157. package/geometry/land-near-relief.js +102 -0
  158. package/geometry/land-sheet.js +220 -0
  159. package/geometry/land-town-ground.js +256 -0
  160. package/geometry/land-waters.js +228 -0
  161. package/geometry/land-wildness.js +123 -0
  162. package/geometry/lathed-vessel.js +293 -0
  163. package/geometry/outline-grid.js +5 -4
  164. package/geometry/outline-segments.js +74 -0
  165. package/geometry/part-ranges.js +35 -0
  166. package/geometry/path-field.js +35 -1
  167. package/geometry/planked-floor.js +149 -0
  168. package/geometry/plant-broadleaf.js +268 -0
  169. package/geometry/plant-shrub.js +198 -0
  170. package/geometry/plant-tints.js +80 -0
  171. package/geometry/plant-trees.js +453 -0
  172. package/geometry/plant-tussock.js +107 -0
  173. package/geometry/primitives.js +65 -23
  174. package/geometry/prop-battlefield.js +69 -0
  175. package/geometry/prop-camp.js +175 -0
  176. package/geometry/prop-door.js +26 -0
  177. package/geometry/prop-harbour.js +105 -0
  178. package/geometry/prop-haycock.js +60 -0
  179. package/geometry/prop-sacks.js +74 -0
  180. package/geometry/prop-sheaf.js +68 -0
  181. package/geometry/prop-street.js +69 -0
  182. package/geometry/prop-tents.js +396 -0
  183. package/geometry/prop-tombs.js +80 -0
  184. package/geometry/prop-trade.js +393 -0
  185. package/geometry/prop-vehicles.js +218 -0
  186. package/geometry/props.js +58 -0
  187. package/geometry/room-arcade.js +134 -0
  188. package/geometry/room-dome.js +188 -0
  189. package/geometry/room-flames.js +138 -0
  190. package/geometry/room-frame.js +106 -0
  191. package/geometry/room-furniture.js +260 -0
  192. package/geometry/room-hearth.js +98 -0
  193. package/geometry/room-kit.js +59 -0
  194. package/geometry/room-openings.js +142 -0
  195. package/geometry/room-stairs.js +180 -0
  196. package/geometry/room-surfaces.js +272 -0
  197. package/geometry/sampled-surface.js +24 -10
  198. package/geometry/scatter-grid.js +6 -3
  199. package/geometry/sculpt.js +5 -1
  200. package/geometry/ship-fittings.js +350 -0
  201. package/geometry/ship-hull.js +460 -0
  202. package/geometry/ship-kit.js +208 -0
  203. package/geometry/ship-lines.js +69 -0
  204. package/geometry/ship-oars.js +150 -0
  205. package/geometry/ship-presets.js +131 -0
  206. package/geometry/ship-rig.js +374 -0
  207. package/geometry/ship-sails.js +148 -0
  208. package/geometry/shore-grid.js +5 -1
  209. package/geometry/strata-field.js +44 -11
  210. package/geometry/strata-tiles.js +20 -6
  211. package/geometry/stream.js +32 -17
  212. package/geometry/swept-tube.js +124 -0
  213. package/geometry/terrain-chunks.js +139 -51
  214. package/geometry/terrain-extension.js +24 -8
  215. package/geometry/town-courtyard-inn.js +272 -0
  216. package/geometry/town-ground.js +76 -0
  217. package/geometry/town-houses.js +343 -0
  218. package/geometry/town-lights.js +254 -0
  219. package/geometry/town-lots.js +172 -0
  220. package/geometry/town-plan.js +370 -0
  221. package/geometry/town-works.js +465 -0
  222. package/geometry/village-layout.js +181 -0
  223. package/geometry/village-yards.js +167 -0
  224. package/geometry/wall-runs.js +64 -0
  225. package/index.js +134 -3
  226. package/math/cloud-textures.js +3 -7
  227. package/math/curve.js +5 -1
  228. package/math/lamp-texels.js +43 -0
  229. package/math/lit-share.js +22 -0
  230. package/math/mountain-ranges.js +177 -54
  231. package/math/periodic.js +6 -0
  232. package/math/rectangles.js +8 -2
  233. package/math/rock-texture.js +17 -12
  234. package/math/surface-textures.js +24 -9
  235. package/math/wandering-path.js +40 -0
  236. package/math/ways.js +120 -0
  237. package/motion/action-dynamics.js +398 -0
  238. package/motion/animal-bearing.js +247 -0
  239. package/motion/animal-canine-bearing.js +178 -0
  240. package/motion/animal-canine-cast.js +131 -0
  241. package/motion/animal-cattle-cast.js +64 -0
  242. package/motion/animal-herd-cast.js +154 -0
  243. package/motion/animal-horse-still.js +161 -0
  244. package/motion/animal-troop-cast.js +43 -0
  245. package/motion/arm-reach.js +3 -2
  246. package/motion/ballistic-arc.js +182 -2
  247. package/motion/biped-cycle.js +4 -2
  248. package/motion/biped-leg.js +4 -1
  249. package/motion/biped-posture.js +459 -0
  250. package/motion/biped-stride.js +142 -32
  251. package/motion/boat-sailing.js +214 -0
  252. package/motion/contact-transition.js +5 -6
  253. package/motion/crowd-alarms.js +36 -6
  254. package/motion/crowd-attention.js +108 -0
  255. package/motion/crowd-beasts.js +203 -0
  256. package/motion/crowd-camp.js +295 -0
  257. package/motion/crowd-figure.js +100 -0
  258. package/motion/crowd-herd.js +86 -0
  259. package/motion/crowd-hold.js +130 -0
  260. package/motion/crowd-pose.js +296 -0
  261. package/motion/crowd-poses.js +481 -0
  262. package/motion/crowd-routine.js +44 -14
  263. package/motion/crowd-town.js +166 -0
  264. package/motion/crowd-water.js +143 -0
  265. package/motion/deck-surface.js +4 -2
  266. package/motion/figure-acts.js +411 -0
  267. package/motion/figure-arms.js +437 -0
  268. package/motion/figure-blade-slide.js +149 -0
  269. package/motion/figure-body-place.js +180 -0
  270. package/motion/figure-bones.js +118 -0
  271. package/motion/figure-bow-draw.js +70 -0
  272. package/motion/figure-fingers.js +215 -0
  273. package/motion/figure-gaze.js +205 -0
  274. package/motion/figure-gestures.js +452 -0
  275. package/motion/figure-grip.js +134 -0
  276. package/motion/figure-head.js +287 -0
  277. package/motion/figure-legs.js +264 -0
  278. package/motion/figure-links.js +293 -0
  279. package/motion/figure-locomotion.js +391 -0
  280. package/motion/figure-mount-up.js +180 -0
  281. package/motion/figure-mount.js +201 -0
  282. package/motion/figure-pose-frame.js +375 -0
  283. package/motion/figure-pose-table.js +156 -0
  284. package/motion/figure-pose.js +343 -0
  285. package/motion/figure-seat.js +267 -0
  286. package/motion/figure-sway.js +125 -0
  287. package/motion/flier-corvid-pose.js +74 -0
  288. package/motion/flier-flight-air.js +122 -0
  289. package/motion/flier-flight-echelon.js +164 -0
  290. package/motion/flier-flight-roost.js +131 -0
  291. package/motion/flier-swarm-flight.js +252 -0
  292. package/motion/formation.js +193 -0
  293. package/motion/instance-sight.js +8 -1
  294. package/motion/melee-contact.js +143 -0
  295. package/motion/moorings.js +48 -0
  296. package/motion/path-steering.js +358 -0
  297. package/motion/player.js +7 -6
  298. package/motion/quadruped.js +109 -33
  299. package/motion/spaces.js +58 -6
  300. package/motion/speech-cadence.js +304 -0
  301. package/motion/vessel-motion.js +57 -0
  302. package/motion/walk-grid.js +235 -0
  303. package/motion/weather.js +70 -12
  304. package/motion/wind.js +27 -1
  305. package/package.json +27 -4
  306. package/rendering/alpha-mips.js +340 -0
  307. package/rendering/animal-camel-figure.js +29 -0
  308. package/rendering/animal-canine-figure.js +59 -0
  309. package/rendering/animal-cattle-figure.js +36 -0
  310. package/rendering/animal-horse-figure.js +49 -0
  311. package/rendering/atmosphere.js +86 -0
  312. package/rendering/camera-track.js +156 -0
  313. package/rendering/{road-surface.js → cart-track.js} +40 -11
  314. package/rendering/caster-motion.js +2 -1
  315. package/rendering/cell-lod-options.js +46 -0
  316. package/rendering/cell-lod.js +665 -80
  317. package/rendering/cloth-material.js +140 -0
  318. package/rendering/cloud-dome.js +2 -2
  319. package/rendering/compilation-schedule.js +18 -10
  320. package/rendering/contact-shadows.js +5 -2
  321. package/rendering/context.js +47 -8
  322. package/rendering/crowd-batches.js +420 -0
  323. package/rendering/crowd-herd.js +198 -0
  324. package/rendering/crowd-rig.js +132 -0
  325. package/rendering/crowd-skinning.js +52 -9
  326. package/rendering/crowd-update.js +419 -0
  327. package/rendering/crowd-visibility.js +107 -0
  328. package/rendering/day-cycle-defaults.js +200 -0
  329. package/rendering/day-cycle.js +487 -0
  330. package/rendering/daylight.js +1 -3
  331. package/rendering/detail-range.js +6 -5
  332. package/rendering/dof.js +11 -4
  333. package/rendering/effects-frame.js +149 -0
  334. package/rendering/effects-water-rises.js +221 -0
  335. package/rendering/energy-stream.js +128 -0
  336. package/rendering/facade-glass-material.js +105 -0
  337. package/rendering/far-shadow.js +81 -54
  338. package/rendering/field-surface.js +138 -0
  339. package/rendering/figure-shield.js +105 -0
  340. package/rendering/figure-skeleton.js +329 -0
  341. package/rendering/fire-light-watch.js +197 -0
  342. package/rendering/fire-pools.js +148 -0
  343. package/rendering/flame-sources.js +86 -0
  344. package/rendering/flier-bird-looks.js +97 -0
  345. package/rendering/flier-corvid-figure.js +67 -0
  346. package/rendering/flier-long-body-company.js +169 -0
  347. package/rendering/flier-swarm.js +186 -0
  348. package/rendering/flocks.js +6 -2
  349. package/rendering/garment-material.js +145 -49
  350. package/rendering/glsl-literal.js +19 -0
  351. package/rendering/ground-marks.js +316 -0
  352. package/rendering/hair-strands.js +38 -24
  353. package/rendering/height-haze.js +80 -33
  354. package/rendering/height-probe.js +15 -3
  355. package/rendering/house-kit-meshes.js +124 -0
  356. package/rendering/interior-bake.js +807 -0
  357. package/rendering/label-layout.js +13 -3
  358. package/rendering/label-range.js +5 -2
  359. package/rendering/lamp-light-map.js +159 -0
  360. package/rendering/lamp-maps.js +62 -0
  361. package/rendering/lamp-wash.js +51 -0
  362. package/rendering/light-budget.js +19 -3
  363. package/rendering/light-points.js +21 -5
  364. package/rendering/local-lights.js +27 -7
  365. package/rendering/material-lod.js +5 -6
  366. package/rendering/memory-estimate.js +84 -0
  367. package/rendering/moored-fleet.js +186 -0
  368. package/rendering/part-costs.js +104 -0
  369. package/rendering/particle-bursts.js +386 -0
  370. package/rendering/particle-emitters.js +61 -25
  371. package/rendering/particle-light-bursts.js +189 -0
  372. package/rendering/particles.js +134 -34
  373. package/rendering/pen-flocks.js +118 -0
  374. package/rendering/piece-batch.js +282 -6
  375. package/rendering/planar-reflection-options.js +159 -0
  376. package/rendering/planar-reflection.js +780 -77
  377. package/rendering/plant-cells.js +122 -0
  378. package/rendering/plant-reeds.js +113 -0
  379. package/rendering/plant-shade-trees.js +239 -0
  380. package/rendering/plant-tuft-patch.js +122 -0
  381. package/rendering/post-shaders.js +84 -21
  382. package/rendering/post.js +39 -19
  383. package/rendering/pressed-cover.js +135 -0
  384. package/rendering/prop-dig.js +136 -0
  385. package/rendering/room-light.js +250 -0
  386. package/rendering/room-materials.js +78 -0
  387. package/rendering/room-space.js +111 -0
  388. package/rendering/scene-lights.js +106 -0
  389. package/rendering/sea-shaders.js +83 -26
  390. package/rendering/settlement-approach.js +226 -0
  391. package/rendering/settlement-dissolve.js +89 -0
  392. package/rendering/settlement-quarter-warm.js +55 -0
  393. package/rendering/settlement-quarter.js +477 -0
  394. package/rendering/settlement-switch.js +42 -0
  395. package/rendering/settlement-town.js +110 -0
  396. package/rendering/shader-warmup.js +80 -36
  397. package/rendering/shadow-depth.js +40 -18
  398. package/rendering/ship-meshes.js +150 -0
  399. package/rendering/shot-cuts.js +68 -0
  400. package/rendering/sky-occlusion.js +42 -15
  401. package/rendering/sky-pmrem.js +216 -0
  402. package/rendering/sky.js +112 -50
  403. package/rendering/smoke-shadows.js +201 -0
  404. package/rendering/stage-framing.js +182 -0
  405. package/rendering/stage-lights.js +46 -39
  406. package/rendering/stain-material.js +74 -0
  407. package/rendering/static-point-shadow.js +62 -23
  408. package/rendering/still-casters.js +77 -27
  409. package/rendering/strata-material.js +2 -2
  410. package/rendering/street-lamps.js +166 -0
  411. package/rendering/sunbeam-motes.js +670 -0
  412. package/rendering/surface-light.js +65 -6
  413. package/rendering/surface-material.js +306 -0
  414. package/rendering/surface-projection.js +32 -0
  415. package/rendering/surface-snippets.js +314 -0
  416. package/rendering/taa.js +49 -18
  417. package/rendering/tree-impostor.js +929 -0
  418. package/rendering/vehicle-train.js +92 -0
  419. package/rendering/viewport.js +67 -4
  420. package/rendering/water-material.js +270 -82
  421. package/rendering/waypoint-beacons.js +191 -0
  422. package/rendering/world-matrices.js +0 -2
  423. package/ruff.toml +20 -0
  424. package/runtime/cue-cursor.js +21 -0
  425. package/runtime/device-quality.js +13 -2
  426. package/runtime/device.js +73 -0
  427. package/runtime/diagnostic-log.js +11 -3
  428. package/runtime/effect-sites.js +85 -0
  429. package/runtime/figure-orders.js +59 -0
  430. package/runtime/first-use.js +8 -5
  431. package/runtime/foley-script.js +124 -0
  432. package/runtime/foley-strides.js +333 -0
  433. package/runtime/frame-pacing.js +18 -4
  434. package/runtime/frame-yield.js +18 -0
  435. package/runtime/gpu-timing.js +8 -4
  436. package/runtime/grid-cache.js +16 -6
  437. package/runtime/grid-rows.js +5 -5
  438. package/runtime/hand-over.js +7 -2
  439. package/runtime/land-bake.js +78 -0
  440. package/runtime/lazy-sets.js +105 -0
  441. package/runtime/pool.js +17 -3
  442. package/runtime/quality-fit.js +59 -27
  443. package/runtime/region-pass-lay.js +40 -0
  444. package/runtime/region-pass.js +78 -0
  445. package/runtime/search.js +6 -2
  446. package/runtime/settlement-reach.js +42 -0
  447. package/runtime/sound-calls.js +113 -0
  448. package/runtime/sound-impacts.js +297 -0
  449. package/runtime/sound-voices.js +194 -0
  450. package/runtime/soundscape.js +282 -0
  451. package/runtime/spatial-audio.js +69 -20
  452. package/runtime/steady-frames.js +221 -0
  453. package/runtime/withdrawable-task.js +19 -8
  454. package/scripts/app-parts.mjs +118 -0
  455. package/scripts/bake-revisions.mjs +81 -0
  456. package/scripts/browser-scripts.mjs +64 -0
  457. package/scripts/bundle.mjs +192 -0
  458. package/scripts/check-app.sh +26 -0
  459. package/scripts/eslint-config.mjs +119 -0
  460. package/scripts/format.sh +92 -0
  461. package/scripts/keep-builds.mjs +158 -0
  462. package/scripts/layers.mjs +112 -0
  463. package/scripts/lint.sh +49 -0
  464. package/scripts/module-graph.mjs +123 -0
  465. package/scripts/pre-commit.sh +38 -0
  466. package/scripts/serve.py +5 -3
  467. package/scripts/site.mjs +358 -0
  468. package/scripts/test-runner.sh +42 -0
  469. package/scripts/vendor.mjs +221 -0
  470. package/scripts/verify-publish.mjs +175 -0
  471. package/scripts/world.mk +59 -0
  472. package/tools/README.md +73 -0
  473. package/tools/contact-sheet.cjs +137 -0
  474. package/tools/cpu-profile.cjs +275 -0
  475. package/tools/cpu-profile.test.cjs +98 -0
  476. package/tools/first-draws.cjs +395 -0
  477. package/tools/flight-guard.cjs +482 -0
  478. package/tools/flight-guard.test.cjs +153 -0
  479. package/tools/flight-profile.cjs +145 -0
  480. package/tools/frame-bench.cjs +336 -0
  481. package/tools/frame-parts.cjs +365 -0
  482. package/tools/ios-sim.sh +145 -0
  483. package/tools/load-audit.cjs +201 -0
  484. package/tools/look-compare.cjs +304 -0
  485. package/tools/look-guard.cjs +407 -0
  486. package/tools/look-guard.test.cjs +93 -0
  487. package/tools/look-stats.cjs +185 -0
  488. package/tools/look-stats.test.cjs +71 -0
  489. package/tools/memory-audit.cjs +323 -0
  490. package/tools/page-driver.cjs +320 -0
  491. package/tools/page-driver.test.cjs +219 -0
  492. package/tools/program-census-report.cjs +191 -0
  493. package/tools/program-census.cjs +465 -0
  494. package/tools/program-census.test.cjs +332 -0
  495. package/tools/remote-runner.sh +265 -0
  496. package/tools/runners.test.cjs +59 -0
  497. package/tools/scene-audit-beat.cjs +344 -0
  498. package/tools/scene-audit-sheet.cjs +282 -0
  499. package/tools/scene-audit.cjs +471 -0
  500. package/tools/scene-audit.test.cjs +201 -0
  501. package/tools/scene-batch.cjs +219 -0
  502. package/tools/scene-bench.cjs +149 -0
  503. package/tools/scene-bench.test.cjs +33 -0
  504. package/tools/scene-run.cjs +443 -0
  505. package/tools/scene-run.test.cjs +94 -0
  506. package/tools/servers.sh +59 -0
  507. package/tools/shader-arrival.cjs +316 -0
  508. package/tools/shader-renewal.cjs +53 -0
  509. package/tools/shader-renewal.test.cjs +115 -0
  510. package/tools/speed-guard.cjs +258 -0
  511. package/tools/stills.cjs +492 -0
  512. package/tools/stills.test.cjs +49 -0
  513. package/tools/turns.sh +7 -0
  514. package/tools/yaml.cjs +158 -0
  515. package/examples/viaduct.css +0 -75
  516. package/rendering/light-shafts.js +0 -131
@@ -0,0 +1,329 @@
1
+ /**
2
+ * A person's skeleton and the figure put together on it (createFigureAssembler): the bones every figure is skinned to
3
+ * (motion/figure-bones.js), the near and far meshes of its body (geometry/figure-body.js) bound to them, the grips of its hands,
4
+ * and the mount it rides.
5
+ * @module
6
+ */
7
+ import * as THREE from 'three';
8
+ import { FIGURE_HOLDS } from '../geometry/figure-gear.js';
9
+ import { handGirth } from '../geometry/figure-limbs.js';
10
+ import { BOW, TIP_BACK, bowGrip } from '../geometry/figure-bow.js';
11
+ import { HAND_JOINTS, bendingHands } from '../motion/figure-fingers.js';
12
+ import { hangFingers, newGrip } from '../motion/figure-grip.js';
13
+ import {
14
+ ANKLE,
15
+ ARM_L,
16
+ ARM_R,
17
+ BALL,
18
+ BELT,
19
+ BROW_L,
20
+ BROW_R,
21
+ CAPE_L,
22
+ CAPE_R,
23
+ CHEST,
24
+ CHEST_AT,
25
+ CLOAK,
26
+ CLOAK_LOW,
27
+ EYE_L,
28
+ EYE_R,
29
+ FOOT_L,
30
+ FOOT_R,
31
+ FOREARM,
32
+ FORE_L,
33
+ FORE_R,
34
+ GRIP,
35
+ HAIR,
36
+ HAND_L,
37
+ HAND_R,
38
+ HEAD,
39
+ HIPS,
40
+ ITEM_L,
41
+ ITEM_R,
42
+ JAW,
43
+ LEG_L,
44
+ LEG_R,
45
+ LIDS,
46
+ MOUTH_L,
47
+ MOUTH_R,
48
+ OPEN_L,
49
+ OPEN_R,
50
+ PELVIS,
51
+ ROOT,
52
+ SHANK,
53
+ SHIN_L,
54
+ SHIN_R,
55
+ SHOULDERS,
56
+ STOWED,
57
+ STRING_DOWN,
58
+ STRING_UP,
59
+ THIGH,
60
+ TOE_L,
61
+ TOE_R,
62
+ UPPER_ARM,
63
+ } from '../motion/figure-bones.js';
64
+
65
+ // The near mesh may come later than the far one: until it does, it has no skin of its own (NO_SKIN) and stays hidden.
66
+ // Where each joint is, in figure units (a figure of full size stands 1.9 m): the neck, the cloak's hang, the belt (the arms'
67
+ // joints are figure-bones.js's).
68
+ const NECK = 1.53,
69
+ CLOAK_AT = [0, 1.47, -0.03],
70
+ CLOAK_SEAT = [0, 0.95, -0.12], // the lower cape's hinge: where the cape falls onto the seat, behind it
71
+ BELT_AT = 1.03,
72
+ JAW_AT = [1.655, -0.005], // the jaw's hinge: height and depth
73
+ NAPE = [1.5, -0.07]; // where hanging hair swings from: height and depth
74
+ const HIDDEN = 0.001, // the scale of a bone whose part is not shown: too small to see, never zero
75
+ FIGURE_HEIGHT = 1.9, // metres a figure of full size stands, and how much higher a rider is
76
+ RIDER = 0.8;
77
+ // The middle of an archer's grip on the bow, from the bone of what the bow hand holds (figure-bow.js).
78
+ function bowGripOf(sx, hold) {
79
+ const grip = bowGrip(sx, hold.r);
80
+ return [grip[0] + sx, grip[1] - (SHOULDERS - UPPER_ARM - FOREARM - GRIP), grip[2]];
81
+ }
82
+ const Y_AXIS = new THREE.Vector3(0, 1, 0),
83
+ _aim = new THREE.Vector3();
84
+ // The bones, joined as a body is, with the near figure's eyes, brows and lids where its head put them. `hold`: how what
85
+ // the figure carries is held (a row of the holds), if anything; `bends`: which of its hands have fingers that bend
86
+ // (bendingHands), whose bones follow the body's own; `joints`: their fingers' bones (handOf).
87
+ function skeleton(near, hold, bends, joints) {
88
+ const bone = [];
89
+ for (let i = 0; i < bends.bones; i++) bone.push(new THREE.Bone());
90
+ // the chest turns on the hips at the small of the back, and carries the head, the arms and the cloak; the hips carry the belt
91
+ bone[PELVIS].position.set(0, HIPS, 0);
92
+ bone[CHEST].position.set(0, CHEST_AT, 0);
93
+ bone[HEAD].position.set(0, NECK - CHEST_AT, 0);
94
+ bone[ARM_L].position.set(-near.sx, SHOULDERS - CHEST_AT, 0);
95
+ bone[FORE_L].position.set(0, -UPPER_ARM, 0);
96
+ bone[ARM_R].position.set(near.sx, SHOULDERS - CHEST_AT, 0);
97
+ bone[CAPE_L].position.set(-near.sx, SHOULDERS - CHEST_AT, 0);
98
+ bone[CAPE_R].position.set(near.sx, SHOULDERS - CHEST_AT, 0);
99
+ bone[FORE_R].position.set(0, -UPPER_ARM, 0);
100
+ bone[LEG_L].position.set(-near.lx, HIPS, 0);
101
+ bone[SHIN_L].position.set(0, -THIGH, 0);
102
+ bone[LEG_R].position.set(near.lx, HIPS, 0);
103
+ bone[SHIN_R].position.set(0, -THIGH, 0);
104
+ for (const [foot, toes] of [
105
+ [FOOT_L, TOE_L],
106
+ [FOOT_R, TOE_R],
107
+ ]) {
108
+ bone[foot].position.set(0, -SHANK, 0);
109
+ bone[toes].position.set(0, -ANKLE, BALL); // on the ground under the ball of the foot, where the foot rolls up onto its toes
110
+ bone[foot].add(bone[toes]);
111
+ }
112
+ bone[CLOAK].position.set(CLOAK_AT[0], CLOAK_AT[1] - CHEST_AT, CLOAK_AT[2]);
113
+ bone[CLOAK_LOW].position.set(CLOAK_SEAT[0] - CLOAK_AT[0], CLOAK_SEAT[1] - CLOAK_AT[1], CLOAK_SEAT[2] - CLOAK_AT[2]);
114
+ bone[LIDS].position.set(0, near.eyeP[1] - NECK, near.eyeP[2]);
115
+ bone[JAW].position.set(0, JAW_AT[0] - NECK, JAW_AT[1]);
116
+ bone[HAND_L].position.set(0, -FOREARM, 0);
117
+ bone[HAND_R].position.set(0, -FOREARM, 0);
118
+ bone[ITEM_R].position.set(0, -GRIP, 0);
119
+ bone[ITEM_L].position.set(0, -GRIP, 0);
120
+ bone[BELT].position.set(0, BELT_AT - HIPS, 0);
121
+ bone[HAIR].position.set(0, NAPE[0] - CHEST_AT, NAPE[1]);
122
+ bone[BROW_L].position.set(-near.browP[0], near.browP[1] - NECK, near.browP[2]);
123
+ bone[BROW_R].position.set(near.browP[0], near.browP[1] - NECK, near.browP[2]);
124
+ bone[EYE_L].position.set(-near.eyeP[0], near.eyeP[1] - NECK, near.eyeP[2]);
125
+ bone[EYE_R].position.set(near.eyeP[0], near.eyeP[1] - NECK, near.eyeP[2]);
126
+ // the legs hang from the root, not from the hips: the hips' turn and list move the legs' joints (motion/biped-leg.js)
127
+ // without turning the legs, which are solved from joint to planted sole
128
+ bone[ROOT].add(bone[PELVIS], bone[CHEST], bone[LEG_L], bone[LEG_R]);
129
+ bone[PELVIS].add(bone[BELT]);
130
+ bone[CHEST].add(bone[HEAD], bone[ARM_L], bone[ARM_R], bone[CLOAK], bone[CAPE_L], bone[CAPE_R], bone[HAIR]);
131
+ bone[HEAD].add(bone[LIDS], bone[JAW], bone[BROW_L], bone[BROW_R], bone[MOUTH_L], bone[MOUTH_R], bone[EYE_L], bone[EYE_R]);
132
+ bone[CLOAK].add(bone[CLOAK_LOW]);
133
+ bone[ARM_L].add(bone[FORE_L]);
134
+ bone[ARM_R].add(bone[FORE_R]);
135
+ bone[LEG_L].add(bone[SHIN_L]);
136
+ bone[LEG_R].add(bone[SHIN_R]);
137
+ bone[SHIN_L].add(bone[FOOT_L]);
138
+ bone[SHIN_R].add(bone[FOOT_R]);
139
+ bone[FORE_L].add(bone[HAND_L]);
140
+ bone[FORE_R].add(bone[HAND_R]);
141
+ bone[HAND_R].add(bone[ITEM_R], bone[OPEN_R]);
142
+ bone[HAND_L].add(bone[ITEM_L], bone[OPEN_L]);
143
+ bone[BELT].add(bone[STOWED]);
144
+ if (hold && hold.stow === 'back') {
145
+ // what is slung across the back goes with the chest, not with the hips under it
146
+ bone[STOWED].position.set(0, BELT_AT - CHEST_AT, 0);
147
+ bone[CHEST].add(bone[STOWED]);
148
+ }
149
+ bone[ITEM_L].add(bone[STRING_UP], bone[STRING_DOWN]);
150
+ if (hold && hold.bow) {
151
+ // an archer: each half of the string hangs at a tip of the stave and runs to the string's middle, and the arrow (on the
152
+ // bone of what a right hand would hold) is nocked there, in the bow hand's keeping
153
+ const [x, y, z] = bowGripOf(near.sx, hold);
154
+ bone[STRING_UP].position.set(x, y + TIP_BACK, z + BOW.half);
155
+ bone[STRING_UP].quaternion.setFromUnitVectors(Y_AXIS, _aim.set(0, 0, -1));
156
+ bone[STRING_DOWN].position.set(x, y + TIP_BACK, z - BOW.half);
157
+ bone[STRING_DOWN].quaternion.setFromUnitVectors(Y_AXIS, _aim.set(0, 0, 1));
158
+ bone[ITEM_R].position.set(x, y + TIP_BACK, z);
159
+ bone[ITEM_L].add(bone[ITEM_R]);
160
+ }
161
+ if (bends.right >= 0) hangFingers(bone, HAND_R, bends.right, 1, joints);
162
+ if (bends.left >= 0) hangFingers(bone, HAND_L, bends.left, -1, joints);
163
+ return bone;
164
+ }
165
+ const SHADOW_SPHERE = [0, 0.95, 0, 2.4]; // a figure's bounds, centre and radius, whatever its pose
166
+ /** The near mesh's geometry until its body has come: no skin of its own, so that it draws nothing. */
167
+ const NO_SKIN = new THREE.BufferGeometry();
168
+ // Two meshes on one skeleton: the full figure up close (near), and a version of about a sixth of the triangles from a distance
169
+ // (far). Returns the figure: its group, its meshes, the bones an actor moves and what it holds and wears. `near` may be null:
170
+ // the far body then sets the bones, which both bodies place alike.
171
+ function assembleFigure(own, L, kind, far, near) {
172
+ const { sx, lx, robe } = far,
173
+ hold = own.holds[L.item] || null,
174
+ joints = own.fingerJoints?.(L) ?? HAND_JOINTS;
175
+ const material = typeof own.material === 'function' ? own.material() : own.material,
176
+ g = new THREE.Group(),
177
+ mesh = new THREE.SkinnedMesh(near ? near.geo : NO_SKIN, material),
178
+ farMesh = new THREE.SkinnedMesh(far.geo, material),
179
+ bends = bendingHands(L, hold, joints),
180
+ bone = skeleton(far, hold, bends, joints);
181
+ mesh.add(bone[ROOT]);
182
+ bone[ROOT].updateMatrixWorld(true);
183
+ const skel = new THREE.Skeleton(bone);
184
+ mesh.bind(skel);
185
+ farMesh.bind(skel, mesh.bindMatrix);
186
+ bone[LIDS].rotation.x = -far.lidA;
187
+ if (hold && hold.stow) {
188
+ bone[ITEM_R].scale.setScalar(HIDDEN);
189
+ bone[ITEM_L].scale.setScalar(HIDDEN);
190
+ }
191
+ const hands = handGirth(L.w || 1),
192
+ kept = hold && hold.r && !hold.stow ? hold.r : 0, // the radius of what a hand holds for good, which it is closed on from the start
193
+ // the grips of the hands whose fingers bend (motion/figure-grip.js): open, but for a hand that holds something for good
194
+ gripR = bends.right >= 0 ? newGrip(bone, bends.right, 1, joints, hands, hold && hold.left ? 0 : kept) : null,
195
+ gripL = bends.left >= 0 ? newGrip(bone, bends.left, -1, joints, hands, hold?.left || hold?.both ? kept : 0) : null;
196
+ if (L.handless) {
197
+ // arms that end at the wrist
198
+ bone[HAND_L].scale.setScalar(HIDDEN);
199
+ bone[HAND_R].scale.setScalar(HIDDEN);
200
+ } else
201
+ for (const [hand, item] of [
202
+ [HAND_L, ITEM_L],
203
+ [HAND_R, ITEM_R],
204
+ ]) {
205
+ bone[hand].scale.setScalar(hands);
206
+ bone[item].scale.multiplyScalar(1 / hands); // what is held keeps its own size in a larger hand
207
+ }
208
+ const wear = new THREE.Vector4(0, 0, 0, 0),
209
+ applyActorWear = (renderer, passScene, _camera, _geometry, material) => {
210
+ const uWear = material?.userData?.uActorWear;
211
+ if (passScene?.overrideMaterial || !uWear) return;
212
+ uWear.value.copy(wear);
213
+ // The material is every figure's, and Three.js uploads a material's uniforms only when a draw changes program or
214
+ // material, so a figure drawn after another would keep the other's wear. The program is let go of instead, never made
215
+ // current here: the figure's draw is then a first use, at which Three.js uploads the camera, the lights and every
216
+ // uniform, this wear among them. A program this hook made current itself looked current to Three.js, which then skipped
217
+ // the camera: the figures were drawn with the lens and the place of an earlier shot, small and astray or out of sight,
218
+ // while their shadows and labels stood right.
219
+ renderer.state.useProgram(null);
220
+ };
221
+ for (const m of [mesh, farMesh]) {
222
+ m.castShadow = true;
223
+ m.receiveShadow = true;
224
+ m.boundingSphere = new THREE.Sphere(new THREE.Vector3(SHADOW_SPHERE[0], SHADOW_SPHERE[1], SHADOW_SPHERE[2]), SHADOW_SPHERE[3]);
225
+ m.layers.set(1);
226
+ m.onBeforeRender = applyActorWear;
227
+ g.add(m);
228
+ }
229
+ mesh.visible = !!near;
230
+ farMesh.visible = !near;
231
+ const draped = L.cloak || L.hood || L.garb === 'fur', // a cloak's sides, or a mantle's, hang on bones of their own beside the arms
232
+ tall = L.h || 1,
233
+ wide = tall * (L.slim || 1); // a slender people are taller for their breadth
234
+ g.scale.set(wide, tall, wide);
235
+ // a rider: the mount hangs under the figure, unscaled by the rider's height; whoever moves the figure keeps it on the ground
236
+ const mount = L.horse && own.mount ? own.mount(L, far) : null;
237
+ if (mount) {
238
+ mount.mesh.scale.setScalar(1 / (L.h || 1));
239
+ mount.mesh.layers.set(1);
240
+ g.add(mount.mesh);
241
+ }
242
+ return {
243
+ group: g,
244
+ hi: mesh,
245
+ lo: farMesh,
246
+ wear,
247
+ mount,
248
+ armL: bone[ARM_L],
249
+ armR: bone[ARM_R],
250
+ foreL: bone[FORE_L],
251
+ foreR: bone[FORE_R],
252
+ legL: bone[LEG_L],
253
+ legR: bone[LEG_R],
254
+ shinL: bone[SHIN_L],
255
+ shinR: bone[SHIN_R],
256
+ footL: bone[FOOT_L],
257
+ footR: bone[FOOT_R],
258
+ toesL: bone[TOE_L],
259
+ toesR: bone[TOE_R],
260
+ robe,
261
+ armClear: far.clear || 0, // how far out its arms hang at rest to clear a robe (figure-clothes.js)
262
+ sheaths: far.sheaths || null, // where a blade it wears lies put away, which it draws along its length
263
+ cloak: L.cloak ? bone[CLOAK] : null,
264
+ cloakLow: L.cloak ? bone[CLOAK_LOW] : null,
265
+ capeL: draped ? bone[CAPE_L] : null,
266
+ capeR: draped ? bone[CAPE_R] : null,
267
+ head: bone[HEAD],
268
+ root: bone[ROOT],
269
+ pelvis: bone[PELVIS],
270
+ chest: bone[CHEST],
271
+ sx,
272
+ lx,
273
+ height: FIGURE_HEIGHT * (L.h || 1) + (mount ? RIDER : 0),
274
+ kind,
275
+ lid: far.lidA ? bone[LIDS] : null,
276
+ lidA: far.lidA,
277
+ jaw: bone[JAW],
278
+ handL: bone[HAND_L],
279
+ handR: bone[HAND_R],
280
+ itemR: bone[ITEM_R],
281
+ itemL: bone[ITEM_L],
282
+ openR: bone[OPEN_R], // the open fingers of a hand whose weapon is put away, which show while it is
283
+ openL: bone[OPEN_L],
284
+ itemSize: 1 / hands, // an item's scale in its hand, drawn
285
+ gripR,
286
+ gripL,
287
+ worn: bone[BELT],
288
+ sheath: bone[STOWED],
289
+ hold,
290
+ hair: far.hs,
291
+ hairBone: far.hs ? bone[HAIR] : null, // what of their hair hangs below the nape swings on it,
292
+ bow: hold && hold.bow ? { grip: new THREE.Vector3(...bowGripOf(far.sx, hold)), up: bone[STRING_UP], down: bone[STRING_DOWN] } : null, // an archer's
293
+ gearSwings: L.item === 'satchel' || !!(hold && (hold.stow === 'hip' || hold.stow === 'belt')), // and what hangs at the belt on the belt's
294
+ nearBuilt: !!near,
295
+ face: far.lidA
296
+ ? {
297
+ brow: [bone[BROW_L], bone[BROW_R]],
298
+ corner: [bone[MOUTH_L], bone[MOUTH_R]],
299
+ eye: [bone[EYE_L], bone[EYE_R]],
300
+ browY: far.browP[1] - NECK,
301
+ browX: far.browP[0],
302
+ browZ: far.browP[2],
303
+ }
304
+ : null,
305
+ };
306
+ }
307
+
308
+ /**
309
+ * A figure assembler: puts a person's figure together from the bodies a figure builder made of their look (createFigureBuilder's
310
+ * buildBody, its `parts` made into a BufferGeometry `geo`): two skinned meshes on one skeleton, the near one up close and the far
311
+ * one, of about a sixth of the triangles, from a distance, with the grips of the hands whose fingers bend and the mount it
312
+ * rides. The meshes are drawn on layer 1, and the figure's `wear` (a Vector4) is handed to the material's `uActorWear` uniform,
313
+ * if it has one, before each is drawn.
314
+ * @param {object} options
315
+ * @param {THREE.Material|function(): THREE.Material} options.material - The skinned material both meshes are drawn with, or
316
+ * what gives it when a figure is first put together (for a page whose materials are made after its modules load).
317
+ * @param {Object<string, object>} [options.holds=FIGURE_HOLDS] - How each kind of thing is carried: the figure builder's kit's.
318
+ * @param {function(object): ?number[]} [options.fingerJoints] - The lengths of a look's finger bones: the builder's kit's.
319
+ * @param {function(object, object): ?{mesh: THREE.Object3D}} [options.mount] - Builds the mount of a look that rides
320
+ * (`horse`), from the look and its far body; its mesh is hung under the figure.
321
+ * @returns {{assembleFigure: function(object, string, object, ?object): object}} assembleFigure(look, kind, far, near): the
322
+ * figure, its group, meshes, bones, grips and mount; `near` may be null until the near body has come.
323
+ */
324
+ function createFigureAssembler({ material, holds = FIGURE_HOLDS, fingerJoints, mount } = {}) {
325
+ const own = { material, holds, fingerJoints, mount };
326
+ return { assembleFigure: (L, kind, far, near) => assembleFigure(own, L, kind, far, near) };
327
+ }
328
+
329
+ export { NO_SKIN, createFigureAssembler };
@@ -0,0 +1,197 @@
1
+ import * as THREE from 'three';
2
+ import { createLightBudget, createShadowRedraw } from './light-budget.js';
3
+ import { createFirePools } from './fire-pools.js';
4
+
5
+ // ════════════════════════════════════════════════════════════════════════
6
+ // The night's own lights, watched for a world. Every flame that lights what is round it is a site in the world's list: a fire
7
+ // (`type: 'fire'`, which also sends up flames and smoke) or a light alone (`type: 'light'`: a lantern, a spell's glow), each
8
+ // known by its flame record (`createFlameSources`); and a world's street lamps may be watched as well. A few times a second the
9
+ // few that matter most, the nearest and strongest in view, are each handed one of a small set of real point lights made once at
10
+ // start-up, before any shader is compiled (`createLightBudget`). A light changing hands fades out and in again by intensity, and
11
+ // is never switched off; each frame it flickers with its flame. A fire on the ground that holds no real light lays a cheap pool
12
+ // of light round it instead (`createFirePools`), which fades as a real light takes it over, so a camp seen from the air still
13
+ // reads lit. Short flashes and a moving spell's light take their turn among the fires.
14
+ // ════════════════════════════════════════════════════════════════════════
15
+ const LEAST_AMBIENT = 0.02, // the least light from the sky reckoned with, so a pool on a black night is not boundless
16
+ SHADOW = { near: 0.25, bias: -0.004, normalBias: 0.03 }, // the first light's shadow camera's near plane (metres) and its biases
17
+ FLASH_REACH = { least: 4, perLight: 2 }, // metres a flash's light reaches: the least, and more by the root of its strength
18
+ SPELL_REACH = 5; // metres: a spell's bright patch on a figure or wall spans a few; a fire's wide reach would light a whole cliff
19
+
20
+ /**
21
+ * The night's lights of a world.
22
+ *
23
+ * @param {object} options
24
+ * @param {THREE.Object3D} options.parent Where the lights and pools are added (the scene).
25
+ * @param {THREE.Camera} options.camera The viewer.
26
+ * @param {object[]} options.sites The world's effect sites (`runtime/effect-sites.js`); the fires and lights among them are
27
+ * watched, and flashes and spells are added to it.
28
+ * @param {(site: object) => object} options.flameOf A site's flame record (`createFlameSources`' `sourceOf`, kept on the site).
29
+ * @param {(lamp: object) => object} [options.lampOf] A street lamp's flame record, for the lamps given to `watchLamps`.
30
+ * @param {(source: object, t: number) => number} options.flicker A flame's flicker at clock t.
31
+ * @param {(source: object, night: number) => number} options.hourShare The share of its power a flame gives at the hour.
32
+ * @param {() => number} options.elapsed The clock, in seconds.
33
+ * @param {() => number} options.frame The frame's number.
34
+ * @param {() => string} options.spaceId The space the viewer is in: only its fires are watched, and the lamps only in `openSpace`.
35
+ * @param {(x: number, z: number) => number} options.ground The ground's height in the viewer's space, for the pools.
36
+ * @param {() => number} options.openLight The light on open ground from the sky and the moon, which a pool is reckoned against.
37
+ * @param {() => number} options.direct The share of the light that falls straight (`createFirePools`' `shade`).
38
+ * @param {object} [options.stillShadow] The first light's kept picture of what stands still (`createStaticPointShadow`): `keep(light)`
39
+ * and `stale()`; none to draw everything each time.
40
+ * @param {(x: number, y: number, z: number, reach: number) => boolean} [options.stirs] Whether something moved within `reach` of
41
+ * the flame (`createCasterMotion`); none redraws the shadow while lit.
42
+ * @param {number} [options.count=5] Real point lights: each adds its share to the shading of every lit surface, so few.
43
+ * @param {Record<string, number>} [options.shadowMaps={ low: 0, medium: 256, high: 512 }] The side of each face of the first
44
+ * light's shadow, by quality preset (0: none).
45
+ * @param {number} [options.shadowReach=14] Metres round its flame that the first light's shadow takes in.
46
+ * @param {Record<string, string>} [options.poolDefines] Shader defines for the pools' material.
47
+ * @param {string} [options.openSpace='world'] The space street lamps stand in.
48
+ * @param {string} [options.spellKind='glow'] The flame kind of a spell's moving light (as strong by day as by night).
49
+ * @returns {object} `build(preset)` makes the lights (before any shader is compiled); `fitShadow(preset)` sizes the first light's
50
+ * shadow for a quality preset; `update(dt, night)` each frame (night: 0 by day, 1 at night); `watchLamps(list)`; `flash(x, y, z,
51
+ * tint, light, life)` a short light; `spell(r, g, b)` a moving light, `{ move(point, power), release() }`; `soon()` chooses again
52
+ * in the coming frame; and `lead`, the brightest fire light now ({ position, intensity, on }).
53
+ */
54
+ export function createFireLightWatch({
55
+ parent,
56
+ camera,
57
+ sites,
58
+ flameOf,
59
+ lampOf = null,
60
+ flicker,
61
+ hourShare,
62
+ elapsed,
63
+ frame,
64
+ spaceId,
65
+ ground,
66
+ openLight,
67
+ direct,
68
+ stillShadow = null,
69
+ stirs = null,
70
+ count = 5,
71
+ shadowMaps = { low: 0, medium: 256, high: 512 },
72
+ shadowReach = 14,
73
+ poolDefines = null,
74
+ openSpace = 'world',
75
+ spellKind = 'glow',
76
+ }) {
77
+ let budget = null,
78
+ pools = null,
79
+ lamps = null;
80
+ const lead = { position: new THREE.Vector3(), intensity: 0, on: false };
81
+ const strength = (rec, night) => rec.power * hourShare(rec, night);
82
+ // The shadow is six draws of what moves round the flame over the picture of what stands still: only while the light is up, at
83
+ // most every other frame (people move slowly against the time it takes), and only when something within its reach moved.
84
+ const redrawShadow = createShadowRedraw({ every: 2, anyway: 30 }),
85
+ stirsNear = stirs ? (x, y, z) => stirs(x, y, z, shadowReach) : () => true,
86
+ stale = stillShadow ? stillShadow.stale : () => false;
87
+
88
+ function build(preset) {
89
+ budget = createLightBudget({ parent, strength, flicker, count });
90
+ const shadow = budget.lights[0].shadow;
91
+ shadow.camera.near = SHADOW.near;
92
+ shadow.camera.far = shadowReach;
93
+ shadow.bias = SHADOW.bias;
94
+ shadow.normalBias = SHADOW.normalBias;
95
+ shadow.autoUpdate = false; // redrawn only while the light is lit, every other frame (update)
96
+ stillShadow?.keep(budget.lights[0]);
97
+ fitShadow(preset);
98
+ pools = createFirePools({ parent, flicker, defines: poolDefines });
99
+ pools.build();
100
+ }
101
+ function fitShadow(preset) {
102
+ const L = budget.lights[0],
103
+ size = shadowMaps[preset] ?? 0;
104
+ if (L.castShadow !== size > 0) L.castShadow = size > 0;
105
+ if (size && L.shadow.mapSize.x !== size) {
106
+ L.shadow.mapSize.set(size, size);
107
+ L.shadow.map?.dispose();
108
+ L.shadow.map = null;
109
+ }
110
+ }
111
+
112
+ // Chooses the flames that hold the real lights, and those that lay pools: every fire and light of the space the eye is in, and
113
+ // the street lamps by night.
114
+ function choose(night) {
115
+ budget.begin(camera);
116
+ const { x, y, z } = camera.position,
117
+ sid = spaceId();
118
+ for (let i = sites.length - 1; i >= 0; i--) {
119
+ const s = sites[i];
120
+ if ((s.type !== 'fire' && s.type !== 'light') || s.off) continue;
121
+ const rec = flameOf(s);
122
+ if (rec.life && elapsed() - rec.born > rec.life) {
123
+ sites.splice(i, 1); // a flash that has died away
124
+ continue;
125
+ }
126
+ if (rec.space === sid) budget.consider(rec, x, y, z, night);
127
+ }
128
+ if (lamps && sid === openSpace && night > 0.02)
129
+ for (let i = 0; i < lamps.length; i++) budget.consider(lampOf(lamps[i]), x, y, z, night);
130
+ budget.settle();
131
+ pools.lay(budget.pools, ground);
132
+ }
133
+
134
+ function soon() {
135
+ budget?.soon();
136
+ }
137
+
138
+ function update(dt, night) {
139
+ if (budget.due(dt)) choose(night);
140
+ const t = elapsed(),
141
+ lights = budget.lights,
142
+ leading = budget.fadeLights(dt, t, night);
143
+ redrawShadow(lights[0], frame(), stirsNear, stale);
144
+ lead.on = leading >= 0;
145
+ if (leading >= 0) {
146
+ lead.position.copy(lights[leading].position);
147
+ lead.intensity = lights[leading].intensity;
148
+ } else lead.intensity = 0;
149
+ pools.shade(budget.pools, night / Math.max(openLight(), LEAST_AMBIENT), t, direct());
150
+ }
151
+
152
+ // A short-lived light (a script's cue, a particle's impact), drawn from the same budget.
153
+ function flash(x, y, z, tint, light, life) {
154
+ const site = { space: spaceId(), type: 'light', kind: 'flash', x, y, z, tint, light, life, rate: 0, born: elapsed(), scene: true };
155
+ flameOf(site).reach = FLASH_REACH.least + FLASH_REACH.perLight * Math.sqrt(light);
156
+ sites.push(site);
157
+ soon();
158
+ }
159
+
160
+ // A moving spell competes with fires for the same lights. The budget ranks on its scan interval, but a held light follows the
161
+ // spell on every frame.
162
+ function spell(red, green, blue) {
163
+ const site = { type: 'light', kind: spellKind, rate: 0, space: spaceId(), x: 0, y: 0, z: 0, light: 1, tint: [red, green, blue] };
164
+ const source = flameOf(site);
165
+ source.moving = true;
166
+ source.reach = SPELL_REACH;
167
+ sites.push(site);
168
+ soon();
169
+ return {
170
+ move(point, power) {
171
+ source.x = point.x;
172
+ source.y = point.y;
173
+ source.z = point.z;
174
+ source.power = power;
175
+ },
176
+ release() {
177
+ source.power = 0;
178
+ const index = sites.indexOf(site);
179
+ if (index >= 0) sites.splice(index, 1);
180
+ soon();
181
+ },
182
+ };
183
+ }
184
+
185
+ return {
186
+ build,
187
+ fitShadow,
188
+ update,
189
+ flash,
190
+ spell,
191
+ soon,
192
+ lead,
193
+ watchLamps(list) {
194
+ lamps = list;
195
+ },
196
+ };
197
+ }
@@ -0,0 +1,148 @@
1
+ import * as THREE from 'three';
2
+
3
+ const DROP = 0.14, // a flame's height over its pool, as a share of the pool's radius, for the falloff's shape
4
+ LEAST_DROP = 0.6, // metres: the least height over its pool a flame's light is reckoned from
5
+ HIGH = 1.3, // metres: a flame higher than this over the ground under it lays its pool where it is (a fire on a tower's top)
6
+ SLOPE = 2, // metres either side of a fire at which the ground is read for its slope
7
+ LIFT = 0.08, // metres a pool lies over the ground
8
+ GROUND_SEEN = 0.06, // how bright the night's ground shows on screen when drawing direct without HDR, where a pool's light is added to it
9
+ FALL = 64; // texels across the pool's falloff
10
+
11
+ const _m = new THREE.Matrix4(),
12
+ _q = new THREE.Quaternion(),
13
+ _n = new THREE.Vector3(),
14
+ _p = new THREE.Vector3(),
15
+ _s = new THREE.Vector3();
16
+ const UP = new THREE.Vector3(0, 1, 0);
17
+
18
+ // The falloff of a pool's light from its middle to its edge: light from a point over the ground (the share of what falls at
19
+ // its foot), eased to nothing at the pool's edge. In half floats: the faint edge is too dim for a byte.
20
+ function falloff() {
21
+ const data = new Uint16Array(FALL * FALL * 4),
22
+ one = THREE.DataUtils.toHalfFloat(1);
23
+ for (let j = 0; j < FALL; j++)
24
+ for (let i = 0; i < FALL; i++) {
25
+ const u = ((i + 0.5) / FALL) * 2 - 1,
26
+ v = ((j + 0.5) / FALL) * 2 - 1,
27
+ r2 = u * u + v * v,
28
+ w = r2 >= 1 ? 0 : (1 - r2) ** 2 / (1 + r2 / (DROP * DROP)) ** 1.5,
29
+ k = (j * FALL + i) * 4;
30
+ data[k] = data[k + 1] = data[k + 2] = THREE.DataUtils.toHalfFloat(w);
31
+ data[k + 3] = one;
32
+ }
33
+ const t = new THREE.DataTexture(data, FALL, FALL, THREE.RGBAFormat, THREE.HalfFloatType);
34
+ t.magFilter = t.minFilter = THREE.LinearFilter;
35
+ t.needsUpdate = true;
36
+ return t;
37
+ }
38
+
39
+ /**
40
+ * The pools of light that fires on the ground lay round them where no real light lights them: a disc on the ground under each,
41
+ * which brightens what is drawn there by the fire's light as light falls on a surface (the ground's own colour times a little
42
+ * more, never a glow laid over it). It is brightest at the fire and falls away as a lamp's light does, flickers with the fire,
43
+ * and fades as a real light takes the fire over, so it hands over to the real thing unseen. One instanced mesh for all of them.
44
+ *
45
+ * The sources are the records `createLightBudget` keeps and hands back as its `pools` (x, y, z, `base`, r, g, b, `power`, `on`,
46
+ * `share`, `pool`, `poolR`); this writes `poolY`, `nx`, `nz` and sets `pool` to 2 once a pool is placed.
47
+ *
48
+ * @param {object} options
49
+ * @param {THREE.Object3D} options.parent Where the mesh is added.
50
+ * @param {(source: object, t: number) => number} options.flicker A source's flicker at clock t (1 steady).
51
+ * @param {number} [options.most=64] Pools drawn at most.
52
+ * @param {number} [options.layer=0] The layer the mesh is drawn in.
53
+ * @param {Record<string, string>} [options.defines] Shader defines for its material (a haze patch's switch, for one).
54
+ * @returns {{ build: () => void, lay: (sources: object[], ground: (x: number, z: number) => number) => void,
55
+ * shade: (sources: object[], lit: number, t: number, direct: boolean) => void }}
56
+ */
57
+ export function createFirePools({ parent, flicker, most = 64, layer = 0, defines = null }) {
58
+ let pools = null;
59
+
60
+ /** Makes the mesh, at start-up, before any shader is compiled: one draw for all the pools in view. */
61
+ function build() {
62
+ const material = new THREE.MeshBasicMaterial({
63
+ map: falloff(),
64
+ transparent: true,
65
+ depthWrite: false,
66
+ toneMapped: false,
67
+ // Standard Three.js fog mixes zero falloff corners toward fogColor, painting bright squares on additive blends;
68
+ // enable fog only when a caller opts into a FOG_FADES haze patch that attenuates toward zero.
69
+ fog: Boolean(defines && 'FOG_FADES' in defines),
70
+ // what is drawn there times (1 + the pool's light): the ground lit by the fire, in its own colour
71
+ blending: THREE.CustomBlending,
72
+ blendEquation: THREE.AddEquation,
73
+ blendSrc: THREE.DstColorFactor,
74
+ blendDst: THREE.OneFactor,
75
+ blendSrcAlpha: THREE.ZeroFactor,
76
+ blendDstAlpha: THREE.OneFactor,
77
+ });
78
+ if (defines) material.defines = { ...defines };
79
+ const mesh = new THREE.InstancedMesh(new THREE.PlaneGeometry(2, 2).rotateX(-Math.PI / 2), material, most);
80
+ mesh.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(most * 3), 3);
81
+ mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
82
+ mesh.instanceColor.setUsage(THREE.DynamicDrawUsage);
83
+ mesh.count = 0;
84
+ mesh.frustumCulled = false; // its pools are chosen in view
85
+ mesh.renderOrder = 2; // over the ground, under the flames and smoke
86
+ mesh.layers.set(layer);
87
+ parent.add(mesh);
88
+ pools = mesh;
89
+ }
90
+
91
+ // Where a fire's pool lies, worked out once: on the ground under it, tilted with the ground, or where the fire itself is
92
+ // when that stands well above the ground.
93
+ function placePool(rec, ground) {
94
+ const g = ground(rec.x, rec.z);
95
+ if (!(rec.base - g < HIGH)) {
96
+ rec.poolY = rec.base - 0.2;
97
+ rec.nx = rec.nz = 0;
98
+ } else {
99
+ rec.poolY = g;
100
+ rec.nx = (ground(rec.x - SLOPE, rec.z) - ground(rec.x + SLOPE, rec.z)) / (2 * SLOPE);
101
+ rec.nz = (ground(rec.x, rec.z - SLOPE) - ground(rec.x, rec.z + SLOPE)) / (2 * SLOPE);
102
+ }
103
+ rec.pool = 2;
104
+ }
105
+
106
+ /** Lays the pools of the sources chosen this round (`recs`, nearest first) on the ground given. */
107
+ function lay(recs, ground) {
108
+ const n = Math.min(recs.length, most);
109
+ for (let j = 0; j < n; j++) {
110
+ const rec = recs[j];
111
+ if (rec.pool === 1) placePool(rec, ground);
112
+ _q.setFromUnitVectors(UP, _n.set(rec.nx, 1, rec.nz).normalize());
113
+ pools.setMatrixAt(j, _m.compose(_p.set(rec.x, rec.poolY + LIFT, rec.z), _q, _s.set(rec.poolR, 1, rec.poolR)));
114
+ }
115
+ pools.count = n;
116
+ pools.instanceMatrix.needsUpdate = true;
117
+ }
118
+
119
+ // Where the picture is drawn straight to the screen without HDR, whose colours stop at white, the ground could be brightened at most
120
+ // twice over: there the pools' light is added instead, as much as the night's ground shows on the screen, times the light.
121
+ function drawDirect(direct) {
122
+ const m = pools.material,
123
+ want = direct ? THREE.OneFactor : THREE.DstColorFactor;
124
+ if (m.blendSrc !== want) m.blendSrc = want;
125
+ }
126
+ // Each frame: how bright each pool is, flickering with its fire, and fading as its real light comes up. `lit`: one over the
127
+ // light that falls on open ground from the sky and the moon, at night (0 by day): a pool brightens the ground by the share
128
+ // its fire adds to that. `direct`: drawn straight to the screen.
129
+ function shade(recs, lit, t, direct) {
130
+ pools.visible = lit > 0 && pools.count > 0;
131
+ if (!pools.visible) return;
132
+ drawDirect(direct);
133
+ const n = pools.count,
134
+ c = pools.instanceColor.array,
135
+ seen = direct ? GROUND_SEEN : 1;
136
+ for (let j = 0; j < n; j++) {
137
+ const rec = recs[j],
138
+ drop = Math.max(LEAST_DROP, rec.y - rec.poolY),
139
+ k = ((seen * lit * rec.power * rec.on) / (drop * drop)) * (1 - rec.share) * flicker(rec, t);
140
+ c[j * 3] = rec.r * k;
141
+ c[j * 3 + 1] = rec.g * k;
142
+ c[j * 3 + 2] = rec.b * k;
143
+ }
144
+ pools.instanceColor.needsUpdate = n > 0;
145
+ }
146
+
147
+ return { build, lay, shade };
148
+ }