roamwright 0.20.1 → 0.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (521) 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 +139 -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/cast-actors.js +379 -0
  253. package/motion/cast-manager.js +321 -0
  254. package/motion/contact-transition.js +5 -6
  255. package/motion/crowd-alarms.js +36 -6
  256. package/motion/crowd-attention.js +108 -0
  257. package/motion/crowd-beasts.js +203 -0
  258. package/motion/crowd-camp.js +295 -0
  259. package/motion/crowd-figure.js +100 -0
  260. package/motion/crowd-herd.js +86 -0
  261. package/motion/crowd-hold.js +130 -0
  262. package/motion/crowd-pose.js +296 -0
  263. package/motion/crowd-poses.js +481 -0
  264. package/motion/crowd-routine.js +44 -14
  265. package/motion/crowd-town.js +166 -0
  266. package/motion/crowd-water.js +143 -0
  267. package/motion/deck-surface.js +4 -2
  268. package/motion/figure-acts.js +411 -0
  269. package/motion/figure-arms.js +437 -0
  270. package/motion/figure-blade-slide.js +149 -0
  271. package/motion/figure-body-place.js +180 -0
  272. package/motion/figure-bones.js +118 -0
  273. package/motion/figure-bow-draw.js +70 -0
  274. package/motion/figure-fingers.js +215 -0
  275. package/motion/figure-gaze.js +205 -0
  276. package/motion/figure-gestures.js +452 -0
  277. package/motion/figure-grip.js +134 -0
  278. package/motion/figure-head.js +287 -0
  279. package/motion/figure-legs.js +264 -0
  280. package/motion/figure-links.js +293 -0
  281. package/motion/figure-locomotion.js +391 -0
  282. package/motion/figure-mount-up.js +180 -0
  283. package/motion/figure-mount.js +201 -0
  284. package/motion/figure-pose-frame.js +375 -0
  285. package/motion/figure-pose-table.js +156 -0
  286. package/motion/figure-pose.js +343 -0
  287. package/motion/figure-seat.js +267 -0
  288. package/motion/figure-sway.js +125 -0
  289. package/motion/flier-corvid-pose.js +74 -0
  290. package/motion/flier-flight-air.js +122 -0
  291. package/motion/flier-flight-echelon.js +164 -0
  292. package/motion/flier-flight-roost.js +131 -0
  293. package/motion/flier-swarm-flight.js +252 -0
  294. package/motion/formation.js +193 -0
  295. package/motion/instance-sight.js +8 -1
  296. package/motion/melee-contact.js +143 -0
  297. package/motion/moorings.js +48 -0
  298. package/motion/path-steering.js +358 -0
  299. package/motion/player.js +7 -6
  300. package/motion/quadruped.js +109 -33
  301. package/motion/spaces.js +58 -6
  302. package/motion/speech-cadence.js +304 -0
  303. package/motion/vessel-motion.js +57 -0
  304. package/motion/walk-grid.js +235 -0
  305. package/motion/weather.js +70 -12
  306. package/motion/wind.js +27 -1
  307. package/package.json +46 -4
  308. package/rendering/alpha-mips.js +340 -0
  309. package/rendering/animal-camel-figure.js +29 -0
  310. package/rendering/animal-canine-figure.js +59 -0
  311. package/rendering/animal-cattle-figure.js +36 -0
  312. package/rendering/animal-horse-figure.js +49 -0
  313. package/rendering/atmosphere.js +86 -0
  314. package/rendering/camera-track.js +156 -0
  315. package/rendering/{road-surface.js → cart-track.js} +40 -11
  316. package/rendering/cast-stage.js +299 -0
  317. package/rendering/caster-motion.js +2 -1
  318. package/rendering/cell-lod-options.js +46 -0
  319. package/rendering/cell-lod.js +665 -80
  320. package/rendering/cloth-material.js +140 -0
  321. package/rendering/cloud-dome.js +2 -2
  322. package/rendering/compilation-schedule.js +18 -10
  323. package/rendering/contact-shadows.js +5 -2
  324. package/rendering/context.js +47 -8
  325. package/rendering/crowd-batches.js +420 -0
  326. package/rendering/crowd-herd.js +198 -0
  327. package/rendering/crowd-rig.js +132 -0
  328. package/rendering/crowd-skinning.js +52 -9
  329. package/rendering/crowd-update.js +419 -0
  330. package/rendering/crowd-visibility.js +107 -0
  331. package/rendering/day-cycle-defaults.js +200 -0
  332. package/rendering/day-cycle.js +487 -0
  333. package/rendering/daylight.js +1 -3
  334. package/rendering/detail-range.js +6 -5
  335. package/rendering/dof.js +11 -4
  336. package/rendering/effects-frame.js +149 -0
  337. package/rendering/effects-water-rises.js +221 -0
  338. package/rendering/energy-stream.js +128 -0
  339. package/rendering/facade-glass-material.js +105 -0
  340. package/rendering/far-shadow.js +81 -54
  341. package/rendering/field-surface.js +138 -0
  342. package/rendering/figure-shield.js +105 -0
  343. package/rendering/figure-skeleton.js +329 -0
  344. package/rendering/fire-light-watch.js +197 -0
  345. package/rendering/fire-pools.js +148 -0
  346. package/rendering/flame-sources.js +86 -0
  347. package/rendering/flier-bird-looks.js +97 -0
  348. package/rendering/flier-corvid-figure.js +67 -0
  349. package/rendering/flier-long-body-company.js +169 -0
  350. package/rendering/flier-swarm.js +186 -0
  351. package/rendering/flocks.js +6 -2
  352. package/rendering/garment-material.js +145 -49
  353. package/rendering/glsl-literal.js +19 -0
  354. package/rendering/ground-marks.js +316 -0
  355. package/rendering/hair-strands.js +38 -24
  356. package/rendering/height-haze.js +80 -33
  357. package/rendering/height-probe.js +15 -3
  358. package/rendering/house-kit-meshes.js +124 -0
  359. package/rendering/interior-bake.js +807 -0
  360. package/rendering/label-layout.js +13 -3
  361. package/rendering/label-range.js +5 -2
  362. package/rendering/lamp-light-map.js +159 -0
  363. package/rendering/lamp-maps.js +62 -0
  364. package/rendering/lamp-wash.js +51 -0
  365. package/rendering/light-budget.js +19 -3
  366. package/rendering/light-points.js +21 -5
  367. package/rendering/local-lights.js +27 -7
  368. package/rendering/material-lod.js +5 -6
  369. package/rendering/memory-estimate.js +84 -0
  370. package/rendering/moored-fleet.js +186 -0
  371. package/rendering/nameplate-groups.js +84 -0
  372. package/rendering/nameplates.js +386 -0
  373. package/rendering/part-costs.js +104 -0
  374. package/rendering/particle-bursts.js +386 -0
  375. package/rendering/particle-emitters.js +61 -25
  376. package/rendering/particle-light-bursts.js +189 -0
  377. package/rendering/particles.js +134 -34
  378. package/rendering/pen-flocks.js +118 -0
  379. package/rendering/piece-batch.js +282 -6
  380. package/rendering/planar-reflection-options.js +159 -0
  381. package/rendering/planar-reflection.js +780 -77
  382. package/rendering/plant-cells.js +122 -0
  383. package/rendering/plant-reeds.js +113 -0
  384. package/rendering/plant-shade-trees.js +239 -0
  385. package/rendering/plant-tuft-patch.js +122 -0
  386. package/rendering/post-shaders.js +84 -21
  387. package/rendering/post.js +39 -19
  388. package/rendering/pressed-cover.js +135 -0
  389. package/rendering/prop-dig.js +136 -0
  390. package/rendering/room-light.js +250 -0
  391. package/rendering/room-materials.js +78 -0
  392. package/rendering/room-space.js +111 -0
  393. package/rendering/scene-lights.js +106 -0
  394. package/rendering/sea-shaders.js +83 -26
  395. package/rendering/settlement-approach.js +226 -0
  396. package/rendering/settlement-dissolve.js +89 -0
  397. package/rendering/settlement-quarter-warm.js +55 -0
  398. package/rendering/settlement-quarter.js +477 -0
  399. package/rendering/settlement-switch.js +42 -0
  400. package/rendering/settlement-town.js +110 -0
  401. package/rendering/shader-warmup.js +80 -36
  402. package/rendering/shadow-depth.js +40 -18
  403. package/rendering/ship-meshes.js +150 -0
  404. package/rendering/shot-cuts.js +68 -0
  405. package/rendering/sky-occlusion.js +42 -15
  406. package/rendering/sky-pmrem.js +216 -0
  407. package/rendering/sky.js +112 -50
  408. package/rendering/smoke-shadows.js +201 -0
  409. package/rendering/stage-framing.js +182 -0
  410. package/rendering/stage-lights.js +46 -39
  411. package/rendering/stain-material.js +74 -0
  412. package/rendering/static-point-shadow.js +62 -23
  413. package/rendering/still-casters.js +77 -27
  414. package/rendering/strata-material.js +2 -2
  415. package/rendering/street-lamps.js +166 -0
  416. package/rendering/sunbeam-motes.js +670 -0
  417. package/rendering/surface-light.js +65 -6
  418. package/rendering/surface-material.js +306 -0
  419. package/rendering/surface-projection.js +32 -0
  420. package/rendering/surface-snippets.js +314 -0
  421. package/rendering/taa.js +49 -18
  422. package/rendering/tree-impostor.js +929 -0
  423. package/rendering/vehicle-train.js +92 -0
  424. package/rendering/viewport.js +67 -4
  425. package/rendering/water-material.js +270 -82
  426. package/rendering/waypoint-beacons.js +191 -0
  427. package/rendering/world-matrices.js +0 -2
  428. package/ruff.toml +20 -0
  429. package/runtime/cue-cursor.js +21 -0
  430. package/runtime/device-quality.js +13 -2
  431. package/runtime/device.js +73 -0
  432. package/runtime/diagnostic-log.js +11 -3
  433. package/runtime/effect-sites.js +85 -0
  434. package/runtime/figure-orders.js +59 -0
  435. package/runtime/first-use.js +8 -5
  436. package/runtime/foley-script.js +124 -0
  437. package/runtime/foley-strides.js +333 -0
  438. package/runtime/frame-pacing.js +18 -4
  439. package/runtime/frame-yield.js +18 -0
  440. package/runtime/gpu-timing.js +8 -4
  441. package/runtime/grid-cache.js +16 -6
  442. package/runtime/grid-rows.js +5 -5
  443. package/runtime/hand-over.js +7 -2
  444. package/runtime/land-bake.js +78 -0
  445. package/runtime/lazy-sets.js +105 -0
  446. package/runtime/pool.js +17 -3
  447. package/runtime/quality-fit.js +59 -27
  448. package/runtime/region-pass-lay.js +40 -0
  449. package/runtime/region-pass.js +78 -0
  450. package/runtime/search.js +6 -2
  451. package/runtime/settlement-reach.js +42 -0
  452. package/runtime/sound-calls.js +113 -0
  453. package/runtime/sound-impacts.js +297 -0
  454. package/runtime/sound-voices.js +194 -0
  455. package/runtime/soundscape.js +282 -0
  456. package/runtime/spatial-audio.js +69 -20
  457. package/runtime/steady-frames.js +221 -0
  458. package/runtime/withdrawable-task.js +19 -8
  459. package/scripts/app-parts.mjs +118 -0
  460. package/scripts/bake-revisions.mjs +81 -0
  461. package/scripts/browser-scripts.mjs +64 -0
  462. package/scripts/bundle.mjs +192 -0
  463. package/scripts/check-app.sh +26 -0
  464. package/scripts/eslint-config.mjs +119 -0
  465. package/scripts/format.sh +92 -0
  466. package/scripts/keep-builds.mjs +158 -0
  467. package/scripts/layers.mjs +112 -0
  468. package/scripts/lint.sh +49 -0
  469. package/scripts/module-graph.mjs +123 -0
  470. package/scripts/pre-commit.sh +38 -0
  471. package/scripts/serve.py +5 -3
  472. package/scripts/site.mjs +358 -0
  473. package/scripts/test-runner.sh +42 -0
  474. package/scripts/vendor.mjs +221 -0
  475. package/scripts/verify-publish.mjs +175 -0
  476. package/scripts/world.mk +59 -0
  477. package/tools/README.md +73 -0
  478. package/tools/contact-sheet.cjs +137 -0
  479. package/tools/cpu-profile.cjs +275 -0
  480. package/tools/cpu-profile.test.cjs +98 -0
  481. package/tools/first-draws.cjs +395 -0
  482. package/tools/flight-guard.cjs +482 -0
  483. package/tools/flight-guard.test.cjs +153 -0
  484. package/tools/flight-profile.cjs +145 -0
  485. package/tools/frame-bench.cjs +336 -0
  486. package/tools/frame-parts.cjs +365 -0
  487. package/tools/ios-sim.sh +145 -0
  488. package/tools/load-audit.cjs +201 -0
  489. package/tools/look-compare.cjs +304 -0
  490. package/tools/look-guard.cjs +407 -0
  491. package/tools/look-guard.test.cjs +93 -0
  492. package/tools/look-stats.cjs +185 -0
  493. package/tools/look-stats.test.cjs +71 -0
  494. package/tools/memory-audit.cjs +323 -0
  495. package/tools/page-driver.cjs +320 -0
  496. package/tools/page-driver.test.cjs +219 -0
  497. package/tools/program-census-report.cjs +191 -0
  498. package/tools/program-census.cjs +465 -0
  499. package/tools/program-census.test.cjs +332 -0
  500. package/tools/remote-runner.sh +265 -0
  501. package/tools/runners.test.cjs +59 -0
  502. package/tools/scene-audit-beat.cjs +344 -0
  503. package/tools/scene-audit-sheet.cjs +282 -0
  504. package/tools/scene-audit.cjs +471 -0
  505. package/tools/scene-audit.test.cjs +201 -0
  506. package/tools/scene-batch.cjs +219 -0
  507. package/tools/scene-bench.cjs +149 -0
  508. package/tools/scene-bench.test.cjs +33 -0
  509. package/tools/scene-run.cjs +443 -0
  510. package/tools/scene-run.test.cjs +94 -0
  511. package/tools/servers.sh +59 -0
  512. package/tools/shader-arrival.cjs +316 -0
  513. package/tools/shader-renewal.cjs +53 -0
  514. package/tools/shader-renewal.test.cjs +115 -0
  515. package/tools/speed-guard.cjs +258 -0
  516. package/tools/stills.cjs +492 -0
  517. package/tools/stills.test.cjs +49 -0
  518. package/tools/turns.sh +7 -0
  519. package/tools/yaml.cjs +158 -0
  520. package/examples/viaduct.css +0 -75
  521. package/rendering/light-shafts.js +0 -131
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Land past a land's edge, so that no horizon is empty. Three things, each plain arrays that the caller makes meshes of:
3
+ *
4
+ * - {@link landEdgeGrid}: the border's own ground carried outward on a grid that is fine along the land and coarse far
5
+ * out. Where the sea meets the border the ground sinks to the sea's floor, so a cape that reaches the edge tapers off to
6
+ * a point instead of running on as a strip to the horizon; a border along land, or across a river's bed, is carried as
7
+ * it was. The same grid carries the sea's sheet ({@link landEdgeArrays}).
8
+ * - {@link createFarCoasts}: land the sheet does not hold but that lies in sight of it across the water, rising out of the
9
+ * sea past the edge as the land's own plain does.
10
+ * - {@link landEdgeRings}: rings of square outline round a land whose border is level all round, each point taking the
11
+ * border's colour and going over to the land's mean colour further out.
12
+ *
13
+ * `terrain-extension.js` is a third layout: rings that grow by a factor, joined to a mesh's own border vertices.
14
+ * @module
15
+ */
16
+
17
+ import { clamp, lerp, sstep } from '../math/scalar.js';
18
+ import { outlineDistance, outlineEdges } from './shore-grid.js';
19
+
20
+ /** The shape of the ground carried past a land's edge, in metres unless said. */
21
+ export const LAND_EDGE_SHAPE = {
22
+ /** Under the sea's level below which the border is the sea's floor, not a river's bed or a beach. */
23
+ seaFloor: 2,
24
+ /** Readings each way along the border, out to a point's own distance past it. */
25
+ along: 6,
26
+ /** Either side of a cape's taper over which its land falls to the sea's floor. */
27
+ coastRamp: 250,
28
+ /** Over how many metres past the border the sea's floor shelves down, and how many metres deeper. */
29
+ shelf: [300, 20],
30
+ /** How many times closer the grid's lines are along the land and in the rings just past it than far out (a twelfth of the land apart). */
31
+ fine: 8,
32
+ /** The outer land lies this far under the border's own ground, so the land's own mesh covers the seam. */
33
+ under: 0.4,
34
+ };
35
+
36
+ /**
37
+ * The outer land's grid of a square sheet: its lines along each axis, the indices of the lines on the sheet's edges, and
38
+ * its height at each point (NaN within the sheet, where the land's own mesh lies).
39
+ * @param {object} options
40
+ * @param {{ x0: number, z0: number, size: number, spacing: number }} options.sheet - The land's sheet.
41
+ * @param {(x: number, z: number) => number} options.heightAt - The land's ground, asked on the sheet and along its edges.
42
+ * @param {number} options.sea - The sea's level.
43
+ * @param {(x: number, z: number) => number} [options.farHeight] - Land past the edge that the sheet leaves out, and its sea's floor; -Infinity where there is none ({@link createFarCoasts}).
44
+ * @param {(x: number, z: number) => (number | null)} [options.covered] - The height to lay the grid at where another sheet is drawn over it, else null.
45
+ * @param {number} [options.reach=3] - How many times the land's size the grid runs out each way.
46
+ * @param {number} [options.rings=2] - How many of the coarse rings just past the land are drawn fine: more where a far shore must be followed.
47
+ * @param {Partial<typeof LAND_EDGE_SHAPE>} [options.shape] - Changes to {@link LAND_EDGE_SHAPE}.
48
+ * @returns {{ axis: number[], n: number, first: number, last: number, height: Float32Array, x0: number, z0: number }} `axis`:
49
+ * each line's offset from the sheet's first edge; `n`: cells to a side; `first` and `last`: the lines on the sheet's edges;
50
+ * `height`: one to a point, row by row.
51
+ */
52
+ export function landEdgeGrid({
53
+ sheet: L,
54
+ heightAt,
55
+ sea: seaLevel,
56
+ farHeight = () => -Infinity,
57
+ covered = () => null,
58
+ reach = 3,
59
+ rings = 2,
60
+ shape = {},
61
+ }) {
62
+ const {
63
+ seaFloor: SEA_FLOOR,
64
+ along: ALONG,
65
+ coastRamp: COAST_RAMP,
66
+ shelf: SHELF,
67
+ fine: FINE,
68
+ under: UNDER,
69
+ } = { ...LAND_EDGE_SHAPE, ...shape };
70
+ let edges = null; // for each edge of the sheet, the distance along it from each of its points to the nearest sea
71
+ // The height carried past the sheet's edge to (x, z): the border's own, sunk to the sea's floor where the sea meets the border
72
+ // within the point's distance past it. The land falls to the bed over COAST_RAMP either side of the taper's line, so the
73
+ // waterline runs along it.
74
+ function heightPast(x, z) {
75
+ const cx = clamp(x, L.x0, L.x0 + L.size),
76
+ cz = clamp(z, L.z0, L.z0 + L.size),
77
+ pastX = Math.abs(x - cx),
78
+ pastZ = Math.abs(z - cz),
79
+ own = heightAt(cx, cz);
80
+ if (!pastX && !pastZ) return own;
81
+ let low = own,
82
+ margin = Infinity; // how much further the nearest sea lies along the border than the point lies past it
83
+ const along = (past, at, toSea) => {
84
+ for (let k = -ALONG; k <= ALONG; k++) low = Math.min(low, at((k / ALONG) * past));
85
+ margin = Math.min(margin, toSea - past);
86
+ };
87
+ // along a north or south edge, and along a west or east edge
88
+ if (pastZ > 0) along(pastZ, s => heightAt(clamp(cx + s, L.x0, L.x0 + L.size), cz), seaAlong(cz > L.z0 ? 1 : 0, cx - L.x0));
89
+ if (pastX > 0) along(pastX, s => heightAt(cx, clamp(cz + s, L.z0, L.z0 + L.size)), seaAlong(cx > L.x0 ? 3 : 2, cz - L.z0));
90
+ const across = farHeight(x, z); // land the sheet leaves out that lies out there, and its sea's floor
91
+ if (margin === Infinity) return Math.max(own, across);
92
+ const bed = low - SHELF[1] * sstep(0, SHELF[0], Math.max(pastX, pastZ));
93
+ return Math.max(lerp(bed, own, sstep(-COAST_RAMP, COAST_RAMP, margin)), across);
94
+ }
95
+ // The distance in metres along edge `side` of the sheet (0 north, 1 south, 2 west, 3 east) from the point `at` metres along it
96
+ // to the nearest of its points where the sea is (Infinity where there is none): worked out once for every point of each edge,
97
+ // in two passes, so that it changes smoothly along the edge.
98
+ function seaAlong(side, at) {
99
+ if (!edges) {
100
+ const n = Math.round(L.size / L.spacing) + 1,
101
+ sea = seaLevel - SEA_FLOOR;
102
+ edges = [0, 1, 2, 3].map(e => {
103
+ const d = new Float32Array(n);
104
+ for (let i = 0; i < n; i++) {
105
+ const t = i * L.spacing,
106
+ h = e < 2 ? heightAt(L.x0 + t, e ? L.z0 + L.size : L.z0) : heightAt(e > 2 ? L.x0 + L.size : L.x0, L.z0 + t);
107
+ d[i] = h < sea ? 0 : i ? d[i - 1] + L.spacing : Infinity;
108
+ }
109
+ for (let i = n - 2; i >= 0; i--) d[i] = Math.min(d[i], d[i + 1] + L.spacing);
110
+ return d;
111
+ });
112
+ }
113
+ const d = edges[side],
114
+ u = clamp(at / L.spacing, 0, d.length - 1),
115
+ i = Math.min(Math.floor(u), d.length - 2);
116
+ return d[i] === Infinity || d[i + 1] === Infinity ? Math.min(d[i], d[i + 1]) : lerp(d[i], d[i + 1], u - i);
117
+ }
118
+ // The coordinates, from the sheet's edge, of the grid's lines along one axis: a twelfth of the sheet apart far out, and FINE
119
+ // times closer along the sheet and in the `rings` rings past it, so that a cape or a bay that meets the border is followed.
120
+ function outerAxis(size, reach, rings) {
121
+ const step = size / 12,
122
+ fine = step / FINE,
123
+ axis = [];
124
+ for (let i = 0; i < reach * 12 - rings; i++) axis.push(-reach * size + i * step);
125
+ for (let k = 0; k < FINE * rings; k++) axis.push(-rings * step + k * fine);
126
+ for (let k = 0; k < 12 * FINE; k++) axis.push(k * fine);
127
+ for (let k = 0; k < FINE * rings; k++) axis.push(size + k * fine);
128
+ for (let i = 0; i < reach * 12 + 1 - rings; i++) axis.push(size + rings * step + i * step);
129
+ return axis;
130
+ }
131
+ const axis = outerAxis(L.size, reach, rings),
132
+ n = axis.length - 1,
133
+ first = reach * 12 - rings + FINE * rings, // the first line on the sheet's edge
134
+ last = first + 12 * FINE, // and the last
135
+ height = new Float32Array((n + 1) * (n + 1));
136
+ for (let j = 0; j <= n; j++)
137
+ for (let i = 0; i <= n; i++) {
138
+ const x = L.x0 + axis[i],
139
+ z = L.z0 + axis[j],
140
+ hidden = i > first && i < last && j > first && j < last,
141
+ laid = hidden ? null : covered(x, z);
142
+ height[j * (n + 1) + i] = hidden ? NaN : laid !== null ? laid : heightPast(x, z) - UNDER;
143
+ }
144
+ return { axis, n, first, last, height, x0: L.x0, z0: L.z0 };
145
+ }
146
+
147
+ /**
148
+ * The arrays of a mesh over a grid's points, its cells two triangles facing up.
149
+ * @param {{ axis: number[], n: number, x0: number, z0: number }} grid - {@link landEdgeGrid}'s.
150
+ * @param {(k: number) => number} y - The height of point `k`.
151
+ * @param {(i: number, j: number) => boolean} keep - Whether cell (i, j) is drawn.
152
+ * @returns {{ position: Float32Array, index: number[] }} World positions, and the triangles' indices.
153
+ */
154
+ export function landEdgeArrays({ axis, n, x0, z0 }, y, keep) {
155
+ const position = new Float32Array((n + 1) * (n + 1) * 3),
156
+ index = [];
157
+ for (let j = 0; j <= n; j++)
158
+ for (let i = 0; i <= n; i++) position.set([x0 + axis[i], y(j * (n + 1) + i), z0 + axis[j]], (j * (n + 1) + i) * 3);
159
+ for (let j = 0; j < n; j++)
160
+ for (let i = 0; i < n; i++) {
161
+ if (!keep(i, j)) continue;
162
+ const a = j * (n + 1) + i;
163
+ index.push(a, a + n + 1, a + 1, a + 1, a + n + 1, a + n + 2);
164
+ }
165
+ return { position, index };
166
+ }
167
+
168
+ /**
169
+ * Land past a land's edge that lies in sight of it across the water: coasts given as outlines, whose land rises out of the
170
+ * sea as the caller's plain does from its own shore.
171
+ * @param {object} options
172
+ * @param {[number, number][][]} options.coasts - Each coast's outline, as X/Z points.
173
+ * @param {(d: number) => number} options.plain - The height of the plain `d` metres inland of a shore (negative: out to sea).
174
+ * @param {(x: number, z: number) => number} [options.warp] - Metres the shore line wanders at a place.
175
+ * @param {(x: number, z: number, d: number) => number} [options.swell] - Metres the plain swells at a place `d` metres inland.
176
+ * @param {number} [options.shelfReach=900] - Metres off a coast within which its sea's floor shelves up to it: past that there is none.
177
+ * @returns {(x: number, z: number) => number} The height of the far land at a place, and of its sea's floor near it; -Infinity where it has none.
178
+ */
179
+ export function createFarCoasts({ coasts, plain, warp = () => 0, swell = () => 0, shelfReach = 900 }) {
180
+ // the outlines' edges and their bounds
181
+ const outlined = coasts.map(coast => ({
182
+ edges: outlineEdges(coast),
183
+ x0: Math.min(...coast.map(p => p[0])) - shelfReach,
184
+ x1: Math.max(...coast.map(p => p[0])) + shelfReach,
185
+ z0: Math.min(...coast.map(p => p[1])) - shelfReach,
186
+ z1: Math.max(...coast.map(p => p[1])) + shelfReach,
187
+ }));
188
+ return function farHeight(x, z) {
189
+ let d = -Infinity;
190
+ for (const o of outlined) if (x > o.x0 && x < o.x1 && z > o.z0 && z < o.z1) d = Math.max(d, outlineDistance(o.edges, x, z));
191
+ if (d < -shelfReach) return -Infinity;
192
+ d += warp(x, z);
193
+ return plain(d) + swell(x, z, d);
194
+ };
195
+ }
196
+
197
+ // The point at t (0 to 4, once round) on a square outline of half size h about the origin: a side for each whole of t.
198
+ function squareAt(t, h, out) {
199
+ const side = Math.floor(t) % 4,
200
+ f = (t - Math.floor(t)) * 2 - 1;
201
+ out[0] = [f, 1, -f, -1][side] * h;
202
+ out[1] = [-1, f, 1, -f][side] * h;
203
+ return out;
204
+ }
205
+
206
+ /**
207
+ * Rings of square outline round a square land whose border is level, from the border out to the far haze, as the arrays of
208
+ * one mesh in two groups (near and far, for two materials). Each point takes the colour of the border where it leaves it,
209
+ * going over to the border's mean colour further out, so that looking along the border, or out over it, it is the same
210
+ * plain running on.
211
+ * @param {object} options
212
+ * @param {number} options.half - Half the size of the innermost ring, in metres (just inside the land's border).
213
+ * @param {number[]} options.past - Metres past that ring of each ring, the first 0.
214
+ * @param {number} options.along - Metres along the border between two points of the first ring.
215
+ * @param {number} options.level - The ground's height at the border all round.
216
+ * @param {(x: number, z: number, past: number) => number} [options.swell] - Metres the plain swells at a place `past` metres out.
217
+ * @param {(x: number, z: number, out: number[]) => number[]} options.colourAt - The land's colour at the border point nearest a place, in linear light.
218
+ * @param {[number, number]} options.meanFrom - Metres past the border where its own colour begins to give way to the mean, and has.
219
+ * @param {number} options.nearRings - How many rings from the border are in the near group.
220
+ * @param {number} [options.grain=9] - Metres of ground to one unit of the texture coordinates, as the land's own mesh has them.
221
+ * @param {number} [options.x=0] - World X of the land's centre.
222
+ * @param {number} [options.z=0] - World Z of the land's centre.
223
+ * @returns {{ position: Float32Array, normal: Float32Array, color: Float32Array, uv: Float32Array, index: number[], nearCount: number }}
224
+ * The mesh's arrays (its normals straight up: a caller that wants them smooth works them out from the triangles), and how
225
+ * many of its indices belong to the near group.
226
+ */
227
+ export function landEdgeRings({
228
+ half,
229
+ past: PAST,
230
+ along,
231
+ level,
232
+ swell = () => 0,
233
+ colourAt,
234
+ meanFrom,
235
+ nearRings,
236
+ grain = 9,
237
+ x: cx = 0,
238
+ z: cz = 0,
239
+ }) {
240
+ const inner = half,
241
+ count = Math.round((8 * inner) / along),
242
+ rings = PAST.length,
243
+ position = new Float32Array(rings * count * 3),
244
+ normal = new Float32Array(rings * count * 3),
245
+ color = new Float32Array(rings * count * 3),
246
+ uv = new Float32Array(rings * count * 2),
247
+ xz = [0, 0],
248
+ edge = [0, 0, 0],
249
+ mean = [0, 0, 0],
250
+ // a place on the ring `out` metres past the innermost, t of the way round (0 to 4)
251
+ ringAt = (t, out) => {
252
+ squareAt(t, inner + out, xz);
253
+ if (cx) xz[0] += cx;
254
+ if (cz) xz[1] += cz;
255
+ return xz;
256
+ };
257
+ for (let i = 0; i < count; i++) {
258
+ ringAt((i / count) * 4, 0);
259
+ colourAt(xz[0], xz[1], edge);
260
+ for (let c = 0; c < 3; c++) mean[c] += edge[c] / count;
261
+ }
262
+ for (let r = 0; r < rings; r++)
263
+ for (let i = 0; i < count; i++) {
264
+ const p = r * count + i,
265
+ past = PAST[r];
266
+ ringAt((i / count) * 4, past);
267
+ const [x, z] = xz;
268
+ position[p * 3] = x;
269
+ position[p * 3 + 1] = level + swell(x, z, past);
270
+ position[p * 3 + 2] = z;
271
+ normal[p * 3 + 1] = 1;
272
+ const toMean = sstep(meanFrom[0], meanFrom[1], past);
273
+ ringAt((i / count) * 4, 0);
274
+ colourAt(xz[0], xz[1], edge);
275
+ for (let c = 0; c < 3; c++) color[p * 3 + c] = edge[c] + (mean[c] - edge[c]) * toMean;
276
+ uv[p * 2] = x / grain;
277
+ uv[p * 2 + 1] = z / grain;
278
+ }
279
+ const index = [];
280
+ let nearCount = 0;
281
+ for (let r = 0; r < rings - 1; r++) {
282
+ if (r === nearRings) nearCount = index.length;
283
+ for (let i = 0; i < count; i++) {
284
+ const a = r * count + i,
285
+ b = r * count + ((i + 1) % count),
286
+ c = a + count,
287
+ d = b + count;
288
+ index.push(a, b, c, b, d, c); // facing up
289
+ }
290
+ }
291
+ return { position, normal, color, uv, index, nearCount };
292
+ }
@@ -0,0 +1,349 @@
1
+ /**
2
+ * The faces of the cliffs of flat-topped mounds (tels, `land-earthworks.js`). A land's mesh, a point every few metres,
3
+ * rounds a mound's brow off over a cell or two and cannot hold the runnels rain cuts down its face, so each mound with a
4
+ * cliff side is given a finer mesh over that side: rows across the face from a little way in on its top to a little way out
5
+ * on the plain, a column every metre or so along it, standing as high as the mound's own shape where the land's mesh lies
6
+ * under it and a little over it elsewhere, and sinking under it at its edges, so that no seam shows. The face is ribbed
7
+ * between runnels; clods and fallen courses stand out from it, and here and there a stretch of it has slumped.
8
+ *
9
+ * Further off, where the land's mesh is drawn at its first coarser level, a lighter copy of the face is laid over whichever
10
+ * of the two meshes stands higher, so that the land need not be held at its finest there. What walks on the mound stands
11
+ * on the face ({@link MoundFaces.heightAt}). Typed arrays only, the same on a page and in a worker.
12
+ * @module
13
+ */
14
+
15
+ import { TAU, clamp, lerp, sstep } from '../math/scalar.js';
16
+ import { gridTriangleHeight, triangleHeightOf } from './grid-sample.js';
17
+
18
+ /**
19
+ * The shape of the faces, in metres unless said. Pass any of these to {@link createMoundFaces} to change it.
20
+ */
21
+ export const MOUND_FACE_SHAPE = {
22
+ /** The face is laid where the mound's side is at least this much its cliff, 0 to 1. */
23
+ leastCliff: 0.3,
24
+ /**
25
+ * The near face's points: metres along the brow from one column to the next; rows on the mound's top, this many metres in
26
+ * from its brow; rows down the face, evenly spaced in height; and rows on the plain, this many metres out from its foot.
27
+ */
28
+ near: { column: 1.2, onTop: [12, 5, 2], faceRows: 24, onPlain: [2, 6, 12] },
29
+ /** The same for the lighter copy drawn further off. */
30
+ lighter: { column: 1.8, onTop: [12, 4], faceRows: 12, onPlain: [4, 12] },
31
+ /** A rib between two runnels stands out from the face by this much at most. */
32
+ rib: 2.8,
33
+ /** Each rib strays this far to the side on its way down. */
34
+ meander: 5,
35
+ /** The clods and fallen courses on the face stand out by this much at most. */
36
+ lump: 2.4,
37
+ /** Metres along the brow in which one slump may lie, where a stretch of the face has slid. */
38
+ slumpEvery: 46,
39
+ /** The share of those stretches that have one, 0 to 1. */
40
+ slumpShare: 0.55,
41
+ /** Half a slump's width, least and most. */
42
+ slumpWide: [8, 19],
43
+ /** A slump's lobe of debris stands out by up to this much, */
44
+ slumpOut: 4.5,
45
+ /** and its scar under the brow is cut back by up to this much. */
46
+ scar: 2.2,
47
+ /** The face keeps this far over the land's mesh where it lies on it, */
48
+ lift: 0.04,
49
+ /** and sinks this far under it at its edges. */
50
+ sink: 0.1,
51
+ /** Metres of ground to one unit of the faces' texture coordinates, as the land's own mesh has them. */
52
+ grain: 9,
53
+ };
54
+
55
+ /**
56
+ * @typedef {object} MoundFaces
57
+ * @property {() => object[]} cliffMounds - The mounds of the earthworks laid out that have a cliff side.
58
+ * @property {(mounds: object[], sheet: { x0: number, z0: number, spacing: number, stride: number, heights: Float32Array }) => object[]} layFaces -
59
+ * The faces of those mounds over a land's baked sheet. Each has its rows (`columns`, `a0`, `step`, `n`, `near`, `far`, and
60
+ * its mound `m`) and the arrays of its mesh (`arrays`) and of its lighter copy (`lighter`): `{ position, normal, uv, index, box }`,
61
+ * `box` the ground it covers as [x0, z0, x1, z1]. Everything survives structured cloning.
62
+ * @property {(faces: object[]) => void} adopt - Has `heightAt` read these faces from now on.
63
+ * @property {(adopted: Promise<void>) => void} layingFaces - Notes that faces are being laid: `adopted` settles once they are adopted.
64
+ * @property {(mound: { x: number, z: number }) => Promise<object[]>} facesOf - The faces laid on a mound, once the land's are.
65
+ * @property {(x: number, z: number) => number} heightAt - The height of a face at a place, or -Infinity where none is laid.
66
+ * @property {object[]} faces - The faces adopted.
67
+ * @property {() => void} forget - Forgets the faces (a land is let go).
68
+ */
69
+
70
+ /**
71
+ * Make the cliff faces of a land's mounds.
72
+ * @param {object} options
73
+ * @param {(x: number, z: number, channel: number) => number} options.vnoise - Seeded value noise, 0 to 1.
74
+ * @param {(i: number, j: number, channel: number) => number} options.hash2 - Seeded hash of two integers, 0 to 1 (`createHash(seed)`).
75
+ * @param {import('./land-earthworks.js').Earthworks} options.earthworks - The land's earthworks, whose mounds these are.
76
+ * @param {Partial<typeof MOUND_FACE_SHAPE>} [options.shape] - Changes to {@link MOUND_FACE_SHAPE}.
77
+ * @returns {MoundFaces}
78
+ */
79
+ export function createMoundFaces({ vnoise, hash2, earthworks, shape = {} }) {
80
+ const {
81
+ leastCliff: LEAST_CLIFF,
82
+ near: NEAR,
83
+ lighter: LIGHTER,
84
+ rib: RIB,
85
+ meander: MEANDER,
86
+ lump: LUMP,
87
+ slumpEvery: SLUMP_EVERY,
88
+ slumpShare: SLUMP_SHARE,
89
+ slumpWide: SLUMP_WIDE,
90
+ slumpOut: SLUMP_OUT,
91
+ scar: SCAR,
92
+ lift: LIFT,
93
+ sink: SINK,
94
+ grain: GRAIN,
95
+ } = { ...MOUND_FACE_SHAPE, ...shape };
96
+ const { heap, onCliff, telHeight } = earthworks,
97
+ { face: FACE, faceCurve: FACE_CURVE } = earthworks.shape; // where a mound's top ends on its cliff side, and the power its face rises by
98
+ let ground = null; // the sheet the faces are being laid over
99
+ const faces = []; // { m, a0, step, n, rows: [{ d: Float32Array, y: Float32Array }] for each column }, and the box it lies in
100
+ let laying = Promise.resolve(); // settles once the faces being laid for the land are adopted (layingFaces)
101
+
102
+ // A rib's height across it, 0 to 1, at q ribs along: a sharp crest between broad runnels.
103
+ function crestAt(q) {
104
+ return (1 - Math.abs(2 * (q - Math.floor(q)) - 1)) ** 1.3;
105
+ }
106
+ // Metres a tel's face stands out from its shape `along` metres round its brow and `down` of the way from its brow to its foot
107
+ // (0 to 1, more on the plain): a rib between runnels, or nothing in one.
108
+ function ribOut(along, down) {
109
+ const at = along + MEANDER * (vnoise(along * 0.04, down * 1.7, 396) - 0.5),
110
+ great = crestAt(at / 11 + 1.6 * vnoise(at * 0.017, 0.5, 391)) * (0.3 + 0.7 * vnoise(at * 0.05, 1.5, 392)),
111
+ small = crestAt(at / 3.6 + 0.8 * vnoise(at * 0.06, 2.5, 394)) * vnoise(at * 0.13, 3.5, 395);
112
+ return RIB * (0.75 * great + 0.25 * small) * (1 - sstep(0.35, 1, down));
113
+ }
114
+ // Metres a slump moves a tel's face out (or, in its scar, in) `along` metres round its brow and `down` of the way from its brow to
115
+ // its foot: the debris of a stretch that slid lies lower down, bulging over the face's lower half, and its scar is cut back
116
+ // under the brow.
117
+ function slumpOut(along, down) {
118
+ const cell = Math.floor(along / SLUMP_EVERY);
119
+ let out = 0;
120
+ for (let k = cell - 1; k <= cell + 1; k++) {
121
+ if (hash2(k, 0, 397) > SLUMP_SHARE) continue;
122
+ const middle = (k + 0.2 + 0.6 * hash2(k, 1, 397)) * SLUMP_EVERY,
123
+ half = SLUMP_WIDE[0] + (SLUMP_WIDE[1] - SLUMP_WIDE[0]) * hash2(k, 2, 397),
124
+ q = (along - middle) / half;
125
+ if (Math.abs(q) >= 1) continue;
126
+ const bell = (1 - q * q) ** 2,
127
+ reach = 0.85 + 0.3 * hash2(k, 3, 397), // how far down its lobe ran out
128
+ lobe = sstep(0.28, 0.62, down) * sstep(reach + 0.2, reach - 0.15, down),
129
+ scar = sstep(0.04, 0.12, down) * sstep(0.34, 0.2, down);
130
+ out += bell * (SLUMP_OUT * (0.6 + 0.4 * hash2(k, 4, 397)) * lobe - SCAR * scar);
131
+ }
132
+ return out;
133
+ }
134
+ // Metres the clods and fallen courses on a tel's face stand out at `along` metres round its brow, `y` metres high, `share` of
135
+ // the way up its heap (telShare): on the face, not on its brow nor where it has spread out at its foot.
136
+ function lumpsAt(along, y, share) {
137
+ const great = vnoise(along * 0.16, y * 0.19, 393),
138
+ small = vnoise(along * 0.42, y * 0.47, 398);
139
+ return LUMP * sstep(0.02, 0.18, share) * sstep(1, 0.88, share) * sstep(0.45, 0.95, 0.68 * great + 0.32 * small);
140
+ }
141
+ // The distance from the middle of tel m, along the bearing (c, s), at which its ragged reach (land-earthworks.js) is `target`:
142
+ // the reach strays with the place, so it is found in a few steps.
143
+ function reachAlong(m, c, s, target, cliff) {
144
+ let d = target;
145
+ for (let k = 0; k < 5; k++) {
146
+ const x = m.x + c * d,
147
+ z = m.z + s * d;
148
+ d = (target - 9 * cliff * (vnoise(x * 0.03, z * 0.03, 372) - 0.5)) / (0.9 + 0.2 * vnoise(x * 0.011, z * 0.011, 371));
149
+ }
150
+ return d;
151
+ }
152
+ // The height at (x, z) of the triangles of the ground's mesh drawn with a point every `stride` points of the sheet (1 at its finest,
153
+ // 2 at its first coarser level), its points raised to `at(x, z)`, each looked up once into `cache` (by its place on the sheet).
154
+ function asMeshed(at, x, z, cache, stride = 1) {
155
+ const spacing = ground.spacing * stride,
156
+ { x0, z0 } = ground,
157
+ u = (x - x0) / spacing,
158
+ v = (z - z0) / spacing,
159
+ i = Math.floor(u),
160
+ j = Math.floor(v),
161
+ node = (di, dj) => {
162
+ const k = (j + dj) * stride * ground.stride + (i + di) * stride;
163
+ let y = cache.get(k);
164
+ if (y === undefined) cache.set(k, (y = at(x0 + (i + di) * spacing, z0 + (j + dj) * spacing)));
165
+ return y;
166
+ };
167
+ return triangleHeightOf(node, u - i, v - j);
168
+ }
169
+ // The height of the ground's own mesh at (x, z), at its finest.
170
+ const meshHeight = (x, z) => gridTriangleHeight(ground, ground.heights, x, z);
171
+ // The height of the ground's own mesh at its first coarser level, a point every second point of the sheet, at (x, z).
172
+ function coarseMeshHeight(x, z, cache) {
173
+ return asMeshed(meshHeight, x, z, cache, 2);
174
+ }
175
+
176
+ // The face of tel m's cliff side: its columns' rows, the ground under the plain beside it read off the ground's mesh. `lighter`:
177
+ // the lighter copy (LIGHTER), laid over the ground's mesh at its finest and at its first coarser level alike.
178
+ function layFace(m, lighter = false) {
179
+ const { column, onTop, faceRows, onPlain } = lighter ? LIGHTER : NEAR;
180
+ let reach = 0;
181
+ while (reach < Math.PI && onCliff(m, Math.cos(m.cliff + reach), Math.sin(m.cliff + reach)) >= LEAST_CLIFF) reach += 0.002;
182
+ const brow = m.r * FACE,
183
+ step = column / brow,
184
+ n = Math.ceil((2 * reach) / step) + 1,
185
+ a0 = m.cliff - ((n - 1) * step) / 2,
186
+ plain = meshHeight, // the ground beyond the tel's foot is its own base
187
+ cache = new Map(), // the tel's shape at the ground's points
188
+ coarse = new Map(), // and the ground's own height at its coarser level's points
189
+ columns = [];
190
+ for (let i = 0; i < n; i++) {
191
+ const a = a0 + i * step,
192
+ c = Math.cos(a),
193
+ s = Math.sin(a),
194
+ cliff = onCliff(m, c, s),
195
+ out = ribOut(a * brow, 0) * cliff, // where the rows are placed: the brow's own
196
+ // the ground the tel stands on, taken as level along this column at its height out on the plain
197
+ base = plain(m.x + c * reachAlong(m, c, s, m.r * 1.3, cliff), m.z + s * reachAlong(m, c, s, m.r * 1.3, cliff)),
198
+ shape = (x, z, shift) => telHeight(m, x, z, Math.hypot(x - m.x, z - m.z), base, shift),
199
+ targets = [
200
+ ...onTop.map(t => brow - t),
201
+ ...Array.from({ length: faceRows + 1 }, (_, k) => m.r - (m.r - brow) * (1 - k / faceRows) ** (1 / FACE_CURVE)),
202
+ ...onPlain.map(t => m.r + t),
203
+ ],
204
+ rows = targets.length,
205
+ d = new Float32Array(rows),
206
+ y = new Float32Array(rows);
207
+ for (let j = 0; j < rows; j++) {
208
+ const r = reachAlong(m, c, s, targets[j] + out, cliff),
209
+ x = m.x + c * r,
210
+ z = m.z + s * r,
211
+ mesh = meshHeight(x, z),
212
+ down = (j - onTop.length) / faceRows, // how far down the face the row lies: below 0 on the top, past 1 on the plain
213
+ ribbed = shape(x, z, (ribOut(a * brow, down) + slumpOut(a * brow, down)) * cliff),
214
+ lumps = lumpsAt(a * brow, ribbed, heap.share) * cliff, // fallen courses and clods
215
+ heaped = ribbed + lumps,
216
+ bare = (px, pz) => shape(px, pz, 0),
217
+ // how far the tel's shape, ribbed and lumpy, stands over the shape the ground's mesh draws of it, at its finest
218
+ laid = mesh + Math.max(heaped - asMeshed(bare, x, z, cache), 0),
219
+ edge = i === 0 || i === n - 1 || j === 0 || j === rows - 1;
220
+ d[j] = r;
221
+ if (!lighter) y[j] = edge ? mesh - SINK : laid + LIFT;
222
+ else {
223
+ // and at its coarser level, which stands over the tel's own shape where the face is hollow and under it on the brow
224
+ const coarseMesh = coarseMeshHeight(x, z, coarse),
225
+ coarseLaid = coarseMesh + Math.max(heaped - asMeshed(bare, x, z, cache, 2), 0);
226
+ y[j] = edge ? Math.min(mesh, coarseMesh) - SINK : Math.max(laid, coarseLaid) + LIFT;
227
+ }
228
+ }
229
+ columns.push({ d, y, c, s });
230
+ cache.clear();
231
+ coarse.clear();
232
+ }
233
+ const near = Math.min(...columns.map(col => col.d[0])),
234
+ far = Math.max(...columns.map(col => col.d[col.d.length - 1]));
235
+ return { m, a0, step, n, columns, near, far };
236
+ }
237
+ // The face's points, normals (worked out from its own points), the ground's grain coordinates (as the ground's mesh has them) and
238
+ // triangles, as arrays for a mesh; and the box of ground it covers, [x0, z0, x1, z1].
239
+ function faceArrays(face) {
240
+ const { columns, n } = face,
241
+ rows = columns[0].d.length,
242
+ position = new Float32Array(n * rows * 3),
243
+ uv = new Float32Array(n * rows * 2),
244
+ normal = new Float32Array(n * rows * 3),
245
+ index = new (n * rows < 65536 ? Uint16Array : Uint32Array)((n - 1) * (rows - 1) * 6),
246
+ box = [Infinity, Infinity, -Infinity, -Infinity];
247
+ columns.forEach(({ d, y, c, s }, i) => {
248
+ for (let j = 0; j < rows; j++) {
249
+ const k = i * rows + j,
250
+ x = face.m.x + c * d[j],
251
+ z = face.m.z + s * d[j];
252
+ position.set([x, y[j], z], k * 3);
253
+ uv.set([x / GRAIN, z / GRAIN], k * 2);
254
+ box[0] = Math.min(box[0], x);
255
+ box[1] = Math.min(box[1], z);
256
+ box[2] = Math.max(box[2], x);
257
+ box[3] = Math.max(box[3], z);
258
+ }
259
+ });
260
+ const at = (i, j, axis) => position[(clamp(i, 0, n - 1) * rows + clamp(j, 0, rows - 1)) * 3 + axis];
261
+ for (let i = 0; i < n; i++)
262
+ for (let j = 0; j < rows; j++) {
263
+ // along the brow, and down the face: the face's normal is square to both, turned up
264
+ const ax = at(i + 1, j, 0) - at(i - 1, j, 0),
265
+ ay = at(i + 1, j, 1) - at(i - 1, j, 1),
266
+ az = at(i + 1, j, 2) - at(i - 1, j, 2),
267
+ bx = at(i, j + 1, 0) - at(i, j - 1, 0),
268
+ by = at(i, j + 1, 1) - at(i, j - 1, 1),
269
+ bz = at(i, j + 1, 2) - at(i, j - 1, 2),
270
+ nx = ay * bz - az * by,
271
+ ny = az * bx - ax * bz,
272
+ nz = ax * by - ay * bx,
273
+ unit = (ny < 0 ? -1 : 1) / (Math.hypot(nx, ny, nz) || 1);
274
+ normal.set([nx * unit, ny * unit, nz * unit], (i * rows + j) * 3);
275
+ }
276
+ let t = 0;
277
+ for (let i = 0; i + 1 < n; i++)
278
+ for (let j = 0; j + 1 < rows; j++, t += 6) {
279
+ const k = i * rows + j;
280
+ index.set([k, k + rows, k + 1, k + 1, k + rows, k + rows + 1], t);
281
+ }
282
+ return { position, normal, uv, index, box };
283
+ }
284
+ // The tels of the earthworks laid out that have a cliff side, each with the level of its top.
285
+ const cliffMounds = () => earthworks.mounds().filter(m => m.kind === 'tel' && m.cliff !== undefined);
286
+ // The faces of `tels` (cliffMounds) over a land's sheet: plain arithmetic, on a worker or on the page. Each has its rows, for
287
+ // what stands on it (adopt), and the arrays for its mesh (as `arrays`) and for its lighter copy's (as `lighter`).
288
+ function layFaces(tels, sheet) {
289
+ ground = sheet;
290
+ const laid = tels.map(m => {
291
+ const face = layFace(m);
292
+ face.arrays = faceArrays(face);
293
+ face.lighter = faceArrays(layFace(m, true));
294
+ return face;
295
+ });
296
+ ground = null;
297
+ return laid;
298
+ }
299
+ // Has the walker stand on the faces laid (layFaces) from now on.
300
+ function adopt(list) {
301
+ faces.length = 0;
302
+ faces.push(...list);
303
+ }
304
+ // Notes that the land's faces are being laid: `adopted` settles once they are adopted (adopt).
305
+ function layingFaces(adopted) {
306
+ laying = adopted;
307
+ }
308
+ // The faces laid on tel m, once the land's are (none on a tel without a cliff): a worker that builds on the tel stands on them
309
+ // too, or what it strews over the brow lies under the face the page draws.
310
+ function facesOf(m) {
311
+ return laying.then(() => faces.filter(f => f.m.x === m.x && f.m.z === m.z));
312
+ }
313
+ // The height of a tel's face at (x, z), or -Infinity where none is laid: the rows of the two columns either side, read at the
314
+ // place's distance from the tel's middle.
315
+ function heightAt(x, z) {
316
+ for (let f = 0; f < faces.length; f++) {
317
+ const face = faces[f],
318
+ dx = x - face.m.x,
319
+ dz = z - face.m.z,
320
+ dd = dx * dx + dz * dz;
321
+ if (dd < face.near * face.near || dd > face.far * face.far) continue;
322
+ let a = Math.atan2(dz, dx) - face.a0;
323
+ a -= TAU * Math.floor(a / TAU);
324
+ const u = a / face.step,
325
+ i = Math.floor(u);
326
+ if (i < 0 || i + 1 >= face.n) continue;
327
+ const d = Math.sqrt(dd),
328
+ y0 = alongColumn(face.columns[i], d),
329
+ y1 = alongColumn(face.columns[i + 1], d);
330
+ if (y0 === -Infinity || y1 === -Infinity) continue;
331
+ return lerp(y0, y1, u - i);
332
+ }
333
+ return -Infinity;
334
+ }
335
+ // A column's height at d metres from its tel's middle, or -Infinity off its ends.
336
+ function alongColumn({ d: ds, y }, d) {
337
+ if (d < ds[0] || d > ds[ds.length - 1]) return -Infinity;
338
+ let j = 0;
339
+ while (ds[j + 1] < d) j++;
340
+ return y[j] + ((y[j + 1] - y[j]) * (d - ds[j])) / (ds[j + 1] - ds[j]);
341
+ }
342
+ // Forgets the faces (a land is let go).
343
+ function forget() {
344
+ faces.length = 0;
345
+ laying = Promise.resolve();
346
+ }
347
+
348
+ return { cliffMounds, layFaces, adopt, layingFaces, facesOf, heightAt, faces, forget };
349
+ }