create-threenative 0.2.18 → 0.2.20
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/agent-docs/references/capability-reference.md +212 -4
- package/agent-docs/references/kit-racing.md +4 -2
- package/agent-docs/references/performance-basics.md +2 -1
- package/agent-docs/references/terrain-authoring.md +21 -7
- package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
- package/dist/index.js +255 -236
- package/dist/quality.d.ts +5 -1
- package/dist/quality.js +75 -6
- package/dist/terrain-kit.js +1 -1
- package/dist/threenative.js +6 -4
- package/dist/web-engine-post-effects.js +6 -0
- package/dist/web-engine-runtime.js +211 -36
- package/package.json +6 -6
- package/template-assets/assets/floor-fern-0.glb +0 -0
- package/template-assets/assets/floor-litter-0.glb +0 -0
- package/template-assets/assets/floor-log-0.glb +0 -0
- package/template-assets/assets/floor-log-1.glb +0 -0
- package/template-assets/assets/floor-stump-0.glb +0 -0
- package/template-assets/assets/floor-twig-0.glb +0 -0
- package/template-assets/quality/eslint.config.js +1 -1
- package/templates/action-rpg/package.json +7 -7
- package/templates/action-rpg/src/loot/drops.ts +3 -7
- package/templates/action-rpg/src/render/camera.ts +2 -2
- package/templates/action-rpg/src/render/clouds.ts +3 -1
- package/templates/action-rpg/src/render/materials.ts +3 -2
- package/templates/action-rpg/src/render/touch-controls.ts +7 -6
- package/templates/action-rpg/src/scenes/Play.ts +1 -15
- package/templates/adventure/AGENTS.md +3 -3
- package/templates/adventure/CLAUDE.md +3 -3
- package/templates/adventure/native-playtests/survives.playtest.json +12 -0
- package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
- package/templates/adventure/package.json +7 -7
- package/templates/adventure/playtests/grass.playtest.json +61 -0
- package/templates/adventure/playtests/performance.playtest.json +1 -1
- package/templates/adventure/playtests/survives.playtest.json +2 -2
- package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
- package/templates/adventure/src/entities/LockOn.ts +42 -4
- package/templates/adventure/src/entities/Warden.ts +4 -1
- package/templates/adventure/src/level/Vale.ts +241 -16
- package/templates/adventure/src/render/camera.ts +2 -2
- package/templates/adventure/src/render/foliage.ts +64 -20
- package/templates/adventure/src/render/grass.ts +325 -0
- package/templates/adventure/src/render/materials.ts +3 -2
- package/templates/adventure/src/render/palette.ts +3 -0
- package/templates/adventure/src/render/touch-controls.ts +4 -1
- package/templates/adventure/src/scenes/Play.ts +96 -1
- package/templates/collectathon/package.json +7 -7
- package/templates/collectathon/src/level/Course.ts +2 -7
- package/templates/collectathon/src/level/terrain.ts +2 -1
- package/templates/collectathon/src/render/camera.ts +2 -2
- package/templates/collectathon/src/render/ground.ts +4 -4
- package/templates/collectathon/src/render/hero.ts +1 -1
- package/templates/collectathon/src/render/materials.ts +0 -1
- package/templates/collectathon/src/render/sky.ts +4 -3
- package/templates/kart/package.json +6 -6
- package/templates/kart/src/entities/Kart.ts +2 -1
- package/templates/kart/src/render/course.ts +2 -1
- package/templates/kart/src/track/Course.ts +3 -1
- package/templates/minimal/package.json +6 -6
- package/templates/minimal/src/render/camera.ts +2 -2
- package/templates/minimal/src/render/clouds.ts +3 -1
- package/templates/minimal/src/render/materials.ts +3 -2
- package/templates/minimal/src/render/touch-controls.ts +7 -6
- package/templates/platformer/package.json +7 -7
- package/templates/platformer/playtests/collect.playtest.json +4 -1
- package/templates/platformer/src/level/Stage.ts +2 -6
- package/templates/platformer/src/scenes/Play.ts +2 -1
- package/templates/puzzle/package.json +7 -7
- package/templates/puzzle/src/entities/Warden.ts +3 -3
- package/templates/puzzle/src/render/camera.ts +2 -2
- package/templates/puzzle/src/render/touch-controls.ts +7 -6
- package/templates/racing/AGENTS.md +2 -2
- package/templates/racing/CLAUDE.md +2 -2
- package/templates/racing/CREDITS.md +29 -0
- package/templates/racing/assets/engine-loop.wav +0 -0
- package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
- package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
- package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
- package/templates/racing/assets/nitro-burst.wav +0 -0
- package/templates/racing/assets/tyre-squeal.wav +0 -0
- package/templates/racing/package.json +7 -7
- package/templates/racing/playtests/drift-natural.playtest.json +68 -0
- package/templates/racing/playtests/drift.playtest.json +100 -0
- package/templates/racing/playtests/hud.playtest.json +117 -0
- package/templates/racing/playtests/launch-pose.playtest.json +34 -0
- package/templates/racing/playtests/nitro.playtest.json +158 -0
- package/templates/racing/playtests/outcome.playtest.json +4 -4
- package/templates/racing/playtests/performance.playtest.json +1 -1
- package/templates/racing/playtests/steady-camera.playtest.json +88 -0
- package/templates/racing/src/audio/engine.ts +138 -0
- package/templates/racing/src/entities/CarBody.ts +83 -10
- package/templates/racing/src/entities/Drift.ts +243 -0
- package/templates/racing/src/entities/LineDriver.ts +2 -2
- package/templates/racing/src/entities/Nitro.ts +72 -0
- package/templates/racing/src/entities/RacingCar.ts +86 -21
- package/templates/racing/src/entities/Rival.ts +35 -21
- package/templates/racing/src/game.ts +6 -0
- package/templates/racing/src/gauges.ts +74 -0
- package/templates/racing/src/render/camera.ts +29 -4
- package/templates/racing/src/render/clouds.ts +3 -1
- package/templates/racing/src/render/effects.ts +244 -0
- package/templates/racing/src/render/materials.ts +43 -8
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/skids.ts +84 -0
- package/templates/racing/src/render/touch-controls.ts +10 -10
- package/templates/racing/src/scenes/Race.ts +277 -25
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +3 -0
- package/templates/racing/src/track/Track.ts +132 -58
- package/templates/racing/src/track/TrackSector.ts +19 -1
- package/templates/racing/src/track/circuit.ts +21 -15
- package/templates/racing/src/ui/GameUi.tsx +0 -2
- package/templates/racing/src/ui/Hud.tsx +417 -50
- package/templates/racing/threenative.config.ts +15 -0
- package/templates/racing/tools/make-racing-audio.mjs +388 -0
- package/templates/rain/package.json +6 -6
- package/templates/rain/src/render/noise-volume.ts +2 -1
- package/templates/rain/src/state.ts +3 -1
- package/templates/rain/src/ui/GameUi.tsx +1 -1
- package/templates/rain/src/ui/automation.ts +10 -8
- package/templates/rain/src/ui/tempest.ts +3 -4
- package/templates/rts/package.json +6 -6
- package/templates/rts/src/sim/terrain.ts +1 -0
- package/templates/rts/src/sim/types.ts +1 -0
- package/templates/runner/package.json +7 -7
- package/templates/runner/src/render/clouds.ts +3 -1
- package/templates/runner/src/render/materials.ts +3 -2
- package/templates/runner/src/render/touch-controls.ts +7 -6
- package/templates/runner/src/scenes/Run.ts +4 -9
- package/templates/sailing/package.json +7 -7
- package/templates/sailing/src/render/touch-controls.ts +7 -6
- package/templates/shooter/package.json +7 -7
- package/templates/shooter/src/render/clouds.ts +3 -1
- package/templates/snow/package.json +7 -7
- package/templates/snow/src/entities/Explorer.ts +6 -12
- package/templates/snow/src/render/bootPrint.ts +3 -1
- package/templates/snow/src/render/camera.ts +3 -2
- package/templates/snow/src/render/scenery.ts +3 -3
- package/templates/snow/src/render/touch-controls.ts +7 -6
- package/templates/snow/src/render/weather.ts +3 -5
- package/templates/snow/src/terrain.ts +2 -1
- package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
- package/templates/starter/package.json +7 -7
- package/templates/starter/src/entities/Player.ts +10 -2
- package/templates/starter/src/render/camera.ts +2 -2
- package/templates/starter/src/render/clouds.ts +3 -1
- package/templates/starter/src/render/materials.ts +3 -2
- package/templates/starter/src/render/touch-controls.ts +7 -6
- package/templates/starter/src/scenes/Play.ts +1 -14
- package/templates/tower-defense/package.json +7 -7
- package/templates/tower-defense/src/render/shapes.ts +1 -2
- package/templates/tower-defense/src/scenes/Battle.ts +3 -8
- package/template-assets/terrain/alpine/assets.json +0 -12
- package/template-assets/terrain/alpine/bake.mjs +0 -6
- package/template-assets/terrain/alpine/credits.json +0 -164
- package/template-assets/terrain/alpine/heightmap.r16 +0 -0
- package/template-assets/terrain/alpine/recipe.json +0 -119
- package/template-assets/terrain/alpine/surface.json +0 -53
- package/template-assets/terrain/coastal/assets.json +0 -11
- package/template-assets/terrain/coastal/bake.mjs +0 -6
- package/template-assets/terrain/coastal/credits.json +0 -117
- package/template-assets/terrain/coastal/heightmap.r16 +0 -0
- package/template-assets/terrain/coastal/recipe.json +0 -113
- package/template-assets/terrain/coastal/surface.json +0 -41
- package/template-assets/terrain/desert/assets.json +0 -12
- package/template-assets/terrain/desert/bake.mjs +0 -6
- package/template-assets/terrain/desert/credits.json +0 -164
- package/template-assets/terrain/desert/heightmap.r16 +0 -0
- package/template-assets/terrain/desert/recipe.json +0 -108
- package/template-assets/terrain/desert/surface.json +0 -54
- package/template-assets/terrain/forest/assets.json +0 -65
- package/template-assets/terrain/forest/bake.mjs +0 -8
- package/template-assets/terrain/forest/credits.json +0 -225
- package/template-assets/terrain/forest/heightmap.r16 +0 -0
- package/template-assets/terrain/forest/recipe.json +0 -350
- package/template-assets/terrain/forest/surface.json +0 -79
- package/template-assets/terrain/tundra/assets.json +0 -12
- package/template-assets/terrain/tundra/bake.mjs +0 -6
- package/template-assets/terrain/tundra/credits.json +0 -164
- package/template-assets/terrain/tundra/heightmap.r16 +0 -0
- package/template-assets/terrain/tundra/recipe.json +0 -277
- package/template-assets/terrain/tundra/surface.json +0 -54
- package/templates/racing/src/ui/Menu.tsx +0 -7
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import { ScatterField3D } from "@threenative/core";
|
|
1
2
|
import {
|
|
3
|
+
Box3,
|
|
2
4
|
BoxGeometry,
|
|
5
|
+
type BufferGeometry,
|
|
3
6
|
CylinderGeometry,
|
|
4
7
|
Group,
|
|
8
|
+
type Material,
|
|
9
|
+
MathUtils,
|
|
5
10
|
Mesh,
|
|
6
11
|
type Object3D,
|
|
7
12
|
PlaneGeometry,
|
|
8
13
|
Vector3,
|
|
9
14
|
} from "three";
|
|
10
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
type FloorKind,
|
|
17
|
+
type IValeSite,
|
|
18
|
+
floorPart,
|
|
19
|
+
plantVale,
|
|
20
|
+
valeGround,
|
|
21
|
+
} from "../render/foliage.js";
|
|
11
22
|
import { flat, mottle } from "../render/materials.js";
|
|
12
23
|
import { C } from "../render/palette.js";
|
|
13
24
|
import { createHut, createPitcherLantern, createSign } from "../render/props.js";
|
|
@@ -17,6 +28,7 @@ import { surfaced } from "../render/surface.js";
|
|
|
17
28
|
export function makeRng(seed: number): () => number {
|
|
18
29
|
let state = seed >>> 0;
|
|
19
30
|
return () => {
|
|
31
|
+
// eslint-disable-next-line no-restricted-syntax -- The clearing is authored against this mulberry32 stream; the engine's seeded RNG is an LCG, so swapping it builds a different level.
|
|
20
32
|
state = (state + 0x6d2b79f5) >>> 0;
|
|
21
33
|
let t = state;
|
|
22
34
|
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
@@ -44,6 +56,15 @@ export interface IVale {
|
|
|
44
56
|
readonly hut: { readonly at: Vector3; readonly lanterns: number };
|
|
45
57
|
/** Flagstones laid along the path, and the share of the path's centre line they cover. */
|
|
46
58
|
readonly path: { readonly stones: number; readonly cover: number };
|
|
59
|
+
/** True on open ground: off the path, out of the ruin's lane and clear of the play spaces. */
|
|
60
|
+
readonly clear: (x: number, z: number, width: number) => boolean;
|
|
61
|
+
/** The old trees that frame the clearing, with the trunk radius nothing scatters inside. */
|
|
62
|
+
readonly trees: readonly { readonly radius: number; readonly x: number; readonly z: number }[];
|
|
63
|
+
/**
|
|
64
|
+
* 0..1 leaf litter under the old trees, easing out to the open meadow. The ground paints its soil
|
|
65
|
+
* by it, the grass thins by it and the debris scatters by it, so the three cannot disagree.
|
|
66
|
+
*/
|
|
67
|
+
readonly floorZone: (x: number, z: number) => number;
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
// ------------------------------------------------------------------------------------ the ground
|
|
@@ -52,7 +73,7 @@ export interface IVale {
|
|
|
52
73
|
|
|
53
74
|
const smooth = (a: number, b: number, t: number): number => {
|
|
54
75
|
const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
|
|
55
|
-
return u
|
|
76
|
+
return MathUtils.smoothstep(u, 0, 1);
|
|
56
77
|
};
|
|
57
78
|
/** 0..1 rolling noise from two crossed sine sheets. */
|
|
58
79
|
const wave = (x: number, z: number, f: number): number =>
|
|
@@ -103,16 +124,24 @@ export const STREAM = {
|
|
|
103
124
|
water: -0.3,
|
|
104
125
|
};
|
|
105
126
|
|
|
106
|
-
|
|
127
|
+
/** Plain length: `Math.hypot` costs several times more, and the grass asks once per blade. */
|
|
128
|
+
const hyp = (dx: number, dz: number): number => Math.sqrt(dx * dx + dz * dz);
|
|
129
|
+
|
|
130
|
+
/** Squared distance to a segment; the caller takes one square root for the nearest. */
|
|
131
|
+
const distanceSqToSegment = (
|
|
107
132
|
x: number,
|
|
108
133
|
z: number,
|
|
109
|
-
|
|
110
|
-
|
|
134
|
+
a: readonly [number, number],
|
|
135
|
+
b: readonly [number, number],
|
|
111
136
|
): number => {
|
|
112
|
-
const
|
|
113
|
-
const
|
|
137
|
+
const ax = a[0];
|
|
138
|
+
const az = a[1];
|
|
139
|
+
const dx = b[0] - ax;
|
|
140
|
+
const dz = b[1] - az;
|
|
114
141
|
const t = Math.min(1, Math.max(0, ((x - ax) * dx + (z - az) * dz) / (dx * dx + dz * dz)));
|
|
115
|
-
|
|
142
|
+
const ex = x - ax - t * dx;
|
|
143
|
+
const ez = z - az - t * dz;
|
|
144
|
+
return ex * ex + ez * ez;
|
|
116
145
|
};
|
|
117
146
|
|
|
118
147
|
/** Metres from the stream's centre line. */
|
|
@@ -121,18 +150,35 @@ export function streamDistance(x: number, z: number): number {
|
|
|
121
150
|
for (let i = 1; i < STREAM.points.length; i += 1) {
|
|
122
151
|
const a = STREAM.points[i - 1];
|
|
123
152
|
const b = STREAM.points[i];
|
|
124
|
-
if (a !== undefined && b !== undefined) best = Math.min(best,
|
|
153
|
+
if (a !== undefined && b !== undefined) best = Math.min(best, distanceSqToSegment(x, z, a, b));
|
|
125
154
|
}
|
|
126
|
-
return best;
|
|
155
|
+
return Math.sqrt(best);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Where the streamed grass grows, 0..1: bare on the path, in the stream, under the hut and in the cave mouth. */
|
|
159
|
+
export function grassCover(x: number, z: number): number {
|
|
160
|
+
if (z < CLEARING.north + 1 && Math.abs(x) < 3.5) return 0;
|
|
161
|
+
return (
|
|
162
|
+
smooth(1.5, 2.3, Math.abs(x - pathX(z))) *
|
|
163
|
+
smooth(1.3, 2.4, streamDistance(x, z)) *
|
|
164
|
+
smooth(2.4, 3.4, hyp(x - HUT.x, z - HUT.z))
|
|
165
|
+
);
|
|
127
166
|
}
|
|
128
167
|
|
|
168
|
+
/** The square the grass grows in: the clearing and the first hills round it. */
|
|
169
|
+
export const GRASS_BOUNDS = {
|
|
170
|
+
maxX: CLEARING.half + 10,
|
|
171
|
+
maxZ: CLEARING.south + 10,
|
|
172
|
+
minX: -CLEARING.half - 10,
|
|
173
|
+
minZ: CLEARING.north - 6,
|
|
174
|
+
};
|
|
175
|
+
|
|
129
176
|
/** 1 on a play space, the path or the cave approach, easing to 0 over a few metres round them. */
|
|
130
177
|
function flatness(x: number, z: number): number {
|
|
131
178
|
let f = 1 - smooth(2.2, 4.4, Math.abs(x - pathX(z)));
|
|
132
179
|
if (z < -15) f = Math.max(f, 1 - smooth(3.5, 5.5, Math.abs(x)));
|
|
133
|
-
f = Math.max(f, 1 - smooth(HUT.radius, HUT.radius + 1.6,
|
|
134
|
-
for (const [px, pz, r] of PADS)
|
|
135
|
-
f = Math.max(f, 1 - smooth(r, r + 3.2, Math.hypot(x - px, z - pz)));
|
|
180
|
+
f = Math.max(f, 1 - smooth(HUT.radius, HUT.radius + 1.6, hyp(x - HUT.x, z - HUT.z)));
|
|
181
|
+
for (const [px, pz, r] of PADS) f = Math.max(f, 1 - smooth(r, r + 3.2, hyp(x - px, z - pz)));
|
|
136
182
|
return f;
|
|
137
183
|
}
|
|
138
184
|
|
|
@@ -140,15 +186,14 @@ function flatness(x: number, z: number): number {
|
|
|
140
186
|
export function valeHeight(x: number, z: number): number {
|
|
141
187
|
// The rise to the cave mouth: the clearing's north end climbs 1.2 m to the cliff.
|
|
142
188
|
const rise = 1.2 * smooth(-11, -17, z);
|
|
143
|
-
const ledge =
|
|
144
|
-
HUT.lift * (1 - smooth(HUT.radius, HUT.radius + 1.6, Math.hypot(x - HUT.x, z - HUT.z)));
|
|
189
|
+
const ledge = HUT.lift * (1 - smooth(HUT.radius, HUT.radius + 1.6, hyp(x - HUT.x, z - HUT.z)));
|
|
145
190
|
// Inside the walls: rolling banks, higher toward the walls, and the outcrops.
|
|
146
191
|
const edge = Math.min(CLEARING.half - Math.abs(x), z - CLEARING.north, CLEARING.south - z);
|
|
147
192
|
const tunnel = Math.abs(x) < 3.5 && z < CLEARING.north + 1;
|
|
148
193
|
let relief = 0.35 + 1.3 * wave(x, z, 0.23) + 0.45 * wave(x + 7, z - 3, 0.61);
|
|
149
194
|
if (edge > 0) relief += 1.4 * (1 - smooth(0, 4.5, edge));
|
|
150
195
|
for (const [ox, oz, r, h] of OUTCROPS)
|
|
151
|
-
relief += h * (1 - smooth(r * 0.5, r,
|
|
196
|
+
relief += h * (1 - smooth(r * 0.5, r, hyp(x - ox, z - oz)));
|
|
152
197
|
// Outside them: a steep rocky bank, then wooded hills.
|
|
153
198
|
if (edge < 0 && !tunnel)
|
|
154
199
|
relief += 2.2 * smooth(0, 3, -edge) + (0.8 + 3.4 * wave(x, z, 0.09)) * smooth(2, 14, -edge);
|
|
@@ -357,8 +402,19 @@ export function buildVale(rng: () => number): IVale {
|
|
|
357
402
|
ground.inner.userData.solid = true;
|
|
358
403
|
group.add(planting.group, ground.inner, ground.outer);
|
|
359
404
|
|
|
405
|
+
const oldTrees = trees.map(([x, z, s]) => ({ radius: 0.6 * s, x, z }));
|
|
360
406
|
return {
|
|
361
407
|
caveExit: at(0, -17),
|
|
408
|
+
clear: site.clear,
|
|
409
|
+
floorZone: (x, z) => {
|
|
410
|
+
let zone = 0;
|
|
411
|
+
for (const tree of oldTrees) {
|
|
412
|
+
const d = Math.hypot(x - tree.x, z - tree.z);
|
|
413
|
+
zone = Math.max(zone, 1 - smooth(tree.radius * 2.4, tree.radius * 8, d));
|
|
414
|
+
}
|
|
415
|
+
return zone;
|
|
416
|
+
},
|
|
417
|
+
trees: oldTrees,
|
|
362
418
|
caveMouth: at(0, -23),
|
|
363
419
|
dummies: [at(-1.6, 4), at(1.8, 4.5)],
|
|
364
420
|
group,
|
|
@@ -381,3 +437,172 @@ export function buildVale(rng: () => number): IVale {
|
|
|
381
437
|
export function isSolid(object: Object3D): boolean {
|
|
382
438
|
return object.userData.solid === true;
|
|
383
439
|
}
|
|
440
|
+
|
|
441
|
+
// ------------------------------------------------------------------------- the woodland floor
|
|
442
|
+
// Baked props, streamed round Wren. The generators live in @threenative/procedural-vegetation and
|
|
443
|
+
// the bytes in ../template-assets/assets (regenerate with `pnpm tsx scripts/bake-floor-assets.ts`);
|
|
444
|
+
// the material is the kit's own, in render/foliage.ts.
|
|
445
|
+
|
|
446
|
+
/** What this needs of the loader: `ctx.assets` satisfies it. */
|
|
447
|
+
export interface IFloorLoader {
|
|
448
|
+
model(path: string): Promise<{ readonly scene: Object3D }>;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** One baked prop, its levels of detail near to far, and how many a square metre holds. */
|
|
452
|
+
interface IFloorProp {
|
|
453
|
+
readonly density: number;
|
|
454
|
+
readonly drawDistance: number;
|
|
455
|
+
readonly files: readonly string[];
|
|
456
|
+
readonly kind: FloorKind;
|
|
457
|
+
readonly scale: readonly [number, number];
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const FLOOR_PROPS: Readonly<Record<string, IFloorProp>> = {
|
|
461
|
+
// The kit's grass stands knee-high, so a prop that should read is sized to clear it.
|
|
462
|
+
fern: {
|
|
463
|
+
density: 0.5,
|
|
464
|
+
drawDistance: 24,
|
|
465
|
+
files: ["floor-fern-0.glb"],
|
|
466
|
+
kind: "frond",
|
|
467
|
+
scale: [1.5, 2.2],
|
|
468
|
+
},
|
|
469
|
+
litter: {
|
|
470
|
+
density: 1.6,
|
|
471
|
+
drawDistance: 18,
|
|
472
|
+
files: ["floor-litter-0.glb"],
|
|
473
|
+
kind: "litter",
|
|
474
|
+
scale: [2.2, 3.2],
|
|
475
|
+
},
|
|
476
|
+
log: {
|
|
477
|
+
density: 0.08,
|
|
478
|
+
drawDistance: 30,
|
|
479
|
+
files: ["floor-log-0.glb", "floor-log-1.glb"],
|
|
480
|
+
kind: "wood",
|
|
481
|
+
scale: [1.6, 2.2],
|
|
482
|
+
},
|
|
483
|
+
stump: {
|
|
484
|
+
density: 0.07,
|
|
485
|
+
drawDistance: 30,
|
|
486
|
+
files: ["floor-stump-0.glb"],
|
|
487
|
+
kind: "wood",
|
|
488
|
+
scale: [1.5, 2.1],
|
|
489
|
+
},
|
|
490
|
+
twig: {
|
|
491
|
+
density: 0.35,
|
|
492
|
+
drawDistance: 20,
|
|
493
|
+
files: ["floor-twig-0.glb"],
|
|
494
|
+
kind: "wood",
|
|
495
|
+
scale: [2.2, 3.2],
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
export interface IWoodlandFloor {
|
|
500
|
+
readonly group: Group;
|
|
501
|
+
/** One streamed field per prop; the playtest reads their totals. */
|
|
502
|
+
readonly fields: readonly ScatterField3D[];
|
|
503
|
+
/** Builds every tile on the next update regardless of budget: on load, behind the curtain. */
|
|
504
|
+
prewarm(): void;
|
|
505
|
+
update(follow: Vector3): void;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** 0..1 from a point and a salt: a placement is the same whatever order the tiles build in. */
|
|
509
|
+
const jitter = (x: number, z: number, salt: number): number => {
|
|
510
|
+
const h = Math.sin(x * 127.1 + z * 311.7 + salt * 74.7) * 43758.5453;
|
|
511
|
+
return h - Math.floor(h);
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
/** A loaded GLB's primitives in the kit's look: one part per glTF material. */
|
|
515
|
+
function chainsOf(
|
|
516
|
+
model: { readonly scene: Object3D },
|
|
517
|
+
kind: FloorKind,
|
|
518
|
+
): {
|
|
519
|
+
geometries: BufferGeometry[];
|
|
520
|
+
material: Material;
|
|
521
|
+
}[] {
|
|
522
|
+
const chains: { geometries: BufferGeometry[]; material: Material }[] = [];
|
|
523
|
+
model.scene.traverse((object) => {
|
|
524
|
+
const mesh = object as Mesh;
|
|
525
|
+
if (mesh.isMesh !== true) return;
|
|
526
|
+
const part = floorPart(mesh, kind);
|
|
527
|
+
chains.push({ geometries: [part.geometry], material: part.material });
|
|
528
|
+
});
|
|
529
|
+
return chains;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* The forest floor: logs, stumps, twigs and leaf litter under the old trees, with ferns among them.
|
|
534
|
+
* Every prop is a baked GLB streamed by `ScatterField3D`, placed off the path, out of the play spaces
|
|
535
|
+
* and clear of the trunks, so nothing floats over the ruin's lane or grows out of a tree.
|
|
536
|
+
*/
|
|
537
|
+
export async function buildWoodlandFloor(
|
|
538
|
+
assets: IFloorLoader,
|
|
539
|
+
vale: IVale,
|
|
540
|
+
seed = 1986,
|
|
541
|
+
): Promise<IWoodlandFloor> {
|
|
542
|
+
const group = new Group();
|
|
543
|
+
group.name = "woodland floor";
|
|
544
|
+
const fields: ScatterField3D[] = [];
|
|
545
|
+
let salt = 1;
|
|
546
|
+
for (const [name, prop] of Object.entries(FLOOR_PROPS)) {
|
|
547
|
+
const models = await Promise.all(prop.files.map((file) => assets.model(file)));
|
|
548
|
+
const near = models[0] as { scene: Object3D };
|
|
549
|
+
// Each baked level replaces its part's geometry; the kit's material and the instances stay.
|
|
550
|
+
const chains = chainsOf(near, prop.kind);
|
|
551
|
+
for (const model of models.slice(1)) {
|
|
552
|
+
chainsOf(model, prop.kind).forEach((deeper, index) => {
|
|
553
|
+
const chain = chains[index];
|
|
554
|
+
if (chain !== undefined) chain.geometries.push(...deeper.geometries);
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
const propSalt = salt;
|
|
558
|
+
salt += 1;
|
|
559
|
+
// The bake leaves each prop where its own generator put it — a fern's fronds start 0.19 m under
|
|
560
|
+
// its origin, a stump's base 0.06 m over — so the prop is lifted by its own lowest point once
|
|
561
|
+
// the instance scale is known, and nothing floats or sinks.
|
|
562
|
+
const sunk = new Box3().setFromObject(near.scene).min.y;
|
|
563
|
+
const lift = Number.isFinite(sunk) ? -sunk : 0;
|
|
564
|
+
const field = new ScatterField3D({
|
|
565
|
+
// A tile draws once per part, so the floor takes tiles four times the default area: five
|
|
566
|
+
// fields at 16 m tiles add enough lone draws to tip the scene's projection to declining.
|
|
567
|
+
chunkSize: 32,
|
|
568
|
+
density: prop.density,
|
|
569
|
+
drawDistance: prop.drawDistance,
|
|
570
|
+
// The same zone the ground paints and the grass thins by: debris gathers at the foot of the
|
|
571
|
+
// old trees instead of sprinkling evenly over ground that is all grass.
|
|
572
|
+
getDensity: (x, z) => vale.floorZone(x, z),
|
|
573
|
+
getHeight: valeHeight,
|
|
574
|
+
parts: chains.map(({ geometries, material }) => ({ lods: geometries, material })),
|
|
575
|
+
place: (point, out) => {
|
|
576
|
+
if (!vale.clear(point.x, point.z, 0.9)) return false;
|
|
577
|
+
// Deadwood and litter gather at the foot of the old trees, so only the trunk itself is out of
|
|
578
|
+
// bounds: a prop half a metre from a trunk is the look, one inside it is a clipped mesh.
|
|
579
|
+
for (const tree of vale.trees)
|
|
580
|
+
if (Math.hypot(point.x - tree.x, point.z - tree.z) < tree.radius) return false;
|
|
581
|
+
out.x = point.x;
|
|
582
|
+
out.z = point.z;
|
|
583
|
+
out.yaw = jitter(point.x, point.z, propSalt) * Math.PI * 2;
|
|
584
|
+
out.scale =
|
|
585
|
+
prop.scale[0] + jitter(point.x, point.z, propSalt + 7) * (prop.scale[1] - prop.scale[0]);
|
|
586
|
+
out.y = point.y + lift * out.scale + 0.002;
|
|
587
|
+
return true;
|
|
588
|
+
},
|
|
589
|
+
farDensity: 0.45,
|
|
590
|
+
seed: seed + propSalt,
|
|
591
|
+
thinEnd: 24,
|
|
592
|
+
thinStart: 8,
|
|
593
|
+
});
|
|
594
|
+
field.name = `floor ${name}`;
|
|
595
|
+
fields.push(field);
|
|
596
|
+
group.add(field);
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
fields,
|
|
600
|
+
group,
|
|
601
|
+
prewarm: () => {
|
|
602
|
+
for (const field of fields) field.prewarm();
|
|
603
|
+
},
|
|
604
|
+
update: (follow) => {
|
|
605
|
+
for (const field of fields) field.update(follow);
|
|
606
|
+
},
|
|
607
|
+
};
|
|
608
|
+
}
|
|
@@ -335,8 +335,8 @@ export function setupCamera(
|
|
|
335
335
|
return yaw;
|
|
336
336
|
},
|
|
337
337
|
update(focus: Vector3, lock: ILockFrame | undefined, dt: number, watch?: Box3): void {
|
|
338
|
-
const rate = 1
|
|
339
|
-
const quick = 1
|
|
338
|
+
const rate = MathUtils.damp(0, 1, YAW_RATE, dt);
|
|
339
|
+
const quick = MathUtils.damp(0, 1, FRAME_RATE, dt);
|
|
340
340
|
if (lock !== undefined) {
|
|
341
341
|
lock.bounds.getCenter(middle);
|
|
342
342
|
const line = Math.atan2(focus.x - middle.x, focus.z - middle.z);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// The vale's planting and its floor, an old misty forest built in code. Giant gnarled trees (a
|
|
4
4
|
// twisted trunk with ridged bark, thick roots and limbs, moss on every upward face) under broad
|
|
5
5
|
// crowns of leaf clumps that sway; far trees in a lighter cut; big lobed broadleaf plants, ferns,
|
|
6
|
-
// purple and pink flowers
|
|
6
|
+
// purple and pink flowers; mossy boulders; an irregular flagstone path; a stream;
|
|
7
7
|
// mushrooms and logs; ivy and vines on the cliff. Every kind is one `InstancedMesh`, so a forest
|
|
8
8
|
// costs a few dozen draws and no light of its own. Nothing here is solid: `level/Vale.ts` decides
|
|
9
9
|
// what blocks, and its height function is the floor everything here stands on.
|
|
@@ -20,11 +20,14 @@ import {
|
|
|
20
20
|
ConeGeometry,
|
|
21
21
|
CylinderGeometry,
|
|
22
22
|
DoubleSide,
|
|
23
|
+
FrontSide,
|
|
23
24
|
Group,
|
|
24
25
|
IcosahedronGeometry,
|
|
25
26
|
InstancedMesh,
|
|
26
27
|
type Material,
|
|
28
|
+
MathUtils,
|
|
27
29
|
Mesh,
|
|
30
|
+
MeshStandardMaterial,
|
|
28
31
|
Object3D,
|
|
29
32
|
OctahedronGeometry,
|
|
30
33
|
SphereGeometry,
|
|
@@ -333,10 +336,19 @@ function limb(
|
|
|
333
336
|
return tube;
|
|
334
337
|
}
|
|
335
338
|
|
|
336
|
-
/**
|
|
337
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Colours bark by its normal: moss on every face that looks up, bark below, darker at the foot.
|
|
341
|
+
* `keepNormals` trusts the normals the geometry already carries instead of recomputing them, for a
|
|
342
|
+
* baked mesh: a recomputed normal on a two-centimetre triangle collapses to NaN, and the NaN lands
|
|
343
|
+
* in the vertex colours this function writes, where bloom carries it across the whole frame.
|
|
344
|
+
*/
|
|
345
|
+
export function mossBark(
|
|
346
|
+
geometry: BufferGeometry,
|
|
347
|
+
moss: number,
|
|
348
|
+
keepNormals = false,
|
|
349
|
+
): BufferGeometry {
|
|
338
350
|
const g = geometry.index === null ? geometry : geometry.toNonIndexed();
|
|
339
|
-
g.computeVertexNormals();
|
|
351
|
+
if (!keepNormals || g.attributes.normal === undefined) g.computeVertexNormals();
|
|
340
352
|
const normal = g.attributes.normal;
|
|
341
353
|
const position = g.attributes.position;
|
|
342
354
|
if (normal === undefined || position === undefined) return g;
|
|
@@ -641,19 +653,8 @@ export function plantVale(site: IValeSite): {
|
|
|
641
653
|
group.add(instanced(cluster(head), swaying(0.25), placements, false));
|
|
642
654
|
}
|
|
643
655
|
|
|
644
|
-
//
|
|
645
|
-
|
|
646
|
-
for (let i = 0; i < 340; i += 1) {
|
|
647
|
-
// Half of them fringe the path, where the cobbles meet the moss.
|
|
648
|
-
const z = clearing.north + rng() * (clearing.south - clearing.north);
|
|
649
|
-
const x =
|
|
650
|
-
i % 2 === 0
|
|
651
|
-
? site.pathX(z) + (rng() < 0.5 ? -1 : 1) * (1.75 + rng() * 1.4)
|
|
652
|
-
: (rng() * 2 - 1) * clearing.half;
|
|
653
|
-
if (Math.abs(x - site.pathX(z)) < 1.7 || site.stream.distance(x, z) < 1.4) continue;
|
|
654
|
-
tufts.push(P(x, 0, z, 0.7 + rng() * 0.9, 0.6 + rng() * 0.9));
|
|
655
|
-
}
|
|
656
|
-
group.add(instanced(fan(4, 0.04, 0.42, 0.4, C.grassTip), swaying(0.6), tufts, false));
|
|
656
|
+
// The grass itself is streamed: `render/grass.ts` is its look, `GrassField3D` in `scenes/Play.ts`
|
|
657
|
+
// grows it.
|
|
657
658
|
|
|
658
659
|
// Mushrooms in rings under the giants, fallen logs, and mossy boulders.
|
|
659
660
|
const mushrooms: Placement[] = [];
|
|
@@ -1006,7 +1007,7 @@ export function valeGround(
|
|
|
1006
1007
|
0.5 + 0.25 * (Math.sin(x * f + z * f * 0.55) + Math.sin(z * f * 1.4 - x * f * 0.37 + 1.3));
|
|
1007
1008
|
const smooth = (a: number, b: number, t: number): number => {
|
|
1008
1009
|
const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
|
|
1009
|
-
return u
|
|
1010
|
+
return MathUtils.smoothstep(u, 0, 1);
|
|
1010
1011
|
};
|
|
1011
1012
|
const paintGround = (geometry: BufferGeometry): void => {
|
|
1012
1013
|
const position = geometry.attributes.position;
|
|
@@ -1021,12 +1022,15 @@ export function valeGround(
|
|
|
1021
1022
|
c.copy(soil).lerp(moss, 0.35 + 0.55 * smooth(0.35, 0.75, wave(x + 40, z - 17, 0.27)));
|
|
1022
1023
|
c.lerp(mossBright, smooth(0.6, 0.85, wave(x - 3, z + 5, 0.45)) * 0.5);
|
|
1023
1024
|
c.lerp(meadow, smooth(0.66, 0.82, wave(x * 0.7, z * 0.7 + 9, 0.21)) * 0.3);
|
|
1025
|
+
// Leaf litter and bare soil under the old trees. The same zone thins the grass and gathers the
|
|
1026
|
+
// scattered debris, so the ground the props stand on is the ground they are meant for.
|
|
1024
1027
|
let nearTree = 0;
|
|
1025
1028
|
for (const [tx, tz, ts] of site.trees) {
|
|
1026
1029
|
const d = Math.hypot(x - tx, z - tz);
|
|
1027
|
-
|
|
1030
|
+
nearTree = Math.max(nearTree, 1 - smooth(1.2 * ts, 4.2 * ts, d));
|
|
1028
1031
|
}
|
|
1029
|
-
c.lerp(litter, nearTree *
|
|
1032
|
+
c.lerp(litter, nearTree * (0.62 + 0.34 * wave(x, z, 0.9)));
|
|
1033
|
+
c.lerp(soil, nearTree * 0.3);
|
|
1030
1034
|
// Dark soil under the path, the flagstones on top of it.
|
|
1031
1035
|
const off = Math.abs(x - site.pathX(z)) + (wave(x, z, 1.3) - 0.5) * 0.5;
|
|
1032
1036
|
if (z > site.clearing.north - 9 && z < site.clearing.south + 1)
|
|
@@ -1070,3 +1074,43 @@ export function valeGround(
|
|
|
1070
1074
|
meshes.inner.name = "vale-floor";
|
|
1071
1075
|
return meshes;
|
|
1072
1076
|
}
|
|
1077
|
+
|
|
1078
|
+
/** What a baked forest-floor part is, so it takes the matching look of the kit. */
|
|
1079
|
+
export type FloorKind = "frond" | "litter" | "wood";
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* The forest floor in the kit's own look, tuned here and nowhere else. Wood (logs, stumps, twigs)
|
|
1083
|
+
* takes the old trees' mossy ridged bark, so a fallen log reads as one of them. Litter keeps the
|
|
1084
|
+
* bake's COLOR_0 times its base colour. A frond keeps Arbor's leaf atlas, cut out rather than
|
|
1085
|
+
* blended, exactly as the tree crowns are.
|
|
1086
|
+
*/
|
|
1087
|
+
export function floorPart(
|
|
1088
|
+
mesh: Mesh,
|
|
1089
|
+
kind: FloorKind,
|
|
1090
|
+
): { geometry: BufferGeometry; material: Material } {
|
|
1091
|
+
if (kind === "wood") {
|
|
1092
|
+
// The bake's own normals, never recomputed: see `mossBark`'s `keepNormals`.
|
|
1093
|
+
const baked = mesh.geometry.index === null ? mesh.geometry : mesh.geometry.toNonIndexed();
|
|
1094
|
+
return {
|
|
1095
|
+
// A little moss on the shoulders, never enough to paint a log the colour of the ground it
|
|
1096
|
+
// lies on: the debris has to read as deadwood, not as another patch of grass.
|
|
1097
|
+
geometry: mossBark(baked, 0.18, true),
|
|
1098
|
+
material: surfaced(0xffffff, "bark", { vertexColors: true }),
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
const baked = mesh.material as MeshStandardMaterial;
|
|
1102
|
+
const frond = kind === "frond";
|
|
1103
|
+
return {
|
|
1104
|
+
geometry: mesh.geometry,
|
|
1105
|
+
material: new MeshStandardMaterial({
|
|
1106
|
+
// COLOR_0 is the bake's variation; the base colour is its tone, so both multiply.
|
|
1107
|
+
color: frond ? 0xffffff : baked.color,
|
|
1108
|
+
map: frond ? baked.map : null,
|
|
1109
|
+
metalness: 0,
|
|
1110
|
+
roughness: 0.9,
|
|
1111
|
+
side: frond ? DoubleSide : FrontSide,
|
|
1112
|
+
vertexColors: true,
|
|
1113
|
+
...(frond ? { alphaTest: 0.45 } : {}),
|
|
1114
|
+
}),
|
|
1115
|
+
};
|
|
1116
|
+
}
|