@wildshard/sdk 0.2.13 → 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 +26 -13
- package/bin/wildshard.mjs +2 -1
- package/docs/api/EXPORT-TIERS.md +16 -4
- package/lint/export-tiers.json +12 -0
- package/lint/host-callbacks.mjs +1 -1
- package/package.json +22 -6
- package/scripts/bake/template-skins.mjs +6 -3
- package/scripts/bake/template-warden.mjs +25 -0
- package/scripts/build-shardfiles.mjs +7 -2
- package/scripts/export-ci21-guests.mjs +89 -0
- package/scripts/prepare-product.mjs +2 -2
- package/scripts/scratch-sweep.mjs +182 -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/as/prelude.ts +67 -0
- package/src/sharddev/assets.ts +1 -1
- package/src/sharddev/authorLint.ts +45 -0
- package/src/sharddev/bake/compactGlb.ts +1 -1
- package/src/sharddev/bake/compileScript.ts +6 -0
- 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 +12 -3
- package/src/sharddev/blobBytes.ts +1 -1
- package/src/sharddev/blobs.ts +2 -2
- package/src/sharddev/checkProject.ts +7 -18
- package/src/sharddev/cli.ts +17 -4
- package/src/sharddev/engineMusic.ts +23 -0
- package/src/sharddev/formatJsonSchema.ts +1 -1
- package/src/sharddev/materialGraphFiles.ts +1 -1
- package/src/sharddev/materials.ts +7 -3
- 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 +6 -1
- package/src/sharddev/projectMap.ts +1 -1
- package/src/sharddev/refusals.ts +5 -3
- package/src/sharddev/reportCard.ts +1 -1
- package/src/sharddev/scene/author.ts +184 -0
- package/src/sharddev/scene/canvas.ts +212 -0
- package/src/sharddev/scene/description.ts +223 -0
- package/src/sharddev/scene/hash.ts +23 -0
- package/src/sharddev/scene/lower.ts +341 -0
- package/src/sharddev/scene/shard.ts +41 -0
- package/src/sharddev/scene/shardfile.ts +621 -0
- package/src/sharddev/threeGate.mjs +14 -0
- package/src/sharddev/threePin.mjs +40 -0
- package/src/sharddev/watch/page.ts +284 -0
- package/src/sharddev/watch/pageEntry.ts +59 -0
- package/src/sharddev/watch/parity-baseline.json +22 -0
- package/src/sharddev/watch/parity.mjs +168 -0
- package/src/sharddev/watch/proof.mjs +199 -0
- package/src/sharddev/watch/protocol.ts +166 -0
- package/src/sharddev/watch/socket.ts +57 -0
- package/src/sharddev/watch/watch.ts +373 -0
- 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 +14 -0
- 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 +232 -0
- package/src/shards/authoring-slice/generators/world.ts +518 -0
- package/src/shards/authoring-slice/shard.config.ts +7 -0
- 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,518 @@
|
|
|
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 { animate, drift, flicker, pulse, rise, solid, sway, Water, type ShardWorld } from '@wildshard/sdk/scene/author';
|
|
10
|
+
import * as T from './textures';
|
|
11
|
+
import { sunsetSky } from './sky';
|
|
12
|
+
|
|
13
|
+
export const LAYOUT = {
|
|
14
|
+
SPAWN: { x: 0, z: 0, yaw: 0 },
|
|
15
|
+
HUT: { x: -4.0, z: -14.0, w: 5.2, d: 4.6, h: 2.5 }, // door face at z + d/2
|
|
16
|
+
POND: { x: -19.4, z: 0, hx: 6.6, hz: 5.4, r: 2.2 },
|
|
17
|
+
ARENA: { x: 25.5, z: -2, r: 9.5 },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const noise = T.makeNoise(99);
|
|
21
|
+
const sstep = THREE.MathUtils.smoothstep;
|
|
22
|
+
|
|
23
|
+
/** Signed distance to the pond's rounded rectangle (negative inside). */
|
|
24
|
+
export function pondSDF(x: number, z: number): number {
|
|
25
|
+
const { x: px, z: pz, hx, hz, r } = LAYOUT.POND;
|
|
26
|
+
const qx = Math.abs(x - px) - hx + r, qz = Math.abs(z - pz) - hz + r;
|
|
27
|
+
return Math.hypot(Math.max(qx, 0), Math.max(qz, 0)) + Math.min(Math.max(qx, qz), 0) - r;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function groundHeight(x: number, z: number): number {
|
|
31
|
+
let y = 0;
|
|
32
|
+
const dp = pondSDF(x, z);
|
|
33
|
+
if (dp < 0.6) y -= 1.1 * (1 - sstep(dp, -1.6, 0.6));
|
|
34
|
+
const da = Math.hypot(x - LAYOUT.ARENA.x, z - LAYOUT.ARENA.z);
|
|
35
|
+
if (da < LAYOUT.ARENA.r) y -= 0.35;
|
|
36
|
+
// the cell edge stays at road height for the four entryways (the cleanroom had no edge)
|
|
37
|
+
const far = sstep(Math.hypot(x - 4, z + 2), 48, 95) * (1 - sstep(Math.hypot(x, z), 170, 230));
|
|
38
|
+
y += far * (noise.fbm(x * 0.02 + 50, z * 0.02 + 50, 3) - 0.35) * 7;
|
|
39
|
+
return y;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The moss floor's colour, as the cleanroom's ground vertex colours times its moss texture's mean. */
|
|
43
|
+
export function groundColour(x: number, z: number): [number, number, number] {
|
|
44
|
+
const v = noise.fbm(x * 0.07, z * 0.07, 4), w = noise.fbm(x * 0.018 + 9, z * 0.018 + 4, 3);
|
|
45
|
+
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);
|
|
46
|
+
const dp = pondSDF(x, z);
|
|
47
|
+
if (dp < 0.9) c.lerp(new THREE.Color(0.42, 0.38, 0.3), 1 - sstep(dp, -0.4, 0.9));
|
|
48
|
+
const moss = new THREE.Color().setRGB(102 / 255, 120 / 255, 48 / 255, THREE.SRGBColorSpace);
|
|
49
|
+
return [c.r * moss.r, c.g * moss.g, c.b * moss.b];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The textures and materials every part shares (`buildWorld`'s `tex` and `M`). */
|
|
53
|
+
function materials(): { M: Record<string, THREE.MeshStandardMaterial>; tex: Record<string, THREE.Texture> } {
|
|
54
|
+
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(), frond: T.frond(), grass: T.grassCard(), flame: T.flameSprite() };
|
|
55
|
+
const M = {
|
|
56
|
+
stone: new THREE.MeshStandardMaterial({ map: tex.stone, roughness: 0.93 }),
|
|
57
|
+
stoneClean: new THREE.MeshStandardMaterial({ map: tex.stoneClean, roughness: 0.9 }),
|
|
58
|
+
slab: new THREE.MeshStandardMaterial({ map: tex.slab, roughness: 0.88 }),
|
|
59
|
+
wood: new THREE.MeshStandardMaterial({ map: tex.wood, roughness: 0.78 }),
|
|
60
|
+
darkWood: new THREE.MeshStandardMaterial({ map: tex.wood, color: '#8a6a52', roughness: 0.82 }),
|
|
61
|
+
shingle: new THREE.MeshStandardMaterial({ name: 'roof', map: tex.shingle, roughness: 0.95 }),
|
|
62
|
+
moss: new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 }),
|
|
63
|
+
iron: new THREE.MeshStandardMaterial({ color: '#3a302a', roughness: 0.5, metalness: 0.6 }),
|
|
64
|
+
bronze: new THREE.MeshStandardMaterial({ color: '#7a5634', roughness: 0.45, metalness: 0.7 }),
|
|
65
|
+
lampGlass: new THREE.MeshStandardMaterial({ color: '#ffc061', emissive: '#ffa73a', emissiveIntensity: 2.6, roughness: 0.3 }),
|
|
66
|
+
ivy: new THREE.MeshStandardMaterial({ map: tex.ivy, alphaTest: 0.45, side: THREE.DoubleSide, roughness: 0.85 }),
|
|
67
|
+
drape: new THREE.MeshStandardMaterial({ map: tex.drape, alphaTest: 0.35, side: THREE.DoubleSide, roughness: 1 }),
|
|
68
|
+
cloth: new THREE.MeshStandardMaterial({ color: '#8a3a2a', roughness: 0.95 }),
|
|
69
|
+
};
|
|
70
|
+
return { M, tex };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 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
|
|
74
|
+
// tongue's height * (0.85 + 0.12 sin 9t + 0.06 sin 23t), foliage in the wind.
|
|
75
|
+
const LAMP_FLICKER = flicker({ rate: 1.1, amount: 0.08 });
|
|
76
|
+
const FLAME_PULSE = pulse({ rate: 1.4, amount: 0.14 });
|
|
77
|
+
const FOLIAGE_SWAY = sway({ rate: 0.5, amount: 0.06 });
|
|
78
|
+
|
|
79
|
+
interface Block { x: number; y: number; z: number; sx: number; sy: number; sz: number; rotY: number; tint: number }
|
|
80
|
+
/** One part's builders: the cleanroom's accumulators (`addBlock`, `addCap`, `drape`, `ivy`) and its lamp helpers. */
|
|
81
|
+
function kit(part: THREE.Group, seed: number, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>) {
|
|
82
|
+
const rand = T.rng(seed);
|
|
83
|
+
const R = (a: number, b: number): number => a + (b - a) * rand();
|
|
84
|
+
const blockGeo = new RoundedBoxGeometry(1, 1, 1, 3, 0.07);
|
|
85
|
+
const capGeo = (() => {
|
|
86
|
+
const g = new RoundedBoxGeometry(1, 1, 1, 7, 0.38);
|
|
87
|
+
const p = g.attributes.position;
|
|
88
|
+
const c = new Float32Array(p.count * 3);
|
|
89
|
+
for (let i = 0; i < p.count; i++) {
|
|
90
|
+
const x = p.getX(i), y = p.getY(i), z = p.getZ(i);
|
|
91
|
+
const n = noise(x * 7 + 10, z * 7 + 10), n2 = noise(x * 19 + 3, z * 19 + y * 9);
|
|
92
|
+
if (y > 0) p.setY(i, y + (n - 0.5) * 0.4 + (n2 - 0.5) * 0.12);
|
|
93
|
+
else p.setY(i, y - n * 0.45);
|
|
94
|
+
const k = 0.72 + n * 0.42 + (n2 - 0.5) * 0.18;
|
|
95
|
+
const top = y > 0 ? 1 : 0.62;
|
|
96
|
+
c.set([0.085 * k * top, 0.16 * k * top, 0.034 * k * top], i * 3); // linear: olive moss
|
|
97
|
+
}
|
|
98
|
+
g.setAttribute('color', new THREE.BufferAttribute(c, 3));
|
|
99
|
+
g.computeVertexNormals();
|
|
100
|
+
return g;
|
|
101
|
+
})();
|
|
102
|
+
const stoneBlocks: Block[] = [], caps: Omit<Block, 'tint'>[] = [], drapeGeos: THREE.BufferGeometry[] = [], ivyGeos: THREE.BufferGeometry[] = [];
|
|
103
|
+
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 }); };
|
|
104
|
+
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 }); };
|
|
105
|
+
function drape(x: number, y: number, z: number, len: number, rotY: number, h = 0.45): void {
|
|
106
|
+
const g = new THREE.PlaneGeometry(len, h, Math.max(1, Math.round(len * 3)), 2);
|
|
107
|
+
g.translate(0, -h / 2, 0);
|
|
108
|
+
const p = g.attributes.position, uv = g.attributes.uv;
|
|
109
|
+
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)); }
|
|
110
|
+
g.rotateY(rotY); g.translate(x, y, z);
|
|
111
|
+
drapeGeos.push(g);
|
|
112
|
+
}
|
|
113
|
+
function ivy(x: number, y: number, z: number, len: number, rotY: number, w = 0.32): void {
|
|
114
|
+
const g = new THREE.PlaneGeometry(w, len, 1, 5);
|
|
115
|
+
g.translate(0, -len / 2, 0);
|
|
116
|
+
const p = g.attributes.position;
|
|
117
|
+
for (let i = 0; i < p.count; i++) p.setZ(i, Math.sin(p.getY(i) * 2.2 + x) * 0.03);
|
|
118
|
+
g.rotateY(rotY); g.translate(x, y, z);
|
|
119
|
+
ivyGeos.push(g);
|
|
120
|
+
}
|
|
121
|
+
function lantern(x: number, y: number, z: number, { on = true, scale = 1, light = true } = {}): THREE.Group {
|
|
122
|
+
const g = new THREE.Group();
|
|
123
|
+
const glass = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.26, 0.2), on ? M.lampGlass : M.iron);
|
|
124
|
+
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;
|
|
125
|
+
const base = new THREE.Mesh(new THREE.BoxGeometry(0.27, 0.05, 0.27), M.iron); base.position.y = -0.155;
|
|
126
|
+
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.05, 0.012, 6, 12), M.iron); ring.position.y = 0.33;
|
|
127
|
+
g.add(glass, cap, base, ring);
|
|
128
|
+
for (const [bx, bz] of [[-1, -1], [1, -1], [-1, 1], [1, 1]] as const) {
|
|
129
|
+
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);
|
|
130
|
+
}
|
|
131
|
+
g.position.set(x, y, z); g.scale.setScalar(scale);
|
|
132
|
+
part.add(g);
|
|
133
|
+
if (on) {
|
|
134
|
+
if (light) {
|
|
135
|
+
const l = new THREE.PointLight('#ffa850', 3.4 * scale, 6, 1.7);
|
|
136
|
+
l.position.set(x, y, z); part.add(animate(l, LAMP_FLICKER));
|
|
137
|
+
}
|
|
138
|
+
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 }));
|
|
139
|
+
s.scale.setScalar(1.1 * scale); s.position.set(x, y, z); part.add(s);
|
|
140
|
+
}
|
|
141
|
+
return g;
|
|
142
|
+
}
|
|
143
|
+
// A gallows post: a squared timber with an arm, a rope and a hanging lantern.
|
|
144
|
+
function lanternPost(x: number, z: number, rotY = 0, { h = 2.7, on = true, stoneBase = false } = {}): void {
|
|
145
|
+
const gy = groundHeight(x, z);
|
|
146
|
+
const ax = Math.sin(rotY), az = Math.cos(rotY);
|
|
147
|
+
if (stoneBase) {
|
|
148
|
+
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);
|
|
149
|
+
addCap(x, gy + 0.72, z, 0.66, 0.16, 0.66);
|
|
150
|
+
}
|
|
151
|
+
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));
|
|
152
|
+
const arm = new THREE.Mesh(new THREE.BoxGeometry(0.14, 0.14, 0.95), M.wood);
|
|
153
|
+
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);
|
|
154
|
+
const brace = new THREE.Mesh(new THREE.BoxGeometry(0.09, 0.09, 0.55), M.wood);
|
|
155
|
+
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);
|
|
156
|
+
const lx = x + ax * 0.74, lz = z + az * 0.74;
|
|
157
|
+
const rope = new THREE.Mesh(new THREE.CylinderGeometry(0.018, 0.018, 0.42, 5), new THREE.MeshStandardMaterial({ color: '#b8925a', roughness: 0.9 }));
|
|
158
|
+
rope.position.set(lx, gy + h - 0.4, lz); part.add(rope);
|
|
159
|
+
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);
|
|
160
|
+
lantern(lx, gy + h - 0.82, lz, { on, scale: 1.25 });
|
|
161
|
+
}
|
|
162
|
+
// A wall bracket lamp: an iron arm out of a stone face.
|
|
163
|
+
function bracketLamp(x: number, y: number, z: number, rotY: number, on = true): void {
|
|
164
|
+
const ax = Math.sin(rotY), az = Math.cos(rotY);
|
|
165
|
+
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);
|
|
166
|
+
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);
|
|
167
|
+
lantern(x + ax * 0.44, y, z + az * 0.44, { on, scale: 1.05 });
|
|
168
|
+
}
|
|
169
|
+
// flush instanced stone, caps, drapes and ivy into the part
|
|
170
|
+
function flush(): void {
|
|
171
|
+
const im = new THREE.InstancedMesh(blockGeo, M.stone, stoneBlocks.length);
|
|
172
|
+
const o = new THREE.Object3D(), c = new THREE.Color();
|
|
173
|
+
stoneBlocks.forEach((b, i) => {
|
|
174
|
+
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();
|
|
175
|
+
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)));
|
|
176
|
+
});
|
|
177
|
+
im.castShadow = im.receiveShadow = true; if (stoneBlocks.length > 0) part.add(im);
|
|
178
|
+
const cm = new THREE.InstancedMesh(capGeo, M.moss, caps.length);
|
|
179
|
+
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); });
|
|
180
|
+
cm.castShadow = cm.receiveShadow = true; if (caps.length > 0) part.add(cm);
|
|
181
|
+
if (drapeGeos.length > 0) { const d = new THREE.Mesh(mergeGeometries(drapeGeos), M.drape); d.castShadow = true; part.add(d); }
|
|
182
|
+
if (ivyGeos.length > 0) part.add(new THREE.Mesh(mergeGeometries(ivyGeos), M.ivy));
|
|
183
|
+
}
|
|
184
|
+
return { rand, R, addBlock, addCap, drape, ivy, lantern, lanternPost, bracketLamp, flush };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function decal(part: THREE.Group, text: string, x: number, y: number, z: number, rotY: number, size = 1, floor = false): THREE.Mesh {
|
|
188
|
+
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 }));
|
|
189
|
+
m.position.set(x, y, z);
|
|
190
|
+
if (floor) m.rotation.set(-Math.PI / 2, 0, rotY); else m.rotation.y = rotY;
|
|
191
|
+
m.receiveShadow = true;
|
|
192
|
+
part.add(m);
|
|
193
|
+
return m;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The hut (cleanroom world.js 398-530): coursed walls, gables, a shingle roof, door, sign, bracket lamp and the room. */
|
|
197
|
+
export function hut(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>): void {
|
|
198
|
+
const { R, addBlock, addCap, drape, ivy, lantern, bracketLamp, flush, rand } = kit(part, 398, M, tex);
|
|
199
|
+
const H = LAYOUT.HUT, doorZ = H.z + H.d / 2;
|
|
200
|
+
const { x: hx, z: hz, w: W, d: D, h: Hh } = H;
|
|
201
|
+
const z0 = doorZ, z1 = hz - D / 2;
|
|
202
|
+
const rows = 6, rh = Hh / rows, doorW = 1.3, doorH = 2.0;
|
|
203
|
+
for (let r = 0; r < rows; r++) {
|
|
204
|
+
const y = r * rh + rh / 2, off = r % 2 ? 0.4 : 0;
|
|
205
|
+
for (const [fz, front] of [[z0, true], [z1, false]] as const) {
|
|
206
|
+
let s = -W / 2 - off;
|
|
207
|
+
while (s < W / 2) {
|
|
208
|
+
const bl = R(0.75, 1.15), a = Math.max(s, -W / 2), b = Math.min(s + bl, W / 2);
|
|
209
|
+
s += bl;
|
|
210
|
+
if (b - a < 0.15) continue;
|
|
211
|
+
if (front && y < doorH && b > -doorW / 2 - 0.12 && a < doorW / 2 + 0.12) {
|
|
212
|
+
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));
|
|
213
|
+
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));
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
addBlock(hx + (a + b) / 2, y, fz, b - a - 0.03, rh - 0.03, 0.5, 0, R(0.82, 1.05));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const fx of [-W / 2, W / 2]) {
|
|
220
|
+
let s = z1 - off;
|
|
221
|
+
while (s < z0) {
|
|
222
|
+
const bl = R(0.75, 1.15), a = Math.max(s, z1 + 0.25), b = Math.min(s + bl, z0 - 0.25);
|
|
223
|
+
s += bl;
|
|
224
|
+
if (b - a < 0.15) continue;
|
|
225
|
+
addBlock(hx + fx, y, (a + b) / 2, 0.5, rh - 0.03, b - a - 0.03, 0, R(0.82, 1.05));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// corner quoins: bigger blocks proud of the wall
|
|
230
|
+
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));
|
|
231
|
+
// the walls' colliders: one invisible box per wall run, said once, from the same numbers the courses use
|
|
232
|
+
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)); };
|
|
233
|
+
const side = (W / 2 - doorW / 2) / 2;
|
|
234
|
+
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);
|
|
235
|
+
wallBox(hx, z1, W, 0.5); wallBox(hx - W / 2, hz, 0.5, D); wallBox(hx + W / 2, hz, 0.5, D);
|
|
236
|
+
// gables, ridge left-right so the eaves face the path
|
|
237
|
+
const RH = 1.55, half = D / 2 + 0.25;
|
|
238
|
+
const tri = new THREE.Shape(); tri.moveTo(-half, 0); tri.lineTo(half, 0); tri.lineTo(0, RH); tri.closePath();
|
|
239
|
+
const gGeo = new THREE.ExtrudeGeometry(tri, { depth: 0.45, bevelEnabled: true, bevelSize: 0.05, bevelThickness: 0.05, bevelSegments: 2 });
|
|
240
|
+
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);
|
|
241
|
+
for (const sx of [-1, 1]) {
|
|
242
|
+
const m = new THREE.Mesh(gGeo, M.stone); m.rotation.y = Math.PI / 2;
|
|
243
|
+
m.position.set(hx + sx * (W / 2) - 0.22, Hh - 0.02, hz); m.castShadow = m.receiveShadow = true; part.add(m);
|
|
244
|
+
}
|
|
245
|
+
// roof: thick overlapping mossy shingles, deep overhang, a fat moss ridge and drapes off the eaves
|
|
246
|
+
const over = 0.6, pitch = Math.atan2(RH, half), slopeLen = (half + over) / Math.cos(pitch);
|
|
247
|
+
const shGeo = new RoundedBoxGeometry(0.56, 0.2, 0.7, 2, 0.07);
|
|
248
|
+
const shingles: { x: number; y: number; z: number; side: number }[] = [];
|
|
249
|
+
for (const sd of [-1, 1]) {
|
|
250
|
+
const rowsN = 7;
|
|
251
|
+
for (let r = 0; r < rowsN; r++) {
|
|
252
|
+
const along = (r + 0.55) / rowsN * slopeLen, jitter = r % 2 ? 0.3 : 0;
|
|
253
|
+
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 });
|
|
254
|
+
}
|
|
255
|
+
const under = new THREE.Mesh(new THREE.BoxGeometry(W + 1.5, 0.16, slopeLen + 0.1), M.darkWood);
|
|
256
|
+
under.position.set(hx, Hh + RH + 0.08 - (slopeLen / 2) * Math.sin(pitch), hz + sd * (slopeLen / 2) * Math.cos(pitch));
|
|
257
|
+
under.rotation.x = sd * pitch; under.castShadow = true; part.add(under);
|
|
258
|
+
const ey = Hh + RH + 0.14 - slopeLen * Math.sin(pitch), ez = hz + sd * slopeLen * Math.cos(pitch);
|
|
259
|
+
addCap(hx, ey, ez, W + 1.55, 0.2, 0.32, 0);
|
|
260
|
+
drape(hx, ey - 0.02, ez + sd * 0.12, W + 1.4, 0, 0.42);
|
|
261
|
+
}
|
|
262
|
+
const shM = new THREE.InstancedMesh(shGeo, M.shingle, shingles.length);
|
|
263
|
+
const o = new THREE.Object3D(), cc = new THREE.Color();
|
|
264
|
+
shingles.forEach((s, i) => {
|
|
265
|
+
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));
|
|
266
|
+
o.scale.set(R(0.95, 1.1), 1, R(0.95, 1.1)); o.updateMatrix(); shM.setMatrixAt(i, o.matrix);
|
|
267
|
+
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)));
|
|
268
|
+
});
|
|
269
|
+
shM.castShadow = shM.receiveShadow = true; shM.name = 'roof'; part.add(shM);
|
|
270
|
+
addCap(hx, Hh + RH + 0.3, hz, W + 1.55, 0.4, 0.66);
|
|
271
|
+
// moss tufts scattered on the roof
|
|
272
|
+
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)); }
|
|
273
|
+
// door frame and lintel, a door leaf swung in, the sign
|
|
274
|
+
for (const sx of [-1, 1]) {
|
|
275
|
+
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);
|
|
276
|
+
}
|
|
277
|
+
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);
|
|
278
|
+
const leaf = new THREE.Mesh(new THREE.BoxGeometry(doorW - 0.05, doorH - 0.05, 0.08), M.darkWood);
|
|
279
|
+
leaf.geometry.translate((doorW - 0.05) / 2, 0, 0);
|
|
280
|
+
leaf.position.set(hx - doorW / 2, doorH / 2, z0 - 0.15); leaf.rotation.y = -1.9; part.add(leaf);
|
|
281
|
+
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 }));
|
|
282
|
+
sign.position.set(hx, doorH + 0.17, z0 + 0.29); part.add(sign);
|
|
283
|
+
decal(part, '3x3', hx + 1.6, 1.85, z0 + 0.27, 0, 0.85);
|
|
284
|
+
decal(part, '3x3', hx + W / 2 + 0.27, 1.85, hz, Math.PI / 2, 0.85);
|
|
285
|
+
bracketLamp(hx - 1.15, 1.85, z0 + 0.25, 0);
|
|
286
|
+
// ivy up the front corners
|
|
287
|
+
ivy(hx - W / 2 - 0.05, Hh, z0 + 0.27, Hh * 0.9, 0, 0.4);
|
|
288
|
+
ivy(hx + W / 2 + 0.27, Hh, z0 - 0.4, Hh * 0.7, Math.PI / 2, 0.4);
|
|
289
|
+
// ---- interior: plank floor, rug, table and stools, a shelf of jars, crates, a hanging lamp ----
|
|
290
|
+
const inW = W - 0.55, inD = D - 0.55, iz = hz;
|
|
291
|
+
const floor = new THREE.Mesh(new THREE.PlaneGeometry(inW, inD), new THREE.MeshStandardMaterial({ map: tex.wood, color: '#a07a58', roughness: 0.85 }));
|
|
292
|
+
floor.rotation.x = -Math.PI / 2; floor.position.set(hx, 0.02, iz); part.add(floor);
|
|
293
|
+
const back = new THREE.Mesh(new THREE.PlaneGeometry(inW, Hh), M.stoneClean); back.position.set(hx, Hh / 2, z1 + 0.26); part.add(back);
|
|
294
|
+
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); }
|
|
295
|
+
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);
|
|
296
|
+
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);
|
|
297
|
+
const table = new THREE.Group();
|
|
298
|
+
const top = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.08, 0.7), M.wood); top.position.y = 0.76; table.add(top);
|
|
299
|
+
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); }
|
|
300
|
+
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);
|
|
301
|
+
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);
|
|
302
|
+
table.position.set(hx + 0.6, 0, iz - 0.3); part.add(table);
|
|
303
|
+
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); }
|
|
304
|
+
const shelf = new THREE.Group();
|
|
305
|
+
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); }
|
|
306
|
+
const jarCols = ['#6a8a5a', '#b08a4a', '#8a4a3a', '#5a6a8a', '#c0a070'];
|
|
307
|
+
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); }
|
|
308
|
+
shelf.position.set(hx - 0.9, 0, z1 + 0.45); part.add(shelf);
|
|
309
|
+
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); }
|
|
310
|
+
barrel(part, M, hx + 1.95, iz - 1.4);
|
|
311
|
+
lantern(hx + 0.6, 1.95, iz - 0.3, { on: true, scale: 0.9, light: false });
|
|
312
|
+
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));
|
|
313
|
+
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));
|
|
314
|
+
// outside: bench, barrels, crates
|
|
315
|
+
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);
|
|
316
|
+
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); }
|
|
317
|
+
for (const [bx, bz] of [[1.75, 0.75], [2.4, 1.05]] as const) barrel(part, M, hx + bx, z0 + bz);
|
|
318
|
+
flush();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function barrel(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, x: number, z: number): void {
|
|
322
|
+
const g = new THREE.CylinderGeometry(0.31, 0.31, 0.78, 16, 4);
|
|
323
|
+
const p = g.attributes.position;
|
|
324
|
+
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); }
|
|
325
|
+
g.computeVertexNormals();
|
|
326
|
+
const m = new THREE.Mesh(g, M.wood); m.position.set(x, 0.39, z); m.castShadow = true; part.add(solid(m));
|
|
327
|
+
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); }
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** The pond (cleanroom world.js 603-650 and main.js 70-111): kerb stones, the moss bridge, reeds, lilies, three lantern
|
|
331
|
+
* posts and the water, its outline the same rounded rectangle the ground is carved from. */
|
|
332
|
+
export function pond(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>, { bridgeUp = false } = {}): void {
|
|
333
|
+
const { R, rand, addBlock, addCap, lanternPost, flush } = kit(part, 603, M, tex);
|
|
334
|
+
const P = LAYOUT.POND;
|
|
335
|
+
// kerb stones around the rim, gaps where the bridge lands
|
|
336
|
+
const per: [number, number][] = [];
|
|
337
|
+
const steps = 140;
|
|
338
|
+
for (let i = 0; i < steps; i++) {
|
|
339
|
+
// walk the rounded rectangle by angle and project onto the SDF zero line
|
|
340
|
+
const a = (i / steps) * Math.PI * 2;
|
|
341
|
+
let rr = 3;
|
|
342
|
+
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; }
|
|
343
|
+
per.push([P.x + Math.cos(a) * rr, P.z + Math.sin(a) * rr]);
|
|
344
|
+
}
|
|
345
|
+
let acc = 0;
|
|
346
|
+
for (let i = 0; i < per.length; i++) {
|
|
347
|
+
const [ax, az] = per[i] ?? [0, 0], [bx, bz] = per[(i + 1) % per.length] ?? [0, 0];
|
|
348
|
+
acc += Math.hypot(bx - ax, bz - az);
|
|
349
|
+
if (acc < 0.85) continue;
|
|
350
|
+
acc = 0;
|
|
351
|
+
if (Math.abs(az - P.z) < 1.1) continue; // the bridge landings
|
|
352
|
+
const ang = Math.atan2(-(bz - az), bx - ax);
|
|
353
|
+
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));
|
|
354
|
+
if (rand() < 0.25) addCap(ax, 0.02, az, R(0.4, 0.8), 0.1, 0.4, ang);
|
|
355
|
+
}
|
|
356
|
+
// the moss bridge: big stone blocks across the long axis; sunk below the surface until A is lit
|
|
357
|
+
const n = 5, x0 = P.x + P.hx - 1.5, x1 = P.x - P.hx + 1.5;
|
|
358
|
+
for (let i = 0; i < n; i++) {
|
|
359
|
+
const x = x0 + (x1 - x0) * (i / (n - 1)), z = P.z + R(-0.15, 0.15);
|
|
360
|
+
const topY = bridgeUp ? 0.28 : -0.07;
|
|
361
|
+
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));
|
|
362
|
+
if (bridgeUp) addCap(x, topY + 0.02, z, 1.75, 0.18, 1.75, R(-0.1, 0.1));
|
|
363
|
+
}
|
|
364
|
+
// reeds, cattails and lilies
|
|
365
|
+
const reedM = new THREE.MeshStandardMaterial({ color: '#7a8a36', roughness: 0.9 });
|
|
366
|
+
const catM = new THREE.MeshStandardMaterial({ color: '#5a3a22', roughness: 0.9 });
|
|
367
|
+
for (let i = 0; i < 140; i++) {
|
|
368
|
+
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);
|
|
369
|
+
const d = pondSDF(x, z);
|
|
370
|
+
if (d < -0.9 || d > 0.6 || Math.abs(z - P.z) < 1.6) continue;
|
|
371
|
+
const h = R(0.6, 1.5);
|
|
372
|
+
const r = new THREE.Mesh(new THREE.CylinderGeometry(0.012, 0.022, h, 4), reedM);
|
|
373
|
+
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);
|
|
374
|
+
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); }
|
|
375
|
+
}
|
|
376
|
+
const padM = new THREE.MeshStandardMaterial({ color: '#4a6e2a', roughness: 0.7, side: THREE.DoubleSide });
|
|
377
|
+
const flowerM = new THREE.MeshStandardMaterial({ color: '#f4e4ee', emissive: '#ffd0e0', emissiveIntensity: 0.15 });
|
|
378
|
+
for (let i = 0; i < 40; i++) {
|
|
379
|
+
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);
|
|
380
|
+
if (Math.abs(z - P.z) < 1.2) continue;
|
|
381
|
+
const m = new THREE.Mesh(new THREE.CircleGeometry(R(0.2, 0.36), 14, 0.3, Math.PI * 2 - 0.3), padM);
|
|
382
|
+
m.rotation.set(-Math.PI / 2, 0, R(0, 6)); m.position.set(x, -0.105, z); part.add(m);
|
|
383
|
+
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); }
|
|
384
|
+
}
|
|
385
|
+
lanternPost(P.x + P.hx - 0.6, P.z + 2.7, Math.PI / 2 - 0.3, { stoneBase: true });
|
|
386
|
+
lanternPost(P.x + P.hx - 1.6, P.z - 1.5, Math.PI / 2, { h: 1.7 });
|
|
387
|
+
lanternPost(P.x - P.hx - 0.9, P.z - 1.6, -Math.PI / 2, { stoneBase: true });
|
|
388
|
+
// the water: the cleanroom's Reflector shape, a Water now
|
|
389
|
+
const w = P.hx + 0.2, h = P.hz + 0.2, rr = P.r + 0.2;
|
|
390
|
+
const shape = new THREE.Shape();
|
|
391
|
+
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);
|
|
392
|
+
shape.lineTo(-w + rr, h); shape.quadraticCurveTo(-w, h, -w, h - rr); shape.lineTo(-w, -h + rr); shape.quadraticCurveTo(-w, -h, -w + rr, -h);
|
|
393
|
+
const water = new Water(shape, { tint: '#3a3458', reflect: 'planar' });
|
|
394
|
+
water.position.set(P.x, -0.12, P.z);
|
|
395
|
+
part.add(water);
|
|
396
|
+
flush();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** The yard (cleanroom world.js 375-430 and 891-1030, AP10 to AP12): brazier A lit, its flame cards, sparks and light;
|
|
400
|
+
* ferns and grass cards round the hut, swaying; fireflies over the slice. The cleanroom moved these in `update(t)`; here
|
|
401
|
+
* each says its motion once with `animate`, and the engine plays it. */
|
|
402
|
+
export function yard(part: THREE.Group, M: Record<string, THREE.MeshStandardMaterial>, tex: Record<string, THREE.Texture>): void {
|
|
403
|
+
const rand = T.rng(877);
|
|
404
|
+
const R = (a: number, b: number): number => a + (b - a) * rand();
|
|
405
|
+
// brazier A: a stone plinth, a lathe bowl, a fire
|
|
406
|
+
const [bx, bz] = [5.9, -12.8], gy = groundHeight(bx, bz);
|
|
407
|
+
const pad = new THREE.Mesh(new RoundedBoxGeometry(2.1, 0.12, 2.1, 2, 0.05), M.slab);
|
|
408
|
+
pad.position.set(bx, gy + 0.02, bz); pad.receiveShadow = true; part.add(pad);
|
|
409
|
+
decal(part, 'A', bx, gy + 0.09, bz + 0.68, 0, 0.9, true);
|
|
410
|
+
const g = new THREE.Group();
|
|
411
|
+
const plinth = new THREE.Mesh(new RoundedBoxGeometry(0.78, 0.5, 0.78, 2, 0.05), M.stone); plinth.position.y = 0.25;
|
|
412
|
+
const step = new THREE.Mesh(new RoundedBoxGeometry(0.98, 0.14, 0.98, 2, 0.04), M.stone); step.position.y = 0.07;
|
|
413
|
+
const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.3, 0.32, 8), M.stone); stem.position.y = 0.66;
|
|
414
|
+
const prof = [new THREE.Vector2(0, 0)];
|
|
415
|
+
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)); }
|
|
416
|
+
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));
|
|
417
|
+
const bowl = new THREE.Mesh(new THREE.LatheGeometry(prof, 8), M.stone); bowl.position.y = 0.8;
|
|
418
|
+
g.add(plinth, step, stem, bowl);
|
|
419
|
+
g.traverse((o) => { if (o instanceof THREE.Mesh) { o.castShadow = true; o.receiveShadow = true; } });
|
|
420
|
+
solid(plinth); g.position.set(bx, gy, bz); part.add(g);
|
|
421
|
+
// the fire: three flame cards breathing (normal blending, so overlapping tongues stay orange), a flickering light
|
|
422
|
+
const top = gy + 1.18, fire = animate(new THREE.Group(), FLAME_PULSE);
|
|
423
|
+
const flame = 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 });
|
|
424
|
+
for (let i = 0; i < 3; i++) {
|
|
425
|
+
const h = [1.9, 1.5, 1.3][i] ?? 1, s = new THREE.Sprite(flame);
|
|
426
|
+
// the cleanroom's mean frame (k = 0.85): the pulse breathes round it
|
|
427
|
+
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, -0.02, [0, 0.12, -0.14][i] ?? 0);
|
|
428
|
+
fire.add(s);
|
|
429
|
+
}
|
|
430
|
+
fire.position.set(bx, top, bz); part.add(fire);
|
|
431
|
+
// its halo (the cleanroom's instanced glows row: 2.6 m, #ff8a40 at 0.18, additive)
|
|
432
|
+
const halo = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex.glow, color: '#ff8a40', blending: THREE.AdditiveBlending, depthWrite: false, transparent: true, opacity: 0.18, fog: false }));
|
|
433
|
+
halo.scale.setScalar(2.6); halo.position.set(bx, top + 0.55, bz); part.add(halo);
|
|
434
|
+
const l = new THREE.PointLight('#ff9a3a', 16, 12, 1.5); l.position.set(bx, top + 0.7, bz); part.add(animate(l, LAMP_FLICKER));
|
|
435
|
+
// sparks: 36 seats round the bowl, each climbing 2.6 m and fading (the cleanroom's (s0 + t sp 0.4) % 1)
|
|
436
|
+
const sparks = new Float32Array(36 * 3);
|
|
437
|
+
for (let i = 0; i < 36; i++) sparks.set([bx + R(-0.35, 0.35), top + 0.4, bz + R(-0.35, 0.35)], i * 3);
|
|
438
|
+
const sparkCloud = new THREE.Points(new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(sparks, 3)),
|
|
439
|
+
new THREE.PointsMaterial({ map: tex.glow, color: new THREE.Color('#ffc060').multiplyScalar(3), size: 0.07, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }));
|
|
440
|
+
part.add(animate(sparkCloud, rise({ rate: 0.3, height: 2.6, spread: 0.5 })));
|
|
441
|
+
// ferns: nine fronds a clump, round the hut and the yard
|
|
442
|
+
const fernSpots: [number, number][] = [[-1.6, -12.4], [-6.8, -12.6], [-6.6, -12.0], [-2.2, -5.4], [3.1, -6.2], [1.6, -11.8], [4.4, -10.6], [-8.4, -9.2], [7.6, -14.6]];
|
|
443
|
+
{
|
|
444
|
+
const fg = new THREE.PlaneGeometry(0.3, 1.05, 1, 6); fg.translate(0, 0.52, 0);
|
|
445
|
+
const p = fg.attributes.position;
|
|
446
|
+
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)); }
|
|
447
|
+
fg.computeVertexNormals();
|
|
448
|
+
const im = new THREE.InstancedMesh(fg, new THREE.MeshStandardMaterial({ map: tex.frond, alphaTest: 0.4, side: THREE.DoubleSide, roughness: 0.8 }), fernSpots.length * 9);
|
|
449
|
+
const o = new THREE.Object3D();
|
|
450
|
+
let k = 0;
|
|
451
|
+
for (const [x, z] of fernSpots) {
|
|
452
|
+
const s = R(0.75, 1.25);
|
|
453
|
+
for (let f = 0; f < 9; f++) {
|
|
454
|
+
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));
|
|
455
|
+
o.scale.set(s, s * R(0.8, 1.1), s); o.updateMatrix(); im.setMatrixAt(k++, o.matrix);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
im.castShadow = true; part.add(animate(im, FOLIAGE_SWAY));
|
|
459
|
+
}
|
|
460
|
+
// grass cards: the cleanroom's crossed card, scattered within 24 m of the yard
|
|
461
|
+
{
|
|
462
|
+
const card = new THREE.PlaneGeometry(0.38, 0.28); card.translate(0, 0.13, 0);
|
|
463
|
+
const cross = mergeGeometries([card, card.clone().rotateY(Math.PI / 2)]);
|
|
464
|
+
const nrm = cross.attributes.normal;
|
|
465
|
+
if (nrm !== undefined) for (let i = 0; i < nrm.count; i++) nrm.setXYZ(i, 0, 1, 0);
|
|
466
|
+
const N = 1400, im = new THREE.InstancedMesh(cross, new THREE.MeshStandardMaterial({ map: tex.grass, alphaTest: 0.35, side: THREE.DoubleSide, roughness: 0.9 }), N);
|
|
467
|
+
const o = new THREE.Object3D(), c = new THREE.Color(), H = LAYOUT.HUT;
|
|
468
|
+
let k = 0, tries = 0;
|
|
469
|
+
while (k < N && tries < N * 5) {
|
|
470
|
+
tries++;
|
|
471
|
+
const r = Math.sqrt(rand()) * 24, a = R(0, Math.PI * 2), x = Math.cos(a) * r - 6, z = Math.sin(a) * r - 6;
|
|
472
|
+
if (x > H.x - H.w / 2 - 0.3 && x < H.x + H.w / 2 + 0.3 && z < H.z + H.d / 2 + 0.3 && z > H.z - H.d / 2 - 0.3) continue;
|
|
473
|
+
if (pondSDF(x, z) < 0.3) continue;
|
|
474
|
+
if (Math.hypot(x - bx, z - bz) < 1.3) continue;
|
|
475
|
+
if (noise.fbm(x * 0.25, z * 0.25, 2) < 0.42 && rand() < 0.75) continue;
|
|
476
|
+
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));
|
|
477
|
+
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)));
|
|
478
|
+
k++;
|
|
479
|
+
}
|
|
480
|
+
im.count = k; part.add(animate(im, FOLIAGE_SWAY));
|
|
481
|
+
}
|
|
482
|
+
// fireflies: 60 seats over the slice, each wandering 0.6 m round itself
|
|
483
|
+
const flies = new Float32Array(60 * 3);
|
|
484
|
+
for (let i = 0; i < 60; i++) flies.set([R(-24, 10), R(0.3, 2.4), R(-18, 6)], i * 3);
|
|
485
|
+
const flyCloud = new THREE.Points(new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(flies, 3)),
|
|
486
|
+
new THREE.PointsMaterial({ map: tex.glow, color: new THREE.Color('#ffd27a').multiplyScalar(2), size: 0.12, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }));
|
|
487
|
+
part.add(animate(flyCloud, drift({ rate: 0.3, radius: 0.6 })));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** The sunset light (cleanroom main.js 40-66): hemisphere, the key sun, the rim, the haze, the composer. */
|
|
491
|
+
export function sunset(world: ShardWorld): void {
|
|
492
|
+
// the sky dome (cleanroom sky.js) and the environment PMREM'd from it at 0.4 (main.js 63-70); under the skyline the
|
|
493
|
+
// cleanroom's environment sees the dome's haze, so the ground the engine filters with is that haze
|
|
494
|
+
const haze = new THREE.Color('#ffb878').multiplyScalar(0.92);
|
|
495
|
+
world.sky(sunsetSky(), { environment: { intensity: 0.4, ground: [haze.r, haze.g, haze.b] } });
|
|
496
|
+
world.scene.fog = new THREE.FogExp2(new THREE.Color('#d898a0'), 0.0062);
|
|
497
|
+
world.part('light', (part) => {
|
|
498
|
+
part.add(new THREE.HemisphereLight(new THREE.Color('#c4b0e4'), new THREE.Color('#7a6a3c'), 0.85));
|
|
499
|
+
const key = new THREE.DirectionalLight(new THREE.Color('#ffd6ae'), 2.2);
|
|
500
|
+
key.position.set(-26, 30, 34); key.castShadow = true;
|
|
501
|
+
part.add(key, key.target);
|
|
502
|
+
const rim = new THREE.DirectionalLight(new THREE.Color('#ff9a80'), 1.2);
|
|
503
|
+
rim.position.set(14, 5, -40);
|
|
504
|
+
part.add(rim);
|
|
505
|
+
});
|
|
506
|
+
world.post({ tone: 'aces', exposure: 1.05, bloom: { strength: 0.42, radius: 0.55, threshold: 0.9 }, vignette: 0.2 });
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** The slice: the light, the hut, the pond, the ground they stand on. */
|
|
510
|
+
export function buildSlice(world: ShardWorld): void {
|
|
511
|
+
const { M, tex } = materials();
|
|
512
|
+
sunset(world);
|
|
513
|
+
world.ground(groundHeight, { colourAt: groundColour });
|
|
514
|
+
world.part('hut', (part) => { hut(part, M, tex); });
|
|
515
|
+
world.part('pond', (part) => { pond(part, M, tex); });
|
|
516
|
+
world.part('yard', (part) => { yard(part, M, tex); });
|
|
517
|
+
world.spawn(-3.9, 0, -5.6, 0.03);
|
|
518
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// SHARD-SOURCE AP15: Mossgate Hollow whole, as one scene module. `wildshard build` runs this as the shard's generator (the
|
|
2
|
+
// shardfile back end); `wildshard watch` calls its describe() and streams the parts to a running page.
|
|
3
|
+
import { defineShard } from '@wildshard/sdk/scene/shard';
|
|
4
|
+
import { buildMossgate } from './world';
|
|
5
|
+
|
|
6
|
+
export const mossgate = defineShard({ slug: 'mossgate', name: 'Mossgate Hollow', author: 'Wildshard', revision: 1, seed: 357 }, buildMossgate);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The cleanroom's sunset sky dome (mossgate-cleanroom src/sky.js `makeSky`, 9cb4dc6) in TSL, line for line (SHARD-SOURCE
|
|
2
|
+
// AP14): periwinkle zenith, mauve, rose, a wide peach horizon glow, the low sun, small puffy clouds lit coral from below
|
|
3
|
+
// and a few stars. `world.sky(...)` compiles it to the dome's graph; the same value noise as the cleanroom's GLSL, so the
|
|
4
|
+
// clouds sit where the cleanroom's do. The detail and underside noise drop their finest octaves (weights 0.012 and 0.03 of
|
|
5
|
+
// the cloud shape) to fit the sky's budget (format look-sky, 1,024 instructions). Its `dusk` is 0 (the slice is the golden hour), so the night mix drops out.
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { dot, floor, fract, max, mix, normalize, pow, sin, smoothstep, step, vec2, vec3 } from 'three/tsl';
|
|
8
|
+
import { skyRay } from '@wildshard/sdk/scene/author';
|
|
9
|
+
import type { GraphValue } from '@wildshard/sdk/materials';
|
|
10
|
+
|
|
11
|
+
type V = ReturnType<typeof vec3>;
|
|
12
|
+
type F = ReturnType<typeof dot>;
|
|
13
|
+
type P = ReturnType<typeof vec2>;
|
|
14
|
+
|
|
15
|
+
/** The cleanroom's SKY colours (linear, as its uniforms hold them). */
|
|
16
|
+
const SKY = { zenith: '#2c3282', upper: '#5652a2', mid: '#b06ea2', low: '#f88c80', horizon: '#ffb878', sun: '#ffe6b0' };
|
|
17
|
+
const lin = (hex: string): V => { const c = new THREE.Color(hex); return vec3(c.r, c.g, c.b); };
|
|
18
|
+
/** Where the sun sits: just over the skyline behind the hut (cleanroom main.js `sunVisible`). */
|
|
19
|
+
export const SUN_DIRECTION = new THREE.Vector3(0.32, 0.035, -1).normalize();
|
|
20
|
+
|
|
21
|
+
const hash = (p: P): F => fract(sin(dot(p, vec2(127.1, 311.7))).mul(43758.5453));
|
|
22
|
+
function noise(p: P): F {
|
|
23
|
+
const i = floor(p), f = fract(p), u = f.mul(f).mul(f.mul(-2).add(3));
|
|
24
|
+
return mix(mix(hash(i), hash(i.add(vec2(1, 0))), u.x), mix(hash(i.add(vec2(0, 1))), hash(i.add(vec2(1, 1))), u.x), u.y);
|
|
25
|
+
}
|
|
26
|
+
/** The cleanroom's five-octave fbm; `octaves` below 5 drops the finest (each is half the weight of the one before). */
|
|
27
|
+
function fbm(start: P, octaves = 5): F {
|
|
28
|
+
let sum: F = noise(start).mul(0.5), p = start, a = 0.5;
|
|
29
|
+
for (let octave = 1; octave < octaves; octave++) { p = p.mul(2.07).add(13.1); a *= 0.5; sum = sum.add(noise(p).mul(a)); }
|
|
30
|
+
return sum;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The sky colour along the view ray. */
|
|
34
|
+
export function sunsetSky(): GraphValue {
|
|
35
|
+
const d = skyRay, h = d.y, e = max(h, 0);
|
|
36
|
+
const sun = vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z);
|
|
37
|
+
// the glow toward the sun's side is wider and warmer
|
|
38
|
+
const sd = max(dot(d, sun), 0);
|
|
39
|
+
const az = pow(max(dot(normalize(d.xz.add(1e-4)), normalize(vec2(SUN_DIRECTION.x, SUN_DIRECTION.z))), 0), 2);
|
|
40
|
+
const lift = az.mul(0.06).add(0.06); // the peach band climbs higher on the sun side
|
|
41
|
+
let col: V = lin(SKY.horizon);
|
|
42
|
+
col = mix(col, lin(SKY.low), smoothstep(lift.sub(0.02), lift.add(0.1), e));
|
|
43
|
+
col = mix(col, lin(SKY.mid), smoothstep(lift.add(0.06), 0.26, e));
|
|
44
|
+
col = mix(col, lin(SKY.upper), smoothstep(0.22, 0.42, e));
|
|
45
|
+
col = mix(col, lin(SKY.zenith), smoothstep(0.4, 0.75, e));
|
|
46
|
+
col = mix(col, lin(SKY.horizon).mul(0.92), smoothstep(0, -0.08, h)); // under the skyline: haze
|
|
47
|
+
// sun: wide warm wash, halo, disc sitting on the horizon
|
|
48
|
+
col = col.add(vec3(1, 0.62, 0.36).mul(pow(sd, 6).mul(0.4).mul(smoothstep(0, 0.4, e).oneMinus())));
|
|
49
|
+
col = col.add(lin(SKY.sun).mul(pow(sd, 120).mul(0.35)));
|
|
50
|
+
col = col.add(vec3(1, 0.85, 0.6).mul(smoothstep(0.99935, 0.9997, sd).mul(0.9)));
|
|
51
|
+
// puffy clouds: a plane projection, small cumulus clumps in a band
|
|
52
|
+
const cp = d.xz.div(max(h.add(0.08), 0.04)).mul(1.6);
|
|
53
|
+
const band = smoothstep(0.04, 0.1, h).mul(smoothstep(0.3, 0.5, h).oneMinus());
|
|
54
|
+
const shape = fbm(cp.mul(0.55).add(4)).mul(0.75).add(fbm(cp.mul(2.4).add(9), 4).mul(0.38));
|
|
55
|
+
const cloud = smoothstep(0.57, 0.68, shape).mul(band);
|
|
56
|
+
const underside = smoothstep(0.2, 0.75, fbm(cp.mul(2.4).add(vec2(0, 0.6)).add(9), 3)); // lit from below
|
|
57
|
+
const lit = mix(vec3(1, 0.46, 0.46), vec3(1, 0.56, 0.32), pow(sd, 2)).mul(0.86);
|
|
58
|
+
const shade = mix(lin(SKY.mid), lin(SKY.upper), 0.45).mul(0.95);
|
|
59
|
+
const cloudCol = mix(lit, shade, underside.mul(0.35)).mul(mix(1, 0.72, smoothstep(0.14, 0.45, e))); // high clouds sit in shade
|
|
60
|
+
col = mix(col, cloudCol, cloud.mul(0.92));
|
|
61
|
+
// stars, faint at the golden hour (dusk 0)
|
|
62
|
+
const st = step(0.9965, hash(floor(d.xz.div(max(h, 0.15)).mul(260)))).mul(smoothstep(0.35, 0.8, e));
|
|
63
|
+
return col.add(vec3(st, st, st).mul(0.15)).mul(0.95);
|
|
64
|
+
}
|