roamwright 0.20.1 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (516) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +19 -14
  3. package/README.md +35 -16
  4. package/examples/animals.html +49 -0
  5. package/examples/animals.js +209 -0
  6. package/examples/crowds.html +50 -0
  7. package/examples/crowds.js +268 -0
  8. package/examples/effects.html +53 -0
  9. package/examples/effects.js +343 -0
  10. package/examples/figure-motion.html +55 -0
  11. package/examples/figure-motion.js +265 -0
  12. package/examples/figure.html +49 -0
  13. package/examples/figure.js +238 -0
  14. package/examples/fliers.html +53 -0
  15. package/examples/fliers.js +292 -0
  16. package/examples/fortification.html +54 -0
  17. package/examples/fortification.js +288 -0
  18. package/examples/house-kit.html +48 -0
  19. package/examples/house-kit.js +175 -0
  20. package/examples/index.html +26 -16
  21. package/examples/island.html +48 -0
  22. package/examples/island.js +134 -52
  23. package/examples/land.html +54 -0
  24. package/examples/land.js +392 -0
  25. package/examples/props-and-plants.html +53 -0
  26. package/examples/props-and-plants.js +275 -0
  27. package/examples/rooms.html +48 -0
  28. package/examples/rooms.js +242 -0
  29. package/examples/ships.html +51 -0
  30. package/examples/ships.js +235 -0
  31. package/examples/showcase.css +320 -0
  32. package/examples/small-world-land.js +151 -0
  33. package/examples/small-world-life.js +160 -0
  34. package/examples/small-world-town.js +127 -0
  35. package/examples/small-world.html +57 -0
  36. package/examples/small-world.js +226 -0
  37. package/examples/soundscape.html +138 -0
  38. package/examples/soundscape.js +467 -0
  39. package/examples/stage-kits.js +300 -0
  40. package/examples/stage.js +374 -0
  41. package/examples/towns.html +50 -0
  42. package/examples/towns.js +325 -0
  43. package/examples/viaduct-camera.js +8 -4
  44. package/examples/viaduct-landscape.js +28 -17
  45. package/examples/viaduct.html +45 -43
  46. package/examples/viaduct.js +68 -92
  47. package/geometry/animal-camel-body.js +410 -0
  48. package/geometry/animal-camel-head.js +118 -0
  49. package/geometry/animal-canine-body.js +361 -0
  50. package/geometry/animal-canine-breeds.js +316 -0
  51. package/geometry/animal-canine-head.js +337 -0
  52. package/geometry/animal-cattle-body.js +391 -0
  53. package/geometry/animal-cattle-coat.js +42 -0
  54. package/geometry/animal-cattle-head.js +152 -0
  55. package/geometry/animal-hen.js +248 -0
  56. package/geometry/animal-horse-body.js +446 -0
  57. package/geometry/animal-horse-bridle.js +171 -0
  58. package/geometry/animal-horse-coat.js +68 -0
  59. package/geometry/animal-horse-face.js +162 -0
  60. package/geometry/animal-horse-hair.js +304 -0
  61. package/geometry/animal-horse-head.js +133 -0
  62. package/geometry/animal-horse-tack.js +157 -0
  63. package/geometry/animal-options.js +59 -0
  64. package/geometry/animal-shapes.js +21 -0
  65. package/geometry/animal-skin.js +390 -0
  66. package/geometry/builder-cells.js +10 -2
  67. package/geometry/builder-frame.js +2 -1
  68. package/geometry/builder.js +15 -4
  69. package/geometry/card-emblem.js +437 -0
  70. package/geometry/catenary-canvas.js +396 -0
  71. package/geometry/cloth-folds.js +143 -0
  72. package/geometry/crawl-shapes.js +71 -0
  73. package/geometry/creased-sheet.js +7 -2
  74. package/geometry/crowd-dress.js +315 -0
  75. package/geometry/crowd-far.js +174 -0
  76. package/geometry/crowd-look.js +42 -0
  77. package/geometry/crowd-weld.js +218 -0
  78. package/geometry/ear.js +9 -4
  79. package/geometry/erosion.js +7 -4
  80. package/geometry/face-grid.js +26 -6
  81. package/geometry/field-map.js +59 -0
  82. package/geometry/figure-arms.js +339 -0
  83. package/geometry/figure-beard.js +250 -0
  84. package/geometry/figure-body.js +297 -0
  85. package/geometry/figure-bow.js +105 -0
  86. package/geometry/figure-cloak.js +189 -0
  87. package/geometry/figure-clothes.js +337 -0
  88. package/geometry/figure-face-grids.js +75 -0
  89. package/geometry/figure-gear.js +446 -0
  90. package/geometry/figure-hair-far.js +151 -0
  91. package/geometry/figure-hair-hangs.js +108 -0
  92. package/geometry/figure-hair-patch.js +66 -0
  93. package/geometry/figure-hair.js +320 -0
  94. package/geometry/figure-hands.js +321 -0
  95. package/geometry/figure-head-features.js +280 -0
  96. package/geometry/figure-head.js +375 -0
  97. package/geometry/figure-headwear.js +223 -0
  98. package/geometry/figure-legs.js +231 -0
  99. package/geometry/figure-limbs.js +39 -0
  100. package/geometry/figure-sculpt.js +82 -0
  101. package/geometry/figure-skin.js +97 -0
  102. package/geometry/figure-skirts.js +303 -0
  103. package/geometry/figure-trunk.js +411 -0
  104. package/geometry/flier-corvid-body.js +322 -0
  105. package/geometry/flier-corvid-wings.js +154 -0
  106. package/geometry/flier-long-body.js +195 -0
  107. package/geometry/flier-shapes.js +219 -0
  108. package/geometry/flier-soaring-bird.js +84 -0
  109. package/geometry/foliage.js +177 -4
  110. package/geometry/fort-city-walls.js +479 -0
  111. package/geometry/fort-gate-approach.js +233 -0
  112. package/geometry/fort-great-walls.js +280 -0
  113. package/geometry/fort-keep.js +297 -0
  114. package/geometry/fort-parts.js +261 -0
  115. package/geometry/fort-polyline.js +261 -0
  116. package/geometry/fort-portal.js +96 -0
  117. package/geometry/fort-ring-wall.js +267 -0
  118. package/geometry/fort-seawall.js +104 -0
  119. package/geometry/fort-terrace-gates.js +323 -0
  120. package/geometry/fort-terrace-plan.js +250 -0
  121. package/geometry/fort-terrace-wall.js +345 -0
  122. package/geometry/garment-tags.js +11 -3
  123. package/geometry/grid-gather.js +69 -0
  124. package/geometry/grid-sample.js +185 -0
  125. package/geometry/hair-gathers.js +19 -4
  126. package/geometry/hair-locks.js +1 -1
  127. package/geometry/hair-patch.js +6 -2
  128. package/geometry/hair-shell.js +14 -2
  129. package/geometry/head-presets.js +103 -0
  130. package/geometry/head-profile.js +13 -2
  131. package/geometry/head-shape.js +51 -23
  132. package/geometry/heightfield.js +26 -9
  133. package/geometry/horizon-angles.js +166 -0
  134. package/geometry/house-kit-body.js +195 -0
  135. package/geometry/house-kit-courtyard-parts.js +340 -0
  136. package/geometry/house-kit-courtyard-roof.js +223 -0
  137. package/geometry/house-kit-courtyard.js +409 -0
  138. package/geometry/house-kit-cut.js +29 -0
  139. package/geometry/house-kit-extras.js +192 -0
  140. package/geometry/house-kit-forms.js +298 -0
  141. package/geometry/house-kit-frame.js +74 -0
  142. package/geometry/house-kit-marks.js +93 -0
  143. package/geometry/house-kit-openings.js +193 -0
  144. package/geometry/house-kit-palette.js +54 -0
  145. package/geometry/house-kit-pool.js +71 -0
  146. package/geometry/house-kit-roofs.js +151 -0
  147. package/geometry/house-kit.js +202 -0
  148. package/geometry/instances.js +4 -4
  149. package/geometry/lamp-wash.js +65 -0
  150. package/geometry/land-clearings.js +83 -0
  151. package/geometry/land-ditches.js +290 -0
  152. package/geometry/land-dry-basin.js +327 -0
  153. package/geometry/land-dunes.js +150 -0
  154. package/geometry/land-earthworks.js +432 -0
  155. package/geometry/land-edge.js +292 -0
  156. package/geometry/land-mound-faces.js +349 -0
  157. package/geometry/land-near-relief.js +102 -0
  158. package/geometry/land-sheet.js +220 -0
  159. package/geometry/land-town-ground.js +256 -0
  160. package/geometry/land-waters.js +228 -0
  161. package/geometry/land-wildness.js +123 -0
  162. package/geometry/lathed-vessel.js +293 -0
  163. package/geometry/outline-grid.js +5 -4
  164. package/geometry/outline-segments.js +74 -0
  165. package/geometry/part-ranges.js +35 -0
  166. package/geometry/path-field.js +35 -1
  167. package/geometry/planked-floor.js +149 -0
  168. package/geometry/plant-broadleaf.js +268 -0
  169. package/geometry/plant-shrub.js +198 -0
  170. package/geometry/plant-tints.js +80 -0
  171. package/geometry/plant-trees.js +453 -0
  172. package/geometry/plant-tussock.js +107 -0
  173. package/geometry/primitives.js +65 -23
  174. package/geometry/prop-battlefield.js +69 -0
  175. package/geometry/prop-camp.js +175 -0
  176. package/geometry/prop-door.js +26 -0
  177. package/geometry/prop-harbour.js +105 -0
  178. package/geometry/prop-haycock.js +60 -0
  179. package/geometry/prop-sacks.js +74 -0
  180. package/geometry/prop-sheaf.js +68 -0
  181. package/geometry/prop-street.js +69 -0
  182. package/geometry/prop-tents.js +396 -0
  183. package/geometry/prop-tombs.js +80 -0
  184. package/geometry/prop-trade.js +393 -0
  185. package/geometry/prop-vehicles.js +218 -0
  186. package/geometry/props.js +58 -0
  187. package/geometry/room-arcade.js +134 -0
  188. package/geometry/room-dome.js +188 -0
  189. package/geometry/room-flames.js +138 -0
  190. package/geometry/room-frame.js +106 -0
  191. package/geometry/room-furniture.js +260 -0
  192. package/geometry/room-hearth.js +98 -0
  193. package/geometry/room-kit.js +59 -0
  194. package/geometry/room-openings.js +142 -0
  195. package/geometry/room-stairs.js +180 -0
  196. package/geometry/room-surfaces.js +272 -0
  197. package/geometry/sampled-surface.js +24 -10
  198. package/geometry/scatter-grid.js +6 -3
  199. package/geometry/sculpt.js +5 -1
  200. package/geometry/ship-fittings.js +350 -0
  201. package/geometry/ship-hull.js +460 -0
  202. package/geometry/ship-kit.js +208 -0
  203. package/geometry/ship-lines.js +69 -0
  204. package/geometry/ship-oars.js +150 -0
  205. package/geometry/ship-presets.js +131 -0
  206. package/geometry/ship-rig.js +374 -0
  207. package/geometry/ship-sails.js +148 -0
  208. package/geometry/shore-grid.js +5 -1
  209. package/geometry/strata-field.js +44 -11
  210. package/geometry/strata-tiles.js +20 -6
  211. package/geometry/stream.js +32 -17
  212. package/geometry/swept-tube.js +124 -0
  213. package/geometry/terrain-chunks.js +139 -51
  214. package/geometry/terrain-extension.js +24 -8
  215. package/geometry/town-courtyard-inn.js +272 -0
  216. package/geometry/town-ground.js +76 -0
  217. package/geometry/town-houses.js +343 -0
  218. package/geometry/town-lights.js +254 -0
  219. package/geometry/town-lots.js +172 -0
  220. package/geometry/town-plan.js +370 -0
  221. package/geometry/town-works.js +465 -0
  222. package/geometry/village-layout.js +181 -0
  223. package/geometry/village-yards.js +167 -0
  224. package/geometry/wall-runs.js +64 -0
  225. package/index.js +134 -3
  226. package/math/cloud-textures.js +3 -7
  227. package/math/curve.js +5 -1
  228. package/math/lamp-texels.js +43 -0
  229. package/math/lit-share.js +22 -0
  230. package/math/mountain-ranges.js +177 -54
  231. package/math/periodic.js +6 -0
  232. package/math/rectangles.js +8 -2
  233. package/math/rock-texture.js +17 -12
  234. package/math/surface-textures.js +24 -9
  235. package/math/wandering-path.js +40 -0
  236. package/math/ways.js +120 -0
  237. package/motion/action-dynamics.js +398 -0
  238. package/motion/animal-bearing.js +247 -0
  239. package/motion/animal-canine-bearing.js +178 -0
  240. package/motion/animal-canine-cast.js +131 -0
  241. package/motion/animal-cattle-cast.js +64 -0
  242. package/motion/animal-herd-cast.js +154 -0
  243. package/motion/animal-horse-still.js +161 -0
  244. package/motion/animal-troop-cast.js +43 -0
  245. package/motion/arm-reach.js +3 -2
  246. package/motion/ballistic-arc.js +182 -2
  247. package/motion/biped-cycle.js +4 -2
  248. package/motion/biped-leg.js +4 -1
  249. package/motion/biped-posture.js +459 -0
  250. package/motion/biped-stride.js +142 -32
  251. package/motion/boat-sailing.js +214 -0
  252. package/motion/contact-transition.js +5 -6
  253. package/motion/crowd-alarms.js +36 -6
  254. package/motion/crowd-attention.js +108 -0
  255. package/motion/crowd-beasts.js +203 -0
  256. package/motion/crowd-camp.js +295 -0
  257. package/motion/crowd-figure.js +100 -0
  258. package/motion/crowd-herd.js +86 -0
  259. package/motion/crowd-hold.js +130 -0
  260. package/motion/crowd-pose.js +296 -0
  261. package/motion/crowd-poses.js +481 -0
  262. package/motion/crowd-routine.js +44 -14
  263. package/motion/crowd-town.js +166 -0
  264. package/motion/crowd-water.js +143 -0
  265. package/motion/deck-surface.js +4 -2
  266. package/motion/figure-acts.js +411 -0
  267. package/motion/figure-arms.js +437 -0
  268. package/motion/figure-blade-slide.js +149 -0
  269. package/motion/figure-body-place.js +180 -0
  270. package/motion/figure-bones.js +118 -0
  271. package/motion/figure-bow-draw.js +70 -0
  272. package/motion/figure-fingers.js +215 -0
  273. package/motion/figure-gaze.js +205 -0
  274. package/motion/figure-gestures.js +452 -0
  275. package/motion/figure-grip.js +134 -0
  276. package/motion/figure-head.js +287 -0
  277. package/motion/figure-legs.js +264 -0
  278. package/motion/figure-links.js +293 -0
  279. package/motion/figure-locomotion.js +391 -0
  280. package/motion/figure-mount-up.js +180 -0
  281. package/motion/figure-mount.js +201 -0
  282. package/motion/figure-pose-frame.js +375 -0
  283. package/motion/figure-pose-table.js +156 -0
  284. package/motion/figure-pose.js +343 -0
  285. package/motion/figure-seat.js +267 -0
  286. package/motion/figure-sway.js +125 -0
  287. package/motion/flier-corvid-pose.js +74 -0
  288. package/motion/flier-flight-air.js +122 -0
  289. package/motion/flier-flight-echelon.js +164 -0
  290. package/motion/flier-flight-roost.js +131 -0
  291. package/motion/flier-swarm-flight.js +252 -0
  292. package/motion/formation.js +193 -0
  293. package/motion/instance-sight.js +8 -1
  294. package/motion/melee-contact.js +143 -0
  295. package/motion/moorings.js +48 -0
  296. package/motion/path-steering.js +358 -0
  297. package/motion/player.js +7 -6
  298. package/motion/quadruped.js +109 -33
  299. package/motion/spaces.js +58 -6
  300. package/motion/speech-cadence.js +304 -0
  301. package/motion/vessel-motion.js +57 -0
  302. package/motion/walk-grid.js +235 -0
  303. package/motion/weather.js +70 -12
  304. package/motion/wind.js +27 -1
  305. package/package.json +27 -4
  306. package/rendering/alpha-mips.js +340 -0
  307. package/rendering/animal-camel-figure.js +29 -0
  308. package/rendering/animal-canine-figure.js +59 -0
  309. package/rendering/animal-cattle-figure.js +36 -0
  310. package/rendering/animal-horse-figure.js +49 -0
  311. package/rendering/atmosphere.js +86 -0
  312. package/rendering/camera-track.js +156 -0
  313. package/rendering/{road-surface.js → cart-track.js} +40 -11
  314. package/rendering/caster-motion.js +2 -1
  315. package/rendering/cell-lod-options.js +46 -0
  316. package/rendering/cell-lod.js +665 -80
  317. package/rendering/cloth-material.js +140 -0
  318. package/rendering/cloud-dome.js +2 -2
  319. package/rendering/compilation-schedule.js +18 -10
  320. package/rendering/contact-shadows.js +5 -2
  321. package/rendering/context.js +47 -8
  322. package/rendering/crowd-batches.js +420 -0
  323. package/rendering/crowd-herd.js +198 -0
  324. package/rendering/crowd-rig.js +132 -0
  325. package/rendering/crowd-skinning.js +52 -9
  326. package/rendering/crowd-update.js +419 -0
  327. package/rendering/crowd-visibility.js +107 -0
  328. package/rendering/day-cycle-defaults.js +200 -0
  329. package/rendering/day-cycle.js +487 -0
  330. package/rendering/daylight.js +1 -3
  331. package/rendering/detail-range.js +6 -5
  332. package/rendering/dof.js +11 -4
  333. package/rendering/effects-frame.js +149 -0
  334. package/rendering/effects-water-rises.js +221 -0
  335. package/rendering/energy-stream.js +128 -0
  336. package/rendering/facade-glass-material.js +105 -0
  337. package/rendering/far-shadow.js +81 -54
  338. package/rendering/field-surface.js +138 -0
  339. package/rendering/figure-shield.js +105 -0
  340. package/rendering/figure-skeleton.js +329 -0
  341. package/rendering/fire-light-watch.js +197 -0
  342. package/rendering/fire-pools.js +148 -0
  343. package/rendering/flame-sources.js +86 -0
  344. package/rendering/flier-bird-looks.js +97 -0
  345. package/rendering/flier-corvid-figure.js +67 -0
  346. package/rendering/flier-long-body-company.js +169 -0
  347. package/rendering/flier-swarm.js +186 -0
  348. package/rendering/flocks.js +6 -2
  349. package/rendering/garment-material.js +145 -49
  350. package/rendering/glsl-literal.js +19 -0
  351. package/rendering/ground-marks.js +316 -0
  352. package/rendering/hair-strands.js +38 -24
  353. package/rendering/height-haze.js +80 -33
  354. package/rendering/height-probe.js +15 -3
  355. package/rendering/house-kit-meshes.js +124 -0
  356. package/rendering/interior-bake.js +807 -0
  357. package/rendering/label-layout.js +13 -3
  358. package/rendering/label-range.js +5 -2
  359. package/rendering/lamp-light-map.js +159 -0
  360. package/rendering/lamp-maps.js +62 -0
  361. package/rendering/lamp-wash.js +51 -0
  362. package/rendering/light-budget.js +19 -3
  363. package/rendering/light-points.js +21 -5
  364. package/rendering/local-lights.js +27 -7
  365. package/rendering/material-lod.js +5 -6
  366. package/rendering/memory-estimate.js +84 -0
  367. package/rendering/moored-fleet.js +186 -0
  368. package/rendering/part-costs.js +104 -0
  369. package/rendering/particle-bursts.js +386 -0
  370. package/rendering/particle-emitters.js +61 -25
  371. package/rendering/particle-light-bursts.js +189 -0
  372. package/rendering/particles.js +134 -34
  373. package/rendering/pen-flocks.js +118 -0
  374. package/rendering/piece-batch.js +282 -6
  375. package/rendering/planar-reflection-options.js +159 -0
  376. package/rendering/planar-reflection.js +780 -77
  377. package/rendering/plant-cells.js +122 -0
  378. package/rendering/plant-reeds.js +113 -0
  379. package/rendering/plant-shade-trees.js +239 -0
  380. package/rendering/plant-tuft-patch.js +122 -0
  381. package/rendering/post-shaders.js +84 -21
  382. package/rendering/post.js +39 -19
  383. package/rendering/pressed-cover.js +135 -0
  384. package/rendering/prop-dig.js +136 -0
  385. package/rendering/room-light.js +250 -0
  386. package/rendering/room-materials.js +78 -0
  387. package/rendering/room-space.js +111 -0
  388. package/rendering/scene-lights.js +106 -0
  389. package/rendering/sea-shaders.js +83 -26
  390. package/rendering/settlement-approach.js +226 -0
  391. package/rendering/settlement-dissolve.js +89 -0
  392. package/rendering/settlement-quarter-warm.js +55 -0
  393. package/rendering/settlement-quarter.js +477 -0
  394. package/rendering/settlement-switch.js +42 -0
  395. package/rendering/settlement-town.js +110 -0
  396. package/rendering/shader-warmup.js +80 -36
  397. package/rendering/shadow-depth.js +40 -18
  398. package/rendering/ship-meshes.js +150 -0
  399. package/rendering/shot-cuts.js +68 -0
  400. package/rendering/sky-occlusion.js +42 -15
  401. package/rendering/sky-pmrem.js +216 -0
  402. package/rendering/sky.js +112 -50
  403. package/rendering/smoke-shadows.js +201 -0
  404. package/rendering/stage-framing.js +182 -0
  405. package/rendering/stage-lights.js +46 -39
  406. package/rendering/stain-material.js +74 -0
  407. package/rendering/static-point-shadow.js +62 -23
  408. package/rendering/still-casters.js +77 -27
  409. package/rendering/strata-material.js +2 -2
  410. package/rendering/street-lamps.js +166 -0
  411. package/rendering/sunbeam-motes.js +670 -0
  412. package/rendering/surface-light.js +65 -6
  413. package/rendering/surface-material.js +306 -0
  414. package/rendering/surface-projection.js +32 -0
  415. package/rendering/surface-snippets.js +314 -0
  416. package/rendering/taa.js +49 -18
  417. package/rendering/tree-impostor.js +929 -0
  418. package/rendering/vehicle-train.js +92 -0
  419. package/rendering/viewport.js +67 -4
  420. package/rendering/water-material.js +270 -82
  421. package/rendering/waypoint-beacons.js +191 -0
  422. package/rendering/world-matrices.js +0 -2
  423. package/ruff.toml +20 -0
  424. package/runtime/cue-cursor.js +21 -0
  425. package/runtime/device-quality.js +13 -2
  426. package/runtime/device.js +73 -0
  427. package/runtime/diagnostic-log.js +11 -3
  428. package/runtime/effect-sites.js +85 -0
  429. package/runtime/figure-orders.js +59 -0
  430. package/runtime/first-use.js +8 -5
  431. package/runtime/foley-script.js +124 -0
  432. package/runtime/foley-strides.js +333 -0
  433. package/runtime/frame-pacing.js +18 -4
  434. package/runtime/frame-yield.js +18 -0
  435. package/runtime/gpu-timing.js +8 -4
  436. package/runtime/grid-cache.js +16 -6
  437. package/runtime/grid-rows.js +5 -5
  438. package/runtime/hand-over.js +7 -2
  439. package/runtime/land-bake.js +78 -0
  440. package/runtime/lazy-sets.js +105 -0
  441. package/runtime/pool.js +17 -3
  442. package/runtime/quality-fit.js +59 -27
  443. package/runtime/region-pass-lay.js +40 -0
  444. package/runtime/region-pass.js +78 -0
  445. package/runtime/search.js +6 -2
  446. package/runtime/settlement-reach.js +42 -0
  447. package/runtime/sound-calls.js +113 -0
  448. package/runtime/sound-impacts.js +297 -0
  449. package/runtime/sound-voices.js +194 -0
  450. package/runtime/soundscape.js +282 -0
  451. package/runtime/spatial-audio.js +69 -20
  452. package/runtime/steady-frames.js +221 -0
  453. package/runtime/withdrawable-task.js +19 -8
  454. package/scripts/app-parts.mjs +118 -0
  455. package/scripts/bake-revisions.mjs +81 -0
  456. package/scripts/browser-scripts.mjs +64 -0
  457. package/scripts/bundle.mjs +192 -0
  458. package/scripts/check-app.sh +26 -0
  459. package/scripts/eslint-config.mjs +119 -0
  460. package/scripts/format.sh +92 -0
  461. package/scripts/keep-builds.mjs +158 -0
  462. package/scripts/layers.mjs +112 -0
  463. package/scripts/lint.sh +49 -0
  464. package/scripts/module-graph.mjs +123 -0
  465. package/scripts/pre-commit.sh +38 -0
  466. package/scripts/serve.py +5 -3
  467. package/scripts/site.mjs +358 -0
  468. package/scripts/test-runner.sh +42 -0
  469. package/scripts/vendor.mjs +221 -0
  470. package/scripts/verify-publish.mjs +175 -0
  471. package/scripts/world.mk +59 -0
  472. package/tools/README.md +73 -0
  473. package/tools/contact-sheet.cjs +137 -0
  474. package/tools/cpu-profile.cjs +275 -0
  475. package/tools/cpu-profile.test.cjs +98 -0
  476. package/tools/first-draws.cjs +395 -0
  477. package/tools/flight-guard.cjs +482 -0
  478. package/tools/flight-guard.test.cjs +153 -0
  479. package/tools/flight-profile.cjs +145 -0
  480. package/tools/frame-bench.cjs +336 -0
  481. package/tools/frame-parts.cjs +365 -0
  482. package/tools/ios-sim.sh +145 -0
  483. package/tools/load-audit.cjs +201 -0
  484. package/tools/look-compare.cjs +304 -0
  485. package/tools/look-guard.cjs +407 -0
  486. package/tools/look-guard.test.cjs +93 -0
  487. package/tools/look-stats.cjs +185 -0
  488. package/tools/look-stats.test.cjs +71 -0
  489. package/tools/memory-audit.cjs +323 -0
  490. package/tools/page-driver.cjs +320 -0
  491. package/tools/page-driver.test.cjs +219 -0
  492. package/tools/program-census-report.cjs +191 -0
  493. package/tools/program-census.cjs +465 -0
  494. package/tools/program-census.test.cjs +332 -0
  495. package/tools/remote-runner.sh +265 -0
  496. package/tools/runners.test.cjs +59 -0
  497. package/tools/scene-audit-beat.cjs +344 -0
  498. package/tools/scene-audit-sheet.cjs +282 -0
  499. package/tools/scene-audit.cjs +471 -0
  500. package/tools/scene-audit.test.cjs +201 -0
  501. package/tools/scene-batch.cjs +219 -0
  502. package/tools/scene-bench.cjs +149 -0
  503. package/tools/scene-bench.test.cjs +33 -0
  504. package/tools/scene-run.cjs +443 -0
  505. package/tools/scene-run.test.cjs +94 -0
  506. package/tools/servers.sh +59 -0
  507. package/tools/shader-arrival.cjs +316 -0
  508. package/tools/shader-renewal.cjs +53 -0
  509. package/tools/shader-renewal.test.cjs +115 -0
  510. package/tools/speed-guard.cjs +258 -0
  511. package/tools/stills.cjs +492 -0
  512. package/tools/stills.test.cjs +49 -0
  513. package/tools/turns.sh +7 -0
  514. package/tools/yaml.cjs +158 -0
  515. package/examples/viaduct.css +0 -75
  516. package/rendering/light-shafts.js +0 -131
@@ -7,7 +7,8 @@ const POINT = 10, // numbers to a point: its place, its normal, its colour, and
7
7
 
8
8
  // Emit each shared vertex once per strand band, correcting the winding from the supplied normals.
9
9
  function packHairPatch(points, triangles, emitVertex) {
10
- const bands = new Map(), corners = [];
10
+ const bands = new Map(),
11
+ corners = [];
11
12
  let vertexCount = 0;
12
13
  for (let t = 0; t < triangles.length; t += 3) {
13
14
  const firstOffset = triangles[t] * POINT,
@@ -25,7 +26,10 @@ function packHairPatch(points, triangles, emitVertex) {
25
26
  (uz * vx - ux * vz) * (points[firstOffset + 4] + points[secondOffset + 4] + points[thirdOffset + 4]) +
26
27
  (ux * vy - uy * vx) * (points[firstOffset + 5] + points[secondOffset + 5] + points[thirdOffset + 5]);
27
28
  let put = bands.get(band);
28
- if (!put) { put = new Map(); bands.set(band, put); }
29
+ if (!put) {
30
+ put = new Map();
31
+ bands.set(band, put);
32
+ }
29
33
  for (const pointOffset of faces < 0 ? [firstOffset, thirdOffset, secondOffset] : [firstOffset, secondOffset, thirdOffset]) {
30
34
  let v = put.get(pointOffset);
31
35
  if (v === undefined) {
@@ -25,7 +25,8 @@ const _o = new THREE.Vector3(),
25
25
  // Returns at(direction, lift, out, outward): the point of the mass at a direction from the head's middle, raised off it by lift
26
26
  // (metres), and the way out there; and full(direction): how much of its fullness the mass has at a direction, 0 to 1.
27
27
  function massOf({ skull, scale, inHair, drop = 0, lumps = 0, lumpy = 5, tucked = null }) {
28
- const full = direction => (EDGE + (1 - EDGE) * sstep(-0.01, RISE, inHair(direction.x, direction.y, direction.z))) * (tucked ? 1 - TUCK * tucked(direction) : 1),
28
+ const full = direction =>
29
+ (EDGE + (1 - EDGE) * sstep(-0.01, RISE, inHair(direction.x, direction.y, direction.z))) * (tucked ? 1 - TUCK * tucked(direction) : 1),
29
30
  swell = direction =>
30
31
  lumps *
31
32
  (Math.sin(direction.x * lumpy * 2.3 + direction.y * lumpy * 1.3) * Math.sin(direction.z * lumpy * 2.1 - direction.y * lumpy * 1.7) +
@@ -82,7 +83,18 @@ function createHairShells(sculptMesh) {
82
83
  at = Math.round(directions[q] * 2e4) + ',' + Math.round(directions[q + 1] * 2e4) + ',' + Math.round(directions[q + 2] * 2e4);
83
84
  let v = known.get(at);
84
85
  if (v === undefined) {
85
- v = add(positions[q], positions[q + 1], positions[q + 2], normals[q], normals[q + 1], normals[q + 2], directions[q], directions[q + 1], directions[q + 2], mass.inHair(directions[q], directions[q + 1], directions[q + 2]));
86
+ v = add(
87
+ positions[q],
88
+ positions[q + 1],
89
+ positions[q + 2],
90
+ normals[q],
91
+ normals[q + 1],
92
+ normals[q + 2],
93
+ directions[q],
94
+ directions[q + 1],
95
+ directions[q + 2],
96
+ mass.inHair(directions[q], directions[q + 1], directions[q + 2]),
97
+ );
86
98
  known.set(at, v);
87
99
  }
88
100
  numbered[i] = v;
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The kinds of human head a figure's face is varied from (`HEAD_PRESETS`: man, woman, heavy, skull), and the skull that caps,
3
+ * helmets, hoods and hair lie over (`SKULL`). A world adds heads of its own peoples beside these (figure-body.js, `heads`).
4
+ * @module
5
+ */
6
+ import { headFn } from './head-shape.js';
7
+
8
+ /**
9
+ * Kinds of head, as how strongly each feature is drawn; a figure's own face is one of these varied by its seed and look.
10
+ * jaw 0..1 the breadth at the jaw's angle; chin, chinW its jut and breadth; nose its reach, noseW, noseL, bridge (a hump, or a
11
+ * dip below 0); brow the ridge; socket how deep the eyes sit; cheek the cheekbones; hollow the cheeks under them; lips their
12
+ * fullness; mouthW; eye how far the lids open; tilt the outer corners raised; slope the forehead leaning back; fold the crease
13
+ * from nose to mouth; wide and tall: the whole head's breadth and height; age and fat 0..1; scar: a seam from [x, y] to [x, y]
14
+ * (millimetres from the head's middle, x to the person's left), then its width and how far its middle bows down; dead: a dried
15
+ * face, with pits for eyes; oneEye: the two eyes healed over and one large faceted eye in the middle of the brow, under a
16
+ * jutting ridge. The shape itself is head-shape.js's `headFn`.
17
+ * @type {Record<string, object>}
18
+ */
19
+ const HEAD_PRESETS = {
20
+ man: {
21
+ jaw: 0.55,
22
+ chin: 1,
23
+ chinW: 1,
24
+ nose: 1,
25
+ noseW: 1,
26
+ noseL: 1,
27
+ bridge: 0.25,
28
+ brow: 1,
29
+ socket: 1,
30
+ cheek: 1,
31
+ hollow: 0.35,
32
+ lips: 0.88,
33
+ mouthW: 1,
34
+ eye: 0.94,
35
+ tilt: 0,
36
+ slope: 1,
37
+ fold: 1,
38
+ },
39
+ woman: {
40
+ jaw: 0.2,
41
+ chin: 0.7,
42
+ chinW: 0.84,
43
+ nose: 0.86,
44
+ noseW: 0.88,
45
+ noseL: 0.96,
46
+ bridge: -0.25,
47
+ brow: 0.3,
48
+ socket: 0.8,
49
+ cheek: 1.12,
50
+ hollow: 0.1,
51
+ lips: 1.22,
52
+ mouthW: 0.93,
53
+ eye: 1.06,
54
+ tilt: 0.35,
55
+ slope: 0.3,
56
+ fold: 0.6,
57
+ },
58
+ heavy: {
59
+ jaw: 1,
60
+ chin: 1.35,
61
+ chinW: 1.25,
62
+ nose: 1.05,
63
+ noseW: 1.3,
64
+ noseL: 1,
65
+ bridge: 0.5,
66
+ brow: 1.8,
67
+ socket: 1.3,
68
+ cheek: 1.3,
69
+ hollow: 0.4,
70
+ lips: 0.8,
71
+ mouthW: 1.1,
72
+ eye: 0.88,
73
+ tilt: 0,
74
+ slope: 1.6,
75
+ fold: 1.4,
76
+ },
77
+ skull: {
78
+ dead: 1,
79
+ jaw: 0.45,
80
+ chin: 0.9,
81
+ chinW: 0.9,
82
+ nose: 0.2,
83
+ noseW: 0.9,
84
+ noseL: 0.8,
85
+ bridge: 0,
86
+ brow: 1.7,
87
+ socket: 2.1,
88
+ cheek: 1.7,
89
+ hollow: 2.6,
90
+ lips: 0,
91
+ mouthW: 1.05,
92
+ eye: 1.3,
93
+ tilt: 0,
94
+ slope: 1.2,
95
+ fold: 0,
96
+ age: 1,
97
+ },
98
+ };
99
+
100
+ /** The skull caps and hair are laid over: a man's head with its forehead leaning back less. */
101
+ const SKULL = headFn({ ...HEAD_PRESETS.man, slope: 0.65 });
102
+
103
+ export { HEAD_PRESETS, SKULL };
@@ -14,7 +14,15 @@ function curve(points) {
14
14
  for (let i = 0; i < pointCount; i++) {
15
15
  const previousSlope = slope[i - 1],
16
16
  nextSlope = slope[i];
17
- tangent.push(i === 0 ? nextSlope : i === pointCount - 1 ? previousSlope : previousSlope * nextSlope <= 0 ? 0 : (2 * previousSlope * nextSlope) / (previousSlope + nextSlope));
17
+ tangent.push(
18
+ i === 0
19
+ ? nextSlope
20
+ : i === pointCount - 1
21
+ ? previousSlope
22
+ : previousSlope * nextSlope <= 0
23
+ ? 0
24
+ : (2 * previousSlope * nextSlope) / (previousSlope + nextSlope),
25
+ );
18
26
  }
19
27
  const exact = x => {
20
28
  if (x <= coordinates[0]) return values[0];
@@ -26,7 +34,10 @@ function curve(points) {
26
34
  t2 = t * t,
27
35
  t3 = t2 * t;
28
36
  return (
29
- values[i] * (2 * t3 - 3 * t2 + 1) + tangent[i] * h * (t3 - 2 * t2 + t) + values[i + 1] * (3 * t2 - 2 * t3) + tangent[i + 1] * h * (t3 - t2)
37
+ values[i] * (2 * t3 - 3 * t2 + 1) +
38
+ tangent[i] * h * (t3 - 2 * t2 + t) +
39
+ values[i + 1] * (3 * t2 - 2 * t3) +
40
+ tangent[i + 1] * h * (t3 - t2)
30
41
  );
31
42
  };
32
43
  return sampled(exact, coordinates[0], coordinates[pointCount - 1]);
@@ -23,13 +23,36 @@ const MM = 0.001,
23
23
  WOUND_DEEP = 4.5, // millimetres a fresh wound's torn flesh lies below the skin round it,
24
24
  WOUND_SWELL = 2.2, // and how far the bruised skin at its edges swells;
25
25
  HEALED_DEEP = 2.4, // once healed (faceFeatures.healed), how far the scar lies sunk where the flesh was torn, and how high its edges and
26
- HEALED_RIDGE = 0.9, // the cords of scar tissue across it stand
27
- // Where a wound has torn the nose away, the opening into the skull's nose left in its place: a pear-shaped hollow down the
28
- // middle of the face (from the top of its rows to its foot, millimetres up the face), its half width at the foot, how deep it
29
- // sinks, and how dark it is within, fresh and healed.
30
- NOSE_HOLE = { top: -19, foot: -46, wide: 9.5, deep: 6, dark: 0.78, healedDeep: 3.5, healedDark: 0.6 },
31
- // Optional single brow eye: centre height, radius, opening, offset and brow ridge in millimetres.
32
- ONE_EYE = { y: 16.5, r: 17.5, wide: 16.5, high: 10.5, out: 7, ridge: 7 };
26
+ HEALED_RIDGE = 0.9; // the cords of scar tissue across it stand
27
+
28
+ /**
29
+ * Where a wound has torn the nose away, the opening into the skull's nose left in its place: a pear-shaped hollow down the
30
+ * middle of the face. A head's `noseHole` feature may change any of these. Millimetres from the head's middle (the eyes' level).
31
+ * @typedef {object} NoseHole
32
+ * @property {number} top - The height its top lies at.
33
+ * @property {number} foot - The height its foot lies at.
34
+ * @property {number} wide - Its half width at the foot.
35
+ * @property {number} deep - How deep it sinks, fresh.
36
+ * @property {number} dark - How dark it is within (0 to 1), fresh.
37
+ * @property {number} healedDeep - How deep it sinks once healed.
38
+ * @property {number} healedDark - How dark it is within once healed.
39
+ */
40
+ /** The default {@link NoseHole}. */
41
+ export const NOSE_HOLE = Object.freeze({ top: -19, foot: -46, wide: 9.5, deep: 6, dark: 0.78, healedDeep: 3.5, healedDark: 0.6 });
42
+ /**
43
+ * A single large eye in the middle of the brow in place of two (whose sockets are closed over), under a jutting ridge: a
44
+ * creature's or a giant's. A head's `oneEye` feature is `true` (or 1) for this shape, or an object that changes any of it.
45
+ * Millimetres from the head's middle.
46
+ * @typedef {object} OneEye
47
+ * @property {number} y - The height of the eye's middle.
48
+ * @property {number} r - The radius of its ball.
49
+ * @property {number} wide - Half the width of its lids' opening.
50
+ * @property {number} high - Half the height of its lids' opening.
51
+ * @property {number} out - How far its ball stands out of the brow.
52
+ * @property {number} ridge - How far the ridge over it juts.
53
+ */
54
+ /** The default {@link OneEye}. */
55
+ export const ONE_EYE = Object.freeze({ y: 16.5, r: 17.5, wide: 16.5, high: 10.5, out: 7, ridge: 7 });
33
56
 
34
57
  // A soft rise of that width about a point, and one about a point of the face. Far from the point it is nothing, and is not
35
58
  // worked out: a head asks for these some hundred thousand times.
@@ -64,7 +87,9 @@ const _slice = { x: 0, z: 0 },
64
87
 
65
88
  // The surface of a head with the given features, as a function of a direction from its middle: sampleHead(direction, outPoint, channels). Channels: lips,
66
89
  // shade, warmth (cheeks, nose), where a beard grows on cheeks and jaw, brow, where a moustache grows, the chin's tuft, a scar. A fine head has open lids and a mouth that can open (its grid lays rows
67
- // along their edges); a plain one, for the far mesh and for coarse sculpts, has them closed and painted.
90
+ // along their edges); a plain one, for the far mesh and for coarse sculpts, has them closed and painted. Among the features,
91
+ // `oneEye` gives the head one eye in the middle of the brow ({@link OneEye}), and `noseHole` changes the opening a wound across
92
+ // the nose leaves ({@link NoseHole}).
68
93
  function headFn(features = {}, fine = false) {
69
94
  const faceFeatures = { jaw: 0.5, lips: 1, cheek: 1, mouthW: 1, brow: 1, socket: 1, hollow: 0, chin: 1, nose: 1, bridge: 0, ...features };
70
95
  const age = faceFeatures.age || 0,
@@ -125,14 +150,16 @@ function headFn(features = {}, fine = false) {
125
150
  lidR = ballR + 1.3,
126
151
  innerX = eyeX - 14.5,
127
152
  outerX = eyeX + 14,
128
- one = !!faceFeatures.oneEye, // the two eyes healed over, and one in the middle of the brow
153
+ one = !!faceFeatures.oneEye, // one eye in the middle of the brow, the two sockets closed over (ONE_EYE)
154
+ oneEye = typeof faceFeatures.oneEye === 'object' ? { ...ONE_EYE, ...faceFeatures.oneEye } : ONE_EYE,
155
+ noseHole = faceFeatures.noseHole ? { ...NOSE_HOLE, ...faceFeatures.noseHole } : NOSE_HOLE,
129
156
  opening = one ? 0 : (faceFeatures.eye ?? 1),
130
157
  tilt = faceFeatures.tilt ?? 0;
131
158
  slice(eyeY, Math.asin(eyeX / width(eyeY)) * 0.93, _slice);
132
159
  const eyeZ = _slice.z - 14.4 - (faceFeatures.deep ?? 0);
133
- slice(ONE_EYE.y, 0, _slice);
134
- const oneZ = _slice.z + ONE_EYE.out - ONE_EYE.r, // where the middle of the one eye's ball is
135
- oneLid = ONE_EYE.r + 1.3;
160
+ slice(oneEye.y, 0, _slice);
161
+ const oneZ = _slice.z + oneEye.out - oneEye.r, // where the middle of the one eye's ball is
162
+ oneLid = oneEye.r + 1.3;
136
163
  const corner = t => eyeY - 1.9 + (1.5 + 1.6 * tilt) * t,
137
164
  upperLid = t => corner(t) + 5.4 * opening * Math.pow(4 * Math.pow(t, 0.85) * (1 - Math.pow(t, 0.85)), 0.72),
138
165
  lowerLid = t => corner(t) - 3.9 * opening * Math.pow(4 * Math.pow(t, 1.15) * (1 - Math.pow(t, 1.15)), 0.8);
@@ -288,15 +315,15 @@ function headFn(features = {}, fine = false) {
288
315
  if (one) {
289
316
  // the one eye: a ridge jutting over it and sloping away to the temples, the lids wrapped round the ball, and within
290
317
  // their opening the skin falls back behind the ball
291
- const dy = y - ONE_EYE.y,
292
- ridgeY = ONE_EYE.y + ONE_EYE.high + 5.5 - 0.006 * ax * ax,
318
+ const dy = y - oneEye.y,
319
+ ridgeY = oneEye.y + oneEye.high + 5.5 - 0.006 * ax * ax,
293
320
  ball = oneLid * oneLid - ax * ax - dy * dy,
294
- r = Math.hypot(ax / ONE_EYE.wide, dy / ONE_EYE.high);
295
- out += ONE_EYE.ridge * bump(y, ridgeY, y > ridgeY ? 7 : 3.6) * sstep(56, 36, ax);
321
+ r = Math.hypot(ax / oneEye.wide, dy / oneEye.high);
322
+ out += oneEye.ridge * bump(y, ridgeY, y > ridgeY ? 7 : 3.6) * sstep(56, 36, ax);
296
323
  if (ball > 0) out = smoothMax(out, oneZ + Math.sqrt(ball) - _slice.z, 1.6);
297
324
  shade -= 0.22 * bump(r, 1, 0.14) + 0.12 * bump(y, ridgeY - 5, 3) * sstep(30, 10, ax);
298
325
  if (r < 1) {
299
- const within = (1 - r) * ONE_EYE.high; // millimetres inside the lids' edge
326
+ const within = (1 - r) * oneEye.high; // millimetres inside the lids' edge
300
327
  out -= fine ? 1.4 * sstep(0, 0.4, within) + 10 * sstep(0.4, 2.2, within) : 0;
301
328
  shade = fine ? lerp(shade, 0.3, sstep(0, 0.6, within)) : shade * (1 - 0.8 * sstep(0, 1.2, within));
302
329
  }
@@ -327,7 +354,8 @@ function headFn(features = {}, fine = false) {
327
354
  // the nose: a ridge down the middle of the face to a rounded tip, wings beside it and the nostrils beneath
328
355
  const noseY = 12 + (y - 12) / noseLong;
329
356
  if (noseY < 17 && noseY > -52) {
330
- const reach = NOSE_OUT(noseY) * (1 + (faceFeatures.nose - 1) * sstep(8, -6, noseY)) + 2.2 * faceFeatures.bridge * bump(noseY, -8, 11),
357
+ const reach =
358
+ NOSE_OUT(noseY) * (1 + (faceFeatures.nose - 1) * sstep(8, -6, noseY)) + 2.2 * faceFeatures.bridge * bump(noseY, -8, 11),
331
359
  t = ax / (NOSE_WIDE(noseY) * (1 + (noseWide - 1) * sstep(-5, -35, noseY))),
332
360
  tip = bump(noseY, -36, 7);
333
361
  const torn = 1 - Math.max(0.85 * raw, noseLost * sstep(-6, -16, noseY)); // what a wound has torn away of the nose
@@ -342,11 +370,11 @@ function headFn(features = {}, fine = false) {
342
370
  shade -= 0.2 * bump(ax, 0, 12) * bump(noseY, -49.6, 2.2) + 0.08 * bump(ax, alaX + 6 * noseWide, 1.6) * bump(noseY, -40, 5);
343
371
  if (noseLost > 0) {
344
372
  // the nose gone: the opening it covered, narrow under the bone and widening to its foot, sunk and dark within
345
- const { top, foot, wide } = NOSE_HOLE,
373
+ const { top, foot, wide } = noseHole,
346
374
  half = wide * (0.35 + 0.65 * sstep(top, foot + 6, noseY)) * noseWide,
347
375
  hole = noseLost * sstep(top + 2, top - 4, noseY) * sstep(foot - 2, foot + 3, noseY) * sstep(1, 0.55, ax / half);
348
- out -= hole * (faceFeatures.healed ? NOSE_HOLE.healedDeep : NOSE_HOLE.deep);
349
- shade *= 1 - hole * (faceFeatures.healed ? NOSE_HOLE.healedDark : NOSE_HOLE.dark);
376
+ out -= hole * (faceFeatures.healed ? noseHole.healedDeep : noseHole.deep);
377
+ shade *= 1 - hole * (faceFeatures.healed ? noseHole.healedDark : noseHole.dark);
350
378
  raw = Math.max(raw, hole); // coloured as the wound round it is, raw or scarred
351
379
  }
352
380
  warm += 0.5 * tip * bump(ax, 0, 13);
@@ -437,7 +465,7 @@ function headFn(features = {}, fine = false) {
437
465
  ch[4] = brow;
438
466
  ch[5] = moustache;
439
467
  ch[6] = tuft;
440
- ch[7] = scar || raw; // a head has an old scar or a fresh wound: the look says which (head.js colours it)
468
+ ch[7] = scar || raw; // a head has an old scar or a fresh wound: its features say which (`healed`), and the caller colours it
441
469
  }
442
470
  };
443
471
 
@@ -490,7 +518,7 @@ function headFn(features = {}, fine = false) {
490
518
  upper: t => upperLid(t) * MM,
491
519
  };
492
520
  sampleHead.mouth = { x: mouthX * MM, y: SEAM * MM };
493
- sampleHead.one = one ? { y: ONE_EYE.y * MM, z: oneZ * MM, r: ONE_EYE.r * MM, wide: ONE_EYE.wide * MM } : null; // the one eye's ball, if so
521
+ sampleHead.one = one ? { y: oneEye.y * MM, z: oneZ * MM, r: oneEye.r * MM, wide: oneEye.wide * MM } : null; // the one eye's ball, if so
494
522
  sampleHead.browLine = x => browLine(x / MM) * MM;
495
523
  sampleHead.scar = (x, y) => (faceFeatures.scar ? scarAt(x / MM, y / MM)[1] : 0); // how much of a scar there is at a point (metres)
496
524
  return sampleHead;
@@ -18,12 +18,13 @@ export function heightfieldSampler(geometry, outside) {
18
18
  const depth = positions.getZ(rows * (columns + 1)) - z0;
19
19
  if (!(width > 0 && depth > 0)) throw new RangeError('Expected a regular heightfield in the X/Z plane');
20
20
  return (x, z) => {
21
- const gridX = (x - x0) / width * columns;
22
- const gridZ = (z - z0) / depth * rows;
21
+ const gridX = ((x - x0) / width) * columns;
22
+ const gridZ = ((z - z0) / depth) * rows;
23
23
  if (gridX < 0 || gridZ < 0 || gridX > columns || gridZ > rows) return outside?.(x, z);
24
24
  const col = Math.min(Math.floor(gridX), columns - 1);
25
25
  const row = Math.min(Math.floor(gridZ), rows - 1);
26
- const columnFraction = gridX - col, rowFraction = gridZ - row;
26
+ const columnFraction = gridX - col,
27
+ rowFraction = gridZ - row;
27
28
  const cornerIndex = row * (columns + 1) + col;
28
29
  const farLeft = positions.getY(cornerIndex + columns + 1);
29
30
  const nearRight = positions.getY(cornerIndex + 1);
@@ -40,13 +41,23 @@ export function heightfieldSampler(geometry, outside) {
40
41
  // attributes with the supplied height function and returns its geometry. Call during construction.
41
42
  export function refineHeightfield(base, { x, z, cells, subdivisions, height, createPatch }) {
42
43
  const { widthSegments: columns, heightSegments: rows } = base.parameters;
43
- if (!(Number.isInteger(cells) && cells > 0 && cells <= Math.min(columns, rows) &&
44
- Number.isInteger(subdivisions) && subdivisions >= 2 && Number.isFinite(x) && Number.isFinite(z))) {
44
+ if (
45
+ !(
46
+ Number.isInteger(cells) &&
47
+ cells > 0 &&
48
+ cells <= Math.min(columns, rows) &&
49
+ Number.isInteger(subdivisions) &&
50
+ subdivisions >= 2 &&
51
+ Number.isFinite(x) &&
52
+ Number.isFinite(z)
53
+ )
54
+ ) {
45
55
  throw new RangeError('Invalid heightfield patch dimensions or position');
46
56
  }
47
57
  if (!base.index || base.index.count !== rows * columns * 6) throw new TypeError('Expected an indexed PlaneGeometry');
48
58
  const positions = base.getAttribute('position');
49
- const x0 = positions.getX(0), z0 = positions.getZ(0);
59
+ const x0 = positions.getX(0),
60
+ z0 = positions.getZ(0);
50
61
  const dx = (positions.getX(columns) - x0) / columns;
51
62
  const dz = (positions.getZ(rows * (columns + 1)) - z0) / rows;
52
63
  const col = Math.round((x - x0) / dx - cells / 2);
@@ -55,10 +66,16 @@ export function refineHeightfield(base, { x, z, cells, subdivisions, height, cre
55
66
  throw new RangeError('Heightfield patch extends past the base grid');
56
67
  }
57
68
  const coarse = heightfieldSampler(base, height);
58
- const cx = x0 + (col + cells / 2) * dx, cz = z0 + (row + cells / 2) * dz;
59
- const width = cells * dx, depth = cells * dz;
69
+ const cx = x0 + (col + cells / 2) * dx,
70
+ cz = z0 + (row + cells / 2) * dz;
71
+ const width = cells * dx,
72
+ depth = cells * dz;
60
73
  const patch = createPatch({
61
- x: cx, z: cz, width, depth, segments: cells * subdivisions,
74
+ x: cx,
75
+ z: cz,
76
+ width,
77
+ depth,
78
+ segments: cells * subdivisions,
62
79
  height(px, pz) {
63
80
  const weight = Math.min((width / 2 - Math.abs(px - cx)) / dx, (depth / 2 - Math.abs(pz - cz)) / dz);
64
81
  if (weight >= 1) return height(px, pz);
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Precomputes 8-azimuth terrain horizon elevation angles (by default out to 740 m) for km-scale low-sun mountain shadows.
3
+ * Pure math/geometry helper safe to run inside Web Workers with zero Three.js dependencies.
4
+ * @module
5
+ */
6
+
7
+ import { clamp } from '../math/scalar.js';
8
+
9
+ const MAX_HORIZON_RAD = Math.PI * 0.45;
10
+ const AZIMUTH_DIRS = Array.from({ length: 8 }, (_, k) => {
11
+ const angle = (k * Math.PI) / 4;
12
+ return [Math.cos(angle), Math.sin(angle)];
13
+ });
14
+
15
+ /**
16
+ * Sample distances for {@link bakeHorizonAngles}: `count` distances growing evenly by ratio from four grid spacings out to
17
+ * `reach`, so that a finer grid looks at nearer ground first and every grid sees as far.
18
+ *
19
+ * @param {number} spacing Metres between grid samples.
20
+ * @param {object} [options]
21
+ * @param {number} [options.reach=740] The farthest distance looked along, in metres.
22
+ * @param {number} [options.count=15] How many distances.
23
+ * @returns {number[]} Distances in metres, nearest first, rounded to a tenth of a metre.
24
+ */
25
+ export function horizonSteps(spacing, { reach = 740, count = 15 } = {}) {
26
+ const first = Math.min(4 * spacing, reach),
27
+ ratio = count > 1 ? (reach / first) ** (1 / (count - 1)) : 1;
28
+ return Array.from({ length: count }, (_, i) => Math.round(first * ratio ** i * 10) / 10);
29
+ }
30
+
31
+ /**
32
+ * Bakes 8-azimuth horizon elevation angles on a heightfield grid into a compact `Uint8Array(stride * rows * 8)`.
33
+ * Channels 3 and 7 (`.w` of `aHorizon0` and `aHorizon1`) are stored inverted (`255 - byte`) so any secondary
34
+ * mesh lacking those attributes receives WebGL's default `(0, 0, 0, 1)`, decoding to `0` (`0 rad` flat horizon).
35
+ *
36
+ * @param {Float32Array} heights Row-major heightfield (`stride * rows`).
37
+ * @param {number} stride Columns per row.
38
+ * @param {number} rows Number of rows.
39
+ * @param {number} spacing Metres between grid samples.
40
+ * @param {object} [options]
41
+ * @param {number[]} [options.steps] Sample distances in metres along each azimuth; by default {@link horizonSteps} of the spacing.
42
+ * @param {number} [options.coarse=2] Coarse grid stride (`1` full grid, `2` half-grid bilinearly upsampled for fast worker bakes).
43
+ * @returns {Uint8Array} Packed 8-byte-per-vertex horizon buffer.
44
+ */
45
+ export function bakeHorizonAngles(heights, stride, rows, spacing, { steps = horizonSteps(spacing), coarse = 2 } = {}) {
46
+ const stepStride = Math.max(1, coarse | 0),
47
+ cw = Math.floor((stride - 1) / stepStride) + 1,
48
+ ch = Math.floor((rows - 1) / stepStride) + 1,
49
+ invSpacing = 1 / spacing,
50
+ maxCol = stride - 1,
51
+ maxRow = rows - 1,
52
+ stepCount = steps.length,
53
+ gridSteps = new Float32Array(stepCount),
54
+ invDists = new Float32Array(stepCount);
55
+
56
+ for (let s = 0; s < stepCount; s++) {
57
+ gridSteps[s] = steps[s] * invSpacing;
58
+ invDists[s] = 1 / Math.max(steps[s], 0.5);
59
+ }
60
+
61
+ const coarseAngles = new Float32Array(cw * ch * 8);
62
+
63
+ for (let cj = 0; cj < ch; cj++) {
64
+ const j = Math.min(cj * stepStride, maxRow),
65
+ rowOffset = j * stride;
66
+ for (let ci = 0; ci < cw; ci++) {
67
+ const i = Math.min(ci * stepStride, maxCol),
68
+ h0 = heights[rowOffset + i],
69
+ dst = (cj * cw + ci) * 8;
70
+ for (let dirIdx = 0; dirIdx < 8; dirIdx++) {
71
+ const dx = AZIMUTH_DIRS[dirIdx][0],
72
+ dz = AZIMUTH_DIRS[dirIdx][1];
73
+ let maxRise = 0;
74
+ for (let s = 0; s < stepCount; s++) {
75
+ const gDist = gridSteps[s],
76
+ fx = i + dx * gDist,
77
+ fz = j + dz * gDist;
78
+ if (fx < 0 || fx > maxCol || fz < 0 || fz > maxRow) break;
79
+ const ix = fx | 0,
80
+ iz = fz | 0,
81
+ ix1 = ix < maxCol ? ix + 1 : ix,
82
+ iz1 = iz < maxRow ? iz + 1 : iz,
83
+ tx = fx - ix,
84
+ tz = fz - iz,
85
+ r0 = iz * stride,
86
+ r1 = iz1 * stride,
87
+ h00 = heights[r0 + ix],
88
+ h10 = heights[r0 + ix1],
89
+ h01 = heights[r1 + ix],
90
+ h11 = heights[r1 + ix1],
91
+ hSample = (h00 + (h10 - h00) * tx) * (1 - tz) + (h01 + (h11 - h01) * tx) * tz,
92
+ rise = (hSample - h0) * invDists[s];
93
+ if (rise > maxRise) maxRise = rise;
94
+ }
95
+ coarseAngles[dst + dirIdx] = maxRise > 0 ? clamp(Math.atan(maxRise) / MAX_HORIZON_RAD, 0, 1) : 0;
96
+ }
97
+ }
98
+ }
99
+
100
+ const out = new Uint8Array(stride * rows * 8);
101
+ const maxCi = cw - 1,
102
+ maxCj = ch - 1;
103
+
104
+ for (let j = 0; j < rows; j++) {
105
+ const fy = j / stepStride,
106
+ cj0 = Math.min(fy | 0, maxCj),
107
+ cj1 = Math.min(cj0 + 1, maxCj),
108
+ ty = clamp(fy - cj0, 0, 1);
109
+ for (let i = 0; i < stride; i++) {
110
+ const fx = i / stepStride,
111
+ ci0 = Math.min(fx | 0, maxCi),
112
+ ci1 = Math.min(ci0 + 1, maxCi),
113
+ tx = clamp(fx - ci0, 0, 1),
114
+ k00 = (cj0 * cw + ci0) * 8,
115
+ k10 = (cj0 * cw + ci1) * 8,
116
+ k01 = (cj1 * cw + ci0) * 8,
117
+ k11 = (cj1 * cw + ci1) * 8,
118
+ dst = (j * stride + i) * 8;
119
+ for (let d = 0; d < 8; d++) {
120
+ const v0 = coarseAngles[k00 + d] + (coarseAngles[k10 + d] - coarseAngles[k00 + d]) * tx,
121
+ v1 = coarseAngles[k01 + d] + (coarseAngles[k11 + d] - coarseAngles[k01 + d]) * tx,
122
+ byte = Math.round(clamp(v0 + (v1 - v0) * ty, 0, 1) * 255);
123
+ out[dst + d] = d === 3 || d === 7 ? 255 - byte : byte;
124
+ }
125
+ }
126
+ }
127
+
128
+ return out;
129
+ }
130
+
131
+ /** Vertex shader declarations for decoding 8-azimuth horizon shadows into `vHorizonSun`. */
132
+ export const HORIZON_SUN_VERTEX_PARS = `/* glsl */
133
+ attribute vec4 aHorizon0, aHorizon1;
134
+ uniform vec4 uHorizonLight;
135
+ varying float vHorizonSun;
136
+ float sampleHorizonSector(int idx, vec4 h0, vec4 h1) {
137
+ if (idx == 0) return h0.x;
138
+ if (idx == 1) return h0.y;
139
+ if (idx == 2) return h0.z;
140
+ if (idx == 3) return 1.0 - h0.w;
141
+ if (idx == 4) return h1.x;
142
+ if (idx == 5) return h1.y;
143
+ if (idx == 6) return h1.z;
144
+ return 1.0 - h1.w;
145
+ }
146
+ float computeHorizonSun(vec4 h0, vec4 h1, vec4 light) {
147
+ if (light.w <= 0.001) return 1.0;
148
+ float az = atan(light.z, light.x);
149
+ float sector = mod(az * 1.27323954 + 8.0, 8.0);
150
+ int s0 = int(floor(sector));
151
+ int s1 = (s0 + 1) % 8;
152
+ float frac = sector - float(s0);
153
+ float horizonElev = mix(sampleHorizonSector(s0, h0, h1), sampleHorizonSector(s1, h0, h1), frac) * ${MAX_HORIZON_RAD.toFixed(5)};
154
+ float sunElev = asin(clamp(light.y, -1.0, 1.0));
155
+ float vis = smoothstep(horizonElev - 0.022, horizonElev + 0.026, sunElev);
156
+ return mix(1.0, vis, light.w);
157
+ }
158
+ `;
159
+
160
+ export const HORIZON_SUN_VERTEX = `/* glsl */
161
+ vHorizonSun = computeHorizonSun(aHorizon0, aHorizon1, uHorizonLight);
162
+ `;
163
+
164
+ export const HORIZON_SUN_FRAGMENT_PARS = `/* glsl */
165
+ varying float vHorizonSun;
166
+ `;