@casmo/tree.js 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +775 -4
- package/dist/effects/custom.d.ts +62 -0
- package/dist/effects/custom.d.ts.map +1 -0
- package/dist/effects/effects.d.ts +92 -6
- package/dist/effects/effects.d.ts.map +1 -1
- package/dist/effects/glow.d.ts +5 -0
- package/dist/effects/glow.d.ts.map +1 -1
- package/dist/effects/grade.d.ts +3 -0
- package/dist/effects/grade.d.ts.map +1 -1
- package/dist/effects/highlight.d.ts +35 -0
- package/dist/effects/highlight.d.ts.map +1 -0
- package/dist/effects/index.d.ts +7 -1
- package/dist/effects/index.d.ts.map +1 -1
- package/dist/effects/inner-lines.d.ts +39 -0
- package/dist/effects/inner-lines.d.ts.map +1 -0
- package/dist/effects/live.d.ts +12 -0
- package/dist/effects/live.d.ts.map +1 -0
- package/dist/effects/mask.d.ts +32 -12
- package/dist/effects/mask.d.ts.map +1 -1
- package/dist/effects/outline.d.ts +12 -0
- package/dist/effects/outline.d.ts.map +1 -1
- package/dist/effects/pass.d.ts +27 -0
- package/dist/effects/pass.d.ts.map +1 -0
- package/dist/effects/screen.d.ts +31 -0
- package/dist/effects/screen.d.ts.map +1 -0
- package/dist/effects/suggested.d.ts +5 -0
- package/dist/effects/suggested.d.ts.map +1 -1
- package/dist/effects/tree-id.d.ts +50 -0
- package/dist/effects/tree-id.d.ts.map +1 -0
- package/dist/effects-qHx_8Dlk.js +1052 -0
- package/dist/effects-qHx_8Dlk.js.map +1 -0
- package/dist/effects.js +3 -249
- package/dist/forest/Forest.d.ts +82 -4
- package/dist/forest/Forest.d.ts.map +1 -1
- package/dist/forest/forest-lod.d.ts +70 -0
- package/dist/forest/forest-lod.d.ts.map +1 -0
- package/dist/forest/impostor-material.d.ts +106 -0
- package/dist/forest/impostor-material.d.ts.map +1 -0
- package/dist/forest/impostor-season.d.ts +13 -0
- package/dist/forest/impostor-season.d.ts.map +1 -0
- package/dist/forest/impostor.d.ts +105 -0
- package/dist/forest/impostor.d.ts.map +1 -0
- package/dist/forest/index.d.ts +1 -0
- package/dist/forest/index.d.ts.map +1 -1
- package/dist/forest/levels.d.ts +144 -0
- package/dist/forest/levels.d.ts.map +1 -0
- package/dist/forest/lod.d.ts +106 -0
- package/dist/forest/lod.d.ts.map +1 -0
- package/dist/forest/nodes.d.ts +42 -1
- package/dist/forest/nodes.d.ts.map +1 -1
- package/dist/forest/octahedral.d.ts +33 -0
- package/dist/forest/octahedral.d.ts.map +1 -0
- package/dist/{forest-ChEaWJrf.js → forest-CM5DrklM.js} +1727 -340
- package/dist/forest-CM5DrklM.js.map +1 -0
- package/dist/generator/fruit.d.ts +2 -0
- package/dist/generator/fruit.d.ts.map +1 -1
- package/dist/generator/index.d.ts +1 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/light.d.ts +36 -0
- package/dist/generator/light.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/materials/crown-nodes.d.ts +5 -0
- package/dist/materials/crown-nodes.d.ts.map +1 -1
- package/dist/materials/leaf-translucency-model.d.ts +6 -1
- package/dist/materials/leaf-translucency-model.d.ts.map +1 -1
- package/dist/materials/material-features.d.ts +12 -0
- package/dist/materials/material-features.d.ts.map +1 -1
- package/dist/materials/shader-hooks.d.ts +155 -0
- package/dist/materials/shader-hooks.d.ts.map +1 -0
- package/dist/motion-Qd7xjeZM.js +276 -0
- package/dist/motion-Qd7xjeZM.js.map +1 -0
- package/dist/nodes-DxgTyF9B.js +436 -0
- package/dist/nodes-DxgTyF9B.js.map +1 -0
- package/dist/react/Forest.d.ts +17 -3
- package/dist/react/Forest.d.ts.map +1 -1
- package/dist/react/ScenePipeline.d.ts +63 -0
- package/dist/react/ScenePipeline.d.ts.map +1 -0
- package/dist/react/SceneShaderHooks.d.ts +25 -0
- package/dist/react/SceneShaderHooks.d.ts.map +1 -0
- package/dist/react/Tree.d.ts +9 -2
- package/dist/react/Tree.d.ts.map +1 -1
- package/dist/react/Weather.d.ts +45 -0
- package/dist/react/Weather.d.ts.map +1 -0
- package/dist/react/Wind.d.ts +12 -1
- package/dist/react/Wind.d.ts.map +1 -1
- package/dist/react/index.d.ts +7 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react.js +347 -10
- package/dist/react.js.map +1 -1
- package/dist/renderer/index.d.ts +6 -0
- package/dist/renderer/index.d.ts.map +1 -1
- package/dist/scene/antialias.d.ts +35 -0
- package/dist/scene/antialias.d.ts.map +1 -0
- package/dist/scene/ao.d.ts +46 -0
- package/dist/scene/ao.d.ts.map +1 -0
- package/dist/scene/bloom.d.ts +19 -0
- package/dist/scene/bloom.d.ts.map +1 -0
- package/dist/scene/fog.d.ts +49 -0
- package/dist/scene/fog.d.ts.map +1 -0
- package/dist/scene/godrays.d.ts +37 -0
- package/dist/scene/godrays.d.ts.map +1 -0
- package/dist/scene/index.d.ts +14 -0
- package/dist/scene/index.d.ts.map +1 -0
- package/dist/scene/motion-blur.d.ts +23 -0
- package/dist/scene/motion-blur.d.ts.map +1 -0
- package/dist/scene/pipeline.d.ts +109 -0
- package/dist/scene/pipeline.d.ts.map +1 -0
- package/dist/scene/settings.d.ts +36 -0
- package/dist/scene/settings.d.ts.map +1 -0
- package/dist/scene/stack.d.ts +25 -0
- package/dist/scene/stack.d.ts.map +1 -0
- package/dist/scene/stage.d.ts +52 -0
- package/dist/scene/stage.d.ts.map +1 -0
- package/dist/scene/suggested.d.ts +12 -0
- package/dist/scene/suggested.d.ts.map +1 -0
- package/dist/scene/tone-mapping.d.ts +20 -0
- package/dist/scene/tone-mapping.d.ts.map +1 -0
- package/dist/scene/velocity.d.ts +34 -0
- package/dist/scene/velocity.d.ts.map +1 -0
- package/dist/scene.js +889 -0
- package/dist/scene.js.map +1 -0
- package/dist/season/nodes.d.ts +13 -0
- package/dist/season/nodes.d.ts.map +1 -1
- package/dist/shader-hooks-BFRtlWGI.js +275 -0
- package/dist/shader-hooks-BFRtlWGI.js.map +1 -0
- package/dist/tree/Tree.d.ts +8 -3
- package/dist/tree/Tree.d.ts.map +1 -1
- package/dist/tree/index.d.ts.map +1 -1
- package/dist/weather/index.d.ts +3 -0
- package/dist/weather/index.d.ts.map +1 -0
- package/dist/weather/shared.d.ts +43 -0
- package/dist/weather/shared.d.ts.map +1 -0
- package/dist/weather/snow.d.ts +87 -0
- package/dist/weather/snow.d.ts.map +1 -0
- package/dist/weather/wetness.d.ts +75 -0
- package/dist/weather/wetness.d.ts.map +1 -0
- package/dist/weather.js +288 -0
- package/dist/weather.js.map +1 -0
- package/dist/wind/Wind.d.ts +100 -5
- package/dist/wind/Wind.d.ts.map +1 -1
- package/dist/wind/burst.d.ts +28 -0
- package/dist/wind/burst.d.ts.map +1 -0
- package/dist/wind/index.d.ts +3 -2
- package/dist/wind/index.d.ts.map +1 -1
- package/dist/wind/motion.d.ts +30 -0
- package/dist/wind/motion.d.ts.map +1 -0
- package/dist/wind/node.d.ts +17 -3
- package/dist/wind/node.d.ts.map +1 -1
- package/package.json +9 -1
- package/dist/effects.js.map +0 -1
- package/dist/forest-ChEaWJrf.js.map +0 -1
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","names":["disposed"],"sources":["../src/react/useTreeStyle.ts","../src/react/Tree.tsx","../src/react/Wind.tsx","../src/react/Forest.tsx"],"sourcesContent":["import { use } from 'react';\nimport { loadStyle, type StyleName } from '../styles/registry';\nimport type { TreeStyle } from '../styles/types';\n\n// One promise per Style name, so every render (and every component) suspends on the same load.\nconst cache = new Map<string, Promise<TreeStyle>>();\n\nfunction styleResource(name: StyleName): Promise<TreeStyle> {\n let promise = cache.get(name);\n if (!promise) {\n promise = loadStyle(name);\n cache.set(name, promise);\n // A failed load is not cached, so a later render can retry (the error still reaches the error boundary).\n promise.catch(() => cache.delete(name));\n }\n return promise;\n}\n\n/**\n * Loads a built-in Style with a dynamic import and returns it. Suspends (React Suspense) while\n * it downloads, so wrap the component in `<Suspense>`. Unknown names throw to the nearest error boundary.\n *\n * ```tsx\n * const lowPoly = useTreeStyle('low-poly');\n * return <Tree style={lowPoly} form=\"conifer\" seed={7} />;\n * ```\n */\nexport function useTreeStyle(name: StyleName): TreeStyle {\n return use(styleResource(name));\n}\n\n/** Starts loading a Style ahead of time (e.g. on hover), without suspending. */\nexport function preloadTreeStyle(name: StyleName): void {\n void styleResource(name).catch(() => {});\n}\n","import { useEffect, useLayoutEffect, useMemo, useState, type Ref } from 'react';\nimport type { ThreeElements } from '@react-three/fiber';\nimport type { TreeDefinition, TreeDefinitionInput, TreeForm } from '../definition';\nimport type { SpeciesDefinition } from '../species/types';\nimport type { TreeStyle } from '../styles/types';\nimport type { StyleName } from '../styles/registry';\nimport { createTree, type Tree as TreeObject } from '../tree';\nimport { sceneWind, type Wind as WindObject } from '../wind';\nimport { useTreeStyle } from './useTreeStyle';\n\ntype GroupProps = Omit<ThreeElements['group'], 'args' | 'object' | 'children' | 'ref' | 'castShadow' | 'receiveShadow' | 'dispose'>;\n\nexport interface TreeProps extends GroupProps {\n /** The Tree Definition to grow (plain object or parsed JSON). Takes precedence over `style`. */\n definition?: TreeDefinitionInput | TreeDefinition;\n /**\n * A Style: its Definition for `form` is grown. Pass the object from {@link useTreeStyle}, or a\n * built-in Style name, which is loaded on demand (the component suspends until it is there).\n */\n style?: TreeStyle | StyleName;\n /** Which of the Style's Forms to grow. Default 'broadleaf'. */\n form?: TreeForm;\n /** A Species (e.g. `oak` from `@casmo/tree.js/species`) to grow in `style`: `style.apply(species)` instead of a Form. */\n species?: SpeciesDefinition;\n /** Picks one individual tree within the Definition's ranges. Default 0. Changing it regenerates the tree. */\n seed?: number;\n /** Growth 0 (sapling) .. 1 (default). Only updates a uniform. */\n growth?: number;\n /** Season 0 .. 1 (wraps). Only updates a uniform. */\n season?: number;\n /** The Wind this tree sways with. Default: the scene-wide `sceneWind` (what `<Wind>` sets). */\n wind?: WindObject;\n /** Whether the tree casts shadows. Default true. */\n castShadow?: boolean;\n /** Whether the tree receives shadows. Default true. */\n receiveShadow?: boolean;\n /** Receives the tree.js `Tree` object (a three.js Group). */\n ref?: Ref<TreeObject>;\n}\n\n/** Trees this module has disposed of (React StrictMode re-runs effects on the same memoised tree). */\nconst disposed = new WeakSet<TreeObject>();\n\n/**\n * A procedural tree. Growth, Season, Wind and shadow props only update the existing tree; a new\n * `seed`, `definition` (by value) or `style`/`form`/`species` regenerates it. The tree is disposed\n * of on unmount.\n */\nexport function Tree({\n definition,\n style,\n form = 'broadleaf',\n species,\n seed = 0,\n growth = 1,\n season = 0,\n wind,\n castShadow = true,\n receiveShadow = true,\n ref,\n ...groupProps\n}: TreeProps) {\n // `use()` (behind useTreeStyle) may be called conditionally, so a style name suspends right here.\n const styleObject = definition === undefined && typeof style === 'string' ? useTreeStyle(style) : style;\n const source = definition ?? (typeof styleObject === 'object' ? (species ? styleObject.apply(species) : styleObject[form]) : undefined);\n if (source === undefined) throw new Error('<Tree> needs a `definition` or a `style`.');\n // Compare Definitions by value, so an inline object literal does not regenerate on every render.\n const key = JSON.stringify(source);\n\n // Bumped when StrictMode disposed the memoised tree, to grow a fresh one.\n const [generation, setGeneration] = useState(0);\n const tree = useMemo(\n () => createTree(JSON.parse(key) as TreeDefinitionInput, { seed, wind, growth, season }),\n // growth/season/wind are only the starting values; the effects below keep them in sync.\n [key, seed, generation],\n );\n\n useEffect(() => {\n if (disposed.has(tree)) setGeneration((g) => g + 1);\n return () => {\n disposed.add(tree);\n tree.dispose();\n };\n }, [tree]);\n\n useLayoutEffect(() => {\n tree.wind = wind ?? sceneWind;\n }, [tree, wind]);\n\n useLayoutEffect(() => {\n tree.growth = growth;\n }, [tree, growth]);\n\n useLayoutEffect(() => {\n tree.season = season;\n }, [tree, season]);\n\n useLayoutEffect(() => {\n for (const mesh of [tree.wood, tree.leaves, tree.fruit]) {\n mesh.castShadow = castShadow;\n mesh.receiveShadow = receiveShadow;\n }\n }, [tree, castShadow, receiveShadow]);\n\n return <primitive object={tree} ref={ref} {...groupProps} />;\n}\n","import { useLayoutEffect } from 'react';\nimport { sceneWind, type Wind as WindObject, type WindDirection } from '../wind';\n\nexport interface WindProps {\n /** World-space direction the wind blows towards (any non-zero length). Unset: leave as is (default +X). */\n direction?: WindDirection;\n /** 0 = calm, 1 = strong wind, more for storms. Unset: leave as is (default 0). */\n strength?: number;\n /** Pins the Wind clock to this many seconds (pause, screenshots). Unset: the renderer clock. */\n time?: number | null;\n /** The Wind to drive. Default: the scene-wide `sceneWind` every `<Tree>` sways with. */\n wind?: WindObject;\n}\n\n/**\n * Declares the Wind. Renders nothing; it writes the Wind's uniforms (no recompile), and puts back the\n * direction, strength and clock it found when it unmounts.\n */\nexport function Wind({ direction, strength, time = null, wind = sceneWind }: WindProps): null {\n // Depend on the components, so a new array literal with the same values does nothing.\n const [x, y, z] = direction === undefined ? [] : Array.isArray(direction) ? direction : (direction as { toArray(): number[] }).toArray();\n\n useLayoutEffect(() => {\n const previous = { direction: wind.direction, strength: wind.strength, time: wind.time };\n return () => {\n wind.set(previous);\n wind.time = previous.time;\n };\n }, [wind]);\n\n useLayoutEffect(() => {\n if (x !== undefined) wind.direction = [x, y!, z!];\n }, [wind, x, y, z]);\n\n useLayoutEffect(() => {\n if (strength !== undefined) wind.strength = strength;\n }, [wind, strength]);\n\n useLayoutEffect(() => {\n wind.time = time;\n }, [wind, time]);\n\n return null;\n}\n","import { useEffect, useLayoutEffect, useMemo, useState, type Ref } from 'react';\nimport type { ThreeElements } from '@react-three/fiber';\nimport type { TreeDefinition, TreeDefinitionInput, TreeForm } from '../definition';\nimport type { TreeStyle } from '../styles/types';\nimport type { StyleName } from '../styles/registry';\nimport { createForest, type Forest as ForestObject } from '../forest';\nimport { forestTreeKey, type ForestPlacement } from '../forest/placement';\nimport { clampGrowth } from '../growth/evaluate';\nimport { wrapSeason } from '../season/profile';\nimport { sceneWind, type Wind as WindObject } from '../wind';\nimport { useTreeStyle } from './useTreeStyle';\n\ntype GroupProps = Omit<ThreeElements['group'], 'args' | 'object' | 'children' | 'ref' | 'castShadow' | 'receiveShadow' | 'dispose'>;\n\n/** Where one tree of a `<Forest>` stands, optionally with its own Growth and Season. */\nexport interface ForestTreePlacement extends ForestPlacement {\n /** This tree's Growth, 0..1. Default: the forest's `growth`. */\n growth?: number;\n /** This tree's Season, 0..1 (wraps). Default: the forest's `season`. */\n season?: number;\n}\n\nexport interface ForestProps extends GroupProps {\n /** The Tree Definition every tree is grown from (plain object or parsed JSON). Takes precedence over `style`. */\n definition?: TreeDefinitionInput | TreeDefinition;\n /** A Style (object from {@link useTreeStyle}, or a built-in Style name, loaded on demand: suspends). */\n style?: TreeStyle | StyleName;\n /** Which of the Style's Forms to grow. Default 'broadleaf'. */\n form?: TreeForm;\n /** How many Variants (distinct trees, each drawn instanced). Default 4. Changing it rebuilds the forest. */\n variants?: number;\n /** The forest seed. Default 0. Changing it rebuilds the forest. */\n seed?: number;\n /**\n * The trees. Trees are matched by key (their `id`, or their position without one), so adding or\n * removing placements only plants or cuts those trees; the others keep their look and instance data.\n */\n placements: readonly ForestTreePlacement[];\n /** Growth of every tree without its own `growth`, 0..1. Default 1. Only rewrites instance data. */\n growth?: number;\n /** Season of every tree without its own `season`, 0..1 (wraps). Default 0. Only rewrites instance data. */\n season?: number;\n /** The Wind the forest sways with. Default: the scene-wide `sceneWind` (what `<Wind>` sets). */\n wind?: WindObject;\n /** Whether the trees cast shadows. Default true. */\n castShadow?: boolean;\n /** Whether the trees receive shadows. Default true. */\n receiveShadow?: boolean;\n /** Receives the tree.js `Forest` object (a three.js Group). */\n ref?: Ref<ForestObject>;\n}\n\n/** Forests this module has disposed of (React StrictMode re-runs effects on the same memoised forest). */\nconst disposed = new WeakSet<ForestObject>();\n\n/** The placement without the React-only per-tree state. */\nfunction placementOf(p: ForestTreePlacement): ForestPlacement {\n const placement = { ...p };\n delete placement.growth;\n delete placement.season;\n return placement;\n}\n\n/** What makes a tree stand where it does; a change re-plants the tree. */\nfunction pose(p: ForestPlacement): string {\n const v = p.position;\n const position = Array.isArray(v) ? [v[0], v[1], v[2]] : [(v as { x: number }).x, (v as { y: number }).y, (v as { z: number }).z];\n return JSON.stringify([position, p.rotation ?? 0, p.scale ?? 1]);\n}\n\n/**\n * Brings `forest` in line with `placements`: cuts trees that are no longer placed, plants new ones,\n * re-plants moved ones, and writes Growth/Season only where they differ. Untouched trees are not rewritten.\n */\nfunction syncForest(forest: ForestObject, placements: readonly ForestTreePlacement[], growth: number, season: number): void {\n if (forest.growth !== clampGrowth(growth)) forest.growth = growth;\n if (forest.season !== wrapSeason(season)) forest.season = season;\n\n const wanted = new Map<string, ForestTreePlacement>();\n for (const p of placements) {\n const key = forestTreeKey(p);\n if (wanted.has(key)) throw new Error(`<Forest> placements have two trees with key \"${key}\"`);\n wanted.set(key, p);\n }\n for (const tree of forest.trees) {\n const p = wanted.get(tree.key);\n if (!p || pose(p) !== pose(tree.placement)) forest.removeTree(tree);\n }\n for (const [key, p] of wanted) {\n const tree = forest.get(key) ?? forest.addTree(placementOf(p));\n const g = p.growth ?? growth;\n const s = p.season ?? season;\n if (tree.growth !== clampGrowth(g)) tree.growth = g;\n if (tree.season !== wrapSeason(s)) tree.season = s;\n }\n}\n\n/**\n * Many trees of one Definition, drawn instanced (a `Forest`). Changing `placements` plants or cuts\n * only the affected trees; Growth, Season, Wind and shadow props only update instance data, uniforms\n * and meshes. A new `definition` (by value), `style`/`form`, `variants` or `seed` rebuilds the forest.\n * The forest is disposed of on unmount.\n */\nexport function Forest({\n definition,\n style,\n form = 'broadleaf',\n variants = 4,\n seed = 0,\n placements,\n growth = 1,\n season = 0,\n wind,\n castShadow = true,\n receiveShadow = true,\n ref,\n ...groupProps\n}: ForestProps) {\n const styleObject = definition === undefined && typeof style === 'string' ? useTreeStyle(style) : style;\n const source = definition ?? (typeof styleObject === 'object' ? styleObject[form] : undefined);\n if (source === undefined) throw new Error('<Forest> needs a `definition` or a `style`.');\n const key = JSON.stringify(source);\n\n const [generation, setGeneration] = useState(0);\n const forest = useMemo(\n () => createForest(JSON.parse(key) as TreeDefinitionInput, [], { variants, seed, wind, growth, season }),\n // placements/growth/season/wind are synced by the layout effects below.\n [key, variants, seed, generation],\n );\n\n useEffect(() => {\n if (disposed.has(forest)) setGeneration((g) => g + 1);\n return () => {\n disposed.add(forest);\n forest.dispose();\n };\n }, [forest]);\n\n useLayoutEffect(() => {\n forest.wind = wind ?? sceneWind;\n }, [forest, wind]);\n\n useLayoutEffect(() => {\n syncForest(forest, placements, growth, season);\n }, [forest, placements, growth, season]);\n\n useLayoutEffect(() => {\n for (const variant of forest.variants) {\n for (const mesh of variant.meshes) {\n mesh.castShadow = castShadow;\n mesh.receiveShadow = receiveShadow;\n }\n }\n }, [forest, castShadow, receiveShadow, placements]);\n\n return <primitive object={forest} ref={ref} {...groupProps} />;\n}\n"],"mappings":";;;;AAKA,IAAM,wBAAQ,IAAI,IAAgC;AAElD,SAAS,cAAc,MAAqC;CAC1D,IAAI,UAAU,MAAM,IAAI,IAAI;CAC5B,IAAI,CAAC,SAAS;EACZ,UAAU,UAAU,IAAI;EACxB,MAAM,IAAI,MAAM,OAAO;EAEvB,QAAQ,YAAY,MAAM,OAAO,IAAI,CAAC;CACxC;CACA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,aAAa,MAA4B;CACvD,OAAO,IAAI,cAAc,IAAI,CAAC;AAChC;;AAGA,SAAgB,iBAAiB,MAAuB;CACtD,cAAmB,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC;AACzC;;;ACOA,IAAMA,6BAAW,IAAI,QAAoB;;;;;;AAOzC,SAAgB,KAAK,EACnB,YACA,OACA,OAAO,aACP,SACA,OAAO,GACP,SAAS,GACT,SAAS,GACT,MACA,aAAa,MACb,gBAAgB,MAChB,KACA,GAAG,cACS;CAEZ,MAAM,cAAc,eAAe,KAAA,KAAa,OAAO,UAAU,WAA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sBAAsB;EACpB,OAAO,OAAO,QAAQ;CACxB,GAAG,CAAC,QAAQ,IAAI,CAAC;CAEjB,sBAAsB;EACpB,WAAW,QAAQ,YAAY,QAAQ,MAAM;CAC/C,GAAG;EAAC;EAAQ;EAAY;EAAQ;CAAM,CAAC;CAEvC,sBAAsB;EACpB,KAAK,MAAM,WAAW,OAAO,UAC3B,KAAK,MAAM,QAAQ,QAAQ,QAAQ;GACjC,KAAK,aAAa;GAClB,KAAK,gBAAgB;EACvB;CAEJ,GAAG;EAAC;EAAQ;EAAY;EAAe;CAAU,CAAC;CAElD,OAAO,oBAAC,aAAD;EAAW,QAAQ;EAAa;EAAK,GAAI;CAAa,CAAA;AAC/D"}
|
|
1
|
+
{"version":3,"file":"react.js","names":["disposed"],"sources":["../src/react/useTreeStyle.ts","../src/react/Tree.tsx","../src/react/Wind.tsx","../src/react/Forest.tsx","../src/react/ScenePipeline.tsx","../src/react/SceneShaderHooks.tsx","../src/react/Weather.tsx"],"sourcesContent":["import { use } from 'react';\nimport { loadStyle, type StyleName } from '../styles/registry';\nimport type { TreeStyle } from '../styles/types';\n\n// One promise per Style name, so every render (and every component) suspends on the same load.\nconst cache = new Map<string, Promise<TreeStyle>>();\n\nfunction styleResource(name: StyleName): Promise<TreeStyle> {\n let promise = cache.get(name);\n if (!promise) {\n promise = loadStyle(name);\n cache.set(name, promise);\n // A failed load is not cached, so a later render can retry (the error still reaches the error boundary).\n promise.catch(() => cache.delete(name));\n }\n return promise;\n}\n\n/**\n * Loads a built-in Style with a dynamic import and returns it. Suspends (React Suspense) while\n * it downloads, so wrap the component in `<Suspense>`. Unknown names throw to the nearest error boundary.\n *\n * ```tsx\n * const lowPoly = useTreeStyle('low-poly');\n * return <Tree style={lowPoly} form=\"conifer\" seed={7} />;\n * ```\n */\nexport function useTreeStyle(name: StyleName): TreeStyle {\n return use(styleResource(name));\n}\n\n/** Starts loading a Style ahead of time (e.g. on hover), without suspending. */\nexport function preloadTreeStyle(name: StyleName): void {\n void styleResource(name).catch(() => {});\n}\n","import { useEffect, useLayoutEffect, useMemo, useState, type Ref } from 'react';\nimport type { ThreeElements } from '@react-three/fiber';\nimport type { TreeDefinition, TreeDefinitionInput, TreeForm } from '../definition';\nimport type { SpeciesDefinition } from '../species/types';\nimport type { TreeStyle } from '../styles/types';\nimport type { StyleName } from '../styles/registry';\nimport { createTree, type Tree as TreeObject } from '../tree';\nimport { sceneWind, type Wind as WindObject } from '../wind';\nimport type { TreeShaderHooks } from '../materials/shader-hooks';\nimport { useTreeStyle } from './useTreeStyle';\n\ntype GroupProps = Omit<ThreeElements['group'], 'args' | 'object' | 'children' | 'ref' | 'castShadow' | 'receiveShadow' | 'dispose'>;\n\nexport interface TreeProps extends GroupProps {\n /** The Tree Definition to grow (plain object or parsed JSON). Takes precedence over `style`. */\n definition?: TreeDefinitionInput | TreeDefinition;\n /**\n * A Style: its Definition for `form` is grown. Pass the object from {@link useTreeStyle}, or a\n * built-in Style name, which is loaded on demand (the component suspends until it is there).\n */\n style?: TreeStyle | StyleName;\n /** Which of the Style's Forms to grow. Default 'broadleaf'. */\n form?: TreeForm;\n /** A Species (e.g. `oak` from `@casmo/tree.js/species`) to grow in `style`: `style.apply(species)` instead of a Form. */\n species?: SpeciesDefinition;\n /** Picks one individual tree within the Definition's ranges. Default 0. Changing it regenerates the tree. */\n seed?: number;\n /** Growth 0 (sapling) .. 1 (default). Only updates a uniform. */\n growth?: number;\n /** Season 0 .. 1 (wraps). Only updates a uniform. */\n season?: number;\n /** The Wind this tree sways with. Default: the scene-wide `sceneWind` (what `<Wind>` sets). */\n wind?: WindObject;\n /**\n * The tree's own Tree Shader Hooks (as `tree.shaderHooks`), which stack after the scene-wide ones\n * (`<SceneShaderHooks>`, `<SnowCover>`, `<Wetness>`). Only the parts whose hooks change rebuild their\n * node graph; keep hooks stable (module scope or `useMemo`), as a new function is a new hook. Unset: none.\n */\n shaderHooks?: TreeShaderHooks;\n /** Whether the tree casts shadows. Default true. */\n castShadow?: boolean;\n /** Whether the tree receives shadows. Default true. */\n receiveShadow?: boolean;\n /** Receives the tree.js `Tree` object (a three.js Group). */\n ref?: Ref<TreeObject>;\n}\n\n/** Trees this module has disposed of (React StrictMode re-runs effects on the same memoised tree). */\nconst disposed = new WeakSet<TreeObject>();\n\n/**\n * A procedural tree. Growth, Season, Wind, Tree Shader Hook and shadow props only update the existing tree; a new\n * `seed`, `definition` (by value) or `style`/`form`/`species` regenerates it. The tree is disposed\n * of on unmount.\n */\nexport function Tree({\n definition,\n style,\n form = 'broadleaf',\n species,\n seed = 0,\n growth = 1,\n season = 0,\n wind,\n shaderHooks,\n castShadow = true,\n receiveShadow = true,\n ref,\n ...groupProps\n}: TreeProps) {\n // `use()` (behind useTreeStyle) may be called conditionally, so a style name suspends right here.\n const styleObject = definition === undefined && typeof style === 'string' ? useTreeStyle(style) : style;\n const source = definition ?? (typeof styleObject === 'object' ? (species ? styleObject.apply(species) : styleObject[form]) : undefined);\n if (source === undefined) throw new Error('<Tree> needs a `definition` or a `style`.');\n // Compare Definitions by value, so an inline object literal does not regenerate on every render.\n const key = JSON.stringify(source);\n\n // Bumped when StrictMode disposed the memoised tree, to grow a fresh one.\n const [generation, setGeneration] = useState(0);\n const tree = useMemo(\n () => createTree(JSON.parse(key) as TreeDefinitionInput, { seed, wind, growth, season, shaderHooks }),\n // growth/season/wind/shaderHooks are only the starting values; the effects below keep them in sync.\n [key, seed, generation],\n );\n\n useEffect(() => {\n if (disposed.has(tree)) setGeneration((g) => g + 1);\n return () => {\n disposed.add(tree);\n tree.dispose();\n };\n }, [tree]);\n\n useLayoutEffect(() => {\n tree.wind = wind ?? sceneWind;\n }, [tree, wind]);\n\n useLayoutEffect(() => {\n tree.shaderHooks = shaderHooks ?? {};\n }, [tree, shaderHooks]);\n\n useLayoutEffect(() => {\n tree.growth = growth;\n }, [tree, growth]);\n\n useLayoutEffect(() => {\n tree.season = season;\n }, [tree, season]);\n\n useLayoutEffect(() => {\n for (const mesh of [tree.wood, tree.leaves, tree.fruit]) {\n mesh.castShadow = castShadow;\n mesh.receiveShadow = receiveShadow;\n }\n }, [tree, castShadow, receiveShadow]);\n\n return <primitive object={tree} ref={ref} {...groupProps} />;\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { sceneWind, type Wind as WindObject, type WindBurstOptions, type WindDirection } from '../wind';\n\nexport interface WindProps {\n /** World-space direction the wind blows towards (any non-zero length). Unset: leave as is (default +X). */\n direction?: WindDirection;\n /** 0 = calm, 1 = strong wind, more for storms. Unset: leave as is (default 0). */\n strength?: number;\n /** Pins the Wind clock to this many seconds (pause, screenshots). Unset: the renderer clock. */\n time?: number | null;\n /** The Wind to drive. Default: the scene-wide `sceneWind` every `<Tree>` sways with. */\n wind?: WindObject;\n}\n\n/**\n * Declares the Wind. Renders nothing; it writes the Wind's uniforms (no recompile), and puts back the\n * direction, strength and clock it found when it unmounts.\n */\nexport function Wind({ direction, strength, time = null, wind = sceneWind }: WindProps): null {\n // Depend on the components, so a new array literal with the same values does nothing.\n const [x, y, z] = direction === undefined ? [] : Array.isArray(direction) ? direction : (direction as { toArray(): number[] }).toArray();\n\n useLayoutEffect(() => {\n const previous = { direction: wind.direction, strength: wind.strength, time: wind.time };\n return () => {\n wind.set(previous);\n wind.time = previous.time;\n };\n }, [wind]);\n\n useLayoutEffect(() => {\n if (x !== undefined) wind.direction = [x, y!, z!];\n }, [wind, x, y, z]);\n\n useLayoutEffect(() => {\n if (strength !== undefined) wind.strength = strength;\n }, [wind, strength]);\n\n useLayoutEffect(() => {\n wind.time = time;\n }, [wind, time]);\n\n return null;\n}\n\n/**\n * A function that triggers a Wind Burst (`wind.burst()`) on `wind` (default the scene-wide `sceneWind`):\n * trees near the ground point bend away from it and settle within 1.2 s. Stable for the same Wind, so it\n * is safe in event handlers and effect deps. Only uniform writes.\n *\n * ```tsx\n * const burst = useWindBurst();\n * <mesh onClick={(e) => burst({ x: e.point.x, z: e.point.z, strength: 1 })} />\n * ```\n */\nexport function useWindBurst(wind: WindObject = sceneWind): (options: WindBurstOptions) => void {\n return useCallback((options: WindBurstOptions) => void wind.burst(options), [wind]);\n}\n","import { useEffect, useLayoutEffect, useMemo, useState, type Ref } from 'react';\nimport type { ThreeElements } from '@react-three/fiber';\nimport type { TreeDefinition, TreeDefinitionInput, TreeForm } from '../definition';\nimport type { TreeStyle } from '../styles/types';\nimport type { StyleName } from '../styles/registry';\nimport { createForest, type Forest as ForestObject } from '../forest';\nimport { forestTreeKey, type ForestPlacement } from '../forest/placement';\nimport type { ForestLodOptions } from '../forest/lod';\nimport { clampGrowth } from '../growth/evaluate';\nimport { wrapSeason } from '../season/profile';\nimport { sceneWind, type Wind as WindObject } from '../wind';\nimport type { TreeShaderHooks } from '../materials/shader-hooks';\nimport { useTreeStyle } from './useTreeStyle';\n\ntype GroupProps = Omit<ThreeElements['group'], 'args' | 'object' | 'children' | 'ref' | 'castShadow' | 'receiveShadow' | 'dispose'>;\n\n/** Where one tree of a `<Forest>` stands, optionally with its own Growth and Season. */\nexport interface ForestTreePlacement extends ForestPlacement {\n /** This tree's Growth, 0..1. Default: the forest's `growth`. */\n growth?: number;\n /** This tree's Season, 0..1 (wraps). Default: the forest's `season`. */\n season?: number;\n}\n\nexport interface ForestProps extends GroupProps {\n /** The Tree Definition every tree is grown from (plain object or parsed JSON). Takes precedence over `style`. */\n definition?: TreeDefinitionInput | TreeDefinition;\n /** A Style (object from {@link useTreeStyle}, or a built-in Style name, loaded on demand: suspends). */\n style?: TreeStyle | StyleName;\n /** Which of the Style's Forms to grow. Default 'broadleaf'. */\n form?: TreeForm;\n /** How many Variants (distinct trees, each drawn instanced). Default 4. Changing it rebuilds the forest. */\n variants?: number;\n /** The forest seed. Default 0. Changing it rebuilds the forest. */\n seed?: number;\n /**\n * The trees. Trees are matched by key (their `id`, or their position without one), so adding or\n * removing placements only plants or cuts those trees; the others keep their look and instance data.\n */\n placements: readonly ForestTreePlacement[];\n /** Growth of every tree without its own `growth`, 0..1. Default 1. Only rewrites instance data. */\n growth?: number;\n /** Season of every tree without its own `season`, 0..1 (wraps). Default 0. Only rewrites instance data. */\n season?: number;\n /** The Wind the forest sways with. Default: the scene-wide `sceneWind` (what `<Wind>` sets). */\n wind?: WindObject;\n /**\n * Detail Levels (ADR 0010), as `createForest`'s `lod`: `true` for the automatic distances, or the\n * distances. Switching it on or off, or a new `impostorAtlas` or `lightDefinition` (by value),\n * rebuilds the forest; new `light`, `impostor`, `fade` or `camera` only write `forest.lod`.\n */\n lod?: boolean | ForestLodOptions;\n /**\n * The Tree Shader Hooks of every tree in the forest, at every Detail Level (as `forest.shaderHooks`),\n * stacked after the scene-wide ones. Keep hooks stable (module scope or `useMemo`). Unset: none.\n */\n shaderHooks?: TreeShaderHooks;\n /** Whether the trees cast shadows. Default true. */\n castShadow?: boolean;\n /** Whether the trees receive shadows. Default true. */\n receiveShadow?: boolean;\n /** Receives the tree.js `Forest` object (a three.js Group). */\n ref?: Ref<ForestObject>;\n}\n\n/** Forests this module has disposed of (React StrictMode re-runs effects on the same memoised forest). */\nconst disposed = new WeakSet<ForestObject>();\n\n/** The placement without the React-only per-tree state. */\nfunction placementOf(p: ForestTreePlacement): ForestPlacement {\n const placement = { ...p };\n delete placement.growth;\n delete placement.season;\n return placement;\n}\n\n/** What makes a tree stand where it does; a change re-plants the tree. */\nfunction pose(p: ForestPlacement): string {\n const v = p.position;\n const position = Array.isArray(v) ? [v[0], v[1], v[2]] : [(v as { x: number }).x, (v as { y: number }).y, (v as { z: number }).z];\n return JSON.stringify([position, p.rotation ?? 0, p.scale ?? 1]);\n}\n\n/** What of `lod` needs a new forest: whether it is on, the Impostor atlas and the Light Definition. */\nfunction lodBuildKey(lod: boolean | ForestLodOptions | undefined): string | null {\n if (!lod) return null;\n const options: Partial<ForestLodOptions> = lod === true ? {} : lod;\n return JSON.stringify([options.impostorAtlas ?? null, options.lightDefinition ?? null]);\n}\n\n/**\n * Brings `forest` in line with `placements`: cuts trees that are no longer placed, plants new ones,\n * re-plants moved ones, and writes Growth/Season only where they differ. Untouched trees are not rewritten.\n */\nfunction syncForest(forest: ForestObject, placements: readonly ForestTreePlacement[], growth: number, season: number): void {\n if (forest.growth !== clampGrowth(growth)) forest.growth = growth;\n if (forest.season !== wrapSeason(season)) forest.season = season;\n\n const wanted = new Map<string, ForestTreePlacement>();\n for (const p of placements) {\n const key = forestTreeKey(p);\n if (wanted.has(key)) throw new Error(`<Forest> placements have two trees with key \"${key}\"`);\n wanted.set(key, p);\n }\n for (const tree of forest.trees) {\n const p = wanted.get(tree.key);\n if (!p || pose(p) !== pose(tree.placement)) forest.removeTree(tree);\n }\n for (const [key, p] of wanted) {\n const tree = forest.get(key) ?? forest.addTree(placementOf(p));\n const g = p.growth ?? growth;\n const s = p.season ?? season;\n if (tree.growth !== clampGrowth(g)) tree.growth = g;\n if (tree.season !== wrapSeason(s)) tree.season = s;\n }\n}\n\n/**\n * Many trees of one Definition, drawn instanced (a `Forest`). Changing `placements` plants or cuts\n * only the affected trees; Growth, Season, Wind, Tree Shader Hook and shadow props only update instance data, uniforms\n * and meshes; changing `lod` distances, fade or camera only writes `forest.lod`. A new `definition`\n * (by value), `style`/`form`, `variants`, `seed`, or switching `lod` on or off rebuilds the forest.\n * The forest is disposed of on unmount.\n */\nexport function Forest({\n definition,\n style,\n form = 'broadleaf',\n variants = 4,\n seed = 0,\n placements,\n growth = 1,\n season = 0,\n wind,\n shaderHooks,\n castShadow = true,\n receiveShadow = true,\n lod,\n ref,\n ...groupProps\n}: ForestProps) {\n const styleObject = definition === undefined && typeof style === 'string' ? useTreeStyle(style) : style;\n const source = definition ?? (typeof styleObject === 'object' ? styleObject[form] : undefined);\n if (source === undefined) throw new Error('<Forest> needs a `definition` or a `style`.');\n const key = JSON.stringify(source);\n\n const lodKey = lodBuildKey(lod);\n\n const [generation, setGeneration] = useState(0);\n const forest = useMemo(\n () => createForest(JSON.parse(key) as TreeDefinitionInput, [], { variants, seed, wind, growth, season, lod, shaderHooks }),\n // placements/growth/season/wind/shaderHooks and the live lod settings are synced by the layout effects below.\n [key, variants, seed, lodKey, generation],\n );\n\n useEffect(() => {\n if (disposed.has(forest)) setGeneration((g) => g + 1);\n return () => {\n disposed.add(forest);\n forest.dispose();\n };\n }, [forest]);\n\n useLayoutEffect(() => {\n forest.wind = wind ?? sceneWind;\n }, [forest, wind]);\n\n useLayoutEffect(() => {\n forest.shaderHooks = shaderHooks ?? {};\n }, [forest, shaderHooks]);\n\n // The live part of `lod`, with the defaults the forest itself fills in.\n const live = forest.resolveLod(lod);\n useLayoutEffect(() => {\n const current = forest.lod;\n if (!live || !current) return;\n const { light, impostor, fade, camera } = live;\n if (light !== current.light || impostor !== current.impostor || fade !== current.fade || camera !== current.camera) {\n forest.lod = { light, impostor, fade, camera };\n }\n }, [forest, live?.light, live?.impostor, live?.fade, live?.camera]);\n\n useLayoutEffect(() => {\n syncForest(forest, placements, growth, season);\n }, [forest, placements, growth, season]);\n\n useLayoutEffect(() => {\n for (const variant of forest.variants) {\n for (const mesh of variant.meshes) {\n mesh.castShadow = castShadow;\n mesh.receiveShadow = receiveShadow;\n }\n }\n }, [forest, castShadow, receiveShadow, placements]);\n\n return <primitive object={forest} ref={ref} {...groupProps} />;\n}\n","import {\n createContext,\n use,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n useState,\n type ReactNode,\n type Ref,\n type RefObject,\n} from 'react';\nimport { useFrame, useThree } from '@react-three/fiber';\nimport type { Light, Object3D, Renderer } from 'three/webgpu';\n// Types only: the Scene Pipeline module (and its three addons) is loaded with a dynamic import the\n// first time a <ScenePipeline> renders, so apps that never use it don't bundle it.\nimport type { ScenePipeline as ScenePipelineObject, ScenePipelineChoice } from '../scene';\nimport type { CustomTreeEffect } from '../effects';\nimport type { ForestTree } from '../forest';\nimport type { Tree } from '../tree';\n\ntype SceneModule = typeof import('../scene');\n\nlet sceneModule: Promise<SceneModule> | undefined;\n\n/** The `@casmo/tree.js/scene` module, loaded once (a failed load is retried on the next render). */\nfunction sceneResource(): Promise<SceneModule> {\n if (!sceneModule) {\n sceneModule = import('../scene');\n sceneModule.catch(() => (sceneModule = undefined));\n }\n return sceneModule;\n}\n\n/** Starts loading the Scene Pipeline module ahead of time, without suspending. */\nexport function preloadScenePipeline(): void {\n void sceneResource().catch(() => {});\n}\n\nexport interface ScenePipelineProps extends ScenePipelineChoice {\n /** A shadow-casting light for god rays, or a ref to one (e.g. a JSX `<directionalLight ref={sun}>`). Never changed. */\n sun?: Light | RefObject<Light | null>;\n /** The trees to outline. Default: every tree. A new array rebuilds the pipeline. */\n selection?: Object3D[];\n /** Keeps the Tree ID channel on, for `pick()`. */\n treeId?: boolean;\n /** The trees the Highlight marks (no rebuild when it changes). */\n highlighted?: (Tree | ForestTree)[];\n /** Keeps the Wind-aware velocity channel on (`scenePass.velocity`). */\n velocity?: boolean;\n /** Receives the tree.js `ScenePipeline` (`null` until it is built and after unmount). */\n ref?: Ref<ScenePipelineObject | null>;\n /** Children can reach the pipeline with {@link useScenePipeline}. */\n children?: ReactNode;\n}\n\nconst ScenePipelineContext = createContext<ScenePipelineObject | null>(null);\n\n// Pipelines <ScenePipeline> has disposed of: a <TreeEffect> leaves those alone.\nconst disposedPipelines = new WeakSet<ScenePipelineObject>();\n\n/**\n * The `ScenePipeline` of the nearest enclosing `<ScenePipeline>` (e.g. to call `pick()`), or `null`\n * outside one and before it is built (the render after it mounts).\n */\nexport function useScenePipeline(): ScenePipelineObject | null {\n return useContext(ScenePipelineContext);\n}\n\nconst isRef = (sun: ScenePipelineProps['sun']): sun is RefObject<Light | null> => !!sun && 'current' in sun && !(sun as Partial<Light>).isLight;\nconst sunOf = (sun: ScenePipelineProps['sun']): Light | undefined => (isRef(sun) ? sun.current ?? undefined : sun);\n\n/**\n * Renders the R3F scene through a Scene Pipeline (`@casmo/tree.js/scene`): the Style's suggested Tree\n * Effects and Scene Effects, or your own. Takes over rendering (`useFrame` at priority 1), follows the\n * camera, calls `set()` when `style`/`treeEffects`/`sceneEffects` change, and disposes of the pipeline\n * on unmount (which gives `scene.fogNode` back). Loads the scene module on first use: suspends.\n *\n * ```tsx\n * <Canvas><ScenePipeline style=\"stylized\" sun={sun} />...</Canvas>\n * ```\n */\nexport function ScenePipeline({ style, treeEffects, sceneEffects, sun, selection, treeId, highlighted, velocity, ref, children }: ScenePipelineProps) {\n const { createScenePipeline } = use(sceneResource());\n const gl = useThree((s) => s.gl) as unknown as Renderer;\n const scene = useThree((s) => s.scene);\n const camera = useThree((s) => s.camera);\n const [pipeline, setPipeline] = useState<ScenePipelineObject | null>(null);\n // The light the pipeline was built with; a `sun` ref that points elsewhere later rebuilds it.\n const builtSun = useRef<Light | undefined>(undefined);\n const [generation, setGeneration] = useState(0);\n // The choice the pipeline has (it is built with the latest one; later changes go through set()).\n const applied = useRef('');\n\n const choice: ScenePipelineChoice = { style, treeEffects, sceneEffects };\n const choiceKey = JSON.stringify(choice);\n const latest = useRef({ choice, highlighted });\n latest.current = { choice, highlighted };\n\n // A passive effect: refs (a JSX `sun`) are all attached by then.\n useEffect(() => {\n const light = sunOf(sun);\n builtSun.current = light;\n applied.current = JSON.stringify(latest.current.choice);\n const created = createScenePipeline(gl, scene, camera, {\n ...latest.current.choice,\n sun: light,\n selection,\n treeId,\n velocity,\n highlighted: [...(latest.current.highlighted ?? [])],\n });\n setPipeline(created);\n return () => {\n disposedPipelines.add(created);\n created.dispose();\n setPipeline(null);\n };\n // generation: a `sun` ref that now points at another light (see useFrame).\n }, [createScenePipeline, gl, scene, camera, sun, generation, selection, treeId, velocity]);\n\n useLayoutEffect(() => {\n if (!pipeline || applied.current === choiceKey) return;\n applied.current = choiceKey;\n pipeline.set(latest.current.choice);\n }, [pipeline, choiceKey]);\n\n useLayoutEffect(() => {\n pipeline?.highlighted.splice(0, Infinity, ...(highlighted ?? []));\n }, [pipeline, highlighted]);\n\n useImperativeHandle(ref, () => pipeline!, [pipeline]);\n\n useFrame((state) => {\n if (isRef(sun) && sunOf(sun) !== builtSun.current) {\n builtSun.current = sunOf(sun);\n setGeneration((g) => g + 1);\n }\n if (pipeline) pipeline.render();\n else state.gl.render(state.scene, state.camera);\n }, 1);\n\n return <ScenePipelineContext value={pipeline}>{children}</ScenePipelineContext>;\n}\n\nexport interface TreeEffectProps<Options> {\n /**\n * The app's own Tree Effect (`CustomTreeEffect` from `@casmo/tree.js/effects`). Keep it stable (module\n * scope or `useMemo`): another effect object is removed and added again (a new graph).\n */\n effect: CustomTreeEffect<Options>;\n /** Its options. Compared by value: new options go through the effect's `update()` (no new graph, no recompile). */\n options?: Options;\n}\n\n/**\n * Adds a custom Tree Effect to the enclosing `<ScenePipeline>` while mounted (`pipeline.addEffect`), at\n * the place its `before` names (`'end'`: after the Highlight); several at the same place run in the order they mounted. New `options`\n * only call `updateEffect`, it stays through Style and settings changes and goes into a rebuilt pipeline,\n * and it is removed on unmount. Renders nothing; does nothing outside a `<ScenePipeline>`.\n *\n * ```tsx\n * <ScenePipeline style=\"stylized\">\n * <TreeEffect effect={foliage} options={{ strength: 0.5 }} />\n * </ScenePipeline>\n * ```\n */\nexport function TreeEffect<Options>({ effect, options }: TreeEffectProps<Options>): null {\n const pipeline = useScenePipeline();\n const latest = useRef(options);\n latest.current = options;\n // The options the effect was added or last updated with, by value.\n const applied = useRef('');\n const optionsKey = JSON.stringify(options) ?? '';\n\n useLayoutEffect(() => {\n if (!pipeline) return;\n applied.current = JSON.stringify(latest.current) ?? '';\n pipeline.addEffect(effect, latest.current as Options);\n return () => {\n if (!disposedPipelines.has(pipeline)) pipeline.removeEffect(effect);\n };\n }, [pipeline, effect]);\n\n useLayoutEffect(() => {\n if (!pipeline || applied.current === optionsKey) return;\n applied.current = optionsKey;\n pipeline.updateEffect(effect, latest.current as Options);\n }, [pipeline, effect, optionsKey]);\n\n return null;\n}\n","import { useLayoutEffect, useRef } from 'react';\nimport { getSceneShaderHooks, setSceneShaderHooks, stackShaderHooks, type TreeShaderHooks } from '../materials/shader-hooks';\n\n/** The hooks one mounted component adds to the scene-wide default. */\ninterface Contribution {\n hooks: TreeShaderHooks;\n}\n\n// The mounted contributions, in the order they mounted, and the scene-wide hooks found before the first.\nconst contributions: Contribution[] = [];\nlet found: TreeShaderHooks = {};\n\n/** Sets the scene-wide default to what was there before React, stacked with every contribution. */\nfunction publish(): void {\n setSceneShaderHooks(stackShaderHooks(found, ...contributions.map((c) => c.hooks)));\n}\n\n/**\n * @internal Adds `hooks` to the scene-wide default Tree Shader Hooks while the calling component is\n * mounted (after the ones the scene had, and the ones of components mounted earlier). Only a change of a\n * part's hooks rebuilds that part's node graphs. The last one to unmount puts back what it found.\n */\nexport function useSceneShaderHooks(hooks: TreeShaderHooks | null): void {\n const contribution = useRef<Contribution | null>(null);\n\n useLayoutEffect(() => {\n if (contributions.length === 0) found = getSceneShaderHooks();\n const entry: Contribution = { hooks: {} };\n contributions.push(entry);\n contribution.current = entry;\n return () => {\n contributions.splice(contributions.indexOf(entry), 1);\n contribution.current = null;\n if (contributions.length === 0) setSceneShaderHooks(found);\n else publish();\n };\n }, []);\n\n useLayoutEffect(() => {\n contribution.current!.hooks = hooks ?? {};\n publish();\n }, [hooks]);\n}\n\nexport interface SceneShaderHooksProps {\n /**\n * Tree Shader Hooks every `<Tree>` and `<Forest>` (and every Tree and Forest made outside React) runs,\n * before its own. Keep hooks stable (module scope or `useMemo`): a new function is a new hook.\n */\n hooks: TreeShaderHooks;\n}\n\n/**\n * Declares scene-wide default Tree Shader Hooks (`setSceneShaderHooks`). Renders nothing. Several stack in\n * the order they mounted, after the hooks the scene had before; when the last one unmounts, those are put\n * back. Changing `hooks` only rebuilds the node graphs of the parts whose hooks changed, once.\n *\n * ```tsx\n * <SceneShaderHooks hooks={{ leaves: frosty }} />\n * ```\n */\nexport function SceneShaderHooks({ hooks }: SceneShaderHooksProps): null {\n useSceneShaderHooks(hooks);\n return null;\n}\n","import { use, useImperativeHandle, useLayoutEffect, useMemo, type Ref } from 'react';\n// Types only: the weather module is loaded with a dynamic import the first time a <SnowCover> or\n// <Wetness> renders, so apps that never use weather don't bundle it (ADR 0012).\nimport type {\n Snow,\n SnowCoverHooks,\n SnowCoverSettings,\n Wetness as WetnessAmount,\n WetnessHooks,\n WetnessSettings,\n} from '../weather';\nimport type { TreeShaderHooks } from '../materials/shader-hooks';\nimport { useSceneShaderHooks } from './SceneShaderHooks';\n\ntype WeatherModule = typeof import('../weather');\n\nlet weatherModule: Promise<WeatherModule> | undefined;\n\n/** The `@casmo/tree.js/weather` module, loaded once (a failed load is retried on the next render). */\nfunction weatherResource(): Promise<WeatherModule> {\n if (!weatherModule) {\n weatherModule = import('../weather');\n weatherModule.catch(() => (weatherModule = undefined));\n }\n return weatherModule;\n}\n\n/** Starts loading the weather module (Snow Cover, Wetness) ahead of time, without suspending. */\nexport function preloadWeather(): void {\n void weatherResource().catch(() => {});\n}\n\n/** Something with a 0..1 amount (a `Snow` or a `Wetness`). */\ninterface Amount {\n amount: number;\n}\n\n/** Writes `amount` (when given) to `source`, and puts back the amount it found on unmount. */\nfunction useAmount(source: Amount, amount: number | undefined): void {\n useLayoutEffect(() => {\n const previous = source.amount;\n return () => {\n source.amount = previous;\n };\n }, [source]);\n\n useLayoutEffect(() => {\n if (amount !== undefined) source.amount = amount;\n }, [source, amount]);\n}\n\n/**\n * Applies `settings` to ready-made weather hooks, unset settings at the hooks' defaults. Compared by value,\n * so an inline object with the same settings writes nothing.\n */\nfunction useSettings<S>(hooks: { readonly settings: object; set(settings: S): unknown }, settings: S): void {\n const defaults = useMemo(() => hooks.settings, [hooks]);\n const key = JSON.stringify(settings);\n useLayoutEffect(() => {\n const given = Object.fromEntries(Object.entries(settings as object).filter(([, value]) => value !== undefined));\n const strength = { ...(defaults as { strength: object }).strength, ...(given as { strength?: object }).strength };\n hooks.set({ ...defaults, ...given, strength } as S);\n // `key` stands for the settings by value.\n }, [hooks, defaults, key]);\n}\n\n/**\n * What `<SnowCover>` and `<Wetness>` share: the ready-made hooks with `settings` applied, `amount` written\n * to `source`, the hooks set scene-wide while mounted and handed to `ref`.\n */\nfunction useWeatherHooks<H extends TreeShaderHooks & { readonly settings: object; set(settings: S): unknown }, S>(\n hooks: H,\n source: Amount,\n amount: number | undefined,\n settings: S,\n ref: Ref<H | null> | undefined,\n): void {\n useSettings<S>(hooks, settings);\n useAmount(source, amount);\n useSceneShaderHooks(hooks);\n useImperativeHandle(ref, () => hooks, [hooks]);\n}\n\nexport interface SnowCoverProps extends SnowCoverSettings {\n /** The snow amount, 0 (none) .. 1 (full cover): written to `snow`. Unset: leave as is (default 0). */\n amount?: number;\n /** The `Snow` the hooks follow and `amount` drives. Default: the scene-wide `sceneSnow`. A new one makes new hooks. */\n snow?: Snow;\n /** Receives the ready-made Snow Cover hooks (`SnowCoverHooks`), e.g. to also hand them to a `<Tree shaderHooks>`. */\n ref?: Ref<SnowCoverHooks | null>;\n}\n\n/**\n * Declares Snow Cover (`@casmo/tree.js/weather`): while mounted, every tree runs the ready-made Snow Cover\n * hooks as scene-wide Tree Shader Hooks (before the app's own), whitening surfaces that face up by `amount`.\n * Renders nothing. `amount` and the settings are uniform writes (no rebuild); an unset setting is its\n * default. On unmount the hooks are removed and the amount it found is put back. Loads the weather module\n * on first use: suspends.\n *\n * ```tsx\n * <SnowCover amount={0.8} slope={60} />\n * ```\n */\nexport function SnowCover({ amount, snow, ref, ...settings }: SnowCoverProps): null {\n const { sceneSnow, snowCoverHooks } = use(weatherResource());\n const source = snow ?? sceneSnow;\n const hooks = useMemo(() => snowCoverHooks({ snow: source }), [snowCoverHooks, source]);\n useWeatherHooks<SnowCoverHooks, SnowCoverSettings>(hooks, source, amount, settings, ref);\n return null;\n}\n\nexport interface WetnessProps extends WetnessSettings {\n /** The wetness amount, 0 (dry) .. 1 (soaked): written to `wetness`. Unset: leave as is (default 0). */\n amount?: number;\n /** The `Wetness` the hooks follow and `amount` drives. Default: the scene-wide `sceneWetness`. A new one makes new hooks. */\n wetness?: WetnessAmount;\n /** Receives the ready-made Wetness hooks (`WetnessHooks`), e.g. to also hand them to a `<Tree shaderHooks>`. */\n ref?: Ref<WetnessHooks | null>;\n}\n\n/**\n * Declares Wetness (`@casmo/tree.js/weather`): while mounted, every tree runs the ready-made Wetness hooks\n * as scene-wide Tree Shader Hooks (before the app's own): darker, with a sheen, by `amount`. Renders\n * nothing. `amount` and the settings are uniform writes (no rebuild); an unset setting is its default. On\n * unmount the hooks are removed and the amount it found is put back. Loads the weather module on first\n * use: suspends.\n *\n * ```tsx\n * <Wetness amount={0.6} sheen={0.7} />\n * ```\n */\nexport function Wetness({ amount, wetness, ref, ...settings }: WetnessProps): null {\n const { sceneWetness, wetnessHooks } = use(weatherResource());\n const source = wetness ?? sceneWetness;\n const hooks = useMemo(() => wetnessHooks({ wetness: source }), [wetnessHooks, source]);\n useWeatherHooks<WetnessHooks, WetnessSettings>(hooks, source, amount, settings, ref);\n return null;\n}\n"],"mappings":";;;;;;;;AAKA,IAAM,wBAAQ,IAAI,IAAgC;AAElD,SAAS,cAAc,MAAqC;CAC1D,IAAI,UAAU,MAAM,IAAI,IAAI;CAC5B,IAAI,CAAC,SAAS;EACZ,UAAU,UAAU,IAAI;EACxB,MAAM,IAAI,MAAM,OAAO;EAEvB,QAAQ,YAAY,MAAM,OAAO,IAAI,CAAC;CACxC;CACA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,aAAa,MAA4B;CACvD,OAAO,IAAI,cAAc,IAAI,CAAC;AAChC;;AAGA,SAAgB,iBAAiB,MAAuB;CACtD,cAAmB,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC;AACzC;;;ACcA,IAAMA,6BAAW,IAAI,QAAoB;;;;;;AAOzC,SAAgB,KAAK,EACnB,YACA,OACA,OAAO,aACP,SACA,OAAO,GACP,SAAS,GACT,SAAS,GACT,MACA,aACA,aAAa,MACb,gBAAgB,MAChB,KACA,GAAG,cACS;CAEZ,MAAM,cAAc,eAAe,KAAA,KAAa,OAAO,UAAU,WAAW,aAAa,KAAK,IAAI;CAClG,MAAM,SAAS,eAAe,OAAO,gBAAgB,WA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EAAE,QAAQ,SAAS,KAAK,GAAG,YAAgC;CACjF,MAAM,EAAE,cAAc,iBAAiB,IAAI,gBAAgB,CAAC;CAC5D,MAAM,SAAS,WAAW;CAE1B,gBADc,cAAc,aAAa,EAAE,SAAS,OAAO,CAAC,GAAG,CAAC,cAAc,MAAM,CACrC,GAAO,QAAQ,QAAQ,UAAU,GAAG;CACnF,OAAO;AACT"}
|
package/dist/renderer/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import type { Renderer } from 'three/webgpu';
|
|
1
2
|
/** Thrown when a tree is drawn by anything other than `WebGPURenderer` (ADR 0002). */
|
|
2
3
|
export declare class UnsupportedRendererError extends Error {
|
|
3
4
|
constructor(what: string);
|
|
4
5
|
}
|
|
5
6
|
/** Throws {@link UnsupportedRendererError} unless `renderer` is a `WebGPURenderer` (either backend). */
|
|
6
7
|
export declare function assertWebGPURenderer(renderer: unknown): void;
|
|
8
|
+
/**
|
|
9
|
+
* @internal The renderer an `onBeforeRender` callback receives (typed as the classic renderer by
|
|
10
|
+
* three's types), as the `WebGPURenderer` it must be. Throws {@link UnsupportedRendererError} otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function webgpuRenderer(renderer: unknown): Renderer;
|
|
7
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderer/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,IAAI,EAAE,MAAM;CAQzB;AAOD,wGAAwG;AACxG,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAI5D"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderer/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,sFAAsF;AACtF,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,IAAI,EAAE,MAAM;CAQzB;AAOD,wGAAwG;AACxG,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAI5D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAG1D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Node } from 'three/webgpu';
|
|
2
|
+
import type { SceneEffectInput, SceneEffectStage } from './stage';
|
|
3
|
+
/**
|
|
4
|
+
* An anti-aliasing mode: SMAA (sharper, a few passes) or FXAA (one cheap pass, softer), both on
|
|
5
|
+
* display colours, last in the stack; or TRAA (temporal: jittered frames blended over time, the
|
|
6
|
+
* smoothest when still), on linear colours before tone mapping, with the Wind-aware velocity channel.
|
|
7
|
+
*/
|
|
8
|
+
export type SceneAntialiasMode = 'smaa' | 'fxaa' | 'traa';
|
|
9
|
+
/** What TRAA reads besides the colour: the scene pass's depth, its Wind-aware velocity and the camera. */
|
|
10
|
+
export type SceneAntialiasInput = Pick<SceneEffectInput, 'depth' | 'velocity' | 'camera'>;
|
|
11
|
+
/**
|
|
12
|
+
* Scene Effect: anti-aliasing. SMAA and FXAA run on display colours: pass them the tone mapped
|
|
13
|
+
* colour in the output colour space (e.g. the output of {@link sceneToneMapping}, or
|
|
14
|
+
* `renderOutput(color)`), and set `pipeline.outputColorTransform = false`. TRAA runs on linear
|
|
15
|
+
* colours, before tone mapping, and needs `input`: the scene pass's depth, its velocity (from
|
|
16
|
+
* `windVelocityMRT()`, so swaying leaves don't ghost) and the camera (which it jitters while the
|
|
17
|
+
* RenderPipeline renders).
|
|
18
|
+
*
|
|
19
|
+
* Side effect of `'traa'`: it sets `options.samples = 0` on the scene pass `depth` comes from (your
|
|
20
|
+
* `pass(scene, camera)`), turning its MSAA off for good: TRAA copies the depth each frame, which a
|
|
21
|
+
* multisampled depth cannot be (TRAA anti-aliases instead). The Scene Pipeline restores the old value
|
|
22
|
+
* when TRAA goes off; with this function, set `samples` back yourself if you drop TRAA.
|
|
23
|
+
*/
|
|
24
|
+
export declare function sceneAntialias(color: Node<'vec4'>, mode: SceneAntialiasMode, input?: SceneAntialiasInput): Node<'vec4'>;
|
|
25
|
+
/**
|
|
26
|
+
* The TRAA step of the stack, before tone mapping (as three requires), on the scene pass's depth and
|
|
27
|
+
* Wind-aware velocity (the Scene Pipeline turns the velocity channel on for it).
|
|
28
|
+
*/
|
|
29
|
+
export declare const traaStage: SceneEffectStage;
|
|
30
|
+
/**
|
|
31
|
+
* The SMAA / FXAA step of the stack, last (after tone mapping). Without tone mapping it applies the
|
|
32
|
+
* renderer's output transform itself, so it always runs on (and outputs) display colours.
|
|
33
|
+
*/
|
|
34
|
+
export declare const antialiasStage: SceneEffectStage;
|
|
35
|
+
//# sourceMappingURL=antialias.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"antialias.d.ts","sourceRoot":"","sources":["../../src/scene/antialias.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAA0B,MAAM,cAAc,CAAC;AAK1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGlE;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1D,0GAA0G;AAC1G,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC;AAiB1F;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,CAEvH;AA6DD;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,gBAOvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,gBAW5B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Camera, ContextNode, PassNode, Scene } from 'three/webgpu';
|
|
2
|
+
import type GTAONode from 'three/addons/tsl/display/GTAONode.js';
|
|
3
|
+
/** Ambient occlusion (GTAO) settings (all optional; every one is a uniform or a per-frame value). */
|
|
4
|
+
export interface SceneAOOptions {
|
|
5
|
+
/** How far around a pixel occluders are searched, in metres (default 1). */
|
|
6
|
+
radius?: number;
|
|
7
|
+
/** How strong the occlusion is (default 1; lower = lighter). */
|
|
8
|
+
scale?: number;
|
|
9
|
+
/** How thick occluders are assumed to be, in metres (default 1). */
|
|
10
|
+
thickness?: number;
|
|
11
|
+
/** How fast the occlusion falls off with distance (default 1). */
|
|
12
|
+
distanceExponent?: number;
|
|
13
|
+
/** How much occluders far from the pixel count (default 1). */
|
|
14
|
+
distanceFallOff?: number;
|
|
15
|
+
/** Samples per pixel (default 16; more = smoother and slower). */
|
|
16
|
+
samples?: number;
|
|
17
|
+
/** The AO buffer's size relative to the canvas (default 1; e.g. 0.5 for half resolution). */
|
|
18
|
+
resolutionScale?: number;
|
|
19
|
+
}
|
|
20
|
+
/** What {@link sceneAO} returns: put the pre-pass and AO in your pipeline through the lighting context. */
|
|
21
|
+
export interface SceneAO {
|
|
22
|
+
/** The depth + view-normal pre-pass (the scene drawn once more, before the scene pass). */
|
|
23
|
+
prePass: PassNode;
|
|
24
|
+
/** The GTAO node (its result: `node.getTextureNode()`). */
|
|
25
|
+
node: GTAONode;
|
|
26
|
+
/**
|
|
27
|
+
* A built-in AO lighting context: set it as your scene pass's `contextNode`, so the AO only
|
|
28
|
+
* darkens ambient (indirect) light, not direct sunlight.
|
|
29
|
+
*/
|
|
30
|
+
context: ContextNode<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Scene Effect: ground-contact ambient occlusion (GTAO). Returns a depth + view-normal pre-pass,
|
|
34
|
+
* GTAO on it and a lighting context; in your own pipeline set `scenePass.contextNode = context`.
|
|
35
|
+
* The scene is drawn twice while AO is on.
|
|
36
|
+
*/
|
|
37
|
+
export declare function sceneAO(scene: Scene, camera: Camera, options?: SceneAOOptions): SceneAO;
|
|
38
|
+
/** {@link sceneAO} with `update()` (numbers only) and `dispose()` (the pre-pass and the AO target). */
|
|
39
|
+
export declare function liveSceneAO(scene: Scene, camera: Camera, options: SceneAOOptions): {
|
|
40
|
+
prePass: PassNode;
|
|
41
|
+
node: GTAONode;
|
|
42
|
+
context: ContextNode<unknown>;
|
|
43
|
+
update: (o: SceneAOOptions) => void;
|
|
44
|
+
dispose(): void;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=ao.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ao.d.ts","sourceRoot":"","sources":["../../src/scene/ao.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAGzE,OAAO,KAAK,QAAQ,MAAM,sCAAsC,CAAC;AAEjE,qGAAqG;AACrG,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6FAA6F;IAC7F,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,2GAA2G;AAC3G,MAAM,WAAW,OAAO;IACtB,2FAA2F;IAC3F,OAAO,EAAE,QAAQ,CAAC;IAClB,2DAA2D;IAC3D,IAAI,EAAE,QAAQ,CAAC;IACf;;;OAGG;IACH,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAG3F;AAED,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;;;;gBAI5D,cAAc,KAAG,IAAI;eAgB3B,IAAI;EAKlB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Node } from 'three/webgpu';
|
|
2
|
+
import type { SceneEffectStage } from './stage';
|
|
3
|
+
/** Bloom settings (all optional; all uniforms). */
|
|
4
|
+
export interface SceneBloomOptions {
|
|
5
|
+
/** How much glare is added (default 0.3). */
|
|
6
|
+
strength?: number;
|
|
7
|
+
/** How far the glare spreads, 0..1 (default 0.5). */
|
|
8
|
+
radius?: number;
|
|
9
|
+
/** Only colours brighter than this (linear luminance, before tone mapping) glow (default 0.6; a plain light sky is about 0.6). */
|
|
10
|
+
threshold?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Scene Effect: bloom, a soft glare around the bright (HDR) parts of the frame, added onto the
|
|
14
|
+
* colour. Use it on linear colours before tone mapping.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sceneBloom(color: Node<'vec4'>, options?: SceneBloomOptions): Node<'vec4'>;
|
|
17
|
+
/** The bloom step of the stack (one graph for all settings: every number is a uniform). */
|
|
18
|
+
export declare const bloomStage: SceneEffectStage;
|
|
19
|
+
//# sourceMappingURL=bloom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloom.d.ts","sourceRoot":"","sources":["../../src/scene/bloom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kIAAkI;IAClI,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC,CAE7F;AAkBD,2FAA2F;AAC3F,eAAO,MAAM,UAAU,EAAE,gBAMxB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ColorRepresentation, type Node, type Scene } from 'three/webgpu';
|
|
2
|
+
/** A far layer of the height mist: a thinner haze over the whole height, far away (all optional). */
|
|
3
|
+
export interface SceneMistFarLayerOptions {
|
|
4
|
+
/** Where the far layer starts, in metres from the camera (default 30). */
|
|
5
|
+
near?: number;
|
|
6
|
+
/** Where the far layer reaches its strength, in metres (default 120). */
|
|
7
|
+
far?: number;
|
|
8
|
+
/** Its strength at `far`, 0-1 (default 0.4). */
|
|
9
|
+
strength?: number;
|
|
10
|
+
}
|
|
11
|
+
/** A height mist: fog that lies low, below `height` (all optional). */
|
|
12
|
+
export interface SceneMistOptions {
|
|
13
|
+
/** The mist's top, in metres above y = 0: densest at the ground, gone at this height (default 2). */
|
|
14
|
+
height?: number;
|
|
15
|
+
/** How dense the mist gets far away, 0-1 (default 0.7). */
|
|
16
|
+
strength?: number;
|
|
17
|
+
/** Where the mist starts, in metres from the camera (default 8). */
|
|
18
|
+
near?: number;
|
|
19
|
+
/** Where the mist reaches its strength, in metres from the camera (default 40). */
|
|
20
|
+
far?: number;
|
|
21
|
+
/** A thinner haze far away, over the whole height (`null` / left out = none). */
|
|
22
|
+
farLayer?: SceneMistFarLayerOptions | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fog settings, in metres, tuned for a small forest scene (all optional; every number and the
|
|
26
|
+
* colour are uniforms). Scale the distances up for large worlds.
|
|
27
|
+
*/
|
|
28
|
+
export interface SceneFogOptions {
|
|
29
|
+
/** The fog colour. Default: `scene.background` when that is a plain Color, otherwise a pale sky blue. */
|
|
30
|
+
color?: ColorRepresentation;
|
|
31
|
+
/** Where the distance fog starts, in metres from the camera (default 10). */
|
|
32
|
+
near?: number;
|
|
33
|
+
/** Where the distance fog is complete, in metres from the camera (default 80). */
|
|
34
|
+
far?: number;
|
|
35
|
+
/** A low height mist on top of the distance fog (`null` / left out = none). */
|
|
36
|
+
mist?: SceneMistOptions | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Scene Effect: distance fog plus an optional low height mist, as a fog node for `scene.fogNode`
|
|
40
|
+
* (three applies it in every material). `background` is the scene's background: when it is a plain
|
|
41
|
+
* Color, that is the default fog colour, so far trees fade into the sky. Pass `scene.background`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function sceneFog(options?: SceneFogOptions, background?: Scene['background']): Node;
|
|
44
|
+
/** {@link sceneFog} with `update()`: new numbers and colour, the same node (no material recompile). */
|
|
45
|
+
export declare function liveSceneFog(options: SceneFogOptions, background?: Scene['background']): {
|
|
46
|
+
node: Node;
|
|
47
|
+
update: (o: SceneFogOptions, bg?: Scene["background"]) => void;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=fog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fog.d.ts","sourceRoot":"","sources":["../../src/scene/fog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,mBAAmB,EAAE,KAAK,IAAI,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAGtF,qGAAqG;AACrG,MAAM,WAAW,wBAAwB;IACvC,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,uEAAuE;AACvE,MAAM,WAAW,gBAAgB;IAC/B,qGAAqG;IACrG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,QAAQ,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,yGAAyG;IACzG,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kFAAkF;IAClF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,IAAI,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC;AAKD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI,CAE9F;AAED,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;UAgCrC,IAAI;gBArBjC,eAAe,OAAO,KAAK,CAAC,YAAY,CAAC,KAAG,IAAI;EAsBpE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Camera, type ColorRepresentation, type DirectionalLight, type Light, type Node, type PointLight, type TextureNode } from 'three/webgpu';
|
|
2
|
+
import { type SceneEffectStage } from './stage';
|
|
3
|
+
/** God rays settings (all optional; every colour and number is a uniform). */
|
|
4
|
+
export interface SceneGodraysOptions {
|
|
5
|
+
/** How dense the lit air is: more makes brighter shafts and haze (default 1.5). */
|
|
6
|
+
density?: number;
|
|
7
|
+
/** The most the shafts cover a pixel, 0..1 (default 0.5). */
|
|
8
|
+
maxDensity?: number;
|
|
9
|
+
/** How fast the shafts fade with the distance from the sun's shadow camera (default 0.6). */
|
|
10
|
+
distanceAttenuation?: number;
|
|
11
|
+
/** The colour of the light in the shafts (default '#fff0c8', warm sunlight). */
|
|
12
|
+
color?: ColorRepresentation;
|
|
13
|
+
/** The search radius in pixels for depth edges in the blend, against light leaking around trunks (default 2). */
|
|
14
|
+
edgeRadius?: number;
|
|
15
|
+
/** How far the blend steps away from a depth edge, in pixels (default 2). */
|
|
16
|
+
edgeStrength?: number;
|
|
17
|
+
}
|
|
18
|
+
/** A light god rays can use: a directional or point light that casts shadows. */
|
|
19
|
+
export type SceneGodraysSun = DirectionalLight | PointLight;
|
|
20
|
+
/** Why `sun` cannot drive god rays, or `undefined` when it can. */
|
|
21
|
+
export declare function godraysSunProblem(sun: Light | undefined): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Scene Effect: god rays, light shafts through the canopy, raymarched through the shadow map of a
|
|
24
|
+
* shadow-casting `sun` and blended depth-aware onto `color` (no light leaking around trunks and
|
|
25
|
+
* leaves). Needs a full shadow setup by the app: `renderer.shadowMap.enabled`, the sun's
|
|
26
|
+
* `castShadow` and casting objects; nothing is changed here. `depth` and `camera` are those of the
|
|
27
|
+
* scene pass. Returns a colour node (not display colours).
|
|
28
|
+
*/
|
|
29
|
+
export declare function sceneGodrays(color: Node<'vec4'>, depth: TextureNode, camera: Camera, sun: SceneGodraysSun, options?: SceneGodraysOptions): Node<'vec4'>;
|
|
30
|
+
/** Warns that god rays are skipped, and why. */
|
|
31
|
+
export declare function warnGodraysSkipped(problem: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* The god rays step of the stack. It reads `input.depth`, `input.camera` and `input.sun`; without a
|
|
34
|
+
* usable sun it is skipped with a console warning (the Scene Pipeline leaves it out before, warning once).
|
|
35
|
+
*/
|
|
36
|
+
export declare const godraysStage: SceneEffectStage;
|
|
37
|
+
//# sourceMappingURL=godrays.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"godrays.d.ts","sourceRoot":"","sources":["../../src/scene/godrays.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,MAAM,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAI7J,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3D,8EAA8E;AAC9E,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6FAA6F;IAC7F,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gFAAgF;IAChF,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,iHAAiH;IACjH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAE5D,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAM5E;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EACnB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,eAAe,EACpB,OAAO,GAAE,mBAAwB,GAChC,IAAI,CAAC,MAAM,CAAC,CAEd;AA0BD,gDAAgD;AAChD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAExD;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,gBAW1B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createScenePipeline, ScenePipeline, type ScenePipelineChoice, type ScenePipelineOptions, type ScenePipelineSettings, } from './pipeline';
|
|
2
|
+
export { sceneAntialias, type SceneAntialiasInput, type SceneAntialiasMode } from './antialias';
|
|
3
|
+
export { type SceneEffectsChoice, type SceneEffectsSettings } from './settings';
|
|
4
|
+
export { sceneAO, type SceneAO, type SceneAOOptions } from './ao';
|
|
5
|
+
export { sceneBloom, type SceneBloomOptions } from './bloom';
|
|
6
|
+
export { sceneMotionBlur, type SceneMotionBlurOptions } from './motion-blur';
|
|
7
|
+
export { SUGGESTED_SCENE_EFFECTS } from './suggested';
|
|
8
|
+
export { applySceneEffects } from './stack';
|
|
9
|
+
export { type SceneEffectInput } from './stage';
|
|
10
|
+
export { sceneFog, type SceneFogOptions, type SceneMistFarLayerOptions, type SceneMistOptions } from './fog';
|
|
11
|
+
export { sceneToneMapping, type SceneToneMappingCurve, type SceneToneMappingOptions } from './tone-mapping';
|
|
12
|
+
export { sceneGodrays, type SceneGodraysOptions, type SceneGodraysSun } from './godrays';
|
|
13
|
+
export { windVelocity, windVelocityMRT, WIND_VELOCITY, type ScenePass } from './velocity';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scene/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,wBAAwB,EAAE,KAAK,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Node, TextureNode } from 'three/webgpu';
|
|
2
|
+
import { type SceneEffectStage } from './stage';
|
|
3
|
+
/** Motion blur settings (all optional; all uniforms). */
|
|
4
|
+
export interface SceneMotionBlurOptions {
|
|
5
|
+
/**
|
|
6
|
+
* How long the shutter is open, in frames: the blur streak is this many frames of motion long
|
|
7
|
+
* (default 1). 0 = no blur.
|
|
8
|
+
*/
|
|
9
|
+
strength?: number;
|
|
10
|
+
/** Colour samples along each pixel's motion; more is smoother and costs more (default 16). */
|
|
11
|
+
samples?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Scene Effect: motion blur. Smears each pixel along its screen-space motion, read from `velocity`
|
|
15
|
+
* (NDC units per frame, as three's `velocity`). Use the scene pass's Wind-aware velocity
|
|
16
|
+
* (`windVelocityMRT()`, or `scenePass.velocity` of a Scene Pipeline with motion blur), so that Wind
|
|
17
|
+
* sway blurs as well as camera and object motion. Use it on linear colours, after god rays and
|
|
18
|
+
* before bloom. Returns a colour node.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sceneMotionBlur(color: Node<'vec4'>, velocity: TextureNode, options?: SceneMotionBlurOptions): Node<'vec4'>;
|
|
21
|
+
/** The motion blur step of the stack: reads `input.velocity` (the Scene Pipeline requests it). */
|
|
22
|
+
export declare const motionBlurStage: SceneEffectStage;
|
|
23
|
+
//# sourceMappingURL=motion-blur.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion-blur.d.ts","sourceRoot":"","sources":["../../src/scene/motion-blur.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3D,yDAAyD;AACzD,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,GAAE,sBAA2B,GAAG,IAAI,CAAC,MAAM,CAAC,CAE9H;AAgCD,kGAAkG;AAClG,eAAO,MAAM,eAAe,EAAE,gBAO7B,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RenderPipeline, type Camera, type Light, type Object3D, type Renderer, type Scene } from 'three/webgpu';
|
|
2
|
+
import type { TreeEffectsChoice } from '../effects/effects';
|
|
3
|
+
import { type CustomTreeEffect, type CustomTreeEffectOptions } from '../effects/custom';
|
|
4
|
+
import type { TreeEffectsSettings } from '../effects/suggested';
|
|
5
|
+
import type { StyleName } from '../styles/registry';
|
|
6
|
+
import type { ForestTree } from '../forest';
|
|
7
|
+
import type { Tree } from '../tree';
|
|
8
|
+
import { type SceneEffectsChoice, type SceneEffectsSettings } from './settings';
|
|
9
|
+
import { type ScenePass } from './velocity';
|
|
10
|
+
/**
|
|
11
|
+
* Which Tree Effects and Scene Effects to render. `style` picks both of that Style's suggestions;
|
|
12
|
+
* `treeEffects` and `sceneEffects` replace a whole group (a Style name, settings or `null` = none;
|
|
13
|
+
* no deep merge: spread the suggestion to change part of it). Nothing set = nothing added.
|
|
14
|
+
*/
|
|
15
|
+
export interface ScenePipelineChoice {
|
|
16
|
+
style?: StyleName;
|
|
17
|
+
treeEffects?: TreeEffectsChoice;
|
|
18
|
+
sceneEffects?: SceneEffectsChoice;
|
|
19
|
+
}
|
|
20
|
+
export interface ScenePipelineOptions extends ScenePipelineChoice {
|
|
21
|
+
/** A shadow-casting light for god rays (never changed by the pipeline). */
|
|
22
|
+
sun?: Light;
|
|
23
|
+
/** The trees to outline (as `TreeEffectsOptions.selection`). Default: every tree. */
|
|
24
|
+
selection?: Object3D[];
|
|
25
|
+
/** Keeps the Tree ID channel on for {@link ScenePipeline.pick} (as `TreeEffectsOptions.treeId`). */
|
|
26
|
+
treeId?: boolean;
|
|
27
|
+
/** The trees the Highlight marks (as `TreeEffectsOptions.highlighted`). */
|
|
28
|
+
highlighted?: (Tree | ForestTree)[];
|
|
29
|
+
/**
|
|
30
|
+
* Keeps the Wind-aware velocity channel on (`scenePass.velocity`, see `windVelocityMRT`), e.g. for
|
|
31
|
+
* your own temporal effects. TRAA and motion blur turn it on by themselves.
|
|
32
|
+
*/
|
|
33
|
+
velocity?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The resolved settings of a Scene Pipeline (`{}` = none in a group). */
|
|
36
|
+
export interface ScenePipelineSettings {
|
|
37
|
+
treeEffects: TreeEffectsSettings;
|
|
38
|
+
sceneEffects: SceneEffectsSettings;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The Scene Pipeline: renders the scene with Tree Effects and Scene Effects in one `RenderPipeline`.
|
|
42
|
+
* A superset of `TreeEffects` (use it instead). It never changes the renderer (tone mapping and the
|
|
43
|
+
* output colour space are applied inside the pipeline). With nothing set it adds nothing: the
|
|
44
|
+
* same image as `renderer.render(scene, camera)`.
|
|
45
|
+
*/
|
|
46
|
+
export declare class ScenePipeline {
|
|
47
|
+
private readonly renderer;
|
|
48
|
+
private readonly scene;
|
|
49
|
+
private readonly camera;
|
|
50
|
+
private readonly options;
|
|
51
|
+
readonly pipeline: RenderPipeline;
|
|
52
|
+
/** The trees the Highlight marks (the `highlighted` option, or an empty list): change it in place. */
|
|
53
|
+
readonly highlighted: (Tree | ForestTree)[];
|
|
54
|
+
private current;
|
|
55
|
+
private readonly custom;
|
|
56
|
+
private graph;
|
|
57
|
+
private input;
|
|
58
|
+
/** Nothing is on (no effects, no extra channel): render with `renderer.render()` itself. */
|
|
59
|
+
private passThrough;
|
|
60
|
+
/** The pipeline's fog while it is on, and the app's `scene.fogNode` it replaced (restored when off). */
|
|
61
|
+
private fog;
|
|
62
|
+
/** God rays were skipped for want of a shadow-casting sun, and that was said once. */
|
|
63
|
+
private warnedSun;
|
|
64
|
+
constructor(renderer: Renderer, scene: Scene, camera: Camera, options?: ScenePipelineOptions);
|
|
65
|
+
/** The scene pass; replaced (the old one disposed) when {@link set} needs another set of channels. */
|
|
66
|
+
get scenePass(): ScenePass;
|
|
67
|
+
/** The active Tree Effects and Scene Effects. */
|
|
68
|
+
get settings(): ScenePipelineSettings;
|
|
69
|
+
/**
|
|
70
|
+
* Switches Style or settings (the same rules as the options). With the same parts on, only
|
|
71
|
+
* uniforms change (no recompile); otherwise a new graph is built and the old one freed.
|
|
72
|
+
*/
|
|
73
|
+
set(choice: ScenePipelineChoice): void;
|
|
74
|
+
/** The app's own Tree Effects, in the order they were added (see {@link addEffect}). */
|
|
75
|
+
get customEffects(): readonly CustomTreeEffect<never>[];
|
|
76
|
+
/**
|
|
77
|
+
* Adds a Tree Effect of the app's own (as `TreeEffects.addEffect()`): it runs at the place it names
|
|
78
|
+
* among the built-in Tree Effects, so before every Scene Effect. It stays through {@link set} until
|
|
79
|
+
* {@link removeEffect}. Builds a new graph, and a new scene pass if it declares a channel that is not on yet.
|
|
80
|
+
*/
|
|
81
|
+
addEffect<Options>(effect: CustomTreeEffect<Options>, ...[options]: CustomTreeEffectOptions<Options>): void;
|
|
82
|
+
/** Changes the options of an added custom effect live, through its `update()` (no new graph, no recompile). */
|
|
83
|
+
updateEffect<Options>(effect: CustomTreeEffect<Options>, options: Options): void;
|
|
84
|
+
/** Removes a custom effect (nothing happens if it is not added); its channels go when nothing else needs them. */
|
|
85
|
+
removeEffect<Options>(effect: CustomTreeEffect<Options>): void;
|
|
86
|
+
/** Brings the scene pass, the graph and the fog in line with the settings and the custom effects. */
|
|
87
|
+
private rebuild;
|
|
88
|
+
/**
|
|
89
|
+
* GPU picking, as `TreeEffects.pick()`: the Tree or Forest tree under a canvas point (CSS pixels)
|
|
90
|
+
* in the last render. Needs the Tree ID channel (the `treeId: true` option).
|
|
91
|
+
*/
|
|
92
|
+
pick(x: number, y: number): Promise<Tree | ForestTree | undefined>;
|
|
93
|
+
/** Renders the scene (call instead of `renderer.render(scene, camera)`). */
|
|
94
|
+
render(): void;
|
|
95
|
+
dispose(): void;
|
|
96
|
+
/** Fog is the one scene change (ADR 0010): take over `scene.fogNode`, remembering the app's value. */
|
|
97
|
+
private setFog;
|
|
98
|
+
/** Gives `scene.fogNode` back to the app (unless the app replaced the pipeline's fog meanwhile). */
|
|
99
|
+
private restoreFog;
|
|
100
|
+
/**
|
|
101
|
+
* The Scene Effects that can run: without a shadow-casting `sun`, god rays are left out (with one
|
|
102
|
+
* console warning per pipeline). Shadows and lights are never changed.
|
|
103
|
+
*/
|
|
104
|
+
private usableSceneEffects;
|
|
105
|
+
private disposeGraph;
|
|
106
|
+
}
|
|
107
|
+
/** Shorthand for `new ScenePipeline(renderer, scene, camera, options)`. */
|
|
108
|
+
export declare function createScenePipeline(renderer: Renderer, scene: Scene, camera: Camera, options?: ScenePipelineOptions): ScenePipeline;
|
|
109
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/scene/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAa,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAS5H,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAwB,KAAK,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAuB,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAKrG,OAAO,EAAmB,KAAK,SAAS,EAA0B,MAAM,YAAY,CAAC;AAErF;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC;AAED,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,2EAA2E;IAC3E,GAAG,CAAC,EAAE,KAAK,C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AI;IAKtC,wFAAwF;IACxF,IAAI,aAAa,IAAI,SAAS,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAEtD;IAED;;;;OAIG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,IAAI;IAK3G,+GAA+G;IAC/G,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAIhF,kHAAkH;IAClH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,IAAI;IAI9D,qGAAqG;IACrG,OAAO,CAAC,OAAO;IAwCf;;;OAGG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC;IAMlE,4EAA4E;IAC5E,MAAM,IAAI,IAAI;IAMd,OAAO,IAAI,IAAI;IAOf,sGAAsG;IACtG,OAAO,CAAC,MAAM;IASd,oGAAoG;IACpG,OAAO,CAAC,UAAU;IAMlB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,YAAY;CAUrB;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAEnI"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { StyleName } from '../styles/registry';
|
|
2
|
+
import type { SceneGodraysOptions } from './godrays';
|
|
3
|
+
import type { SceneAOOptions } from './ao';
|
|
4
|
+
import type { SceneAntialiasMode } from './antialias';
|
|
5
|
+
import type { SceneBloomOptions } from './bloom';
|
|
6
|
+
import type { SceneMotionBlurOptions } from './motion-blur';
|
|
7
|
+
import type { SceneToneMappingOptions } from './tone-mapping';
|
|
8
|
+
import type { SceneFogOptions } from './fog';
|
|
9
|
+
/**
|
|
10
|
+
* A combination of Scene Effects; leave an effect out to skip it. `{}` = no Scene Effects.
|
|
11
|
+
* One optional field per Scene Effect (its options type lives in the effect's own file).
|
|
12
|
+
*/
|
|
13
|
+
export interface SceneEffectsSettings {
|
|
14
|
+
/** Tone mapping and the output colour space, applied inside the pipeline. */
|
|
15
|
+
toneMapping?: SceneToneMappingOptions;
|
|
16
|
+
/** God rays through the canopy; need a shadow-casting `sun` (skipped with a warning otherwise). */
|
|
17
|
+
godrays?: SceneGodraysOptions;
|
|
18
|
+
/** Ground-contact ambient occlusion (GTAO) in the scene pass's lighting: darkens ambient light only. */
|
|
19
|
+
ao?: SceneAOOptions;
|
|
20
|
+
/** Motion blur along the Wind-aware velocity (camera, object and Wind motion); never suggested. */
|
|
21
|
+
motionBlur?: SceneMotionBlurOptions;
|
|
22
|
+
/** Bloom: a soft glare around the bright parts of the frame, before tone mapping. */
|
|
23
|
+
bloom?: SceneBloomOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Anti-aliasing; `null` = none. SMAA / FXAA: of the display colours, last in the stack. TRAA:
|
|
26
|
+
* before tone mapping, with the Wind-aware velocity channel (never suggested).
|
|
27
|
+
*/
|
|
28
|
+
antialias?: SceneAntialiasMode | null;
|
|
29
|
+
/** Distance fog and height mist, set as `scene.fogNode` (the app's value is restored). */
|
|
30
|
+
fog?: SceneFogOptions;
|
|
31
|
+
}
|
|
32
|
+
/** The suggested Scene Effects of a built-in Style, or the settings themselves; `null` = none. */
|
|
33
|
+
export type SceneEffectsChoice = StyleName | SceneEffectsSettings | null;
|
|
34
|
+
/** The settings of a choice; throws for an unknown Style. */
|
|
35
|
+
export declare function resolveSceneEffects(choice: SceneEffectsChoice): SceneEffectsSettings;
|
|
36
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/scene/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAG7C;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,6EAA6E;IAC7E,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACtC,mGAAmG;IACnG,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,wGAAwG;IACxG,EAAE,CAAC,EAAE,cAAc,CAAC;IACpB,mGAAmG;IACnG,UAAU,CAAC,EAAE,sBAAsB,CAAC;IACpC,qFAAqF;IACrF,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACtC,0FAA0F;IAC1F,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB;AAED,kGAAkG;AAClG,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,oBAAoB,GAAG,IAAI,CAAC;AAEzE,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,oBAAoB,CAMpF"}
|