import * as THREE from 'three'; import * as T from './textures'; import type { World } from './index'; import { PICK_LAYER, invisibleInk } from './common'; /** * Le bureau du professeur, en 3D, construit par code (primitives + textures * canvas). Les objets interactifs portent un `name` : c'est ce nom que le * scenario.json référence. Un modèle Blender (.glb) avec les mêmes noms * d'objets pourrait remplacer ce fichier sans toucher au scénario. * * Repère : mètres, pièce de 6 × 6 × 3 m centrée sur l'origine. * Nord = z négatif, Est = x positif. Chaque mur a son repère local : * x = droite de l'écran quand on regarde le mur, y = hauteur, z = vers la pièce. */ const ROOM = 6; const HEIGHT = 3; // --- Matériaux ------------------------------------------------------------------- const grain = T.woodGrain(); const wood = (color: string, rough = 0.6) => new THREE.MeshStandardMaterial({ color, map: grain, roughness: rough, metalness: 0 }); const M = { woodDark: wood('#4a2d1a'), woodMid: wood('#6b4428', 0.5), woodLight: wood('#8a5c38', 0.45), woodBlack: wood('#2a1a10', 0.7), brass: new THREE.MeshStandardMaterial({ color: '#c9a24a', metalness: 0.85, roughness: 0.3 }), metal: new THREE.MeshStandardMaterial({ color: '#5d6268', metalness: 0.7, roughness: 0.45 }), dark: new THREE.MeshStandardMaterial({ color: '#120a05', roughness: 1 }), leather: new THREE.MeshStandardMaterial({ color: '#6e3324', roughness: 0.55 }), green: new THREE.MeshStandardMaterial({ color: '#3a8a55', roughness: 0.3, metalness: 0.1, side: THREE.DoubleSide }), curtain: new THREE.MeshStandardMaterial({ color: '#5a1a1f', roughness: 0.9, side: THREE.DoubleSide }), ceiling: new THREE.MeshStandardMaterial({ color: '#151c1d', roughness: 1 }), paper: new THREE.MeshStandardMaterial({ color: '#efe6cf', roughness: 0.9 }), }; // --- Aides de construction -------------------------------------------------------------- function box(w: number, h: number, d: number, mat: THREE.Material | THREE.Material[], x = 0, y = 0, z = 0, name?: string): THREE.Mesh { const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat); m.position.set(x, y, z); if (name) m.name = name; return m; } function group(name: string | undefined, x = 0, y = 0, z = 0, ...children: THREE.Object3D[]): THREE.Group { const g = new THREE.Group(); if (name) g.name = name; g.position.set(x, y, z); if (children.length) g.add(...children); return g; } function plane(w: number, h: number, mat: THREE.Material, x = 0, y = 0, z = 0, name?: string): THREE.Mesh { const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h), mat); m.position.set(x, y, z); if (name) m.name = name; return m; } /** * Zone cliquable invisible : agrandit la cible d'un petit objet (clé) ou * délimite un détail peint dans une texture (chiffre du tableau). */ function pickZone(w: number, h: number, x: number, y: number, z: number, name?: string): THREE.Mesh { const m = plane(w, h, new THREE.MeshBasicMaterial({ side: THREE.DoubleSide }), x, y, z, name); m.layers.set(PICK_LAYER); m.userData.noShadow = true; return m; } function decal(tex: THREE.Texture, w: number, h: number, x: number, y: number, z: number, name?: string, rotZ = 0): THREE.Mesh { // Légère émission pour que la peinture reste lisible dans la pénombre. const mat = new THREE.MeshStandardMaterial({ map: tex, emissiveMap: tex, emissive: '#ffffff', emissiveIntensity: 0.35, transparent: true, roughness: 0.7, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2 }); const m = plane(w, h, mat, x, y, z, name); m.rotation.z = rotZ; m.userData.noShadow = true; return m; } /** Repère d'un mur : rotation autour de y et position du centre au sol. */ function wallFrame(rotY: number, x: number, z: number): THREE.Group { const g = new THREE.Group(); g.rotation.y = rotY; g.position.set(x, 0, z); return g; } /** Mur plein avec ouvertures éventuelles ; UV en mètres (texture répétée). */ function wallMesh(holes: { x: number; y: number; w: number; h: number }[]): THREE.Mesh { const half = ROOM / 2; const shape = new THREE.Shape(); shape.moveTo(-half, 0); shape.lineTo(half, 0); shape.lineTo(half, HEIGHT); shape.lineTo(-half, HEIGHT); shape.closePath(); for (const hole of holes) { const p = new THREE.Path(); p.moveTo(hole.x - hole.w / 2, hole.y); p.lineTo(hole.x - hole.w / 2, hole.y + hole.h); p.lineTo(hole.x + hole.w / 2, hole.y + hole.h); p.lineTo(hole.x + hole.w / 2, hole.y); p.closePath(); shape.holes.push(p); } const mat = new THREE.MeshStandardMaterial({ map: wallpaperTex, roughness: 0.85, shadowSide: THREE.DoubleSide }); const mesh = new THREE.Mesh(new THREE.ShapeGeometry(shape), mat); mesh.name = 'mur'; mesh.receiveShadow = true; mesh.castShadow = true; return mesh; } /** Boiserie basse + cimaise + plinthe entre x0 et x1 (repère du mur). */ function wainscotRun(x0: number, x1: number): THREE.Group { const w = x1 - x0; const cx = (x0 + x1) / 2; const tex = wainscotTex.clone(); tex.wrapS = THREE.RepeatWrapping; tex.repeat.set(w / 0.8, 1); tex.needsUpdate = true; const panel = plane(w, 0.83, new THREE.MeshStandardMaterial({ map: tex, roughness: 0.6 }), cx, 0.12 + 0.415, 0.012); panel.receiveShadow = true; return group( undefined, 0, 0, 0, panel, box(w, 0.06, 0.05, M.woodMid, cx, 0.97, 0.025), box(w, 0.13, 0.025, M.woodBlack, cx, 0.065, 0.0125), box(w, 0.08, 0.06, M.woodMid, cx, HEIGHT - 0.04, 0.03), ); } let wallpaperTex: THREE.CanvasTexture; let wainscotTex: THREE.CanvasTexture; // --- Mobilier ------------------------------------------------------------------------ function desk(): THREE.Group { const top = box(1.66, 0.04, 0.8, M.woodLight, 0, 0.78, 0, 'deskTop'); const pedestal = (name: string, x: number) => { const g = group(name, x, 0, 0); g.add(box(0.5, 0.68, 0.72, M.woodDark, 0, 0.42, 0)); for (const y of [0.6, 0.26]) { const front = box(0.46, 0.3, 0.02, M.woodMid, 0, 0, 0.37); const handle = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.1, 12), M.brass); handle.rotation.z = Math.PI / 2; handle.position.set(0, 0, 0.39); const drawer = group(undefined, 0, y, 0, front, handle); // Le tiroir du haut à gauche s'ouvre réellement (contenu : factures + lampe UV). if (name === 'drawersLeft' && y === 0.6) { drawer.name = 'drawerL1'; drawer.add(...drawerBody(), ...drawerContents()); } g.add(drawer); } for (const fx of [-0.22, 0.22]) for (const fz of [-0.32, 0.32]) g.add(box(0.05, 0.08, 0.05, M.woodBlack, fx, 0.04, fz)); return g; }; /** Caisson intérieur d'un tiroir (visible une fois tiré). */ function drawerBody(): THREE.Object3D[] { const inside = new THREE.MeshStandardMaterial({ color: '#3a2414', map: grain, roughness: 0.9 }); return [ box(0.42, 0.01, 0.5, inside, 0, -0.12, 0.11), box(0.01, 0.2, 0.5, inside, -0.205, -0.03, 0.11), box(0.01, 0.2, 0.5, inside, 0.205, -0.03, 0.11), box(0.42, 0.2, 0.01, inside, 0, -0.03, -0.14), ]; } /** Factures en vrac et lampe UV à moitié cachée dessous. */ function drawerContents(): THREE.Object3D[] { const paper = (c: string) => new THREE.MeshStandardMaterial({ color: c, roughness: 0.95 }); const sheets: THREE.Object3D[] = []; [ ['#e9e1cc', -0.07, 0.12, 0.15], ['#ddd3b8', -0.05, 0.16, -0.1], ['#efe8d6', -0.02, 0.1, 0.32], ].forEach(([c, x, z, r], i) => { const s = box(0.17, 0.003, 0.12, paper(c as string), x as number, -0.113 + i * 0.004, z as number); s.rotation.y = r as number; sheets.push(s); }); // Lampe UV : corps sombre, tête et lentille violette qui dépasse des factures const body = new THREE.Mesh(new THREE.CylinderGeometry(0.016, 0.016, 0.12, 16), new THREE.MeshStandardMaterial({ color: '#3d4247', metalness: 0.6, roughness: 0.4 })); body.rotation.z = Math.PI / 2; const head = new THREE.Mesh(new THREE.CylinderGeometry(0.024, 0.02, 0.035, 16), new THREE.MeshStandardMaterial({ color: '#2c2f33', metalness: 0.6, roughness: 0.4 })); head.rotation.z = Math.PI / 2; head.position.x = 0.075; const lens = new THREE.Mesh(new THREE.CircleGeometry(0.02, 16), new THREE.MeshStandardMaterial({ color: '#6a3fc0', emissive: '#4a2a90', emissiveIntensity: 0.6, roughness: 0.2 })); lens.rotation.y = Math.PI / 2; lens.position.x = 0.093; const zone = pickZone(0.18, 0.09, 0.02, 0, 0); zone.rotation.x = -Math.PI / 2; const lamp = group('uvlampItem', 0.085, -0.098, 0.15, body, head, lens, zone); lamp.rotation.y = 0.5; // Une facture posée en travers de la lampe const over = box(0.15, 0.003, 0.1, paper('#e4dcc4'), 0.02, -0.08, 0.16); over.rotation.set(0.12, -0.4, 0.05); return [...sheets, lamp, over]; } // Tiroir secret : façade sans poignée, identique au bandeau du bureau. const drawerInside = new THREE.MeshStandardMaterial({ color: '#2a1a0e', roughness: 1 }); const keyGroup = key(); keyGroup.position.set(0.02, -0.042, 0.12); const secret = group( 'secretDrawer', 0, 0.69, 0, box(0.58, 0.13, 0.02, M.woodMid, 0, 0, 0.365, 'secretFront'), box(0.54, 0.01, 0.5, drawerInside, 0, -0.05, 0.11), box(0.01, 0.1, 0.5, drawerInside, -0.27, 0, 0.11), box(0.01, 0.1, 0.5, drawerInside, 0.27, 0, 0.11), box(0.54, 0.1, 0.01, drawerInside, 0, 0, -0.14), keyGroup, ); // Lampe de banquier const base = new THREE.Mesh(new THREE.CylinderGeometry(0.09, 0.1, 0.02, 32), M.brass); base.position.y = 0.01; const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.3, 12), M.brass); stem.position.y = 0.16; const shade = new THREE.Mesh(new THREE.CylinderGeometry(0.11, 0.11, 0.38, 32, 1, true, 0, Math.PI), M.green); shade.rotation.z = Math.PI / 2; shade.position.y = 0.32; const bulb = new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.02, 0.3, 12), new THREE.MeshStandardMaterial({ color: '#fff3d6', emissive: '#ffd59a', emissiveIntensity: 1.6 })); bulb.rotation.z = Math.PI / 2; bulb.position.y = 0.3; bulb.userData.noShadow = true; const lampLight = new THREE.PointLight('#ffc98a', 2.2, 0, 2); lampLight.position.set(0, 0.24, 0.05); lampLight.castShadow = true; lampLight.shadow.mapSize.set(1024, 1024); lampLight.shadow.bias = -0.002; lampLight.shadow.radius = 4; const lamp = group('lamp', -0.52, 0.8, -0.12, base, stem, shade, bulb, lampLight); // Livres, encrier const books = group( 'deskBooks', 0.56, 0.8, -0.08, box(0.26, 0.06, 0.2, wood('#6b2a2a', 0.8), 0, 0.03, 0), box(0.23, 0.05, 0.18, wood('#2a4a6b', 0.8), 0.01, 0.085, 0, undefined), box(0.2, 0.045, 0.17, wood('#5a5a2a', 0.8), -0.01, 0.133, 0), ); books.rotation.y = -0.12; const quill = new THREE.Mesh(new THREE.CylinderGeometry(0.002, 0.004, 0.22, 6), new THREE.MeshStandardMaterial({ color: '#eeeeee' })); quill.position.set(0.03, 0.11, 0); quill.rotation.z = -0.5; const ink = group('inkwell', 0.26, 0.8, -0.05, new THREE.Mesh(new THREE.CylinderGeometry(0.03, 0.035, 0.05, 16), new THREE.MeshStandardMaterial({ color: '#1a2433', roughness: 0.2, metalness: 0.3 })), quill); (ink.children[0] as THREE.Mesh).position.y = 0.025; return group( 'desk', 0, 0, 0.4, top, pedestal('drawersLeft', -0.55), pedestal('drawersRight', 0.55), box(0.6, 0.55, 0.02, M.woodBlack, 0, 0.36, -0.33), // panneau de fond secret, lamp, books, ink, ); } function key(): THREE.Group { const ring = new THREE.Mesh(new THREE.TorusGeometry(0.022, 0.0065, 12, 32), M.brass); ring.position.x = -0.06; const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.005, 0.005, 0.11, 12), M.brass); shaft.rotation.z = Math.PI / 2; shaft.position.x = 0.0; const bit1 = box(0.008, 0.02, 0.006, M.brass, 0.04, -0.013, 0); const bit2 = box(0.008, 0.028, 0.006, M.brass, 0.05, -0.017, 0); const k = group('key', 0, 0, 0, ring, shaft, bit1, bit2, pickZone(0.2, 0.09, -0.01, 0, 0)); k.rotation.x = -Math.PI / 2; k.rotation.z = 0.25; k.scale.setScalar(1.3); return k; } // --- Murs --------------------------------------------------------------------------- function northWall(): THREE.Group { const g = wallFrame(0, 0, -ROOM / 2); g.add(wallMesh([]), wainscotRun(-3, 3)); // Horloge const clock = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.2, 0.05, 48), M.woodDark); clock.rotation.x = Math.PI / 2; const clockFace = new THREE.Mesh(new THREE.CircleGeometry(0.19, 48), new THREE.MeshStandardMaterial({ map: T.clockFace(), roughness: 0.5 })); clockFace.position.z = 0.026; const clockRim = new THREE.Mesh(new THREE.TorusGeometry(0.2, 0.018, 12, 48), M.brass); clockRim.position.z = 0.025; g.add(group('clock', -1.9, 1.95, 0.03, clock, clockFace, clockRim)); // Carte encadrée g.add(group('map', 0, 2.05, 0.02, box(1.0, 0.7, 0.04, M.woodBlack), plane(0.9, 0.6, new THREE.MeshStandardMaterial({ map: T.mapTexture(), roughness: 0.9 }), 0, 0, 0.021))); // Mot épinglé au-dessus du bureau const note = plane(0.21, 0.15, new THREE.MeshStandardMaterial({ map: T.noteTexture(), roughness: 0.9 }), 0, 0, 0); const pin = new THREE.Mesh(new THREE.SphereGeometry(0.008, 12, 8), new THREE.MeshStandardMaterial({ color: '#b33', roughness: 0.3 })); pin.position.set(0, 0.06, 0.006); const noteGroup = group('note', 0.35, 1.18, 0.006, note, pin); noteGroup.rotation.z = -0.06; g.add(noteGroup); g.add(decal(T.paintedDigit('3', T.PAINT.blue), 0.8, 0.8, 1.75, 1.35, 0.004, 'digit3', -0.08)); g.add(desk()); return g; } function eastWall(): THREE.Group { const g = wallFrame(-Math.PI / 2, ROOM / 2, 0); const win = { x: -1.3, y: 0.98, w: 1.1, h: 1.45 }; g.add(wallMesh([win]), wainscotRun(-3, 3)); // Fenêtre condamnée : embrasure, châssis, vitre, planches, ciel nocturne. const cx = win.x; const cy = win.y + win.h / 2; const reveal = M.woodDark; const frame = group( 'window', 0, 0, 0, box(win.w + 0.16, 0.08, 0.08, M.woodDark, cx, win.y + win.h + 0.04, 0.0), box(win.w + 0.24, 0.05, 0.2, M.woodMid, cx, win.y - 0.02, 0.06), box(0.08, win.h, 0.08, M.woodDark, cx - win.w / 2 - 0.04, cy, 0), box(0.08, win.h, 0.08, M.woodDark, cx + win.w / 2 + 0.04, cy, 0), box(win.w, 0.012, 0.22, reveal, cx, win.y + win.h, -0.11), box(win.w, 0.012, 0.22, reveal, cx, win.y, -0.11), box(0.012, win.h, 0.22, reveal, cx - win.w / 2, cy, -0.11), box(0.012, win.h, 0.22, reveal, cx + win.w / 2, cy, -0.11), box(0.05, win.h, 0.05, M.woodDark, cx, cy, -0.12), box(win.w, 0.05, 0.05, M.woodDark, cx, cy, -0.12), plane(win.w, win.h, new THREE.MeshStandardMaterial({ color: '#9fb8d0', transparent: true, opacity: 0.1, roughness: 0.35, metalness: 0 }), cx, cy, -0.14), plane(win.w + 0.6, win.h + 0.6, new THREE.MeshBasicMaterial({ map: T.nightSky() }), cx, cy, -0.6), ); const plank1 = box(win.w + 0.2, 0.13, 0.03, M.woodBlack, cx, cy + 0.3, -0.2); plank1.rotation.z = -0.25; const plank2 = box(win.w + 0.2, 0.13, 0.03, M.woodBlack, cx, cy - 0.28, -0.2); plank2.rotation.z = 0.18; frame.add(plank1, plank2); g.add(frame); // Rideaux (plis par déformation d'un plan) const curtainGeo = () => { const geo = new THREE.PlaneGeometry(0.42, 2.55, 24, 1); const pos = geo.attributes.position; for (let i = 0; i < pos.count; i++) pos.setZ(i, Math.sin(pos.getX(i) * 38) * 0.03); geo.computeVertexNormals(); return geo; }; const left = new THREE.Mesh(curtainGeo(), M.curtain); left.position.set(cx - win.w / 2 - 0.2, 1.4, 0.14); const right = new THREE.Mesh(curtainGeo(), M.curtain); right.position.set(cx + win.w / 2 + 0.2, 1.4, 0.14); const rod = new THREE.Mesh(new THREE.CylinderGeometry(0.015, 0.015, win.w + 0.9, 12), M.brass); rod.rotation.z = Math.PI / 2; rod.position.set(cx, 2.68, 0.16); g.add(group('curtains', 0, 0, 0, left, right, rod)); // Tableau const fw = 1.2; const fh = 0.85; const t = 0.07; const canvas = plane(fw - 2 * t, fh - 2 * t, new THREE.MeshStandardMaterial({ map: T.paintingCanvas(), roughness: 0.75 }), 0, 0, 0.02, 'paintingCanvas'); const painting = group( 'painting', 1.0, 1.75, 0.03, box(fw, t, 0.06, M.brass, 0, fh / 2 - t / 2, 0), box(fw, t, 0.06, M.brass, 0, -fh / 2 + t / 2, 0), box(t, fh, 0.06, M.brass, -fw / 2 + t / 2, 0, 0), box(t, fh, 0.06, M.brass, fw / 2 - t / 2, 0, 0), canvas, pickZone(0.12, 0.14, 0.33, 0.24, 0.025, 'digit1'), ); // Message à l'encre invisible : n'apparaît que dans le halo de la lampe UV, // puis reste visible une fois révélé. Enfant de la toile : un clic dessus = clic sur la toile. const uv = plane(0.92, 0.41, invisibleInk(T.uvMessage(["SL JVMMYL Z'VBCYL", "H S'OLBYL VB SL", "ALTWZ Z'LZA HYYLAL"])), 0, -0.08, 0.004, 'uvMessage'); uv.userData.noShadow = true; canvas.add(uv); g.add(painting); // Applique de tableau const bar = new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.02, 0.36, 16), M.brass); bar.rotation.z = Math.PI / 2; bar.position.set(1.0, 2.27, 0.13); g.add(bar, box(0.02, 0.06, 0.12, M.brass, 1.0, 2.25, 0.06)); const spot = new THREE.SpotLight('#ffd6a0', 3.5, 3, 0.75, 0.6, 2); spot.name = 'paintingSpot'; spot.position.set(1.0, 2.3, 0.5); spot.target.position.set(1.0, 1.65, 0); g.add(spot, spot.target); // Console et vase const vase = new THREE.Mesh( new THREE.LatheGeometry([new THREE.Vector2(0.0, 0), new THREE.Vector2(0.06, 0.0), new THREE.Vector2(0.09, 0.08), new THREE.Vector2(0.07, 0.2), new THREE.Vector2(0.065, 0.26), new THREE.Vector2(0.075, 0.28)], 32), new THREE.MeshStandardMaterial({ color: '#2c4a5e', roughness: 0.25, metalness: 0.1, side: THREE.DoubleSide }), ); // Fond du vase (intérieur) et deux piles cachées dedans const vaseBottom = new THREE.Mesh(new THREE.CircleGeometry(0.06, 24), new THREE.MeshStandardMaterial({ color: '#1d3442', roughness: 0.6 })); vaseBottom.rotation.x = -Math.PI / 2; vaseBottom.position.y = 0.005; const battery = (x: number, z: number, r: number) => { const b = new THREE.Mesh(new THREE.CylinderGeometry(0.0075, 0.0075, 0.05, 16), new THREE.MeshStandardMaterial({ color: '#2a2d31', metalness: 0.5, roughness: 0.4 })); const cap = new THREE.Mesh(new THREE.CylinderGeometry(0.0076, 0.0076, 0.014, 16), new THREE.MeshStandardMaterial({ color: '#c9a24a', metalness: 0.7, roughness: 0.3, emissive: '#5a4210', emissiveIntensity: 0.6 })); cap.position.y = 0.019; const bg = group(undefined, x, 0.013, z, b, cap); bg.rotation.set(Math.PI / 2, 0, r); return bg; }; const batteryZone = pickZone(0.1, 0.1, 0, 0.03, 0); batteryZone.rotation.x = -Math.PI / 2; const batteries = group('batteriesItem', 0, 0, 0, battery(-0.012, 0.004, 0.4), battery(0.012, -0.006, -0.3), batteryZone); const flowers = group('flowers', 0, 0.28, 0); [ ['#c84a5a', -0.05, 0.25], ['#e0b84a', 0.07, 0.2], ['#c84a5a', 0.02, 0.32], ].forEach(([c, x, h]) => { const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.003, 0.003, h as number, 6), new THREE.MeshStandardMaterial({ color: '#3d6b3d' })); stem.position.set((x as number) / 2, (h as number) / 2, 0); stem.rotation.z = -(x as number) * 2; const head = new THREE.Mesh(new THREE.SphereGeometry(0.025, 12, 8), new THREE.MeshStandardMaterial({ color: c as string, roughness: 0.8 })); head.position.set(x as number, h as number, 0); flowers.add(stem, head); }); const consoleTable = group( 'console', 1.0, 0, 0.22, box(0.8, 0.04, 0.34, M.woodLight, 0, 0.8, 0), ...[-0.36, 0.36].flatMap((x) => [-0.14, 0.14].map((z) => box(0.035, 0.78, 0.035, M.woodDark, x, 0.39, z))), group('vase', 0, 0.82, 0, vase, vaseBottom, batteries, flowers, pickZone(0.24, 0.6, 0, 0.27, 0.1)), ); g.add(consoleTable); return g; } function southWall(): THREE.Group { const g = wallFrame(Math.PI, 0, ROOM / 2); const door = { x: 0, y: 0, w: 1.0, h: 2.15 }; g.add(wallMesh([door]), wainscotRun(-3, -0.58), wainscotRun(0.58, 3)); // Encadrement g.add(box(0.1, 2.25, 0.05, M.woodBlack, -0.55, 1.125, 0.025), box(0.1, 2.25, 0.05, M.woodBlack, 0.55, 1.125, 0.025), box(1.2, 0.1, 0.05, M.woodBlack, 0, 2.2, 0.025)); // Porte (pivot sur la charnière, côté gauche de l'écran) const slabW = 0.98; const slab = group(undefined, slabW / 2, 0, 0); const doorMat = wood('#5e3b22', 0.55); slab.add(box(slabW, 2.13, 0.05, doorMat, 0, 1.065, 0)); for (const [x, y, h] of [ [-0.22, 1.6, 0.6], [0.22, 1.6, 0.6], [-0.22, 0.62, 0.86], [0.22, 0.62, 0.86], ]) { slab.add(box(0.34, h, 0.02, M.woodDark, x, y, 0.03)); slab.add(box(0.28, h - 0.06, 0.012, doorMat, x, y, 0.045)); } const knob = new THREE.Mesh(new THREE.SphereGeometry(0.035, 24, 16), M.brass); knob.position.set(0.43, 1.0, 0.07); const rosette = new THREE.Mesh(new THREE.CylinderGeometry(0.03, 0.03, 0.02, 24), M.brass); rosette.rotation.x = Math.PI / 2; rosette.position.set(0.43, 1.0, 0.03); const lock = group('lock', 0.43, 0.87, 0.03, box(0.05, 0.11, 0.012, M.brass), box(0.012, 0.03, 0.004, M.dark, 0, 0.005, 0.008)); const keyholeDot = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.004, 16), M.dark); keyholeDot.rotation.x = Math.PI / 2; keyholeDot.position.set(0, 0.022, 0.008); lock.add(keyholeDot); slab.add(knob, rosette, lock); const doorPivot = group('door', -slabW / 2, 0, -0.01, slab); g.add(doorPivot); // Couloir derrière la porte (visible une fois ouverte) const corridorMat = new THREE.MeshStandardMaterial({ color: '#2a2018', roughness: 1, side: THREE.BackSide }); const corridor = box(1.6, 2.4, 3.2, corridorMat, 0, 1.2, -1.7); corridor.receiveShadow = false; const glow = plane(1.6, 2.4, new THREE.MeshBasicMaterial({ color: '#ffcf8a' }), 0, 1.2, -3.25); glow.rotation.y = 0; g.add(corridor, glow); // Boîtier de commande const lampMat = () => new THREE.MeshStandardMaterial({ color: '#262626', roughness: 0.3, emissive: '#000000', emissiveIntensity: 2.5 }); const panel = group('panel', 0.95, 1.45, 0.0); panel.add(box(0.36, 0.46, 0.06, M.metal, 0, 0, 0.03)); panel.add(plane(0.22, 0.042, new THREE.MeshStandardMaterial({ map: T.brassPlate('COMMANDE'), metalness: 0.6, roughness: 0.4 }), 0, 0.18, 0.061)); [ [-0.08, 0.08], [0.08, 0.08], [-0.08, -0.06], [0.08, -0.06], ].forEach(([x, y], i) => { const l = new THREE.Mesh(new THREE.CylinderGeometry(0.042, 0.042, 0.02, 32), lampMat()); l.rotation.x = Math.PI / 2; l.position.set(x, y, 0.07); l.name = `panelLamp${i + 1}`; l.userData.noShadow = true; const ring = new THREE.Mesh(new THREE.TorusGeometry(0.045, 0.007, 8, 32), M.metal); ring.position.set(x, y, 0.07); panel.add(l, ring); }); const numbers = plane(0.32, 0.4, new THREE.MeshBasicMaterial({ map: T.panelNumbers(), transparent: true, depthWrite: false }), 0, -0.05, 0.0615); numbers.userData.noShadow = true; panel.add(numbers); const led = new THREE.Mesh(new THREE.SphereGeometry(0.012, 16, 12), new THREE.MeshStandardMaterial({ color: '#3a1a1a', emissive: '#000000', emissiveIntensity: 3 })); led.position.set(0, -0.19, 0.062); led.name = 'panelLed'; panel.add(led); for (const [x, y] of [ [-0.16, 0.21], [0.16, 0.21], [-0.16, -0.21], [0.16, -0.21], ]) { const s = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.005, 12), M.brass); s.rotation.x = Math.PI / 2; s.position.set(x, y, 0.062); panel.add(s); } g.add(panel, conduit(0.95, 1.68)); // Miroir const mirror = group('mirror', -1.6, 1.75, 0.02); const glass = new THREE.Mesh(new THREE.CircleGeometry(0.26, 48), new THREE.MeshStandardMaterial({ color: '#5a7a86', metalness: 0.6, roughness: 0.12 })); glass.position.z = 0.01; mirror.add(new THREE.Mesh(new THREE.TorusGeometry(0.27, 0.03, 16, 64), M.brass), glass); g.add(mirror); g.add(decal(T.paintedDigit('4', T.PAINT.green), 0.6, 0.6, -1.1, 0.52, 0.016, 'digit4', 0.07)); return g; } function westWall(): THREE.Group { const g = wallFrame(Math.PI / 2, -ROOM / 2, 0); g.add(wallMesh([]), wainscotRun(-3, 3)); // Bibliothèque const W = 1.8; const H = 2.15; const D = 0.36; const shelf = group('bookshelf', -0.2, 0, D / 2); const carcass = M.woodDark; shelf.add(box(W, H, 0.02, M.woodBlack, 0, H / 2, -D / 2 + 0.01)); shelf.add(box(0.04, H, D, carcass, -W / 2 + 0.02, H / 2, 0), box(0.04, H, D, carcass, W / 2 - 0.02, H / 2, 0)); shelf.add(box(W + 0.08, 0.06, D + 0.04, M.woodMid, 0, H + 0.03, 0.01)); const rows = [0.1, 0.62, 1.14, 1.66]; rows.forEach((y) => shelf.add(box(W - 0.08, 0.03, D - 0.02, M.woodMid, 0, y - 0.015, 0))); shelf.add(box(W - 0.08, 0.04, D - 0.02, M.woodMid, 0, H - 0.04, 0)); const palette = ['#5a2323', '#23405a', '#2f4a2a', '#5a4a23', '#3a2a4a', '#6b5a3a', '#4a2a1a', '#2a3a3a', '#704030']; const spineMats = palette.map((c) => new THREE.MeshStandardMaterial({ map: T.spine(c), roughness: 0.7 })); const sideMats = palette.map((c) => new THREE.MeshStandardMaterial({ color: c, roughness: 0.8 })); const pages = new THREE.MeshStandardMaterial({ color: '#8f8470', roughness: 0.9 }); let seed = 42; const rnd = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }; rows.forEach((y, row) => { let x = -W / 2 + 0.06; let placed = false; while (x < W / 2 - 0.1) { if (row === 0 && x > 0.3) break; // place réservée au coffret const special = row === 2 && !placed && x > 0.25; const t = special ? 0.06 : 0.025 + rnd() * 0.04; const h = special ? 0.38 : 0.26 + rnd() * 0.16; const d = 0.22 + rnd() * 0.05; if (!special && rnd() < 0.06) { x += t + 0.05; continue; } let book: THREE.Mesh; if (special) { placed = true; const cream = new THREE.MeshStandardMaterial({ color: '#e6dcc0', roughness: 0.8 }); const spineMat = new THREE.MeshStandardMaterial({ map: T.specialSpine(), roughness: 0.7 }); book = new THREE.Mesh(new THREE.BoxGeometry(t, h, d), [cream, cream, pages, pages, spineMat, cream]); book.name = 'book2'; } else { const k = Math.floor(rnd() * palette.length); book = new THREE.Mesh(new THREE.BoxGeometry(t, h, d), [sideMats[k], sideMats[k], pages, pages, spineMats[k], sideMats[k]]); } book.position.set(x + t / 2, y + h / 2, D / 2 - d / 2 - 0.02); shelf.add(book); x += t + 0.003; } }); shelf.add(strongbox()); g.add(shelf); g.add(breaker(), conduit(-1.6, 1.67)); // Fauteuil const chair = group('armchair', 1.9, 0, 0.55); chair.add(box(0.8, 0.22, 0.75, M.leather, 0, 0.3, 0)); chair.add(box(0.8, 0.75, 0.2, M.leather, 0, 0.7, -0.3)); chair.add(box(0.16, 0.42, 0.75, M.leather, -0.39, 0.45, 0), box(0.16, 0.42, 0.75, M.leather, 0.39, 0.45, 0)); chair.add(box(0.6, 0.1, 0.55, new THREE.MeshStandardMaterial({ color: '#7a3a28', roughness: 0.5 }), 0, 0.46, 0.05)); for (const fx of [-0.36, 0.36]) for (const fz of [-0.3, 0.3]) chair.add(box(0.06, 0.2, 0.06, M.woodBlack, fx, 0.1, fz)); chair.rotation.y = -0.25; g.add(chair); return g; } // --- Mécanismes : coffret à molettes, disjoncteur, plafonnier ------------------------------ /** Coffret à code (4 molettes), rangé en bas de la bibliothèque. */ function strongbox(): THREE.Group { const steel = new THREE.MeshStandardMaterial({ color: '#3d4247', metalness: 0.75, roughness: 0.4 }); const inside = new THREE.MeshStandardMaterial({ color: '#1b1d20', roughness: 0.9 }); const w = 0.4; const h = 0.3; const d = 0.28; const t = 0.015; const zc = 0.02; // centre en profondeur (face avant à z = 0,16) const safe = group('safe', 0.56, 0.1, 0); safe.add( box(w, t, d, steel, 0, t / 2, zc), box(w, t, d, steel, 0, h - t / 2, zc), box(t, h, d, steel, -w / 2 + t / 2, h / 2, zc), box(t, h, d, steel, w / 2 - t / 2, h / 2, zc), box(w, h, t, steel, 0, h / 2, zc - d / 2 + t / 2), box(w - 2 * t, 0.004, d - 2 * t, inside, 0, t + 0.002, zc), ); // Manette du disjoncteur, posée au fond du coffret const grip = new THREE.Mesh(new THREE.CylinderGeometry(0.018, 0.018, 0.07, 16), new THREE.MeshStandardMaterial({ color: '#8a1c14', roughness: 0.35 })); grip.position.x = 0.07; grip.rotation.z = Math.PI / 2; const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.007, 0.007, 0.12, 12), M.metal); shaft.rotation.z = Math.PI / 2; const lever = group('leverItem', 0, t + 0.02, zc + 0.02, shaft, grip, pickZone(0.22, 0.12, 0.01, 0, 0)); (lever.children[2] as THREE.Mesh).rotation.x = -Math.PI / 2; lever.rotation.y = 0.3; safe.add(lever); // Porte, pivot sur le bord gauche const door = group('safeDoor', -w / 2, h / 2, zc + d / 2); door.add(box(w, h, 0.02, steel, w / 2, 0, 0.01)); door.add(box(w - 0.04, h - 0.04, 0.004, new THREE.MeshStandardMaterial({ color: '#4a5055', metalness: 0.7, roughness: 0.35 }), w / 2, 0, 0.022)); const plate = plane(0.3, 0.05, new THREE.MeshStandardMaterial({ map: T.brassPlate('LINDQVIST & FILS'), metalness: 0.6, roughness: 0.4 }), w / 2, 0.1, 0.025); door.add(plate); const digits = T.dialDigits(); const dialMat = new THREE.MeshStandardMaterial({ map: digits, emissiveMap: digits, emissive: '#ffffff', emissiveIntensity: 0.18, roughness: 0.5 }); [-0.105, -0.035, 0.035, 0.105].forEach((dx, i) => { const wheel = new THREE.Mesh(new THREE.CylinderGeometry(0.03, 0.03, 0.05, 32), [dialMat, M.metal, M.metal]); wheel.rotation.z = Math.PI / 2; const dial = group(`dial${i + 1}`, w / 2 + dx, -0.01, 0.04, wheel); door.add(dial); }); door.add(box(0.28, 0.08, 0.012, M.dark, w / 2, -0.01, 0.026)); // fente des molettes // Repères de lecture : deux flèches rouges de part et d'autre de la ligne de code. const markMat = new THREE.MeshStandardMaterial({ color: '#c0281c', emissive: '#c0281c', emissiveIntensity: 0.35, roughness: 0.4 }); [-1, 1].forEach((side) => { const arrow = new THREE.Mesh(new THREE.ConeGeometry(0.012, 0.022, 3), markMat); arrow.rotation.z = (side * Math.PI) / 2; // pointe vers les molettes arrow.position.set(w / 2 + side * 0.155, -0.01, 0.04); door.add(arrow, box(0.012, 0.003, 0.004, markMat, w / 2 + side * 0.143, -0.01, 0.07)); }); // Poignée : c'est elle qui tente d'ouvrir le coffret. const handle = new THREE.Mesh(new THREE.CylinderGeometry(0.01, 0.01, 0.1, 12), M.brass); handle.position.y = 0; door.add(group('safeHandle', w - 0.05, -0.09, 0.045, handle, box(0.03, 0.03, 0.02, M.brass, 0, 0, -0.015))); safe.add(door); return safe; } /** Disjoncteur du circuit du boîtier (mur ouest, à gauche de la bibliothèque). */ function breaker(): THREE.Group { const grey = new THREE.MeshStandardMaterial({ color: '#6b7076', metalness: 0.5, roughness: 0.5 }); const g = group('breaker', -1.6, 1.45, 0); g.add(box(0.32, 0.44, 0.1, grey, 0, 0, 0.05)); g.add(plane(0.24, 0.045, new THREE.MeshStandardMaterial({ map: T.brassPlate('DISJONCTEUR'), metalness: 0.6, roughness: 0.4 }), 0, 0.17, 0.101)); g.add(box(0.07, 0.14, 0.02, M.dark, 0, -0.02, 0.105, 'breakerSocket')); const led = new THREE.Mesh(new THREE.SphereGeometry(0.012, 16, 12), new THREE.MeshStandardMaterial({ color: '#3a1a1a', emissive: '#000000', emissiveIntensity: 3 })); led.position.set(0.11, 0.13, 0.105); led.name = 'breakerLed'; led.userData.noShadow = true; g.add(led); // Manette installée (cachée tant qu'on ne l'a pas posée), pivot sur l'axe x const arm = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.13, 12), M.metal); arm.position.y = 0.065; const grip = new THREE.Mesh(new THREE.CylinderGeometry(0.018, 0.018, 0.07, 16), new THREE.MeshStandardMaterial({ color: '#8a1c14', roughness: 0.35 })); grip.rotation.z = Math.PI / 2; grip.position.y = 0.13; const lever = group('breakerLever', 0, -0.02, 0.115, arm, grip, pickZone(0.12, 0.2, 0, 0.08, 0.02)); lever.rotation.x = 2.79; // installée en position basse g.add(lever); return g; } /** Gaine électrique verticale (hors des objets cliquables, pour un contour propre). */ function conduit(x: number, fromY: number): THREE.Mesh { const m = new THREE.Mesh(new THREE.CylinderGeometry(0.014, 0.014, HEIGHT - fromY, 12), M.metal); m.position.set(x, (HEIGHT + fromY) / 2, 0.03); return m; } /** Plafonnier : s'allume quand le courant revient. */ function pendant(): THREE.Group { const cord = new THREE.Mesh(new THREE.CylinderGeometry(0.006, 0.006, 0.55, 8), M.dark); cord.position.y = -0.275; const shade = new THREE.Mesh(new THREE.ConeGeometry(0.22, 0.16, 32, 1, true), new THREE.MeshStandardMaterial({ color: '#c9a24a', metalness: 0.8, roughness: 0.35, side: THREE.DoubleSide })); shade.position.y = -0.6; const bulb = new THREE.Mesh(new THREE.SphereGeometry(0.05, 16, 12), new THREE.MeshStandardMaterial({ color: '#6a6458', emissive: '#000000', emissiveIntensity: 2 })); bulb.position.y = -0.68; bulb.name = 'ceilingBulb'; bulb.userData.noShadow = true; const light = new THREE.PointLight('#ffe2b8', 9, 0, 2); light.position.y = -0.72; light.name = 'ceilingLight'; return group('pendant', 0, HEIGHT, 0, cord, shade, bulb, light); } // --- Assemblage ------------------------------------------------------------------------ export function buildBureau(): World { wallpaperTex = T.wallpaper(); wainscotTex = T.wainscot(); const root = new THREE.Group(); root.name = 'bureau'; // Sol, plafond, tapis const floor = new THREE.Mesh(new THREE.PlaneGeometry(ROOM, ROOM), new THREE.MeshStandardMaterial({ map: T.floorPlanks(), roughness: 0.55 })); floor.rotation.x = -Math.PI / 2; floor.receiveShadow = true; const ceiling = new THREE.Mesh(new THREE.PlaneGeometry(ROOM, ROOM), M.ceiling); ceiling.rotation.x = Math.PI / 2; ceiling.position.y = HEIGHT; const rug = new THREE.Mesh(new THREE.CircleGeometry(1, 64), new THREE.MeshStandardMaterial({ color: '#4a1e1e', roughness: 1 })); rug.rotation.x = -Math.PI / 2; rug.scale.set(1.6, 1.1, 1); rug.position.set(-1.2, 0.004, 0.1); const rugBorder = new THREE.Mesh(new THREE.RingGeometry(0.92, 0.95, 64), new THREE.MeshStandardMaterial({ color: '#9a7a3a', roughness: 1 })); rugBorder.rotation.x = -Math.PI / 2; rugBorder.scale.set(1.6, 1.1, 1); rugBorder.position.set(-1.2, 0.005, 0.1); root.add(floor, ceiling, rug, rugBorder); root.add(northWall(), eastWall(), southWall(), westWall()); // Éclairage d'ambiance root.add(new THREE.HemisphereLight('#4a6066', '#2a1a10', 0.8)); const fill = new THREE.PointLight('#ffdcb0', 3.5, 0, 2); fill.position.set(0, 2.7, 0); root.add(fill, pendant()); // Clair de lune à travers la fenêtre const moon = new THREE.DirectionalLight('#9cc4ff', 0.9); moon.position.set(7, 4.2, -1.3); moon.target.position.set(0.5, 0, -0.8); moon.castShadow = true; moon.shadow.mapSize.set(1024, 1024); Object.assign(moon.shadow.camera, { left: -3, right: 3, top: 3, bottom: -3, near: 1, far: 15 }); moon.shadow.bias = -0.001; root.add(moon, moon.target); root.traverse((o) => { if ((o as THREE.Mesh).isMesh && !o.userData.noShadow) { o.castShadow = true; o.receiveShadow = true; } }); floor.castShadow = false; ceiling.castShadow = false; return { root }; }