@threenative/procedural-environment 0.0.0-stage → 0.1.3
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/LICENSES/Apex-MIT.txt +35 -0
- package/LICENSES/Arbor-MIT.txt +24 -0
- package/LICENSES/Outcrop-MIT.txt +26 -0
- package/LICENSES/forest-kit-MIT.txt +26 -0
- package/README.md +209 -2
- package/dist/index.d.ts +309 -0
- package/dist/index.js +5409 -0
- package/package.json +53 -3
- package/scans/LeafSet012-leaves.webp +0 -0
- package/scans/LeafSet016-leaves.webp +0 -0
- package/scans/LeafSet027-leaves.webp +0 -0
- package/scans/bark_brown_01-color.webp +0 -0
- package/scans/bark_brown_01-normal.webp +0 -0
- package/scans/bark_brown_02-detail.webp +0 -0
- package/scans/bark_brown_02-normal.webp +0 -0
- package/scans/bark_willow_02-color.webp +0 -0
- package/scans/bark_willow_02-normal.webp +0 -0
- package/scans/chinese_hackberry_bark-color.webp +0 -0
- package/scans/chinese_hackberry_bark-normal.webp +0 -0
- package/scans/credits.json +99 -0
- package/scans/fern_02-frond.webp +0 -0
- package/scans/grass_medium_02-blade.webp +0 -0
- package/scans/island_tree_01-leaves.webp +0 -0
- package/scans/jacaranda_tree-leaves.webp +0 -0
- package/scans/japanese_camphor_bark-color.webp +0 -0
- package/scans/japanese_camphor_bark-normal.webp +0 -0
- package/scans/japanese_cedar_bark-color.webp +0 -0
- package/scans/japanese_cedar_bark-normal.webp +0 -0
- package/scans/jolcham_oak_bark_01-color.webp +0 -0
- package/scans/jolcham_oak_bark_01-normal.webp +0 -0
- package/scans/knotted_pine_bark-color.webp +0 -0
- package/scans/knotted_pine_bark-normal.webp +0 -0
- package/scans/metasequoia_bark-color.webp +0 -0
- package/scans/metasequoia_bark-normal.webp +0 -0
- package/scans/palm_bark-color.webp +0 -0
- package/scans/palm_bark-normal.webp +0 -0
- package/scans/pine_tree_01-sprig.webp +0 -0
- package/scans/rock_boulder_dry-detail.webp +0 -0
- package/scans/rock_boulder_dry-normal.webp +0 -0
- package/scans/sakura_bark-color.webp +0 -0
- package/scans/sakura_bark-normal.webp +0 -0
- package/scans/shrub_01-leaves.webp +0 -0
- package/scans/shrub_02-leaves.webp +0 -0
- package/scans/tree_bark_03-color.webp +0 -0
- package/scans/tree_bark_03-normal.webp +0 -0
- package/vendor/apex/apex-city-kit.js +7425 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Furtado
|
|
4
|
+
|
|
5
|
+
Apex City Kit (apex-city-kit.html) is written by João Paulo Furtado, who holds its copyright and
|
|
6
|
+
licenses it to this package under the MIT licence. The vendored copy
|
|
7
|
+
(vendor/apex/apex-city-kit.js) keeps the page's script verbatim, with one line added that hands
|
|
8
|
+
the generator and its GLTFExporter to the bake and stops before the page UI boots; the page's
|
|
9
|
+
HTML and CSS stay upstream.
|
|
10
|
+
|
|
11
|
+
The script inlines three.js r183 and its add-ons, Copyright 2010-2026 Three.js Authors, under the
|
|
12
|
+
MIT licence; its own licence header is kept in the vendored file.
|
|
13
|
+
|
|
14
|
+
Its 26 embedded PBR maps (diffuse, normal and ARM, as WebP) are CC0 1.0 scans from Poly Haven
|
|
15
|
+
(https://polyhaven.com), no attribution required, credited here with thanks: asphalt_02,
|
|
16
|
+
concrete, red_brick, rectangular_paving, rusty_metal_02, rubberized_track, oak_wood_planks,
|
|
17
|
+
grey_roof_tiles_02, painted_metal_shutter and concrete_wall_007.
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
in the Software without restriction, including without limitation the rights
|
|
22
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
furnished to do so, subject to the following conditions:
|
|
25
|
+
|
|
26
|
+
The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Furtado
|
|
4
|
+
|
|
5
|
+
Arbor (arbor.js) is written by João Paulo Furtado, who holds its copyright and
|
|
6
|
+
licenses it to this package under the MIT licence.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Furtado
|
|
4
|
+
|
|
5
|
+
Outcrop (rockgen.js) is written by João Paulo Furtado, who holds its copyright and
|
|
6
|
+
licenses it to this package under the MIT licence. The vendored
|
|
7
|
+
copy keeps the generator verbatim as an ES module over three; the
|
|
8
|
+
viewer page and its UI stay upstream.
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Furtado
|
|
4
|
+
|
|
5
|
+
forest-kit is written by João Paulo Furtado, who holds its copyright and
|
|
6
|
+
licenses it to this package under the MIT licence. The vendored
|
|
7
|
+
copy keeps its generators and drops three: `src/render/` look material, world,
|
|
8
|
+
terrain, sky, water and scatter stay upstream.
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,210 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @threenative/procedural-environment
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Optional bake-first procedural nature: trees, cover, the forest floor and rocks, found by
|
|
4
|
+
biome. An agent asks for `oak`, `reeds`, `log` or a coastal `cliff` and gets a GLB it owns. The
|
|
5
|
+
generators are [Arbor](LICENSES/Arbor-MIT.txt), [forest-kit](LICENSES/forest-kit-MIT.txt),
|
|
6
|
+
[Outcrop](LICENSES/Outcrop-MIT.txt) and the [Apex City Kit](LICENSES/Apex-MIT.txt), all written by João Paulo Furtado and vendored under the
|
|
7
|
+
MIT licence. `Arbor.three`, forest-kit's `build()`,
|
|
8
|
+
its three shapes and the browser PNG encoder are cut: the game owns the look and the sway, so no
|
|
9
|
+
game ships the generator.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i -D @threenative/procedural-environment
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Find what to bake
|
|
16
|
+
|
|
17
|
+
One catalog holds every element (`tree`, `cover`, `debris`, `rock`, `city`) with its biomes and the exact
|
|
18
|
+
bake call. A biome takes its id or a request word: `jungle` is `tropical`, `swamp` is `wetland`,
|
|
19
|
+
`canyon` is `desert`.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { environmentBiomes, environmentElements } from "@threenative/procedural-environment";
|
|
23
|
+
|
|
24
|
+
environmentBiomes().map((biome) => biome.id);
|
|
25
|
+
// forest, hills, coastal, alpine, desert, tundra, volcanic, savanna, tropical, mediterranean, wetland, garden
|
|
26
|
+
environmentElements({ biome: "desert", kind: "rock" }).map((element) => element.bake);
|
|
27
|
+
// ['bakeRock({ form: "boulder", biome: "desert", seed: 1, out: "assets/environment" })', ...]
|
|
28
|
+
environmentElements({ search: "palm" }); // coconut, fanpalm, with their biomes
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
An unknown biome or kind throws and names the nearest ids. Biome ids match the Strata terrain
|
|
32
|
+
kits (forest, coastal, alpine, desert, tundra) where they overlap.
|
|
33
|
+
|
|
34
|
+
## Browse everything: `pnpm asset-library`
|
|
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.
|
|
45
|
+
|
|
46
|
+
## Trees, cover and the forest floor
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { bakeVegetation, vegetationPresets } from "@threenative/procedural-environment";
|
|
50
|
+
|
|
51
|
+
vegetationPresets(); // [{ id: "oak", name: "English oak", latin: "Quercus robur", kind: "tree" }, ...]
|
|
52
|
+
const lods = await bakeVegetation({ preset: "oak", seed: 7, lods: [0, 1, 2], out: "assets/trees" });
|
|
53
|
+
// assets/trees/oak-7-lod0.glb ... each entry: { lod, path, triangles, bounds: { min, max } }
|
|
54
|
+
await bakeVegetation({ preset: "log", seed: 3, out: "assets/debris" });
|
|
55
|
+
await bakeVegetation({ preset: "reeds", seed: 4, out: "assets/cover" });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- The same preset, seed and lods write the same bytes. Files are written to a temporary name,
|
|
59
|
+
then renamed.
|
|
60
|
+
- Fail closed: an unknown preset throws and names the nearest ids, the seed must be an
|
|
61
|
+
integer, each lod is 0 (full) to 2 (far).
|
|
62
|
+
- Each GLB holds two primitives, `bark` and `foliage`, with `COLOR_0`, `TEXCOORD_0` and a
|
|
63
|
+
`_WIND` vec4 per vertex: x trunk sway (m), y branch sway (m), z leaf flutter (m), w phase.
|
|
64
|
+
Units are metres, +Y is up, the plant stands on the origin.
|
|
65
|
+
- Textures are CC0 scans by default (`scans/credits.json`). Bark: species bark from Poly Haven on
|
|
66
|
+
the Arbor trees whose bark has a scan (oak, cedar, palm, sakura ...; the pines keep Arbor's drawn orange bark, because the scan read pale and smooth). Wood and stone: a grey
|
|
67
|
+
detail scan on forest-kit `log`, `stump`, `branch`, `twig` and `rock`, whose `COLOR_0` takes twice
|
|
68
|
+
Arbor's untextured colour factor, so the kit's palette stays. The bake's `scan` names the bark or detail scan.
|
|
69
|
+
- Foliage: real scanned leaves, cut from the alpha atlases of Poly Haven plant models, and from
|
|
70
|
+
ambientCG leaf sets where Poly Haven has no such leaf. Arbor still lays out each leaf card (its
|
|
71
|
+
twigs, fronds and blossoms), but each leaf, blade, frond or needle sprig is a scan, tinted to the
|
|
72
|
+
species palette. The families: oak (ambientCG `LeafSet016`), maple (`LeafSet027`), ovate and birch
|
|
73
|
+
leaves (`shrub_01`), elliptic (`island_tree_01`), lance (`shrub_02`), feathery acacia and jacaranda
|
|
74
|
+
(`jacaranda_tree`), grass blades (`grass_medium_02`), fern fronds (`fern_02`), spruce
|
|
75
|
+
sprigs (`pine_tree_01`). Foliage is matte (roughness 0.85) with a gentle leaf normal (scale 0.5), so
|
|
76
|
+
it does not reflect the sky as grey-white patches. forest-kit cover and leaf litter
|
|
77
|
+
wear a grey blade or leaf scan with the same `COLOR_0` rule. Leaf litter then rides the alpha-masked
|
|
78
|
+
`foliage` primitive, so each leaf keeps its scanned outline. The bake's `leafScan` names the
|
|
79
|
+
sprites. Ginkgo, palm fronds, yucca, flower heads, the elephant ear and the fine-scale cedar,
|
|
80
|
+
cypress, araucaria and pine needle cards read better drawn than scanned and
|
|
81
|
+
keep Arbor's drawing (`__tests__/texture-health.spec.ts` fails on any other foliage without a scan
|
|
82
|
+
or a texture).
|
|
83
|
+
- `textures: "generated"` keeps the generators' own textures pixel for pixel. Every embedded image
|
|
84
|
+
is WebP (`EXT_texture_webp`, required): bark scans 512 px at q75 (normals q80), leaf sprites q75
|
|
85
|
+
and leaf atlases q80, both with lossless alpha, so a cutout edge stays exact. A leaf card also carries a
|
|
86
|
+
normal map at half resolution, cooked from its own outline and veins.
|
|
87
|
+
- One scan serves every species that shares it (19 bark profiles, 11 scans). Each GLB embeds its
|
|
88
|
+
copy, and the cook's shared-images pass (`@threenative/assets`, on by default) writes each
|
|
89
|
+
distinct image once under `shared/images/`, so a game ships the bark once.
|
|
90
|
+
- The Arbor presets also carry their bark and leaf atlas and alpha-masked leaves. A forest-kit
|
|
91
|
+
preset shades from `COLOR_0` and its grey scan: wood and stone ride `bark`, cover (a thin blade or
|
|
92
|
+
frond) and leaf litter ride the double-sided, alpha-masked `foliage` primitive, and its float sway
|
|
93
|
+
is `_WIND.z`, with debris writing all four zero.
|
|
94
|
+
- `form` and `leafImage` patch an Arbor preset's shape and leaf card. A forest-kit preset throws
|
|
95
|
+
when given either, because it has no leaf card to patch.
|
|
96
|
+
- `leafSize` caps the drawn leaf card's longest side: Arbor draws 1024 px, and a far level or a
|
|
97
|
+
shrub a metre tall shows a few hundred at most, so a game that cares about bytes bakes those
|
|
98
|
+
smaller. A game's own `leafImage` is never resized; the two together throw.
|
|
99
|
+
- `barkImage` and `barkNormalImage` paint a photographed surface and its relief on the bark
|
|
100
|
+
instead of Arbor's drawn one. A species whose trunk is the whole silhouette needs it: a
|
|
101
|
+
`saguaro` is a column, and the drawn cactus bark is a flat pinstripe. The relief is a glTF
|
|
102
|
+
tangent-space normal PNG, drawn against the albedo; without it the bark is left flat, because
|
|
103
|
+
Arbor's own bark normal belongs to a bark that is no longer sampled. `barkNormalImage` without
|
|
104
|
+
`barkImage` throws.
|
|
105
|
+
- `@napi-rs/canvas` paints the leaf atlas at bake time (Arbor needs a Canvas 2D), and `sharp`
|
|
106
|
+
encodes the WebPs.
|
|
107
|
+
|
|
108
|
+
## Rocks, cliffs and mountains
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { bakeRock } from "@threenative/procedural-environment";
|
|
112
|
+
|
|
113
|
+
await bakeRock({ form: "cliff", biome: "coastal", seed: 7, lods: [0, 1], out: "assets/rocks" });
|
|
114
|
+
// assets/rocks/cliff-coastal-7-lod0.glb ... the same { lod, path, triangles, bounds } entries
|
|
115
|
+
await bakeRock({ form: "boulder", biome: "forest", traits: { weathering: 0.8 }, out: "assets/rocks" });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- Forms: `boulder`, `slab`, `spire`, `hoodoo`, `stack` (sea stack), `mesa`, `arch`, `cliff`
|
|
119
|
+
(tiles along X) and `mountain`. A cliff is one module of a wall: bake module n with the same
|
|
120
|
+
seed and `module: n` (or `offset: [n * width, 0, 0]`), stand the modules one width apart and they join with no
|
|
121
|
+
seam. A module that stands alone shows a cut face at each end. The biome sets the strata, fracture and weathering, and the
|
|
122
|
+
painted cover: moss in a forest, snow in the tundra, sand in the desert, algae under the tide.
|
|
123
|
+
- `traits` and `surface` override the biome's values key by key (`roughness`, `strata`,
|
|
124
|
+
`columnar`; `rockA`, `moss`, `snow`, `tide`), `size` sets metres and `detail` (0 to 1, default
|
|
125
|
+
0.3) the level-0 density. An unknown key throws. Any override puts a hash in the file name.
|
|
126
|
+
- Each GLB holds one primitive on a `rock` material: `POSITION`, `NORMAL` and `COLOR_0` (linear
|
|
127
|
+
RGB, rock and cover already blended), plus `_ROCK`, `_COVER` and `_WET`, the inputs of Outcrop's
|
|
128
|
+
triplanar `createRockMaterial`. Beside it the bake writes that material's two maps as lossless
|
|
129
|
+
WebPs (`rock` in the result: detail rgb albedo and a roughness, normal rgb and a height). No UVs:
|
|
130
|
+
the material projects them triplanar. Metres, +Y up, the rock rests on y = 0.
|
|
131
|
+
- The same options write the same bytes. `three` builds the geometry at bake time only.
|
|
132
|
+
|
|
133
|
+
## City modules: roads, buildings, props, vehicles
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { bakeCity, environmentElements } from "@threenative/procedural-environment";
|
|
137
|
+
|
|
138
|
+
environmentElements({ kind: "city" }).map((element) => `${element.category}: ${element.id}`);
|
|
139
|
+
// 75 modules: Roads: cross, ... Buildings: office, ... Vehicles: sedan, ... Decals & Works: road-grime
|
|
140
|
+
await bakeCity({ module: "cross", out: "assets/city" });
|
|
141
|
+
// assets/city/cross-31082.glb, one { lod: 0, path, triangles, bounds } entry
|
|
142
|
+
await bakeCity({ module: "apartments", seed: 7, floors: 8, out: "assets/city" });
|
|
143
|
+
await bakeCity({
|
|
144
|
+
module: "curve",
|
|
145
|
+
bendAngle: 55,
|
|
146
|
+
bendRadius: 24,
|
|
147
|
+
bendSide: "left",
|
|
148
|
+
roadWidth: 12,
|
|
149
|
+
sidewalk: false,
|
|
150
|
+
curb: false,
|
|
151
|
+
out: "assets/city",
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- The generator is the vendored [Apex City Kit](LICENSES/Apex-MIT.txt) page with its
|
|
156
|
+
own three.js r183 in `vendor/apex/`. The bake runs the page's generator and its GLTFExporter in a
|
|
157
|
+
`node:vm` context, with `@napi-rs/canvas` for the canvas and image decode, and exports the way
|
|
158
|
+
the page's GLB button does (binary, `trs`, textures capped at 1024 px).
|
|
159
|
+
- Options and limits are the page's: `seed` 0 to 4294967295 (default 31082), `detail` 0 to 2
|
|
160
|
+
(default 2), `wet` 0 to 100 (default 30), `floors` 2 to 12 (default 4), `text` at most 24
|
|
161
|
+
characters, `dressing` true or false. An unknown module names the nearest ids. Options other
|
|
162
|
+
than the seed put a hash in the file name.
|
|
163
|
+
- Each GLB holds one merged mesh per material with the page's PBR materials and embedded
|
|
164
|
+
textures: the CC0 Poly Haven maps (asphalt, concrete, brick, paving, metal, rubber, oak, roof
|
|
165
|
+
tiles, shutter, formwork; JPEG colour, PNG normal and ARM) and the canvas-drawn signs, liveries
|
|
166
|
+
and markings. The root node's extras hold `module`, `seed`, `parameters`, `units` and the road
|
|
167
|
+
`sockets`. Units are metres with +Y up. Stock tiles use a 24 m grid.
|
|
168
|
+
- Set `roadWidth` (6–16 m) on straight and curve modules, and `roadLength` (8–200 m)
|
|
169
|
+
on straights. Curves expose `bendAngle` (5–180°), `bendRadius` (12–120 m), and
|
|
170
|
+
`bendSide` (`left` or `right` from the north inlet). These pieces still carry two lanes.
|
|
171
|
+
To join them, align the socket positions and point their outward directions opposite each
|
|
172
|
+
other. Match socket widths for a flush join. The outlet of a non-90° bend has side `end`.
|
|
173
|
+
- Use `roadSurface` (`asphalt`, `concrete`, or `paving`) on socketed roads. Toggle
|
|
174
|
+
`sidewalk` and `curb` independently on straight, curve, cross, tee, alley, grid, pit,
|
|
175
|
+
and cul-de-sac modules. On straight and curve modules, `markings: false` removes lane paint.
|
|
176
|
+
- The page's PNG and JPEG maps are re-encoded as WebP q80 at bake (`EXT_texture_webp`): the 95
|
|
177
|
+
distinct city images drop from 5.6 MB to 1.2 MB.
|
|
178
|
+
- The same options write the same bytes on one machine and Node major: sign text draws with the
|
|
179
|
+
machine's `sans-serif` and `monospace` fonts, and Node 20 and 22 round some colour factors one
|
|
180
|
+
bit differently from Node 24 and the browser.
|
|
181
|
+
|
|
182
|
+
## In a game
|
|
183
|
+
|
|
184
|
+
Cook the GLBs with `assets.models.passes.prune: false` (prune strips the uv and
|
|
185
|
+
`_WIND` a material reads), load them with `ctx.assets.model` and write the sway as TSL in
|
|
186
|
+
`src/render/wind.ts` (`attribute("_wind", "vec4")`, a time uniform, `modelWorldMatrixInverse`).
|
|
187
|
+
|
|
188
|
+
A Strata terrain world takes the same trees with the species prefix `arbor:<preset>[@seed]`
|
|
189
|
+
(`terrain_generate`, `terrain_biome_new`); install this package next to `@threenative/terrain`.
|
|
190
|
+
|
|
191
|
+
## Nature map
|
|
192
|
+
|
|
193
|
+
One package, one table: what bakes here, what the engine streams, and where the rest lives. An
|
|
194
|
+
agent asked for "a realistic forest" should not have to find nine places by itself.
|
|
195
|
+
|
|
196
|
+
| Piece | Where it lives | Import path |
|
|
197
|
+
| --- | --- | --- |
|
|
198
|
+
| Trees (28 species) | `bakeVegetation`, Arbor presets, kind `tree` | `@threenative/procedural-environment` |
|
|
199
|
+
| Cover (grasses, ferns, flowers, shrubs) | `bakeVegetation`, Arbor presets plus forest-kit `reeds`, `tussock`, `seedgrass`, `clover`, `dock`, `plume`, kind `cover` | `@threenative/procedural-environment` |
|
|
200
|
+
| Debris (`log`, `stump`, `twig`, `branch`, `leaflitter`, `rock`) | `bakeVegetation`, forest-kit presets, kind `debris` | `@threenative/procedural-environment` |
|
|
201
|
+
| Rocks, cliffs, arches, mesas, sea stacks, mountains | `bakeRock`, Outcrop forms, kind `rock` | `@threenative/procedural-environment` |
|
|
202
|
+
| City roads, buildings, street props, vehicles, race kit (75 modules) | `bakeCity`, Apex City Kit modules, kind `city` | `@threenative/procedural-environment` |
|
|
203
|
+
| Which of these belong in a biome | `environmentElements({ biome, kind, search })`, `environmentBiomes()` | `@threenative/procedural-environment` |
|
|
204
|
+
| Grass that sways and parts around the player | `GrassField3D`, streamed in chunks under a frame budget | `@threenative/core` |
|
|
205
|
+
| Any other baked mesh scattered round the player | `ScatterField3D`, the same tile ring as grass, one `InstancedMesh` per level per part | `@threenative/core` |
|
|
206
|
+
| The look: materials, wind TSL, distance fade | the game's own `src/render/`, reading `_WIND` and `GRASS_FIELD_ATTRIBUTES` | game source |
|
|
207
|
+
| Sky and sun | `Daylight` | `@threenative/core` |
|
|
208
|
+
| Water | `WaterSurface3D`, `WaterBodies` | `@threenative/core` |
|
|
209
|
+
| Terrain, biomes and a cooked world | `@threenative/terrain` (`terrain_generate`, `arbor:<preset>[@seed]` species) | `@threenative/terrain` |
|
|
210
|
+
| Textures | Poly Haven CC0 bark and detail scans and CC0 leaf, blade and frond sprites (Poly Haven, ambientCG) vendored in `scans/` (WebP); other scanned CC0 maps through the asset MCP | `@threenative/procedural-environment` |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where each element belongs. A biome lists the trees, cover, debris and rock forms that read as
|
|
3
|
+
* that place, and names the Outcrop rock surface its rocks wear. Ids match the Strata terrain kits
|
|
4
|
+
* (forest, coastal, alpine, desert, tundra) where they overlap. A spec fails when an element has no
|
|
5
|
+
* biome, so a new preset gets one here.
|
|
6
|
+
*/
|
|
7
|
+
interface IEnvironmentBiome {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** Other words a request uses for this place ("jungle", "swamp"); `environmentElements` searches them. */
|
|
11
|
+
readonly words: readonly string[];
|
|
12
|
+
/** The Outcrop biome whose colours, weathering and cover (moss, snow, sand, algae) the rocks take. */
|
|
13
|
+
readonly rock: string;
|
|
14
|
+
/** Element ids: Arbor and forest-kit presets, and Outcrop rock forms. */
|
|
15
|
+
readonly elements: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface IBakeCityOptions {
|
|
19
|
+
/** Directory the GLB is written to; created when missing. */
|
|
20
|
+
readonly out: string;
|
|
21
|
+
/** A module id: `environmentElements({ kind: "city" })` lists all 75 (cross, office, sedan, civic-bridge ...). */
|
|
22
|
+
readonly module: string;
|
|
23
|
+
/** An integer 0 to 4294967295. The same options always write the same bytes. Default 31082, the page's. */
|
|
24
|
+
readonly seed?: number;
|
|
25
|
+
/** Geometry detail: 0 low, 1 standard, 2 high. Default 2. */
|
|
26
|
+
readonly detail?: number;
|
|
27
|
+
/** Surface wetness, 0 to 100. Default 30. */
|
|
28
|
+
readonly wet?: number;
|
|
29
|
+
/** Building floors, an integer 2 to 12. Default 4. */
|
|
30
|
+
readonly floors?: number;
|
|
31
|
+
/** Sign text, at most 24 characters; empty uses the generated name. Default "". */
|
|
32
|
+
readonly text?: string;
|
|
33
|
+
/** Include street fixtures. Default true. */
|
|
34
|
+
readonly dressing?: boolean;
|
|
35
|
+
/** Straight and curve carriageway width in metres (6–16). Default 10. */
|
|
36
|
+
readonly roadWidth?: number;
|
|
37
|
+
/** Straight length in metres (8–200). Default 24. */
|
|
38
|
+
readonly roadLength?: number;
|
|
39
|
+
/** Curve sweep in degrees (5–180). Default 90. */
|
|
40
|
+
readonly bendAngle?: number;
|
|
41
|
+
/** Curve centreline radius in metres (12–120). Default 12. */
|
|
42
|
+
readonly bendRadius?: number;
|
|
43
|
+
/** Curve direction from its north inlet. Default "right". */
|
|
44
|
+
readonly bendSide?: "left" | "right";
|
|
45
|
+
/** Roadway material for modules with road sockets. Default "asphalt". */
|
|
46
|
+
readonly roadSurface?: "asphalt" | "concrete" | "paving";
|
|
47
|
+
/** Include pedestrian paving on supported road modules. Default true. */
|
|
48
|
+
readonly sidewalk?: boolean;
|
|
49
|
+
/** Include curbs on supported road modules. Default true. */
|
|
50
|
+
readonly curb?: boolean;
|
|
51
|
+
/** Include lane paint on straight and curve modules. Default true. */
|
|
52
|
+
readonly markings?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface IVegetationPreset {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly latin?: string;
|
|
59
|
+
/** `tree`, `cover` (grass, fern, flower, shrub) or `debris` (log, twig, litter, stone). */
|
|
60
|
+
readonly kind: string;
|
|
61
|
+
}
|
|
62
|
+
interface IBakeVegetationOptions {
|
|
63
|
+
/** Directory the GLBs are written to; created when missing. */
|
|
64
|
+
readonly out: string;
|
|
65
|
+
/** A preset id from `vegetationPresets()`. */
|
|
66
|
+
readonly preset: string;
|
|
67
|
+
/** An integer. The same preset and seed always write the same bytes. Default 1. */
|
|
68
|
+
readonly seed?: number;
|
|
69
|
+
/** Levels of detail to write, each 0 (full) to 2 (far). Default `[0]`. */
|
|
70
|
+
readonly lods?: readonly number[];
|
|
71
|
+
/**
|
|
72
|
+
* A patch over the preset, so a game changes a species' form and leaf card with no package edit:
|
|
73
|
+
* `levels`, `leaves` and `tex.cells` merge row by row into the preset's own rows, and any other key
|
|
74
|
+
* replaces the preset's value. Each key must name a field the preset has. The file names carry a
|
|
75
|
+
* hash of the patch, so a formed bake never overwrites the stock one.
|
|
76
|
+
*/
|
|
77
|
+
readonly form?: Readonly<Record<string, unknown>>;
|
|
78
|
+
/**
|
|
79
|
+
* A PNG the leaves draw instead of Arbor's drawn card, as an atlas laid out on the preset's
|
|
80
|
+
* `tex.grid` (cell 0 top-left, row by row); `form` picks the grid and each leaf row's `cells`.
|
|
81
|
+
* The file names carry a hash of its bytes.
|
|
82
|
+
*/
|
|
83
|
+
readonly leafImage?: string;
|
|
84
|
+
/**
|
|
85
|
+
* The longest side of Arbor's drawn leaf card, in pixels; Arbor draws 1024. A far level is drawn
|
|
86
|
+
* at a few pixels on screen, so a 1024 px card is bytes the frame never shows. A game's own
|
|
87
|
+
* `leafImage` is always used as given, and the two together throw.
|
|
88
|
+
*/
|
|
89
|
+
readonly leafSize?: number;
|
|
90
|
+
/**
|
|
91
|
+
* A PNG painted on the bark instead of Arbor's drawn one, for a species whose trunk is the whole
|
|
92
|
+
* silhouette (`saguaro`): the drawn bark is a flat pinstripe, and no photograph of a ribbed
|
|
93
|
+
* column is in the preset. The file names carry a hash of its bytes.
|
|
94
|
+
*/
|
|
95
|
+
readonly barkImage?: string;
|
|
96
|
+
/**
|
|
97
|
+
* The bark's relief as a glTF tangent-space normal PNG, drawn against `barkImage`.
|
|
98
|
+
*
|
|
99
|
+
* Arbor's own bark normal belongs to its drawn bark and is dropped when `barkImage` replaces it,
|
|
100
|
+
* so without this the trunk keeps a smooth surface and a ribbed column loses its ribs. Throws
|
|
101
|
+
* without `barkImage`, because a relief with no albedo to show is a caller's mistake.
|
|
102
|
+
*/
|
|
103
|
+
readonly barkNormalImage?: string;
|
|
104
|
+
/**
|
|
105
|
+
* `"scans"` (the default) wraps bark and forest-kit wood and stone in a Poly Haven CC0 scan, and
|
|
106
|
+
* draws leaves, blades, fronds and needles from CC0 leaf scans, where one fits (the bake's `scan`
|
|
107
|
+
* and `leafScan` name them); `"generated"` keeps the generator's own texture, byte for byte, as the
|
|
108
|
+
* raw Arbor and forest-kit pages draw it.
|
|
109
|
+
*/
|
|
110
|
+
readonly textures?: "scans" | "generated";
|
|
111
|
+
}
|
|
112
|
+
interface IEnvironmentBake {
|
|
113
|
+
readonly bounds: {
|
|
114
|
+
readonly max: readonly [number, number, number];
|
|
115
|
+
readonly min: readonly [number, number, number];
|
|
116
|
+
};
|
|
117
|
+
readonly lod: number;
|
|
118
|
+
readonly path: string;
|
|
119
|
+
readonly triangles: number;
|
|
120
|
+
/** The Poly Haven scan the bark or wood wears, absent when the texture is generated. */
|
|
121
|
+
readonly scan?: string;
|
|
122
|
+
/**
|
|
123
|
+
* The scanned foliage sprites the leaves, blades or fronds wear (`+` between several), absent when
|
|
124
|
+
* the leaf card is Arbor's drawing or a game's leafImage.
|
|
125
|
+
*/
|
|
126
|
+
readonly leafScan?: string;
|
|
127
|
+
/**
|
|
128
|
+
* A rock's material inputs: Outcrop's ROCK_TEXTURES profile, metres per repeat, and the two lossless WebPs
|
|
129
|
+
* its triplanar material samples (detail: rgb albedo multiplier, a roughness; normal: rgb
|
|
130
|
+
* tangent normal, a height). The GLB's `_ROCK`, `_COVER` and `_WET` attributes are the rest.
|
|
131
|
+
*/
|
|
132
|
+
readonly rock?: {
|
|
133
|
+
readonly texture: string;
|
|
134
|
+
readonly tile: number;
|
|
135
|
+
readonly detail: string;
|
|
136
|
+
readonly normal: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* List every preset a bake can grow: id, name, latin name and kind.
|
|
141
|
+
* Trees and cover come from Arbor; the `debris` rows (log, stump, twig, branch, leaflitter, rock)
|
|
142
|
+
* and the extra cover rows (reeds, tussock, seedgrass, clover, dock, plume) come from forest-kit.
|
|
143
|
+
* @situation list the oak, pine, spruce, palm and other tree species a bake can grow
|
|
144
|
+
* @situation choose a tree species id for bakeVegetation or a terrain arbor: species
|
|
145
|
+
* @situation what deadwood, leaf litter, boulders, reeds and tussocks can I bake for a forest floor
|
|
146
|
+
* @constraint ids come from the vendored Arbor and forest-kit presets; trees are kind "tree", grass, ferns and flowers are kind "cover", deadwood, litter and stone are kind "debris"
|
|
147
|
+
* @requires npm i -D @threenative/procedural-environment
|
|
148
|
+
* @example vegetationPresets().filter((p) => p.kind === "debris").map((p) => p.id);
|
|
149
|
+
*/
|
|
150
|
+
declare function vegetationPresets(): IVegetationPreset[];
|
|
151
|
+
/**
|
|
152
|
+
* Bake a procedural tree (Arbor) to GLBs, one per level of detail, ready for ctx.assets.model.
|
|
153
|
+
* Each GLB carries the _WIND vertex attribute, COLOR_0 and TEXCOORD_0 and embeds WebP textures:
|
|
154
|
+
* Arbor trees and cover wear a CC0 bark scan and alpha-masked leaves, blades, fronds and needles
|
|
155
|
+
* painted from CC0 leaf scans; forest-kit wood and stone wear a grey CC0 detail scan, and forest-kit
|
|
156
|
+
* cover and leaf litter a grey CC0 blade or leaf scan, each over the kit's COLOR_0 palette.
|
|
157
|
+
* @situation generate a procedural tree, an oak, pine, spruce, palm or any forest species as a GLB
|
|
158
|
+
* @situation procedural oak tree GLB with level of detail for a game forest
|
|
159
|
+
* @situation tree GLB for Unity, Unreal or Godot, with wind weights in a _WIND attribute
|
|
160
|
+
* @situation a fallen mossy log and leaf litter on the forest floor, with a stump, twigs and boulders
|
|
161
|
+
* @situation reeds and cattails at a pond edge, or sedge tussocks, clover and seeding grass as cover
|
|
162
|
+
* @alias trees
|
|
163
|
+
* @alias palm trees
|
|
164
|
+
* @alias street trees along a road
|
|
165
|
+
* @alias bushes and shrubs
|
|
166
|
+
* @alias grass, flowers and ferns as ground cover
|
|
167
|
+
* @alias dead trees, fallen logs and stumps
|
|
168
|
+
* @alias low poly tree with level of detail
|
|
169
|
+
* @alias realistic textured tree model
|
|
170
|
+
* @alias foliage and vegetation models
|
|
171
|
+
* @alias pine, oak or spruce forest trees
|
|
172
|
+
* @alias grass tufts and clumps
|
|
173
|
+
* @constraint fails closed: an unknown preset throws naming the nearest ids, the seed must be an integer and each lod 0 to 2
|
|
174
|
+
* @constraint the same preset, seed and lods write identical bytes; files are written atomically (temporary file, then rename)
|
|
175
|
+
* @constraint bake-time only, so keep it a dev dependency; the game owns the look and the sway (a TSL render/wind.ts reading _WIND), because Arbor.three is not shipped
|
|
176
|
+
* @constraint _WIND is vec4 (trunk sway, branch sway, flutter, phase): forest-kit sway is flutter in z, and debris writes all four zero
|
|
177
|
+
* @constraint textures default to "scans" (the bake's `scan` and `leafScan` name them); nine presets with no fitting CC0 leaf scan (ginkgo, palms, banana, joshua, flowers, elephantear) keep Arbor's drawn leaf card; textures: "generated" keeps every generator texture byte for byte
|
|
178
|
+
* @constraint form, leafImage, barkImage and barkNormalImage patch an Arbor preset only; a forest-kit debris or cover preset throws when given any
|
|
179
|
+
* @requires npm i -D @threenative/procedural-environment
|
|
180
|
+
* @example await bakeVegetation({ preset: "oak", seed: 7, lods: [0, 1], out: "assets/trees" });
|
|
181
|
+
* @example await bakeVegetation({ preset: "log", seed: 3, out: "assets/debris" });
|
|
182
|
+
*/
|
|
183
|
+
declare function bakeVegetation(options: IBakeVegetationOptions): Promise<IEnvironmentBake[]>;
|
|
184
|
+
/** What an element is: a tree, ground cover, floor debris, a rock form or an Apex city module. */
|
|
185
|
+
type EnvironmentKind = "tree" | "cover" | "debris" | "rock" | "city";
|
|
186
|
+
interface IEnvironmentElement {
|
|
187
|
+
readonly id: string;
|
|
188
|
+
readonly name: string;
|
|
189
|
+
readonly latin?: string;
|
|
190
|
+
readonly kind: EnvironmentKind;
|
|
191
|
+
/** Biome ids from `environmentBiomes()` this element belongs in. */
|
|
192
|
+
readonly biomes: readonly string[];
|
|
193
|
+
/** A city module's Apex category: Roads, Buildings, Street Props, Vehicles, Race Kit ... */
|
|
194
|
+
readonly category?: string;
|
|
195
|
+
/** The call that bakes it, ready to paste; a rock's names the filter's biome, else its first. */
|
|
196
|
+
readonly bake: string;
|
|
197
|
+
}
|
|
198
|
+
interface IEnvironmentFilter {
|
|
199
|
+
/** A biome id or one of its words ("jungle" finds tropical). */
|
|
200
|
+
readonly biome?: string;
|
|
201
|
+
readonly kind?: EnvironmentKind;
|
|
202
|
+
/** Words that must all appear in the id, name, latin name, kind or biomes ("pine", "red rock"). */
|
|
203
|
+
readonly search?: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Every biome: its id, name, the request words that mean it, the rock surface its rocks wear and
|
|
207
|
+
* the element ids that belong there.
|
|
208
|
+
* @situation which biomes can I bake nature for: forest, desert, jungle, tundra, coast, volcano
|
|
209
|
+
* @situation what trees, plants, debris and rocks belong in a desert or an alpine biome
|
|
210
|
+
* @constraint ids match the Strata terrain kits where they overlap (forest, coastal, alpine, desert, tundra)
|
|
211
|
+
* @requires npm i -D @threenative/procedural-environment
|
|
212
|
+
* @example environmentBiomes().map((biome) => biome.id);
|
|
213
|
+
*/
|
|
214
|
+
declare function environmentBiomes(): IEnvironmentBiome[];
|
|
215
|
+
/**
|
|
216
|
+
* Find the nature elements to bake, by biome, kind or words: trees, ground cover, forest-floor
|
|
217
|
+
* debris and rock forms (boulders, cliffs, sea stacks, mesas, arches, mountains), each with the
|
|
218
|
+
* exact bake call.
|
|
219
|
+
* @situation what can I bake for a desert, a jungle, a coast, a tundra or a volcanic island
|
|
220
|
+
* @situation list the rocks, cliffs and mountains for a biome, or every plant that grows there
|
|
221
|
+
* @situation find a tree or plant by name or latin name, such as pine, palm, cactus or fern
|
|
222
|
+
* @alias nature props for a level
|
|
223
|
+
* @alias jungle and tropical plants
|
|
224
|
+
* @alias desert cactus
|
|
225
|
+
* @alias vegetation for a biome
|
|
226
|
+
* @constraint fails closed: an unknown biome or kind throws naming the nearest ids
|
|
227
|
+
* @constraint biome takes an id or one of its words, so "jungle" finds tropical and "swamp" finds wetland
|
|
228
|
+
* @requires npm i -D @threenative/procedural-environment
|
|
229
|
+
* @example environmentElements({ biome: "desert", kind: "rock" }).map((element) => element.bake);
|
|
230
|
+
* @example environmentElements({ search: "palm" });
|
|
231
|
+
*/
|
|
232
|
+
declare function environmentElements(filter?: IEnvironmentFilter): IEnvironmentElement[];
|
|
233
|
+
interface IBakeRockOptions {
|
|
234
|
+
/** Directory the GLBs are written to; created when missing. */
|
|
235
|
+
readonly out: string;
|
|
236
|
+
/** A rock form: `environmentElements({ kind: "rock" })` lists boulder, slab, cliff, arch, mountain and the rest. */
|
|
237
|
+
readonly form: string;
|
|
238
|
+
/** A biome id or word from `environmentBiomes()`; sets the rock's weathering and colour. Default "hills". */
|
|
239
|
+
readonly biome?: string;
|
|
240
|
+
/** An integer. The same options always write the same bytes. Default 1. */
|
|
241
|
+
readonly seed?: number;
|
|
242
|
+
/** Levels of detail, each 0 (full) to 2 (far); level n keeps `detail` x 1, 0.5, 0.2. Default `[0]`. */
|
|
243
|
+
readonly lods?: readonly number[];
|
|
244
|
+
/** Mesh density of level 0, 0 to 1: about 1 500 triangles at 0, 70 000 at 1. Default 0.3. */
|
|
245
|
+
readonly detail?: number;
|
|
246
|
+
/** Width, height, depth in metres; default the form's own (a boulder is 2.4 x 1.8 x 2.1 m). */
|
|
247
|
+
readonly size?: readonly [number, number, number];
|
|
248
|
+
/** Shape overrides 0 to 1 over the biome's: roughness, chipping, strata, layers, tilt, fracture, columnar, weathering. */
|
|
249
|
+
readonly traits?: Readonly<Record<string, number>>;
|
|
250
|
+
/** Colour and cover overrides over the biome's: rockA, rockB, accent, moss, snow, sand, lichen, tide and their colours. */
|
|
251
|
+
readonly surface?: Readonly<Record<string, string | number>>;
|
|
252
|
+
/**
|
|
253
|
+
* A tileable form's (cliff) module along +X: module n sits n widths over and meets n - 1 and
|
|
254
|
+
* n + 1 without a seam, as Outcrop's `tile()` lays them. Place it at x = n x width. Default 0.
|
|
255
|
+
*/
|
|
256
|
+
readonly module?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Where the module stands in its run, in metres. A tileable form (`cliff`) joins its neighbour
|
|
259
|
+
* only when both share the seed and stand one width apart: module n takes `[n * width, 0, 0]`.
|
|
260
|
+
*/
|
|
261
|
+
readonly offset?: readonly [number, number, number];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Bake a procedural rock (Outcrop) to GLBs, one per level of detail: a boulder, slab, spire,
|
|
265
|
+
* hoodoo, sea stack, mesa, arch, tileable cliff module or a mountain, weathered and coloured for
|
|
266
|
+
* its biome (moss in a forest, snow in the tundra, sand in the desert, algae below the tide line).
|
|
267
|
+
* @situation generate a procedural rock, boulder or cliff as a GLB for a game level
|
|
268
|
+
* @situation desert mesa, hoodoo or sandstone arch; coastal sea stack; alpine spire; volcanic basalt columns
|
|
269
|
+
* @situation a procedural mountain mesh for the horizon, with snow at altitude
|
|
270
|
+
* @alias rocks and boulders
|
|
271
|
+
* @alias cliffs and mountains
|
|
272
|
+
* @constraint fails closed: an unknown form or biome throws naming the nearest ids, as do unknown traits or surface keys, a non-integer seed, a lod outside 0 to 2 and a detail outside 0 to 1
|
|
273
|
+
* @constraint the same options write identical bytes; files are written atomically (temporary file, then rename)
|
|
274
|
+
* @constraint each GLB carries POSITION, NORMAL and COLOR_0 (linear RGB, rock and cover already blended) on one `rock` material; units are metres, +Y up, the rock rests on y = 0
|
|
275
|
+
* @constraint a `cliff` module shows a cut face at each end: bake a run with one seed and `offset: [n * width, 0, 0]`, stand the modules one width apart and bury the two ends of the run
|
|
276
|
+
* @constraint bake-time only, so keep it a dev dependency; the game owns the material and can re-material by the glTF material name `rock`
|
|
277
|
+
* @requires npm i -D @threenative/procedural-environment
|
|
278
|
+
* @example await bakeRock({ form: "cliff", biome: "coastal", seed: 7, lods: [0, 1], out: "assets/rocks" });
|
|
279
|
+
* @example await bakeRock({ form: "boulder", biome: "forest", traits: { weathering: 0.8 }, out: "assets/rocks" });
|
|
280
|
+
* @example for (const n of [0, 1, 2]) await bakeRock({ form: "cliff", biome: "desert", seed: 7, offset: [n * 10, 0, 0], out: "assets/rocks" }); // three modules of one wall
|
|
281
|
+
*/
|
|
282
|
+
declare function bakeRock(options: IBakeRockOptions): Promise<IEnvironmentBake[]>;
|
|
283
|
+
/**
|
|
284
|
+
* Bake an Apex City Kit module to one GLB: a road tile, a building, a street prop, a vehicle, a race
|
|
285
|
+
* kit piece, a block or lot, a sidewalk, transit, a public space, a utility or a decal. The page's
|
|
286
|
+
* own generator and GLTFExporter run headless, so the GLB carries its merged meshes, its materials
|
|
287
|
+
* and textures (Poly Haven CC0 PBR maps and the canvas-drawn signs, liveries and markings) and its
|
|
288
|
+
* road sockets in the root node's extras.
|
|
289
|
+
* @situation generate a modular city street, intersection, roundabout or highway tile as a GLB
|
|
290
|
+
* @situation a procedural building, storefront, office tower, apartment block, house or warehouse for a city level
|
|
291
|
+
* @situation street props for a city: traffic signal, streetlight, bus shelter, hydrant, bench, mailbox, dumpster
|
|
292
|
+
* @situation a race track kit: starting grid, timing gantry, barriers, tire wall, kerbs, pit lane; or a car, van, kart or formula car
|
|
293
|
+
* @alias city kit
|
|
294
|
+
* @alias modular road tiles
|
|
295
|
+
* @alias low poly city buildings
|
|
296
|
+
* @alias cars and vehicles
|
|
297
|
+
* @constraint fails closed: an unknown module throws naming the nearest ids; seed is an integer 0 to 4294967295, detail 0 to 2, wet 0 to 100, floors an integer 2 to 12, text at most 24 characters, dressing a boolean
|
|
298
|
+
* @constraint the same options write identical bytes on one Node major and machine (fonts draw the sign text); files are written atomically (temporary file, then rename)
|
|
299
|
+
* @constraint units are metres, +Y up; stock roads fit a 24 m grid, and custom straights and bends export updated socket positions, directions, widths and lane centres in the root node's extras
|
|
300
|
+
* @constraint roadWidth and markings apply to straight and curve; roadLength applies to straight; bendAngle, bendRadius and bendSide apply to curve; roadSurface applies to socketed road modules
|
|
301
|
+
* @constraint bake-time only, so keep it a dev dependency; textures are capped at 1024 px like the page's export
|
|
302
|
+
* @requires npm i -D @threenative/procedural-environment
|
|
303
|
+
* @example await bakeCity({ module: "cross", out: "assets/city" });
|
|
304
|
+
* @example await bakeCity({ module: "curve", bendAngle: 55, bendRadius: 24, bendSide: "left", roadWidth: 12, sidewalk: false, curb: false, out: "assets/city" });
|
|
305
|
+
* @example await bakeCity({ module: "apartments", seed: 7, floors: 8, out: "assets/city" });
|
|
306
|
+
*/
|
|
307
|
+
declare function bakeCity(options: IBakeCityOptions): Promise<IEnvironmentBake[]>;
|
|
308
|
+
|
|
309
|
+
export { type EnvironmentKind, type IBakeCityOptions, type IBakeRockOptions, type IBakeVegetationOptions, type IEnvironmentBake, type IEnvironmentBiome, type IEnvironmentElement, type IEnvironmentFilter, type IVegetationPreset, bakeCity, bakeRock, bakeVegetation, environmentBiomes, environmentElements, vegetationPresets };
|