@wildshard/shard-format 0.14.0 → 0.16.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/package.json +34 -2
- package/src/format/baked-terrain.golden.json +2760 -0
- package/src/format/colliders.golden.json +1619 -0
- package/src/format/colliders.ts +568 -0
- package/src/format/contentBounds.ts +6 -0
- package/src/format/creatures.ts +4 -3
- package/src/format/forest-placement.golden.json +4588 -0
- package/src/format/forest-placement.ts +385 -0
- package/src/format/geometry-layout.golden.json +180 -0
- package/src/format/grass-field.ts +287 -0
- package/src/format/headless-sections.ts +49 -0
- package/src/format/interact-table.golden.json +340 -0
- package/src/format/interact-table.ts +541 -0
- package/src/format/item-catalogue.golden.json +2310 -0
- package/src/format/item-catalogue.ts +148 -0
- package/src/format/mover-pose.ts +46 -0
- package/src/format/native-geometry-channels.ts +64 -0
- package/src/format/noise.ts +106 -0
- package/src/format/road-light.ts +47 -0
- package/src/format/seeded-rng.golden.json +857 -0
- package/src/format/seeded-rng.ts +111 -0
- package/src/format/small-laws.golden.json +57 -0
- package/src/format/terrain-field.golden.json +3998 -0
- package/src/format/terrain-field.ts +405 -0
- package/src/format/whole-partition.ts +170 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/* oxlint-disable capitalized-comments, complexity, curly, id-length, import/exports-last, import/group-exports, max-depth, max-lines, max-lines-per-function, max-params, max-statements, no-bitwise, no-continue, no-inline-comments, no-magic-numbers, no-nested-ternary, no-param-reassign, no-plusplus, no-use-before-define, typescript/explicit-function-return-type, typescript/explicit-member-accessibility, typescript/prefer-readonly, typescript/prefer-readonly-parameter-types, typescript/strict-boolean-expressions, unicorn/no-array-for-each, unicorn/no-nested-ternary, unicorn/no-null, unicorn/numeric-separators-style -- verbatim port of the engine's law (SDK-SPLIT SP4); bit-exact output is pinned by golden vectors, so it keeps the engine's form */
|
|
2
|
+
/**
|
|
3
|
+
* SDK-SPLIT SP4d (Q35): moved from engine `shared/engine/world/forest/placement.ts`; the bake and the engine plant one
|
|
4
|
+
* forest. Where the forest goes, with no three.js, no active level and no installed terrain: the caller hands the
|
|
5
|
+
* terrain samplers, the seed, the tree cap and the forest spec (`ForestPlacementSource`), and gets plain tree records
|
|
6
|
+
* whose tint is a linear rgb triple (three's `Color.setHSL` in the linear working space, `hslToRgb`). The engine wraps
|
|
7
|
+
* these in its `THREE.Color` instances; the build keeps them as numbers.
|
|
8
|
+
*/
|
|
9
|
+
import { CHUNK_HALF, CHUNK_SIZE } from './contentBounds.ts'
|
|
10
|
+
import { Noise2D, smoothstep } from './noise.ts'
|
|
11
|
+
import { Rng } from './seeded-rng.ts'
|
|
12
|
+
|
|
13
|
+
export type TreeSpecies = string
|
|
14
|
+
export type SpeciesWeights = Partial<Record<TreeSpecies, number>>
|
|
15
|
+
/** how a species is planted: its scale range; whether it follows the zone's growth (ForestPlacementSpec.scale); the trunk's
|
|
16
|
+
* extra girth (m); its spacing — 'wide' keeps every neighbour 3.5 m off (a giant's buttresses), 'tight' 0.6 m (a sapling),
|
|
17
|
+
* else 1.2 m; a hue shift of its tint */
|
|
18
|
+
export interface TreeSpeciesTraits {
|
|
19
|
+
readonly id: TreeSpecies
|
|
20
|
+
readonly scale: readonly [number, number]
|
|
21
|
+
readonly grows: boolean
|
|
22
|
+
readonly girth: number
|
|
23
|
+
readonly spacing: 'wide' | 'normal' | 'tight'
|
|
24
|
+
readonly hue?: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A shard's forest: the engine's `ForestSpec` (level data), structurally. */
|
|
28
|
+
export interface ForestPlacementSpec {
|
|
29
|
+
spacing: number
|
|
30
|
+
densityFreq: number
|
|
31
|
+
clearings: [number, number]
|
|
32
|
+
maxSlope: number
|
|
33
|
+
tintHue: number
|
|
34
|
+
tintHueJitter: [number, number]
|
|
35
|
+
tintSat: [number, number]
|
|
36
|
+
tintLight: [number, number]
|
|
37
|
+
largeVariantChance: number
|
|
38
|
+
density?: (x: number, z: number) => number
|
|
39
|
+
scale?: (x: number, z: number) => number
|
|
40
|
+
species?: (x: number, z: number) => SpeciesWeights
|
|
41
|
+
/** how each species of the set is planted, in draw order (needed with `species`) */
|
|
42
|
+
speciesTraits?: readonly TreeSpeciesTraits[]
|
|
43
|
+
understory?: { ferns: number; shrubs: number; fernCanopy: boolean }
|
|
44
|
+
infill?: { x: number; z: number; r: number }
|
|
45
|
+
mask?: (x: number, z: number) => number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A linear rgb colour, each channel 0..1. */
|
|
49
|
+
export type Rgb = [number, number, number]
|
|
50
|
+
|
|
51
|
+
/** One placed tree: its foot (ground − 0.25), trunk collision radius, variant, scale, yaw, height and linear tint. */
|
|
52
|
+
export interface ForestTree {
|
|
53
|
+
x: number
|
|
54
|
+
y: number
|
|
55
|
+
z: number
|
|
56
|
+
r: number
|
|
57
|
+
variant: number
|
|
58
|
+
scale: number
|
|
59
|
+
rot: number
|
|
60
|
+
height: number
|
|
61
|
+
tint: Rgb
|
|
62
|
+
species?: TreeSpecies | undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const euclideanModulo = (n: number, m: number): number => ((n % m) + m) % m
|
|
66
|
+
const clamp01 = (value: number): number => Math.max(0, Math.min(1, value))
|
|
67
|
+
function hue2rgb(p: number, q: number, t: number): number {
|
|
68
|
+
if (t < 0) t += 1
|
|
69
|
+
if (t > 1) t -= 1
|
|
70
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t
|
|
71
|
+
if (t < 1 / 2) return q
|
|
72
|
+
if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t)
|
|
73
|
+
return p
|
|
74
|
+
}
|
|
75
|
+
/** three.js `Color.setHSL(h, s, l)` in the linear working space (no colour-space conversion), as a linear rgb triple. */
|
|
76
|
+
export function hslToRgb(h: number, s: number, l: number): Rgb {
|
|
77
|
+
// h,s,l ranges are in 0.0 - 1.0
|
|
78
|
+
h = euclideanModulo(h, 1)
|
|
79
|
+
s = clamp01(s)
|
|
80
|
+
l = clamp01(l)
|
|
81
|
+
if (s === 0) return [l, l, l]
|
|
82
|
+
const p = l <= 0.5 ? l * (1 + s) : l + s - l * s
|
|
83
|
+
const q = 2 * l - p
|
|
84
|
+
return [hue2rgb(q, p, h + 1 / 3), hue2rgb(q, p, h), hue2rgb(q, p, h - 1 / 3)]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** the chunk test the engine's Heightfield makes: (x, z) at least `margin` inside the cell */
|
|
88
|
+
function inChunk(x: number, z: number, margin = 0): boolean {
|
|
89
|
+
return (
|
|
90
|
+
Math.abs(x) <= CHUNK_HALF - margin && Math.abs(z) <= CHUNK_HALF - margin
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The soft canopy density over the chunk (`n` x `n` cells, row-major, z rows): each tree's crown as a disc of radius
|
|
96
|
+
* 0.16 x its height, summed and capped at 1. The ground darkens and grass thins by it; the forest builds it at runtime and
|
|
97
|
+
* a tiled ground bakes it into a per-vertex channel (G227 `_CANOPY`). Pure: the same trees give the same map.
|
|
98
|
+
*/
|
|
99
|
+
export function canopyMapOf(
|
|
100
|
+
trees: readonly Pick<ForestTree, 'x' | 'z' | 'height'>[],
|
|
101
|
+
n = 256,
|
|
102
|
+
): Float32Array {
|
|
103
|
+
const data = new Float32Array(n * n)
|
|
104
|
+
const toCell = (v: number): number => ((v + CHUNK_HALF) / CHUNK_SIZE) * n
|
|
105
|
+
for (const t of trees) {
|
|
106
|
+
const r = (t.height * 0.16) / (CHUNK_SIZE / n) // crown radius in cells
|
|
107
|
+
const cx = toCell(t.x),
|
|
108
|
+
cz = toCell(t.z)
|
|
109
|
+
const R = Math.ceil(r + 1)
|
|
110
|
+
for (let j = -R; j <= R; j++)
|
|
111
|
+
for (let i = -R; i <= R; i++) {
|
|
112
|
+
const x = Math.round(cx) + i,
|
|
113
|
+
z = Math.round(cz) + j
|
|
114
|
+
if (x < 0 || z < 0 || x >= n || z >= n) continue
|
|
115
|
+
const d = Math.hypot(x - cx, z - cz) / r
|
|
116
|
+
if (d < 1)
|
|
117
|
+
data[z * n + x] = Math.min(
|
|
118
|
+
1,
|
|
119
|
+
(data[z * n + x] ?? 0) + (1 - d * d) * 0.7,
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return data
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** What placement needs of a variant (TreeFactory's variants carry these; the build's bakes pass them from the specs). */
|
|
127
|
+
export interface PlantSpec {
|
|
128
|
+
trunkRadius: number
|
|
129
|
+
height: number
|
|
130
|
+
species?: TreeSpecies | undefined
|
|
131
|
+
collider?: number | undefined
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Explicit forest construction inputs: the terrain samplers, the seed, the tree cap and the forest (none: no trees).
|
|
135
|
+
* Supplying this never selects a level, installs terrain or changes page constants. */
|
|
136
|
+
export interface ForestPlacementSource {
|
|
137
|
+
readonly heightAt: (x: number, z: number) => number
|
|
138
|
+
readonly normalAt: (
|
|
139
|
+
x: number,
|
|
140
|
+
z: number,
|
|
141
|
+
eps?: number,
|
|
142
|
+
) => readonly [number, number, number]
|
|
143
|
+
readonly trailDistance: (x: number, z: number) => number
|
|
144
|
+
readonly cabinMask: (x: number, z: number) => number
|
|
145
|
+
readonly pondMask: (x: number, z: number) => number
|
|
146
|
+
readonly seed: number
|
|
147
|
+
readonly treeCount: number
|
|
148
|
+
readonly forest?: ForestPlacementSpec
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A 16 m grid cell as one integer (exact for cells within 2^20 of the origin: any coordinate a query meets in play). */
|
|
152
|
+
const cellKey = (cx: number, cz: number): number =>
|
|
153
|
+
(cx + 1048576) * 2097152 + (cz + 1048576)
|
|
154
|
+
|
|
155
|
+
/** Trees bucketed in 16 m cells, for "which trunks are near (x, z)" (collision, planting, herds, bolts); generic over the
|
|
156
|
+
* tree's record, so a renderer-free host buckets its baked trunks exactly as the page's forest does. */
|
|
157
|
+
export class TreeGrid<
|
|
158
|
+
T extends { readonly x: number; readonly z: number; readonly r: number } =
|
|
159
|
+
ForestTree,
|
|
160
|
+
> {
|
|
161
|
+
private cells = new Map<number, T[]>()
|
|
162
|
+
add(t: T): void {
|
|
163
|
+
const k = cellKey(Math.floor(t.x / 16), Math.floor(t.z / 16))
|
|
164
|
+
let bucket = this.cells.get(k)
|
|
165
|
+
if (!bucket) {
|
|
166
|
+
bucket = []
|
|
167
|
+
this.cells.set(k, bucket)
|
|
168
|
+
}
|
|
169
|
+
bucket.push(t)
|
|
170
|
+
}
|
|
171
|
+
/** trees whose trunk might intersect a circle at (x,z) */
|
|
172
|
+
nearby(x: number, z: number, radius = 2): T[] {
|
|
173
|
+
const out: T[] = []
|
|
174
|
+
const cx = Math.floor(x / 16),
|
|
175
|
+
cz = Math.floor(z / 16)
|
|
176
|
+
for (let i = -1; i <= 1; i++)
|
|
177
|
+
for (let j = -1; j <= 1; j++) {
|
|
178
|
+
const list = this.cells.get(cellKey(cx + i, cz + j))
|
|
179
|
+
if (list)
|
|
180
|
+
for (const t of list) {
|
|
181
|
+
const dx = t.x - x,
|
|
182
|
+
dz = t.z - z,
|
|
183
|
+
reach = radius + t.r + 3
|
|
184
|
+
// Reject only outside the circle's box; keep the exact trunk-distance law.
|
|
185
|
+
if (Math.abs(dx) > reach || Math.abs(dz) > reach) continue
|
|
186
|
+
if (Math.hypot(dx, dz) < reach) out.push(t)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return out
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The source's trees for these variants (none for an empty list: a treeless shard). */
|
|
194
|
+
export function placeForest(
|
|
195
|
+
variants: readonly PlantSpec[],
|
|
196
|
+
source: ForestPlacementSource,
|
|
197
|
+
): { trees: ForestTree[]; grid: TreeGrid } {
|
|
198
|
+
const steps = placeForestSteps(variants, source)
|
|
199
|
+
for (;;) {
|
|
200
|
+
const step = steps.next()
|
|
201
|
+
if (step.done === true) return step.value
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** `placeForest` as steps (SF67: `Forest.buildSliced` pauses between them): a yield every 256 candidates, which draws
|
|
206
|
+
* nothing, so the same trees from the same stream */
|
|
207
|
+
export function* placeForestSteps(
|
|
208
|
+
variants: readonly PlantSpec[],
|
|
209
|
+
source: ForestPlacementSource,
|
|
210
|
+
): Generator<void, { trees: ForestTree[]; grid: TreeGrid }> {
|
|
211
|
+
const trees: ForestTree[] = []
|
|
212
|
+
const grid = new TreeGrid()
|
|
213
|
+
if (variants.length === 0) return { trees, grid }
|
|
214
|
+
const F = source.forest
|
|
215
|
+
if (!F) return { trees, grid } // no ShardManifest.forest: no forest to place
|
|
216
|
+
const rng = new Rng(source.seed + 99)
|
|
217
|
+
const density = new Noise2D(source.seed + 5)
|
|
218
|
+
const cell = F.spacing // metres between candidates → ~3400 candidates at 8.5, thinned by density
|
|
219
|
+
const half = CHUNK_HALF - 6
|
|
220
|
+
const candidates: [number, number][] = []
|
|
221
|
+
for (let x = -half; x < half; x += cell)
|
|
222
|
+
for (let z = -half; z < half; z += cell) {
|
|
223
|
+
candidates.push([
|
|
224
|
+
x + rng.range(-cell * 0.45, cell * 0.45),
|
|
225
|
+
z + rng.range(-cell * 0.45, cell * 0.45),
|
|
226
|
+
])
|
|
227
|
+
}
|
|
228
|
+
// shuffle so thinning is unbiased
|
|
229
|
+
for (let i = candidates.length - 1; i > 0; i--) {
|
|
230
|
+
const j = Math.floor(rng.next() * (i + 1))
|
|
231
|
+
const a = candidates[i],
|
|
232
|
+
b = candidates[j]
|
|
233
|
+
if (a && b) {
|
|
234
|
+
candidates[i] = b
|
|
235
|
+
candidates[j] = a
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// PH-B4: a species set picks each tree's species from the chunk's zone mix, then one of that species' variants
|
|
240
|
+
const mix =
|
|
241
|
+
F.species && F.speciesTraits && variants.every(v => v.species !== undefined)
|
|
242
|
+
? F.species
|
|
243
|
+
: null
|
|
244
|
+
const traits: readonly TreeSpeciesTraits[] = F.speciesTraits ?? []
|
|
245
|
+
const traitOf = new Map(traits.map(t => [t.id, t]))
|
|
246
|
+
const bySpecies = new Map<TreeSpecies, number[]>()
|
|
247
|
+
variants.forEach((v, i) => {
|
|
248
|
+
if (v.species)
|
|
249
|
+
bySpecies.set(v.species, [...(bySpecies.get(v.species) ?? []), i])
|
|
250
|
+
})
|
|
251
|
+
const plantSpecies = (
|
|
252
|
+
x: number,
|
|
253
|
+
y: number,
|
|
254
|
+
z: number,
|
|
255
|
+
w: SpeciesWeights,
|
|
256
|
+
): void => {
|
|
257
|
+
let total = 0
|
|
258
|
+
for (const { id: s } of traits)
|
|
259
|
+
total += bySpecies.has(s) ? Math.max(0, w[s] ?? 0) : 0
|
|
260
|
+
if (total <= 0) return
|
|
261
|
+
let r = rng.next() * total,
|
|
262
|
+
species: TreeSpecies = traits[0]?.id ?? ''
|
|
263
|
+
for (const { id: s } of traits) {
|
|
264
|
+
const k = bySpecies.has(s) ? Math.max(0, w[s] ?? 0) : 0
|
|
265
|
+
if (r < k) {
|
|
266
|
+
species = s
|
|
267
|
+
break
|
|
268
|
+
}
|
|
269
|
+
r -= k
|
|
270
|
+
}
|
|
271
|
+
const list = bySpecies.get(species) ?? []
|
|
272
|
+
const variant = list[rng.int(0, list.length - 1)] ?? 0
|
|
273
|
+
const v = variants[variant]
|
|
274
|
+
if (!v) throw new Error(`[forest] no tree variant ${variant}`)
|
|
275
|
+
const trait = traitOf.get(species)
|
|
276
|
+
if (trait === undefined)
|
|
277
|
+
throw new Error(`[forest] no traits for species '${species}'`)
|
|
278
|
+
const scale =
|
|
279
|
+
rng.range(trait.scale[0], trait.scale[1]) *
|
|
280
|
+
(trait.grows && F.scale ? F.scale(x, z) : 1)
|
|
281
|
+
const r0 = v.trunkRadius * scale * (v.collider ?? 1) + trait.girth
|
|
282
|
+
// no trunk inside another's: a giant keeps its neighbours off its buttresses and out from under its limbs
|
|
283
|
+
for (const o of grid.nearby(x, z, r0 + 8)) {
|
|
284
|
+
const other =
|
|
285
|
+
o.species === undefined ? undefined : traitOf.get(o.species)?.spacing
|
|
286
|
+
const gap =
|
|
287
|
+
trait.spacing === 'wide' || other === 'wide'
|
|
288
|
+
? 3.5
|
|
289
|
+
: trait.spacing === 'tight' || other === 'tight'
|
|
290
|
+
? 0.6
|
|
291
|
+
: 1.2
|
|
292
|
+
if (Math.hypot(o.x - x, o.z - z) < o.r + r0 + gap) return
|
|
293
|
+
}
|
|
294
|
+
const h = F.tintHue + rng.range(F.tintHueJitter[0], F.tintHueJitter[1])
|
|
295
|
+
const tint = hslToRgb(
|
|
296
|
+
h + (trait.hue ?? 0),
|
|
297
|
+
rng.range(0.1, 0.3),
|
|
298
|
+
rng.range(0.8, 0.95),
|
|
299
|
+
)
|
|
300
|
+
const t: ForestTree = {
|
|
301
|
+
x,
|
|
302
|
+
y: y - 0.25,
|
|
303
|
+
z,
|
|
304
|
+
r: r0,
|
|
305
|
+
variant,
|
|
306
|
+
scale,
|
|
307
|
+
rot: rng.range(0, Math.PI * 2),
|
|
308
|
+
height: v.height * scale,
|
|
309
|
+
tint,
|
|
310
|
+
species,
|
|
311
|
+
}
|
|
312
|
+
trees.push(t)
|
|
313
|
+
grid.add(t)
|
|
314
|
+
}
|
|
315
|
+
// a zone's infill (ChunkForest.infill; Pine Hollow's Hollow grove, PH-L1 round 2): a second candidate grid half a cell
|
|
316
|
+
// off the first, inside a circle, tested after the chunk's own (so every tree the grid placed stays where it was)
|
|
317
|
+
const infill: [number, number][] = []
|
|
318
|
+
const fill = F.infill
|
|
319
|
+
if (fill) {
|
|
320
|
+
for (let x = fill.x - fill.r + cell / 2; x < fill.x + fill.r; x += cell)
|
|
321
|
+
for (let z = fill.z - fill.r + cell / 2; z < fill.z + fill.r; z += cell) {
|
|
322
|
+
const jx = x + rng.range(-cell * 0.3, cell * 0.3),
|
|
323
|
+
jz = z + rng.range(-cell * 0.3, cell * 0.3)
|
|
324
|
+
if (Math.hypot(jx - fill.x, jz - fill.z) < fill.r) infill.push([jx, jz])
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
let tested = 0
|
|
328
|
+
for (const [x, z] of [...candidates, ...infill]) {
|
|
329
|
+
if ((++tested & 255) === 0) yield
|
|
330
|
+
if (trees.length >= source.treeCount) break
|
|
331
|
+
if (!inChunk(x, z, 4)) continue
|
|
332
|
+
const d = density.fbm(x * F.densityFreq, z * F.densityFreq, 3) // clearings & dense groves
|
|
333
|
+
const keep =
|
|
334
|
+
(smoothstep(F.clearings[0], F.clearings[1], d) * 0.92 + 0.08) *
|
|
335
|
+
(F.density ? F.density(x, z) : 1)
|
|
336
|
+
if (rng.next() > keep) continue
|
|
337
|
+
if (F.mask && rng.next() > F.mask(x, z)) continue // a shard's own planting field (Nalati's spruce gullies)
|
|
338
|
+
const roadEntry =
|
|
339
|
+
(Math.abs(x) < 16 && Math.abs(z) > CHUNK_HALF - 95) ||
|
|
340
|
+
(Math.abs(z) < 16 && Math.abs(x) > CHUNK_HALF - 95)
|
|
341
|
+
if (roadEntry) continue
|
|
342
|
+
if (source.trailDistance(x, z) < 9 + rng.range(0, 4)) continue
|
|
343
|
+
if (source.cabinMask(x, z) > 0.02) continue
|
|
344
|
+
if (source.pondMask(x, z) > 0.03) continue
|
|
345
|
+
const [, ny] = source.normalAt(x, z)
|
|
346
|
+
if (ny < F.maxSlope) continue // too steep
|
|
347
|
+
const y = source.heightAt(x, z)
|
|
348
|
+
if (mix) {
|
|
349
|
+
plantSpecies(x, y, z, mix(x, z))
|
|
350
|
+
continue
|
|
351
|
+
}
|
|
352
|
+
const variant = rng.next() < F.largeVariantChance ? 3 : rng.int(0, 2)
|
|
353
|
+
const scale = rng.range(0.8, 1.2) * (F.scale ? F.scale(x, z) : 1)
|
|
354
|
+
const v = variants[variant]
|
|
355
|
+
if (!v) throw new Error(`[forest] no tree variant ${variant}`)
|
|
356
|
+
const tint = hslToRgb(
|
|
357
|
+
F.tintHue + rng.range(F.tintHueJitter[0], F.tintHueJitter[1]),
|
|
358
|
+
rng.range(F.tintSat[0], F.tintSat[1]),
|
|
359
|
+
rng.range(F.tintLight[0], F.tintLight[1]),
|
|
360
|
+
)
|
|
361
|
+
const t: ForestTree = {
|
|
362
|
+
x,
|
|
363
|
+
y: y - 0.25,
|
|
364
|
+
z,
|
|
365
|
+
r: v.trunkRadius * scale + 0.15,
|
|
366
|
+
variant,
|
|
367
|
+
scale,
|
|
368
|
+
rot: rng.range(0, Math.PI * 2),
|
|
369
|
+
height: v.height * scale,
|
|
370
|
+
tint,
|
|
371
|
+
}
|
|
372
|
+
trees.push(t)
|
|
373
|
+
grid.add(t)
|
|
374
|
+
}
|
|
375
|
+
return { trees, grid }
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** The 16 m lookup grid over given trees (what `placeForest` returns beside them). */
|
|
379
|
+
export function treeGridOf<
|
|
380
|
+
T extends { readonly x: number; readonly z: number; readonly r: number },
|
|
381
|
+
>(trees: readonly T[]): TreeGrid<T> {
|
|
382
|
+
const grid = new TreeGrid<T>()
|
|
383
|
+
for (const t of trees) grid.add(t)
|
|
384
|
+
return grid
|
|
385
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
{
|
|
2
|
+
"about": "SDK-SPLIT SP4e: engine models/nativeGeometry.ts NativeAttributesSchema and game/shardfile/wholeGeometryPieces.ts readWholePartition over geometry-layout.golden-specs.ts",
|
|
3
|
+
"channels": [
|
|
4
|
+
{
|
|
5
|
+
"ok": {
|
|
6
|
+
"position": {
|
|
7
|
+
"semantic": "POSITION",
|
|
8
|
+
"storage": "Float32Array",
|
|
9
|
+
"normalized": false,
|
|
10
|
+
"itemSize": 3
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"ok": {
|
|
16
|
+
"position": {
|
|
17
|
+
"semantic": "POSITION",
|
|
18
|
+
"storage": "Int16Array",
|
|
19
|
+
"normalized": false,
|
|
20
|
+
"itemSize": 3
|
|
21
|
+
},
|
|
22
|
+
"normal": {
|
|
23
|
+
"semantic": "NORMAL",
|
|
24
|
+
"storage": "Int8Array",
|
|
25
|
+
"normalized": true,
|
|
26
|
+
"itemSize": 4
|
|
27
|
+
},
|
|
28
|
+
"aFace": {
|
|
29
|
+
"semantic": "_AFACE",
|
|
30
|
+
"storage": "Float16Array",
|
|
31
|
+
"normalized": false,
|
|
32
|
+
"itemSize": 1
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"ok": {
|
|
38
|
+
"uv": {
|
|
39
|
+
"semantic": "TEXCOORD_0",
|
|
40
|
+
"storage": "Uint16Array",
|
|
41
|
+
"normalized": true,
|
|
42
|
+
"itemSize": 2
|
|
43
|
+
},
|
|
44
|
+
"color": {
|
|
45
|
+
"semantic": "COLOR_0",
|
|
46
|
+
"storage": "Uint8Array",
|
|
47
|
+
"normalized": true,
|
|
48
|
+
"itemSize": 4
|
|
49
|
+
},
|
|
50
|
+
"ids": {
|
|
51
|
+
"semantic": "_ID",
|
|
52
|
+
"storage": "Uint32Array",
|
|
53
|
+
"normalized": false,
|
|
54
|
+
"itemSize": 1
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{ "ok": {} },
|
|
59
|
+
{
|
|
60
|
+
"error": "Invalid type: Expected (\"Float32Array\" | \"Float16Array\" | \"Uint16Array\" | \"Uint32Array\" | \"Int16Array\" | \"Int8Array\" | \"Uint8Array\") but received \"Float64Array\""
|
|
61
|
+
},
|
|
62
|
+
{ "error": "Invalid value: Expected <=4 but received 5" },
|
|
63
|
+
{ "error": "Invalid integer: Received 1.5" },
|
|
64
|
+
{ "error": "Invalid key: Expected never but received \"extra\"" },
|
|
65
|
+
{ "error": "Invalid key: Expected \"normalized\" but received undefined" },
|
|
66
|
+
{
|
|
67
|
+
"ok": {
|
|
68
|
+
"0": {
|
|
69
|
+
"semantic": "POSITION",
|
|
70
|
+
"storage": "Float32Array",
|
|
71
|
+
"normalized": false,
|
|
72
|
+
"itemSize": 3
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{ "error": "Invalid type: Expected Object but received null" }
|
|
77
|
+
],
|
|
78
|
+
"partitions": [
|
|
79
|
+
{
|
|
80
|
+
"id": "roof",
|
|
81
|
+
"vertices": [0, 1, 2, 3],
|
|
82
|
+
"triangles": [0, 1],
|
|
83
|
+
"vertexCount": 12,
|
|
84
|
+
"indexCount": 18,
|
|
85
|
+
"index": "u16",
|
|
86
|
+
"grid": null,
|
|
87
|
+
"vertexLength": 4,
|
|
88
|
+
"triangleLength": 2,
|
|
89
|
+
"denseVertices": false,
|
|
90
|
+
"denseTriangles": false
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "roof",
|
|
94
|
+
"vertices": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
|
95
|
+
"triangles": [0, 1, 2, 3, 4, 5],
|
|
96
|
+
"vertexCount": 12,
|
|
97
|
+
"indexCount": 18,
|
|
98
|
+
"index": "u16",
|
|
99
|
+
"grid": null,
|
|
100
|
+
"vertexLength": 12,
|
|
101
|
+
"triangleLength": 6,
|
|
102
|
+
"denseVertices": true,
|
|
103
|
+
"denseTriangles": true
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "roof",
|
|
107
|
+
"vertices": [2, 3, 4, 9, 10],
|
|
108
|
+
"triangles": [1, 4, 5],
|
|
109
|
+
"vertexCount": 12,
|
|
110
|
+
"indexCount": 18,
|
|
111
|
+
"index": "u32",
|
|
112
|
+
"grid": null,
|
|
113
|
+
"vertexLength": 5,
|
|
114
|
+
"triangleLength": 3,
|
|
115
|
+
"denseVertices": false,
|
|
116
|
+
"denseTriangles": false
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"id": "roof",
|
|
120
|
+
"vertices": [3, 4, 5, 6, 7, 8],
|
|
121
|
+
"triangles": [1, 2],
|
|
122
|
+
"vertexCount": 12,
|
|
123
|
+
"indexCount": 0,
|
|
124
|
+
"index": "none",
|
|
125
|
+
"grid": { "origin": [1.5, -2, 0.25], "step": 0.00390625 },
|
|
126
|
+
"vertexLength": 6,
|
|
127
|
+
"triangleLength": 2,
|
|
128
|
+
"denseVertices": false,
|
|
129
|
+
"denseTriangles": false
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "roof",
|
|
133
|
+
"vertices": [],
|
|
134
|
+
"triangles": [],
|
|
135
|
+
"vertexCount": 12,
|
|
136
|
+
"indexCount": 18,
|
|
137
|
+
"index": "u16",
|
|
138
|
+
"grid": null,
|
|
139
|
+
"vertexLength": 0,
|
|
140
|
+
"triangleLength": 0,
|
|
141
|
+
"denseVertices": false,
|
|
142
|
+
"denseTriangles": false
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"error": "Invalid type: Expected (unknown | Object) but received Object"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"error": "Invalid type: Expected (unknown | Object) but received Object"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"error": "Invalid type: Expected (unknown | Object) but received Object"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"id": "roof",
|
|
155
|
+
"vertices": "16777216 from 0",
|
|
156
|
+
"triangles": [0],
|
|
157
|
+
"vertexCount": 12,
|
|
158
|
+
"indexCount": 18,
|
|
159
|
+
"index": "u16",
|
|
160
|
+
"grid": null,
|
|
161
|
+
"vertexLength": 16777216,
|
|
162
|
+
"triangleLength": 1,
|
|
163
|
+
"denseVertices": true,
|
|
164
|
+
"denseTriangles": false
|
|
165
|
+
},
|
|
166
|
+
{ "error": "Invalid type: Expected (unknown | Object) but received Array" },
|
|
167
|
+
{ "error": "Invalid type: Expected (unknown | Object) but received Array" },
|
|
168
|
+
{ "error": "Invalid value: Expected >=1 but received 0" },
|
|
169
|
+
{
|
|
170
|
+
"error": "Invalid type: Expected (\"none\" | \"u16\" | \"u32\") but received \"u8\""
|
|
171
|
+
},
|
|
172
|
+
{ "error": "Invalid value: Expected <=1 but received 2" },
|
|
173
|
+
{
|
|
174
|
+
"error": "Invalid value: Expected >=0.000244140625 but received 0.0001220703125"
|
|
175
|
+
},
|
|
176
|
+
{ "error": "Invalid key: Expected never but received \"extra\"" },
|
|
177
|
+
{ "error": "Invalid key: Expected \"id\" but received undefined" },
|
|
178
|
+
{ "error": "Invalid type: Expected (unknown | Object) but received Object" }
|
|
179
|
+
]
|
|
180
|
+
}
|