@wildshard/sdk 0.2.13 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUIDE.md +16 -11
- package/bin/wildshard.mjs +2 -1
- package/docs/api/EXPORT-TIERS.md +12 -3
- package/lint/export-tiers.json +9 -0
- package/package.json +17 -5
- package/scripts/build-shardfiles.mjs +7 -2
- package/scripts/prepare-product.mjs +2 -2
- package/scripts/scratch-sweep.mjs +180 -0
- package/scripts/wildshard.mjs +1 -1
- package/skills/wildshard-mockup-to-model/SKILL.md +5 -3
- package/skills/wildshard-upgrade/SKILL.md +4 -4
- package/src/cli/help.ts +9 -5
- package/src/cli/upload/validate.ts +7 -5
- package/src/sharddev/assets.ts +1 -1
- package/src/sharddev/bake/compactGlb.ts +1 -1
- package/src/sharddev/bake/glbCompression.ts +1 -1
- package/src/sharddev/bake/gltfSource.ts +1 -1
- package/src/sharddev/bake/placeholders.ts +1 -1
- package/src/sharddev/bake/terrain.ts +1 -1
- package/src/sharddev/blobBytes.ts +1 -1
- package/src/sharddev/blobs.ts +2 -2
- package/src/sharddev/cli.ts +17 -4
- package/src/sharddev/formatJsonSchema.ts +1 -1
- package/src/sharddev/materialGraphFiles.ts +1 -1
- package/src/sharddev/newProject.ts +18 -10
- package/src/sharddev/outputProduct.ts +2 -2
- package/src/sharddev/productOutput.ts +2 -2
- package/src/sharddev/project.ts +1 -1
- package/src/sharddev/projectMap.ts +1 -1
- package/src/sharddev/refusals.ts +4 -2
- package/src/sharddev/reportCard.ts +1 -1
- package/src/sharddev/scene/author.ts +79 -0
- package/src/sharddev/scene/canvas.ts +213 -0
- package/src/sharddev/scene/description.ts +170 -0
- package/src/sharddev/scene/hash.ts +23 -0
- package/src/sharddev/scene/lower.ts +226 -0
- package/src/sharddev/scene/shard.ts +38 -0
- package/src/sharddev/scene/shardfile.ts +328 -0
- package/src/sharddev/threeGate.mjs +14 -0
- package/src/sharddev/threePin.mjs +40 -0
- package/src/sharddev/watch/page.ts +197 -0
- package/src/sharddev/watch/pageEntry.ts +23 -0
- package/src/sharddev/watch/proof.mjs +92 -0
- package/src/sharddev/watch/protocol.ts +108 -0
- package/src/sharddev/watch/socket.ts +57 -0
- package/src/sharddev/watch/watch.ts +209 -0
- package/src/shards/authoring-slice/generators/shard.ts +6 -0
- package/src/shards/authoring-slice/generators/textures.ts +173 -0
- package/src/shards/authoring-slice/generators/world.ts +415 -0
- package/src/shards/authoring-slice/shard.config.ts +7 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Procedural textures, ported from the Mossgate cleanroom (mossgate-cleanroom eac5bb8 src/textures.js). The painters are the
|
|
2
|
+
// cleanroom's own lines; only `canvas()` / `new CanvasTexture(c)` became `paint` / `paintCanvas`, which run at compile time.
|
|
3
|
+
import type { DataTexture } from 'three';
|
|
4
|
+
import { paint } from '@wildshard/sdk/scene/author';
|
|
5
|
+
import { paintCanvas, type PaintContext } from '@wildshard/sdk/scene/canvas';
|
|
6
|
+
|
|
7
|
+
export function rng(seed = 1): () => number {
|
|
8
|
+
let s = seed >>> 0;
|
|
9
|
+
return () => {
|
|
10
|
+
s = (s + 0x6d2b79f5) >>> 0;
|
|
11
|
+
let t = s;
|
|
12
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
13
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
14
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Noise { (x: number, y: number): number; fbm: (x: number, y: number, oct?: number) => number }
|
|
19
|
+
// Smooth value noise, 2D, tileable over `period`.
|
|
20
|
+
export function makeNoise(seed = 7): Noise {
|
|
21
|
+
const r = rng(seed);
|
|
22
|
+
const N = 256;
|
|
23
|
+
const g = new Float32Array(N * N);
|
|
24
|
+
for (let i = 0; i < g.length; i++) g[i] = r();
|
|
25
|
+
const at = (x: number, y: number): number => g[((y & (N - 1)) * N) + (x & (N - 1))] ?? 0;
|
|
26
|
+
const sm = (t: number): number => t * t * (3 - 2 * t);
|
|
27
|
+
const n = (x: number, y: number): number => {
|
|
28
|
+
const xi = Math.floor(x), yi = Math.floor(y);
|
|
29
|
+
const xf = sm(x - xi), yf = sm(y - yi);
|
|
30
|
+
const a = at(xi, yi), b = at(xi + 1, yi), c = at(xi, yi + 1), d = at(xi + 1, yi + 1);
|
|
31
|
+
return a + (b - a) * xf + (c - a) * yf + (a - b - c + d) * xf * yf;
|
|
32
|
+
};
|
|
33
|
+
const fbm = (x: number, y: number, oct = 4): number => {
|
|
34
|
+
let s = 0, amp = 0.5, f = 1;
|
|
35
|
+
for (let i = 0; i < oct; i++) { s += amp * n(x * f, y * f); amp *= 0.5; f *= 2; }
|
|
36
|
+
return s;
|
|
37
|
+
};
|
|
38
|
+
return Object.assign(n, { fbm });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type Rgb = [number, number, number];
|
|
42
|
+
const mix = (a: number, b: number, t: number): number => a + (b - a) * t;
|
|
43
|
+
const mix3 = (a: readonly number[], b: readonly number[], t: number): Rgb => [mix(a[0] ?? 0, b[0] ?? 0, t), mix(a[1] ?? 0, b[1] ?? 0, t), mix(a[2] ?? 0, b[2] ?? 0, t)];
|
|
44
|
+
const clamp = (v: number, lo = 0, hi = 1): number => Math.max(lo, Math.min(hi, v));
|
|
45
|
+
|
|
46
|
+
// Weathered warm-grey stone with moss blotches and edge darkening.
|
|
47
|
+
export function stone(seed = 3, { moss = 0.35 } = {}): DataTexture {
|
|
48
|
+
const n = makeNoise(seed);
|
|
49
|
+
const S = 512;
|
|
50
|
+
const g1 = [106, 102, 94], g2 = [150, 145, 134], mossC = [84, 104, 38];
|
|
51
|
+
return paint(S, S, (u, v) => {
|
|
52
|
+
const a = n.fbm(u * 8, v * 8, 5);
|
|
53
|
+
const sp = n(u * 120, v * 120);
|
|
54
|
+
let col = mix3(g1, g2, clamp(a * 1.6 - 0.3));
|
|
55
|
+
col = col.map((x) => x * (0.85 + sp * 0.25)) as Rgb;
|
|
56
|
+
// cracks
|
|
57
|
+
const cr = Math.abs(n.fbm(u * 6 + 5, v * 6 + 2, 3) - 0.5);
|
|
58
|
+
if (cr < 0.012) col = col.map((x) => x * 0.6) as Rgb;
|
|
59
|
+
// moss: favours the top of a face (v small)
|
|
60
|
+
const m = n.fbm(u * 10 + 3, v * 10 + 7, 4) + (1 - v) * 0.25 * moss * 2;
|
|
61
|
+
const t = clamp((m - (1 - moss)) * 6);
|
|
62
|
+
col = mix3(col, mossC.map((x) => x * (0.8 + sp * 0.4)), t);
|
|
63
|
+
// edge darkening for bevel read
|
|
64
|
+
const e = Math.min(u, v, 1 - u, 1 - v);
|
|
65
|
+
const ed = clamp(e * 18, 0.7, 1);
|
|
66
|
+
return col.map((x) => x * ed);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Flat slab stone for the path: lighter, pink-grey, no moss on top.
|
|
71
|
+
export function slab(): DataTexture {
|
|
72
|
+
const n = makeNoise(21);
|
|
73
|
+
const S = 256;
|
|
74
|
+
return paint(S, S, (u, v) => {
|
|
75
|
+
const a = n.fbm(u * 6, v * 6, 4);
|
|
76
|
+
const sp = n(u * 90, v * 90);
|
|
77
|
+
const col = mix3([126, 120, 110], [164, 156, 142], clamp(a * 1.5 - 0.2));
|
|
78
|
+
const e = Math.min(u, v, 1 - u, 1 - v);
|
|
79
|
+
const ed = clamp(e * 14, 0.72, 1);
|
|
80
|
+
return col.map((x) => x * (0.88 + sp * 0.2) * ed);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function wood(): DataTexture {
|
|
85
|
+
const n = makeNoise(5);
|
|
86
|
+
const S = 256;
|
|
87
|
+
return paint(S, S, (u, v) => {
|
|
88
|
+
const grain = n(u * 4, v * 60) * 0.6 + n(u * 2, v * 140) * 0.4;
|
|
89
|
+
return mix3([84, 58, 38], [138, 98, 62], grain);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function shingle(): DataTexture {
|
|
94
|
+
const n = makeNoise(9);
|
|
95
|
+
const S = 256;
|
|
96
|
+
return paint(S, S, (u, v) => {
|
|
97
|
+
const a = n.fbm(u * 8, v * 8, 4);
|
|
98
|
+
const sp = n(u * 100, v * 100);
|
|
99
|
+
let col = mix3([104, 96, 78], [128, 120, 96], a);
|
|
100
|
+
col = mix3(col, [112, 130, 50], clamp((n.fbm(u * 5 + 3, v * 5, 3) - 0.5) * 3));
|
|
101
|
+
return col.map((x) => x * (0.85 + sp * 0.3));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Painted floor/wall stencil ("A", "3x3"), white on transparent.
|
|
106
|
+
export function stencil(text: string, { w = 256, h = 128, font = 'bold 96px monospace', alpha = 0.75 } = {}): DataTexture {
|
|
107
|
+
return paintCanvas(w, h, (ctx) => {
|
|
108
|
+
ctx.clearRect(0, 0, w, h);
|
|
109
|
+
ctx.fillStyle = `rgba(235,228,214,${alpha})`;
|
|
110
|
+
ctx.font = font;
|
|
111
|
+
ctx.textAlign = 'center';
|
|
112
|
+
ctx.textBaseline = 'middle';
|
|
113
|
+
ctx.fillText(text, w / 2, h / 2 + 4);
|
|
114
|
+
// scuff it
|
|
115
|
+
const r = rng(text.length * 31);
|
|
116
|
+
ctx.globalCompositeOperation = 'destination-out';
|
|
117
|
+
for (let i = 0; i < 260; i++) {
|
|
118
|
+
ctx.fillStyle = `rgba(0,0,0,${r() * 0.6})`;
|
|
119
|
+
ctx.fillRect(r() * w, r() * h, 1 + r() * 4, 1 + r() * 3);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Soft round glow sprite.
|
|
125
|
+
export function glow(): DataTexture {
|
|
126
|
+
return paintCanvas(128, 128, (ctx) => {
|
|
127
|
+
const g = ctx.createRadialGradient(64, 64, 0, 64, 64, 64);
|
|
128
|
+
g.addColorStop(0, 'rgba(255,240,200,1)');
|
|
129
|
+
g.addColorStop(0.25, 'rgba(255,190,90,0.6)');
|
|
130
|
+
g.addColorStop(1, 'rgba(255,140,40,0)');
|
|
131
|
+
ctx.fillStyle = g;
|
|
132
|
+
ctx.fillRect(0, 0, 128, 128);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Ivy strand: a wavy stem with heart-shaped leaves, top to bottom.
|
|
137
|
+
export function ivy(): DataTexture {
|
|
138
|
+
return paintCanvas(128, 512, (ctx: PaintContext) => {
|
|
139
|
+
ctx.clearRect(0, 0, 128, 512);
|
|
140
|
+
const r = rng(13);
|
|
141
|
+
ctx.strokeStyle = '#4a5a22'; ctx.lineWidth = 3;
|
|
142
|
+
ctx.beginPath(); ctx.moveTo(64, 0);
|
|
143
|
+
for (let y = 0; y <= 512; y += 16) ctx.lineTo(64 + Math.sin(y / 40) * 14, y);
|
|
144
|
+
ctx.stroke();
|
|
145
|
+
for (let y = 8; y < 500; y += 13) {
|
|
146
|
+
const x = 64 + Math.sin(y / 40) * 14, s = r() < 0.5 ? -1 : 1, sz = 10 + r() * 9 - y / 120;
|
|
147
|
+
const l = 0.7 + r() * 0.4;
|
|
148
|
+
ctx.fillStyle = `rgb(${Math.round(92 * l)},${Math.round(128 * l)},${Math.round(40 * l)})`;
|
|
149
|
+
ctx.save(); ctx.translate(x + s * sz * 0.8, y); ctx.rotate(s * (0.4 + r() * 0.6));
|
|
150
|
+
ctx.beginPath(); ctx.moveTo(0, -sz * 0.2);
|
|
151
|
+
ctx.bezierCurveTo(sz, -sz, sz * 1.1, sz * 0.4, 0, sz); ctx.bezierCurveTo(-sz * 1.1, sz * 0.4, -sz, -sz, 0, -sz * 0.2);
|
|
152
|
+
ctx.fill(); ctx.restore();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Hanging moss: shaggy strands, dense at the top, thinning to wisps.
|
|
158
|
+
export function hangingMoss(): DataTexture {
|
|
159
|
+
return paintCanvas(256, 256, (ctx) => {
|
|
160
|
+
ctx.clearRect(0, 0, 256, 256);
|
|
161
|
+
const r = rng(29);
|
|
162
|
+
for (let i = 0; i < 90; i++) {
|
|
163
|
+
const x = r() * 256, len = 40 + r() * 200 * r(), w = 3 + r() * 6;
|
|
164
|
+
const l = 0.75 + r() * 0.35;
|
|
165
|
+
const g = ctx.createLinearGradient(0, 0, 0, len);
|
|
166
|
+
g.addColorStop(0, `rgba(${Math.round(98 * l)},${Math.round(118 * l)},${Math.round(40 * l)},1)`);
|
|
167
|
+
g.addColorStop(1, `rgba(${Math.round(130 * l)},${Math.round(142 * l)},${Math.round(60 * l)},0)`);
|
|
168
|
+
ctx.fillStyle = g;
|
|
169
|
+
ctx.beginPath(); ctx.moveTo(x - w, 0); ctx.quadraticCurveTo(x + (r() - 0.5) * 10, len * 0.6, x + (r() - 0.5) * 8, len); ctx.lineTo(x + w, 0); ctx.fill();
|
|
170
|
+
}
|
|
171
|
+
ctx.fillStyle = 'rgb(84,104,36)'; ctx.fillRect(0, 0, 256, 10);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
// The Mossgate hut, pond and lamps as three.js source (AUTHORING-PARITY AP7), ported from the cleanroom's
|
|
2
|
+
// src/world.js and src/main.js (mossgate-cleanroom eac5bb8). The geometry, materials and lights are the cleanroom's own
|
|
3
|
+
// lines. What changed: each block is a `world.part`, colliders are `solid(mesh)` beside the mesh instead of hand-typed
|
|
4
|
+
// boxes, the pond's Reflector is a `Water`, the canvas painters run at compile time, and each part draws from its own
|
|
5
|
+
// seeded stream, so editing the hut never reshuffles the pond.
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry.js';
|
|
8
|
+
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
9
|
+
import { solid, Water, type ShardWorld } from '@wildshard/sdk/scene/author';
|
|
10
|
+
import * as T from './textures';
|
|
11
|
+
|
|
12
|
+
export const LAYOUT = {
|
|
13
|
+
SPAWN: { x: 0, z: 0, yaw: 0 },
|
|
14
|
+
HUT: { x: -4.0, z: -14.0, w: 5.2, d: 4.6, h: 2.5 }, // door face at z + d/2
|
|
15
|
+
POND: { x: -19.4, z: 0, hx: 6.6, hz: 5.4, r: 2.2 },
|
|
16
|
+
ARENA: { x: 25.5, z: -2, r: 9.5 },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const noise = T.makeNoise(99);
|
|
20
|
+
const sstep = THREE.MathUtils.smoothstep;
|
|
21
|
+
|
|
22
|
+
/** Signed distance to the pond's rounded rectangle (negative inside). */
|
|
23
|
+
export function pondSDF(x: number, z: number): number {
|
|
24
|
+
const { x: px, z: pz, hx, hz, r } = LAYOUT.POND;
|
|
25
|
+
const qx = Math.abs(x - px) - hx + r, qz = Math.abs(z - pz) - hz + r;
|
|
26
|
+
return Math.hypot(Math.max(qx, 0), Math.max(qz, 0)) + Math.min(Math.max(qx, qz), 0) - r;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function groundHeight(x: number, z: number): number {
|
|
30
|
+
let y = 0;
|
|
31
|
+
const dp = pondSDF(x, z);
|
|
32
|
+
if (dp < 0.6) y -= 1.1 * (1 - sstep(dp, -1.6, 0.6));
|
|
33
|
+
const da = Math.hypot(x - LAYOUT.ARENA.x, z - LAYOUT.ARENA.z);
|
|
34
|
+
if (da < LAYOUT.ARENA.r) y -= 0.35;
|
|
35
|
+
// the cell edge stays at road height for the four entryways (the cleanroom had no edge)
|
|
36
|
+
const far = sstep(Math.hypot(x - 4, z + 2), 48, 95) * (1 - sstep(Math.hypot(x, z), 170, 230));
|
|
37
|
+
y += far * (noise.fbm(x * 0.02 + 50, z * 0.02 + 50, 3) - 0.35) * 7;
|
|
38
|
+
return y;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The moss floor's colour, as the cleanroom's ground vertex colours times its moss texture's mean. */
|
|
42
|
+
export function groundColour(x: number, z: number): [number, number, number] {
|
|
43
|
+
const v = noise.fbm(x * 0.07, z * 0.07, 4), w = noise.fbm(x * 0.018 + 9, z * 0.018 + 4, 3);
|
|
44
|
+
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);
|
|
45
|
+
const dp = pondSDF(x, z);
|
|
46
|
+
if (dp < 0.9) c.lerp(new THREE.Color(0.42, 0.38, 0.3), 1 - sstep(dp, -0.4, 0.9));
|
|
47
|
+
const moss = new THREE.Color().setRGB(102 / 255, 120 / 255, 48 / 255, THREE.SRGBColorSpace);
|
|
48
|
+
return [c.r * moss.r, c.g * moss.g, c.b * moss.b];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The textures and materials every part shares (`buildWorld`'s `tex` and `M`). */
|
|
52
|
+
function materials(): { M: Record<string, THREE.MeshStandardMaterial>; tex: Record<string, THREE.Texture> } {
|
|
53
|
+
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(), glow: T.glow(), ivy: T.ivy(), drape: T.hangingMoss() };
|
|
54
|
+
const M = {
|
|
55
|
+
stone: new THREE.MeshStandardMaterial({ map: tex.stone, roughness: 0.93 }),
|
|
56
|
+
stoneClean: new THREE.MeshStandardMaterial({ map: tex.stoneClean, roughness: 0.9 }),
|
|
57
|
+
slab: new THREE.MeshStandardMaterial({ map: tex.slab, roughness: 0.88 }),
|
|
58
|
+
wood: new THREE.MeshStandardMaterial({ map: tex.wood, roughness: 0.78 }),
|
|
59
|
+
darkWood: new THREE.MeshStandardMaterial({ map: tex.wood, color: '#8a6a52', roughness: 0.82 }),
|
|
60
|
+
shingle: new THREE.MeshStandardMaterial({ name: 'roof', map: tex.shingle, roughness: 0.95 }),
|
|
61
|
+
moss: new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 }),
|
|
62
|
+
iron: new THREE.MeshStandardMaterial({ color: '#3a302a', roughness: 0.5, metalness: 0.6 }),
|
|
63
|
+
bronze: new THREE.MeshStandardMaterial({ color: '#7a5634', roughness: 0.45, metalness: 0.7 }),
|
|
64
|
+
lampGlass: new THREE.MeshStandardMaterial({ color: '#ffc061', emissive: '#ffa73a', emissiveIntensity: 2.6, roughness: 0.3 }),
|
|
65
|
+
ivy: new THREE.MeshStandardMaterial({ map: tex.ivy, alphaTest: 0.45, side: THREE.DoubleSide, roughness: 0.85 }),
|
|
66
|
+
drape: new THREE.MeshStandardMaterial({ map: tex.drape, alphaTest: 0.35, side: THREE.DoubleSide, roughness: 1 }),
|
|
67
|
+
cloth: new THREE.MeshStandardMaterial({ color: '#8a3a2a', roughness: 0.95 }),
|
|
68
|
+
};
|
|
69
|
+
return { M, tex };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface Block { x: number; y: number; z: number; sx: number; sy: number; sz: number; rotY: number; tint: number }
|
|
73
|
+
/** One part's builders: the cleanroom's accumulators (`addBlock`, `addCap`, `drape`, `ivy`) and its lamp helpers. */
|
|
74
|
+
function kit(part: THREE.Group, seed: number, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>) {
|
|
75
|
+
const rand = T.rng(seed);
|
|
76
|
+
const R = (a: number, b: number): number => a + (b - a) * rand();
|
|
77
|
+
const blockGeo = new RoundedBoxGeometry(1, 1, 1, 3, 0.07);
|
|
78
|
+
const capGeo = (() => {
|
|
79
|
+
const g = new RoundedBoxGeometry(1, 1, 1, 7, 0.38);
|
|
80
|
+
const p = g.attributes.position;
|
|
81
|
+
const c = new Float32Array(p.count * 3);
|
|
82
|
+
for (let i = 0; i < p.count; i++) {
|
|
83
|
+
const x = p.getX(i), y = p.getY(i), z = p.getZ(i);
|
|
84
|
+
const n = noise(x * 7 + 10, z * 7 + 10), n2 = noise(x * 19 + 3, z * 19 + y * 9);
|
|
85
|
+
if (y > 0) p.setY(i, y + (n - 0.5) * 0.4 + (n2 - 0.5) * 0.12);
|
|
86
|
+
else p.setY(i, y - n * 0.45);
|
|
87
|
+
const k = 0.72 + n * 0.42 + (n2 - 0.5) * 0.18;
|
|
88
|
+
const top = y > 0 ? 1 : 0.62;
|
|
89
|
+
c.set([0.085 * k * top, 0.16 * k * top, 0.034 * k * top], i * 3); // linear: olive moss
|
|
90
|
+
}
|
|
91
|
+
g.setAttribute('color', new THREE.BufferAttribute(c, 3));
|
|
92
|
+
g.computeVertexNormals();
|
|
93
|
+
return g;
|
|
94
|
+
})();
|
|
95
|
+
const stoneBlocks: Block[] = [], caps: Omit<Block, 'tint'>[] = [], drapeGeos: THREE.BufferGeometry[] = [], ivyGeos: THREE.BufferGeometry[] = [];
|
|
96
|
+
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 }); };
|
|
97
|
+
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 }); };
|
|
98
|
+
function drape(x: number, y: number, z: number, len: number, rotY: number, h = 0.45): void {
|
|
99
|
+
const g = new THREE.PlaneGeometry(len, h, Math.max(1, Math.round(len * 3)), 2);
|
|
100
|
+
g.translate(0, -h / 2, 0);
|
|
101
|
+
const p = g.attributes.position, uv = g.attributes.uv;
|
|
102
|
+
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)); }
|
|
103
|
+
g.rotateY(rotY); g.translate(x, y, z);
|
|
104
|
+
drapeGeos.push(g);
|
|
105
|
+
}
|
|
106
|
+
function ivy(x: number, y: number, z: number, len: number, rotY: number, w = 0.32): void {
|
|
107
|
+
const g = new THREE.PlaneGeometry(w, len, 1, 5);
|
|
108
|
+
g.translate(0, -len / 2, 0);
|
|
109
|
+
const p = g.attributes.position;
|
|
110
|
+
for (let i = 0; i < p.count; i++) p.setZ(i, Math.sin(p.getY(i) * 2.2 + x) * 0.03);
|
|
111
|
+
g.rotateY(rotY); g.translate(x, y, z);
|
|
112
|
+
ivyGeos.push(g);
|
|
113
|
+
}
|
|
114
|
+
function lantern(x: number, y: number, z: number, { on = true, scale = 1, light = true } = {}): THREE.Group {
|
|
115
|
+
const g = new THREE.Group();
|
|
116
|
+
const glass = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.26, 0.2), on ? M.lampGlass : M.iron);
|
|
117
|
+
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;
|
|
118
|
+
const base = new THREE.Mesh(new THREE.BoxGeometry(0.27, 0.05, 0.27), M.iron); base.position.y = -0.155;
|
|
119
|
+
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.05, 0.012, 6, 12), M.iron); ring.position.y = 0.33;
|
|
120
|
+
g.add(glass, cap, base, ring);
|
|
121
|
+
for (const [bx, bz] of [[-1, -1], [1, -1], [-1, 1], [1, 1]] as const) {
|
|
122
|
+
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);
|
|
123
|
+
}
|
|
124
|
+
g.position.set(x, y, z); g.scale.setScalar(scale);
|
|
125
|
+
part.add(g);
|
|
126
|
+
if (on) {
|
|
127
|
+
if (light) {
|
|
128
|
+
const l = new THREE.PointLight('#ffa850', 3.4 * scale, 6, 1.7);
|
|
129
|
+
l.position.set(x, y, z); part.add(l);
|
|
130
|
+
}
|
|
131
|
+
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex.glow, color: '#ffb466', blending: THREE.AdditiveBlending, depthWrite: false, transparent: true, opacity: 0.5, fog: false }));
|
|
132
|
+
s.scale.setScalar(1.1 * scale); s.position.set(x, y, z); part.add(s);
|
|
133
|
+
}
|
|
134
|
+
return g;
|
|
135
|
+
}
|
|
136
|
+
// A gallows post: a squared timber with an arm, a rope and a hanging lantern.
|
|
137
|
+
function lanternPost(x: number, z: number, rotY = 0, { h = 2.7, on = true, stoneBase = false } = {}): void {
|
|
138
|
+
const gy = groundHeight(x, z);
|
|
139
|
+
const ax = Math.sin(rotY), az = Math.cos(rotY);
|
|
140
|
+
if (stoneBase) {
|
|
141
|
+
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);
|
|
142
|
+
addCap(x, gy + 0.72, z, 0.66, 0.16, 0.66);
|
|
143
|
+
}
|
|
144
|
+
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(solid(p));
|
|
145
|
+
const arm = new THREE.Mesh(new THREE.BoxGeometry(0.14, 0.14, 0.95), M.wood);
|
|
146
|
+
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);
|
|
147
|
+
const brace = new THREE.Mesh(new THREE.BoxGeometry(0.09, 0.09, 0.55), M.wood);
|
|
148
|
+
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);
|
|
149
|
+
const lx = x + ax * 0.74, lz = z + az * 0.74;
|
|
150
|
+
const rope = new THREE.Mesh(new THREE.CylinderGeometry(0.018, 0.018, 0.42, 5), new THREE.MeshStandardMaterial({ color: '#b8925a', roughness: 0.9 }));
|
|
151
|
+
rope.position.set(lx, gy + h - 0.4, lz); part.add(rope);
|
|
152
|
+
const coil = new THREE.Mesh(new THREE.TorusGeometry(0.07, 0.03, 6, 12), rope.material); coil.position.set(lx, gy + h - 0.12, lz); coil.rotation.y = rotY; part.add(coil);
|
|
153
|
+
lantern(lx, gy + h - 0.82, lz, { on, scale: 1.25 });
|
|
154
|
+
}
|
|
155
|
+
// A wall bracket lamp: an iron arm out of a stone face.
|
|
156
|
+
function bracketLamp(x: number, y: number, z: number, rotY: number, on = true): void {
|
|
157
|
+
const ax = Math.sin(rotY), az = Math.cos(rotY);
|
|
158
|
+
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);
|
|
159
|
+
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);
|
|
160
|
+
lantern(x + ax * 0.44, y, z + az * 0.44, { on, scale: 1.05 });
|
|
161
|
+
}
|
|
162
|
+
// flush instanced stone, caps, drapes and ivy into the part
|
|
163
|
+
function flush(): void {
|
|
164
|
+
const im = new THREE.InstancedMesh(blockGeo, M.stone, stoneBlocks.length);
|
|
165
|
+
const o = new THREE.Object3D(), c = new THREE.Color();
|
|
166
|
+
stoneBlocks.forEach((b, i) => {
|
|
167
|
+
o.position.set(b.x, b.y, b.z); o.rotation.set(0, b.rotY, 0, 'YXZ'); o.scale.set(b.sx, b.sy, b.sz); o.updateMatrix();
|
|
168
|
+
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)));
|
|
169
|
+
});
|
|
170
|
+
im.castShadow = im.receiveShadow = true; if (stoneBlocks.length > 0) part.add(im);
|
|
171
|
+
const cm = new THREE.InstancedMesh(capGeo, M.moss, caps.length);
|
|
172
|
+
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); });
|
|
173
|
+
cm.castShadow = cm.receiveShadow = true; if (caps.length > 0) part.add(cm);
|
|
174
|
+
if (drapeGeos.length > 0) { const d = new THREE.Mesh(mergeGeometries(drapeGeos), M.drape); d.castShadow = true; part.add(d); }
|
|
175
|
+
if (ivyGeos.length > 0) part.add(new THREE.Mesh(mergeGeometries(ivyGeos), M.ivy));
|
|
176
|
+
}
|
|
177
|
+
return { rand, R, addBlock, addCap, drape, ivy, lantern, lanternPost, bracketLamp, flush };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function decal(part: THREE.Group, text: string, x: number, y: number, z: number, rotY: number, size = 1, floor = false): THREE.Mesh {
|
|
181
|
+
const m = new THREE.Mesh(new THREE.PlaneGeometry(size, size / 2), new THREE.MeshStandardMaterial({ map: T.stencil(text), transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, roughness: 0.9 }));
|
|
182
|
+
m.position.set(x, y, z);
|
|
183
|
+
if (floor) m.rotation.set(-Math.PI / 2, 0, rotY); else m.rotation.y = rotY;
|
|
184
|
+
m.receiveShadow = true;
|
|
185
|
+
part.add(m);
|
|
186
|
+
return m;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The hut (cleanroom world.js 398-530): coursed walls, gables, a shingle roof, door, sign, bracket lamp and the room. */
|
|
190
|
+
export function hut(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>): void {
|
|
191
|
+
const { R, addBlock, addCap, drape, ivy, lantern, bracketLamp, flush, rand } = kit(part, 398, M, tex);
|
|
192
|
+
const H = LAYOUT.HUT, doorZ = H.z + H.d / 2;
|
|
193
|
+
const { x: hx, z: hz, w: W, d: D, h: Hh } = H;
|
|
194
|
+
const z0 = doorZ, z1 = hz - D / 2;
|
|
195
|
+
const rows = 6, rh = Hh / rows, doorW = 1.3, doorH = 2.0;
|
|
196
|
+
for (let r = 0; r < rows; r++) {
|
|
197
|
+
const y = r * rh + rh / 2, off = r % 2 ? 0.4 : 0;
|
|
198
|
+
for (const [fz, front] of [[z0, true], [z1, false]] as const) {
|
|
199
|
+
let s = -W / 2 - off;
|
|
200
|
+
while (s < W / 2) {
|
|
201
|
+
const bl = R(0.75, 1.15), a = Math.max(s, -W / 2), b = Math.min(s + bl, W / 2);
|
|
202
|
+
s += bl;
|
|
203
|
+
if (b - a < 0.15) continue;
|
|
204
|
+
if (front && y < doorH && b > -doorW / 2 - 0.12 && a < doorW / 2 + 0.12) {
|
|
205
|
+
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));
|
|
206
|
+
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));
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
addBlock(hx + (a + b) / 2, y, fz, b - a - 0.03, rh - 0.03, 0.5, 0, R(0.82, 1.05));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const fx of [-W / 2, W / 2]) {
|
|
213
|
+
let s = z1 - off;
|
|
214
|
+
while (s < z0) {
|
|
215
|
+
const bl = R(0.75, 1.15), a = Math.max(s, z1 + 0.25), b = Math.min(s + bl, z0 - 0.25);
|
|
216
|
+
s += bl;
|
|
217
|
+
if (b - a < 0.15) continue;
|
|
218
|
+
addBlock(hx + fx, y, (a + b) / 2, 0.5, rh - 0.03, b - a - 0.03, 0, R(0.82, 1.05));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// corner quoins: bigger blocks proud of the wall
|
|
223
|
+
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));
|
|
224
|
+
// the walls' colliders: one invisible box per wall run, said once, from the same numbers the courses use
|
|
225
|
+
const wallBox = (x: number, z: number, sx: number, sz: number): void => { const m = new THREE.Mesh(new THREE.BoxGeometry(sx, Hh, sz), M.stone); m.position.set(x, Hh / 2, z); m.visible = false; part.add(solid(m)); };
|
|
226
|
+
const side = (W / 2 - doorW / 2) / 2;
|
|
227
|
+
wallBox(hx - (W / 2 + doorW / 2) / 2 - 0.05, z0, side * 2, 0.5); wallBox(hx + (W / 2 + doorW / 2) / 2 + 0.05, z0, side * 2, 0.5);
|
|
228
|
+
wallBox(hx, z1, W, 0.5); wallBox(hx - W / 2, hz, 0.5, D); wallBox(hx + W / 2, hz, 0.5, D);
|
|
229
|
+
// gables, ridge left-right so the eaves face the path
|
|
230
|
+
const RH = 1.55, half = D / 2 + 0.25;
|
|
231
|
+
const tri = new THREE.Shape(); tri.moveTo(-half, 0); tri.lineTo(half, 0); tri.lineTo(0, RH); tri.closePath();
|
|
232
|
+
const gGeo = new THREE.ExtrudeGeometry(tri, { depth: 0.45, bevelEnabled: true, bevelSize: 0.05, bevelThickness: 0.05, bevelSegments: 2 });
|
|
233
|
+
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);
|
|
234
|
+
for (const sx of [-1, 1]) {
|
|
235
|
+
const m = new THREE.Mesh(gGeo, M.stone); m.rotation.y = Math.PI / 2;
|
|
236
|
+
m.position.set(hx + sx * (W / 2) - 0.22, Hh - 0.02, hz); m.castShadow = m.receiveShadow = true; part.add(m);
|
|
237
|
+
}
|
|
238
|
+
// roof: thick overlapping mossy shingles, deep overhang, a fat moss ridge and drapes off the eaves
|
|
239
|
+
const over = 0.6, pitch = Math.atan2(RH, half), slopeLen = (half + over) / Math.cos(pitch);
|
|
240
|
+
const shGeo = new RoundedBoxGeometry(0.56, 0.2, 0.7, 2, 0.07);
|
|
241
|
+
const shingles: { x: number; y: number; z: number; side: number }[] = [];
|
|
242
|
+
for (const sd of [-1, 1]) {
|
|
243
|
+
const rowsN = 7;
|
|
244
|
+
for (let r = 0; r < rowsN; r++) {
|
|
245
|
+
const along = (r + 0.55) / rowsN * slopeLen, jitter = r % 2 ? 0.3 : 0;
|
|
246
|
+
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 });
|
|
247
|
+
}
|
|
248
|
+
const under = new THREE.Mesh(new THREE.BoxGeometry(W + 1.5, 0.16, slopeLen + 0.1), M.darkWood);
|
|
249
|
+
under.position.set(hx, Hh + RH + 0.08 - (slopeLen / 2) * Math.sin(pitch), hz + sd * (slopeLen / 2) * Math.cos(pitch));
|
|
250
|
+
under.rotation.x = sd * pitch; under.castShadow = true; part.add(under);
|
|
251
|
+
const ey = Hh + RH + 0.14 - slopeLen * Math.sin(pitch), ez = hz + sd * slopeLen * Math.cos(pitch);
|
|
252
|
+
addCap(hx, ey, ez, W + 1.55, 0.2, 0.32, 0);
|
|
253
|
+
drape(hx, ey - 0.02, ez + sd * 0.12, W + 1.4, 0, 0.42);
|
|
254
|
+
}
|
|
255
|
+
const shM = new THREE.InstancedMesh(shGeo, M.shingle, shingles.length);
|
|
256
|
+
const o = new THREE.Object3D(), cc = new THREE.Color();
|
|
257
|
+
shingles.forEach((s, i) => {
|
|
258
|
+
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));
|
|
259
|
+
o.scale.set(R(0.95, 1.1), 1, R(0.95, 1.1)); o.updateMatrix(); shM.setMatrixAt(i, o.matrix);
|
|
260
|
+
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)));
|
|
261
|
+
});
|
|
262
|
+
shM.castShadow = shM.receiveShadow = true; shM.name = 'roof'; part.add(shM);
|
|
263
|
+
addCap(hx, Hh + RH + 0.3, hz, W + 1.55, 0.4, 0.66);
|
|
264
|
+
// moss tufts scattered on the roof
|
|
265
|
+
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)); }
|
|
266
|
+
// door frame and lintel, a door leaf swung in, the sign
|
|
267
|
+
for (const sx of [-1, 1]) {
|
|
268
|
+
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);
|
|
269
|
+
}
|
|
270
|
+
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);
|
|
271
|
+
const leaf = new THREE.Mesh(new THREE.BoxGeometry(doorW - 0.05, doorH - 0.05, 0.08), M.darkWood);
|
|
272
|
+
leaf.geometry.translate((doorW - 0.05) / 2, 0, 0);
|
|
273
|
+
leaf.position.set(hx - doorW / 2, doorH / 2, z0 - 0.15); leaf.rotation.y = -1.9; part.add(leaf);
|
|
274
|
+
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 }));
|
|
275
|
+
sign.position.set(hx, doorH + 0.17, z0 + 0.29); part.add(sign);
|
|
276
|
+
decal(part, '3x3', hx + 1.6, 1.85, z0 + 0.27, 0, 0.85);
|
|
277
|
+
decal(part, '3x3', hx + W / 2 + 0.27, 1.85, hz, Math.PI / 2, 0.85);
|
|
278
|
+
bracketLamp(hx - 1.15, 1.85, z0 + 0.25, 0);
|
|
279
|
+
// ivy up the front corners
|
|
280
|
+
ivy(hx - W / 2 - 0.05, Hh, z0 + 0.27, Hh * 0.9, 0, 0.4);
|
|
281
|
+
ivy(hx + W / 2 + 0.27, Hh, z0 - 0.4, Hh * 0.7, Math.PI / 2, 0.4);
|
|
282
|
+
// ---- interior: plank floor, rug, table and stools, a shelf of jars, crates, a hanging lamp ----
|
|
283
|
+
const inW = W - 0.55, inD = D - 0.55, iz = hz;
|
|
284
|
+
const floor = new THREE.Mesh(new THREE.PlaneGeometry(inW, inD), new THREE.MeshStandardMaterial({ map: tex.wood, color: '#a07a58', roughness: 0.85 }));
|
|
285
|
+
floor.rotation.x = -Math.PI / 2; floor.position.set(hx, 0.02, iz); part.add(floor);
|
|
286
|
+
const back = new THREE.Mesh(new THREE.PlaneGeometry(inW, Hh), M.stoneClean); back.position.set(hx, Hh / 2, z1 + 0.26); part.add(back);
|
|
287
|
+
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); }
|
|
288
|
+
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);
|
|
289
|
+
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);
|
|
290
|
+
const table = new THREE.Group();
|
|
291
|
+
const top = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.08, 0.7), M.wood); top.position.y = 0.76; table.add(top);
|
|
292
|
+
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); }
|
|
293
|
+
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);
|
|
294
|
+
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);
|
|
295
|
+
table.position.set(hx + 0.6, 0, iz - 0.3); part.add(table);
|
|
296
|
+
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); }
|
|
297
|
+
const shelf = new THREE.Group();
|
|
298
|
+
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); }
|
|
299
|
+
const jarCols = ['#6a8a5a', '#b08a4a', '#8a4a3a', '#5a6a8a', '#c0a070'];
|
|
300
|
+
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), new THREE.MeshStandardMaterial({ color: jarCols[i % 5], roughness: 0.4 })); j.position.set(-0.75 + (i % 5) * 0.36 + R(-0.05, 0.05), i < 5 ? 1.05 : 1.6, 0); shelf.add(j); }
|
|
301
|
+
shelf.position.set(hx - 0.9, 0, z1 + 0.45); part.add(shelf);
|
|
302
|
+
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); }
|
|
303
|
+
barrel(part, M, hx + 1.95, iz - 1.4);
|
|
304
|
+
lantern(hx + 0.6, 1.95, iz - 0.3, { on: true, scale: 0.9, light: false });
|
|
305
|
+
const inLight = new THREE.PointLight('#ffa040', 7, 6.5, 1.4); inLight.position.set(hx + 0.4, 1.8, iz + 0.2); part.add(inLight);
|
|
306
|
+
const inLight2 = new THREE.PointLight('#ff9a40', 3, 4, 1.5); inLight2.position.set(hx - 1.5, 1.5, iz - 1.0); part.add(inLight2);
|
|
307
|
+
// outside: bench, barrels, crates
|
|
308
|
+
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);
|
|
309
|
+
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); }
|
|
310
|
+
for (const [bx, bz] of [[1.75, 0.75], [2.4, 1.05]] as const) barrel(part, M, hx + bx, z0 + bz);
|
|
311
|
+
flush();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function barrel(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, x: number, z: number): void {
|
|
315
|
+
const g = new THREE.CylinderGeometry(0.31, 0.31, 0.78, 16, 4);
|
|
316
|
+
const p = g.attributes.position;
|
|
317
|
+
for (let i = 0; i < p.count; i++) { const y = p.getY(i), k = 1 + 0.12 * (1 - (y / 0.39) ** 2); p.setX(i, p.getX(i) * k); p.setZ(i, p.getZ(i) * k); }
|
|
318
|
+
g.computeVertexNormals();
|
|
319
|
+
const m = new THREE.Mesh(g, M.wood); m.position.set(x, 0.39, z); m.castShadow = true; part.add(solid(m));
|
|
320
|
+
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); }
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** The pond (cleanroom world.js 603-650 and main.js 70-111): kerb stones, the moss bridge, reeds, lilies, three lantern
|
|
324
|
+
* posts and the water, its outline the same rounded rectangle the ground is carved from. */
|
|
325
|
+
export function pond(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>, { bridgeUp = false } = {}): void {
|
|
326
|
+
const { R, rand, addBlock, addCap, lanternPost, flush } = kit(part, 603, M, tex);
|
|
327
|
+
const P = LAYOUT.POND;
|
|
328
|
+
// kerb stones around the rim, gaps where the bridge lands
|
|
329
|
+
const per: [number, number][] = [];
|
|
330
|
+
const steps = 140;
|
|
331
|
+
for (let i = 0; i < steps; i++) {
|
|
332
|
+
// walk the rounded rectangle by angle and project onto the SDF zero line
|
|
333
|
+
const a = (i / steps) * Math.PI * 2;
|
|
334
|
+
let rr = 3;
|
|
335
|
+
for (let k = 0; k < 30; k++) { const d = pondSDF(P.x + Math.cos(a) * rr, P.z + Math.sin(a) * rr); rr -= d * 0.8; }
|
|
336
|
+
per.push([P.x + Math.cos(a) * rr, P.z + Math.sin(a) * rr]);
|
|
337
|
+
}
|
|
338
|
+
let acc = 0;
|
|
339
|
+
for (let i = 0; i < per.length; i++) {
|
|
340
|
+
const [ax, az] = per[i] ?? [0, 0], [bx, bz] = per[(i + 1) % per.length] ?? [0, 0];
|
|
341
|
+
acc += Math.hypot(bx - ax, bz - az);
|
|
342
|
+
if (acc < 0.85) continue;
|
|
343
|
+
acc = 0;
|
|
344
|
+
if (Math.abs(az - P.z) < 1.1) continue; // the bridge landings
|
|
345
|
+
const ang = Math.atan2(-(bz - az), bx - ax);
|
|
346
|
+
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));
|
|
347
|
+
if (rand() < 0.25) addCap(ax, 0.02, az, R(0.4, 0.8), 0.1, 0.4, ang);
|
|
348
|
+
}
|
|
349
|
+
// the moss bridge: big stone blocks across the long axis; sunk below the surface until A is lit
|
|
350
|
+
const n = 5, x0 = P.x + P.hx - 1.5, x1 = P.x - P.hx + 1.5;
|
|
351
|
+
for (let i = 0; i < n; i++) {
|
|
352
|
+
const x = x0 + (x1 - x0) * (i / (n - 1)), z = P.z + R(-0.15, 0.15);
|
|
353
|
+
const topY = bridgeUp ? 0.28 : -0.07;
|
|
354
|
+
addBlock(x, topY - 0.6, z, 1.7, 1.2, 1.7, R(-0.08, 0.08), bridgeUp ? R(0.78, 0.9) : R(0.32, 0.4));
|
|
355
|
+
if (bridgeUp) addCap(x, topY + 0.02, z, 1.75, 0.18, 1.75, R(-0.1, 0.1));
|
|
356
|
+
}
|
|
357
|
+
// reeds, cattails and lilies
|
|
358
|
+
const reedM = new THREE.MeshStandardMaterial({ color: '#7a8a36', roughness: 0.9 });
|
|
359
|
+
const catM = new THREE.MeshStandardMaterial({ color: '#5a3a22', roughness: 0.9 });
|
|
360
|
+
for (let i = 0; i < 140; i++) {
|
|
361
|
+
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);
|
|
362
|
+
const d = pondSDF(x, z);
|
|
363
|
+
if (d < -0.9 || d > 0.6 || Math.abs(z - P.z) < 1.6) continue;
|
|
364
|
+
const h = R(0.6, 1.5);
|
|
365
|
+
const r = new THREE.Mesh(new THREE.CylinderGeometry(0.012, 0.022, h, 4), reedM);
|
|
366
|
+
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);
|
|
367
|
+
if (rand() < 0.4) { const c = new THREE.Mesh(new THREE.CapsuleGeometry(0.04, 0.2, 3, 6), catM); c.position.set(x, groundHeight(x, z) + h - 0.05, z); part.add(c); }
|
|
368
|
+
}
|
|
369
|
+
const padM = new THREE.MeshStandardMaterial({ color: '#4a6e2a', roughness: 0.7, side: THREE.DoubleSide });
|
|
370
|
+
const flowerM = new THREE.MeshStandardMaterial({ color: '#f4e4ee', emissive: '#ffd0e0', emissiveIntensity: 0.15 });
|
|
371
|
+
for (let i = 0; i < 40; i++) {
|
|
372
|
+
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);
|
|
373
|
+
if (Math.abs(z - P.z) < 1.2) continue;
|
|
374
|
+
const m = new THREE.Mesh(new THREE.CircleGeometry(R(0.2, 0.36), 14, 0.3, Math.PI * 2 - 0.3), padM);
|
|
375
|
+
m.rotation.set(-Math.PI / 2, 0, R(0, 6)); m.position.set(x, -0.105, z); part.add(m);
|
|
376
|
+
if (rand() < 0.25) { const f = new THREE.Mesh(new THREE.SphereGeometry(0.07, 8, 6), flowerM); f.position.set(x, -0.07, z); f.scale.y = 0.6; part.add(f); }
|
|
377
|
+
}
|
|
378
|
+
lanternPost(P.x + P.hx - 0.6, P.z + 2.7, Math.PI / 2 - 0.3, { stoneBase: true });
|
|
379
|
+
lanternPost(P.x + P.hx - 1.6, P.z - 1.5, Math.PI / 2, { h: 1.7 });
|
|
380
|
+
lanternPost(P.x - P.hx - 0.9, P.z - 1.6, -Math.PI / 2, { stoneBase: true });
|
|
381
|
+
// the water: the cleanroom's Reflector shape, a Water now
|
|
382
|
+
const w = P.hx + 0.2, h = P.hz + 0.2, rr = P.r + 0.2;
|
|
383
|
+
const shape = new THREE.Shape();
|
|
384
|
+
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);
|
|
385
|
+
shape.lineTo(-w + rr, h); shape.quadraticCurveTo(-w, h, -w, h - rr); shape.lineTo(-w, -h + rr); shape.quadraticCurveTo(-w, -h, -w + rr, -h);
|
|
386
|
+
const water = new Water(shape, { tint: '#3a3458', reflect: 'planar' });
|
|
387
|
+
water.position.set(P.x, -0.12, P.z);
|
|
388
|
+
part.add(water);
|
|
389
|
+
flush();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** The sunset light (cleanroom main.js 40-66): hemisphere, the key sun, the rim, the haze, the composer. */
|
|
393
|
+
export function sunset(world: ShardWorld): void {
|
|
394
|
+
world.scene.fog = new THREE.FogExp2(new THREE.Color('#d898a0'), 0.0062);
|
|
395
|
+
world.part('light', (part) => {
|
|
396
|
+
part.add(new THREE.HemisphereLight(new THREE.Color('#c4b0e4'), new THREE.Color('#7a6a3c'), 0.85));
|
|
397
|
+
const key = new THREE.DirectionalLight(new THREE.Color('#ffd6ae'), 2.2);
|
|
398
|
+
key.position.set(-26, 30, 34); key.castShadow = true;
|
|
399
|
+
part.add(key, key.target);
|
|
400
|
+
const rim = new THREE.DirectionalLight(new THREE.Color('#ff9a80'), 1.2);
|
|
401
|
+
rim.position.set(14, 5, -40);
|
|
402
|
+
part.add(rim);
|
|
403
|
+
});
|
|
404
|
+
world.post({ tone: 'aces', exposure: 1.05, bloom: { strength: 0.42, radius: 0.55, threshold: 0.9 }, vignette: 0.2 });
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** The slice: the light, the hut, the pond, the ground they stand on. */
|
|
408
|
+
export function buildSlice(world: ShardWorld): void {
|
|
409
|
+
const { M, tex } = materials();
|
|
410
|
+
sunset(world);
|
|
411
|
+
world.ground(groundHeight, { colourAt: groundColour });
|
|
412
|
+
world.part('hut', (part) => { hut(part, M, tex); });
|
|
413
|
+
world.part('pond', (part) => { pond(part, M, tex); });
|
|
414
|
+
world.spawn(-3.9, 0, -5.6, 0.03);
|
|
415
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// AUTHORING-PARITY AP7: a shard whose only source is a three.js scene (generators/world.ts).
|
|
2
|
+
import { slice } from './generators/shard';
|
|
3
|
+
|
|
4
|
+
/** The scene shard: its generator and its describe() for `wildshard watch`. */
|
|
5
|
+
export const generate: typeof slice = slice;
|
|
6
|
+
// oxlint-disable-next-line import/no-default-export -- The author CLI executes this project entry.
|
|
7
|
+
export default generate;
|