webgpu-trees 0.0.0-stage → 0.2.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 (330) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1547 -2
  3. package/assets/SOURCES.md +263 -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/magnolia.albedo.avif +0 -0
  41. package/assets/bark/magnolia.normal.avif +0 -0
  42. package/assets/bark/maple.albedo.avif +0 -0
  43. package/assets/bark/maple.normal.avif +0 -0
  44. package/assets/bark/montereyPine.albedo.avif +0 -0
  45. package/assets/bark/montereyPine.normal.avif +0 -0
  46. package/assets/bark/norMaple.albedo.avif +0 -0
  47. package/assets/bark/norMaple.normal.avif +0 -0
  48. package/assets/bark/oak.albedo.avif +0 -0
  49. package/assets/bark/oak.normal.avif +0 -0
  50. package/assets/bark/palmLattice.albedo.avif +0 -0
  51. package/assets/bark/palmLattice.normal.avif +0 -0
  52. package/assets/bark/palmPineapple.albedo.avif +0 -0
  53. package/assets/bark/palmPineapple.normal.avif +0 -0
  54. package/assets/bark/palmRings.albedo.avif +0 -0
  55. package/assets/bark/palmRings.normal.avif +0 -0
  56. package/assets/bark/pine.albedo.avif +0 -0
  57. package/assets/bark/pine.normal.avif +0 -0
  58. package/assets/bark/pineFlakes.albedo.avif +0 -0
  59. package/assets/bark/pineFlakes.normal.avif +0 -0
  60. package/assets/bark/plane.albedo.avif +0 -0
  61. package/assets/bark/plane.normal.avif +0 -0
  62. package/assets/bark/poplar.albedo.avif +0 -0
  63. package/assets/bark/poplar.normal.avif +0 -0
  64. package/assets/bark/redAlder.albedo.avif +0 -0
  65. package/assets/bark/redAlder.normal.avif +0 -0
  66. package/assets/bark/redOak.albedo.avif +0 -0
  67. package/assets/bark/redOak.normal.avif +0 -0
  68. package/assets/bark/ridged.albedo.avif +0 -0
  69. package/assets/bark/ridged.normal.avif +0 -0
  70. package/assets/bark/sitkaSpruce.albedo.avif +0 -0
  71. package/assets/bark/sitkaSpruce.normal.avif +0 -0
  72. package/assets/bark/spruce.albedo.avif +0 -0
  73. package/assets/bark/spruce.normal.avif +0 -0
  74. package/assets/bark/stonePine.albedo.avif +0 -0
  75. package/assets/bark/stonePine.normal.avif +0 -0
  76. package/assets/bark/sweetgum.albedo.avif +0 -0
  77. package/assets/bark/sweetgum.normal.avif +0 -0
  78. package/assets/bark/sycMaple.albedo.avif +0 -0
  79. package/assets/bark/sycMaple.normal.avif +0 -0
  80. package/assets/bark/torreyPine.albedo.avif +0 -0
  81. package/assets/bark/torreyPine.normal.avif +0 -0
  82. package/assets/bark/whitePine.albedo.avif +0 -0
  83. package/assets/bark/whitePine.normal.avif +0 -0
  84. package/assets/bark/whiteSpruce.albedo.avif +0 -0
  85. package/assets/bark/whiteSpruce.normal.avif +0 -0
  86. package/assets/bark/whiteWillow.albedo.avif +0 -0
  87. package/assets/bark/whiteWillow.normal.avif +0 -0
  88. package/assets/bark/willow.albedo.avif +0 -0
  89. package/assets/bark/willow.normal.avif +0 -0
  90. package/assets/leaves/alder.albedo.avif +0 -0
  91. package/assets/leaves/alder.normal.avif +0 -0
  92. package/assets/leaves/ash.albedo.avif +0 -0
  93. package/assets/leaves/ash.normal.avif +0 -0
  94. package/assets/leaves/aspen.albedo.avif +0 -0
  95. package/assets/leaves/aspen.normal.avif +0 -0
  96. package/assets/leaves/beech.albedo.avif +0 -0
  97. package/assets/leaves/beech.normal.avif +0 -0
  98. package/assets/leaves/birch.albedo.avif +0 -0
  99. package/assets/leaves/birch.normal.avif +0 -0
  100. package/assets/leaves/blackthorn.albedo.avif +0 -0
  101. package/assets/leaves/blackthorn.normal.avif +0 -0
  102. package/assets/leaves/blade.albedo.avif +0 -0
  103. package/assets/leaves/blade.normal.avif +0 -0
  104. package/assets/leaves/broomSprig.albedo.avif +0 -0
  105. package/assets/leaves/broomSprig.normal.avif +0 -0
  106. package/assets/leaves/corsicanShoot.albedo.avif +0 -0
  107. package/assets/leaves/corsicanShoot.normal.avif +0 -0
  108. package/assets/leaves/cypress.albedo.avif +0 -0
  109. package/assets/leaves/cypress.normal.avif +0 -0
  110. package/assets/leaves/cypressPad.albedo.avif +0 -0
  111. package/assets/leaves/cypressPad.normal.avif +0 -0
  112. package/assets/leaves/deadFronds.albedo.avif +0 -0
  113. package/assets/leaves/deadFronds.normal.avif +0 -0
  114. package/assets/leaves/deltoid.albedo.avif +0 -0
  115. package/assets/leaves/deltoid.normal.avif +0 -0
  116. package/assets/leaves/douglasShoot.albedo.avif +0 -0
  117. package/assets/leaves/douglasShoot.normal.avif +0 -0
  118. package/assets/leaves/elderSprig.albedo.avif +0 -0
  119. package/assets/leaves/elderSprig.normal.avif +0 -0
  120. package/assets/leaves/elliptic.albedo.avif +0 -0
  121. package/assets/leaves/elliptic.normal.avif +0 -0
  122. package/assets/leaves/eucalyptus.albedo.avif +0 -0
  123. package/assets/leaves/eucalyptus.normal.avif +0 -0
  124. package/assets/leaves/fan.albedo.avif +0 -0
  125. package/assets/leaves/fan.normal.avif +0 -0
  126. package/assets/leaves/fanB.albedo.avif +0 -0
  127. package/assets/leaves/fanB.normal.avif +0 -0
  128. package/assets/leaves/fir.albedo.avif +0 -0
  129. package/assets/leaves/fir.normal.avif +0 -0
  130. package/assets/leaves/frond.albedo.avif +0 -0
  131. package/assets/leaves/frond.normal.avif +0 -0
  132. package/assets/leaves/gorse.albedo.avif +0 -0
  133. package/assets/leaves/gorse.normal.avif +0 -0
  134. package/assets/leaves/hawthorn.albedo.avif +0 -0
  135. package/assets/leaves/hawthorn.normal.avif +0 -0
  136. package/assets/leaves/hemlockShoot.albedo.avif +0 -0
  137. package/assets/leaves/hemlockShoot.normal.avif +0 -0
  138. package/assets/leaves/hornbeam.albedo.avif +0 -0
  139. package/assets/leaves/hornbeam.normal.avif +0 -0
  140. package/assets/leaves/lance.albedo.avif +0 -0
  141. package/assets/leaves/lance.normal.avif +0 -0
  142. package/assets/leaves/larchShoot.albedo.avif +0 -0
  143. package/assets/leaves/larchShoot.normal.avif +0 -0
  144. package/assets/leaves/lime.albedo.avif +0 -0
  145. package/assets/leaves/lime.normal.avif +0 -0
  146. package/assets/leaves/liveOak.albedo.avif +0 -0
  147. package/assets/leaves/liveOak.normal.avif +0 -0
  148. package/assets/leaves/londonPlane.albedo.avif +0 -0
  149. package/assets/leaves/londonPlane.normal.avif +0 -0
  150. package/assets/leaves/magnolia.albedo.avif +0 -0
  151. package/assets/leaves/magnolia.normal.avif +0 -0
  152. package/assets/leaves/maple.albedo.avif +0 -0
  153. package/assets/leaves/maple.normal.avif +0 -0
  154. package/assets/leaves/norMaple.albedo.avif +0 -0
  155. package/assets/leaves/norMaple.normal.avif +0 -0
  156. package/assets/leaves/oak.albedo.avif +0 -0
  157. package/assets/leaves/oak.normal.avif +0 -0
  158. package/assets/leaves/paintFan.albedo.avif +0 -0
  159. package/assets/leaves/paintFan.normal.avif +0 -0
  160. package/assets/leaves/paintFrond.albedo.avif +0 -0
  161. package/assets/leaves/paintFrond.normal.avif +0 -0
  162. package/assets/leaves/pine.albedo.avif +0 -0
  163. package/assets/leaves/pine.normal.avif +0 -0
  164. package/assets/leaves/pineClumpDark.albedo.avif +0 -0
  165. package/assets/leaves/pineClumpDark.normal.avif +0 -0
  166. package/assets/leaves/pineClumpLight.albedo.avif +0 -0
  167. package/assets/leaves/pineClumpLight.normal.avif +0 -0
  168. package/assets/leaves/poplar.albedo.avif +0 -0
  169. package/assets/leaves/poplar.normal.avif +0 -0
  170. package/assets/leaves/queenFrond.albedo.avif +0 -0
  171. package/assets/leaves/queenFrond.normal.avif +0 -0
  172. package/assets/leaves/redAlder.albedo.avif +0 -0
  173. package/assets/leaves/redAlder.normal.avif +0 -0
  174. package/assets/leaves/redOak.albedo.avif +0 -0
  175. package/assets/leaves/redOak.normal.avif +0 -0
  176. package/assets/leaves/round.albedo.avif +0 -0
  177. package/assets/leaves/round.normal.avif +0 -0
  178. package/assets/leaves/scale.albedo.avif +0 -0
  179. package/assets/leaves/scale.normal.avif +0 -0
  180. package/assets/leaves/scotsPineClump.albedo.avif +0 -0
  181. package/assets/leaves/scotsPineClump.normal.avif +0 -0
  182. package/assets/leaves/seaBuckthornSprig.albedo.avif +0 -0
  183. package/assets/leaves/seaBuckthornSprig.normal.avif +0 -0
  184. package/assets/leaves/serrate.albedo.avif +0 -0
  185. package/assets/leaves/serrate.normal.avif +0 -0
  186. package/assets/leaves/sitkaShoot.albedo.avif +0 -0
  187. package/assets/leaves/sitkaShoot.normal.avif +0 -0
  188. package/assets/leaves/stonePineCanopy.albedo.avif +0 -0
  189. package/assets/leaves/stonePineCanopy.normal.avif +0 -0
  190. package/assets/leaves/stonePineCushion.albedo.avif +0 -0
  191. package/assets/leaves/stonePineCushion.normal.avif +0 -0
  192. package/assets/leaves/sweetgum.albedo.avif +0 -0
  193. package/assets/leaves/sweetgum.normal.avif +0 -0
  194. package/assets/leaves/sycamore.albedo.avif +0 -0
  195. package/assets/leaves/sycamore.normal.avif +0 -0
  196. package/assets/leaves/torreyPine.albedo.avif +0 -0
  197. package/assets/leaves/torreyPine.normal.avif +0 -0
  198. package/assets/leaves/whitePine.albedo.avif +0 -0
  199. package/assets/leaves/whitePine.normal.avif +0 -0
  200. package/assets/leaves/whiteSpruceShoot.albedo.avif +0 -0
  201. package/assets/leaves/whiteSpruceShoot.normal.avif +0 -0
  202. package/assets/leaves/whiteWillow.albedo.avif +0 -0
  203. package/assets/leaves/whiteWillow.normal.avif +0 -0
  204. package/assets/leaves/willow.albedo.avif +0 -0
  205. package/assets/leaves/willow.normal.avif +0 -0
  206. package/assets/marks/marks.json +894 -0
  207. package/assets/marks/painterly.avif +0 -0
  208. package/assets/marks/sheets.avif +0 -0
  209. package/assets/scans.json +6406 -0
  210. package/lib/age.d.ts +36 -0
  211. package/lib/age.d.ts.map +1 -0
  212. package/lib/age.js +170 -0
  213. package/lib/age.js.map +1 -0
  214. package/lib/atmosphere.d.ts +64 -0
  215. package/lib/atmosphere.d.ts.map +1 -0
  216. package/lib/atmosphere.js +260 -0
  217. package/lib/atmosphere.js.map +1 -0
  218. package/lib/dabs.d.ts +4 -0
  219. package/lib/dabs.d.ts.map +1 -0
  220. package/lib/dabs.js +77 -0
  221. package/lib/dabs.js.map +1 -0
  222. package/lib/engine.d.ts +211 -0
  223. package/lib/engine.d.ts.map +1 -0
  224. package/lib/engine.js +3808 -0
  225. package/lib/engine.js.map +1 -0
  226. package/lib/genetics.d.ts +129 -0
  227. package/lib/genetics.d.ts.map +1 -0
  228. package/lib/genetics.js +721 -0
  229. package/lib/genetics.js.map +1 -0
  230. package/lib/geometry.d.ts +237 -0
  231. package/lib/geometry.d.ts.map +1 -0
  232. package/lib/geometry.js +1944 -0
  233. package/lib/geometry.js.map +1 -0
  234. package/lib/grow.d.ts +83 -0
  235. package/lib/grow.d.ts.map +1 -0
  236. package/lib/grow.js +3851 -0
  237. package/lib/grow.js.map +1 -0
  238. package/lib/hiz.d.ts +74 -0
  239. package/lib/hiz.d.ts.map +1 -0
  240. package/lib/hiz.js +161 -0
  241. package/lib/hiz.js.map +1 -0
  242. package/lib/impostor.d.ts +106 -0
  243. package/lib/impostor.d.ts.map +1 -0
  244. package/lib/impostor.js +450 -0
  245. package/lib/impostor.js.map +1 -0
  246. package/lib/index.d.ts +17 -0
  247. package/lib/index.d.ts.map +1 -0
  248. package/lib/index.js +16 -0
  249. package/lib/index.js.map +1 -0
  250. package/lib/leaves.d.ts +30 -0
  251. package/lib/leaves.d.ts.map +1 -0
  252. package/lib/leaves.js +829 -0
  253. package/lib/leaves.js.map +1 -0
  254. package/lib/light.d.ts +110 -0
  255. package/lib/light.d.ts.map +1 -0
  256. package/lib/light.js +430 -0
  257. package/lib/light.js.map +1 -0
  258. package/lib/lobes.d.ts +25 -0
  259. package/lib/lobes.d.ts.map +1 -0
  260. package/lib/lobes.js +151 -0
  261. package/lib/lobes.js.map +1 -0
  262. package/lib/marks.d.ts +63 -0
  263. package/lib/marks.d.ts.map +1 -0
  264. package/lib/marks.js +553 -0
  265. package/lib/marks.js.map +1 -0
  266. package/lib/mips.d.ts +42 -0
  267. package/lib/mips.d.ts.map +1 -0
  268. package/lib/mips.js +220 -0
  269. package/lib/mips.js.map +1 -0
  270. package/lib/paintedMarks.d.ts +21 -0
  271. package/lib/paintedMarks.d.ts.map +1 -0
  272. package/lib/paintedMarks.js +53 -0
  273. package/lib/paintedMarks.js.map +1 -0
  274. package/lib/palm.d.ts +162 -0
  275. package/lib/palm.d.ts.map +1 -0
  276. package/lib/palm.js +779 -0
  277. package/lib/palm.js.map +1 -0
  278. package/lib/palmAtlas.d.ts +79 -0
  279. package/lib/palmAtlas.d.ts.map +1 -0
  280. package/lib/palmAtlas.js +335 -0
  281. package/lib/palmAtlas.js.map +1 -0
  282. package/lib/palmGeometry.d.ts +41 -0
  283. package/lib/palmGeometry.d.ts.map +1 -0
  284. package/lib/palmGeometry.js +309 -0
  285. package/lib/palmGeometry.js.map +1 -0
  286. package/lib/phenology.d.ts +21 -0
  287. package/lib/phenology.d.ts.map +1 -0
  288. package/lib/phenology.js +168 -0
  289. package/lib/phenology.js.map +1 -0
  290. package/lib/random.d.ts +34 -0
  291. package/lib/random.d.ts.map +1 -0
  292. package/lib/random.js +92 -0
  293. package/lib/random.js.map +1 -0
  294. package/lib/scans.d.ts +232 -0
  295. package/lib/scans.d.ts.map +1 -0
  296. package/lib/scans.js +397 -0
  297. package/lib/scans.js.map +1 -0
  298. package/lib/scatter.d.ts +70 -0
  299. package/lib/scatter.d.ts.map +1 -0
  300. package/lib/scatter.js +186 -0
  301. package/lib/scatter.js.map +1 -0
  302. package/lib/species.d.ts +369 -0
  303. package/lib/species.d.ts.map +1 -0
  304. package/lib/species.js +2978 -0
  305. package/lib/species.js.map +1 -0
  306. package/lib/sprays.d.ts +112 -0
  307. package/lib/sprays.d.ts.map +1 -0
  308. package/lib/sprays.js +1137 -0
  309. package/lib/sprays.js.map +1 -0
  310. package/lib/stand.d.ts +52 -0
  311. package/lib/stand.d.ts.map +1 -0
  312. package/lib/stand.js +279 -0
  313. package/lib/stand.js.map +1 -0
  314. package/lib/styles.d.ts +135 -0
  315. package/lib/styles.d.ts.map +1 -0
  316. package/lib/styles.js +79 -0
  317. package/lib/styles.js.map +1 -0
  318. package/lib/tree.d.ts +134 -0
  319. package/lib/tree.d.ts.map +1 -0
  320. package/lib/tree.js +57 -0
  321. package/lib/tree.js.map +1 -0
  322. package/lib/variants.d.ts +157 -0
  323. package/lib/variants.d.ts.map +1 -0
  324. package/lib/variants.js +532 -0
  325. package/lib/variants.js.map +1 -0
  326. package/lib/visibility.d.ts +105 -0
  327. package/lib/visibility.d.ts.map +1 -0
  328. package/lib/visibility.js +242 -0
  329. package/lib/visibility.js.map +1 -0
  330. package/package.json +62 -3
package/lib/stand.js ADDED
@@ -0,0 +1,279 @@
1
+ // Where each tree stands among the others: alone in the open, at a wood's
2
+ // edge, or deep in a wood. Worked out from the trees themselves (where they
3
+ // stand and how big their crowns are), so a host hands over only its list.
4
+ //
5
+ // A tree's light comes from the sky round it as much as from above. Round a
6
+ // tree alone, the sky comes down to the horizon on every side, and it keeps
7
+ // its branches to the ground and grows round. At a wood's edge, its
8
+ // neighbours' crowns hide the low sky on the wood's side: there its lower
9
+ // branches starve and die (it self-prunes), its crown reaches out over the
10
+ // open ground and keeps its leaves low on that side, and leans a little to
11
+ // it. Deep in a wood the low sky is hidden all round, and a tree keeps only
12
+ // a small crown high up, on a tall clean bole.
13
+ //
14
+ // So for each tree, round it in sixteen sectors: how much of each sector the
15
+ // crowns of its neighbours fill, as walls of leaves standing past its own
16
+ // crown. A neighbour counts by how much of the sector it spans (its crown's
17
+ // width at its distance), how high it reaches over this tree's crown base
18
+ // (a shrub under an oak hides nothing of the oak's sky), and how near it
19
+ // stands (one a tree's height off past the crowns hides little); and one
20
+ // crown hides only so much (`CROWN_HIDES`), so a way is closed as far as
21
+ // it is crowns deep. From the
22
+ // sixteen, kept as the first two terms of their Fourier series (all one
23
+ // needs to tell an edge from the inside of a wood):
24
+ //
25
+ // enclosure their mean: 0 in the open, about a half at a straight edge,
26
+ // 1 deep in a wood;
27
+ // lopsided how much more closed one side is than the other (the first
28
+ // harmonic's amplitude: 0.64 for a straight edge);
29
+ // open which way it is most open (unit, on the ground);
30
+ // canopy how tall the walls stand, for its own height;
31
+ // gap how far past its own crown they stand, for its crown's radius.
32
+ //
33
+ // Growing (grow.ts) and the shaders (engine.ts) both read the light of a
34
+ // place in or under the crown from these the same way (`standLight`): the
35
+ // sky of each sector is hidden up to the wall's top as seen from there.
36
+ /** A tree on open ground: nothing round it. */
37
+ export const OPEN_STAND = { enclosure: 0, lopsided: 0, openX: 1, openZ: 0, canopy: 1, gap: 1 };
38
+ /** How many sectors round a tree its neighbours are reckoned in. */
39
+ export const STAND_SECTORS = 16;
40
+ /** A neighbour this far past the crowns (as a share of the tree's height) hides nothing of its sky. */
41
+ const STAND_REACH = 0.8;
42
+ /**
43
+ * How much of what lies behind it one crown hides: a crown is leaves, not a wall (exp(-k L) across a
44
+ * crown's leafy shell twice, for a crown of middling density). Two crowns deep a way is mostly closed,
45
+ * three nearly all: so a wood's second row still has some of the open side's light.
46
+ */
47
+ const CROWN_HIDES = 0.7;
48
+ /** The nearest a wall is taken to stand from a place, as a share of the crown's radius. */
49
+ const WALL_NEAREST = 0.15;
50
+ /** How closed a tree is in a direction on the ground (unit): its stand's two terms, 0..1. */
51
+ export function closedness(stand, ux, uz) {
52
+ return Math.min(1, Math.max(0, stand.enclosure - stand.lopsided * (ux * stand.openX + uz * stand.openZ)));
53
+ }
54
+ /**
55
+ * What class of variant a tree is grown as: `interior` where even its most open side is mostly closed,
56
+ * `edge` where one side is closed and another open, `open` where nothing much is closed anywhere.
57
+ */
58
+ export function standingOf(stand) {
59
+ const least = stand.enclosure - stand.lopsided;
60
+ const most = stand.enclosure + stand.lopsided;
61
+ if (least >= 0.4)
62
+ return "interior";
63
+ if (most >= 0.5)
64
+ return "edge";
65
+ return "open";
66
+ }
67
+ /**
68
+ * How much of the sky (as a horizontal surface sees it, the sky taken as evenly bright: Moon and Spencer's
69
+ * uniform sky) reaches a place in a tree's own frame (metres from its foot, its open side along +x), past
70
+ * the walls of its neighbours' crowns: 1 in the open, little at the foot of a wood's interior. In each
71
+ * sector the sky is hidden up to the wall's top as seen from the place, as far as the sector is closed;
72
+ * the share of a uniform sky below an elevation θ is sin²θ. The wall stands `gap` crown radii past the
73
+ * crown. (The tree's own crown is not counted: see `standShare`.) The shaders work it out the same way.
74
+ */
75
+ export function standLight(stand, size, x, y, z) {
76
+ if (stand.enclosure <= 0 && stand.lopsided <= 0)
77
+ return 1;
78
+ const rise = stand.canopy * size.height - y;
79
+ if (rise <= 0)
80
+ return 1;
81
+ const wall = size.crownRadius * (1 + stand.gap);
82
+ let lost = 0;
83
+ for (let s = 0; s < STAND_SECTORS; s++) {
84
+ const a = ((s + 0.5) / STAND_SECTORS) * 2 * Math.PI;
85
+ const ux = Math.cos(a);
86
+ const c = Math.min(1, Math.max(0, stand.enclosure - stand.lopsided * ux));
87
+ const d = Math.max(WALL_NEAREST * size.crownRadius, wall - (x * ux + z * Math.sin(a)));
88
+ lost += (c * rise * rise) / (rise * rise + d * d);
89
+ }
90
+ return 1 - lost / STAND_SECTORS;
91
+ }
92
+ /** The elevations of the sky's bands a place's light is reckoned in (radians), and each band's share of a uniform sky. */
93
+ const BANDS = [0, 22.5, 45, 67.5, 90].map((d) => (d * Math.PI) / 180);
94
+ // (Worked out once: each sector's way round, each band's bounds as sin² and its middle ray's elevation. `standShare`
95
+ // is asked for every few voxels of every crown grown in a stand, and these were most of its time.)
96
+ const SECTOR_UX = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.cos(((s + 0.5) / STAND_SECTORS) * 2 * Math.PI));
97
+ const SECTOR_UZ = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.sin(((s + 0.5) / STAND_SECTORS) * 2 * Math.PI));
98
+ const BAND_LO = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.sin(BANDS[b]) ** 2);
99
+ const BAND_HI = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.sin(BANDS[b + 1]) ** 2);
100
+ const BAND_COS = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.cos(0.5 * (BANDS[b] + BANDS[b + 1])));
101
+ const BAND_SIN = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.sin(0.5 * (BANDS[b] + BANDS[b + 1])));
102
+ /**
103
+ * Of the sky that would reach a place in a tree's crown were it standing alone, the share its stand leaves
104
+ * it, 0..1 (its own frame, its open side along +x). Its sky comes to it through its own crown either way:
105
+ * the crown taken as its ellipsoid with a leafy shell `shell` deep and an airy heart, which lets through
106
+ * exp(-k L) over the leafy length L a ray crosses (Monsi and Saeki, as the shaders light a crown). The
107
+ * stand hides what comes in below its walls' tops. So a place on the shaded side of an edge tree, which
108
+ * had most of its sky from its own side, keeps only what comes over or through the rest of the crown; a
109
+ * place on the open side loses only what reached it through the crown already. A tree in an even shade
110
+ * all over (a shrub under a wood's canopy) keeps all of its share where nothing hides its sides: what
111
+ * shapes a crown is where its light comes from, not how much there is.
112
+ */
113
+ export function standShare(stand, size, k, shell, x, y, z) {
114
+ if (stand.enclosure <= 0 && stand.lopsided <= 0)
115
+ return 1;
116
+ const rise = stand.canopy * size.height - y;
117
+ if (rise <= 0)
118
+ return 1;
119
+ const ry = Math.max(0.05, 0.5 * (size.height - size.crownBase));
120
+ const rx = Math.max(0.05, size.crownRadius);
121
+ const air = 0.18 * Math.min(rx, ry);
122
+ const px = x / rx;
123
+ const py = (y - size.crownBase - ry) / ry;
124
+ const pz = z / rx;
125
+ const c0 = px * px + py * py + pz * pz - 1;
126
+ const wall = size.crownRadius * (1 + stand.gap);
127
+ let alone = 0;
128
+ let left = 0;
129
+ for (let s = 0; s < STAND_SECTORS; s++) {
130
+ const ux = SECTOR_UX[s];
131
+ const uz = SECTOR_UZ[s];
132
+ const closed = Math.min(1, Math.max(0, stand.enclosure - stand.lopsided * ux));
133
+ const d = Math.max(WALL_NEAREST * size.crownRadius, wall - (x * ux + z * uz));
134
+ // (The wall's top as seen from here, as sin² of its elevation: the share of the sky below it.)
135
+ const below = (rise * rise) / (rise * rise + d * d);
136
+ for (let b = 0; b < BAND_LO.length; b++) {
137
+ const lo = BAND_LO[b];
138
+ const hi = BAND_HI[b];
139
+ // (Through its own crown along the band's middle ray: the leafy length it crosses, the crown's ellipsoid.)
140
+ const dx = (BAND_COS[b] * ux) / rx;
141
+ const dy = BAND_SIN[b] / ry;
142
+ const dz = (BAND_COS[b] * uz) / rx;
143
+ const qa = dx * dx + dy * dy + dz * dz;
144
+ const qb = px * dx + py * dy + pz * dz;
145
+ const disc = qb * qb - qa * c0;
146
+ let through = 1;
147
+ if (disc > 0) {
148
+ const root = Math.sqrt(disc);
149
+ const len = Math.max(0, (-qb + root) / qa) - Math.max(0, (-qb - root) / qa);
150
+ through = Math.exp(-k * Math.min(Math.max(len - air, 0), 2 * shell));
151
+ }
152
+ const sky = hi - lo;
153
+ const hidden = closed * Math.min(1, Math.max(0, (below - lo) / sky));
154
+ alone += sky * through;
155
+ left += sky * through * (1 - hidden);
156
+ }
157
+ }
158
+ return alone > 0 ? left / alone : 1;
159
+ }
160
+ /**
161
+ * Each tree's stand, from where the trees stand and their sizes: `x` and `z` (the ground's), one each a
162
+ * tree, and their sizes. Neighbours are found through a grid of cells hashed by place, so it takes some tens
163
+ * of milliseconds for tens of thousands of trees.
164
+ */
165
+ export function standsOf(x, z, sizes) {
166
+ const n = sizes.length;
167
+ const out = new Array(n);
168
+ if (n === 0)
169
+ return out;
170
+ let maxR = 0;
171
+ let maxReach = 0;
172
+ for (const s of sizes) {
173
+ maxR = Math.max(maxR, s.crownRadius);
174
+ maxReach = Math.max(maxReach, s.crownRadius + STAND_REACH * s.height);
175
+ }
176
+ const cell = Math.max(4, (maxR + maxReach) / 3);
177
+ // (A hashed grid: each cell's trees chained through `next`, its first in `head`.)
178
+ const slots = 1 << Math.max(10, Math.ceil(Math.log2(n * 2)));
179
+ const head = new Int32Array(slots).fill(-1);
180
+ const next = new Int32Array(n).fill(-1);
181
+ const key = (ix, iz) => (Math.imul(ix, 73856093) ^ Math.imul(iz, 19349663)) & (slots - 1);
182
+ for (let i = 0; i < n; i++) {
183
+ const k = key(Math.floor(x[i] / cell), Math.floor(z[i] / cell));
184
+ next[i] = head[k];
185
+ head[k] = i;
186
+ }
187
+ const w = (2 * Math.PI) / STAND_SECTORS;
188
+ const open = new Float64Array(STAND_SECTORS);
189
+ const nearest = new Float64Array(STAND_SECTORS);
190
+ const cos = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.cos((s + 0.5) * w));
191
+ const sin = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.sin((s + 0.5) * w));
192
+ for (let i = 0; i < n; i++) {
193
+ const si = sizes[i];
194
+ const depth = Math.max(0.1, si.height - si.crownBase);
195
+ const far = si.crownRadius + maxR + STAND_REACH * si.height;
196
+ const span = Math.ceil(far / cell);
197
+ const cx = Math.floor(x[i] / cell);
198
+ const cz = Math.floor(z[i] / cell);
199
+ // (Each sector's sky left open, as the product of what each neighbour leaves of it.)
200
+ open.fill(1);
201
+ nearest.fill(Infinity);
202
+ let tall = 0;
203
+ let weight = 0;
204
+ const seen = new Set();
205
+ for (let a = -span; a <= span; a++)
206
+ for (let b = -span; b <= span; b++) {
207
+ const k = key(cx + a, cz + b);
208
+ if (seen.has(k))
209
+ continue;
210
+ seen.add(k);
211
+ for (let j = head[k]; j >= 0; j = next[j]) {
212
+ if (j === i)
213
+ continue;
214
+ const dx = x[j] - x[i];
215
+ const dz = z[j] - z[i];
216
+ const d = Math.hypot(dx, dz);
217
+ if (d < 1e-3 || d > far)
218
+ continue;
219
+ const sj = sizes[j];
220
+ const gap = d - si.crownRadius - sj.crownRadius;
221
+ // (How far it reaches over this tree's crown base, for the crown's depth; and how near it stands.)
222
+ const over = Math.min(1, Math.max(0, (sj.height - si.crownBase) / depth));
223
+ const near = Math.min(1, Math.max(0, 1 - Math.max(0, gap) / (STAND_REACH * si.height)));
224
+ const p = CROWN_HIDES * over * near;
225
+ if (p <= 0.01)
226
+ continue;
227
+ // (The angle its crown spans from here, and the sectors that takes in, each by how much of it.)
228
+ const phi = Math.atan2(dz, dx);
229
+ const half = d > sj.crownRadius ? Math.asin(sj.crownRadius / d) : 0.5 * Math.PI;
230
+ const s0 = Math.floor((phi - half) / w);
231
+ const s1 = Math.floor((phi + half) / w);
232
+ for (let s = s0; s <= s1; s++) {
233
+ const lo = Math.max(phi - half, s * w);
234
+ const hi = Math.min(phi + half, (s + 1) * w);
235
+ const f = Math.max(0, hi - lo) / w;
236
+ if (f <= 0)
237
+ continue;
238
+ const q = ((s % STAND_SECTORS) + STAND_SECTORS) % STAND_SECTORS;
239
+ open[q] *= 1 - f * p;
240
+ tall += f * p * sj.height;
241
+ weight += f * p;
242
+ // (The wall a sector has is its nearest crown that fills a fair part of it.)
243
+ if (f * p >= 0.2)
244
+ nearest[q] = Math.min(nearest[q], gap);
245
+ }
246
+ }
247
+ }
248
+ let c0 = 0;
249
+ let re = 0;
250
+ let im = 0;
251
+ let gaps = 0;
252
+ let walled = 0;
253
+ for (let s = 0; s < STAND_SECTORS; s++) {
254
+ const c = 1 - open[s];
255
+ c0 += c;
256
+ re += c * cos[s];
257
+ im += c * sin[s];
258
+ if (Number.isFinite(nearest[s])) {
259
+ gaps += c * nearest[s];
260
+ walled += c;
261
+ }
262
+ }
263
+ c0 /= STAND_SECTORS;
264
+ // (The first harmonic: twice the mean of closedness turned round by each sector's direction.)
265
+ re *= 2 / STAND_SECTORS;
266
+ im *= 2 / STAND_SECTORS;
267
+ const c1 = Math.hypot(re, im);
268
+ out[i] = {
269
+ enclosure: c0,
270
+ lopsided: c1,
271
+ openX: c1 > 1e-6 ? -re / c1 : 1,
272
+ openZ: c1 > 1e-6 ? -im / c1 : 0,
273
+ canopy: weight > 0 ? tall / weight / si.height : 1,
274
+ gap: walled > 0 ? Math.min(3, Math.max(-0.3, gaps / walled / si.crownRadius)) : 1,
275
+ };
276
+ }
277
+ return out;
278
+ }
279
+ //# sourceMappingURL=stand.js.map
@@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EAAE,IAAI,GAAG,MAAM,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAClF,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// Where each tree stands among the others: alone in the open, at a wood's\n// edge, or deep in a wood. Worked out from the trees themselves (where they\n// stand and how big their crowns are), so a host hands over only its list.\n//\n// A tree's light comes from the sky round it as much as from above. Round a\n// tree alone, the sky comes down to the horizon on every side, and it keeps\n// its branches to the ground and grows round. At a wood's edge, its\n// neighbours' crowns hide the low sky on the wood's side: there its lower\n// branches starve and die (it self-prunes), its crown reaches out over the\n// open ground and keeps its leaves low on that side, and leans a little to\n// it. Deep in a wood the low sky is hidden all round, and a tree keeps only\n// a small crown high up, on a tall clean bole.\n//\n// So for each tree, round it in sixteen sectors: how much of each sector the\n// crowns of its neighbours fill, as walls of leaves standing past its own\n// crown. A neighbour counts by how much of the sector it spans (its crown's\n// width at its distance), how high it reaches over this tree's crown base\n// (a shrub under an oak hides nothing of the oak's sky), and how near it\n// stands (one a tree's height off past the crowns hides little); and one\n// crown hides only so much (`CROWN_HIDES`), so a way is closed as far as\n// it is crowns deep. From the\n// sixteen, kept as the first two terms of their Fourier series (all one\n// needs to tell an edge from the inside of a wood):\n//\n// enclosure their mean: 0 in the open, about a half at a straight edge,\n// 1 deep in a wood;\n// lopsided how much more closed one side is than the other (the first\n// harmonic's amplitude: 0.64 for a straight edge);\n// open which way it is most open (unit, on the ground);\n// canopy how tall the walls stand, for its own height;\n// gap how far past its own crown they stand, for its crown's radius.\n//\n// Growing (grow.ts) and the shaders (engine.ts) both read the light of a\n// place in or under the crown from these the same way (`standLight`): the\n// sky of each sector is hidden up to the wall's top as seen from there.\n\nimport { type TreeSize } from \"./tree.ts\";\n\n/** Where a tree stands among the others. See the head of stand.ts. */\nexport interface Stand {\n enclosure: number;\n lopsided: number;\n /** Which way it is most open, on the ground (x, z: unit). */\n openX: number;\n openZ: number;\n canopy: number;\n gap: number;\n}\n\n/** A tree on open ground: nothing round it. */\nexport const OPEN_STAND: Readonly<Stand> = { enclosure: 0, lopsided: 0, openX: 1, openZ: 0, canopy: 1, gap: 1 };\n\n/** How a tree is grown for where it stands: a variant's class. */\nexport type Standing = \"open\" | \"edge\" | \"interior\";\n\n/** How many sectors round a tree its neighbours are reckoned in. */\nexport const STAND_SECTORS = 16;\n/** A neighbour this far past the crowns (as a share of the tree's height) hides nothing of its sky. */\nconst STAND_REACH = 0.8;\n/**\n * How much of what lies behind it one crown hides: a crown is leaves, not a wall (exp(-k L) across a\n * crown's leafy shell twice, for a crown of middling density). Two crowns deep a way is mostly closed,\n * three nearly all: so a wood's second row still has some of the open side's light.\n */\nconst CROWN_HIDES = 0.7;\n/** The nearest a wall is taken to stand from a place, as a share of the crown's radius. */\nconst WALL_NEAREST = 0.15;\n\n/** How closed a tree is in a direction on the ground (unit): its stand's two terms, 0..1. */\nexport function closedness(stand: Stand, ux: number, uz: number): number {\n return Math.min(1, Math.max(0, stand.enclosure - stand.lopsided * (ux * stand.openX + uz * stand.openZ)));\n}\n\n/**\n * What class of variant a tree is grown as: `interior` where even its most open side is mostly closed,\n * `edge` where one side is closed and another open, `open` where nothing much is closed anywhere.\n */\nexport function standingOf(stand: Stand): Standing {\n const least = stand.enclosure - stand.lopsided;\n const most = stand.enclosure + stand.lopsided;\n if (least >= 0.4) return \"interior\";\n if (most >= 0.5) return \"edge\";\n return \"open\";\n}\n\n/**\n * How much of the sky (as a horizontal surface sees it, the sky taken as evenly bright: Moon and Spencer's\n * uniform sky) reaches a place in a tree's own frame (metres from its foot, its open side along +x), past\n * the walls of its neighbours' crowns: 1 in the open, little at the foot of a wood's interior. In each\n * sector the sky is hidden up to the wall's top as seen from the place, as far as the sector is closed;\n * the share of a uniform sky below an elevation θ is sin²θ. The wall stands `gap` crown radii past the\n * crown. (The tree's own crown is not counted: see `standShare`.) The shaders work it out the same way.\n */\nexport function standLight(stand: Stand, size: TreeSize, x: number, y: number, z: number): number {\n if (stand.enclosure <= 0 && stand.lopsided <= 0) return 1;\n const rise = stand.canopy * size.height - y;\n if (rise <= 0) return 1;\n const wall = size.crownRadius * (1 + stand.gap);\n let lost = 0;\n for (let s = 0; s < STAND_SECTORS; s++) {\n const a = ((s + 0.5) / STAND_SECTORS) * 2 * Math.PI;\n const ux = Math.cos(a);\n const c = Math.min(1, Math.max(0, stand.enclosure - stand.lopsided * ux));\n const d = Math.max(WALL_NEAREST * size.crownRadius, wall - (x * ux + z * Math.sin(a)));\n lost += (c * rise * rise) / (rise * rise + d * d);\n }\n return 1 - lost / STAND_SECTORS;\n}\n\n/** The elevations of the sky's bands a place's light is reckoned in (radians), and each band's share of a uniform sky. */\nconst BANDS = [0, 22.5, 45, 67.5, 90].map((d) => (d * Math.PI) / 180);\n// (Worked out once: each sector's way round, each band's bounds as sin² and its middle ray's elevation. `standShare`\n// is asked for every few voxels of every crown grown in a stand, and these were most of its time.)\nconst SECTOR_UX = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.cos(((s + 0.5) / STAND_SECTORS) * 2 * Math.PI));\nconst SECTOR_UZ = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.sin(((s + 0.5) / STAND_SECTORS) * 2 * Math.PI));\nconst BAND_LO = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.sin(BANDS[b]) ** 2);\nconst BAND_HI = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.sin(BANDS[b + 1]) ** 2);\nconst BAND_COS = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.cos(0.5 * (BANDS[b] + BANDS[b + 1])));\nconst BAND_SIN = Float64Array.from({ length: BANDS.length - 1 }, (_, b) => Math.sin(0.5 * (BANDS[b] + BANDS[b + 1])));\n\n/**\n * Of the sky that would reach a place in a tree's crown were it standing alone, the share its stand leaves\n * it, 0..1 (its own frame, its open side along +x). Its sky comes to it through its own crown either way:\n * the crown taken as its ellipsoid with a leafy shell `shell` deep and an airy heart, which lets through\n * exp(-k L) over the leafy length L a ray crosses (Monsi and Saeki, as the shaders light a crown). The\n * stand hides what comes in below its walls' tops. So a place on the shaded side of an edge tree, which\n * had most of its sky from its own side, keeps only what comes over or through the rest of the crown; a\n * place on the open side loses only what reached it through the crown already. A tree in an even shade\n * all over (a shrub under a wood's canopy) keeps all of its share where nothing hides its sides: what\n * shapes a crown is where its light comes from, not how much there is.\n */\nexport function standShare(stand: Stand, size: TreeSize, k: number, shell: number, x: number, y: number, z: number): number {\n if (stand.enclosure <= 0 && stand.lopsided <= 0) return 1;\n const rise = stand.canopy * size.height - y;\n if (rise <= 0) return 1;\n const ry = Math.max(0.05, 0.5 * (size.height - size.crownBase));\n const rx = Math.max(0.05, size.crownRadius);\n const air = 0.18 * Math.min(rx, ry);\n const px = x / rx;\n const py = (y - size.crownBase - ry) / ry;\n const pz = z / rx;\n const c0 = px * px + py * py + pz * pz - 1;\n const wall = size.crownRadius * (1 + stand.gap);\n let alone = 0;\n let left = 0;\n for (let s = 0; s < STAND_SECTORS; s++) {\n const ux = SECTOR_UX[s];\n const uz = SECTOR_UZ[s];\n const closed = Math.min(1, Math.max(0, stand.enclosure - stand.lopsided * ux));\n const d = Math.max(WALL_NEAREST * size.crownRadius, wall - (x * ux + z * uz));\n // (The wall's top as seen from here, as sin² of its elevation: the share of the sky below it.)\n const below = (rise * rise) / (rise * rise + d * d);\n for (let b = 0; b < BAND_LO.length; b++) {\n const lo = BAND_LO[b];\n const hi = BAND_HI[b];\n // (Through its own crown along the band's middle ray: the leafy length it crosses, the crown's ellipsoid.)\n const dx = (BAND_COS[b] * ux) / rx;\n const dy = BAND_SIN[b] / ry;\n const dz = (BAND_COS[b] * uz) / rx;\n const qa = dx * dx + dy * dy + dz * dz;\n const qb = px * dx + py * dy + pz * dz;\n const disc = qb * qb - qa * c0;\n let through = 1;\n if (disc > 0) {\n const root = Math.sqrt(disc);\n const len = Math.max(0, (-qb + root) / qa) - Math.max(0, (-qb - root) / qa);\n through = Math.exp(-k * Math.min(Math.max(len - air, 0), 2 * shell));\n }\n const sky = hi - lo;\n const hidden = closed * Math.min(1, Math.max(0, (below - lo) / sky));\n alone += sky * through;\n left += sky * through * (1 - hidden);\n }\n }\n return alone > 0 ? left / alone : 1;\n}\n\n/**\n * Each tree's stand, from where the trees stand and their sizes: `x` and `z` (the ground's), one each a\n * tree, and their sizes. Neighbours are found through a grid of cells hashed by place, so it takes some tens\n * of milliseconds for tens of thousands of trees.\n */\nexport function standsOf(x: ArrayLike<number>, z: ArrayLike<number>, sizes: readonly TreeSize[]): Stand[] {\n const n = sizes.length;\n const out: Stand[] = new Array(n);\n if (n === 0) return out;\n let maxR = 0;\n let maxReach = 0;\n for (const s of sizes) {\n maxR = Math.max(maxR, s.crownRadius);\n maxReach = Math.max(maxReach, s.crownRadius + STAND_REACH * s.height);\n }\n const cell = Math.max(4, (maxR + maxReach) / 3);\n // (A hashed grid: each cell's trees chained through `next`, its first in `head`.)\n const slots = 1 << Math.max(10, Math.ceil(Math.log2(n * 2)));\n const head = new Int32Array(slots).fill(-1);\n const next = new Int32Array(n).fill(-1);\n const key = (ix: number, iz: number) => (Math.imul(ix, 73856093) ^ Math.imul(iz, 19349663)) & (slots - 1);\n for (let i = 0; i < n; i++) {\n const k = key(Math.floor(x[i] / cell), Math.floor(z[i] / cell));\n next[i] = head[k];\n head[k] = i;\n }\n const w = (2 * Math.PI) / STAND_SECTORS;\n const open = new Float64Array(STAND_SECTORS);\n const nearest = new Float64Array(STAND_SECTORS);\n const cos = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.cos((s + 0.5) * w));\n const sin = Float64Array.from({ length: STAND_SECTORS }, (_, s) => Math.sin((s + 0.5) * w));\n for (let i = 0; i < n; i++) {\n const si = sizes[i];\n const depth = Math.max(0.1, si.height - si.crownBase);\n const far = si.crownRadius + maxR + STAND_REACH * si.height;\n const span = Math.ceil(far / cell);\n const cx = Math.floor(x[i] / cell);\n const cz = Math.floor(z[i] / cell);\n // (Each sector's sky left open, as the product of what each neighbour leaves of it.)\n open.fill(1);\n nearest.fill(Infinity);\n let tall = 0;\n let weight = 0;\n const seen = new Set<number>();\n for (let a = -span; a <= span; a++)\n for (let b = -span; b <= span; b++) {\n const k = key(cx + a, cz + b);\n if (seen.has(k)) continue;\n seen.add(k);\n for (let j = head[k]; j >= 0; j = next[j]) {\n if (j === i) continue;\n const dx = x[j] - x[i];\n const dz = z[j] - z[i];\n const d = Math.hypot(dx, dz);\n if (d < 1e-3 || d > far) continue;\n const sj = sizes[j];\n const gap = d - si.crownRadius - sj.crownRadius;\n // (How far it reaches over this tree's crown base, for the crown's depth; and how near it stands.)\n const over = Math.min(1, Math.max(0, (sj.height - si.crownBase) / depth));\n const near = Math.min(1, Math.max(0, 1 - Math.max(0, gap) / (STAND_REACH * si.height)));\n const p = CROWN_HIDES * over * near;\n if (p <= 0.01) continue;\n // (The angle its crown spans from here, and the sectors that takes in, each by how much of it.)\n const phi = Math.atan2(dz, dx);\n const half = d > sj.crownRadius ? Math.asin(sj.crownRadius / d) : 0.5 * Math.PI;\n const s0 = Math.floor((phi - half) / w);\n const s1 = Math.floor((phi + half) / w);\n for (let s = s0; s <= s1; s++) {\n const lo = Math.max(phi - half, s * w);\n const hi = Math.min(phi + half, (s + 1) * w);\n const f = Math.max(0, hi - lo) / w;\n if (f <= 0) continue;\n const q = ((s % STAND_SECTORS) + STAND_SECTORS) % STAND_SECTORS;\n open[q] *= 1 - f * p;\n tall += f * p * sj.height;\n weight += f * p;\n // (The wall a sector has is its nearest crown that fills a fair part of it.)\n if (f * p >= 0.2) nearest[q] = Math.min(nearest[q], gap);\n }\n }\n }\n let c0 = 0;\n let re = 0;\n let im = 0;\n let gaps = 0;\n let walled = 0;\n for (let s = 0; s < STAND_SECTORS; s++) {\n const c = 1 - open[s];\n c0 += c;\n re += c * cos[s];\n im += c * sin[s];\n if (Number.isFinite(nearest[s])) {\n gaps += c * nearest[s];\n walled += c;\n }\n }\n c0 /= STAND_SECTORS;\n // (The first harmonic: twice the mean of closedness turned round by each sector's direction.)\n re *= 2 / STAND_SECTORS;\n im *= 2 / STAND_SECTORS;\n const c1 = Math.hypot(re, im);\n out[i] = {\n enclosure: c0,\n lopsided: c1,\n openX: c1 > 1e-6 ? -re / c1 : 1,\n openZ: c1 > 1e-6 ? -im / c1 : 0,\n canopy: weight > 0 ? tall / weight / si.height : 1,\n gap: walled > 0 ? Math.min(3, Math.max(-0.3, gaps / walled / si.crownRadius)) : 1,\n };\n }\n return out;\n}\n"]}
@@ -0,0 +1,135 @@
1
+ /** How the trees are drawn, apart from what they are. Change it at any time: it is read each frame. */
2
+ export interface TreeStyle {
3
+ /** How far a crown's light is laid in flat bands, as paint is, 0 (smooth) to 1 (bands only). */
4
+ steps: number;
5
+ /** How many bands of light, from shade to sun. */
6
+ bands: number;
7
+ /** How round each clump of leaves is lit, 0 (as the crown's outside faces) to 1 (each clump a ball of its own). */
8
+ round: number;
9
+ /** How much one dab differs in tone from the next (and, in a cluster of leaves, one leaf from the next), 0..1. */
10
+ jitter: number;
11
+ /** How big the dabs are, beside what covers their clump: 1 as grown. */
12
+ dabScale: number;
13
+ /** How much sunlight comes through the leaves to an eye looking towards the sun, 0..1. */
14
+ through: number;
15
+ /**
16
+ * How tightly the light through the leaves gathers about the sun, as the eye looks towards it: the power
17
+ * of Barré-Brisebois's view term (GDC 2011). Low, a crown glows from wide of the sun; high, only round it.
18
+ */
19
+ throughPower: number;
20
+ /** How far a leaf's facing bends the light through it, 0..1 (the model's distortion): more, the glow follows the crown's form. */
21
+ throughWarp: number;
22
+ /**
23
+ * How much the light through the leaves varies, 0..1: by how deep in the crown a clump is, how much sun
24
+ * reaches it there (Monsi and Saeki), and leaf by leaf (each its own thickness). 0, every backlit leaf
25
+ * glows the same lime green.
26
+ */
27
+ throughVary: number;
28
+ /** How far the light wraps round past the side of a clump facing away from the sun, 0..1. */
29
+ wrap: number;
30
+ /** How strongly the brush's strokes (or each leaf's own tone in a cluster) show in a dab, 0..1. */
31
+ strokes: number;
32
+ /**
33
+ * How far a crown shades itself, 0..1: 1, as much as the light lost through its leaves makes it (Monsi and
34
+ * Saeki); 0, not at all, every leaf facing the sun as lit as the crown's outside. A painter keeps less of it
35
+ * than there is.
36
+ */
37
+ selfShade: number;
38
+ /** How square to the sun a leaf must face to take all of it: 0.65 lights a form as a painter does, 1 as the sun does. */
39
+ fullLight: number;
40
+ /** How furrowed the bark is, 0 (smooth, a painted trunk) to 1. */
41
+ bark: number;
42
+ /**
43
+ * How much moss the wood carries, 0..1: on what faces up, in the grooves between a trunk's buttresses,
44
+ * low on the trunk and on its side away from the sun.
45
+ */
46
+ moss: number;
47
+ /** Crustose & foliose bark lichen cover on rough trunks and scaffold limbs above the damp root collar, 0..1. */
48
+ lichen: number;
49
+ /** How far a realistic tree's near leaf cards turn towards the eye, 0..1: none at all shows some edge-on as slivers. */
50
+ faceEye: number;
51
+ /**
52
+ * How far a crown is lit as a few big masses, 0..1: each of its lobes (its clumps gathered into a handful,
53
+ * `lobes.ts`) shaded as a ball seen from the eye, pixel by pixel, so the light runs smoothly across all the
54
+ * dabs of a lobe. 0: each dab lit as one stroke, as the crown's outside faces where it is.
55
+ */
56
+ lobe: number;
57
+ /** How far each dab is lit as a small ball of its own, pixel by pixel, over its lobe, 0..1 (the sculpted look's bubbles). */
58
+ bulge: number;
59
+ /** How far the light on the leaves turns warm, towards a yellow-green, 0..1 (the sun's own tint stays the host's). */
60
+ warm: number;
61
+ /** How far the shade turns cool, towards a teal blue-green, 0..1 (over the host's shade tint). */
62
+ cool: number;
63
+ /** How saturated the leaves' colour is beside the species', 0 (grey) to 2: 1 as the species has it. */
64
+ chroma: number;
65
+ /** How bright the rim of a lobe is against the light, 0..1: light through its thin edge, and the sky behind it. */
66
+ rim: number;
67
+ /** In a look whose marks have them (sculpted), the share of a near crown's dabs drawn as sprigs of leaves, 0..1. */
68
+ sprigs: number;
69
+ /** How bright the sunlit side of a crown is beside its shade, 1 as the sun gives it: a painter's light is brighter. */
70
+ bright: number;
71
+ /**
72
+ * The painterly look: how long a broad leaf is at most, in metres (other kinds keep to theirs beside it, a
73
+ * palm's fronds far longer). A dab whose leaves would be longer carries smaller ones, more of them.
74
+ */
75
+ leafSize: number;
76
+ /**
77
+ * How far a crown's light comes from its own leaves and wood (light.ts: each grown tree's box of cells, the sun
78
+ * marched through it), 0..1, and the rest from its ellipsoid: 1, each bough shades the one below and the
79
+ * sun comes through the gaps between; 0, every leaf at one depth in the crown lit alike.
80
+ */
81
+ structure: number;
82
+ /** How thick the leaves are to the light in that box, beside what the species' crown carries: 1 as grown. */
83
+ density: number;
84
+ /**
85
+ * How far in flower the trees are, 0..1, where their pictures show flowers (the realistic look: a gorse's yellow
86
+ * pea flowers, `ScanLook.flowers`): the share of its sprays in flower, each by a number of its own; 1 in full
87
+ * flower, as in spring, 0 out of it, the flowers gone and the spines left. It is the bloom when the host gives no
88
+ * day of the year (`TreeEnvironment.day`); given one, each flowering species' own year says (`ScanLook.flowering`).
89
+ * 0.3: a gorse's few flowers over the year, a third of it in full flower and much of it not.
90
+ */
91
+ bloom: number;
92
+ }
93
+ /**
94
+ * How the trees are drawn, chosen when they are made (the pieces differ, not only the light):
95
+ * - `stylized`: crowns laid in dabs of paint, lit in bands (the painted look);
96
+ * - `painterly`: crowns of small, crisp clusters of leaves, the light laid over them as a few big soft masses,
97
+ * warm where lit and cool in shade;
98
+ * - `sculpted`: crowns as soft clay lobes, a few sprigs of leaves on them;
99
+ * - `real`: near crowns of leaf cards set in the crown, each a spray of the species' leaves, and far ones of
100
+ * the same sprays.
101
+ */
102
+ export type TreeLook = "stylized" | "painterly" | "sculpted" | "real";
103
+ export declare const TREE_LOOKS: readonly TreeLook[];
104
+ /** The painted look's style (and every look's, for the numbers it does not use). */
105
+ export declare const DEFAULT_STYLE: TreeStyle;
106
+ /** The realistic look's style: light as the sun gives it, the crown's shade, light through the leaves, furrowed bark. */
107
+ export declare const REAL_STYLE: TreeStyle;
108
+ /**
109
+ * The painterly look's style, after the painted crowns of stylized games: smooth light laid over big lobes
110
+ * (no bands), wrapping well round them, a cluster's leaves each a little their own tone, the lit side warm
111
+ * and the shade cool, the colour a step richer than the species', a bright rim against the sun.
112
+ */
113
+ export declare const PAINTERLY_STYLE: TreeStyle;
114
+ /** The sculpted look's style: clay lobes, lit smooth and soft, each dab a little ball on its lobe, a few sprigs. */
115
+ export declare const SCULPTED_STYLE: TreeStyle;
116
+ /** Each look's own style, which `trees.style` starts as. */
117
+ export declare const LOOK_STYLES: Readonly<Record<TreeLook, TreeStyle>>;
118
+ /** The range each of a style's numbers keeps to (and the step a slider takes over it). */
119
+ export declare const STYLE_RANGES: Readonly<Record<keyof TreeStyle, {
120
+ min: number;
121
+ max: number;
122
+ step: number;
123
+ }>>;
124
+ /** What is wrong with a style: every number there, finite, and in its range. Empty if nothing. */
125
+ export declare function checkStyle(style: TreeStyle): string[];
126
+ /**
127
+ * How a look's crown is gathered into lobes, the masses its light is laid over: a lobe is about `share` of
128
+ * the crown's mean radius round, and a crown has `least` to `most` of them.
129
+ */
130
+ export declare const LOOK_LOBES: Readonly<Record<TreeLook, {
131
+ share: number;
132
+ least: number;
133
+ most: number;
134
+ }>>;
135
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAQA,uGAAuG;AACvG,MAAM,WAAW,SAAS;IACxB,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,mHAAmH;IACnH,KAAK,EAAE,MAAM,CAAC;IACd,kHAAkH;IAClH,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,kIAAkI;IAClI,WAAW,EAAE,MAA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H,eAAO,MAAM,eAAe,EAAE,SAAyX,CAAC;AAExZ,oHAAoH;AACpH,eAAO,MAAM,cAAc,EAAE,SAA8X,CAAC;AAE5Z,4DAA4D;AAC5D,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAuG,CAAC;AAEtK,0FAA0F;AAC1F,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BtG,CAAC;AAEF,kGAAkG;AAClG,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,EAAE,CAQrD;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAKjG,CAAC"}
package/lib/styles.js ADDED
@@ -0,0 +1,79 @@
1
+ // How the trees are drawn, apart from what they are: a style is a row of
2
+ // numbers, read each frame, and a look is the set of pieces a style draws
3
+ // with (dabs of paint, clusters of leaves, soft lobes, leaf cards), chosen
4
+ // when the trees are made. Each look starts from its own style; any style's
5
+ // numbers can be changed while the trees stand.
6
+ //
7
+ // Plain data and arithmetic, no three: the tests read it as it is.
8
+ export const TREE_LOOKS = ["stylized", "painterly", "sculpted", "real"];
9
+ /** The painted look's style (and every look's, for the numbers it does not use). */
10
+ export const DEFAULT_STYLE = { steps: 0.75, bands: 3, round: 0.45, jitter: 0.35, dabScale: 1, through: 0.5, throughPower: 4, throughWarp: 0.1, throughVary: 0.4, moss: 0.25, lichen: 0.15, wrap: 0.35, strokes: 0.6, selfShade: 0.5, fullLight: 0.65, bark: 0, faceEye: 0.35, lobe: 0, bulge: 0, warm: 0, cool: 0, chroma: 1, rim: 0, sprigs: 0, bright: 1, leafSize: 0.22, structure: 0.8, density: 0.8, bloom: 0.3 };
11
+ /** The realistic look's style: light as the sun gives it, the crown's shade, light through the leaves, furrowed bark. */
12
+ // (selfShade a half, as the painted look's: the crown's own shade taken in full, through a whole leafy
13
+ // shell, leaves out the light the leaves scatter to one another, and a sunlit crown comes out dark.)
14
+ export const REAL_STYLE = { ...DEFAULT_STYLE, steps: 0, bands: 3, round: 0.3, jitter: 0.15, dabScale: 1, through: 0.9, throughPower: 3.5, throughWarp: 0.2, throughVary: 0.8, moss: 0.55, lichen: 0.45, wrap: 0.3, strokes: 1, selfShade: 0.45, fullLight: 0.9, bark: 1, faceEye: 0.35, structure: 1, density: 1.5 };
15
+ /**
16
+ * The painterly look's style, after the painted crowns of stylized games: smooth light laid over big lobes
17
+ * (no bands), wrapping well round them, a cluster's leaves each a little their own tone, the lit side warm
18
+ * and the shade cool, the colour a step richer than the species', a bright rim against the sun.
19
+ */
20
+ export const PAINTERLY_STYLE = { ...DEFAULT_STYLE, steps: 0, bands: 4, round: 0.15, jitter: 0.5, dabScale: 1.4, through: 0.7, throughPower: 3, throughWarp: 0.12, throughVary: 0.65, moss: 0.45, lichen: 0.3, wrap: 0.5, strokes: 0.85, selfShade: 0.2, fullLight: 0.7, bark: 0, lobe: 0.8, bulge: 0.1, warm: 0.6, cool: 0.6, chroma: 1.35, rim: 0.6, sprigs: 0, bright: 1.7, structure: 0.8, density: 0.8 };
21
+ /** The sculpted look's style: clay lobes, lit smooth and soft, each dab a little ball on its lobe, a few sprigs. */
22
+ export const SCULPTED_STYLE = { ...DEFAULT_STYLE, steps: 0, bands: 4, round: 0, jitter: 0.08, dabScale: 1.5, through: 0.3, throughPower: 3, throughWarp: 0.2, throughVary: 0.4, moss: 0.35, lichen: 0.2, wrap: 0.35, strokes: 0.25, selfShade: 0.25, fullLight: 0.8, bark: 0, lobe: 0.85, bulge: 0.45, warm: 0.45, cool: 0.5, chroma: 1.25, rim: 0.25, sprigs: 0.14, bright: 1.5, structure: 0.6, density: 0.6 };
23
+ /** Each look's own style, which `trees.style` starts as. */
24
+ export const LOOK_STYLES = { stylized: DEFAULT_STYLE, painterly: PAINTERLY_STYLE, sculpted: SCULPTED_STYLE, real: REAL_STYLE };
25
+ /** The range each of a style's numbers keeps to (and the step a slider takes over it). */
26
+ export const STYLE_RANGES = {
27
+ steps: { min: 0, max: 1, step: 0.01 },
28
+ bands: { min: 1, max: 8, step: 1 },
29
+ round: { min: 0, max: 1, step: 0.01 },
30
+ jitter: { min: 0, max: 1, step: 0.01 },
31
+ dabScale: { min: 0.25, max: 2.5, step: 0.01 },
32
+ through: { min: 0, max: 1, step: 0.01 },
33
+ throughPower: { min: 1, max: 16, step: 0.1 },
34
+ throughWarp: { min: 0, max: 1, step: 0.01 },
35
+ throughVary: { min: 0, max: 1, step: 0.01 },
36
+ wrap: { min: 0, max: 1, step: 0.01 },
37
+ strokes: { min: 0, max: 1, step: 0.01 },
38
+ selfShade: { min: 0, max: 1, step: 0.01 },
39
+ fullLight: { min: 0.2, max: 1, step: 0.01 },
40
+ bark: { min: 0, max: 1, step: 0.01 },
41
+ moss: { min: 0, max: 1, step: 0.01 },
42
+ lichen: { min: 0, max: 1, step: 0.01 },
43
+ faceEye: { min: 0, max: 1, step: 0.01 },
44
+ lobe: { min: 0, max: 1, step: 0.01 },
45
+ bulge: { min: 0, max: 1, step: 0.01 },
46
+ warm: { min: 0, max: 1, step: 0.01 },
47
+ cool: { min: 0, max: 1, step: 0.01 },
48
+ chroma: { min: 0, max: 2, step: 0.01 },
49
+ rim: { min: 0, max: 1, step: 0.01 },
50
+ sprigs: { min: 0, max: 0.5, step: 0.01 },
51
+ bright: { min: 0.5, max: 2.5, step: 0.01 },
52
+ leafSize: { min: 0.05, max: 1.5, step: 0.01 },
53
+ structure: { min: 0, max: 1, step: 0.01 },
54
+ density: { min: 0.25, max: 3, step: 0.01 },
55
+ bloom: { min: 0, max: 1, step: 0.01 },
56
+ };
57
+ /** What is wrong with a style: every number there, finite, and in its range. Empty if nothing. */
58
+ export function checkStyle(style) {
59
+ const out = [];
60
+ for (const [key, r] of Object.entries(STYLE_RANGES)) {
61
+ const v = style[key];
62
+ if (typeof v !== "number" || !Number.isFinite(v))
63
+ out.push(`${key} is not a number`);
64
+ else if (v < r.min || v > r.max)
65
+ out.push(`${key} ${v} is outside ${r.min}..${r.max}`);
66
+ }
67
+ return out;
68
+ }
69
+ /**
70
+ * How a look's crown is gathered into lobes, the masses its light is laid over: a lobe is about `share` of
71
+ * the crown's mean radius round, and a crown has `least` to `most` of them.
72
+ */
73
+ export const LOOK_LOBES = {
74
+ stylized: { share: 0.5, least: 2, most: 24 },
75
+ painterly: { share: 0.52, least: 2, most: 20 },
76
+ sculpted: { share: 0.4, least: 3, most: 32 },
77
+ real: { share: 0.5, least: 2, most: 24 },
78
+ };
79
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,0EAA0E;AAC1E,2EAA2E;AAC3E,4EAA4E;AAC5E,gDAAgD;AAChD,EAAE;AACF,mEAAmE;AA0GnE,MAAM,CAAC,MAAM,UAAU,GAAwB,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAE7F,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAc,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,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E,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC5C,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC9C,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC5C,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;CACzC,CAAC","sourcesContent":["// How the trees are drawn, apart from what they are: a style is a row of\n// numbers, read each frame, and a look is the set of pieces a style draws\n// with (dabs of paint, clusters of leaves, soft lobes, leaf cards), chosen\n// when the trees are made. Each look starts from its own style; any style's\n// numbers can be changed while the trees stand.\n//\n// Plain data and arithmetic, no three: the tests read it as it is.\n\n/** How the trees are drawn, apart from what they are. Change it at any time: it is read each frame. */\nexport interface TreeStyle {\n /** How far a crown's light is laid in flat bands, as paint is, 0 (smooth) to 1 (bands only). */\n steps: number;\n /** How many bands of light, from shade to sun. */\n bands: number;\n /** How round each clump of leaves is lit, 0 (as the crown's outside faces) to 1 (each clump a ball of its own). */\n round: number;\n /** How much one dab differs in tone from the next (and, in a cluster of leaves, one leaf from the next), 0..1. */\n jitter: number;\n /** How big the dabs are, beside what covers their clump: 1 as grown. */\n dabScale: number;\n /** How much sunlight comes through the leaves to an eye looking towards the sun, 0..1. */\n through: number;\n /**\n * How tightly the light through the leaves gathers about the sun, as the eye looks towards it: the power\n * of Barré-Brisebois's view term (GDC 2011). Low, a crown glows from wide of the sun; high, only round it.\n */\n throughPower: number;\n /** How far a leaf's facing bends the light through it, 0..1 (the model's distortion): more, the glow follows the crown's form. */\n throughWarp: number;\n /**\n * How much the light through the leaves varies, 0..1: by how deep in the crown a clump is, how much sun\n * reaches it there (Monsi and Saeki), and leaf by leaf (each its own thickness). 0, every backlit leaf\n * glows the same lime green.\n */\n throughVary: number;\n /** How far the light wraps round past the side of a clump facing away from the sun, 0..1. */\n wrap: number;\n /** How strongly the brush's strokes (or each leaf's own tone in a cluster) show in a dab, 0..1. */\n strokes: number;\n /**\n * How far a crown shades itself, 0..1: 1, as much as the light lost through its leaves makes it (Monsi and\n * Saeki); 0, not at all, every leaf facing the sun as lit as the crown's outside. A painter keeps less of it\n * than there is.\n */\n selfShade: number;\n /** How square to the sun a leaf must face to take all of it: 0.65 lights a form as a painter does, 1 as the sun does. */\n fullLight: number;\n /** How furrowed the bark is, 0 (smooth, a painted trunk) to 1. */\n bark: number;\n /**\n * How much moss the wood carries, 0..1: on what faces up, in the grooves between a trunk's buttresses,\n * low on the trunk and on its side away from the sun.\n */\n moss: number;\n /** Crustose & foliose bark lichen cover on rough trunks and scaffold limbs above the damp root collar, 0..1. */\n lichen: number;\n /** How far a realistic tree's near leaf cards turn towards the eye, 0..1: none at all shows some edge-on as slivers. */\n faceEye: number;\n /**\n * How far a crown is lit as a few big masses, 0..1: each of its lobes (its clumps gathered into a handful,\n * `lobes.ts`) shaded as a ball seen from the eye, pixel by pixel, so the light runs smoothly across all the\n * dabs of a lobe. 0: each dab lit as one stroke, as the crown's outside faces where it is.\n */\n lobe: number;\n /** How far each dab is lit as a small ball of its own, pixel by pixel, over its lobe, 0..1 (the sculpted look's bubbles). */\n bulge: number;\n /** How far the light on the leaves turns warm, towards a yellow-green, 0..1 (the sun's own tint stays the host's). */\n warm: number;\n /** How far the shade turns cool, towards a teal blue-green, 0..1 (over the host's shade tint). */\n cool: number;\n /** How saturated the leaves' colour is beside the species', 0 (grey) to 2: 1 as the species has it. */\n chroma: number;\n /** How bright the rim of a lobe is against the light, 0..1: light through its thin edge, and the sky behind it. */\n rim: number;\n /** In a look whose marks have them (sculpted), the share of a near crown's dabs drawn as sprigs of leaves, 0..1. */\n sprigs: number;\n /** How bright the sunlit side of a crown is beside its shade, 1 as the sun gives it: a painter's light is brighter. */\n bright: number;\n /**\n * The painterly look: how long a broad leaf is at most, in metres (other kinds keep to theirs beside it, a\n * palm's fronds far longer). A dab whose leaves would be longer carries smaller ones, more of them.\n */\n leafSize: number;\n /**\n * How far a crown's light comes from its own leaves and wood (light.ts: each grown tree's box of cells, the sun\n * marched through it), 0..1, and the rest from its ellipsoid: 1, each bough shades the one below and the\n * sun comes through the gaps between; 0, every leaf at one depth in the crown lit alike.\n */\n structure: number;\n /** How thick the leaves are to the light in that box, beside what the species' crown carries: 1 as grown. */\n density: number;\n /**\n * How far in flower the trees are, 0..1, where their pictures show flowers (the realistic look: a gorse's yellow\n * pea flowers, `ScanLook.flowers`): the share of its sprays in flower, each by a number of its own; 1 in full\n * flower, as in spring, 0 out of it, the flowers gone and the spines left. It is the bloom when the host gives no\n * day of the year (`TreeEnvironment.day`); given one, each flowering species' own year says (`ScanLook.flowering`).\n * 0.3: a gorse's few flowers over the year, a third of it in full flower and much of it not.\n */\n bloom: number;\n}\n\n/**\n * How the trees are drawn, chosen when they are made (the pieces differ, not only the light):\n * - `stylized`: crowns laid in dabs of paint, lit in bands (the painted look);\n * - `painterly`: crowns of small, crisp clusters of leaves, the light laid over them as a few big soft masses,\n * warm where lit and cool in shade;\n * - `sculpted`: crowns as soft clay lobes, a few sprigs of leaves on them;\n * - `real`: near crowns of leaf cards set in the crown, each a spray of the species' leaves, and far ones of\n * the same sprays.\n */\nexport type TreeLook = \"stylized\" | \"painterly\" | \"sculpted\" | \"real\";\n\nexport const TREE_LOOKS: readonly TreeLook[] = [\"stylized\", \"painterly\", \"sculpted\", \"real\"];\n\n/** The painted look's style (and every look's, for the numbers it does not use). */\nexport const DEFAULT_STYLE: TreeStyle = { steps: 0.75, bands: 3, round: 0.45, jitter: 0.35, dabScale: 1, through: 0.5, throughPower: 4, throughWarp: 0.1, throughVary: 0.4, moss: 0.25, lichen: 0.15, wrap: 0.35, strokes: 0.6, selfShade: 0.5, fullLight: 0.65, bark: 0, faceEye: 0.35, lobe: 0, bulge: 0, warm: 0, cool: 0, chroma: 1, rim: 0, sprigs: 0, bright: 1, leafSize: 0.22, structure: 0.8, density: 0.8, bloom: 0.3 };\n\n/** The realistic look's style: light as the sun gives it, the crown's shade, light through the leaves, furrowed bark. */\n// (selfShade a half, as the painted look's: the crown's own shade taken in full, through a whole leafy\n// shell, leaves out the light the leaves scatter to one another, and a sunlit crown comes out dark.)\nexport const REAL_STYLE: TreeStyle = { ...DEFAULT_STYLE, steps: 0, bands: 3, round: 0.3, jitter: 0.15, dabScale: 1, through: 0.9, throughPower: 3.5, throughWarp: 0.2, throughVary: 0.8, moss: 0.55, lichen: 0.45, wrap: 0.3, strokes: 1, selfShade: 0.45, fullLight: 0.9, bark: 1, faceEye: 0.35, structure: 1, density: 1.5 };\n\n/**\n * The painterly look's style, after the painted crowns of stylized games: smooth light laid over big lobes\n * (no bands), wrapping well round them, a cluster's leaves each a little their own tone, the lit side warm\n * and the shade cool, the colour a step richer than the species', a bright rim against the sun.\n */\nexport const PAINTERLY_STYLE: TreeStyle = { ...DEFAULT_STYLE, steps: 0, bands: 4, round: 0.15, jitter: 0.5, dabScale: 1.4, through: 0.7, throughPower: 3, throughWarp: 0.12, throughVary: 0.65, moss: 0.45, lichen: 0.3, wrap: 0.5, strokes: 0.85, selfShade: 0.2, fullLight: 0.7, bark: 0, lobe: 0.8, bulge: 0.1, warm: 0.6, cool: 0.6, chroma: 1.35, rim: 0.6, sprigs: 0, bright: 1.7, structure: 0.8, density: 0.8 };\n\n/** The sculpted look's style: clay lobes, lit smooth and soft, each dab a little ball on its lobe, a few sprigs. */\nexport const SCULPTED_STYLE: TreeStyle = { ...DEFAULT_STYLE, steps: 0, bands: 4, round: 0, jitter: 0.08, dabScale: 1.5, through: 0.3, throughPower: 3, throughWarp: 0.2, throughVary: 0.4, moss: 0.35, lichen: 0.2, wrap: 0.35, strokes: 0.25, selfShade: 0.25, fullLight: 0.8, bark: 0, lobe: 0.85, bulge: 0.45, warm: 0.45, cool: 0.5, chroma: 1.25, rim: 0.25, sprigs: 0.14, bright: 1.5, structure: 0.6, density: 0.6 };\n\n/** Each look's own style, which `trees.style` starts as. */\nexport const LOOK_STYLES: Readonly<Record<TreeLook, TreeStyle>> = { stylized: DEFAULT_STYLE, painterly: PAINTERLY_STYLE, sculpted: SCULPTED_STYLE, real: REAL_STYLE };\n\n/** The range each of a style's numbers keeps to (and the step a slider takes over it). */\nexport const STYLE_RANGES: Readonly<Record<keyof TreeStyle, { min: number; max: number; step: number }>> = {\n steps: { min: 0, max: 1, step: 0.01 },\n bands: { min: 1, max: 8, step: 1 },\n round: { min: 0, max: 1, step: 0.01 },\n jitter: { min: 0, max: 1, step: 0.01 },\n dabScale: { min: 0.25, max: 2.5, step: 0.01 },\n through: { min: 0, max: 1, step: 0.01 },\n throughPower: { min: 1, max: 16, step: 0.1 },\n throughWarp: { min: 0, max: 1, step: 0.01 },\n throughVary: { min: 0, max: 1, step: 0.01 },\n wrap: { min: 0, max: 1, step: 0.01 },\n strokes: { min: 0, max: 1, step: 0.01 },\n selfShade: { min: 0, max: 1, step: 0.01 },\n fullLight: { min: 0.2, max: 1, step: 0.01 },\n bark: { min: 0, max: 1, step: 0.01 },\n moss: { min: 0, max: 1, step: 0.01 },\n lichen: { min: 0, max: 1, step: 0.01 },\n faceEye: { min: 0, max: 1, step: 0.01 },\n lobe: { min: 0, max: 1, step: 0.01 },\n bulge: { min: 0, max: 1, step: 0.01 },\n warm: { min: 0, max: 1, step: 0.01 },\n cool: { min: 0, max: 1, step: 0.01 },\n chroma: { min: 0, max: 2, step: 0.01 },\n rim: { min: 0, max: 1, step: 0.01 },\n sprigs: { min: 0, max: 0.5, step: 0.01 },\n bright: { min: 0.5, max: 2.5, step: 0.01 },\n leafSize: { min: 0.05, max: 1.5, step: 0.01 },\n structure: { min: 0, max: 1, step: 0.01 },\n density: { min: 0.25, max: 3, step: 0.01 },\n bloom: { min: 0, max: 1, step: 0.01 },\n};\n\n/** What is wrong with a style: every number there, finite, and in its range. Empty if nothing. */\nexport function checkStyle(style: TreeStyle): string[] {\n const out: string[] = [];\n for (const [key, r] of Object.entries(STYLE_RANGES) as [keyof TreeStyle, { min: number; max: number }][]) {\n const v = style[key];\n if (typeof v !== \"number\" || !Number.isFinite(v)) out.push(`${key} is not a number`);\n else if (v < r.min || v > r.max) out.push(`${key} ${v} is outside ${r.min}..${r.max}`);\n }\n return out;\n}\n\n/**\n * How a look's crown is gathered into lobes, the masses its light is laid over: a lobe is about `share` of\n * the crown's mean radius round, and a crown has `least` to `most` of them.\n */\nexport const LOOK_LOBES: Readonly<Record<TreeLook, { share: number; least: number; most: number }>> = {\n stylized: { share: 0.5, least: 2, most: 24 },\n painterly: { share: 0.52, least: 2, most: 20 },\n sculpted: { share: 0.4, least: 3, most: 32 },\n real: { share: 0.5, least: 2, most: 24 },\n};\n"]}