webgpu-trees 0.0.0-stage → 0.1.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 (322) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1541 -2
  3. package/assets/SOURCES.md +255 -0
  4. package/assets/bark/alder.albedo.avif +0 -0
  5. package/assets/bark/alder.normal.avif +0 -0
  6. package/assets/bark/aleppoPine.albedo.avif +0 -0
  7. package/assets/bark/aleppoPine.normal.avif +0 -0
  8. package/assets/bark/ash.albedo.avif +0 -0
  9. package/assets/bark/ash.normal.avif +0 -0
  10. package/assets/bark/aspen.albedo.avif +0 -0
  11. package/assets/bark/aspen.normal.avif +0 -0
  12. package/assets/bark/beech.albedo.avif +0 -0
  13. package/assets/bark/beech.normal.avif +0 -0
  14. package/assets/bark/birch.albedo.avif +0 -0
  15. package/assets/bark/birch.normal.avif +0 -0
  16. package/assets/bark/birchFoot.albedo.avif +0 -0
  17. package/assets/bark/birchFoot.normal.avif +0 -0
  18. package/assets/bark/corsicanPine.albedo.avif +0 -0
  19. package/assets/bark/corsicanPine.normal.avif +0 -0
  20. package/assets/bark/cypress.albedo.avif +0 -0
  21. package/assets/bark/cypress.normal.avif +0 -0
  22. package/assets/bark/douglas.albedo.avif +0 -0
  23. package/assets/bark/douglas.normal.avif +0 -0
  24. package/assets/bark/eucalyptus.albedo.avif +0 -0
  25. package/assets/bark/eucalyptus.normal.avif +0 -0
  26. package/assets/bark/eucalyptusUpper.albedo.avif +0 -0
  27. package/assets/bark/eucalyptusUpper.normal.avif +0 -0
  28. package/assets/bark/fibrous.albedo.avif +0 -0
  29. package/assets/bark/fibrous.normal.avif +0 -0
  30. package/assets/bark/hemlock.albedo.avif +0 -0
  31. package/assets/bark/hemlock.normal.avif +0 -0
  32. package/assets/bark/hornbeam.albedo.avif +0 -0
  33. package/assets/bark/hornbeam.normal.avif +0 -0
  34. package/assets/bark/larch.albedo.avif +0 -0
  35. package/assets/bark/larch.normal.avif +0 -0
  36. package/assets/bark/lime.albedo.avif +0 -0
  37. package/assets/bark/lime.normal.avif +0 -0
  38. package/assets/bark/liveOak.albedo.avif +0 -0
  39. package/assets/bark/liveOak.normal.avif +0 -0
  40. package/assets/bark/maple.albedo.avif +0 -0
  41. package/assets/bark/maple.normal.avif +0 -0
  42. package/assets/bark/montereyPine.albedo.avif +0 -0
  43. package/assets/bark/montereyPine.normal.avif +0 -0
  44. package/assets/bark/norMaple.albedo.avif +0 -0
  45. package/assets/bark/norMaple.normal.avif +0 -0
  46. package/assets/bark/oak.albedo.avif +0 -0
  47. package/assets/bark/oak.normal.avif +0 -0
  48. package/assets/bark/palmLattice.albedo.avif +0 -0
  49. package/assets/bark/palmLattice.normal.avif +0 -0
  50. package/assets/bark/palmPineapple.albedo.avif +0 -0
  51. package/assets/bark/palmPineapple.normal.avif +0 -0
  52. package/assets/bark/palmRings.albedo.avif +0 -0
  53. package/assets/bark/palmRings.normal.avif +0 -0
  54. package/assets/bark/pine.albedo.avif +0 -0
  55. package/assets/bark/pine.normal.avif +0 -0
  56. package/assets/bark/pineFlakes.albedo.avif +0 -0
  57. package/assets/bark/pineFlakes.normal.avif +0 -0
  58. package/assets/bark/plane.albedo.avif +0 -0
  59. package/assets/bark/plane.normal.avif +0 -0
  60. package/assets/bark/poplar.albedo.avif +0 -0
  61. package/assets/bark/poplar.normal.avif +0 -0
  62. package/assets/bark/redAlder.albedo.avif +0 -0
  63. package/assets/bark/redAlder.normal.avif +0 -0
  64. package/assets/bark/redOak.albedo.avif +0 -0
  65. package/assets/bark/redOak.normal.avif +0 -0
  66. package/assets/bark/ridged.albedo.avif +0 -0
  67. package/assets/bark/ridged.normal.avif +0 -0
  68. package/assets/bark/sitkaSpruce.albedo.avif +0 -0
  69. package/assets/bark/sitkaSpruce.normal.avif +0 -0
  70. package/assets/bark/spruce.albedo.avif +0 -0
  71. package/assets/bark/spruce.normal.avif +0 -0
  72. package/assets/bark/stonePine.albedo.avif +0 -0
  73. package/assets/bark/stonePine.normal.avif +0 -0
  74. package/assets/bark/sycMaple.albedo.avif +0 -0
  75. package/assets/bark/sycMaple.normal.avif +0 -0
  76. package/assets/bark/torreyPine.albedo.avif +0 -0
  77. package/assets/bark/torreyPine.normal.avif +0 -0
  78. package/assets/bark/whitePine.albedo.avif +0 -0
  79. package/assets/bark/whitePine.normal.avif +0 -0
  80. package/assets/bark/whiteSpruce.albedo.avif +0 -0
  81. package/assets/bark/whiteSpruce.normal.avif +0 -0
  82. package/assets/bark/whiteWillow.albedo.avif +0 -0
  83. package/assets/bark/whiteWillow.normal.avif +0 -0
  84. package/assets/bark/willow.albedo.avif +0 -0
  85. package/assets/bark/willow.normal.avif +0 -0
  86. package/assets/leaves/alder.albedo.avif +0 -0
  87. package/assets/leaves/alder.normal.avif +0 -0
  88. package/assets/leaves/ash.albedo.avif +0 -0
  89. package/assets/leaves/ash.normal.avif +0 -0
  90. package/assets/leaves/aspen.albedo.avif +0 -0
  91. package/assets/leaves/aspen.normal.avif +0 -0
  92. package/assets/leaves/beech.albedo.avif +0 -0
  93. package/assets/leaves/beech.normal.avif +0 -0
  94. package/assets/leaves/birch.albedo.avif +0 -0
  95. package/assets/leaves/birch.normal.avif +0 -0
  96. package/assets/leaves/blackthorn.albedo.avif +0 -0
  97. package/assets/leaves/blackthorn.normal.avif +0 -0
  98. package/assets/leaves/blade.albedo.avif +0 -0
  99. package/assets/leaves/blade.normal.avif +0 -0
  100. package/assets/leaves/broomSprig.albedo.avif +0 -0
  101. package/assets/leaves/broomSprig.normal.avif +0 -0
  102. package/assets/leaves/corsicanShoot.albedo.avif +0 -0
  103. package/assets/leaves/corsicanShoot.normal.avif +0 -0
  104. package/assets/leaves/cypress.albedo.avif +0 -0
  105. package/assets/leaves/cypress.normal.avif +0 -0
  106. package/assets/leaves/cypressPad.albedo.avif +0 -0
  107. package/assets/leaves/cypressPad.normal.avif +0 -0
  108. package/assets/leaves/deadFronds.albedo.avif +0 -0
  109. package/assets/leaves/deadFronds.normal.avif +0 -0
  110. package/assets/leaves/deltoid.albedo.avif +0 -0
  111. package/assets/leaves/deltoid.normal.avif +0 -0
  112. package/assets/leaves/douglasShoot.albedo.avif +0 -0
  113. package/assets/leaves/douglasShoot.normal.avif +0 -0
  114. package/assets/leaves/elderSprig.albedo.avif +0 -0
  115. package/assets/leaves/elderSprig.normal.avif +0 -0
  116. package/assets/leaves/elliptic.albedo.avif +0 -0
  117. package/assets/leaves/elliptic.normal.avif +0 -0
  118. package/assets/leaves/eucalyptus.albedo.avif +0 -0
  119. package/assets/leaves/eucalyptus.normal.avif +0 -0
  120. package/assets/leaves/fan.albedo.avif +0 -0
  121. package/assets/leaves/fan.normal.avif +0 -0
  122. package/assets/leaves/fanB.albedo.avif +0 -0
  123. package/assets/leaves/fanB.normal.avif +0 -0
  124. package/assets/leaves/fir.albedo.avif +0 -0
  125. package/assets/leaves/fir.normal.avif +0 -0
  126. package/assets/leaves/frond.albedo.avif +0 -0
  127. package/assets/leaves/frond.normal.avif +0 -0
  128. package/assets/leaves/gorse.albedo.avif +0 -0
  129. package/assets/leaves/gorse.normal.avif +0 -0
  130. package/assets/leaves/hawthorn.albedo.avif +0 -0
  131. package/assets/leaves/hawthorn.normal.avif +0 -0
  132. package/assets/leaves/hemlockShoot.albedo.avif +0 -0
  133. package/assets/leaves/hemlockShoot.normal.avif +0 -0
  134. package/assets/leaves/hornbeam.albedo.avif +0 -0
  135. package/assets/leaves/hornbeam.normal.avif +0 -0
  136. package/assets/leaves/lance.albedo.avif +0 -0
  137. package/assets/leaves/lance.normal.avif +0 -0
  138. package/assets/leaves/larchShoot.albedo.avif +0 -0
  139. package/assets/leaves/larchShoot.normal.avif +0 -0
  140. package/assets/leaves/lime.albedo.avif +0 -0
  141. package/assets/leaves/lime.normal.avif +0 -0
  142. package/assets/leaves/liveOak.albedo.avif +0 -0
  143. package/assets/leaves/liveOak.normal.avif +0 -0
  144. package/assets/leaves/londonPlane.albedo.avif +0 -0
  145. package/assets/leaves/londonPlane.normal.avif +0 -0
  146. package/assets/leaves/maple.albedo.avif +0 -0
  147. package/assets/leaves/maple.normal.avif +0 -0
  148. package/assets/leaves/norMaple.albedo.avif +0 -0
  149. package/assets/leaves/norMaple.normal.avif +0 -0
  150. package/assets/leaves/oak.albedo.avif +0 -0
  151. package/assets/leaves/oak.normal.avif +0 -0
  152. package/assets/leaves/paintFan.albedo.avif +0 -0
  153. package/assets/leaves/paintFan.normal.avif +0 -0
  154. package/assets/leaves/paintFrond.albedo.avif +0 -0
  155. package/assets/leaves/paintFrond.normal.avif +0 -0
  156. package/assets/leaves/pine.albedo.avif +0 -0
  157. package/assets/leaves/pine.normal.avif +0 -0
  158. package/assets/leaves/pineClumpDark.albedo.avif +0 -0
  159. package/assets/leaves/pineClumpDark.normal.avif +0 -0
  160. package/assets/leaves/pineClumpLight.albedo.avif +0 -0
  161. package/assets/leaves/pineClumpLight.normal.avif +0 -0
  162. package/assets/leaves/poplar.albedo.avif +0 -0
  163. package/assets/leaves/poplar.normal.avif +0 -0
  164. package/assets/leaves/queenFrond.albedo.avif +0 -0
  165. package/assets/leaves/queenFrond.normal.avif +0 -0
  166. package/assets/leaves/redAlder.albedo.avif +0 -0
  167. package/assets/leaves/redAlder.normal.avif +0 -0
  168. package/assets/leaves/redOak.albedo.avif +0 -0
  169. package/assets/leaves/redOak.normal.avif +0 -0
  170. package/assets/leaves/round.albedo.avif +0 -0
  171. package/assets/leaves/round.normal.avif +0 -0
  172. package/assets/leaves/scale.albedo.avif +0 -0
  173. package/assets/leaves/scale.normal.avif +0 -0
  174. package/assets/leaves/scotsPineClump.albedo.avif +0 -0
  175. package/assets/leaves/scotsPineClump.normal.avif +0 -0
  176. package/assets/leaves/seaBuckthornSprig.albedo.avif +0 -0
  177. package/assets/leaves/seaBuckthornSprig.normal.avif +0 -0
  178. package/assets/leaves/serrate.albedo.avif +0 -0
  179. package/assets/leaves/serrate.normal.avif +0 -0
  180. package/assets/leaves/sitkaShoot.albedo.avif +0 -0
  181. package/assets/leaves/sitkaShoot.normal.avif +0 -0
  182. package/assets/leaves/stonePineCanopy.albedo.avif +0 -0
  183. package/assets/leaves/stonePineCanopy.normal.avif +0 -0
  184. package/assets/leaves/stonePineCushion.albedo.avif +0 -0
  185. package/assets/leaves/stonePineCushion.normal.avif +0 -0
  186. package/assets/leaves/sycamore.albedo.avif +0 -0
  187. package/assets/leaves/sycamore.normal.avif +0 -0
  188. package/assets/leaves/torreyPine.albedo.avif +0 -0
  189. package/assets/leaves/torreyPine.normal.avif +0 -0
  190. package/assets/leaves/whitePine.albedo.avif +0 -0
  191. package/assets/leaves/whitePine.normal.avif +0 -0
  192. package/assets/leaves/whiteSpruceShoot.albedo.avif +0 -0
  193. package/assets/leaves/whiteSpruceShoot.normal.avif +0 -0
  194. package/assets/leaves/whiteWillow.albedo.avif +0 -0
  195. package/assets/leaves/whiteWillow.normal.avif +0 -0
  196. package/assets/leaves/willow.albedo.avif +0 -0
  197. package/assets/leaves/willow.normal.avif +0 -0
  198. package/assets/marks/marks.json +894 -0
  199. package/assets/marks/painterly.avif +0 -0
  200. package/assets/marks/sheets.avif +0 -0
  201. package/assets/scans.json +6066 -0
  202. package/lib/age.d.ts +36 -0
  203. package/lib/age.d.ts.map +1 -0
  204. package/lib/age.js +170 -0
  205. package/lib/age.js.map +1 -0
  206. package/lib/atmosphere.d.ts +64 -0
  207. package/lib/atmosphere.d.ts.map +1 -0
  208. package/lib/atmosphere.js +260 -0
  209. package/lib/atmosphere.js.map +1 -0
  210. package/lib/dabs.d.ts +4 -0
  211. package/lib/dabs.d.ts.map +1 -0
  212. package/lib/dabs.js +77 -0
  213. package/lib/dabs.js.map +1 -0
  214. package/lib/engine.d.ts +211 -0
  215. package/lib/engine.d.ts.map +1 -0
  216. package/lib/engine.js +3808 -0
  217. package/lib/engine.js.map +1 -0
  218. package/lib/genetics.d.ts +129 -0
  219. package/lib/genetics.d.ts.map +1 -0
  220. package/lib/genetics.js +721 -0
  221. package/lib/genetics.js.map +1 -0
  222. package/lib/geometry.d.ts +237 -0
  223. package/lib/geometry.d.ts.map +1 -0
  224. package/lib/geometry.js +1944 -0
  225. package/lib/geometry.js.map +1 -0
  226. package/lib/grow.d.ts +83 -0
  227. package/lib/grow.d.ts.map +1 -0
  228. package/lib/grow.js +3851 -0
  229. package/lib/grow.js.map +1 -0
  230. package/lib/hiz.d.ts +74 -0
  231. package/lib/hiz.d.ts.map +1 -0
  232. package/lib/hiz.js +161 -0
  233. package/lib/hiz.js.map +1 -0
  234. package/lib/impostor.d.ts +106 -0
  235. package/lib/impostor.d.ts.map +1 -0
  236. package/lib/impostor.js +450 -0
  237. package/lib/impostor.js.map +1 -0
  238. package/lib/index.d.ts +17 -0
  239. package/lib/index.d.ts.map +1 -0
  240. package/lib/index.js +16 -0
  241. package/lib/index.js.map +1 -0
  242. package/lib/leaves.d.ts +30 -0
  243. package/lib/leaves.d.ts.map +1 -0
  244. package/lib/leaves.js +829 -0
  245. package/lib/leaves.js.map +1 -0
  246. package/lib/light.d.ts +110 -0
  247. package/lib/light.d.ts.map +1 -0
  248. package/lib/light.js +430 -0
  249. package/lib/light.js.map +1 -0
  250. package/lib/lobes.d.ts +25 -0
  251. package/lib/lobes.d.ts.map +1 -0
  252. package/lib/lobes.js +151 -0
  253. package/lib/lobes.js.map +1 -0
  254. package/lib/marks.d.ts +63 -0
  255. package/lib/marks.d.ts.map +1 -0
  256. package/lib/marks.js +553 -0
  257. package/lib/marks.js.map +1 -0
  258. package/lib/mips.d.ts +42 -0
  259. package/lib/mips.d.ts.map +1 -0
  260. package/lib/mips.js +220 -0
  261. package/lib/mips.js.map +1 -0
  262. package/lib/paintedMarks.d.ts +21 -0
  263. package/lib/paintedMarks.d.ts.map +1 -0
  264. package/lib/paintedMarks.js +53 -0
  265. package/lib/paintedMarks.js.map +1 -0
  266. package/lib/palm.d.ts +162 -0
  267. package/lib/palm.d.ts.map +1 -0
  268. package/lib/palm.js +779 -0
  269. package/lib/palm.js.map +1 -0
  270. package/lib/palmAtlas.d.ts +79 -0
  271. package/lib/palmAtlas.d.ts.map +1 -0
  272. package/lib/palmAtlas.js +335 -0
  273. package/lib/palmAtlas.js.map +1 -0
  274. package/lib/palmGeometry.d.ts +41 -0
  275. package/lib/palmGeometry.d.ts.map +1 -0
  276. package/lib/palmGeometry.js +309 -0
  277. package/lib/palmGeometry.js.map +1 -0
  278. package/lib/phenology.d.ts +21 -0
  279. package/lib/phenology.d.ts.map +1 -0
  280. package/lib/phenology.js +164 -0
  281. package/lib/phenology.js.map +1 -0
  282. package/lib/random.d.ts +34 -0
  283. package/lib/random.d.ts.map +1 -0
  284. package/lib/random.js +92 -0
  285. package/lib/random.js.map +1 -0
  286. package/lib/scans.d.ts +232 -0
  287. package/lib/scans.d.ts.map +1 -0
  288. package/lib/scans.js +391 -0
  289. package/lib/scans.js.map +1 -0
  290. package/lib/scatter.d.ts +70 -0
  291. package/lib/scatter.d.ts.map +1 -0
  292. package/lib/scatter.js +186 -0
  293. package/lib/scatter.js.map +1 -0
  294. package/lib/species.d.ts +369 -0
  295. package/lib/species.d.ts.map +1 -0
  296. package/lib/species.js +2817 -0
  297. package/lib/species.js.map +1 -0
  298. package/lib/sprays.d.ts +112 -0
  299. package/lib/sprays.d.ts.map +1 -0
  300. package/lib/sprays.js +1137 -0
  301. package/lib/sprays.js.map +1 -0
  302. package/lib/stand.d.ts +52 -0
  303. package/lib/stand.d.ts.map +1 -0
  304. package/lib/stand.js +279 -0
  305. package/lib/stand.js.map +1 -0
  306. package/lib/styles.d.ts +135 -0
  307. package/lib/styles.d.ts.map +1 -0
  308. package/lib/styles.js +79 -0
  309. package/lib/styles.js.map +1 -0
  310. package/lib/tree.d.ts +134 -0
  311. package/lib/tree.d.ts.map +1 -0
  312. package/lib/tree.js +57 -0
  313. package/lib/tree.js.map +1 -0
  314. package/lib/variants.d.ts +157 -0
  315. package/lib/variants.d.ts.map +1 -0
  316. package/lib/variants.js +532 -0
  317. package/lib/variants.js.map +1 -0
  318. package/lib/visibility.d.ts +105 -0
  319. package/lib/visibility.d.ts.map +1 -0
  320. package/lib/visibility.js +242 -0
  321. package/lib/visibility.js.map +1 -0
  322. package/package.json +62 -3
package/lib/age.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { type TreeSpecies } from "./species.js";
2
+ import { type TreeSize } from "./tree.js";
3
+ /** A tree this share of its specimen's height or taller is grown as its specimen is ... */
4
+ export declare const AGE_OLD = 0.8;
5
+ /** ... and one this share of it or shorter as all young. */
6
+ export declare const AGE_YOUNG = 0.3;
7
+ /**
8
+ * How young a tree of this size is for its kind, 0 (its specimen's age or older) to 1 (a young tree): by its
9
+ * height or its crown's reach beside its specimen's, whichever is the more (a short tree with a crown as wide as
10
+ * its specimen's is an old one, cut back or on a windy headland, not a young one).
11
+ */
12
+ export declare function youthOf(sp: TreeSpecies, size: TreeSize): number;
13
+ /** How much narrower for its depth a crown is than its specimen's, 0 (as wide or wider) to 1 (a column). */
14
+ export declare function narrownessOf(sp: TreeSpecies, size: TreeSize): number;
15
+ /**
16
+ * A species' row as a tree of this size grows (see the head of this file): its own row for a tree as big as
17
+ * its specimen, and for a palm, a conifer or a shrub at any size; else a copy, what comes with age faded by how
18
+ * young it is, its flat top rounded by how narrow.
19
+ */
20
+ export declare function habitAt(sp: TreeSpecies, size: TreeSize): TreeSpecies;
21
+ export type LifeStageKey = "sapling" | "young" | "mid" | "mature";
22
+ export declare const LIFE_STAGE_KEYS: readonly LifeStageKey[];
23
+ export interface LifeStage {
24
+ key: LifeStageKey;
25
+ label: string;
26
+ heightFrac: number;
27
+ size: TreeSize;
28
+ /** Horizontal centre `x` (m) when the four stages stand left-to-right centred round x = 0. */
29
+ x: number;
30
+ }
31
+ /**
32
+ * Four representative life stages of a species from sapling to mature specimen, arranged left-to-right
33
+ * to true relative scale round `x = 0` without overlapping crowns.
34
+ */
35
+ export declare function lifeStageSizes(sp: TreeSpecies): LifeStage[];
36
+ //# sourceMappingURL=age.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"age.d.ts","sourceRoot":"","sources":["../src/age.ts"],"names":[],"mappings":"AA8BA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,2FAA2F;AAC3F,eAAO,MAAM,OAAO,MAAM,CAAC;AAC3B,4DAA4D;AAC5D,eAAO,MAAM,SAAS,MAAM,CAAC;AAa7B;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,CAI/D;AAED,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,CAIpE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,CA+BpE;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;AAClE,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAA0C,CAAC;AAE9F,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,YAAY,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,8FAA8F;IAC9F,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,WAAW,GAAG,SAAS,EAAE,CAyD3D"}
package/lib/age.js ADDED
@@ -0,0 +1,170 @@
1
+ // A tree's habit at its own size. A species' row is its specimen: a grown tree of its kind, old enough to
2
+ // show all it comes to (a stone pine's umbrella, a Scots pine's flat top and plates, a blue gum's hanging
3
+ // bunches on a forked bole, a Torrey pine's tufts on bare upcurved limbs). Most trees a survey hands over are
4
+ // smaller than that, and narrower: a course's are planted and young, or drawn up in a wood. Grown from the
5
+ // specimen's row at a fraction of its size, they came out as small copies of an old tree (a stone pine of
6
+ // 4 m an umbrella on a stick; one of 12 m on a crown half as wide as the specimen's a tower of stacked
7
+ // cushions), which is not what young trees of any of these kinds look like.
8
+ //
9
+ // So before it is grown, a broadleaf's row is taken as its own size grows it (`habitAt`):
10
+ //
11
+ // - How young it is, from its height or its crown's reach beside its specimen's, whichever is more: none at 0.8
12
+ // of it and over, all of it at 0.3 and under (`AGE_OLD`, `AGE_YOUNG`). What comes with age then fades with youth, as the trees' accounts in
13
+ // docs/MORPHOLOGY.md have it: crowns are rounded and full while young, their flat tops, umbrellas, plates
14
+ // and pads coming as they age (stone pine: "globose and shrubby when young, umbrella-shaped in mid-age and
15
+ // flat and broad in maturity", EU Atlas; Scots pine: "open ovoid-conic when young", old trees "broadly domed
16
+ // or even flat-topped" and forking into sub-leaders, GDB; Torrey pine: wild crowns rounded to irregular, its
17
+ // tufts at the ends of long bare limbs an old tree's; Aleppo pine "flattening and opening up with age"); a
18
+ // young tree keeps its leader (eucalyptus and birch "excurrent while young", Scots pine excurrent young,
19
+ // decurrent old), its trunk not yet forked into its old limbs, its underside not yet lifted bare; a
20
+ // blue gum's hanging bunches are its open adult crown's. (A weeping cultivar with `weep >= 0.7`, such as
21
+ // weeping willow, hangs from its first years so its whips are kept, whereas a silver birch's pendulous
22
+ // outer tresses come with age.)
23
+ // - How narrow it is for its depth beside its specimen: a flat top or an umbrella is a wide crown's (a crown as
24
+ // deep as it is wide is a dome, not a slab), so a flat-topped species' top rounds as its crown narrows, all
25
+ // the way to a dome at half its specimen's width for its depth.
26
+ //
27
+ // A tree at its specimen's size and proportions grows exactly as its row says. Palms, conifers grown whorl by
28
+ // whorl and shrubs are as their rows say at any size: a palm's head is its leaves, whatever its height, and a
29
+ // young spruce is the cone its row already is.
30
+ /** A tree this share of its specimen's height or taller is grown as its specimen is ... */
31
+ export const AGE_OLD = 0.8;
32
+ /** ... and one this share of it or shorter as all young. */
33
+ export const AGE_YOUNG = 0.3;
34
+ /** How far a young tree keeps its leader, of what its row leaves (0 none more, 1 all the way to one stem). */
35
+ const YOUNG_LEADER = 0.4;
36
+ /** How much of a row's pads a young tree is without, at youth 1, and of its bunches. */
37
+ const YOUNG_PADS = 0.3;
38
+ const YOUNG_CLUSTERS = 0.6;
39
+ /** Where a young crown is widest, as a share of the way up it: an ovoid's, rounded. */
40
+ const YOUNG_PEAK = 0.4;
41
+ /** How much of a flat top a crown loses for each share it is narrower than its specimen: all of it at half as wide. */
42
+ const NARROW_DOME = 2;
43
+ /** The roundness of a crown's top that is neither flat nor pointed: an ellipse's (Rautiainen's exponent 2). */
44
+ const ROUND = 2;
45
+ /**
46
+ * How young a tree of this size is for its kind, 0 (its specimen's age or older) to 1 (a young tree): by its
47
+ * height or its crown's reach beside its specimen's, whichever is the more (a short tree with a crown as wide as
48
+ * its specimen's is an old one, cut back or on a windy headland, not a young one).
49
+ */
50
+ export function youthOf(sp, size) {
51
+ const m = Math.max(size.height / Math.max(0.01, sp.height), size.crownRadius / Math.max(0.01, sp.crownRadius));
52
+ const t = Math.min(1, Math.max(0, (AGE_OLD - m) / (AGE_OLD - AGE_YOUNG)));
53
+ return t * t * (3 - 2 * t);
54
+ }
55
+ /** How much narrower for its depth a crown is than its specimen's, 0 (as wide or wider) to 1 (a column). */
56
+ export function narrownessOf(sp, size) {
57
+ const own = size.crownRadius / Math.max(0.01, size.height - size.crownBase);
58
+ const specimen = sp.crownRadius / Math.max(0.01, sp.height - sp.crownBase);
59
+ return Math.min(1, Math.max(0, 1 - own / Math.max(1e-3, specimen)));
60
+ }
61
+ /**
62
+ * A species' row as a tree of this size grows (see the head of this file): its own row for a tree as big as
63
+ * its specimen, and for a palm, a conifer or a shrub at any size; else a copy, what comes with age faded by how
64
+ * young it is, its flat top rounded by how narrow.
65
+ */
66
+ export function habitAt(sp, size) {
67
+ if (sp.architecture !== "broadleaf")
68
+ return sp;
69
+ const y = youthOf(sp, size);
70
+ const n = narrownessOf(sp, size);
71
+ if (y <= 0 && n <= 0)
72
+ return sp;
73
+ const out = { ...sp };
74
+ const fade = (v, k) => (v === undefined ? undefined : v * (1 - k));
75
+ // Its top: a flat or umbrella top (round over 2) is an old tree's and a wide crown's; young or narrow, rounded.
76
+ // (A crown half as wide for its depth as its specimen's is a dome: an umbrella's limbs have not spread yet.)
77
+ const flat = Math.min(1, Math.max(y, NARROW_DOME * n));
78
+ if (sp.crownRound !== undefined && sp.crownRound > ROUND)
79
+ out.crownRound = ROUND + (sp.crownRound - ROUND) * (1 - flat);
80
+ if (y > 0) {
81
+ // (Its pads and plates fewer: an old open tree's shelves. A narrow one keeps them: a sheltered Monterey cypress's
82
+ // pads are its kind's.)
83
+ out.pads = fade(sp.pads, YOUNG_PADS * y);
84
+ if (sp.crownPeak !== undefined)
85
+ out.crownPeak = sp.crownPeak + (YOUNG_PEAK - sp.crownPeak) * 0.5 * y;
86
+ out.leader = sp.leader + (1 - sp.leader) * YOUNG_LEADER * y;
87
+ // (Its old limbs not yet grown: a forked trunk, a stone pine's V-forks, are an older tree's.)
88
+ if (sp.fork !== undefined || sp.forkShare !== undefined)
89
+ out.forkShare = (sp.forkShare ?? (sp.fork !== undefined && sp.forkStems !== undefined ? 1 : 0)) * (1 - y);
90
+ out.canopyLift = fade(sp.canopyLift, y);
91
+ out.clusters = fade(sp.clusters, YOUNG_CLUSTERS * y);
92
+ out.lean = fade(sp.lean, 0.8 * y);
93
+ if ((sp.weep ?? 0) > 0 && (sp.weep ?? 0) < 0.7) {
94
+ out.weep = fade(sp.weep, y);
95
+ if (sp.bend < 0)
96
+ out.bend = sp.bend * (1 - 0.8 * y);
97
+ if ((sp.limbCurveBack ?? 0) < 0)
98
+ out.limbCurveBack = sp.limbCurveBack * (1 - 0.8 * y);
99
+ }
100
+ }
101
+ // (Fields left out stay left out: a copy with `undefined` written in is the same row to the grower.)
102
+ for (const k of Object.keys(out))
103
+ if (out[k] === undefined)
104
+ delete out[k];
105
+ return out;
106
+ }
107
+ export const LIFE_STAGE_KEYS = ["sapling", "young", "mid", "mature"];
108
+ /**
109
+ * Four representative life stages of a species from sapling to mature specimen, arranged left-to-right
110
+ * to true relative scale round `x = 0` without overlapping crowns.
111
+ */
112
+ export function lifeStageSizes(sp) {
113
+ const { height: H, crownRadius: R, crownBase: B, trunkRadius: T } = sp;
114
+ const palm = sp.architecture === "palm";
115
+ const tree = sp.architecture === "broadleaf" || sp.architecture === "conifer";
116
+ const h0 = Math.max(0.7, 0.18 * H);
117
+ const h1 = Math.max(1.1, 0.38 * H);
118
+ const h2 = Math.max(1.5, 0.68 * H);
119
+ const raw = [
120
+ {
121
+ key: "sapling",
122
+ label: "Sapling",
123
+ heightFrac: 0.18,
124
+ size: {
125
+ height: h0,
126
+ crownRadius: palm ? Math.max(0.45, 0.55 * R) : tree ? Math.max(0.28, Math.min(0.14 * R, 0.28 * h0)) : Math.max(0.28, 0.14 * R),
127
+ crownBase: palm ? Math.min(0.25 * h0, 0.08 * B) : tree ? Math.min(0.22 * h0, 0.35 * B) : Math.min(0.3 * h0, 0.12 * B),
128
+ trunkRadius: Math.max(0.012, T * 0.18 ** (tree ? 1.55 : 1.25)),
129
+ },
130
+ },
131
+ {
132
+ key: "young",
133
+ label: "Young",
134
+ heightFrac: 0.38,
135
+ size: {
136
+ height: h1,
137
+ crownRadius: palm ? Math.max(0.65, 0.78 * R) : tree ? Math.max(0.45, Math.min(0.32 * R, 0.34 * h1)) : Math.max(0.45, 0.32 * R),
138
+ crownBase: tree ? Math.min(0.24 * h1, 0.65 * B) : Math.min(0.6 * h1, B * 0.32),
139
+ trunkRadius: Math.max(0.02, T * 0.38 ** (tree ? 1.45 : 1.2)),
140
+ },
141
+ },
142
+ {
143
+ key: "mid",
144
+ label: "Mid-age",
145
+ heightFrac: 0.68,
146
+ size: {
147
+ height: h2,
148
+ crownRadius: palm ? 0.92 * R : tree ? Math.max(0.65, Math.min(0.64 * R, 0.48 * h2)) : 0.64 * R,
149
+ crownBase: tree ? Math.min(0.24 * h2, 0.85 * B) : Math.min(0.8 * h2, B * 0.66),
150
+ trunkRadius: Math.max(0.025, T * 0.68 ** (tree ? 1.25 : 1.15)),
151
+ },
152
+ },
153
+ {
154
+ key: "mature",
155
+ label: "Mature",
156
+ heightFrac: 1,
157
+ size: { height: H, crownRadius: R, crownBase: B, trunkRadius: T },
158
+ },
159
+ ];
160
+ const gap = Math.max(1.2, 0.35 * R);
161
+ const xs = [0];
162
+ for (let i = 1; i < raw.length; i++) {
163
+ xs.push(xs[i - 1] + raw[i - 1].size.crownRadius + gap + raw[i].size.crownRadius);
164
+ }
165
+ const left = xs[0] - raw[0].size.crownRadius;
166
+ const right = xs[raw.length - 1] + raw[raw.length - 1].size.crownRadius;
167
+ const midX = 0.5 * (left + right);
168
+ return raw.map((st, i) => ({ ...st, x: xs[i] - midX }));
169
+ }
170
+ //# sourceMappingURL=age.js.map
package/lib/age.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"age.js","sourceRoot":"","sources":["../src/age.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,0GAA0G;AAC1G,8GAA8G;AAC9G,2GAA2G;AAC3G,0GAA0G;AAC1G,uGAAuG;AACvG,4EAA4E;AAC5E,EAAE;AACF,0FAA0F;AAC1F,EAAE;AACF,gHAAgH;AAChH,8IAA8I;AAC9I,4GAA4G;AAC5G,6GAA6G;AAC7G,+GAA+G;AAC/G,+GAA+G;AAC/G,6GAA6G;AAC7G,2GAA2G;AAC3G,sGAAsG;AACtG,2GAA2G;AAC3G,yGAAyG;AACzG,kCAAkC;AAClC,gHAAgH;AAChH,8GAA8G;AAC9G,kEAAkE;AAClE,EAAE;AACF,8GAA8G;AAC9G,8GAA8G;AAC9G,+CAA+C;AAK/C,2FAA2F;AAC3F,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAC3B,4DAA4D;AAC5D,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B,8GAA8G;AA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","sourcesContent":["// A tree's habit at its own size. A species' row is its specimen: a grown tree of its kind, old enough to\n// show all it comes to (a stone pine's umbrella, a Scots pine's flat top and plates, a blue gum's hanging\n// bunches on a forked bole, a Torrey pine's tufts on bare upcurved limbs). Most trees a survey hands over are\n// smaller than that, and narrower: a course's are planted and young, or drawn up in a wood. Grown from the\n// specimen's row at a fraction of its size, they came out as small copies of an old tree (a stone pine of\n// 4 m an umbrella on a stick; one of 12 m on a crown half as wide as the specimen's a tower of stacked\n// cushions), which is not what young trees of any of these kinds look like.\n//\n// So before it is grown, a broadleaf's row is taken as its own size grows it (`habitAt`):\n//\n// - How young it is, from its height or its crown's reach beside its specimen's, whichever is more: none at 0.8\n// of it and over, all of it at 0.3 and under (`AGE_OLD`, `AGE_YOUNG`). What comes with age then fades with youth, as the trees' accounts in\n// docs/MORPHOLOGY.md have it: crowns are rounded and full while young, their flat tops, umbrellas, plates\n// and pads coming as they age (stone pine: \"globose and shrubby when young, umbrella-shaped in mid-age and\n// flat and broad in maturity\", EU Atlas; Scots pine: \"open ovoid-conic when young\", old trees \"broadly domed\n// or even flat-topped\" and forking into sub-leaders, GDB; Torrey pine: wild crowns rounded to irregular, its\n// tufts at the ends of long bare limbs an old tree's; Aleppo pine \"flattening and opening up with age\"); a\n// young tree keeps its leader (eucalyptus and birch \"excurrent while young\", Scots pine excurrent young,\n// decurrent old), its trunk not yet forked into its old limbs, its underside not yet lifted bare; a\n// blue gum's hanging bunches are its open adult crown's. (A weeping cultivar with `weep >= 0.7`, such as\n// weeping willow, hangs from its first years so its whips are kept, whereas a silver birch's pendulous\n// outer tresses come with age.)\n// - How narrow it is for its depth beside its specimen: a flat top or an umbrella is a wide crown's (a crown as\n// deep as it is wide is a dome, not a slab), so a flat-topped species' top rounds as its crown narrows, all\n// the way to a dome at half its specimen's width for its depth.\n//\n// A tree at its specimen's size and proportions grows exactly as its row says. Palms, conifers grown whorl by\n// whorl and shrubs are as their rows say at any size: a palm's head is its leaves, whatever its height, and a\n// young spruce is the cone its row already is.\n\nimport { type TreeSpecies } from \"./species.ts\";\nimport { type TreeSize } from \"./tree.ts\";\n\n/** A tree this share of its specimen's height or taller is grown as its specimen is ... */\nexport const AGE_OLD = 0.8;\n/** ... and one this share of it or shorter as all young. */\nexport const AGE_YOUNG = 0.3;\n/** How far a young tree keeps its leader, of what its row leaves (0 none more, 1 all the way to one stem). */\nconst YOUNG_LEADER = 0.4;\n/** How much of a row's pads a young tree is without, at youth 1, and of its bunches. */\nconst YOUNG_PADS = 0.3;\nconst YOUNG_CLUSTERS = 0.6;\n/** Where a young crown is widest, as a share of the way up it: an ovoid's, rounded. */\nconst YOUNG_PEAK = 0.4;\n/** How much of a flat top a crown loses for each share it is narrower than its specimen: all of it at half as wide. */\nconst NARROW_DOME = 2;\n/** The roundness of a crown's top that is neither flat nor pointed: an ellipse's (Rautiainen's exponent 2). */\nconst ROUND = 2;\n\n/**\n * How young a tree of this size is for its kind, 0 (its specimen's age or older) to 1 (a young tree): by its\n * height or its crown's reach beside its specimen's, whichever is the more (a short tree with a crown as wide as\n * its specimen's is an old one, cut back or on a windy headland, not a young one).\n */\nexport function youthOf(sp: TreeSpecies, size: TreeSize): number {\n const m = Math.max(size.height / Math.max(0.01, sp.height), size.crownRadius / Math.max(0.01, sp.crownRadius));\n const t = Math.min(1, Math.max(0, (AGE_OLD - m) / (AGE_OLD - AGE_YOUNG)));\n return t * t * (3 - 2 * t);\n}\n\n/** How much narrower for its depth a crown is than its specimen's, 0 (as wide or wider) to 1 (a column). */\nexport function narrownessOf(sp: TreeSpecies, size: TreeSize): number {\n const own = size.crownRadius / Math.max(0.01, size.height - size.crownBase);\n const specimen = sp.crownRadius / Math.max(0.01, sp.height - sp.crownBase);\n return Math.min(1, Math.max(0, 1 - own / Math.max(1e-3, specimen)));\n}\n\n/**\n * A species' row as a tree of this size grows (see the head of this file): its own row for a tree as big as\n * its specimen, and for a palm, a conifer or a shrub at any size; else a copy, what comes with age faded by how\n * young it is, its flat top rounded by how narrow.\n */\nexport function habitAt(sp: TreeSpecies, size: TreeSize): TreeSpecies {\n if (sp.architecture !== \"broadleaf\") return sp;\n const y = youthOf(sp, size);\n const n = narrownessOf(sp, size);\n if (y <= 0 && n <= 0) return sp;\n const out: TreeSpecies = { ...sp };\n const fade = (v: number | undefined, k: number) => (v === undefined ? undefined : v * (1 - k));\n // Its top: a flat or umbrella top (round over 2) is an old tree's and a wide crown's; young or narrow, rounded.\n // (A crown half as wide for its depth as its specimen's is a dome: an umbrella's limbs have not spread yet.)\n const flat = Math.min(1, Math.max(y, NARROW_DOME * n));\n if (sp.crownRound !== undefined && sp.crownRound > ROUND) out.crownRound = ROUND + (sp.crownRound - ROUND) * (1 - flat);\n if (y > 0) {\n // (Its pads and plates fewer: an old open tree's shelves. A narrow one keeps them: a sheltered Monterey cypress's\n // pads are its kind's.)\n out.pads = fade(sp.pads, YOUNG_PADS * y);\n if (sp.crownPeak !== undefined) out.crownPeak = sp.crownPeak + (YOUNG_PEAK - sp.crownPeak) * 0.5 * y;\n out.leader = sp.leader + (1 - sp.leader) * YOUNG_LEADER * y;\n // (Its old limbs not yet grown: a forked trunk, a stone pine's V-forks, are an older tree's.)\n if (sp.fork !== undefined || sp.forkShare !== undefined) out.forkShare = (sp.forkShare ?? (sp.fork !== undefined && sp.forkStems !== undefined ? 1 : 0)) * (1 - y);\n out.canopyLift = fade(sp.canopyLift, y);\n out.clusters = fade(sp.clusters, YOUNG_CLUSTERS * y);\n out.lean = fade(sp.lean, 0.8 * y);\n if ((sp.weep ?? 0) > 0 && (sp.weep ?? 0) < 0.7) {\n out.weep = fade(sp.weep, y);\n if (sp.bend < 0) out.bend = sp.bend * (1 - 0.8 * y);\n if ((sp.limbCurveBack ?? 0) < 0) out.limbCurveBack = sp.limbCurveBack! * (1 - 0.8 * y);\n }\n }\n // (Fields left out stay left out: a copy with `undefined` written in is the same row to the grower.)\n for (const k of Object.keys(out) as (keyof TreeSpecies)[]) if (out[k] === undefined) delete out[k];\n return out;\n}\n\nexport type LifeStageKey = \"sapling\" | \"young\" | \"mid\" | \"mature\";\nexport const LIFE_STAGE_KEYS: readonly LifeStageKey[] = [\"sapling\", \"young\", \"mid\", \"mature\"];\n\nexport interface LifeStage {\n key: LifeStageKey;\n label: string;\n heightFrac: number;\n size: TreeSize;\n /** Horizontal centre `x` (m) when the four stages stand left-to-right centred round x = 0. */\n x: number;\n}\n\n/**\n * Four representative life stages of a species from sapling to mature specimen, arranged left-to-right\n * to true relative scale round `x = 0` without overlapping crowns.\n */\nexport function lifeStageSizes(sp: TreeSpecies): LifeStage[] {\n const { height: H, crownRadius: R, crownBase: B, trunkRadius: T } = sp;\n const palm = sp.architecture === \"palm\";\n const tree = sp.architecture === \"broadleaf\" || sp.architecture === \"conifer\";\n const h0 = Math.max(0.7, 0.18 * H);\n const h1 = Math.max(1.1, 0.38 * H);\n const h2 = Math.max(1.5, 0.68 * H);\n const raw: Omit<LifeStage, \"x\">[] = [\n {\n key: \"sapling\",\n label: \"Sapling\",\n heightFrac: 0.18,\n size: {\n height: h0,\n crownRadius: palm ? Math.max(0.45, 0.55 * R) : tree ? Math.max(0.28, Math.min(0.14 * R, 0.28 * h0)) : Math.max(0.28, 0.14 * R),\n crownBase: palm ? Math.min(0.25 * h0, 0.08 * B) : tree ? Math.min(0.22 * h0, 0.35 * B) : Math.min(0.3 * h0, 0.12 * B),\n trunkRadius: Math.max(0.012, T * 0.18 ** (tree ? 1.55 : 1.25)),\n },\n },\n {\n key: \"young\",\n label: \"Young\",\n heightFrac: 0.38,\n size: {\n height: h1,\n crownRadius: palm ? Math.max(0.65, 0.78 * R) : tree ? Math.max(0.45, Math.min(0.32 * R, 0.34 * h1)) : Math.max(0.45, 0.32 * R),\n crownBase: tree ? Math.min(0.24 * h1, 0.65 * B) : Math.min(0.6 * h1, B * 0.32),\n trunkRadius: Math.max(0.02, T * 0.38 ** (tree ? 1.45 : 1.2)),\n },\n },\n {\n key: \"mid\",\n label: \"Mid-age\",\n heightFrac: 0.68,\n size: {\n height: h2,\n crownRadius: palm ? 0.92 * R : tree ? Math.max(0.65, Math.min(0.64 * R, 0.48 * h2)) : 0.64 * R,\n crownBase: tree ? Math.min(0.24 * h2, 0.85 * B) : Math.min(0.8 * h2, B * 0.66),\n trunkRadius: Math.max(0.025, T * 0.68 ** (tree ? 1.25 : 1.15)),\n },\n },\n {\n key: \"mature\",\n label: \"Mature\",\n heightFrac: 1,\n size: { height: H, crownRadius: R, crownBase: B, trunkRadius: T },\n },\n ];\n const gap = Math.max(1.2, 0.35 * R);\n const xs = [0];\n for (let i = 1; i < raw.length; i++) {\n xs.push(xs[i - 1] + raw[i - 1].size.crownRadius + gap + raw[i].size.crownRadius);\n }\n const left = xs[0] - raw[0].size.crownRadius;\n const right = xs[raw.length - 1] + raw[raw.length - 1].size.crownRadius;\n const midX = 0.5 * (left + right);\n return raw.map((st, i) => ({ ...st, x: xs[i] - midX }));\n}\n"]}
@@ -0,0 +1,64 @@
1
+ import * as THREE from "three/webgpu";
2
+ type Vec3 = THREE.Node<"vec3">;
3
+ export interface AtmosphereOptions {
4
+ /** Atmospheric haze turbidity (1 crisp mountain air .. 10 hazy summer day). */
5
+ turbidity: number;
6
+ /** Rayleigh molecular scattering strength multiplier. */
7
+ rayleigh: number;
8
+ /** Mie aerosol scattering strength multiplier. */
9
+ mie: number;
10
+ /** Mie forward-scattering anisotropy g in (-0.95..0.95), typically ~0.76. */
11
+ mieAnisotropy: number;
12
+ /** Stratospheric ozone Chappuis absorption multiplier (deepens zenith blue at twilight). */
13
+ ozone: number;
14
+ /** Exponential ground haze density multiplier. */
15
+ hazeDensity: number;
16
+ /** Exponential scale height of ground aerosols / mist (m). */
17
+ hazeScaleHeight: number;
18
+ /** Overall aerial perspective blend strength, 0..2 (1 = physical). */
19
+ aerialStrength: number;
20
+ /** Solar irradiance multiplier. */
21
+ sunIntensity: number;
22
+ /** World Y height (m) taken as sea/ground level for exponential density. */
23
+ groundElevation: number;
24
+ }
25
+ export declare const DEFAULT_ATMOSPHERE: AtmosphereOptions;
26
+ export declare const ATMOSPHERE_RANGES: Readonly<Record<keyof AtmosphereOptions, {
27
+ min: number;
28
+ max: number;
29
+ step: number;
30
+ }>>;
31
+ /** Validate atmosphere parameters; empty array if all finite and in range. */
32
+ export declare function checkAtmosphere(opts: AtmosphereOptions): string[];
33
+ /**
34
+ * Evaluate physically based single + multiple-scattering sky radiance in linear RGB along unit direction `dir`.
35
+ */
36
+ export declare function evalSkyScattering(dir: readonly [number, number, number], sun: readonly [number, number, number], partial?: Partial<AtmosphereOptions>): [number, number, number];
37
+ /**
38
+ * Evaluate height-integrated aerial perspective (Rayleigh sky fill + Mie haze + extinction)
39
+ * from `eye` to world point `at`.
40
+ */
41
+ export declare function evalAerialPerspective(colour: readonly [number, number, number], eye: readonly [number, number, number], at: readonly [number, number, number], sun: readonly [number, number, number], partial?: Partial<AtmosphereOptions>): [number, number, number];
42
+ declare function encodeSkyUv(dx: number, dy: number, dz: number): [number, number];
43
+ declare function decodeSkyUv(u: number, v: number): [number, number, number];
44
+ export interface Atmosphere {
45
+ readonly options: AtmosphereOptions;
46
+ /** Sky-View LUT texture (128x64 RGBA8, filterable on all WebGPU devices). */
47
+ readonly skyLut: THREE.DataTexture;
48
+ /** Re-bake the Sky-View LUT and update aerial-perspective uniforms for the current `sun`. */
49
+ update(sun: THREE.Vector3): void;
50
+ /** TSL node suitable for `TreesOptions.world.air(colour, at)`. */
51
+ air(colour: Vec3, at: Vec3): Vec3;
52
+ /** TSL node returning physically based sky radiance + solar disc along unit ray `dir`. */
53
+ skyColor(dir: Vec3): Vec3;
54
+ /** Convenience sky dome mesh matching `atmosphere.skyColor`. */
55
+ makeSkyMesh(radius?: number): THREE.Mesh;
56
+ dispose(): void;
57
+ }
58
+ /**
59
+ * Create a physically based atmospheric scattering & aerial-perspective system backed by
60
+ * an automatically updated filterable RGBA8 Sky-View LUT and TSL shader nodes.
61
+ */
62
+ export declare function createAtmosphere(initial?: Partial<AtmosphereOptions>): Atmosphere;
63
+ export { encodeSkyUv, decodeSkyUv };
64
+ //# sourceMappingURL=atmosphere.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atmosphere.d.ts","sourceRoot":"","sources":["../src/atmosphere.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE/B,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,6EAA6E;IAC7E,aAAa,EAAE,MAAM,CAAC;IACtB,4FAA4F;IAC5F,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,eAAe,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,cAAc,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,kBAAkB,EAAE,iBAWhC,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,iBAAiB,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAWnH,CAAC;AAEF,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAQjE;AA4BD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACtC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAA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,GAAG,KAAK,CAAC,IAAI,CAAC;IACzC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,UAAU,CAmHjF;AAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,260 @@
1
+ // Physically based atmospheric scattering (Rayleigh + Mie + ozone absorption)
2
+ // and height-integrated aerial perspective for distant landscapes.
3
+ //
4
+ // `evalSkyScattering` and `evalAerialPerspective` are pure arithmetic so tests
5
+ // can verify the physics directly; `createAtmosphere` bakes a filterable RGBA8
6
+ // Sky-View LUT and exposes a TSL `air(colour, at)` node for `TreesOptions.world.air`.
7
+ import * as THREE from "three/webgpu";
8
+ import { Fn, cameraPosition, clamp, dot, exp, float, length, max, mix, normalize, positionGeometry, pow, smoothstep, texture, uniform, vec2, vec3 } from "three/tsl";
9
+ export const DEFAULT_ATMOSPHERE = {
10
+ turbidity: 2.2,
11
+ rayleigh: 1.0,
12
+ mie: 1.0,
13
+ mieAnisotropy: 0.76,
14
+ ozone: 1.0,
15
+ hazeDensity: 1.0,
16
+ hazeScaleHeight: 220,
17
+ aerialStrength: 1.0,
18
+ sunIntensity: 1.0,
19
+ groundElevation: 0,
20
+ };
21
+ export const ATMOSPHERE_RANGES = {
22
+ turbidity: { min: 1, max: 10, step: 0.1 },
23
+ rayleigh: { min: 0, max: 3, step: 0.05 },
24
+ mie: { min: 0, max: 4, step: 0.05 },
25
+ mieAnisotropy: { min: 0, max: 0.95, step: 0.01 },
26
+ ozone: { min: 0, max: 3, step: 0.05 },
27
+ hazeDensity: { min: 0, max: 4, step: 0.05 },
28
+ hazeScaleHeight: { min: 20, max: 2000, step: 10 },
29
+ aerialStrength: { min: 0, max: 2, step: 0.05 },
30
+ sunIntensity: { min: 0.2, max: 3, step: 0.05 },
31
+ groundElevation: { min: -200, max: 2000, step: 5 },
32
+ };
33
+ /** Validate atmosphere parameters; empty array if all finite and in range. */
34
+ export function checkAtmosphere(opts) {
35
+ const out = [];
36
+ for (const [k, r] of Object.entries(ATMOSPHERE_RANGES)) {
37
+ const v = opts[k];
38
+ if (typeof v !== "number" || !Number.isFinite(v))
39
+ out.push(`${k} is not a number`);
40
+ else if (v < r.min || v > r.max)
41
+ out.push(`${k} ${v} is outside ${r.min}..${r.max}`);
42
+ }
43
+ return out;
44
+ }
45
+ // Physical sea-level scattering coefficients (m^-1) scaled for Earth-like atmosphere.
46
+ const BETA_RAYLEIGH = [5.8e-6, 13.5e-6, 33.1e-6];
47
+ const BETA_OZONE = [0.65e-6, 1.88e-6, 0.085e-6];
48
+ const RAYLEIGH_SCALE_HEIGHT = 8000;
49
+ const MIE_SCALE_HEIGHT = 1200;
50
+ function cornetteShanksPhase(cosTheta, g) {
51
+ const g2 = g * g;
52
+ const num = 3 * (1 - g2) * (1 + cosTheta * cosTheta);
53
+ const den = 8 * Math.PI * (2 + g2) * Math.pow(Math.max(1e-4, 1 + g2 - 2 * g * cosTheta), 1.5);
54
+ return num / den;
55
+ }
56
+ function rayleighPhase(cosTheta) {
57
+ return (3 / (16 * Math.PI)) * (1 + cosTheta * cosTheta);
58
+ }
59
+ /** Optical airmass along elevation cosine `mu = max(dir.y, 0)` using Kasten-Young approximation. */
60
+ function airmass(dirY, scaleH) {
61
+ const sinE = Math.max(0.015, dirY);
62
+ const deg = (Math.asin(Math.min(1, sinE)) * 180) / Math.PI;
63
+ // Scale Kasten-Young airmass by atmospheric thickness ratio vs 8 km Rayleigh layer.
64
+ const k = 1 / (sinE + 0.50572 * Math.pow(deg + 6.07995, -1.6364));
65
+ return k * scaleH;
66
+ }
67
+ /**
68
+ * Evaluate physically based single + multiple-scattering sky radiance in linear RGB along unit direction `dir`.
69
+ */
70
+ export function evalSkyScattering(dir, sun, partial) {
71
+ const o = { ...DEFAULT_ATMOSPHERE, ...partial };
72
+ const dl = Math.hypot(dir[0], dir[1], dir[2]) || 1;
73
+ const dx = dir[0] / dl;
74
+ const dy = dir[1] / dl;
75
+ const dz = dir[2] / dl;
76
+ const sl = Math.hypot(sun[0], sun[1], sun[2]) || 1;
77
+ const sx = sun[0] / sl;
78
+ const sy = sun[1] / sl;
79
+ const sz = sun[2] / sl;
80
+ const cosTheta = Math.min(1, Math.max(-1, dx * sx + dy * sy + dz * sz));
81
+ const pR = rayleighPhase(cosTheta);
82
+ const pM = cornetteShanksPhase(cosTheta, o.mieAnisotropy);
83
+ const viewY = Math.max(0.015, dy);
84
+ const sunY = Math.max(-0.12, sy);
85
+ const sunLift = Math.max(0, Math.min(1, (sunY + 0.12) / 0.22));
86
+ const mViewR = airmass(viewY, RAYLEIGH_SCALE_HEIGHT);
87
+ const mViewM = airmass(viewY, MIE_SCALE_HEIGHT);
88
+ const mSunR = airmass(Math.max(0.015, sunY), RAYLEIGH_SCALE_HEIGHT);
89
+ const mSunM = airmass(Math.max(0.015, sunY), MIE_SCALE_HEIGHT);
90
+ const mieBeta = 2.1e-5 * o.mie * o.turbidity;
91
+ const out = [0, 0, 0];
92
+ for (let c = 0; c < 3; c++) {
93
+ const betaR = BETA_RAYLEIGH[c] * o.rayleigh;
94
+ const betaO = BETA_OZONE[c] * o.ozone;
95
+ const tauView = betaR * mViewR + mieBeta * mViewM * 1.11 + betaO * mViewR * 0.6;
96
+ const tauSun = betaR * mSunR + mieBeta * mSunM * 1.11 + betaO * mSunR * 0.6;
97
+ const transView = Math.exp(-tauView);
98
+ const transSun = Math.exp(-tauSun);
99
+ // Analytical single-scattering integral + isotropic multi-scattering floor.
100
+ const scatterCoeff = betaR * pR + mieBeta * pM;
101
+ const totalExt = Math.max(1e-7, betaR + mieBeta * 1.11 + betaO * 0.6);
102
+ const single = ((scatterCoeff / totalExt) * (1 - transView)) * transSun;
103
+ const multi = (0.045 * (betaR / BETA_RAYLEIGH[2] + 0.25) * (1 - Math.exp(-tauView * 0.7))) * (0.35 + 0.65 * Math.max(0, sunY));
104
+ const groundBounce = dy < 0 ? Math.exp(dy * 5) : 1;
105
+ out[c] = Math.max(0, (single * 18 + multi * 1.8) * o.sunIntensity * sunLift * groundBounce);
106
+ }
107
+ return out;
108
+ }
109
+ /**
110
+ * Evaluate height-integrated aerial perspective (Rayleigh sky fill + Mie haze + extinction)
111
+ * from `eye` to world point `at`.
112
+ */
113
+ export function evalAerialPerspective(colour, eye, at, sun, partial) {
114
+ const o = { ...DEFAULT_ATMOSPHERE, ...partial };
115
+ const vx = at[0] - eye[0];
116
+ const vy = at[1] - eye[1];
117
+ const vz = at[2] - eye[2];
118
+ const dist = Math.hypot(vx, vy, vz);
119
+ if (dist < 1e-3 || o.aerialStrength <= 0)
120
+ return [colour[0], colour[1], colour[2]];
121
+ const dx = vx / dist;
122
+ const dy = vy / dist;
123
+ const dz = vz / dist;
124
+ const H = Math.max(10, o.hazeScaleHeight);
125
+ // Exact exponential height-density integral along ray from eye.y to at.y:
126
+ // int_0^dist exp(-(eye.y - g + dy*s)/H) ds
127
+ const h0 = Math.max(-2, (eye[1] - o.groundElevation) / H);
128
+ const h1 = Math.max(-2, (at[1] - o.groundElevation) / H);
129
+ const dh = h1 - h0;
130
+ const heightFactor = Math.abs(dh) < 1e-4 ? Math.exp(-h0) : (Math.exp(-h0) - Math.exp(-h1)) / dh;
131
+ const effDist = dist * Math.min(4, Math.max(0.05, heightFactor)) * o.aerialStrength;
132
+ const mieExt = 5.5e-5 * o.mie * o.turbidity * o.hazeDensity;
133
+ const inscatter = evalSkyScattering([dx, Math.max(0.02, dy), dz], sun, o);
134
+ const out = [0, 0, 0];
135
+ for (let c = 0; c < 3; c++) {
136
+ const beta = BETA_RAYLEIGH[c] * o.rayleigh * 2.2 + mieExt;
137
+ const trans = Math.exp(-beta * effDist);
138
+ out[c] = colour[c] * trans + inscatter[c] * (1 - trans);
139
+ }
140
+ return out;
141
+ }
142
+ const LUT_W = 128;
143
+ const LUT_H = 64;
144
+ function encodeSkyUv(dx, dy, dz) {
145
+ const az = Math.atan2(dz, dx);
146
+ const u = (az / (Math.PI * 2) + 1) % 1;
147
+ // Nonlinear elevation mapping concentrates texels near the horizon where scattering changes fastest.
148
+ const s = Math.sign(dy) * Math.sqrt(Math.min(1, Math.abs(dy)));
149
+ const v = s * 0.5 + 0.5;
150
+ return [u, v];
151
+ }
152
+ function decodeSkyUv(u, v) {
153
+ const az = u * Math.PI * 2;
154
+ const s = v * 2 - 1;
155
+ const dy = Math.sign(s) * s * s;
156
+ const r = Math.sqrt(Math.max(0, 1 - dy * dy));
157
+ return [r * Math.cos(az), dy, r * Math.sin(az)];
158
+ }
159
+ /**
160
+ * Create a physically based atmospheric scattering & aerial-perspective system backed by
161
+ * an automatically updated filterable RGBA8 Sky-View LUT and TSL shader nodes.
162
+ */
163
+ export function createAtmosphere(initial) {
164
+ const options = { ...DEFAULT_ATMOSPHERE, ...initial };
165
+ const lutData = new Uint8Array(LUT_W * LUT_H * 4);
166
+ const skyLut = new THREE.DataTexture(lutData, LUT_W, LUT_H, THREE.RGBAFormat, THREE.UnsignedByteType);
167
+ skyLut.colorSpace = THREE.NoColorSpace;
168
+ skyLut.magFilter = skyLut.minFilter = THREE.LinearFilter;
169
+ skyLut.wrapS = THREE.RepeatWrapping;
170
+ skyLut.wrapT = THREE.ClampToEdgeWrapping;
171
+ skyLut.generateMipmaps = false;
172
+ const uSun = uniform(new THREE.Vector3(0.4, 0.8, 0.3).normalize());
173
+ const uHaze = uniform(new THREE.Vector4(options.hazeScaleHeight, options.groundElevation, options.aerialStrength, options.sunIntensity));
174
+ const uBeta = uniform(new THREE.Vector4(BETA_RAYLEIGH[0] * options.rayleigh * 2.2 + 5.5e-5 * options.mie * options.turbidity * options.hazeDensity, BETA_RAYLEIGH[1] * options.rayleigh * 2.2 + 5.5e-5 * options.mie * options.turbidity * options.hazeDensity, BETA_RAYLEIGH[2] * options.rayleigh * 2.2 + 5.5e-5 * options.mie * options.turbidity * options.hazeDensity, options.mieAnisotropy));
175
+ let lastKey = "";
176
+ const bakeLut = (sun) => {
177
+ const mieExt = 5.5e-5 * options.mie * options.turbidity * options.hazeDensity;
178
+ uSun.value.copy(sun).normalize();
179
+ uHaze.value.set(Math.max(10, options.hazeScaleHeight), options.groundElevation, options.aerialStrength, options.sunIntensity);
180
+ uBeta.value.set(BETA_RAYLEIGH[0] * options.rayleigh * 2.2 + mieExt, BETA_RAYLEIGH[1] * options.rayleigh * 2.2 + mieExt, BETA_RAYLEIGH[2] * options.rayleigh * 2.2 + mieExt, options.mieAnisotropy);
181
+ const key = `${uSun.value.x.toFixed(3)},${uSun.value.y.toFixed(3)},${uSun.value.z.toFixed(3)}|${JSON.stringify(options)}`;
182
+ if (key === lastKey)
183
+ return;
184
+ lastKey = key;
185
+ const sunArr = [uSun.value.x, uSun.value.y, uSun.value.z];
186
+ for (let j = 0; j < LUT_H; j++) {
187
+ const v = (j + 0.5) / LUT_H;
188
+ for (let i = 0; i < LUT_W; i++) {
189
+ const u = (i + 0.5) / LUT_W;
190
+ const dir = decodeSkyUv(u, v);
191
+ const c = evalSkyScattering(dir, sunArr, options);
192
+ const o = (j * LUT_W + i) * 4;
193
+ // Reversible Reinhard encoding keeps HDR sky peaks within filterable RGBA8.
194
+ lutData[o] = Math.round(Math.min(1, c[0] / (1 + c[0])) * 255);
195
+ lutData[o + 1] = Math.round(Math.min(1, c[1] / (1 + c[1])) * 255);
196
+ lutData[o + 2] = Math.round(Math.min(1, c[2] / (1 + c[2])) * 255);
197
+ lutData[o + 3] = 255;
198
+ }
199
+ }
200
+ skyLut.needsUpdate = true;
201
+ };
202
+ bakeLut(uSun.value);
203
+ const sqrtSafe = (x) => x.max(0).sqrt();
204
+ const absSafe = (x) => x.abs();
205
+ const sampleLut = (dir) => {
206
+ const az = dir.z.atan(dir.x);
207
+ const u = az.div(Math.PI * 2).add(1).fract();
208
+ const s = dir.y.sign().mul(sqrtSafe(absSafe(dir.y)));
209
+ const v = clamp(s.mul(0.5).add(0.5), 0.008, 0.992);
210
+ const enc = texture(skyLut, vec2(u, v)).level(float(0)).rgb;
211
+ return enc.div(max(vec3(1).sub(enc), vec3(0.01)));
212
+ };
213
+ const skyColor = (dir) => {
214
+ const d = normalize(dir);
215
+ const sky = sampleLut(d);
216
+ const cosTheta = dot(d, uSun);
217
+ const sunDisc = smoothstep(float(0.99965), float(0.99993), cosTheta).mul(14).mul(uHaze.w).mul(smoothstep(float(-0.08), float(0.12), uSun.y));
218
+ const aureole = pow(clamp(cosTheta, 0, 1), float(96)).mul(0.55).mul(uHaze.w).mul(smoothstep(float(-0.08), float(0.15), uSun.y));
219
+ return sky.add(vec3(1.15, 0.98, 0.82).mul(sunDisc.add(aureole)));
220
+ };
221
+ // Affine colour transform: colour * transmittance + inscatter, compatible with `intoAir` decomposition.
222
+ const air = (colour, at) => {
223
+ const delta = at.sub(cameraPosition);
224
+ const dist = length(delta);
225
+ const dir = delta.div(max(dist, float(1e-3)));
226
+ const H = uHaze.x;
227
+ const h0 = max(float(-2), cameraPosition.y.sub(uHaze.y).div(H));
228
+ const h1 = max(float(-2), at.y.sub(uHaze.y).div(H));
229
+ const dh = h1.sub(h0);
230
+ const hf = exp(h0.negate()).sub(exp(h1.negate())).div(dh.sign().mul(max(dh.abs(), float(1e-4))));
231
+ const hfFlat = exp(h0.negate());
232
+ const heightFactor = clamp(mix(hfFlat, hf, smoothstep(float(1e-4), float(1e-3), dh.abs())), 0.05, 4);
233
+ const effDist = dist.mul(heightFactor).mul(uHaze.z);
234
+ const trans = exp(uBeta.xyz.negate().mul(effDist));
235
+ const skyDir = normalize(vec3(dir.x, max(dir.y, float(0.02)), dir.z));
236
+ const inscatter = sampleLut(skyDir);
237
+ return colour.mul(trans).add(inscatter.mul(vec3(1).sub(trans)));
238
+ };
239
+ const makeSkyMesh = (radius = 9000) => {
240
+ const mat = new THREE.MeshBasicNodeMaterial({ side: THREE.BackSide, fog: false, depthWrite: false });
241
+ mat.colorNode = Fn(() => skyColor(positionGeometry))();
242
+ const mesh = new THREE.Mesh(new THREE.SphereGeometry(radius, 32, 16), mat);
243
+ mesh.name = "atmosphere-sky";
244
+ mesh.renderOrder = -1;
245
+ return mesh;
246
+ };
247
+ return {
248
+ options,
249
+ skyLut,
250
+ update: bakeLut,
251
+ air,
252
+ skyColor,
253
+ makeSkyMesh,
254
+ dispose() {
255
+ skyLut.dispose();
256
+ },
257
+ };
258
+ }
259
+ export { encodeSkyUv, decodeSkyUv };
260
+ //# sourceMappingURL=atmosphere.js.map