File size: 21,978 Bytes
59c7fd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
import * as THREE from 'three';
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
import { makeWood, makeConcrete, makeMetal, makeWindowGlow } from './textures.js';

const tmp = new THREE.Object3D();

function boxMesh(w, h, d, mat, x, y, z, parent, r = 0.004) {
  const m = new THREE.Mesh(new RoundedBoxGeometry(w, h, d, 2, r), mat);
  m.position.set(x, y, z);
  m.castShadow = true; m.receiveShadow = true;
  if (parent) parent.add(m);
  return m;
}

function beamTexture() {
  const c = document.createElement('canvas'); c.width = 128; c.height = 512;
  const g = c.getContext('2d');
  const grad = g.createLinearGradient(0, 0, 0, 512);
  grad.addColorStop(0, 'rgba(255,236,190,0.35)');
  grad.addColorStop(0.5, 'rgba(255,226,166,0.14)');
  grad.addColorStop(1, 'rgba(255,220,150,0)');
  g.fillStyle = grad; g.fillRect(0, 0, 128, 512);
  const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
}

export function createEnvironment(scene) {
  const root = new THREE.Group();
  root.name = 'environment';
  scene.add(root);

  /* ---------- floor ---------- */
  const conc = makeConcrete({ seed: 17, size: 1024, repeat: [12, 12] });
  const floorMat = new THREE.MeshStandardMaterial({
    map: conc.map, bumpMap: conc.bumpMap, roughnessMap: conc.roughnessMap,
    bumpScale: 0.02, roughness: 0.9, color: '#b3aa9b',
  });
  const floor = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), floorMat);
  floor.rotation.x = -Math.PI / 2;
  floor.receiveShadow = true;
  root.add(floor);

  // dark oiled patch under the bench area
  const patchMat = new THREE.MeshStandardMaterial({ color: '#5a4a37', roughness: 0.8, transparent: true, opacity: 0.35, depthWrite: false });
  const patch = new THREE.Mesh(new THREE.CircleGeometry(2.2, 48), patchMat);
  patch.rotation.x = -Math.PI / 2; patch.position.y = 0.002; patch.scale.set(1.45, 1, 1); root.add(patch);

  /* ---------- timber walls ---------- */
  const wallWood = makeWood({ base: '#70502f', dark: '#352112', light: '#a27a50', seed: 61, repeat: [3.1, 1.6], knots: 16, size: 1024 });
  const wallMat = new THREE.MeshStandardMaterial({
    map: wallWood.map, bumpMap: wallWood.bumpMap, roughnessMap: wallWood.roughnessMap,
    bumpScale: 0.03, roughness: 0.85, color: '#dcc7a8',
  });
  const darkWood = makeWood({ base: '#4a3220', dark: '#22150a', light: '#745334', seed: 73, repeat: [2, 2], knots: 4 });
  const darkMat = new THREE.MeshStandardMaterial({ map: darkWood.map, bumpMap: darkWood.bumpMap, roughness: 0.8, bumpScale: 0.02 });

  const W = 6.6, H = 4.9;
  // back wall with a large window opening
  const winX = -1.6, winW = 3.4, winY = 1.0, winH = 2.45;
  const wallZ = -W;
  // left of window
  boxMesh(W - (winW / 2 + winX) + 0.8, H, 0.25, wallMat, (-W + (winX - winW / 2)) / 2, H / 2, wallZ, root);
  // right of window
  const rightStart = winX + winW / 2;
  const rw = W - rightStart;
  boxMesh(rw + 0.8, H, 0.25, wallMat, rightStart + rw / 2 + 0.4, H / 2, wallZ, root);
  // above and below window
  boxMesh(winW, H - (winY + winH), 0.25, wallMat, winX, winY + winH + (H - winY - winH) / 2, wallZ, root);
  boxMesh(winW, winY, 0.25, wallMat, winX, winY / 2, wallZ, root);

  // side walls
  boxMesh(0.25, H, W * 2, wallMat, -W - 0.4, H / 2, 0, root);
  boxMesh(0.25, H, W * 2, wallMat, W + 0.4, H / 2, 0, root);
  // front wall (behind the hero camera, for 360 completeness)
  boxMesh(W * 2, H, 0.25, wallMat, 0, H / 2, W + 0.4, root);
  // lower wainscot band around walls
  boxMesh(W * 2, 1.0, 0.08, darkMat, 0, 0.5, -W + 0.17, root);
  boxMesh(0.08, 1.0, W * 2, darkMat, -W + 0.1, 0.5, 0, root);
  boxMesh(0.08, 1.0, W * 2, darkMat, W - 0.1, 0.5, 0, root);

  // vertical battens on back wall
  const battenGeo = new RoundedBoxGeometry(0.11, H, 0.06, 2, 0.006);
  const battens = new THREE.InstancedMesh(battenGeo, darkMat, 28);
  let bi = 0;
  for (let x = -W + 0.35; x < W - 0.2; x += 0.72) {
    for (const [y, h] of [[H / 2, H]]) {
      if (x > winX - winW / 2 - 0.1 && x < winX + winW / 2 + 0.1) continue;
      tmp.position.set(x, y, -W + 0.19);
      tmp.scale.set(1, 1, 1);
      tmp.rotation.set(0, 0, 0);
      tmp.updateMatrix();
      battens.setMatrixAt(bi++, tmp.matrix);
    }
  }
  battens.count = bi;
  battens.castShadow = true; battens.receiveShadow = true;
  root.add(battens);

  /* ---------- window ---------- */
  const glow = makeWindowGlow();
  const glowMat = new THREE.MeshBasicMaterial({ map: glow, toneMapped: false });
  const pane = new THREE.Mesh(new THREE.PlaneGeometry(winW - 0.16, winH - 0.16), glowMat);
  pane.position.set(winX, winY + winH / 2, -W + 0.06); root.add(pane);

  // frame
  const fMat = darkMat;
  boxMesh(winW + 0.24, 0.16, 0.22, fMat, winX, winY - 0.02, -W + 0.18, root); // sill
  boxMesh(winW + 0.24, 0.16, 0.22, fMat, winX, winY + winH + 0.02, -W + 0.18, root);
  boxMesh(0.16, winH + 0.2, 0.22, fMat, winX - winW / 2 - 0.02, winY + winH / 2, -W + 0.18, root);
  boxMesh(0.16, winH + 0.2, 0.22, fMat, winX + winW / 2 + 0.02, winY + winH / 2, -W + 0.18, root);
  boxMesh(0.09, winH, 0.16, fMat, winX, winY + winH / 2, -W + 0.18, root); // mullion
  boxMesh(winW, 0.09, 0.16, fMat, winX, winY + winH * 0.62, -W + 0.18, root); // transom

  // deep window reveal
  boxMesh(0.35, winH + 0.2, 0.35, darkMat, winX - winW / 2 - 0.1, winY + winH / 2, -W - 0.05, root);
  boxMesh(0.35, winH + 0.2, 0.35, darkMat, winX + winW / 2 + 0.1, winY + winH / 2, -W - 0.05, root);

  /* ---------- ceiling / rafters ---------- */
  const ceilMat = new THREE.MeshStandardMaterial({ color: '#3a2b1d', roughness: 0.95 });
  const ceil = new THREE.Mesh(new THREE.PlaneGeometry(W * 2, W * 2), ceilMat);
  ceil.rotation.x = Math.PI / 2; ceil.position.y = 5.3; ceil.receiveShadow = true; root.add(ceil);
  const rafterMat = darkMat;
  for (let i = -3; i <= 3; i++) {
    boxMesh(W * 2, 0.2, 0.16, rafterMat, 0, 4.7, i * 2.0, root);
    boxMesh(0.16, 0.2, W * 2, rafterMat, i * 2.0, 4.55, 0, root);
  }
  // ridge beam
  boxMesh(W * 2, 0.26, 0.26, rafterMat, 0, 5.02, 0, root);

  /* ---------- sun shafts ---------- */
  const bTex = beamTexture();
  const beamMat = new THREE.MeshBasicMaterial({
    map: bTex, transparent: true, opacity: 0.30, blending: THREE.AdditiveBlending,
    depthWrite: false, side: THREE.DoubleSide, toneMapped: false,
  });
  for (let i = 0; i < 4; i++) {
    const b = new THREE.Mesh(new THREE.PlaneGeometry(0.85, 6.5), beamMat);
    b.position.set(winX - 1.1 + i * 0.85, 2.2, -3.1);
    b.rotation.set(-0.48, 0, -0.38);
    root.add(b);
  }

  /* ---------- props: sawhorse + plank ---------- */
  const propGroup = new THREE.Group(); root.add(propGroup);
  function sawhorse(x, z, ry) {
    const s = new THREE.Group(); s.position.set(x, 0, z); s.rotation.y = ry; propGroup.add(s);
    for (const sx of [-1, 1]) {
      const a = boxMesh(0.075, 1.05, 0.075, darkMat, sx * 0.28, 0.48, 0.19, s);
      a.rotation.x = -0.3; a.rotation.z = sx * 0.08;
      const b = boxMesh(0.075, 1.05, 0.075, darkMat, sx * 0.28, 0.48, -0.19, s);
      b.rotation.x = 0.3; b.rotation.z = sx * 0.08;
    }
    boxMesh(1.0, 0.11, 0.16, darkMat, 0, 0.92, 0, s, 0.01);
    boxMesh(0.9, 0.06, 0.09, darkMat, 0, 0.4, 0, s, 0.006);
    return s;
  }
  const sh = sawhorse(-3.9, -1.4, 0.18);
  const plank = boxMesh(1.9, 0.055, 0.3, wallMat, 0, 1.0, 0, sh, 0.006);
  plank.rotation.z = 0.02;

  /* ---------- lumber stack / leaning boards ---------- */
  const stack = new THREE.Group(); stack.position.set(3.6, 0, -3.6); stack.rotation.y = -0.3; root.add(stack);
  for (let i = 0; i < 7; i++) {
    const b = boxMesh(2.1, 0.065, 0.26, wallMat, (i % 2) * 0.08, 0.04 + i * 0.07, (i % 3) * 0.04, stack, 0.005);
    b.rotation.y = (i % 2 ? 1 : -1) * 0.018;
    b.material = i % 2 ? darkMat : wallMat;
  }
  for (let i = 0; i < 4; i++) {
    const b = boxMesh(0.06, 2.4, 0.3, wallMat, 2.35 + i * 0.02, 1.2, -0.2 + i * 0.17, stack, 0.005);
    b.rotation.z = -0.16 - i * 0.008;
  }

  /* ---------- tool chest on right ---------- */
  const chest = new THREE.Group(); chest.position.set(3.9, 0, 0.5); chest.rotation.y = -0.5; root.add(chest);
  boxMesh(0.95, 0.55, 0.55, darkMat, 0, 0.28, 0, chest, 0.012);
  boxMesh(1.0, 0.08, 0.6, wallMat, 0, 0.59, 0, chest, 0.01);
  for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
    const h = new THREE.Mesh(new THREE.TorusGeometry(0.045, 0.012, 8, 12, Math.PI), new THREE.MeshStandardMaterial({ color: '#2a2a2a', metalness: 0.8, roughness: 0.5 }));
    h.position.set(sx * 0.25, 0.63, sz * 0.31); h.rotation.y = Math.PI / 2; chest.add(h);
  }
  // saw on chest
  {
    const saw = new THREE.Group(); saw.position.set(0.05, 0.68, 0); saw.rotation.set(0.12, 0.4, 0.1); chest.add(saw);
    const bladeShape = new THREE.Shape();
    bladeShape.moveTo(-0.34, 0); bladeShape.lineTo(0.32, 0); bladeShape.lineTo(0.36, 0.05);
    bladeShape.lineTo(0.28, 0.1); bladeShape.lineTo(-0.3, 0.12); bladeShape.closePath();
    const bg = new THREE.ExtrudeGeometry(bladeShape, { depth: 0.004, bevelEnabled: false });
    const bm = new THREE.Mesh(bg, new THREE.MeshStandardMaterial({ color: '#b9bcc0', metalness: 1, roughness: 0.3, side: THREE.DoubleSide }));
    bm.castShadow = true; saw.add(bm);
    boxMesh(0.16, 0.2, 0.035, darkMat, -0.4, 0.07, 0, saw, 0.02);
  }

  /* ---------- hanging tools on back wall ---------- */
  const hang = new THREE.Group(); root.add(hang);
  const steelMat = new THREE.MeshStandardMaterial({ color: '#8f9497', metalness: 1, roughness: 0.4 });
  function hangSaw(x, y, ry) {
    const s = new THREE.Group(); s.position.set(x, y, -W + 0.14); s.rotation.z = ry; hang.add(s);
    const sh = new THREE.Shape();
    sh.moveTo(0, 0); sh.lineTo(0.65, 0.02); sh.lineTo(0.72, 0.1); sh.lineTo(0.6, 0.17); sh.lineTo(0.02, 0.2); sh.closePath();
    const gm = new THREE.Mesh(new THREE.ExtrudeGeometry(sh, { depth: 0.008, bevelEnabled: true, bevelSize: 0.002, bevelThickness: 0.001, bevelSegments: 1 }), steelMat);
    gm.castShadow = true; s.add(gm);
    boxMesh(0.16, 0.22, 0.035, darkMat, -0.05, 0.1, 0.01, s, 0.018);
    for (let i = 0; i < 16; i++) {
      const tooth = boxMesh(0.012, 0.03, 0.008, steelMat, 0.05 + i * 0.04, -0.012, 0.004, s);
      tooth.rotation.z = 0.25;
    }
  }
  hangSaw(2.7, 2.3, 0.12);
  hangSaw(4.2, 1.7, -0.4);

  // chisel rack on the wall left of the window
  const rack = new THREE.Group(); rack.position.set(-4.0, 2.15, -W + 0.18); root.add(rack);
  boxMesh(1.25, 0.07, 0.1, darkMat, 0, 0, 0, rack, 0.008);
  for (let i = 0; i < 6; i++) {
    const x = -0.5 + i * 0.2;
    const h = boxMesh(0.028, 0.34, 0.03, darkMat, x, 0.2, 0, rack, 0.01);
    h.rotation.z = 0.03;
    const bl = boxMesh(0.04, 0.2, 0.008, steelMat, x, 0.4, 0.002, rack);
    bl.rotation.z = 0.03;
  }
  // jar shelf
  const shelf = new THREE.Group(); shelf.position.set(-4.6, 1.55, -W + 0.3); root.add(shelf);
  boxMesh(1.7, 0.06, 0.38, darkMat, 0, 0, 0, shelf, 0.008);
  for (let i = 0; i < 5; i++) {
    const jarMat = new THREE.MeshStandardMaterial({ color: i % 2 ? '#8b7b5a' : '#6e7a72', roughness: 0.4, metalness: 0.2, transparent: true, opacity: 0.92 });
    const jar = new THREE.Mesh(new THREE.CylinderGeometry(0.075, 0.08, 0.18 + (i % 3) * 0.04, 14), jarMat);
    jar.position.set(-0.65 + i * 0.3, 0.12, 0); jar.castShadow = true; shelf.add(jar);
    const lid = new THREE.Mesh(new THREE.CylinderGeometry(0.078, 0.078, 0.025, 14), steelMat);
    lid.position.set(-0.65 + i * 0.3, 0.22 + (i % 3) * 0.02, 0); shelf.add(lid);
  }

  /* ---------- wall framing, tool board, front door ---------- */
  // heavy horizontal beam across the back wall
  boxMesh(W * 2, 0.24, 0.3, darkMat, 0, 4.18, -W + 0.2, root, 0.01);
  boxMesh(0.22, H, 0.3, darkMat, -W + 0.22, H / 2, W - 0.22, root, 0.008);
  boxMesh(0.22, H, 0.3, darkMat, W - 0.22, H / 2, W - 0.22, root, 0.008);
  for (const x of [-5.9, -3.0, 1.4, 4.6]) {
    boxMesh(0.16, H, 0.16, darkMat, x, H / 2, -W + 0.22, root, 0.008);
  }

  // pegboard tool board left of the window
  const board = new THREE.Group(); board.position.set(-5.05, 2.45, -W + 0.23); root.add(board);
  boxMesh(2.1, 1.55, 0.07, darkMat, 0, 0, 0, board, 0.008);
  boxMesh(2.2, 0.09, 0.12, wallMat, 0, 0.82, 0.03, board, 0.006);
  const pegGeo = new THREE.CylinderGeometry(0.005, 0.005, 0.02, 6);
  const pegMat = new THREE.MeshStandardMaterial({ color: '#281d13', roughness: 1 });
  const pegs = new THREE.InstancedMesh(pegGeo, pegMat, 48);
  let pi = 0;
  for (let gy = 0; gy < 5; gy++) for (let gx = 0; gx < 10; gx++) {
    tmp.position.set(-0.9 + gx * 0.2, -0.6 + gy * 0.25, 0.04);
    tmp.rotation.set(Math.PI / 2, 0, 0); tmp.scale.set(1, 1, 1); tmp.updateMatrix();
    pegs.setMatrixAt(pi++, tmp.matrix);
  }
  pegs.count = pi; board.add(pegs);
  // try squares and clamps on the board
  const steel2 = new THREE.MeshStandardMaterial({ color: '#8a9094', metalness: 1, roughness: 0.35 });
  for (const [x, y, ry, s] of [[-0.62, 0.35, 0.25, 1], [0.55, 0.18, -0.2, 0.85], [1.4, 0.34, 0.36, 0.7]]) {
    const sq = new THREE.Group(); sq.position.set(x, y, 0.08); sq.rotation.z = ry; sq.scale.setScalar(s); board.add(sq);
    boxMesh(0.035, 0.5, 0.01, steel2, 0, -0.2, 0, sq);
    boxMesh(0.28, 0.035, 0.01, steel2, 0.12, 0.02, 0, sq);
    boxMesh(0.055, 0.6, 0.03, darkMat, 0, -0.15, -0.02, sq, 0.01);
  }
  // wooden plane till
  const till = new THREE.Group(); till.position.set(-4.9, 1.5, -W + 0.35); till.rotation.x = -0.18; root.add(till);
  boxMesh(1.5, 0.08, 0.42, darkMat, 0, 0, 0, till, 0.008);
  for (let i = 0; i < 3; i++) {
    const p = boxMesh(0.24, 0.075, 0.065, i === 1 ? darkMat : wallMat, -0.4 + i * 0.35, 0.075, 0, till, 0.015);
    p.rotation.y = 0.04;
    boxMesh(0.06, 0.11, 0.05, darkMat, -0.37 + i * 0.35, 0.14, 0, till, 0.012);
  }

  /* ---------- big front door (for reverse orbits) ---------- */
  const door = new THREE.Group(); door.position.set(2.6, 0, W + 0.25); root.add(door);
  boxMesh(1.8, 1.8, 0.2, wallMat, 0, 4.0, 0, door, 0.012);
  boxMesh(1.95, 3.3, 0.16, darkMat, 0, 1.65, -0.02, door, 0.012);
  boxMesh(1.65, 3.1, 0.1, wallMat, 0, 1.6, -0.12, door, 0.008);
  for (const sy of [-1, 1]) {
    const b = boxMesh(1.8, 0.15, 0.08, darkMat, 0, 1.6 + sy * 1.1, -0.2, door, 0.008);
    b.rotation.z = sy * 0.62;
  }
  for (const sy of [-1, 1]) {
    boxMesh(0.04, 0.5, 0.06, steel2, 0.72, 1.6 + sy * 0.9, -0.2, door);
  }
  const handle = new THREE.Mesh(new THREE.TorusGeometry(0.075, 0.014, 8, 16), steel2);
  handle.position.set(0.58, 1.55, -0.21); handle.rotation.y = Math.PI / 2; door.add(handle);

  // shelf beside door
  const sideShelf = new THREE.Group(); sideShelf.position.set(5.1, 2.1, W + 0.1); root.add(sideShelf);
  boxMesh(1.6, 0.07, 0.4, darkMat, 0, 0, 0, sideShelf, 0.008);
  for (let i = 0; i < 3; i++) {
    const b = boxMesh(0.34, 0.28 + i * 0.04, 0.3, i === 1 ? darkMat : wallMat, -0.45 + i * 0.45, 0.18, 0, sideShelf, 0.01);
    b.rotation.y = i * 0.1;
  }

  /* ---------- ladder + crates on the front wall ---------- */
  const ladder = new THREE.Group(); ladder.position.set(-2.7, 0, W - 0.55); ladder.rotation.x = -0.14; root.add(ladder);
  for (const sx of [-1, 1]) {
    boxMesh(0.075, 3.55, 0.075, darkMat, sx * 0.31, 1.77, 0, ladder, 0.006);
  }
  for (let i = 0; i < 9; i++) {
    boxMesh(0.68, 0.055, 0.06, darkMat, 0, 0.25 + i * 0.37, 0, ladder, 0.005);
  }
  const crates = new THREE.Group(); crates.position.set(-4.6, 0, W - 1.05); crates.rotation.y = 0.22; root.add(crates);
  for (let i = 0; i < 3; i++) {
    const c = boxMesh(0.85, 0.5, 0.6, i % 2 ? darkMat : wallMat, 0, 0.25 + i * 0.51, 0, crates, 0.01);
    for (const sx of [-1, 1]) boxMesh(0.05, 0.42, 0.62, darkMat, sx * 0.4, 0.25 + i * 0.51, 0, crates, 0.004);
  }
  // coats / aprons hanging by the door
  for (let i = 0; i < 2; i++) {
    const coat = new THREE.Group(); coat.position.set(1.35 + i * 0.55, 2.15, W + 0.1); root.add(coat);
    const clothMat = new THREE.MeshStandardMaterial({ color: i ? '#6b7159' : '#7a5c42', roughness: 0.95 });
    const cv = new THREE.Mesh(new THREE.CylinderGeometry(0.17, 0.22, 0.85, 10, 1, true), clothMat);
    cv.position.y = -0.42; cv.castShadow = true; coat.add(cv);
    const cd = new THREE.Mesh(new THREE.SphereGeometry(0.19, 10, 8, 0, Math.PI * 2, 0, Math.PI / 2), clothMat);
    cd.position.y = 0.0; cd.castShadow = true; coat.add(cd);
    boxMesh(0.04, 0.04, 0.12, steel2, 0, 0.08, 0.02, coat);
  }

  /* ---------- side wall shelving / clamps ---------- */
  for (const x of [-5.6, 4.9]) {
    for (let i = 0; i < 4; i++) {
      const c = new THREE.Group(); c.position.set(x > 0 ? W - 0.28 : -W + 0.28, 1.9 + i * 0.42, x > 0 ? -2.6 : -2.0); root.add(c);
      const bar = boxMesh(0.04, 0.05, 0.5, darkMat, 0, 0, 0, c, 0.005);
      boxMesh(0.12, 0.22, 0.1, darkMat, 0, 0.08, 0.18, c, 0.01);
      boxMesh(0.12, 0.22, 0.1, darkMat, 0, 0.08, -0.18, c, 0.01);
    }
  }

  /* ---------- bucket of shavings + floor curls ---------- */
  const bucket = new THREE.Group(); bucket.position.set(-2.7, 0, 2.0); bucket.rotation.y = 0.4; root.add(bucket);
  const staveMat = new THREE.MeshStandardMaterial({ color: '#7e5a38', roughness: 0.85 });
  const bucketGeo = new THREE.CylinderGeometry(0.26, 0.23, 0.46, 18, 1, true);
  const bucketMesh = new THREE.Mesh(bucketGeo, staveMat);
  bucketMesh.castShadow = true; bucketMesh.receiveShadow = true; bucket.add(bucketMesh);
  for (const y of [-0.14, 0.14]) {
    const hoop = new THREE.Mesh(new THREE.TorusGeometry(0.255 + y * 0.05, 0.012, 6, 22), steel2);
    hoop.rotation.x = Math.PI / 2; hoop.position.y = y; hoop.castShadow = true; bucket.add(hoop);
  }
  const fill = new THREE.Mesh(new THREE.CylinderGeometry(0.24, 0.24, 0.12, 18), new THREE.MeshStandardMaterial({ color: '#d8b884', roughness: 0.9 }));
  fill.position.y = 0.18; bucket.add(fill);
  const curlMat = new THREE.MeshStandardMaterial({ color: '#e2c28d', roughness: 0.85, side: THREE.DoubleSide });
  for (let i = 0; i < 7; i++) {
    const pts = [];
    for (let j = 0; j <= 30; j++) {
      const t = j / 30, a = t * Math.PI * 4;
      pts.push(new THREE.Vector3(Math.cos(a) * (0.03 + t * 0.05), t * 0.05, Math.sin(a) * (0.03 + t * 0.05)));
    }
    const cg = new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), 50, 0.006, 5);
    const cm = new THREE.Mesh(cg, curlMat);
    cm.position.set(-0.08 + (i % 3) * 0.07, 0.24 + (i % 2) * 0.03, -0.05 + (i % 4) * 0.035);
    cm.rotation.set(i, i * 0.7, 0); cm.castShadow = true; bucket.add(cm);
  }
  // scattered floor shavings
  for (let i = 0; i < 10; i++) {
    const pts = [];
    for (let j = 0; j <= 24; j++) {
      const t = j / 24, a = t * Math.PI * 3;
      pts.push(new THREE.Vector3(Math.cos(a) * (0.02 + t * 0.04), Math.sin(t * 3) * 0.004, Math.sin(a) * (0.02 + t * 0.04)));
    }
    const cg = new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), 44, 0.004, 4);
    const cm = new THREE.Mesh(cg, curlMat);
    const a = i * 2.1, r = 1.8 + (i % 3) * 0.55;
    cm.position.set(Math.cos(a) * r + 1.0, 0.008, Math.sin(a) * r + 0.9);
    cm.rotation.y = i * 1.3; cm.scale.setScalar(0.8 + (i % 3) * 0.3); root.add(cm);
  }

  /* ---------- floor wood scraps / shavings ---------- */
  const scrapMat = new THREE.MeshStandardMaterial({ color: '#a7794a', roughness: 0.9 });
  const scrapGeo = new RoundedBoxGeometry(0.25, 0.03, 0.09, 2, 0.004);
  const scraps = new THREE.InstancedMesh(scrapGeo, scrapMat, 16);
  for (let i = 0; i < 16; i++) {
    const a = i * 1.7;
    const r = 1.5 + (i % 5) * 0.25;
    tmp.position.set(Math.cos(a) * r + 1.7, 0.016, Math.sin(a) * r * 0.7 + 0.8);
    tmp.rotation.set(0, a * 1.3, 0.02);
    tmp.scale.set(1, 1, 1);
    tmp.updateMatrix(); scraps.setMatrixAt(i, tmp.matrix);
  }
  scraps.castShadow = true; scraps.receiveShadow = true; root.add(scraps);

  /* ---------- dust motes ---------- */
  const dustCount = 420;
  const dustGeo = new THREE.BufferGeometry();
  const dpos = new Float32Array(dustCount * 3);
  for (let i = 0; i < dustCount; i++) {
    dpos[i * 3] = (Math.random() - 0.5) * 11;
    dpos[i * 3 + 1] = 0.2 + Math.random() * 4.4;
    dpos[i * 3 + 2] = (Math.random() - 0.5) * 11;
  }
  dustGeo.setAttribute('position', new THREE.BufferAttribute(dpos, 3));
  const dc = document.createElement('canvas'); dc.width = dc.height = 64;
  const dg = dc.getContext('2d');
  const dgrad = dg.createRadialGradient(32, 32, 0, 32, 32, 32);
  dgrad.addColorStop(0, 'rgba(255,244,214,0.9)');
  dgrad.addColorStop(0.3, 'rgba(255,236,190,0.35)');
  dgrad.addColorStop(1, 'rgba(255,230,180,0)');
  dg.fillStyle = dgrad; dg.fillRect(0, 0, 64, 64);
  const dustTex = new THREE.CanvasTexture(dc); dustTex.colorSpace = THREE.SRGBColorSpace;
  const dustMat = new THREE.PointsMaterial({
    map: dustTex, size: 0.035, transparent: true, opacity: 0.55,
    depthWrite: false, blending: THREE.AdditiveBlending, sizeAttenuation: true,
  });
  const dustPts = new THREE.Points(dustGeo, dustMat);
  root.add(dustPts);

  /* ---------- sky dome ---------- */
  const skyGeo = new THREE.SphereGeometry(80, 32, 20);
  const skyMat = new THREE.ShaderMaterial({
    side: THREE.BackSide, depthWrite: false,
    uniforms: {
      top: { value: new THREE.Color('#7fa9c9') },
      mid: { value: new THREE.Color('#efdfc0') },
      bot: { value: new THREE.Color('#c79a6a') },
    },
    vertexShader: `varying vec3 vP; void main(){ vP = position; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }`,
    fragmentShader: `varying vec3 vP; uniform vec3 top; uniform vec3 mid; uniform vec3 bot;
      void main(){ float h = normalize(vP).y;
        vec3 c = mix(bot, mid, smoothstep(-0.15, 0.18, h));
        c = mix(c, top, smoothstep(0.16, 0.7, h));
        gl_FragColor = vec4(c, 1.0);
      }`,
  });
  const sky = new THREE.Mesh(skyGeo, skyMat);
  root.add(sky);

  scene.fog = new THREE.Fog(0x9a8b74, 12, 42);

  return {
    root, dustPts, beamMat,
    update(t) {
      dustPts.rotation.y = t * 0.008;
      dustPts.position.y = Math.sin(t * 0.22) * 0.04;
      beamMat.opacity = 0.26 + Math.sin(t * 0.35) * 0.03;
    },
  };
}