@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
|
@@ -25,4 +25,6 @@ export declare function fruitGeometry(fruit: SkeletonFruit[], { type, sides }: {
|
|
|
25
25
|
}, level: number, seed: number, variation: Pick<VariationDefinition, 'season'>, growth: GrowthWindow[], branchSway: ReadonlyMap<string, PartSway>): GeometryBuffers;
|
|
26
26
|
/** Empty geometry buffers (a tree without Fruit). */
|
|
27
27
|
export declare function emptyGeometry(): GeometryBuffers;
|
|
28
|
+
/** At or below this many sides, Fruit uses the coarse profiles (and the nut a plain icosahedron). */
|
|
29
|
+
export declare const COARSE_SIDES = 5;
|
|
28
30
|
//# sourceMappingURL=fruit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fruit.d.ts","sourceRoot":"","sources":["../../src/generator/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AAEpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAKxC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAQ,MAAM,SAAS,CAAC;AAClG,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAahD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,CAuClH;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,YAAY,EAAE,CAK/H;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,aAAa,EAAE,EACtB,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,EAChE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,EAC9C,MAAM,EAAE,YAAY,EAAE,EACtB,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,GACxC,eAAe,CAcjB;AAED,qDAAqD;AACrD,wBAAgB,aAAa,IAAI,eAAe,CAS/C;AAqED,qGAAqG;AACrG,eAAO,MAAM,YAAY,IAAI,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TreeDefinition } from '../definition';
|
|
2
2
|
import type { GeometryBuffers, TreeData, TreeSkeleton } from './types';
|
|
3
3
|
export { growthTiming } from './growth';
|
|
4
|
+
export { generateLightTree, lightDefinition } from './light';
|
|
4
5
|
export { crownDistance, crownNormal, type CrownVolume } from './crown';
|
|
5
6
|
export type { GrowthTiming, GrowthWindow, GeometryBuffers, TreeAttributes, VertexAttribute, SkeletonBranch, SkeletonFruit, SkeletonRoot, SkeletonLeaf, SkeletonPoint, TreeData, TreeSkeleton, Vec3 } from './types';
|
|
6
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAepD,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpN;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CA8D/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,MAAM,CAI5E;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAInD"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAepD,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpN;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CA8D/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,MAAM,CAI5E;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAInD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type DefinitionPatch, type TreeDefinition } from '../definition';
|
|
2
|
+
import type { TreeData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* The Light Definition (ADR 0010): the Definition a Forest's Light Detail Level is generated from.
|
|
5
|
+
* Fixed reductions of `definition`:
|
|
6
|
+
* - about half the sides and sections of the trunk and every branch level (at least 3 sides, 1 section),
|
|
7
|
+
* half the sides of the Roots and half the extra rings of the Root Flare;
|
|
8
|
+
* - the deepest branch level dropped (when there are at least two and it has branches), and the leaves
|
|
9
|
+
* then grow on the level above, larger by the square root of the dropped level's `count` (at most
|
|
10
|
+
* {@link MAX_LEAF_GROWTH} times) to keep the crown filled;
|
|
11
|
+
* - with a single branch level kept: half the leaves per branch, larger to keep the same leaf area;
|
|
12
|
+
* - coarse Fruit: half the sides, at most {@link COARSE_SIDES} (at least 3).
|
|
13
|
+
*
|
|
14
|
+
* Then `override` is merged on top (like {@link extendDefinition}: objects deeply, arrays replace) and the
|
|
15
|
+
* result is validated. Pure and deterministic; never mutates `definition`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function lightDefinition(definition: TreeDefinition, override?: DefinitionPatch): TreeDefinition;
|
|
18
|
+
/**
|
|
19
|
+
* The Light Detail Level of a Variant (ADR 0010): the tree of `definition` and `seed`, generated from its
|
|
20
|
+
* {@link lightDefinition} (with `override`) so that it keeps every surviving branch in place:
|
|
21
|
+
*
|
|
22
|
+
* - the skeleton grows with the Full Definition's sections (branch paths fork their randomness, ADR 0003,
|
|
23
|
+
* so every branch the Light level keeps lies exactly where it does in the Full tree); the wood mesh then
|
|
24
|
+
* sweeps only every other skeleton point (the Light sections) with the Light sides;
|
|
25
|
+
* - leaves grow on the outermost Light branches, and only where the Full tree has leaves on that branch
|
|
26
|
+
* or the branches growing from it (Sculpts deleting branches or painting leaves carry over);
|
|
27
|
+
* - about half the Full tree's Fruit (each kept or not by its own stable random number) hangs where it
|
|
28
|
+
* hangs in Full, drawn coarse (a Fruit that is already coarse cannot get fewer faces otherwise).
|
|
29
|
+
*
|
|
30
|
+
* Growth, Wind and Season attributes are those of the Full tree: a surviving branch (and its Fruit) grows,
|
|
31
|
+
* sways and changes with the Season exactly as in Full; a Light leaf grows from the first to the last Full
|
|
32
|
+
* leaf on its branch. Leaves and Fruit keep the Full `aLevel`. With `materials.occlusion` the meshes carry
|
|
33
|
+
* `aOcclusion` like Full, so the Light meshes can share the Variant's materials. Pure and deterministic.
|
|
34
|
+
*/
|
|
35
|
+
export declare function generateLightTree(definition: TreeDefinition, seed: number, override?: DefinitionPatch): TreeData;
|
|
36
|
+
//# sourceMappingURL=light.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"light.d.ts","sourceRoot":"","sources":["../../src/generator/light.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAe5F,OAAO,KAAK,EAAgC,QAAQ,EAAE,MAAM,SAAS,CAAC;AAgBtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,GAAE,eAAoB,GAAG,cAAc,CAyB1G;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,QAAQ,CAsFhH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,14 +4,15 @@ export * from './season';
|
|
|
4
4
|
export { crownDistance, crownNormal, hashGeometry, hashTreeData, type CrownVolume, type TreeData, type GrowthTiming, type GrowthWindow, type TreeSkeleton, type SkeletonBranch, type SkeletonPoint, type SkeletonLeaf, type SkeletonFruit, type SkeletonRoot, type GeometryBuffers, type TreeAttributes, type VertexAttribute, type Vec3, } from './generator';
|
|
5
5
|
export { createRandom, type Random } from './random';
|
|
6
6
|
export { createBarkMaterial, createLeafMaterial } from './materials';
|
|
7
|
+
export { getSceneShaderHooks, setSceneShaderHooks, stackShaderHooks, type TreeShaderHook, type TreeShaderHooks, type TreeShaderInput, type TreeShaderOutput, } from './materials/shader-hooks';
|
|
7
8
|
export { DEFAULT_TEXTURE_BASE_PATH, getTextureOptions, loadTexture, resolveTextureUrl, setTextureOptions, textureReady, type TextureKind, type TextureOptions, } from './textures';
|
|
8
9
|
export { assertWebGPURenderer, UnsupportedRendererError } from './renderer';
|
|
9
|
-
export { Wind, sceneWind, WindResponse, type WindDirection, type WindOptions } from './wind';
|
|
10
|
+
export { Wind, sceneWind, WindResponse, MAX_WIND_BURSTS, WIND_BURST_LIFETIME, WIND_BURST_REACH, type WindBurst, type WindBurstOptions, type WindDirection, type WindOptions, } from './wind';
|
|
10
11
|
export type { TreeStyle } from './styles/types';
|
|
11
12
|
export type { StyleSource } from './styles/apply';
|
|
12
13
|
export type { SpeciesDefinition, SpeciesTrunkDefinition, SpeciesBranchLevelDefinition, SpeciesFoliageDefinition, SpeciesBarkDefinition, SpeciesFruitDefinition, SpeciesRootsDefinition, } from './species/types';
|
|
13
14
|
export { loadStyle, STYLE_NAMES, styleLabel, styleOfShading, type StyleName } from './styles/registry';
|
|
14
15
|
export { materialFeaturesOf, SUGGESTED_MATERIAL_FEATURES, withMaterialFeatures } from './styles/material-features';
|
|
15
16
|
export { bakeTree, disposeBakedTree, exportBakedTree, type BakeOptions, type ExportBakedTreeOptions, type MaterialFeatureExtras, } from './bake';
|
|
16
|
-
export { createForest, Forest, ForestTree, ForestVariant, type ForestOptions, type ForestPlacement, type ForestInstanceState, type ForestTreeTraits, } from './forest';
|
|
17
|
+
export { createForest, Forest, ForestTree, ForestVariant, type ForestOptions, type ForestPlacement, type ForestInstanceState, type ForestTreeTraits, DetailLevel, selectDetailLevel, type DetailLevelSelection, type ForestLodOptions, type ForestLodSettings, type ForestLodUpdate, type ImpostorAtlasOptions, } from './forest';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AACpF,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,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,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,WAAW,EACX,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as hashTreeData, B as leafSeasonAttribute, C as getTextureOptions, D as textureReady, E as setTextureOptions, F as fruitSeason, G as srgbToLinear, H as sampleTrack, I as fruitSeasonAttribute, J as createRandom, K as woodSeasonAttribute, L as fruitTracks, M as crownNormal, N as KEYFRAME_EPSILON, O as groundTintAmount, P as evaluateSeason, R as hexToLinear, S as DEFAULT_TEXTURE_BASE_PATH, T as resolveTextureUrl, U as seasonShift, V as partSeasonAt, W as segmentWeight, _ as assertWebGPURenderer, b as isFlatShading, c as loadStyle, d as WindResponse, f as applySeasonToLeafMaterial, g as UnsupportedRendererError, h as leafSeasonNode, i as ForestVariant, j as crownDistance, k as hashGeometry, l as createTree, m as createSeasonNodes, n as Forest, o as DetailLevel, p as createFruitSeasonNodes, q as wrapSeason, r as ForestTree, s as selectDetailLevel, t as createForest, u as Tree, v as createBarkMaterial, w as loadTexture, x as BARK_REPEAT, y as createLeafMaterial, z as leafSeason } from "./forest-CM5DrklM.js";
|
|
2
|
+
import { o as setSceneShaderHooks, r as getSceneShaderHooks, s as stackShaderHooks } from "./shader-hooks-BFRtlWGI.js";
|
|
3
|
+
import { a as WIND_BURST_LIFETIME, i as MAX_WIND_BURSTS, l as sceneWind, o as WIND_BURST_REACH, s as Wind } from "./motion-Qd7xjeZM.js";
|
|
2
4
|
import { C as CURRENT_SCHEMA_VERSION, E as MAX_BRANCH_LEVELS, S as BARK_TYPES, T as LEAF_TYPES, _ as DEFAULT_GROUND_TINT, a as SUGGESTED_MATERIAL_FEATURES, b as DEFAULT_TRANSLUCENCY, c as extendDefinition, d as TreeDefinitionError, f as DEFAULT_BRANCH_LEVEL, g as DEFAULT_FRUIT_COLOR, h as DEFAULT_FRUIT_AMOUNT, l as fetchDefinition, m as DEFAULT_FRUIT, n as styleLabel, o as materialFeaturesOf, p as DEFAULT_DEFINITION, r as styleOfShading, s as withMaterialFeatures, t as STYLE_NAMES, u as parseDefinition, v as DEFAULT_OCCLUSION, w as FRUIT_TYPES, x as coneCurve, y as DEFAULT_ROOTS } from "./names-BE9he6CS.js";
|
|
5
|
+
import { _ as clampGrowth, v as growPositions, y as treeScale } from "./nodes-DxgTyF9B.js";
|
|
3
6
|
import { t as SEASON_PROFILES } from "./profiles-BAiyeFlh.js";
|
|
4
7
|
import { BufferAttribute, BufferGeometry, Color, DoubleSide, Group, Mesh, MeshStandardMaterial } from "three/webgpu";
|
|
5
8
|
import { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
|
|
@@ -443,6 +446,6 @@ async function exportBakedTree(tree, options = {}) {
|
|
|
443
446
|
disposeBakedTree(baked);
|
|
444
447
|
}
|
|
445
448
|
}
|
|
446
|
-
export { BARK_TYPES, CURRENT_SCHEMA_VERSION, DEFAULT_BRANCH_LEVEL, DEFAULT_DEFINITION, DEFAULT_FRUIT, DEFAULT_FRUIT_AMOUNT, DEFAULT_FRUIT_COLOR, DEFAULT_GROUND_TINT, DEFAULT_OCCLUSION, DEFAULT_ROOTS, DEFAULT_TEXTURE_BASE_PATH, DEFAULT_TRANSLUCENCY, FRUIT_TYPES, Forest, ForestTree, ForestVariant, KEYFRAME_EPSILON, LEAF_TYPES, MAX_BRANCH_LEVELS, SEASON_PROFILES, STYLE_NAMES, SUGGESTED_MATERIAL_FEATURES, Tree, TreeDefinitionError, UnsupportedRendererError, Wind, WindResponse, applySeasonToLeafMaterial, assertWebGPURenderer, bakeTree, coneCurve, createBarkMaterial, createForest, createFruitSeasonNodes, createLeafMaterial, createRandom, createSeasonNodes, createTree, crownDistance, crownNormal, disposeBakedTree, evaluateSeason, exportBakedTree, extendDefinition, fetchDefinition, fruitSeason, fruitSeasonAttribute, fruitTracks, getTextureOptions, hashGeometry, hashTreeData, hexToLinear, leafSeason, leafSeasonAttribute, loadStyle, loadTexture, materialFeaturesOf, parseDefinition, partSeasonAt, resolveTextureUrl, sampleTrack, sceneWind, seasonShift, segmentWeight, setTextureOptions, srgbToLinear, styleLabel, styleOfShading, textureReady, withMaterialFeatures, woodSeasonAttribute, wrapSeason };
|
|
449
|
+
export { BARK_TYPES, CURRENT_SCHEMA_VERSION, DEFAULT_BRANCH_LEVEL, DEFAULT_DEFINITION, DEFAULT_FRUIT, DEFAULT_FRUIT_AMOUNT, DEFAULT_FRUIT_COLOR, DEFAULT_GROUND_TINT, DEFAULT_OCCLUSION, DEFAULT_ROOTS, DEFAULT_TEXTURE_BASE_PATH, DEFAULT_TRANSLUCENCY, DetailLevel, FRUIT_TYPES, Forest, ForestTree, ForestVariant, KEYFRAME_EPSILON, LEAF_TYPES, MAX_BRANCH_LEVELS, MAX_WIND_BURSTS, SEASON_PROFILES, STYLE_NAMES, SUGGESTED_MATERIAL_FEATURES, Tree, TreeDefinitionError, UnsupportedRendererError, WIND_BURST_LIFETIME, WIND_BURST_REACH, Wind, WindResponse, applySeasonToLeafMaterial, assertWebGPURenderer, bakeTree, coneCurve, createBarkMaterial, createForest, createFruitSeasonNodes, createLeafMaterial, createRandom, createSeasonNodes, createTree, crownDistance, crownNormal, disposeBakedTree, evaluateSeason, exportBakedTree, extendDefinition, fetchDefinition, fruitSeason, fruitSeasonAttribute, fruitTracks, getSceneShaderHooks, getTextureOptions, hashGeometry, hashTreeData, hexToLinear, leafSeason, leafSeasonAttribute, leafSeasonNode, loadStyle, loadTexture, materialFeaturesOf, parseDefinition, partSeasonAt, resolveTextureUrl, sampleTrack, sceneWind, seasonShift, segmentWeight, selectDetailLevel, setSceneShaderHooks, setTextureOptions, srgbToLinear, stackShaderHooks, styleLabel, styleOfShading, textureReady, withMaterialFeatures, woodSeasonAttribute, wrapSeason };
|
|
447
450
|
|
|
448
451
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/bake/index.ts"],"sourcesContent":["import {\n BufferAttribute,\n BufferGeometry,\n Color,\n DoubleSide,\n Group,\n type Material,\n Mesh,\n MeshStandardMaterial,\n type Texture,\n} from 'three/webgpu';\nimport { GLTFExporter, type GLTFExporterPlugin, type GLTFWriter } from 'three/addons/exporters/GLTFExporter.js';\nimport type { MaterialFeatures, TranslucencyDefinition, TreeDefinition } from '../definition';\nimport { crownNormal, type CrownVolume, type GeometryBuffers } from '../generator';\nimport { clampGrowth, growPositions, treeScale } from '../growth';\nimport { groundTintAmount } from '../materials/ground-tint';\nimport { BARK_REPEAT } from '../materials/maps';\nimport { isFlatShading } from '../materials/shading';\nimport { fruitSeason, hexToLinear, leafSeason, partSeasonAt, wrapSeason } from '../season';\nimport type { Tree } from '../tree';\n\n/**\n * Baked Tree: one tree frozen at a Seed, Growth and Season as plain static geometry with\n * standard PBR materials (`MeshStandardMaterial`, no node materials), for glTF export and other tools.\n * Growth and Season are evaluated on the CPU with the same models the shaders run (`growPositions`,\n * `leafSeason`, `fruitSeason`); Wind is left out (a Baked Tree stands still).\n *\n * Material Features (ADR 0008) are baked into standard glTF channels: Crown Normals blended into the normals,\n * Structural Occlusion as a `_occlusion` attribute (glTF `_OCCLUSION`, strength already applied; optionally also in the vertex\n * colours), Leaf Translucency as `KHR_materials_diffuse_transmission` (written by `exportBakedTree`),\n * and the settings with the Crown Volume in `userData.treejs` of the leaf and bark materials (glTF\n * `extras`). With no Material Feature set, the result is exactly as without them.\n */\n\n/** Growth and Season to bake at; each defaults to the tree's current value. */\nexport interface BakeOptions {\n growth?: number;\n season?: number;\n /**\n * With Structural Occlusion (`materials.occlusion`): also multiply the occlusion into the vertex\n * colours (`COLOR_0`), for engines that only read vertex colours. It then darkens direct light too.\n * Default false: `COLOR_0` is as without the feature, and the occlusion is only in `_OCCLUSION`.\n */\n occlusionInVertexColors?: boolean;\n}\n\n/** A triangle with (almost) no area is a part that has not sprouted yet: it is dropped. */\nconst MIN_AREA2 = 1e-16;\n\ninterface BakedBuffers {\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n colors: Float32Array | null;\n /** Structural Occlusion per vertex (0 = occluded, 1 = open), written as `_OCCLUSION`; null without it. */\n occlusion: Float32Array | null;\n /** Per vertex: whether it is shown at all. */\n visible: (v: number) => boolean;\n /** Crown Normals: the normals are blended towards these Crown Volume normals (per vertex) by `amount`. */\n crownNormals?: BakedCrownNormals;\n}\n\ninterface BakedCrownNormals {\n normals: Float32Array;\n amount: number;\n /** Per vertex: its card is turned to face the crown's outside (winding reversed, `normals` already flipped). */\n flipped: Uint8Array;\n}\n\n/**\n * Keeps the triangles whose three vertices are visible and that have an area, and only the\n * vertices those triangles use. Returns null when nothing is left (glTF forbids empty meshes).\n */\nfunction compact(buffers: BakedBuffers, indices: Uint32Array, flat: boolean): BufferGeometry | null {\n const { positions } = buffers;\n const kept: number[] = [];\n const remap = new Int32Array(positions.length / 3).fill(-1);\n let count = 0;\n for (let t = 0; t < indices.length; t += 3) {\n const [a, b, c] = [indices[t]!, indices[t + 1]!, indices[t + 2]!];\n if (!buffers.visible(a) || !buffers.visible(b) || !buffers.visible(c)) continue;\n if (area2(positions, a, b, c) < MIN_AREA2) continue;\n for (const v of buffers.crownNormals?.flipped[a] ? [a, c, b] : [a, b, c]) {\n if (remap[v] === -1) remap[v] = count++;\n kept.push(remap[v]!);\n }\n }\n if (kept.length === 0) return null;\n\n const pick = (source: Float32Array, size: number) => {\n const out = new Float32Array(count * size);\n remap.forEach((to, from) => {\n if (to >= 0) out.set(source.subarray(from * size, from * size + size), to * size);\n });\n return out;\n };\n let geometry = new BufferGeometry();\n geometry.setAttribute('position', new BufferAttribute(pick(positions, 3), 3));\n geometry.setAttribute('normal', new BufferAttribute(pick(buffers.normals, 3), 3));\n geometry.setAttribute('uv', new BufferAttribute(pick(buffers.uvs, 2), 2));\n if (buffers.colors) geometry.setAttribute('color', new BufferAttribute(pick(buffers.colors, 3), 3));\n if (buffers.occlusion) geometry.setAttribute(OCCLUSION, new BufferAttribute(pick(buffers.occlusion, 1), 1));\n if (buffers.crownNormals) geometry.setAttribute(CROWN_NORMAL, new BufferAttribute(pick(buffers.crownNormals.normals, 3), 3));\n geometry.setIndex(new BufferAttribute(Uint32Array.from(kept), 1));\n if (flat) {\n // glTF has no flat-shading switch: split the vertices and give each face its own normal.\n geometry = geometry.toNonIndexed();\n geometry.computeVertexNormals();\n }\n if (buffers.crownNormals) {\n // After the split, so under flat shading the facet normals are blended and the facets stay visible below 1.\n blendNormals(geometry, buffers.crownNormals.amount);\n geometry.deleteAttribute(CROWN_NORMAL);\n }\n geometry.computeBoundingBox();\n geometry.computeBoundingSphere();\n return geometry;\n}\n\n/** The geometry attribute GLTFExporter writes as the `_OCCLUSION` vertex attribute. */\nconst OCCLUSION = '_occlusion';\n/** Scratch attribute: the Crown Volume normal per vertex, removed once the normals are blended. */\nconst CROWN_NORMAL = 'crownNormal';\n\n/** `normalize(mix(normal, crown normal, amount))`, as the leaf material's normalNode; the crown's where they cancel out. */\nfunction blendNormals(geometry: BufferGeometry, amount: number): void {\n const normal = geometry.getAttribute('normal');\n const crown = geometry.getAttribute(CROWN_NORMAL);\n for (let v = 0; v < normal.count; v++) {\n const c = [crown.getX(v), crown.getY(v), crown.getZ(v)];\n let x = normal.getX(v) + (c[0]! - normal.getX(v)) * amount;\n let y = normal.getY(v) + (c[1]! - normal.getY(v)) * amount;\n let z = normal.getZ(v) + (c[2]! - normal.getZ(v)) * amount;\n const length = Math.sqrt(x * x + y * y + z * z);\n if (length > 1e-4) [x, y, z] = [x / length, y / length, z / length];\n else [x, y, z] = c as [number, number, number];\n normal.setXYZ(v, x, y, z);\n }\n}\n\nfunction area2(p: Float32Array, a: number, b: number, c: number): number {\n const u = [p[b * 3]! - p[a * 3]!, p[b * 3 + 1]! - p[a * 3 + 1]!, p[b * 3 + 2]! - p[a * 3 + 2]!];\n const w = [p[c * 3]! - p[a * 3]!, p[c * 3 + 1]! - p[a * 3 + 1]!, p[c * 3 + 2]! - p[a * 3 + 2]!];\n const x = u[1]! * w[2]! - u[2]! * w[1]!;\n const y = u[2]! * w[0]! - u[0]! * w[2]!;\n const z = u[0]! * w[1]! - u[1]! * w[0]!;\n return x * x + y * y + z * z;\n}\n\n/**\n * Wood: grown positions; the bark's base-to-tip darkening (smooth shading) as vertex colours.\n * With a Ground Tint the vertex colours carry the whole bark colour (the material is white), tinted\n * near the ground on the grown positions, like the bark colorNode.\n */\nfunction bakeWood(definition: TreeDefinition, wood: GeometryBuffers, growth: number, occlusion: BakedOcclusion): BufferGeometry | null {\n const flat = isFlatShading(definition.materials.shading);\n const { color, groundTint } = definition.materials.bark;\n const positions = growPositions(wood, growth);\n let colors: Float32Array | null = null;\n if (!flat || groundTint) {\n // Same as the bark colorNode: mix(base * 0.75, base, sqrt(clamp(uv.y))), then the Ground Tint.\n colors = new Float32Array(wood.positions.length);\n const bark = groundTint ? hexToLinear(color) : [1, 1, 1];\n const tint = groundTint ? hexToLinear(groundTint.color) : [1, 1, 1];\n for (let v = 0; v < colors.length / 3; v++) {\n const shade = flat ? 1 : 0.75 + 0.25 * Math.sqrt(Math.min(Math.max(wood.uvs[v * 2 + 1]!, 0), 1));\n const amount = groundTint ? groundTintAmount(groundTint, positions[v * 3 + 1]!) : 0;\n for (let c = 0; c < 3; c++) colors[v * 3 + c] = bark[c]! * shade * (1 - amount) + tint[c]! * amount;\n }\n }\n return compact({ positions, normals: wood.normals, uvs: wood.uvs, ...occlusion.of(wood, colors), visible: () => true }, wood.indices, flat);\n}\n\n/**\n * Leaves: grown positions; fallen leaves dropped; Season (or blossom) colour × the Seed's tint as vertex\n * colours. Also returns the mean colour of the shown leaves (linear, before any occlusion), the colour\n * Leaf Translucency glows in.\n */\nfunction bakeLeaves(\n definition: TreeDefinition,\n leaves: GeometryBuffers,\n growth: number,\n season: number,\n occlusion: BakedOcclusion,\n crown: CrownVolume,\n amount: number | undefined,\n): { geometry: BufferGeometry | null; meanColor: [number, number, number] } {\n const count = leaves.positions.length / 3;\n const aSeason = leaves.attributes.aSeason!.array;\n const shown = new Uint8Array(count);\n const colors = new Float32Array(count * 3);\n for (let v = 0; v < count; v++) {\n const state = leafSeason(definition.season, season, partSeasonAt(aSeason, v));\n shown[v] = state.visible ? 1 : 0;\n for (let c = 0; c < 3; c++) colors[v * 3 + c] = state.color[c]! * (leaves.colors?.[v * 3 + c] ?? 1);\n }\n const meanColor = meanShownColor(colors, shown);\n const positions = growPositions(leaves, growth);\n const crownNormals = amount ? bakedCrownNormals(leaves, positions, growth, crown, amount, definition.leaves.shape === 'card') : undefined;\n const geometry = compact(\n {\n positions,\n normals: crownNormals ? orient(leaves.normals, crownNormals.flipped) : leaves.normals,\n uvs: leaves.uvs,\n ...occlusion.of(leaves, colors),\n visible: (v) => shown[v] === 1,\n crownNormals,\n },\n leaves.indices,\n isFlatShading(definition.materials.shading),\n );\n return { geometry, meanColor };\n}\n\n/** Mean of the colours of the shown vertices (each channel at most 1); black when none is shown. */\nfunction meanShownColor(colors: Float32Array, shown: Uint8Array): [number, number, number] {\n const sum: [number, number, number] = [0, 0, 0];\n let count = 0;\n shown.forEach((on, v) => {\n if (!on) return;\n for (let c = 0; c < 3; c++) sum[c]! += colors[v * 3 + c]!;\n count++;\n });\n return sum.map((c) => Math.min(c / Math.max(count, 1), 1)) as [number, number, number];\n}\n\n/**\n * Crown Normals for the leaves: the Crown Volume's normal at each grown vertex (the Volume scaled by\n * the Growth scale, as in the material), and which leaf cards to turn around. A card (`leaves.shape`\n * 'card') is flat and double-sided with one normal for both sides: turning it (normal and winding\n * together) changes nothing else, but makes its front face the crown's outside, so in engines that flip\n * the normal of back faces the blended normal of every card points out. Decided per card at its attachment\n * point (`aOrigin`, shared by its vertices). Solid leaf shapes are closed: their front faces are already\n * their outside, and they keep their winding.\n */\nfunction bakedCrownNormals(\n leaves: GeometryBuffers,\n grown: Float32Array,\n growth: number,\n crown: CrownVolume,\n amount: number,\n cards: boolean,\n): BakedCrownNormals {\n const count = grown.length / 3;\n const scale = treeScale(growth);\n const origin = leaves.attributes.aOrigin!.array;\n const n = leaves.normals;\n const normals = new Float32Array(count * 3);\n const flipped = new Uint8Array(count);\n for (let v = 0; v < count; v++) {\n const i = v * 3;\n normals.set(crownNormal(crown, [grown[i]! / scale, grown[i + 1]! / scale, grown[i + 2]! / scale]), i);\n if (!cards) continue;\n const out = crownNormal(crown, [origin[i]!, origin[i + 1]!, origin[i + 2]!]);\n flipped[v] = n[i]! * out[0] + n[i + 1]! * out[1] + n[i + 2]! * out[2] < 0 ? 1 : 0;\n }\n return { normals, amount, flipped };\n}\n\n/** The normals with those of `flipped` vertices reversed. */\nfunction orient(normals: Float32Array, flipped: Uint8Array): Float32Array {\n const out = normals.slice();\n flipped.forEach((flip, v) => {\n if (flip) for (let c = 0; c < 3; c++) out[v * 3 + c] = -out[v * 3 + c]!;\n });\n return out;\n}\n\n/**\n * Structural Occlusion as baked, for one part with its vertex colours (null: none): `occlusion` is\n * `mix(1, aOcclusion, strength)` per vertex (what the material's aoNode shows), null when the tree has\n * none. With `inColors` the colours come back multiplied by it (in place; a part without colours gets\n * the occlusion as grey ones), else unchanged.\n */\ninterface BakedOcclusion {\n of(part: GeometryBuffers, colors: Float32Array | null): { occlusion: Float32Array | null; colors: Float32Array | null };\n}\n\nfunction bakedOcclusion(strength: number | null, inColors: boolean): BakedOcclusion {\n return {\n of: (part, colors) => {\n const ao = part.attributes.aOcclusion?.array;\n if (strength === null || !ao) return { occlusion: null, colors };\n const occlusion = Float32Array.from(ao, (a) => 1 - strength * (1 - a));\n if (!inColors) return { occlusion, colors };\n return { occlusion, colors: darken(colors ?? new Float32Array(part.positions.length).fill(1), occlusion) };\n },\n };\n}\n\n/** Each vertex's colour times its occlusion (in place). */\nfunction darken(colors: Float32Array, occlusion: Float32Array): Float32Array {\n for (let i = 0; i < colors.length; i++) colors[i]! *= occlusion[Math.floor(i / 3)]!;\n return colors;\n}\n\n/**\n * Fruit: each Fruit scaled about its attachment point by the Fruit amount (dropped when not\n * shown), then grown; the Fruit colour × the Seed's tint as vertex colours. Same order as the shader.\n */\nfunction bakeFruit(\n definition: TreeDefinition,\n fruit: GeometryBuffers,\n growth: number,\n season: number,\n occlusion: BakedOcclusion,\n): BufferGeometry | null {\n const count = fruit.positions.length / 3;\n if (count === 0) return null;\n const aSeason = fruit.attributes.aSeason!.array;\n const aOrigin = fruit.attributes.aOrigin!.array;\n const shown = new Uint8Array(count);\n const colors = new Float32Array(count * 3);\n const scaled = new Float32Array(count * 3);\n for (let v = 0; v < count; v++) {\n const state = fruitSeason(definition.season, season, partSeasonAt(aSeason, v));\n shown[v] = state.visible ? 1 : 0;\n for (let c = 0; c < 3; c++) {\n const i = v * 3 + c;\n colors[i] = state.color[c]! * (fruit.colors?.[i] ?? 1);\n scaled[i] = aOrigin[i]! + (fruit.positions[i]! - aOrigin[i]!) * state.scale;\n }\n }\n return compact(\n {\n positions: growPositions({ ...fruit, positions: scaled }, growth),\n normals: fruit.normals,\n uvs: fruit.uvs,\n ...occlusion.of(fruit, colors),\n visible: (v) => shown[v] === 1,\n },\n fruit.indices,\n isFlatShading(definition.materials.shading),\n );\n}\n\n/** A loaded texture for the baked material (a copy, so the tree's shared texture is untouched); null without image data. */\nfunction bakedMap(texture: Texture | null | undefined, repeat?: readonly [number, number]): Texture | null {\n if (!texture?.image) return null;\n const copy = texture.clone();\n if (repeat) copy.repeat.set(...repeat);\n return copy;\n}\n\n/**\n * Freezes a tree at a Growth and Season (default: the tree's own) into a static `Group` of\n * meshes `wood`, `leaves` and `fruit` (a mesh with nothing to show is left out) with standard PBR\n * materials: no node materials, no Growth/Season/Wind attributes, no animation. Material Features\n * are baked in (see the top of this module). The result is\n * independent of `tree`; call `disposeBakedTree` when done with it.\n */\nexport function bakeTree(tree: Tree, options: BakeOptions = {}): Group {\n const { definition, data } = tree;\n const source = tree.wood.material as MeshStandardMaterial; // MeshStandardNodeMaterial: same props\n const growth = clampGrowth(options.growth ?? tree.growth);\n const season = wrapSeason(options.season ?? tree.season);\n const bark = definition.materials.bark;\n const flat = isFlatShading(definition.materials.shading);\n // The features as the tree shows them now (values tuned live included).\n const features = tree.materialFeatures;\n const occlusion = bakedOcclusion(features.occlusion?.strength ?? null, options.occlusionInVertexColors ?? false);\n const extras = materialFeatureExtras(features, tree.data.crown, growth, options.occlusionInVertexColors ?? false);\n\n const group = new Group();\n group.name = definition.name || 'Tree';\n group.userData = { seed: tree.seed, growth, season };\n\n const woodGeometry = bakeWood(definition, data.wood, growth, occlusion);\n if (woodGeometry) {\n const material = new MeshStandardMaterial({\n name: 'bark',\n color: new Color(bark.groundTint ? 0xffffff : bark.color),\n roughness: bark.roughness,\n metalness: 0,\n vertexColors: woodGeometry.hasAttribute('color'),\n flatShading: flat,\n map: bakedMap(source.map, BARK_REPEAT),\n normalMap: bakedMap(source.normalMap, BARK_REPEAT),\n });\n if (extras) material.userData = { treejs: extras };\n group.add(bakedMesh('wood', woodGeometry, material));\n }\n\n const { geometry: leafGeometry, meanColor } = bakeLeaves(definition, data.leaves, growth, season, occlusion, data.crown, features.crownNormals);\n if (leafGeometry) {\n const map = bakedMap(tree.leaves.material.map);\n const material = new MeshStandardMaterial({\n name: 'leaves',\n color: 0xffffff,\n roughness: definition.materials.leaf.roughness,\n metalness: 0,\n vertexColors: true,\n flatShading: flat,\n side: DoubleSide,\n map,\n alphaTest: map ? definition.materials.leaf.alphaTest : 0,\n });\n if (extras) material.userData = { treejs: extras };\n const { translucency } = features;\n // The transmission colour is the leaves' own colour (without the occlusion of `occlusionInVertexColors`).\n if (translucency) diffuseTransmission.set(material, { factor: translucency.strength, color: meanColor });\n group.add(bakedMesh('leaves', leafGeometry, material));\n }\n\n const fruitGeometry = bakeFruit(definition, data.fruit, growth, season, occlusion);\n if (fruitGeometry) {\n const material = new MeshStandardMaterial({\n name: 'fruit',\n color: 0xffffff,\n roughness: tree.fruit.material.roughness,\n metalness: 0,\n vertexColors: true,\n flatShading: flat,\n });\n group.add(bakedMesh('fruit', fruitGeometry, material));\n }\n return group;\n}\n\n/**\n * The `treejs` object in the extras of the baked leaf and bark materials: the Material Feature\n * settings and the Crown Volume, for engines that rebuild the effects in their own shaders. The Crown\n * Volume is in the Baked Tree's space (scaled by its Growth, like the geometry). Null when the tree has\n * no Material Feature, so its glTF is as without them.\n */\nexport interface MaterialFeatureExtras {\n /** Crown Normals amount; the baked `NORMAL` already has them blended in. */\n crownNormals?: number;\n /** Leaf Translucency settings (also written as `KHR_materials_diffuse_transmission`). */\n translucency?: TranslucencyDefinition;\n occlusion?: {\n /** The Structural Occlusion strength the tree had. */\n strength: number;\n /**\n * Always true: the baked `_OCCLUSION` is final, `mix(1, aOcclusion, strength)`, with the strength\n * already applied. Use it as AO as it is; do not apply `strength` again.\n */\n strengthApplied: true;\n /** Whether `COLOR_0` is also multiplied by `_OCCLUSION` (`occlusionInVertexColors`). */\n inVertexColors: boolean;\n };\n crown: CrownVolume;\n}\n\nfunction materialFeatureExtras(\n features: MaterialFeatures,\n crown: CrownVolume,\n growth: number,\n occlusionInVertexColors: boolean,\n): MaterialFeatureExtras | null {\n const { crownNormals, translucency, occlusion } = features;\n if (!crownNormals && !translucency && !occlusion) return null;\n const scale = treeScale(growth);\n const { center, radii } = crown;\n return {\n ...(crownNormals ? { crownNormals } : {}),\n ...(translucency ? { translucency: { ...translucency } } : {}),\n ...(occlusion ? { occlusion: { strength: occlusion.strength, strengthApplied: true, inVertexColors: occlusionInVertexColors } } : {}),\n crown: { center: [center[0] * scale, center[1] * scale, center[2] * scale], radii: [radii[0] * scale, radii[1] * scale, radii[2] * scale] },\n };\n}\n\n/** Leaf Translucency of a baked leaf material, written as `KHR_materials_diffuse_transmission` on export. */\nconst diffuseTransmission = new WeakMap<Material, { factor: number; color: [number, number, number] }>();\n\n/** GLTFExporter plugin: Leaf Translucency as `KHR_materials_diffuse_transmission` (factor = strength, colour = the leaf colour). */\nclass DiffuseTransmissionExtension implements GLTFExporterPlugin {\n readonly name = 'KHR_materials_diffuse_transmission';\n constructor(private readonly writer: GLTFWriter) {}\n\n async writeMaterialAsync(material: Material, materialDef: Record<string, unknown>): Promise<void> {\n const transmission = diffuseTransmission.get(material);\n if (!transmission) return;\n const extensions = (materialDef.extensions ??= {}) as Record<string, unknown>;\n extensions[this.name] = { diffuseTransmissionFactor: transmission.factor, diffuseTransmissionColorFactor: transmission.color };\n (this.writer as unknown as { extensionsUsed: Record<string, boolean> }).extensionsUsed[this.name] = true;\n }\n}\n\nfunction bakedMesh(name: string, geometry: BufferGeometry, material: MeshStandardMaterial): Mesh {\n const mesh = new Mesh(geometry, material);\n mesh.name = name;\n mesh.castShadow = mesh.receiveShadow = true;\n return mesh;\n}\n\n/** Frees the geometries, materials and texture copies of a baked tree. */\nexport function disposeBakedTree(baked: Group): void {\n baked.traverse((object) => {\n if (!(object instanceof Mesh)) return;\n object.geometry.dispose();\n const material = object.material as MeshStandardMaterial;\n material.map?.dispose();\n material.normalMap?.dispose();\n material.dispose();\n });\n}\n\nexport interface ExportBakedTreeOptions extends BakeOptions {\n /** `.glb` (ArrayBuffer, default) or `.gltf` JSON with embedded buffers. */\n binary?: boolean;\n}\n\n/**\n * Bakes a tree (see {@link bakeTree}) and writes it as glTF 2.0: a `.glb` ArrayBuffer by default,\n * or the `.gltf` JSON object with `binary: false`. Waits for the tree's textures first. In Node,\n * three's GLTFExporter needs a `FileReader` global.\n */\nexport function exportBakedTree(tree: Tree, options?: ExportBakedTreeOptions & { binary?: true }): Promise<ArrayBuffer>;\nexport function exportBakedTree(tree: Tree, options: ExportBakedTreeOptions & { binary: false }): Promise<Record<string, unknown>>;\nexport function exportBakedTree(tree: Tree, options?: ExportBakedTreeOptions): Promise<ArrayBuffer | Record<string, unknown>>;\nexport async function exportBakedTree(\n tree: Tree,\n options: ExportBakedTreeOptions = {},\n): Promise<ArrayBuffer | Record<string, unknown>> {\n await tree.ready;\n const baked = bakeTree(tree, options);\n try {\n const exporter = new GLTFExporter().register((writer) => new DiffuseTransmissionExtension(writer));\n const result = await exporter.parseAsync(baked, { binary: options.binary ?? true });\n return result as ArrayBuffer | Record<string, unknown>;\n } finally {\n disposeBakedTree(baked);\n }\n}\n"],"mappings":";;;;;;;AA+CA,IAAM,YAAY;;;;;AA0BlB,SAAS,QAAQ,SAAuB,SAAsB,MAAsC;CAClG,MAAM,EAAE,cAAc;CACtB,MAAM,OAAiB,CAAC;CACxB,MAAM,QAAQ,IAAI,WAAW,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE;CAC1D,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;EAC1C,MAAM,CAAC,GAAG,GAAG,KAAK;GAAC,QAAQ;GAAK,QAAQ,IAAI;GAAK,QAAQ,IAAI;EAAG;EAChE,IAAI,CAAC,QAAQ,QAAQ,CAAC,KAAK,CAAC,QAAQ,QAAQ,CAAC,KAAK,CAAC,QAAQ,QAAQ,CAAC,GAAG;EACvE,IAAI,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,WAAW;EAC3C,KAAK,MAAM,KAAK,QAAQ,cAAc,QAAQ,KAAK;GAAC;GAAG;GAAG;EAAC,IAAI;GAAC;GAAG;GAAG;EAAC,GAAG;GACxE,IAAI,MAAM,OAAO,IAAI,MAAM,KAAK;GAChC,KAAK,KAAK,MAAM,EAAG;EACrB;CACF;CACA,IAAI,KAAK,WAAW,GAAG,OAAO;CAE9B,MAAM,QAAQ,QAAsB,SAAiB;EACnD,MAAM,MAAM,IAAI,aAAa,QAAQ,IAAI;EACzC,MAAM,SAAS,IAAI,SAAS;GAC1B,IAAI,MAAM,GAAG,IAAI,IAAI,OAAO,SAAS,OAAO,MAAM,OAAO,OAAO,IAAI,GAAG,KAAK,IAAI;EAClF,CAAC;EACD,OAAO;CACT;C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AE,2BAA2B,aAAa;GAAQ,gCAAgC,aAAa;EAAM;EAC7H,KAAM,OAAkE,eAAe,KAAK,QAAQ;CACtG;AACF;AAEA,SAAS,UAAU,MAAc,UAA0B,UAAsC;CAC/F,MAAM,OAAO,IAAI,KAAK,UAAU,QAAQ;CACxC,KAAK,OAAO;CACZ,KAAK,aAAa,KAAK,gBAAgB;CACvC,OAAO;AACT;;AAGA,SAAgB,iBAAiB,OAAoB;CACnD,MAAM,UAAU,WAAW;EACzB,IAAI,EAAE,kBAAkB,OAAO;EAC/B,OAAO,SAAS,QAAQ;EACxB,MAAM,WAAW,OAAO;EACxB,SAAS,KAAK,QAAQ;EACtB,SAAS,WAAW,QAAQ;EAC5B,SAAS,QAAQ;CACnB,CAAC;AACH;AAeA,eAAsB,gBACpB,MACA,UAAkC,CAAC,GACa;CAChD,MAAM,KAAK;CACX,MAAM,QAAQ,SAAS,MAAM,OAAO;CACpC,IAAI;EAGF,OAAO,MAFU,IAAI,aAAa,CAAC,CAAC,UAAU,WAAW,IAAI,6BAA6B,MAAM,CAC3E,CAAA,CAAS,WAAW,OAAO,EAAE,QAAQ,QAAQ,UAAU,KAAK,CAAC;CAEpF,UAAU;EACR,iBAAiB,KAAK;CACxB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/bake/index.ts"],"sourcesContent":["import {\n BufferAttribute,\n BufferGeometry,\n Color,\n DoubleSide,\n Group,\n type Material,\n Mesh,\n MeshStandardMaterial,\n type Texture,\n} from 'three/webgpu';\nimport { GLTFExporter, type GLTFExporterPlugin, type GLTFWriter } from 'three/addons/exporters/GLTFExporter.js';\nimport type { MaterialFeatures, TranslucencyDefinition, TreeDefinition } from '../definition';\nimport { crownNormal, type CrownVolume, type GeometryBuffers } from '../generator';\nimport { clampGrowth, growPositions, treeScale } from '../growth';\nimport { groundTintAmount } from '../materials/ground-tint';\nimport { BARK_REPEAT } from '../materials/maps';\nimport { isFlatShading } from '../materials/shading';\nimport { fruitSeason, hexToLinear, leafSeason, partSeasonAt, wrapSeason } from '../season';\nimport type { Tree } from '../tree';\n\n/**\n * Baked Tree: one tree frozen at a Seed, Growth and Season as plain static geometry with\n * standard PBR materials (`MeshStandardMaterial`, no node materials), for glTF export and other tools.\n * Growth and Season are evaluated on the CPU with the same models the shaders run (`growPositions`,\n * `leafSeason`, `fruitSeason`); Wind is left out (a Baked Tree stands still).\n *\n * Material Features (ADR 0008) are baked into standard glTF channels: Crown Normals blended into the normals,\n * Structural Occlusion as a `_occlusion` attribute (glTF `_OCCLUSION`, strength already applied; optionally also in the vertex\n * colours), Leaf Translucency as `KHR_materials_diffuse_transmission` (written by `exportBakedTree`),\n * and the settings with the Crown Volume in `userData.treejs` of the leaf and bark materials (glTF\n * `extras`). With no Material Feature set, the result is exactly as without them.\n */\n\n/** Growth and Season to bake at; each defaults to the tree's current value. */\nexport interface BakeOptions {\n growth?: number;\n season?: number;\n /**\n * With Structural Occlusion (`materials.occlusion`): also multiply the occlusion into the vertex\n * colours (`COLOR_0`), for engines that only read vertex colours. It then darkens direct light too.\n * Default false: `COLOR_0` is as without the feature, and the occlusion is only in `_OCCLUSION`.\n */\n occlusionInVertexColors?: boolean;\n}\n\n/** A triangle with (almost) no area is a part that has not sprouted yet: it is dropped. */\nconst MIN_AREA2 = 1e-16;\n\ninterface BakedBuffers {\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n colors: Float32Array | null;\n /** Structural Occlusion per vertex (0 = occluded, 1 = open), written as `_OCCLUSION`; null without it. */\n occlusion: Float32Array | null;\n /** Per vertex: whether it is shown at all. */\n visible: (v: number) => boolean;\n /** Crown Normals: the normals are blended towards these Crown Volume normals (per vertex) by `amount`. */\n crownNormals?: BakedCrownNormals;\n}\n\ninterface BakedCrownNormals {\n normals: Float32Array;\n amount: number;\n /** Per vertex: its card is turned to face the crown's outside (winding reversed, `normals` already flipped). */\n flipped: Uint8Array;\n}\n\n/**\n * Keeps the triangles whose three vertices are visible and that have an area, and only the\n * vertices those triangles use. Returns null when nothing is left (glTF forbids empty meshes).\n */\nfunction compact(buffers: BakedBuffers, indices: Uint32Array, flat: boolean): BufferGeometry | null {\n const { positions } = buffers;\n const kept: number[] = [];\n const remap = new Int32Array(positions.length / 3).fill(-1);\n let count = 0;\n for (let t = 0; t < indices.length; t += 3) {\n const [a, b, c] = [indices[t]!, indices[t + 1]!, indices[t + 2]!];\n if (!buffers.visible(a) || !buffers.visible(b) || !buffers.visible(c)) continue;\n if (area2(positions, a, b, c) < MIN_AREA2) continue;\n for (const v of buffers.crownNormals?.flipped[a] ? [a, c, b] : [a, b, c]) {\n if (remap[v] === -1) remap[v] = count++;\n kept.push(remap[v]!);\n }\n }\n if (kept.length === 0) return null;\n\n const pick = (source: Float32Array, size: number) => {\n const out = new Float32Array(count * size);\n remap.forEach((to, from) => {\n if (to >= 0) out.set(source.subarray(from * size, from * size + size), to * size);\n });\n return out;\n };\n let geometry = new BufferGeometry();\n geometry.setAttribute('position', new BufferAttribute(pick(positions, 3), 3));\n geometry.setAttribute('normal', new BufferAttribute(pick(buffers.normals, 3), 3));\n geometry.setAttribute('uv', new BufferAttribute(pick(buffers.uvs, 2), 2));\n if (buffers.colors) geometry.setAttribute('color', new BufferAttribute(pick(buffers.colors, 3), 3));\n if (buffers.occlusion) geometry.setAttribute(OCCLUSION, new BufferAttribute(pick(buffers.occlusion, 1), 1));\n if (buffers.crownNormals) geometry.setAttribute(CROWN_NORMAL, new BufferAttribute(pick(buffers.crownNormals.normals, 3), 3));\n geometry.setIndex(new BufferAttribute(Uint32Array.from(kept), 1));\n if (flat) {\n // glTF has no flat-shading switch: split the vertices and give each face its own normal.\n geometry = geometry.toNonIndexed();\n geometry.computeVertexNormals();\n }\n if (buffers.crownNormals) {\n // After the split, so under flat shading the facet normals are blended and the facets stay visible below 1.\n blendNormals(geometry, buffers.crownNormals.amount);\n geometry.deleteAttribute(CROWN_NORMAL);\n }\n geometry.computeBoundingBox();\n geometry.computeBoundingSphere();\n return geometry;\n}\n\n/** The geometry attribute GLTFExporter writes as the `_OCCLUSION` vertex attribute. */\nconst OCCLUSION = '_occlusion';\n/** Scratch attribute: the Crown Volume normal per vertex, removed once the normals are blended. */\nconst CROWN_NORMAL = 'crownNormal';\n\n/** `normalize(mix(normal, crown normal, amount))`, as the leaf material's normalNode; the crown's where they cancel out. */\nfunction blendNormals(geometry: BufferGeometry, amount: number): void {\n const normal = geometry.getAttribute('normal');\n const crown = geometry.getAttribute(CROWN_NORMAL);\n for (let v = 0; v < normal.count; v++) {\n const c = [crown.getX(v), crown.getY(v), crown.getZ(v)];\n let x = normal.getX(v) + (c[0]! - normal.getX(v)) * amount;\n let y = normal.getY(v) + (c[1]! - normal.getY(v)) * amount;\n let z = normal.getZ(v) + (c[2]! - normal.getZ(v)) * amount;\n const length = Math.sqrt(x * x + y * y + z * z);\n if (length > 1e-4) [x, y, z] = [x / length, y / length, z / length];\n else [x, y, z] = c as [number, number, number];\n normal.setXYZ(v, x, y, z);\n }\n}\n\nfunction area2(p: Float32Array, a: number, b: number, c: number): number {\n const u = [p[b * 3]! - p[a * 3]!, p[b * 3 + 1]! - p[a * 3 + 1]!, p[b * 3 + 2]! - p[a * 3 + 2]!];\n const w = [p[c * 3]! - p[a * 3]!, p[c * 3 + 1]! - p[a * 3 + 1]!, p[c * 3 + 2]! - p[a * 3 + 2]!];\n const x = u[1]! * w[2]! - u[2]! * w[1]!;\n const y = u[2]! * w[0]! - u[0]! * w[2]!;\n const z = u[0]! * w[1]! - u[1]! * w[0]!;\n return x * x + y * y + z * z;\n}\n\n/**\n * Wood: grown positions; the bark's base-to-tip darkening (smooth shading) as vertex colours.\n * With a Ground Tint the vertex colours carry the whole bark colour (the material is white), tinted\n * near the ground on the grown positions, like the bark colorNode.\n */\nfunction bakeWood(definition: TreeDefinition, wood: GeometryBuffers, growth: number, occlusion: BakedOcclusion): BufferGeometry | null {\n const flat = isFlatShading(definition.materials.shading);\n const { color, groundTint } = definition.materials.bark;\n const positions = growPositions(wood, growth);\n let colors: Float32Array | null = null;\n if (!flat || groundTint) {\n // Same as the bark colorNode: mix(base * 0.75, base, sqrt(clamp(uv.y))), then the Ground Tint.\n colors = new Float32Array(wood.positions.length);\n const bark = groundTint ? hexToLinear(color) : [1, 1, 1];\n const tint = groundTint ? hexToLinear(groundTint.color) : [1, 1, 1];\n for (let v = 0; v < colors.length / 3; v++) {\n const shade = flat ? 1 : 0.75 + 0.25 * Math.sqrt(Math.min(Math.max(wood.uvs[v * 2 + 1]!, 0), 1));\n const amount = groundTint ? groundTintAmount(groundTint, positions[v * 3 + 1]!) : 0;\n for (let c = 0; c < 3; c++) colors[v * 3 + c] = bark[c]! * shade * (1 - amount) + tint[c]! * amount;\n }\n }\n return compact({ positions, normals: wood.normals, uvs: wood.uvs, ...occlusion.of(wood, colors), visible: () => true }, wood.indices, flat);\n}\n\n/**\n * Leaves: grown positions; fallen leaves dropped; Season (or blossom) colour × the Seed's tint as vertex\n * colours. Also returns the mean colour of the shown leaves (linear, before any occlusion), the colour\n * Leaf Translucency glows in.\n */\nfunction bakeLeaves(\n definition: TreeDefinition,\n leaves: GeometryBuffers,\n growth: number,\n season: number,\n occlusion: BakedOcclusion,\n crown: CrownVolume,\n amount: number | undefined,\n): { geometry: BufferGeometry | null; meanColor: [number, number, number] } {\n const count = leaves.positions.length / 3;\n const aSeason = leaves.attributes.aSeason!.array;\n const shown = new Uint8Array(count);\n const colors = new Float32Array(count * 3);\n for (let v = 0; v < count; v++) {\n const state = leafSeason(definition.season, season, partSeasonAt(aSeason, v));\n shown[v] = state.visible ? 1 : 0;\n for (let c = 0; c < 3; c++) colors[v * 3 + c] = state.color[c]! * (leaves.colors?.[v * 3 + c] ?? 1);\n }\n const meanColor = meanShownColor(colors, shown);\n const positions = growPositions(leaves, growth);\n const crownNormals = amount ? bakedCrownNormals(leaves, positions, growth, crown, amount, definition.leaves.shape === 'card') : undefined;\n const geometry = compact(\n {\n positions,\n normals: crownNormals ? orient(leaves.normals, crownNormals.flipped) : leaves.normals,\n uvs: leaves.uvs,\n ...occlusion.of(leaves, colors),\n visible: (v) => shown[v] === 1,\n crownNormals,\n },\n leaves.indices,\n isFlatShading(definition.materials.shading),\n );\n return { geometry, meanColor };\n}\n\n/** Mean of the colours of the shown vertices (each channel at most 1); black when none is shown. */\nfunction meanShownColor(colors: Float32Array, shown: Uint8Array): [number, number, number] {\n const sum: [number, number, number] = [0, 0, 0];\n let count = 0;\n shown.forEach((on, v) => {\n if (!on) return;\n for (let c = 0; c < 3; c++) sum[c]! += colors[v * 3 + c]!;\n count++;\n });\n return sum.map((c) => Math.min(c / Math.max(count, 1), 1)) as [number, number, number];\n}\n\n/**\n * Crown Normals for the leaves: the Crown Volume's normal at each grown vertex (the Volume scaled by\n * the Growth scale, as in the material), and which leaf cards to turn around. A card (`leaves.shape`\n * 'card') is flat and double-sided with one normal for both sides: turning it (normal and winding\n * together) changes nothing else, but makes its front face the crown's outside, so in engines that flip\n * the normal of back faces the blended normal of every card points out. Decided per card at its attachment\n * point (`aOrigin`, shared by its vertices). Solid leaf shapes are closed: their front faces are already\n * their outside, and they keep their winding.\n */\nfunction bakedCrownNormals(\n leaves: GeometryBuffers,\n grown: Float32Array,\n growth: number,\n crown: CrownVolume,\n amount: number,\n cards: boolean,\n): BakedCrownNormals {\n const count = grown.length / 3;\n const scale = treeScale(growth);\n const origin = leaves.attributes.aOrigin!.array;\n const n = leaves.normals;\n const normals = new Float32Array(count * 3);\n const flipped = new Uint8Array(count);\n for (let v = 0; v < count; v++) {\n const i = v * 3;\n normals.set(crownNormal(crown, [grown[i]! / scale, grown[i + 1]! / scale, grown[i + 2]! / scale]), i);\n if (!cards) continue;\n const out = crownNormal(crown, [origin[i]!, origin[i + 1]!, origin[i + 2]!]);\n flipped[v] = n[i]! * out[0] + n[i + 1]! * out[1] + n[i + 2]! * out[2] < 0 ? 1 : 0;\n }\n return { normals, amount, flipped };\n}\n\n/** The normals with those of `flipped` vertices reversed. */\nfunction orient(normals: Float32Array, flipped: Uint8Array): Float32Array {\n const out = normals.slice();\n flipped.forEach((flip, v) => {\n if (flip) for (let c = 0; c < 3; c++) out[v * 3 + c] = -out[v * 3 + c]!;\n });\n return out;\n}\n\n/**\n * Structural Occlusion as baked, for one part with its vertex colours (null: none): `occlusion` is\n * `mix(1, aOcclusion, strength)` per vertex (what the material's aoNode shows), null when the tree has\n * none. With `inColors` the colours come back multiplied by it (in place; a part without colours gets\n * the occlusion as grey ones), else unchanged.\n */\ninterface BakedOcclusion {\n of(part: GeometryBuffers, colors: Float32Array | null): { occlusion: Float32Array | null; colors: Float32Array | null };\n}\n\nfunction bakedOcclusion(strength: number | null, inColors: boolean): BakedOcclusion {\n return {\n of: (part, colors) => {\n const ao = part.attributes.aOcclusion?.array;\n if (strength === null || !ao) return { occlusion: null, colors };\n const occlusion = Float32Array.from(ao, (a) => 1 - strength * (1 - a));\n if (!inColors) return { occlusion, colors };\n return { occlusion, colors: darken(colors ?? new Float32Array(part.positions.length).fill(1), occlusion) };\n },\n };\n}\n\n/** Each vertex's colour times its occlusion (in place). */\nfunction darken(colors: Float32Array, occlusion: Float32Array): Float32Array {\n for (let i = 0; i < colors.length; i++) colors[i]! *= occlusion[Math.floor(i / 3)]!;\n return colors;\n}\n\n/**\n * Fruit: each Fruit scaled about its attachment point by the Fruit amount (dropped when not\n * shown), then grown; the Fruit colour × the Seed's tint as vertex colours. Same order as the shader.\n */\nfunction bakeFruit(\n definition: TreeDefinition,\n fruit: GeometryBuffers,\n growth: number,\n season: number,\n occlusion: BakedOcclusion,\n): BufferGeometry | null {\n const count = fruit.positions.length / 3;\n if (count === 0) return null;\n const aSeason = fruit.attributes.aSeason!.array;\n const aOrigin = fruit.attributes.aOrigin!.array;\n const shown = new Uint8Array(count);\n const colors = new Float32Array(count * 3);\n const scaled = new Float32Array(count * 3);\n for (let v = 0; v < count; v++) {\n const state = fruitSeason(definition.season, season, partSeasonAt(aSeason, v));\n shown[v] = state.visible ? 1 : 0;\n for (let c = 0; c < 3; c++) {\n const i = v * 3 + c;\n colors[i] = state.color[c]! * (fruit.colors?.[i] ?? 1);\n scaled[i] = aOrigin[i]! + (fruit.positions[i]! - aOrigin[i]!) * state.scale;\n }\n }\n return compact(\n {\n positions: growPositions({ ...fruit, positions: scaled }, growth),\n normals: fruit.normals,\n uvs: fruit.uvs,\n ...occlusion.of(fruit, colors),\n visible: (v) => shown[v] === 1,\n },\n fruit.indices,\n isFlatShading(definition.materials.shading),\n );\n}\n\n/** A loaded texture for the baked material (a copy, so the tree's shared texture is untouched); null without image data. */\nfunction bakedMap(texture: Texture | null | undefined, repeat?: readonly [number, number]): Texture | null {\n if (!texture?.image) return null;\n const copy = texture.clone();\n if (repeat) copy.repeat.set(...repeat);\n return copy;\n}\n\n/**\n * Freezes a tree at a Growth and Season (default: the tree's own) into a static `Group` of\n * meshes `wood`, `leaves` and `fruit` (a mesh with nothing to show is left out) with standard PBR\n * materials: no node materials, no Growth/Season/Wind attributes, no animation. Material Features\n * are baked in (see the top of this module). The result is\n * independent of `tree`; call `disposeBakedTree` when done with it.\n */\nexport function bakeTree(tree: Tree, options: BakeOptions = {}): Group {\n const { definition, data } = tree;\n const source = tree.wood.material as MeshStandardMaterial; // MeshStandardNodeMaterial: same props\n const growth = clampGrowth(options.growth ?? tree.growth);\n const season = wrapSeason(options.season ?? tree.season);\n const bark = definition.materials.bark;\n const flat = isFlatShading(definition.materials.shading);\n // The features as the tree shows them now (values tuned live included).\n const features = tree.materialFeatures;\n const occlusion = bakedOcclusion(features.occlusion?.strength ?? null, options.occlusionInVertexColors ?? false);\n const extras = materialFeatureExtras(features, tree.data.crown, growth, options.occlusionInVertexColors ?? false);\n\n const group = new Group();\n group.name = definition.name || 'Tree';\n group.userData = { seed: tree.seed, growth, season };\n\n const woodGeometry = bakeWood(definition, data.wood, growth, occlusion);\n if (woodGeometry) {\n const material = new MeshStandardMaterial({\n name: 'bark',\n color: new Color(bark.groundTint ? 0xffffff : bark.color),\n roughness: bark.roughness,\n metalness: 0,\n vertexColors: woodGeometry.hasAttribute('color'),\n flatShading: flat,\n map: bakedMap(source.map, BARK_REPEAT),\n normalMap: bakedMap(source.normalMap, BARK_REPEAT),\n });\n if (extras) material.userData = { treejs: extras };\n group.add(bakedMesh('wood', woodGeometry, material));\n }\n\n const { geometry: leafGeometry, meanColor } = bakeLeaves(definition, data.leaves, growth, season, occlusion, data.crown, features.crownNormals);\n if (leafGeometry) {\n const map = bakedMap(tree.leaves.material.map);\n const material = new MeshStandardMaterial({\n name: 'leaves',\n color: 0xffffff,\n roughness: definition.materials.leaf.roughness,\n metalness: 0,\n vertexColors: true,\n flatShading: flat,\n side: DoubleSide,\n map,\n alphaTest: map ? definition.materials.leaf.alphaTest : 0,\n });\n if (extras) material.userData = { treejs: extras };\n const { translucency } = features;\n // The transmission colour is the leaves' own colour (without the occlusion of `occlusionInVertexColors`).\n if (translucency) diffuseTransmission.set(material, { factor: translucency.strength, color: meanColor });\n group.add(bakedMesh('leaves', leafGeometry, material));\n }\n\n const fruitGeometry = bakeFruit(definition, data.fruit, growth, season, occlusion);\n if (fruitGeometry) {\n const material = new MeshStandardMaterial({\n name: 'fruit',\n color: 0xffffff,\n roughness: tree.fruit.material.roughness,\n metalness: 0,\n vertexColors: true,\n flatShading: flat,\n });\n group.add(bakedMesh('fruit', fruitGeometry, material));\n }\n return group;\n}\n\n/**\n * The `treejs` object in the extras of the baked leaf and bark materials: the Material Feature\n * settings and the Crown Volume, for engines that rebuild the effects in their own shaders. The Crown\n * Volume is in the Baked Tree's space (scaled by its Growth, like the geometry). Null when the tree has\n * no Material Feature, so its glTF is as without them.\n */\nexport interface MaterialFeatureExtras {\n /** Crown Normals amount; the baked `NORMAL` already has them blended in. */\n crownNormals?: number;\n /** Leaf Translucency settings (also written as `KHR_materials_diffuse_transmission`). */\n translucency?: TranslucencyDefinition;\n occlusion?: {\n /** The Structural Occlusion strength the tree had. */\n strength: number;\n /**\n * Always true: the baked `_OCCLUSION` is final, `mix(1, aOcclusion, strength)`, with the strength\n * already applied. Use it as AO as it is; do not apply `strength` again.\n */\n strengthApplied: true;\n /** Whether `COLOR_0` is also multiplied by `_OCCLUSION` (`occlusionInVertexColors`). */\n inVertexColors: boolean;\n };\n crown: CrownVolume;\n}\n\nfunction materialFeatureExtras(\n features: MaterialFeatures,\n crown: CrownVolume,\n growth: number,\n occlusionInVertexColors: boolean,\n): MaterialFeatureExtras | null {\n const { crownNormals, translucency, occlusion } = features;\n if (!crownNormals && !translucency && !occlusion) return null;\n const scale = treeScale(growth);\n const { center, radii } = crown;\n return {\n ...(crownNormals ? { crownNormals } : {}),\n ...(translucency ? { translucency: { ...translucency } } : {}),\n ...(occlusion ? { occlusion: { strength: occlusion.strength, strengthApplied: true, inVertexColors: occlusionInVertexColors } } : {}),\n crown: { center: [center[0] * scale, center[1] * scale, center[2] * scale], radii: [radii[0] * scale, radii[1] * scale, radii[2] * scale] },\n };\n}\n\n/** Leaf Translucency of a baked leaf material, written as `KHR_materials_diffuse_transmission` on export. */\nconst diffuseTransmission = new WeakMap<Material, { factor: number; color: [number, number, number] }>();\n\n/** GLTFExporter plugin: Leaf Translucency as `KHR_materials_diffuse_transmission` (factor = strength, colour = the leaf colour). */\nclass DiffuseTransmissionExtension implements GLTFExporterPlugin {\n readonly name = 'KHR_materials_diffuse_transmission';\n constructor(private readonly writer: GLTFWriter) {}\n\n async writeMaterialAsync(material: Material, materialDef: Record<string, unknown>): Promise<void> {\n const transmission = diffuseTransmission.get(material);\n if (!transmission) return;\n const extensions = (materialDef.extensions ??= {}) as Record<string, unknown>;\n extensions[this.name] = { diffuseTransmissionFactor: transmission.factor, diffuseTransmissionColorFactor: transmission.color };\n (this.writer as unknown as { extensionsUsed: Record<string, boolean> }).extensionsUsed[this.name] = true;\n }\n}\n\nfunction bakedMesh(name: string, geometry: BufferGeometry, material: MeshStandardMaterial): Mesh {\n const mesh = new Mesh(geometry, material);\n mesh.name = name;\n mesh.castShadow = mesh.receiveShadow = true;\n return mesh;\n}\n\n/** Frees the geometries, materials and texture copies of a baked tree. */\nexport function disposeBakedTree(baked: Group): void {\n baked.traverse((object) => {\n if (!(object instanceof Mesh)) return;\n object.geometry.dispose();\n const material = object.material as MeshStandardMaterial;\n material.map?.dispose();\n material.normalMap?.dispose();\n material.dispose();\n });\n}\n\nexport interface ExportBakedTreeOptions extends BakeOptions {\n /** `.glb` (ArrayBuffer, default) or `.gltf` JSON with embedded buffers. */\n binary?: boolean;\n}\n\n/**\n * Bakes a tree (see {@link bakeTree}) and writes it as glTF 2.0: a `.glb` ArrayBuffer by default,\n * or the `.gltf` JSON object with `binary: false`. Waits for the tree's textures first. In Node,\n * three's GLTFExporter needs a `FileReader` global.\n */\nexport function exportBakedTree(tree: Tree, options?: ExportBakedTreeOptions & { binary?: true }): Promise<ArrayBuffer>;\nexport function exportBakedTree(tree: Tree, options: ExportBakedTreeOptions & { binary: false }): Promise<Record<string, unknown>>;\nexport function exportBakedTree(tree: Tree, options?: ExportBakedTreeOptions): Promise<ArrayBuffer | Record<string, unknown>>;\nexport async function exportBakedTree(\n tree: Tree,\n options: ExportBakedTreeOptions = {},\n): Promise<ArrayBuffer | Record<string, unknown>> {\n await tree.ready;\n const baked = bakeTree(tree, options);\n try {\n const exporter = new GLTFExporter().register((writer) => new DiffuseTransmissionExtension(writer));\n const result = await exporter.parseAsync(baked, { binary: options.binary ?? true });\n return result as ArrayBuffer | Record<string, unknown>;\n } finally {\n disposeBakedTree(baked);\n }\n}\n"],"mappings":";;;;;;;;;;AA+CA,IAAM,YAAY;;;;;AA0BlB,SAAS,QAAQ,SAAuB,SAAsB,MAAsC;CAClG,MAAM,EAAE,cAAc;CACtB,MAAM,OAAiB,CAAC;CACxB,MAAM,QAAQ,IAAI,WAAW,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE;CAC1D,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;EAC1C,MAAM,CAAC,GAAG,GAAG,KAAK;G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Q,SAAS,MAAM,OAAO;CACpC,IAAI;EAGF,OAAO,MAFU,IAAI,aAAa,CAAC,CAAC,UAAU,WAAW,IAAI,6BAA6B,MAAM,CAC3E,CAAA,CAAS,WAAW,OAAO,EAAE,QAAQ,QAAQ,UAAU,KAAK,CAAC;CAEpF,UAAU;EACR,iBAAiB,KAAK;CACxB;AACF"}
|
|
@@ -17,4 +17,9 @@ export interface CrownNodes {
|
|
|
17
17
|
* so a sapling is measured against its own, smaller crown. Shared by the Material Features.
|
|
18
18
|
*/
|
|
19
19
|
export declare function crownNodes(crown: CrownVolume, growth: Node<'float'>): CrownNodes;
|
|
20
|
+
/**
|
|
21
|
+
* The Crown Volume measured at `point`, a position in the fully grown tree's own space (Growth 1, no
|
|
22
|
+
* Wind). `crownNodes` uses it for a tree's vertices; an Impostor for the point its bake pictured.
|
|
23
|
+
*/
|
|
24
|
+
export declare function crownAt(crown: CrownVolume, point: Node<'vec3'>): CrownNodes;
|
|
20
25
|
//# sourceMappingURL=crown-nodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crown-nodes.d.ts","sourceRoot":"","sources":["../../src/materials/crown-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,qHAAqH;IACrH,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"crown-nodes.d.ts","sourceRoot":"","sources":["../../src/materials/crown-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,qHAAqH;IACrH,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,UAAU,CAIhF;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,UAAU,CAO3E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MeshStandardNodeMaterial, type Node } from 'three/webgpu';
|
|
2
2
|
import type { CrownVolume } from '../generator';
|
|
3
|
-
import { type LeafTranslucencyValues } from './leaf-translucency';
|
|
3
|
+
import { type LeafTranslucencyTerm, type LeafTranslucencyValues } from './leaf-translucency';
|
|
4
4
|
/**
|
|
5
5
|
* Gives a leaf material Leaf Translucency (`materials.leaf.translucency` as uniforms, a Material Feature, ADR 0008):
|
|
6
6
|
* its lighting model becomes the translucent one (the physical model with the term for flat and standard
|
|
@@ -11,4 +11,9 @@ import { type LeafTranslucencyValues } from './leaf-translucency';
|
|
|
11
11
|
* `positionNode` grows with (a Tree's Growth uniform, or a Forest's per-instance Growth).
|
|
12
12
|
*/
|
|
13
13
|
export declare function applyLeafTranslucency(material: MeshStandardNodeMaterial, values: LeafTranslucencyValues, crown: CrownVolume, growth: Node<'float'>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Gives `material` the translucent lighting model for a ready-made term (`applyLeafTranslucency` builds
|
|
16
|
+
* it from a tree's vertices; an Impostor from its baked Crown Volume distance).
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyLeafTranslucencyTerm(material: MeshStandardNodeMaterial, term: LeafTranslucencyTerm): void;
|
|
14
19
|
//# sourceMappingURL=leaf-translucency-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leaf-translucency-model.d.ts","sourceRoot":"","sources":["../../src/materials/leaf-translucency-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EAEV,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"leaf-translucency-model.d.ts","sourceRoot":"","sources":["../../src/materials/leaf-translucency-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EAEV,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAML,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC5B,MAAM,qBAAqB,CAAC;AA4B7B;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,wBAAwB,EAClC,MAAM,EAAE,sBAAsB,EAC9B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,GACpB,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,wBAAwB,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAM9G"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MeshStandardNodeMaterial, Node, NodeMaterial } from 'three/webgpu';
|
|
2
2
|
import type { MaterialFeatures, TranslucencyDefinition, TreeDefinition } from '../definition';
|
|
3
3
|
import type { CrownVolume } from '../generator';
|
|
4
|
+
import type { LeafTranslucencyValues } from './leaf-translucency';
|
|
4
5
|
/** One tree's materials to give the Material Features (a Tree's, or one Forest Variant's). */
|
|
5
6
|
export interface MaterialFeatureTarget {
|
|
6
7
|
/** The leaf material (Crown Normals, Leaf Translucency). */
|
|
@@ -14,6 +15,15 @@ export interface MaterialFeatureTarget {
|
|
|
14
15
|
/** Turns a tree-space normal into the mesh's own space (a Forest rotates it by the instance). Default: as is. */
|
|
15
16
|
toObject?: (normal: Node<'vec3'>) => Node<'vec3'>;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The live values of the Material Features that are on, as the uniforms every target shares (null for
|
|
20
|
+
* a feature that is off). For materials made after the features were applied (a Forest's Impostors).
|
|
21
|
+
*/
|
|
22
|
+
export interface MaterialFeatureNodes {
|
|
23
|
+
crownNormals: Node<'float'> | null;
|
|
24
|
+
translucency: LeafTranslucencyValues | null;
|
|
25
|
+
occlusion: Node<'float'> | null;
|
|
26
|
+
}
|
|
17
27
|
/**
|
|
18
28
|
* The Material Features (GLOSSARY, ADR 0008) of a Tree or Forest: applies those the Definition sets to
|
|
19
29
|
* the materials of each target and owns their values as uniforms, shared by all targets, so a feature
|
|
@@ -25,6 +35,8 @@ export declare class LiveMaterialFeatures {
|
|
|
25
35
|
private readonly translucencyValues;
|
|
26
36
|
private readonly occlusion;
|
|
27
37
|
constructor(definition: TreeDefinition, targets: readonly MaterialFeatureTarget[]);
|
|
38
|
+
/** The features that are on, as their shared uniforms (tuning them reaches every material that reads them). */
|
|
39
|
+
get nodes(): MaterialFeatureNodes;
|
|
28
40
|
/** The features that are on, with their current values (same shape as `materialFeaturesOf`). */
|
|
29
41
|
get values(): MaterialFeatures;
|
|
30
42
|
/** Crown Normals amount, null when off. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"material-features.d.ts","sourceRoot":"","sources":["../../src/materials/material-features.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,IAAI,EAAE,YAAY,EAAe,MAAM,cAAc,CAAC;AAC9F,OAAO,KAAK,EAAE,gBAAgB,EAAE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Q,CAAC,SAAS,CAAsB;gBAEpC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,qBAAqB,EAAE;IAcjF,+GAA+G;IAC/G,IAAI,KAAK,IAAI,oBAAoB,CAEhC;IAED,gGAAgG;IAChG,IAAI,MAAM,IAAI,gBAAgB,CAc7B;IAED,2CAA2C;IAC3C,IAAI,YAAY,IAAI,MAAM,GAAG,IAAI,CAEhC;IAED,uFAAuF;IACvF,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAK7B;IAED,0DAA0D;IAC1D,IAAI,YAAY,IAAI,sBAAsB,GAAG,IAAI,CAEhD;IAED,0HAA0H;IAC1H,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,sBAAsB,CAAC,EAQtD;IAED,oDAAoD;IACpD,IAAI,iBAAiB,IAAI,MAAM,GAAG,IAAI,CAErC;IAED,gGAAgG;IAChG,IAAI,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAKlC;CACF"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Group, type BufferGeometry, type MeshStandardNodeMaterial, type Node } from 'three/webgpu';
|
|
2
|
+
import type { Shading } from '../definition';
|
|
3
|
+
import { type TreePart } from '../effects/mask';
|
|
4
|
+
/** What a {@link TreeShaderHook} is given: TSL nodes of the fragment it shades, and which tree part it shades. */
|
|
5
|
+
export interface TreeShaderInput {
|
|
6
|
+
/** The tree part the hook shades: 'bark', 'leaves' or 'fruit'. */
|
|
7
|
+
part: TreePart;
|
|
8
|
+
/** The tree's shading model (its Style): 'flat' (low-poly), 'toon' (stylized) or 'standard' (realistic). */
|
|
9
|
+
shading: Shading;
|
|
10
|
+
/**
|
|
11
|
+
* The base colour (linear rgb): after Season, Ground Tint, textures and the Seed's tint, before lighting.
|
|
12
|
+
* In a stack of hooks: the colour the hook before returned.
|
|
13
|
+
*/
|
|
14
|
+
color: Node<'vec3'>;
|
|
15
|
+
/** The part's roughness (0..1) before the hook (in a stack: the one the hook before returned, if any). */
|
|
16
|
+
roughness: Node<'float'>;
|
|
17
|
+
/**
|
|
18
|
+
* The world-space normal the fragment is lit with, after Wind (and Wind Bursts) and Growth, with Crown
|
|
19
|
+
* Normals and the bark normal map; facing the viewer on both sides of a leaf card. On an Impostor: its
|
|
20
|
+
* baked normal, turned with the tree and its sway.
|
|
21
|
+
*/
|
|
22
|
+
normal: Node<'vec3'>;
|
|
23
|
+
/** The fragment's world position (after Wind and Growth). */
|
|
24
|
+
position: Node<'vec3'>;
|
|
25
|
+
/** The tree's own world position (its origin, at the foot of the trunk). */
|
|
26
|
+
treePosition: Node<'vec3'>;
|
|
27
|
+
/** The tree's Season (0..1). */
|
|
28
|
+
season: Node<'float'>;
|
|
29
|
+
/** The tree's Growth (0..1). */
|
|
30
|
+
growth: Node<'float'>;
|
|
31
|
+
}
|
|
32
|
+
/** What a {@link TreeShaderHook} may return instead of a bare colour. */
|
|
33
|
+
export interface TreeShaderOutput {
|
|
34
|
+
/** The new colour (linear rgb), lit as before. */
|
|
35
|
+
color: Node<'vec3'>;
|
|
36
|
+
/** The new roughness (0..1); the part's own when absent. */
|
|
37
|
+
roughness?: Node<'float'>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A Tree Shader Hook (GLOSSARY, ADR 0012): a TSL function the app hands the library for a tree part. It
|
|
41
|
+
* gets the part's base colour and inputs (see {@link TreeShaderInput}) and returns a new colour, or a
|
|
42
|
+
* colour and a roughness. It is called once each time it is set (to build the node graph), not per frame:
|
|
43
|
+
* animate it with uniforms.
|
|
44
|
+
*/
|
|
45
|
+
export type TreeShaderHook = (input: TreeShaderInput) => Node<'vec3'> | TreeShaderOutput;
|
|
46
|
+
/**
|
|
47
|
+
* The Tree Shader Hooks per tree part: one hook, or several that stack (each gets the colour and
|
|
48
|
+
* roughness the one before returned). A part left out (or `undefined`) has only the scene-wide default
|
|
49
|
+
* hooks ({@link setSceneShaderHooks}); a part's own hooks stack after those; `null` overrides them: the
|
|
50
|
+
* part is drawn with no hook at all. See {@link shaderHookOrder} for the order.
|
|
51
|
+
*/
|
|
52
|
+
export type TreeShaderHooks = Partial<Record<TreePart, TreeShaderHook | readonly TreeShaderHook[] | null>>;
|
|
53
|
+
/**
|
|
54
|
+
* @internal Marks a hook the library ships (Snow Cover, Wetness) as ready-made: in every stack it runs
|
|
55
|
+
* before the app's own hooks (see {@link shaderHookOrder}). Returns the hook.
|
|
56
|
+
*/
|
|
57
|
+
export declare function readyMadeShaderHook<T extends TreeShaderHook>(hook: T): T;
|
|
58
|
+
/**
|
|
59
|
+
* The hooks a tree part runs, in their fixed order: first the ready-made hooks (Snow Cover, Wetness), then
|
|
60
|
+
* the app's own; within each group the scene-wide default's before the Tree's or Forest's own, each in the
|
|
61
|
+
* order given. A hook listed twice runs once (at its first place). A part set to `null` on the Tree or
|
|
62
|
+
* Forest runs none, not even the scene-wide default's.
|
|
63
|
+
*/
|
|
64
|
+
export declare function shaderHookOrder(scene: TreeShaderHooks, own: TreeShaderHooks, part: TreePart): TreeShaderHook[];
|
|
65
|
+
/**
|
|
66
|
+
* Stacks sets of hooks into one: per part, the hooks of every set in the given order (as a list), e.g.
|
|
67
|
+
* `stackShaderHooks(snowCover, { leaves: painterly })`. A part that is `null` in a set and has no hook in
|
|
68
|
+
* any set stays `null`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function stackShaderHooks(...sets: readonly TreeShaderHooks[]): TreeShaderHooks;
|
|
71
|
+
/**
|
|
72
|
+
* Sets the scene-wide default Tree Shader Hooks: every Tree and Forest runs them (now and when created
|
|
73
|
+
* later), before its own hooks, unless it sets that part to `null`. `{}` removes them. Only the parts
|
|
74
|
+
* whose hooks change rebuild their node graphs, once; the geometry is never rebuilt.
|
|
75
|
+
*/
|
|
76
|
+
export declare function setSceneShaderHooks(hooks: TreeShaderHooks): void;
|
|
77
|
+
/** The scene-wide default Tree Shader Hooks (a copy), see {@link setSceneShaderHooks}. */
|
|
78
|
+
export declare function getSceneShaderHooks(): TreeShaderHooks;
|
|
79
|
+
/**
|
|
80
|
+
* One material hooks are applied to: a Tree's part, a Forest Variant's part (drawn at every Detail Level
|
|
81
|
+
* but Impostor), or a Forest Variant's Impostor card, which draws several parts.
|
|
82
|
+
*/
|
|
83
|
+
export interface ShaderHookTarget {
|
|
84
|
+
material: MeshStandardNodeMaterial;
|
|
85
|
+
/** The tree parts the material draws, and (when it draws several) how much of each a fragment is (0..1). */
|
|
86
|
+
parts: readonly TreePart[];
|
|
87
|
+
partWeight?: (part: TreePart) => Node<'float'>;
|
|
88
|
+
/** Whether the material multiplies in per-vertex colours (the Seed's tint): `vertexColors` and a `color` attribute. */
|
|
89
|
+
vertexColors: boolean;
|
|
90
|
+
season: Node<'float'>;
|
|
91
|
+
growth: Node<'float'>;
|
|
92
|
+
/** The tree's world position (a node the fragment stage can read). Default: see `treeBase`. */
|
|
93
|
+
treePosition?: Node<'vec3'>;
|
|
94
|
+
/**
|
|
95
|
+
* The tree's base in the material's object space, as the vertex stage knows it before `positionNode`
|
|
96
|
+
* runs (a Forest instance). It is handed to the fragment stage only when a hook reads `treePosition`.
|
|
97
|
+
* Without it nor `treePosition`: the origin of the drawn object.
|
|
98
|
+
*/
|
|
99
|
+
treeBase?: Node<'vec3'>;
|
|
100
|
+
/**
|
|
101
|
+
* The Wind displacement of the vertex in the material's object space (attributes and uniforms only).
|
|
102
|
+
* Default: the one registered with the material's `positionNode` (`setWindMotion`).
|
|
103
|
+
*/
|
|
104
|
+
sway?: Node<'vec3'> | null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The {@link ShaderHookTarget} of one tree part drawn by `material` from `geometry` (a Tree's part, or a
|
|
108
|
+
* Forest Variant's): it multiplies in vertex colours when the material uses them and the geometry has them.
|
|
109
|
+
*/
|
|
110
|
+
export declare function partHookTarget(part: TreePart, material: MeshStandardNodeMaterial, geometry: BufferGeometry, inputs: Pick<ShaderHookTarget, 'season' | 'growth' | 'treeBase'>): ShaderHookTarget;
|
|
111
|
+
/**
|
|
112
|
+
* The Tree Shader Hooks of a Tree or Forest: applies the hooks of each part (its own stacked after the
|
|
113
|
+
* scene-wide default's, {@link shaderHookOrder}) to that part's materials. A change rebuilds the node graph
|
|
114
|
+
* of the affected materials once (new `colorNode` / `roughnessNode`, `needsUpdate`), never the geometry;
|
|
115
|
+
* removing every hook puts the material's own nodes back as they were. A part whose hooks do not change is
|
|
116
|
+
* left alone. With no hook the materials are never touched (ADR 0008).
|
|
117
|
+
*/
|
|
118
|
+
export declare class LiveShaderHooks {
|
|
119
|
+
private readonly shading;
|
|
120
|
+
private own;
|
|
121
|
+
private stacks;
|
|
122
|
+
private readonly targets;
|
|
123
|
+
private readonly originals;
|
|
124
|
+
private readonly ref;
|
|
125
|
+
constructor(targets: readonly ShaderHookTarget[], shading: Shading, own?: TreeShaderHooks);
|
|
126
|
+
/** The own hooks per part (a copy), as set. */
|
|
127
|
+
get hooks(): TreeShaderHooks;
|
|
128
|
+
set hooks(value: TreeShaderHooks);
|
|
129
|
+
/** Adds materials made later (a Forest's Impostor cards), with the current hooks applied. */
|
|
130
|
+
addTargets(targets: readonly ShaderHookTarget[]): void;
|
|
131
|
+
/** Re-resolves the hooks (after the own or the scene-wide default ones changed) and rebuilds what changed. */
|
|
132
|
+
refresh(): void;
|
|
133
|
+
/** Stops following the scene-wide default hooks. */
|
|
134
|
+
dispose(): void;
|
|
135
|
+
private resolve;
|
|
136
|
+
private apply;
|
|
137
|
+
}
|
|
138
|
+
/** @internal What a Tree and a Forest share: a group of tree meshes with Tree Shader Hooks. */
|
|
139
|
+
export declare abstract class ShaderHookedGroup extends Group {
|
|
140
|
+
protected abstract readonly hooks: LiveShaderHooks;
|
|
141
|
+
/**
|
|
142
|
+
* The Tree Shader Hook per tree part (GLOSSARY, ADR 0012), e.g. `{ leaves: ({ color }) => color.mul(0.8) }`:
|
|
143
|
+
* a TSL function (or a list of them, which stack) that gets the part's base colour, world normal, world
|
|
144
|
+
* positions, Season and Growth and returns a new colour (optionally with a roughness). Assign a new
|
|
145
|
+
* object to set, change or remove hooks: a part left out has only the scene-wide default hooks
|
|
146
|
+
* (`setSceneShaderHooks`), its own run after those, and `null` runs none at all. Only the parts whose
|
|
147
|
+
* hooks changed rebuild their node graph, once; the geometry is never rebuilt. Without a hook a part is
|
|
148
|
+
* drawn exactly as before. On a Forest they reach every tree at every Detail Level, and the Impostors,
|
|
149
|
+
* which apply them at draw time to their baked colour, normals and Season data (changing a hook never
|
|
150
|
+
* rebakes).
|
|
151
|
+
*/
|
|
152
|
+
get shaderHooks(): TreeShaderHooks;
|
|
153
|
+
set shaderHooks(value: TreeShaderHooks);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=shader-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader-hooks.d.ts","sourceRoot":"","sources":["../../src/materials/shader-hooks.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,KAAK,cAAc,EAAE,KAAK,wBAAwB,EAAE,KAAK,IAAI,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG5D,kHAAkH;AAClH,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,IAAI,EAAE,QAAQ,CAAC;IACf,4GAA4G;IAC5G,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,0GAA0G;IAC1G,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB;;;;OAIG;IACH,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,4EAA4E;IAC5E,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3B,gCAA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