@casmo/tree.js 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -16
- package/dist/apply-CcodnAbs.js +250 -0
- package/dist/apply-CcodnAbs.js.map +1 -0
- package/dist/bake/index.d.ts +2 -2
- package/dist/bake/index.d.ts.map +1 -1
- package/dist/definition/crown-shape.d.ts +9 -0
- package/dist/definition/crown-shape.d.ts.map +1 -0
- package/dist/definition/defaults.d.ts +7 -1
- package/dist/definition/defaults.d.ts.map +1 -1
- package/dist/definition/index.d.ts +4 -3
- package/dist/definition/index.d.ts.map +1 -1
- package/dist/definition/migrations.d.ts +0 -8
- package/dist/definition/migrations.d.ts.map +1 -1
- package/dist/definition/schema.d.ts.map +1 -1
- package/dist/definition/types.d.ts +95 -6
- package/dist/definition/types.d.ts.map +1 -1
- package/dist/effects/mask.d.ts +3 -3
- package/dist/effects/mask.d.ts.map +1 -1
- package/dist/effects.js +3 -3
- package/dist/effects.js.map +1 -1
- package/dist/forest/Forest.d.ts +10 -1
- package/dist/forest/Forest.d.ts.map +1 -1
- package/dist/forest/nodes.d.ts +4 -1
- package/dist/forest/nodes.d.ts.map +1 -1
- package/dist/{forest-OX9WvAwh.js → forest-DTrD8puH.js} +695 -546
- package/dist/forest-DTrD8puH.js.map +1 -0
- package/dist/generator/branches.d.ts +2 -2
- package/dist/generator/branches.d.ts.map +1 -1
- package/dist/generator/fruit.d.ts +28 -0
- package/dist/generator/fruit.d.ts.map +1 -0
- package/dist/generator/growth.d.ts +1 -1
- package/dist/generator/growth.d.ts.map +1 -1
- package/dist/generator/index.d.ts +4 -4
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/leaf-shapes.d.ts +33 -1
- package/dist/generator/leaf-shapes.d.ts.map +1 -1
- package/dist/generator/trunk.d.ts +8 -2
- package/dist/generator/trunk.d.ts.map +1 -1
- package/dist/generator/types.d.ts +34 -5
- package/dist/generator/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -4
- package/dist/index.js.map +1 -1
- package/dist/materials/index.d.ts +6 -0
- package/dist/materials/index.d.ts.map +1 -1
- package/dist/names-C6-wuJ29.js +589 -0
- package/dist/names-C6-wuJ29.js.map +1 -0
- package/dist/react/Tree.d.ts +5 -2
- package/dist/react/Tree.d.ts.map +1 -1
- package/dist/react.js +10 -6
- package/dist/react.js.map +1 -1
- package/dist/season/nodes.d.ts +16 -0
- package/dist/season/nodes.d.ts.map +1 -1
- package/dist/season/profile.d.ts +26 -0
- package/dist/season/profile.d.ts.map +1 -1
- package/dist/species/almond.js +213 -0
- package/dist/species/almond.js.map +1 -0
- package/dist/species/almond.json +201 -0
- package/dist/species/apple.js +220 -0
- package/dist/species/apple.js.map +1 -0
- package/dist/species/apple.json +211 -0
- package/dist/species/ash.js +177 -0
- package/dist/species/ash.js.map +1 -0
- package/dist/species/ash.json +168 -0
- package/dist/species/beech.js +164 -0
- package/dist/species/beech.js.map +1 -0
- package/dist/species/beech.json +158 -0
- package/dist/species/birch.js +160 -0
- package/dist/species/birch.js.map +1 -0
- package/dist/species/birch.json +154 -0
- package/dist/species/catalog.d.ts +61 -0
- package/dist/species/catalog.d.ts.map +1 -0
- package/dist/species/cedar.js +159 -0
- package/dist/species/cedar.js.map +1 -0
- package/dist/species/cedar.json +159 -0
- package/dist/species/cherry.js +227 -0
- package/dist/species/cherry.js.map +1 -0
- package/dist/species/cherry.json +215 -0
- package/dist/species/chestnut.js +220 -0
- package/dist/species/chestnut.js.map +1 -0
- package/dist/species/chestnut.json +211 -0
- package/dist/species/douglas-fir.js +164 -0
- package/dist/species/douglas-fir.js.map +1 -0
- package/dist/species/douglas-fir.json +161 -0
- package/dist/species/elm.js +163 -0
- package/dist/species/elm.js.map +1 -0
- package/dist/species/elm.json +154 -0
- package/dist/species/hemlock.js +165 -0
- package/dist/species/hemlock.js.map +1 -0
- package/dist/species/hemlock.json +162 -0
- package/dist/species/hickory.js +190 -0
- package/dist/species/hickory.js.map +1 -0
- package/dist/species/hickory.json +183 -0
- package/dist/species/index.d.ts +10 -0
- package/dist/species/index.d.ts.map +1 -0
- package/dist/species/juniper.js +148 -0
- package/dist/species/juniper.js.map +1 -0
- package/dist/species/juniper.json +145 -0
- package/dist/species/loaders.d.ts +7 -0
- package/dist/species/loaders.d.ts.map +1 -0
- package/dist/species/mahogany.js +191 -0
- package/dist/species/mahogany.js.map +1 -0
- package/dist/species/mahogany.json +187 -0
- package/dist/species/maple.js +167 -0
- package/dist/species/maple.js.map +1 -0
- package/dist/species/maple.json +162 -0
- package/dist/species/oak.js +210 -0
- package/dist/species/oak.js.map +1 -0
- package/dist/species/oak.json +203 -0
- package/dist/species/olive.js +179 -0
- package/dist/species/olive.js.map +1 -0
- package/dist/species/olive.json +172 -0
- package/dist/species/peach.js +213 -0
- package/dist/species/peach.js.map +1 -0
- package/dist/species/peach.json +201 -0
- package/dist/species/pear.js +203 -0
- package/dist/species/pear.js.map +1 -0
- package/dist/species/pear.json +191 -0
- package/dist/species/pine.js +153 -0
- package/dist/species/pine.js.map +1 -0
- package/dist/species/pine.json +153 -0
- package/dist/species/plum.js +227 -0
- package/dist/species/plum.js.map +1 -0
- package/dist/species/plum.json +215 -0
- package/dist/species/red-oak.js +210 -0
- package/dist/species/red-oak.js.map +1 -0
- package/dist/species/red-oak.json +203 -0
- package/dist/species/redwood.js +164 -0
- package/dist/species/redwood.js.map +1 -0
- package/dist/species/redwood.json +161 -0
- package/dist/species/sequoia.js +157 -0
- package/dist/species/sequoia.js.map +1 -0
- package/dist/species/sequoia.json +157 -0
- package/dist/species/spruce.js +160 -0
- package/dist/species/spruce.js.map +1 -0
- package/dist/species/spruce.json +157 -0
- package/dist/species/teak.js +156 -0
- package/dist/species/teak.js.map +1 -0
- package/dist/species/teak.json +148 -0
- package/dist/species/types.d.ts +61 -0
- package/dist/species/types.d.ts.map +1 -0
- package/dist/species/walnut.js +210 -0
- package/dist/species/walnut.js.map +1 -0
- package/dist/species/walnut.json +203 -0
- package/dist/species/white-oak.js +203 -0
- package/dist/species/white-oak.js.map +1 -0
- package/dist/species/white-oak.json +199 -0
- package/dist/species.js +160 -0
- package/dist/species.js.map +1 -0
- package/dist/styles/apply.d.ts +12 -0
- package/dist/styles/apply.d.ts.map +1 -0
- package/dist/styles/low-poly/index.d.ts +1 -1
- package/dist/styles/low-poly/index.d.ts.map +1 -1
- package/dist/styles/low-poly.js +9 -8
- package/dist/styles/low-poly.js.map +1 -1
- package/dist/styles/names.d.ts +28 -0
- package/dist/styles/names.d.ts.map +1 -0
- package/dist/styles/realistic/index.d.ts +3 -8
- package/dist/styles/realistic/index.d.ts.map +1 -1
- package/dist/styles/realistic/textures.d.ts +20 -0
- package/dist/styles/realistic/textures.d.ts.map +1 -0
- package/dist/styles/realistic.js +10 -16
- package/dist/styles/realistic.js.map +1 -1
- package/dist/styles/registry.d.ts +2 -13
- package/dist/styles/registry.d.ts.map +1 -1
- package/dist/styles/stylized/index.d.ts +1 -1
- package/dist/styles/stylized/index.d.ts.map +1 -1
- package/dist/styles/stylized.js +9 -8
- package/dist/styles/stylized.js.map +1 -1
- package/dist/styles/types.d.ts +16 -2
- package/dist/styles/types.d.ts.map +1 -1
- package/dist/textures/realistic/bark-fibrous-normal.png +0 -0
- package/dist/textures/realistic/bark-fibrous.png +0 -0
- package/dist/textures/realistic/bark-papery-normal.png +0 -0
- package/dist/textures/realistic/bark-papery.png +0 -0
- package/dist/textures/realistic/bark-plated-normal.png +0 -0
- package/dist/textures/realistic/bark-plated.png +0 -0
- package/dist/textures/realistic/bark-smooth-normal.png +0 -0
- package/dist/textures/realistic/bark-smooth.png +0 -0
- package/dist/textures/realistic/leaf-compound.png +0 -0
- package/dist/textures/realistic/leaf-lobed.png +0 -0
- package/dist/textures/realistic/leaf-palmate.png +0 -0
- package/dist/textures/realistic/scale.png +0 -0
- package/dist/tree/Tree.d.ts +6 -4
- package/dist/tree/Tree.d.ts.map +1 -1
- package/package.json +9 -2
- package/dist/forest-OX9WvAwh.js.map +0 -1
- package/dist/types-BZjHhNz7.js +0 -20
- package/dist/types-BZjHhNz7.js.map +0 -1
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
* Current Tree Definition schema version. Bump it, and add a migration in `migrations.ts`,
|
|
12
12
|
* whenever the format changes or a generator change would alter existing trees (ADR 0003).
|
|
13
13
|
*/
|
|
14
|
-
export declare const CURRENT_SCHEMA_VERSION =
|
|
14
|
+
export declare const CURRENT_SCHEMA_VERSION = 3;
|
|
15
15
|
/** `#rrggbb` colour string. */
|
|
16
16
|
export type HexColor = string;
|
|
17
17
|
/** [x, y, z] */
|
|
18
18
|
export type Vec3Tuple = [number, number, number];
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Form: a label that groups trees (a Style's `broadleaf` / `conifer` Definition). It never
|
|
21
|
+
* changes geometry and is not part of the Tree Definition; a crown's shape comes from its
|
|
22
|
+
* Crown Shape curves (ADR 0004).
|
|
23
|
+
*/
|
|
20
24
|
export type TreeForm = 'broadleaf' | 'conifer';
|
|
21
25
|
/** Trunk parameters (branch level 0). */
|
|
22
26
|
export interface TrunkDefinition {
|
|
@@ -34,6 +38,21 @@ export interface TrunkDefinition {
|
|
|
34
38
|
lengthVariation: number;
|
|
35
39
|
/** Seed range: maximum sideways drift per section, as a fraction of the section length (0..1). */
|
|
36
40
|
bend: number;
|
|
41
|
+
/**
|
|
42
|
+
* Number of Stems growing from the ground (integer >= 1). Each Stem is a full trunk with these
|
|
43
|
+
* parameters and the full branch structure; Stem paths are "0", "1", "2", ... Absent = 1 (a single trunk).
|
|
44
|
+
*/
|
|
45
|
+
stems?: number;
|
|
46
|
+
/**
|
|
47
|
+
* How far each Stem leans out from vertical, degrees (0..90). The Seed varies it per Stem
|
|
48
|
+
* (± 30 %) and turns the ring of Stems. Absent = 0 (upright).
|
|
49
|
+
*/
|
|
50
|
+
spread?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Pull on the leader, the upper third of each Stem (−1..1): − makes it nod over (a hemlock's
|
|
53
|
+
* drooping tip), + pulls a leaning Stem back up. The lower trunk is never bent. Absent = 0 (none).
|
|
54
|
+
*/
|
|
55
|
+
gravity?: number;
|
|
37
56
|
}
|
|
38
57
|
/**
|
|
39
58
|
* One level of branching. `branches[0]` grows from the trunk, `branches[1]` from the
|
|
@@ -68,6 +87,14 @@ export interface BranchLevelDefinition {
|
|
|
68
87
|
bend: number;
|
|
69
88
|
/** Upward (+) or downward (−) pull on the branch tip (−1..1). */
|
|
70
89
|
gravity: number;
|
|
90
|
+
/**
|
|
91
|
+
* Crown Shape: multiplies `length` by the attach position on the parent (`t` 0 = base .. 1 = tip),
|
|
92
|
+
* values >= 0. Linear between keyframes, holding the first/last value outside them. Absent = flat (1).
|
|
93
|
+
* E.g. a cone: `[{ t: start, value: 1 }, { t: 1, value: 0.1 }]`.
|
|
94
|
+
*/
|
|
95
|
+
lengthProfile?: Keyframe<number>[];
|
|
96
|
+
/** Crown Shape: multiplies `angle` by the attach position on the parent, like `lengthProfile` (values >= 0; the angle stays <= 180). */
|
|
97
|
+
angleProfile?: Keyframe<number>[];
|
|
71
98
|
}
|
|
72
99
|
/** Maximum number of branching levels below the trunk. */
|
|
73
100
|
export declare const MAX_BRANCH_LEVELS = 4;
|
|
@@ -76,8 +103,24 @@ export declare const MAX_BRANCH_LEVELS = 4;
|
|
|
76
103
|
* (a smooth round ball of foliage, for toon shading).
|
|
77
104
|
*/
|
|
78
105
|
export type LeafShape = 'card' | 'clump' | 'needle' | 'puff';
|
|
106
|
+
/**
|
|
107
|
+
* Leaf Type: the kind of leaf a Species has. Each Style decides how to draw it (leaf shape,
|
|
108
|
+
* count, size, texture); in a Tree Definition it is a label that never changes geometry by itself.
|
|
109
|
+
*/
|
|
110
|
+
export type LeafType = 'broad' | 'lobed' | 'palmate' | 'compound' | 'needle' | 'scale';
|
|
111
|
+
/** All Leaf Types. */
|
|
112
|
+
export declare const LEAF_TYPES: readonly LeafType[];
|
|
113
|
+
/**
|
|
114
|
+
* Bark Type: the kind of bark surface a Species has. Each Style decides how to draw it (colour
|
|
115
|
+
* only, or a texture); in a Tree Definition it is a label that never changes geometry by itself.
|
|
116
|
+
*/
|
|
117
|
+
export type BarkType = 'furrowed' | 'smooth' | 'papery' | 'fibrous' | 'plated';
|
|
118
|
+
/** All Bark Types. */
|
|
119
|
+
export declare const BARK_TYPES: readonly BarkType[];
|
|
79
120
|
/** Leaves, placed on the last branching level (or the trunk if there are no branches). */
|
|
80
121
|
export interface LeavesDefinition {
|
|
122
|
+
/** Leaf Type the leaves were drawn from (set by `Style.apply`), so a Style can be re-applied. Optional. */
|
|
123
|
+
type?: LeafType;
|
|
81
124
|
/** Leaves per terminal branch (integer >= 0; 0 = no leaves). */
|
|
82
125
|
count: number;
|
|
83
126
|
/** Leaf shape. */
|
|
@@ -91,9 +134,43 @@ export interface LeavesDefinition {
|
|
|
91
134
|
/** Angle between branch and leaf, degrees (0..180). */
|
|
92
135
|
angle: number;
|
|
93
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Fruit Type: the kind of Fruit a tree bears. `round` (apple, cherry, plum), `pear`, `nut` (a
|
|
139
|
+
* spiky husk, e.g. chestnut), `cone` (conifer cones) or `berry` (small, e.g. juniper).
|
|
140
|
+
*/
|
|
141
|
+
export type FruitType = 'round' | 'pear' | 'nut' | 'cone' | 'berry';
|
|
142
|
+
/** Every Fruit Type. */
|
|
143
|
+
export declare const FRUIT_TYPES: readonly FruitType[];
|
|
144
|
+
/**
|
|
145
|
+
* Fruit (ADR 0006): its own tree part, grown on the outermost twigs (the trunk if there are no
|
|
146
|
+
* branch levels) from its own random stream, drawn as small solid shapes in the `fruit` mesh.
|
|
147
|
+
* Absent = no Fruit. Season comes from the Season Profile's `fruit` and `fruitColor` tracks.
|
|
148
|
+
*/
|
|
149
|
+
export interface FruitDefinition {
|
|
150
|
+
/** Fruit Type (shape). */
|
|
151
|
+
type: FruitType;
|
|
152
|
+
/**
|
|
153
|
+
* Fruit per outermost twig (>= 0). A fraction is a chance: 0.3 = one Fruit on about 30% of the
|
|
154
|
+
* twigs, 1.5 = one on every twig and a second on about half (which twigs comes from the Seed).
|
|
155
|
+
*/
|
|
156
|
+
count: number;
|
|
157
|
+
/** Fruit length (and about its diameter), metres (> 0). */
|
|
158
|
+
size: number;
|
|
159
|
+
/** Seed range: ± this fraction of `size` (0..1). */
|
|
160
|
+
sizeVariation: number;
|
|
161
|
+
/** How far the Fruit dangles below its twig (0 = sits on the twig pointing outward .. 1 = hangs straight down). */
|
|
162
|
+
hang: number;
|
|
163
|
+
/**
|
|
164
|
+
* Polygon detail, set by the Style: faces around each Fruit (3..16). 5 or fewer also gives a coarse
|
|
165
|
+
* profile (a few flat facets, low-poly). Absent = the Fruit Type's own smooth template.
|
|
166
|
+
*/
|
|
167
|
+
sides?: number;
|
|
168
|
+
}
|
|
94
169
|
/** Material shading model. Low-poly uses `flat`, stylized `toon`, realistic `standard`. */
|
|
95
170
|
export type Shading = 'standard' | 'flat' | 'toon';
|
|
96
171
|
export interface BarkMaterialDefinition {
|
|
172
|
+
/** Bark Type the bark was drawn from (set by `Style.apply`), so a Style can be re-applied. Optional. */
|
|
173
|
+
type?: BarkType;
|
|
97
174
|
/** Base bark colour. */
|
|
98
175
|
color: HexColor;
|
|
99
176
|
/** PBR roughness (0..1). */
|
|
@@ -116,7 +193,10 @@ export interface MaterialsDefinition {
|
|
|
116
193
|
bark: BarkMaterialDefinition;
|
|
117
194
|
leaf: LeafMaterialDefinition;
|
|
118
195
|
}
|
|
119
|
-
/**
|
|
196
|
+
/**
|
|
197
|
+
* One keyframe of a track. In a Season Profile `t` is the Season (0 = first day of spring .. 1 = last
|
|
198
|
+
* day of winter); in a Crown Shape curve it is the attach position on the parent branch (0 = base .. 1 = tip).
|
|
199
|
+
*/
|
|
120
200
|
export interface Keyframe<V> {
|
|
121
201
|
t: number;
|
|
122
202
|
value: V;
|
|
@@ -134,6 +214,13 @@ export interface SeasonProfileDefinition {
|
|
|
134
214
|
blossom: Keyframe<number>[];
|
|
135
215
|
/** Blossom colour. */
|
|
136
216
|
blossomColor: HexColor;
|
|
217
|
+
/**
|
|
218
|
+
* Fruit amount keyframes (0 = none .. 1 = all Fruit at full size); each Fruit shows while the amount
|
|
219
|
+
* is above its own rank and swells with the amount. Absent = 1 all year. Only used with `fruit`.
|
|
220
|
+
*/
|
|
221
|
+
fruit?: Keyframe<number>[];
|
|
222
|
+
/** Fruit colour keyframes (ripening). Absent = a red (`DEFAULT_FRUIT_COLOR`) all year. Only used with `fruit`. */
|
|
223
|
+
fruitColor?: Keyframe<HexColor>[];
|
|
137
224
|
}
|
|
138
225
|
/** Per-tree response to the scene-wide Wind. All 0 (stiff) .. 1 (very flexible). */
|
|
139
226
|
export interface WindResponseDefinition {
|
|
@@ -158,7 +245,7 @@ export interface VariationDefinition {
|
|
|
158
245
|
interface SculptBase {
|
|
159
246
|
/** The Seed the Sculpt was made on; every other Seed ignores it (ADR 0003). */
|
|
160
247
|
seed: number;
|
|
161
|
-
/** Branch path, e.g. "0" (trunk) or "0.3.1". */
|
|
248
|
+
/** Branch path, e.g. "0" (trunk / first Stem), "1" (second Stem) or "0.3.1". */
|
|
162
249
|
path: string;
|
|
163
250
|
}
|
|
164
251
|
/** Removes a branch and everything growing from it. */
|
|
@@ -186,12 +273,14 @@ export interface TreeDefinition {
|
|
|
186
273
|
schemaVersion: typeof CURRENT_SCHEMA_VERSION;
|
|
187
274
|
/** Optional human-readable name. */
|
|
188
275
|
name: string;
|
|
189
|
-
/**
|
|
190
|
-
|
|
276
|
+
/** Id of the Species this Definition was made from by `Style.apply` (e.g. `'oak'`). Optional; never changes geometry. */
|
|
277
|
+
species?: string;
|
|
191
278
|
trunk: TrunkDefinition;
|
|
192
279
|
/** Branching levels below the trunk (0..{@link MAX_BRANCH_LEVELS} entries). */
|
|
193
280
|
branches: BranchLevelDefinition[];
|
|
194
281
|
leaves: LeavesDefinition;
|
|
282
|
+
/** Fruit on the outermost twigs; absent = none. */
|
|
283
|
+
fruit?: FruitDefinition;
|
|
195
284
|
materials: MaterialsDefinition;
|
|
196
285
|
season: SeasonProfileDefinition;
|
|
197
286
|
wind: WindResponseDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/definition/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,+BAA+B;AAC/B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,gBAAgB;AAChB,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/definition/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,+BAA+B;AAC/B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,gBAAgB;AAChB,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AAE/C,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,eAAe,EAAE,MAAM,CAAC;IACxB,kGAAkG;IAClG,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,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B,CAAC;IAChC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,SAAS,EAAE,mBAAmB,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC9C,CAAC,CAAC,SAAS,QAAQ,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,GAC7D,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACtC,CAAC,CAAC;AAER;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC"}
|
package/dist/effects/mask.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { type Camera, type Material, type MRTNode, type Node, type Object3D, typ
|
|
|
2
2
|
/** Name of the tree mask output in a pass's MRT (`scenePass.getTextureNode(TREE_MASK)`). */
|
|
3
3
|
export declare const TREE_MASK = "treeMask";
|
|
4
4
|
/** The part of a tree a material draws. */
|
|
5
|
-
export type TreePart = 'bark' | 'leaves';
|
|
5
|
+
export type TreePart = 'bark' | 'leaves' | 'fruit';
|
|
6
6
|
/**
|
|
7
|
-
* Which tree part a material draws: 'bark' or '
|
|
7
|
+
* Which tree part a material draws: 'bark', 'leaves' or 'fruit' for tree.js materials (and their clones),
|
|
8
8
|
* `null` for anything else. Tree Effects only change the pixels drawn by these materials.
|
|
9
9
|
*/
|
|
10
10
|
export declare function treePartOf(material: Material | null | undefined): TreePart | null;
|
|
11
11
|
/**
|
|
12
12
|
* TSL node: the tree mask value of the object being drawn, `vec4(tree, leaves, selected, 1)`:
|
|
13
|
-
* r = 1 on tree pixels, g = 1 on leaf pixels, b = 1 on pixels of selected trees (the outline's
|
|
13
|
+
* r = 1 on tree pixels (bark, leaves and Fruit), g = 1 on leaf pixels, b = 1 on pixels of selected trees (the outline's
|
|
14
14
|
* selection), 0 elsewhere. A per-object uniform decided from the drawn material
|
|
15
15
|
* ({@link treePartOf}), so no tree material is changed and every other object writes 0.
|
|
16
16
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../../src/effects/mask.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAGtB,4FAA4F;AAC5F,eAAO,MAAM,SAAS,aAAa,CAAC;AAEpC,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../../src/effects/mask.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAGtB,4FAA4F;AAC5F,eAAO,MAAM,SAAS,aAAa,CAAC;AAEpC,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,QAAQ,GAAG,IAAI,CAGjF;AAOD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,SAAS,GAAE,SAAS,QAAQ,EAAE,GAAG,IAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAOzF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,SAAS,GAAE,SAAS,QAAQ,EAAE,GAAG,IAAW,GAAG,OAAO,CAIjF;AAED,6FAA6F;AAC7F,MAAM,WAAW,eAAe;IAC9B,6FAA6F;IAC7F,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,kGAAkG;IAClG,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,0FAA0F;AAC1F,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,SAAS,QAAQ,EAAE,GAAG,IAAW,GAAG,eAAe,CAK3H"}
|
package/dist/effects.js
CHANGED
|
@@ -5,12 +5,12 @@ import { gaussianBlur } from "three/addons/tsl/display/GaussianBlurNode.js";
|
|
|
5
5
|
/** Name of the tree mask output in a pass's MRT (`scenePass.getTextureNode(TREE_MASK)`). */
|
|
6
6
|
var TREE_MASK = "treeMask";
|
|
7
7
|
/**
|
|
8
|
-
* Which tree part a material draws: 'bark' or '
|
|
8
|
+
* Which tree part a material draws: 'bark', 'leaves' or 'fruit' for tree.js materials (and their clones),
|
|
9
9
|
* `null` for anything else. Tree Effects only change the pixels drawn by these materials.
|
|
10
10
|
*/
|
|
11
11
|
function treePartOf(material) {
|
|
12
12
|
const part = material?.userData.treePart;
|
|
13
|
-
return part === "bark" || part === "leaves" ? part : null;
|
|
13
|
+
return part === "bark" || part === "leaves" || part === "fruit" ? part : null;
|
|
14
14
|
}
|
|
15
15
|
function isSelected(object, selection) {
|
|
16
16
|
for (let o = object; o; o = o.parent) if (selection.includes(o)) return true;
|
|
@@ -18,7 +18,7 @@ function isSelected(object, selection) {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* TSL node: the tree mask value of the object being drawn, `vec4(tree, leaves, selected, 1)`:
|
|
21
|
-
* r = 1 on tree pixels, g = 1 on leaf pixels, b = 1 on pixels of selected trees (the outline's
|
|
21
|
+
* r = 1 on tree pixels (bark, leaves and Fruit), g = 1 on leaf pixels, b = 1 on pixels of selected trees (the outline's
|
|
22
22
|
* selection), 0 elsewhere. A per-object uniform decided from the drawn material
|
|
23
23
|
* ({@link treePartOf}), so no tree material is changed and every other object writes 0.
|
|
24
24
|
*
|
package/dist/effects.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effects.js","names":["tslColor","color","tslColor","color","tslColor","n"],"sources":["../src/effects/mask.ts","../src/effects/outline.ts","../src/effects/glow.ts","../src/effects/grade.ts","../src/effects/suggested.ts","../src/effects/effects.ts"],"sourcesContent":["import {\n UnsignedByteType,\n Vector4,\n type Camera,\n type Material,\n type MRTNode,\n type Node,\n type Object3D,\n type PassNode,\n type Scene,\n type TextureNode,\n} from 'three/webgpu';\nimport { mrt, output, pass, uniform } from 'three/tsl';\n\n/** Name of the tree mask output in a pass's MRT (`scenePass.getTextureNode(TREE_MASK)`). */\nexport const TREE_MASK = 'treeMask';\n\n/** The part of a tree a material draws. */\nexport type TreePart = 'bark' | 'leaves';\n\n/**\n * Which tree part a material draws: 'bark' or 'leaves' for tree.js materials (and their clones),\n * `null` for anything else. Tree Effects only change the pixels drawn by these materials.\n */\nexport function treePartOf(material: Material | null | undefined): TreePart | null {\n const part: unknown = material?.userData.treePart;\n return part === 'bark' || part === 'leaves' ? part : null;\n}\n\nfunction isSelected(object: Object3D | null, selection: readonly Object3D[]): boolean {\n for (let o = object; o; o = o.parent) if (selection.includes(o)) return true;\n return false;\n}\n\n/**\n * TSL node: the tree mask value of the object being drawn, `vec4(tree, leaves, selected, 1)`:\n * r = 1 on tree pixels, g = 1 on leaf pixels, b = 1 on pixels of selected trees (the outline's\n * selection), 0 elsewhere. A per-object uniform decided from the drawn material\n * ({@link treePartOf}), so no tree material is changed and every other object writes 0.\n *\n * `selection`: the selected tree objects (Trees, Forests, any ancestor of tree meshes), read on\n * every draw, so it may be changed in place. `null` (default) selects every tree.\n */\nexport function createTreeMask(selection: readonly Object3D[] | null = null): Node<'vec4'> {\n return uniform(new Vector4(0, 0, 0, 1)).onObjectUpdate((frame, self) => {\n const part = treePartOf(frame.material);\n const selected = part !== null && (selection === null || isSelected(frame.object, selection));\n self.value.set(part ? 1 : 0, part === 'leaves' ? 1 : 0, selected ? 1 : 0, 1);\n return undefined;\n });\n}\n\n/**\n * The MRT output that renders the tree mask ({@link createTreeMask}) next to the colour. Merge it\n * into the MRT of your own scene pass: `scenePass.setMRT(mrt({ output, normal: normalView }).merge(treeMaskMRT()))`,\n * then read it with `scenePass.getTextureNode(TREE_MASK)`.\n */\nexport function treeMaskMRT(selection: readonly Object3D[] | null = null): MRTNode {\n const node = mrt({ [TREE_MASK]: createTreeMask(selection) });\n node.setClearColor(TREE_MASK, 0x000000, 0);\n return node;\n}\n\n/** What every Tree Effect reads: the scene colour and the tree mask (screen-space nodes). */\nexport interface TreeEffectInput {\n /** Scene colour (linear, before tone mapping), e.g. `scenePass.getTextureNode('output')`. */\n color: Node<'vec4'>;\n /** Tree mask texture (see {@link createTreeMask}), e.g. `scenePass.getTextureNode(TREE_MASK)`. */\n mask: TextureNode;\n}\n\n/** A scene pass that renders the colour and the tree mask, ready for the Tree Effects. */\nexport interface TreeEffectsPass extends TreeEffectInput {\n pass: PassNode;\n}\n\n/**\n * Creates `pass(scene, camera)` with MRT `{ output, treeMask }` and returns it with its colour and\n * mask texture nodes. `selection`: the trees to outline (default `null` = all trees), see\n * {@link createTreeMask}. If your pipeline already has a scene pass, merge {@link treeMaskMRT} into it instead.\n */\nexport function treeEffectsPass(scene: Scene, camera: Camera, selection: readonly Object3D[] | null = null): TreeEffectsPass {\n const scenePass = pass(scene, camera);\n scenePass.setMRT(mrt({ output }).merge(treeMaskMRT(selection)));\n scenePass.getTexture(TREE_MASK).type = UnsignedByteType;\n return { pass: scenePass, color: scenePass.getTextureNode('output'), mask: scenePass.getTextureNode(TREE_MASK) };\n}\n","import { Color, type ColorRepresentation, type Node } from 'three/webgpu';\nimport { color as tslColor, float, mix, textureSize, uv, vec2, vec4 } from 'three/tsl';\nimport type { TreeEffectInput } from './mask';\n\n/** Tree outline settings. */\nexport interface TreeOutlineOptions {\n /** Line colour (default a dark green-brown). */\n color?: ColorRepresentation;\n /** Line width in pixels (default 2). */\n thickness?: number;\n /** Opacity of the line, 0..1 (default 1). */\n strength?: number;\n}\n\n// Eight sample directions around a pixel (unit length).\nconst D = Math.SQRT1_2;\nconst DIRECTIONS: [number, number][] = [[1, 0], [-1, 0], [0, 1], [0, -1], [D, D], [D, -D], [-D, D], [-D, -D]];\n\n/**\n * Tree Effect: an outline along the silhouettes of the selected trees (the `selection` of the\n * tree mask, see `createTreeMask`; all trees by default), around the outside of the canopy and\n * the gaps in it. The line is drawn on the inside of the silhouette, so only tree pixels change.\n */\nexport function treeOutline(input: TreeEffectInput, options: TreeOutlineOptions = {}): Node<'vec4'> {\n const { color = '#1d2a14', thickness = 2, strength = 1 } = options;\n const { mask } = input;\n const step = vec2(thickness).div(vec2(textureSize(mask) as unknown as Node<'ivec2'>));\n const centre = uv();\n // Fraction of neighbours (at `thickness` px) that are not selected tree pixels.\n let outside: Node<'float'> = float(0);\n for (const [x, y] of DIRECTIONS) {\n outside = outside.add(float(1).sub(mask.sample(centre.add(step.mul(vec2(x, y)))).b));\n }\n const edge = outside.mul(3 / DIRECTIONS.length).clamp(0, 1).mul(mask.sample(centre).b).mul(strength);\n return vec4(mix(input.color.rgb, tslColor(new Color(color)), edge), input.color.a);\n}\n","import { Color, type ColorRepresentation, type Node } from 'three/webgpu';\nimport { color as tslColor, luminance, smoothstep, vec4 } from 'three/tsl';\nimport { gaussianBlur } from 'three/addons/tsl/display/GaussianBlurNode.js';\nimport type { TreeEffectInput } from './mask';\n\n/** Leaf glow settings. */\nexport interface LeafGlowOptions {\n /** Glow colour, multiplied with the blurred leaf colour (default white). */\n color?: ColorRepresentation;\n /** Glow strength (default 0.6). */\n intensity?: number;\n /** Only leaf pixels brighter than this (linear luminance) glow; 0 = all leaves (default 0.15). */\n threshold?: number;\n /** Blur radius (Gaussian sigma, in pixels at half resolution; default 6). */\n radius?: number;\n}\n\n/**\n * Tree Effect: a soft glow of the leaves. The bright (sunlit) leaf pixels are blurred and added\n * back onto the tree pixels (leaves and the wood between them), never onto the rest of the scene.\n */\nexport function leafGlow(input: TreeEffectInput, options: LeafGlowOptions = {}): Node<'vec4'> {\n const { color = '#ffffff', intensity = 0.6, threshold = 0.15, radius = 6 } = options;\n const bright = smoothstep(threshold, threshold * 2 + 0.05, luminance(input.color.rgb));\n const leaves = vec4(input.color.rgb.mul(input.mask.g).mul(bright), 1);\n const blurred = gaussianBlur(leaves, null, radius, { resolutionScale: 0.5 });\n const glow = blurred.rgb.mul(tslColor(new Color(color))).mul(intensity).mul(input.mask.r);\n return vec4(input.color.rgb.add(glow), input.color.a);\n}\n","import { Color, type ColorRepresentation, type Node } from 'three/webgpu';\nimport { color as tslColor, float, luminance, mix, select, vec3, vec4 } from 'three/tsl';\nimport type { TreeEffectInput } from './mask';\n\n/** Tree colour grading settings (all optional; the defaults change nothing). */\nexport interface TreeColorGradeOptions {\n /** Brightness multiplier (default 1). */\n exposure?: number;\n /** 0 = grey, 1 = unchanged (default), > 1 = more saturated. */\n saturation?: number;\n /** Contrast around mid grey: 1 = unchanged (default), > 1 = more contrast. */\n contrast?: number;\n /** Colour multiplied in, e.g. a warm '#fff2dd' (default white). */\n tint?: ColorRepresentation;\n}\n\nconst MID_GREY = 0.18; // linear\n\n/**\n * Tree Effect: colour grading (exposure, tint, saturation, contrast) of the tree pixels only.\n * Returns the graded colour where the tree mask is set and `input.color` unchanged elsewhere.\n */\nexport function treeColorGrade(input: TreeEffectInput, options: TreeColorGradeOptions = {}): Node<'vec4'> {\n const { exposure = 1, saturation = 1, contrast = 1, tint = '#ffffff' } = options;\n const tinted = input.color.rgb.mul(tslColor(new Color(tint))).mul(exposure);\n const saturated = mix(vec3(luminance(tinted)), tinted, saturation).max(0);\n const contrasted = saturated.div(MID_GREY).pow(vec3(float(contrast))).mul(MID_GREY);\n return select(input.mask.r.greaterThan(0.5), vec4(contrasted, input.color.a), input.color);\n}\n","import type { StyleName } from '../styles/registry';\nimport type { TreeColorGradeOptions } from './grade';\nimport type { LeafGlowOptions } from './glow';\nimport type { TreeOutlineOptions } from './outline';\n\n/** A combination of Tree Effects; leave an effect out to skip it. `{}` = no effects. */\nexport interface TreeEffectsSettings {\n grade?: TreeColorGradeOptions;\n glow?: LeafGlowOptions;\n outline?: TreeOutlineOptions;\n}\n\n/** The suggested combination of Tree Effects for each built-in Style. */\nexport const SUGGESTED_TREE_EFFECTS: Record<StyleName, TreeEffectsSettings> = {\n // Crisp facets: a dark ink line and slightly punchier colours.\n 'low-poly': {\n grade: { saturation: 1.15, contrast: 1.1 },\n outline: { color: '#18230f', thickness: 2, strength: 0.9 },\n },\n // Storybook look: soft glowing foliage, a warm tint and a soft coloured outline.\n stylized: {\n grade: { saturation: 0.95, contrast: 1.08, tint: '#fff1e0' },\n glow: { color: '#fff6c8', intensity: 0.45, threshold: 0.3, radius: 8 },\n outline: { color: '#2b3a1c', thickness: 2, strength: 0.6 },\n },\n // Natural: only a gentle grade (warmer, a touch more contrast) and a faint sunlit leaf glow.\n realistic: {\n grade: { exposure: 1.05, contrast: 1.08, saturation: 0.95, tint: '#fff5e6' },\n glow: { color: '#e8ffc0', intensity: 0.35, threshold: 0.12, radius: 4 },\n },\n};\n","import { RenderPipeline, type Camera, type Node, type Object3D, type Renderer, type Scene } from 'three/webgpu';\nimport type { StyleName } from '../styles/registry';\nimport { leafGlow } from './glow';\nimport { treeColorGrade } from './grade';\nimport { treeEffectsPass, type TreeEffectInput, type TreeEffectsPass } from './mask';\nimport { treeOutline } from './outline';\nimport { SUGGESTED_TREE_EFFECTS, type TreeEffectsSettings } from './suggested';\n\n/**\n * Applies a combination of Tree Effects to `input` and returns the resulting colour node, for use in\n * your own post-processing pipeline (`pipeline.outputNode = applyTreeEffects(...)`, or feed it into\n * more effects). Order: colour grade, leaf glow, outline. Empty settings return `input.color`.\n */\nexport function applyTreeEffects(input: TreeEffectInput, settings: TreeEffectsSettings): Node<'vec4'> {\n let color = input.color;\n if (settings.grade) color = treeColorGrade({ color, mask: input.mask }, settings.grade);\n if (settings.glow) color = leafGlow({ color, mask: input.mask }, settings.glow);\n if (settings.outline) color = treeOutline({ color, mask: input.mask }, settings.outline);\n return color;\n}\n\n/** The suggested combination of a built-in Style, or the settings themselves; `null` = no effects. */\nexport type TreeEffectsChoice = StyleName | TreeEffectsSettings | null;\n\nfunction resolveEffects(choice: TreeEffectsChoice): TreeEffectsSettings {\n if (choice === null) return {};\n if (typeof choice !== 'string') return choice;\n const settings = (SUGGESTED_TREE_EFFECTS as Record<string, TreeEffectsSettings | undefined>)[choice];\n if (!settings) throw new Error(`No suggested Tree Effects for Style \"${choice}\"`);\n return settings;\n}\n\nexport interface TreeEffectsOptions {\n /** Which effects: a Style name (its suggested combination), custom settings, or `null` (none). Default: none. */\n effects?: TreeEffectsChoice;\n /**\n * The trees to outline (Trees, Forests, groups of them; mutable, read on every draw).\n * Default: every tree in the scene.\n */\n selection?: Object3D[];\n}\n\n/**\n * A ready-made post-processing pipeline (`RenderPipeline`) with the Tree Effects: render with\n * `effects.render()` instead of `renderer.render(scene, camera)`. Switch the combination with\n * `effects.set('stylized')` (e.g. a preview). For your own pipeline, use {@link treeEffectsPass}\n * and {@link applyTreeEffects} instead.\n */\nexport class TreeEffects {\n readonly pipeline: RenderPipeline;\n /** The scene pass (colour + tree mask). */\n readonly scenePass: TreeEffectsPass;\n private nodes: Node[] = [];\n private current: TreeEffectsSettings = {};\n\n constructor(renderer: Renderer, scene: Scene, camera: Camera, options: TreeEffectsOptions = {}) {\n this.pipeline = new RenderPipeline(renderer);\n this.scenePass = treeEffectsPass(scene, camera, options.selection ?? null);\n this.set(options.effects ?? null);\n }\n\n /** The active combination (`{}` = none). */\n get settings(): TreeEffectsSettings {\n return this.current;\n }\n\n /** Switches to a Style's suggested combination, custom settings, or none (`null`). */\n set(effects: TreeEffectsChoice): void {\n this.current = resolveEffects(effects);\n this.disposeNodes();\n const output = applyTreeEffects(this.scenePass, this.current);\n this.nodes = collectEffectNodes(output, this.scenePass.color);\n this.pipeline.outputNode = output;\n this.pipeline.needsUpdate = true;\n }\n\n /** Renders the scene with the effects (call instead of `renderer.render(scene, camera)`). */\n render(): void {\n this.pipeline.render();\n }\n\n dispose(): void {\n this.disposeNodes();\n this.scenePass.pass.dispose();\n this.pipeline.dispose();\n }\n\n private disposeNodes(): void {\n for (const node of this.nodes) node.dispose();\n this.nodes = [];\n }\n}\n\n/** The render-target owning nodes (blur) in an effects graph, to dispose them on change. */\nfunction collectEffectNodes(output: Node, stop: Node): Node[] {\n const found = new Set<Node>();\n const visit = (node: Node, seen: Set<Node>): void => {\n if (seen.has(node) || node === stop) return;\n seen.add(node);\n const n = node as Node & { isGaussianBlurNode?: boolean };\n if (n.isGaussianBlurNode) found.add(node);\n for (const child of node.getChildren()) visit(child as Node, seen);\n };\n visit(output, new Set());\n return [...found];\n}\n\n/** Shorthand for `new TreeEffects(renderer, scene, camera, options)`. */\nexport function createTreeEffects(renderer: Renderer, scene: Scene, camera: Camera, options?: TreeEffectsOptions): TreeEffects {\n return new TreeEffects(renderer, scene, camera, options);\n}\n"],"mappings":";;;;;AAeA,IAAa,YAAY;;;;;AASzB,SAAgB,WAAW,UAAwD;CACjF,MAAM,OAAgB,UAAU,SAAS;CACzC,OAAO,SAAS,UAAU,SAAS,WAAW,OAAO;AACvD;AAEA,SAAS,WAAW,QAAyB,WAAyC;CACpF,KAAK,IAAI,IAAI,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,UAAU,SAAS,CAAC,GAAG,OAAO;CACxE,OAAO;AACT;;;;;;;;;;AA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rC,KAAK,IAAI,IAAI;EAEb,IAAIC,KAAE,oBAAoB,MAAM,IAAI,IAAI;EACxC,KAAK,MAAM,SAAS,KAAK,YAAY,GAAG,MAAM,OAAe,IAAI;CACnE;CACA,MAAM,wBAAQ,IAAI,IAAI,CAAC;CACvB,OAAO,CAAC,GAAG,KAAK;AAClB;;AAGA,SAAgB,kBAAkB,UAAoB,OAAc,QAAgB,SAA2C;CAC7H,OAAO,IAAI,YAAY,UAAU,OAAO,QAAQ,OAAO;AACzD"}
|
|
1
|
+
{"version":3,"file":"effects.js","names":["tslColor","color","tslColor","color","tslColor","n"],"sources":["../src/effects/mask.ts","../src/effects/outline.ts","../src/effects/glow.ts","../src/effects/grade.ts","../src/effects/suggested.ts","../src/effects/effects.ts"],"sourcesContent":["import {\n UnsignedByteType,\n Vector4,\n type Camera,\n type Material,\n type MRTNode,\n type Node,\n type Object3D,\n type PassNode,\n type Scene,\n type TextureNode,\n} from 'three/webgpu';\nimport { mrt, output, pass, uniform } from 'three/tsl';\n\n/** Name of the tree mask output in a pass's MRT (`scenePass.getTextureNode(TREE_MASK)`). */\nexport const TREE_MASK = 'treeMask';\n\n/** The part of a tree a material draws. */\nexport type TreePart = 'bark' | 'leaves' | 'fruit';\n\n/**\n * Which tree part a material draws: 'bark', 'leaves' or 'fruit' for tree.js materials (and their clones),\n * `null` for anything else. Tree Effects only change the pixels drawn by these materials.\n */\nexport function treePartOf(material: Material | null | undefined): TreePart | null {\n const part: unknown = material?.userData.treePart;\n return part === 'bark' || part === 'leaves' || part === 'fruit' ? part : null;\n}\n\nfunction isSelected(object: Object3D | null, selection: readonly Object3D[]): boolean {\n for (let o = object; o; o = o.parent) if (selection.includes(o)) return true;\n return false;\n}\n\n/**\n * TSL node: the tree mask value of the object being drawn, `vec4(tree, leaves, selected, 1)`:\n * r = 1 on tree pixels (bark, leaves and Fruit), g = 1 on leaf pixels, b = 1 on pixels of selected trees (the outline's\n * selection), 0 elsewhere. A per-object uniform decided from the drawn material\n * ({@link treePartOf}), so no tree material is changed and every other object writes 0.\n *\n * `selection`: the selected tree objects (Trees, Forests, any ancestor of tree meshes), read on\n * every draw, so it may be changed in place. `null` (default) selects every tree.\n */\nexport function createTreeMask(selection: readonly Object3D[] | null = null): Node<'vec4'> {\n return uniform(new Vector4(0, 0, 0, 1)).onObjectUpdate((frame, self) => {\n const part = treePartOf(frame.material);\n const selected = part !== null && (selection === null || isSelected(frame.object, selection));\n self.value.set(part ? 1 : 0, part === 'leaves' ? 1 : 0, selected ? 1 : 0, 1);\n return undefined;\n });\n}\n\n/**\n * The MRT output that renders the tree mask ({@link createTreeMask}) next to the colour. Merge it\n * into the MRT of your own scene pass: `scenePass.setMRT(mrt({ output, normal: normalView }).merge(treeMaskMRT()))`,\n * then read it with `scenePass.getTextureNode(TREE_MASK)`.\n */\nexport function treeMaskMRT(selection: readonly Object3D[] | null = null): MRTNode {\n const node = mrt({ [TREE_MASK]: createTreeMask(selection) });\n node.setClearColor(TREE_MASK, 0x000000, 0);\n return node;\n}\n\n/** What every Tree Effect reads: the scene colour and the tree mask (screen-space nodes). */\nexport interface TreeEffectInput {\n /** Scene colour (linear, before tone mapping), e.g. `scenePass.getTextureNode('output')`. */\n color: Node<'vec4'>;\n /** Tree mask texture (see {@link createTreeMask}), e.g. `scenePass.getTextureNode(TREE_MASK)`. */\n mask: TextureNode;\n}\n\n/** A scene pass that renders the colour and the tree mask, ready for the Tree Effects. */\nexport interface TreeEffectsPass extends TreeEffectInput {\n pass: PassNode;\n}\n\n/**\n * Creates `pass(scene, camera)` with MRT `{ output, treeMask }` and returns it with its colour and\n * mask texture nodes. `selection`: the trees to outline (default `null` = all trees), see\n * {@link createTreeMask}. If your pipeline already has a scene pass, merge {@link treeMaskMRT} into it instead.\n */\nexport function treeEffectsPass(scene: Scene, camera: Camera, selection: readonly Object3D[] | null = null): TreeEffectsPass {\n const scenePass = pass(scene, camera);\n scenePass.setMRT(mrt({ output }).merge(treeMaskMRT(selection)));\n scenePass.getTexture(TREE_MASK).type = UnsignedByteType;\n return { pass: scenePass, color: scenePass.getTextureNode('output'), mask: scenePass.getTextureNode(TREE_MASK) };\n}\n","import { Color, type ColorRepresentation, type Node } from 'three/webgpu';\nimport { color as tslColor, float, mix, textureSize, uv, vec2, vec4 } from 'three/tsl';\nimport type { TreeEffectInput } from './mask';\n\n/** Tree outline settings. */\nexport interface TreeOutlineOptions {\n /** Line colour (default a dark green-brown). */\n color?: ColorRepresentation;\n /** Line width in pixels (default 2). */\n thickness?: number;\n /** Opacity of the line, 0..1 (default 1). */\n strength?: number;\n}\n\n// Eight sample directions around a pixel (unit length).\nconst D = Math.SQRT1_2;\nconst DIRECTIONS: [number, number][] = [[1, 0], [-1, 0], [0, 1], [0, -1], [D, D], [D, -D], [-D, D], [-D, -D]];\n\n/**\n * Tree Effect: an outline along the silhouettes of the selected trees (the `selection` of the\n * tree mask, see `createTreeMask`; all trees by default), around the outside of the canopy and\n * the gaps in it. The line is drawn on the inside of the silhouette, so only tree pixels change.\n */\nexport function treeOutline(input: TreeEffectInput, options: TreeOutlineOptions = {}): Node<'vec4'> {\n const { color = '#1d2a14', thickness = 2, strength = 1 } = options;\n const { mask } = input;\n const step = vec2(thickness).div(vec2(textureSize(mask) as unknown as Node<'ivec2'>));\n const centre = uv();\n // Fraction of neighbours (at `thickness` px) that are not selected tree pixels.\n let outside: Node<'float'> = float(0);\n for (const [x, y] of DIRECTIONS) {\n outside = outside.add(float(1).sub(mask.sample(centre.add(step.mul(vec2(x, y)))).b));\n }\n const edge = outside.mul(3 / DIRECTIONS.length).clamp(0, 1).mul(mask.sample(centre).b).mul(strength);\n return vec4(mix(input.color.rgb, tslColor(new Color(color)), edge), input.color.a);\n}\n","import { Color, type ColorRepresentation, type Node } from 'three/webgpu';\nimport { color as tslColor, luminance, smoothstep, vec4 } from 'three/tsl';\nimport { gaussianBlur } from 'three/addons/tsl/display/GaussianBlurNode.js';\nimport type { TreeEffectInput } from './mask';\n\n/** Leaf glow settings. */\nexport interface LeafGlowOptions {\n /** Glow colour, multiplied with the blurred leaf colour (default white). */\n color?: ColorRepresentation;\n /** Glow strength (default 0.6). */\n intensity?: number;\n /** Only leaf pixels brighter than this (linear luminance) glow; 0 = all leaves (default 0.15). */\n threshold?: number;\n /** Blur radius (Gaussian sigma, in pixels at half resolution; default 6). */\n radius?: number;\n}\n\n/**\n * Tree Effect: a soft glow of the leaves. The bright (sunlit) leaf pixels are blurred and added\n * back onto the tree pixels (leaves and the wood between them), never onto the rest of the scene.\n */\nexport function leafGlow(input: TreeEffectInput, options: LeafGlowOptions = {}): Node<'vec4'> {\n const { color = '#ffffff', intensity = 0.6, threshold = 0.15, radius = 6 } = options;\n const bright = smoothstep(threshold, threshold * 2 + 0.05, luminance(input.color.rgb));\n const leaves = vec4(input.color.rgb.mul(input.mask.g).mul(bright), 1);\n const blurred = gaussianBlur(leaves, null, radius, { resolutionScale: 0.5 });\n const glow = blurred.rgb.mul(tslColor(new Color(color))).mul(intensity).mul(input.mask.r);\n return vec4(input.color.rgb.add(glow), input.color.a);\n}\n","import { Color, type ColorRepresentation, type Node } from 'three/webgpu';\nimport { color as tslColor, float, luminance, mix, select, vec3, vec4 } from 'three/tsl';\nimport type { TreeEffectInput } from './mask';\n\n/** Tree colour grading settings (all optional; the defaults change nothing). */\nexport interface TreeColorGradeOptions {\n /** Brightness multiplier (default 1). */\n exposure?: number;\n /** 0 = grey, 1 = unchanged (default), > 1 = more saturated. */\n saturation?: number;\n /** Contrast around mid grey: 1 = unchanged (default), > 1 = more contrast. */\n contrast?: number;\n /** Colour multiplied in, e.g. a warm '#fff2dd' (default white). */\n tint?: ColorRepresentation;\n}\n\nconst MID_GREY = 0.18; // linear\n\n/**\n * Tree Effect: colour grading (exposure, tint, saturation, contrast) of the tree pixels only.\n * Returns the graded colour where the tree mask is set and `input.color` unchanged elsewhere.\n */\nexport function treeColorGrade(input: TreeEffectInput, options: TreeColorGradeOptions = {}): Node<'vec4'> {\n const { exposure = 1, saturation = 1, contrast = 1, tint = '#ffffff' } = options;\n const tinted = input.color.rgb.mul(tslColor(new Color(tint))).mul(exposure);\n const saturated = mix(vec3(luminance(tinted)), tinted, saturation).max(0);\n const contrasted = saturated.div(MID_GREY).pow(vec3(float(contrast))).mul(MID_GREY);\n return select(input.mask.r.greaterThan(0.5), vec4(contrasted, input.color.a), input.color);\n}\n","import type { StyleName } from '../styles/registry';\nimport type { TreeColorGradeOptions } from './grade';\nimport type { LeafGlowOptions } from './glow';\nimport type { TreeOutlineOptions } from './outline';\n\n/** A combination of Tree Effects; leave an effect out to skip it. `{}` = no effects. */\nexport interface TreeEffectsSettings {\n grade?: TreeColorGradeOptions;\n glow?: LeafGlowOptions;\n outline?: TreeOutlineOptions;\n}\n\n/** The suggested combination of Tree Effects for each built-in Style. */\nexport const SUGGESTED_TREE_EFFECTS: Record<StyleName, TreeEffectsSettings> = {\n // Crisp facets: a dark ink line and slightly punchier colours.\n 'low-poly': {\n grade: { saturation: 1.15, contrast: 1.1 },\n outline: { color: '#18230f', thickness: 2, strength: 0.9 },\n },\n // Storybook look: soft glowing foliage, a warm tint and a soft coloured outline.\n stylized: {\n grade: { saturation: 0.95, contrast: 1.08, tint: '#fff1e0' },\n glow: { color: '#fff6c8', intensity: 0.45, threshold: 0.3, radius: 8 },\n outline: { color: '#2b3a1c', thickness: 2, strength: 0.6 },\n },\n // Natural: only a gentle grade (warmer, a touch more contrast) and a faint sunlit leaf glow.\n realistic: {\n grade: { exposure: 1.05, contrast: 1.08, saturation: 0.95, tint: '#fff5e6' },\n glow: { color: '#e8ffc0', intensity: 0.35, threshold: 0.12, radius: 4 },\n },\n};\n","import { RenderPipeline, type Camera, type Node, type Object3D, type Renderer, type Scene } from 'three/webgpu';\nimport type { StyleName } from '../styles/registry';\nimport { leafGlow } from './glow';\nimport { treeColorGrade } from './grade';\nimport { treeEffectsPass, type TreeEffectInput, type TreeEffectsPass } from './mask';\nimport { treeOutline } from './outline';\nimport { SUGGESTED_TREE_EFFECTS, type TreeEffectsSettings } from './suggested';\n\n/**\n * Applies a combination of Tree Effects to `input` and returns the resulting colour node, for use in\n * your own post-processing pipeline (`pipeline.outputNode = applyTreeEffects(...)`, or feed it into\n * more effects). Order: colour grade, leaf glow, outline. Empty settings return `input.color`.\n */\nexport function applyTreeEffects(input: TreeEffectInput, settings: TreeEffectsSettings): Node<'vec4'> {\n let color = input.color;\n if (settings.grade) color = treeColorGrade({ color, mask: input.mask }, settings.grade);\n if (settings.glow) color = leafGlow({ color, mask: input.mask }, settings.glow);\n if (settings.outline) color = treeOutline({ color, mask: input.mask }, settings.outline);\n return color;\n}\n\n/** The suggested combination of a built-in Style, or the settings themselves; `null` = no effects. */\nexport type TreeEffectsChoice = StyleName | TreeEffectsSettings | null;\n\nfunction resolveEffects(choice: TreeEffectsChoice): TreeEffectsSettings {\n if (choice === null) return {};\n if (typeof choice !== 'string') return choice;\n const settings = (SUGGESTED_TREE_EFFECTS as Record<string, TreeEffectsSettings | undefined>)[choice];\n if (!settings) throw new Error(`No suggested Tree Effects for Style \"${choice}\"`);\n return settings;\n}\n\nexport interface TreeEffectsOptions {\n /** Which effects: a Style name (its suggested combination), custom settings, or `null` (none). Default: none. */\n effects?: TreeEffectsChoice;\n /**\n * The trees to outline (Trees, Forests, groups of them; mutable, read on every draw).\n * Default: every tree in the scene.\n */\n selection?: Object3D[];\n}\n\n/**\n * A ready-made post-processing pipeline (`RenderPipeline`) with the Tree Effects: render with\n * `effects.render()` instead of `renderer.render(scene, camera)`. Switch the combination with\n * `effects.set('stylized')` (e.g. a preview). For your own pipeline, use {@link treeEffectsPass}\n * and {@link applyTreeEffects} instead.\n */\nexport class TreeEffects {\n readonly pipeline: RenderPipeline;\n /** The scene pass (colour + tree mask). */\n readonly scenePass: TreeEffectsPass;\n private nodes: Node[] = [];\n private current: TreeEffectsSettings = {};\n\n constructor(renderer: Renderer, scene: Scene, camera: Camera, options: TreeEffectsOptions = {}) {\n this.pipeline = new RenderPipeline(renderer);\n this.scenePass = treeEffectsPass(scene, camera, options.selection ?? null);\n this.set(options.effects ?? null);\n }\n\n /** The active combination (`{}` = none). */\n get settings(): TreeEffectsSettings {\n return this.current;\n }\n\n /** Switches to a Style's suggested combination, custom settings, or none (`null`). */\n set(effects: TreeEffectsChoice): void {\n this.current = resolveEffects(effects);\n this.disposeNodes();\n const output = applyTreeEffects(this.scenePass, this.current);\n this.nodes = collectEffectNodes(output, this.scenePass.color);\n this.pipeline.outputNode = output;\n this.pipeline.needsUpdate = true;\n }\n\n /** Renders the scene with the effects (call instead of `renderer.render(scene, camera)`). */\n render(): void {\n this.pipeline.render();\n }\n\n dispose(): void {\n this.disposeNodes();\n this.scenePass.pass.dispose();\n this.pipeline.dispose();\n }\n\n private disposeNodes(): void {\n for (const node of this.nodes) node.dispose();\n this.nodes = [];\n }\n}\n\n/** The render-target owning nodes (blur) in an effects graph, to dispose them on change. */\nfunction collectEffectNodes(output: Node, stop: Node): Node[] {\n const found = new Set<Node>();\n const visit = (node: Node, seen: Set<Node>): void => {\n if (seen.has(node) || node === stop) return;\n seen.add(node);\n const n = node as Node & { isGaussianBlurNode?: boolean };\n if (n.isGaussianBlurNode) found.add(node);\n for (const child of node.getChildren()) visit(child as Node, seen);\n };\n visit(output, new Set());\n return [...found];\n}\n\n/** Shorthand for `new TreeEffects(renderer, scene, camera, options)`. */\nexport function createTreeEffects(renderer: Renderer, scene: Scene, camera: Camera, options?: TreeEffectsOptions): TreeEffects {\n return new TreeEffects(renderer, scene, camera, options);\n}\n"],"mappings":";;;;;AAeA,IAAa,YAAY;;;;;AASzB,SAAgB,WAAW,UAAwD;CACjF,MAAM,OAAgB,UAAU,SAAS;CACzC,OAAO,SAAS,UAAU,SAAS,YAAY,SAAS,UAAU,OAAO;AAC3E;AAEA,SAAS,WAAW,QAAyB,WAAyC;CACpF,KAAK,IAAI,IAAI,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,UAAU,SAAS,CAAC,GAAG,OAAO;CACxE,OAAO;AACT;;;;;;;;;;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EACrC,KAAK,IAAI,IAAI;EAEb,IAAIC,KAAE,oBAAoB,MAAM,IAAI,IAAI;EACxC,KAAK,MAAM,SAAS,KAAK,YAAY,GAAG,MAAM,OAAe,IAAI;CACnE;CACA,MAAM,wBAAQ,IAAI,IAAI,CAAC;CACvB,OAAO,CAAC,GAAG,KAAK;AAClB;;AAGA,SAAgB,kBAAkB,UAAoB,OAAc,QAAgB,SAA2C;CAC7H,OAAO,IAAI,YAAY,UAAU,OAAO,QAAQ,OAAO;AACzD"}
|
package/dist/forest/Forest.d.ts
CHANGED
|
@@ -57,7 +57,8 @@ export declare class ForestTree implements ForestTreeTraits {
|
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* One Variant of a Forest: one Seed's tree, drawn once per tree that uses it with an instanced
|
|
60
|
-
* wood mesh
|
|
60
|
+
* wood mesh, an instanced leaf mesh and, when the Definition has Fruit, an instanced fruit mesh
|
|
61
|
+
* (one draw call per material). All three share one instance matrix buffer.
|
|
61
62
|
*/
|
|
62
63
|
export declare class ForestVariant {
|
|
63
64
|
private readonly forest;
|
|
@@ -68,18 +69,26 @@ export declare class ForestVariant {
|
|
|
68
69
|
readonly windResponse: WindResponse;
|
|
69
70
|
readonly barkMaterial: MeshStandardNodeMaterial;
|
|
70
71
|
readonly leafMaterial: MeshStandardNodeMaterial;
|
|
72
|
+
/** Fruit material, null when the Definition has no Fruit. */
|
|
73
|
+
readonly fruitMaterial: MeshStandardNodeMaterial | null;
|
|
71
74
|
/** The trees drawn as this Variant, in instance order. */
|
|
72
75
|
readonly trees: ForestTree[];
|
|
73
76
|
private woodMesh;
|
|
74
77
|
private leafMesh;
|
|
78
|
+
private fruitMesh;
|
|
75
79
|
private instanceData;
|
|
76
80
|
private readonly woodSource;
|
|
77
81
|
private readonly leafSource;
|
|
82
|
+
private readonly fruitSource;
|
|
78
83
|
constructor(forest: Forest, definition: TreeDefinition, index: number, seed: number, wind: WindSource, capacity: number, textures?: TextureOptions);
|
|
79
84
|
/** Instanced mesh of trunks and branches. Replaced (not resized) when the Variant outgrows its capacity. */
|
|
80
85
|
get wood(): InstancedMesh<BufferGeometry, MeshStandardNodeMaterial>;
|
|
81
86
|
/** Instanced mesh of the leaves. Replaced along with {@link wood}. */
|
|
82
87
|
get leaves(): InstancedMesh<BufferGeometry, MeshStandardNodeMaterial>;
|
|
88
|
+
/** Instanced mesh of the Fruit (null when the Definition has no Fruit). Replaced along with {@link wood}. */
|
|
89
|
+
get fruit(): InstancedMesh<BufferGeometry, MeshStandardNodeMaterial> | null;
|
|
90
|
+
/** The Variant's meshes: wood, leaves and (with Fruit) fruit. */
|
|
91
|
+
get meshes(): InstancedMesh<BufferGeometry, MeshStandardNodeMaterial>[];
|
|
83
92
|
get capacity(): number;
|
|
84
93
|
/** @internal */
|
|
85
94
|
add(tree: ForestTree): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Forest.d.ts","sourceRoot":"","sources":["../../src/forest/Forest.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAGd,KAAK,EAGL,aAAa,EAMb,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Forest.d.ts","sourceRoot":"","sources":["../../src/forest/Forest.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAGd,KAAK,EAGL,aAAa,EAMb,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAmD,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAM9F,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAa,IAAI,EAAe,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtF,OAAO,EAOL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AAErB,uCAAuC;AACvC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AAI,IAAI,IAAI,IAAI,CAEf;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,EAEnB;IAED,gDAAgD;IAChD,IAAI,KAAK,IAAI,SAAS,UAAU,EAAE,CAEjC;IAED,uBAAuB;IACvB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,wEAAwE;IACxE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS;IAIjD;;;OAGG;IACH,OAAO,CAAC,SAAS,EAAE,eAAe,GAAG,UAAU;IAuB/C,8GAA8G;IAC9G,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;IAQvD,mGAAmG;IACnG,MAAM,CAAC,YAAY,EAAE;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,GAAG,SAAS;IAKtF,mGAAmG;IACnG,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,mBAAmB;IAMtE,yGAAyG;IACzG,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAGvB;IAED,yGAAyG;IACzG,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAGvB;IAED,gHAAgH;IACvG,OAAO,IAAI,IAAI;CAMzB"}
|
package/dist/forest/nodes.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ export declare function instanceState(): {
|
|
|
26
26
|
* `positionGeometry`, and only their displacement is turned into forest space with the
|
|
27
27
|
* instance rotation and scale: M·(p + d) = M·p + R·s·d. The Wind direction goes the other way
|
|
28
28
|
* (forest -> tree space) and each tree sways with its own phase.
|
|
29
|
+
*
|
|
30
|
+
* `base`: the tree-space position Growth starts from (default `positionGeometry`); Fruit passes
|
|
31
|
+
* its Season-scaled position here.
|
|
29
32
|
*/
|
|
30
|
-
export declare function forestPosition(wind: WindSource, response: WindResponse): Node<'vec3'>;
|
|
33
|
+
export declare function forestPosition(wind: WindSource, response: WindResponse, base?: Node<'vec3'>): Node<'vec3'>;
|
|
31
34
|
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/forest/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAmC,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE9F;;;;GAIG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,mBAAmB;;;CAAuC,CAAC;AAExE,iEAAiE;AACjE,wBAAgB,aAAa,IAAI;IAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;CAAE,CAGhI;AAUD
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/forest/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAmC,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE9F;;;;GAIG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,mBAAmB;;;CAAuC,CAAC;AAExE,iEAAiE;AACjE,wBAAgB,aAAa,IAAI;IAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC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