@casmo/tree.js 0.0.0-stage → 0.1.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 (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +485 -2
  3. package/dist/bake/index.d.ts +39 -0
  4. package/dist/bake/index.d.ts.map +1 -0
  5. package/dist/definition/defaults.d.ts +9 -0
  6. package/dist/definition/defaults.d.ts.map +1 -0
  7. package/dist/definition/index.d.ts +5 -0
  8. package/dist/definition/index.d.ts.map +1 -0
  9. package/dist/definition/migrations.d.ts +12 -0
  10. package/dist/definition/migrations.d.ts.map +1 -0
  11. package/dist/definition/parse.d.ts +30 -0
  12. package/dist/definition/parse.d.ts.map +1 -0
  13. package/dist/definition/schema.d.ts +13 -0
  14. package/dist/definition/schema.d.ts.map +1 -0
  15. package/dist/definition/types.d.ts +217 -0
  16. package/dist/definition/types.d.ts.map +1 -0
  17. package/dist/effects/effects.d.ts +46 -0
  18. package/dist/effects/effects.d.ts.map +1 -0
  19. package/dist/effects/glow.d.ts +19 -0
  20. package/dist/effects/glow.d.ts.map +1 -0
  21. package/dist/effects/grade.d.ts +19 -0
  22. package/dist/effects/grade.d.ts.map +1 -0
  23. package/dist/effects/index.d.ts +7 -0
  24. package/dist/effects/index.d.ts.map +1 -0
  25. package/dist/effects/mask.d.ts +44 -0
  26. package/dist/effects/mask.d.ts.map +1 -0
  27. package/dist/effects/outline.d.ts +18 -0
  28. package/dist/effects/outline.d.ts.map +1 -0
  29. package/dist/effects/suggested.d.ts +13 -0
  30. package/dist/effects/suggested.d.ts.map +1 -0
  31. package/dist/effects.js +249 -0
  32. package/dist/effects.js.map +1 -0
  33. package/dist/forest/Forest.d.ts +156 -0
  34. package/dist/forest/Forest.d.ts.map +1 -0
  35. package/dist/forest/index.d.ts +14 -0
  36. package/dist/forest/index.d.ts.map +1 -0
  37. package/dist/forest/nodes.d.ts +31 -0
  38. package/dist/forest/nodes.d.ts.map +1 -0
  39. package/dist/forest/placement.d.ts +52 -0
  40. package/dist/forest/placement.d.ts.map +1 -0
  41. package/dist/forest-OX9WvAwh.js +3057 -0
  42. package/dist/forest-OX9WvAwh.js.map +1 -0
  43. package/dist/generator/attributes.d.ts +20 -0
  44. package/dist/generator/attributes.d.ts.map +1 -0
  45. package/dist/generator/branches.d.ts +12 -0
  46. package/dist/generator/branches.d.ts.map +1 -0
  47. package/dist/generator/frames.d.ts +21 -0
  48. package/dist/generator/frames.d.ts.map +1 -0
  49. package/dist/generator/growth.d.ts +15 -0
  50. package/dist/generator/growth.d.ts.map +1 -0
  51. package/dist/generator/index.d.ts +22 -0
  52. package/dist/generator/index.d.ts.map +1 -0
  53. package/dist/generator/leaf-shapes.d.ts +10 -0
  54. package/dist/generator/leaf-shapes.d.ts.map +1 -0
  55. package/dist/generator/leaves.d.ts +14 -0
  56. package/dist/generator/leaves.d.ts.map +1 -0
  57. package/dist/generator/mesh.d.ts +11 -0
  58. package/dist/generator/mesh.d.ts.map +1 -0
  59. package/dist/generator/sculpt.d.ts +28 -0
  60. package/dist/generator/sculpt.d.ts.map +1 -0
  61. package/dist/generator/trunk.d.ts +6 -0
  62. package/dist/generator/trunk.d.ts.map +1 -0
  63. package/dist/generator/types.d.ts +126 -0
  64. package/dist/generator/types.d.ts.map +1 -0
  65. package/dist/generator/vec.d.ts +12 -0
  66. package/dist/generator/vec.d.ts.map +1 -0
  67. package/dist/generator/wind.d.ts +27 -0
  68. package/dist/generator/wind.d.ts.map +1 -0
  69. package/dist/growth/evaluate.d.ts +32 -0
  70. package/dist/growth/evaluate.d.ts.map +1 -0
  71. package/dist/growth/index.d.ts +3 -0
  72. package/dist/growth/index.d.ts.map +1 -0
  73. package/dist/growth/tsl.d.ts +12 -0
  74. package/dist/growth/tsl.d.ts.map +1 -0
  75. package/dist/index.d.ts +14 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +198 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/materials/index.d.ts +18 -0
  80. package/dist/materials/index.d.ts.map +1 -0
  81. package/dist/materials/maps.d.ts +23 -0
  82. package/dist/materials/maps.d.ts.map +1 -0
  83. package/dist/materials/shading.d.ts +18 -0
  84. package/dist/materials/shading.d.ts.map +1 -0
  85. package/dist/materials/toon.d.ts +12 -0
  86. package/dist/materials/toon.d.ts.map +1 -0
  87. package/dist/math/index.d.ts +23 -0
  88. package/dist/math/index.d.ts.map +1 -0
  89. package/dist/profiles-BAiyeFlh.js +113 -0
  90. package/dist/profiles-BAiyeFlh.js.map +1 -0
  91. package/dist/random/index.d.ts +37 -0
  92. package/dist/random/index.d.ts.map +1 -0
  93. package/dist/react/Forest.d.ts +54 -0
  94. package/dist/react/Forest.d.ts.map +1 -0
  95. package/dist/react/Tree.d.ts +41 -0
  96. package/dist/react/Tree.d.ts.map +1 -0
  97. package/dist/react/Wind.d.ts +17 -0
  98. package/dist/react/Wind.d.ts.map +1 -0
  99. package/dist/react/index.d.ts +6 -0
  100. package/dist/react/index.d.ts.map +1 -0
  101. package/dist/react/useTreeStyle.d.ts +15 -0
  102. package/dist/react/useTreeStyle.d.ts.map +1 -0
  103. package/dist/react.js +239 -0
  104. package/dist/react.js.map +1 -0
  105. package/dist/renderer/index.d.ts +7 -0
  106. package/dist/renderer/index.d.ts.map +1 -0
  107. package/dist/season/check.d.ts +3 -0
  108. package/dist/season/check.d.ts.map +1 -0
  109. package/dist/season/index.d.ts +4 -0
  110. package/dist/season/index.d.ts.map +1 -0
  111. package/dist/season/nodes.d.ts +32 -0
  112. package/dist/season/nodes.d.ts.map +1 -0
  113. package/dist/season/profile.d.ts +78 -0
  114. package/dist/season/profile.d.ts.map +1 -0
  115. package/dist/season/profiles.d.ts +40 -0
  116. package/dist/season/profiles.d.ts.map +1 -0
  117. package/dist/styles/low-poly/index.d.ts +16 -0
  118. package/dist/styles/low-poly/index.d.ts.map +1 -0
  119. package/dist/styles/low-poly.js +165 -0
  120. package/dist/styles/low-poly.js.map +1 -0
  121. package/dist/styles/realistic/index.d.ts +23 -0
  122. package/dist/styles/realistic/index.d.ts.map +1 -0
  123. package/dist/styles/realistic.js +206 -0
  124. package/dist/styles/realistic.js.map +1 -0
  125. package/dist/styles/registry.d.ts +17 -0
  126. package/dist/styles/registry.d.ts.map +1 -0
  127. package/dist/styles/stylized/index.d.ts +17 -0
  128. package/dist/styles/stylized/index.d.ts.map +1 -0
  129. package/dist/styles/stylized.js +266 -0
  130. package/dist/styles/stylized.js.map +1 -0
  131. package/dist/styles/types.d.ts +12 -0
  132. package/dist/styles/types.d.ts.map +1 -0
  133. package/dist/textures/index.d.ts +44 -0
  134. package/dist/textures/index.d.ts.map +1 -0
  135. package/dist/textures/realistic/bark-normal.png +0 -0
  136. package/dist/textures/realistic/bark.png +0 -0
  137. package/dist/textures/realistic/leaf.png +0 -0
  138. package/dist/textures/realistic/needles.png +0 -0
  139. package/dist/tree/Tree.d.ts +70 -0
  140. package/dist/tree/Tree.d.ts.map +1 -0
  141. package/dist/tree/index.d.ts +14 -0
  142. package/dist/tree/index.d.ts.map +1 -0
  143. package/dist/types-BZjHhNz7.js +20 -0
  144. package/dist/types-BZjHhNz7.js.map +1 -0
  145. package/dist/wind/Wind.d.ts +54 -0
  146. package/dist/wind/Wind.d.ts.map +1 -0
  147. package/dist/wind/index.d.ts +4 -0
  148. package/dist/wind/index.d.ts.map +1 -0
  149. package/dist/wind/node.d.ts +38 -0
  150. package/dist/wind/node.d.ts.map +1 -0
  151. package/dist/wind/response.d.ts +27 -0
  152. package/dist/wind/response.d.ts.map +1 -0
  153. package/package.json +107 -4
@@ -0,0 +1,70 @@
1
+ import { BufferGeometry, Group, Mesh, type Material, type MeshStandardNodeMaterial, type UniformNode } from 'three/webgpu';
2
+ import type { TreeDefinition } from '../definition';
3
+ import { type TreeData } from '../generator';
4
+ import { type SeasonUniform } from '../season';
5
+ import { type TextureOptions } from '../textures';
6
+ import { Wind, WindResponse } from '../wind';
7
+ /** Per-tree state a Tree starts with. */
8
+ export interface TreeOptions {
9
+ /** Growth, 0 (sapling) .. 1 (fully grown, default). */
10
+ growth?: number;
11
+ /** Season, 0 (first day of spring, default) .. 1 (last day of winter). */
12
+ season?: number;
13
+ /** The Wind this tree sways with. Default: the scene-wide {@link sceneWind}. */
14
+ wind?: Wind;
15
+ /**
16
+ * Where this tree's textures load from (base path / per-URL overrides); takes precedence over
17
+ * the app-wide `setTextureOptions`. Only Definitions with textures (e.g. the realistic Style) use it.
18
+ */
19
+ textures?: TextureOptions;
20
+ }
21
+ /**
22
+ * A generated tree as a three.js object. Add it to a scene rendered by `WebGPURenderer`.
23
+ * `growth`, `season` and the Wind only update uniforms: no regeneration, no recompile.
24
+ */
25
+ export declare class Tree extends Group {
26
+ readonly isTree = true;
27
+ readonly definition: TreeDefinition;
28
+ readonly seed: number;
29
+ /** The generator output this object was built from (pure data). */
30
+ readonly data: TreeData;
31
+ /** Trunk and branches. */
32
+ readonly wood: Mesh<BufferGeometry, Material>;
33
+ /** Leaf cards (empty geometry for a bare tree). */
34
+ readonly leaves: Mesh<BufferGeometry, MeshStandardNodeMaterial>;
35
+ /** This tree's Growth uniform (read by the wood and leaf materials' `positionNode`). */
36
+ readonly growthUniform: UniformNode<'float', number>;
37
+ /** The Season uniform the leaf material reads (shared nodes may reference it). */
38
+ readonly seasonUniform: SeasonUniform;
39
+ /** This tree's response to the Wind, from `definition.wind`; `windResponse.set(...)` changes it live. */
40
+ readonly windResponse: WindResponse;
41
+ private readonly windBinding;
42
+ /**
43
+ * Resolves once every texture of this tree has loaded (at once for a tree without textures);
44
+ * rejects if one fails. Await it before a first render that must show the textures.
45
+ */
46
+ readonly ready: Promise<void>;
47
+ constructor(definition: TreeDefinition, data: TreeData, options?: TreeOptions);
48
+ /**
49
+ * The Wind this tree sways with (shared with every other tree using it). Assigning another
50
+ * Wind only rebinds uniforms: no regeneration, no recompile.
51
+ */
52
+ get wind(): Wind;
53
+ set wind(value: Wind);
54
+ /**
55
+ * Season: 0 (first day of spring) .. 1 (last day of winter); sets leaf colour, leaf coverage
56
+ * and blossom from the Definition's Season Profile. Values outside 0..1 wrap around the year.
57
+ * Only updates a uniform, so it is cheap to animate.
58
+ */
59
+ get season(): number;
60
+ set season(value: number);
61
+ /**
62
+ * How far this tree has grown: 0 (sapling) .. 1 (fully grown); values outside are clamped.
63
+ * Setting it only writes a uniform, so it is cheap to animate every frame.
64
+ */
65
+ get growth(): number;
66
+ set growth(value: number);
67
+ /** Frees the GPU resources (geometries and materials) of this tree and removes it from its parent. */
68
+ dispose(): void;
69
+ }
70
+ //# sourceMappingURL=Tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../src/tree/Tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,KAAK,EAGL,IAAI,EACJ,KAAK,QAAQ,EACb,KAAK,wBAAwB,EAE7B,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAqC,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIhF,OAAO,EAAgD,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE7F,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAoC,IAAI,EAAe,YAAY,EAAE,MAAM,SAAS,CAAC;AAiD5F,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,IAAK,SAAQ,KAAK;IAC7B,QAAQ,CAAC,MAAM,QAAQ;IACvB,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC9C,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC;IAChE,wFAAwF;IACxF,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,kFAAkF;IAClF,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,yGAAyG;IACzG,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAE1C;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBAElB,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,GAAE,WAAgB;IAkCjF;;;OAGG;IACH,IAAI,IAAI,IAAI,IAAI,CAEf;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,EAEnB;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,sGAAsG;IAC7F,OAAO,IAAI,IAAI;CAWzB"}
@@ -0,0 +1,14 @@
1
+ import { type TreeDefinition, type TreeDefinitionInput } from '../definition';
2
+ import { Tree, type TreeOptions } from './Tree';
3
+ export { Tree, type TreeOptions } from './Tree';
4
+ export interface CreateTreeOptions extends TreeOptions {
5
+ /** Picks one individual tree within the Definition's ranges. Default 0. */
6
+ seed?: number;
7
+ }
8
+ /**
9
+ * Grows a tree from a Tree Definition (plain object or parsed JSON) and a Seed and
10
+ * returns a three.js object to add to a scene rendered by `WebGPURenderer`.
11
+ * Throws `TreeDefinitionError` for an invalid Definition.
12
+ */
13
+ export declare function createTree(definition: TreeDefinitionInput | TreeDefinition, options?: CreateTreeOptions): Tree;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tree/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE/F,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,mBAAmB,GAAG,cAAc,EAChD,OAAO,GAAE,iBAAsB,GAC9B,IAAI,CASN"}
@@ -0,0 +1,20 @@
1
+ // src/definition/types.ts
2
+ /**
3
+ * Tree Definition schema (see GLOSSARY.md). Plain JSON: it is what the Tree Editor exports
4
+ * and what `createTree` consumes. Every field is documented with its unit and allowed range;
5
+ * the runtime rules live in `schema.ts` and the defaults in `defaults.ts`.
6
+ *
7
+ * Conventions: lengths in metres (scene units), angles in degrees, colours as `#rrggbb`,
8
+ * "fraction" fields are 0..1. Fields named `*Variation` are Seed ranges: the Seed picks a
9
+ * value within ± that fraction of the base value.
10
+ */
11
+ /**
12
+ * Current Tree Definition schema version. Bump it, and add a migration in `migrations.ts`,
13
+ * whenever the format changes or a generator change would alter existing trees (ADR 0003).
14
+ */
15
+ var CURRENT_SCHEMA_VERSION = 2;
16
+ /** Maximum number of branching levels below the trunk. */
17
+ var MAX_BRANCH_LEVELS = 4;
18
+ export { MAX_BRANCH_LEVELS as n, CURRENT_SCHEMA_VERSION as t };
19
+
20
+ //# sourceMappingURL=types-BZjHhNz7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-BZjHhNz7.js","names":[],"sources":["../src/definition/types.ts"],"sourcesContent":["/**\n * Tree Definition schema (see GLOSSARY.md). Plain JSON: it is what the Tree Editor exports\n * and what `createTree` consumes. Every field is documented with its unit and allowed range;\n * the runtime rules live in `schema.ts` and the defaults in `defaults.ts`.\n *\n * Conventions: lengths in metres (scene units), angles in degrees, colours as `#rrggbb`,\n * \"fraction\" fields are 0..1. Fields named `*Variation` are Seed ranges: the Seed picks a\n * value within ± that fraction of the base value.\n */\n\n/**\n * Current Tree Definition schema version. Bump it, and add a migration in `migrations.ts`,\n * whenever the format changes or a generator change would alter existing trees (ADR 0003).\n */\nexport const CURRENT_SCHEMA_VERSION = 2;\n\n/** `#rrggbb` colour string. */\nexport type HexColor = string;\n\n/** [x, y, z] */\nexport type Vec3Tuple = [number, number, number];\n\n/** The overall kind of tree a Definition grows. */\nexport type TreeForm = 'broadleaf' | 'conifer';\n\n/** Trunk parameters (branch level 0). */\nexport interface TrunkDefinition {\n /** Trunk length at full Growth, metres (> 0). */\n length: number;\n /** Radius at the base, metres (> 0). */\n radius: number;\n /** Tip radius as a fraction of the base radius (0 = point, 1 = cylinder). */\n taper: number;\n /** Number of sides around the trunk (integer >= 3). */\n sides: number;\n /** Number of sections along the trunk (integer >= 1). */\n sections: number;\n /** Seed range: the Seed scales length by up to ± this fraction (0..1). */\n lengthVariation: number;\n /** Seed range: maximum sideways drift per section, as a fraction of the section length (0..1). */\n bend: number;\n}\n\n/**\n * One level of branching. `branches[0]` grows from the trunk, `branches[1]` from the\n * level-1 branches, and so on (at most {@link MAX_BRANCH_LEVELS} levels).\n */\nexport interface BranchLevelDefinition {\n /** Child branches per parent branch (integer >= 0). */\n count: number;\n /** Where along the parent children start, as a fraction of the parent length (0..1). */\n start: number;\n /** Where along the parent children stop, as a fraction of the parent length (0..1, >= start). */\n end: number;\n /** Angle between parent and child direction, degrees (0..180). */\n angle: number;\n /** Seed range: ± this fraction of `angle` (0..1). */\n angleVariation: number;\n /** Rotation around the parent between successive children, degrees (0..360; 137.5 = golden angle). */\n spiral: number;\n /** Child length as a fraction of the parent's length (> 0). */\n length: number;\n /** Seed range: ± this fraction of `length` (0..1). */\n lengthVariation: number;\n /** Child base radius as a fraction of the parent's radius where it attaches (0..1). */\n radius: number;\n /** Tip radius as a fraction of the base radius (0..1). */\n taper: number;\n /** Number of sides around each branch (integer >= 3). */\n sides: number;\n /** Number of sections along each branch (integer >= 1). */\n sections: number;\n /** Seed range: maximum sideways drift per section, as a fraction of the section length (0..1). */\n bend: number;\n /** Upward (+) or downward (−) pull on the branch tip (−1..1). */\n gravity: number;\n}\n\n/** Maximum number of branching levels below the trunk. */\nexport const MAX_BRANCH_LEVELS = 4;\n\n/**\n * How a leaf is drawn: a flat card, a faceted clump of foliage, a needle cluster, or a puff\n * (a smooth round ball of foliage, for toon shading).\n */\nexport type LeafShape = 'card' | 'clump' | 'needle' | 'puff';\n\n/** Leaves, placed on the last branching level (or the trunk if there are no branches). */\nexport interface LeavesDefinition {\n /** Leaves per terminal branch (integer >= 0; 0 = no leaves). */\n count: number;\n /** Leaf shape. */\n shape: LeafShape;\n /** Leaf size (width and length of a card / clump diameter), metres (> 0). */\n size: number;\n /** Seed range: ± this fraction of `size` (0..1). */\n sizeVariation: number;\n /** Where along the terminal branch leaves start, as a fraction of its length (0..1). */\n start: number;\n /** Angle between branch and leaf, degrees (0..180). */\n angle: number;\n}\n\n/** Material shading model. Low-poly uses `flat`, stylized `toon`, realistic `standard`. */\nexport type Shading = 'standard' | 'flat' | 'toon';\n\nexport interface BarkMaterialDefinition {\n /** Base bark colour. */\n color: HexColor;\n /** PBR roughness (0..1). */\n roughness: number;\n /** Colour texture URL (resolved against the app's texture base path), or null for none. */\n map: string | null;\n /** Normal map URL, or null for none. */\n normalMap: string | null;\n}\n\nexport interface LeafMaterialDefinition {\n /** PBR roughness (0..1). Leaf colour comes from the Season Profile. */\n roughness: number;\n /** Leaf card texture URL (alpha cut-out), or null for none. */\n map: string | null;\n /** Alpha cut-off for `map` (0..1). */\n alphaTest: number;\n}\n\nexport interface MaterialsDefinition {\n shading: Shading;\n bark: BarkMaterialDefinition;\n leaf: LeafMaterialDefinition;\n}\n\n/** One keyframe of a Season Profile track. `t` is the Season (0 = first day of spring .. 1 = last day of winter). */\nexport interface Keyframe<V> {\n t: number;\n value: V;\n}\n\n/**\n * How leaf colour, leaf coverage and blossom change across Season. Each track needs\n * at least one keyframe; keyframes are sorted by `t` (non-decreasing).\n */\nexport interface SeasonProfileDefinition {\n /** Leaf colour keyframes. */\n leafColor: Keyframe<HexColor>[];\n /** Leaf coverage keyframes (0 = bare .. 1 = full). */\n leafCoverage: Keyframe<number>[];\n /** Blossom amount keyframes (0 = none .. 1 = full bloom). */\n blossom: Keyframe<number>[];\n /** Blossom colour. */\n blossomColor: HexColor;\n}\n\n/** Per-tree response to the scene-wide Wind. All 0 (stiff) .. 1 (very flexible). */\nexport interface WindResponseDefinition {\n /** Sway of the trunk. */\n trunk: number;\n /** Sway of the branches. */\n branches: number;\n /** Flutter of the leaves. */\n leaves: number;\n /** Sway speed multiplier (> 0; 1 = default). */\n frequency: number;\n}\n\n/** Seed ranges that are not tied to one tree part. All 0 (none) .. 1. */\nexport interface VariationDefinition {\n /** How much the Seed shifts bark and leaf colours. */\n color: number;\n /** How much the Seed shifts the timing of Growth (fraction of the 0..1 range). */\n growth: number;\n /** How much the Seed shifts the timing of Season (fraction of the 0..1 range). */\n season: number;\n}\n\ninterface SculptBase {\n /** The Seed the Sculpt was made on; every other Seed ignores it (ADR 0003). */\n seed: number;\n /** Branch path, e.g. \"0\" (trunk) or \"0.3.1\". */\n path: string;\n}\n/** Removes a branch and everything growing from it. */\nexport interface DeleteSculpt extends SculptBase {\n action: 'delete';\n}\n/** Rotates (Euler XYZ, radians) and scales a branch around its base. */\nexport interface MoveSculpt extends SculptBase {\n action: 'move';\n rotation: Vec3Tuple;\n /** Length scale (> 0). */\n scale: number;\n}\n/** Sets the leaf coverage (0..1) of a branch and everything growing from it. */\nexport interface LeavesSculpt extends SculptBase {\n action: 'leaves';\n coverage: number;\n}\n/** A hand edit made in the Tree Editor, tied to one Seed. */\nexport type Sculpt = DeleteSculpt | MoveSculpt | LeavesSculpt;\n\n/**\n * The full parameter set that describes how a tree is generated, independent of any Seed.\n */\nexport interface TreeDefinition {\n schemaVersion: typeof CURRENT_SCHEMA_VERSION;\n /** Optional human-readable name. */\n name: string;\n /** 'conifer': the branches from the trunk shrink towards its tip (a cone); 'broadleaf': they don't. */\n form: TreeForm;\n trunk: TrunkDefinition;\n /** Branching levels below the trunk (0..{@link MAX_BRANCH_LEVELS} entries). */\n branches: BranchLevelDefinition[];\n leaves: LeavesDefinition;\n materials: MaterialsDefinition;\n season: SeasonProfileDefinition;\n wind: WindResponseDefinition;\n variation: VariationDefinition;\n sculpts: Sculpt[];\n}\n\n/**\n * Deep partial for Definition input. Objects may omit fields (they get defaults); arrays\n * replace the default array as a whole. Branch levels may be partial (missing fields come\n * from {@link DEFAULT_BRANCH_LEVEL}); keyframes and Sculpts must be complete.\n */\nexport type DeepPartial<T> = T extends (infer U)[]\n ? (U extends Keyframe<unknown> | Sculpt ? U : DeepPartial<U>)[]\n : T extends object\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T;\n\n/**\n * What callers may pass: `schemaVersion` plus any subset of the fields; the rest is defaulted.\n * Older `schemaVersion`s are accepted and migrated.\n */\nexport type TreeDefinitionInput = { schemaVersion: number } & DeepPartial<Omit<TreeDefinition, 'schemaVersion'>>;\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,yBAAyB;;AAiEtC,IAAa,oBAAoB"}
@@ -0,0 +1,54 @@
1
+ import { Vector3, type UniformNode } from 'three/webgpu';
2
+ export type WindDirection = Vector3 | readonly [number, number, number];
3
+ export interface WindOptions {
4
+ /** World-space direction the wind blows towards (any length > 0; stored as a unit vector). Default +X. */
5
+ direction?: WindDirection;
6
+ /** 0 = calm (default), 1 = strong wind; larger values are allowed for storms. */
7
+ strength?: number;
8
+ }
9
+ /**
10
+ * Scene-wide Wind: a direction and a strength that every tree listening to it sways with.
11
+ * Changing them only writes uniform values (no recompile). Trees use {@link sceneWind} unless
12
+ * `createTree(..., { wind })` names another one. How much each tree moves is its Definition's
13
+ * Wind response (`definition.wind`).
14
+ */
15
+ export declare class Wind {
16
+ /** The shared TSL uniforms tree materials read. Write through the setters, not here. */
17
+ readonly uniforms: {
18
+ readonly direction: UniformNode<'vec3', Vector3>;
19
+ readonly strength: UniformNode<'float', number>;
20
+ /** Seconds; follows the renderer clock unless {@link Wind.time} pins it. */
21
+ readonly time: UniformNode<'float', number>;
22
+ };
23
+ private pinnedTime;
24
+ constructor(options?: WindOptions);
25
+ /** Unit direction the wind blows towards (a copy: assign a new value to change it). */
26
+ get direction(): Vector3;
27
+ set direction(value: WindDirection);
28
+ get strength(): number;
29
+ set strength(value: number);
30
+ /**
31
+ * Pins the Wind clock to a time in seconds (pause, deterministic screenshots), or `null`
32
+ * (default) to follow the renderer's clock.
33
+ */
34
+ get time(): number | null;
35
+ set time(value: number | null);
36
+ /** Sets direction and/or strength; returns this. */
37
+ set(options: WindOptions): this;
38
+ }
39
+ /** The scene-wide Wind every tree sways with by default. */
40
+ export declare const sceneWind: Wind;
41
+ /** The uniforms Wind nodes read: those of a {@link Wind}, or of a {@link WindBinding}. */
42
+ export type WindUniforms = Wind['uniforms'];
43
+ /**
44
+ * Per-object Wind uniforms that follow whichever Wind is bound to them, read once per render.
45
+ * Trees and Forests build their Wind nodes on these, so switching to another Wind is one
46
+ * assignment: no new nodes, no recompile, no regeneration.
47
+ */
48
+ export declare class WindBinding {
49
+ /** The bound Wind. */
50
+ wind: Wind;
51
+ readonly uniforms: WindUniforms;
52
+ constructor(wind: Wind);
53
+ }
54
+ //# sourceMappingURL=Wind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wind.d.ts","sourceRoot":"","sources":["../../src/wind/Wind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAGzD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAExE,MAAM,WAAW,WAAW;IAC1B,0GAA0G;IAC1G,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBAAa,IAAI;IACf,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAChD,4EAA4E;QAC5E,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC7C,CAAC;IACF,OAAO,CAAC,UAAU,CAAuB;gBAE7B,OAAO,GAAE,WAAgB;IASrC,uFAAuF;IACvF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,SAAS,CAAC,KAAK,EAAE,aAAa,EAOjC;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAGzB;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAG5B;IAED,oDAAoD;IACpD,GAAG,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;CAKhC;AAED,4DAA4D;AAC5D,eAAO,MAAM,SAAS,MAAa,CAAC;AAEpC,0FAA0F;AAC1F,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,WAAW;IACtB,sBAAsB;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;gBAEpB,IAAI,EAAE,IAAI;CASvB"}
@@ -0,0 +1,4 @@
1
+ export { Wind, WindBinding, sceneWind, type WindDirection, type WindOptions, type WindUniforms } from './Wind';
2
+ export { WindResponse } from './response';
3
+ export { windOffset, applyWind, objectWindDirection, type WindFrame, type WindSource } from './node';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wind/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { Node, NodeMaterial } from 'three/webgpu';
2
+ import type { WindUniforms } from './Wind';
3
+ import type { WindResponse } from './response';
4
+ /**
5
+ * Overrides for trees that are not one object each (Forest instances): the Wind direction in
6
+ * the tree's own space and the tree's phase (radians), e.g. from per-instance attributes.
7
+ */
8
+ export interface WindFrame {
9
+ direction?: Node<'vec3'>;
10
+ phase?: Node<'float'>;
11
+ }
12
+ /** Anything holding Wind uniforms: a {@link Wind} or a {@link WindBinding} that follows one. */
13
+ export interface WindSource {
14
+ readonly uniforms: WindUniforms;
15
+ }
16
+ /** The scene Wind direction in the rendered object's space (rotation only, normalized). */
17
+ export declare function objectWindDirection(wind: WindSource): Node<'vec3'>;
18
+ /**
19
+ * TSL node: the Wind displacement (vec3, object space) of each vertex, from the per-vertex
20
+ * `aWind` weights (trunk sway, branch sway, leaf flutter), the tree's Wind response and the
21
+ * scene Wind. It only depends on geometry attributes and uniforms, so it adds onto any other
22
+ * position node (Growth): `position = grown + windOffset(...)` (see {@link applyWind}).
23
+ *
24
+ * - trunk: leans with the wind and swings slowly, bending from the ground (weight = height²);
25
+ * - branches: swing faster, with a phase that varies smoothly in space so joints stay attached,
26
+ * plus a little cross-wind motion;
27
+ * - leaves: flutter along their normal, more at the tip.
28
+ * All of it is scaled by slow gusts. Wind direction is world space; it is turned into the tree's
29
+ * object space (rotation only, so a scaled-up tree sways proportionally more). `frame` replaces
30
+ * that direction and the response's phase (see {@link WindFrame}).
31
+ */
32
+ export declare function windOffset(wind: WindSource, response: WindResponse, frame?: WindFrame): Node<'vec3'>;
33
+ /**
34
+ * Adds a Wind offset to a material's vertex position (its existing `positionNode`, or the plain
35
+ * local position). The shadow pass reuses `positionNode`, so shadows sway along.
36
+ */
37
+ export declare function applyWind(material: NodeMaterial, offset: Node<'vec3'>): void;
38
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/wind/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAavD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ/C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;CACvB;AAED,gGAAgG;AAChG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;CACjC;AAED,2FAA2F;AAC3F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAElE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,GAAE,SAAc,GAAG,IAAI,CAAC,MAAM,CAAC,CAgCxG;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAG5E"}
@@ -0,0 +1,27 @@
1
+ import type { UniformNode } from 'three/webgpu';
2
+ import type { WindResponseDefinition } from '../definition';
3
+ /**
4
+ * One tree's response to the Wind (from its Definition's `wind`), held in uniforms so the
5
+ * Tree Editor can change it live. `height` (trunk height) and `phase` (from the Seed) shape the
6
+ * motion: the sway scales with the tree, and trees of different Seeds move out of step.
7
+ */
8
+ export declare class WindResponse {
9
+ readonly uniforms: {
10
+ readonly trunk: UniformNode<'float', number>;
11
+ readonly branches: UniformNode<'float', number>;
12
+ readonly leaves: UniformNode<'float', number>;
13
+ readonly frequency: UniformNode<'float', number>;
14
+ readonly height: UniformNode<'float', number>;
15
+ /** Radians, 0..2π. */
16
+ readonly phase: UniformNode<'float', number>;
17
+ };
18
+ constructor(response: WindResponseDefinition, shape: {
19
+ height: number;
20
+ phase: number;
21
+ });
22
+ /** The current response, as in the Definition's `wind`. */
23
+ get values(): WindResponseDefinition;
24
+ /** Changes part of the response (uniform writes only). Weights are 0..1, frequency > 0. */
25
+ set(response: Partial<WindResponseDefinition>): this;
26
+ }
27
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/wind/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D;;;;GAIG;AACH,qBAAa,YAAY;IACvB,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7C,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAChD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9C,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACjD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9C,sBAAsB;QACtB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC9C,CAAC;gBAEU,QAAQ,EAAE,sBAAsB,EAAE,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAYtF,2DAA2D;IAC3D,IAAI,MAAM,IAAI,sBAAsB,CAGnC;IAED,2FAA2F;IAC3F,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,sBAAsB,CAAC,GAAG,IAAI;CAerD"}
package/package.json CHANGED
@@ -1,6 +1,109 @@
1
1
  {
2
2
  "name": "@casmo/tree.js",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Procedural trees for three.js (WebGPURenderer, TSL node materials).",
5
+ "keywords": [
6
+ "three",
7
+ "three.js",
8
+ "webgpu",
9
+ "tsl",
10
+ "procedural",
11
+ "tree",
12
+ "vegetation",
13
+ "forest",
14
+ "react-three-fiber"
15
+ ],
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "sideEffects": false,
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Casmo/tree.js.git"
22
+ },
23
+ "homepage": "https://github.com/Casmo/tree.js#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/Casmo/tree.js/issues"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ },
38
+ "./styles/low-poly": {
39
+ "types": "./dist/styles/low-poly/index.d.ts",
40
+ "import": "./dist/styles/low-poly.js"
41
+ },
42
+ "./styles/stylized": {
43
+ "types": "./dist/styles/stylized/index.d.ts",
44
+ "import": "./dist/styles/stylized.js"
45
+ },
46
+ "./styles/realistic": {
47
+ "types": "./dist/styles/realistic/index.d.ts",
48
+ "import": "./dist/styles/realistic.js"
49
+ },
50
+ "./react": {
51
+ "types": "./dist/react/index.d.ts",
52
+ "import": "./dist/react.js"
53
+ },
54
+ "./effects": {
55
+ "types": "./dist/effects/index.d.ts",
56
+ "import": "./dist/effects.js"
57
+ },
58
+ "./package.json": "./package.json"
59
+ },
60
+ "scripts": {
61
+ "dev": "vite",
62
+ "dev:editor": "vite --config editor/vite.config.ts",
63
+ "build": "vite build && tsc -p tsconfig.build.json",
64
+ "build:editor": "vite build --config editor/vite.config.ts",
65
+ "build:examples": "vite build --config examples/vite.config.ts",
66
+ "typecheck": "tsc -p tsconfig.json --noEmit",
67
+ "lint": "eslint .",
68
+ "test": "vitest run",
69
+ "test:watch": "vitest",
70
+ "test:e2e": "playwright test",
71
+ "readme-media": "node scripts/readme-media/capture.mjs",
72
+ "prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run build"
73
+ },
74
+ "peerDependencies": {
75
+ "@react-three/fiber": ">=9.0.0",
76
+ "react": ">=19.0.0",
77
+ "three": ">=0.187.0"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "@react-three/fiber": {
81
+ "optional": true
82
+ },
83
+ "react": {
84
+ "optional": true
85
+ }
86
+ },
87
+ "devDependencies": {
88
+ "@eslint/js": "^10.0.1",
89
+ "@playwright/test": "^1.65.1",
90
+ "@react-three/fiber": "^9.8.2",
91
+ "@react-three/test-renderer": "^9.1.1",
92
+ "@types/node": "^22.0.0",
93
+ "@types/react": "^19.3.0",
94
+ "@types/react-dom": "^19.3.0",
95
+ "@types/three": "^0.187.0",
96
+ "eslint": "^10.15.0",
97
+ "gltf-validator": "^2.0.0-dev.3.10",
98
+ "react": "~19.2.0",
99
+ "react-dom": "~19.2.0",
100
+ "three": "^0.187.0",
101
+ "typescript": "~6.0.3",
102
+ "typescript-eslint": "^8.73.0",
103
+ "vite": "^8.3.8",
104
+ "vitest": "^5.1.0"
105
+ },
106
+ "publishConfig": {
107
+ "access": "public"
108
+ }
109
+ }