roamwright 0.4.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (549) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +21 -14
  3. package/README.md +38 -42
  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/bedding.js +141 -0
  67. package/geometry/builder-cells.js +50 -0
  68. package/geometry/builder-frame.js +48 -0
  69. package/geometry/builder.js +200 -177
  70. package/geometry/card-emblem.js +437 -0
  71. package/geometry/catenary-canvas.js +396 -0
  72. package/geometry/cell-mask.js +25 -0
  73. package/geometry/cloth-folds.js +143 -0
  74. package/geometry/crawl-shapes.js +71 -0
  75. package/geometry/creased-sheet.js +40 -35
  76. package/geometry/crowd-dress.js +315 -0
  77. package/geometry/crowd-far.js +174 -0
  78. package/geometry/crowd-look.js +42 -0
  79. package/geometry/crowd-weld.js +218 -0
  80. package/geometry/ear.js +44 -39
  81. package/geometry/erosion.js +71 -45
  82. package/geometry/face-grid.js +85 -65
  83. package/geometry/field-map.js +59 -0
  84. package/geometry/figure-arms.js +339 -0
  85. package/geometry/figure-beard.js +250 -0
  86. package/geometry/figure-body.js +297 -0
  87. package/geometry/figure-bow.js +105 -0
  88. package/geometry/figure-cloak.js +189 -0
  89. package/geometry/figure-clothes.js +337 -0
  90. package/geometry/figure-face-grids.js +75 -0
  91. package/geometry/figure-gear.js +446 -0
  92. package/geometry/figure-hair-far.js +151 -0
  93. package/geometry/figure-hair-hangs.js +108 -0
  94. package/geometry/figure-hair-patch.js +66 -0
  95. package/geometry/figure-hair.js +320 -0
  96. package/geometry/figure-hands.js +321 -0
  97. package/geometry/figure-head-features.js +280 -0
  98. package/geometry/figure-head.js +375 -0
  99. package/geometry/figure-headwear.js +223 -0
  100. package/geometry/figure-legs.js +231 -0
  101. package/geometry/figure-limbs.js +39 -0
  102. package/geometry/figure-sculpt.js +82 -0
  103. package/geometry/figure-skin.js +97 -0
  104. package/geometry/figure-skirts.js +303 -0
  105. package/geometry/figure-trunk.js +411 -0
  106. package/geometry/flier-corvid-body.js +322 -0
  107. package/geometry/flier-corvid-wings.js +154 -0
  108. package/geometry/flier-long-body.js +195 -0
  109. package/geometry/flier-shapes.js +219 -0
  110. package/geometry/flier-soaring-bird.js +84 -0
  111. package/geometry/foliage.js +187 -14
  112. package/geometry/fort-city-walls.js +479 -0
  113. package/geometry/fort-gate-approach.js +233 -0
  114. package/geometry/fort-great-walls.js +280 -0
  115. package/geometry/fort-keep.js +297 -0
  116. package/geometry/fort-parts.js +261 -0
  117. package/geometry/fort-polyline.js +261 -0
  118. package/geometry/fort-portal.js +96 -0
  119. package/geometry/fort-ring-wall.js +267 -0
  120. package/geometry/fort-seawall.js +104 -0
  121. package/geometry/fort-terrace-gates.js +323 -0
  122. package/geometry/fort-terrace-plan.js +250 -0
  123. package/geometry/fort-terrace-wall.js +345 -0
  124. package/geometry/garment-tags.js +11 -3
  125. package/geometry/grid-gather.js +69 -0
  126. package/geometry/grid-sample.js +185 -0
  127. package/geometry/hair-gathers.js +57 -42
  128. package/geometry/hair-locks.js +42 -42
  129. package/geometry/hair-patch.js +24 -20
  130. package/geometry/hair-shell.js +43 -31
  131. package/geometry/head-presets.js +103 -0
  132. package/geometry/head-profile.js +26 -15
  133. package/geometry/head-shape.js +123 -95
  134. package/geometry/heightfield.js +50 -24
  135. package/geometry/horizon-angles.js +166 -0
  136. package/geometry/house-kit-body.js +195 -0
  137. package/geometry/house-kit-courtyard-parts.js +340 -0
  138. package/geometry/house-kit-courtyard-roof.js +223 -0
  139. package/geometry/house-kit-courtyard.js +409 -0
  140. package/geometry/house-kit-cut.js +29 -0
  141. package/geometry/house-kit-extras.js +192 -0
  142. package/geometry/house-kit-forms.js +298 -0
  143. package/geometry/house-kit-frame.js +74 -0
  144. package/geometry/house-kit-marks.js +93 -0
  145. package/geometry/house-kit-openings.js +193 -0
  146. package/geometry/house-kit-palette.js +54 -0
  147. package/geometry/house-kit-pool.js +71 -0
  148. package/geometry/house-kit-roofs.js +151 -0
  149. package/geometry/house-kit.js +202 -0
  150. package/geometry/index-parts.js +2 -2
  151. package/geometry/instance-visibility.js +12 -12
  152. package/geometry/instances.js +17 -17
  153. package/geometry/lamp-wash.js +65 -0
  154. package/geometry/land-clearings.js +83 -0
  155. package/geometry/land-ditches.js +290 -0
  156. package/geometry/land-dry-basin.js +327 -0
  157. package/geometry/land-dunes.js +150 -0
  158. package/geometry/land-earthworks.js +432 -0
  159. package/geometry/land-edge.js +292 -0
  160. package/geometry/land-mound-faces.js +349 -0
  161. package/geometry/land-near-relief.js +102 -0
  162. package/geometry/land-sheet.js +220 -0
  163. package/geometry/land-town-ground.js +256 -0
  164. package/geometry/land-waters.js +228 -0
  165. package/geometry/land-wildness.js +123 -0
  166. package/geometry/lathed-vessel.js +293 -0
  167. package/geometry/outline-grid.js +11 -10
  168. package/geometry/outline-segments.js +74 -0
  169. package/geometry/part-ranges.js +38 -3
  170. package/geometry/path-field.js +98 -34
  171. package/geometry/placement.js +52 -52
  172. package/geometry/planked-floor.js +149 -0
  173. package/geometry/plant-broadleaf.js +268 -0
  174. package/geometry/plant-shrub.js +198 -0
  175. package/geometry/plant-tints.js +80 -0
  176. package/geometry/plant-trees.js +453 -0
  177. package/geometry/plant-tussock.js +107 -0
  178. package/geometry/point-buckets.js +50 -0
  179. package/geometry/primitives.js +117 -59
  180. package/geometry/prop-battlefield.js +69 -0
  181. package/geometry/prop-camp.js +175 -0
  182. package/geometry/prop-door.js +26 -0
  183. package/geometry/prop-harbour.js +105 -0
  184. package/geometry/prop-haycock.js +60 -0
  185. package/geometry/prop-sacks.js +74 -0
  186. package/geometry/prop-sheaf.js +68 -0
  187. package/geometry/prop-street.js +69 -0
  188. package/geometry/prop-tents.js +396 -0
  189. package/geometry/prop-tombs.js +80 -0
  190. package/geometry/prop-trade.js +393 -0
  191. package/geometry/prop-vehicles.js +218 -0
  192. package/geometry/props.js +58 -0
  193. package/geometry/room-arcade.js +134 -0
  194. package/geometry/room-dome.js +188 -0
  195. package/geometry/room-flames.js +138 -0
  196. package/geometry/room-frame.js +106 -0
  197. package/geometry/room-furniture.js +260 -0
  198. package/geometry/room-hearth.js +98 -0
  199. package/geometry/room-kit.js +59 -0
  200. package/geometry/room-openings.js +142 -0
  201. package/geometry/room-stairs.js +180 -0
  202. package/geometry/room-surfaces.js +272 -0
  203. package/geometry/sagging-tube.js +27 -27
  204. package/geometry/sampled-surface.js +123 -77
  205. package/geometry/scatter-grid.js +49 -6
  206. package/geometry/sculpt.js +97 -93
  207. package/geometry/ship-fittings.js +350 -0
  208. package/geometry/ship-hull.js +460 -0
  209. package/geometry/ship-kit.js +208 -0
  210. package/geometry/ship-lines.js +69 -0
  211. package/geometry/ship-oars.js +150 -0
  212. package/geometry/ship-presets.js +131 -0
  213. package/geometry/ship-rig.js +374 -0
  214. package/geometry/ship-sails.js +148 -0
  215. package/geometry/shore-grid.js +81 -34
  216. package/geometry/strata-field.js +131 -98
  217. package/geometry/strata-tiles.js +108 -94
  218. package/geometry/stream.js +96 -59
  219. package/geometry/swept-tube.js +124 -0
  220. package/geometry/terrain-chunks.js +216 -123
  221. package/geometry/terrain-extension.js +29 -13
  222. package/geometry/town-courtyard-inn.js +272 -0
  223. package/geometry/town-ground.js +76 -0
  224. package/geometry/town-houses.js +343 -0
  225. package/geometry/town-lights.js +254 -0
  226. package/geometry/town-lots.js +172 -0
  227. package/geometry/town-plan.js +370 -0
  228. package/geometry/town-works.js +465 -0
  229. package/geometry/village-layout.js +181 -0
  230. package/geometry/village-yards.js +167 -0
  231. package/geometry/wall-runs.js +64 -0
  232. package/index.js +138 -2
  233. package/math/cell-edge.js +16 -16
  234. package/math/cell-key.js +6 -0
  235. package/math/circle-clearances.js +19 -0
  236. package/math/cloth-textures.js +6 -6
  237. package/math/cloud-textures.js +22 -26
  238. package/math/color.js +14 -14
  239. package/math/curve.js +26 -22
  240. package/math/lamp-texels.js +43 -0
  241. package/math/lit-share.js +22 -0
  242. package/math/mountain-ranges.js +379 -205
  243. package/math/noise.js +101 -49
  244. package/math/particle-noise.js +28 -28
  245. package/math/periodic.js +11 -5
  246. package/math/random.js +24 -15
  247. package/math/rectangles.js +58 -0
  248. package/math/rock-texture.js +22 -17
  249. package/math/scalar.js +5 -5
  250. package/math/surface-textures.js +74 -59
  251. package/math/wandering-path.js +40 -0
  252. package/math/ways.js +120 -0
  253. package/motion/action-dynamics.js +398 -0
  254. package/motion/animal-bearing.js +247 -0
  255. package/motion/animal-canine-bearing.js +178 -0
  256. package/motion/animal-canine-cast.js +131 -0
  257. package/motion/animal-cattle-cast.js +64 -0
  258. package/motion/animal-herd-cast.js +154 -0
  259. package/motion/animal-horse-still.js +161 -0
  260. package/motion/animal-troop-cast.js +43 -0
  261. package/motion/arm-reach.js +27 -26
  262. package/motion/ballistic-arc.js +191 -0
  263. package/motion/biped-cycle.js +46 -0
  264. package/motion/biped-leg.js +40 -0
  265. package/motion/biped-posture.js +459 -0
  266. package/motion/biped-stride.js +226 -140
  267. package/motion/boat-sailing.js +214 -0
  268. package/motion/contact-transition.js +32 -0
  269. package/motion/crowd-alarms.js +72 -42
  270. package/motion/crowd-attention.js +108 -0
  271. package/motion/crowd-beasts.js +203 -0
  272. package/motion/crowd-camp.js +295 -0
  273. package/motion/crowd-figure.js +100 -0
  274. package/motion/crowd-herd.js +86 -0
  275. package/motion/crowd-hold.js +130 -0
  276. package/motion/crowd-pose.js +296 -0
  277. package/motion/crowd-poses.js +481 -0
  278. package/motion/crowd-routine.js +126 -67
  279. package/motion/crowd-town.js +166 -0
  280. package/motion/crowd-water.js +143 -0
  281. package/motion/daily-clock.js +9 -9
  282. package/motion/deck-surface.js +40 -0
  283. package/motion/figure-acts.js +411 -0
  284. package/motion/figure-arms.js +437 -0
  285. package/motion/figure-blade-slide.js +149 -0
  286. package/motion/figure-body-place.js +180 -0
  287. package/motion/figure-bones.js +118 -0
  288. package/motion/figure-bow-draw.js +70 -0
  289. package/motion/figure-fingers.js +215 -0
  290. package/motion/figure-gaze.js +205 -0
  291. package/motion/figure-gestures.js +452 -0
  292. package/motion/figure-grip.js +134 -0
  293. package/motion/figure-head.js +287 -0
  294. package/motion/figure-legs.js +264 -0
  295. package/motion/figure-links.js +293 -0
  296. package/motion/figure-locomotion.js +391 -0
  297. package/motion/figure-mount-up.js +180 -0
  298. package/motion/figure-mount.js +201 -0
  299. package/motion/figure-pose-frame.js +375 -0
  300. package/motion/figure-pose-table.js +156 -0
  301. package/motion/figure-pose.js +343 -0
  302. package/motion/figure-seat.js +267 -0
  303. package/motion/figure-sway.js +125 -0
  304. package/motion/flier-corvid-pose.js +74 -0
  305. package/motion/flier-flight-air.js +122 -0
  306. package/motion/flier-flight-echelon.js +164 -0
  307. package/motion/flier-flight-roost.js +131 -0
  308. package/motion/flier-swarm-flight.js +252 -0
  309. package/motion/formation.js +193 -0
  310. package/motion/ground-lookahead.js +5 -5
  311. package/motion/instance-sight.js +15 -8
  312. package/motion/melee-contact.js +143 -0
  313. package/motion/moorings.js +48 -0
  314. package/motion/path-steering.js +358 -0
  315. package/motion/player.js +41 -32
  316. package/motion/quadruped.js +244 -168
  317. package/motion/spaces.js +90 -38
  318. package/motion/speech-cadence.js +304 -0
  319. package/motion/vessel-motion.js +57 -0
  320. package/motion/walk-grid.js +235 -0
  321. package/motion/weather.js +133 -26
  322. package/motion/wind.js +58 -13
  323. package/package.json +33 -6
  324. package/rendering/alpha-mips.js +340 -0
  325. package/rendering/animal-camel-figure.js +29 -0
  326. package/rendering/animal-canine-figure.js +59 -0
  327. package/rendering/animal-cattle-figure.js +36 -0
  328. package/rendering/animal-horse-figure.js +49 -0
  329. package/rendering/atmosphere.js +86 -0
  330. package/rendering/camera-track.js +156 -0
  331. package/rendering/cart-track.js +92 -0
  332. package/rendering/caster-motion.js +6 -5
  333. package/rendering/cell-lod-options.js +46 -0
  334. package/rendering/cell-lod.js +754 -113
  335. package/rendering/cloth-material.js +140 -0
  336. package/rendering/cloud-dome.js +30 -30
  337. package/rendering/cloud-field.js +2 -2
  338. package/rendering/compilation-schedule.js +79 -14
  339. package/rendering/contact-shadows.js +7 -4
  340. package/rendering/context.js +57 -6
  341. package/rendering/crowd-batches.js +420 -0
  342. package/rendering/crowd-herd.js +198 -0
  343. package/rendering/crowd-rig.js +132 -0
  344. package/rendering/crowd-skinning.js +62 -19
  345. package/rendering/crowd-update.js +419 -0
  346. package/rendering/crowd-visibility.js +107 -0
  347. package/rendering/crust.js +18 -12
  348. package/rendering/day-cycle-defaults.js +200 -0
  349. package/rendering/day-cycle.js +487 -0
  350. package/rendering/daylight.js +4 -6
  351. package/rendering/detail-range.js +29 -0
  352. package/rendering/dispose-meshes.js +18 -0
  353. package/rendering/dof.js +20 -13
  354. package/rendering/effects-frame.js +149 -0
  355. package/rendering/effects-water-rises.js +221 -0
  356. package/rendering/energy-stream.js +128 -0
  357. package/rendering/eye-adapt.js +14 -14
  358. package/rendering/facade-glass-material.js +105 -0
  359. package/rendering/far-shadow.js +89 -62
  360. package/rendering/field-surface.js +138 -0
  361. package/rendering/figure-shield.js +105 -0
  362. package/rendering/figure-skeleton.js +329 -0
  363. package/rendering/fire-light-watch.js +197 -0
  364. package/rendering/fire-pools.js +148 -0
  365. package/rendering/flame-sources.js +86 -0
  366. package/rendering/flier-bird-looks.js +97 -0
  367. package/rendering/flier-corvid-figure.js +67 -0
  368. package/rendering/flier-long-body-company.js +169 -0
  369. package/rendering/flier-swarm.js +186 -0
  370. package/rendering/flocks.js +82 -78
  371. package/rendering/garment-material.js +147 -51
  372. package/rendering/glow-lines.js +13 -13
  373. package/rendering/glsl-literal.js +19 -0
  374. package/rendering/ground-marks.js +316 -0
  375. package/rendering/hair-strands.js +45 -31
  376. package/rendering/height-haze.js +80 -33
  377. package/rendering/height-probe.js +164 -22
  378. package/rendering/house-kit-meshes.js +124 -0
  379. package/rendering/interior-bake.js +807 -0
  380. package/rendering/label-layout.js +56 -0
  381. package/rendering/label-range.js +41 -0
  382. package/rendering/lamp-light-map.js +159 -0
  383. package/rendering/lamp-maps.js +62 -0
  384. package/rendering/lamp-wash.js +51 -0
  385. package/rendering/light-budget.js +71 -55
  386. package/rendering/light-points.js +21 -5
  387. package/rendering/local-lights.js +39 -8
  388. package/rendering/material-lod.js +49 -50
  389. package/rendering/memory-estimate.js +84 -0
  390. package/rendering/moored-fleet.js +186 -0
  391. package/rendering/part-costs.js +104 -0
  392. package/rendering/particle-bursts.js +386 -0
  393. package/rendering/particle-emitters.js +135 -99
  394. package/rendering/particle-light-bursts.js +189 -0
  395. package/rendering/particles.js +212 -101
  396. package/rendering/pen-flocks.js +118 -0
  397. package/rendering/piece-batch.js +298 -11
  398. package/rendering/planar-reflection-options.js +159 -0
  399. package/rendering/planar-reflection.js +806 -103
  400. package/rendering/plant-cells.js +122 -0
  401. package/rendering/plant-reeds.js +113 -0
  402. package/rendering/plant-shade-trees.js +239 -0
  403. package/rendering/plant-tuft-patch.js +122 -0
  404. package/rendering/post-shaders.js +98 -31
  405. package/rendering/post.js +107 -87
  406. package/rendering/pressed-cover.js +135 -0
  407. package/rendering/prop-dig.js +136 -0
  408. package/rendering/rain-streaks.js +67 -0
  409. package/rendering/room-light.js +250 -0
  410. package/rendering/room-materials.js +78 -0
  411. package/rendering/room-space.js +111 -0
  412. package/rendering/scene-lights.js +106 -0
  413. package/rendering/sea-shaders.js +94 -37
  414. package/rendering/settlement-approach.js +226 -0
  415. package/rendering/settlement-dissolve.js +89 -0
  416. package/rendering/settlement-quarter-warm.js +55 -0
  417. package/rendering/settlement-quarter.js +477 -0
  418. package/rendering/settlement-switch.js +42 -0
  419. package/rendering/settlement-town.js +110 -0
  420. package/rendering/shader-warmup.js +101 -44
  421. package/rendering/shadow-alignment.js +4 -4
  422. package/rendering/shadow-depth.js +47 -25
  423. package/rendering/ship-meshes.js +150 -0
  424. package/rendering/shot-cuts.js +68 -0
  425. package/rendering/sky-occlusion.js +56 -29
  426. package/rendering/sky-pmrem.js +216 -0
  427. package/rendering/sky.js +126 -54
  428. package/rendering/smoke-shadows.js +201 -0
  429. package/rendering/stage-framing.js +182 -0
  430. package/rendering/stage-lights.js +46 -39
  431. package/rendering/stain-material.js +74 -0
  432. package/rendering/static-point-shadow.js +65 -26
  433. package/rendering/still-casters.js +77 -27
  434. package/rendering/strata-material.js +12 -12
  435. package/rendering/stream-flow.js +10 -10
  436. package/rendering/street-lamps.js +166 -0
  437. package/rendering/sunbeam-motes.js +670 -0
  438. package/rendering/surface-light.js +65 -6
  439. package/rendering/surface-material.js +306 -0
  440. package/rendering/surface-projection.js +32 -0
  441. package/rendering/surface-snippets.js +314 -0
  442. package/rendering/taa.js +75 -44
  443. package/rendering/talus.js +15 -15
  444. package/rendering/terrain-rock.js +7 -7
  445. package/rendering/texture-fills.js +8 -8
  446. package/rendering/textures.js +28 -28
  447. package/rendering/tree-impostor.js +929 -0
  448. package/rendering/vehicle-train.js +92 -0
  449. package/rendering/viewport.js +67 -4
  450. package/rendering/wakes.js +24 -24
  451. package/rendering/water-material.js +304 -103
  452. package/rendering/waypoint-beacons.js +191 -0
  453. package/rendering/world-matrices.js +38 -40
  454. package/ruff.toml +20 -0
  455. package/runtime/cue-cursor.js +21 -0
  456. package/runtime/device-quality.js +13 -2
  457. package/runtime/device.js +73 -0
  458. package/runtime/diagnostic-log.js +12 -4
  459. package/runtime/effect-sites.js +85 -0
  460. package/runtime/figure-orders.js +59 -0
  461. package/runtime/first-use.js +36 -28
  462. package/runtime/foley-script.js +124 -0
  463. package/runtime/foley-strides.js +333 -0
  464. package/runtime/frame-pacing.js +47 -0
  465. package/runtime/frame-yield.js +18 -0
  466. package/runtime/gpu-timing.js +15 -11
  467. package/runtime/grid-cache.js +16 -6
  468. package/runtime/grid-rows.js +44 -5
  469. package/runtime/hand-over.js +47 -24
  470. package/runtime/land-bake.js +78 -0
  471. package/runtime/lazy-sets.js +105 -0
  472. package/runtime/pool.js +73 -17
  473. package/runtime/quality-fit.js +60 -28
  474. package/runtime/region-pass-lay.js +40 -0
  475. package/runtime/region-pass.js +78 -0
  476. package/runtime/search.js +26 -22
  477. package/runtime/settlement-reach.js +42 -0
  478. package/runtime/sound-calls.js +113 -0
  479. package/runtime/sound-impacts.js +297 -0
  480. package/runtime/sound-voices.js +194 -0
  481. package/runtime/soundscape.js +282 -0
  482. package/runtime/spatial-audio.js +79 -30
  483. package/runtime/steady-frames.js +221 -0
  484. package/runtime/withdrawable-task.js +46 -0
  485. package/runtime/worker.js +7 -0
  486. package/scripts/app-parts.mjs +118 -0
  487. package/scripts/bake-revisions.mjs +81 -0
  488. package/scripts/browser-scripts.mjs +64 -0
  489. package/scripts/bundle.mjs +192 -0
  490. package/scripts/check-app.sh +26 -0
  491. package/scripts/eslint-config.mjs +119 -0
  492. package/scripts/format.sh +92 -0
  493. package/scripts/keep-builds.mjs +158 -0
  494. package/scripts/layers.mjs +112 -0
  495. package/scripts/lint.sh +49 -0
  496. package/scripts/module-graph.mjs +123 -0
  497. package/scripts/pre-commit.sh +38 -0
  498. package/scripts/serve.py +5 -3
  499. package/scripts/site.mjs +358 -0
  500. package/scripts/test-runner.sh +42 -0
  501. package/scripts/vendor.mjs +221 -0
  502. package/scripts/verify-publish.mjs +175 -0
  503. package/scripts/world.mk +59 -0
  504. package/tools/README.md +73 -0
  505. package/tools/contact-sheet.cjs +137 -0
  506. package/tools/cpu-profile.cjs +275 -0
  507. package/tools/cpu-profile.test.cjs +98 -0
  508. package/tools/first-draws.cjs +395 -0
  509. package/tools/flight-guard.cjs +482 -0
  510. package/tools/flight-guard.test.cjs +153 -0
  511. package/tools/flight-profile.cjs +145 -0
  512. package/tools/frame-bench.cjs +336 -0
  513. package/tools/frame-parts.cjs +365 -0
  514. package/tools/ios-sim.sh +145 -0
  515. package/tools/load-audit.cjs +201 -0
  516. package/tools/look-compare.cjs +304 -0
  517. package/tools/look-guard.cjs +407 -0
  518. package/tools/look-guard.test.cjs +93 -0
  519. package/tools/look-stats.cjs +185 -0
  520. package/tools/look-stats.test.cjs +71 -0
  521. package/tools/memory-audit.cjs +323 -0
  522. package/tools/page-driver.cjs +320 -0
  523. package/tools/page-driver.test.cjs +219 -0
  524. package/tools/program-census-report.cjs +191 -0
  525. package/tools/program-census.cjs +465 -0
  526. package/tools/program-census.test.cjs +332 -0
  527. package/tools/remote-runner.sh +265 -0
  528. package/tools/runners.test.cjs +59 -0
  529. package/tools/scene-audit-beat.cjs +344 -0
  530. package/tools/scene-audit-sheet.cjs +282 -0
  531. package/tools/scene-audit.cjs +471 -0
  532. package/tools/scene-audit.test.cjs +201 -0
  533. package/tools/scene-batch.cjs +219 -0
  534. package/tools/scene-bench.cjs +149 -0
  535. package/tools/scene-bench.test.cjs +33 -0
  536. package/tools/scene-run.cjs +443 -0
  537. package/tools/scene-run.test.cjs +94 -0
  538. package/tools/servers.sh +59 -0
  539. package/tools/shader-arrival.cjs +316 -0
  540. package/tools/shader-renewal.cjs +53 -0
  541. package/tools/shader-renewal.test.cjs +115 -0
  542. package/tools/speed-guard.cjs +258 -0
  543. package/tools/stills.cjs +492 -0
  544. package/tools/stills.test.cjs +49 -0
  545. package/tools/turns.sh +7 -0
  546. package/tools/yaml.cjs +158 -0
  547. package/examples/viaduct.css +0 -75
  548. package/rendering/light-shafts.js +0 -131
  549. package/rendering/road-surface.js +0 -63
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Woven architectural cloth material (awnings, tents, sails, banners) with triplanar weave
3
+ * and crumple relief, distance-faded normal perturbation, backlit translucency, and optional
4
+ * street-lamp bounce at night.
5
+ * @module
6
+ */
7
+
8
+ import * as THREE from 'three';
9
+ import { LOW_LIGHT_REFLECTANCE } from './low-light.js';
10
+ import { thinSurfaceLight } from './surface-light.js';
11
+
12
+ /**
13
+ * Creates a procedural woven-cloth `MeshStandardMaterial` for architectural awnings, tents, banners, and sails.
14
+ *
15
+ * @param {object} options
16
+ * @param {THREE.Texture} options.weaveTexture Tileable woven cloth texture.
17
+ * @param {THREE.Texture} options.crumpleTexture Tileable fold/crumple relief texture (blue channel used for height).
18
+ * @param {object} [options.uniforms] Shared uniform wrappers (`uSunLight`, and when `lampWash` is true: `uNight`, `uGas`, `uGasWash`, `uLampMap`, `uLampR`).
19
+ * @param {boolean} [options.lampWash=false] Include night street-lamp and window bounce reflected off paving below canopies.
20
+ * @param {{ sky?: number, sun?: number }} [options.backlight] Backlit sky and sunlight transmission weights.
21
+ * @param {boolean} [options.shadowedTranslucency=true] Gate backlit sunlight by `sunShadow()` (`installFarShadowShader`).
22
+ * @param {number} [options.roughness=0.88] Base fabric roughness.
23
+ * @param {string} [options.cacheKey] Explicit program cache key.
24
+ * @returns {THREE.MeshStandardMaterial}
25
+ */
26
+ export function createClothMaterial({
27
+ weaveTexture,
28
+ crumpleTexture,
29
+ uniforms = {},
30
+ lampWash = false,
31
+ backlight = {},
32
+ shadowedTranslucency = true,
33
+ roughness = 0.88,
34
+ cacheKey = lampWash ? 'kitcloth-weave-gas-bounce' : 'kitcloth-weave',
35
+ } = {}) {
36
+ const sky = backlight.sky ?? 0.32;
37
+ const sun = backlight.sun ?? 0.22;
38
+ const uSunLight = uniforms.uSunLight ?? { value: 1 };
39
+ const uNight = uniforms.uNight ?? { value: 0 };
40
+ const uGas = uniforms.uGas ?? { value: new THREE.Color(1, 0.72, 0.38) };
41
+ const uGasWash = uniforms.uGasWash ?? { value: 0 };
42
+ const uLampMap = uniforms.uLampMap ?? { value: null };
43
+ const uLampR = uniforms.uLampR ?? { value: new THREE.Vector4(0, 0, 0, 0) };
44
+
45
+ const through = thinSurfaceLight({
46
+ sky,
47
+ sun,
48
+ sunlight: shadowedTranslucency ? 'sunSeen * uSunLight' : 'uSunLight',
49
+ shadowed: shadowedTranslucency,
50
+ });
51
+
52
+ const material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness });
53
+ material.onBeforeCompile = sh => {
54
+ sh.uniforms.uClothTex = { value: weaveTexture };
55
+ sh.uniforms.uClothCrumple = { value: crumpleTexture };
56
+ if (lampWash) {
57
+ sh.uniforms.uNight = uNight;
58
+ sh.uniforms.uGas = uGas;
59
+ sh.uniforms.uGasWash = uGasWash;
60
+ sh.uniforms.uLampMap = uLampMap;
61
+ sh.uniforms.uLampR = uLampR;
62
+ }
63
+ sh.uniforms.uSunLight = uSunLight;
64
+ sh.vertexShader = sh.vertexShader.replace('#include <common>', '#include <common>\nvarying vec3 vWc; varying vec3 vClothN;').replace(
65
+ '#include <project_vertex>',
66
+ `/* glsl */
67
+ #include <project_vertex>
68
+ vec4 wc = vec4(transformed, 1.0);
69
+ vec3 wn = objectNormal;
70
+ #ifdef USE_INSTANCING
71
+ wc = instanceMatrix * wc;
72
+ wn = mat3(instanceMatrix) * wn;
73
+ #endif
74
+ vWc = (modelMatrix * wc).xyz;
75
+ vClothN = normalize(mat3(modelMatrix) * wn);`,
76
+ );
77
+ const commonDecl = lampWash
78
+ ? '#include <common>\nvarying vec3 vWc; varying vec3 vClothN; uniform sampler2D uClothTex, uClothCrumple; uniform float uNight, uGasWash; uniform vec3 uGas; uniform sampler2D uLampMap; uniform vec4 uLampR; uniform float uSunLight; float gClothH = 0.5;' +
79
+ LOW_LIGHT_REFLECTANCE
80
+ : '#include <common>\nvarying vec3 vWc; varying vec3 vClothN; uniform sampler2D uClothTex, uClothCrumple; uniform float uSunLight; float gClothH = 0.5;';
81
+ const nightBounce = lampWash
82
+ ? `/* glsl */
83
+ if (uNight > 0.0) {
84
+ vec2 lampUv = (vWc.xz - uLampR.xy) * uLampR.zw;
85
+ if (all(greaterThan(lampUv, vec2(0.0))) && all(lessThan(lampUv, vec2(1.0)))) {
86
+ vec2 pools = texture2D(uLampMap, lampUv).rg;
87
+ float up = (vec4(normal, 0.0) * viewMatrix).y;
88
+ // The paving below a canopy reflects the lamps into the yarn and across the folded hem.
89
+ float lamp = pools.r + 0.1 * sqrt(pools.r) + 0.022 * uGasWash;
90
+ vec3 bounce = (uGas * lamp + vec3(1.0, 0.63, 0.33) * pools.g * 0.28) * ((0.83 - 0.29 * up) * uNight);
91
+ outgoingLight += diffuseTextileBounce(diffuseColor.rgb, bounce, 0.48);
92
+ }
93
+ }`
94
+ : '';
95
+ sh.fragmentShader = sh.fragmentShader
96
+ .replace('#include <common>', commonDecl)
97
+ .replace(
98
+ '#include <map_fragment>',
99
+ `/* glsl */
100
+ #include <map_fragment>
101
+ {
102
+ vec3 bw = abs(vClothN); bw *= bw; bw /= max(bw.x + bw.y + bw.z, 1e-4);
103
+ vec3 weave = texture2D(uClothTex, vWc.zy * 2.35).rgb * bw.x + texture2D(uClothTex, vWc.xz * 2.35).rgb * bw.y + texture2D(uClothTex, vWc.xy * 2.35).rgb * bw.z;
104
+ vec3 crumple = texture2D(uClothCrumple, vWc.zy * 0.44).rgb * bw.x + texture2D(uClothCrumple, vWc.xz * 0.44).rgb * bw.y + texture2D(uClothCrumple, vWc.xy * 0.44).rgb * bw.z;
105
+ float closeFade = 1.0 - smoothstep(10.0, 42.0, length(vViewPosition));
106
+ gClothH = mix(0.5, dot(weave, vec3(0.333)) * 0.55 + crumple.b * 0.45, closeFade);
107
+ diffuseColor.rgb *= mix(1.0, (0.72 + 0.52 * dot(weave, vec3(0.333))) * (0.86 + 0.26 * crumple.b), closeFade * 0.85);
108
+ }`,
109
+ )
110
+ .replace(
111
+ '#include <roughnessmap_fragment>',
112
+ `/* glsl */
113
+ #include <roughnessmap_fragment>
114
+ roughnessFactor = clamp(roughnessFactor + 0.14 * (0.5 - gClothH), 0.38, 0.98);`,
115
+ )
116
+ .replace(
117
+ '#include <normal_fragment_maps>',
118
+ `/* glsl */
119
+ #include <normal_fragment_maps>
120
+ {
121
+ float clothRelief = 2.6 * (1.0 - smoothstep(10.0, 36.0, length(vViewPosition)));
122
+ if (clothRelief > 0.01) {
123
+ vec3 sgx = dFdx(-vViewPosition), sgy = dFdy(-vViewPosition);
124
+ float lx = length(sgx), ly = length(sgy);
125
+ if (lx > 1e-7 && ly > 1e-7) {
126
+ sgx /= lx; sgy /= ly;
127
+ vec3 r1 = cross(sgy, normal), r2 = cross(normal, sgx);
128
+ float det = dot(sgx, r1);
129
+ vec3 nb = abs(det) * normal - clothRelief * sign(det) * (dFdx(gClothH) * r1 + dFdy(gClothH) * r2);
130
+ float l2 = dot(nb, nb);
131
+ if (l2 > 1e-8) normal = nb * inversesqrt(l2);
132
+ }
133
+ }
134
+ }`,
135
+ )
136
+ .replace('#include <opaque_fragment>', nightBounce + through);
137
+ };
138
+ material.customProgramCacheKey = () => cacheKey;
139
+ return material;
140
+ }
@@ -25,7 +25,7 @@ export function createCloudDome({ renderer, field, warmProgram }) {
25
25
  JUMP = 0.6, // the viewer carried further than this in one frame (the field's units) is a cut: the clouds are drawn whole at once
26
26
  TURNED = 0.96, // and so is a light that turned by more than this cosine,
27
27
  CHANGED = 0.1; // or a sky whose threshold moved by more
28
- const f = (v, digits = 4) => v.toFixed(digits);
28
+ const formatFloat = (v, digits = 4) => v.toFixed(digits);
29
29
 
30
30
  const DOME_FS = `/* glsl */
31
31
  precision highp float; precision highp sampler3D;
@@ -43,15 +43,15 @@ export function createCloudDome({ renderer, field, warmProgram }) {
43
43
  const float ERODE = 0.12; // how far the creases between billows eat into the body, and
44
44
  const float FINER = 0.42; // the finer ones, as a share of that
45
45
  // Where a point lies in the block of billows: p from the viewer in the field's units, h its height in the layer.
46
- vec3 inBlock(vec2 p, float h) { return vec3(uAt * ${f(CLOUD_SHEET, 1)} + p, h * ${f(DEPTH)}).xzy * ${f(BLOCKS)}; }
46
+ vec3 inBlock(vec2 p, float h) { return vec3(uAt * ${formatFloat(CLOUD_SHEET, 1)} + p, h * ${formatFloat(DEPTH)}).xzy * ${formatFloat(BLOCKS)}; }
47
47
  // How far inside a cloud's body a point lies, in the field's value: 0 at its edge, SOFT and more in full cloud, below 0 in
48
48
  // clear air. p: from the viewer in the field's units; h: its height in the layer (0 the base, 1 the top). over: how far the
49
49
  // field stands over the threshold there; base: what the cloud's underside leaves of it there (0 below it, 1 well above);
50
50
  // rough: how far the billows eat into it there.
51
51
  float bodyAt(vec2 p, float h, float lod, out float over, out float base, out float rough) {
52
- vec4 texel = textureLod(uCloudField, uAt + p * ${f(1 / CLOUD_SHEET, 6)}, lod);
52
+ vec4 texel = textureLod(uCloudField, uAt + p * ${formatFloat(1 / CLOUD_SHEET, 6)}, lod);
53
53
  over = cloudField(texel) - uCloud;
54
- float h2 = h * h, body = over - ${f(SPAN)} * h2 * h2;
54
+ float h2 = h * h, body = over - ${formatFloat(SPAN)} * h2 * h2;
55
55
  rough = ERODE * (0.45 + 0.55 * smoothstep(0.0, 0.3, h)); // a cloud's base is smoother than its sides and top
56
56
  // the base is level but for shallow hollows between hanging bulges (the sheet's finer lumps), deeper under a closed sky
57
57
  base = smoothstep(0.0, BASE_SOFT, h - (BASE_HOLLOW + BASE_HOLLOW_CLOSED * smoothstep(0.25, 0.6, over)) * (1.0 - texel.g));
@@ -60,22 +60,22 @@ export function createCloudDome({ renderer, field, warmProgram }) {
60
60
  }
61
61
  // The share of a stretch that is cloud when its two ends lie a and b inside the body, the body taken to change evenly between
62
62
  // them: a cloud's edge is found where it lies between two steps, not at the nearer step (which drew it in terraces).
63
- float filled(float a, float b) {
64
- vec2 e = max(vec2(a, b), 0.0), sum = mix(e * e * ${f(0.5)} / SOFT, e - 0.5 * SOFT, step(SOFT, e));
65
- return abs(b - a) > 1e-4 ? clamp((sum.y - sum.x) / (b - a), 0.0, 1.0) : clamp(a / SOFT, 0.0, 1.0);
63
+ float filled(float startDensity, float endDensity) {
64
+ vec2 densities = max(vec2(startDensity, endDensity), 0.0), sum = mix(densities * densities * ${formatFloat(0.5)} / SOFT, densities - 0.5 * SOFT, step(SOFT, densities));
65
+ return abs(endDensity - startDensity) > 1e-4 ? clamp((sum.y - sum.x) / (endDensity - startDensity), 0.0, 1.0) : clamp(startDensity / SOFT, 0.0, 1.0);
66
66
  }
67
67
  void main() {
68
- vec2 r = (vUv - 0.5) * ${f(2 * RIM)};
68
+ vec2 r = (vUv - 0.5) * ${formatFloat(2 * RIM)};
69
69
  float r2 = dot(r, r);
70
- if (r2 >= ${f(RIM * RIM)}) { gl_FragColor = vec4(0.0); return; }
70
+ if (r2 >= ${formatFloat(RIM * RIM)}) { gl_FragColor = vec4(0.0); return; }
71
71
  float up = (1.0 - r2) / (1.0 + r2); // the direction's height: 1 overhead, 0 at the horizon
72
- if (up < ${f(LOWEST - 0.012)}) { gl_FragColor = vec4(0.0); return; } // no cloud is drawn that low in the sky (cloud-field.js)
73
- vec2 q = r * (1.0 + up) / (max(up, 0.0) + ${f(DIP)}); // how far the ray runs level for each unit it climbs
72
+ if (up < ${formatFloat(LOWEST - 0.012)}) { gl_FragColor = vec4(0.0); return; } // no cloud is drawn that low in the sky (cloud-field.js)
73
+ vec2 q = r * (1.0 + up) / (max(up, 0.0) + ${formatFloat(DIP)}); // how far the ray runs level for each unit it climbs
74
74
  float reach = length(q), slope = sqrt(1.0 + reach * reach);
75
75
  int steps = int(min(float(STEPS) + 9.0 * reach, float(MAX_STEPS))); // a ray near the horizon runs long through the layer
76
76
  float dh = 1.0 / float(steps);
77
77
  // the sheet's level of detail: a step is not finer than the way it travels, or a far cloud showed as a stack of slivers
78
- float lod = clamp(log2(max(reach * dh * ${f(DEPTH * TEXELS)}, 0.01)) - 0.5, 0.0, 3.0);
78
+ float lod = clamp(log2(max(reach * dh * ${formatFloat(DEPTH * TEXELS)}, 0.01)) - 0.5, 0.0, 3.0);
79
79
  float finer = FINER * (1.0 - lod / 1.5); // the finer billows fade out where a step is too long to show them
80
80
  // each ray's steps stand a little higher or lower than its neighbours', so what is left of the layer's levels in a cloud's
81
81
  // shading does not run on as lines
@@ -85,7 +85,7 @@ export function createCloudDome({ renderer, field, warmProgram }) {
85
85
  for (int i = 0; i < MAX_STEPS; i++) {
86
86
  if (i >= steps) break;
87
87
  float h = (float(i) + shift) * dh;
88
- vec2 p = q * (${f(FLARE)} * (1.0 + h * ${f(THICK)}));
88
+ vec2 p = q * (${formatFloat(FLARE)} * (1.0 + h * ${formatFloat(THICK)}));
89
89
  float body = bodyAt(p, h, lod, over, base, rough), cloud;
90
90
  #if FINE
91
91
  if (finer > 0.0 && max(was, body) > 0.0) {
@@ -94,7 +94,7 @@ export function createCloudDome({ renderer, field, warmProgram }) {
94
94
  for (int k = 1; k <= 3; k++) {
95
95
  float t = float(k) / 3.0, hk = h - (1.0 - t) * dh, part = mix(was, body, t);
96
96
  if (part > 0.0) {
97
- vec3 small = textureLod(uBillows, inBlock(q * (${f(FLARE)} * (1.0 + hk * ${f(THICK)})), hk) * 4.0 + uChurn.zxy * 3.0, lod).rgb;
97
+ vec3 small = textureLod(uBillows, inBlock(q * (${formatFloat(FLARE)} * (1.0 + hk * ${formatFloat(THICK)})), hk) * 4.0 + uChurn.zxy * 3.0, lod).rgb;
98
98
  part -= rough * finer * (1.0 - dot(small, vec3(0.5, 0.3, 0.2)));
99
99
  }
100
100
  cloud += filled(wasFine, part);
@@ -115,9 +115,9 @@ export function createCloudDome({ renderer, field, warmProgram }) {
115
115
  if (cloud < 0.003) continue;
116
116
  // the cloud between this point and the light, in steps that lengthen
117
117
  float between = 0.0, gone = 0.0, span = float(L_FIRST);
118
- vec2 from = q * (${f(FLARE)} * (1.0 + lit * ${f(THICK)}));
118
+ vec2 from = q * (${formatFloat(FLARE)} * (1.0 + lit * ${formatFloat(THICK)}));
119
119
  for (int j = 0; j < LIGHT_STEPS; j++) {
120
- float l = gone + 0.5 * span, hl = lit + uLight.y * l * ${f(1 / DEPTH)};
120
+ float l = gone + 0.5 * span, hl = lit + uLight.y * l * ${formatFloat(1 / DEPTH)};
121
121
  if (hl <= 0.0 || hl >= 1.0) break;
122
122
  between += clamp(bodyAt(from + uLight.xz * l, hl, max(lod, 0.5) + 0.5 * float(j), none, base, rough) / SOFT, 0.0, 1.0) * base * span;
123
123
  gone += span; span *= float(L_GROW);
@@ -125,17 +125,17 @@ export function createCloudDome({ renderer, field, warmProgram }) {
125
125
  between *= SIGMA;
126
126
  float once = exp(-between); // light that comes straight through
127
127
  float many = 0.7 * exp(-between * 0.3) + 0.3 * exp(-between * 0.1); // and light passed on from drop to drop, which reaches deeper
128
- float top = sqrt(sqrt(clamp(over * ${f(1 / SPAN)}, 0.0, 1.0)));
128
+ float top = sqrt(sqrt(clamp(over * ${formatFloat(1 / SPAN)}, 0.0, 1.0)));
129
129
  // the sky's light: from above, less the deeper under the cloud's top, and a little from below on its base
130
130
  float sky = 0.84 * exp(-3.0 * max(top - lit, 0.0)) * (0.5 + 0.5 * lit) + 0.16 * exp(-5.0 * lit);
131
- float a = 1.0 - exp(-cloud * (SIGMA * ${f(DEPTH)}) * dh * slope);
131
+ float a = 1.0 - exp(-cloud * (SIGMA * ${formatFloat(DEPTH)}) * dh * slope);
132
132
  sum += seen * a * vec3(many, once, sky);
133
133
  seen *= 1.0 - a;
134
134
  if (seen < 0.02) break;
135
135
  }
136
136
  // each is kept in a byte: a grain of half a step of it hides the steps between
137
137
  float grain = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715)))) - 0.5;
138
- gl_FragColor = vec4(sum, min((1.0 - seen) * ${f(1 / 0.98)}, 1.0)) + grain * ${f(1 / 255, 6)};
138
+ gl_FragColor = vec4(sum, min((1.0 - seen) * ${formatFloat(1 / 0.98)}, 1.0)) + grain * ${formatFloat(1 / 255, 6)};
139
139
  }`;
140
140
 
141
141
  // For the sky's shader: declares cloudDome(d), the clouds' picture in a direction above the horizon (r, g, b, a as above).
@@ -143,11 +143,11 @@ export function createCloudDome({ renderer, field, warmProgram }) {
143
143
  uniform sampler2D uDome, uDomeNext; uniform vec4 uDomeShift; uniform float uDomeMix;
144
144
  // where a ray that runs q level for each unit it climbs lies in a map
145
145
  vec2 domeUv(vec2 q) {
146
- float Q = dot(q, q), up = (sqrt(1.0 + Q * ${f(1 - DIP * DIP, 6)}) - Q * ${f(DIP)}) / (1.0 + Q);
147
- return 0.5 + q * ((up + ${f(DIP)}) / (1.0 + up) * ${f(0.5 / RIM, 6)});
146
+ float Q = dot(q, q), up = (sqrt(1.0 + Q * ${formatFloat(1 - DIP * DIP, 6)}) - Q * ${formatFloat(DIP)}) / (1.0 + Q);
147
+ return 0.5 + q * ((up + ${formatFloat(DIP)}) / (1.0 + up) * ${formatFloat(0.5 / RIM, 6)});
148
148
  }
149
149
  vec4 cloudDome(vec3 d) {
150
- vec2 q = d.xz / (max(d.y, 0.0) + ${f(DIP)});
150
+ vec2 q = d.xz / (max(d.y, 0.0) + ${formatFloat(DIP)});
151
151
  vec4 c = textureLod(uDome, domeUv(q + uDomeShift.xy), 0.0);
152
152
  if (uDomeMix > 0.0) c = mix(c, textureLod(uDomeNext, domeUv(q + uDomeShift.zw), 0.0), uDomeMix);
153
153
  return c;
@@ -200,12 +200,12 @@ export function createCloudDome({ renderer, field, warmProgram }) {
200
200
  function equalBands(size, bands) {
201
201
  const below = y => 0.5 + (y * Math.sqrt(1 - y * y) + Math.asin(y)) / Math.PI, // the share of a circle below y (-1 its foot, 1 its top)
202
202
  rows = [0];
203
- for (let k = 1; k < bands; k++) {
203
+ for (let bandIndex = 1; bandIndex < bands; bandIndex++) {
204
204
  let low = -1,
205
205
  high = 1;
206
206
  for (let i = 0; i < 30; i++) {
207
207
  const mid = (low + high) / 2;
208
- if (below(mid) < k / bands) low = mid;
208
+ if (below(mid) < bandIndex / bands) low = mid;
209
209
  else high = mid;
210
210
  }
211
211
  rows.push(Math.round(((low + 1) / 2) * size));
@@ -222,7 +222,7 @@ export function createCloudDome({ renderer, field, warmProgram }) {
222
222
  map.scissorTest = true;
223
223
  return map;
224
224
  };
225
- // Sets the preset's level of cloud detail (3, 4 or 5): the maps' size and the steps of their drawing.
225
+ // Sets the level of cloud detail (3, 4 or 5): the maps' size and the steps of their drawing.
226
226
  let pending = Promise.resolve(),
227
227
  disposed = false;
228
228
  function setCloudDetail(level) {
@@ -241,8 +241,8 @@ export function createCloudDome({ renderer, field, warmProgram }) {
241
241
  STEPS: level.steps,
242
242
  MAX_STEPS: level.most,
243
243
  LIGHT_STEPS: level.light,
244
- L_FIRST: f(level.first),
245
- L_GROW: f(level.grow),
244
+ L_FIRST: formatFloat(level.first),
245
+ L_GROW: formatFloat(level.grow),
246
246
  FINE: level.fine,
247
247
  });
248
248
  domeMat.needsUpdate = true;
@@ -293,11 +293,11 @@ export function createCloudDome({ renderer, field, warmProgram }) {
293
293
  // sky where the maps lie. light: towards the sun or the moon, whichever lights the clouds; threshold: the field's value
294
294
  // where cloud begins; seconds: the world's time; bright: how strong that light is now (a dark one may turn unseen, as when
295
295
  // the moon takes over from the sun that has set).
296
- function updateCloudDome(dt, light, threshold, seconds, bright, region) {
296
+ function updateCloudDome(deltaSeconds, light, threshold, seconds, bright, region) {
297
297
  const { level, last } = dome,
298
298
  sheet = cloudU.uCloudField.value,
299
299
  billows = cloudBillows.value;
300
- if (!level || !sheet?.version || !billows?.version) return; // no preset yet, or the workers have not filled the sheet and the block
300
+ if (!level || !sheet?.version || !billows?.version) return; // no level set yet, or the workers have not filled the sheet and the block
301
301
  const cut =
302
302
  !dome.whole ||
303
303
  last.space !== region ||
@@ -320,7 +320,7 @@ export function createCloudDome({ renderer, field, warmProgram }) {
320
320
  dome.band = 0;
321
321
  dome.mix = 0;
322
322
  } else if (dome.fading) {
323
- dome.mix += dt / FADE;
323
+ dome.mix += deltaSeconds / FADE;
324
324
  if (dome.mix >= 1) {
325
325
  const shown = dome.next,
326
326
  at = dome.nextAt;
@@ -53,10 +53,10 @@ export function createCloudField({
53
53
  const driftX = drift.x * ALOFT * FIELD_PER_METRE,
54
54
  driftZ = drift.y * ALOFT * FIELD_PER_METRE,
55
55
  slant = (FLARE * (1 + SHADOW_AT * THICK)) / (Math.max(light.y, 0) + DIP),
56
- sh = cloudU.uCloudSh.value;
56
+ cloudShadow = cloudU.uCloudSh.value;
57
57
  overhead.x = x * FIELD_PER_METRE + driftX;
58
58
  overhead.z = z * FIELD_PER_METRE + driftZ;
59
- sh.set(
59
+ cloudShadow.set(
60
60
  wrap((driftX + light.x * slant) / CLOUD_SHEET),
61
61
  wrap((driftZ + light.z * slant) / CLOUD_SHEET),
62
62
  threshold + SHADOW_FROM,
@@ -1,7 +1,13 @@
1
- // Coordinate early, whole-scene and incremental program warmup. The application supplies its pass
2
- // graph and decides how newly linked programs enter the renderer's first-use queue.
3
- export function createCompilationSchedule({renderer, scene, beginCompiles, putToUse, useProgram, timeoutMs = 20000, onError = () => {}}) {
1
+ /**
2
+ * Coordinate shader compilation and first use across an application's render passes.
3
+ * During loading, await `warmShaders(roots, { blocking: true })` to pass the blocking
4
+ * flag to `beginCompiles` and submit shader programs together. During play, omit
5
+ * the flag to follow the application's incremental schedule. The roots can be one
6
+ * subtree or several disjoint subtrees that share a lighting environment.
7
+ */
8
+ export function createCompilationSchedule({ renderer, scene, beginCompiles, putToUse, useProgram, timeoutMs = 20000, onError = () => {} }) {
4
9
  let warmed = false;
10
+ const interrupted = new WeakMap();
5
11
  const programs = () => renderer.info.programs;
6
12
  const addedSince = known => programs().filter(program => !known.has(program));
7
13
  function beginWarm() {
@@ -10,25 +16,84 @@ export function createCompilationSchedule({renderer, scene, beginCompiles, putTo
10
16
  try {
11
17
  const done = beginCompiles(scene, warmed);
12
18
  const added = addedSince(known);
13
- return Promise.resolve(done).then(() => putToUse(added.filter(p => programs().includes(p)))).catch(onError);
14
- } catch (error) { onError(error); }
19
+ return Promise.resolve(done)
20
+ .then(() => putToUse(added.filter(program => programs().includes(program))))
21
+ .catch(onError);
22
+ } catch (error) {
23
+ onError(error);
24
+ }
15
25
  }
16
- async function warmShaders(root = scene) {
26
+ // Disjoint subtrees of one scene can share a pass without being reparented. A blocking load
27
+ // may submit them together and initialize the programs before its first draw.
28
+ async function warmShaders(root = scene, { blocking = false, signal, retryKey = root } = {}) {
29
+ signal?.throwIfAborted();
30
+ if (Array.isArray(root)) {
31
+ const roots = root;
32
+ if (!roots.length) return;
33
+ root = {
34
+ traverse(visit) {
35
+ for (const tree of roots) tree.traverse(visit);
36
+ },
37
+ traverseVisible(visit) {
38
+ // The target scene already contributes its visible lights. Only detached roots
39
+ // bring additional lights to Three's compile pass.
40
+ for (const tree of roots) {
41
+ let parent = tree;
42
+ while (parent && parent !== scene) parent = parent.parent;
43
+ if (!parent) tree.traverseVisible(visit);
44
+ }
45
+ },
46
+ };
47
+ }
17
48
  const known = new Set(programs());
18
- let timer;
49
+ const unfinished = signal && interrupted.get(retryKey);
50
+ if (unfinished) for (const program of known) if (unfinished.has(program)) known.delete(program);
51
+ let timer, onAbort;
52
+ const deadline = signal && new AbortController();
53
+ const active = signal && AbortSignal.any([signal, deadline.signal]);
19
54
  try {
20
- const done = beginCompiles(root, warmed);
21
- if (root !== scene && !warmed) {
55
+ const done = beginCompiles(root, warmed, blocking, active);
56
+ if (root !== scene && !warmed && !blocking && !signal) {
22
57
  Promise.resolve(done).catch(onError);
23
58
  return;
24
59
  }
25
- await Promise.race([done, new Promise(resolve => { timer = setTimeout(resolve, timeoutMs); })]);
60
+ const limit = new Promise((resolve, reject) => {
61
+ if (!active) {
62
+ timer = setTimeout(resolve, timeoutMs);
63
+ return;
64
+ }
65
+ onAbort = () => reject(active.reason);
66
+ if (active.aborted) {
67
+ onAbort();
68
+ return;
69
+ }
70
+ active.addEventListener('abort', onAbort, { once: true });
71
+ timer = setTimeout(() => deadline.abort(new Error('Shader preparation timed out')), timeoutMs);
72
+ });
73
+ await Promise.race([done, limit]);
74
+ active?.throwIfAborted();
26
75
  if (root === scene) {
27
76
  for (const program of programs()) useProgram(program);
28
77
  warmed = true;
29
- } else await putToUse(addedSince(known));
30
- } catch (error) { onError(error); }
31
- finally { clearTimeout(timer); }
78
+ } else if (blocking) {
79
+ for (const program of addedSince(known)) useProgram(program);
80
+ } else await putToUse(addedSince(known), active);
81
+ if (unfinished) interrupted.delete(retryKey);
82
+ } catch (error) {
83
+ if (signal) {
84
+ const unclaimed = unfinished || new WeakSet();
85
+ for (const program of addedSince(known)) unclaimed.add(program);
86
+ interrupted.set(retryKey, unclaimed);
87
+ // Other passes in the same preparation may still have an incremental submission queued.
88
+ deadline.abort(error);
89
+ if (signal.aborted) throw signal.reason;
90
+ }
91
+ onError(error);
92
+ if (signal) throw error;
93
+ } finally {
94
+ clearTimeout(timer);
95
+ if (onAbort) active.removeEventListener('abort', onAbort);
96
+ }
32
97
  }
33
- return {beginWarm, warmShaders};
98
+ return { beginWarm, warmShaders };
34
99
  }
@@ -16,8 +16,11 @@ export class ContactShadows {
16
16
  geometry.setAttribute('intensity', new THREE.InstancedBufferAttribute(new Float32Array(capacity), 1).setUsage(THREE.DynamicDrawUsage));
17
17
  geometry.instanceCount = 0;
18
18
  const material = new THREE.ShaderMaterial({
19
- transparent: true, depthWrite: false, polygonOffset: true,
20
- polygonOffsetFactor: -2, polygonOffsetUnits: -6,
19
+ transparent: true,
20
+ depthWrite: false,
21
+ polygonOffset: true,
22
+ polygonOffsetFactor: -2,
23
+ polygonOffsetUnits: -6,
21
24
  uniforms: { opacityScale: { value: opacity }, lift: { value: lift } },
22
25
  vertexShader: `
23
26
  attribute vec4 contact;
@@ -28,8 +31,8 @@ export class ContactShadows {
28
31
  void main() {
29
32
  offset = position.xz;
30
33
  weight = intensity;
31
- vec3 p = contact.xyz + vec3(position.x * contact.w, lift, position.z * contact.w);
32
- gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
34
+ vec3 contactPosition = contact.xyz + vec3(position.x * contact.w, lift, position.z * contact.w);
35
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(contactPosition, 1.0);
33
36
  }`,
34
37
  fragmentShader: `
35
38
  uniform float opacityScale;
@@ -1,18 +1,69 @@
1
+ /**
2
+ * Create the Three.js renderer, scenes and camera used by a Roamwright world, and define
3
+ * the default Three.js visibility layer numbers shared across rendering passes.
4
+ * @module
5
+ */
6
+
1
7
  import * as THREE from 'three';
2
8
 
3
- export function createRenderContext(canvas, { antialias = true, fov = 68, near = 0.25, far = 7000 } = {}) {
9
+ /**
10
+ * Default Three.js layer numbers reserved by Roamwright's rendering passes.
11
+ * Every pass accepts a `layer` / `maskLayer` / `extraLayer` option to override its slot.
12
+ *
13
+ * - `main` (`0`): default scene objects reflected in planar water mirrors.
14
+ * - `unmirrored` (`1`): objects visible to the main camera but excluded from planar reflections unless enabled.
15
+ * - `stillCasters` (`2`): static shadow casters cached by `createStaticPointShadow` and `still-casters.js`.
16
+ * - `heightProbe` (`3`): temporary layer used during offscreen `createHeightProbe` depth measurements.
17
+ * - `reflectionMask` (`30`): water-visibility stencil mask drawn only by the planar reflection camera.
18
+ */
19
+ export const RENDER_LAYERS = Object.freeze({
20
+ main: 0,
21
+ unmirrored: 1,
22
+ stillCasters: 2,
23
+ heightProbe: 3,
24
+ reflectionMask: 30,
25
+ });
26
+
27
+ /**
28
+ * Create a shadow-enabled renderer, a perspective camera and a group for world objects.
29
+ * Size the renderer to the canvas and update the camera aspect ratio before rendering.
30
+ * @param {HTMLCanvasElement} canvas - Drawing surface for the WebGL renderer.
31
+ * @param {object} [options]
32
+ * @param {boolean} [options.antialias=true] - Hardware antialiasing on the drawing buffer.
33
+ * @param {number} [options.fov=68] - Vertical field of view in degrees.
34
+ * @param {number} [options.near=0.25] - Near clipping plane in world units.
35
+ * @param {number} [options.far=7000] - Far clipping plane in world units.
36
+ * @param {THREE.ToneMapping} [options.toneMapping=THREE.ACESFilmicToneMapping] - Renderer tone-mapping operator.
37
+ * @param {number} [options.toneMappingExposure=1.0] - Renderer tone-mapping exposure.
38
+ * @param {THREE.EulerOrder} [options.rotationOrder='YXZ'] - Camera Euler rotation order.
39
+ * @param {number[]} [options.enabledLayers=[RENDER_LAYERS.unmirrored]] - Additional camera layers enabled alongside layer 0.
40
+ * @returns The renderer, main scene, camera, world group and a separate scene for effects.
41
+ */
42
+ export function createRenderContext(
43
+ canvas,
44
+ {
45
+ antialias = true,
46
+ fov = 68,
47
+ near = 0.25,
48
+ far = 7000,
49
+ toneMapping = THREE.ACESFilmicToneMapping,
50
+ toneMappingExposure = 1.0,
51
+ rotationOrder = 'YXZ',
52
+ enabledLayers = [RENDER_LAYERS.unmirrored],
53
+ } = {},
54
+ ) {
4
55
  const renderer = new THREE.WebGLRenderer({ canvas, antialias, powerPreference: 'high-performance', stencil: false });
5
56
  renderer.outputColorSpace = THREE.SRGBColorSpace;
6
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
7
- renderer.toneMappingExposure = 1.0;
57
+ renderer.toneMapping = toneMapping;
58
+ renderer.toneMappingExposure = toneMappingExposure;
8
59
  renderer.shadowMap.enabled = true;
9
- renderer.shadowMap.type = Number(THREE.REVISION) === 170 ? THREE.PCFSoftShadowMap : THREE.PCFShadowMap;
60
+ renderer.shadowMap.type = THREE.PCFShadowMap;
10
61
  renderer.info.autoReset = false;
11
62
  const scene = new THREE.Scene();
12
63
  const camera = new THREE.PerspectiveCamera(fov, 1, near, far);
13
- camera.rotation.order = 'YXZ';
64
+ camera.rotation.order = rotationOrder;
14
65
  scene.add(camera);
15
- camera.layers.enable(1);
66
+ for (let i = 0; i < enabledLayers.length; i++) camera.layers.enable(enabledLayers[i]);
16
67
  const worldGroup = new THREE.Group();
17
68
  scene.add(worldGroup);
18
69
  const fxScene = new THREE.Scene();