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/scatter.js ADDED
@@ -0,0 +1,186 @@
1
+ // Procedural landscape & biome scattering (CPU and WebGPU compute) producing
2
+ // packed `TREE_STRIDE` arrays ready for `createTrees`.
3
+ import * as THREE from "three/webgpu";
4
+ import { Fn, If, atomicAdd, atomicStore, clamp, float, floor, instanceIndex, int, ivec2, max, min, mix, storage, textureLoad, uint, uniform, vec2 } from "three/tsl";
5
+ import { TREE_STRIDE, hash01 } from "./variants.js";
6
+ /**
7
+ * Deterministic jittered-grid biome scatterer. Emits a tight `Float32Array` with
8
+ * `TREE_STRIDE` floats per tree ready to pass into `createTrees({ trees, species })`.
9
+ */
10
+ export function scatterTrees(options) {
11
+ const spacing = Math.max(0.5, options.spacing);
12
+ const jitter = Math.min(1, Math.max(0, options.jitter ?? 0.85));
13
+ const seed = options.seed ?? 1337;
14
+ const cols = Math.max(1, Math.floor(options.width / spacing));
15
+ const rows = Math.max(1, Math.floor(options.depth / spacing));
16
+ const cap = options.maxTrees ?? cols * rows;
17
+ const heightAt = options.heightAt ?? (() => 0);
18
+ const moistureAt = options.moistureAt ?? (() => 0.5);
19
+ const eps = Math.min(1, spacing * 0.25);
20
+ const raw = [];
21
+ let emitted = 0;
22
+ for (let r = 0; r < rows && emitted < cap; r++) {
23
+ for (let c = 0; c < cols && emitted < cap; c++) {
24
+ const cellId = r * cols + c;
25
+ const jx = (hash01(cellId, seed + 11) - 0.5) * jitter;
26
+ const jz = (hash01(cellId, seed + 23) - 0.5) * jitter;
27
+ const x = options.x0 + (c + 0.5 + jx) * spacing;
28
+ const z = options.z0 + (r + 0.5 + jz) * spacing;
29
+ if (options.allowAt && !options.allowAt(x, z))
30
+ continue;
31
+ const y = heightAt(x, z);
32
+ const dhx = (heightAt(x + eps, z) - heightAt(x - eps, z)) / (2 * eps);
33
+ const dhz = (heightAt(x, z + eps) - heightAt(x, z - eps)) / (2 * eps);
34
+ const slopeDeg = (Math.atan(Math.hypot(dhx, dhz)) * 180) / Math.PI;
35
+ const moisture = moistureAt(x, z);
36
+ let totalWeight = 0;
37
+ const eligible = [];
38
+ for (const b of options.biomes) {
39
+ if (b.weight <= 0 || b.species < 0 || b.species >= options.species.length)
40
+ continue;
41
+ if (b.minElevation !== undefined && y < b.minElevation)
42
+ continue;
43
+ if (b.maxElevation !== undefined && y > b.maxElevation)
44
+ continue;
45
+ if (b.maxSlopeDeg !== undefined && slopeDeg > b.maxSlopeDeg)
46
+ continue;
47
+ if (b.moistureRange && (moisture < b.moistureRange[0] || moisture > b.moistureRange[1]))
48
+ continue;
49
+ totalWeight += b.weight;
50
+ eligible.push({ b, w: b.weight });
51
+ }
52
+ if (totalWeight <= 0)
53
+ continue;
54
+ let pick = hash01(cellId, seed + 37) * totalWeight;
55
+ let chosen = eligible[eligible.length - 1].b;
56
+ for (const e of eligible) {
57
+ pick -= e.w;
58
+ if (pick <= 0) {
59
+ chosen = e.b;
60
+ break;
61
+ }
62
+ }
63
+ const sp = options.species[chosen.species];
64
+ const sr = chosen.scaleRange;
65
+ const scale = sr ? sr[0] + hash01(cellId, seed + 53) * (sr[1] - sr[0]) : NaN;
66
+ const yaw = hash01(cellId, seed + 71) * Math.PI * 2;
67
+ const treeSeed = Math.floor(hash01(cellId, seed + 97) * 1_000_000);
68
+ raw.push(x, y, z, chosen.species, Number.isFinite(scale) ? sp.height * scale : NaN, Number.isFinite(scale) ? sp.crownRadius * scale : NaN, Number.isFinite(scale) ? sp.crownBase * scale : NaN, Number.isFinite(scale) ? sp.trunkRadius * scale : NaN, yaw, treeSeed);
69
+ emitted++;
70
+ }
71
+ }
72
+ return Float32Array.from(raw);
73
+ }
74
+ /**
75
+ * WebGPU compute scatterer sampling a terrain height/moisture texture in parallel,
76
+ * filtering by elevation and slope, and compacting `TREE_STRIDE` instances via `atomicAdd`.
77
+ */
78
+ export function createGpuScatter(options) {
79
+ const spacing = Math.max(0.5, options.spacing);
80
+ const cols = Math.max(1, Math.floor(options.width / spacing));
81
+ const rows = Math.max(1, Math.floor(options.depth / spacing));
82
+ const cells = cols * rows;
83
+ const maxTrees = Math.max(1, options.maxTrees);
84
+ const seed = options.seed ?? 42;
85
+ const packedAttr = new THREE.StorageBufferAttribute(new Float32Array(maxTrees * TREE_STRIDE), 1);
86
+ const countAttr = new THREE.StorageBufferAttribute(new Uint32Array(1), 1);
87
+ const packedW = storage(packedAttr, "float", maxTrees * TREE_STRIDE);
88
+ const countAtomic = storage(countAttr, "uint", 1).toAtomic();
89
+ const uArea = uniform(new THREE.Vector4(options.x0, options.z0, options.width, options.depth));
90
+ const uRules = uniform(new THREE.Vector4(options.minElevation ?? -1e6, options.maxElevation ?? 1e6, options.maxSlopeCos ?? 0.65, Math.max(1, options.speciesCount)));
91
+ const texW = Math.max(1, options.terrainTex.image?.width ?? 64);
92
+ const texH = Math.max(1, options.terrainTex.image?.height ?? 64);
93
+ const hashNode = (n, s) => {
94
+ const h0 = n.bitXor(uint(s)).mul(uint(0x9e3779b1));
95
+ const h1 = h0.bitXor(h0.shiftRight(uint(16))).mul(uint(0x7feb352d));
96
+ const h2 = h1.bitXor(h1.shiftRight(uint(15))).mul(uint(0x846ca68b));
97
+ return float(h2.bitXor(h2.shiftRight(uint(16))).bitAnd(uint(0xffff))).div(65536);
98
+ };
99
+ // Manual bilinear textureLoad avoids requiring optional `float32-filterable` on rgba32float terrain textures.
100
+ const sampleTerrain = (uvCoord) => {
101
+ const fx = clamp(uvCoord.x, 0, 1).mul(texW - 1);
102
+ const fy = clamp(uvCoord.y, 0, 1).mul(texH - 1);
103
+ const x0 = int(floor(fx));
104
+ const y0 = int(floor(fy));
105
+ const x1 = int(min(floor(fx).add(1), float(texW - 1)));
106
+ const y1 = int(min(floor(fy).add(1), float(texH - 1)));
107
+ const tx = fx.fract();
108
+ const ty = fy.fract();
109
+ const s00 = textureLoad(options.terrainTex, ivec2(x0, y0), int(0)).rg;
110
+ const s10 = textureLoad(options.terrainTex, ivec2(x1, y0), int(0)).rg;
111
+ const s01 = textureLoad(options.terrainTex, ivec2(x0, y1), int(0)).rg;
112
+ const s11 = textureLoad(options.terrainTex, ivec2(x1, y1), int(0)).rg;
113
+ return mix(mix(s00, s10, tx), mix(s01, s11, tx), ty);
114
+ };
115
+ const clearPass = Fn(() => {
116
+ If(instanceIndex.equal(uint(0)), () => {
117
+ atomicStore(countAtomic.element(uint(0)), uint(0));
118
+ });
119
+ })().compute(1);
120
+ const scatterPass = Fn(() => {
121
+ const id = instanceIndex;
122
+ If(id.lessThan(uint(cells)), () => {
123
+ const r = id.div(uint(cols));
124
+ const c = id.sub(r.mul(uint(cols)));
125
+ const jx = hashNode(id, seed + 11).sub(0.5).mul(0.85);
126
+ const jz = hashNode(id, seed + 23).sub(0.5).mul(0.85);
127
+ const x = uArea.x.add(float(c).add(0.5).add(jx).mul(spacing));
128
+ const z = uArea.y.add(float(r).add(0.5).add(jz).mul(spacing));
129
+ const uv = clamp(vec2(x.sub(uArea.x).div(uArea.z), z.sub(uArea.y).div(uArea.w)), 0.002, 0.998);
130
+ const sample = sampleTerrain(uv);
131
+ const elev = sample.r;
132
+ const du = float(1 / Math.max(texW - 1, 1));
133
+ const dv = float(1 / Math.max(texH - 1, 1));
134
+ const hx = sampleTerrain(uv.add(vec2(du, 0))).r.sub(elev).div(max(uArea.z.mul(du), float(0.1)));
135
+ const hz = sampleTerrain(uv.add(vec2(0, dv))).r.sub(elev).div(max(uArea.w.mul(dv), float(0.1)));
136
+ const slopeCos = float(1).div(hx.mul(hx).add(hz.mul(hz)).add(1).sqrt());
137
+ const ok = elev.greaterThanEqual(uRules.x).and(elev.lessThanEqual(uRules.y)).and(slopeCos.greaterThanEqual(uRules.z));
138
+ If(ok, () => {
139
+ const slot = atomicAdd(countAtomic.element(uint(0)), uint(1));
140
+ If(slot.lessThan(uint(maxTrees)), () => {
141
+ const base = slot.mul(uint(TREE_STRIDE));
142
+ const sp = floor(hashNode(id, seed + 37).mul(uRules.w.sub(0.001)));
143
+ const yaw = hashNode(id, seed + 71).mul(Math.PI * 2);
144
+ const tSeed = floor(hashNode(id, seed + 97).mul(1_000_000));
145
+ // Negative sentinels in size slots are converted to NaN on readback (avoids WGSL compile-time 0/0).
146
+ const unset = float(-1);
147
+ packedW.element(base).assign(x);
148
+ packedW.element(base.add(1)).assign(elev);
149
+ packedW.element(base.add(2)).assign(z);
150
+ packedW.element(base.add(3)).assign(sp);
151
+ packedW.element(base.add(4)).assign(unset);
152
+ packedW.element(base.add(5)).assign(unset);
153
+ packedW.element(base.add(6)).assign(unset);
154
+ packedW.element(base.add(7)).assign(unset);
155
+ packedW.element(base.add(8)).assign(yaw);
156
+ packedW.element(base.add(9)).assign(tSeed);
157
+ });
158
+ });
159
+ });
160
+ })().compute(cells);
161
+ return {
162
+ packedAttr,
163
+ countAttr,
164
+ async run(renderer) {
165
+ await renderer.compute([clearPass, scatterPass]);
166
+ const countBuf = new Uint32Array(await renderer.getArrayBufferAsync(countAttr));
167
+ const count = Math.min(maxTrees, countBuf[0] ?? 0);
168
+ const packedAll = new Float32Array(await renderer.getArrayBufferAsync(packedAttr));
169
+ const packed = packedAll.slice(0, count * TREE_STRIDE);
170
+ for (let i = 0; i < count; i++) {
171
+ const o = i * TREE_STRIDE;
172
+ for (let k = 4; k <= 7; k++)
173
+ if (packed[o + k] <= 0)
174
+ packed[o + k] = NaN;
175
+ }
176
+ return { count, packed };
177
+ },
178
+ dispose() {
179
+ clearPass.dispose();
180
+ scatterPass.dispose();
181
+ packedAttr.dispose();
182
+ countAttr.dispose();
183
+ },
184
+ };
185
+ }
186
+ //# sourceMappingURL=scatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scatter.js","sourceRoot":"","sources":["../src/scatter.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uDAAuD;AAEvD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAErK,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAoCpD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAuB;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;IAClC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;IAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,IA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CAAC;YACrB,SAAS,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Procedural landscape & biome scattering (CPU and WebGPU compute) producing\n// packed `TREE_STRIDE` arrays ready for `createTrees`.\n\nimport * as THREE from \"three/webgpu\";\nimport { Fn, If, atomicAdd, atomicStore, clamp, float, floor, instanceIndex, int, ivec2, max, min, mix, storage, textureLoad, uint, uniform, vec2 } from \"three/tsl\";\nimport { type TreeSpecies } from \"./species.ts\";\nimport { TREE_STRIDE, hash01 } from \"./variants.ts\";\n\nexport interface ScatterBiome {\n /** Species row index into `species`. */\n species: number;\n /** Relative selection weight when multiple biomes overlap. */\n weight: number;\n minElevation?: number;\n maxElevation?: number;\n /** Maximum terrain slope in degrees where this species grows. */\n maxSlopeDeg?: number;\n /** Moisture range in `[0, 1]`. */\n moistureRange?: [number, number];\n /** Optional random height/crown scale multiplier `[min, max]`. */\n scaleRange?: [number, number];\n}\n\nexport interface ScatterOptions {\n x0: number;\n z0: number;\n width: number;\n depth: number;\n /** Nominal spacing between candidate grid cells (m). */\n spacing: number;\n seed?: number;\n /** Jitter within each cell, 0..1 (default 0.85). */\n jitter?: number;\n /** Cap on total emitted trees. */\n maxTrees?: number;\n biomes: readonly ScatterBiome[];\n heightAt?: (x: number, z: number) => number;\n moistureAt?: (x: number, z: number) => number;\n allowAt?: (x: number, z: number) => boolean;\n species: readonly TreeSpecies[];\n}\n\n/**\n * Deterministic jittered-grid biome scatterer. Emits a tight `Float32Array` with\n * `TREE_STRIDE` floats per tree ready to pass into `createTrees({ trees, species })`.\n */\nexport function scatterTrees(options: ScatterOptions): Float32Array {\n const spacing = Math.max(0.5, options.spacing);\n const jitter = Math.min(1, Math.max(0, options.jitter ?? 0.85));\n const seed = options.seed ?? 1337;\n const cols = Math.max(1, Math.floor(options.width / spacing));\n const rows = Math.max(1, Math.floor(options.depth / spacing));\n const cap = options.maxTrees ?? cols * rows;\n const heightAt = options.heightAt ?? (() => 0);\n const moistureAt = options.moistureAt ?? (() => 0.5);\n const eps = Math.min(1, spacing * 0.25);\n\n const raw: number[] = [];\n let emitted = 0;\n\n for (let r = 0; r < rows && emitted < cap; r++) {\n for (let c = 0; c < cols && emitted < cap; c++) {\n const cellId = r * cols + c;\n const jx = (hash01(cellId, seed + 11) - 0.5) * jitter;\n const jz = (hash01(cellId, seed + 23) - 0.5) * jitter;\n const x = options.x0 + (c + 0.5 + jx) * spacing;\n const z = options.z0 + (r + 0.5 + jz) * spacing;\n if (options.allowAt && !options.allowAt(x, z)) continue;\n\n const y = heightAt(x, z);\n const dhx = (heightAt(x + eps, z) - heightAt(x - eps, z)) / (2 * eps);\n const dhz = (heightAt(x, z + eps) - heightAt(x, z - eps)) / (2 * eps);\n const slopeDeg = (Math.atan(Math.hypot(dhx, dhz)) * 180) / Math.PI;\n const moisture = moistureAt(x, z);\n\n let totalWeight = 0;\n const eligible: { b: ScatterBiome; w: number }[] = [];\n for (const b of options.biomes) {\n if (b.weight <= 0 || b.species < 0 || b.species >= options.species.length) continue;\n if (b.minElevation !== undefined && y < b.minElevation) continue;\n if (b.maxElevation !== undefined && y > b.maxElevation) continue;\n if (b.maxSlopeDeg !== undefined && slopeDeg > b.maxSlopeDeg) continue;\n if (b.moistureRange && (moisture < b.moistureRange[0] || moisture > b.moistureRange[1])) continue;\n totalWeight += b.weight;\n eligible.push({ b, w: b.weight });\n }\n if (totalWeight <= 0) continue;\n\n let pick = hash01(cellId, seed + 37) * totalWeight;\n let chosen = eligible[eligible.length - 1].b;\n for (const e of eligible) {\n pick -= e.w;\n if (pick <= 0) {\n chosen = e.b;\n break;\n }\n }\n\n const sp = options.species[chosen.species];\n const sr = chosen.scaleRange;\n const scale = sr ? sr[0] + hash01(cellId, seed + 53) * (sr[1] - sr[0]) : NaN;\n const yaw = hash01(cellId, seed + 71) * Math.PI * 2;\n const treeSeed = Math.floor(hash01(cellId, seed + 97) * 1_000_000);\n\n raw.push(\n x,\n y,\n z,\n chosen.species,\n Number.isFinite(scale) ? sp.height * scale : NaN,\n Number.isFinite(scale) ? sp.crownRadius * scale : NaN,\n Number.isFinite(scale) ? sp.crownBase * scale : NaN,\n Number.isFinite(scale) ? sp.trunkRadius * scale : NaN,\n yaw,\n treeSeed,\n );\n emitted++;\n }\n }\n\n return Float32Array.from(raw);\n}\n\nexport interface GpuScatterOptions {\n x0: number;\n z0: number;\n width: number;\n depth: number;\n spacing: number;\n maxTrees: number;\n /** Texture storing elevation in `.r` (metres) and moisture `[0..1]` in `.g`. */\n terrainTex: THREE.DataTexture;\n minElevation?: number;\n maxElevation?: number;\n maxSlopeCos?: number;\n speciesCount: number;\n seed?: number;\n}\n\nexport interface GpuScatter {\n readonly packedAttr: THREE.StorageBufferAttribute;\n readonly countAttr: THREE.StorageBufferAttribute;\n /** Dispatch compute scatter and return `{ count, packed }` read back on CPU. */\n run(renderer: THREE.WebGPURenderer): Promise<{ count: number; packed: Float32Array }>;\n dispose(): void;\n}\n\n/**\n * WebGPU compute scatterer sampling a terrain height/moisture texture in parallel,\n * filtering by elevation and slope, and compacting `TREE_STRIDE` instances via `atomicAdd`.\n */\nexport function createGpuScatter(options: GpuScatterOptions): GpuScatter {\n const spacing = Math.max(0.5, options.spacing);\n const cols = Math.max(1, Math.floor(options.width / spacing));\n const rows = Math.max(1, Math.floor(options.depth / spacing));\n const cells = cols * rows;\n const maxTrees = Math.max(1, options.maxTrees);\n const seed = options.seed ?? 42;\n\n const packedAttr = new THREE.StorageBufferAttribute(new Float32Array(maxTrees * TREE_STRIDE), 1);\n const countAttr = new THREE.StorageBufferAttribute(new Uint32Array(1), 1);\n const packedW = storage(packedAttr, \"float\", maxTrees * TREE_STRIDE);\n const countAtomic = storage(countAttr, \"uint\", 1).toAtomic();\n\n const uArea = uniform(new THREE.Vector4(options.x0, options.z0, options.width, options.depth));\n const uRules = uniform(new THREE.Vector4(\n options.minElevation ?? -1e6,\n options.maxElevation ?? 1e6,\n options.maxSlopeCos ?? 0.65,\n Math.max(1, options.speciesCount),\n ));\n\n const texW = Math.max(1, options.terrainTex.image?.width ?? 64);\n const texH = Math.max(1, options.terrainTex.image?.height ?? 64);\n\n const hashNode = (n: THREE.Node<\"uint\">, s: number) => {\n const h0 = n.bitXor(uint(s)).mul(uint(0x9e3779b1));\n const h1 = h0.bitXor(h0.shiftRight(uint(16))).mul(uint(0x7feb352d));\n const h2 = h1.bitXor(h1.shiftRight(uint(15))).mul(uint(0x846ca68b));\n return float(h2.bitXor(h2.shiftRight(uint(16))).bitAnd(uint(0xffff))).div(65536);\n };\n\n // Manual bilinear textureLoad avoids requiring optional `float32-filterable` on rgba32float terrain textures.\n const sampleTerrain = (uvCoord: THREE.Node<\"vec2\">) => {\n const fx = clamp(uvCoord.x, 0, 1).mul(texW - 1);\n const fy = clamp(uvCoord.y, 0, 1).mul(texH - 1);\n const x0 = int(floor(fx));\n const y0 = int(floor(fy));\n const x1 = int(min(floor(fx).add(1), float(texW - 1)));\n const y1 = int(min(floor(fy).add(1), float(texH - 1)));\n const tx = fx.fract();\n const ty = fy.fract();\n const s00 = textureLoad(options.terrainTex, ivec2(x0, y0), int(0)).rg;\n const s10 = textureLoad(options.terrainTex, ivec2(x1, y0), int(0)).rg;\n const s01 = textureLoad(options.terrainTex, ivec2(x0, y1), int(0)).rg;\n const s11 = textureLoad(options.terrainTex, ivec2(x1, y1), int(0)).rg;\n return mix(mix(s00, s10, tx), mix(s01, s11, tx), ty);\n };\n\n const clearPass = Fn(() => {\n If(instanceIndex.equal(uint(0)), () => {\n atomicStore(countAtomic.element(uint(0)), uint(0));\n });\n })().compute(1);\n\n const scatterPass = Fn(() => {\n const id = instanceIndex;\n If(id.lessThan(uint(cells)), () => {\n const r = id.div(uint(cols));\n const c = id.sub(r.mul(uint(cols)));\n const jx = hashNode(id, seed + 11).sub(0.5).mul(0.85);\n const jz = hashNode(id, seed + 23).sub(0.5).mul(0.85);\n const x = uArea.x.add(float(c).add(0.5).add(jx).mul(spacing));\n const z = uArea.y.add(float(r).add(0.5).add(jz).mul(spacing));\n const uv = clamp(vec2(x.sub(uArea.x).div(uArea.z), z.sub(uArea.y).div(uArea.w)), 0.002, 0.998);\n const sample = sampleTerrain(uv);\n const elev = sample.r;\n const du = float(1 / Math.max(texW - 1, 1));\n const dv = float(1 / Math.max(texH - 1, 1));\n const hx = sampleTerrain(uv.add(vec2(du, 0))).r.sub(elev).div(max(uArea.z.mul(du), float(0.1)));\n const hz = sampleTerrain(uv.add(vec2(0, dv))).r.sub(elev).div(max(uArea.w.mul(dv), float(0.1)));\n const slopeCos = float(1).div(hx.mul(hx).add(hz.mul(hz)).add(1).sqrt());\n const ok = elev.greaterThanEqual(uRules.x).and(elev.lessThanEqual(uRules.y)).and(slopeCos.greaterThanEqual(uRules.z));\n If(ok, () => {\n const slot = atomicAdd(countAtomic.element(uint(0)), uint(1));\n If(slot.lessThan(uint(maxTrees)), () => {\n const base = slot.mul(uint(TREE_STRIDE));\n const sp = floor(hashNode(id, seed + 37).mul(uRules.w.sub(0.001)));\n const yaw = hashNode(id, seed + 71).mul(Math.PI * 2);\n const tSeed = floor(hashNode(id, seed + 97).mul(1_000_000));\n // Negative sentinels in size slots are converted to NaN on readback (avoids WGSL compile-time 0/0).\n const unset = float(-1);\n packedW.element(base).assign(x);\n packedW.element(base.add(1)).assign(elev);\n packedW.element(base.add(2)).assign(z);\n packedW.element(base.add(3)).assign(sp);\n packedW.element(base.add(4)).assign(unset);\n packedW.element(base.add(5)).assign(unset);\n packedW.element(base.add(6)).assign(unset);\n packedW.element(base.add(7)).assign(unset);\n packedW.element(base.add(8)).assign(yaw);\n packedW.element(base.add(9)).assign(tSeed);\n });\n });\n });\n })().compute(cells);\n\n return {\n packedAttr,\n countAttr,\n async run(renderer) {\n await renderer.compute([clearPass, scatterPass]);\n const countBuf = new Uint32Array(await renderer.getArrayBufferAsync(countAttr));\n const count = Math.min(maxTrees, countBuf[0] ?? 0);\n const packedAll = new Float32Array(await renderer.getArrayBufferAsync(packedAttr));\n const packed = packedAll.slice(0, count * TREE_STRIDE);\n for (let i = 0; i < count; i++) {\n const o = i * TREE_STRIDE;\n for (let k = 4; k <= 7; k++) if (packed[o + k] <= 0) packed[o + k] = NaN;\n }\n return { count, packed };\n },\n dispose() {\n clearPass.dispose();\n scatterPass.dispose();\n packedAttr.dispose();\n countAttr.dispose();\n },\n };\n}\n"]}
@@ -0,0 +1,369 @@
1
+ /**
2
+ * How the tree is put together (Hallé and Oldeman's models, by the handful that matter on a course):
3
+ *
4
+ * - `broadleaf`: a short trunk that soon divides into a few great limbs, which divide again (oak, maple,
5
+ * plane, eucalyptus; an old pine, whose leader has given up the lead). Grown from its buds, in the light,
6
+ * inside its crown's outline.
7
+ * - `conifer`: one leader to the top, with branches in whorls along it, longest low down (spruce, fir,
8
+ * most pines when young). Grown whorl by whorl.
9
+ * - `shrub`: several stems from the ground, no trunk to speak of (holly, gorse, broom, rhododendron).
10
+ * - `palm`: one unbranched stem, as thick at the top as at the foot, crowned with a head of fronds that
11
+ * arch out from its top and hang (date palm, fan palm). `whorl` is how many fronds the head carries,
12
+ * `bend` how far they arch over, and `crownRadius` how far they reach.
13
+ */
14
+ export type Architecture = "broadleaf" | "conifer" | "shrub" | "palm";
15
+ /**
16
+ * What its leaves are like, for the looks' sprays of them: broad (oak, maple, plane), narrow (eucalyptus,
17
+ * willow), needle (a fir's or a spruce's short needles all along its shoots), small (box, holly, a shrub's),
18
+ * frond (a palm's: a pinnate frond or a fan), pine (a pine's long needles in brushes at its shoots' ends,
19
+ * the shoots behind bare: a pine keeps its needles only a few years). A whorled conifer with needles has its
20
+ * near boughs drawn as sheets; a pine's tufts are not boughs, and are drawn as sprays.
21
+ */
22
+ export type LeafKind = "broad" | "narrow" | "needle" | "small" | "frond" | "pine";
23
+ export declare const LEAF_KIND_ROWS: readonly LeafKind[];
24
+ /**
25
+ * The outline of the crown seen from the side: how wide it is at each height, from its base to its top.
26
+ * Weber and Penn's shapes (1995), less the ones that serve only a tree's first branches, made round
27
+ * (`CROWN_OUTLINES` in tree.ts): each is widest somewhere up the crown, upright there, and curves in above
28
+ * and below. A row's `crownPeak` and `crownRound` say where and how, over its shape's own.
29
+ */
30
+ export type CrownShape = "conical" | "spherical" | "hemispherical" | "cylindrical" | "taperedCylindrical" | "flame" | "inverseConical" | "tendFlame";
31
+ /**
32
+ * Where a species is commonly found on courses, by the places Couch Golf Club's courses are in: coastal
33
+ * California (Los Angeles, San Diego, San Francisco), the Pacific Northwest's coast, Great Britain's
34
+ * heaths, France (Paris), Ontario (Toronto), the Dutch coast and Denmark.
35
+ */
36
+ export type Region = "california" | "pacific-northwest" | "great-britain" | "france" | "ontario" | "netherlands" | "denmark";
37
+ export declare const REGION_ROWS: readonly Region[];
38
+ export interface TreeSpecies {
39
+ name: string;
40
+ /** Its botanical name, when it is one species (a generic row has none). */
41
+ latin?: string;
42
+ /** Where it is commonly found on courses (`REGION_ROWS`). Read by no grower or shader: for a host choosing a region's trees. */
43
+ regions?: Region[];
44
+ /**
45
+ * The crown proportions its real trees are documented to take, from drawn up in a stand to open-grown,
46
+ * [least, most]: `crownRatio` its crown's radius over its height (a beech in a wood, 0.14, to a parkland
47
+ * beech's dome, 0.5), `baseRatio` its crown's base over its height (branches to the ground in the open to
48
+ * a wood's long clean bole). Read by no grower or shader: for a host telling which species a measured tree
49
+ * is, by the range of its kind and not by the one specimen the row grows when nothing gives a tree's size
50
+ * (`height`, `crownRadius`, `crownBase`), which is set to a showpiece and may be retuned. From
51
+ * docs/MORPHOLOGY.md and its sources, noted on each species. Left out: no source gives them, and a host
52
+ * has only the specimen's.
53
+ */
54
+ crownRatio?: [number, number];
55
+ baseRatio?: [number, number];
56
+ /**
57
+ * How tall its real trees grow (m), [typical, most]: the low end of the height its grown trees commonly
58
+ * reach, and the most the sources give for the species (beyond the odd record tree). Read by no grower or
59
+ * shader: for a host telling which species a measured tree is, so a tree taller than its kind grows is not
60
+ * taken for it (a young tree is well under the typical). From docs/MORPHOLOGY.md and its sources, noted on
61
+ * each species.
62
+ */
63
+ heightRange?: [number, number];
64
+ architecture: Architecture;
65
+ /** How tall (m). */
66
+ height: number;
67
+ /** How far its crown reaches from the trunk (m). */
68
+ crownRadius: number;
69
+ /** How high its lowest leaves are above the ground (m). */
70
+ crownBase: number;
71
+ /** Its trunk's radius at breast height (m). */
72
+ trunkRadius: number;
73
+ shape: CrownShape;
74
+ /**
75
+ * How deep into the crown its leaves go, 0..1: 0, on its outside only (a beech in summer, all its
76
+ * leaves in the light); 1, through to the trunk (a young conifer, a shrub). Real crowns are mostly
77
+ * shells: a leaf in deep shade costs the tree more than it gives.
78
+ */
79
+ foliageDepth: number;
80
+ /** How see-through the crown is, 0 (solid) to 1 (sky through it everywhere): a pine's open crown, a birch's. */
81
+ openness: number;
82
+ /**
83
+ * Where the crown is widest, as a share of the way up it (0 its base, 1 its top), over its shape's own: an
84
+ * open-grown oak is widest a sixth of the way up, an old Scots pine's top nearly a third.
85
+ */
86
+ crownPeak?: number;
87
+ /**
88
+ * How round the crown is above its widest, over its shape's own: the exponent of the superellipse its
89
+ * outline follows there (Rautiainen et al. 2008), 1 a cone, 2 an ellipse, 3 or more a flat top.
90
+ */
91
+ crownRound?: number;
92
+ /** How lumpy the crown's outline is, 0..1: 0 smooth all round, 1 bulging out and falling back by nearly a third between. */
93
+ lobes?: number;
94
+ /** How many stems rise from the ground: 1 for a tree, several for a shrub or a coppiced stool. */
95
+ stems: number;
96
+ /** The angle a branch leaves its parent at (degrees), and how much that differs branch to branch. */
97
+ branchAngle: number;
98
+ branchAngleSpread: number;
99
+ /**
100
+ * How the branches bend as they grow, -1..1: up towards the light (1, a fastigiate poplar), level, or
101
+ * down under their own weight (-1, a spruce's lower boughs, a weeping beech).
102
+ */
103
+ bend: number;
104
+ /** How crooked the branches are, 0 (straight) to 1 (an old oak's). */
105
+ crooked: number;
106
+ /**
107
+ * How much the leader keeps the lead, 0..1: 1, one stem to the top (a conifer); 0, it divides early and
108
+ * none leads (an oak in the open).
109
+ */
110
+ leader: number;
111
+ /** How many branches to a whorl (conifers), and how many whorls a metre of leader carries. */
112
+ whorl: number;
113
+ whorlsPerMetre: number;
114
+ /** How many branches it carries, as a share of what fills its crown: 0.3, a sparse old pine; 1, full. */
115
+ branchiness: number;
116
+ /**
117
+ * How many great limbs (scaffolds) a broadleaf's trunk carries into its crown, below its leader. Left out:
118
+ * 4, and one more for every third of `leader` (an oak's few, a birch's many along its leader); a shrub's
119
+ * stems are its scaffolds, and it has none besides.
120
+ */
121
+ scaffolds?: number;
122
+ /**
123
+ * How readily a broadleaf or a shrub sheds its shaded branches, 0..1: the light a branch must gather for
124
+ * each of its pieces of wood to be kept (Takenaka 1994). Left out: from `openness` and `branchiness`.
125
+ */
126
+ shed?: number;
127
+ /**
128
+ * How many dead branch stubs a long clean bole keeps, 0..1: the lower branches a tree grown in a wood
129
+ * has lost, broken off short (a birch's, an oak's, an alder's). A pine or a beech prunes itself clean:
130
+ * 0 or left out, none.
131
+ */
132
+ boleStubs?: number;
133
+ /**
134
+ * The angle its first-order limbs (a broadleaf's great limbs, a conifer's boughs) leave the trunk at
135
+ * (degrees from upright), at the top of its crown and at its base: [top, base]. A spruce's top boughs
136
+ * rise and its low ones droop ([55, 115]); an oak's scaffolds leave steeper above than below. Left out:
137
+ * `branchAngle`, swung wider low and steeper high.
138
+ */
139
+ limbAngle?: [number, number];
140
+ /**
141
+ * How a first-order limb turns along its length (degrees; up +, down -): over all of it, or, when
142
+ * `limbCurveBack` is given, over its inner half, its outer half turning by that instead. A spruce's
143
+ * J-curved bough droops (-35) and its tip turns up (+45); a Torrey pine's limb runs out level and turns up
144
+ * at its end (0, +50); a willow's rises and arches over (+10, -60). Left out: from `bend`.
145
+ */
146
+ limbCurve?: number;
147
+ limbCurveBack?: number;
148
+ /**
149
+ * How far a twig turns at each node where its tip died and a side bud took the lead (sympodial growth,
150
+ * degrees): a plane's or a sycamore's zigzag twigs (25), a maple's or an ash's straight ones (0, its
151
+ * terminal bud goes on). Left out: 15.
152
+ */
153
+ zigzag?: number;
154
+ /**
155
+ * How far its wood runs straight between elbows (m): a crooked tree whose limbs and branches zigzag at
156
+ * angular elbows (a California sycamore's), all their wandering and turning to the light at once at each,
157
+ * rather than a little at every internode, which drawn through its nodes is a wavy line. Left out: they
158
+ * wander as they grow, and `zigzag` sets their twigs aside internode by internode.
159
+ */
160
+ zigzagRun?: number;
161
+ /**
162
+ * How its side buds are set round a shoot: one at a node turning by the golden angle (`spiral`, most
163
+ * trees), opposite in pairs crossed at right angles (`opposite`: maple, ash; one of each pair is grown, so
164
+ * its shoots alternate side to side and cross), or in two ranks in the shoot's plane (`distichous`: beech,
165
+ * elm, whose shoots lie in flat fans). Left out: spiral.
166
+ */
167
+ phyllotaxis?: "spiral" | "opposite" | "distichous";
168
+ /**
169
+ * How far a conifer's side shoots hang from their bough, 0..1: 0 level, in the bough's plane (a fir's flat
170
+ * spray, a pine's plate); 1 straight down (a Norway spruce's comb of hanging shoots, a cedar's hanging
171
+ * sprays). Left out: from `bend`.
172
+ */
173
+ sprayHang?: number;
174
+ /**
175
+ * How much of the crown's underside is cleared of leaves, 0..1, so its limbs show beneath it (a stone
176
+ * pine's umbrella on bare limbs, a park oak's raised skirt): the leaves under a bowl from the crown's base at
177
+ * its rim up to this share of the way to its heart at its middle are not grown.
178
+ */
179
+ canopyLift?: number;
180
+ /**
181
+ * Where a broadleaf's trunk divides into its great limbs, as a share of its crown's base's height (a stone
182
+ * pine's stem forks a third to half of the way up its height, its limbs rising bare in V-forks to the
183
+ * umbrella, the ribs under it): left out, at its crown's base.
184
+ */
185
+ fork?: number;
186
+ /**
187
+ * How many stems a forked stem (`fork`) divides into there, 2 to 4 (a stone pine's few thick crooked stems),
188
+ * each as thick as the pipe model makes it, the stem's wood shared among them; with it, the stem leans or
189
+ * sways on the way up as `crooked` says. Left out: its great limbs leave it one by one, as `scaffolds` says.
190
+ */
191
+ forkStems?: number;
192
+ /**
193
+ * How many times each of those stems divides again in V-forks, rising then spreading, before its arms are
194
+ * limbs (a stone pine's). Left out: its stems are trunks of their own, each leaning out from the fork and
195
+ * turning up, with its share of the crown, its own great limbs (`scaffolds`) and its own leader (a forked
196
+ * oak's two trunks, a coast live oak's leaning ones).
197
+ */
198
+ forkSplits?: number;
199
+ /**
200
+ * The share of its trees whose trunk forks (`fork`, `forkStems`), 0..1: each tree's seed decides, so a
201
+ * stand is a mix (a parkland oak's forked trunk, a coast live oak's two or three leaning trunks). Fewer in
202
+ * a closed wood, where a tree is drawn up on one stem, and those fork higher. Left out: every tree if
203
+ * `fork` and `forkStems` are given, else none.
204
+ */
205
+ forkShare?: number;
206
+ /**
207
+ * How far one tree's fork strays from `fork`, either way, as a share of its crown base's height: a fork
208
+ * near the ground (one root plate, its trunks leaning apart from it) to one under the crown. Left out: 0.
209
+ */
210
+ forkSpread?: number;
211
+ /** The most stems a forked trunk divides into (`forkStems` the least), each tree its own. Left out: `forkStems`. */
212
+ forkStemsMost?: number;
213
+ /**
214
+ * The share of its trees that grow as a clump of a few stems from one root plate, 0..1 (a silver birch's or
215
+ * a black alder's from a stool): each a tree's stem, leaning out a little and turning up, with its share of
216
+ * one crown. Each tree's seed decides; fewer in a closed wood. Left out: none (a shrub's `stems` are its own).
217
+ */
218
+ stemShare?: number;
219
+ /** How many stems such a clump has, [least, most], 2..4. Left out: [2, 3]. */
220
+ stemRange?: [number, number];
221
+ /**
222
+ * How far its leaves gather into flat-topped pads, 0..1: each branch off a great limb keeps only the leaves
223
+ * near its top, so the crown is shelves of foliage with air and bare wood under each (a Monterey cypress
224
+ * on a headland, an old Scots pine's plates, a cloud-pruned pine). 0 or left out: an even skin.
225
+ */
226
+ pads?: number;
227
+ /**
228
+ * How far its leaves gather into a few separate bunches hanging at its branches' ends, with sky between
229
+ * them, 0..1 (a blue gum's pendulous clumps of sickle leaves): each branch off a great limb keeps its leaves
230
+ * only on its last shoots, the bunch hanging under them, bigger the more it gathers, and a share of its
231
+ * branches bear none, their wood shed back to the limb. 0 or left out: an even skin.
232
+ */
233
+ clusters?: number;
234
+ /**
235
+ * How far a tree of one stem leans where it leaves the ground (degrees from upright), its trunk easing back
236
+ * upright by its crown's base, so its crown stands over its foot and its stem is a curve under it (a
237
+ * California sycamore's, by a creek); each tree leans its own way. Left out: 0, it stands upright (a host
238
+ * may lean a whole tree a little).
239
+ */
240
+ lean?: number;
241
+ /**
242
+ * How much its trunk's foot spreads into buttresses and flutes, 0..1 (a western red cedar's, a Sitka
243
+ * spruce's): the root flare wider and higher. Left out: 0, an ordinary flare.
244
+ */
245
+ buttress?: number;
246
+ leafKind: LeafKind;
247
+ /** How big a clump of leaves is (m across), on a tree of this kind at its own size. */
248
+ clumpSize: number;
249
+ /** How much one clump differs in size from the next, 0..1. */
250
+ clumpSpread: number;
251
+ /** The colour of the crown in sunlight, seen from a way off (leaves, not one leaf). */
252
+ leafColor: string;
253
+ /**
254
+ * Colours its trees take instead, one each, chosen by the tree's seed: a host whose look gives each kind
255
+ * of tree a few greens. Left out, every tree is `leafColor`, varied by `treeVariation`.
256
+ */
257
+ leafColors?: string[];
258
+ /** How much one clump differs in tone from the next, and one tree from the next, 0..1. */
259
+ leafVariation: number;
260
+ treeVariation: number;
261
+ /** What the sun through the leaves is tinted by (it comes through greener and warmer than it falls). */
262
+ throughTint: [number, number, number];
263
+ barkColor: string;
264
+ /** How much lighter its bark is up the trunk than at its foot, 0..1: a eucalyptus's, a birch's. */
265
+ barkPale: number;
266
+ /** How little the wind moves it, 0 (a willow's whips) to 1 (an old oak's trunk). */
267
+ stiffness: number;
268
+ /**
269
+ * How much of the crown hangs in whips, 0..1: twigs that grow out and then fall straight down under their
270
+ * own weight, to as low as the crown's base, leaved along all their length (a weeping willow's curtain,
271
+ * a weeping birch's tresses). 0 or left out: none.
272
+ */
273
+ weep?: number;
274
+ /** Its leaf: a feather palm's (leaflets along a rachis: date palm, queen palm) or a fan palm's (a pleated fan on a long stalk). */
275
+ palmLeaf?: "feather" | "fan";
276
+ /**
277
+ * How its trees are kept unless a host says otherwise of a tree: `natural` (its dead leaves hanging under
278
+ * its green, a fan palm's skirt), `skirt` (cut back to a short one), `skinned` (dead and drooping leaves cut,
279
+ * the stem cleaned), `pineapple` (cut back to the leaves above the level, its leaf bases trimmed into a ball
280
+ * under the crown). Left out: a feather palm pineapple cut, a fan palm skinned.
281
+ */
282
+ pruning?: "natural" | "skirt" | "skinned" | "pineapple";
283
+ /** How far a feather palm's leaflets stand in several planes, 0..1 (a queen palm's plumose leaf); 0, two flat rows in a V. */
284
+ plumose?: number;
285
+ /** A dead leaf's colour (hex): straw to grey-brown. */
286
+ deadColor?: string;
287
+ /** How far down its stem a palm's skirt of dead leaves hangs when it is kept natural, 0..1 of the way to the ground. */
288
+ skirt?: number;
289
+ /** How wide its leaves are beside its kind's (1): a feather palm's leaflets' reach, a fan palm's blade. */
290
+ frondWidth?: number;
291
+ /** How far a fan palm's split segment tips droop, beside its kind's (1). */
292
+ fanDroop?: number;
293
+ }
294
+ /** What kind of value a species field read from JSON must be: a number, a string, a list of strings, two numbers, or one of some words. */
295
+ export type SpeciesFieldKind = "number" | "string" | "strings" | "pair" | readonly string[];
296
+ /**
297
+ * Every field a species may leave out (`TreeSpecies`'s optional members), and what it must be when given: for
298
+ * a host reading species from JSON (the lab's presets). The compiler holds the list to the type: a member
299
+ * missing or one too many will not build. The rest of a species must all be there; `checkSpecies` then says
300
+ * whether the values are sound.
301
+ */
302
+ export declare const OPTIONAL_SPECIES_FIELDS: {
303
+ readonly latin: "string";
304
+ readonly regions: "strings";
305
+ readonly crownRatio: "pair";
306
+ readonly baseRatio: "pair";
307
+ readonly heightRange: "pair";
308
+ readonly crownPeak: "number";
309
+ readonly crownRound: "number";
310
+ readonly lobes: "number";
311
+ readonly scaffolds: "number";
312
+ readonly shed: "number";
313
+ readonly boleStubs: "number";
314
+ readonly limbAngle: "pair";
315
+ readonly limbCurve: "number";
316
+ readonly limbCurveBack: "number";
317
+ readonly zigzag: "number";
318
+ readonly zigzagRun: "number";
319
+ readonly phyllotaxis: readonly ["spiral", "opposite", "distichous"];
320
+ readonly sprayHang: "number";
321
+ readonly canopyLift: "number";
322
+ readonly fork: "number";
323
+ readonly forkStems: "number";
324
+ readonly forkSplits: "number";
325
+ readonly forkShare: "number";
326
+ readonly forkSpread: "number";
327
+ readonly forkStemsMost: "number";
328
+ readonly stemShare: "number";
329
+ readonly stemRange: "pair";
330
+ readonly pads: "number";
331
+ readonly clusters: "number";
332
+ readonly lean: "number";
333
+ readonly buttress: "number";
334
+ readonly leafColors: "strings";
335
+ readonly weep: "number";
336
+ readonly palmLeaf: readonly ["feather", "fan"];
337
+ readonly pruning: readonly ["natural", "skirt", "skinned", "pineapple"];
338
+ readonly plumose: "number";
339
+ readonly deadColor: "string";
340
+ readonly skirt: "number";
341
+ readonly frondWidth: "number";
342
+ readonly fanDroop: "number";
343
+ };
344
+ /** Whether `value` is of `kind` (`SpeciesFieldKind`). */
345
+ export declare function isSpeciesFieldKind(value: unknown, kind: SpeciesFieldKind): boolean;
346
+ /**
347
+ * The trees a course in a temperate place is likely to have, at the sizes they reach there. By eye: the oak,
348
+ * the plane, the eucalyptus and the Scots pine set against photographs of open-grown trees (an oak's crown
349
+ * wider than it is tall, a plane's full oval, a park eucalyptus between its vase and Riviera's tall blue
350
+ * gums, a Scots pine's flat lopsided top on a thin trunk). The oak's, the Scots pine's and the spruce's
351
+ * outlines and proportions (crown reach and base for height) are measured from photographs of open-grown
352
+ * trees (test/outlines.json): an open-grown spruce is much wider than a forest one. An old Scots pine has
353
+ * given up its leader, and is grown as a broadleaf, with needles.
354
+ */
355
+ export declare const STARTER_SPECIES: readonly TreeSpecies[];
356
+ /**
357
+ * More species, by the regions Couch Golf Club's courses are in, keyed by a short id. Each row's size is a
358
+ * typical open-grown tree of its kind on a course or in a park there (not a forest-grown record tree),
359
+ * taken from the source named over it; its form, colours and the rest are by eye, from photographs.
360
+ * "UF/IFAS" is Gilman and Watson's tree fact sheets (University of Florida, Environmental Horticulture).
361
+ */
362
+ export declare const MORE_SPECIES: Readonly<Record<string, TreeSpecies>>;
363
+ /** Every species: the starters, then the regional ones. */
364
+ export declare const ALL_SPECIES: readonly TreeSpecies[];
365
+ /** A copy to change, that changes no one else's. */
366
+ export declare function cloneSpecies(s: TreeSpecies): TreeSpecies;
367
+ /** What is wrong with a species, if anything: a list of plain sentences, empty when it is sound. */
368
+ export declare function checkSpecies(s: TreeSpecies): string[];
369
+ //# sourceMappingURL=species.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"species.d.ts","sourceRoot":"","sources":["../src/species.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAClF,eAAO,MAAM,cAAc,EAAE,SAAS,QAAQ,EAA4D,CAAC;AAE3G;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,GAAG,aAAa,GAAG,oBAAoB,GAAG,OAAO,GAAG,gBAAgB,GAAG,WAAW,CAAC;AAErJ;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,mBAAmB,GAAG,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,CAAC;AAC7H,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAAwG,CAAC;AAElJ,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gIAAgI;IAChI,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,SAAS,CAAC,E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