@threenative/procedural-environment 0.1.2 → 0.1.4

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 CHANGED
@@ -14,7 +14,7 @@ npm i -D @threenative/procedural-environment
14
14
 
15
15
  ## Find what to bake
16
16
 
17
- One catalog holds every element (`tree`, `cover`, `debris`, `rock`, `city`) with its biomes and the exact
17
+ The bake catalog lists each element (`tree`, `cover`, `debris`, `rock`, `city`) with its biomes and the exact
18
18
  bake call. A biome takes its id or a request word: `jungle` is `tropical`, `swamp` is `wetland`,
19
19
  `canyon` is `desert`.
20
20
 
@@ -33,15 +33,54 @@ kits (forest, coastal, alpine, desert, tundra) where they overlap.
33
33
 
34
34
  ## Browse everything: `pnpm asset-library`
35
35
 
36
- From the repository root, `pnpm asset-library` builds this package and opens a Storybook-shaped
37
- viewer: a sidebar of every element by kind with search and a biome filter, one story per element
38
- with every option its bake takes as a control (seed, level of detail, textures, a rock's biome,
39
- size, shape traits, surface cover and cliff module, a city module's floors, wetness and sign), a
40
- docs tab with the paste-ready bake call, size, triangles and GLB attributes, and an overview story
41
- per kind at true scale. Each story calls this package's own bake, so the viewer shows what a game
42
- gets. The URL holds the story (`#/rock/cliff?biome=coastal&module=1`), so a link shows the same
43
- bake. While it runs, an edit under `src/`, `vendor/` or `scans/` rebuilds the package and reloads
44
- the page.
36
+ From the repository root, `pnpm asset-library` builds this package and opens a Storybook-style
37
+ viewer. Search the sidebar by name or filter by biome and style tags. Selecting several tags
38
+ shows assets with any of those tags. Nature and city modules are tagged Realistic, the Biome
39
+ Kit is tagged Stylized, and the Dungeon kit is tagged Low Poly. Open a story to orbit the asset.
40
+ GLB stories run the package's bake with the selected controls. The Docs tab shows the exact
41
+ bake call and mesh attributes, and the Stats tab shows dimensions and triangle counts.
42
+ Story links retain the controls, such as `#/rock/cliff?biome=coastal&module=1`. Changes
43
+ under `src/`, `vendor/`, or `scans/` rebuild the package and reload the viewer.
44
+
45
+ ### Stylized Biome Kit
46
+
47
+ Open **Stylized Biome Kit** in the same sidebar for the alpine forest, snow peaks, and desert
48
+ canyon scenes, all original asset variants, and the three mountain ridges. These generators
49
+ return Three.js objects with their original WebGL shader materials. Advance
50
+ `stylizedUniforms.uTime.value` each frame to animate water, snow, and foliage.
51
+
52
+ ```ts
53
+ import { createStylizedAsset, stylizedAssets } from "@threenative/procedural-environment/stylized";
54
+
55
+ const assets = stylizedAssets();
56
+ const { group } = createStylizedAsset("mountain-snow", { seed: 8, variant: 1 });
57
+ scene.add(group);
58
+ ```
59
+
60
+ The subpath also exports the source kit's `terrain`, `sky`, and `scatter` helpers. The Docs tab
61
+ copies the call for the selected asset and controls. Variant indices in code start at zero.
62
+
63
+ ### Dungeon kit
64
+
65
+ The **Dungeon** section includes 49 procedural pieces and two assembled previews. Each piece comes
66
+ in Ancient Ruins, Ice Dungeon, and Lava Depths. Walls run along X and pair with 4 m floor modules.
67
+ Rotate walls 90° around Y for the other axis. Straight stairs rise 2 m toward negative Z.
68
+
69
+ ```ts
70
+ import { createStylizedAsset, stylizedUniforms } from "@threenative/procedural-environment/stylized";
71
+
72
+ const torch = createStylizedAsset("dungeon-wall-torch", { seed: 12, variant: 0 });
73
+ scene.add(torch.group);
74
+
75
+ function tick(elapsedSeconds: number) {
76
+ stylizedUniforms.uTime.value = elapsedSeconds;
77
+ torch.update?.(elapsedSeconds);
78
+ }
79
+ ```
80
+
81
+ The wall torch, brazier, hanging lamp, candle cluster, and altar carry their own point light. The
82
+ shader moves the flame and embers, and `update` flickers the emitted light. The Theme control in the
83
+ viewer corresponds to variant indices 0, 1, and 2.
45
84
 
46
85
  ## Trees, cover and the forest floor
47
86
 
@@ -0,0 +1,108 @@
1
+ import * as three from 'three';
2
+ import { Group, Object3D, Mesh, ShaderMaterial, Vector3, Color, Material } from 'three';
3
+
4
+ interface IStylizedScene {
5
+ group: Group;
6
+ view: { pos: [number, number, number]; target: [number, number, number] };
7
+ env: {
8
+ skyTop: number;
9
+ horizon: number;
10
+ fog: [number, number, number];
11
+ sun: { dir: [number, number, number]; color: number; intensity: number };
12
+ hemi: { sky: number; ground: number; intensity: number };
13
+ shadow: number;
14
+ };
15
+ }
16
+
17
+ declare const uniforms: { uTime: { value: number } };
18
+
19
+ /**
20
+ * Build a gradient sky dome with the Stylized Biome Kit's WebGL shader.
21
+ * @situation a procedural stylized gradient sky dome for an alpine, snow, or desert scene
22
+ * @example scene.add(sky({ top: 0x3a8be8, horizon: 0xe2f1ff }));
23
+ * @requires npm i @threenative/procedural-environment
24
+ */
25
+ declare function sky(options?: { top?: number; horizon?: number; radius?: number }): Mesh<
26
+ three.SphereGeometry,
27
+ ShaderMaterial
28
+ >;
29
+ /**
30
+ * Build stylized heightfield geometry with a color callback and a second-color mask for path edges.
31
+ * @situation make stylized heightfield terrain with vertex colors and a worn path
32
+ * @example const meadow = terrain({ height: (x, z) => 1 + Math.sin(x) * Math.cos(z), color: (_x, _z, _y, _n, out) => out.set(0x55b93e) });
33
+ * @requires npm i @threenative/procedural-environment
34
+ */
35
+ declare function terrain(options: {
36
+ size?: number;
37
+ segments?: number;
38
+ focus?: number;
39
+ height: (x: number, z: number) => number;
40
+ color: (
41
+ x: number,
42
+ z: number,
43
+ y: number,
44
+ normal: Vector3,
45
+ color: Color,
46
+ blend: { tint: Color; mask: number },
47
+ ) => void;
48
+ }): Mesh;
49
+ /**
50
+ * Make instanced batches of a Stylized Biome Kit piece at explicit positions.
51
+ * @situation instance a stylized biome tree or grass asset at many positions
52
+ * @example scene.add(scatter(group, [{ x: 5, z: 8 }, { x: 9, z: 10, rot: 1 }]));
53
+ * @requires npm i @threenative/procedural-environment
54
+ */
55
+ declare function scatter(
56
+ source: Object3D,
57
+ placements: {
58
+ x: number;
59
+ y?: number;
60
+ z: number;
61
+ rot?: number;
62
+ tiltX?: number;
63
+ tiltZ?: number;
64
+ scale?: number | [number, number, number];
65
+ }[],
66
+ ): Group;
67
+
68
+ declare const stylizedMaterials: Record<string, Material>;
69
+
70
+ interface IStylizedAsset {
71
+ id: string;
72
+ name: string;
73
+ kind: "stylized" | "dungeon";
74
+ category: string;
75
+ biomes: string[];
76
+ variants: number;
77
+ variantNames?: readonly string[];
78
+ }
79
+ interface IStylizedAssetOptions {
80
+ variant?: number;
81
+ seed?: number;
82
+ overrides?: Record<string, unknown>;
83
+ }
84
+ /**
85
+ * List the Stylized Biome Kit pieces and scenes, including available variants.
86
+ * @situation browse procedural stylized biome assets for alpine forest, snow peaks, or desert canyon
87
+ * @situation browse modular dungeon walls, stone floors, arches, doors, props, fixtures, and assembled dungeon scenes
88
+ * @requires npm i @threenative/procedural-environment
89
+ * @example const rows = stylizedAssets();
90
+ */
91
+ declare function stylizedAssets(): IStylizedAsset[];
92
+ /**
93
+ * Generate a Stylized Biome Kit or Dungeon piece or scene with its Three.js materials.
94
+ * @situation create stylized mountain ridges, snowy trees, sandstone formations, or animated water
95
+ * @situation create modular dungeon walls, stairs, arches, dungeon props and fixtures in an overgrown, frozen, or volcanic theme
96
+ * @constraint the biome shaders, dungeon surface finish, and fire motion use Three.js WebGL materials
97
+ * @requires npm i @threenative/procedural-environment
98
+ * @example const { group } = createStylizedAsset("mountain-snow", { seed: 8, variant: 1 });
99
+ */
100
+ declare function createStylizedAsset(id: string, options?: IStylizedAssetOptions): {
101
+ group: Object3D;
102
+ animated: boolean;
103
+ update?: (seconds: number) => void;
104
+ view?: IStylizedScene["view"];
105
+ env?: IStylizedScene["env"];
106
+ };
107
+
108
+ export { type IStylizedAsset, type IStylizedAssetOptions, createStylizedAsset, scatter, sky, stylizedAssets, stylizedMaterials, uniforms as stylizedUniforms, terrain };