@wildshard/sdk 0.3.0 → 0.3.1
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/GUIDE.md +10 -2
- package/docs/api/EXPORT-TIERS.md +7 -4
- package/lint/export-tiers.json +3 -0
- package/lint/host-callbacks.mjs +1 -1
- package/package.json +9 -5
- package/scripts/bake/template-skins.mjs +6 -3
- package/scripts/bake/template-warden.mjs +25 -0
- package/scripts/export-ci21-guests.mjs +89 -0
- package/scripts/scratch-sweep.mjs +3 -1
- package/src/sharddev/as/prelude.ts +67 -0
- package/src/sharddev/authorLint.ts +45 -0
- package/src/sharddev/bake/compileScript.ts +6 -0
- package/src/sharddev/bake/terrain.ts +11 -2
- package/src/sharddev/checkProject.ts +7 -18
- package/src/sharddev/engineMusic.ts +23 -0
- package/src/sharddev/materials.ts +7 -3
- package/src/sharddev/project.ts +5 -0
- package/src/sharddev/refusals.ts +1 -1
- package/src/sharddev/scene/author.ts +116 -11
- package/src/sharddev/scene/canvas.ts +2 -3
- package/src/sharddev/scene/description.ts +55 -2
- package/src/sharddev/scene/lower.ts +144 -29
- package/src/sharddev/scene/shard.ts +5 -2
- package/src/sharddev/scene/shardfile.ts +365 -72
- package/src/sharddev/watch/page.ts +116 -29
- package/src/sharddev/watch/pageEntry.ts +38 -2
- package/src/sharddev/watch/parity-baseline.json +22 -0
- package/src/sharddev/watch/parity.mjs +168 -0
- package/src/sharddev/watch/proof.mjs +129 -22
- package/src/sharddev/watch/protocol.ts +66 -8
- package/src/sharddev/watch/watch.ts +215 -51
- package/src/shards/_template/assets/3058c100bc477fd6fe8268f33b53756b8a2556e7e41c58b2216c703ca7b042c6 +1 -0
- package/src/shards/_template/assets/8a0440f392737a31cf0926a3c7dc011c320144972882945a5462c893e817d94a +0 -0
- package/src/shards/_template/behaviour/door.as +16 -26
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/clientScripts.json +43 -43
- package/src/shards/_template/data/creatures.json +2 -2
- package/src/shards/_template/data/look.json +141 -13
- package/src/shards/_template/data/rows.json +20 -2
- package/src/shards/_template/data/skins.json +32 -0
- package/src/shards/_template/data/water.json +18 -0
- package/src/shards/_template/generators/product.ts +5 -1
- package/src/shards/_template/generators/warden.ts +273 -0
- package/src/shards/_template/generators/world.ts +52 -21
- package/src/shards/_template/hero.json +6 -6
- package/src/shards/authoring-slice/generators/shard.ts +9 -1
- package/src/shards/authoring-slice/generators/sky.ts +64 -0
- package/src/shards/authoring-slice/generators/template-sky.ts +27 -0
- package/src/shards/authoring-slice/generators/textures.ts +59 -0
- package/src/shards/authoring-slice/generators/world.ts +108 -5
- package/src/shards/mossgate/generators/shard.ts +6 -0
- package/src/shards/mossgate/generators/sky.ts +64 -0
- package/src/shards/mossgate/generators/textures.ts +249 -0
- package/src/shards/mossgate/generators/world.ts +998 -0
- package/src/shards/mossgate/shard.config.ts +7 -0
- package/scripts/shard-output-report.d.mts +0 -9
- package/scripts/shard-output-report.mjs +0 -85
- package/scripts/shard-platform-cli.mjs +0 -93
|
@@ -0,0 +1,998 @@
|
|
|
1
|
+
// Mossgate Hollow, whole, as three.js source (SHARD-SOURCE AP15): the cleanroom's src/world.js and the light of its
|
|
2
|
+
// src/main.js (mossgate-cleanroom 9cb4dc6), ported section by section. The geometry, materials and lights are the
|
|
3
|
+
// cleanroom's own lines. What changed, as in the authoring slice (AP7): each section is a `world.part` with its own seeded
|
|
4
|
+
// stream (editing the hut never reshuffles the trees), each `colliders.push` box is an invisible `solid` box at the same
|
|
5
|
+
// numbers, the pond's Reflector is a `Water`, the canvas painters run at compile time, `update(t)` is said once with
|
|
6
|
+
// `animate`, the instanced glow billboard (an `onBeforeCompile` patch) is one additive Sprite per halo, and the phone
|
|
7
|
+
// LODs and static merge are the engine's (AP8). The quest state is fixed: brazier A lit, the gate shut, the bridge sunk,
|
|
8
|
+
// the Warden idle; making it live is stage 6 (AP23 to AP27).
|
|
9
|
+
import * as THREE from 'three';
|
|
10
|
+
import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry.js';
|
|
11
|
+
import { mergeGeometries, mergeVertices } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
12
|
+
import { animate, drift, flicker, pulse, rise, solid, sway, Water, type ShardWorld } from '@wildshard/sdk/scene/author';
|
|
13
|
+
import * as T from './textures';
|
|
14
|
+
import { sunsetSky } from './sky';
|
|
15
|
+
|
|
16
|
+
export const LAYOUT = {
|
|
17
|
+
SPAWN: { x: 0.3, z: 1.8, yaw: 0.04 },
|
|
18
|
+
HUT: { x: -4.0, z: -14.0, w: 5.2, d: 4.6, h: 2.5 }, // door face at z + d/2
|
|
19
|
+
LAMPLIGHTER: { x: 1.3, z: -6.4 },
|
|
20
|
+
SIGN: { x: -6.8, z: -8.8 },
|
|
21
|
+
BRAZIERS: [[5.9, -12.8, 'A'], [-27.6, 0.2, 'B'], [9.6, -5.4, 'C']] as const,
|
|
22
|
+
ROW: [[8.3, -12.8, 'B'], [10.7, -12.8, 'C']] as const,
|
|
23
|
+
GATE: { x: -10, z: 0, half: 1.75 },
|
|
24
|
+
POND: { x: -19.4, z: 0, hx: 6.6, hz: 5.4, r: 2.2 },
|
|
25
|
+
ARENA: { x: 25.5, z: -2, r: 9.5 },
|
|
26
|
+
ARCH: { x: 16, z: -2 },
|
|
27
|
+
YARD: { x0: -10, x1: 12.5, z0: -18.6, z1: 8 },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The quest state the shard shows (the cleanroom's `?lit=A`): stage 6 makes it live. */
|
|
31
|
+
export const STATE = { lit: 'A', gateOpen: false, bridgeUp: false };
|
|
32
|
+
|
|
33
|
+
const noise = T.makeNoise(99);
|
|
34
|
+
const sstep = THREE.MathUtils.smoothstep;
|
|
35
|
+
type Materials = Record<string, THREE.MeshStandardMaterial>;
|
|
36
|
+
type Textures = Record<string, THREE.Texture>;
|
|
37
|
+
|
|
38
|
+
/** Signed distance to the pond's rounded rectangle (negative inside). */
|
|
39
|
+
export function pondSDF(x: number, z: number): number {
|
|
40
|
+
const { x: px, z: pz, hx, hz, r } = LAYOUT.POND;
|
|
41
|
+
const qx = Math.abs(x - px) - hx + r, qz = Math.abs(z - pz) - hz + r;
|
|
42
|
+
return Math.hypot(Math.max(qx, 0), Math.max(qz, 0)) + Math.min(Math.max(qx, qz), 0) - r;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function groundHeight(x: number, z: number): number {
|
|
46
|
+
let y = 0;
|
|
47
|
+
const dp = pondSDF(x, z);
|
|
48
|
+
if (dp < 0.6) y -= 1.1 * (1 - sstep(dp, -1.6, 0.6));
|
|
49
|
+
const da = Math.hypot(x - LAYOUT.ARENA.x, z - LAYOUT.ARENA.z);
|
|
50
|
+
if (da < LAYOUT.ARENA.r) y -= 0.35;
|
|
51
|
+
// the cell edge stays at road height for the four entryways (the cleanroom had no edge)
|
|
52
|
+
const far = sstep(Math.hypot(x - 4, z + 2), 48, 95) * (1 - sstep(Math.hypot(x, z), 170, 230));
|
|
53
|
+
y += far * (noise.fbm(x * 0.02 + 50, z * 0.02 + 50, 3) - 0.35) * 7;
|
|
54
|
+
return y;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The moss floor's colour, as the cleanroom's ground vertex colours times its moss texture's mean. */
|
|
58
|
+
export function groundColour(x: number, z: number): [number, number, number] {
|
|
59
|
+
const v = noise.fbm(x * 0.07, z * 0.07, 4), w = noise.fbm(x * 0.018 + 9, z * 0.018 + 4, 3);
|
|
60
|
+
const c = new THREE.Color().setRGB(0.96 + (v - 0.5) * 0.3, 0.98 + (v - 0.5) * 0.22, 0.86 + (w - 0.5) * 0.3);
|
|
61
|
+
const dp = pondSDF(x, z);
|
|
62
|
+
if (dp < 0.9) c.lerp(new THREE.Color(0.42, 0.38, 0.3), 1 - sstep(dp, -0.4, 0.9));
|
|
63
|
+
const moss = new THREE.Color().setRGB(102 / 255, 120 / 255, 48 / 255, THREE.SRGBColorSpace);
|
|
64
|
+
return [c.r * moss.r, c.g * moss.g, c.b * moss.b];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The textures and materials every part shares (`buildWorld`'s `tex` and `M`). */
|
|
68
|
+
function materials(): { M: Materials; tex: Textures } {
|
|
69
|
+
const tex = { stone: T.stone(3, { moss: 0.32 }), stoneClean: T.stone(8, { moss: 0.12 }), slab: T.slab(), wood: T.wood(), shingle: T.shingle(), checker: T.checker(), glow: T.glow(), ivy: T.ivy(), drape: T.hangingMoss(), frond: T.frond(), grass: T.grassCard(), flame: T.flameSprite() };
|
|
70
|
+
const M = {
|
|
71
|
+
stone: new THREE.MeshStandardMaterial({ map: tex.stone, roughness: 0.93 }),
|
|
72
|
+
stoneClean: new THREE.MeshStandardMaterial({ map: tex.stoneClean, roughness: 0.9 }),
|
|
73
|
+
slab: new THREE.MeshStandardMaterial({ map: tex.slab, roughness: 0.88 }),
|
|
74
|
+
wood: new THREE.MeshStandardMaterial({ map: tex.wood, roughness: 0.78 }),
|
|
75
|
+
darkWood: new THREE.MeshStandardMaterial({ map: tex.wood, color: '#8a6a52', roughness: 0.82 }),
|
|
76
|
+
shingle: new THREE.MeshStandardMaterial({ name: 'roof', map: tex.shingle, roughness: 0.95 }),
|
|
77
|
+
moss: new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 }),
|
|
78
|
+
iron: new THREE.MeshStandardMaterial({ color: '#3a302a', roughness: 0.5, metalness: 0.6 }),
|
|
79
|
+
bronze: new THREE.MeshStandardMaterial({ color: '#7a5634', roughness: 0.45, metalness: 0.7 }),
|
|
80
|
+
lampGlass: new THREE.MeshStandardMaterial({ color: '#ffc061', emissive: '#ffa73a', emissiveIntensity: 2.6, roughness: 0.3 }),
|
|
81
|
+
lampOff: new THREE.MeshStandardMaterial({ color: '#4a3e30', roughness: 0.6 }),
|
|
82
|
+
ivy: new THREE.MeshStandardMaterial({ map: tex.ivy, alphaTest: 0.45, side: THREE.DoubleSide, roughness: 0.85 }),
|
|
83
|
+
drape: new THREE.MeshStandardMaterial({ map: tex.drape, alphaTest: 0.35, side: THREE.DoubleSide, roughness: 1 }),
|
|
84
|
+
cloth: new THREE.MeshStandardMaterial({ color: '#8a3a2a', roughness: 0.95 }),
|
|
85
|
+
rope: new THREE.MeshStandardMaterial({ color: '#b8925a', roughness: 0.9 }),
|
|
86
|
+
};
|
|
87
|
+
return { M, tex };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The cleanroom's update(t), said as data (AP12): every lamp's intensity * (0.92 + 0.05 sin 7t + 0.03 sin 17.3t), a flame
|
|
91
|
+
// tongue's height * (0.85 + 0.12 sin 9t + 0.06 sin 23t), foliage in the wind, sparks climbing, fireflies wandering.
|
|
92
|
+
const LAMP_FLICKER = flicker({ rate: 1.1, amount: 0.08 });
|
|
93
|
+
const FLAME_PULSE = pulse({ rate: 1.4, amount: 0.14 });
|
|
94
|
+
const FOLIAGE_SWAY = sway({ rate: 0.5, amount: 0.06 });
|
|
95
|
+
|
|
96
|
+
// One material per halo colour and strength, per stencil text: repeated ones share a draw (the cleanroom's decalMats).
|
|
97
|
+
const glowMats = new Map<string, THREE.SpriteMaterial>(), decalMats = new Map<string, THREE.MeshStandardMaterial>();
|
|
98
|
+
const sparkMats = new Map<string, THREE.PointsMaterial>();
|
|
99
|
+
let flameMat: THREE.SpriteMaterial | null = null;
|
|
100
|
+
function glowMat(tex: Textures, colour: string, opacity: number): THREE.SpriteMaterial {
|
|
101
|
+
const key = `${colour}/${opacity}`;
|
|
102
|
+
let m = glowMats.get(key);
|
|
103
|
+
if (m === undefined) { m = new THREE.SpriteMaterial({ map: tex.glow, color: colour, blending: THREE.AdditiveBlending, depthWrite: false, transparent: true, opacity, fog: false }); glowMats.set(key, m); }
|
|
104
|
+
return m;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface Block { x: number; y: number; z: number; sx: number; sy: number; sz: number; rotY: number; rotX?: number; tint: number }
|
|
108
|
+
const boxGeo = new THREE.BoxGeometry(1, 1, 1), hidden = new THREE.MeshBasicMaterial();
|
|
109
|
+
|
|
110
|
+
/** One part's builders: the cleanroom's accumulators (`addBlock`, `addCap`, `drape`, `ivy`), its colliders, lamps and fires. */
|
|
111
|
+
function kit(part: THREE.Group, seed: number, M: Materials, tex: Textures) {
|
|
112
|
+
const rand = T.rng(seed);
|
|
113
|
+
const R = (a: number, b: number): number => a + (b - a) * rand();
|
|
114
|
+
const blockGeo = new RoundedBoxGeometry(1, 1, 1, 3, 0.07);
|
|
115
|
+
const capGeo = (() => {
|
|
116
|
+
const g = new RoundedBoxGeometry(1, 1, 1, 7, 0.38);
|
|
117
|
+
const p = g.attributes.position;
|
|
118
|
+
if (p === undefined) return g;
|
|
119
|
+
const c = new Float32Array(p.count * 3);
|
|
120
|
+
for (let i = 0; i < p.count; i++) {
|
|
121
|
+
const x = p.getX(i), y = p.getY(i), z = p.getZ(i);
|
|
122
|
+
const n = noise(x * 7 + 10, z * 7 + 10), n2 = noise(x * 19 + 3, z * 19 + y * 9);
|
|
123
|
+
if (y > 0) p.setY(i, y + (n - 0.5) * 0.4 + (n2 - 0.5) * 0.12);
|
|
124
|
+
else p.setY(i, y - n * 0.45);
|
|
125
|
+
const k = 0.72 + n * 0.42 + (n2 - 0.5) * 0.18;
|
|
126
|
+
const top = y > 0 ? 1 : 0.62;
|
|
127
|
+
c.set([0.085 * k * top, 0.16 * k * top, 0.034 * k * top], i * 3); // linear: olive moss
|
|
128
|
+
}
|
|
129
|
+
g.setAttribute('color', new THREE.BufferAttribute(c, 3));
|
|
130
|
+
g.computeVertexNormals();
|
|
131
|
+
return g;
|
|
132
|
+
})();
|
|
133
|
+
const stoneBlocks: Block[] = [], caps: Omit<Block, 'tint'>[] = [], drapeGeos: THREE.BufferGeometry[] = [], ivyGeos: THREE.BufferGeometry[] = [];
|
|
134
|
+
const addBlock = (x: number, y: number, z: number, sx: number, sy: number, sz: number, rotY = 0, tint = 1): void => { stoneBlocks.push({ x, y, z, sx, sy, sz, rotY, tint }); };
|
|
135
|
+
const addCap = (x: number, y: number, z: number, sx: number, sy: number, sz: number, rotY = 0): void => { caps.push({ x, y, z, sx, sy, sz, rotY }); };
|
|
136
|
+
/** The cleanroom's `colliders.push({ x, y, z, hx, hy, hz, rotY })`: an invisible solid box at the same numbers. */
|
|
137
|
+
function collider(c: { x: number; y: number; z: number; hx: number; hy: number; hz: number; rotY: number }): void {
|
|
138
|
+
const m = new THREE.Mesh(boxGeo, hidden);
|
|
139
|
+
m.position.set(c.x, c.y, c.z); m.scale.set(c.hx * 2, c.hy * 2, c.hz * 2); m.rotation.y = c.rotY; m.visible = false;
|
|
140
|
+
part.add(solid(m));
|
|
141
|
+
}
|
|
142
|
+
function drape(x: number, y: number, z: number, len: number, rotY: number, h = 0.45): void {
|
|
143
|
+
const g = new THREE.PlaneGeometry(len, h, Math.max(1, Math.round(len * 3)), 2);
|
|
144
|
+
g.translate(0, -h / 2, 0);
|
|
145
|
+
const p = g.attributes.position, uv = g.attributes.uv;
|
|
146
|
+
if (p !== undefined) for (let i = 0; i < p.count; i++) { p.setZ(i, (noise(p.getX(i) * 3 + x, y) - 0.5) * 0.06); uv?.setX(i, uv.getX(i) * len * 0.9 + R(0, 0)); }
|
|
147
|
+
g.rotateY(rotY); g.translate(x, y, z);
|
|
148
|
+
drapeGeos.push(g);
|
|
149
|
+
}
|
|
150
|
+
function ivy(x: number, y: number, z: number, len: number, rotY: number, w = 0.32): void {
|
|
151
|
+
const g = new THREE.PlaneGeometry(w, len, 1, 5);
|
|
152
|
+
g.translate(0, -len / 2, 0);
|
|
153
|
+
const p = g.attributes.position;
|
|
154
|
+
if (p !== undefined) for (let i = 0; i < p.count; i++) p.setZ(i, Math.sin(p.getY(i) * 2.2 + x) * 0.03);
|
|
155
|
+
g.rotateY(rotY); g.translate(x, y, z);
|
|
156
|
+
ivyGeos.push(g);
|
|
157
|
+
}
|
|
158
|
+
function lantern(x: number, y: number, z: number, { on = true, scale = 1, light = true } = {}): THREE.Group {
|
|
159
|
+
const g = new THREE.Group();
|
|
160
|
+
const glass = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.26, 0.2), on ? M.lampGlass : M.lampOff);
|
|
161
|
+
const cap = new THREE.Mesh(new THREE.ConeGeometry(0.21, 0.15, 4), M.iron); cap.position.y = 0.22; cap.rotation.y = Math.PI / 4;
|
|
162
|
+
const base = new THREE.Mesh(new THREE.BoxGeometry(0.27, 0.05, 0.27), M.iron); base.position.y = -0.155;
|
|
163
|
+
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.05, 0.012, 6, 12), M.iron); ring.position.y = 0.33;
|
|
164
|
+
g.add(glass, cap, base, ring);
|
|
165
|
+
for (const [bx, bz] of [[-1, -1], [1, -1], [-1, 1], [1, 1]] as const) {
|
|
166
|
+
const b = new THREE.Mesh(new THREE.BoxGeometry(0.035, 0.32, 0.035), M.iron); b.position.set(bx * 0.11, 0, bz * 0.11); g.add(b);
|
|
167
|
+
}
|
|
168
|
+
g.position.set(x, y, z); g.scale.setScalar(scale);
|
|
169
|
+
part.add(g);
|
|
170
|
+
if (on) {
|
|
171
|
+
if (light) {
|
|
172
|
+
const l = new THREE.PointLight('#ffa850', 3.4 * scale, 6, 1.7);
|
|
173
|
+
l.position.set(x, y, z); part.add(animate(l, LAMP_FLICKER));
|
|
174
|
+
}
|
|
175
|
+
halo(x, y, z, 1.1 * scale, '#ffb466', 0.5);
|
|
176
|
+
}
|
|
177
|
+
return g;
|
|
178
|
+
}
|
|
179
|
+
function halo(x: number, y: number, z: number, size: number, colour: string, opacity: number): void {
|
|
180
|
+
const s = new THREE.Sprite(glowMat(tex, colour, opacity));
|
|
181
|
+
s.scale.setScalar(size); s.position.set(x, y, z); part.add(s);
|
|
182
|
+
}
|
|
183
|
+
// A gallows post: a squared timber with an arm, a rope and a hanging lantern.
|
|
184
|
+
function lanternPost(x: number, z: number, rotY = 0, { h = 2.7, on = true, stoneBase = false } = {}): void {
|
|
185
|
+
const gy = groundHeight(x, z);
|
|
186
|
+
const ax = Math.sin(rotY), az = Math.cos(rotY);
|
|
187
|
+
if (stoneBase) {
|
|
188
|
+
const b = new THREE.Mesh(new RoundedBoxGeometry(0.62, 0.7, 0.62, 2, 0.05), M.stone); b.position.set(x, gy + 0.35, z); b.castShadow = true; part.add(b);
|
|
189
|
+
addCap(x, gy + 0.72, z, 0.66, 0.16, 0.66);
|
|
190
|
+
}
|
|
191
|
+
const p = new THREE.Mesh(new THREE.BoxGeometry(0.2, h, 0.2), M.wood); p.position.set(x, gy + h / 2, z); p.castShadow = true; part.add(p);
|
|
192
|
+
const arm = new THREE.Mesh(new THREE.BoxGeometry(0.14, 0.14, 0.95), M.wood);
|
|
193
|
+
arm.position.set(x + ax * 0.4, gy + h - 0.12, z + az * 0.4); arm.rotation.y = rotY; arm.castShadow = true; part.add(arm);
|
|
194
|
+
const brace = new THREE.Mesh(new THREE.BoxGeometry(0.09, 0.09, 0.55), M.wood);
|
|
195
|
+
brace.position.set(x + ax * 0.2, gy + h - 0.36, z + az * 0.2); brace.rotation.set(0, rotY, 0); brace.rotateX(0.75); part.add(brace);
|
|
196
|
+
const lx = x + ax * 0.74, lz = z + az * 0.74;
|
|
197
|
+
const rope = new THREE.Mesh(new THREE.CylinderGeometry(0.018, 0.018, 0.42, 5), M.rope);
|
|
198
|
+
rope.position.set(lx, gy + h - 0.4, lz); part.add(rope);
|
|
199
|
+
const coil = new THREE.Mesh(new THREE.TorusGeometry(0.07, 0.03, 6, 12), M.rope); coil.position.set(lx, gy + h - 0.12, lz); coil.rotation.y = rotY; part.add(coil);
|
|
200
|
+
lantern(lx, gy + h - 0.82, lz, { on, scale: 1.25 });
|
|
201
|
+
collider({ x, y: gy + h / 2, z, hx: 0.12, hy: h / 2, hz: 0.12, rotY: 0 });
|
|
202
|
+
}
|
|
203
|
+
// A wall bracket lamp: an iron arm out of a stone face.
|
|
204
|
+
function bracketLamp(x: number, y: number, z: number, rotY: number, on = true): void {
|
|
205
|
+
const ax = Math.sin(rotY), az = Math.cos(rotY);
|
|
206
|
+
const arm = new THREE.Mesh(new THREE.BoxGeometry(0.06, 0.06, 0.5), M.iron); arm.position.set(x + ax * 0.22, y + 0.42, z + az * 0.22); arm.rotation.y = rotY; part.add(arm);
|
|
207
|
+
const plate = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.3, 0.04), M.iron); plate.position.set(x, y + 0.36, z); plate.rotation.y = rotY; part.add(plate);
|
|
208
|
+
lantern(x + ax * 0.44, y, z + az * 0.44, { on, scale: 1.05 });
|
|
209
|
+
}
|
|
210
|
+
// Fire: three flame cards breathing (normal blending, so overlapping tongues stay orange), a flickering light, a halo,
|
|
211
|
+
// and 36 sparks climbing 2.6 m (the cleanroom's (s0 + t sp 0.4) % 1).
|
|
212
|
+
function fire(x: number, y: number, z: number, size = 1): void {
|
|
213
|
+
flameMat ??= new THREE.SpriteMaterial({ map: tex.flame, color: new THREE.Color(1.5, 1.3, 1.15), depthWrite: false, transparent: true, fog: false, alphaTest: 0.05 });
|
|
214
|
+
const g = animate(new THREE.Group(), FLAME_PULSE);
|
|
215
|
+
for (let i = 0; i < 3; i++) {
|
|
216
|
+
const h = ([1.9, 1.5, 1.3][i] ?? 1) * size, s = new THREE.Sprite(flameMat);
|
|
217
|
+
// the cleanroom's mean frame (k = 0.85): the pulse breathes round it
|
|
218
|
+
s.center.set(0.5, 0.1); s.scale.set(h * 0.62 * 1.05, h * 0.85, 1); s.position.set(([0, -0.24, 0.26][i] ?? 0) * size, -0.02, ([0, 0.12, -0.14][i] ?? 0) * size);
|
|
219
|
+
g.add(s);
|
|
220
|
+
}
|
|
221
|
+
g.position.set(x, y, z); part.add(g);
|
|
222
|
+
const l = new THREE.PointLight('#ff9a3a', 16 * size, 12, 1.5); l.position.set(x, y + 0.7, z); part.add(animate(l, LAMP_FLICKER));
|
|
223
|
+
halo(x, y + 0.55, z, 2.6 * size, '#ff8a40', 0.18);
|
|
224
|
+
const sparks = new Float32Array(36 * 3);
|
|
225
|
+
for (let i = 0; i < 36; i++) sparks.set([x + R(-0.35, 0.35), y + 0.4, z + R(-0.35, 0.35)], i * 3);
|
|
226
|
+
let sm = sparkMats.get('fire');
|
|
227
|
+
if (sm === undefined) { sm = new THREE.PointsMaterial({ map: tex.glow, color: new THREE.Color('#ffc060').multiplyScalar(3), size: 0.07, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }); sparkMats.set('fire', sm); }
|
|
228
|
+
part.add(animate(new THREE.Points(new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(sparks, 3)), sm), rise({ rate: 0.3, height: 2.6 * size, spread: 0.5 })));
|
|
229
|
+
}
|
|
230
|
+
// flush instanced stone, caps, drapes and ivy into the part
|
|
231
|
+
function flush(): void {
|
|
232
|
+
const o = new THREE.Object3D(), c = new THREE.Color();
|
|
233
|
+
if (stoneBlocks.length > 0) {
|
|
234
|
+
const im = new THREE.InstancedMesh(blockGeo, M.stone, stoneBlocks.length);
|
|
235
|
+
stoneBlocks.forEach((b, i) => {
|
|
236
|
+
o.position.set(b.x, b.y, b.z); o.rotation.set(0, b.rotY, 0, 'YXZ'); if (b.rotX !== undefined) o.rotation.set(b.rotX, 0, 0); o.scale.set(b.sx, b.sy, b.sz); o.updateMatrix();
|
|
237
|
+
im.setMatrixAt(i, o.matrix); im.setColorAt(i, c.setRGB(b.tint, b.tint * R(0.96, 1.0), b.tint * R(0.9, 0.97)));
|
|
238
|
+
});
|
|
239
|
+
im.castShadow = im.receiveShadow = true; part.add(im);
|
|
240
|
+
}
|
|
241
|
+
if (caps.length > 0) {
|
|
242
|
+
const cm = new THREE.InstancedMesh(capGeo, M.moss, caps.length);
|
|
243
|
+
caps.forEach((b, i) => { o.position.set(b.x, b.y, b.z); o.rotation.set(0, b.rotY, 0); o.scale.set(b.sx, b.sy, b.sz); o.updateMatrix(); cm.setMatrixAt(i, o.matrix); });
|
|
244
|
+
cm.castShadow = cm.receiveShadow = true; part.add(cm);
|
|
245
|
+
}
|
|
246
|
+
if (drapeGeos.length > 0) { const d = new THREE.Mesh(mergeGeometries(drapeGeos), M.drape); d.castShadow = true; part.add(d); }
|
|
247
|
+
if (ivyGeos.length > 0) part.add(new THREE.Mesh(mergeGeometries(ivyGeos), M.ivy));
|
|
248
|
+
}
|
|
249
|
+
return { rand, R, capGeo, stoneBlocks, addBlock, addCap, collider, drape, ivy, lantern, halo, lanternPost, bracketLamp, fire, flush };
|
|
250
|
+
}
|
|
251
|
+
type Kit = ReturnType<typeof kit>;
|
|
252
|
+
|
|
253
|
+
function decal(part: THREE.Group, text: string, x: number, y: number, z: number, rotY: number, size = 1, floor = false): THREE.Mesh {
|
|
254
|
+
let mat = decalMats.get(text);
|
|
255
|
+
if (mat === undefined) { mat = new THREE.MeshStandardMaterial({ map: T.stencil(text), transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, roughness: 0.9 }); decalMats.set(text, mat); }
|
|
256
|
+
const m = new THREE.Mesh(new THREE.PlaneGeometry(size, size / 2), mat);
|
|
257
|
+
m.position.set(x, y, z);
|
|
258
|
+
if (floor) m.rotation.set(-Math.PI / 2, 0, rotY); else m.rotation.y = rotY;
|
|
259
|
+
m.receiveShadow = true;
|
|
260
|
+
part.add(m);
|
|
261
|
+
return m;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The yard and pond-garden walls (cleanroom world.js 183-244): coursed blocks, a fat moss cap, drapes, ivy, stencils. */
|
|
265
|
+
export function walls(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
266
|
+
const k = kit(part, 183, M, tex), { R, addBlock, addCap, collider, drape, ivy } = k;
|
|
267
|
+
function wall(x0: number, z0: number, x1: number, z1: number, { h = 1.45, t = 0.75, gaps = [] as [number, number][], label = '3x3' as string | null } = {}): void {
|
|
268
|
+
const dx = x1 - x0, dz = z1 - z0, len = Math.hypot(dx, dz);
|
|
269
|
+
const rotY = Math.atan2(-dz, dx), ux = dx / len, uz = dz / len, nx = -uz, nz = ux;
|
|
270
|
+
const courses = 3, ch = h / courses;
|
|
271
|
+
const inGap = (m: number): boolean => gaps.some(([a, b]) => m > a && m < b);
|
|
272
|
+
for (let c = 0; c < courses; c++) {
|
|
273
|
+
let s = c % 2 ? -0.6 : 0;
|
|
274
|
+
while (s < len) {
|
|
275
|
+
const bl = Math.min(R(0.8, 1.5), len - Math.max(s, 0));
|
|
276
|
+
const a = Math.max(s, 0), b = Math.min(s + bl, len);
|
|
277
|
+
const m = (a + b) / 2;
|
|
278
|
+
if (b - a > 0.2 && !inGap(m)) addBlock(x0 + ux * m, ch * c + ch / 2, z0 + uz * m, b - a - 0.05, ch - 0.04, t * R(0.94, 1.06), rotY, R(0.8, 1.08));
|
|
279
|
+
s += bl;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const edges = [0, ...gaps.flat(), len];
|
|
283
|
+
for (let i = 0; i < edges.length; i += 2) {
|
|
284
|
+
const a = edges[i] ?? 0, b = edges[i + 1] ?? 0;
|
|
285
|
+
if (b - a < 0.3) continue;
|
|
286
|
+
const m = (a + b) / 2, cx = x0 + ux * m, cz = z0 + uz * m;
|
|
287
|
+
addCap(cx, h + 0.06, cz, b - a + 0.12, 0.36, t + 0.22, rotY);
|
|
288
|
+
collider({ x: cx, y: h / 2, z: cz, hx: (b - a) / 2, hy: h / 2 + 0.2, hz: t / 2, rotY });
|
|
289
|
+
for (const side of [-1, 1]) {
|
|
290
|
+
// drapes in short runs so the edge stays ragged
|
|
291
|
+
for (let s = a + R(0, 0.6); s < b - 0.4; s += R(1.2, 2.6)) {
|
|
292
|
+
const l = Math.min(R(0.6, 1.6), b - s);
|
|
293
|
+
drape(x0 + ux * (s + l / 2) + nx * side * (t / 2 + 0.115), h + 0.02, z0 + uz * (s + l / 2) + nz * side * (t / 2 + 0.115), l, rotY, R(0.25, 0.6));
|
|
294
|
+
}
|
|
295
|
+
for (let s = a + R(0.5, 2); s < b - 0.3; s += R(2.5, 5)) {
|
|
296
|
+
ivy(x0 + ux * s + nx * side * (t / 2 + 0.05), h + 0.05, z0 + uz * s + nz * side * (t / 2 + 0.05), R(0.7, h), rotY);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (label !== null && b - a > 4) {
|
|
300
|
+
for (const side of [-1, 1]) decal(part, label, cx + nx * side * (t / 2 + 0.02), h * 0.55, cz + nz * side * (t / 2 + 0.02), rotY + (side > 0 ? 0 : Math.PI), 1.0);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const Y = LAYOUT.YARD, G = LAYOUT.GATE, P = LAYOUT.POND;
|
|
305
|
+
wall(Y.x0, Y.z0, Y.x0, Y.z1, { gaps: [[G.z - Y.z0 - G.half - 0.5, G.z - Y.z0 + G.half + 0.5]] }); // west, the moss gate
|
|
306
|
+
wall(Y.x0, Y.z0, Y.x1, Y.z0); // north, behind the hut
|
|
307
|
+
wall(Y.x1, Y.z0, Y.x1, Y.z1, { gaps: [[LAYOUT.ARCH.z - Y.z0 - 1.9, LAYOUT.ARCH.z - Y.z0 + 1.9]] }); // east, toward the arch
|
|
308
|
+
wall(Y.x0, Y.z1, Y.x1, Y.z1, { h: 1.2 }); // south
|
|
309
|
+
// the pond's garden: low walls around it, open toward the gate
|
|
310
|
+
wall(Y.x0, -9, P.x - P.hx - 7, -9, { h: 1.2, label: null });
|
|
311
|
+
wall(Y.x0, 9, P.x - P.hx - 7, 9, { h: 1.2, label: null });
|
|
312
|
+
wall(P.x - P.hx - 7, -9, P.x - P.hx - 7, 9, { h: 1.2 });
|
|
313
|
+
// the lamps along the walls (cleanroom world.js 973-977)
|
|
314
|
+
k.lanternPost(-7.4, 3.6, -Math.PI / 2 - 0.4);
|
|
315
|
+
k.lanternPost(13.4, -5.0, Math.PI / 2);
|
|
316
|
+
k.bracketLamp(Y.x1 - 0.4, 1.0, -12.6, -Math.PI / 2, true);
|
|
317
|
+
k.flush();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The distant dev district (cleanroom world.js 246-274): towers, slabs and scaffold frames the haze eats. */
|
|
321
|
+
export function district(part: THREE.Group): void {
|
|
322
|
+
const rand = T.rng(246), R = (a: number, b: number): number => a + (b - a) * rand();
|
|
323
|
+
const solids: { x: number; z: number; w: number; h: number; d: number; r: number }[] = [];
|
|
324
|
+
const beams: { x: number; y: number; z: number; sx: number; sy: number; sz: number; r: number }[] = [];
|
|
325
|
+
for (let i = 0; i < 110; i++) {
|
|
326
|
+
const a = R(0, Math.PI * 2), d = R(85, 200);
|
|
327
|
+
const x = 4 + Math.cos(a) * d, z = -2 + Math.sin(a) * d;
|
|
328
|
+
const kind = rand();
|
|
329
|
+
if (kind < 0.62) solids.push({ x, z, w: R(4, 16), h: R(3, 10) * (rand() < 0.2 ? 1.6 : 1), d: R(4, 16), r: R(0, 3) });
|
|
330
|
+
else {
|
|
331
|
+
// a scaffold frame: four posts and two rings of beams
|
|
332
|
+
const w = R(5, 10), h = R(6, 13), r = R(0, 3);
|
|
333
|
+
const cs = Math.cos(r), sn = Math.sin(r);
|
|
334
|
+
const P2 = (px: number, pz: number): [number, number] => [x + px * cs - pz * sn, z + px * sn + pz * cs];
|
|
335
|
+
for (const [px, pz] of [[-1, -1], [1, -1], [1, 1], [-1, 1]] as const) { const [qx, qz] = P2(px * w / 2, pz * w / 2); beams.push({ x: qx, y: h / 2, z: qz, sx: 0.5, sy: h, sz: 0.5, r }); }
|
|
336
|
+
for (const yy of [h * 0.5, h]) {
|
|
337
|
+
for (const [px, pz, sx, sz] of [[0, -1, w, 0.45], [0, 1, w, 0.45], [-1, 0, 0.45, w], [1, 0, 0.45, w]] as const) { const [qx, qz] = P2(px * w / 2, pz * w / 2); beams.push({ x: qx, y: yy, z: qz, sx, sy: 0.45, sz, r }); }
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const im = new THREE.InstancedMesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshStandardMaterial({ color: '#8a7a8c', roughness: 0.95 }), solids.length + beams.length);
|
|
342
|
+
const o = new THREE.Object3D();
|
|
343
|
+
let k = 0;
|
|
344
|
+
for (const b of solids) { o.position.set(b.x, groundHeight(b.x, b.z) + b.h / 2 - 0.5, b.z); o.scale.set(b.w, b.h, b.d); o.rotation.set(0, b.r, 0); o.updateMatrix(); im.setMatrixAt(k++, o.matrix); }
|
|
345
|
+
for (const b of beams) { o.position.set(b.x, groundHeight(b.x, b.z) + b.y - 0.3, b.z); o.scale.set(b.sx, b.sy, b.sz); o.rotation.set(0, b.r, 0); o.updateMatrix(); im.setMatrixAt(k++, o.matrix); }
|
|
346
|
+
part.add(im);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface Slab { x: number; z: number; sx: number; sz: number; r: number }
|
|
350
|
+
/** The stepping-stone paths' slabs (cleanroom world.js 276-296), from their own stream: the grass reads them too. */
|
|
351
|
+
function pathSlabs(): { slabs: Slab[]; R: (a: number, b: number) => number } {
|
|
352
|
+
const rand = T.rng(276), R = (a: number, b: number): number => a + (b - a) * rand();
|
|
353
|
+
const slabs: Slab[] = [];
|
|
354
|
+
function path(points: readonly (readonly [number, number])[], { step = 1.15, width = 1.25 } = {}): void {
|
|
355
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
356
|
+
const [ax, az] = points[i] ?? [0, 0], [bx, bz] = points[i + 1] ?? [0, 0];
|
|
357
|
+
const len = Math.hypot(bx - ax, bz - az), n = Math.max(1, Math.round(len / step));
|
|
358
|
+
for (let k = i === 0 ? 0 : 1; k <= n; k++) {
|
|
359
|
+
const t = k / n, dir = Math.atan2(bx - ax, bz - az);
|
|
360
|
+
const x = ax + (bx - ax) * t + R(-0.15, 0.15), z = az + (bz - az) * t + R(-0.1, 0.1);
|
|
361
|
+
slabs.push({ x, z, sx: width * R(0.7, 1.0), sz: step * R(0.62, 0.8), r: dir + R(-0.22, 0.22) });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const H = LAYOUT.HUT, doorZ = H.z + H.d / 2, G = LAYOUT.GATE, P = LAYOUT.POND, [A, B] = LAYOUT.BRAZIERS;
|
|
366
|
+
path([[0, 3], [-0.6, -4], [-2.6, -9], [H.x, doorZ + 0.6]]);
|
|
367
|
+
path([[-1.4, 0.6], [-5, 0.2], [G.x + 1.2, G.z]], { width: 1.15 });
|
|
368
|
+
path([[0.8, -1.2], [4.2, -4], [A[0], A[1] + 2.1]], { width: 1.05 });
|
|
369
|
+
path([[1.5, 0.6], [6, -1.2], [LAYOUT.ARCH.x - 1.4, LAYOUT.ARCH.z]], { width: 1.15 });
|
|
370
|
+
path([[G.x - 1.2, G.z], [P.x + P.hx + 0.9, P.z]], { width: 1.2 });
|
|
371
|
+
path([[P.x - P.hx - 0.6, P.z], [B[0] + 1.3, B[1]]], { width: 1.1 });
|
|
372
|
+
return { slabs, R };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** The stepping-stone paths: flat irregular stones flush with the moss, their corners squashed so they read worn. */
|
|
376
|
+
export function paths(part: THREE.Group, M: Materials): void {
|
|
377
|
+
const { slabs, R } = pathSlabs();
|
|
378
|
+
const base = new RoundedBoxGeometry(1, 0.12, 1, 3, 0.05);
|
|
379
|
+
const p = base.attributes.position;
|
|
380
|
+
if (p !== undefined) for (let i = 0; i < p.count; i++) {
|
|
381
|
+
const x = p.getX(i), z = p.getZ(i), r = Math.hypot(x, z);
|
|
382
|
+
if (r > 0.55) { const k = 0.55 / r + (1 - 0.55 / r) * 0.45; p.setX(i, x * k); p.setZ(i, z * k); }
|
|
383
|
+
}
|
|
384
|
+
base.computeVertexNormals();
|
|
385
|
+
const im = new THREE.InstancedMesh(base, M.slab, slabs.length);
|
|
386
|
+
const o = new THREE.Object3D(), c = new THREE.Color();
|
|
387
|
+
slabs.forEach((s, i) => {
|
|
388
|
+
o.position.set(s.x, groundHeight(s.x, s.z), s.z);
|
|
389
|
+
o.rotation.set(R(-0.015, 0.015), s.r, R(-0.015, 0.015));
|
|
390
|
+
o.scale.set(s.sx, 1, s.sz);
|
|
391
|
+
o.updateMatrix(); im.setMatrixAt(i, o.matrix);
|
|
392
|
+
im.setColorAt(i, c.setScalar(R(0.82, 1.04)));
|
|
393
|
+
});
|
|
394
|
+
im.receiveShadow = true;
|
|
395
|
+
part.add(im);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** The braziers (cleanroom world.js 401-428): a lettered pad, a stone plinth, a wide bowl; A lit, the rest cold coal. */
|
|
399
|
+
export function braziers(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
400
|
+
const k = kit(part, 401, M, tex);
|
|
401
|
+
const coalM = new THREE.MeshStandardMaterial({ color: '#2a2220', roughness: 1 });
|
|
402
|
+
function brazier(bx: number, bz: number, letter: string, lit: boolean, scale = 1): void {
|
|
403
|
+
const gy = groundHeight(bx, bz);
|
|
404
|
+
const pad = new THREE.Mesh(new RoundedBoxGeometry(2.1, 0.12, 2.1, 2, 0.05), M.slab);
|
|
405
|
+
pad.position.set(bx, gy + 0.02, bz); pad.receiveShadow = true; part.add(pad);
|
|
406
|
+
decal(part, letter, bx, gy + 0.09, bz + 0.68, 0, 0.9, true);
|
|
407
|
+
const g = new THREE.Group();
|
|
408
|
+
const plinth = new THREE.Mesh(new RoundedBoxGeometry(0.78, 0.5, 0.78, 2, 0.05), M.stone); plinth.position.y = 0.25;
|
|
409
|
+
const step = new THREE.Mesh(new RoundedBoxGeometry(0.98, 0.14, 0.98, 2, 0.04), M.stone); step.position.y = 0.07;
|
|
410
|
+
const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.3, 0.32, 8), M.stone); stem.position.y = 0.66;
|
|
411
|
+
const prof = [new THREE.Vector2(0, 0)];
|
|
412
|
+
for (let i = 0; i <= 10; i++) { const t = i / 10; prof.push(new THREE.Vector2(0.22 + 0.42 * Math.sin(t * Math.PI / 2), t * 0.4)); }
|
|
413
|
+
prof.push(new THREE.Vector2(0.72, 0.42), new THREE.Vector2(0.7, 0.46), new THREE.Vector2(0.6, 0.42), new THREE.Vector2(0.0, 0.32));
|
|
414
|
+
const bowl = new THREE.Mesh(new THREE.LatheGeometry(prof, 8), M.stone); bowl.position.y = 0.8;
|
|
415
|
+
g.add(plinth, step, stem, bowl);
|
|
416
|
+
g.traverse((o) => { if (o instanceof THREE.Mesh) { o.castShadow = true; o.receiveShadow = true; } });
|
|
417
|
+
g.position.set(bx, gy, bz); g.scale.setScalar(scale); part.add(g);
|
|
418
|
+
k.collider({ x: bx, y: gy + 0.6, z: bz, hx: 0.45, hy: 0.6, hz: 0.45, rotY: 0 });
|
|
419
|
+
const top = gy + 1.18 * scale;
|
|
420
|
+
if (lit) k.fire(bx, top, bz, scale);
|
|
421
|
+
else {
|
|
422
|
+
const coal = new THREE.Mesh(new THREE.CircleGeometry(0.5 * scale, 12), coalM);
|
|
423
|
+
coal.rotation.x = -Math.PI / 2; coal.position.set(bx, top - 0.02, bz); part.add(coal);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
for (const [x, z, l] of LAYOUT.BRAZIERS) brazier(x, z, l, STATE.lit.includes(l));
|
|
427
|
+
for (const [x, z, l] of LAYOUT.ROW) brazier(x, z, l, STATE.lit.includes(l), 0.92);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** The hut (cleanroom world.js 430-554): coursed walls, gables, a shingle roof, door, sign, bracket lamp and the room. */
|
|
431
|
+
export function hut(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
432
|
+
const k = kit(part, 430, M, tex), { R, addBlock, addCap, drape, ivy, lantern, bracketLamp, collider, rand } = k;
|
|
433
|
+
const H = LAYOUT.HUT, doorZ = H.z + H.d / 2;
|
|
434
|
+
const { x: hx, z: hz, w: W, d: D, h: Hh } = H;
|
|
435
|
+
const z0 = doorZ, z1 = hz - D / 2;
|
|
436
|
+
const rows = 6, rh = Hh / rows, doorW = 1.3, doorH = 2.0;
|
|
437
|
+
for (let r = 0; r < rows; r++) {
|
|
438
|
+
const y = r * rh + rh / 2, off = r % 2 ? 0.4 : 0;
|
|
439
|
+
for (const [fz, front] of [[z0, true], [z1, false]] as const) {
|
|
440
|
+
let s = -W / 2 - off;
|
|
441
|
+
while (s < W / 2) {
|
|
442
|
+
const bl = R(0.75, 1.15), a = Math.max(s, -W / 2), b = Math.min(s + bl, W / 2);
|
|
443
|
+
s += bl;
|
|
444
|
+
if (b - a < 0.15) continue;
|
|
445
|
+
if (front && y < doorH && b > -doorW / 2 - 0.12 && a < doorW / 2 + 0.12) {
|
|
446
|
+
if (a < -doorW / 2 - 0.12) addBlock(hx + (a - doorW / 2 - 0.12) / 2, y, fz, -doorW / 2 - 0.12 - a - 0.03, rh - 0.03, 0.5, 0, R(0.82, 1.05));
|
|
447
|
+
if (b > doorW / 2 + 0.12) addBlock(hx + (b + doorW / 2 + 0.12) / 2, y, fz, b - doorW / 2 - 0.12 - 0.03, rh - 0.03, 0.5, 0, R(0.82, 1.05));
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
addBlock(hx + (a + b) / 2, y, fz, b - a - 0.03, rh - 0.03, 0.5, 0, R(0.82, 1.05));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
for (const fx of [-W / 2, W / 2]) {
|
|
454
|
+
let s = z1 - off;
|
|
455
|
+
while (s < z0) {
|
|
456
|
+
const bl = R(0.75, 1.15), a = Math.max(s, z1 + 0.25), b = Math.min(s + bl, z0 - 0.25);
|
|
457
|
+
s += bl;
|
|
458
|
+
if (b - a < 0.15) continue;
|
|
459
|
+
addBlock(hx + fx, y, (a + b) / 2, 0.5, rh - 0.03, b - a - 0.03, 0, R(0.82, 1.05));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
// corner quoins: bigger blocks proud of the wall
|
|
464
|
+
for (const [cx, cz] of [[-W / 2, z0], [W / 2, z0], [-W / 2, z1], [W / 2, z1]] as const) for (let r = 0; r < 3; r++) addBlock(hx + cx, r * 0.85 + 0.42, cz, 0.62, 0.8, 0.62, 0, R(0.75, 0.95));
|
|
465
|
+
// the walls' colliders: one box per wall run, from the same numbers the courses use
|
|
466
|
+
const side = (W / 2 - doorW / 2) / 2;
|
|
467
|
+
collider({ x: hx - (W / 2 + doorW / 2) / 2 - 0.05, y: Hh / 2, z: z0, hx: side, hy: Hh / 2, hz: 0.25, rotY: 0 });
|
|
468
|
+
collider({ x: hx + (W / 2 + doorW / 2) / 2 + 0.05, y: Hh / 2, z: z0, hx: side, hy: Hh / 2, hz: 0.25, rotY: 0 });
|
|
469
|
+
collider({ x: hx, y: Hh / 2, z: z1, hx: W / 2, hy: Hh / 2, hz: 0.25, rotY: 0 });
|
|
470
|
+
collider({ x: hx - W / 2, y: Hh / 2, z: hz, hx: 0.25, hy: Hh / 2, hz: D / 2, rotY: 0 });
|
|
471
|
+
collider({ x: hx + W / 2, y: Hh / 2, z: hz, hx: 0.25, hy: Hh / 2, hz: D / 2, rotY: 0 });
|
|
472
|
+
// gables, ridge left-right so the eaves face the path
|
|
473
|
+
const RH = 1.55, half = D / 2 + 0.25;
|
|
474
|
+
const tri = new THREE.Shape(); tri.moveTo(-half, 0); tri.lineTo(half, 0); tri.lineTo(0, RH); tri.closePath();
|
|
475
|
+
const gGeo = new THREE.ExtrudeGeometry(tri, { depth: 0.45, bevelEnabled: true, bevelSize: 0.05, bevelThickness: 0.05, bevelSegments: 2 });
|
|
476
|
+
const uvA = gGeo.attributes.uv; if (uvA !== undefined) for (let i = 0; i < uvA.count; i++) uvA.setXY(i, uvA.getX(i) * 0.4, uvA.getY(i) * 0.4);
|
|
477
|
+
for (const sx of [-1, 1]) {
|
|
478
|
+
const m = new THREE.Mesh(gGeo, M.stone); m.rotation.y = Math.PI / 2;
|
|
479
|
+
m.position.set(hx + sx * (W / 2) - 0.22, Hh - 0.02, hz); m.castShadow = m.receiveShadow = true; part.add(m);
|
|
480
|
+
}
|
|
481
|
+
// roof: thick overlapping mossy shingles, deep overhang, a fat moss ridge and drapes off the eaves
|
|
482
|
+
const over = 0.6, pitch = Math.atan2(RH, half), slopeLen = (half + over) / Math.cos(pitch);
|
|
483
|
+
const shGeo = new RoundedBoxGeometry(0.56, 0.2, 0.7, 2, 0.07);
|
|
484
|
+
const shingles: { x: number; y: number; z: number; side: number }[] = [];
|
|
485
|
+
for (const sd of [-1, 1]) {
|
|
486
|
+
const rowsN = 7;
|
|
487
|
+
for (let r = 0; r < rowsN; r++) {
|
|
488
|
+
const along = (r + 0.55) / rowsN * slopeLen, jitter = r % 2 ? 0.3 : 0;
|
|
489
|
+
for (let xx = -W / 2 - 0.6; xx <= W / 2 + 0.65; xx += 0.58) shingles.push({ x: hx + xx + jitter - 0.15, y: Hh + RH + 0.2 - along * Math.sin(pitch), z: hz + sd * along * Math.cos(pitch), side: sd });
|
|
490
|
+
}
|
|
491
|
+
const under = new THREE.Mesh(new THREE.BoxGeometry(W + 1.5, 0.16, slopeLen + 0.1), M.darkWood);
|
|
492
|
+
under.position.set(hx, Hh + RH + 0.08 - (slopeLen / 2) * Math.sin(pitch), hz + sd * (slopeLen / 2) * Math.cos(pitch));
|
|
493
|
+
under.rotation.x = sd * pitch; under.castShadow = true; part.add(under);
|
|
494
|
+
const ey = Hh + RH + 0.14 - slopeLen * Math.sin(pitch), ez = hz + sd * slopeLen * Math.cos(pitch);
|
|
495
|
+
addCap(hx, ey, ez, W + 1.55, 0.2, 0.32, 0);
|
|
496
|
+
drape(hx, ey - 0.02, ez + sd * 0.12, W + 1.4, 0, 0.42);
|
|
497
|
+
}
|
|
498
|
+
const shM = new THREE.InstancedMesh(shGeo, M.shingle, shingles.length);
|
|
499
|
+
const o = new THREE.Object3D(), cc = new THREE.Color();
|
|
500
|
+
shingles.forEach((s, i) => {
|
|
501
|
+
o.position.set(s.x, s.y, s.z); o.rotation.set(s.side * pitch + R(-0.06, 0.06), R(-0.05, 0.05), R(-0.04, 0.04));
|
|
502
|
+
o.scale.set(R(0.95, 1.1), 1, R(0.95, 1.1)); o.updateMatrix(); shM.setMatrixAt(i, o.matrix);
|
|
503
|
+
const m = rand(); shM.setColorAt(i, cc.setRGB(R(0.7, 0.95), R(0.8, 1.05) + m * 0.08, R(0.6, 0.8)));
|
|
504
|
+
});
|
|
505
|
+
shM.castShadow = shM.receiveShadow = true; shM.name = 'roof'; part.add(shM);
|
|
506
|
+
addCap(hx, Hh + RH + 0.3, hz, W + 1.55, 0.4, 0.66);
|
|
507
|
+
// moss tufts scattered on the roof
|
|
508
|
+
for (let i = 0; i < 16; i++) { const sd = i % 2 ? 1 : -1, al = R(0.2, 0.85) * slopeLen; addCap(hx + R(-W / 2, W / 2), Hh + RH + 0.32 - al * Math.sin(pitch), hz + sd * al * Math.cos(pitch), R(0.5, 1.1), 0.16, R(0.4, 0.7), R(-0.3, 0.3)); }
|
|
509
|
+
// door frame and lintel, a door leaf swung in, the sign
|
|
510
|
+
for (const sx of [-1, 1]) {
|
|
511
|
+
const m = new THREE.Mesh(new THREE.BoxGeometry(0.22, doorH + 0.15, 0.32), M.wood); m.position.set(hx + sx * (doorW / 2 + 0.07), (doorH + 0.15) / 2, z0 + 0.08); m.castShadow = true; part.add(m);
|
|
512
|
+
}
|
|
513
|
+
const lintel = new THREE.Mesh(new THREE.BoxGeometry(doorW + 0.7, 0.26, 0.36), M.wood); lintel.position.set(hx, doorH + 0.16, z0 + 0.1); lintel.castShadow = true; part.add(lintel);
|
|
514
|
+
const leaf = new THREE.Mesh(new THREE.BoxGeometry(doorW - 0.05, doorH - 0.05, 0.08), M.darkWood);
|
|
515
|
+
leaf.geometry.translate((doorW - 0.05) / 2, 0, 0);
|
|
516
|
+
leaf.position.set(hx - doorW / 2, doorH / 2, z0 - 0.15); leaf.rotation.y = -1.9; part.add(leaf);
|
|
517
|
+
const sign = new THREE.Mesh(new THREE.PlaneGeometry(1.7, 0.28), new THREE.MeshStandardMaterial({ map: T.stencil('MOSSGATE HUT', { w: 512, h: 80, font: 'bold 44px monospace', alpha: 0.9 }), transparent: true, roughness: 0.8 }));
|
|
518
|
+
sign.position.set(hx, doorH + 0.17, z0 + 0.29); part.add(sign);
|
|
519
|
+
decal(part, '3x3', hx + 1.6, 1.85, z0 + 0.27, 0, 0.85);
|
|
520
|
+
decal(part, '3x3', hx + W / 2 + 0.27, 1.85, hz, Math.PI / 2, 0.85);
|
|
521
|
+
bracketLamp(hx - 1.15, 1.85, z0 + 0.25, 0);
|
|
522
|
+
// ivy up the front corners
|
|
523
|
+
ivy(hx - W / 2 - 0.05, Hh, z0 + 0.27, Hh * 0.9, 0, 0.4);
|
|
524
|
+
ivy(hx + W / 2 + 0.27, Hh, z0 - 0.4, Hh * 0.7, Math.PI / 2, 0.4);
|
|
525
|
+
// ---- interior: plank floor, rug, table and stools, a shelf of jars, crates, a hanging lamp ----
|
|
526
|
+
const inW = W - 0.55, inD = D - 0.55, iz = hz;
|
|
527
|
+
const floor = new THREE.Mesh(new THREE.PlaneGeometry(inW, inD), new THREE.MeshStandardMaterial({ map: tex.wood, color: '#a07a58', roughness: 0.85 }));
|
|
528
|
+
floor.rotation.x = -Math.PI / 2; floor.position.set(hx, 0.02, iz); part.add(floor);
|
|
529
|
+
const back = new THREE.Mesh(new THREE.PlaneGeometry(inW, Hh), M.stoneClean); back.position.set(hx, Hh / 2, z1 + 0.26); part.add(back);
|
|
530
|
+
for (const sx of [-1, 1]) { const w = new THREE.Mesh(new THREE.PlaneGeometry(inD, Hh), M.stoneClean); w.rotation.y = -sx * Math.PI / 2; w.position.set(hx + sx * (inW / 2), Hh / 2, iz); part.add(w); }
|
|
531
|
+
const ceil = new THREE.Mesh(new THREE.PlaneGeometry(inW, inD), M.darkWood); ceil.rotation.x = Math.PI / 2; ceil.position.set(hx, Hh, iz); part.add(ceil);
|
|
532
|
+
const rug = new THREE.Mesh(new THREE.PlaneGeometry(1.8, 1.2), M.cloth); rug.rotation.x = -Math.PI / 2; rug.position.set(hx + 0.1, 0.03, iz + 0.4); part.add(rug);
|
|
533
|
+
const table = new THREE.Group();
|
|
534
|
+
const top = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.08, 0.7), M.wood); top.position.y = 0.76; table.add(top);
|
|
535
|
+
for (const [lx, lz] of [[-0.5, -0.27], [0.5, -0.27], [-0.5, 0.27], [0.5, 0.27]] as const) { const l = new THREE.Mesh(new THREE.BoxGeometry(0.08, 0.74, 0.08), M.darkWood); l.position.set(lx, 0.37, lz); table.add(l); }
|
|
536
|
+
const candle = new THREE.Mesh(new THREE.CylinderGeometry(0.04, 0.04, 0.16, 8), new THREE.MeshStandardMaterial({ color: '#f2e2c0', emissive: '#ffb050', emissiveIntensity: 0.4 })); candle.position.set(0.3, 0.88, 0); table.add(candle);
|
|
537
|
+
const bowlT = new THREE.Mesh(new THREE.SphereGeometry(0.13, 10, 6, 0, Math.PI * 2, Math.PI / 2, Math.PI / 2), M.bronze); bowlT.position.set(-0.25, 0.92, 0.05); table.add(bowlT);
|
|
538
|
+
table.position.set(hx + 0.6, 0, iz - 0.3); part.add(table);
|
|
539
|
+
for (const sx of [-0.5, 1.6]) { const st = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.18, 0.45, 8), M.wood); st.position.set(hx + sx, 0.225, iz + 0.15); part.add(st); }
|
|
540
|
+
const shelf = new THREE.Group();
|
|
541
|
+
for (const y of [0.9, 1.45]) { const b = new THREE.Mesh(new THREE.BoxGeometry(1.8, 0.06, 0.32), M.wood); b.position.y = y; shelf.add(b); }
|
|
542
|
+
const jarM = ['#6a8a5a', '#b08a4a', '#8a4a3a', '#5a6a8a', '#c0a070'].map((c) => new THREE.MeshStandardMaterial({ color: c, roughness: 0.4 }));
|
|
543
|
+
for (let i = 0; i < 9; i++) { const j = new THREE.Mesh(new THREE.CylinderGeometry(0.07, 0.08, R(0.16, 0.28), 8), jarM[i % 5]); j.position.set(-0.75 + (i % 5) * 0.36 + R(-0.05, 0.05), i < 5 ? 1.05 : 1.6, 0); shelf.add(j); }
|
|
544
|
+
shelf.position.set(hx - 0.9, 0, z1 + 0.45); part.add(shelf);
|
|
545
|
+
for (const [cx, cz, s] of [[-1.85, -0.6, 0.6], [-1.85, 0.05, 0.5], [-1.8, -0.3, 0.42]] as const) { const cr = new THREE.Mesh(new RoundedBoxGeometry(s, s, s, 1, 0.03), M.wood); cr.position.set(hx + cx, s / 2 + (s < 0.45 ? 0.6 : 0), iz + cz); cr.rotation.y = R(-0.3, 0.3); part.add(cr); }
|
|
546
|
+
barrel(part, k, M, hx + 1.95, iz - 1.4);
|
|
547
|
+
lantern(hx + 0.6, 1.95, iz - 0.3, { on: true, scale: 0.9, light: false });
|
|
548
|
+
const inLight = new THREE.PointLight('#ffa040', 7, 6.5, 1.4); inLight.position.set(hx + 0.4, 1.8, iz + 0.2); part.add(animate(inLight, LAMP_FLICKER));
|
|
549
|
+
const inLight2 = new THREE.PointLight('#ff9a40', 3, 4, 1.5); inLight2.position.set(hx - 1.5, 1.5, iz - 1.0); part.add(animate(inLight2, LAMP_FLICKER));
|
|
550
|
+
// outside: bench, barrels, crates
|
|
551
|
+
const bench = new THREE.Mesh(new RoundedBoxGeometry(1.5, 0.12, 0.44, 2, 0.03), M.wood); bench.position.set(hx - 2.15, 0.48, z0 + 0.95); bench.castShadow = true; part.add(bench);
|
|
552
|
+
for (const bx of [-0.58, 0.58]) { const l = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.45, 0.38), M.darkWood); l.position.set(hx - 2.15 + bx, 0.22, z0 + 0.95); part.add(l); }
|
|
553
|
+
for (const [bx, bz] of [[1.75, 0.75], [2.4, 1.05]] as const) barrel(part, k, M, hx + bx, z0 + bz);
|
|
554
|
+
k.flush();
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function barrel(part: THREE.Group, k: Kit, M: Materials, x: number, z: number): void {
|
|
558
|
+
const g = new THREE.CylinderGeometry(0.31, 0.31, 0.78, 16, 4);
|
|
559
|
+
const p = g.attributes.position;
|
|
560
|
+
if (p !== undefined) for (let i = 0; i < p.count; i++) { const y = p.getY(i), s = 1 + 0.12 * (1 - (y / 0.39) ** 2); p.setX(i, p.getX(i) * s); p.setZ(i, p.getZ(i) * s); }
|
|
561
|
+
g.computeVertexNormals();
|
|
562
|
+
const m = new THREE.Mesh(g, M.wood); m.position.set(x, 0.39, z); m.castShadow = true; part.add(m);
|
|
563
|
+
for (const y of [0.15, 0.62]) { const ring = new THREE.Mesh(new THREE.TorusGeometry(0.345, 0.02, 6, 24), M.iron); ring.rotation.x = Math.PI / 2; ring.position.set(x, y, z); part.add(ring); }
|
|
564
|
+
k.collider({ x, y: 0.39, z, hx: 0.31, hy: 0.39, hz: 0.31, rotY: 0 });
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** The sign post at the fork (cleanroom world.js 566-575). */
|
|
568
|
+
export function signpost(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
569
|
+
const k = kit(part, 566, M, tex), { x, z } = LAYOUT.SIGN;
|
|
570
|
+
const post = new THREE.Mesh(new THREE.BoxGeometry(0.16, 1.7, 0.16), M.wood); post.position.set(x, 0.85, z); post.castShadow = true; part.add(post);
|
|
571
|
+
const board = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.34, 0.07), M.wood); board.position.set(x - 0.15, 1.35, z); board.rotation.y = 0.35; board.castShadow = true; part.add(board);
|
|
572
|
+
const txt = new THREE.Mesh(new THREE.PlaneGeometry(1.0, 0.24), new THREE.MeshStandardMaterial({ map: T.stencil('HOLLOW', { w: 256, h: 64, font: 'bold 44px monospace', alpha: 0.9 }), transparent: true }));
|
|
573
|
+
txt.position.set(x - 0.15 + Math.sin(0.35) * 0.045, 1.35, z + Math.cos(0.35) * 0.045); txt.rotation.y = 0.35; part.add(txt);
|
|
574
|
+
k.collider({ x, y: 0.85, z, hx: 0.1, hy: 0.85, hz: 0.1, rotY: 0 });
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** The moss gate (cleanroom world.js 577-606): two tall mossy pillars, a barred gate, plaque A, lamps. */
|
|
578
|
+
export function gate(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
579
|
+
const k = kit(part, 577, M, tex), { R, addBlock, addCap, collider, drape, ivy, bracketLamp } = k;
|
|
580
|
+
const { x: gx, z: gz, half } = LAYOUT.GATE;
|
|
581
|
+
for (const side of [-1, 1]) {
|
|
582
|
+
const pz = gz + side * (half + 0.6);
|
|
583
|
+
for (let r = 0; r < 4; r++) addBlock(gx, r * 0.9 + 0.45, pz, 1.35 - r * 0.03, 0.86, 1.35 - r * 0.03, R(-0.04, 0.04), R(0.82, 1.0));
|
|
584
|
+
addCap(gx, 3.68, pz, 1.6, 0.55, 1.6);
|
|
585
|
+
collider({ x: gx, y: 1.7, z: pz, hx: 0.62, hy: 1.7, hz: 0.62, rotY: 0 });
|
|
586
|
+
for (const f of [-1, 1]) {
|
|
587
|
+
drape(gx + f * 0.72, 3.32, pz, 1.35, Math.PI / 2, R(0.5, 0.8));
|
|
588
|
+
ivy(gx + f * 0.66, 3.25, pz + R(-0.4, 0.4), R(1.4, 2.6), Math.PI / 2, 0.42);
|
|
589
|
+
ivy(gx + f * 0.66, 3.25, pz + R(-0.4, 0.4), R(0.8, 1.8), Math.PI / 2, 0.36);
|
|
590
|
+
}
|
|
591
|
+
bracketLamp(gx + 0.66, 2.35, pz, Math.PI / 2, true);
|
|
592
|
+
}
|
|
593
|
+
// the gate: a top rail, a bottom rail and thick round bars, sunk into the ground when open
|
|
594
|
+
const bars = new THREE.Group();
|
|
595
|
+
const span = half * 2 + 0.05;
|
|
596
|
+
for (const y of [0.2, 2.75]) { const rail = new THREE.Mesh(new RoundedBoxGeometry(0.34, 0.3, span, 2, 0.05), M.stone); rail.position.y = y; bars.add(rail); }
|
|
597
|
+
const barGeo = new RoundedBoxGeometry(0.26, 2.6, 0.26, 2, 0.06);
|
|
598
|
+
for (let i = 0; i < 6; i++) { const m = new THREE.Mesh(barGeo, M.stone); m.position.set(0, 1.45, -half + 0.3 + i * ((half * 2 - 0.6) / 5)); bars.add(m); }
|
|
599
|
+
bars.traverse((o) => { if (o instanceof THREE.Mesh) o.castShadow = true; });
|
|
600
|
+
bars.position.set(gx, STATE.gateOpen ? -2.6 : 0, gz); part.add(bars);
|
|
601
|
+
if (!STATE.gateOpen) collider({ x: gx, y: 1.2, z: gz, hx: 0.15, hy: 1.2, hz: half, rotY: 0 });
|
|
602
|
+
const plaque = new THREE.Mesh(new RoundedBoxGeometry(0.55, 0.55, 0.1, 2, 0.03), M.stoneClean);
|
|
603
|
+
plaque.position.set(gx + 0.66, 1.75, gz - half - 0.6); plaque.rotation.y = Math.PI / 2; part.add(plaque);
|
|
604
|
+
decal(part, 'A', gx + 0.72, 1.75, gz - half - 0.6, Math.PI / 2, 0.6);
|
|
605
|
+
k.flush();
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** The Lamplighter (cleanroom world.js 608-639): a hooded, round-faced keeper with a lantern on a staff, a static pose. */
|
|
609
|
+
export function lamplighter(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
610
|
+
const k = kit(part, 608, M, tex);
|
|
611
|
+
const { x, z } = LAYOUT.LAMPLIGHTER, faceYaw = Math.atan2(0 - x, 0 - z), cloak = '#4a6a2e';
|
|
612
|
+
const g = new THREE.Group();
|
|
613
|
+
const cloakM = new THREE.MeshStandardMaterial({ color: cloak, roughness: 0.92 });
|
|
614
|
+
const prof: THREE.Vector2[] = [];
|
|
615
|
+
for (let i = 0; i <= 12; i++) { const t = i / 12; prof.push(new THREE.Vector2(0.5 - 0.26 * t + 0.06 * Math.sin(t * Math.PI), t * 1.05)); }
|
|
616
|
+
const body = new THREE.Mesh(new THREE.LatheGeometry(prof, 20), cloakM); body.castShadow = true;
|
|
617
|
+
const hem = new THREE.Mesh(new THREE.TorusGeometry(0.47, 0.04, 6, 24), new THREE.MeshStandardMaterial({ color: '#2e4220', roughness: 0.9 })); hem.rotation.x = Math.PI / 2; hem.position.y = 0.04;
|
|
618
|
+
const head = new THREE.Mesh(new THREE.SphereGeometry(0.3, 24, 16), new THREE.MeshStandardMaterial({ color: '#f0d9b8', roughness: 0.65 })); head.position.y = 1.22; head.castShadow = true;
|
|
619
|
+
const hood = new THREE.Mesh(new THREE.SphereGeometry(0.37, 24, 16, 0, Math.PI * 2, 0, Math.PI * 0.64), cloakM); hood.position.set(0, 1.26, -0.04); hood.rotation.x = -0.45; hood.castShadow = true;
|
|
620
|
+
const tip = new THREE.Mesh(new THREE.ConeGeometry(0.16, 0.42, 12), cloakM); tip.position.set(0, 1.62, -0.2); tip.rotation.x = -0.75;
|
|
621
|
+
const eyeM = new THREE.MeshBasicMaterial({ color: '#1a1410' });
|
|
622
|
+
for (const ex of [-0.1, 0.1]) { const e = new THREE.Mesh(new THREE.SphereGeometry(0.038, 8, 6), eyeM); e.position.set(ex, 1.24, 0.27); g.add(e); }
|
|
623
|
+
const cheekM = new THREE.MeshStandardMaterial({ color: '#f0a890', roughness: 0.7 });
|
|
624
|
+
for (const ex of [-0.17, 0.17]) { const c = new THREE.Mesh(new THREE.SphereGeometry(0.05, 8, 6), cheekM); c.position.set(ex, 1.15, 0.24); c.scale.z = 0.4; g.add(c); }
|
|
625
|
+
for (const sx of [-1, 1]) { const arm = new THREE.Mesh(new THREE.CapsuleGeometry(0.09, 0.42, 4, 8), cloakM); arm.position.set(sx * 0.36, 0.72, 0.1); arm.rotation.set(-0.5, 0, sx * 0.25); arm.castShadow = true; g.add(arm); }
|
|
626
|
+
const belt = new THREE.Mesh(new THREE.TorusGeometry(0.4, 0.035, 6, 24), M.darkWood); belt.rotation.x = Math.PI / 2; belt.position.y = 0.62;
|
|
627
|
+
g.add(body, hem, head, hood, tip, belt);
|
|
628
|
+
const pole = new THREE.Mesh(new THREE.CylinderGeometry(0.035, 0.04, 2.0, 6), M.wood); pole.position.set(0.48, 1.0, 0.2); pole.castShadow = true; g.add(pole);
|
|
629
|
+
g.position.set(x, groundHeight(x, z), z); g.rotation.y = faceYaw; g.scale.setScalar(1.35); part.add(g);
|
|
630
|
+
const wp = new THREE.Vector3(0.48, 1.86, 0.2).multiplyScalar(1.35).applyEuler(g.rotation).add(g.position);
|
|
631
|
+
k.lantern(wp.x, wp.y, wp.z, { on: true, scale: 1.0 });
|
|
632
|
+
k.collider({ x, y: 0.8, z, hx: 0.4, hy: 0.8, hz: 0.4, rotY: 0 });
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** The pond (cleanroom world.js 641-697): kerb stones, the moss bridge, reeds, lilies, three lantern posts and the water,
|
|
636
|
+
* its outline the same rounded rectangle the ground is carved from. */
|
|
637
|
+
export function pond(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
638
|
+
const k = kit(part, 641, M, tex), { R, rand, addBlock, addCap, lanternPost, collider } = k;
|
|
639
|
+
const P = LAYOUT.POND;
|
|
640
|
+
// kerb stones around the rim, gaps where the bridge lands
|
|
641
|
+
const per: [number, number][] = [];
|
|
642
|
+
const steps = 140;
|
|
643
|
+
for (let i = 0; i < steps; i++) {
|
|
644
|
+
// walk the rounded rectangle by angle and project onto the SDF zero line
|
|
645
|
+
const a = (i / steps) * Math.PI * 2;
|
|
646
|
+
let rr = 3;
|
|
647
|
+
for (let j = 0; j < 30; j++) { const d = pondSDF(P.x + Math.cos(a) * rr, P.z + Math.sin(a) * rr); rr -= d * 0.8; }
|
|
648
|
+
per.push([P.x + Math.cos(a) * rr, P.z + Math.sin(a) * rr]);
|
|
649
|
+
}
|
|
650
|
+
let acc = 0;
|
|
651
|
+
for (let i = 0; i < per.length; i++) {
|
|
652
|
+
const [ax, az] = per[i] ?? [0, 0], [bx, bz] = per[(i + 1) % per.length] ?? [0, 0];
|
|
653
|
+
acc += Math.hypot(bx - ax, bz - az);
|
|
654
|
+
if (acc < 0.85) continue;
|
|
655
|
+
acc = 0;
|
|
656
|
+
if (Math.abs(az - P.z) < 1.1) continue; // the bridge landings
|
|
657
|
+
const ang = Math.atan2(-(bz - az), bx - ax);
|
|
658
|
+
addBlock(ax, -0.16 + R(0, 0.05), az, R(0.7, 0.95), 0.3, R(0.5, 0.65), ang + R(-0.15, 0.15), R(0.62, 0.8));
|
|
659
|
+
if (rand() < 0.25) addCap(ax, 0.02, az, R(0.4, 0.8), 0.1, 0.4, ang);
|
|
660
|
+
}
|
|
661
|
+
// the moss bridge: big stone blocks across the long axis; sunk below the surface until A is lit
|
|
662
|
+
const n = 5, x0 = P.x + P.hx - 1.5, x1 = P.x - P.hx + 1.5;
|
|
663
|
+
for (let i = 0; i < n; i++) {
|
|
664
|
+
const x = x0 + (x1 - x0) * (i / (n - 1)), z = P.z + R(-0.15, 0.15);
|
|
665
|
+
const topY = STATE.bridgeUp ? 0.28 : -0.07;
|
|
666
|
+
addBlock(x, topY - 0.6, z, 1.7, 1.2, 1.7, R(-0.08, 0.08), STATE.bridgeUp ? R(0.78, 0.9) : R(0.32, 0.4));
|
|
667
|
+
if (STATE.bridgeUp) { addCap(x, topY + 0.02, z, 1.75, 0.18, 1.75, R(-0.1, 0.1)); collider({ x, y: topY - 0.6, z, hx: 0.85, hy: 0.6, hz: 0.85, rotY: 0 }); }
|
|
668
|
+
}
|
|
669
|
+
// reeds, cattails and lilies
|
|
670
|
+
const reedM = new THREE.MeshStandardMaterial({ color: '#7a8a36', roughness: 0.9 });
|
|
671
|
+
const catM = new THREE.MeshStandardMaterial({ color: '#5a3a22', roughness: 0.9 });
|
|
672
|
+
const catGeo = new THREE.CapsuleGeometry(0.04, 0.2, 3, 6);
|
|
673
|
+
for (let i = 0; i < 140; i++) {
|
|
674
|
+
const a = R(0, Math.PI * 2), x = P.x + Math.cos(a) * R(4, 9), z = P.z + Math.sin(a) * R(3, 8);
|
|
675
|
+
const d = pondSDF(x, z);
|
|
676
|
+
if (d < -0.9 || d > 0.6 || Math.abs(z - P.z) < 1.6) continue;
|
|
677
|
+
const h = R(0.6, 1.5);
|
|
678
|
+
const r = new THREE.Mesh(new THREE.CylinderGeometry(0.012, 0.022, h, 4), reedM);
|
|
679
|
+
r.position.set(x, groundHeight(x, z) + h / 2, z); r.rotation.set(R(-0.18, 0.18), 0, R(-0.18, 0.18)); part.add(r);
|
|
680
|
+
if (rand() < 0.4) { const c = new THREE.Mesh(catGeo, catM); c.position.set(x, groundHeight(x, z) + h - 0.05, z); part.add(c); }
|
|
681
|
+
}
|
|
682
|
+
const padM = new THREE.MeshStandardMaterial({ color: '#4a6e2a', roughness: 0.7, side: THREE.DoubleSide });
|
|
683
|
+
const flowerM = new THREE.MeshStandardMaterial({ color: '#f4e4ee', emissive: '#ffd0e0', emissiveIntensity: 0.15 });
|
|
684
|
+
const flowerGeo = new THREE.SphereGeometry(0.07, 8, 6);
|
|
685
|
+
for (let i = 0; i < 40; i++) {
|
|
686
|
+
const x = P.x + R(-P.hx + 0.8, P.hx - 0.8), z = P.z + R(-P.hz + 0.8, P.hz - 0.8);
|
|
687
|
+
if (Math.abs(z - P.z) < 1.2) continue;
|
|
688
|
+
const m = new THREE.Mesh(new THREE.CircleGeometry(R(0.2, 0.36), 14, 0.3, Math.PI * 2 - 0.3), padM);
|
|
689
|
+
m.rotation.set(-Math.PI / 2, 0, R(0, 6)); m.position.set(x, -0.105, z); part.add(m);
|
|
690
|
+
if (rand() < 0.25) { const f = new THREE.Mesh(flowerGeo, flowerM); f.position.set(x, -0.07, z); f.scale.y = 0.6; part.add(f); }
|
|
691
|
+
}
|
|
692
|
+
lanternPost(P.x + P.hx - 0.6, P.z + 2.7, Math.PI / 2 - 0.3, { stoneBase: true });
|
|
693
|
+
lanternPost(P.x + P.hx - 1.6, P.z - 1.5, Math.PI / 2, { h: 1.7 });
|
|
694
|
+
lanternPost(P.x - P.hx - 0.9, P.z - 1.6, -Math.PI / 2, { stoneBase: true });
|
|
695
|
+
// the water: the cleanroom's Reflector shape, a Water now
|
|
696
|
+
const w = P.hx + 0.2, h = P.hz + 0.2, rr = P.r + 0.2;
|
|
697
|
+
const shape = new THREE.Shape();
|
|
698
|
+
shape.moveTo(-w + rr, -h); shape.lineTo(w - rr, -h); shape.quadraticCurveTo(w, -h, w, -h + rr); shape.lineTo(w, h - rr); shape.quadraticCurveTo(w, h, w - rr, h);
|
|
699
|
+
shape.lineTo(-w + rr, h); shape.quadraticCurveTo(-w, h, -w, h - rr); shape.lineTo(-w, -h + rr); shape.quadraticCurveTo(-w, -h, -w + rr, -h);
|
|
700
|
+
const water = new Water(shape, { tint: '#3a3458', reflect: 'planar' });
|
|
701
|
+
water.position.set(P.x, -0.12, P.z);
|
|
702
|
+
part.add(water);
|
|
703
|
+
k.flush();
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/** The arena (cleanroom world.js 699-813): a sunk checker floor, a mossy ring wall, a stone arch, rim braziers and the
|
|
707
|
+
* Barrow Warden, a hulking golem of mossy blocks in its idle pose. */
|
|
708
|
+
export function arena(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
709
|
+
const k = kit(part, 699, M, tex), { R, rand, stoneBlocks, addBlock, addCap, collider, drape, ivy, bracketLamp, capGeo } = k;
|
|
710
|
+
const { x: ax, z: az, r } = LAYOUT.ARENA;
|
|
711
|
+
const t = tex.checker?.clone();
|
|
712
|
+
if (t !== undefined) { t.repeat.set(r * 2 / 8, r * 2 / 8); t.needsUpdate = true; }
|
|
713
|
+
const floor = new THREE.Mesh(new THREE.CircleGeometry(r, 64), new THREE.MeshStandardMaterial({ map: t ?? null, roughness: 0.9 }));
|
|
714
|
+
floor.rotation.x = -Math.PI / 2; floor.position.set(ax, -0.34, az); floor.receiveShadow = true; part.add(floor);
|
|
715
|
+
const gateA = Math.PI; // the arch faces west, toward the yard
|
|
716
|
+
const n = 34;
|
|
717
|
+
for (let i = 0; i < n; i++) {
|
|
718
|
+
const a0 = (i / n) * Math.PI * 2, a1 = ((i + 1) / n) * Math.PI * 2, am = (a0 + a1) / 2;
|
|
719
|
+
const da = Math.atan2(Math.sin(am - gateA), Math.cos(am - gateA));
|
|
720
|
+
if (Math.abs(da) < 0.2) continue;
|
|
721
|
+
const x0 = ax + Math.cos(a0) * r, z0 = az + Math.sin(a0) * r, x1 = ax + Math.cos(a1) * r, z1 = az + Math.sin(a1) * r;
|
|
722
|
+
const len = Math.hypot(x1 - x0, z1 - z0), rot = Math.atan2(-(z1 - z0), x1 - x0), cx = (x0 + x1) / 2, cz = (z0 + z1) / 2;
|
|
723
|
+
for (let c = 0; c < 3; c++) addBlock(cx, -0.34 + c * 0.55 + 0.27, cz, len + 0.02, 0.52, 0.8, rot, R(0.78, 1.0));
|
|
724
|
+
addCap(cx, 1.36, cz, len + 0.12, 0.34, 1.0, rot);
|
|
725
|
+
drape(cx - Math.cos(am) * 0.52, 1.32, cz - Math.sin(am) * 0.52, len, rot, R(0.2, 0.55));
|
|
726
|
+
if (rand() < 0.35) ivy(cx - Math.cos(am) * 0.45, 1.3, cz - Math.sin(am) * 0.45, R(0.6, 1.4), rot);
|
|
727
|
+
collider({ x: cx, y: 0.5, z: cz, hx: len / 2, hy: 1.0, hz: 0.4, rotY: rot });
|
|
728
|
+
if (i % 6 === 3) decal(part, '8x8', cx - Math.cos(am) * 0.42, 0.5, cz - Math.sin(am) * 0.42, Math.atan2(-Math.cos(am), -Math.sin(am)), 1.0);
|
|
729
|
+
}
|
|
730
|
+
// the arch
|
|
731
|
+
const gx = LAYOUT.ARCH.x, gz = LAYOUT.ARCH.z;
|
|
732
|
+
for (const s of [-1, 1]) {
|
|
733
|
+
const pz = gz + s * 1.9;
|
|
734
|
+
for (let j = 0; j < 4; j++) addBlock(gx, j * 0.8 + 0.4, pz, 1.05, 0.76, 1.05, 0, R(0.8, 1.0));
|
|
735
|
+
collider({ x: gx, y: 1.6, z: pz, hx: 0.52, hy: 1.6, hz: 0.52, rotY: 0 });
|
|
736
|
+
bracketLamp(gx - 0.55, 2.4, pz, -Math.PI / 2, true);
|
|
737
|
+
}
|
|
738
|
+
const archCurve = new THREE.EllipseCurve(0, 0, 1.9, 1.35, 0, Math.PI);
|
|
739
|
+
for (let j = 0; j < 9; j++) {
|
|
740
|
+
const p = archCurve.getPoint((j + 0.5) / 9), p2 = archCurve.getPoint((j + 1) / 9), p1 = archCurve.getPoint(j / 9);
|
|
741
|
+
stoneBlocks.push({ x: gx, y: 3.2 + p.y, z: gz + p.x, sx: 1.0, sy: 0.7, sz: 0.72, rotY: 0, rotX: -Math.atan2(p2.y - p1.y, p2.x - p1.x), tint: R(0.8, 1.0) });
|
|
742
|
+
}
|
|
743
|
+
addCap(gx, 4.72, gz, 1.25, 0.42, 2.6);
|
|
744
|
+
for (const f of [-1, 1]) drape(gx + f * 0.55, 4.62, gz, 2.4, Math.PI / 2, 0.55);
|
|
745
|
+
for (let j = 0; j < 5; j++) ivy(gx - 0.56, 4.4, gz + R(-1.5, 1.5), R(0.6, 2.0), Math.PI / 2, 0.36);
|
|
746
|
+
// rim braziers on the far wall: A north, B east, C south; lit with their quest brazier
|
|
747
|
+
for (const [l, a] of [['A', -0.42], ['B', 0], ['C', 0.42]] as const) {
|
|
748
|
+
const bx = ax + Math.cos(a) * (r + 0.05), bz = az + Math.sin(a) * (r + 0.05);
|
|
749
|
+
const g = new THREE.Group();
|
|
750
|
+
const ped = new THREE.Mesh(new RoundedBoxGeometry(0.85, 0.5, 0.85, 2, 0.05), M.stone); ped.position.y = 0.25;
|
|
751
|
+
const bowl = new THREE.Mesh(new THREE.CylinderGeometry(0.48, 0.3, 0.32, 8), M.stone); bowl.position.y = 0.66;
|
|
752
|
+
g.add(ped, bowl); g.position.set(bx, 1.45, bz); part.add(g);
|
|
753
|
+
decal(part, l, bx - Math.cos(a) * 0.44, 1.7, bz - Math.sin(a) * 0.44, Math.atan2(-Math.cos(a), -Math.sin(a)), 0.4);
|
|
754
|
+
if (STATE.lit.includes(l)) k.fire(bx, 2.25, bz, 0.8);
|
|
755
|
+
}
|
|
756
|
+
// the Barrow Warden, idle: legs, hips, a torso with its core, a head with glowing eyes, arms hanging, moss on top
|
|
757
|
+
const golem = new THREE.Group();
|
|
758
|
+
const eyeM = new THREE.MeshBasicMaterial({ color: new THREE.Color('#ffb040').multiplyScalar(2.2) });
|
|
759
|
+
const coreM = new THREE.MeshBasicMaterial({ color: new THREE.Color('#ff9a30').multiplyScalar(1.2) });
|
|
760
|
+
const block = (w: number, h: number, d: number, x: number, y: number, z: number, parent: THREE.Object3D = golem): THREE.Mesh => {
|
|
761
|
+
const m = new THREE.Mesh(new RoundedBoxGeometry(w, h, d, 3, 0.12), M.stone); m.position.set(x, y, z); m.castShadow = true; m.receiveShadow = true; parent.add(m); return m;
|
|
762
|
+
};
|
|
763
|
+
const body = new THREE.Group(); golem.add(body);
|
|
764
|
+
for (const s of [-1, 1]) { block(0.75, 1.1, 0.8, s * 0.55, 0.55, 0); block(0.9, 0.35, 1.0, s * 0.55, 0.17, 0.08); }
|
|
765
|
+
body.position.y = 1.1;
|
|
766
|
+
block(1.5, 0.6, 1.0, 0, 0.3, 0, body); // hips
|
|
767
|
+
block(2.3, 1.5, 1.35, 0, 1.35, 0, body); // torso
|
|
768
|
+
const core = new THREE.Mesh(new THREE.OctahedronGeometry(0.22, 0), coreM); core.position.set(0, 1.35, 0.7); body.add(core);
|
|
769
|
+
block(0.95, 0.8, 0.9, 0, 2.5, 0.15, body); // head
|
|
770
|
+
for (const s of [-1, 1]) { const e = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.08, 0.03), eyeM); e.position.set(s * 0.2, 2.55, 0.61); body.add(e); }
|
|
771
|
+
const hm = new THREE.Mesh(capGeo, M.moss); hm.scale.set(1.05, 0.3, 1.0); hm.position.set(0, 2.92, 0.12); body.add(hm);
|
|
772
|
+
const sm = new THREE.Mesh(capGeo, M.moss); sm.scale.set(2.5, 0.32, 1.45); sm.position.set(0, 2.12, 0); body.add(sm);
|
|
773
|
+
for (const s of [-1, 1]) {
|
|
774
|
+
const sh = new THREE.Group(); sh.position.set(s * 1.45, 1.85, 0); body.add(sh);
|
|
775
|
+
const pm = new THREE.Mesh(capGeo, M.moss); pm.scale.set(0.95, 0.28, 0.95); pm.position.set(0, 0.42, 0); sh.add(pm);
|
|
776
|
+
block(0.85, 0.8, 0.85, 0, 0, 0, sh); block(0.65, 1.0, 0.65, 0, -0.85, 0, sh); block(0.9, 0.85, 0.9, 0, -1.75, 0.05, sh);
|
|
777
|
+
sh.rotation.set(0, 0, s * 0.12);
|
|
778
|
+
}
|
|
779
|
+
golem.position.set(ax, -0.34, az);
|
|
780
|
+
golem.rotation.y = -Math.PI / 2; // facing the arch (west)
|
|
781
|
+
golem.scale.setScalar(1.45);
|
|
782
|
+
part.add(golem);
|
|
783
|
+
// vines over the shoulders
|
|
784
|
+
for (let i = 0; i < 6; i++) { const z = R(-1.2, 1.2); ivy(ax - 1.05, 4.3, az + z * 1.3, R(1.0, 2.2), Math.PI / 2, 0.4); }
|
|
785
|
+
const eyeLight = new THREE.PointLight('#ffa040', 5, 6, 1.5); eyeLight.position.set(ax - 1.6, 3.8, az); part.add(eyeLight);
|
|
786
|
+
collider({ x: ax, y: 1.5, z: az, hx: 1.2, hy: 2.0, hz: 1.0, rotY: 0 });
|
|
787
|
+
k.flush();
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** Trees (cleanroom world.js 815-862): round toy trees, a bumpy vertex-coloured canopy ball on a tapered trunk. */
|
|
791
|
+
export function trees(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
792
|
+
const k = kit(part, 815, M, tex), { R } = k;
|
|
793
|
+
const spots: [number, number, number][] = [
|
|
794
|
+
[-8.2, -16.6, 1.0], [0.8, -21, 1.15], [-12.5, -21, 1.2], [6.5, -20.5, 1.05], [11, -16, 0.95], [-13, -12, 1.1],
|
|
795
|
+
[-7.8, 5.6, 0.9], [9.5, 5.5, 1.0], [-13.5, 8, 1.15], [-30, 9, 1.2], [-30, -8, 1.15], [-24.5, -10.5, 1.05],
|
|
796
|
+
[-14.5, 11.5, 1.0], [-34, 2, 1.3], [16, -9.5, 1.0], [16, 6, 1.1], [36, -12, 1.2], [37, 8, 1.15], [24, 10, 1.1],
|
|
797
|
+
[20, -15, 1.25], [3, 12, 1.2], [-4, 13, 1.1], [14, 14, 1.2], [-20, 13, 1.1], [-20, -13, 1.15],
|
|
798
|
+
];
|
|
799
|
+
for (let i = 0; i < 46; i++) { const a = R(0, Math.PI * 2), d = R(36, 72); spots.push([4 + Math.cos(a) * d, -2 + Math.sin(a) * d, R(1.1, 1.7)]); }
|
|
800
|
+
const trunkGeo = new THREE.CylinderGeometry(0.13, 0.2, 1, 7); trunkGeo.translate(0, 0.5, 0);
|
|
801
|
+
// a bumpy ball: big lumps plus small leafy bumps, smooth normals, sunlit crown and a darker underside
|
|
802
|
+
let core: THREE.BufferGeometry = new THREE.IcosahedronGeometry(1, 6);
|
|
803
|
+
core.deleteAttribute('normal'); core.deleteAttribute('uv'); core = mergeVertices(core);
|
|
804
|
+
const p = core.attributes.position, v = new THREE.Vector3();
|
|
805
|
+
if (p !== undefined) {
|
|
806
|
+
const c = new Float32Array(p.count * 3);
|
|
807
|
+
for (let i = 0; i < p.count; i++) {
|
|
808
|
+
v.fromBufferAttribute(p, i);
|
|
809
|
+
const big = noise.fbm(v.x * 1.6 + 5, v.z * 1.6 + v.y * 1.3 + 5, 2);
|
|
810
|
+
const lumps = 1 - Math.abs(noise(v.x * 5.5 + 11, v.y * 5.5 + v.z * 4.1 + 3) * 2 - 1); // ridged: rounded leaf clumps
|
|
811
|
+
const fine = noise(v.x * 16 + 1, v.y * 16 + v.z * 13);
|
|
812
|
+
v.multiplyScalar(0.9 + (big - 0.5) * 0.22 + lumps * 0.09 + fine * 0.025); v.y *= 0.94;
|
|
813
|
+
p.setXYZ(i, v.x, v.y, v.z);
|
|
814
|
+
const kk = 0.42 + 0.58 * sstep(v.y, -0.95, 0.85);
|
|
815
|
+
const leaf = 0.82 + lumps * 0.22 + (fine - 0.5) * 0.18;
|
|
816
|
+
c.set([0.19 * kk * leaf, 0.28 * kk * leaf, 0.06 * kk * leaf], i * 3); // linear
|
|
817
|
+
}
|
|
818
|
+
core.setAttribute('color', new THREE.BufferAttribute(c, 3)); core.computeVertexNormals();
|
|
819
|
+
}
|
|
820
|
+
const trunkM = new THREE.MeshStandardMaterial({ color: '#7a5638', map: tex.wood, roughness: 0.9 });
|
|
821
|
+
const coreM = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88 });
|
|
822
|
+
const tI = new THREE.InstancedMesh(trunkGeo, trunkM, spots.length);
|
|
823
|
+
const cI = new THREE.InstancedMesh(core, coreM, spots.length);
|
|
824
|
+
const o = new THREE.Object3D(), col = new THREE.Color();
|
|
825
|
+
spots.forEach(([x, z, s], i) => {
|
|
826
|
+
const gy = groundHeight(x, z), th = 2.1 * s;
|
|
827
|
+
o.position.set(x, gy, z); o.scale.set(s, th, s); o.rotation.set(0, R(0, 6), 0); o.updateMatrix(); tI.setMatrixAt(i, o.matrix);
|
|
828
|
+
o.position.set(x, gy + th + 0.85 * s, z); o.scale.setScalar(1.3 * s); o.updateMatrix(); cI.setMatrixAt(i, o.matrix);
|
|
829
|
+
col.setRGB(R(0.88, 1.08), R(0.92, 1.06), R(0.8, 1.0)); cI.setColorAt(i, col);
|
|
830
|
+
if (Math.hypot(x, z) < 45) k.collider({ x, y: gy + 1, z, hx: 0.22 * s, hy: 1, hz: 0.22 * s, rotY: 0 });
|
|
831
|
+
});
|
|
832
|
+
tI.castShadow = cI.castShadow = true; cI.receiveShadow = true;
|
|
833
|
+
part.add(tI, cI);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const BOULDERS: readonly [number, number, number][] = [[-6.2, -4.6, 0.75], [6.4, 3.4, 0.8], [-8.4, -11.2, 0.7], [10.6, -16.2, 0.8], [-8.8, 6.6, 0.7], [7.8, 5.8, 0.6],
|
|
837
|
+
[-6.8, -17, 0.55], [2.4, -16.8, 0.5], [LAYOUT.POND.x + LAYOUT.POND.hx + 2.4, LAYOUT.POND.z + 4.5, 0.8], [LAYOUT.POND.x - LAYOUT.POND.hx - 2.2, LAYOUT.POND.z - 4.6, 0.7], [13.8, 3.4, 0.6], [-3.6, 5.4, 0.45]];
|
|
838
|
+
|
|
839
|
+
/** Boulders (cleanroom world.js 864-889): mossy-topped rocks. */
|
|
840
|
+
export function boulders(part: THREE.Group, M: Materials, tex: Textures): void {
|
|
841
|
+
const k = kit(part, 864, M, tex), { R } = k;
|
|
842
|
+
let g: THREE.BufferGeometry = new THREE.IcosahedronGeometry(1, 3);
|
|
843
|
+
g.deleteAttribute('normal'); g.deleteAttribute('uv'); g = mergeVertices(g);
|
|
844
|
+
const p = g.attributes.position, v = new THREE.Vector3();
|
|
845
|
+
if (p !== undefined) {
|
|
846
|
+
const c = new Float32Array(p.count * 3);
|
|
847
|
+
for (let i = 0; i < p.count; i++) {
|
|
848
|
+
v.fromBufferAttribute(p, i);
|
|
849
|
+
v.multiplyScalar(1 + (noise.fbm(v.x * 2 + 3, v.y * 2 + v.z * 2, 3) - 0.5) * 0.5); v.y *= 0.72;
|
|
850
|
+
p.setXYZ(i, v.x, v.y, v.z);
|
|
851
|
+
const mossT = sstep(v.y + noise(v.x * 5, v.z * 5) * 0.4, 0.15, 0.45);
|
|
852
|
+
const s = 0.22 + noise(v.x * 12, v.z * 12 + v.y * 12) * 0.08;
|
|
853
|
+
const cc = new THREE.Color(s, s * 0.95, s * 0.86).lerp(new THREE.Color(0.09, 0.16, 0.035), mossT);
|
|
854
|
+
c.set([cc.r, cc.g, cc.b], i * 3);
|
|
855
|
+
}
|
|
856
|
+
g.setAttribute('color', new THREE.BufferAttribute(c, 3)); g.computeVertexNormals();
|
|
857
|
+
}
|
|
858
|
+
const m = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.95 });
|
|
859
|
+
for (const [x, z, s] of BOULDERS) {
|
|
860
|
+
const b = new THREE.Mesh(g, m);
|
|
861
|
+
b.position.set(x, groundHeight(x, z) + s * 0.22, z); b.scale.set(s * R(1.1, 1.5), s, s * R(0.9, 1.2)); b.rotation.y = R(0, 6);
|
|
862
|
+
b.castShadow = b.receiveShadow = true; part.add(b);
|
|
863
|
+
k.collider({ x, y: s * 0.4, z, hx: s * 0.9, hy: s * 0.6, hz: s * 0.9, rotY: 0 });
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/** Ferns, mushrooms and flowers (cleanroom world.js 891-936): ferns along the yard's edges, by the boulders and the hut. */
|
|
868
|
+
export function flora(part: THREE.Group, tex: Textures): void {
|
|
869
|
+
const rand = T.rng(891), R = (a: number, b: number): number => a + (b - a) * rand();
|
|
870
|
+
const Y = LAYOUT.YARD, G = LAYOUT.GATE;
|
|
871
|
+
const edge: [number, number][] = [];
|
|
872
|
+
for (let z = Y.z0 + 0.8; z < Y.z1 - 0.5; z += R(1.3, 2.8)) { if (Math.abs(z - G.z) > 2.6) edge.push([Y.x0 + 0.8, z]); if (Math.abs(z - LAYOUT.ARCH.z) > 2.6) edge.push([Y.x1 - 0.8, z]); }
|
|
873
|
+
for (let x = Y.x0 + 0.8; x < Y.x1 - 0.5; x += R(1.4, 3)) { edge.push([x, Y.z0 + 0.8]); edge.push([x, Y.z1 - 0.8]); }
|
|
874
|
+
const fernSpots: [number, number][] = [...edge, ...BOULDERS.map(([x, z]): [number, number] => [x + R(-0.8, 0.8), z + R(0.5, 1)]),
|
|
875
|
+
[-1.6, -12.4], [-6.8, -12.6], [-6.6, -12.0], [G.x + 1.0, G.z - 2.6], [G.x + 1.0, G.z + 2.6], [-2.2, -5.4], [3.1, -6.2], [1.6, -11.8]];
|
|
876
|
+
{
|
|
877
|
+
const fg = new THREE.PlaneGeometry(0.3, 1.05, 1, 6); fg.translate(0, 0.52, 0);
|
|
878
|
+
const p = fg.attributes.position;
|
|
879
|
+
if (p !== undefined) for (let i = 0; i < p.count; i++) { const y = p.getY(i); p.setZ(i, y * y * 0.55); p.setY(i, y * (1 - y * 0.25)); }
|
|
880
|
+
fg.computeVertexNormals();
|
|
881
|
+
const im = new THREE.InstancedMesh(fg, new THREE.MeshStandardMaterial({ map: tex.frond, alphaTest: 0.4, side: THREE.DoubleSide, roughness: 0.8 }), fernSpots.length * 9);
|
|
882
|
+
const o = new THREE.Object3D();
|
|
883
|
+
let k = 0;
|
|
884
|
+
for (const [x, z] of fernSpots) {
|
|
885
|
+
const s = R(0.75, 1.25);
|
|
886
|
+
for (let f = 0; f < 9; f++) {
|
|
887
|
+
o.position.set(x, groundHeight(x, z), z); o.rotation.set(0, (f / 9) * Math.PI * 2 + R(-0.2, 0.2), 0); o.rotateX(R(-0.55, -0.25));
|
|
888
|
+
o.scale.set(s, s * R(0.8, 1.1), s); o.updateMatrix(); im.setMatrixAt(k++, o.matrix);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
im.castShadow = true; part.add(animate(im, FOLIAGE_SWAY));
|
|
892
|
+
}
|
|
893
|
+
// mushrooms and flowers: the same small meshes, one shared geometry each (the cleanroom merged them per material)
|
|
894
|
+
const capGeo = new THREE.SphereGeometry(0.12, 12, 8, 0, Math.PI * 2, 0, Math.PI / 2);
|
|
895
|
+
const stemGeo = new THREE.CylinderGeometry(0.03, 0.04, 0.16, 6), dotGeo = new THREE.SphereGeometry(0.018, 5, 4);
|
|
896
|
+
const capM = new THREE.MeshStandardMaterial({ color: '#c8462a', roughness: 0.5 });
|
|
897
|
+
const stemM = new THREE.MeshStandardMaterial({ color: '#efe2c4', roughness: 0.8 });
|
|
898
|
+
const dotM = new THREE.MeshBasicMaterial({ color: '#f4ead8' });
|
|
899
|
+
const pick = (): [number, number] => fernSpots[Math.floor(rand() * fernSpots.length)] ?? [0, 0];
|
|
900
|
+
for (let i = 0; i < 60; i++) {
|
|
901
|
+
const b = pick();
|
|
902
|
+
const x = b[0] + R(-0.8, 0.8), z = b[1] + R(-0.8, 0.8), s = R(0.8, 1.7), y = groundHeight(x, z);
|
|
903
|
+
const st = new THREE.Mesh(stemGeo, stemM); st.position.set(x, y + 0.08 * s, z); st.scale.setScalar(s); part.add(st);
|
|
904
|
+
const cp = new THREE.Mesh(capGeo, capM); cp.position.set(x, y + 0.15 * s, z); cp.scale.set(s, s * 0.75, s); cp.castShadow = true; part.add(cp);
|
|
905
|
+
for (let d = 0; d < 3; d++) { const dt = new THREE.Mesh(dotGeo, dotM); const a = R(0, 6); dt.position.set(x + Math.cos(a) * 0.06 * s, y + 0.15 * s + 0.07 * s, z + Math.sin(a) * 0.06 * s); dt.scale.setScalar(s); part.add(dt); }
|
|
906
|
+
}
|
|
907
|
+
const flowerM = [new THREE.MeshStandardMaterial({ color: '#f2eedc' }), new THREE.MeshStandardMaterial({ color: '#e8c050' })];
|
|
908
|
+
const flowerGeo = new THREE.SphereGeometry(0.035, 6, 4);
|
|
909
|
+
for (let i = 0; i < 80; i++) {
|
|
910
|
+
const b = pick();
|
|
911
|
+
const x = b[0] + R(-1.4, 1.4), z = b[1] + R(-1.4, 1.4);
|
|
912
|
+
const f = new THREE.Mesh(flowerGeo, flowerM[i % 2]); f.position.set(x, groundHeight(x, z) + R(0.1, 0.2), z); part.add(f);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/** Grass (cleanroom world.js 937-959): 9,000 crossed cards within 62 m, off the hut, the pond, the arena and the path. */
|
|
917
|
+
export function grass(part: THREE.Group, tex: Textures): void {
|
|
918
|
+
const rand = T.rng(937), R = (a: number, b: number): number => a + (b - a) * rand();
|
|
919
|
+
const { slabs } = pathSlabs(), H = LAYOUT.HUT, doorZ = H.z + H.d / 2;
|
|
920
|
+
const card = new THREE.PlaneGeometry(0.38, 0.28); card.translate(0, 0.13, 0);
|
|
921
|
+
const cross = mergeGeometries([card, card.clone().rotateY(Math.PI / 2)]);
|
|
922
|
+
const nrm = cross.attributes.normal;
|
|
923
|
+
if (nrm !== undefined) for (let i = 0; i < nrm.count; i++) nrm.setXYZ(i, 0, 1, 0);
|
|
924
|
+
const N = 9000, im = new THREE.InstancedMesh(cross, new THREE.MeshStandardMaterial({ map: tex.grass, alphaTest: 0.35, side: THREE.DoubleSide, roughness: 0.9 }), N);
|
|
925
|
+
const o = new THREE.Object3D(), c = new THREE.Color();
|
|
926
|
+
const onSlab = (x: number, z: number): boolean => slabs.some((s) => Math.abs(s.x - x) < s.sx * 0.55 && Math.abs(s.z - z) < s.sx * 0.55);
|
|
927
|
+
let k = 0, tries = 0;
|
|
928
|
+
while (k < N && tries < N * 5) {
|
|
929
|
+
tries++;
|
|
930
|
+
const r = Math.sqrt(rand()) * 62, a = R(0, Math.PI * 2);
|
|
931
|
+
const x = Math.cos(a) * r + 2, z = Math.sin(a) * r - 2;
|
|
932
|
+
if (x > H.x - H.w / 2 - 0.3 && x < H.x + H.w / 2 + 0.3 && z < doorZ + 0.3 && z > H.z - H.d / 2 - 0.3) continue;
|
|
933
|
+
if (pondSDF(x, z) < 0.3) continue;
|
|
934
|
+
if (Math.hypot(x - LAYOUT.ARENA.x, z - LAYOUT.ARENA.z) < LAYOUT.ARENA.r + 0.6) continue;
|
|
935
|
+
if (noise.fbm(x * 0.25, z * 0.25, 2) < 0.42 && rand() < 0.75) continue;
|
|
936
|
+
if (r < 30 && onSlab(x, z)) continue;
|
|
937
|
+
o.position.set(x, groundHeight(x, z) - 0.02, z); o.rotation.set(0, R(0, Math.PI), 0); o.scale.setScalar(R(0.5, 1.1));
|
|
938
|
+
o.updateMatrix(); im.setMatrixAt(k, o.matrix); im.setColorAt(k, c.setRGB(R(0.82, 1.0), R(0.82, 1.0), R(0.62, 0.85)));
|
|
939
|
+
k++;
|
|
940
|
+
}
|
|
941
|
+
im.count = k; part.add(animate(im, FOLIAGE_SWAY));
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** Fireflies (cleanroom world.js 979-991): 160 seats over the hollow, each wandering 0.6 m round itself. */
|
|
945
|
+
export function fireflies(part: THREE.Group, tex: Textures): void {
|
|
946
|
+
const rand = T.rng(979), R = (a: number, b: number): number => a + (b - a) * rand();
|
|
947
|
+
const flies = new Float32Array(160 * 3);
|
|
948
|
+
for (let i = 0; i < 160; i++) flies.set([R(-30, 34), R(0.3, 2.4), R(-18, 10)], i * 3);
|
|
949
|
+
const cloud = new THREE.Points(new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(flies, 3)),
|
|
950
|
+
new THREE.PointsMaterial({ map: tex.glow, color: new THREE.Color('#ffd27a').multiplyScalar(2), size: 0.12, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }));
|
|
951
|
+
part.add(animate(cloud, drift({ rate: 0.3, radius: 0.6 })));
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/** The sunset light (cleanroom main.js 40-66): the painted sky, hemisphere, the key sun, the rim, the haze, the composer. */
|
|
955
|
+
export function sunset(world: ShardWorld): void {
|
|
956
|
+
// the sky dome (cleanroom sky.js) and the environment PMREM'd from it at 0.4 (main.js 63-70); under the skyline the
|
|
957
|
+
// cleanroom's environment sees the dome's haze, so the ground the engine filters with is that haze
|
|
958
|
+
const haze = new THREE.Color('#ffb878').multiplyScalar(0.92);
|
|
959
|
+
world.sky(sunsetSky(), { environment: { intensity: 0.4, ground: [haze.r, haze.g, haze.b] } });
|
|
960
|
+
world.scene.fog = new THREE.FogExp2(new THREE.Color('#d898a0'), 0.0062);
|
|
961
|
+
world.part('light', (part) => {
|
|
962
|
+
part.add(new THREE.HemisphereLight(new THREE.Color('#c4b0e4'), new THREE.Color('#7a6a3c'), 0.85));
|
|
963
|
+
const key = new THREE.DirectionalLight(new THREE.Color('#ffd6ae'), 2.2);
|
|
964
|
+
key.position.set(-26, 30, 34); key.castShadow = true;
|
|
965
|
+
part.add(key, key.target);
|
|
966
|
+
const rim = new THREE.DirectionalLight(new THREE.Color('#ff9a80'), 1.2);
|
|
967
|
+
rim.position.set(14, 5, -40);
|
|
968
|
+
part.add(rim);
|
|
969
|
+
});
|
|
970
|
+
world.post({ tone: 'aces', exposure: 1.05, bloom: { strength: 0.42, radius: 0.55, threshold: 0.9 }, vignette: 0.2 });
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/** Mossgate Hollow: the light, the ground and every section of the cleanroom, one part each. */
|
|
974
|
+
export function buildMossgate(world: ShardWorld): void {
|
|
975
|
+
// a fresh build (watch runs it on every save) makes its own shared materials
|
|
976
|
+
glowMats.clear(); decalMats.clear(); sparkMats.clear(); flameMat = null;
|
|
977
|
+
const { M, tex } = materials();
|
|
978
|
+
sunset(world);
|
|
979
|
+
// the cleanroom's ground mesh: MeshStandardMaterial({ map: moss, vertexColors: true, roughness: 0.97 }); its moss map's
|
|
980
|
+
// clumps (4 m a tile, blotches about a quarter metre across, fine speckle) as the PBR detail layer
|
|
981
|
+
world.ground(groundHeight, { colourAt: groundColour, material: new THREE.MeshStandardMaterial({ roughness: 0.97 }), detail: { scale: 0.35, mottle: 0.3, grain: 0.15, relief: 0.5 } });
|
|
982
|
+
world.part('walls', (part) => { walls(part, M, tex); });
|
|
983
|
+
world.part('district', (part) => { district(part); });
|
|
984
|
+
world.part('paths', (part) => { paths(part, M); });
|
|
985
|
+
world.part('braziers', (part) => { braziers(part, M, tex); });
|
|
986
|
+
world.part('hut', (part) => { hut(part, M, tex); });
|
|
987
|
+
world.part('sign', (part) => { signpost(part, M, tex); });
|
|
988
|
+
world.part('gate', (part) => { gate(part, M, tex); });
|
|
989
|
+
world.part('lamplighter', (part) => { lamplighter(part, M, tex); });
|
|
990
|
+
world.part('pond', (part) => { pond(part, M, tex); });
|
|
991
|
+
world.part('arena', (part) => { arena(part, M, tex); });
|
|
992
|
+
world.part('trees', (part) => { trees(part, M, tex); });
|
|
993
|
+
world.part('boulders', (part) => { boulders(part, M, tex); });
|
|
994
|
+
world.part('flora', (part) => { flora(part, tex); });
|
|
995
|
+
world.part('grass', (part) => { grass(part, tex); });
|
|
996
|
+
world.part('fireflies', (part) => { fireflies(part, tex); });
|
|
997
|
+
world.spawn(LAYOUT.SPAWN.x, 0, LAYOUT.SPAWN.z, LAYOUT.SPAWN.yaw);
|
|
998
|
+
}
|