@casmo/tree.js 0.3.0 → 0.5.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 +775 -4
- package/dist/effects/custom.d.ts +62 -0
- package/dist/effects/custom.d.ts.map +1 -0
- package/dist/effects/effects.d.ts +92 -6
- package/dist/effects/effects.d.ts.map +1 -1
- package/dist/effects/glow.d.ts +5 -0
- package/dist/effects/glow.d.ts.map +1 -1
- package/dist/effects/grade.d.ts +3 -0
- package/dist/effects/grade.d.ts.map +1 -1
- package/dist/effects/highlight.d.ts +35 -0
- package/dist/effects/highlight.d.ts.map +1 -0
- package/dist/effects/index.d.ts +7 -1
- package/dist/effects/index.d.ts.map +1 -1
- package/dist/effects/inner-lines.d.ts +39 -0
- package/dist/effects/inner-lines.d.ts.map +1 -0
- package/dist/effects/live.d.ts +12 -0
- package/dist/effects/live.d.ts.map +1 -0
- package/dist/effects/mask.d.ts +32 -12
- package/dist/effects/mask.d.ts.map +1 -1
- package/dist/effects/outline.d.ts +12 -0
- package/dist/effects/outline.d.ts.map +1 -1
- package/dist/effects/pass.d.ts +27 -0
- package/dist/effects/pass.d.ts.map +1 -0
- package/dist/effects/screen.d.ts +31 -0
- package/dist/effects/screen.d.ts.map +1 -0
- package/dist/effects/suggested.d.ts +5 -0
- package/dist/effects/suggested.d.ts.map +1 -1
- package/dist/effects/tree-id.d.ts +50 -0
- package/dist/effects/tree-id.d.ts.map +1 -0
- package/dist/effects-qHx_8Dlk.js +1052 -0
- package/dist/effects-qHx_8Dlk.js.map +1 -0
- package/dist/effects.js +3 -249
- package/dist/forest/Forest.d.ts +82 -4
- package/dist/forest/Forest.d.ts.map +1 -1
- package/dist/forest/forest-lod.d.ts +70 -0
- package/dist/forest/forest-lod.d.ts.map +1 -0
- package/dist/forest/impostor-material.d.ts +106 -0
- package/dist/forest/impostor-material.d.ts.map +1 -0
- package/dist/forest/impostor-season.d.ts +13 -0
- package/dist/forest/impostor-season.d.ts.map +1 -0
- package/dist/forest/impostor.d.ts +105 -0
- package/dist/forest/impostor.d.ts.map +1 -0
- package/dist/forest/index.d.ts +1 -0
- package/dist/forest/index.d.ts.map +1 -1
- package/dist/forest/levels.d.ts +144 -0
- package/dist/forest/levels.d.ts.map +1 -0
- package/dist/forest/lod.d.ts +106 -0
- package/dist/forest/lod.d.ts.map +1 -0
- package/dist/forest/nodes.d.ts +42 -1
- package/dist/forest/nodes.d.ts.map +1 -1
- package/dist/forest/octahedral.d.ts +33 -0
- package/dist/forest/octahedral.d.ts.map +1 -0
- package/dist/{forest-ChEaWJrf.js → forest-CM5DrklM.js} +1727 -340
- package/dist/forest-CM5DrklM.js.map +1 -0
- package/dist/generator/fruit.d.ts +2 -0
- package/dist/generator/fruit.d.ts.map +1 -1
- package/dist/generator/index.d.ts +1 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/light.d.ts +36 -0
- package/dist/generator/light.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/materials/crown-nodes.d.ts +5 -0
- package/dist/materials/crown-nodes.d.ts.map +1 -1
- package/dist/materials/leaf-translucency-model.d.ts +6 -1
- package/dist/materials/leaf-translucency-model.d.ts.map +1 -1
- package/dist/materials/material-features.d.ts +12 -0
- package/dist/materials/material-features.d.ts.map +1 -1
- package/dist/materials/shader-hooks.d.ts +155 -0
- package/dist/materials/shader-hooks.d.ts.map +1 -0
- package/dist/motion-Qd7xjeZM.js +276 -0
- package/dist/motion-Qd7xjeZM.js.map +1 -0
- package/dist/nodes-DxgTyF9B.js +436 -0
- package/dist/nodes-DxgTyF9B.js.map +1 -0
- package/dist/react/Forest.d.ts +17 -3
- package/dist/react/Forest.d.ts.map +1 -1
- package/dist/react/ScenePipeline.d.ts +63 -0
- package/dist/react/ScenePipeline.d.ts.map +1 -0
- package/dist/react/SceneShaderHooks.d.ts +25 -0
- package/dist/react/SceneShaderHooks.d.ts.map +1 -0
- package/dist/react/Tree.d.ts +9 -2
- package/dist/react/Tree.d.ts.map +1 -1
- package/dist/react/Weather.d.ts +45 -0
- package/dist/react/Weather.d.ts.map +1 -0
- package/dist/react/Wind.d.ts +12 -1
- package/dist/react/Wind.d.ts.map +1 -1
- package/dist/react/index.d.ts +7 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react.js +347 -10
- package/dist/react.js.map +1 -1
- package/dist/renderer/index.d.ts +6 -0
- package/dist/renderer/index.d.ts.map +1 -1
- package/dist/scene/antialias.d.ts +35 -0
- package/dist/scene/antialias.d.ts.map +1 -0
- package/dist/scene/ao.d.ts +46 -0
- package/dist/scene/ao.d.ts.map +1 -0
- package/dist/scene/bloom.d.ts +19 -0
- package/dist/scene/bloom.d.ts.map +1 -0
- package/dist/scene/fog.d.ts +49 -0
- package/dist/scene/fog.d.ts.map +1 -0
- package/dist/scene/godrays.d.ts +37 -0
- package/dist/scene/godrays.d.ts.map +1 -0
- package/dist/scene/index.d.ts +14 -0
- package/dist/scene/index.d.ts.map +1 -0
- package/dist/scene/motion-blur.d.ts +23 -0
- package/dist/scene/motion-blur.d.ts.map +1 -0
- package/dist/scene/pipeline.d.ts +109 -0
- package/dist/scene/pipeline.d.ts.map +1 -0
- package/dist/scene/settings.d.ts +36 -0
- package/dist/scene/settings.d.ts.map +1 -0
- package/dist/scene/stack.d.ts +25 -0
- package/dist/scene/stack.d.ts.map +1 -0
- package/dist/scene/stage.d.ts +52 -0
- package/dist/scene/stage.d.ts.map +1 -0
- package/dist/scene/suggested.d.ts +12 -0
- package/dist/scene/suggested.d.ts.map +1 -0
- package/dist/scene/tone-mapping.d.ts +20 -0
- package/dist/scene/tone-mapping.d.ts.map +1 -0
- package/dist/scene/velocity.d.ts +34 -0
- package/dist/scene/velocity.d.ts.map +1 -0
- package/dist/scene.js +889 -0
- package/dist/scene.js.map +1 -0
- package/dist/season/nodes.d.ts +13 -0
- package/dist/season/nodes.d.ts.map +1 -1
- package/dist/shader-hooks-BFRtlWGI.js +275 -0
- package/dist/shader-hooks-BFRtlWGI.js.map +1 -0
- package/dist/tree/Tree.d.ts +8 -3
- package/dist/tree/Tree.d.ts.map +1 -1
- package/dist/tree/index.d.ts.map +1 -1
- package/dist/weather/index.d.ts +3 -0
- package/dist/weather/index.d.ts.map +1 -0
- package/dist/weather/shared.d.ts +43 -0
- package/dist/weather/shared.d.ts.map +1 -0
- package/dist/weather/snow.d.ts +87 -0
- package/dist/weather/snow.d.ts.map +1 -0
- package/dist/weather/wetness.d.ts +75 -0
- package/dist/weather/wetness.d.ts.map +1 -0
- package/dist/weather.js +288 -0
- package/dist/weather.js.map +1 -0
- package/dist/wind/Wind.d.ts +100 -5
- package/dist/wind/Wind.d.ts.map +1 -1
- package/dist/wind/burst.d.ts +28 -0
- package/dist/wind/burst.d.ts.map +1 -0
- package/dist/wind/index.d.ts +3 -2
- package/dist/wind/index.d.ts.map +1 -1
- package/dist/wind/motion.d.ts +30 -0
- package/dist/wind/motion.d.ts.map +1 -0
- package/dist/wind/node.d.ts +17 -3
- package/dist/wind/node.d.ts.map +1 -1
- package/package.json +9 -1
- package/dist/effects.js.map +0 -1
- package/dist/forest-ChEaWJrf.js.map +0 -1
package/dist/wind/Wind.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector3, type UniformNode } from 'three/webgpu';
|
|
1
|
+
import { Vector3, type UniformArrayNode, type UniformNode } from 'three/webgpu';
|
|
2
2
|
export type WindDirection = Vector3 | readonly [number, number, number];
|
|
3
3
|
export interface WindOptions {
|
|
4
4
|
/** World-space direction the wind blows towards (any length > 0; stored as a unit vector). Default +X. */
|
|
@@ -6,6 +6,53 @@ export interface WindOptions {
|
|
|
6
6
|
/** 0 = calm (default), 1 = strong wind; larger values are allowed for storms. */
|
|
7
7
|
strength?: number;
|
|
8
8
|
}
|
|
9
|
+
/** A {@link Wind.burst}: where on the ground, how hard and how far. */
|
|
10
|
+
export interface WindBurstOptions {
|
|
11
|
+
/** World-space ground point (x, z) the air pushes away from. */
|
|
12
|
+
x: number;
|
|
13
|
+
z: number;
|
|
14
|
+
/**
|
|
15
|
+
* How hard it pushes (default 1). Weaker values push less; a negative value is the reduced-motion
|
|
16
|
+
* burst: trees in reach lean away at once (no travelling front, no swing back) and settle, with
|
|
17
|
+
* the size of the value as strength.
|
|
18
|
+
*/
|
|
19
|
+
strength?: number;
|
|
20
|
+
/** Metres it reaches (> 0). Default {@link WIND_BURST_REACH} per unit of strength. */
|
|
21
|
+
radius?: number;
|
|
22
|
+
}
|
|
23
|
+
/** A running Wind Burst, as {@link Wind.bursts} lists it. */
|
|
24
|
+
export interface WindBurst {
|
|
25
|
+
readonly x: number;
|
|
26
|
+
readonly z: number;
|
|
27
|
+
readonly strength: number;
|
|
28
|
+
readonly radius: number;
|
|
29
|
+
/** The Wind time (seconds) it started at. */
|
|
30
|
+
readonly start: number;
|
|
31
|
+
}
|
|
32
|
+
/** Seconds a Wind Burst lasts. */
|
|
33
|
+
export declare const WIND_BURST_LIFETIME = 1.2;
|
|
34
|
+
/** Most Wind Bursts one Wind runs at once; a new one beyond it replaces the oldest. */
|
|
35
|
+
export declare const MAX_WIND_BURSTS = 8;
|
|
36
|
+
/** Metres a Wind Burst reaches per unit of strength, unless given a `radius`. */
|
|
37
|
+
export declare const WIND_BURST_REACH = 8;
|
|
38
|
+
/** Something that switches Wind Bursts on once they are used (see {@link WindBurstsUsed}). */
|
|
39
|
+
export interface BurstListener {
|
|
40
|
+
burstsUsed(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether a Wind (or a {@link WindBinding}) has ever had a Wind Burst. Tree materials only get burst
|
|
44
|
+
* nodes once it has: until then they are exactly as without Wind Bursts. Listeners are held weakly and
|
|
45
|
+
* told once.
|
|
46
|
+
*/
|
|
47
|
+
export declare class WindBurstsUsed {
|
|
48
|
+
private used;
|
|
49
|
+
private listeners;
|
|
50
|
+
get triggered(): boolean;
|
|
51
|
+
/** Tells `listener` (at once if already triggered) when the first burst comes. */
|
|
52
|
+
listen(listener: BurstListener): void;
|
|
53
|
+
/** Marks bursts as used and tells every listener (only the first time). */
|
|
54
|
+
trigger(): void;
|
|
55
|
+
}
|
|
9
56
|
/**
|
|
10
57
|
* Scene-wide Wind: a direction and a strength that every tree listening to it sways with.
|
|
11
58
|
* Changing them only writes uniform values (no recompile). Trees use {@link sceneWind} unless
|
|
@@ -19,8 +66,14 @@ export declare class Wind {
|
|
|
19
66
|
readonly strength: UniformNode<'float', number>;
|
|
20
67
|
/** Seconds; follows the renderer clock unless {@link Wind.time} pins it. */
|
|
21
68
|
readonly time: UniformNode<'float', number>;
|
|
69
|
+
/** Wind Bursts (see {@link WindBurstUniforms}). */
|
|
70
|
+
readonly bursts: WindBurstUniforms;
|
|
22
71
|
};
|
|
23
72
|
private pinnedTime;
|
|
73
|
+
/** The renderer clock as last seen by a render (the Wind time when not pinned). */
|
|
74
|
+
private clock;
|
|
75
|
+
/** Running and recently ended bursts, oldest first (at most {@link MAX_WIND_BURSTS}). */
|
|
76
|
+
private started;
|
|
24
77
|
constructor(options?: WindOptions);
|
|
25
78
|
/** Unit direction the wind blows towards (a copy: assign a new value to change it). */
|
|
26
79
|
get direction(): Vector3;
|
|
@@ -33,6 +86,29 @@ export declare class Wind {
|
|
|
33
86
|
*/
|
|
34
87
|
get time(): number | null;
|
|
35
88
|
set time(value: number | null);
|
|
89
|
+
/**
|
|
90
|
+
* Starts a Wind Burst: a short push of air from a ground point that bends the trees within its
|
|
91
|
+
* radius away from it and fades out within {@link WIND_BURST_LIFETIME} seconds of Wind time, on top
|
|
92
|
+
* of the Wind. At most {@link MAX_WIND_BURSTS} run at once; another one replaces the oldest. Only
|
|
93
|
+
* uniform writes, except that the first burst on a Wind rebuilds the node graphs of the trees swaying
|
|
94
|
+
* with it once (never their geometry): until then their materials have no burst nodes at all. Returns this.
|
|
95
|
+
*/
|
|
96
|
+
burst({ x, z, strength, radius }: WindBurstOptions): this;
|
|
97
|
+
/**
|
|
98
|
+
* @internal The bursts the shader loops over (oldest first, at most {@link MAX_WIND_BURSTS}): the
|
|
99
|
+
* started ones while any of them runs, else none. They only change in {@link Wind.burst}; the
|
|
100
|
+
* shader leaves out those that have not started or have ended.
|
|
101
|
+
*/
|
|
102
|
+
get drawnBursts(): readonly WindBurst[];
|
|
103
|
+
/** The Wind Bursts running at the current Wind time, oldest first. */
|
|
104
|
+
get bursts(): WindBurst[];
|
|
105
|
+
/**
|
|
106
|
+
* @internal The Wind time of a render at renderer time `frameTime` (called once per render by
|
|
107
|
+
* the Wind's own and its bindings' time uniforms): the pinned time, or that clock, which it keeps.
|
|
108
|
+
*/
|
|
109
|
+
timeAt(frameTime: number): number;
|
|
110
|
+
/** The current Wind time: the pinned time, or the renderer clock as of the last render. */
|
|
111
|
+
private get now();
|
|
36
112
|
/** Sets direction and/or strength; returns this. */
|
|
37
113
|
set(options: WindOptions): this;
|
|
38
114
|
}
|
|
@@ -43,12 +119,31 @@ export type WindUniforms = Wind['uniforms'];
|
|
|
43
119
|
/**
|
|
44
120
|
* Per-object Wind uniforms that follow whichever Wind is bound to them, read once per render.
|
|
45
121
|
* 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
|
|
122
|
+
* assignment: no new nodes, no recompile, no regeneration (only the first time the binding follows a
|
|
123
|
+
* Wind that has had a Wind Burst do the materials built on it add burst nodes, one rebuild).
|
|
47
124
|
*/
|
|
48
|
-
export declare class WindBinding {
|
|
49
|
-
/** The bound Wind. */
|
|
50
|
-
wind: Wind;
|
|
125
|
+
export declare class WindBinding implements BurstListener {
|
|
51
126
|
readonly uniforms: WindUniforms;
|
|
127
|
+
private bound;
|
|
52
128
|
constructor(wind: Wind);
|
|
129
|
+
/** The bound Wind. Binding one that has had a Wind Burst switches bursts on (see {@link WindBurstsUsed}). */
|
|
130
|
+
get wind(): Wind;
|
|
131
|
+
set wind(value: Wind);
|
|
132
|
+
/** @internal A Wind this binding listened to had its first burst: switch bursts on if it is still the bound one. */
|
|
133
|
+
burstsUsed(): void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The Wind Burst uniforms tree materials read: a fixed-size array of {@link MAX_WIND_BURSTS} slots,
|
|
137
|
+
* and how many of them to loop over (0 when no burst runs, so the loop costs nothing). Tree materials
|
|
138
|
+
* only read them once a burst has been triggered (`used`).
|
|
139
|
+
*/
|
|
140
|
+
export interface WindBurstUniforms {
|
|
141
|
+
/** Per slot: x, z (world-space ground point), start (Wind time), strength. */
|
|
142
|
+
readonly points: UniformArrayNode<'vec4'>;
|
|
143
|
+
/** Per slot: the radius in metres. */
|
|
144
|
+
readonly radii: UniformArrayNode<'float'>;
|
|
145
|
+
readonly count: UniformNode<'int', number>;
|
|
146
|
+
/** Whether any burst has been triggered (then materials add burst nodes; see {@link WindBurstsUsed}). */
|
|
147
|
+
readonly used: WindBurstsUsed;
|
|
53
148
|
}
|
|
54
149
|
//# sourceMappingURL=Wind.d.ts.map
|
package/dist/wind/Wind.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"Wind.d.ts","sourceRoot":"","sources":["../../src/wind/Wind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAW,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAGzF,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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Y,CAAC;IAChC,OAAO,CAAC,KAAK,CAAO;gBAER,IAAI,EAAE,IAAI;IAYtB,6GAA6G;IAC7G,IAAI,IAAI,IAAI,IAAI,CAEf;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,EAGnB;IAED,oHAAoH;IACpH,UAAU,IAAI,IAAI;CAGnB;AAGD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC1C,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3C,yGAAyG;IACzG,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Node } from 'three/webgpu';
|
|
2
|
+
import type { WindSource } from './node';
|
|
3
|
+
/**
|
|
4
|
+
* TSL node: the push of the Wind Bursts of `wind` at a world-space ground point `xz` (vec2: world
|
|
5
|
+
* x, z), summed over the running bursts: away from each burst point, about 0..0.75 × strength at
|
|
6
|
+
* its peak, 0 beyond the burst's radius and once it has ended. `time` is the Wind time to evaluate
|
|
7
|
+
* it at (default the Wind's clock), e.g. the previous frame's for Wind-aware velocity. With no
|
|
8
|
+
* burst running the loop runs zero times and the push is exactly 0.
|
|
9
|
+
*/
|
|
10
|
+
export declare function windBurstPush(wind: WindSource, xz: Node<'vec2'>, time?: Node<'float'>): Node<'vec2'>;
|
|
11
|
+
/**
|
|
12
|
+
* Where a Wind Burst finds a tree and how its push turns into the tree's space: a Tree is the
|
|
13
|
+
* rendered object ({@link objectBurstFrame}); a tree drawn as an instance passes its own.
|
|
14
|
+
*/
|
|
15
|
+
export interface WindBurstFrame {
|
|
16
|
+
/** The tree's world-space ground point (vec2: world x, z). */
|
|
17
|
+
origin: Node<'vec2'>;
|
|
18
|
+
/** Turns a world-space vector into the tree's space: rotation only, its length kept. */
|
|
19
|
+
toTree(world: Node<'vec3'>): Node<'vec3'>;
|
|
20
|
+
}
|
|
21
|
+
/** The {@link WindBurstFrame} of a tree that is one object: its world origin and rotation. */
|
|
22
|
+
export declare function objectBurstFrame(): WindBurstFrame;
|
|
23
|
+
/**
|
|
24
|
+
* TSL node: the Wind displacement `still`, plus Wind Bursts once `source`'s Wind has had one: then
|
|
25
|
+
* `withBursts()` (built at that moment, once). See {@link WindBurstSwitchNode}.
|
|
26
|
+
*/
|
|
27
|
+
export declare function withWindBursts(source: WindSource, still: Node<'vec3'>, withBursts: () => Node<'vec3'>): Node<'vec3'>;
|
|
28
|
+
//# sourceMappingURL=burst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"burst.d.ts","sourceRoot":"","sources":["../../src/wind/burst.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA0D,MAAM,cAAc,CAAC;AAG5F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAgBzC;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,GAAE,IAAI,CAAC,OAAO,CAAsB,GAAG,IAAI,CAAC,MAAM,CAAC,CAIxH;AAwBD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,8DAA8D;IAC9D,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,wFAAwF;IACxF,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED,8FAA8F;AAC9F,wBAAgB,gBAAgB,IAAI,cAAc,CASjD;AAgDD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAEpH"}
|
package/dist/wind/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Wind, WindBinding, sceneWind, type WindDirection, type WindOptions, type WindUniforms } from './Wind';
|
|
1
|
+
export { Wind, WindBinding, sceneWind, MAX_WIND_BURSTS, WIND_BURST_LIFETIME, WIND_BURST_REACH, type WindBurst, type WindBurstOptions, type WindBurstUniforms, type WindDirection, type WindOptions, type WindUniforms, } from './Wind';
|
|
2
|
+
export { windBurstPush, objectBurstFrame, type WindBurstFrame } from './burst';
|
|
2
3
|
export { WindResponse } from './response';
|
|
3
|
-
export { windOffset, applyWind, objectWindDirection, type WindFrame, type WindSource } from './node';
|
|
4
|
+
export { windOffset, treeSwayOffset, applyWind, objectWindDirection, type WindFrame, type WindSource } from './node';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/wind/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wind/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wind/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,WAAW,EACX,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Node } from 'three/webgpu';
|
|
2
|
+
import type { WindSource } from './node';
|
|
3
|
+
/**
|
|
4
|
+
* How a tree material's vertices move with the Wind between two Wind times, for Wind-aware velocity
|
|
5
|
+
* (ADR 0011). Registered by Trees and Forests next to their materials' `positionNode`; read only by
|
|
6
|
+
* a scene pass that asks for a velocity channel (`windVelocityMRT` in `@casmo/tree.js/scene`). The
|
|
7
|
+
* materials themselves are never changed for it.
|
|
8
|
+
*/
|
|
9
|
+
export interface WindMotion {
|
|
10
|
+
/** The Wind (or binding) the material sways with: its clock gives the current Wind time. */
|
|
11
|
+
readonly source: WindSource;
|
|
12
|
+
/**
|
|
13
|
+
* TSL node: where each vertex was at Wind time `previous` relative to where it is now, in the
|
|
14
|
+
* space `positionNode` outputs (the shader's `positionLocal`). Only Wind: Growth and Season are
|
|
15
|
+
* the current ones (they are not motion).
|
|
16
|
+
*/
|
|
17
|
+
shift(previous: Node<'float'>): Node<'vec3'>;
|
|
18
|
+
/**
|
|
19
|
+
* TSL node: the current Wind displacement of each vertex, in the space `positionNode` outputs (only
|
|
20
|
+
* attributes and uniforms). Tree Shader Hooks turn the smooth normal with it (the swayed normal).
|
|
21
|
+
*/
|
|
22
|
+
readonly offset?: Node<'vec3'>;
|
|
23
|
+
}
|
|
24
|
+
/** Registers the Wind motion of the materials drawn with `positionNode`. */
|
|
25
|
+
export declare function setWindMotion(positionNode: Node, motion: WindMotion): void;
|
|
26
|
+
/** The Wind motion of a material's `positionNode`, if it is a tree.js tree position. */
|
|
27
|
+
export declare function windMotionOf(positionNode: Node | null | undefined): WindMotion | undefined;
|
|
28
|
+
/** The Wind time (seconds) a source shows at renderer time `frameTime`: its pinned time, or the clock. */
|
|
29
|
+
export declare function windTimeOf(source: WindSource, frameTime: number): number;
|
|
30
|
+
//# sourceMappingURL=motion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../src/wind/motion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,4FAA4F;IAC5F,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7C;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CAChC;AAQD,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAE1E;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,YAAY,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAE1F;AAED,0GAA0G;AAC1G,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAGxE"}
|
package/dist/wind/node.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { Node, NodeMaterial } from 'three/webgpu';
|
|
2
2
|
import type { WindUniforms } from './Wind';
|
|
3
3
|
import type { WindResponse } from './response';
|
|
4
|
+
import { type WindBurstFrame } from './burst';
|
|
4
5
|
/**
|
|
5
6
|
* 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
|
+
* the tree's own space and the tree's phase (radians), e.g. from per-instance attributes; and the
|
|
8
|
+
* Wind time (seconds) to evaluate the sway at (default the Wind's own clock), e.g. the previous
|
|
9
|
+
* frame's for Wind-aware velocity. `burst`: where the tree stands for Wind Bursts (default the
|
|
10
|
+
* rendered object), or `false` for a tree that does not take Wind Bursts. Burst nodes are only added
|
|
11
|
+
* once the Wind has had a burst (one node-graph rebuild then; see `Wind.burst`).
|
|
7
12
|
*/
|
|
8
13
|
export interface WindFrame {
|
|
9
14
|
direction?: Node<'vec3'>;
|
|
10
15
|
phase?: Node<'float'>;
|
|
16
|
+
time?: Node<'float'>;
|
|
17
|
+
burst?: WindBurstFrame | false;
|
|
11
18
|
}
|
|
12
19
|
/** Anything holding Wind uniforms: a {@link Wind} or a {@link WindBinding} that follows one. */
|
|
13
20
|
export interface WindSource {
|
|
@@ -25,11 +32,18 @@ export declare function objectWindDirection(wind: WindSource): Node<'vec3'>;
|
|
|
25
32
|
* - branches: swing faster, with a phase that varies smoothly in space so joints stay attached,
|
|
26
33
|
* plus a little cross-wind motion;
|
|
27
34
|
* - leaves: flutter along their normal, more at the tip.
|
|
28
|
-
* All of it is scaled by slow gusts. Wind
|
|
35
|
+
* All of it is scaled by slow gusts. Wind Bursts push trunk, branches and leaves the same way, away
|
|
36
|
+
* from each burst point, scaled by the same response (and not by the Wind strength). Wind direction is world space; it is turned into the tree's
|
|
29
37
|
* object space (rotation only, so a scaled-up tree sways proportionally more). `frame` replaces
|
|
30
|
-
* that direction
|
|
38
|
+
* that direction, the response's phase and the Wind time (see {@link WindFrame}).
|
|
31
39
|
*/
|
|
32
40
|
export declare function windOffset(wind: WindSource, response: WindResponse, frame?: WindFrame): Node<'vec3'>;
|
|
41
|
+
/**
|
|
42
|
+
* TSL node: the Wind displacement (vec3, the tree's space) of a whole tree drawn as one picture (an
|
|
43
|
+
* Impostor card), at the tree-space point `point`: the trunk sway of its height (as `aWind.x`:
|
|
44
|
+
* (height / trunk height)², clamped), with the crown's branches swinging along as one. No leaf flutter.
|
|
45
|
+
*/
|
|
46
|
+
export declare function treeSwayOffset(wind: WindSource, response: WindResponse, point: Node<'vec3'>, frame?: WindFrame): Node<'vec3'>;
|
|
33
47
|
/**
|
|
34
48
|
* Adds a Wind offset to a material's vertex position (its existing `positionNode`, or the plain
|
|
35
49
|
* local position). The shadow pass reuses `positionNode`, so shadows sway along.
|
package/dist/wind/node.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAcvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAmD,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAU/F;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,KAAK,CAAC,EAAE,cAAc,GAAG,KAAK,CAAC;CAChC;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;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,GAAE,SAAc,GAAG,IAAI,CAAC,MAAM,CAAC,CAuBxG;AA4DD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,GAAE,SAAc,GAAG,IAAI,CAAC,MAAM,CAAC,CAQjI;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAG5E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casmo/tree.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Procedural trees for three.js (WebGPURenderer, TSL node materials).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three",
|
|
@@ -55,6 +55,14 @@
|
|
|
55
55
|
"types": "./dist/effects/index.d.ts",
|
|
56
56
|
"import": "./dist/effects.js"
|
|
57
57
|
},
|
|
58
|
+
"./scene": {
|
|
59
|
+
"types": "./dist/scene/index.d.ts",
|
|
60
|
+
"import": "./dist/scene.js"
|
|
61
|
+
},
|
|
62
|
+
"./weather": {
|
|
63
|
+
"types": "./dist/weather/index.d.ts",
|
|
64
|
+
"import": "./dist/weather.js"
|
|
65
|
+
},
|
|
58
66
|
"./species": {
|
|
59
67
|
"types": "./dist/species/index.d.ts",
|
|
60
68
|
"import": "./dist/species.js"
|
package/dist/effects.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;;;;;;;;;;AAWA,SAAgB,eAAe,YAAwC,MAAoB;CACzF,OAAO,QAAQ,IAAI,QAAQ,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,OAAO,SAAS;EACtE,MAAM,OAAO,WAAW,MAAM,QAAQ;EACtC,MAAM,WAAW,SAAS,SAAS,cAAc,QAAQ,WAAW,MAAM,QAAQ,SAAS;EAC3F,KAAK,MAAM,IAAI,OAAO,IAAI,GAAG,SAAS,WAAW,IAAI,GAAG,WAAW,IAAI,GAAG,CAAC;CAE7E,CAAC;AACH;;;;;;AAOA,SAAgB,YAAY,YAAwC,MAAe;CACjF,MAAM,OAAO,IAAI,GAAG,YAAY,eAAe,SAAS,EAAE,CAAC;CAC3D,KAAK,cAAc,WAAW,GAAU,CAAC;CACzC,OAAO;AACT;;;;;;AAoBA,SAAgB,gBAAgB,OAAc,QAAgB,YA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