@casmo/tree.js 0.1.0 → 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 (190) hide show
  1. package/README.md +106 -16
  2. package/dist/apply-CcodnAbs.js +250 -0
  3. package/dist/apply-CcodnAbs.js.map +1 -0
  4. package/dist/bake/index.d.ts +2 -2
  5. package/dist/bake/index.d.ts.map +1 -1
  6. package/dist/definition/crown-shape.d.ts +9 -0
  7. package/dist/definition/crown-shape.d.ts.map +1 -0
  8. package/dist/definition/defaults.d.ts +7 -1
  9. package/dist/definition/defaults.d.ts.map +1 -1
  10. package/dist/definition/index.d.ts +4 -3
  11. package/dist/definition/index.d.ts.map +1 -1
  12. package/dist/definition/migrations.d.ts +0 -8
  13. package/dist/definition/migrations.d.ts.map +1 -1
  14. package/dist/definition/schema.d.ts.map +1 -1
  15. package/dist/definition/types.d.ts +95 -6
  16. package/dist/definition/types.d.ts.map +1 -1
  17. package/dist/effects/mask.d.ts +3 -3
  18. package/dist/effects/mask.d.ts.map +1 -1
  19. package/dist/effects.js +3 -3
  20. package/dist/effects.js.map +1 -1
  21. package/dist/forest/Forest.d.ts +10 -1
  22. package/dist/forest/Forest.d.ts.map +1 -1
  23. package/dist/forest/nodes.d.ts +4 -1
  24. package/dist/forest/nodes.d.ts.map +1 -1
  25. package/dist/{forest-OX9WvAwh.js → forest-DTrD8puH.js} +695 -546
  26. package/dist/forest-DTrD8puH.js.map +1 -0
  27. package/dist/generator/branches.d.ts +2 -2
  28. package/dist/generator/branches.d.ts.map +1 -1
  29. package/dist/generator/fruit.d.ts +28 -0
  30. package/dist/generator/fruit.d.ts.map +1 -0
  31. package/dist/generator/growth.d.ts +1 -1
  32. package/dist/generator/growth.d.ts.map +1 -1
  33. package/dist/generator/index.d.ts +4 -4
  34. package/dist/generator/index.d.ts.map +1 -1
  35. package/dist/generator/leaf-shapes.d.ts +33 -1
  36. package/dist/generator/leaf-shapes.d.ts.map +1 -1
  37. package/dist/generator/trunk.d.ts +8 -2
  38. package/dist/generator/trunk.d.ts.map +1 -1
  39. package/dist/generator/types.d.ts +34 -5
  40. package/dist/generator/types.d.ts.map +1 -1
  41. package/dist/index.d.ts +4 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +48 -4
  44. package/dist/index.js.map +1 -1
  45. package/dist/materials/index.d.ts +6 -0
  46. package/dist/materials/index.d.ts.map +1 -1
  47. package/dist/names-C6-wuJ29.js +589 -0
  48. package/dist/names-C6-wuJ29.js.map +1 -0
  49. package/dist/react/Tree.d.ts +5 -2
  50. package/dist/react/Tree.d.ts.map +1 -1
  51. package/dist/react.js +10 -6
  52. package/dist/react.js.map +1 -1
  53. package/dist/season/nodes.d.ts +16 -0
  54. package/dist/season/nodes.d.ts.map +1 -1
  55. package/dist/season/profile.d.ts +26 -0
  56. package/dist/season/profile.d.ts.map +1 -1
  57. package/dist/species/almond.js +213 -0
  58. package/dist/species/almond.js.map +1 -0
  59. package/dist/species/almond.json +201 -0
  60. package/dist/species/apple.js +220 -0
  61. package/dist/species/apple.js.map +1 -0
  62. package/dist/species/apple.json +211 -0
  63. package/dist/species/ash.js +177 -0
  64. package/dist/species/ash.js.map +1 -0
  65. package/dist/species/ash.json +168 -0
  66. package/dist/species/beech.js +164 -0
  67. package/dist/species/beech.js.map +1 -0
  68. package/dist/species/beech.json +158 -0
  69. package/dist/species/birch.js +160 -0
  70. package/dist/species/birch.js.map +1 -0
  71. package/dist/species/birch.json +154 -0
  72. package/dist/species/catalog.d.ts +61 -0
  73. package/dist/species/catalog.d.ts.map +1 -0
  74. package/dist/species/cedar.js +159 -0
  75. package/dist/species/cedar.js.map +1 -0
  76. package/dist/species/cedar.json +159 -0
  77. package/dist/species/cherry.js +227 -0
  78. package/dist/species/cherry.js.map +1 -0
  79. package/dist/species/cherry.json +215 -0
  80. package/dist/species/chestnut.js +220 -0
  81. package/dist/species/chestnut.js.map +1 -0
  82. package/dist/species/chestnut.json +211 -0
  83. package/dist/species/douglas-fir.js +164 -0
  84. package/dist/species/douglas-fir.js.map +1 -0
  85. package/dist/species/douglas-fir.json +161 -0
  86. package/dist/species/elm.js +163 -0
  87. package/dist/species/elm.js.map +1 -0
  88. package/dist/species/elm.json +154 -0
  89. package/dist/species/hemlock.js +165 -0
  90. package/dist/species/hemlock.js.map +1 -0
  91. package/dist/species/hemlock.json +162 -0
  92. package/dist/species/hickory.js +190 -0
  93. package/dist/species/hickory.js.map +1 -0
  94. package/dist/species/hickory.json +183 -0
  95. package/dist/species/index.d.ts +10 -0
  96. package/dist/species/index.d.ts.map +1 -0
  97. package/dist/species/juniper.js +148 -0
  98. package/dist/species/juniper.js.map +1 -0
  99. package/dist/species/juniper.json +145 -0
  100. package/dist/species/loaders.d.ts +7 -0
  101. package/dist/species/loaders.d.ts.map +1 -0
  102. package/dist/species/mahogany.js +191 -0
  103. package/dist/species/mahogany.js.map +1 -0
  104. package/dist/species/mahogany.json +187 -0
  105. package/dist/species/maple.js +167 -0
  106. package/dist/species/maple.js.map +1 -0
  107. package/dist/species/maple.json +162 -0
  108. package/dist/species/oak.js +210 -0
  109. package/dist/species/oak.js.map +1 -0
  110. package/dist/species/oak.json +203 -0
  111. package/dist/species/olive.js +179 -0
  112. package/dist/species/olive.js.map +1 -0
  113. package/dist/species/olive.json +172 -0
  114. package/dist/species/peach.js +213 -0
  115. package/dist/species/peach.js.map +1 -0
  116. package/dist/species/peach.json +201 -0
  117. package/dist/species/pear.js +203 -0
  118. package/dist/species/pear.js.map +1 -0
  119. package/dist/species/pear.json +191 -0
  120. package/dist/species/pine.js +153 -0
  121. package/dist/species/pine.js.map +1 -0
  122. package/dist/species/pine.json +153 -0
  123. package/dist/species/plum.js +227 -0
  124. package/dist/species/plum.js.map +1 -0
  125. package/dist/species/plum.json +215 -0
  126. package/dist/species/red-oak.js +210 -0
  127. package/dist/species/red-oak.js.map +1 -0
  128. package/dist/species/red-oak.json +203 -0
  129. package/dist/species/redwood.js +164 -0
  130. package/dist/species/redwood.js.map +1 -0
  131. package/dist/species/redwood.json +161 -0
  132. package/dist/species/sequoia.js +157 -0
  133. package/dist/species/sequoia.js.map +1 -0
  134. package/dist/species/sequoia.json +157 -0
  135. package/dist/species/spruce.js +160 -0
  136. package/dist/species/spruce.js.map +1 -0
  137. package/dist/species/spruce.json +157 -0
  138. package/dist/species/teak.js +156 -0
  139. package/dist/species/teak.js.map +1 -0
  140. package/dist/species/teak.json +148 -0
  141. package/dist/species/types.d.ts +61 -0
  142. package/dist/species/types.d.ts.map +1 -0
  143. package/dist/species/walnut.js +210 -0
  144. package/dist/species/walnut.js.map +1 -0
  145. package/dist/species/walnut.json +203 -0
  146. package/dist/species/white-oak.js +203 -0
  147. package/dist/species/white-oak.js.map +1 -0
  148. package/dist/species/white-oak.json +199 -0
  149. package/dist/species.js +160 -0
  150. package/dist/species.js.map +1 -0
  151. package/dist/styles/apply.d.ts +12 -0
  152. package/dist/styles/apply.d.ts.map +1 -0
  153. package/dist/styles/low-poly/index.d.ts +1 -1
  154. package/dist/styles/low-poly/index.d.ts.map +1 -1
  155. package/dist/styles/low-poly.js +9 -8
  156. package/dist/styles/low-poly.js.map +1 -1
  157. package/dist/styles/names.d.ts +28 -0
  158. package/dist/styles/names.d.ts.map +1 -0
  159. package/dist/styles/realistic/index.d.ts +3 -8
  160. package/dist/styles/realistic/index.d.ts.map +1 -1
  161. package/dist/styles/realistic/textures.d.ts +20 -0
  162. package/dist/styles/realistic/textures.d.ts.map +1 -0
  163. package/dist/styles/realistic.js +10 -16
  164. package/dist/styles/realistic.js.map +1 -1
  165. package/dist/styles/registry.d.ts +2 -13
  166. package/dist/styles/registry.d.ts.map +1 -1
  167. package/dist/styles/stylized/index.d.ts +1 -1
  168. package/dist/styles/stylized/index.d.ts.map +1 -1
  169. package/dist/styles/stylized.js +9 -8
  170. package/dist/styles/stylized.js.map +1 -1
  171. package/dist/styles/types.d.ts +16 -2
  172. package/dist/styles/types.d.ts.map +1 -1
  173. package/dist/textures/realistic/bark-fibrous-normal.png +0 -0
  174. package/dist/textures/realistic/bark-fibrous.png +0 -0
  175. package/dist/textures/realistic/bark-papery-normal.png +0 -0
  176. package/dist/textures/realistic/bark-papery.png +0 -0
  177. package/dist/textures/realistic/bark-plated-normal.png +0 -0
  178. package/dist/textures/realistic/bark-plated.png +0 -0
  179. package/dist/textures/realistic/bark-smooth-normal.png +0 -0
  180. package/dist/textures/realistic/bark-smooth.png +0 -0
  181. package/dist/textures/realistic/leaf-compound.png +0 -0
  182. package/dist/textures/realistic/leaf-lobed.png +0 -0
  183. package/dist/textures/realistic/leaf-palmate.png +0 -0
  184. package/dist/textures/realistic/scale.png +0 -0
  185. package/dist/tree/Tree.d.ts +6 -4
  186. package/dist/tree/Tree.d.ts.map +1 -1
  187. package/package.json +9 -2
  188. package/dist/forest-OX9WvAwh.js.map +0 -1
  189. package/dist/types-BZjHhNz7.js +0 -20
  190. package/dist/types-BZjHhNz7.js.map +0 -1
package/README.md CHANGED
@@ -12,6 +12,7 @@ thousands at once as an instanced Forest, add opt-in Tree Effects, or design you
12
12
  - [Quick start](#quick-start)
13
13
  - [WebGPURenderer is required](#webgpurenderer-is-required)
14
14
  - [Styles](#styles)
15
+ - [Species](#species)
15
16
  - [Tree Definitions and Seeds](#tree-definitions-and-seeds)
16
17
  - [Growth and Season](#growth-and-season)
17
18
  - [Wind](#wind)
@@ -37,6 +38,7 @@ npm install @casmo/tree.js three
37
38
  | --- | --- |
38
39
  | `@casmo/tree.js` | `createTree`, `createForest`, Definitions, Wind, Baked Tree export, `loadStyle`, ... |
39
40
  | `@casmo/tree.js/styles/low-poly` (`stylized`, `realistic`) | a built-in Style: one Tree Definition per Form (a few kB of data) |
41
+ | `@casmo/tree.js/species` | the 28 Species (`oak`, `douglasFir`, ...), `loadSpecies`, `SPECIES_NAMES`; JSON files |
40
42
  | `@casmo/tree.js/effects` | Tree Effects (post-processing) |
41
43
  | `@casmo/tree.js/react` | `<Tree>`, `<Forest>`, `<Wind>`, `useTreeStyle` for React Three Fiber |
42
44
 
@@ -70,8 +72,8 @@ scene.add(tree);
70
72
  renderer.setAnimationLoop(() => renderer.render(scene, camera));
71
73
  ```
72
74
 
73
- A `Tree` is a three.js `Group` with two meshes, `tree.wood` and `tree.leaves` (both cast and receive
74
- shadows). `tree.dispose()` frees its geometries and materials and removes it from the scene.
75
+ A `Tree` is a three.js `Group` with three meshes, `tree.wood`, `tree.leaves` and `tree.fruit` (empty
76
+ without Fruit; all cast and receive shadows). `tree.dispose()` frees its geometries and materials and removes it from the scene.
75
77
 
76
78
  ## WebGPURenderer is required
77
79
 
@@ -130,6 +132,52 @@ const tallPine = createTree(extendDefinition(stylized.conifer, { trunk: { length
130
132
  scene.add(oak, pine, birch, tallPine);
131
133
  ```
132
134
 
135
+ ## Species
136
+
137
+ [![All 28 Species, each in the low-poly, stylized and realistic Styles](docs/species/contact-sheet.jpg)](docs/species/README.md)
138
+
139
+ *Every Species in `low-poly`, `stylized` and `realistic`; the [Species gallery](docs/species/README.md) has larger
140
+ images (with Fruit or in autumn), a code example and the JSON of each.*
141
+
142
+ 28 real trees ship with the library, each described once by its shape (Stems, Crown Shape), Leaf Type, Bark
143
+ Type, Fruit, colours and Season Profile, and drawn in any Style:
144
+
145
+ ```ts
146
+ import { createTree, loadStyle } from '@casmo/tree.js';
147
+ import { oak } from '@casmo/tree.js/species';
148
+ scene.add(createTree((await loadStyle('realistic')).apply(oak), { seed: 42 }));
149
+ ```
150
+
151
+ - **Broadleaf**: `almond`, `apple`, `ash`, `beech`, `birch`, `cherry`, `chestnut`, `elm`, `hickory`, `mahogany`, `maple`, `oak`, `olive`, `peach`, `pear`, `plum`, `redOak`, `teak`, `walnut`, `whiteOak`
152
+ - **Conifer**: `cedar`, `douglasFir`, `hemlock`, `juniper`, `pine`, `redwood`, `sequoia`, `spruce`
153
+
154
+ `style.apply(species, overrides?)` returns an ordinary, complete Tree Definition, so it works everywhere a
155
+ Definition does (`createTree`, `createForest`, Baked Trees, the Tree Editor). Each Species is its own module:
156
+ importing two doesn't bundle the other 26.
157
+
158
+ ```ts
159
+ import { createForest, createTree } from '@casmo/tree.js';
160
+ import { apple, douglasFir, loadSpecies, SPECIES_NAMES, type SpeciesName } from '@casmo/tree.js/species';
161
+ import lowPoly from '@casmo/tree.js/styles/low-poly';
162
+ import stylized from '@casmo/tree.js/styles/stylized';
163
+
164
+ const tallFir = createTree(stylized.apply(douglasFir, { trunk: { length: 14 } }), { seed: 3 });
165
+ const orchard = createForest(lowPoly.apply(apple), [
166
+ { id: 'a', position: [0, 0, 0] },
167
+ { id: 'b', position: [5, 0, 1] },
168
+ ]);
169
+
170
+ // At runtime, e.g. from level data: a dynamic import per Species (rejects unknown ids).
171
+ const name: SpeciesName = SPECIES_NAMES.includes('birch') ? 'birch' : 'oak';
172
+ const birch = createTree(lowPoly.apply(await loadSpecies(name)), { season: 0.6 });
173
+ scene.add(tallFir, orchard, birch);
174
+ ```
175
+
176
+ `SPECIES_BY_NAME` maps every id to its Species (for a picker that lists them all; it bundles all 28).
177
+ Without a bundler, every Species is also a plain JSON file: `@casmo/tree.js/species/<id>.json` (for example
178
+ `https://cdn.jsdelivr.net/npm/@casmo/tree.js/dist/species/douglas-fir.json`). In React:
179
+ `<Tree species={oak} style={lowPoly} seed={7} />`. Try them all in [`examples/species`](examples/species/main.ts).
180
+
133
181
  ## Tree Definitions and Seeds
134
182
 
135
183
  ![Five birches grown from the same Tree Definition with Seeds 1 to 5](docs/images/seeds.png)
@@ -146,8 +194,7 @@ always give exactly the same tree.
146
194
  import { createTree, fetchDefinition, parseDefinition, TreeDefinitionError, type TreeDefinitionInput } from '@casmo/tree.js';
147
195
 
148
196
  const birch: TreeDefinitionInput = {
149
- schemaVersion: 2,
150
- form: 'broadleaf',
197
+ schemaVersion: 3,
151
198
  trunk: { length: 6, radius: 0.15 },
152
199
  branches: [
153
200
  { count: 6, angle: 45 },
@@ -162,13 +209,46 @@ const fromEditor = await fetchDefinition('/trees/my-oak.json'); // a Tree Editor
162
209
  const tree = createTree(fromEditor, { seed: 7 });
163
210
 
164
211
  try {
165
- parseDefinition('{"schemaVersion": 2, "trunk": {"length": -1}}');
212
+ parseDefinition('{"schemaVersion": 3, "trunk": {"length": -1}}');
166
213
  } catch (error) {
167
214
  if (error instanceof TreeDefinitionError) console.warn(error.field, error.message); // 'trunk.length'
168
215
  }
169
216
  ```
170
217
 
171
- Older Definitions (lower `schemaVersion`) are migrated when parsed. `extendDefinition(base, patch)`
218
+ Each branch level can carry a **Crown Shape**: optional `lengthProfile` and `angleProfile` keyframe
219
+ curves over where a branch sits on its parent (0 = base .. 1 = tip) that multiply the level's `length`
220
+ and `angle` (linear between keyframes, flat = 1 when absent). A cone is
221
+ `lengthProfile: [{ t: 0.2, value: 1 }, { t: 1, value: 0.1 }]` on the first level; a ball, column, vase
222
+ or flat top are other curves.
223
+
224
+ A tree can grow several **Stems** from the ground: `trunk: { stems: 3, spread: 20 }` stands three full
225
+ trunks (each with the whole branch structure) in a small ring, leaning out about 20° from vertical (the
226
+ Seed varies each lean). `trunk.gravity` (−1..1) bends only the leader, the top third of each Stem: −1 makes
227
+ it nod like a hemlock's. Absent, a tree has one upright Stem without gravity.
228
+
229
+ **Fruit** is an optional `fruit` block: `type` (`'round'`, `'pear'`, `'nut'`, `'cone'` or `'berry'`),
230
+ `count` per outermost twig, `size`, `sizeVariation` and `hang` (0 = sits on the twig .. 1 = hangs
231
+ straight down). A fractional `count` is a chance per twig: `0.3` puts one Fruit on about 30% of the
232
+ twigs, `1.5` one on every twig and a second on about half (the Seed picks which). The optional `sides`
233
+ (3..16) is its polygon detail, set by `Style.apply`: low-poly draws a few flat facets (5 or fewer sides
234
+ also coarsen the profile), stylized and realistic smoother shapes; absent = each Fruit Type's own detail.
235
+ It is drawn in its own mesh in the Definition's shading, only on a fully grown tree, and sways with its twig:
236
+
237
+ ```ts
238
+ import { createTree } from '@casmo/tree.js';
239
+
240
+ const apple = createTree({
241
+ schemaVersion: 3,
242
+ fruit: { type: 'round', count: 2, size: 0.1, hang: 0.8 },
243
+ season: {
244
+ fruit: [{ t: 0.1, value: 0 }, { t: 0.35, value: 1 }, { t: 0.6, value: 1 }, { t: 0.7, value: 0 }],
245
+ fruitColor: [{ t: 0.25, value: '#7cb342' }, { t: 0.5, value: '#c62828' }],
246
+ },
247
+ });
248
+ ```
249
+
250
+ Older Definitions (lower `schemaVersion`) are migrated when parsed (a v2 `form: 'conifer'` becomes the
251
+ equivalent cone `lengthProfile`, so the tree stays identical). `extendDefinition(base, patch)`
172
252
  deep-merges a patch (arrays replace) and validates the result. Sculpts (hand edits made in the Tree Editor)
173
253
  belong to one Seed: they only change the tree of that Seed.
174
254
 
@@ -184,7 +264,7 @@ Both only write a uniform, so they are cheap to animate every frame:
184
264
  ```ts
185
265
  import { createTree, SEASON_PROFILES } from '@casmo/tree.js';
186
266
 
187
- const tree = createTree({ schemaVersion: 2, season: SEASON_PROFILES.deciduous }, { seed: 5, growth: 0, season: 0 });
267
+ const tree = createTree({ schemaVersion: 3, season: SEASON_PROFILES.deciduous }, { seed: 5, growth: 0, season: 0 });
188
268
  scene.add(tree);
189
269
 
190
270
  renderer.setAnimationLoop((time) => {
@@ -197,7 +277,8 @@ renderer.setAnimationLoop((time) => {
197
277
  Each tree's Seed shifts its timing a little (`variation.growth`, `variation.season`), so trees of one
198
278
  Definition don't change in lockstep. `SEASON_PROFILES.deciduous` and `.evergreen` are ready-made Season
199
279
  Profiles; write your own as keyframes in the Definition's `season` (`leafColor`, `leafCoverage`,
200
- `blossom`, `blossomColor`).
280
+ `blossom`, `blossomColor`, and for Fruit `fruit` (amount: each Fruit shows above its own rank and swells
281
+ with the amount; 1 all year when absent) and `fruitColor` (ripening)).
201
282
 
202
283
  ## Wind
203
284
 
@@ -211,11 +292,11 @@ unless you give it another `Wind`. All of it is uniforms, so changing the wind i
211
292
  import { createTree, sceneWind, Wind } from '@casmo/tree.js';
212
293
 
213
294
  sceneWind.set({ direction: [1, 0, -0.4], strength: 0.6 }); // 0 = calm (default), 1 = strong
214
- const swaying = createTree({ schemaVersion: 2, wind: { trunk: 0.4, branches: 0.8, leaves: 1 } }, { seed: 1 });
295
+ const swaying = createTree({ schemaVersion: 3, wind: { trunk: 0.4, branches: 0.8, leaves: 1 } }, { seed: 1 });
215
296
 
216
297
  // A separate wind, e.g. for a sheltered courtyard:
217
298
  const breeze = new Wind({ direction: [0, 0, 1], strength: 0.2 });
218
- const sheltered = createTree({ schemaVersion: 2 }, { seed: 2, wind: breeze });
299
+ const sheltered = createTree({ schemaVersion: 3 }, { seed: 2, wind: breeze });
219
300
 
220
301
  swaying.windResponse.set({ leaves: 0.5 }); // change one tree's response live
221
302
  sceneWind.time = 1.5; // pin the wind clock (seconds), e.g. for screenshots; null = the renderer's clock
@@ -231,7 +312,8 @@ A swaying tree needs a render loop (`renderer.setAnimationLoop`).
231
312
  *400 trees from 4 Variants, with a per-tree Season (autumn towards the right).*
232
313
 
233
314
  A Forest draws many trees of one Definition from a few Variants (Seeds), each instanced, so 1,000 trees
234
- cost two draw calls per Variant. Every tree still looks its own: its Variant, rotation, Growth delay,
315
+ cost two draw calls per Variant (three with Fruit: `variant.fruit` is a third instanced mesh, null without
316
+ Fruit). Every tree still looks its own: its Variant, rotation, Growth delay,
235
317
  Season shift and wind phase come from a hash of the forest seed and the tree's id (or position), so adding
236
318
  or removing trees never changes the others.
237
319
 
@@ -269,7 +351,7 @@ if (hit) console.log(forest.treeAt(hit)?.key);
269
351
 
270
352
  `@casmo/tree.js/effects` has opt-in post-processing (TSL nodes for three.js `RenderPipeline`) that only
271
353
  changes the pixels of trees: an **outline**, a **leaf glow** and **colour grading**. Trees look fine
272
- without them. Every tree.js material (Trees and Forests) is found automatically (a per-object tree mask in
354
+ without them. Every tree.js material (wood, leaves and Fruit, of Trees and Forests) is found automatically (a per-object tree mask in
273
355
  an MRT output), so no tree has to be registered.
274
356
 
275
357
  ```ts
@@ -320,7 +402,7 @@ function Trees() {
320
402
  <>
321
403
  <Tree style={lowPoly} form="broadleaf" seed={1} growth={0.8} season={0.4} />
322
404
  <Tree style="low-poly" form="conifer" seed={2} position={[3, 0, 0]} castShadow={false} />
323
- <Tree definition={{ schemaVersion: 2, leaves: { count: 4 } }} seed={7} position={[-3, 0, 0]} />
405
+ <Tree definition={{ schemaVersion: 3, leaves: { count: 4 } }} seed={7} position={[-3, 0, 0]} />
324
406
  <Forest
325
407
  style={lowPoly}
326
408
  form="conifer"
@@ -408,12 +490,13 @@ Styles and the realistic textures load relative to the library's URL, so they co
408
490
  *A `.glb` from `exportBakedTree(tree, { season: 0.6 })`, loaded back with three.js' `GLTFLoader`.*
409
491
 
410
492
  A Baked Tree is a static copy of one tree at a fixed Growth and Season (no Growth, Season or Wind left), with
411
- classic `MeshStandardMaterial`s, for other engines or tools:
493
+ classic `MeshStandardMaterial`s, for other engines or tools. It has meshes `wood`, `leaves` and, when Fruit
494
+ shows at the baked Growth and Season, `fruit`:
412
495
 
413
496
  ```ts
414
497
  import { bakeTree, createTree, disposeBakedTree, exportBakedTree } from '@casmo/tree.js';
415
498
 
416
- const tree = createTree({ schemaVersion: 2 }, { seed: 4 });
499
+ const tree = createTree({ schemaVersion: 3 }, { seed: 4 });
417
500
  const glb = await exportBakedTree(tree, { growth: 1, season: 0.6 }); // ArrayBuffer (.glb); binary: false = glTF JSON
418
501
  const url = URL.createObjectURL(new Blob([glb], { type: 'model/gltf-binary' }));
419
502
 
@@ -428,7 +511,11 @@ disposeBakedTree(baked);
428
511
 
429
512
  Definitions with textures (the realistic Style, or your own `materials.bark.map` / `materials.leaf.map`
430
513
  URLs) load them relative to the package's `dist/textures/` by default. To serve them yourself, copy that
431
- folder and point tree.js at it, app-wide or per tree:
514
+ folder and point tree.js at it, app-wide or per tree. `realistic.apply` picks a leaf card per Leaf Type
515
+ (`realistic/leaf.png`, `leaf-lobed.png`, `leaf-palmate.png`, `leaf-compound.png`, `needles.png`,
516
+ `scale.png`) and a colour + normal pair per Bark Type (`realistic/bark.png` for furrowed, `bark-smooth.png`,
517
+ `bark-papery.png`, `bark-fibrous.png`, `bark-plated.png`, each with its `-normal.png`); all are made by
518
+ `scripts/generate-textures.mjs` (MIT, reproducible):
432
519
 
433
520
  ```ts
434
521
  import { createTree, setTextureOptions } from '@casmo/tree.js';
@@ -461,6 +548,7 @@ a live preview (Seed, Growth, Season, Wind, Tree Effects), sculpt single branche
461
548
  | [`examples/react`](examples/react/main.tsx) | `/examples/react/` | React Three Fiber: `<Tree>`, `<Wind>`, `useTreeStyle`; `?scene=forest` for `<Forest>` | <img src="docs/images/example-react.png" alt="examples/react" width="160"> |
462
549
  | [`examples/forest`](examples/forest/main.ts) | `/examples/forest/` | a 400-tree Forest; `?trees=&variants=&style=&season=` | <img src="docs/images/example-forest.png" alt="examples/forest" width="160"> |
463
550
  | [`examples/effects`](examples/effects/main.ts) | `/examples/effects/` | Tree Effects per Style; `?style=stylized&effects=outline` | <img src="docs/images/example-effects.png" alt="examples/effects" width="160"> |
551
+ | [`examples/species`](examples/species/main.ts) | `/examples/species/` | a Species x Style picker over the whole collection; `?species=douglas-fir&style=realistic` | <img src="docs/images/example-species.png" alt="examples/species" width="160"> |
464
552
 
465
553
  ```sh
466
554
  npm install
@@ -477,6 +565,8 @@ sources too; the e2e test serves it unmodified, with the import map answered by
477
565
 
478
566
  `npm test` (Vitest), `npm run typecheck`, `npm run lint`, `npm run build` (library -> `dist/`),
479
567
  `npm run test:e2e` (Playwright; run `npm run build` and `npm run build:examples` first, as CI does).
568
+ The Species gallery (`docs/species/`: images, contact sheet and page) is regenerated by `npm run gallery`
569
+ (Playwright, the e2e renderer; `npm run gallery -- oak birch` redoes only those Species).
480
570
  The README's screenshots and GIFs (`docs/images/`) are rendered by `npm run readme-media`
481
571
  (Playwright + ffmpeg; run `npm run build` first; `npm run readme-media -- wind hero` redoes only those).
482
572
  Design decisions live in [`docs/adr`](docs/adr), the vocabulary in [`GLOSSARY.md`](GLOSSARY.md).
@@ -0,0 +1,250 @@
1
+ import { a as extendDefinition, i as styleShading, r as styleOfShading, s as parseDefinition } from "./names-C6-wuJ29.js";
2
+ // src/styles/realistic/textures.ts
3
+ /**
4
+ * The realistic Style's texture files, as relative URLs (resolved against the texture base path).
5
+ * All made by scripts/generate-textures.mjs. `bark`/`barkNormal` are the furrowed pair, `leaf` the
6
+ * broad card and `needles` the needle card (the generic broadleaf / conifer use these).
7
+ */
8
+ var TEXTURES = {
9
+ bark: "realistic/bark.png",
10
+ barkNormal: "realistic/bark-normal.png",
11
+ leaf: "realistic/leaf.png",
12
+ needles: "realistic/needles.png"
13
+ };
14
+ /** The alpha-cut leaf card texture for each Leaf Type. */
15
+ var LEAF_TEXTURES = {
16
+ broad: TEXTURES.leaf,
17
+ lobed: "realistic/leaf-lobed.png",
18
+ palmate: "realistic/leaf-palmate.png",
19
+ compound: "realistic/leaf-compound.png",
20
+ needle: TEXTURES.needles,
21
+ scale: "realistic/scale.png"
22
+ };
23
+ /** The colour + normal map pair for each Bark Type. */
24
+ var BARK_TEXTURES = {
25
+ furrowed: {
26
+ map: TEXTURES.bark,
27
+ normalMap: TEXTURES.barkNormal
28
+ },
29
+ smooth: {
30
+ map: "realistic/bark-smooth.png",
31
+ normalMap: "realistic/bark-smooth-normal.png"
32
+ },
33
+ papery: {
34
+ map: "realistic/bark-papery.png",
35
+ normalMap: "realistic/bark-papery-normal.png"
36
+ },
37
+ fibrous: {
38
+ map: "realistic/bark-fibrous.png",
39
+ normalMap: "realistic/bark-fibrous-normal.png"
40
+ },
41
+ plated: {
42
+ map: "realistic/bark-plated.png",
43
+ normalMap: "realistic/bark-plated-normal.png"
44
+ }
45
+ };
46
+ // src/styles/apply.ts
47
+ var isNeedleLike = (type) => type === "needle" || type === "scale";
48
+ var untexturedLeaf = {
49
+ roughness: 1,
50
+ map: null,
51
+ alphaTest: .5
52
+ };
53
+ var untexturedBark = () => ({
54
+ roughness: 1,
55
+ map: null,
56
+ normalMap: null
57
+ });
58
+ var LOOKS = {
59
+ "low-poly": {
60
+ trunk: {
61
+ sides: 5,
62
+ sections: 4
63
+ },
64
+ branches: [{
65
+ sides: 4,
66
+ sections: 2
67
+ }, {
68
+ sides: 3,
69
+ sections: 1
70
+ }],
71
+ bark: untexturedBark,
72
+ fruitSides: 4,
73
+ leaf: (type) => isNeedleLike(type) ? {
74
+ shape: "needle",
75
+ perDensity: 14,
76
+ sizeScale: 1.86,
77
+ material: untexturedLeaf
78
+ } : {
79
+ shape: "clump",
80
+ perDensity: 4,
81
+ sizeScale: 2.86,
82
+ material: untexturedLeaf
83
+ }
84
+ },
85
+ stylized: {
86
+ trunk: {
87
+ sides: 10,
88
+ sections: 8
89
+ },
90
+ branches: [
91
+ {
92
+ sides: 6,
93
+ sections: 3
94
+ },
95
+ {
96
+ sides: 4,
97
+ sections: 1
98
+ },
99
+ {
100
+ sides: 3,
101
+ sections: 1
102
+ }
103
+ ],
104
+ bark: untexturedBark,
105
+ fruitSides: 6,
106
+ leaf: (type) => isNeedleLike(type) ? {
107
+ shape: "puff",
108
+ perDensity: 8,
109
+ sizeScale: 1.7,
110
+ material: untexturedLeaf
111
+ } : {
112
+ shape: "puff",
113
+ perDensity: 4,
114
+ sizeScale: 3.14,
115
+ material: untexturedLeaf
116
+ }
117
+ },
118
+ realistic: {
119
+ trunk: {
120
+ sides: 12,
121
+ sections: 10
122
+ },
123
+ branches: [
124
+ {
125
+ sides: 8,
126
+ sections: 6
127
+ },
128
+ {
129
+ sides: 5,
130
+ sections: 4
131
+ },
132
+ {
133
+ sides: 3,
134
+ sections: 2
135
+ }
136
+ ],
137
+ bark: (type) => ({
138
+ roughness: .95,
139
+ ...BARK_TEXTURES[type]
140
+ }),
141
+ fruitSides: 9,
142
+ leaf: (type) => isNeedleLike(type) ? {
143
+ shape: "card",
144
+ perDensity: 120,
145
+ sizeScale: 1.7,
146
+ material: {
147
+ roughness: .7,
148
+ map: LEAF_TEXTURES[type],
149
+ alphaTest: .4
150
+ }
151
+ } : {
152
+ shape: "card",
153
+ perDensity: 80,
154
+ sizeScale: 2.2,
155
+ material: {
156
+ roughness: .65,
157
+ map: LEAF_TEXTURES[type],
158
+ alphaTest: .4
159
+ }
160
+ }
161
+ }
162
+ };
163
+ function fromSpecies(species) {
164
+ const { id, name, trunk, branches, season, wind, variation, fruit, foliage, bark } = species;
165
+ return {
166
+ base: {
167
+ schemaVersion: 3,
168
+ name,
169
+ species: id,
170
+ trunk,
171
+ branches,
172
+ season,
173
+ wind,
174
+ variation,
175
+ sculpts: [],
176
+ ...fruit ? { fruit } : {}
177
+ },
178
+ foliage,
179
+ bark
180
+ };
181
+ }
182
+ function fromDefinition(input) {
183
+ const { leaves, materials, ...base } = parseDefinition(input);
184
+ const leafType = leaves.type ?? (leaves.shape === "needle" || /needle/.test(materials.leaf.map ?? "") ? "needle" : "broad");
185
+ const source = LOOKS[styleOfShading(materials.shading)].leaf(leafType);
186
+ return {
187
+ base,
188
+ foliage: {
189
+ type: leafType,
190
+ density: leaves.count / source.perDensity,
191
+ size: leaves.size / source.sizeScale,
192
+ sizeVariation: leaves.sizeVariation,
193
+ start: leaves.start,
194
+ angle: leaves.angle
195
+ },
196
+ bark: {
197
+ type: materials.bark.type ?? "furrowed",
198
+ color: materials.bark.color
199
+ }
200
+ };
201
+ }
202
+ function draw(name, { base, foliage, bark }) {
203
+ const look = LOOKS[name];
204
+ const leaf = look.leaf(foliage.type);
205
+ const fruit = base.fruit;
206
+ return parseDefinition({
207
+ ...base,
208
+ ...fruit ? { fruit: {
209
+ ...fruit,
210
+ sides: look.fruitSides
211
+ } } : {},
212
+ trunk: {
213
+ ...base.trunk,
214
+ ...look.trunk
215
+ },
216
+ branches: base.branches.map((level, i) => ({
217
+ ...level,
218
+ ...look.branches[Math.min(i, look.branches.length - 1)]
219
+ })),
220
+ leaves: {
221
+ type: foliage.type,
222
+ count: Math.round(foliage.density * leaf.perDensity),
223
+ shape: leaf.shape,
224
+ size: foliage.size * leaf.sizeScale,
225
+ sizeVariation: foliage.sizeVariation,
226
+ start: foliage.start,
227
+ angle: foliage.angle
228
+ },
229
+ materials: {
230
+ shading: styleShading(name),
231
+ bark: {
232
+ type: bark.type,
233
+ color: bark.color,
234
+ ...look.bark(bark.type)
235
+ },
236
+ leaf: { ...leaf.material }
237
+ }
238
+ });
239
+ }
240
+ /**
241
+ * Applies a built-in Style's look to a Species or a Tree Definition (see `TreeStyle.apply`).
242
+ * Pure: never mutates its inputs.
243
+ */
244
+ function applyStyle(name, source, overrides) {
245
+ const definition = draw(name, "schemaVersion" in source ? fromDefinition(source) : fromSpecies(source));
246
+ return overrides ? extendDefinition(definition, overrides) : definition;
247
+ }
248
+ export { TEXTURES as i, BARK_TEXTURES as n, LEAF_TEXTURES as r, applyStyle as t };
249
+
250
+ //# sourceMappingURL=apply-CcodnAbs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-CcodnAbs.js","names":[],"sources":["../src/styles/realistic/textures.ts","../src/styles/apply.ts"],"sourcesContent":["import type { BarkType, LeafType } from '../../definition/types';\n\n/**\n * The realistic Style's texture files, as relative URLs (resolved against the texture base path).\n * All made by scripts/generate-textures.mjs. `bark`/`barkNormal` are the furrowed pair, `leaf` the\n * broad card and `needles` the needle card (the generic broadleaf / conifer use these).\n */\nexport const TEXTURES = {\n bark: 'realistic/bark.png',\n barkNormal: 'realistic/bark-normal.png',\n leaf: 'realistic/leaf.png',\n needles: 'realistic/needles.png',\n} as const;\n\n/** The alpha-cut leaf card texture for each Leaf Type. */\nexport const LEAF_TEXTURES: Readonly<Record<LeafType, string>> = {\n broad: TEXTURES.leaf,\n lobed: 'realistic/leaf-lobed.png',\n palmate: 'realistic/leaf-palmate.png',\n compound: 'realistic/leaf-compound.png',\n needle: TEXTURES.needles,\n scale: 'realistic/scale.png',\n};\n\n/** The colour + normal map pair for each Bark Type. */\nexport const BARK_TEXTURES: Readonly<Record<BarkType, { map: string; normalMap: string }>> = {\n furrowed: { map: TEXTURES.bark, normalMap: TEXTURES.barkNormal },\n smooth: { map: 'realistic/bark-smooth.png', normalMap: 'realistic/bark-smooth-normal.png' },\n papery: { map: 'realistic/bark-papery.png', normalMap: 'realistic/bark-papery-normal.png' },\n fibrous: { map: 'realistic/bark-fibrous.png', normalMap: 'realistic/bark-fibrous-normal.png' },\n plated: { map: 'realistic/bark-plated.png', normalMap: 'realistic/bark-plated-normal.png' },\n};\n","// Style.apply (ADR 0005): a Style turns a Style-neutral Species (or an existing Tree Definition)\n// into a complete Tree Definition by choosing only the look: shading, polygon detail, how the\n// Leaf Type and Bark Type are drawn, and textures. Shape fields pass through untouched.\nimport { extendDefinition, parseDefinition, type DefinitionPatch } from '../definition/parse';\nimport {\n CURRENT_SCHEMA_VERSION,\n type BarkMaterialDefinition,\n type BarkType,\n type LeafMaterialDefinition,\n type LeafShape,\n type LeafType,\n type TreeDefinition,\n type TreeDefinitionInput,\n} from '../definition/types';\nimport type { SpeciesBarkDefinition, SpeciesDefinition, SpeciesFoliageDefinition } from '../species/types';\nimport { styleOfShading, styleShading, type StyleName } from './names';\nimport { BARK_TEXTURES, LEAF_TEXTURES } from './realistic/textures';\n\n/** Polygon detail of one tree part. */\ninterface Detail {\n sides: number;\n sections: number;\n}\n\n/** How a Style draws one Leaf Type. */\ninterface LeafLook {\n shape: LeafShape;\n /** Leaves per terminal branch at density 1 (count = round(density × this)). */\n perDensity: number;\n /** Leaf size = the Species' real leaf-spray size × this. */\n sizeScale: number;\n material: LeafMaterialDefinition;\n}\n\n/** Everything a Style decides about a tree: its look (its shading is in names.ts). */\ninterface StyleLook {\n trunk: Detail;\n /** Detail per branch level; deeper levels reuse the last entry. */\n branches: Detail[];\n bark(type: BarkType): Omit<BarkMaterialDefinition, 'type' | 'color'>;\n leaf(type: LeafType): LeafLook;\n /** Faces around each Fruit (`fruit.sides`): few flat facets in low-poly, smooth in the others. */\n fruitSides: number;\n}\n\nconst isNeedleLike = (type: LeafType) => type === 'needle' || type === 'scale';\nconst untexturedLeaf: LeafMaterialDefinition = { roughness: 1, map: null, alphaTest: 0.5 };\nconst untexturedBark = () => ({ roughness: 1, map: null, normalMap: null });\n\n// Low-poly and stylized are calibrated so a Species with density 0.5 and leaf-spray size 0.35 m comes\n// out close to each Style's own broadleaf / conifer Definitions. Realistic draws far more (cheap, 2\n// triangle) cards per twig than its own Definitions: a Species has fewer twigs than the realistic\n// generic trees (the low-poly and stylized triangle budgets cap them at about 40-90), so the cards\n// have to fill the crown. Deeper branch levels get little detail (twigs are thin and many).\nconst LOOKS = {\n 'low-poly': {\n trunk: { sides: 5, sections: 4 },\n branches: [{ sides: 4, sections: 2 }, { sides: 3, sections: 1 }],\n bark: untexturedBark,\n fruitSides: 4,\n leaf: (type) =>\n isNeedleLike(type)\n ? { shape: 'needle', perDensity: 14, sizeScale: 1.86, material: untexturedLeaf }\n : { shape: 'clump', perDensity: 4, sizeScale: 2.86, material: untexturedLeaf },\n },\n stylized: {\n trunk: { sides: 10, sections: 8 },\n branches: [{ sides: 6, sections: 3 }, { sides: 4, sections: 1 }, { sides: 3, sections: 1 }],\n bark: untexturedBark,\n fruitSides: 6,\n // All puffs; smaller and denser for needle / scale foliage.\n leaf: (type) =>\n isNeedleLike(type)\n ? { shape: 'puff', perDensity: 8, sizeScale: 1.7, material: untexturedLeaf }\n : { shape: 'puff', perDensity: 4, sizeScale: 3.14, material: untexturedLeaf },\n },\n realistic: {\n trunk: { sides: 12, sections: 10 },\n branches: [{ sides: 8, sections: 6 }, { sides: 5, sections: 4 }, { sides: 3, sections: 2 }],\n // A texture per Bark Type and per Leaf Type (scripts/generate-textures.mjs).\n bark: (type) => ({ roughness: 0.95, ...BARK_TEXTURES[type] }),\n fruitSides: 9,\n leaf: (type) =>\n isNeedleLike(type)\n ? { shape: 'card', perDensity: 120, sizeScale: 1.7, material: { roughness: 0.7, map: LEAF_TEXTURES[type], alphaTest: 0.4 } }\n : { shape: 'card', perDensity: 80, sizeScale: 2.2, material: { roughness: 0.65, map: LEAF_TEXTURES[type], alphaTest: 0.4 } },\n },\n} satisfies Record<StyleName, StyleLook>;\n\n/** What `Style.apply` accepts: a Species, or a Tree Definition to re-style. */\nexport type StyleSource = SpeciesDefinition | TreeDefinition | TreeDefinitionInput;\n\n/** The Style-neutral content of a source: every non-look field, plus foliage and bark. */\ninterface Neutral {\n /** Definition fields that pass through (shape, Season, Wind, Sculpts, Fruit, ...). */\n base: Record<string, unknown> & { trunk: object; branches: object[] };\n foliage: SpeciesFoliageDefinition;\n bark: SpeciesBarkDefinition;\n}\n\nfunction fromSpecies(species: SpeciesDefinition): Neutral {\n const { id, name, trunk, branches, season, wind, variation, fruit, foliage, bark } = species;\n return {\n base: {\n schemaVersion: CURRENT_SCHEMA_VERSION,\n name,\n species: id,\n trunk,\n branches,\n season,\n wind,\n variation,\n sculpts: [],\n ...(fruit ? { fruit } : {}),\n },\n foliage,\n bark,\n };\n}\n\nfunction fromDefinition(input: TreeDefinition | TreeDefinitionInput): Neutral {\n const definition = parseDefinition(input);\n const { leaves, materials, ...base } = definition;\n // Definitions not made by `apply` carry no Leaf / Bark Type: guess them from how they are drawn.\n const leafType = leaves.type ?? (leaves.shape === 'needle' || /needle/.test(materials.leaf.map ?? '') ? 'needle' : 'broad');\n const source = LOOKS[styleOfShading(materials.shading)].leaf(leafType);\n return {\n base,\n foliage: {\n type: leafType,\n density: leaves.count / source.perDensity,\n size: leaves.size / source.sizeScale,\n sizeVariation: leaves.sizeVariation,\n start: leaves.start,\n angle: leaves.angle,\n },\n bark: { type: materials.bark.type ?? 'furrowed', color: materials.bark.color },\n };\n}\n\nfunction draw(name: StyleName, { base, foliage, bark }: Neutral): TreeDefinition {\n const look: StyleLook = LOOKS[name];\n const leaf = look.leaf(foliage.type);\n const fruit = base.fruit as TreeDefinition['fruit'];\n return parseDefinition({\n ...base,\n ...(fruit ? { fruit: { ...fruit, sides: look.fruitSides } } : {}),\n trunk: { ...base.trunk, ...look.trunk },\n branches: base.branches.map((level, i) => ({ ...level, ...look.branches[Math.min(i, look.branches.length - 1)] })),\n leaves: {\n type: foliage.type,\n count: Math.round(foliage.density * leaf.perDensity),\n shape: leaf.shape,\n size: foliage.size * leaf.sizeScale,\n sizeVariation: foliage.sizeVariation,\n start: foliage.start,\n angle: foliage.angle,\n },\n materials: {\n shading: styleShading(name),\n bark: { type: bark.type, color: bark.color, ...look.bark(bark.type) },\n leaf: { ...leaf.material },\n },\n });\n}\n\n/**\n * Applies a built-in Style's look to a Species or a Tree Definition (see `TreeStyle.apply`).\n * Pure: never mutates its inputs.\n */\nexport function applyStyle(name: StyleName, source: StyleSource, overrides?: DefinitionPatch): TreeDefinition {\n const neutral = 'schemaVersion' in source ? fromDefinition(source) : fromSpecies(source);\n const definition = draw(name, neutral);\n return overrides ? extendDefinition(definition, overrides) : definition;\n}\n"],"mappings":";;;;;;;AAOA,IAAa,WAAW;CACtB,MAAM;CACN,YAAY;CACZ,MAAM;CACN,SAAS;AACX;;AAGA,IAAa,gBAAoD;CAC/D,OAAO,SAAS;CAChB,OAAO;CACP,SAAS;CACT,UAAU;CACV,QAAQ,SAAS;CACjB,OAAO;AACT;;AAGA,IAAa,gBAAgF;CAC3F,UAAU;EAAE,KAAK,SAAS;EAAM,WAAW,SAAS;CAAW;CAC/D,QAAQ;EAAE,KAAK;EAA6B,WAAW;CAAmC;CAC1F,QAAQ;EAAE,KAAK;EAA6B,WAAW;CAAmC;CAC1F,SAAS;EAAE,KAAK;EAA8B,WAAW;CAAoC;CAC7F,QAAQ;EAAE,KAAK;EAA6B,WAAW;CAAmC;AAC5F;;ACcA,IAAM,gBAAgB,SAAmB,SAAS,YAAY,SAAS;AACvE,IAAM,iBAAyC;CAAE,WAAW;CAAG,KAAK;CAAM,WAAW;AAAI;AACzF,IAAM,wBAAwB;CAAE,WAAW;CAAG,KAAK;CAAM,WAAW;AAAK;AAOzE,IAAM,QAAQ;CACZ,YAAY;EACV,OAAO;GAAE,OAAO;GAAG,UAAU;EAAE;EAC/B,UAAU,CAAC;GAAE,OAAO;GAAG,UAAU;EAAE,GAAG;GAAE,OAAO;GAAG,UAAU;EAAE,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SAAS,aAAa,IAAI;GAC1B,MAAM;IAAE,MAAM,KAAK;IAAM,OAAO,KAAK;IAAO,GAAG,KAAK,KAAK,KAAK,IAAI;GAAE;GACpE,MAAM,EAAE,GAAG,KAAK,SAAS;EAC3B;CACF,CAAC;AACH;;;;;AAMA,SAAgB,WAAW,MAAiB,QAAqB,WAA6C;CAE5G,MAAM,aAAa,KAAK,MADR,mBAAmB,SAAS,eAAe,MAAM,IAAI,YAAY,MAAM,CAClD;CACrC,OAAO,YAAY,iBAAiB,YAAY,SAAS,IAAI;AAC/D"}
@@ -4,7 +4,7 @@ import type { Tree } from '../tree';
4
4
  * Baked Tree: one tree frozen at a Seed, Growth and Season as plain static geometry with
5
5
  * standard PBR materials (`MeshStandardMaterial`, no node materials, no custom attributes), for
6
6
  * glTF export and other tools. Growth and Season are evaluated on the CPU with the same models the
7
- * shaders run (`growPositions`, `leafSeason`); Wind is left out (a Baked Tree stands still).
7
+ * shaders run (`growPositions`, `leafSeason`, `fruitSeason`); Wind is left out (a Baked Tree stands still).
8
8
  */
9
9
  /** Growth and Season to bake at; each defaults to the tree's current value. */
10
10
  export interface BakeOptions {
@@ -13,7 +13,7 @@ export interface BakeOptions {
13
13
  }
14
14
  /**
15
15
  * Freezes a tree at a Growth and Season (default: the tree's own) into a static `Group` of
16
- * meshes `wood` and `leaves` (a mesh with nothing to show is left out) with standard PBR
16
+ * meshes `wood`, `leaves` and `fruit` (a mesh with nothing to show is left out) with standard PBR
17
17
  * materials: no node materials, no Growth/Season/Wind attributes, no animation. The result is
18
18
  * independent of `tree`; call `disposeBakedTree` when done with it.
19
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bake/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,EAIN,MAAM,cAAc,CAAC;AAQtB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,W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,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,WAAgB,GAAG,KAAK,CAyDrE;AASD,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CASnD;AAED,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IACzD,2EAA2E;IAC3E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG;IAAE,MAAM,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACxH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAsB,GAAG;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACnI,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Keyframe } from './types';
2
+ /**
3
+ * The conifer cone as a Crown Shape length curve for a branch level starting at `start`: full length
4
+ * at `start`, shrinking linearly to a tenth of it near the trunk tip, never below a tenth (the v2
5
+ * generator's `max(0.1, (1 - t) / (1 - start))`). Written by the v2 -> v3 migration and used by every
6
+ * Style's own conifer.
7
+ */
8
+ export declare function coneCurve(start: number): Keyframe<number>[];
9
+ //# sourceMappingURL=crown-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crown-shape.d.ts","sourceRoot":"","sources":["../../src/definition/crown-shape.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,CAO3D"}
@@ -1,6 +1,12 @@
1
- import { type BranchLevelDefinition, type TreeDefinition } from './types';
1
+ import { type BranchLevelDefinition, type FruitDefinition, type HexColor, type Keyframe, type TreeDefinition } from './types';
2
2
  /** Defaults for one branching level; fills fields missing from a partial `branches[i]`. */
3
3
  export declare const DEFAULT_BRANCH_LEVEL: BranchLevelDefinition;
4
+ /** Defaults for the fields of a `fruit` block (a Definition has no Fruit unless it has the block). */
5
+ export declare const DEFAULT_FRUIT: FruitDefinition;
6
+ /** Fruit amount when the Season Profile has no `fruit` track: all Fruit at full size all year. */
7
+ export declare const DEFAULT_FRUIT_AMOUNT: Keyframe<number>[];
8
+ /** Fruit colour when the Season Profile has no `fruitColor` track. */
9
+ export declare const DEFAULT_FRUIT_COLOR: Keyframe<HexColor>[];
4
10
  /**
5
11
  * The documented defaults: a small broadleaf tree with two branching levels.
6
12
  * Anything a Definition leaves out is taken from here.
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/definition/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,qBAAqB,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAElG,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,EAAE,qBAelC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,cAqDhC,CAAC"}
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/definition/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAEjB,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,EAAE,qBAelC,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,aAAa,EAAE,eAM3B,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAyB,CAAC;AAE7E,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAiC,CAAC;AAEtF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,cAoDhC,CAAC"}
@@ -1,5 +1,6 @@
1
- export { CURRENT_SCHEMA_VERSION, MAX_BRANCH_LEVELS } from './types';
2
- export type { TreeDefinition, TreeDefinitionInput, DeepPartial, HexColor, Vec3Tuple, TreeForm, TrunkDefinition, BranchLevelDefinition, LeafShape, LeavesDefinition, Shading, MaterialsDefinition, BarkMaterialDefinition, LeafMaterialDefinition, Keyframe, SeasonProfileDefinition, WindResponseDefinition, VariationDefinition, Sculpt, DeleteSculpt, MoveSculpt, LeavesSculpt, } from './types';
3
- export { DEFAULT_DEFINITION, DEFAULT_BRANCH_LEVEL } from './defaults';
1
+ export { BARK_TYPES, CURRENT_SCHEMA_VERSION, FRUIT_TYPES, LEAF_TYPES, MAX_BRANCH_LEVELS } from './types';
2
+ export type { TreeDefinition, TreeDefinitionInput, DeepPartial, HexColor, Vec3Tuple, TreeForm, TrunkDefinition, BranchLevelDefinition, LeafShape, LeafType, BarkType, LeavesDefinition, FruitType, FruitDefinition, Shading, MaterialsDefinition, BarkMaterialDefinition, LeafMaterialDefinition, Keyframe, SeasonProfileDefinition, WindResponseDefinition, VariationDefinition, Sculpt, DeleteSculpt, MoveSculpt, LeavesSculpt, } from './types';
3
+ export { coneCurve } from './crown-shape';
4
+ export { DEFAULT_DEFINITION, DEFAULT_BRANCH_LEVEL, DEFAULT_FRUIT, DEFAULT_FRUIT_AMOUNT, DEFAULT_FRUIT_COLOR } from './defaults';
4
5
  export { parseDefinition, extendDefinition, fetchDefinition, TreeDefinitionError, type DefinitionPatch, } from './parse';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACpE,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,QAAQ,EACR,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,EACN,YAAY,EACZ,UAAU,EACV,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACzG,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,QAAQ,EACR,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,EACN,YAAY,EACZ,UAAU,EACV,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAChI,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC"}
@@ -1,11 +1,3 @@
1
- /**
2
- * Schema migrations. `MIGRATIONS[n]` turns a raw (unvalidated) schemaVersion `n` object into
3
- * a raw schemaVersion `n + 1` object. Migrations run in order before defaults and validation,
4
- * so they only need to move/rename what changed; missing fields are defaulted afterwards.
5
- *
6
- * To change the format: bump CURRENT_SCHEMA_VERSION, add `MIGRATIONS[old]`, and add a
7
- * fixture in test/fixtures/definition-v<old>.json with a test.
8
- */
9
1
  type Raw = Record<string, unknown>;
10
2
  export declare const MIGRATIONS: Record<number, (input: Raw) => Raw>;
11
3
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/definition/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnC,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAgB1D,CAAC"}
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/definition/migrations.ts"],"names":[],"mappings":"AAWA,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnC,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAmC1D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/definition/schema.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAEjB,6GAA6G;AAC7G,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK3C;AAYD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEjE;AA+JD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAE/E"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/definition/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAgBL,KAAK,cAAc,EAEpB,MAAM,SAAS,CAAC;AAEjB,6GAA6G;AAC7G,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK3C;AAYD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEjE;AAiMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAE/E"}