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/tree.d.ts ADDED
@@ -0,0 +1,134 @@
1
+ import { type PalmCrown } from "./palm.js";
2
+ import { type CrownShape } from "./species.js";
3
+ /** How big one tree is (m): what a survey measures of it, and what a ball hitting it meets. */
4
+ export interface TreeSize {
5
+ height: number;
6
+ crownRadius: number;
7
+ /** How high its lowest leaves are above the ground. */
8
+ crownBase: number;
9
+ /** Its trunk's radius at breast height: 1.3 m up, or a tenth of the way up a tree under 13 m (a shrub's stems near their foot). */
10
+ trunkRadius: number;
11
+ }
12
+ /**
13
+ * A crown shape's outline, as Weber and Penn's pruning envelope (1995) made round: how high in the crown
14
+ * it is widest (`peak`, 0 its base, 1 its top), how round it is above that (`round`: the exponent of a
15
+ * superellipse, Lamé's curve, which Rautiainen et al. (2008) fitted to measured crowns: 1 a cone, 2 an
16
+ * ellipse, higher a flatter top), how round below (`roundLow`), and how wide it still is at its base, where
17
+ * its lowest live branches are (`base`, a share of its widest). Its side is upright where it is widest, so
18
+ * no crown has a waist or a corner there; only a cone (round near 1) comes to a point at its top.
19
+ */
20
+ export interface CrownOutline {
21
+ peak: number;
22
+ round: number;
23
+ roundLow: number;
24
+ base: number;
25
+ }
26
+ /** Each shape's outline. Rautiainen et al. (2008) measured round 1.35 for Scots pine and 1.42 for Norway spruce. */
27
+ export declare const CROWN_OUTLINES: Readonly<Record<CrownShape, CrownOutline>>;
28
+ /** What a species may say of its crown's outline over its shape's (`TreeSpecies` has both). */
29
+ export interface CrownOverride {
30
+ crownPeak?: number;
31
+ crownRound?: number;
32
+ }
33
+ /** A shape's outline, with what a species says over it. */
34
+ export declare function crownOutline(shape: CrownShape, over?: CrownOverride): CrownOutline;
35
+ /**
36
+ * How wide a crown of a shape is at a height within it, as a share of its widest: `t` is 0 at the crown's
37
+ * base and 1 at its top. Give the species (or its `crownPeak` and `crownRound`) to have its own outline.
38
+ */
39
+ export declare function crownProfile(shape: CrownShape, t: number, over?: CrownOverride): number;
40
+ /**
41
+ * An ellipsoid from the crown's base to the tree's top, `crownRadius` round: Couch Golf Club's collider for
42
+ * a crown, and what the shaders take the crown to be when they work out how much light gets through it.
43
+ * A drawn crown keeps to its box (`crownRadius` round, from `crownBase` to `height`) and to its species'
44
+ * outline, not to this: a spruce is widest at its foot, where the ellipsoid is narrowest.
45
+ */
46
+ export declare function crownEllipsoid(size: TreeSize): {
47
+ cy: number;
48
+ rx: number;
49
+ ry: number;
50
+ };
51
+ /** How far a point is inside the crown's ellipsoid: under 1 inside, 1 on it, over 1 outside. */
52
+ export declare function insideCrown(size: TreeSize, x: number, y: number, z: number): number;
53
+ /**
54
+ * The branches, as nodes: each node is a point on a branch with its radius there, joined to its parent by
55
+ * a straight piece of wood. Node 0 is the foot of the first stem; a node whose parent is -1 is the foot
56
+ * of a stem.
57
+ */
58
+ export interface Skeleton {
59
+ count: number;
60
+ x: Float32Array;
61
+ y: Float32Array;
62
+ z: Float32Array;
63
+ radius: Float32Array;
64
+ parent: Int32Array;
65
+ /** 0 a stem (the trunk), 1 a limb off it, 2 a branch off that, and so on. */
66
+ order: Uint8Array;
67
+ /**
68
+ * The node where this node's limb leaves its stem: the first node of the order-1 branch it is on (itself,
69
+ * or an ancestor). For a node on a stem, the stem's foot. Wind moves a limb and all on it together, and
70
+ * gives each limb its own phase from where this node is.
71
+ */
72
+ limb: Int32Array;
73
+ /** How far along the wood from the ground to here (m). */
74
+ along: Float32Array;
75
+ }
76
+ /**
77
+ * The leaves, gathered into clumps: a spray of leaves at a twig's end, drawn as one thing far off and as
78
+ * its leaves close to. Each is a sphere of leaves hung on a node of the skeleton.
79
+ */
80
+ export interface Clumps {
81
+ count: number;
82
+ x: Float32Array;
83
+ y: Float32Array;
84
+ z: Float32Array;
85
+ radius: Float32Array;
86
+ /** Which way the clump faces out of the crown (unit): where its leaves turn to the light. */
87
+ nx: Float32Array;
88
+ ny: Float32Array;
89
+ nz: Float32Array;
90
+ /** The skeleton node it hangs from (a twig's end). */
91
+ node: Int32Array;
92
+ /** How deep in the crown it is, 0 (its outside) to 1 (its heart): how much of the sky its leaves see. */
93
+ depth: Float32Array;
94
+ /**
95
+ * Which way its twig runs at the clump (unit): from the node's parent to the node. A leaf card lies along
96
+ * it, so a frond's leaves follow the frond and a whip's hang with the whip.
97
+ */
98
+ tx: Float32Array;
99
+ ty: Float32Array;
100
+ tz: Float32Array;
101
+ }
102
+ /** A tree, grown. */
103
+ export interface GrownTree {
104
+ /**
105
+ * The size it was grown to: as asked, the size its fit is stretched from. (An umbrella pine's crown is kept to the
106
+ * top of it, grow.ts `umbrellaCap`, as a crown its stand has lifted is: its crown's base is its lowest leaves'.)
107
+ */
108
+ size: TreeSize;
109
+ skeleton: Skeleton;
110
+ clumps: Clumps;
111
+ /** How much its trunk's foot spreads into buttresses, 0..1 (its species' `buttress`; left out, 0). */
112
+ buttress?: number;
113
+ /**
114
+ * How its leaves are carried, for drawing them (its species' own, each 0..1; left out, 0): how far a
115
+ * conifer's side shoots hang from their boughs in curtains (`sprayHang`), how far its leaves lie in
116
+ * flat-topped pads (`pads`), how far they gather in hanging bunches (`clusters`).
117
+ */
118
+ habit?: {
119
+ sprayHang?: number;
120
+ pads?: number;
121
+ clusters?: number;
122
+ };
123
+ /** A palm's crown (palm.ts): its fronds, its stem and how it is kept, which its drawing reads in place of its clumps. */
124
+ palm?: PalmCrown;
125
+ /** Its leaves' area, one side (m²), where it is known (a palm's, frond by frond); else its species' leaf area index makes it. */
126
+ leafArea?: number;
127
+ /**
128
+ * How big its clumps are beside its kind's at its height (0..1; left out, 1): a narrow or young crown's are
129
+ * finer than its specimen's (grow.ts `CLUMP_NARROW`), more of them. Its near dabs follow its crown, not its
130
+ * clumps: fewer to a finer clump (geometry.ts `dabPieces`).
131
+ */
132
+ clumpShare?: number;
133
+ }
134
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,+FAA+F;AAC/F,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,mIAAmI;IACnI,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oHAAoH;AACpH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CASrE,CAAC;AAEF,+FAA+F;AAC/F,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAQlF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,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AAM,WAAW,SAAS;IACxB;;;OAGG;IACH,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,sGAAsG;IACtG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,yHAAyH;IACzH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,iIAAiI;IACjI,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
package/lib/tree.js ADDED
@@ -0,0 +1,57 @@
1
+ // What a tree is between being grown and being drawn: its size, the envelope
2
+ // it must keep to, its branches and its clumps of leaves.
3
+ //
4
+ // Growing makes these (grow.ts) from a species, a size and a seed; drawing
5
+ // reads them and knows nothing of how they were made. They are plain arrays
6
+ // in metres, the tree's foot at the origin, +Y up.
7
+ /** Each shape's outline. Rautiainen et al. (2008) measured round 1.35 for Scots pine and 1.42 for Norway spruce. */
8
+ export const CROWN_OUTLINES = {
9
+ conical: { peak: 0.2, round: 1.35, roundLow: 2, base: 0.6 },
10
+ spherical: { peak: 0.45, round: 2, roundLow: 2, base: 0.3 },
11
+ hemispherical: { peak: 0.2, round: 2, roundLow: 1.6, base: 0.55 },
12
+ cylindrical: { peak: 0.5, round: 4, roundLow: 4, base: 0.85 },
13
+ taperedCylindrical: { peak: 0.2, round: 1.5, roundLow: 2.5, base: 0.75 },
14
+ flame: { peak: 0.3, round: 1.2, roundLow: 1.5, base: 0.25 },
15
+ inverseConical: { peak: 0.7, round: 2.6, roundLow: 1.3, base: 0.25 },
16
+ tendFlame: { peak: 0.4, round: 1.6, roundLow: 2, base: 0.5 },
17
+ };
18
+ /** A shape's outline, with what a species says over it. */
19
+ export function crownOutline(shape, over) {
20
+ const o = CROWN_OUTLINES[shape];
21
+ return {
22
+ peak: Math.min(0.95, Math.max(0, over?.crownPeak ?? o.peak)),
23
+ round: Math.max(0.8, over?.crownRound ?? o.round),
24
+ roundLow: o.roundLow,
25
+ base: o.base,
26
+ };
27
+ }
28
+ /**
29
+ * How wide a crown of a shape is at a height within it, as a share of its widest: `t` is 0 at the crown's
30
+ * base and 1 at its top. Give the species (or its `crownPeak` and `crownRound`) to have its own outline.
31
+ */
32
+ export function crownProfile(shape, t, over) {
33
+ const o = crownOutline(shape, over);
34
+ const s = Math.min(1, Math.max(0, t));
35
+ if (s >= o.peak) {
36
+ const u = o.peak >= 1 ? 1 : (s - o.peak) / (1 - o.peak);
37
+ return u >= 1 ? 0 : (1 - u ** o.round) ** (1 / o.round);
38
+ }
39
+ const u = (o.peak - s) / o.peak;
40
+ return o.base + (1 - o.base) * (1 - u ** o.roundLow) ** (1 / o.roundLow);
41
+ }
42
+ /**
43
+ * An ellipsoid from the crown's base to the tree's top, `crownRadius` round: Couch Golf Club's collider for
44
+ * a crown, and what the shaders take the crown to be when they work out how much light gets through it.
45
+ * A drawn crown keeps to its box (`crownRadius` round, from `crownBase` to `height`) and to its species'
46
+ * outline, not to this: a spruce is widest at its foot, where the ellipsoid is narrowest.
47
+ */
48
+ export function crownEllipsoid(size) {
49
+ const depth = Math.max(0.01, size.height - size.crownBase);
50
+ return { cy: size.crownBase + depth / 2, rx: size.crownRadius, ry: depth / 2 };
51
+ }
52
+ /** How far a point is inside the crown's ellipsoid: under 1 inside, 1 on it, over 1 outside. */
53
+ export function insideCrown(size, x, y, z) {
54
+ const e = crownEllipsoid(size);
55
+ return Math.hypot(x / e.rx, (y - e.cy) / e.ry, z / e.rx);
56
+ }
57
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC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AAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAc;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3D,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;AACjF,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,IAAc,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IACzE,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["// What a tree is between being grown and being drawn: its size, the envelope\n// it must keep to, its branches and its clumps of leaves.\n//\n// Growing makes these (grow.ts) from a species, a size and a seed; drawing\n// reads them and knows nothing of how they were made. They are plain arrays\n// in metres, the tree's foot at the origin, +Y up.\n\nimport { type PalmCrown } from \"./palm.ts\";\nimport { type CrownShape } from \"./species.ts\";\n\n/** How big one tree is (m): what a survey measures of it, and what a ball hitting it meets. */\nexport interface TreeSize {\n height: number;\n crownRadius: number;\n /** How high its lowest leaves are above the ground. */\n crownBase: number;\n /** Its trunk's radius at breast height: 1.3 m up, or a tenth of the way up a tree under 13 m (a shrub's stems near their foot). */\n trunkRadius: number;\n}\n\n/**\n * A crown shape's outline, as Weber and Penn's pruning envelope (1995) made round: how high in the crown\n * it is widest (`peak`, 0 its base, 1 its top), how round it is above that (`round`: the exponent of a\n * superellipse, Lamé's curve, which Rautiainen et al. (2008) fitted to measured crowns: 1 a cone, 2 an\n * ellipse, higher a flatter top), how round below (`roundLow`), and how wide it still is at its base, where\n * its lowest live branches are (`base`, a share of its widest). Its side is upright where it is widest, so\n * no crown has a waist or a corner there; only a cone (round near 1) comes to a point at its top.\n */\nexport interface CrownOutline {\n peak: number;\n round: number;\n roundLow: number;\n base: number;\n}\n\n/** Each shape's outline. Rautiainen et al. (2008) measured round 1.35 for Scots pine and 1.42 for Norway spruce. */\nexport const CROWN_OUTLINES: Readonly<Record<CrownShape, CrownOutline>> = {\n conical: { peak: 0.2, round: 1.35, roundLow: 2, base: 0.6 },\n spherical: { peak: 0.45, round: 2, roundLow: 2, base: 0.3 },\n hemispherical: { peak: 0.2, round: 2, roundLow: 1.6, base: 0.55 },\n cylindrical: { peak: 0.5, round: 4, roundLow: 4, base: 0.85 },\n taperedCylindrical: { peak: 0.2, round: 1.5, roundLow: 2.5, base: 0.75 },\n flame: { peak: 0.3, round: 1.2, roundLow: 1.5, base: 0.25 },\n inverseConical: { peak: 0.7, round: 2.6, roundLow: 1.3, base: 0.25 },\n tendFlame: { peak: 0.4, round: 1.6, roundLow: 2, base: 0.5 },\n};\n\n/** What a species may say of its crown's outline over its shape's (`TreeSpecies` has both). */\nexport interface CrownOverride {\n crownPeak?: number;\n crownRound?: number;\n}\n\n/** A shape's outline, with what a species says over it. */\nexport function crownOutline(shape: CrownShape, over?: CrownOverride): CrownOutline {\n const o = CROWN_OUTLINES[shape];\n return {\n peak: Math.min(0.95, Math.max(0, over?.crownPeak ?? o.peak)),\n round: Math.max(0.8, over?.crownRound ?? o.round),\n roundLow: o.roundLow,\n base: o.base,\n };\n}\n\n/**\n * How wide a crown of a shape is at a height within it, as a share of its widest: `t` is 0 at the crown's\n * base and 1 at its top. Give the species (or its `crownPeak` and `crownRound`) to have its own outline.\n */\nexport function crownProfile(shape: CrownShape, t: number, over?: CrownOverride): number {\n const o = crownOutline(shape, over);\n const s = Math.min(1, Math.max(0, t));\n if (s >= o.peak) {\n const u = o.peak >= 1 ? 1 : (s - o.peak) / (1 - o.peak);\n return u >= 1 ? 0 : (1 - u ** o.round) ** (1 / o.round);\n }\n const u = (o.peak - s) / o.peak;\n return o.base + (1 - o.base) * (1 - u ** o.roundLow) ** (1 / o.roundLow);\n}\n\n/**\n * An ellipsoid from the crown's base to the tree's top, `crownRadius` round: Couch Golf Club's collider for\n * a crown, and what the shaders take the crown to be when they work out how much light gets through it.\n * A drawn crown keeps to its box (`crownRadius` round, from `crownBase` to `height`) and to its species'\n * outline, not to this: a spruce is widest at its foot, where the ellipsoid is narrowest.\n */\nexport function crownEllipsoid(size: TreeSize): { cy: number; rx: number; ry: number } {\n const depth = Math.max(0.01, size.height - size.crownBase);\n return { cy: size.crownBase + depth / 2, rx: size.crownRadius, ry: depth / 2 };\n}\n\n/** How far a point is inside the crown's ellipsoid: under 1 inside, 1 on it, over 1 outside. */\nexport function insideCrown(size: TreeSize, x: number, y: number, z: number): number {\n const e = crownEllipsoid(size);\n return Math.hypot(x / e.rx, (y - e.cy) / e.ry, z / e.rx);\n}\n\n/**\n * The branches, as nodes: each node is a point on a branch with its radius there, joined to its parent by\n * a straight piece of wood. Node 0 is the foot of the first stem; a node whose parent is -1 is the foot\n * of a stem.\n */\nexport interface Skeleton {\n count: number;\n x: Float32Array;\n y: Float32Array;\n z: Float32Array;\n radius: Float32Array;\n parent: Int32Array;\n /** 0 a stem (the trunk), 1 a limb off it, 2 a branch off that, and so on. */\n order: Uint8Array;\n /**\n * The node where this node's limb leaves its stem: the first node of the order-1 branch it is on (itself,\n * or an ancestor). For a node on a stem, the stem's foot. Wind moves a limb and all on it together, and\n * gives each limb its own phase from where this node is.\n */\n limb: Int32Array;\n /** How far along the wood from the ground to here (m). */\n along: Float32Array;\n}\n\n/**\n * The leaves, gathered into clumps: a spray of leaves at a twig's end, drawn as one thing far off and as\n * its leaves close to. Each is a sphere of leaves hung on a node of the skeleton.\n */\nexport interface Clumps {\n count: number;\n x: Float32Array;\n y: Float32Array;\n z: Float32Array;\n radius: Float32Array;\n /** Which way the clump faces out of the crown (unit): where its leaves turn to the light. */\n nx: Float32Array;\n ny: Float32Array;\n nz: Float32Array;\n /** The skeleton node it hangs from (a twig's end). */\n node: Int32Array;\n /** How deep in the crown it is, 0 (its outside) to 1 (its heart): how much of the sky its leaves see. */\n depth: Float32Array;\n /**\n * Which way its twig runs at the clump (unit): from the node's parent to the node. A leaf card lies along\n * it, so a frond's leaves follow the frond and a whip's hang with the whip.\n */\n tx: Float32Array;\n ty: Float32Array;\n tz: Float32Array;\n}\n\n/** A tree, grown. */\nexport interface GrownTree {\n /**\n * The size it was grown to: as asked, the size its fit is stretched from. (An umbrella pine's crown is kept to the\n * top of it, grow.ts `umbrellaCap`, as a crown its stand has lifted is: its crown's base is its lowest leaves'.)\n */\n size: TreeSize;\n skeleton: Skeleton;\n clumps: Clumps;\n /** How much its trunk's foot spreads into buttresses, 0..1 (its species' `buttress`; left out, 0). */\n buttress?: number;\n /**\n * How its leaves are carried, for drawing them (its species' own, each 0..1; left out, 0): how far a\n * conifer's side shoots hang from their boughs in curtains (`sprayHang`), how far its leaves lie in\n * flat-topped pads (`pads`), how far they gather in hanging bunches (`clusters`).\n */\n habit?: { sprayHang?: number; pads?: number; clusters?: number };\n /** A palm's crown (palm.ts): its fronds, its stem and how it is kept, which its drawing reads in place of its clumps. */\n palm?: PalmCrown;\n /** Its leaves' area, one side (m²), where it is known (a palm's, frond by frond); else its species' leaf area index makes it. */\n leafArea?: number;\n /**\n * How big its clumps are beside its kind's at its height (0..1; left out, 1): a narrow or young crown's are\n * finer than its specimen's (grow.ts `CLUMP_NARROW`), more of them. Its near dabs follow its crown, not its\n * clumps: fewer to a finer clump (geometry.ts `dabPieces`).\n */\n clumpShare?: number;\n}\n"]}
@@ -0,0 +1,157 @@
1
+ import { type Pruning } from "./palm.js";
2
+ import { type TreeSpecies } from "./species.js";
3
+ import { type Stand, type Standing } from "./stand.js";
4
+ import { type TreeSize } from "./tree.js";
5
+ /** One tree on the ground. Its size, left out, is its species'. */
6
+ export interface TreeInstance {
7
+ x: number;
8
+ /** The ground's height at its foot. */
9
+ y: number;
10
+ z: number;
11
+ /** Its species, by row in the list of species. */
12
+ species: number;
13
+ height?: number;
14
+ crownRadius?: number;
15
+ crownBase?: number;
16
+ trunkRadius?: number;
17
+ /** Which way it faces (radians). Left out, it is chosen from its place. */
18
+ yaw?: number;
19
+ /** Its own number, for whatever is chosen of it at random. Left out, it is made from its place. */
20
+ seed?: number;
21
+ /** Where it stands among the others, over what is worked out from its neighbours (stand.ts): any part of it. */
22
+ stand?: Partial<Stand>;
23
+ /** A palm's: how it is kept (palm.ts), over its species' `pruning`. */
24
+ pruning?: Pruning;
25
+ }
26
+ /** Trees packed as numbers, `TREE_STRIDE` to a tree, in the order of `TREE_FIELDS`: what a host with many trees hands over. NaN for a size, yaw or seed is "left out". */
27
+ export declare const TREE_FIELDS: readonly ["x", "y", "z", "species", "height", "crownRadius", "crownBase", "trunkRadius", "yaw", "seed"];
28
+ export declare const TREE_STRIDE: 10;
29
+ export declare function packTrees(list: readonly TreeInstance[]): Float32Array;
30
+ /** A number from 0 to 1 that depends on an integer and a salt and nothing else (an integer hash: the same on every machine). */
31
+ export declare function hash01(n: number, salt: number): number;
32
+ /** A hex colour (sRGB) as linear red, green and blue. */
33
+ export declare function linearRgb(hex: string): [number, number, number];
34
+ /** An integer seed from a place on the ground: stable between loads, to the centimetre. */
35
+ export declare function seedOfPlace(x: number, z: number): number;
36
+ export interface VariantOptions {
37
+ /**
38
+ * How many shapes each species' trees are sorted into, at the fewest (each grown once a seed): more fit closer
39
+ * and cost more to hold. More are made where its trees' shapes spread further than `stretch` lets one variant
40
+ * be fitted to them all.
41
+ */
42
+ shapes: number;
43
+ /**
44
+ * How far a tree's crown may be stretched from its variant's, one way more than the other (its depth beside its
45
+ * width: 1.3, a crown grown as deep as it is wide fitted to one 1.3 times as deep as wide); a variant may be
46
+ * scaled as a whole by this to the 2.5, and its trunk beside its crown to the 3. Left out, `FIT_STRETCH`.
47
+ */
48
+ stretch?: number;
49
+ /** The most shapes a species' trees are sorted into for one way of standing, whatever their spread (`MOST_SHAPES` left out). */
50
+ mostShapes?: number;
51
+ /** How many trees are grown for each shape, from different seeds. */
52
+ seeds: number;
53
+ /** How far a tree may lean from upright (degrees), at most. */
54
+ lean: number;
55
+ /** Whether a tree may be its variant mirrored. */
56
+ mirror: boolean;
57
+ /** Whether trees are grown for where they stand (stand.ts): edge and interior trees as well as open ones. */
58
+ stands: boolean;
59
+ /**
60
+ * A number mixed into every variant's seed: another set of trees of the same shapes (0 or left out: the
61
+ * set as it has always been).
62
+ */
63
+ seed?: number;
64
+ /**
65
+ * Optional per-tree world-space trunk lean `[leanX, leanZ]` (`2 * N` floats, as `sin(angle)` in world XZ)
66
+ * applied atop gentle random jitter so phototropic, shoreline, or wind-flagged leans point accurately in world space.
67
+ */
68
+ leans?: Float32Array;
69
+ /**
70
+ * Optional per-tree linear leaf tint multiplier `[r, g, b]` (`3 * N` floats) for host edaphic moisture/fertility/exposure gradients.
71
+ */
72
+ tints?: Float32Array;
73
+ }
74
+ /**
75
+ * How many seeds a shape is grown from, at least, for a species whose trees differ in their form at the foot
76
+ * (`formsVary`: some forked, some clumps, some one stem), so that a stand of them shows the mix.
77
+ */
78
+ export declare const FORM_SEEDS = 3;
79
+ export declare const DEFAULT_VARIANT_OPTIONS: VariantOptions;
80
+ /**
81
+ * How far a tree's crown may be stretched from the variant it is fitted from (see `VariantOptions.stretch`).
82
+ * Every tree is a variant stretched to its own size, up its trunk, up its crown and across it, and the stretch is
83
+ * not the tree's: its clumps keep their size ((across + up) / 2: engine.ts `fitOf`) while the spaces between them
84
+ * and the wood under them stretch. Sorted into two shapes by k-means, Riviera's eucalyptus of 4.7 to 26 m on crowns
85
+ * of 1 to 5.3 m were fitted from variants grown 7.8 and 8 m tall, some crowns stretched six times as far up as
86
+ * across: a Monterey cypress's pads drawn apart up its crown, each on a bare spike of stretched twig with the
87
+ * top of its crown floating over them; a stone pine of 33 m a tower of its 12 m variant's cushions stacked; a
88
+ * blue gum's crown squashed into a thin lid, its limbs pressed into loops; a sycamore's crown a ball on poles.
89
+ */
90
+ export declare const FIT_STRETCH = 1.3;
91
+ /** A shape is grown from a seed more for every this many of its trees, up to `VariantOptions.seeds`. */
92
+ export declare const SEED_TREES = 8;
93
+ /** ... and for every this many, of a species whose trees differ in form at the foot (`formsVary`). */
94
+ export declare const FORM_TREES = 3;
95
+ /** The most shapes a species' trees are sorted into for one way of standing (see `VariantOptions.mostShapes`). */
96
+ export declare const MOST_SHAPES = 12;
97
+ /** A tree to grow. */
98
+ export interface Variant {
99
+ species: number;
100
+ size: TreeSize;
101
+ seed: number;
102
+ /** How many trees on the ground are this one. */
103
+ trees: number;
104
+ /** Where it is grown as standing; and its stand, in its own frame (open along +x): its trees' on the whole. */
105
+ standing: Standing;
106
+ stand: Stand;
107
+ /** A palm's pruning, where its trees are kept otherwise than their species says (palm.ts); left out, its species'. */
108
+ pruning?: Pruning;
109
+ }
110
+ /** Where one tree on the ground stands and how its variant is fitted to it. */
111
+ export interface Placement {
112
+ variant: number;
113
+ x: number;
114
+ y: number;
115
+ z: number;
116
+ yaw: number;
117
+ /** Its own size. */
118
+ size: TreeSize;
119
+ /** How far it leans, along x and z (as the sine of the angle). */
120
+ leanX: number;
121
+ leanZ: number;
122
+ /** 1, or -1 for its variant mirrored. */
123
+ mirror: number;
124
+ /** A tint for the tree's leaves, about 1 in each of r, g and b (its bark takes only how light it is). */
125
+ tint: [number, number, number];
126
+ /** A number of its own, 0..1. */
127
+ own: number;
128
+ /** Where it stands (its own, on the ground: stand.ts), and the class of variant that makes it. */
129
+ stand: Stand;
130
+ standing: Standing;
131
+ }
132
+ export interface Plan {
133
+ variants: Variant[];
134
+ placements: Placement[];
135
+ }
136
+ /**
137
+ * A palm's trees sorted into shapes, each within a band of heights: no tree more than PALM_BAND times as tall
138
+ * as the shortest of its band. A palm's head and the collar of boots under it are its kind's size in metres at
139
+ * any height (palm.ts), and a variant fitted to a tree is stretched up its trunk and its crown by the tree's
140
+ * height over its own (`fitPoint`): a 10 m variant drawn as a 28 m palm made its 2 m collar of boots a carrot of
141
+ * 6–9 m. So a palm is grown near its trees' heights (stretched a sixth either way on Riviera, a third at most), and a band of
142
+ * fewer than PALM_BAND_SHAPED palms in one shape: a course has few palms, so the few more variants cost little.
143
+ */
144
+ export declare const PALM_BAND = 1.4;
145
+ /** A tree's own size: its own numbers where it has them, its species' where not, and never one that cannot be grown. */
146
+ export declare function sizeOf(packed: Float32Array, i: number, species: TreeSpecies): TreeSize;
147
+ /**
148
+ * What to grow for these trees, and how each is fitted to what is grown. Each tree's stand is worked out
149
+ * from its neighbours (stand.ts) unless `options.stands` is off; `stands` (by tree) sets any part of it.
150
+ */
151
+ export declare function planVariants(packed: Float32Array, species: readonly TreeSpecies[], options?: VariantOptions, stands?: readonly (Partial<Stand> | null | undefined)[], prunings?: readonly (Pruning | null | undefined)[]): Plan;
152
+ /**
153
+ * Where a point of a variant (its own frame, metres from its foot) is on a tree fitted from it, in that
154
+ * tree's frame before it is turned and leant: what the shaders do to every vertex (engine.ts, `fitOf`).
155
+ */
156
+ export declare function fitPoint(grownSize: TreeSize, size: TreeSize, mirror: number, p: [number, number, number]): [number, number, number];
157
+ //# sourceMappingURL=variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../src/variants.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAc,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAwB,MAAM,YAAY,CAAC;AACzF,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