@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TreeShaderHooks } from '../materials/shader-hooks';
|
|
2
|
+
/**
|
|
3
|
+
* @internal Adds `hooks` to the scene-wide default Tree Shader Hooks while the calling component is
|
|
4
|
+
* mounted (after the ones the scene had, and the ones of components mounted earlier). Only a change of a
|
|
5
|
+
* part's hooks rebuilds that part's node graphs. The last one to unmount puts back what it found.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useSceneShaderHooks(hooks: TreeShaderHooks | null): void;
|
|
8
|
+
export interface SceneShaderHooksProps {
|
|
9
|
+
/**
|
|
10
|
+
* Tree Shader Hooks every `<Tree>` and `<Forest>` (and every Tree and Forest made outside React) runs,
|
|
11
|
+
* before its own. Keep hooks stable (module scope or `useMemo`): a new function is a new hook.
|
|
12
|
+
*/
|
|
13
|
+
hooks: TreeShaderHooks;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Declares scene-wide default Tree Shader Hooks (`setSceneShaderHooks`). Renders nothing. Several stack in
|
|
17
|
+
* the order they mounted, after the hooks the scene had before; when the last one unmounts, those are put
|
|
18
|
+
* back. Changing `hooks` only rebuilds the node graphs of the parts whose hooks changed, once.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <SceneShaderHooks hooks={{ leaves: frosty }} />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function SceneShaderHooks({ hooks }: SceneShaderHooksProps): null;
|
|
25
|
+
//# sourceMappingURL=SceneShaderHooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneShaderHooks.d.ts","sourceRoot":"","sources":["../../src/react/SceneShaderHooks.tsx"],"names":[],"mappings":"AACA,OAAO,EAA8D,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAgB7H;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAoBvE;AAED,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,KAAK,EAAE,eAAe,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE,qBAAqB,GAAG,IAAI,CAGvE"}
|
package/dist/react/Tree.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { TreeStyle } from '../styles/types';
|
|
|
6
6
|
import type { StyleName } from '../styles/registry';
|
|
7
7
|
import { type Tree as TreeObject } from '../tree';
|
|
8
8
|
import { type Wind as WindObject } from '../wind';
|
|
9
|
+
import type { TreeShaderHooks } from '../materials/shader-hooks';
|
|
9
10
|
type GroupProps = Omit<ThreeElements['group'], 'args' | 'object' | 'children' | 'ref' | 'castShadow' | 'receiveShadow' | 'dispose'>;
|
|
10
11
|
export interface TreeProps extends GroupProps {
|
|
11
12
|
/** The Tree Definition to grow (plain object or parsed JSON). Takes precedence over `style`. */
|
|
@@ -27,6 +28,12 @@ export interface TreeProps extends GroupProps {
|
|
|
27
28
|
season?: number;
|
|
28
29
|
/** The Wind this tree sways with. Default: the scene-wide `sceneWind` (what `<Wind>` sets). */
|
|
29
30
|
wind?: WindObject;
|
|
31
|
+
/**
|
|
32
|
+
* The tree's own Tree Shader Hooks (as `tree.shaderHooks`), which stack after the scene-wide ones
|
|
33
|
+
* (`<SceneShaderHooks>`, `<SnowCover>`, `<Wetness>`). Only the parts whose hooks change rebuild their
|
|
34
|
+
* node graph; keep hooks stable (module scope or `useMemo`), as a new function is a new hook. Unset: none.
|
|
35
|
+
*/
|
|
36
|
+
shaderHooks?: TreeShaderHooks;
|
|
30
37
|
/** Whether the tree casts shadows. Default true. */
|
|
31
38
|
castShadow?: boolean;
|
|
32
39
|
/** Whether the tree receives shadows. Default true. */
|
|
@@ -35,10 +42,10 @@ export interface TreeProps extends GroupProps {
|
|
|
35
42
|
ref?: Ref<TreeObject>;
|
|
36
43
|
}
|
|
37
44
|
/**
|
|
38
|
-
* A procedural tree. Growth, Season, Wind and shadow props only update the existing tree; a new
|
|
45
|
+
* A procedural tree. Growth, Season, Wind, Tree Shader Hook and shadow props only update the existing tree; a new
|
|
39
46
|
* `seed`, `definition` (by value) or `style`/`form`/`species` regenerates it. The tree is disposed
|
|
40
47
|
* of on unmount.
|
|
41
48
|
*/
|
|
42
|
-
export declare function Tree({ definition, style, form, species, seed, growth, season, wind, castShadow, receiveShadow, ref, ...groupProps }: TreeProps): import("react").JSX.Element;
|
|
49
|
+
export declare function Tree({ definition, style, form, species, seed, growth, season, wind, shaderHooks, castShadow, receiveShadow, ref, ...groupProps }: TreeProps): import("react").JSX.Element;
|
|
43
50
|
export {};
|
|
44
51
|
//# sourceMappingURL=Tree.d.ts.map
|
package/dist/react/Tree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../src/react/Tree.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,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAc,KAAK,IAAI,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAa,KAAK,IAAI,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../src/react/Tree.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,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAc,KAAK,IAAI,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAa,KAAK,IAAI,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAGjE,KAAK,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,YAAY,GAAG,eAAe,GAAG,SAAS,CAAC,CAAC;AAEpI,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C,gGAAgG;IAChG,UAAU,CAAC,EAAE,mBAAmB,GAAG,cAAc,CAAC;IAClD;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9B,+DAA+D;IAC/D,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,yHAAyH;IACzH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,6GAA6G;IAC7G,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uDAAuD;IACvD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6DAA6D;IAC7D,GAAG,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;CACvB;AAKD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,EACnB,UAAU,EACV,KAAK,EACL,IAAkB,EAClB,OAAO,EACP,IAAQ,EACR,MAAU,EACV,MAAU,EACV,IAAI,EACJ,WAAW,EACX,UAAiB,EACjB,aAAoB,EACpB,GAAG,EACH,GAAG,UAAU,EACd,EAAE,SAAS,+BAgDX"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Ref } from 'react';
|
|
2
|
+
import type { Snow, SnowCoverHooks, SnowCoverSettings, Wetness as WetnessAmount, WetnessHooks, WetnessSettings } from '../weather';
|
|
3
|
+
/** Starts loading the weather module (Snow Cover, Wetness) ahead of time, without suspending. */
|
|
4
|
+
export declare function preloadWeather(): void;
|
|
5
|
+
export interface SnowCoverProps extends SnowCoverSettings {
|
|
6
|
+
/** The snow amount, 0 (none) .. 1 (full cover): written to `snow`. Unset: leave as is (default 0). */
|
|
7
|
+
amount?: number;
|
|
8
|
+
/** The `Snow` the hooks follow and `amount` drives. Default: the scene-wide `sceneSnow`. A new one makes new hooks. */
|
|
9
|
+
snow?: Snow;
|
|
10
|
+
/** Receives the ready-made Snow Cover hooks (`SnowCoverHooks`), e.g. to also hand them to a `<Tree shaderHooks>`. */
|
|
11
|
+
ref?: Ref<SnowCoverHooks | null>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Declares Snow Cover (`@casmo/tree.js/weather`): while mounted, every tree runs the ready-made Snow Cover
|
|
15
|
+
* hooks as scene-wide Tree Shader Hooks (before the app's own), whitening surfaces that face up by `amount`.
|
|
16
|
+
* Renders nothing. `amount` and the settings are uniform writes (no rebuild); an unset setting is its
|
|
17
|
+
* default. On unmount the hooks are removed and the amount it found is put back. Loads the weather module
|
|
18
|
+
* on first use: suspends.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <SnowCover amount={0.8} slope={60} />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function SnowCover({ amount, snow, ref, ...settings }: SnowCoverProps): null;
|
|
25
|
+
export interface WetnessProps extends WetnessSettings {
|
|
26
|
+
/** The wetness amount, 0 (dry) .. 1 (soaked): written to `wetness`. Unset: leave as is (default 0). */
|
|
27
|
+
amount?: number;
|
|
28
|
+
/** The `Wetness` the hooks follow and `amount` drives. Default: the scene-wide `sceneWetness`. A new one makes new hooks. */
|
|
29
|
+
wetness?: WetnessAmount;
|
|
30
|
+
/** Receives the ready-made Wetness hooks (`WetnessHooks`), e.g. to also hand them to a `<Tree shaderHooks>`. */
|
|
31
|
+
ref?: Ref<WetnessHooks | null>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Declares Wetness (`@casmo/tree.js/weather`): while mounted, every tree runs the ready-made Wetness hooks
|
|
35
|
+
* as scene-wide Tree Shader Hooks (before the app's own): darker, with a sheen, by `amount`. Renders
|
|
36
|
+
* nothing. `amount` and the settings are uniform writes (no rebuild); an unset setting is its default. On
|
|
37
|
+
* unmount the hooks are removed and the amount it found is put back. Loads the weather module on first
|
|
38
|
+
* use: suspends.
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <Wetness amount={0.6} sheen={0.7} />
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function Wetness({ amount, wetness, ref, ...settings }: WetnessProps): null;
|
|
45
|
+
//# sourceMappingURL=Weather.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Weather.d.ts","sourceRoot":"","sources":["../../src/react/Weather.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsD,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAGrF,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,iBAAiB,EACjB,OAAO,IAAI,aAAa,EACxB,YAAY,EACZ,eAAe,EAChB,MAAM,YAAY,CAAC;AAiBpB,iGAAiG;AACjG,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAqDD,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACvD,sGAAsG;IACtG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uHAAuH;IACvH,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,qHAAqH;IACrH,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CAClC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,EAAE,cAAc,GAAG,IAAI,CAMlF;AAED,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,uGAAuG;IACvG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6HAA6H;IAC7H,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,gHAAgH;IAChH,GAAG,CAAC,EAAE,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,EAAE,YAAY,GAAG,IAAI,CAMjF"}
|
package/dist/react/Wind.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Wind as WindObject, type WindDirection } from '../wind';
|
|
1
|
+
import { type Wind as WindObject, type WindBurstOptions, type WindDirection } from '../wind';
|
|
2
2
|
export interface WindProps {
|
|
3
3
|
/** World-space direction the wind blows towards (any non-zero length). Unset: leave as is (default +X). */
|
|
4
4
|
direction?: WindDirection;
|
|
@@ -14,4 +14,15 @@ export interface WindProps {
|
|
|
14
14
|
* direction, strength and clock it found when it unmounts.
|
|
15
15
|
*/
|
|
16
16
|
export declare function Wind({ direction, strength, time, wind }: WindProps): null;
|
|
17
|
+
/**
|
|
18
|
+
* A function that triggers a Wind Burst (`wind.burst()`) on `wind` (default the scene-wide `sceneWind`):
|
|
19
|
+
* trees near the ground point bend away from it and settle within 1.2 s. Stable for the same Wind, so it
|
|
20
|
+
* is safe in event handlers and effect deps. Only uniform writes.
|
|
21
|
+
*
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const burst = useWindBurst();
|
|
24
|
+
* <mesh onClick={(e) => burst({ x: e.point.x, z: e.point.z, strength: 1 })} />
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useWindBurst(wind?: WindObject): (options: WindBurstOptions) => void;
|
|
17
28
|
//# sourceMappingURL=Wind.d.ts.map
|
package/dist/react/Wind.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wind.d.ts","sourceRoot":"","sources":["../../src/react/Wind.tsx"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,IAAI,IAAI,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Wind.d.ts","sourceRoot":"","sources":["../../src/react/Wind.tsx"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,IAAI,IAAI,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAExG,MAAM,WAAW,SAAS;IACxB,2GAA2G;IAC3G,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,wFAAwF;IACxF,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAW,EAAE,IAAgB,EAAE,EAAE,SAAS,GAAG,IAAI,CAyB5F;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,UAAsB,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAE9F"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { Tree, type TreeProps } from './Tree';
|
|
2
|
-
export { Wind, type WindProps } from './Wind';
|
|
2
|
+
export { Wind, useWindBurst, type WindProps } from './Wind';
|
|
3
|
+
export type { WindBurstOptions } from '../wind';
|
|
3
4
|
export { useTreeStyle, preloadTreeStyle } from './useTreeStyle';
|
|
4
5
|
export type { StyleName } from '../styles/registry';
|
|
5
6
|
export { Forest, type ForestProps, type ForestTreePlacement } from './Forest';
|
|
7
|
+
export { ScenePipeline, TreeEffect, useScenePipeline, preloadScenePipeline, type ScenePipelineProps, type TreeEffectProps } from './ScenePipeline';
|
|
8
|
+
export type { CustomTreeEffect } from '../effects';
|
|
9
|
+
export { SceneShaderHooks, type SceneShaderHooksProps } from './SceneShaderHooks';
|
|
10
|
+
export type { TreeShaderHook, TreeShaderHooks, TreeShaderInput, TreeShaderOutput } from '../materials/shader-hooks';
|
|
11
|
+
export { SnowCover, Wetness, preloadWeather, type SnowCoverProps, type WetnessProps } from './Weather';
|
|
6
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnJ,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAClF,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACpH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as forestTreeKey, c as loadStyle, l as createTree, q as wrapSeason, t as createForest } from "./forest-CM5DrklM.js";
|
|
2
|
+
import { l as sceneWind } from "./motion-Qd7xjeZM.js";
|
|
3
|
+
import { _ as clampGrowth } from "./nodes-DxgTyF9B.js";
|
|
4
|
+
import { o as setSceneShaderHooks, r as getSceneShaderHooks, s as stackShaderHooks } from "./shader-hooks-BFRtlWGI.js";
|
|
5
|
+
import { createContext, use, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { useFrame, useThree } from "@react-three/fiber";
|
|
4
8
|
// src/react/useTreeStyle.ts
|
|
5
9
|
var cache = /* @__PURE__ */ new Map();
|
|
6
10
|
function styleResource(name) {
|
|
@@ -32,11 +36,11 @@ function preloadTreeStyle(name) {
|
|
|
32
36
|
/** Trees this module has disposed of (React StrictMode re-runs effects on the same memoised tree). */
|
|
33
37
|
var disposed$1 = /* @__PURE__ */ new WeakSet();
|
|
34
38
|
/**
|
|
35
|
-
* A procedural tree. Growth, Season, Wind and shadow props only update the existing tree; a new
|
|
39
|
+
* A procedural tree. Growth, Season, Wind, Tree Shader Hook and shadow props only update the existing tree; a new
|
|
36
40
|
* `seed`, `definition` (by value) or `style`/`form`/`species` regenerates it. The tree is disposed
|
|
37
41
|
* of on unmount.
|
|
38
42
|
*/
|
|
39
|
-
function Tree({ definition, style, form = "broadleaf", species, seed = 0, growth = 1, season = 0, wind, castShadow = true, receiveShadow = true, ref, ...groupProps }) {
|
|
43
|
+
function Tree({ definition, style, form = "broadleaf", species, seed = 0, growth = 1, season = 0, wind, shaderHooks, castShadow = true, receiveShadow = true, ref, ...groupProps }) {
|
|
40
44
|
const styleObject = definition === void 0 && typeof style === "string" ? useTreeStyle(style) : style;
|
|
41
45
|
const source = definition ?? (typeof styleObject === "object" ? species ? styleObject.apply(species) : styleObject[form] : void 0);
|
|
42
46
|
if (source === void 0) throw new Error("<Tree> needs a `definition` or a `style`.");
|
|
@@ -46,7 +50,8 @@ function Tree({ definition, style, form = "broadleaf", species, seed = 0, growth
|
|
|
46
50
|
seed,
|
|
47
51
|
wind,
|
|
48
52
|
growth,
|
|
49
|
-
season
|
|
53
|
+
season,
|
|
54
|
+
shaderHooks
|
|
50
55
|
}), [
|
|
51
56
|
key,
|
|
52
57
|
seed,
|
|
@@ -62,6 +67,9 @@ function Tree({ definition, style, form = "broadleaf", species, seed = 0, growth
|
|
|
62
67
|
useLayoutEffect(() => {
|
|
63
68
|
tree.wind = wind ?? sceneWind;
|
|
64
69
|
}, [tree, wind]);
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
tree.shaderHooks = shaderHooks ?? {};
|
|
72
|
+
}, [tree, shaderHooks]);
|
|
65
73
|
useLayoutEffect(() => {
|
|
66
74
|
tree.growth = growth;
|
|
67
75
|
}, [tree, growth]);
|
|
@@ -126,6 +134,19 @@ function Wind({ direction, strength, time = null, wind = sceneWind }) {
|
|
|
126
134
|
}, [wind, time]);
|
|
127
135
|
return null;
|
|
128
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* A function that triggers a Wind Burst (`wind.burst()`) on `wind` (default the scene-wide `sceneWind`):
|
|
139
|
+
* trees near the ground point bend away from it and settle within 1.2 s. Stable for the same Wind, so it
|
|
140
|
+
* is safe in event handlers and effect deps. Only uniform writes.
|
|
141
|
+
*
|
|
142
|
+
* ```tsx
|
|
143
|
+
* const burst = useWindBurst();
|
|
144
|
+
* <mesh onClick={(e) => burst({ x: e.point.x, z: e.point.z, strength: 1 })} />
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
function useWindBurst(wind = sceneWind) {
|
|
148
|
+
return useCallback((options) => void wind.burst(options), [wind]);
|
|
149
|
+
}
|
|
129
150
|
// src/react/Forest.tsx
|
|
130
151
|
/** Forests this module has disposed of (React StrictMode re-runs effects on the same memoised forest). */
|
|
131
152
|
var disposed = /* @__PURE__ */ new WeakSet();
|
|
@@ -154,6 +175,12 @@ function pose(p) {
|
|
|
154
175
|
p.scale ?? 1
|
|
155
176
|
]);
|
|
156
177
|
}
|
|
178
|
+
/** What of `lod` needs a new forest: whether it is on, the Impostor atlas and the Light Definition. */
|
|
179
|
+
function lodBuildKey(lod) {
|
|
180
|
+
if (!lod) return null;
|
|
181
|
+
const options = lod === true ? {} : lod;
|
|
182
|
+
return JSON.stringify([options.impostorAtlas ?? null, options.lightDefinition ?? null]);
|
|
183
|
+
}
|
|
157
184
|
/**
|
|
158
185
|
* Brings `forest` in line with `placements`: cuts trees that are no longer placed, plants new ones,
|
|
159
186
|
* re-plants moved ones, and writes Growth/Season only where they differ. Untouched trees are not rewritten.
|
|
@@ -181,26 +208,31 @@ function syncForest(forest, placements, growth, season) {
|
|
|
181
208
|
}
|
|
182
209
|
/**
|
|
183
210
|
* Many trees of one Definition, drawn instanced (a `Forest`). Changing `placements` plants or cuts
|
|
184
|
-
* only the affected trees; Growth, Season, Wind and shadow props only update instance data, uniforms
|
|
185
|
-
* and meshes
|
|
211
|
+
* only the affected trees; Growth, Season, Wind, Tree Shader Hook and shadow props only update instance data, uniforms
|
|
212
|
+
* and meshes; changing `lod` distances, fade or camera only writes `forest.lod`. A new `definition`
|
|
213
|
+
* (by value), `style`/`form`, `variants`, `seed`, or switching `lod` on or off rebuilds the forest.
|
|
186
214
|
* The forest is disposed of on unmount.
|
|
187
215
|
*/
|
|
188
|
-
function Forest({ definition, style, form = "broadleaf", variants = 4, seed = 0, placements, growth = 1, season = 0, wind, castShadow = true, receiveShadow = true, ref, ...groupProps }) {
|
|
216
|
+
function Forest({ definition, style, form = "broadleaf", variants = 4, seed = 0, placements, growth = 1, season = 0, wind, shaderHooks, castShadow = true, receiveShadow = true, lod, ref, ...groupProps }) {
|
|
189
217
|
const styleObject = definition === void 0 && typeof style === "string" ? useTreeStyle(style) : style;
|
|
190
218
|
const source = definition ?? (typeof styleObject === "object" ? styleObject[form] : void 0);
|
|
191
219
|
if (source === void 0) throw new Error("<Forest> needs a `definition` or a `style`.");
|
|
192
220
|
const key = JSON.stringify(source);
|
|
221
|
+
const lodKey = lodBuildKey(lod);
|
|
193
222
|
const [generation, setGeneration] = useState(0);
|
|
194
223
|
const forest = useMemo(() => createForest(JSON.parse(key), [], {
|
|
195
224
|
variants,
|
|
196
225
|
seed,
|
|
197
226
|
wind,
|
|
198
227
|
growth,
|
|
199
|
-
season
|
|
228
|
+
season,
|
|
229
|
+
lod,
|
|
230
|
+
shaderHooks
|
|
200
231
|
}), [
|
|
201
232
|
key,
|
|
202
233
|
variants,
|
|
203
234
|
seed,
|
|
235
|
+
lodKey,
|
|
204
236
|
generation
|
|
205
237
|
]);
|
|
206
238
|
useEffect(() => {
|
|
@@ -213,6 +245,27 @@ function Forest({ definition, style, form = "broadleaf", variants = 4, seed = 0,
|
|
|
213
245
|
useLayoutEffect(() => {
|
|
214
246
|
forest.wind = wind ?? sceneWind;
|
|
215
247
|
}, [forest, wind]);
|
|
248
|
+
useLayoutEffect(() => {
|
|
249
|
+
forest.shaderHooks = shaderHooks ?? {};
|
|
250
|
+
}, [forest, shaderHooks]);
|
|
251
|
+
const live = forest.resolveLod(lod);
|
|
252
|
+
useLayoutEffect(() => {
|
|
253
|
+
const current = forest.lod;
|
|
254
|
+
if (!live || !current) return;
|
|
255
|
+
const { light, impostor, fade, camera } = live;
|
|
256
|
+
if (light !== current.light || impostor !== current.impostor || fade !== current.fade || camera !== current.camera) forest.lod = {
|
|
257
|
+
light,
|
|
258
|
+
impostor,
|
|
259
|
+
fade,
|
|
260
|
+
camera
|
|
261
|
+
};
|
|
262
|
+
}, [
|
|
263
|
+
forest,
|
|
264
|
+
live?.light,
|
|
265
|
+
live?.impostor,
|
|
266
|
+
live?.fade,
|
|
267
|
+
live?.camera
|
|
268
|
+
]);
|
|
216
269
|
useLayoutEffect(() => {
|
|
217
270
|
syncForest(forest, placements, growth, season);
|
|
218
271
|
}, [
|
|
@@ -238,6 +291,290 @@ function Forest({ definition, style, form = "broadleaf", variants = 4, seed = 0,
|
|
|
238
291
|
...groupProps
|
|
239
292
|
});
|
|
240
293
|
}
|
|
241
|
-
|
|
294
|
+
// src/react/ScenePipeline.tsx
|
|
295
|
+
var sceneModule;
|
|
296
|
+
/** The `@casmo/tree.js/scene` module, loaded once (a failed load is retried on the next render). */
|
|
297
|
+
function sceneResource() {
|
|
298
|
+
if (!sceneModule) {
|
|
299
|
+
sceneModule = import("./scene.js");
|
|
300
|
+
sceneModule.catch(() => sceneModule = void 0);
|
|
301
|
+
}
|
|
302
|
+
return sceneModule;
|
|
303
|
+
}
|
|
304
|
+
/** Starts loading the Scene Pipeline module ahead of time, without suspending. */
|
|
305
|
+
function preloadScenePipeline() {
|
|
306
|
+
sceneResource().catch(() => {});
|
|
307
|
+
}
|
|
308
|
+
var ScenePipelineContext = createContext(null);
|
|
309
|
+
var disposedPipelines = /* @__PURE__ */ new WeakSet();
|
|
310
|
+
/**
|
|
311
|
+
* The `ScenePipeline` of the nearest enclosing `<ScenePipeline>` (e.g. to call `pick()`), or `null`
|
|
312
|
+
* outside one and before it is built (the render after it mounts).
|
|
313
|
+
*/
|
|
314
|
+
function useScenePipeline() {
|
|
315
|
+
return useContext(ScenePipelineContext);
|
|
316
|
+
}
|
|
317
|
+
var isRef = (sun) => !!sun && "current" in sun && !sun.isLight;
|
|
318
|
+
var sunOf = (sun) => isRef(sun) ? sun.current ?? void 0 : sun;
|
|
319
|
+
/**
|
|
320
|
+
* Renders the R3F scene through a Scene Pipeline (`@casmo/tree.js/scene`): the Style's suggested Tree
|
|
321
|
+
* Effects and Scene Effects, or your own. Takes over rendering (`useFrame` at priority 1), follows the
|
|
322
|
+
* camera, calls `set()` when `style`/`treeEffects`/`sceneEffects` change, and disposes of the pipeline
|
|
323
|
+
* on unmount (which gives `scene.fogNode` back). Loads the scene module on first use: suspends.
|
|
324
|
+
*
|
|
325
|
+
* ```tsx
|
|
326
|
+
* <Canvas><ScenePipeline style="stylized" sun={sun} />...</Canvas>
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
function ScenePipeline({ style, treeEffects, sceneEffects, sun, selection, treeId, highlighted, velocity, ref, children }) {
|
|
330
|
+
const { createScenePipeline } = use(sceneResource());
|
|
331
|
+
const gl = useThree((s) => s.gl);
|
|
332
|
+
const scene = useThree((s) => s.scene);
|
|
333
|
+
const camera = useThree((s) => s.camera);
|
|
334
|
+
const [pipeline, setPipeline] = useState(null);
|
|
335
|
+
const builtSun = useRef(void 0);
|
|
336
|
+
const [generation, setGeneration] = useState(0);
|
|
337
|
+
const applied = useRef("");
|
|
338
|
+
const choice = {
|
|
339
|
+
style,
|
|
340
|
+
treeEffects,
|
|
341
|
+
sceneEffects
|
|
342
|
+
};
|
|
343
|
+
const choiceKey = JSON.stringify(choice);
|
|
344
|
+
const latest = useRef({
|
|
345
|
+
choice,
|
|
346
|
+
highlighted
|
|
347
|
+
});
|
|
348
|
+
latest.current = {
|
|
349
|
+
choice,
|
|
350
|
+
highlighted
|
|
351
|
+
};
|
|
352
|
+
useEffect(() => {
|
|
353
|
+
const light = sunOf(sun);
|
|
354
|
+
builtSun.current = light;
|
|
355
|
+
applied.current = JSON.stringify(latest.current.choice);
|
|
356
|
+
const created = createScenePipeline(gl, scene, camera, {
|
|
357
|
+
...latest.current.choice,
|
|
358
|
+
sun: light,
|
|
359
|
+
selection,
|
|
360
|
+
treeId,
|
|
361
|
+
velocity,
|
|
362
|
+
highlighted: [...latest.current.highlighted ?? []]
|
|
363
|
+
});
|
|
364
|
+
setPipeline(created);
|
|
365
|
+
return () => {
|
|
366
|
+
disposedPipelines.add(created);
|
|
367
|
+
created.dispose();
|
|
368
|
+
setPipeline(null);
|
|
369
|
+
};
|
|
370
|
+
}, [
|
|
371
|
+
createScenePipeline,
|
|
372
|
+
gl,
|
|
373
|
+
scene,
|
|
374
|
+
camera,
|
|
375
|
+
sun,
|
|
376
|
+
generation,
|
|
377
|
+
selection,
|
|
378
|
+
treeId,
|
|
379
|
+
velocity
|
|
380
|
+
]);
|
|
381
|
+
useLayoutEffect(() => {
|
|
382
|
+
if (!pipeline || applied.current === choiceKey) return;
|
|
383
|
+
applied.current = choiceKey;
|
|
384
|
+
pipeline.set(latest.current.choice);
|
|
385
|
+
}, [pipeline, choiceKey]);
|
|
386
|
+
useLayoutEffect(() => {
|
|
387
|
+
pipeline?.highlighted.splice(0, Infinity, ...highlighted ?? []);
|
|
388
|
+
}, [pipeline, highlighted]);
|
|
389
|
+
useImperativeHandle(ref, () => pipeline, [pipeline]);
|
|
390
|
+
useFrame((state) => {
|
|
391
|
+
if (isRef(sun) && sunOf(sun) !== builtSun.current) {
|
|
392
|
+
builtSun.current = sunOf(sun);
|
|
393
|
+
setGeneration((g) => g + 1);
|
|
394
|
+
}
|
|
395
|
+
if (pipeline) pipeline.render();
|
|
396
|
+
else state.gl.render(state.scene, state.camera);
|
|
397
|
+
}, 1);
|
|
398
|
+
return /* @__PURE__ */ jsx(ScenePipelineContext, {
|
|
399
|
+
value: pipeline,
|
|
400
|
+
children
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Adds a custom Tree Effect to the enclosing `<ScenePipeline>` while mounted (`pipeline.addEffect`), at
|
|
405
|
+
* the place its `before` names (`'end'`: after the Highlight); several at the same place run in the order they mounted. New `options`
|
|
406
|
+
* only call `updateEffect`, it stays through Style and settings changes and goes into a rebuilt pipeline,
|
|
407
|
+
* and it is removed on unmount. Renders nothing; does nothing outside a `<ScenePipeline>`.
|
|
408
|
+
*
|
|
409
|
+
* ```tsx
|
|
410
|
+
* <ScenePipeline style="stylized">
|
|
411
|
+
* <TreeEffect effect={foliage} options={{ strength: 0.5 }} />
|
|
412
|
+
* </ScenePipeline>
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
function TreeEffect({ effect, options }) {
|
|
416
|
+
const pipeline = useScenePipeline();
|
|
417
|
+
const latest = useRef(options);
|
|
418
|
+
latest.current = options;
|
|
419
|
+
const applied = useRef("");
|
|
420
|
+
const optionsKey = JSON.stringify(options) ?? "";
|
|
421
|
+
useLayoutEffect(() => {
|
|
422
|
+
if (!pipeline) return;
|
|
423
|
+
applied.current = JSON.stringify(latest.current) ?? "";
|
|
424
|
+
pipeline.addEffect(effect, latest.current);
|
|
425
|
+
return () => {
|
|
426
|
+
if (!disposedPipelines.has(pipeline)) pipeline.removeEffect(effect);
|
|
427
|
+
};
|
|
428
|
+
}, [pipeline, effect]);
|
|
429
|
+
useLayoutEffect(() => {
|
|
430
|
+
if (!pipeline || applied.current === optionsKey) return;
|
|
431
|
+
applied.current = optionsKey;
|
|
432
|
+
pipeline.updateEffect(effect, latest.current);
|
|
433
|
+
}, [
|
|
434
|
+
pipeline,
|
|
435
|
+
effect,
|
|
436
|
+
optionsKey
|
|
437
|
+
]);
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
// src/react/SceneShaderHooks.tsx
|
|
441
|
+
var contributions = [];
|
|
442
|
+
var found = {};
|
|
443
|
+
/** Sets the scene-wide default to what was there before React, stacked with every contribution. */
|
|
444
|
+
function publish() {
|
|
445
|
+
setSceneShaderHooks(stackShaderHooks(found, ...contributions.map((c) => c.hooks)));
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* @internal Adds `hooks` to the scene-wide default Tree Shader Hooks while the calling component is
|
|
449
|
+
* mounted (after the ones the scene had, and the ones of components mounted earlier). Only a change of a
|
|
450
|
+
* part's hooks rebuilds that part's node graphs. The last one to unmount puts back what it found.
|
|
451
|
+
*/
|
|
452
|
+
function useSceneShaderHooks(hooks) {
|
|
453
|
+
const contribution = useRef(null);
|
|
454
|
+
useLayoutEffect(() => {
|
|
455
|
+
if (contributions.length === 0) found = getSceneShaderHooks();
|
|
456
|
+
const entry = { hooks: {} };
|
|
457
|
+
contributions.push(entry);
|
|
458
|
+
contribution.current = entry;
|
|
459
|
+
return () => {
|
|
460
|
+
contributions.splice(contributions.indexOf(entry), 1);
|
|
461
|
+
contribution.current = null;
|
|
462
|
+
if (contributions.length === 0) setSceneShaderHooks(found);
|
|
463
|
+
else publish();
|
|
464
|
+
};
|
|
465
|
+
}, []);
|
|
466
|
+
useLayoutEffect(() => {
|
|
467
|
+
contribution.current.hooks = hooks ?? {};
|
|
468
|
+
publish();
|
|
469
|
+
}, [hooks]);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Declares scene-wide default Tree Shader Hooks (`setSceneShaderHooks`). Renders nothing. Several stack in
|
|
473
|
+
* the order they mounted, after the hooks the scene had before; when the last one unmounts, those are put
|
|
474
|
+
* back. Changing `hooks` only rebuilds the node graphs of the parts whose hooks changed, once.
|
|
475
|
+
*
|
|
476
|
+
* ```tsx
|
|
477
|
+
* <SceneShaderHooks hooks={{ leaves: frosty }} />
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
function SceneShaderHooks({ hooks }) {
|
|
481
|
+
useSceneShaderHooks(hooks);
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
// src/react/Weather.tsx
|
|
485
|
+
var weatherModule;
|
|
486
|
+
/** The `@casmo/tree.js/weather` module, loaded once (a failed load is retried on the next render). */
|
|
487
|
+
function weatherResource() {
|
|
488
|
+
if (!weatherModule) {
|
|
489
|
+
weatherModule = import("./weather.js");
|
|
490
|
+
weatherModule.catch(() => weatherModule = void 0);
|
|
491
|
+
}
|
|
492
|
+
return weatherModule;
|
|
493
|
+
}
|
|
494
|
+
/** Starts loading the weather module (Snow Cover, Wetness) ahead of time, without suspending. */
|
|
495
|
+
function preloadWeather() {
|
|
496
|
+
weatherResource().catch(() => {});
|
|
497
|
+
}
|
|
498
|
+
/** Writes `amount` (when given) to `source`, and puts back the amount it found on unmount. */
|
|
499
|
+
function useAmount(source, amount) {
|
|
500
|
+
useLayoutEffect(() => {
|
|
501
|
+
const previous = source.amount;
|
|
502
|
+
return () => {
|
|
503
|
+
source.amount = previous;
|
|
504
|
+
};
|
|
505
|
+
}, [source]);
|
|
506
|
+
useLayoutEffect(() => {
|
|
507
|
+
if (amount !== void 0) source.amount = amount;
|
|
508
|
+
}, [source, amount]);
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Applies `settings` to ready-made weather hooks, unset settings at the hooks' defaults. Compared by value,
|
|
512
|
+
* so an inline object with the same settings writes nothing.
|
|
513
|
+
*/
|
|
514
|
+
function useSettings(hooks, settings) {
|
|
515
|
+
const defaults = useMemo(() => hooks.settings, [hooks]);
|
|
516
|
+
const key = JSON.stringify(settings);
|
|
517
|
+
useLayoutEffect(() => {
|
|
518
|
+
const given = Object.fromEntries(Object.entries(settings).filter(([, value]) => value !== void 0));
|
|
519
|
+
const strength = {
|
|
520
|
+
...defaults.strength,
|
|
521
|
+
...given.strength
|
|
522
|
+
};
|
|
523
|
+
hooks.set({
|
|
524
|
+
...defaults,
|
|
525
|
+
...given,
|
|
526
|
+
strength
|
|
527
|
+
});
|
|
528
|
+
}, [
|
|
529
|
+
hooks,
|
|
530
|
+
defaults,
|
|
531
|
+
key
|
|
532
|
+
]);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* What `<SnowCover>` and `<Wetness>` share: the ready-made hooks with `settings` applied, `amount` written
|
|
536
|
+
* to `source`, the hooks set scene-wide while mounted and handed to `ref`.
|
|
537
|
+
*/
|
|
538
|
+
function useWeatherHooks(hooks, source, amount, settings, ref) {
|
|
539
|
+
useSettings(hooks, settings);
|
|
540
|
+
useAmount(source, amount);
|
|
541
|
+
useSceneShaderHooks(hooks);
|
|
542
|
+
useImperativeHandle(ref, () => hooks, [hooks]);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Declares Snow Cover (`@casmo/tree.js/weather`): while mounted, every tree runs the ready-made Snow Cover
|
|
546
|
+
* hooks as scene-wide Tree Shader Hooks (before the app's own), whitening surfaces that face up by `amount`.
|
|
547
|
+
* Renders nothing. `amount` and the settings are uniform writes (no rebuild); an unset setting is its
|
|
548
|
+
* default. On unmount the hooks are removed and the amount it found is put back. Loads the weather module
|
|
549
|
+
* on first use: suspends.
|
|
550
|
+
*
|
|
551
|
+
* ```tsx
|
|
552
|
+
* <SnowCover amount={0.8} slope={60} />
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
function SnowCover({ amount, snow, ref, ...settings }) {
|
|
556
|
+
const { sceneSnow, snowCoverHooks } = use(weatherResource());
|
|
557
|
+
const source = snow ?? sceneSnow;
|
|
558
|
+
useWeatherHooks(useMemo(() => snowCoverHooks({ snow: source }), [snowCoverHooks, source]), source, amount, settings, ref);
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Declares Wetness (`@casmo/tree.js/weather`): while mounted, every tree runs the ready-made Wetness hooks
|
|
563
|
+
* as scene-wide Tree Shader Hooks (before the app's own): darker, with a sheen, by `amount`. Renders
|
|
564
|
+
* nothing. `amount` and the settings are uniform writes (no rebuild); an unset setting is its default. On
|
|
565
|
+
* unmount the hooks are removed and the amount it found is put back. Loads the weather module on first
|
|
566
|
+
* use: suspends.
|
|
567
|
+
*
|
|
568
|
+
* ```tsx
|
|
569
|
+
* <Wetness amount={0.6} sheen={0.7} />
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
function Wetness({ amount, wetness, ref, ...settings }) {
|
|
573
|
+
const { sceneWetness, wetnessHooks } = use(weatherResource());
|
|
574
|
+
const source = wetness ?? sceneWetness;
|
|
575
|
+
useWeatherHooks(useMemo(() => wetnessHooks({ wetness: source }), [wetnessHooks, source]), source, amount, settings, ref);
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
export { Forest, ScenePipeline, SceneShaderHooks, SnowCover, Tree, TreeEffect, Wetness, Wind, preloadScenePipeline, preloadTreeStyle, preloadWeather, useScenePipeline, useTreeStyle, useWindBurst };
|
|
242
579
|
|
|
243
580
|
//# sourceMappingURL=react.js.map
|