@casmo/tree.js 0.0.0-stage → 0.1.1
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.
- package/LICENSE +21 -0
- package/README.md +485 -2
- package/dist/bake/index.d.ts +39 -0
- package/dist/bake/index.d.ts.map +1 -0
- package/dist/definition/defaults.d.ts +9 -0
- package/dist/definition/defaults.d.ts.map +1 -0
- package/dist/definition/index.d.ts +5 -0
- package/dist/definition/index.d.ts.map +1 -0
- package/dist/definition/migrations.d.ts +12 -0
- package/dist/definition/migrations.d.ts.map +1 -0
- package/dist/definition/parse.d.ts +30 -0
- package/dist/definition/parse.d.ts.map +1 -0
- package/dist/definition/schema.d.ts +13 -0
- package/dist/definition/schema.d.ts.map +1 -0
- package/dist/definition/types.d.ts +217 -0
- package/dist/definition/types.d.ts.map +1 -0
- package/dist/effects/effects.d.ts +46 -0
- package/dist/effects/effects.d.ts.map +1 -0
- package/dist/effects/glow.d.ts +19 -0
- package/dist/effects/glow.d.ts.map +1 -0
- package/dist/effects/grade.d.ts +19 -0
- package/dist/effects/grade.d.ts.map +1 -0
- package/dist/effects/index.d.ts +7 -0
- package/dist/effects/index.d.ts.map +1 -0
- package/dist/effects/mask.d.ts +44 -0
- package/dist/effects/mask.d.ts.map +1 -0
- package/dist/effects/outline.d.ts +18 -0
- package/dist/effects/outline.d.ts.map +1 -0
- package/dist/effects/suggested.d.ts +13 -0
- package/dist/effects/suggested.d.ts.map +1 -0
- package/dist/effects.js +249 -0
- package/dist/effects.js.map +1 -0
- package/dist/forest/Forest.d.ts +156 -0
- package/dist/forest/Forest.d.ts.map +1 -0
- package/dist/forest/index.d.ts +14 -0
- package/dist/forest/index.d.ts.map +1 -0
- package/dist/forest/nodes.d.ts +31 -0
- package/dist/forest/nodes.d.ts.map +1 -0
- package/dist/forest/placement.d.ts +52 -0
- package/dist/forest/placement.d.ts.map +1 -0
- package/dist/forest-OX9WvAwh.js +3057 -0
- package/dist/forest-OX9WvAwh.js.map +1 -0
- package/dist/generator/attributes.d.ts +20 -0
- package/dist/generator/attributes.d.ts.map +1 -0
- package/dist/generator/branches.d.ts +12 -0
- package/dist/generator/branches.d.ts.map +1 -0
- package/dist/generator/frames.d.ts +21 -0
- package/dist/generator/frames.d.ts.map +1 -0
- package/dist/generator/growth.d.ts +15 -0
- package/dist/generator/growth.d.ts.map +1 -0
- package/dist/generator/index.d.ts +22 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/leaf-shapes.d.ts +10 -0
- package/dist/generator/leaf-shapes.d.ts.map +1 -0
- package/dist/generator/leaves.d.ts +14 -0
- package/dist/generator/leaves.d.ts.map +1 -0
- package/dist/generator/mesh.d.ts +11 -0
- package/dist/generator/mesh.d.ts.map +1 -0
- package/dist/generator/sculpt.d.ts +28 -0
- package/dist/generator/sculpt.d.ts.map +1 -0
- package/dist/generator/trunk.d.ts +6 -0
- package/dist/generator/trunk.d.ts.map +1 -0
- package/dist/generator/types.d.ts +126 -0
- package/dist/generator/types.d.ts.map +1 -0
- package/dist/generator/vec.d.ts +12 -0
- package/dist/generator/vec.d.ts.map +1 -0
- package/dist/generator/wind.d.ts +27 -0
- package/dist/generator/wind.d.ts.map +1 -0
- package/dist/growth/evaluate.d.ts +32 -0
- package/dist/growth/evaluate.d.ts.map +1 -0
- package/dist/growth/index.d.ts +3 -0
- package/dist/growth/index.d.ts.map +1 -0
- package/dist/growth/tsl.d.ts +12 -0
- package/dist/growth/tsl.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +198 -0
- package/dist/index.js.map +1 -0
- package/dist/materials/index.d.ts +18 -0
- package/dist/materials/index.d.ts.map +1 -0
- package/dist/materials/maps.d.ts +23 -0
- package/dist/materials/maps.d.ts.map +1 -0
- package/dist/materials/shading.d.ts +18 -0
- package/dist/materials/shading.d.ts.map +1 -0
- package/dist/materials/toon.d.ts +12 -0
- package/dist/materials/toon.d.ts.map +1 -0
- package/dist/math/index.d.ts +23 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/profiles-BAiyeFlh.js +113 -0
- package/dist/profiles-BAiyeFlh.js.map +1 -0
- package/dist/random/index.d.ts +37 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/react/Forest.d.ts +54 -0
- package/dist/react/Forest.d.ts.map +1 -0
- package/dist/react/Tree.d.ts +41 -0
- package/dist/react/Tree.d.ts.map +1 -0
- package/dist/react/Wind.d.ts +17 -0
- package/dist/react/Wind.d.ts.map +1 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/useTreeStyle.d.ts +15 -0
- package/dist/react/useTreeStyle.d.ts.map +1 -0
- package/dist/react.js +239 -0
- package/dist/react.js.map +1 -0
- package/dist/renderer/index.d.ts +7 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/season/check.d.ts +3 -0
- package/dist/season/check.d.ts.map +1 -0
- package/dist/season/index.d.ts +4 -0
- package/dist/season/index.d.ts.map +1 -0
- package/dist/season/nodes.d.ts +32 -0
- package/dist/season/nodes.d.ts.map +1 -0
- package/dist/season/profile.d.ts +78 -0
- package/dist/season/profile.d.ts.map +1 -0
- package/dist/season/profiles.d.ts +40 -0
- package/dist/season/profiles.d.ts.map +1 -0
- package/dist/styles/low-poly/index.d.ts +16 -0
- package/dist/styles/low-poly/index.d.ts.map +1 -0
- package/dist/styles/low-poly.js +165 -0
- package/dist/styles/low-poly.js.map +1 -0
- package/dist/styles/realistic/index.d.ts +23 -0
- package/dist/styles/realistic/index.d.ts.map +1 -0
- package/dist/styles/realistic.js +206 -0
- package/dist/styles/realistic.js.map +1 -0
- package/dist/styles/registry.d.ts +17 -0
- package/dist/styles/registry.d.ts.map +1 -0
- package/dist/styles/stylized/index.d.ts +17 -0
- package/dist/styles/stylized/index.d.ts.map +1 -0
- package/dist/styles/stylized.js +266 -0
- package/dist/styles/stylized.js.map +1 -0
- package/dist/styles/types.d.ts +12 -0
- package/dist/styles/types.d.ts.map +1 -0
- package/dist/textures/index.d.ts +44 -0
- package/dist/textures/index.d.ts.map +1 -0
- package/dist/textures/realistic/bark-normal.png +0 -0
- package/dist/textures/realistic/bark.png +0 -0
- package/dist/textures/realistic/leaf.png +0 -0
- package/dist/textures/realistic/needles.png +0 -0
- package/dist/tree/Tree.d.ts +70 -0
- package/dist/tree/Tree.d.ts.map +1 -0
- package/dist/tree/index.d.ts +14 -0
- package/dist/tree/index.d.ts.map +1 -0
- package/dist/types-BZjHhNz7.js +20 -0
- package/dist/types-BZjHhNz7.js.map +1 -0
- package/dist/wind/Wind.d.ts +54 -0
- package/dist/wind/Wind.d.ts.map +1 -0
- package/dist/wind/index.d.ts +4 -0
- package/dist/wind/index.d.ts.map +1 -0
- package/dist/wind/node.d.ts +38 -0
- package/dist/wind/node.d.ts.map +1 -0
- package/dist/wind/response.d.ts +27 -0
- package/dist/wind/response.d.ts.map +1 -0
- package/package.json +107 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TreeDefinition } from '../definition';
|
|
2
|
+
import type { GeometryBuffers, TreeData, TreeSkeleton } from './types';
|
|
3
|
+
export { growthTiming } from './growth';
|
|
4
|
+
export type { GrowthTiming, GrowthWindow, GeometryBuffers, TreeAttributes, VertexAttribute, SkeletonBranch, SkeletonLeaf, SkeletonPoint, TreeData, TreeSkeleton, Vec3 } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* The Generator: a pure function from a (parsed) Tree Definition and a Seed to tree data.
|
|
7
|
+
* No three.js, no GPU, no globals; runs in Node. Same input, same output, on every machine.
|
|
8
|
+
*
|
|
9
|
+
* Each part of the tree draws from its own `random.fork(<part>)` stream so that adding
|
|
10
|
+
* a new part never shifts the numbers of an existing one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateTree(definition: TreeDefinition, seed: number): TreeData;
|
|
13
|
+
/**
|
|
14
|
+
* Height of the (possibly Sculpted) trunk's tip: the scale of a tree's Wind sway. A Sculpt may
|
|
15
|
+
* delete the trunk (an empty tree, nothing sways); the height is then 1.
|
|
16
|
+
*/
|
|
17
|
+
export declare function trunkHeight(skeleton: Pick<TreeSkeleton, 'branches'>): number;
|
|
18
|
+
/** Stable 32-bit hash (hex) of the generated geometry buffers, for determinism checks. */
|
|
19
|
+
export declare function hashGeometry(geometry: GeometryBuffers): string;
|
|
20
|
+
/** Stable hash of a tree's generated geometry (wood and leaves). */
|
|
21
|
+
export declare function hashTreeData(data: TreeData): string;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAWpD,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEvL;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CA6B/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,MAAM,CAG5E;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAE9D;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LeafShape, VariationDefinition } from '../definition';
|
|
2
|
+
import type { GeometryBuffers, GrowthWindow, SkeletonLeaf } from './types';
|
|
3
|
+
import { type PartSway } from './wind';
|
|
4
|
+
/**
|
|
5
|
+
* Leaf geometry for the solid shapes ('clump', 'needle', 'puff'): one small closed mesh per leaf,
|
|
6
|
+
* placed in the leaf's frame (across, normal, direction) and scaled by its size. Like cards,
|
|
7
|
+
* every vertex carries the leaf's tint as its colour and the leaf's part attributes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function solidLeafGeometry(leaves: SkeletonLeaf[], shape: Exclude<LeafShape, 'card'>, level: number, seed: number, variation?: Pick<VariationDefinition, 'season'>, growth?: GrowthWindow[], branchSway?: ReadonlyMap<string, PartSway>): GeometryBuffers;
|
|
10
|
+
//# sourceMappingURL=leaf-shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leaf-shapes.d.ts","sourceRoot":"","sources":["../../src/generator/leaf-shapes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAQ,MAAM,SAAS,CAAC;AACjF,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAgG1D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EAAE,EACtB,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EACjC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAiB,EAC9D,MAAM,GAAE,YAAY,EAAO,EAC3B,UAAU,GAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAa,GACpD,eAAe,CAqCjB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TreeDefinition, VariationDefinition } from '../definition';
|
|
2
|
+
import type { Random } from '../random';
|
|
3
|
+
import type { GeometryBuffers, GrowthWindow, SkeletonBranch, SkeletonLeaf } from './types';
|
|
4
|
+
import { type PartSway } from './wind';
|
|
5
|
+
/**
|
|
6
|
+
* Places leaves on the outermost branches (the trunk if there are no branch levels).
|
|
7
|
+
* Each leaf draws from `random.fork(leafId)`, so leaves never shift the branches and
|
|
8
|
+
* one leaf never shifts another. The colour tint shared by the whole tree comes from
|
|
9
|
+
* `random.fork('tint')`. The shape ('card' here, 'clump'/'needle'/'puff' in `leaf-shapes.ts`) only affects the mesh.
|
|
10
|
+
*/
|
|
11
|
+
export declare function placeLeaves(definition: TreeDefinition, branches: SkeletonBranch[], random: Random): SkeletonLeaf[];
|
|
12
|
+
/** One diamond-shaped card per leaf (4 vertices, 2 triangles); vertex colours carry the leaf's tint. */
|
|
13
|
+
export declare function leafGeometry(leaves: SkeletonLeaf[], level: number, seed: number, variation?: Pick<VariationDefinition, 'season'>, growth?: GrowthWindow[], branchSway?: ReadonlyMap<string, PartSway>): GeometryBuffers;
|
|
14
|
+
//# sourceMappingURL=leaves.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leaves.d.ts","sourceRoot":"","sources":["../../src/generator/leaves.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAIxC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAQ,MAAM,SAAS,CAAC;AACjG,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAO1D;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAmClH;AAED,wGAAwG;AACxG,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,EAAE,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAiB,EAC9D,MAAM,GAAE,YAAY,EAAO,EAC3B,UAAU,GAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAa,GACpD,eAAe,CAuCjB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PartSeason } from '../season/profile';
|
|
2
|
+
import type { GeometryBuffers, GrowthWindow, SkeletonBranch } from './types';
|
|
3
|
+
import type { PartSway } from './wind';
|
|
4
|
+
/**
|
|
5
|
+
* Sweeps a ring of `sides` vertices along a branch's points, using parallel-transport
|
|
6
|
+
* frames so branches in any direction get even rings, and caps the tip.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sweepBranch(branch: SkeletonBranch, sides: number, random: number, season?: PartSeason, growth?: GrowthWindow, sway?: PartSway): GeometryBuffers;
|
|
9
|
+
/** Concatenates geometry buffers into one (indices are offset). */
|
|
10
|
+
export declare function mergeBuffers(parts: GeometryBuffers[]): GeometryBuffers;
|
|
11
|
+
//# sourceMappingURL=mesh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../src/generator/mesh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGvC;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,UAA0D,EAClE,MAAM,GAAE,YAAmC,EAC3C,IAAI,CAAC,EAAE,QAAQ,GACd,eAAe,CAiDjB;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,eAAe,CAwBtE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Sculpt, TreeDefinition } from '../definition';
|
|
2
|
+
import type { SkeletonBranch, SkeletonLeaf } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* The Sculpt pass (ADR 0003): hand edits stored in the Definition, applied after the procedural
|
|
5
|
+
* skeleton is grown and before leaves, Growth timing, Wind weights and meshes are derived from it.
|
|
6
|
+
* So a sculpted part still grows, changes with the Season and sways like any other.
|
|
7
|
+
*
|
|
8
|
+
* A Sculpt only applies on the Seed it was made on; every other Seed ignores it. Sculpts apply in
|
|
9
|
+
* Definition order. A Sculpt whose path does not exist (any more) for this Seed is skipped.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sculptsFor(definition: TreeDefinition, seed: number): Sculpt[];
|
|
12
|
+
/** True if `path` is `root` or grows from it (its descendants). */
|
|
13
|
+
export declare const inSubtree: (path: string, root: string) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Applies the branch Sculpts to the skeleton branches (returns a new array, paths unchanged):
|
|
16
|
+
* - `delete` drops the branch and everything growing from it;
|
|
17
|
+
* - `move` rotates (Euler XYZ, radians, three.js convention, in tree space) and scales the branch
|
|
18
|
+
* and everything growing from it about the branch base. `scale` scales lengths; radii stay.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sculptBranches(branches: SkeletonBranch[], sculpts: Sculpt[]): SkeletonBranch[];
|
|
21
|
+
/**
|
|
22
|
+
* Applies the `leaves` Sculpts (painting): each sets the coverage (0..1) of a branch and everything
|
|
23
|
+
* growing from it; a later Sculpt on a sub-branch overrides it there. A leaf is kept while its own
|
|
24
|
+
* stable random number (from the Seed and leaf id) is below its coverage, so painting more coverage
|
|
25
|
+
* only ever adds leaves. Season coverage then applies on top of the kept leaves as usual.
|
|
26
|
+
*/
|
|
27
|
+
export declare function sculptLeaves(leaves: SkeletonLeaf[], sculpts: Sculpt[], seed: number): SkeletonLeaf[];
|
|
28
|
+
//# sourceMappingURL=sculpt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sculpt.d.ts","sourceRoot":"","sources":["../../src/generator/sculpt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAQ,MAAM,SAAS,CAAC;AAGlE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE7E;AAED,mEAAmE;AACnE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,OAAuD,CAAC;AAE/G;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAuB9F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAQpG"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TreeDefinition } from '../definition';
|
|
2
|
+
import type { Random } from '../random';
|
|
3
|
+
import type { SkeletonBranch } from './types';
|
|
4
|
+
/** Builds the trunk centre line from the Definition, varied by the Seed within its ranges. */
|
|
5
|
+
export declare function buildTrunk(definition: TreeDefinition, random: Random): SkeletonBranch;
|
|
6
|
+
//# sourceMappingURL=trunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trunk.d.ts","sourceRoot":"","sources":["../../src/generator/trunk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,SAAS,CAAC;AAE7D,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAkBrF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export type Vec3 = [number, number, number];
|
|
2
|
+
/** One point on a branch's centre line. */
|
|
3
|
+
export interface SkeletonPoint {
|
|
4
|
+
position: Vec3;
|
|
5
|
+
radius: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* One branch of the skeleton. `path` is stable for a given Definition and Seed
|
|
9
|
+
* (ADR 0003): the trunk is "0", its children "0.0", "0.1", ... (ticket #4).
|
|
10
|
+
*/
|
|
11
|
+
export interface SkeletonBranch {
|
|
12
|
+
path: string;
|
|
13
|
+
/** Path of the parent branch, or null for the trunk. */
|
|
14
|
+
parent: string | null;
|
|
15
|
+
/** 0 = trunk, 1 = first branching level, ... */
|
|
16
|
+
level: number;
|
|
17
|
+
/** Where the branch sits on its parent, as a fraction (0..1) of the parent's length; 0 for the trunk. */
|
|
18
|
+
attach: number;
|
|
19
|
+
/** Unit direction the branch leaves its parent in (before bend and gravity); straight up for the trunk. */
|
|
20
|
+
direction: Vec3;
|
|
21
|
+
points: SkeletonPoint[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* One leaf. `id` is `<branch path>/<index>`, stable for a given Definition and Seed,
|
|
25
|
+
* so leaf Sculpts (painting) can address it.
|
|
26
|
+
*/
|
|
27
|
+
export interface SkeletonLeaf {
|
|
28
|
+
id: string;
|
|
29
|
+
/** Path of the branch the leaf grows on. */
|
|
30
|
+
branch: string;
|
|
31
|
+
/** Index of the leaf on its branch (0 nearest the branch base). */
|
|
32
|
+
index: number;
|
|
33
|
+
/** Where the leaf sits on its branch, as a fraction (0..1) of the branch length. */
|
|
34
|
+
attach: number;
|
|
35
|
+
/** Attachment point on the branch centre line. */
|
|
36
|
+
position: Vec3;
|
|
37
|
+
/** Unit vector from the attachment point to the leaf tip. */
|
|
38
|
+
direction: Vec3;
|
|
39
|
+
/** Unit normal of the leaf card's front face. */
|
|
40
|
+
normal: Vec3;
|
|
41
|
+
/** Leaf length (base to tip). */
|
|
42
|
+
size: number;
|
|
43
|
+
/**
|
|
44
|
+
* The Seed's colour variation for this leaf: an RGB multiplier, each channel within
|
|
45
|
+
* 1 ± the Definition's `variation.color`. The leaf material multiplies its (Season) colour
|
|
46
|
+
* by it; the geometry's vertex `colors` hold the same values.
|
|
47
|
+
*/
|
|
48
|
+
tint: Vec3;
|
|
49
|
+
}
|
|
50
|
+
export interface TreeSkeleton {
|
|
51
|
+
/** Trunk first, then breadth first: all of level 1, all of level 2, ... */
|
|
52
|
+
branches: SkeletonBranch[];
|
|
53
|
+
leaves: SkeletonLeaf[];
|
|
54
|
+
}
|
|
55
|
+
/** A custom per-vertex attribute: `itemSize` floats per vertex. */
|
|
56
|
+
export interface VertexAttribute {
|
|
57
|
+
array: Float32Array;
|
|
58
|
+
itemSize: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Per-vertex attributes every tree mesh carries; Growth, Season and Wind (tickets #6-#8)
|
|
62
|
+
* are computed from these in TSL, and may add their own entries.
|
|
63
|
+
* A "part" is a branch (wood mesh) or a leaf (leaves mesh).
|
|
64
|
+
*/
|
|
65
|
+
export interface TreeAttributes {
|
|
66
|
+
[name: string]: VertexAttribute;
|
|
67
|
+
/** Part level: 0 = trunk, n = branching level n, leaves = number of branch levels + 1. */
|
|
68
|
+
aLevel: VertexAttribute;
|
|
69
|
+
/** Position of the vertex along its part, 0 at the base to 1 at the tip. */
|
|
70
|
+
aAlong: VertexAttribute;
|
|
71
|
+
/** Where the part sits on its parent (0..1 of the parent's length); 0 for the trunk. */
|
|
72
|
+
aAttach: VertexAttribute;
|
|
73
|
+
/** Stable random number per part (0..1), from the Seed and the branch path / leaf id. */
|
|
74
|
+
aRandom: VertexAttribute;
|
|
75
|
+
/** Base point of the part (vec3): pivot for growing and swaying it. */
|
|
76
|
+
aOrigin: VertexAttribute;
|
|
77
|
+
/**
|
|
78
|
+
* Growth (vec3): x = Growth at which the part starts to sprout, y = Growth at which it is fully
|
|
79
|
+
* grown (its window, see `TreeData.growth`), z = distance of the vertex from the part's centre
|
|
80
|
+
* line (the branch radius there; 0 for leaves and branch tips), used to thicken over Growth.
|
|
81
|
+
*/
|
|
82
|
+
aGrowth: VertexAttribute;
|
|
83
|
+
/**
|
|
84
|
+
* Season (vec3): x = timing shift from the Seed (within ± `variation.season`), y = coverage rank,
|
|
85
|
+
* z = blossom rank (0..1, leaves only; 0 on wood). See `leafSeason` in src/season.
|
|
86
|
+
*/
|
|
87
|
+
aSeason: VertexAttribute;
|
|
88
|
+
/**
|
|
89
|
+
* Wind weights (vec3, each 0..1): x = trunk sway (pinned at the ground, 1 at the trunk top),
|
|
90
|
+
* y = branch sway (0 on the trunk, rising towards the outermost twigs), z = leaf flutter (0 on wood,
|
|
91
|
+
* 0 at a leaf base, 1 at its tip). See `generator/wind.ts`.
|
|
92
|
+
*/
|
|
93
|
+
aWind: VertexAttribute;
|
|
94
|
+
}
|
|
95
|
+
/** Plain geometry buffers (no three.js types), ready to wrap in a BufferGeometry. */
|
|
96
|
+
export interface GeometryBuffers {
|
|
97
|
+
positions: Float32Array;
|
|
98
|
+
normals: Float32Array;
|
|
99
|
+
uvs: Float32Array;
|
|
100
|
+
/** Optional per-vertex colours, linear RGB (leaves). */
|
|
101
|
+
colors?: Float32Array;
|
|
102
|
+
indices: Uint32Array;
|
|
103
|
+
attributes: TreeAttributes;
|
|
104
|
+
}
|
|
105
|
+
/** The span of Growth (0..1) over which one part grows from nothing to full size. */
|
|
106
|
+
export interface GrowthWindow {
|
|
107
|
+
start: number;
|
|
108
|
+
end: number;
|
|
109
|
+
}
|
|
110
|
+
/** Growth windows per part, parallel to `TreeSkeleton.branches` and `TreeSkeleton.leaves`. */
|
|
111
|
+
export interface GrowthTiming {
|
|
112
|
+
branches: GrowthWindow[];
|
|
113
|
+
leaves: GrowthWindow[];
|
|
114
|
+
}
|
|
115
|
+
/** Everything the Generator produces for one Definition + Seed. Pure data, Node-safe. */
|
|
116
|
+
export interface TreeData {
|
|
117
|
+
seed: number;
|
|
118
|
+
skeleton: TreeSkeleton;
|
|
119
|
+
/** Wood mesh: trunk and all branches. */
|
|
120
|
+
wood: GeometryBuffers;
|
|
121
|
+
/** Leaf cards, vertex coloured. Empty buffers for a bare tree. */
|
|
122
|
+
leaves: GeometryBuffers;
|
|
123
|
+
/** When each part grows (the Seed shifts it within `variation.growth`). Also in the `aGrowth` attribute. */
|
|
124
|
+
growth: GrowthTiming;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5C,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,yGAAyG;IACzG,MAAM,EAAE,MAAM,CAAC;IACf,2GAA2G;IAC3G,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,4CAA4C;IAC5C,MAAM,EAA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AAc,CAAC;CAC5B;AAED,qFAAqF;AACrF,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,yFAAyF;AACzF,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,yCAAyC;IACzC,IAAI,EAAE,eAAe,CAAC;IACtB,kEAAkE;IAClE,MAAM,EAAE,eAAe,CAAC;IACxB,4GAA4G;IAC5G,MAAM,EAAE,YAAY,CAAC;CACtB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Vec3 } from './types';
|
|
2
|
+
export declare const add: (a: Vec3, b: Vec3) => Vec3;
|
|
3
|
+
export declare const sub: (a: Vec3, b: Vec3) => Vec3;
|
|
4
|
+
export declare const scale: (a: Vec3, s: number) => Vec3;
|
|
5
|
+
export declare const dot: (a: Vec3, b: Vec3) => number;
|
|
6
|
+
export declare const cross: (a: Vec3, b: Vec3) => Vec3;
|
|
7
|
+
export declare const length: (a: Vec3) => number;
|
|
8
|
+
export declare function normalize(a: Vec3): Vec3;
|
|
9
|
+
export declare const lerp: (a: Vec3, b: Vec3, t: number) => Vec3;
|
|
10
|
+
/** Any unit vector perpendicular to the unit vector `v`. */
|
|
11
|
+
export declare function perpendicular(v: Vec3): Vec3;
|
|
12
|
+
//# sourceMappingURL=vec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vec.d.ts","sourceRoot":"","sources":["../../src/generator/vec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC,eAAO,MAAM,GAAG,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,KAAG,IAA+C,CAAC;AACvF,eAAO,MAAM,GAAG,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,KAAG,IAA+C,CAAC;AACvF,eAAO,MAAM,KAAK,GAAI,GAAG,IAAI,EAAE,GAAG,MAAM,KAAG,IAAsC,CAAC;AAClF,eAAO,MAAM,GAAG,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,KAAG,MAAiD,CAAC;AACzF,eAAO,MAAM,KAAK,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,KAAG,IAIxC,CAAC;AACF,eAAO,MAAM,MAAM,GAAI,GAAG,IAAI,KAAG,MAAkC,CAAC;AACpE,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAGvC;AACD,eAAO,MAAM,IAAI,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,KAAG,IAIlD,CAAC;AACF,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAG3C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GeometryBuffers, SkeletonBranch } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Wind weights (ticket #8). Every vertex carries `aWind` = (trunk sway, branch sway, leaf flutter),
|
|
4
|
+
* each 0..1, which the Wind TSL node scales by the Definition's Wind response and the scene Wind.
|
|
5
|
+
*
|
|
6
|
+
* - trunk sway: (height / trunk height)², clamped: the trunk bends from the ground and carries
|
|
7
|
+
* everything above it.
|
|
8
|
+
* - branch sway: 0 on the trunk; along a branch of level L it rises by 1/levels from the value its
|
|
9
|
+
* parent has at the attach point, so joints never tear and the outermost twigs reach up to 1.
|
|
10
|
+
* - leaf flutter: 0 on wood; along a leaf from 0 at its base to 1 at its tip.
|
|
11
|
+
*/
|
|
12
|
+
export interface PartSway {
|
|
13
|
+
/** Branch sway at the base of the part. */
|
|
14
|
+
base: number;
|
|
15
|
+
/** Branch sway gained from the base (along = 0) to the tip (along = 1). */
|
|
16
|
+
gain: number;
|
|
17
|
+
/** True for leaves: leaf flutter = along. */
|
|
18
|
+
flutter: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const NO_SWAY: PartSway;
|
|
21
|
+
/** Branch sway of every branch (by path). `branches` must be ordered parents first (the skeleton is). */
|
|
22
|
+
export declare function branchSway(branches: SkeletonBranch[], levels: number): Map<string, PartSway>;
|
|
23
|
+
/** The sway of a leaf: its branch's sway at the attach point, plus flutter. */
|
|
24
|
+
export declare function leafSway(branch: PartSway, attach: number): PartSway;
|
|
25
|
+
/** Fills the trunk-sway channel (x of `aWind`) from each vertex's height. */
|
|
26
|
+
export declare function writeTrunkSway(buffers: GeometryBuffers, trunkHeight: number): void;
|
|
27
|
+
//# sourceMappingURL=wind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wind.d.ts","sourceRoot":"","sources":["../../src/generator/wind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;GASG;AACH,MAAM,WAAW,QAAQ;IACvB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,OAAO,EAAE,QAA+C,CAAC;AAEtE,yGAAyG;AACzG,wBAAgB,UAAU,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAY5F;AAED,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAEnE;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAOlF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { GeometryBuffers } from '../generator';
|
|
2
|
+
/**
|
|
3
|
+
* The Growth model, one spec with two backends: `growPositions` (CPU, here) and `growthPosition`
|
|
4
|
+
* (TSL, `./tsl.ts`). Keep them in step. Per vertex, at Growth `g`:
|
|
5
|
+
*
|
|
6
|
+
* 1. thicken: move the vertex towards its part's centre line, keeping `thickness(g)` of its radius
|
|
7
|
+
* (`aGrowth.z`, along the vertex normal);
|
|
8
|
+
* 2. sprout: scale the part about its base point (`aOrigin`) by `partProgress(g, start, end)`
|
|
9
|
+
* (`aGrowth.xy`), so a part grows out of a point on its (already grown) parent;
|
|
10
|
+
* 3. size: scale the whole tree about its base (local origin) by `treeScale(g)`.
|
|
11
|
+
*
|
|
12
|
+
* Every step is written as `x - offset * (1 - factor)`, so at Growth 1 the positions are exactly
|
|
13
|
+
* the generated ones: a tree at Growth 1 is a normal static tree.
|
|
14
|
+
*/
|
|
15
|
+
/** Size of the whole tree at Growth 0 (sapling), relative to fully grown. */
|
|
16
|
+
export declare const SAPLING_SCALE = 0.2;
|
|
17
|
+
/** Branch thickness at Growth 0, relative to the size-scaled thickness when fully grown. */
|
|
18
|
+
export declare const SAPLING_THICKNESS = 0.4;
|
|
19
|
+
/** Smallest window width, so parts with `start == end` (the trunk) are simply grown. */
|
|
20
|
+
export declare const MIN_WINDOW = 0.00001;
|
|
21
|
+
export declare const treeScale: (growth: number) => number;
|
|
22
|
+
export declare const thickness: (growth: number) => number;
|
|
23
|
+
/** How far one part has sprouted (0 = not yet, 1 = full size), eased; 1 from `end` on. */
|
|
24
|
+
export declare function partProgress(growth: number, start: number, end: number): number;
|
|
25
|
+
/** Clamps a Growth value to 0..1 (NaN becomes 1, fully grown). */
|
|
26
|
+
export declare function clampGrowth(growth: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Vertex positions of generated geometry at a given Growth, on the CPU (for baking a tree and
|
|
29
|
+
* for tests; at runtime the same model runs in TSL). Returns a new array.
|
|
30
|
+
*/
|
|
31
|
+
export declare function growPositions(buffers: GeometryBuffers, growth: number): Float32Array;
|
|
32
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/growth/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;GAYG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,aAAa,MAAM,CAAC;AACjC,4FAA4F;AAC5F,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,wFAAwF;AACxF,eAAO,MAAM,UAAU,UAAO,CAAC;AAE/B,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,KAAG,MAAsD,CAAC;AAClG,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,KAAG,MAA8D,CAAC;AAE1G,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/E;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAkBpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/growth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,EACT,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node } from 'three/webgpu';
|
|
2
|
+
/**
|
|
3
|
+
* Growth in TSL: the vertex position of a tree part at Growth `growth` (a float node, usually the
|
|
4
|
+
* tree's Growth uniform; a Forest can pass a per-instance attribute instead). Same model and steps
|
|
5
|
+
* as `growPositions` (see `./evaluate.ts`), driven by the Generator's `aGrowth` and `aOrigin` attributes.
|
|
6
|
+
*
|
|
7
|
+
* `position` is the input position (default `positionLocal`). To compose with other vertex effects,
|
|
8
|
+
* feed this node into them, e.g. `material.positionNode = windPosition(growthPosition(uGrowth))`:
|
|
9
|
+
* Growth first, so the rest acts on the grown tree.
|
|
10
|
+
*/
|
|
11
|
+
export declare function growthPosition(growth: Node<'float'>, position?: Node<'vec3'>): Node<'vec3'>;
|
|
12
|
+
//# sourceMappingURL=tsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsl.d.ts","sourceRoot":"","sources":["../../src/growth/tsl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAiBzC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAE,IAAI,CAAC,MAAM,CAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,CAa1G"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createTree, Tree, type CreateTreeOptions, type TreeOptions } from './tree';
|
|
2
|
+
export * from './definition';
|
|
3
|
+
export * from './season';
|
|
4
|
+
export { hashGeometry, hashTreeData, type TreeData, type GrowthTiming, type GrowthWindow, type TreeSkeleton, type SkeletonBranch, type SkeletonPoint, type SkeletonLeaf, type GeometryBuffers, type TreeAttributes, type VertexAttribute, type Vec3, } from './generator';
|
|
5
|
+
export { createRandom, type Random } from './random';
|
|
6
|
+
export { createBarkMaterial, createLeafMaterial } from './materials';
|
|
7
|
+
export { DEFAULT_TEXTURE_BASE_PATH, getTextureOptions, loadTexture, resolveTextureUrl, setTextureOptions, textureReady, type TextureKind, type TextureOptions, } from './textures';
|
|
8
|
+
export { assertWebGPURenderer, UnsupportedRendererError } from './renderer';
|
|
9
|
+
export { Wind, sceneWind, WindResponse, type WindDirection, type WindOptions } from './wind';
|
|
10
|
+
export type { TreeStyle } from './styles/types';
|
|
11
|
+
export { loadStyle, STYLE_NAMES, type StyleName } from './styles/registry';
|
|
12
|
+
export { bakeTree, disposeBakedTree, exportBakedTree, type BakeOptions, type ExportBakedTreeOptions, } from './bake';
|
|
13
|
+
export { createForest, Forest, ForestTree, ForestVariant, type ForestOptions, type ForestPlacement, type ForestInstanceState, type ForestTreeTraits, } from './forest';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AACpF,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,IAAI,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC7F,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,sBAAsB,GAC5B,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,MAAM,EACN,UAAU,EACV,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { n as MAX_BRANCH_LEVELS, t as CURRENT_SCHEMA_VERSION } from "./types-BZjHhNz7.js";
|
|
2
|
+
import { A as hashTreeData, B as srgbToLinear, C as loadTexture, D as clampGrowth, E as textureReady, F as leafSeasonAttribute, G as fetchDefinition, H as wrapSeason, I as partSeasonAt, J as DEFAULT_BRANCH_LEVEL, K as parseDefinition, L as sampleTrack, M as evaluateSeason, N as hexToLinear, O as growPositions, P as leafSeason, R as seasonShift, S as getTextureOptions, T as setTextureOptions, U as createRandom, V as woodSeasonAttribute, W as extendDefinition, Y as DEFAULT_DEFINITION, _ as createBarkMaterial, b as BARK_REPEAT, c as createTree, d as Wind, f as sceneWind, g as assertWebGPURenderer, h as UnsupportedRendererError, i as ForestVariant, j as KEYFRAME_EPSILON, k as hashGeometry, l as Tree, m as createSeasonNodes, n as Forest, o as STYLE_NAMES, p as applySeasonToLeafMaterial, q as TreeDefinitionError, r as ForestTree, s as loadStyle, t as createForest, u as WindResponse, v as createLeafMaterial, w as resolveTextureUrl, x as DEFAULT_TEXTURE_BASE_PATH, y as isFlatShading, z as segmentWeight } from "./forest-OX9WvAwh.js";
|
|
3
|
+
import { t as SEASON_PROFILES } from "./profiles-BAiyeFlh.js";
|
|
4
|
+
import { BufferAttribute, BufferGeometry, Color, DoubleSide, Group, Mesh, MeshStandardMaterial } from "three/webgpu";
|
|
5
|
+
import { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
|
|
6
|
+
// src/bake/index.ts
|
|
7
|
+
/** A triangle with (almost) no area is a part that has not sprouted yet: it is dropped. */
|
|
8
|
+
var MIN_AREA2 = 1e-16;
|
|
9
|
+
/**
|
|
10
|
+
* Keeps the triangles whose three vertices are visible and that have an area, and only the
|
|
11
|
+
* vertices those triangles use. Returns null when nothing is left (glTF forbids empty meshes).
|
|
12
|
+
*/
|
|
13
|
+
function compact(buffers, indices, flat) {
|
|
14
|
+
const { positions } = buffers;
|
|
15
|
+
const kept = [];
|
|
16
|
+
const remap = new Int32Array(positions.length / 3).fill(-1);
|
|
17
|
+
let count = 0;
|
|
18
|
+
for (let t = 0; t < indices.length; t += 3) {
|
|
19
|
+
const [a, b, c] = [
|
|
20
|
+
indices[t],
|
|
21
|
+
indices[t + 1],
|
|
22
|
+
indices[t + 2]
|
|
23
|
+
];
|
|
24
|
+
if (!buffers.visible(a) || !buffers.visible(b) || !buffers.visible(c)) continue;
|
|
25
|
+
if (area2(positions, a, b, c) < MIN_AREA2) continue;
|
|
26
|
+
for (const v of [
|
|
27
|
+
a,
|
|
28
|
+
b,
|
|
29
|
+
c
|
|
30
|
+
]) {
|
|
31
|
+
if (remap[v] === -1) remap[v] = count++;
|
|
32
|
+
kept.push(remap[v]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (kept.length === 0) return null;
|
|
36
|
+
const pick = (source, size) => {
|
|
37
|
+
const out = new Float32Array(count * size);
|
|
38
|
+
remap.forEach((to, from) => {
|
|
39
|
+
if (to >= 0) out.set(source.subarray(from * size, from * size + size), to * size);
|
|
40
|
+
});
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
let geometry = new BufferGeometry();
|
|
44
|
+
geometry.setAttribute("position", new BufferAttribute(pick(positions, 3), 3));
|
|
45
|
+
geometry.setAttribute("normal", new BufferAttribute(pick(buffers.normals, 3), 3));
|
|
46
|
+
geometry.setAttribute("uv", new BufferAttribute(pick(buffers.uvs, 2), 2));
|
|
47
|
+
if (buffers.colors) geometry.setAttribute("color", new BufferAttribute(pick(buffers.colors, 3), 3));
|
|
48
|
+
geometry.setIndex(new BufferAttribute(Uint32Array.from(kept), 1));
|
|
49
|
+
if (flat) {
|
|
50
|
+
geometry = geometry.toNonIndexed();
|
|
51
|
+
geometry.computeVertexNormals();
|
|
52
|
+
}
|
|
53
|
+
geometry.computeBoundingBox();
|
|
54
|
+
geometry.computeBoundingSphere();
|
|
55
|
+
return geometry;
|
|
56
|
+
}
|
|
57
|
+
function area2(p, a, b, c) {
|
|
58
|
+
const u = [
|
|
59
|
+
p[b * 3] - p[a * 3],
|
|
60
|
+
p[b * 3 + 1] - p[a * 3 + 1],
|
|
61
|
+
p[b * 3 + 2] - p[a * 3 + 2]
|
|
62
|
+
];
|
|
63
|
+
const w = [
|
|
64
|
+
p[c * 3] - p[a * 3],
|
|
65
|
+
p[c * 3 + 1] - p[a * 3 + 1],
|
|
66
|
+
p[c * 3 + 2] - p[a * 3 + 2]
|
|
67
|
+
];
|
|
68
|
+
const x = u[1] * w[2] - u[2] * w[1];
|
|
69
|
+
const y = u[2] * w[0] - u[0] * w[2];
|
|
70
|
+
const z = u[0] * w[1] - u[1] * w[0];
|
|
71
|
+
return x * x + y * y + z * z;
|
|
72
|
+
}
|
|
73
|
+
/** Wood: grown positions; the bark's base-to-tip darkening (smooth shading) as vertex colours. */
|
|
74
|
+
function bakeWood(definition, wood, growth) {
|
|
75
|
+
const flat = isFlatShading(definition.materials.shading);
|
|
76
|
+
let colors = null;
|
|
77
|
+
if (!flat) {
|
|
78
|
+
colors = new Float32Array(wood.positions.length);
|
|
79
|
+
for (let v = 0; v < colors.length / 3; v++) {
|
|
80
|
+
const shade = .75 + .25 * Math.sqrt(Math.min(Math.max(wood.uvs[v * 2 + 1], 0), 1));
|
|
81
|
+
colors.fill(shade, v * 3, v * 3 + 3);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return compact({
|
|
85
|
+
positions: growPositions(wood, growth),
|
|
86
|
+
normals: wood.normals,
|
|
87
|
+
uvs: wood.uvs,
|
|
88
|
+
colors,
|
|
89
|
+
visible: () => true
|
|
90
|
+
}, wood.indices, flat);
|
|
91
|
+
}
|
|
92
|
+
/** Leaves: grown positions; fallen leaves dropped; Season (or blossom) colour × the Seed's tint as vertex colours. */
|
|
93
|
+
function bakeLeaves(definition, leaves, growth, season) {
|
|
94
|
+
const count = leaves.positions.length / 3;
|
|
95
|
+
const aSeason = leaves.attributes.aSeason.array;
|
|
96
|
+
const shown = new Uint8Array(count);
|
|
97
|
+
const colors = new Float32Array(count * 3);
|
|
98
|
+
for (let v = 0; v < count; v++) {
|
|
99
|
+
const state = leafSeason(definition.season, season, partSeasonAt(aSeason, v));
|
|
100
|
+
shown[v] = state.visible ? 1 : 0;
|
|
101
|
+
for (let c = 0; c < 3; c++) colors[v * 3 + c] = state.color[c] * (leaves.colors?.[v * 3 + c] ?? 1);
|
|
102
|
+
}
|
|
103
|
+
return compact({
|
|
104
|
+
positions: growPositions(leaves, growth),
|
|
105
|
+
normals: leaves.normals,
|
|
106
|
+
uvs: leaves.uvs,
|
|
107
|
+
colors,
|
|
108
|
+
visible: (v) => shown[v] === 1
|
|
109
|
+
}, leaves.indices, isFlatShading(definition.materials.shading));
|
|
110
|
+
}
|
|
111
|
+
/** A loaded texture for the baked material (a copy, so the tree's shared texture is untouched); null without image data. */
|
|
112
|
+
function bakedMap(texture, repeat) {
|
|
113
|
+
if (!texture?.image) return null;
|
|
114
|
+
const copy = texture.clone();
|
|
115
|
+
if (repeat) copy.repeat.set(...repeat);
|
|
116
|
+
return copy;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Freezes a tree at a Growth and Season (default: the tree's own) into a static `Group` of
|
|
120
|
+
* meshes `wood` and `leaves` (a mesh with nothing to show is left out) with standard PBR
|
|
121
|
+
* materials: no node materials, no Growth/Season/Wind attributes, no animation. The result is
|
|
122
|
+
* independent of `tree`; call `disposeBakedTree` when done with it.
|
|
123
|
+
*/
|
|
124
|
+
function bakeTree(tree, options = {}) {
|
|
125
|
+
const { definition, data } = tree;
|
|
126
|
+
const source = tree.wood.material;
|
|
127
|
+
const growth = clampGrowth(options.growth ?? tree.growth);
|
|
128
|
+
const season = wrapSeason(options.season ?? tree.season);
|
|
129
|
+
const bark = definition.materials.bark;
|
|
130
|
+
const flat = isFlatShading(definition.materials.shading);
|
|
131
|
+
const group = new Group();
|
|
132
|
+
group.name = definition.name || "Tree";
|
|
133
|
+
group.userData = {
|
|
134
|
+
seed: tree.seed,
|
|
135
|
+
growth,
|
|
136
|
+
season
|
|
137
|
+
};
|
|
138
|
+
const woodGeometry = bakeWood(definition, data.wood, growth);
|
|
139
|
+
if (woodGeometry) {
|
|
140
|
+
const material = new MeshStandardMaterial({
|
|
141
|
+
name: "bark",
|
|
142
|
+
color: new Color(bark.color),
|
|
143
|
+
roughness: bark.roughness,
|
|
144
|
+
metalness: 0,
|
|
145
|
+
vertexColors: woodGeometry.hasAttribute("color"),
|
|
146
|
+
flatShading: flat,
|
|
147
|
+
map: bakedMap(source.map, BARK_REPEAT),
|
|
148
|
+
normalMap: bakedMap(source.normalMap, BARK_REPEAT)
|
|
149
|
+
});
|
|
150
|
+
group.add(bakedMesh("wood", woodGeometry, material));
|
|
151
|
+
}
|
|
152
|
+
const leafGeometry = bakeLeaves(definition, data.leaves, growth, season);
|
|
153
|
+
if (leafGeometry) {
|
|
154
|
+
const map = bakedMap(tree.leaves.material.map);
|
|
155
|
+
const material = new MeshStandardMaterial({
|
|
156
|
+
name: "leaves",
|
|
157
|
+
color: 16777215,
|
|
158
|
+
roughness: definition.materials.leaf.roughness,
|
|
159
|
+
metalness: 0,
|
|
160
|
+
vertexColors: true,
|
|
161
|
+
flatShading: flat,
|
|
162
|
+
side: DoubleSide,
|
|
163
|
+
map,
|
|
164
|
+
alphaTest: map ? definition.materials.leaf.alphaTest : 0
|
|
165
|
+
});
|
|
166
|
+
group.add(bakedMesh("leaves", leafGeometry, material));
|
|
167
|
+
}
|
|
168
|
+
return group;
|
|
169
|
+
}
|
|
170
|
+
function bakedMesh(name, geometry, material) {
|
|
171
|
+
const mesh = new Mesh(geometry, material);
|
|
172
|
+
mesh.name = name;
|
|
173
|
+
mesh.castShadow = mesh.receiveShadow = true;
|
|
174
|
+
return mesh;
|
|
175
|
+
}
|
|
176
|
+
/** Frees the geometries, materials and texture copies of a baked tree. */
|
|
177
|
+
function disposeBakedTree(baked) {
|
|
178
|
+
baked.traverse((object) => {
|
|
179
|
+
if (!(object instanceof Mesh)) return;
|
|
180
|
+
object.geometry.dispose();
|
|
181
|
+
const material = object.material;
|
|
182
|
+
material.map?.dispose();
|
|
183
|
+
material.normalMap?.dispose();
|
|
184
|
+
material.dispose();
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async function exportBakedTree(tree, options = {}) {
|
|
188
|
+
await tree.ready;
|
|
189
|
+
const baked = bakeTree(tree, options);
|
|
190
|
+
try {
|
|
191
|
+
return await new GLTFExporter().parseAsync(baked, { binary: options.binary ?? true });
|
|
192
|
+
} finally {
|
|
193
|
+
disposeBakedTree(baked);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export { CURRENT_SCHEMA_VERSION, DEFAULT_BRANCH_LEVEL, DEFAULT_DEFINITION, DEFAULT_TEXTURE_BASE_PATH, Forest, ForestTree, ForestVariant, KEYFRAME_EPSILON, MAX_BRANCH_LEVELS, SEASON_PROFILES, STYLE_NAMES, Tree, TreeDefinitionError, UnsupportedRendererError, Wind, WindResponse, applySeasonToLeafMaterial, assertWebGPURenderer, bakeTree, createBarkMaterial, createForest, createLeafMaterial, createRandom, createSeasonNodes, createTree, disposeBakedTree, evaluateSeason, exportBakedTree, extendDefinition, fetchDefinition, getTextureOptions, hashGeometry, hashTreeData, hexToLinear, leafSeason, leafSeasonAttribute, loadStyle, loadTexture, parseDefinition, partSeasonAt, resolveTextureUrl, sampleTrack, sceneWind, seasonShift, segmentWeight, setTextureOptions, srgbToLinear, textureReady, woodSeasonAttribute, wrapSeason };
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/bake/index.ts"],"sourcesContent":["import {\n BufferAttribute,\n BufferGeometry,\n Color,\n DoubleSide,\n Group,\n Mesh,\n MeshStandardMaterial,\n type Texture,\n} from 'three/webgpu';\nimport { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';\nimport type { TreeDefinition } from '../definition';\nimport type { GeometryBuffers } from '../generator';\nimport { clampGrowth, growPositions } from '../growth';\nimport { BARK_REPEAT } from '../materials/maps';\nimport { isFlatShading } from '../materials/shading';\nimport { leafSeason, partSeasonAt, wrapSeason } from '../season';\nimport type { Tree } from '../tree';\n\n/**\n * Baked Tree: one tree frozen at a Seed, Growth and Season as plain static geometry with\n * standard PBR materials (`MeshStandardMaterial`, no node materials, no custom attributes), for\n * glTF export and other tools. Growth and Season are evaluated on the CPU with the same models the\n * shaders run (`growPositions`, `leafSeason`); Wind is left out (a Baked Tree stands still).\n */\n\n/** Growth and Season to bake at; each defaults to the tree's current value. */\nexport interface BakeOptions {\n growth?: number;\n season?: number;\n}\n\n/** A triangle with (almost) no area is a part that has not sprouted yet: it is dropped. */\nconst MIN_AREA2 = 1e-16;\n\ninterface BakedBuffers {\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n colors: Float32Array | null;\n /** Per vertex: whether it is shown at all. */\n visible: (v: number) => boolean;\n}\n\n/**\n * Keeps the triangles whose three vertices are visible and that have an area, and only the\n * vertices those triangles use. Returns null when nothing is left (glTF forbids empty meshes).\n */\nfunction compact(buffers: BakedBuffers, indices: Uint32Array, flat: boolean): BufferGeometry | null {\n const { positions } = buffers;\n const kept: number[] = [];\n const remap = new Int32Array(positions.length / 3).fill(-1);\n let count = 0;\n for (let t = 0; t < indices.length; t += 3) {\n const [a, b, c] = [indices[t]!, indices[t + 1]!, indices[t + 2]!];\n if (!buffers.visible(a) || !buffers.visible(b) || !buffers.visible(c)) continue;\n if (area2(positions, a, b, c) < MIN_AREA2) continue;\n for (const v of [a, b, c]) {\n if (remap[v] === -1) remap[v] = count++;\n kept.push(remap[v]!);\n }\n }\n if (kept.length === 0) return null;\n\n const pick = (source: Float32Array, size: number) => {\n const out = new Float32Array(count * size);\n remap.forEach((to, from) => {\n if (to >= 0) out.set(source.subarray(from * size, from * size + size), to * size);\n });\n return out;\n };\n let geometry = new BufferGeometry();\n geometry.setAttribute('position', new BufferAttribute(pick(positions, 3), 3));\n geometry.setAttribute('normal', new BufferAttribute(pick(buffers.normals, 3), 3));\n geometry.setAttribute('uv', new BufferAttribute(pick(buffers.uvs, 2), 2));\n if (buffers.colors) geometry.setAttribute('color', new BufferAttribute(pick(buffers.colors, 3), 3));\n geometry.setIndex(new BufferAttribute(Uint32Array.from(kept), 1));\n if (flat) {\n // glTF has no flat-shading switch: split the vertices and give each face its own normal.\n geometry = geometry.toNonIndexed();\n geometry.computeVertexNormals();\n }\n geometry.computeBoundingBox();\n geometry.computeBoundingSphere();\n return geometry;\n}\n\nfunction area2(p: Float32Array, a: number, b: number, c: number): number {\n const u = [p[b * 3]! - p[a * 3]!, p[b * 3 + 1]! - p[a * 3 + 1]!, p[b * 3 + 2]! - p[a * 3 + 2]!];\n const w = [p[c * 3]! - p[a * 3]!, p[c * 3 + 1]! - p[a * 3 + 1]!, p[c * 3 + 2]! - p[a * 3 + 2]!];\n const x = u[1]! * w[2]! - u[2]! * w[1]!;\n const y = u[2]! * w[0]! - u[0]! * w[2]!;\n const z = u[0]! * w[1]! - u[1]! * w[0]!;\n return x * x + y * y + z * z;\n}\n\n/** Wood: grown positions; the bark's base-to-tip darkening (smooth shading) as vertex colours. */\nfunction bakeWood(definition: TreeDefinition, wood: GeometryBuffers, growth: number): BufferGeometry | null {\n const flat = isFlatShading(definition.materials.shading);\n let colors: Float32Array | null = null;\n if (!flat) {\n // Same as the bark colorNode: mix(base * 0.75, base, sqrt(clamp(uv.y))).\n colors = new Float32Array(wood.positions.length);\n for (let v = 0; v < colors.length / 3; v++) {\n const shade = 0.75 + 0.25 * Math.sqrt(Math.min(Math.max(wood.uvs[v * 2 + 1]!, 0), 1));\n colors.fill(shade, v * 3, v * 3 + 3);\n }\n }\n return compact(\n { positions: growPositions(wood, growth), normals: wood.normals, uvs: wood.uvs, colors, visible: () => true },\n wood.indices,\n flat,\n );\n}\n\n/** Leaves: grown positions; fallen leaves dropped; Season (or blossom) colour × the Seed's tint as vertex colours. */\nfunction bakeLeaves(definition: TreeDefinition, leaves: GeometryBuffers, growth: number, season: number): BufferGeometry | null {\n const count = leaves.positions.length / 3;\n const aSeason = leaves.attributes.aSeason!.array;\n const shown = new Uint8Array(count);\n const colors = new Float32Array(count * 3);\n for (let v = 0; v < count; v++) {\n const state = leafSeason(definition.season, season, partSeasonAt(aSeason, v));\n shown[v] = state.visible ? 1 : 0;\n for (let c = 0; c < 3; c++) colors[v * 3 + c] = state.color[c]! * (leaves.colors?.[v * 3 + c] ?? 1);\n }\n return compact(\n { positions: growPositions(leaves, growth), normals: leaves.normals, uvs: leaves.uvs, colors, visible: (v) => shown[v] === 1 },\n leaves.indices,\n isFlatShading(definition.materials.shading),\n );\n}\n\n/** A loaded texture for the baked material (a copy, so the tree's shared texture is untouched); null without image data. */\nfunction bakedMap(texture: Texture | null | undefined, repeat?: readonly [number, number]): Texture | null {\n if (!texture?.image) return null;\n const copy = texture.clone();\n if (repeat) copy.repeat.set(...repeat);\n return copy;\n}\n\n/**\n * Freezes a tree at a Growth and Season (default: the tree's own) into a static `Group` of\n * meshes `wood` and `leaves` (a mesh with nothing to show is left out) with standard PBR\n * materials: no node materials, no Growth/Season/Wind attributes, no animation. The result is\n * independent of `tree`; call `disposeBakedTree` when done with it.\n */\nexport function bakeTree(tree: Tree, options: BakeOptions = {}): Group {\n const { definition, data } = tree;\n const source = tree.wood.material as MeshStandardMaterial; // MeshStandardNodeMaterial: same props\n const growth = clampGrowth(options.growth ?? tree.growth);\n const season = wrapSeason(options.season ?? tree.season);\n const bark = definition.materials.bark;\n const flat = isFlatShading(definition.materials.shading);\n\n const group = new Group();\n group.name = definition.name || 'Tree';\n group.userData = { seed: tree.seed, growth, season };\n\n const woodGeometry = bakeWood(definition, data.wood, growth);\n if (woodGeometry) {\n const material = new MeshStandardMaterial({\n name: 'bark',\n color: new Color(bark.color),\n roughness: bark.roughness,\n metalness: 0,\n vertexColors: woodGeometry.hasAttribute('color'),\n flatShading: flat,\n map: bakedMap(source.map, BARK_REPEAT),\n normalMap: bakedMap(source.normalMap, BARK_REPEAT),\n });\n group.add(bakedMesh('wood', woodGeometry, material));\n }\n\n const leafGeometry = bakeLeaves(definition, data.leaves, growth, season);\n if (leafGeometry) {\n const map = bakedMap(tree.leaves.material.map);\n const material = new MeshStandardMaterial({\n name: 'leaves',\n color: 0xffffff,\n roughness: definition.materials.leaf.roughness,\n metalness: 0,\n vertexColors: true,\n flatShading: flat,\n side: DoubleSide,\n map,\n alphaTest: map ? definition.materials.leaf.alphaTest : 0,\n });\n group.add(bakedMesh('leaves', leafGeometry, material));\n }\n return group;\n}\n\nfunction bakedMesh(name: string, geometry: BufferGeometry, material: MeshStandardMaterial): Mesh {\n const mesh = new Mesh(geometry, material);\n mesh.name = name;\n mesh.castShadow = mesh.receiveShadow = true;\n return mesh;\n}\n\n/** Frees the geometries, materials and texture copies of a baked tree. */\nexport function disposeBakedTree(baked: Group): void {\n baked.traverse((object) => {\n if (!(object instanceof Mesh)) return;\n object.geometry.dispose();\n const material = object.material as MeshStandardMaterial;\n material.map?.dispose();\n material.normalMap?.dispose();\n material.dispose();\n });\n}\n\nexport interface ExportBakedTreeOptions extends BakeOptions {\n /** `.glb` (ArrayBuffer, default) or `.gltf` JSON with embedded buffers. */\n binary?: boolean;\n}\n\n/**\n * Bakes a tree (see {@link bakeTree}) and writes it as glTF 2.0: a `.glb` ArrayBuffer by default,\n * or the `.gltf` JSON object with `binary: false`. Waits for the tree's textures first. In Node,\n * three's GLTFExporter needs a `FileReader` global.\n */\nexport function exportBakedTree(tree: Tree, options?: ExportBakedTreeOptions & { binary?: true }): Promise<ArrayBuffer>;\nexport function exportBakedTree(tree: Tree, options: ExportBakedTreeOptions & { binary: false }): Promise<Record<string, unknown>>;\nexport function exportBakedTree(tree: Tree, options?: ExportBakedTreeOptions): Promise<ArrayBuffer | Record<string, unknown>>;\nexport async function exportBakedTree(\n tree: Tree,\n options: ExportBakedTreeOptions = {},\n): Promise<ArrayBuffer | Record<string, unknown>> {\n await tree.ready;\n const baked = bakeTree(tree, options);\n try {\n const result = await new GLTFExporter().parseAsync(baked, { binary: options.binary ?? true });\n return result as ArrayBuffer | Record<string, unknown>;\n } finally {\n disposeBakedTree(baked);\n }\n}\n"],"mappings":";;;;;;;AAiCA,IAAM,YAAY;;;;;AAelB,SAAS,QAAQ,SAAuB,SAAsB,MAAsC;CAClG,MAAM,EAAE,cAAc;CACtB,MAAM,OAAiB,CAAC;CACxB,MAAM,QAAQ,IAAI,WAAW,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE;CAC1D,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;EAC1C,MAAM,CAAC,GAAG,GAAG,KAAK;GAAC,QAAQ;GAAK,QAAQ,IAAI;GAAK,QAAQ,IAAI;EAAG;EAChE,IAAI,CAAC,QAAQ,QAAQ,CAAC,KAAK,CAAC,QAAQ,QAAQ,CAAC,KAAK,CAAC,QAAQ,QAAQ,CAA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