@casmo/tree.js 0.4.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 +590 -4
- package/dist/effects/custom.d.ts +62 -0
- package/dist/effects/custom.d.ts.map +1 -0
- package/dist/effects/effects.d.ts +42 -1
- package/dist/effects/effects.d.ts.map +1 -1
- package/dist/effects/index.d.ts +2 -0
- package/dist/effects/index.d.ts.map +1 -1
- package/dist/effects/mask.d.ts +9 -1
- package/dist/effects/mask.d.ts.map +1 -1
- package/dist/effects/tree-id.d.ts.map +1 -1
- package/dist/effects-qHx_8Dlk.js +1052 -0
- package/dist/effects-qHx_8Dlk.js.map +1 -0
- package/dist/effects.js +2 -963
- package/dist/forest/Forest.d.ts +80 -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-lg61rhKM.js → forest-CM5DrklM.js} +1723 -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-lg61rhKM.js.map +0 -1
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { a as WIND_BURST_LIFETIME, t as setWindMotion } from "./motion-Qd7xjeZM.js";
|
|
2
|
+
import { Node } from "three/webgpu";
|
|
3
|
+
import { Fn, Loop, attribute, bool, cos, cross, dot, exp, float, instanceIndex, int, modelWorldMatrix, modelWorldMatrixInverse, nodeObject, normalGeometry, normalLocal, positionGeometry, positionLocal, select, sin, smoothstep, step, vec2, vec3, vec4 } from "three/tsl";
|
|
4
|
+
// src/growth/evaluate.ts
|
|
5
|
+
/**
|
|
6
|
+
* The Growth model, one spec with two backends: `growPositions` (CPU, here) and `growthPosition`
|
|
7
|
+
* (TSL, `./tsl.ts`). Keep them in step. Per vertex, at Growth `g`:
|
|
8
|
+
*
|
|
9
|
+
* 1. thicken: move the vertex towards its part's centre line, keeping `thickness(g)` of its radius
|
|
10
|
+
* (`aGrowth.z`, along the vertex normal);
|
|
11
|
+
* 2. sprout: scale the part about its base point (`aOrigin`) by `partProgress(g, start, end)`
|
|
12
|
+
* (`aGrowth.xy`), so a part grows out of a point on its (already grown) parent;
|
|
13
|
+
* 3. size: scale the whole tree about its base (local origin) by `treeScale(g)`.
|
|
14
|
+
*
|
|
15
|
+
* Every step is written as `x - offset * (1 - factor)`, so at Growth 1 the positions are exactly
|
|
16
|
+
* the generated ones: a tree at Growth 1 is a normal static tree.
|
|
17
|
+
*/
|
|
18
|
+
/** Size of the whole tree at Growth 0 (sapling), relative to fully grown. */
|
|
19
|
+
var SAPLING_SCALE = .2;
|
|
20
|
+
/** Branch thickness at Growth 0, relative to the size-scaled thickness when fully grown. */
|
|
21
|
+
var SAPLING_THICKNESS = .4;
|
|
22
|
+
/** Smallest window width, so parts with `start == end` (the trunk) are simply grown. */
|
|
23
|
+
var MIN_WINDOW = 1e-5;
|
|
24
|
+
var treeScale = (growth) => SAPLING_SCALE + .8 * growth;
|
|
25
|
+
var thickness$1 = (growth) => SAPLING_THICKNESS + .6 * growth;
|
|
26
|
+
/** How far one part has sprouted (0 = not yet, 1 = full size), eased; 1 from `end` on. */
|
|
27
|
+
function partProgress$1(growth, start, end) {
|
|
28
|
+
const p = Math.min(Math.max((growth - end) / Math.max(end - start, MIN_WINDOW) + 1, 0), 1);
|
|
29
|
+
return p * p * (3 - 2 * p);
|
|
30
|
+
}
|
|
31
|
+
/** Clamps a Growth value to 0..1 (NaN becomes 1, fully grown). */
|
|
32
|
+
function clampGrowth(growth) {
|
|
33
|
+
return Number.isNaN(growth) ? 1 : Math.min(Math.max(growth, 0), 1);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Vertex positions of generated geometry at a given Growth, on the CPU (for baking a tree and
|
|
37
|
+
* for tests; at runtime the same model runs in TSL). Returns a new array.
|
|
38
|
+
*/
|
|
39
|
+
function growPositions(buffers, growth) {
|
|
40
|
+
const g = clampGrowth(growth);
|
|
41
|
+
const { positions, normals } = buffers;
|
|
42
|
+
const { aOrigin, aGrowth } = buffers.attributes;
|
|
43
|
+
const out = new Float32Array(positions.length);
|
|
44
|
+
const scale = treeScale(g);
|
|
45
|
+
const thin = 1 - thickness$1(g);
|
|
46
|
+
for (let v = 0; v < positions.length / 3; v++) {
|
|
47
|
+
const [start, end, radius] = [
|
|
48
|
+
aGrowth.array[v * 3],
|
|
49
|
+
aGrowth.array[v * 3 + 1],
|
|
50
|
+
aGrowth.array[v * 3 + 2]
|
|
51
|
+
];
|
|
52
|
+
const shrink = 1 - partProgress$1(g, start, end);
|
|
53
|
+
for (let k = 0; k < 3; k++) {
|
|
54
|
+
const i = v * 3 + k;
|
|
55
|
+
const thick = positions[i] - normals[i] * radius * thin;
|
|
56
|
+
const sprouted = thick - (thick - aOrigin.array[i]) * shrink;
|
|
57
|
+
out[i] = sprouted - sprouted * (1 - scale);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
// src/growth/tsl.ts
|
|
63
|
+
/** Size of the whole tree at Growth `g` (twin of `treeScale`): the scale `growthPosition` gives the tree. */
|
|
64
|
+
var growthScale = (g) => float(SAPLING_SCALE).add(float(1 - SAPLING_SCALE).mul(g));
|
|
65
|
+
/** Branch thickness at Growth `g` (twin of `thickness`). */
|
|
66
|
+
var thickness = (g) => float(SAPLING_THICKNESS).add(float(1 - SAPLING_THICKNESS).mul(g));
|
|
67
|
+
/** How far one part has sprouted, eased (twin of `partProgress`). */
|
|
68
|
+
function partProgress(g, start, end) {
|
|
69
|
+
const p = g.sub(end).div(end.sub(start).max(MIN_WINDOW)).add(1).clamp(0, 1);
|
|
70
|
+
return p.mul(p).mul(float(3).sub(p.mul(2)));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Growth in TSL: the vertex position of a tree part at Growth `growth` (a float node, usually the
|
|
74
|
+
* tree's Growth uniform; a Forest can pass a per-instance attribute instead). Same model and steps
|
|
75
|
+
* as `growPositions` (see `./evaluate.ts`), driven by the Generator's `aGrowth` and `aOrigin` attributes.
|
|
76
|
+
*
|
|
77
|
+
* `position` is the input position (default `positionLocal`). To compose with other vertex effects,
|
|
78
|
+
* feed this node into them, e.g. `material.positionNode = windPosition(growthPosition(uGrowth))`:
|
|
79
|
+
* Growth first, so the rest acts on the grown tree.
|
|
80
|
+
*/
|
|
81
|
+
function growthPosition(growth, position = positionLocal) {
|
|
82
|
+
const g = float(growth).clamp(0, 1);
|
|
83
|
+
const data = attribute("aGrowth", "vec3");
|
|
84
|
+
const origin = attribute("aOrigin", "vec3");
|
|
85
|
+
const [start, end, radius] = [
|
|
86
|
+
data.x,
|
|
87
|
+
data.y,
|
|
88
|
+
data.z
|
|
89
|
+
];
|
|
90
|
+
const scale = growthScale(g);
|
|
91
|
+
const thin = float(1).sub(thickness(g));
|
|
92
|
+
const shrink = float(1).sub(partProgress(g, start, end));
|
|
93
|
+
const thick = position.sub(normalGeometry.mul(radius).mul(thin));
|
|
94
|
+
const sprouted = thick.sub(thick.sub(origin).mul(shrink));
|
|
95
|
+
return sprouted.sub(sprouted.mul(float(1).sub(scale)));
|
|
96
|
+
}
|
|
97
|
+
// src/wind/burst.ts
|
|
98
|
+
/** Metres per second the front travels outward from the burst point. */
|
|
99
|
+
var SPEED = 30;
|
|
100
|
+
/** The push follows cos(SWING × since): the lean away crosses zero after 0.5 s and springs back a little. */
|
|
101
|
+
var SWING = Math.PI;
|
|
102
|
+
/** Reduced motion (negative strength): everything in reach leans at once by this much, fading over REDUCED_FADE s. */
|
|
103
|
+
var REDUCED_PEAK = .5;
|
|
104
|
+
var REDUCED_FADE = .6;
|
|
105
|
+
/** The whole burst fades out over the last 40 % of its lifetime. */
|
|
106
|
+
var LIFE_FADE_FROM = WIND_BURST_LIFETIME * .6;
|
|
107
|
+
/**
|
|
108
|
+
* TSL node: the push of the Wind Bursts of `wind` at a world-space ground point `xz` (vec2: world
|
|
109
|
+
* x, z), summed over the running bursts: away from each burst point, about 0..0.75 × strength at
|
|
110
|
+
* its peak, 0 beyond the burst's radius and once it has ended. `time` is the Wind time to evaluate
|
|
111
|
+
* it at (default the Wind's clock), e.g. the previous frame's for Wind-aware velocity. With no
|
|
112
|
+
* burst running the loop runs zero times and the push is exactly 0.
|
|
113
|
+
*/
|
|
114
|
+
function windBurstPush(wind, xz, time = wind.uniforms.time) {
|
|
115
|
+
const { points, radii, count } = wind.uniforms.bursts;
|
|
116
|
+
return burstPush(points, radii, count, xz, time);
|
|
117
|
+
}
|
|
118
|
+
var burstPush = Fn(([points, radii, count, xz, time]) => {
|
|
119
|
+
const push = vec2(0).toVar();
|
|
120
|
+
Loop({
|
|
121
|
+
start: int(0),
|
|
122
|
+
end: count,
|
|
123
|
+
type: "int",
|
|
124
|
+
condition: "<"
|
|
125
|
+
}, ({ i }) => {
|
|
126
|
+
const burst = points.element(i);
|
|
127
|
+
const strength = burst.w;
|
|
128
|
+
const age = time.sub(burst.z);
|
|
129
|
+
const away = xz.sub(burst.xy);
|
|
130
|
+
const distance = away.length();
|
|
131
|
+
const since = age.sub(distance.div(SPEED)).max(0);
|
|
132
|
+
const swing = exp(since.div(-.04)).oneMinus().mul(exp(since.div(-.4))).mul(cos(since.mul(SWING)));
|
|
133
|
+
const reduced = smoothstep(0, REDUCED_FADE, age).oneMinus().mul(REDUCED_PEAK);
|
|
134
|
+
const pulse = select(strength.lessThan(0), reduced, swing);
|
|
135
|
+
const falloff = smoothstep(0, radii.element(i), distance).oneMinus();
|
|
136
|
+
const life = smoothstep(LIFE_FADE_FROM, WIND_BURST_LIFETIME, age).oneMinus().mul(step(0, age)).mul(step(age, WIND_BURST_LIFETIME));
|
|
137
|
+
push.addAssign(away.div(distance.max(.001)).mul(pulse.mul(falloff).mul(life).mul(strength.abs())));
|
|
138
|
+
});
|
|
139
|
+
return push;
|
|
140
|
+
});
|
|
141
|
+
/** The {@link WindBurstFrame} of a tree that is one object: its world origin and rotation. */
|
|
142
|
+
function objectBurstFrame() {
|
|
143
|
+
return {
|
|
144
|
+
origin: modelWorldMatrix.mul(vec4(0, 0, 0, 1)).xz,
|
|
145
|
+
toTree: (world) => {
|
|
146
|
+
const local = modelWorldMatrixInverse.mul(vec4(world, 0)).xyz;
|
|
147
|
+
return local.mul(world.length().div(local.length().max(1e-6)));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A Wind displacement that only takes Wind Bursts once they are used: it is `still` (the displacement
|
|
153
|
+
* without bursts, exactly as before Wind Bursts existed) until the first burst on `source`'s Wind, then
|
|
154
|
+
* `withBursts()`, built once. The switch is one-time: every material built with it is marked for a
|
|
155
|
+
* rebuild of its node graph (`needsUpdate`), never its geometry. The node is transparent: it builds to,
|
|
156
|
+
* traverses and hashes as the displacement it holds.
|
|
157
|
+
*/
|
|
158
|
+
var WindBurstSwitchNode = class extends Node {
|
|
159
|
+
static get type() {
|
|
160
|
+
return "WindBurstSwitchNode";
|
|
161
|
+
}
|
|
162
|
+
/** The displacement drawn now (the only child, so traversal sees only what is drawn). */
|
|
163
|
+
node;
|
|
164
|
+
#withBursts;
|
|
165
|
+
#materials = /* @__PURE__ */ new Set();
|
|
166
|
+
constructor(source, still, withBursts) {
|
|
167
|
+
super("vec3");
|
|
168
|
+
this.node = still;
|
|
169
|
+
this.#withBursts = withBursts;
|
|
170
|
+
source.uniforms.bursts.used.listen(this);
|
|
171
|
+
}
|
|
172
|
+
burstsUsed() {
|
|
173
|
+
if (!this.#withBursts) return;
|
|
174
|
+
this.node = this.#withBursts();
|
|
175
|
+
this.#withBursts = null;
|
|
176
|
+
this.needsUpdate = true;
|
|
177
|
+
for (const ref of this.#materials) {
|
|
178
|
+
const material = ref.deref();
|
|
179
|
+
if (material) material.needsUpdate = true;
|
|
180
|
+
}
|
|
181
|
+
this.#materials.clear();
|
|
182
|
+
}
|
|
183
|
+
getCacheKey(force, ignores) {
|
|
184
|
+
return this.node.getCacheKey(force, ignores);
|
|
185
|
+
}
|
|
186
|
+
setup(builder) {
|
|
187
|
+
if (this.#withBursts && builder.material) this.#materials.add(new WeakRef(builder.material));
|
|
188
|
+
return this.node;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* TSL node: the Wind displacement `still`, plus Wind Bursts once `source`'s Wind has had one: then
|
|
193
|
+
* `withBursts()` (built at that moment, once). See {@link WindBurstSwitchNode}.
|
|
194
|
+
*/
|
|
195
|
+
function withWindBursts(source, still, withBursts) {
|
|
196
|
+
return nodeObject(new WindBurstSwitchNode(source, still, withBursts));
|
|
197
|
+
}
|
|
198
|
+
// src/wind/node.ts
|
|
199
|
+
var TRUNK_AMPLITUDE = .15;
|
|
200
|
+
var BRANCH_AMPLITUDE = .1;
|
|
201
|
+
var LEAF_AMPLITUDE = .2;
|
|
202
|
+
var BURST_BEND = 3;
|
|
203
|
+
/** The scene Wind direction in the rendered object's space (rotation only, normalized). */
|
|
204
|
+
function objectWindDirection(wind) {
|
|
205
|
+
return modelWorldMatrixInverse.mul(vec4(wind.uniforms.direction, 0)).xyz.normalize();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* TSL node: the Wind displacement (vec3, object space) of each vertex, from the per-vertex
|
|
209
|
+
* `aWind` weights (trunk sway, branch sway, leaf flutter), the tree's Wind response and the
|
|
210
|
+
* scene Wind. It only depends on geometry attributes and uniforms, so it adds onto any other
|
|
211
|
+
* position node (Growth): `position = grown + windOffset(...)` (see {@link applyWind}).
|
|
212
|
+
*
|
|
213
|
+
* - trunk: leans with the wind and swings slowly, bending from the ground (weight = height²);
|
|
214
|
+
* - branches: swing faster, with a phase that varies smoothly in space so joints stay attached,
|
|
215
|
+
* plus a little cross-wind motion;
|
|
216
|
+
* - leaves: flutter along their normal, more at the tip.
|
|
217
|
+
* All of it is scaled by slow gusts. Wind Bursts push trunk, branches and leaves the same way, away
|
|
218
|
+
* 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
|
|
219
|
+
* object space (rotation only, so a scaled-up tree sways proportionally more). `frame` replaces
|
|
220
|
+
* that direction, the response's phase and the Wind time (see {@link WindFrame}).
|
|
221
|
+
*/
|
|
222
|
+
function windOffset(wind, response, frame = {}) {
|
|
223
|
+
const weights = attribute("aWind", "vec3");
|
|
224
|
+
const random = attribute("aRandom", "float");
|
|
225
|
+
const origin = attribute("aOrigin", "vec3");
|
|
226
|
+
const motion = windMotion(wind, response, frame);
|
|
227
|
+
const { t, gust } = motion;
|
|
228
|
+
const sway = swayOffset(motion, response, {
|
|
229
|
+
trunk: weights.x,
|
|
230
|
+
branches: weights.y,
|
|
231
|
+
spatialPhase: dot(positionGeometry, vec3(.9, .4, .7))
|
|
232
|
+
});
|
|
233
|
+
const leafLength = positionGeometry.sub(origin).length();
|
|
234
|
+
const flutter = sin(t.mul(9).add(random.mul(6.2832)));
|
|
235
|
+
const leaves = normalGeometry.mul(flutter.mul(response.uniforms.leaves).mul(weights.z).mul(leafLength).mul(wind.uniforms.strength).mul(gust).mul(LEAF_AMPLITUDE));
|
|
236
|
+
const offset = sway.add(leaves);
|
|
237
|
+
if (frame.burst === false) return offset;
|
|
238
|
+
return withWindBursts(wind, offset, () => {
|
|
239
|
+
const push = burstMotion(wind, frame);
|
|
240
|
+
const burstLeaves = normalGeometry.mul(flutter.mul(response.uniforms.leaves).mul(weights.z).mul(leafLength).mul(push.length()).mul(LEAF_AMPLITUDE));
|
|
241
|
+
return offset.add(burstSway(push, response, weights.x, weights.y)).add(burstLeaves);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function windMotion(wind, response, frame) {
|
|
245
|
+
const r = response.uniforms;
|
|
246
|
+
const t = (frame.time ?? wind.uniforms.time).mul(r.frequency).add(frame.phase ?? r.phase);
|
|
247
|
+
const direction = (frame.direction ?? objectWindDirection(wind)).normalize();
|
|
248
|
+
const gust = sin(t.mul(.37)).add(sin(t.mul(.91).add(1.7))).mul(.1).add(.8);
|
|
249
|
+
return {
|
|
250
|
+
t,
|
|
251
|
+
direction,
|
|
252
|
+
gust,
|
|
253
|
+
scale: wind.uniforms.strength.mul(r.height).mul(gust)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/** The Wind Bursts' push in the tree's space (× {@link BURST_BEND}). */
|
|
257
|
+
function burstMotion(wind, frame) {
|
|
258
|
+
const { origin, toTree } = frame.burst || objectBurstFrame();
|
|
259
|
+
const push = windBurstPush(wind, origin, frame.time);
|
|
260
|
+
return toTree(vec3(push.x, 0, push.y)).mul(BURST_BEND);
|
|
261
|
+
}
|
|
262
|
+
/** The trunk and branch bend of a Wind Burst push (tree space): like the Wind's lean, without its swing. */
|
|
263
|
+
function burstSway(push, response, trunk, branches) {
|
|
264
|
+
const r = response.uniforms;
|
|
265
|
+
const weight = r.trunk.mul(trunk).mul(TRUNK_AMPLITUDE).add(r.branches.mul(branches).mul(BRANCH_AMPLITUDE));
|
|
266
|
+
return push.mul(weight.mul(r.height));
|
|
267
|
+
}
|
|
268
|
+
function swayOffset({ t, direction, scale }, response, weights) {
|
|
269
|
+
const r = response.uniforms;
|
|
270
|
+
const across = cross(direction, vec3(0, 1, 0));
|
|
271
|
+
const trunkSwing = sin(t.mul(1.1)).mul(.25).add(.75);
|
|
272
|
+
const trunk = direction.mul(trunkSwing.mul(r.trunk).mul(weights.trunk).mul(scale).mul(TRUNK_AMPLITUDE));
|
|
273
|
+
const branchSwing = sin(t.mul(2.3).add(weights.spatialPhase)).mul(.35).add(.65);
|
|
274
|
+
const branchCross = sin(t.mul(1.7).add(weights.spatialPhase.mul(1.3))).mul(.3);
|
|
275
|
+
const branches = direction.mul(branchSwing).add(across.mul(branchCross)).mul(r.branches.mul(weights.branches).mul(scale).mul(BRANCH_AMPLITUDE));
|
|
276
|
+
return trunk.add(branches);
|
|
277
|
+
}
|
|
278
|
+
/** Branch sway of a whole crown as one: about the mean of `aWind.y` over a crown. */
|
|
279
|
+
var CROWN_BRANCH_SWAY = .5;
|
|
280
|
+
/**
|
|
281
|
+
* TSL node: the Wind displacement (vec3, the tree's space) of a whole tree drawn as one picture (an
|
|
282
|
+
* Impostor card), at the tree-space point `point`: the trunk sway of its height (as `aWind.x`:
|
|
283
|
+
* (height / trunk height)², clamped), with the crown's branches swinging along as one. No leaf flutter.
|
|
284
|
+
*/
|
|
285
|
+
function treeSwayOffset(wind, response, point, frame = {}) {
|
|
286
|
+
const h = point.y.div(response.uniforms.height.max(1e-6)).clamp(0, 1);
|
|
287
|
+
const trunk = h.mul(h);
|
|
288
|
+
const branches = trunk.mul(CROWN_BRANCH_SWAY);
|
|
289
|
+
const sway = swayOffset(windMotion(wind, response, frame), response, {
|
|
290
|
+
trunk,
|
|
291
|
+
branches,
|
|
292
|
+
spatialPhase: float(0)
|
|
293
|
+
});
|
|
294
|
+
if (frame.burst === false) return sway;
|
|
295
|
+
return withWindBursts(wind, sway, () => sway.add(burstSway(burstMotion(wind, frame), response, trunk, branches)));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Adds a Wind offset to a material's vertex position (its existing `positionNode`, or the plain
|
|
299
|
+
* local position). The shadow pass reuses `positionNode`, so shadows sway along.
|
|
300
|
+
*/
|
|
301
|
+
function applyWind(material, offset) {
|
|
302
|
+
material.positionNode = material.positionNode ? material.positionNode.add(offset) : positionLocal.add(offset);
|
|
303
|
+
material.needsUpdate = true;
|
|
304
|
+
}
|
|
305
|
+
// src/forest/nodes.ts
|
|
306
|
+
var INSTANCE_ATTRIBUTES = {
|
|
307
|
+
iRotation: 0,
|
|
308
|
+
iState: 4
|
|
309
|
+
};
|
|
310
|
+
var levelInstances = /* @__PURE__ */ new WeakMap();
|
|
311
|
+
/** @internal Marks `mesh` as drawing a Detail Level: every Forest node built for it reads `instance`. */
|
|
312
|
+
function drawsDetailLevel(mesh, instance) {
|
|
313
|
+
levelInstances.set(mesh, instance);
|
|
314
|
+
}
|
|
315
|
+
function levelInstanceOf(builder) {
|
|
316
|
+
const object = builder.object;
|
|
317
|
+
return object ? levelInstances.get(object) : void 0;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* A node that is `level(instance)` on a Detail Level mesh and `instanced()` on anything else (the
|
|
321
|
+
* Variant's instanced meshes), decided when the material is built for the drawn object.
|
|
322
|
+
*/
|
|
323
|
+
function perInstance(instanced, level) {
|
|
324
|
+
return Fn((builder) => {
|
|
325
|
+
const instance = levelInstanceOf(builder);
|
|
326
|
+
return instance ? level(instance) : instanced();
|
|
327
|
+
})();
|
|
328
|
+
}
|
|
329
|
+
/** The tree's quaternion. */
|
|
330
|
+
function instanceRotation() {
|
|
331
|
+
return perInstance(() => attribute("iRotation", "vec4"), (instance) => instance.rotation);
|
|
332
|
+
}
|
|
333
|
+
/** Per-tree values in the instanced Season/Growth/Wind slots. */
|
|
334
|
+
function instanceState() {
|
|
335
|
+
const state = perInstance(() => attribute("iState", "vec4"), (instance) => instance.state);
|
|
336
|
+
return {
|
|
337
|
+
scale: state.x,
|
|
338
|
+
growth: state.y,
|
|
339
|
+
season: state.z,
|
|
340
|
+
windPhase: state.w
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/** The tree's slot in its Variant (`uint`): the instance index on the instanced meshes, from the level list on a Detail Level mesh. */
|
|
344
|
+
function instanceSlot() {
|
|
345
|
+
return perInstance(() => instanceIndex, (instance) => instance.slot);
|
|
346
|
+
}
|
|
347
|
+
/** Whether to draw this fragment: the Detail Level cross-fade (always true on the instanced meshes). */
|
|
348
|
+
function levelVisible() {
|
|
349
|
+
return perInstance(() => bool(true), (instance) => instance.visible);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* The tree's base in forest space, on a Detail Level mesh (the Impostor card places itself from it).
|
|
353
|
+
* Throws when built for any other object: the instanced meshes get their position from three.js.
|
|
354
|
+
*/
|
|
355
|
+
function levelTreePosition() {
|
|
356
|
+
return perInstance(() => {
|
|
357
|
+
throw new Error("levelTreePosition() only works on a Detail Level mesh");
|
|
358
|
+
}, (instance) => instance.position);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* The tree's base in forest space, on the instanced meshes and the Detail Level meshes alike, as the
|
|
362
|
+
* vertex stage knows it before `positionNode` runs. On an InstancedMesh three.js only hands over the
|
|
363
|
+
* placed vertex (M·p), so the base is M·p − R·s·p, kept in a variable so that it is worked out before
|
|
364
|
+
* `positionNode` replaces `positionLocal`; on a Detail Level mesh it is the tree's data.
|
|
365
|
+
*/
|
|
366
|
+
function instanceTreeBase() {
|
|
367
|
+
return perInstance(() => positionLocal.sub(instanceRotate(positionGeometry).mul(instanceState().scale)).toVar(), (instance) => instance.position);
|
|
368
|
+
}
|
|
369
|
+
/** Rotates `v` by the quaternion `q` (`inverse` = by its conjugate). */
|
|
370
|
+
function rotateByQuaternion(q, v, inverse = false) {
|
|
371
|
+
const u = inverse ? q.xyz.negate() : q.xyz;
|
|
372
|
+
const t = cross(u, v).mul(2);
|
|
373
|
+
return v.add(t.mul(q.w)).add(cross(u, t));
|
|
374
|
+
}
|
|
375
|
+
/** Rotates `v` by the instance quaternion (`inverse` = by its conjugate): tree space to forest space. */
|
|
376
|
+
function instanceRotate(v, inverse = false) {
|
|
377
|
+
return rotateByQuaternion(instanceRotation(), v, inverse);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* The tree's vertex placed in forest space without Growth or Wind (M·p). On an InstancedMesh three.js
|
|
381
|
+
* already applied the instance matrix to `positionLocal` (and the normal). A Detail Level mesh is not
|
|
382
|
+
* instanced by three, so this places the vertex from the tree's data and turns the normal with it.
|
|
383
|
+
*/
|
|
384
|
+
function placedPosition() {
|
|
385
|
+
return perInstance(() => positionLocal, (instance) => {
|
|
386
|
+
normalLocal.assign(rotateByQuaternion(instance.rotation, normalLocal));
|
|
387
|
+
return instance.position.add(rotateByQuaternion(instance.rotation, positionGeometry).mul(instance.state.x));
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Where a Wind Burst finds a Forest tree: its own base (through the Forest's transform) and its own
|
|
392
|
+
* rotation, so each instance bends away from the burst point like a single Tree does.
|
|
393
|
+
*/
|
|
394
|
+
function instanceBurstFrame() {
|
|
395
|
+
const forest = objectBurstFrame();
|
|
396
|
+
return {
|
|
397
|
+
origin: modelWorldMatrix.mul(vec4(instanceTreeBase(), 1)).xz,
|
|
398
|
+
toTree: (world) => instanceRotate(forest.toTree(world), true)
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The vertex position of a Forest tree (positionNode of an instanced Variant mesh).
|
|
403
|
+
*
|
|
404
|
+
* On an InstancedMesh, three.js applies the instance matrix to `positionLocal` before
|
|
405
|
+
* `positionNode` runs, but Growth and Wind are defined in the tree's own space (about the
|
|
406
|
+
* generated `aOrigin`s, relative to its trunk height). So both are computed from
|
|
407
|
+
* `positionGeometry`, and only their displacement is turned into forest space with the
|
|
408
|
+
* instance rotation and scale: M·(p + d) = M·p + R·s·d. The Wind direction goes the other way
|
|
409
|
+
* (forest -> tree space) and each tree sways with its own phase.
|
|
410
|
+
*
|
|
411
|
+
* `base`: the tree-space position Growth starts from (default `positionGeometry`); Fruit passes
|
|
412
|
+
* its Season-scaled position here.
|
|
413
|
+
*/
|
|
414
|
+
function forestPosition(wind, response, base = positionGeometry) {
|
|
415
|
+
const { scale, growth, windPhase } = instanceState();
|
|
416
|
+
const grown = growthPosition(growth, base);
|
|
417
|
+
const burst = instanceBurstFrame();
|
|
418
|
+
const offsetAt = (time) => windOffset(wind, response, {
|
|
419
|
+
direction: instanceRotate(objectWindDirection(wind), true),
|
|
420
|
+
phase: windPhase,
|
|
421
|
+
time,
|
|
422
|
+
burst
|
|
423
|
+
});
|
|
424
|
+
const offset = offsetAt();
|
|
425
|
+
const displacement = grown.add(offset).sub(positionGeometry);
|
|
426
|
+
const position = placedPosition().add(instanceRotate(displacement).mul(scale));
|
|
427
|
+
setWindMotion(position, {
|
|
428
|
+
source: wind,
|
|
429
|
+
shift: (previous) => instanceRotate(offsetAt(previous).sub(offset)).mul(scale),
|
|
430
|
+
offset: instanceRotate(offset).mul(scale)
|
|
431
|
+
});
|
|
432
|
+
return position;
|
|
433
|
+
}
|
|
434
|
+
export { clampGrowth as _, instanceRotate as a, instanceTreeBase as c, applyWind as d, objectWindDirection as f, growthScale as g, growthPosition as h, instanceBurstFrame as i, levelTreePosition as l, windOffset as m, drawsDetailLevel as n, instanceSlot as o, treeSwayOffset as p, forestPosition as r, instanceState as s, INSTANCE_ATTRIBUTES as t, levelVisible as u, growPositions as v, treeScale as y };
|
|
435
|
+
|
|
436
|
+
//# sourceMappingURL=nodes-DxgTyF9B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes-DxgTyF9B.js","names":["thickness","partProgress"],"sources":["../src/growth/evaluate.ts","../src/growth/tsl.ts","../src/wind/burst.ts","../src/wind/node.ts","../src/forest/nodes.ts"],"sourcesContent":["import type { GeometryBuffers } from '../generator';\n\n/**\n * The Growth model, one spec with two backends: `growPositions` (CPU, here) and `growthPosition`\n * (TSL, `./tsl.ts`). Keep them in step. Per vertex, at Growth `g`:\n *\n * 1. thicken: move the vertex towards its part's centre line, keeping `thickness(g)` of its radius\n * (`aGrowth.z`, along the vertex normal);\n * 2. sprout: scale the part about its base point (`aOrigin`) by `partProgress(g, start, end)`\n * (`aGrowth.xy`), so a part grows out of a point on its (already grown) parent;\n * 3. size: scale the whole tree about its base (local origin) by `treeScale(g)`.\n *\n * Every step is written as `x - offset * (1 - factor)`, so at Growth 1 the positions are exactly\n * the generated ones: a tree at Growth 1 is a normal static tree.\n */\n\n/** Size of the whole tree at Growth 0 (sapling), relative to fully grown. */\nexport const SAPLING_SCALE = 0.2;\n/** Branch thickness at Growth 0, relative to the size-scaled thickness when fully grown. */\nexport const SAPLING_THICKNESS = 0.4;\n/** Smallest window width, so parts with `start == end` (the trunk) are simply grown. */\nexport const MIN_WINDOW = 1e-5;\n\nexport const treeScale = (growth: number): number => SAPLING_SCALE + (1 - SAPLING_SCALE) * growth;\nexport const thickness = (growth: number): number => SAPLING_THICKNESS + (1 - SAPLING_THICKNESS) * growth;\n\n/** How far one part has sprouted (0 = not yet, 1 = full size), eased; 1 from `end` on. */\nexport function partProgress(growth: number, start: number, end: number): number {\n const p = Math.min(Math.max((growth - end) / Math.max(end - start, MIN_WINDOW) + 1, 0), 1);\n return p * p * (3 - 2 * p);\n}\n\n/** Clamps a Growth value to 0..1 (NaN becomes 1, fully grown). */\nexport function clampGrowth(growth: number): number {\n return Number.isNaN(growth) ? 1 : Math.min(Math.max(growth, 0), 1);\n}\n\n/**\n * Vertex positions of generated geometry at a given Growth, on the CPU (for baking a tree and\n * for tests; at runtime the same model runs in TSL). Returns a new array.\n */\nexport function growPositions(buffers: GeometryBuffers, growth: number): Float32Array {\n const g = clampGrowth(growth);\n const { positions, normals } = buffers;\n const { aOrigin, aGrowth } = buffers.attributes;\n const out = new Float32Array(positions.length);\n const scale = treeScale(g);\n const thin = 1 - thickness(g);\n for (let v = 0; v < positions.length / 3; v++) {\n const [start, end, radius] = [aGrowth.array[v * 3]!, aGrowth.array[v * 3 + 1]!, aGrowth.array[v * 3 + 2]!];\n const shrink = 1 - partProgress(g, start, end);\n for (let k = 0; k < 3; k++) {\n const i = v * 3 + k;\n const thick = positions[i]! - normals[i]! * radius * thin;\n const sprouted = thick - (thick - aOrigin.array[i]!) * shrink;\n out[i] = sprouted - sprouted * (1 - scale);\n }\n }\n return out;\n}\n","import { attribute, float, normalGeometry, positionLocal } from 'three/tsl';\nimport type { Node } from 'three/webgpu';\nimport { MIN_WINDOW, SAPLING_SCALE, SAPLING_THICKNESS } from './evaluate';\n\n// The TSL twins of the helpers in `./evaluate.ts`, step for step.\n\n/** Size of the whole tree at Growth `g` (twin of `treeScale`): the scale `growthPosition` gives the tree. */\nexport const growthScale = (g: Node<'float'>): Node<'float'> => float(SAPLING_SCALE).add(float(1 - SAPLING_SCALE).mul(g));\n\n/** Branch thickness at Growth `g` (twin of `thickness`). */\nconst thickness = (g: Node<'float'>): Node<'float'> => float(SAPLING_THICKNESS).add(float(1 - SAPLING_THICKNESS).mul(g));\n\n/** How far one part has sprouted, eased (twin of `partProgress`). */\nfunction partProgress(g: Node<'float'>, start: Node<'float'>, end: Node<'float'>): Node<'float'> {\n const p = g.sub(end).div(end.sub(start).max(MIN_WINDOW)).add(1).clamp(0, 1);\n return p.mul(p).mul(float(3).sub(p.mul(2)));\n}\n\n/**\n * Growth in TSL: the vertex position of a tree part at Growth `growth` (a float node, usually the\n * tree's Growth uniform; a Forest can pass a per-instance attribute instead). Same model and steps\n * as `growPositions` (see `./evaluate.ts`), driven by the Generator's `aGrowth` and `aOrigin` attributes.\n *\n * `position` is the input position (default `positionLocal`). To compose with other vertex effects,\n * feed this node into them, e.g. `material.positionNode = windPosition(growthPosition(uGrowth))`:\n * Growth first, so the rest acts on the grown tree.\n */\nexport function growthPosition(growth: Node<'float'>, position: Node<'vec3'> = positionLocal): Node<'vec3'> {\n const g = float(growth).clamp(0, 1);\n const data = attribute<'vec3'>('aGrowth', 'vec3');\n const origin = attribute<'vec3'>('aOrigin', 'vec3');\n const [start, end, radius] = [data.x, data.y, data.z];\n\n const scale = growthScale(g);\n const thin = float(1).sub(thickness(g));\n const shrink = float(1).sub(partProgress(g, start, end));\n\n const thick = position.sub(normalGeometry.mul(radius).mul(thin));\n const sprouted = thick.sub(thick.sub(origin).mul(shrink));\n return sprouted.sub(sprouted.mul(float(1).sub(scale)));\n}\n","import { Node, type Material, type NodeBuilder, type UniformArrayNode } from 'three/webgpu';\nimport { cos, exp, Fn, int, Loop, modelWorldMatrix, modelWorldMatrixInverse, nodeObject, select, smoothstep, step, vec2, vec4 } from 'three/tsl';\nimport { WIND_BURST_LIFETIME, type BurstListener } from './Wind';\nimport type { WindSource } from './node';\n\n// The shape of a Wind Burst: a front travelling out from the burst point, a quick rise and a short swing back.\n/** Metres per second the front travels outward from the burst point. */\nconst SPEED = 30;\n/** Seconds the push takes to rise as the front passes, and to decay after. */\nconst RISE = 0.04;\nconst TAIL = 0.4;\n/** The push follows cos(SWING × since): the lean away crosses zero after 0.5 s and springs back a little. */\nconst SWING = Math.PI;\n/** Reduced motion (negative strength): everything in reach leans at once by this much, fading over REDUCED_FADE s. */\nconst REDUCED_PEAK = 0.5;\nconst REDUCED_FADE = 0.6;\n/** The whole burst fades out over the last 40 % of its lifetime. */\nconst LIFE_FADE_FROM = WIND_BURST_LIFETIME * 0.6;\n\n/**\n * TSL node: the push of the Wind Bursts of `wind` at a world-space ground point `xz` (vec2: world\n * x, z), summed over the running bursts: away from each burst point, about 0..0.75 × strength at\n * its peak, 0 beyond the burst's radius and once it has ended. `time` is the Wind time to evaluate\n * it at (default the Wind's clock), e.g. the previous frame's for Wind-aware velocity. With no\n * burst running the loop runs zero times and the push is exactly 0.\n */\nexport function windBurstPush(wind: WindSource, xz: Node<'vec2'>, time: Node<'float'> = wind.uniforms.time): Node<'vec2'> {\n const { points, radii, count } = wind.uniforms.bursts;\n // The uniforms are passed in (not closed over), so they are part of the node graph.\n return burstPush(points, radii, count, xz, time);\n}\n\ntype BurstPushInputs = [UniformArrayNode<'vec4'>, UniformArrayNode<'float'>, Node<'int'>, Node<'vec2'>, Node<'float'>];\n\nconst burstPush = Fn(([points, radii, count, xz, time]: BurstPushInputs) => {\n const push = vec2(0).toVar();\n Loop({ start: int(0), end: count, type: 'int', condition: '<' }, ({ i }) => {\n const burst = points.element(i); // x, z, start, strength\n const strength = burst.w;\n const age = time.sub(burst.z);\n const away = xz.sub(burst.xy);\n const distance = away.length();\n // Clamped, so the rise term never overflows before the front arrives (it is 0 there anyway).\n const since = age.sub(distance.div(SPEED)).max(0);\n const swing = exp(since.div(-RISE)).oneMinus().mul(exp(since.div(-TAIL))).mul(cos(since.mul(SWING)));\n const reduced = smoothstep(0, REDUCED_FADE, age).oneMinus().mul(REDUCED_PEAK);\n const pulse = select(strength.lessThan(0), reduced, swing);\n const falloff = smoothstep(0, radii.element(i), distance).oneMinus();\n const life = smoothstep(LIFE_FADE_FROM, WIND_BURST_LIFETIME, age).oneMinus().mul(step(0, age)).mul(step(age, WIND_BURST_LIFETIME));\n push.addAssign(away.div(distance.max(1e-3)).mul(pulse.mul(falloff).mul(life).mul(strength.abs())));\n });\n return push;\n}) as unknown as (...inputs: BurstPushInputs) => Node<'vec2'>;\n\n/**\n * Where a Wind Burst finds a tree and how its push turns into the tree's space: a Tree is the\n * rendered object ({@link objectBurstFrame}); a tree drawn as an instance passes its own.\n */\nexport interface WindBurstFrame {\n /** The tree's world-space ground point (vec2: world x, z). */\n origin: Node<'vec2'>;\n /** Turns a world-space vector into the tree's space: rotation only, its length kept. */\n toTree(world: Node<'vec3'>): Node<'vec3'>;\n}\n\n/** The {@link WindBurstFrame} of a tree that is one object: its world origin and rotation. */\nexport function objectBurstFrame(): WindBurstFrame {\n return {\n origin: modelWorldMatrix.mul(vec4(0, 0, 0, 1)).xz,\n toTree: (world) => {\n const local = modelWorldMatrixInverse.mul(vec4(world, 0)).xyz;\n // Rotation only: undo the inverse scale (0 stays 0).\n return local.mul(world.length().div(local.length().max(1e-6)));\n },\n };\n}\n\n/**\n * A Wind displacement that only takes Wind Bursts once they are used: it is `still` (the displacement\n * without bursts, exactly as before Wind Bursts existed) until the first burst on `source`'s Wind, then\n * `withBursts()`, built once. The switch is one-time: every material built with it is marked for a\n * rebuild of its node graph (`needsUpdate`), never its geometry. The node is transparent: it builds to,\n * traverses and hashes as the displacement it holds.\n */\nclass WindBurstSwitchNode extends Node implements BurstListener {\n static get type(): string {\n return 'WindBurstSwitchNode';\n }\n\n /** The displacement drawn now (the only child, so traversal sees only what is drawn). */\n node: Node<'vec3'>;\n #withBursts: (() => Node<'vec3'>) | null;\n readonly #materials = new Set<WeakRef<Material>>();\n\n constructor(source: WindSource, still: Node<'vec3'>, withBursts: () => Node<'vec3'>) {\n super('vec3');\n this.node = still;\n this.#withBursts = withBursts;\n source.uniforms.bursts.used.listen(this);\n }\n\n burstsUsed(): void {\n if (!this.#withBursts) return;\n this.node = this.#withBursts();\n this.#withBursts = null;\n this.needsUpdate = true;\n for (const ref of this.#materials) {\n const material = ref.deref();\n if (material) material.needsUpdate = true;\n }\n this.#materials.clear();\n }\n\n override getCacheKey(force?: boolean, ignores?: Set<Node>): number {\n return this.node.getCacheKey(force, ignores);\n }\n\n override setup(builder: NodeBuilder): Node {\n if (this.#withBursts && builder.material) this.#materials.add(new WeakRef(builder.material));\n return this.node;\n }\n}\n\n/**\n * TSL node: the Wind displacement `still`, plus Wind Bursts once `source`'s Wind has had one: then\n * `withBursts()` (built at that moment, once). See {@link WindBurstSwitchNode}.\n */\nexport function withWindBursts(source: WindSource, still: Node<'vec3'>, withBursts: () => Node<'vec3'>): Node<'vec3'> {\n return nodeObject(new WindBurstSwitchNode(source, still, withBursts)) as unknown as Node<'vec3'>;\n}\n","import type { Node, NodeMaterial } from 'three/webgpu';\nimport {\n attribute,\n cross,\n dot,\n float,\n modelWorldMatrixInverse,\n normalGeometry,\n positionGeometry,\n positionLocal,\n sin,\n vec3,\n vec4,\n} from 'three/tsl';\nimport type { WindUniforms } from './Wind';\nimport type { WindResponse } from './response';\nimport { objectBurstFrame, windBurstPush, withWindBursts, type WindBurstFrame } from './burst';\n\n// Sway amplitudes at Wind strength 1 and response 1, as a fraction of the trunk height.\nconst TRUNK_AMPLITUDE = 0.15;\nconst BRANCH_AMPLITUDE = 0.1;\n// Leaf flutter, as a fraction of the distance from the leaf base.\nconst LEAF_AMPLITUDE = 0.2;\n// How hard a Wind Burst bends a tree, relative to a Wind of the same strength.\nconst BURST_BEND = 3;\n\n/**\n * Overrides for trees that are not one object each (Forest instances): the Wind direction in\n * the tree's own space and the tree's phase (radians), e.g. from per-instance attributes; and the\n * Wind time (seconds) to evaluate the sway at (default the Wind's own clock), e.g. the previous\n * frame's for Wind-aware velocity. `burst`: where the tree stands for Wind Bursts (default the\n * rendered object), or `false` for a tree that does not take Wind Bursts. Burst nodes are only added\n * once the Wind has had a burst (one node-graph rebuild then; see `Wind.burst`).\n */\nexport interface WindFrame {\n direction?: Node<'vec3'>;\n phase?: Node<'float'>;\n time?: Node<'float'>;\n burst?: WindBurstFrame | false;\n}\n\n/** Anything holding Wind uniforms: a {@link Wind} or a {@link WindBinding} that follows one. */\nexport interface WindSource {\n readonly uniforms: WindUniforms;\n}\n\n/** The scene Wind direction in the rendered object's space (rotation only, normalized). */\nexport function objectWindDirection(wind: WindSource): Node<'vec3'> {\n return modelWorldMatrixInverse.mul(vec4(wind.uniforms.direction, 0)).xyz.normalize();\n}\n\n/**\n * TSL node: the Wind displacement (vec3, object space) of each vertex, from the per-vertex\n * `aWind` weights (trunk sway, branch sway, leaf flutter), the tree's Wind response and the\n * scene Wind. It only depends on geometry attributes and uniforms, so it adds onto any other\n * position node (Growth): `position = grown + windOffset(...)` (see {@link applyWind}).\n *\n * - trunk: leans with the wind and swings slowly, bending from the ground (weight = height²);\n * - branches: swing faster, with a phase that varies smoothly in space so joints stay attached,\n * plus a little cross-wind motion;\n * - leaves: flutter along their normal, more at the tip.\n * All of it is scaled by slow gusts. Wind Bursts push trunk, branches and leaves the same way, away\n * 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\n * object space (rotation only, so a scaled-up tree sways proportionally more). `frame` replaces\n * that direction, the response's phase and the Wind time (see {@link WindFrame}).\n */\nexport function windOffset(wind: WindSource, response: WindResponse, frame: WindFrame = {}): Node<'vec3'> {\n const weights = attribute('aWind', 'vec3');\n const random = attribute('aRandom', 'float');\n const origin = attribute('aOrigin', 'vec3');\n const motion = windMotion(wind, response, frame);\n const { t, gust } = motion;\n const sway = swayOffset(motion, response, { trunk: weights.x, branches: weights.y, spatialPhase: dot(positionGeometry, vec3(0.9, 0.4, 0.7)) });\n\n const leafLength = positionGeometry.sub(origin).length();\n const flutter = sin(t.mul(9).add(random.mul(6.2832)));\n const leaves = normalGeometry.mul(\n flutter.mul(response.uniforms.leaves).mul(weights.z).mul(leafLength).mul(wind.uniforms.strength).mul(gust).mul(LEAF_AMPLITUDE),\n );\n const offset = sway.add(leaves);\n if (frame.burst === false) return offset;\n\n // Wind Bursts: added on top (only once the Wind has had one), so with none running (a push of exactly\n // 0) the sum is the Wind's own.\n return withWindBursts(wind, offset, () => {\n const push = burstMotion(wind, frame);\n const burstLeaves = normalGeometry.mul(flutter.mul(response.uniforms.leaves).mul(weights.z).mul(leafLength).mul(push.length()).mul(LEAF_AMPLITUDE));\n return offset.add(burstSway(push, response, weights.x, weights.y)).add(burstLeaves);\n });\n}\n\n/** The Wind clock, direction and gusts one tree sways with. */\ninterface WindMotion {\n /** The tree's Wind time (seconds × frequency + phase). */\n t: Node<'float'>;\n direction: Node<'vec3'>;\n /** 0.6 .. 1: two slow, incommensurate waves. */\n gust: Node<'float'>;\n /** Strength × trunk height × gust. */\n scale: Node<'float'>;\n}\n\nfunction windMotion(wind: WindSource, response: WindResponse, frame: WindFrame): WindMotion {\n const r = response.uniforms;\n const t = (frame.time ?? wind.uniforms.time).mul(r.frequency).add(frame.phase ?? r.phase);\n const direction = (frame.direction ?? objectWindDirection(wind)).normalize();\n const gust = sin(t.mul(0.37)).add(sin(t.mul(0.91).add(1.7))).mul(0.1).add(0.8);\n return { t, direction, gust, scale: wind.uniforms.strength.mul(r.height).mul(gust) };\n}\n\n/** The Wind Bursts' push in the tree's space (× {@link BURST_BEND}). */\nfunction burstMotion(wind: WindSource, frame: WindFrame): Node<'vec3'> {\n const { origin, toTree } = frame.burst || objectBurstFrame();\n const push = windBurstPush(wind, origin, frame.time);\n return toTree(vec3(push.x, 0, push.y)).mul(BURST_BEND);\n}\n\n/** The trunk and branch bend of a Wind Burst push (tree space): like the Wind's lean, without its swing. */\nfunction burstSway(push: Node<'vec3'>, response: WindResponse, trunk: Node<'float'>, branches: Node<'float'>): Node<'vec3'> {\n const r = response.uniforms;\n const weight = r.trunk.mul(trunk).mul(TRUNK_AMPLITUDE).add(r.branches.mul(branches).mul(BRANCH_AMPLITUDE));\n return push.mul(weight.mul(r.height));\n}\n\n/** Trunk and branch sway weights (as `aWind.x`, `aWind.y`) and the branch's spatial phase. */\ninterface SwayWeights {\n trunk: Node<'float'>;\n branches: Node<'float'>;\n spatialPhase: Node<'float'>;\n}\n\nfunction swayOffset({ t, direction, scale }: WindMotion, response: WindResponse, weights: SwayWeights): Node<'vec3'> {\n const r = response.uniforms;\n const across = cross(direction, vec3(0, 1, 0));\n const trunkSwing = sin(t.mul(1.1)).mul(0.25).add(0.75); // 0.5 .. 1: lean plus swing\n const trunk = direction.mul(trunkSwing.mul(r.trunk).mul(weights.trunk).mul(scale).mul(TRUNK_AMPLITUDE));\n\n const branchSwing = sin(t.mul(2.3).add(weights.spatialPhase)).mul(0.35).add(0.65); // 0.3 .. 1\n const branchCross = sin(t.mul(1.7).add(weights.spatialPhase.mul(1.3))).mul(0.3);\n const branches = direction\n .mul(branchSwing)\n .add(across.mul(branchCross))\n .mul(r.branches.mul(weights.branches).mul(scale).mul(BRANCH_AMPLITUDE));\n return trunk.add(branches);\n}\n\n/** Branch sway of a whole crown as one: about the mean of `aWind.y` over a crown. */\nconst CROWN_BRANCH_SWAY = 0.5;\n\n/**\n * TSL node: the Wind displacement (vec3, the tree's space) of a whole tree drawn as one picture (an\n * Impostor card), at the tree-space point `point`: the trunk sway of its height (as `aWind.x`:\n * (height / trunk height)², clamped), with the crown's branches swinging along as one. No leaf flutter.\n */\nexport function treeSwayOffset(wind: WindSource, response: WindResponse, point: Node<'vec3'>, frame: WindFrame = {}): Node<'vec3'> {\n const h = point.y.div(response.uniforms.height.max(1e-6)).clamp(0, 1);\n const trunk = h.mul(h);\n const branches = trunk.mul(CROWN_BRANCH_SWAY);\n const motion = windMotion(wind, response, frame);\n const sway = swayOffset(motion, response, { trunk, branches, spatialPhase: float(0) });\n if (frame.burst === false) return sway;\n return withWindBursts(wind, sway, () => sway.add(burstSway(burstMotion(wind, frame), response, trunk, branches)));\n}\n\n/**\n * Adds a Wind offset to a material's vertex position (its existing `positionNode`, or the plain\n * local position). The shadow pass reuses `positionNode`, so shadows sway along.\n */\nexport function applyWind(material: NodeMaterial, offset: Node<'vec3'>): void {\n material.positionNode = material.positionNode ? (material.positionNode as Node<'vec3'>).add(offset) : positionLocal.add(offset);\n material.needsUpdate = true;\n}\n","import type { Node, NodeBuilder } from 'three/webgpu';\nimport { attribute, bool, cross, Fn, instanceIndex, modelWorldMatrix, normalLocal, positionGeometry, positionLocal, vec4 } from 'three/tsl';\nimport { growthPosition } from '../growth';\nimport { objectBurstFrame, objectWindDirection, windOffset, type WindBurstFrame, type WindResponse, type WindSource } from '../wind';\nimport { setWindMotion } from '../wind/motion';\n\n/**\n * Per-instance data of a Forest (one interleaved instanced buffer, 8 floats per tree):\n * `iRotation` = the tree's rotation as a quaternion (x, y, z, w);\n * `iState` = (scale, Growth, Season, Wind phase), Growth/Season already include the tree's offsets.\n */\nexport const INSTANCE_STRIDE = 8;\nexport const INSTANCE_ATTRIBUTES = { iRotation: 0, iState: 4 } as const;\n\n/**\n * What a mesh that draws one Detail Level of a Variant (ADR 0010) reads instead of the instanced\n * attributes: the tree's data by slot, the slot coming from the level list at `instanceIndex`.\n */\nexport interface LevelInstance {\n /** The tree's slot in the Variant (`uint`). */\n slot: Node<'uint'>;\n /** As `iRotation`. */\n rotation: Node<'vec4'>;\n /** As `iState`. */\n state: Node<'vec4'>;\n /** The tree's base in forest space. */\n position: Node<'vec3'>;\n /** The tree's cross-fade mask at this level (`bool`: draw this fragment), see `levelDither`. */\n visible: Node<'bool'>;\n}\n\n// Which mesh draws a Detail Level, and from where. Looked up when a material is built for an object,\n// so the Variant's materials serve its instanced meshes and its Detail Level meshes alike.\nconst levelInstances = new WeakMap<object, LevelInstance>();\n\n/** @internal Marks `mesh` as drawing a Detail Level: every Forest node built for it reads `instance`. */\nexport function drawsDetailLevel(mesh: object, instance: LevelInstance): void {\n levelInstances.set(mesh, instance);\n}\n\nfunction levelInstanceOf(builder: NodeBuilder): LevelInstance | undefined {\n const object = builder.object as object | null | undefined;\n return object ? levelInstances.get(object) : undefined;\n}\n\n/**\n * A node that is `level(instance)` on a Detail Level mesh and `instanced()` on anything else (the\n * Variant's instanced meshes), decided when the material is built for the drawn object.\n */\nfunction perInstance<T extends Node>(instanced: () => T, level: (instance: LevelInstance) => T): T {\n return Fn((builder: NodeBuilder) => {\n const instance = levelInstanceOf(builder);\n return instance ? level(instance) : instanced();\n })() as unknown as T;\n}\n\n/** The tree's quaternion. */\nfunction instanceRotation(): Node<'vec4'> {\n return perInstance(\n () => attribute<'vec4'>('iRotation', 'vec4'),\n (instance) => instance.rotation,\n );\n}\n\n/** Per-tree values in the instanced Season/Growth/Wind slots. */\nexport function instanceState(): { scale: Node<'float'>; growth: Node<'float'>; season: Node<'float'>; windPhase: Node<'float'> } {\n const state = perInstance(\n () => attribute<'vec4'>('iState', 'vec4'),\n (instance) => instance.state,\n );\n return { scale: state.x, growth: state.y, season: state.z, windPhase: state.w };\n}\n\n/** The tree's slot in its Variant (`uint`): the instance index on the instanced meshes, from the level list on a Detail Level mesh. */\nexport function instanceSlot(): Node<'uint'> {\n return perInstance(\n () => instanceIndex as unknown as Node<'uint'>,\n (instance) => instance.slot,\n );\n}\n\n/** Whether to draw this fragment: the Detail Level cross-fade (always true on the instanced meshes). */\nexport function levelVisible(): Node<'bool'> {\n return perInstance(\n () => bool(true),\n (instance) => instance.visible,\n );\n}\n\n/**\n * The tree's base in forest space, on a Detail Level mesh (the Impostor card places itself from it).\n * Throws when built for any other object: the instanced meshes get their position from three.js.\n */\nexport function levelTreePosition(): Node<'vec3'> {\n return perInstance(\n () => {\n throw new Error('levelTreePosition() only works on a Detail Level mesh');\n },\n (instance) => instance.position,\n );\n}\n\n/**\n * The tree's base in forest space, on the instanced meshes and the Detail Level meshes alike, as the\n * vertex stage knows it before `positionNode` runs. On an InstancedMesh three.js only hands over the\n * placed vertex (M·p), so the base is M·p − R·s·p, kept in a variable so that it is worked out before\n * `positionNode` replaces `positionLocal`; on a Detail Level mesh it is the tree's data.\n */\nexport function instanceTreeBase(): Node<'vec3'> {\n return perInstance(\n () => positionLocal.sub(instanceRotate(positionGeometry).mul(instanceState().scale)).toVar(),\n (instance) => instance.position,\n );\n}\n\n/** Rotates `v` by the quaternion `q` (`inverse` = by its conjugate). */\nexport function rotateByQuaternion(q: Node<'vec4'>, v: Node<'vec3'>, inverse = false): Node<'vec3'> {\n const u = inverse ? q.xyz.negate() : q.xyz;\n const t = cross(u, v).mul(2);\n return v.add(t.mul(q.w)).add(cross(u, t));\n}\n\n/** Rotates `v` by the instance quaternion (`inverse` = by its conjugate): tree space to forest space. */\nexport function instanceRotate(v: Node<'vec3'>, inverse = false): Node<'vec3'> {\n return rotateByQuaternion(instanceRotation(), v, inverse);\n}\n\n/**\n * The tree's vertex placed in forest space without Growth or Wind (M·p). On an InstancedMesh three.js\n * already applied the instance matrix to `positionLocal` (and the normal). A Detail Level mesh is not\n * instanced by three, so this places the vertex from the tree's data and turns the normal with it.\n */\nfunction placedPosition(): Node<'vec3'> {\n return perInstance(\n () => positionLocal,\n (instance) => {\n normalLocal.assign(rotateByQuaternion(instance.rotation, normalLocal));\n return instance.position.add(rotateByQuaternion(instance.rotation, positionGeometry).mul(instance.state.x));\n },\n );\n}\n\n/**\n * Where a Wind Burst finds a Forest tree: its own base (through the Forest's transform) and its own\n * rotation, so each instance bends away from the burst point like a single Tree does.\n */\nexport function instanceBurstFrame(): WindBurstFrame {\n const forest = objectBurstFrame();\n return {\n origin: modelWorldMatrix.mul(vec4(instanceTreeBase(), 1)).xz,\n toTree: (world) => instanceRotate(forest.toTree(world), true),\n };\n}\n\n/**\n * The vertex position of a Forest tree (positionNode of an instanced Variant mesh).\n *\n * On an InstancedMesh, three.js applies the instance matrix to `positionLocal` before\n * `positionNode` runs, but Growth and Wind are defined in the tree's own space (about the\n * generated `aOrigin`s, relative to its trunk height). So both are computed from\n * `positionGeometry`, and only their displacement is turned into forest space with the\n * instance rotation and scale: M·(p + d) = M·p + R·s·d. The Wind direction goes the other way\n * (forest -> tree space) and each tree sways with its own phase.\n *\n * `base`: the tree-space position Growth starts from (default `positionGeometry`); Fruit passes\n * its Season-scaled position here.\n */\nexport function forestPosition(wind: WindSource, response: WindResponse, base: Node<'vec3'> = positionGeometry): Node<'vec3'> {\n const { scale, growth, windPhase } = instanceState();\n const grown = growthPosition(growth, base);\n // One frame for now and the previous Wind time: both read the same tree base.\n const burst = instanceBurstFrame();\n const offsetAt = (time?: Node<'float'>) =>\n windOffset(wind, response, { direction: instanceRotate(objectWindDirection(wind), true), phase: windPhase, time, burst });\n const offset = offsetAt();\n const displacement = grown.add(offset).sub(positionGeometry);\n const position = placedPosition().add(instanceRotate(displacement).mul(scale));\n // Wind-aware velocity (ADR 0011): each instance's own phase at the previous Wind time. Detail Level\n // meshes draw with these same materials (and per-tree nodes), so they get it too.\n setWindMotion(position, {\n source: wind,\n shift: (previous) => instanceRotate(offsetAt(previous).sub(offset)).mul(scale),\n offset: instanceRotate(offset).mul(scale),\n });\n return position;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,IAAa,gBAAgB;;AAE7B,IAAa,oBAAoB;;AAEjC,IAAa,aAAa;AAE1B,IAAa,aAAa,WAA2B,gBAAiB,KAAqB;AAC3F,IAAaA,eAAa,WAA2B,oBAAqB,KAAyB;;AAGnG,SAAgBC,eAAa,QAAgB,OAAe,KAAqB;CAC/E,MAAM,IAAI,KAAK,IAAI,KAAK,KAAK,SAAS,OAAO,KAAK,IAAI,MAAM,OAAO,UAAU,IAAI,GAAG,CAAC,GAAG,CAAC;CACzF,OAAO,IAAI,KAAK,IAAI,IAAI;AAC1B;;AAGA,SAAgB,YAAY,QAAwB;CAClD,OAAO,OAAO,MAAM,MAAM,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,QAAQ,CAAC,GAAG,CAAC;AACnE;;;;;AAMA,SAAgB,cAAc,SAA0B,QAA8B;CACpF,MAAM,IAAI,YAAY,MAAM;CAC5B,MAAM,EAAE,WAAW,YAAY;CAC/B,MAAM,EAAE,SAAS,YAAY,QAAQ;CACrC,MAAM,MAAM,IAAI,aAAa,UAAU,MAAM;CAC7C,MAAM,QAAQ,UAAU,CAAC;CACzB,MAAM,OAAO,IAAID,YAAU,CAAC;CAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,SAAS,GAAG,KAAK;EAC7C,MAAM,CAAC,OAAO,KAAK,UAAU;GAAC,QAAQ,MAAM,IAAI;GAAK,QAAQ,MAAM,IAAI,IAAI;GAAK,QAAQ,MAAM,IAAI,IAAI;EAAG;EACzG,MAAM,SAAS,IAAIC,eAAa,GAAG,OAAO,GAAG;EAC7C,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GAC1B,MAAM,IAAI,IAAI,IAAI;GAClB,MAAM,QA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CAAC,CAAC,CAAC,CAAC;EAC1D,SAAS,UAAU,eAAe,OAAO,OAAO,KAAK,GAAG,IAAI;CAC9D;AACF;;;;;;;;;;;;;;AAeA,SAAgB,eAAe,MAAkB,UAAwB,OAAqB,kBAAgC;CAC5H,MAAM,EAAE,OAAO,QAAQ,cAAc,cAAc;CACnD,MAAM,QAAQ,eAAe,QAAQ,IAAI;CAEzC,MAAM,QAAQ,mBAAmB;CACjC,MAAM,YAAY,SAChB,WAAW,MAAM,UAAU;EAAE,WAAW,eAAe,oBAAoB,IAAI,GAAG,IAAI;EAAG,OAAO;EAAW;EAAM;CAAM,CAAC;CAC1H,MAAM,SAAS,SAAS;CACxB,MAAM,eAAe,MAAM,IAAI,MAAM,CAAC,CAAC,IAAI,gBAAgB;CAC3D,MAAM,WAAW,eAAe,CAAC,CAAC,IAAI,eAAe,YAAY,CAAC,CAAC,IAAI,KAAK,CAAC;CAG7E,cAAc,UAAU;EACtB,QAAQ;EACR,QAAQ,aAAa,eAAe,SAAS,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK;EAC7E,QAAQ,eAAe,MAAM,CAAC,CAAC,IAAI,KAAK;CAC1C,CAAC;CACD,OAAO;AACT"}
|
package/dist/react/Forest.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ import type { TreeStyle } from '../styles/types';
|
|
|
5
5
|
import type { StyleName } from '../styles/registry';
|
|
6
6
|
import { type Forest as ForestObject } from '../forest';
|
|
7
7
|
import { type ForestPlacement } from '../forest/placement';
|
|
8
|
+
import type { ForestLodOptions } from '../forest/lod';
|
|
8
9
|
import { type Wind as WindObject } from '../wind';
|
|
10
|
+
import type { TreeShaderHooks } from '../materials/shader-hooks';
|
|
9
11
|
type GroupProps = Omit<ThreeElements['group'], 'args' | 'object' | 'children' | 'ref' | 'castShadow' | 'receiveShadow' | 'dispose'>;
|
|
10
12
|
/** Where one tree of a `<Forest>` stands, optionally with its own Growth and Season. */
|
|
11
13
|
export interface ForestTreePlacement extends ForestPlacement {
|
|
@@ -36,6 +38,17 @@ export interface ForestProps extends GroupProps {
|
|
|
36
38
|
season?: number;
|
|
37
39
|
/** The Wind the forest sways with. Default: the scene-wide `sceneWind` (what `<Wind>` sets). */
|
|
38
40
|
wind?: WindObject;
|
|
41
|
+
/**
|
|
42
|
+
* Detail Levels (ADR 0010), as `createForest`'s `lod`: `true` for the automatic distances, or the
|
|
43
|
+
* distances. Switching it on or off, or a new `impostorAtlas` or `lightDefinition` (by value),
|
|
44
|
+
* rebuilds the forest; new `light`, `impostor`, `fade` or `camera` only write `forest.lod`.
|
|
45
|
+
*/
|
|
46
|
+
lod?: boolean | ForestLodOptions;
|
|
47
|
+
/**
|
|
48
|
+
* The Tree Shader Hooks of every tree in the forest, at every Detail Level (as `forest.shaderHooks`),
|
|
49
|
+
* stacked after the scene-wide ones. Keep hooks stable (module scope or `useMemo`). Unset: none.
|
|
50
|
+
*/
|
|
51
|
+
shaderHooks?: TreeShaderHooks;
|
|
39
52
|
/** Whether the trees cast shadows. Default true. */
|
|
40
53
|
castShadow?: boolean;
|
|
41
54
|
/** Whether the trees receive shadows. Default true. */
|
|
@@ -45,10 +58,11 @@ export interface ForestProps extends GroupProps {
|
|
|
45
58
|
}
|
|
46
59
|
/**
|
|
47
60
|
* Many trees of one Definition, drawn instanced (a `Forest`). Changing `placements` plants or cuts
|
|
48
|
-
* only the affected trees; Growth, Season, Wind and shadow props only update instance data, uniforms
|
|
49
|
-
* and meshes
|
|
61
|
+
* only the affected trees; Growth, Season, Wind, Tree Shader Hook and shadow props only update instance data, uniforms
|
|
62
|
+
* and meshes; changing `lod` distances, fade or camera only writes `forest.lod`. A new `definition`
|
|
63
|
+
* (by value), `style`/`form`, `variants`, `seed`, or switching `lod` on or off rebuilds the forest.
|
|
50
64
|
* The forest is disposed of on unmount.
|
|
51
65
|
*/
|
|
52
|
-
export declare function Forest({ definition, style, form, variants, seed, placements, growth, season, wind, castShadow, receiveShadow, ref, ...groupProps }: ForestProps): import("react").JSX.Element;
|
|
66
|
+
export declare function Forest({ definition, style, form, variants, seed, placements, growth, season, wind, shaderHooks, castShadow, receiveShadow, lod, ref, ...groupProps }: ForestProps): import("react").JSX.Element;
|
|
53
67
|
export {};
|
|
54
68
|
//# sourceMappingURL=Forest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Forest.d.ts","sourceRoot":"","sources":["../../src/react/Forest.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAgB,KAAK,MAAM,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"Forest.d.ts","sourceRoot":"","sources":["../../src/react/Forest.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAgB,KAAK,MAAM,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,qB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ACvD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;CACzB;AAsDD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,EACrB,UAAU,EACV,KAAK,EACL,IAAkB,EAClB,QAAY,EACZ,IAAQ,EACR,UAAU,EACV,MAAU,EACV,MAAU,EACV,IAAI,EACJ,WAAW,EACX,UAAiB,EACjB,aAAoB,EACpB,GAAG,EACH,GAAG,EACH,GAAG,UAAU,EACd,EAAE,WAAW,+BAwDb"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ReactNode, type Ref, type RefObject } from 'react';
|
|
2
|
+
import type { Light, Object3D } from 'three/webgpu';
|
|
3
|
+
import type { ScenePipeline as ScenePipelineObject, ScenePipelineChoice } from '../scene';
|
|
4
|
+
import type { CustomTreeEffect } from '../effects';
|
|
5
|
+
import type { ForestTree } from '../forest';
|
|
6
|
+
import type { Tree } from '../tree';
|
|
7
|
+
/** Starts loading the Scene Pipeline module ahead of time, without suspending. */
|
|
8
|
+
export declare function preloadScenePipeline(): void;
|
|
9
|
+
export interface ScenePipelineProps extends ScenePipelineChoice {
|
|
10
|
+
/** A shadow-casting light for god rays, or a ref to one (e.g. a JSX `<directionalLight ref={sun}>`). Never changed. */
|
|
11
|
+
sun?: Light | RefObject<Light | null>;
|
|
12
|
+
/** The trees to outline. Default: every tree. A new array rebuilds the pipeline. */
|
|
13
|
+
selection?: Object3D[];
|
|
14
|
+
/** Keeps the Tree ID channel on, for `pick()`. */
|
|
15
|
+
treeId?: boolean;
|
|
16
|
+
/** The trees the Highlight marks (no rebuild when it changes). */
|
|
17
|
+
highlighted?: (Tree | ForestTree)[];
|
|
18
|
+
/** Keeps the Wind-aware velocity channel on (`scenePass.velocity`). */
|
|
19
|
+
velocity?: boolean;
|
|
20
|
+
/** Receives the tree.js `ScenePipeline` (`null` until it is built and after unmount). */
|
|
21
|
+
ref?: Ref<ScenePipelineObject | null>;
|
|
22
|
+
/** Children can reach the pipeline with {@link useScenePipeline}. */
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `ScenePipeline` of the nearest enclosing `<ScenePipeline>` (e.g. to call `pick()`), or `null`
|
|
27
|
+
* outside one and before it is built (the render after it mounts).
|
|
28
|
+
*/
|
|
29
|
+
export declare function useScenePipeline(): ScenePipelineObject | null;
|
|
30
|
+
/**
|
|
31
|
+
* Renders the R3F scene through a Scene Pipeline (`@casmo/tree.js/scene`): the Style's suggested Tree
|
|
32
|
+
* Effects and Scene Effects, or your own. Takes over rendering (`useFrame` at priority 1), follows the
|
|
33
|
+
* camera, calls `set()` when `style`/`treeEffects`/`sceneEffects` change, and disposes of the pipeline
|
|
34
|
+
* on unmount (which gives `scene.fogNode` back). Loads the scene module on first use: suspends.
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <Canvas><ScenePipeline style="stylized" sun={sun} />...</Canvas>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function ScenePipeline({ style, treeEffects, sceneEffects, sun, selection, treeId, highlighted, velocity, ref, children }: ScenePipelineProps): import("react").JSX.Element;
|
|
41
|
+
export interface TreeEffectProps<Options> {
|
|
42
|
+
/**
|
|
43
|
+
* The app's own Tree Effect (`CustomTreeEffect` from `@casmo/tree.js/effects`). Keep it stable (module
|
|
44
|
+
* scope or `useMemo`): another effect object is removed and added again (a new graph).
|
|
45
|
+
*/
|
|
46
|
+
effect: CustomTreeEffect<Options>;
|
|
47
|
+
/** Its options. Compared by value: new options go through the effect's `update()` (no new graph, no recompile). */
|
|
48
|
+
options?: Options;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adds a custom Tree Effect to the enclosing `<ScenePipeline>` while mounted (`pipeline.addEffect`), at
|
|
52
|
+
* the place its `before` names (`'end'`: after the Highlight); several at the same place run in the order they mounted. New `options`
|
|
53
|
+
* only call `updateEffect`, it stays through Style and settings changes and goes into a rebuilt pipeline,
|
|
54
|
+
* and it is removed on unmount. Renders nothing; does nothing outside a `<ScenePipeline>`.
|
|
55
|
+
*
|
|
56
|
+
* ```tsx
|
|
57
|
+
* <ScenePipeline style="stylized">
|
|
58
|
+
* <TreeEffect effect={foliage} options={{ strength: 0.5 }} />
|
|
59
|
+
* </ScenePipeline>
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function TreeEffect<Options>({ effect, options }: TreeEffectProps<Options>): null;
|
|
63
|
+
//# sourceMappingURL=ScenePipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScenePipeline.d.ts","sourceRoot":"","sources":["../../src/react/ScenePipeline.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,SAAS,EACd,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAY,MAAM,cAAc,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,IAAI,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAepC,kFAAkF;AAClF,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,uHAAuH;IACvH,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACtC,oFAAoF;IACpF,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,kDAAkD;IAClD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kEAAkE;IAClE,WAAW,CAAC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