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
@@ -1,61 +1,187 @@
1
- // Seeded height and scree fields for elliptical uplands, branching ranges and groups of hills.
1
+ /**
2
+ * Add seeded hills, ridges and escarpments to a terrain height function.
3
+ * {@link createMountainRanges} samples relief and loose rock for the same location.
4
+ * @module
5
+ */
2
6
  import { clamp, lerp, sstep } from './scalar.js';
3
7
  import { createNoise } from './noise.js';
4
8
  import { createHash } from './random.js';
5
9
 
6
- const RANGE_FROM = [0.3, 0.75], // how broken an upland must be to begin to be a range, and to be one wholly
7
- FOOT = 1.15, // where a flank's rock slope meets its apron, in flank widths from the crest
8
- APRON = 0.13, // the share of a crest's height its apron stands for: the scree and wash banked against its foot
9
- REACH = 2.1, // flank widths from the crest at which nothing of a range is left
10
- TAIL_REACH = 1.9, // and the same past a crest's end, in the lengths its end falls away over
11
- NARROW = 0.4, // the share of its width a range keeps where its crest has fallen away
12
- CREST_ROUND = 7, // metres a crest is rounded over, so its line does not saw across the ground's cells
13
- PEAK_SPACING = 0.6, // peaks along a crest, in half-widths of the range ...
14
- PEAK_SPAN = [60, 200], // ... but no nearer and no farther apart than this, in metres
15
- PEAK_POINT = 1.4, // how pointed a peak is and how level a saddle (1: a straight line from one to the other)
16
- PEAK_DROP = 0.26, // the most a lesser peak stands under the highest, as a share of it,
17
- SADDLE_DROP = [0.05, 0.24], // and a saddle under the lower of its two peaks;
18
- PASS = [0.12, 0.2], // the share of the saddles that are passes, and how much lower a pass lies
19
- HELD = 0.6, // the share of its length beyond its width that an ellipse's crest holds its height over, where it is a range
20
- LOP = 0.3, // how much narrower than its half-width a range's steeper flank may be, and the other wider
21
- BOW = 0.3, // how far a flank's slope may be bowed out or hollowed
22
- WANDER = 0.28, // how far a crest strays from its straight line, in half-widths
23
- WARP = [0.5, 3.2], // how far a range's whole shape is pulled about, in half-widths, and over what length, in peak spacings
24
- SHOULDER = 0.85, // the share of a crest's saddles that send a short spur of their own down one side
25
- EMBAYED = 0.32, // how much nearer the crest a valley's floor meets the apron than a spur's toe does
26
- CUT = 0.6, // the share of a flank's height the valleys between its spurs are cut down by
27
- RIB_CUT = 0.42, // and the gullies in a spur's side
28
- KNOB = 0.3, // how far a spur's own crest is notched between its knobs, as a share of the valleys' depth
29
- RIB_SPAN = [36, 80], // metres from one such gully to the next: six cells of the ground at the least
30
- CRAG = 0.42, // how far broken rock roughens a flank
31
- NOTCH = 0.1, // and notches a crest between its peaks, as a share of its height
32
- BEDS = { thick: 21, hold: 0.34, dip: [0.05, 0.03], warp: 9 }, // the rock's hard beds: metres from one to the next, how far they step a
33
- // flank into cliffs and benches at the most, how they dip (metres to a metre east and south) and how far (metres) they are warped
34
- SPUR_LEAST = 0.1, // the share of its height a crest must keep for a spur to leave it
35
- SCARP = { face: 0.5, back: 1.3, rim: 0.55, cliff: [0.28, 0.48], level: 0.35, wander: 2.4 }, // an escarpment: its face's and its dip
36
- // slope's widths as shares of the half-width, how far its rim stands off the middle toward its face, how far down the face its
37
- // cliff reaches (in flank widths) and the share of the height it drops, how much of a range's peaks and saddles its rim keeps,
38
- // and how much farther than a range's crest it strays, in bays and headlands
39
- HILL = { base: 0.3, long: [0.2, 0.5], wide: [0.35, 0.6], high: [0.4, 1], turn: 1.1 }, // a field of hills: the swell they stand
40
- // on as a share of its height; each hill's half-length as a share of the field's lesser radius, its half-width as a share of its
41
- // length, its height as a share of the field's, and how far (radians) its crest may turn off the field's strike
42
- SWELL_REACH = 3.2, // how far out a swell's foot runs, as its radius squared,
43
- SWELL_WARP = 0.22, // and how far that radius is pulled about
44
- SEG = 9; // numbers to a spur: its ends (u, v), the metres along it at each, its flanks' width at each, its ribs' phase
10
+ /**
11
+ * The shape of every range, escarpment and field of hills: the defaults of {@link createMountainRanges}'s `shape` option,
12
+ * any of which a caller may replace. Shares and widths are as each line says; lengths are metres.
13
+ */
14
+ export const RANGE_SHAPE = Object.freeze({
15
+ // how broken an upland must be to begin to be a range, and to be one wholly
16
+ rangeFrom: [0.3, 0.75],
17
+ // where a flank's rock slope meets its apron, in flank widths from the crest
18
+ foot: 1.15,
19
+ // the share of a crest's height its apron stands for: the scree and wash banked against its foot
20
+ apron: 0.13,
21
+ // flank widths from the crest at which nothing of a range is left
22
+ reach: 2.1,
23
+ // and the same past a crest's end, in the lengths its end falls away over
24
+ tailReach: 1.9,
25
+ // the share of its width a range keeps where its crest has fallen away
26
+ narrow: 0.4,
27
+ // metres a crest is rounded over, so its line does not saw across the ground's cells
28
+ crestRound: 7,
29
+ // peaks along a crest, in half-widths of the range ...
30
+ peakSpacing: 0.6,
31
+ // ... but no nearer and no farther apart than this, in metres
32
+ peakSpan: [60, 200],
33
+ // how pointed a peak is and how level a saddle (1: a straight line from one to the other)
34
+ peakPoint: 1.4,
35
+ // the most a lesser peak stands under the highest, as a share of it,
36
+ peakDrop: 0.26,
37
+ // and a saddle under the lower of its two peaks;
38
+ saddleDrop: [0.05, 0.24],
39
+ // the share of the saddles that are passes, and how much lower a pass lies
40
+ pass: [0.12, 0.2],
41
+ // the share of its length beyond its width that an ellipse's crest holds its height over, where it is a range
42
+ held: 0.6,
43
+ // how much narrower than its half-width a range's steeper flank may be, and the other wider
44
+ lop: 0.3,
45
+ // how far a flank's slope may be bowed out or hollowed
46
+ bow: 0.3,
47
+ // how far a crest strays from its straight line, in half-widths
48
+ wander: 0.28,
49
+ // how far a range's whole shape is pulled about, in half-widths, and over what length, in peak spacings
50
+ warp: [0.5, 3.2],
51
+ // the share of a crest's saddles that send a short spur of their own down one side
52
+ shoulder: 0.85,
53
+ // how much nearer the crest a valley's floor meets the apron than a spur's toe does
54
+ embayed: 0.32,
55
+ // the share of a flank's height the valleys between its spurs are cut down by
56
+ cut: 0.6,
57
+ // and the gullies in a spur's side
58
+ ribCut: 0.42,
59
+ // how far a spur's own crest is notched between its knobs, as a share of the valleys' depth
60
+ knob: 0.3,
61
+ // metres from one such gully to the next: six cells of the ground at the least
62
+ ribSpan: [36, 80],
63
+ // how far broken rock roughens a flank
64
+ crag: 0.42,
65
+ // and notches a crest between its peaks, as a share of its height
66
+ notch: 0.1,
67
+ // the rock's hard beds: metres from one to the next, how far they step a flank into cliffs and benches at the most, how they dip
68
+ // (metres to a metre along +X and +Z) and how far (metres) they are warped
69
+ beds: { thick: 21, hold: 0.34, dip: [0.05, 0.03], warp: 9 },
70
+ // the share of its height a crest must keep for a spur to leave it
71
+ spurLeast: 0.1,
72
+ // an escarpment: its face's and its dip slope's widths as shares of the half-width, how far its rim stands off the middle
73
+ // toward its face, how far down the face its cliff reaches (in flank widths) and the share of the height it drops, how much of
74
+ // a range's peaks and saddles its rim keeps, and how much farther than a range's crest it strays, in bays and headlands
75
+ scarp: { face: 0.5, back: 1.3, rim: 0.55, cliff: [0.28, 0.48], level: 0.35, wander: 2.4 },
76
+ // a field of hills: the swell they stand on as a share of its height; each hill's half-length as a share of the field's lesser
77
+ // radius, its half-width as a share of its length, its height as a share of the field's, and how far (radians) its crest may
78
+ // turn off the field's strike
79
+ hill: { base: 0.3, long: [0.2, 0.5], wide: [0.35, 0.6], high: [0.4, 1], turn: 1.1 },
80
+ // how far out a swell's foot runs, as its radius squared,
81
+ swellReach: 3.2,
82
+ // and how far that radius is pulled about
83
+ swellWarp: 0.22,
84
+ });
85
+ const SEG = 9; // numbers to a spur: its ends (u, v), the metres along it at each, its flanks' width at each, its ribs' phase
86
+
87
+ /**
88
+ * @typedef {object} EllipticalUpland
89
+ * @property {number} x - Centre X in metres.
90
+ * @property {number} z - Centre Z in metres.
91
+ * @property {number} rx - X radius in metres, or half-length along the supplied axis.
92
+ * @property {number} rz - Z radius in metres, or half-width across the supplied axis.
93
+ * @property {number} h - Height scale in metres.
94
+ * @property {number} rough - Relief roughness from 0 for a smooth swell to 1 for a broken ridge.
95
+ * @property {number} [axis] - Long-axis bearing in radians from +X toward +Z.
96
+ * @property {number} [face] - Bearing toward the steep side of an escarpment, in radians.
97
+ * @property {number} [hills] - Number of hills to scatter inside the ellipse.
98
+ */
99
+
100
+ /**
101
+ * @typedef {object} Ridge
102
+ * @property {[number, number, number][]} crest - At least two distinct consecutive points, each [x, z, height multiplier].
103
+ * @property {number} wide - Flank half-width in metres.
104
+ * @property {number} h - Height in metres before applying each crest point’s multiplier.
105
+ * @property {number} rough - Relief roughness from 0 to 1.
106
+ * @property {number} [face] - Bearing toward the steep side of an escarpment, in radians from +X toward +Z.
107
+ */
45
108
 
46
109
  // The long axis of an upland given as an ellipse ({ x, z, rx, rz }), as [bearing, half-length, half-width]: the longer of its
47
110
  // radii, or along `axis` (a bearing: 0 east, clockwise seen from above), with rx then its half-length and rz its half-width.
48
- const ellipseAxis = m => (m.axis !== undefined ? [m.axis, m.rx, m.rz] : m.rx >= m.rz ? [0, m.rx, m.rz] : [Math.PI / 2, m.rz, m.rx]);
49
- // The line of an upland's crest as its data gives it ([[x, z], ...]) and its half-width, for the map's drawing of it.
50
- export function crestOf(m) {
51
- if (m.crest) return { line: m.crest, wide: m.wide };
52
- const [bearing, a, b] = ellipseAxis(m),
53
- reach = 0.8 * a;
54
- return { line: [-reach, reach].map(u => [m.x + u * Math.cos(bearing), m.z + u * Math.sin(bearing)]), wide: b };
111
+ const ellipseAxis = landform =>
112
+ landform.axis !== undefined
113
+ ? [landform.axis, landform.rx, landform.rz]
114
+ : landform.rx >= landform.rz
115
+ ? [0, landform.rx, landform.rz]
116
+ : [Math.PI / 2, landform.rz, landform.rx];
117
+ /**
118
+ * Get the crest line and flank half-width for drawing a map. An explicit ridge
119
+ * keeps its original point array, including the third height component. An
120
+ * ellipse yields two X/Z endpoints along its long axis.
121
+ * @param {EllipticalUpland | Ridge} landform - Landform supplied to the range layout.
122
+ */
123
+ export function crestOf(landform) {
124
+ if (landform.crest) return { line: landform.crest, wide: landform.wide };
125
+ const [bearing, halfLength, halfWidth] = ellipseAxis(landform),
126
+ reach = 0.8 * halfLength;
127
+ return { line: [-reach, reach].map(u => [landform.x + u * Math.cos(bearing), landform.z + u * Math.sin(bearing)]), wide: halfWidth };
55
128
  }
56
129
 
57
- // Each field owns its layout and sampling scratch so separate terrains can be sampled independently.
58
- export function createMountainRanges(seed = 0) {
130
+ /**
131
+ * Build a reusable field of mountain relief. Call `layout` with ellipses or ridgelines,
132
+ * then add `heightAt(x, z)` to the base terrain elevation in metres. Each call also
133
+ * overwrites `surface.scree`, the loose-rock amount for that sample.
134
+ * Calling `layout` again replaces the previous landforms. Keep their order stable
135
+ * when reproducing a landscape because each landform’s seed depends on its index.
136
+ * @param {number} [seed] - World seed for the ridges, spurs and surface detail.
137
+ * @param {object} [options]
138
+ * @param {Partial<typeof RANGE_SHAPE>} [options.shape] - Replaces any of {@link RANGE_SHAPE}'s figures (a nested one whole).
139
+ * @example
140
+ * ```js
141
+ * import { createMountainRanges } from 'roamwright/math/mountain-ranges.js';
142
+ *
143
+ * const mountains = createMountainRanges(42);
144
+ * mountains.layout([{ crest: [[0, 0, 0.6], [120, 40, 1]], wide: 50, h: 90, rough: 0.8 }]);
145
+ * const elevation = 12 + mountains.heightAt(80, 25);
146
+ * const looseRock = mountains.surface.scree;
147
+ * ```
148
+ */
149
+ export function createMountainRanges(seed = 0, { shape = {} } = {}) {
150
+ // This instance's shape, under the names the arithmetic below reads.
151
+ const {
152
+ rangeFrom: RANGE_FROM,
153
+ foot: FOOT,
154
+ apron: APRON,
155
+ reach: REACH,
156
+ tailReach: TAIL_REACH,
157
+ narrow: NARROW,
158
+ crestRound: CREST_ROUND,
159
+ peakSpacing: PEAK_SPACING,
160
+ peakSpan: PEAK_SPAN,
161
+ peakPoint: PEAK_POINT,
162
+ peakDrop: PEAK_DROP,
163
+ saddleDrop: SADDLE_DROP,
164
+ pass: PASS,
165
+ held: HELD,
166
+ lop: LOP,
167
+ bow: BOW,
168
+ wander: WANDER,
169
+ warp: WARP,
170
+ shoulder: SHOULDER,
171
+ embayed: EMBAYED,
172
+ cut: CUT,
173
+ ribCut: RIB_CUT,
174
+ knob: KNOB,
175
+ ribSpan: RIB_SPAN,
176
+ crag: CRAG,
177
+ notch: NOTCH,
178
+ beds: BEDS,
179
+ spurLeast: SPUR_LEAST,
180
+ scarp: SCARP,
181
+ hill: HILL,
182
+ swellReach: SWELL_REACH,
183
+ swellWarp: SWELL_WARP,
184
+ } = { ...RANGE_SHAPE, ...shape };
59
185
  const { fbm, ridged, vnoise } = createNoise(seed);
60
186
  const hash2 = createHash(seed);
61
187
  // What rangesAt found out about the place it worked out last, for the colours: how far it is scree and wash, the apron at a
@@ -67,8 +193,8 @@ export function createMountainRanges(seed = 0) {
67
193
 
68
194
  // The swell of an ellipse ({ x, z, rx, rz, h, rough }) at (x, z), in metres: a rise that falls away smoothly all round, broken
69
195
  // by noise the more it is rough.
70
- function swellAt(m, x, z) {
71
- const r0 = ((x - m.x) / m.rx) ** 2 + ((z - m.z) / m.rz) ** 2;
196
+ function swellAt(landform, x, z) {
197
+ const r0 = ((x - landform.x) / landform.rx) ** 2 + ((z - landform.z) / landform.rz) ** 2;
72
198
  if (r0 >= SWELL_REACH + SWELL_WARP / 2) return 0;
73
199
  if (crag < 0) {
74
200
  // the noise is worked out only where a swell is near
@@ -76,72 +202,81 @@ export function createMountainRanges(seed = 0) {
76
202
  pull = SWELL_WARP * (fbm(x * 0.0021, z * 0.0021, 2, 337) - 0.5);
77
203
  }
78
204
  const r = r0 + pull;
79
- return r < SWELL_REACH ? m.h * Math.exp(-1.5 * Math.max(r, 0)) * lerp(1, 0.35 + 1.25 * crag, m.rough) : 0;
205
+ return r < SWELL_REACH ? landform.h * Math.exp(-1.5 * Math.max(r, 0)) * lerp(1, 0.35 + 1.25 * crag, landform.rough) : 0;
80
206
  }
81
207
 
82
208
  // The height of a limb's crest at u, as a share of its own: 1 along its length, falling away past each end.
83
- function crestShare(L, u) {
84
- const over = u < 0 ? -u / L.tail0 : u > L.len ? (u - L.len) / L.tail1 : 0;
85
- return (over > 0 ? Math.exp(-1.5 * over ** L.fall) : 1) * lerp(L.k0, L.k1, clamp(u / (L.len || 1), 0, 1));
209
+ function crestShare(limbData, u) {
210
+ const over = u < 0 ? -u / limbData.tail0 : u > limbData.len ? (u - limbData.len) / limbData.tail1 : 0;
211
+ return (over > 0 ? Math.exp(-1.5 * over ** limbData.fall) : 1) * lerp(limbData.k0, limbData.k1, clamp(u / (limbData.len || 1), 0, 1));
86
212
  }
87
213
  // How far a limb's crest stands off its straight line at u: it wanders, and an escarpment's rim stands toward its face.
88
- function crestOffset(L, u) {
89
- const stray = 2 * (vnoise(u / L.wave + 7.3, 0, L.seed) - L.strayAt);
90
- return L.rim + L.wander * stray * (L.line ? sstep(0, L.step, u) * sstep(L.len, L.len - L.step, u) : 1); // the stretches of a line meet end to end
214
+ function crestOffset(limbData, u) {
215
+ const stray = 2 * (vnoise(u / limbData.wave + 7.3, 0, limbData.seed) - limbData.strayAt);
216
+ return (
217
+ limbData.rim +
218
+ limbData.wander * stray * (limbData.line ? sstep(0, limbData.step, u) * sstep(limbData.len, limbData.len - limbData.step, u) : 1)
219
+ ); // the stretches of a line meet end to end
91
220
  }
92
221
  // How far a range leans to one side at u, -1..1: no range's two flanks are alike, and which is the steeper changes along it.
93
- const leanAt = (L, u, seed) => 2 * vnoise(u / (4 * L.step) + 3.1, 0, L.seed + seed) - 1;
94
- // The width of a limb's flank on `side` of its crest at u, where the crest stands at share E of its height: a range narrows as
222
+ const leanAt = (limbData, u, seed) => 2 * vnoise(u / (4 * limbData.step) + 3.1, 0, limbData.seed + seed) - 1;
223
+ // The width of a limb's flank on `side` of its crest at u, where the crest stands at fraction crestFraction of its height: a range narrows as
95
224
  // its crest falls, so its flanks keep their slope, and the flank it leans toward is the narrower and steeper.
96
- const flankWidth = (L, E, side, u) =>
97
- L.b * (NARROW + (1 - NARROW) * E) * (L.face ? (L.face === side ? SCARP.face : SCARP.back) : 1 - side * LOP * L.rough * leanAt(L, u, 9));
225
+ const flankWidth = (limbData, crestFraction, side, u) =>
226
+ limbData.b *
227
+ (NARROW + (1 - NARROW) * crestFraction) *
228
+ (limbData.face ? (limbData.face === side ? SCARP.face : SCARP.back) : 1 - side * LOP * limbData.rough * leanAt(limbData, u, 9));
98
229
  // How far a range's shape is pulled off its place at (x, z), along x (`turn` 0) or z (1), as a share of the most: at two scales.
99
- const warpAt = (L, x, z, turn) => 2 * fbm(x * L.warpOver + 31.7 * turn, z * L.warpOver + 11.3 * turn, 2, L.seed + 3 + turn) - 1;
230
+ const warpAt = (limbData, x, z, turn) =>
231
+ 2 * fbm(x * limbData.warpOver + 31.7 * turn, z * limbData.warpOver + 11.3 * turn, 2, limbData.seed + 3 + turn) - 1;
100
232
  // How far a crest is notched at u, as a share of the most.
101
- const notchAt = (L, u) => 2 * fbm(u / (0.7 * L.step), 0, 3, L.seed + 6) - 1;
233
+ const notchAt = (limbData, u) => 2 * fbm(u / (0.7 * limbData.step), 0, 3, limbData.seed + 6) - 1;
102
234
 
103
235
  // The peaks and saddles of a limb's crest, as [u, share of the height] in turn from a peak to a peak: a peak stands where the
104
236
  // data puts the upland (the middle of an ellipse, the points of a line), the rest a spacing apart.
105
- function crestKnots(L, spacing) {
106
- const first = L.line ? 0 : L.len / 2,
107
- step = L.line ? L.len / Math.max(1, Math.round(L.len / spacing)) : spacing,
108
- last = L.line ? Math.round(L.len / step) : 0, // the peak at a line's far point
109
- from = -Math.ceil((first + 1.3 * L.tail0) / step),
110
- to = Math.ceil((L.len + 1.3 * L.tail1 - first) / step),
111
- level = L.rough * (L.face ? SCARP.level : 1),
237
+ function crestKnots(limbData, spacing) {
238
+ const first = limbData.line ? 0 : limbData.len / 2,
239
+ step = limbData.line ? limbData.len / Math.max(1, Math.round(limbData.len / spacing)) : spacing,
240
+ last = limbData.line ? Math.round(limbData.len / step) : 0, // the peak at a line's far point
241
+ from = -Math.ceil((first + 1.3 * limbData.tail0) / step),
242
+ to = Math.ceil((limbData.len + 1.3 * limbData.tail1 - first) / step),
243
+ level = limbData.rough * (limbData.face ? SCARP.level : 1),
112
244
  knots = [];
113
245
  let before = 0;
114
246
  for (let k = from; k <= to; k++) {
115
- const given = k === 0 || (L.line && k === last),
116
- u = first + (k + (given ? 0 : 0.6 * (hash2(k, 1, L.seed) - 0.5))) * step,
117
- peak = given ? 1 : 1 - level * PEAK_DROP * Math.sqrt(hash2(k, 2, L.seed)); // a few stand near the highest, most well under it
247
+ const given = k === 0 || (limbData.line && k === last),
248
+ u = first + (k + (given ? 0 : 0.6 * (hash2(k, 1, limbData.seed) - 0.5))) * step,
249
+ peak = given ? 1 : 1 - level * PEAK_DROP * Math.sqrt(hash2(k, 2, limbData.seed)); // a few stand near the highest, most well under it
118
250
  if (k > from) {
119
- const drop = lerp(SADDLE_DROP[0], SADDLE_DROP[1], hash2(k, 4, L.seed)) + (hash2(k, 5, L.seed) < PASS[0] ? PASS[1] : 0);
120
- knots.push(lerp(knots[knots.length - 2], u, 0.35 + 0.3 * hash2(k, 3, L.seed)), Math.min(before, peak) - level * drop);
251
+ const drop =
252
+ lerp(SADDLE_DROP[0], SADDLE_DROP[1], hash2(k, 4, limbData.seed)) + (hash2(k, 5, limbData.seed) < PASS[0] ? PASS[1] : 0);
253
+ knots.push(lerp(knots[knots.length - 2], u, 0.35 + 0.3 * hash2(k, 3, limbData.seed)), Math.min(before, peak) - level * drop);
121
254
  }
122
255
  knots.push(u, peak);
123
256
  before = peak;
124
257
  }
125
- L.step = step;
258
+ limbData.step = step;
126
259
  return Float64Array.from(knots);
127
260
  }
128
261
  // How high a limb's crest stands at u between its peaks and saddles, as a share: pointed at a peak, level across a saddle.
129
- function knotShare(L, u) {
130
- const K = L.knots,
131
- n = K.length / 2;
132
- if (u <= K[0]) return K[1];
133
- if (u >= K[2 * n - 2]) return K[2 * n - 1];
134
- let i = clamp(Math.floor(((u - K[0]) / L.step) * 2), 0, n - 2);
135
- while (K[2 * i] > u) i--;
136
- while (K[2 * i + 2] < u) i++;
137
- const t = (u - K[2 * i]) / (K[2 * i + 2] - K[2 * i]),
138
- a = K[2 * i + 1],
139
- b = K[2 * i + 3];
140
- return a >= b ? b + (a - b) * (1 - t) ** PEAK_POINT : a + (b - a) * t ** PEAK_POINT;
262
+ function knotShare(limbData, u) {
263
+ const knots = limbData.knots,
264
+ n = knots.length / 2;
265
+ if (u <= knots[0]) return knots[1];
266
+ if (u >= knots[2 * n - 2]) return knots[2 * n - 1];
267
+ let i = clamp(Math.floor(((u - knots[0]) / limbData.step) * 2), 0, n - 2);
268
+ while (knots[2 * i] > u) i--;
269
+ while (knots[2 * i + 2] < u) i++;
270
+ const t = (u - knots[2 * i]) / (knots[2 * i + 2] - knots[2 * i]),
271
+ startHeight = knots[2 * i + 1],
272
+ endHeight = knots[2 * i + 3];
273
+ return startHeight >= endHeight
274
+ ? endHeight + (startHeight - endHeight) * (1 - t) ** PEAK_POINT
275
+ : startHeight + (endHeight - startHeight) * t ** PEAK_POINT;
141
276
  }
142
277
  // The spurs that run down one side of a limb: one from each peak, with a branch or two that leave it lower down, and a short
143
278
  // one from the shoulder of most saddles. A spur is a straight line: the range's warp bends it.
144
- function limbSpurs(L, side) {
279
+ function limbSpurs(limbData, side) {
145
280
  const out = [],
146
281
  spur = (u0, v0, angle, long, tau, wide0, wide1, seed) =>
147
282
  out.push(
@@ -153,26 +288,26 @@ export function createMountainRanges(seed = 0) {
153
288
  tau + long,
154
289
  wide0,
155
290
  wide1,
156
- hash2(seed, 9, L.seed),
291
+ hash2(seed, 9, limbData.seed),
157
292
  );
158
- for (let k = 0; k < L.knots.length; k += 2) {
159
- const u = L.knots[k],
160
- E = crestShare(L, u),
293
+ for (let k = 0; k < limbData.knots.length; k += 2) {
294
+ const u = limbData.knots[k],
295
+ crestFraction = crestShare(limbData, u),
161
296
  id = k + (side > 0 ? 1 : 0),
162
- r = n => hash2(id, n, L.seed + 1),
297
+ r = n => hash2(id, n, limbData.seed + 1),
163
298
  peak = k % 4 === 0;
164
- if (E < SPUR_LEAST || (!peak && r(0) > SHOULDER)) continue;
165
- const buttress = L.face === side, // an escarpment's face is buttressed, not spurred
166
- long = flankWidth(L, E, side, u) * FOOT * (buttress ? 0.75 : peak ? 0.45 + 0.7 * r(1) : 0.3 + 0.35 * r(1)),
167
- splay = u < 0 ? -sstep(0, 1, -u / L.tail0) : u > L.len ? sstep(0, 1, (u - L.len) / L.tail1) : 0, // round a crest's end they fan out
299
+ if (crestFraction < SPUR_LEAST || (!peak && r(0) > SHOULDER)) continue;
300
+ const buttress = limbData.face === side, // an escarpment's face is buttressed, not spurred
301
+ long = flankWidth(limbData, crestFraction, side, u) * FOOT * (buttress ? 0.75 : peak ? 0.45 + 0.7 * r(1) : 0.3 + 0.35 * r(1)),
302
+ splay = u < 0 ? -sstep(0, 1, -u / limbData.tail0) : u > limbData.len ? sstep(0, 1, (u - limbData.len) / limbData.tail1) : 0, // round a crest's end they fan out
168
303
  lean = (r(2) - 0.5) * 1.1 + 0.9 * splay,
169
- v = crestOffset(L, u),
170
- girth = L.step * (0.8 + 0.4 * r(7));
304
+ v = crestOffset(limbData, u),
305
+ girth = limbData.step * (0.8 + 0.4 * r(7));
171
306
  spur(u, v, lean, long, 0, 0.42 * girth, 0.64 * girth, id);
172
307
  if (buttress || !peak) continue;
173
- for (let b = 0; b < 2; b++) {
174
- const at = (b ? 0.6 : 0.38) + 0.14 * r(3 + b),
175
- turn = lean + (b ? -1 : 1) * (r(5) < 0.5 ? -1 : 1) * (0.6 + 0.4 * r(6 + b));
308
+ for (let branchIndex = 0; branchIndex < 2; branchIndex++) {
309
+ const at = (branchIndex ? 0.6 : 0.38) + 0.14 * r(3 + branchIndex),
310
+ turn = lean + (branchIndex ? -1 : 1) * (r(5) < 0.5 ? -1 : 1) * (0.6 + 0.4 * r(6 + branchIndex));
176
311
  spur(
177
312
  u + at * long * Math.sin(lean),
178
313
  v + side * at * long * Math.cos(lean),
@@ -181,32 +316,33 @@ export function createMountainRanges(seed = 0) {
181
316
  at * long,
182
317
  0.3 * girth,
183
318
  0.42 * girth,
184
- id + 1000 * (b + 1),
319
+ id + 1000 * (branchIndex + 1),
185
320
  );
186
321
  }
187
322
  }
188
323
  // where a crest ends, a long spur runs out and away on either side of its fall, so that the end of a range is no cone
189
324
  for (const [u, away, free] of [
190
- [0, -1, L.free0],
191
- [L.len, 1, L.free1],
325
+ [0, -1, limbData.free0],
326
+ [limbData.len, 1, limbData.free1],
192
327
  ]) {
193
328
  if (!free) continue;
194
329
  const id = 5000 + (away > 0 ? 2 : 0) + (side > 0 ? 1 : 0),
195
- long = flankWidth(L, crestShare(L, u), side, u) * FOOT * (0.7 + 0.6 * hash2(id, 1, L.seed + 1)),
196
- girth = L.step * (1 + 0.4 * hash2(id, 2, L.seed + 1));
197
- spur(u, crestOffset(L, u), away * (0.6 + 0.7 * hash2(id, 3, L.seed + 1)), long, 0, 0.42 * girth, 0.64 * girth, id);
330
+ long = flankWidth(limbData, crestShare(limbData, u), side, u) * FOOT * (0.7 + 0.6 * hash2(id, 1, limbData.seed + 1)),
331
+ girth = limbData.step * (1 + 0.4 * hash2(id, 2, limbData.seed + 1));
332
+ spur(u, crestOffset(limbData, u), away * (0.6 + 0.7 * hash2(id, 3, limbData.seed + 1)), long, 0, 0.42 * girth, 0.64 * girth, id);
198
333
  }
199
- return binned(L, out);
334
+ return binned(limbData, out);
200
335
  }
201
336
  // The spurs of `list` sorted into bins along a limb's crest, a peak spacing long each: every bin holds the spurs that reach into
202
337
  // its stretch, so a place asks only the few that could lie near it.
203
- function binned(L, list) {
204
- const bins = Array.from({ length: Math.ceil((L.to - L.from) / L.step) }, () => []);
338
+ function binned(limbData, list) {
339
+ const bins = Array.from({ length: Math.ceil((limbData.to - limbData.from) / limbData.step) }, () => []);
205
340
  for (let i = 0; i < list.length; i += SEG) {
206
341
  const reach = Math.max(list[i + 6], list[i + 7]),
207
- first = Math.floor((Math.min(list[i], list[i + 2]) - reach - L.from) / L.step),
208
- last = Math.floor((Math.max(list[i], list[i + 2]) + reach - L.from) / L.step);
209
- for (let b = Math.max(first, 0); b <= Math.min(last, bins.length - 1); b++) bins[b].push(...list.slice(i, i + SEG));
342
+ first = Math.floor((Math.min(list[i], list[i + 2]) - reach - limbData.from) / limbData.step),
343
+ last = Math.floor((Math.max(list[i], list[i + 2]) + reach - limbData.from) / limbData.step);
344
+ for (let binIndex = Math.max(first, 0); binIndex <= Math.min(last, bins.length - 1); binIndex++)
345
+ bins[binIndex].push(...list.slice(i, i + SEG));
210
346
  }
211
347
  return bins.map(bin => Float64Array.from(bin));
212
348
  }
@@ -217,7 +353,7 @@ export function createMountainRanges(seed = 0) {
217
353
  // swell it is where it is not broken enough to be one (none: a swell about its own crest).
218
354
  function limb(spec, seed) {
219
355
  const sharp = sstep(RANGE_FROM[0], RANGE_FROM[1], spec.rough),
220
- L = {
356
+ limbData = {
221
357
  ...spec,
222
358
  seed,
223
359
  sharp,
@@ -226,23 +362,27 @@ export function createMountainRanges(seed = 0) {
226
362
  wander: WANDER * spec.b * spec.rough * (spec.face ? SCARP.wander : 1),
227
363
  strayAt: 0.5,
228
364
  };
229
- L.knots = crestKnots(L, clamp(PEAK_SPACING * L.b, PEAK_SPAN[0], PEAK_SPAN[1]));
230
- L.wave = 3 * L.step;
231
- L.warp = WARP[0] * L.b * L.rough * sharp;
232
- L.warpOver = 1 / (WARP[1] * L.step);
233
- L.rib = clamp(0.3 * L.step, RIB_SPAN[0], RIB_SPAN[1]);
365
+ limbData.knots = crestKnots(limbData, clamp(PEAK_SPACING * limbData.b, PEAK_SPAN[0], PEAK_SPAN[1]));
366
+ limbData.wave = 3 * limbData.step;
367
+ limbData.warp = WARP[0] * limbData.b * limbData.rough * sharp;
368
+ limbData.warpOver = 1 / (WARP[1] * limbData.step);
369
+ limbData.rib = clamp(0.3 * limbData.step, RIB_SPAN[0], RIB_SPAN[1]);
234
370
  // the stretch of its frame outside which the range raises nothing, however it is pulled about (by twice its warp at the most)
235
- L.from = -TAIL_REACH * L.tail0 - 2 * L.warp;
236
- L.to = L.len + TAIL_REACH * L.tail1 + 2 * L.warp;
237
- L.far = REACH * L.b * Math.max(1 + LOP, SCARP.back) + Math.abs(L.rim) + 2 * L.wander + 2 * L.warp;
371
+ limbData.from = -TAIL_REACH * limbData.tail0 - 2 * limbData.warp;
372
+ limbData.to = limbData.len + TAIL_REACH * limbData.tail1 + 2 * limbData.warp;
373
+ limbData.far = REACH * limbData.b * Math.max(1 + LOP, SCARP.back) + Math.abs(limbData.rim) + 2 * limbData.wander + 2 * limbData.warp;
238
374
  // a summit stands where the data puts it, the middle of an ellipse or the points of a line: there the crest has not strayed
239
375
  // (crestOffset), nor been pulled about or notched, which `pin` holds for each end of the limb [warp along x, along z, notch]
240
- const mid = L.len / 2,
241
- pinAt = u => [warpAt(L, L.x + u * L.ax, L.z + u * L.az, 0), warpAt(L, L.x + u * L.ax, L.z + u * L.az, 1), notchAt(L, u)];
242
- L.pin = L.line ? [pinAt(0), pinAt(L.len)] : [pinAt(mid), pinAt(mid)];
243
- if (!L.line) L.strayAt = vnoise(mid / L.wave + 7.3, 0, seed);
244
- L.spurs = { 1: limbSpurs(L, 1), [-1]: limbSpurs(L, -1) };
245
- return L;
376
+ const mid = limbData.len / 2,
377
+ pinAt = u => [
378
+ warpAt(limbData, limbData.x + u * limbData.ax, limbData.z + u * limbData.az, 0),
379
+ warpAt(limbData, limbData.x + u * limbData.ax, limbData.z + u * limbData.az, 1),
380
+ notchAt(limbData, u),
381
+ ];
382
+ limbData.pin = limbData.line ? [pinAt(0), pinAt(limbData.len)] : [pinAt(mid), pinAt(mid)];
383
+ if (!limbData.line) limbData.strayAt = vnoise(mid / limbData.wave + 7.3, 0, seed);
384
+ limbData.spurs = { 1: limbSpurs(limbData, 1), [-1]: limbSpurs(limbData, -1) };
385
+ return limbData;
246
386
  }
247
387
 
248
388
  const spurAt = { best: 0, next: 0, tau: 0, phase: 0, side: 0 }; // what spurNear found: the nearest spur's share and the next one's, how far along the nearest, its phase and which side of it
@@ -292,71 +432,82 @@ export function createMountainRanges(seed = 0) {
292
432
  }
293
433
  // Metres a limb's range raises the ground at (x, z), and the swell about its crest where it has no ellipse's (`smooth`: how
294
434
  // far it is that swell).
295
- function rangeHeight(L, x, z, smooth) {
296
- const px = x - L.x,
297
- pz = z - L.z,
298
- along = px * L.ax + pz * L.az;
299
- if (along < L.from || along > L.to || Math.abs(pz * L.ax - px * L.az) > L.far) return 0; // before any noise is worked out
300
- // a range's shape is pulled about, so that no crest, spur or foot is a ruled line; not at its summits (L.pin)
301
- const [from, to] = L.pin,
302
- held = clamp(along / (L.len || 1), 0, 1),
303
- dx = px + L.warp * (warpAt(L, x, z, 0) - lerp(from[0], to[0], held)),
304
- dz = pz + L.warp * (warpAt(L, x, z, 1) - lerp(from[1], to[1], held)),
305
- u = dx * L.ax + dz * L.az;
306
- if (u < -TAIL_REACH * L.tail0 || u > L.len + TAIL_REACH * L.tail1) return 0;
307
- const off = dz * L.ax - dx * L.az - crestOffset(L, u),
435
+ function rangeHeight(limbData, x, z, smooth) {
436
+ const px = x - limbData.x,
437
+ pz = z - limbData.z,
438
+ along = px * limbData.ax + pz * limbData.az;
439
+ if (along < limbData.from || along > limbData.to || Math.abs(pz * limbData.ax - px * limbData.az) > limbData.far) return 0; // before any noise is worked out
440
+ // a range's shape is pulled about, so that no crest, spur or foot is a ruled line; not at its summits (limbData.pin)
441
+ const [from, to] = limbData.pin,
442
+ held = clamp(along / (limbData.len || 1), 0, 1),
443
+ dx = px + limbData.warp * (warpAt(limbData, x, z, 0) - lerp(from[0], to[0], held)),
444
+ dz = pz + limbData.warp * (warpAt(limbData, x, z, 1) - lerp(from[1], to[1], held)),
445
+ u = dx * limbData.ax + dz * limbData.az;
446
+ if (u < -TAIL_REACH * limbData.tail0 || u > limbData.len + TAIL_REACH * limbData.tail1) return 0;
447
+ const off = dz * limbData.ax - dx * limbData.az - crestOffset(limbData, u),
308
448
  side = off < 0 ? -1 : 1,
309
- D = side * off,
310
- E = crestShare(L, u),
311
- crest = L.h * E * knotShare(L, u) * (1 + L.sharp * L.rough * NOTCH * (notchAt(L, u) - lerp(from[2], to[2], held))),
312
- swell = smooth > 0 ? crest * Math.exp(-1.5 * (D / L.b) ** 2) : 0,
313
- wide = flankWidth(L, E, side, u),
314
- s = D / wide;
449
+ flankDistance = side * off,
450
+ crestFraction = crestShare(limbData, u),
451
+ crest =
452
+ limbData.h *
453
+ crestFraction *
454
+ knotShare(limbData, u) *
455
+ (1 + limbData.sharp * limbData.rough * NOTCH * (notchAt(limbData, u) - lerp(from[2], to[2], held))),
456
+ swell = smooth > 0 ? crest * Math.exp(-1.5 * (flankDistance / limbData.b) ** 2) : 0,
457
+ wide = flankWidth(limbData, crestFraction, side, u),
458
+ s = flankDistance / wide;
315
459
  if (smooth >= 1 || s >= REACH) return swell * smooth;
316
- spurNear(L.spurs[side][clamp(Math.floor((u - L.from) / L.step), 0, L.spurs[side].length - 1)], u, off);
317
- const R = spurAt.best,
318
- scarp = L.face ? (L.face === side ? 1 : -1) : 0,
319
- own = sstep(0, 0.25, R - spurAt.next), // how far the place is one spur's alone: what is its own (its knobs, its gullies) fades out toward the next spur
320
- knobs = 1 - KNOB * own * vnoise(spurAt.tau / L.step + 40 * spurAt.phase, 0, L.seed + 8),
321
- floor = 1 - ((R * R) / (R + 0.15)) * 1.15 * knobs, // how far the place is a valley's floor: a spur's crest is a sharp line, the floor rounded
460
+ spurNear(limbData.spurs[side][clamp(Math.floor((u - limbData.from) / limbData.step), 0, limbData.spurs[side].length - 1)], u, off);
461
+ const spurStrength = spurAt.best,
462
+ scarp = limbData.face ? (limbData.face === side ? 1 : -1) : 0,
463
+ own = sstep(0, 0.25, spurStrength - spurAt.next), // how far the place is one spur's alone: what is its own (its knobs, its gullies) fades out toward the next spur
464
+ knobs = 1 - KNOB * own * vnoise(spurAt.tau / limbData.step + 40 * spurAt.phase, 0, limbData.seed + 8),
465
+ floor = 1 - ((spurStrength * spurStrength) / (spurStrength + 0.15)) * 1.15 * knobs, // how far the place is a valley's floor: a spur's crest is a sharp line, the floor rounded
322
466
  round = CREST_ROUND / wide,
323
- bow = 1 + side * BOW * L.rough * leanAt(L, u, 10),
467
+ bow = 1 + side * BOW * limbData.rough * leanAt(limbData, u, 10),
324
468
  body = flankBody((Math.sqrt(s * s + round * round) - round) / (1 - EMBAYED * floor * sstep(0.1, 0.5, s)), scarp, bow),
325
- deep = L.rough * CUT * sstep(0.02, 0.3, s) * (scarp < 0 ? 0.5 : 1),
326
- sides = L.rough * RIB_CUT * own * (1 - R) * sstep(0.1, 0.35, s),
327
- gully = spurAt.tau / L.rib + spurAt.phase + spurAt.side,
469
+ deep = limbData.rough * CUT * sstep(0.02, 0.3, s) * (scarp < 0 ? 0.5 : 1),
470
+ sides = limbData.rough * RIB_CUT * own * (1 - spurStrength) * sstep(0.1, 0.35, s),
471
+ gully = spurAt.tau / limbData.rib + spurAt.phase + spurAt.side,
328
472
  cut = (1 - deep * floor) * (1 - sides * Math.abs(2 * (gully - Math.floor(gully)) - 1)), // what the valleys and gullies leave of the flank
329
- broken = body > 0 ? 1 + L.rough * CRAG * sstep(0, 0.12, s) * (ridged(x * 0.009, z * 0.009, 4, 331) - 0.45) : 1,
330
- stone = bedded(crest * (1 - APRON) * body * cut * broken, x, z, BEDS.hold * L.rough),
473
+ broken = body > 0 ? 1 + limbData.rough * CRAG * sstep(0, 0.12, s) * (ridged(x * 0.009, z * 0.009, 4, 331) - 0.45) : 1,
474
+ stone = bedded(crest * (1 - APRON) * body * cut * broken, x, z, BEDS.hold * limbData.rough),
331
475
  // the apron is banked highest where a valley comes out onto it, in a fan
332
- apron = crest * APRON * Math.exp(-1.2 * s * s) * (1 + 0.5 * L.rough * (floor - 0.5) * sstep(0.6, 1, s)),
476
+ apron = crest * APRON * Math.exp(-1.2 * s * s) * (1 + 0.5 * limbData.rough * (floor - 0.5) * sstep(0.6, 1, s)),
333
477
  lies = sstep(2, 1.3, s) * Math.max(sstep(0.75, 1.05, s), 0.7 * floor * floor * sstep(0.3, 0.8, s)),
334
- loose = L.sharp * sstep(8, 30, L.h * E) * lies;
478
+ loose = limbData.sharp * sstep(8, 30, limbData.h * crestFraction) * lies;
335
479
  if (loose > range.scree) range.scree = loose;
336
480
  return lerp(stone + apron, swell, smooth);
337
481
  }
338
482
  // Metres a limb raises the ground at (x, z): its range, and where it is not broken enough to be one wholly, its swell.
339
- function limbHeight(L, x, z) {
340
- if (!L.swell) return rangeHeight(L, x, z, 1 - L.sharp);
341
- return (L.sharp < 1 ? (1 - L.sharp) * swellAt(L.swell, x, z) : 0) + (L.sharp > 0 ? L.sharp * rangeHeight(L, x, z, 0) : 0);
483
+ function limbHeight(limbData, x, z) {
484
+ if (!limbData.swell) return rangeHeight(limbData, x, z, 1 - limbData.sharp);
485
+ return (
486
+ (limbData.sharp < 1 ? (1 - limbData.sharp) * swellAt(limbData.swell, x, z) : 0) +
487
+ (limbData.sharp > 0 ? limbData.sharp * rangeHeight(limbData, x, z, 0) : 0)
488
+ );
342
489
  }
343
490
  // The higher of two limbs of one upland, rounded where they meet.
344
- function joined(a, b) {
345
- const most = Math.max(a, b),
491
+ function joined(firstHeight, secondHeight) {
492
+ const most = Math.max(firstHeight, secondHeight),
346
493
  k = 0.25 * most,
347
- near = k > 0 ? Math.max(k - Math.abs(a - b), 0) / k : 0;
494
+ near = k > 0 ? Math.max(k - Math.abs(firstHeight - secondHeight), 0) / k : 0;
348
495
  return most + (near * near * k) / 4;
349
496
  }
350
- // Metres the uplands laid out raise the ground at (x, z); `range` then says what else was found there.
497
+ /**
498
+ * @param {number} x - World X in metres.
499
+ * @param {number} z - World Z in metres.
500
+ * @returns {number} Added elevation in metres. An empty layout contributes zero.
501
+ */
351
502
  function rangesAt(x, z) {
352
503
  let h = 0;
353
504
  range.scree = 0;
354
505
  crag = -1;
355
506
  for (let i = 0; i < uplands.length; i++) {
356
- const U = uplands[i];
357
- if (x < U.x0 || x > U.x1 || z < U.z0 || z > U.z1) continue;
507
+ const upland = uplands[i];
508
+ if (x < upland.x0 || x > upland.x1 || z < upland.z0 || z > upland.z1) continue;
358
509
  let top = 0;
359
- for (let j = 0; j < U.limbs.length; j++) top = joined(top, limbHeight(U.limbs[j], x, z));
510
+ for (let j = 0; j < upland.limbs.length; j++) top = joined(top, limbHeight(upland.limbs[j], x, z));
360
511
  h += top;
361
512
  }
362
513
  return h;
@@ -371,12 +522,14 @@ export function createMountainRanges(seed = 0) {
371
522
  box.z0 = Math.min(box.z0, z);
372
523
  box.z1 = Math.max(box.z1, z);
373
524
  };
374
- for (const L of limbs) {
375
- for (const u of [L.from, L.to]) for (const v of [-L.far, L.far]) hold(L.x + u * L.ax - v * L.az, L.z + u * L.az + v * L.ax);
376
- if (L.swell) {
525
+ for (const limbData of limbs) {
526
+ for (const u of [limbData.from, limbData.to])
527
+ for (const v of [-limbData.far, limbData.far])
528
+ hold(limbData.x + u * limbData.ax - v * limbData.az, limbData.z + u * limbData.az + v * limbData.ax);
529
+ if (limbData.swell) {
377
530
  const reach = Math.sqrt(SWELL_REACH + SWELL_WARP / 2);
378
- hold(L.swell.x - reach * L.swell.rx, L.swell.z - reach * L.swell.rz);
379
- hold(L.swell.x + reach * L.swell.rx, L.swell.z + reach * L.swell.rz);
531
+ hold(limbData.swell.x - reach * limbData.swell.rx, limbData.swell.z - reach * limbData.swell.rz);
532
+ hold(limbData.swell.x + reach * limbData.swell.rx, limbData.swell.z + reach * limbData.swell.rz);
380
533
  }
381
534
  }
382
535
  return box;
@@ -385,15 +538,15 @@ export function createMountainRanges(seed = 0) {
385
538
  const faceSide = (face, ax, az) => (face === undefined ? 0 : Math.cos(face) * -az + Math.sin(face) * ax < 0 ? -1 : 1);
386
539
  // An upland given as an ellipse ({ x, z, rx, rz, h, rough }): one limb along its long axis. The more broken it is, the longer
387
540
  // its crest holds its height before it falls away.
388
- function ellipseLimb(m, seed) {
389
- const [bearing, a, b] = ellipseAxis(m),
390
- held = HELD * sstep(RANGE_FROM[0], RANGE_FROM[1], m.rough) * Math.max(a - 0.5 * b, 0.2 * a), // the half-length its crest holds its height over: little of a round one's
391
- tail = a - 0.95 * held,
541
+ function ellipseLimb(landform, seed) {
542
+ const [bearing, halfLength, halfWidth] = ellipseAxis(landform),
543
+ held = HELD * sstep(RANGE_FROM[0], RANGE_FROM[1], landform.rough) * Math.max(halfLength - 0.5 * halfWidth, 0.2 * halfLength), // the half-length its crest holds its height over: little of a round one's
544
+ tail = halfLength - 0.95 * held,
392
545
  ax = Math.cos(bearing),
393
546
  az = Math.sin(bearing),
394
547
  crest = {
395
- x: m.x - held * ax,
396
- z: m.z - held * az,
548
+ x: landform.x - held * ax,
549
+ z: landform.z - held * az,
397
550
  ax,
398
551
  az,
399
552
  len: 2 * held,
@@ -405,58 +558,79 @@ export function createMountainRanges(seed = 0) {
405
558
  free1: true,
406
559
  };
407
560
  return limb(
408
- { ...crest, b, h: m.h, rough: m.rough, face: faceSide(m.face, ax, az), line: false, swell: m.axis === undefined ? m : null },
561
+ {
562
+ ...crest,
563
+ b: halfWidth,
564
+ h: landform.h,
565
+ rough: landform.rough,
566
+ face: faceSide(landform.face, ax, az),
567
+ line: false,
568
+ swell: landform.axis === undefined ? landform : null,
569
+ },
409
570
  seed,
410
571
  );
411
572
  }
412
573
  // An upland given as a line ({ crest: [[x, z, share of h], ...], wide, h, rough }): a limb to each stretch, each running on a
413
574
  // little past the point where the next begins.
414
- function lineLimbs(m, seed) {
575
+ function lineLimbs(landform, seed) {
415
576
  const limbs = [],
416
- tail = end => m.wide * (end ? 0.65 : 0.7);
417
- for (let i = 0; i + 1 < m.crest.length; i++) {
418
- const [x, z, k0] = m.crest[i],
419
- [x1, z1, k1] = m.crest[i + 1],
577
+ tail = end => landform.wide * (end ? 0.65 : 0.7);
578
+ for (let i = 0; i + 1 < landform.crest.length; i++) {
579
+ const [x, z, k0] = landform.crest[i],
580
+ [x1, z1, k1] = landform.crest[i + 1],
420
581
  len = Math.hypot(x1 - x, z1 - z),
421
582
  ax = (x1 - x) / len,
422
583
  az = (z1 - z) / len,
423
584
  first = i === 0,
424
- last = i + 2 === m.crest.length,
585
+ last = i + 2 === landform.crest.length,
425
586
  crest = { x, z, ax, az, len, tail0: tail(first), tail1: tail(last), k0, k1, free0: first, free1: last };
426
587
  limbs.push(
427
- limb({ ...crest, b: m.wide, h: m.h, rough: m.rough, face: faceSide(m.face, ax, az), line: true, swell: null }, seed + i * 3),
588
+ limb(
589
+ {
590
+ ...crest,
591
+ b: landform.wide,
592
+ h: landform.h,
593
+ rough: landform.rough,
594
+ face: faceSide(landform.face, ax, az),
595
+ line: true,
596
+ swell: null,
597
+ },
598
+ seed + i * 3,
599
+ ),
428
600
  );
429
601
  }
430
602
  return limbs;
431
603
  }
432
604
  // A field of hills ({ x, z, rx, rz, h, rough, hills: how many }): small ranges scattered over its ellipse, their crests near one
433
605
  // strike (`axis`, or the ellipse's long axis), on a low swell.
434
- function hillField(m, seed) {
435
- const [strike, , lesser] = ellipseAxis(m),
606
+ function hillField(landform, seed) {
607
+ const [strike, , lesser] = ellipseAxis(landform),
436
608
  r = (i, n) => hash2(i, n, seed + 2),
437
- out = [boxed([ellipseLimb({ ...m, h: m.h * HILL.base, rough: 0, axis: undefined }, seed)])];
438
- for (let i = 0; i < m.hills; i++) {
439
- const far = 0.85 * Math.sqrt((i + 0.5) / m.hills),
609
+ out = [boxed([ellipseLimb({ ...landform, h: landform.h * HILL.base, rough: 0, axis: undefined }, seed)])];
610
+ for (let i = 0; i < landform.hills; i++) {
611
+ const far = 0.85 * Math.sqrt((i + 0.5) / landform.hills),
440
612
  round = i * 2.39996 + r(i, 1), // the golden angle from one to the next, so they fill the ellipse evenly
441
613
  long = lesser * lerp(HILL.long[0], HILL.long[1], r(i, 2)),
442
614
  hill = {
443
- x: m.x + m.rx * far * Math.cos(round),
444
- z: m.z + m.rz * far * Math.sin(round),
615
+ x: landform.x + landform.rx * far * Math.cos(round),
616
+ z: landform.z + landform.rz * far * Math.sin(round),
445
617
  rx: long,
446
618
  rz: long * lerp(HILL.wide[0], HILL.wide[1], r(i, 3)),
447
- h: m.h * lerp(HILL.high[0], HILL.high[1], r(i, 4)) * (1 - 0.4 * far * far),
448
- rough: m.rough,
619
+ h: landform.h * lerp(HILL.high[0], HILL.high[1], r(i, 4)) * (1 - 0.4 * far * far),
620
+ rough: landform.rough,
449
621
  axis: strike + (r(i, 5) - 0.5) * HILL.turn,
450
622
  };
451
623
  out.push(boxed([ellipseLimb(hill, seed + 10 + i * 3)]));
452
624
  }
453
625
  return out;
454
626
  }
455
- // Lays out a land's uplands (its data's list), for rangesAt.
627
+ /** @param {(EllipticalUpland | Ridge)[]} list - Landforms in stable seed order. */
456
628
  function layOutRanges(list) {
457
- uplands = list.flatMap((m, i) => {
629
+ uplands = list.flatMap((landform, i) => {
458
630
  const seed = 400 + i * 41;
459
- return m.hills ? hillField(m, seed) : [boxed(m.crest ? lineLimbs(m, seed) : [ellipseLimb(m, seed)])];
631
+ return landform.hills
632
+ ? hillField(landform, seed)
633
+ : [boxed(landform.crest ? lineLimbs(landform, seed) : [ellipseLimb(landform, seed)])];
460
634
  });
461
635
  }
462
636
  return { layout: layOutRanges, heightAt: rangesAt, surface: range };