Download code/ds_tr-clock/subject.js from Mike0021/inkling-mini-phaseA-3d-scenes: direct link, hf CLI and curl.
- Browser
- Download file 31.7 kB
-
https://huggingface.co/datasets/Mike0021/inkling-mini-phaseA-3d-scenes/resolve/main/code/ds_tr-clock/subject.js
- Command line
-
hf download hf://datasets/Mike0021/inkling-mini-phaseA-3d-scenes/code/ds_tr-clock/subject.js
-
curl -L -o subject.js https://huggingface.co/datasets/Mike0021/inkling-mini-phaseA-3d-scenes/resolve/main/code/ds_tr-clock/subject.js
31.7 kB
| import * as THREE from 'three'; | |
| import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js'; | |
| import { | |
| makeMahogany, makeDial, makeMoon, makeBrassMaps, makePlaque, | |
| } from './textures.js'; | |
| const V2 = THREE.Vector2; | |
| /* ---------- material library ---------- */ | |
| export function makeClockMaterials() { | |
| const wood = makeMahogany(7); | |
| const brass = makeBrassMaps(73); | |
| const dial = makeDial(53); | |
| const moon = makeMoon(61); | |
| const plaqueTex = makePlaque(); | |
| const mahogany = new THREE.MeshPhysicalMaterial({ | |
| map: wood.map, | |
| bumpMap: wood.bumpMap, | |
| bumpScale: 0.03, | |
| roughnessMap: wood.roughnessMap, | |
| roughness: 0.5, | |
| metalness: 0, | |
| color: 0xa98d7d, | |
| clearcoat: 0.48, | |
| clearcoatRoughness: 0.24, | |
| envMapIntensity: 0.85, | |
| }); | |
| const mahoganyDark = new THREE.MeshPhysicalMaterial({ | |
| map: wood.map, | |
| bumpMap: wood.bumpMap, | |
| bumpScale: 0.026, | |
| roughnessMap: wood.roughnessMap, | |
| color: 0x8a6553, | |
| roughness: 0.48, | |
| clearcoat: 0.6, | |
| clearcoatRoughness: 0.22, | |
| envMapIntensity: 0.9, | |
| }); | |
| const mahoganyLight = new THREE.MeshPhysicalMaterial({ | |
| map: wood.map, | |
| bumpMap: wood.bumpMap, | |
| bumpScale: 0.018, | |
| roughnessMap: wood.roughnessMap, | |
| color: 0x7d5b4b, | |
| roughness: 0.58, | |
| clearcoat: 0.2, | |
| clearcoatRoughness: 0.4, | |
| envMapIntensity: 0.3, | |
| }); | |
| const brassMat = new THREE.MeshStandardMaterial({ | |
| map: brass.map, | |
| roughnessMap: brass.roughnessMap, | |
| color: 0xf0c976, | |
| metalness: 1.0, | |
| roughness: 0.3, | |
| envMapIntensity: 1.45, | |
| }); | |
| const brassAged = new THREE.MeshStandardMaterial({ | |
| map: brass.map, | |
| roughnessMap: brass.roughnessMap, | |
| color: 0xbb8f45, | |
| metalness: 1.0, | |
| roughness: 0.44, | |
| envMapIntensity: 1.2, | |
| }); | |
| const steel = new THREE.MeshStandardMaterial({ | |
| color: 0x2b2b30, metalness: 1, roughness: 0.36, envMapIntensity: 1.1, | |
| }); | |
| const dialMat = new THREE.MeshStandardMaterial({ | |
| map: dial.map, roughness: 0.42, metalness: 0.0, envMapIntensity: 0.55, | |
| }); | |
| const moonMat = new THREE.MeshStandardMaterial({ | |
| map: moon.map, roughness: 0.36, metalness: 0.05, envMapIntensity: 0.9, | |
| emissive: 0x1a2c44, emissiveIntensity: 0.55, | |
| }); | |
| const glass = new THREE.MeshPhysicalMaterial({ | |
| color: 0xdde8e4, | |
| metalness: 0, | |
| roughness: 0.035, | |
| transparent: true, | |
| opacity: 0.13, | |
| envMapIntensity: 2.1, | |
| clearcoat: 1, | |
| clearcoatRoughness: 0.03, | |
| side: THREE.DoubleSide, | |
| depthWrite: false, | |
| }); | |
| const darkInterior = new THREE.MeshStandardMaterial({ | |
| color: 0x170d07, roughness: 0.94, metalness: 0, | |
| }); | |
| const velvet = new THREE.MeshPhysicalMaterial({ | |
| color: 0x1b0505, roughness: 0.97, metalness: 0, | |
| sheen: 0.35, sheenColor: 0x4a100c, sheenRoughness: 0.8, | |
| envMapIntensity: 0.12, | |
| }); | |
| const holly = new THREE.MeshStandardMaterial({ | |
| color: 0x9a7f52, roughness: 0.55, metalness: 0.1, envMapIntensity: 0.5, | |
| }); | |
| const black = new THREE.MeshStandardMaterial({ | |
| color: 0x120b06, roughness: 0.7, metalness: 0.1, | |
| }); | |
| return { mahogany, mahoganyDark, mahoganyLight, brass: brassMat, brassAged, steel, dialMat, moonMat, glass, darkInterior, velvet, holly, black, plaqueTex, dialCanvas: dial.canvas, moonTex: moon.map }; | |
| } | |
| /* ---------- geometry helpers ---------- */ | |
| function rbox(w, h, d, mat, r = 0.006, seg = 3) { | |
| const rad = Math.min(r, w * 0.45, h * 0.45, d * 0.45); | |
| return new THREE.Mesh(new RoundedBoxGeometry(w, h, d, seg, rad), mat); | |
| } | |
| function box(w, h, d, mat) { return new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat); } | |
| function cyl(rt, rb, h, mat, seg = 32) { | |
| return new THREE.Mesh(new THREE.CylinderGeometry(rt, rb, h, seg), mat); | |
| } | |
| function lathe(profile, mat, seg = 48) { | |
| return new THREE.Mesh(new THREE.LatheGeometry(profile, seg), mat); | |
| } | |
| function extrude(shape, depth, mat, bevel = 0.004) { | |
| const g = new THREE.ExtrudeGeometry(shape, { | |
| depth, curveSegments: 56, bevelEnabled: bevel > 0, | |
| bevelThickness: bevel, bevelSize: bevel, bevelSegments: 3, | |
| }); | |
| g.computeVertexNormals(); | |
| return new THREE.Mesh(g, mat); | |
| } | |
| function rectRing(w, h, tw, th, depth, mat) { | |
| const s = new THREE.Shape(); | |
| s.moveTo(-w / 2, -h / 2); s.lineTo(w / 2, -h / 2); s.lineTo(w / 2, h / 2); s.lineTo(-w / 2, h / 2); s.lineTo(-w / 2, -h / 2); | |
| const ho = new THREE.Path(); | |
| const iw = w / 2 - tw, ih = h / 2 - th; | |
| ho.moveTo(-iw, -ih); ho.lineTo(-iw, ih); ho.lineTo(iw, ih); ho.lineTo(iw, -ih); ho.lineTo(-iw, -ih); | |
| s.holes.push(ho); | |
| return extrude(s, depth, mat, 0.005); | |
| } | |
| function archShape(w, bottom, spring, mat) {} | |
| function makeArchOutline(w, bottom, spring, topR) { | |
| const s = new THREE.Shape(); | |
| s.moveTo(-w / 2, bottom); | |
| s.lineTo(-w / 2, spring); | |
| s.absarc(0, spring, topR, Math.PI, 0, true); | |
| s.lineTo(w / 2, bottom); | |
| s.lineTo(-w / 2, bottom); | |
| return s; | |
| } | |
| function archFrame(wOut, bottomOut, springOut, wIn, bottomIn, springIn, depth, mat) { | |
| const s = makeArchOutline(wOut, bottomOut, springOut, wOut / 2); | |
| const hole = new THREE.Path(); | |
| hole.moveTo(-wIn / 2, bottomIn); | |
| hole.lineTo(-wIn / 2, springIn); | |
| hole.absarc(0, springIn, wIn / 2, Math.PI, 0, true); | |
| hole.lineTo(wIn / 2, bottomIn); | |
| hole.lineTo(-wIn / 2, bottomIn); | |
| s.holes.push(hole); | |
| return extrude(s, depth, mat, 0.006); | |
| } | |
| function flutedColumn(h, r, mat, flutes = 14) { | |
| const pts = [ | |
| new V2(0, 0), new V2(r * 0.86, 0.004), new V2(r, 0.014), | |
| new V2(r * 0.94, 0.05), new V2(r * 0.94, h * 0.9), | |
| new V2(r, h * 0.94), new V2(r * 0.72, h * 0.985), new V2(0, h), | |
| ]; | |
| const g = new THREE.LatheGeometry(pts, 56); | |
| const p = g.attributes.position; | |
| for (let i = 0; i < p.count; i++) { | |
| const x = p.getX(i), y = p.getY(i), z = p.getZ(i); | |
| const rad = Math.hypot(x, z); | |
| if (rad < 1e-5) continue; | |
| const a = Math.atan2(z, x); | |
| const mask = THREE.MathUtils.smoothstep(y, h * 0.05, h * 0.1) * (1 - THREE.MathUtils.smoothstep(y, h * 0.9, h * 0.95)); | |
| const f = 1 - 0.055 * mask * Math.pow(Math.max(0, Math.cos(a * flutes)), 1.6); | |
| p.setX(i, x * f); p.setZ(i, z * f); | |
| } | |
| g.computeVertexNormals(); | |
| return new THREE.Mesh(g, mat); | |
| } | |
| function shellGeometry(R = 1, ridges = 9) { | |
| const NU = 16, NV = 48; | |
| const pos = [], uv = [], idx = []; | |
| for (let iu = 0; iu <= NU; iu++) { | |
| const u = iu / NU; | |
| for (let iv = 0; iv <= NV; iv++) { | |
| const v = iv / NV * 2 - 1; | |
| const theta = v * 1.02; | |
| const rim = 0.93 + 0.07 * Math.cos(v * ridges * Math.PI); | |
| const rr = u * R * rim; | |
| const x = Math.sin(theta) * rr; | |
| const y = Math.cos(theta) * rr * 0.82; | |
| const bulge = R * (0.16 * (1 - u * u) + 0.055 * u * Math.abs(Math.sin(v * ridges * Math.PI))); | |
| pos.push(x, y, bulge); | |
| uv.push(iv / NV, u); | |
| } | |
| } | |
| for (let iu = 0; iu < NU; iu++) { | |
| for (let iv = 0; iv < NV; iv++) { | |
| const a = iu * (NV + 1) + iv, b = a + NV + 1; | |
| idx.push(a, b, a + 1, b, b + 1, a + 1); | |
| } | |
| } | |
| const g = new THREE.BufferGeometry(); | |
| g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); | |
| g.setAttribute('uv', new THREE.Float32BufferAttribute(uv, 2)); | |
| g.setIndex(idx); | |
| g.computeVertexNormals(); | |
| return g; | |
| } | |
| function leafGeometry() { | |
| const s = new THREE.Shape(); | |
| s.moveTo(0, 0); | |
| s.bezierCurveTo(0.035, 0.02, 0.055, 0.075, 0.008, 0.13); | |
| s.bezierCurveTo(-0.04, 0.075, -0.03, 0.02, 0, 0); | |
| return new THREE.ExtrudeGeometry(s, { depth: 0.008, bevelEnabled: true, bevelThickness: 0.004, bevelSize: 0.004, bevelSegments: 2, curveSegments: 20 }); | |
| } | |
| function handMesh(length, width, spadeW, mat, thickness = 0.004) { | |
| const s = new THREE.Shape(); | |
| s.moveTo(-width * 0.5, -0.018); | |
| s.lineTo(-width * 0.8, length * 0.6); | |
| s.lineTo(-spadeW * 0.5, length * 0.8); | |
| s.lineTo(-spadeW * 0.28, length * 0.94); | |
| s.lineTo(0, length); | |
| s.lineTo(spadeW * 0.28, length * 0.94); | |
| s.lineTo(spadeW * 0.5, length * 0.8); | |
| s.lineTo(width * 0.8, length * 0.6); | |
| s.lineTo(width * 0.5, -0.018); | |
| s.lineTo(-width * 0.5, -0.018); | |
| const g = new THREE.ExtrudeGeometry(s, { depth: thickness, bevelEnabled: true, bevelThickness: 0.0011, bevelSize: 0.0011, bevelSegments: 2, curveSegments: 8 }); | |
| g.computeVertexNormals(); | |
| return new THREE.Mesh(g, mat); | |
| } | |
| function finial(mat, h = 0.22, r = 0.045) { | |
| const p = [ | |
| new V2(0, 0), new V2(r * 1.25, 0.008), new V2(r * 1.32, 0.03), | |
| new V2(r * 0.6, 0.055), new V2(r * 0.45, 0.09), | |
| new V2(r * 0.95, 0.125), new V2(r * 0.9, 0.16), | |
| new V2(r * 0.42, 0.185), new V2(r * 0.18, 0.205), | |
| new V2(0, h), | |
| ]; | |
| const m = lathe(p, mat, 40); | |
| return m; | |
| } | |
| /* ---------- main build ---------- */ | |
| export function buildClock() { | |
| const M = makeClockMaterials(); | |
| const group = new THREE.Group(); | |
| group.name = 'subject'; | |
| const anim = {}; | |
| const add = (mesh, parent = group) => { parent.add(mesh); return mesh; }; | |
| /* ===== feet & plinth ===== */ | |
| for (const sx of [-1, 1]) for (const sz of [-1, 1]) { | |
| const foot = lathe([ | |
| new V2(0, 0), new V2(0.042, 0.002), new V2(0.058, 0.012), | |
| new V2(0.062, 0.032), new V2(0.048, 0.058), new V2(0.03, 0.075), new V2(0, 0.078), | |
| ], M.mahoganyDark, 32); | |
| foot.position.set(sx * 0.245, 0, sz * 0.145); | |
| add(foot); | |
| } | |
| add(rbox(0.66, 0.035, 0.45, M.mahoganyDark, 0.008)).position.y = 0.092; | |
| add(rbox(0.615, 0.08, 0.415, M.mahogany, 0.008)).position.y = 0.15; | |
| add(rbox(0.58, 0.035, 0.385, M.mahoganyDark, 0.006)).position.y = 0.207; | |
| add(rbox(0.555, 0.04, 0.365, M.mahogany, 0.005)).position.y = 0.243; | |
| // base shell carving | |
| const shellMat = M.mahoganyDark.clone(); shellMat.side = THREE.DoubleSide; | |
| const shell = new THREE.Mesh(shellGeometry(0.098, 9), shellMat); | |
| shell.position.set(0, 0.14, 0.222); | |
| shell.scale.set(1.0, 0.95, 1.0); | |
| add(shell); | |
| // leaf appliques | |
| const leafGeo = leafGeometry(); | |
| for (const sx of [-1, 1]) { | |
| const leaf = new THREE.Mesh(leafGeo, M.mahoganyDark); | |
| leaf.position.set(sx * 0.17, 0.115, 0.227); | |
| leaf.rotation.z = sx * -0.55; | |
| leaf.scale.set(0.9, 0.9, 0.9); | |
| add(leaf); | |
| const leaf2 = new THREE.Mesh(leafGeo, M.mahoganyDark); | |
| leaf2.position.set(sx * 0.245, 0.13, 0.225); | |
| leaf2.rotation.z = sx * 1.9; | |
| leaf2.scale.set(0.7, 0.7, 0.7); | |
| add(leaf2); | |
| // brass inlay dot | |
| const dot = new THREE.Mesh(new THREE.SphereGeometry(0.008, 16, 10), M.brass); | |
| dot.position.set(sx * 0.29, 0.18, 0.228); | |
| add(dot); | |
| } | |
| // holly stringing on base | |
| for (const yy of [0.118, 0.19]) { | |
| add(rbox(0.53, 0.004, 0.004, M.holly, 0.001)).position.set(0, yy, 0.2195); | |
| } | |
| /* ===== trunk carcass (hollow for pendulum) ===== */ | |
| const trunkY0 = 0.27, trunkY1 = 1.48; | |
| const trunkH = trunkY1 - trunkY0; | |
| const trunkCY = (trunkY0 + trunkY1) / 2; | |
| // back | |
| add(rbox(0.50, trunkH, 0.028, M.mahoganyDark, 0.005)).position.set(0, trunkCY, -0.15); | |
| // sides | |
| for (const sx of [-1, 1]) { | |
| add(rbox(0.032, trunkH, 0.315, M.mahogany, 0.005)).position.set(sx * 0.246, trunkCY, 0.005); | |
| // raised side panel | |
| const sp = rbox(0.012, 0.92, 0.195, M.mahoganyDark, 0.005); | |
| sp.position.set(sx * 0.265, 0.83, 0.01); | |
| add(sp); | |
| const spIn = rbox(0.006, 0.80, 0.15, M.mahogany, 0.004); | |
| spIn.position.set(sx * 0.272, 0.83, 0.01); | |
| add(spIn); | |
| // side inlay strings | |
| for (const zz of [-0.075, 0.095]) { | |
| const st = rbox(0.004, 0.86, 0.003, M.holly, 0.001); | |
| st.position.set(sx * 0.2705, 0.83, zz); add(st); | |
| } | |
| } | |
| add(rbox(0.50, 0.03, 0.30, M.mahoganyDark, 0.004)).position.set(0, trunkY0 + 0.01, 0.0); | |
| add(rbox(0.50, 0.03, 0.30, M.mahoganyDark, 0.004)).position.set(0, trunkY1 - 0.01, 0.0); | |
| // interior velvet / dark | |
| const vel = box(0.45, 1.08, 0.008, M.velvet); | |
| vel.position.set(0, 0.86, -0.115); add(vel); | |
| // velvet side linings | |
| for (const sx of [-1, 1]) { | |
| const vs = box(0.008, 1.08, 0.2, M.velvet); | |
| vs.position.set(sx * 0.215, 0.86, -0.02); add(vs); | |
| } | |
| const innerTop = box(0.43, 0.008, 0.2, M.darkInterior); innerTop.position.set(0, 1.405, -0.02); add(innerTop); | |
| // door frame (arched) at front | |
| const doorFrame = archFrame(0.44, 0.26, 1.18, 0.352, 0.305, 1.18, 0.026, M.mahogany); | |
| doorFrame.position.z = 0.155; add(doorFrame); | |
| // glass pane | |
| const glassShape = makeArchOutline(0.39, 0.295, 1.18, 0.195); | |
| const glassPane = extrude(glassShape, 0.002, M.glass, 0.0); | |
| glassPane.position.z = 0.165; add(glassPane); | |
| // mid rail | |
| const midRail = rbox(0.40, 0.028, 0.022, M.mahoganyDark, 0.004); | |
| midRail.position.set(0, 0.665, 0.175); add(midRail); | |
| // lower raised panel | |
| const lowerPanel = rbox(0.315, 0.30, 0.018, M.mahoganyDark, 0.005); | |
| lowerPanel.position.set(0, 0.475, 0.173); add(lowerPanel); | |
| const lowerPanelIn = rbox(0.26, 0.245, 0.008, M.mahogany, 0.004); | |
| lowerPanelIn.position.set(0, 0.475, 0.185); add(lowerPanelIn); | |
| // inlay stringing around door | |
| for (const sx of [-1, 1]) { | |
| const st = rbox(0.004, 1.10, 0.003, M.holly, 0.0008); | |
| st.position.set(sx * 0.207, 0.85, 0.171); add(st); | |
| } | |
| // door hinges | |
| for (const yy of [0.36, 1.2]) { | |
| const h = rbox(0.018, 0.075, 0.01, M.brassAged, 0.003); | |
| h.position.set(0.198, yy, 0.181); add(h); | |
| } | |
| // keyhole escutcheon | |
| const esc = lathe([new V2(0, 0), new V2(0.034, 0), new V2(0.036, 0.004), new V2(0.032, 0.008), new V2(0, 0.009)], M.brass, 32); | |
| esc.rotation.x = Math.PI / 2; esc.position.set(0, 0.50, 0.192); add(esc); | |
| const keyhole = box(0.009, 0.018, 0.004, M.black); | |
| keyhole.position.set(0, 0.497, 0.198); add(keyhole); | |
| const keyhole2 = new THREE.Mesh(new THREE.ConeGeometry(0.009, 0.018, 3), M.black); | |
| keyhole2.rotation.z = Math.PI; keyhole2.position.set(0, 0.475, 0.198); add(keyhole2); | |
| // fluted quarter columns on trunk front | |
| for (const sx of [-1, 1]) { | |
| const col = flutedColumn(1.16, 0.026, M.mahogany, 12); | |
| col.position.set(sx * 0.232, 0.29, 0.145); add(col); | |
| for (const yy of [0.292, 1.435]) { | |
| const ring = new THREE.Mesh(new THREE.TorusGeometry(0.026, 0.006, 10, 28), M.brassAged); | |
| ring.rotation.x = Math.PI / 2; ring.position.set(sx * 0.232, yy, 0.145); add(ring); | |
| } | |
| const cap = lathe([new V2(0, 0), new V2(0.032, 0), new V2(0.038, 0.008), new V2(0.028, 0.02), new V2(0, 0.022)], M.brassAged, 28); | |
| cap.position.set(sx * 0.232, 1.43, 0.145); add(cap); | |
| } | |
| // carved leaf ornaments framing the door panel | |
| for (const sx of [-1, 1]) for (const [yy, rz] of [[0.33, 0.8], [0.62, -0.8], [1.36, -0.7]]) { | |
| const lf = new THREE.Mesh(leafGeo, M.mahoganyDark); | |
| lf.position.set(sx * 0.155, yy, 0.19); | |
| lf.rotation.z = sx * rz; | |
| lf.scale.set(0.62, 0.62, 0.5); | |
| add(lf); | |
| } | |
| // brass beading along lower door panel | |
| for (const yy of [0.322, 0.628]) { | |
| const bead = new THREE.Mesh(new THREE.TorusGeometry(0.0045, 0.0018, 6, 24), M.brassAged); | |
| bead.position.set(0, yy, 0.192); bead.rotation.z = Math.PI / 2; add(bead); | |
| } | |
| /* ===== waist mouldings ===== */ | |
| add(rbox(0.60, 0.035, 0.38, M.mahoganyLight, 0.006)).position.y = 1.495; | |
| add(rbox(0.635, 0.045, 0.41, M.mahoganyDark, 0.008)).position.y = 1.535; | |
| add(rbox(0.60, 0.025, 0.385, M.mahogany, 0.006)).position.y = 1.57; | |
| add(rbox(0.575, 0.02, 0.36, M.holly, 0.003)).position.y = 1.548; | |
| // carved scroll appliques at the waist | |
| for (const sx of [-1, 1]) { | |
| const pts = [ | |
| new THREE.Vector3(sx * 0.16, 1.48, 0.196), | |
| new THREE.Vector3(sx * 0.235, 1.50, 0.196), | |
| new THREE.Vector3(sx * 0.272, 1.535, 0.196), | |
| new THREE.Vector3(sx * 0.255, 1.565, 0.196), | |
| new THREE.Vector3(sx * 0.218, 1.552, 0.198), | |
| new THREE.Vector3(sx * 0.235, 1.528, 0.198), | |
| ]; | |
| const curve = new THREE.CatmullRomCurve3(pts); | |
| const sc = new THREE.Mesh(new THREE.TubeGeometry(curve, 30, 0.009, 8, false), M.mahoganyDark); | |
| add(sc); | |
| const rosette = new THREE.Mesh(new THREE.SphereGeometry(0.016, 16, 12), M.brassAged); | |
| rosette.scale.z = 0.45; | |
| rosette.position.set(sx * 0.272, 1.522, 0.208); add(rosette); | |
| } | |
| /* ===== hood ===== */ | |
| const hoodCY = 1.91; | |
| add(rbox(0.62, 0.66, 0.39, M.mahogany, 0.01)).position.set(0, hoodCY, 0); | |
| // hood side raised panels | |
| for (const sx of [-1, 1]) { | |
| const hp = rbox(0.012, 0.44, 0.23, M.mahoganyDark, 0.005); | |
| hp.position.set(sx * 0.315, 1.90, 0.0); add(hp); | |
| const hpi = rbox(0.006, 0.36, 0.17, M.mahogany, 0.004); | |
| hpi.position.set(sx * 0.322, 1.90, 0.0); add(hpi); | |
| const ring = new THREE.Mesh(new THREE.TorusGeometry(0.06, 0.006, 10, 32), M.brassAged); | |
| ring.rotation.y = Math.PI / 2; ring.position.set(sx * 0.326, 1.90, 0.0); add(ring); | |
| const port = new THREE.Mesh(new THREE.CircleGeometry(0.056, 40), new THREE.MeshPhysicalMaterial({ | |
| color: 0x1a2a30, roughness: 0.08, metalness: 0.35, envMapIntensity: 1.8, | |
| })); | |
| port.rotation.y = sx * Math.PI / 2; port.position.set(sx * 0.3255, 1.90, 0.0); add(port); | |
| const sun = new THREE.Mesh(new THREE.SphereGeometry(0.018, 16, 12), M.brassAged); | |
| sun.position.set(sx * 0.329, 1.90, 0.0); sun.scale.x = 0.35; add(sun); | |
| } | |
| // hood glazed door frame | |
| const hoodFrame = archFrame(0.50, 1.585, 1.86, 0.41, 1.655, 1.86, 0.034, M.mahoganyLight); | |
| hoodFrame.position.z = 0.198; add(hoodFrame); | |
| // glass over dial | |
| const hoodGlassShape = makeArchOutline(0.455, 1.645, 1.86, 0.2275); | |
| const hoodGlass = extrude(hoodGlassShape, 0.002, M.glass, 0); | |
| hoodGlass.position.z = 0.2365; add(hoodGlass); | |
| // hood columns | |
| for (const sx of [-1, 1]) { | |
| const col = flutedColumn(0.55, 0.03, M.mahogany, 12); | |
| col.position.set(sx * 0.295, 1.60, 0.185); add(col); | |
| const base = lathe([new V2(0, 0), new V2(0.042, 0), new V2(0.045, 0.01), new V2(0.034, 0.026), new V2(0.03, 0.036), new V2(0, 0.038)], M.brassAged, 32); | |
| base.position.set(sx * 0.295, 1.585, 0.185); add(base); | |
| const cap = lathe([new V2(0, 0), new V2(0.034, 0), new V2(0.045, 0.008), new V2(0.047, 0.02), new V2(0.04, 0.03), new V2(0, 0.032)], M.brassAged, 32); | |
| cap.position.set(sx * 0.295, 2.135, 0.185); add(cap); | |
| // column mount bracket on hood | |
| const brk = rbox(0.05, 0.05, 0.03, M.mahoganyDark, 0.004); | |
| brk.position.set(sx * 0.295, 1.60, 0.17); add(brk); | |
| } | |
| /* ===== dial ===== */ | |
| // arched ivory dial plate filling the glazed door opening | |
| const plateMat = new THREE.MeshStandardMaterial({ | |
| color: 0xcdb893, roughness: 0.56, metalness: 0.0, envMapIntensity: 0.4, | |
| }); | |
| const plateShape = makeArchOutline(0.405, 1.662, 1.945, 0.2025); | |
| const plate = extrude(plateShape, 0.006, plateMat, 0.002); | |
| plate.position.z = 0.199; add(plate); | |
| const plateRing = archFrame(0.415, 1.657, 1.945, 0.394, 1.682, 1.945, 0.004, M.brassAged); | |
| plateRing.position.z = 0.205; add(plateRing); | |
| const dialR = 0.181, dialCY = 1.90, dialZ = 0.209; | |
| const dial = new THREE.Mesh(new THREE.CircleGeometry(dialR, 96), M.dialMat); | |
| dial.position.set(0, dialCY, dialZ); add(dial); | |
| // brass bezel | |
| const bezelProfile = [ | |
| new V2(0.167, 0), new V2(0.182, 0.0), new V2(0.193, 0.006), | |
| new V2(0.198, 0.014), new V2(0.192, 0.021), new V2(0.178, 0.022), new V2(0.168, 0.016), | |
| ]; | |
| const bezel = lathe(bezelProfile, M.brass, 72); | |
| bezel.rotation.x = Math.PI / 2; | |
| bezel.position.set(0, dialCY, dialZ + 0.003); add(bezel); | |
| // bezel screws | |
| const screwGeo = new THREE.SphereGeometry(0.0045, 10, 8); | |
| const screws = new THREE.InstancedMesh(screwGeo, M.brass, 12); | |
| const mtx = new THREE.Matrix4(); | |
| for (let i = 0; i < 12; i++) { | |
| const a = (i / 12) * Math.PI * 2; | |
| mtx.makeTranslation(Math.cos(a) * 0.186, Math.sin(a) * 0.186, 0.0); | |
| screws.setMatrixAt(i, mtx); | |
| } | |
| screws.position.set(0, dialCY, dialZ + 0.026); add(screws); | |
| // moon phase aperture | |
| const moonCY = dialCY + 0.079; | |
| const moonR = 0.058; | |
| const moonBack = new THREE.Mesh(new THREE.CircleGeometry(moonR + 0.001, 48), new THREE.MeshStandardMaterial({ color: 0x0b1a2d, roughness: 0.7, metalness: 0 })); | |
| moonBack.position.set(0, moonCY, dialZ + 0.002); add(moonBack); | |
| const moonDisc = new THREE.Mesh(new THREE.CircleGeometry(moonR, 48), M.moonMat); | |
| moonDisc.position.set(0, moonCY, dialZ + 0.005); add(moonDisc); | |
| const moonRing = new THREE.Mesh(new THREE.TorusGeometry(moonR + 0.002, 0.006, 12, 64), M.brass); | |
| moonRing.position.set(0, moonCY, dialZ + 0.008); add(moonRing); | |
| const moonRing2 = new THREE.Mesh(new THREE.TorusGeometry(moonR + 0.012, 0.0025, 8, 64), M.brassAged); | |
| moonRing2.position.set(0, moonCY, dialZ + 0.006); add(moonRing2); | |
| anim.moon = moonDisc; | |
| // hands | |
| const hands = new THREE.Group(); | |
| hands.position.set(0, dialCY, dialZ + 0.013); add(hands); | |
| const hourHand = handMesh(0.105, 0.0048, 0.0095, M.brass, 0.0032); | |
| const minuteHand = handMesh(0.151, 0.0039, 0.0068, M.brass, 0.0032); | |
| const secHand = new THREE.Group(); | |
| const secRod = box(0.0022, 0.023, 0.002, M.steel); | |
| secRod.position.y = 0.0075; secHand.add(secRod); | |
| const secTail = box(0.0026, 0.006, 0.002, M.steel); | |
| secTail.position.y = -0.008; secHand.add(secTail); | |
| const secBob = lathe([new V2(0, 0), new V2(0.0035, 0.001), new V2(0.004, 0.003), new V2(0, 0.004)], M.brass, 16); | |
| secBob.position.y = -0.0105; secHand.add(secBob); | |
| secHand.position.set(0, -0.0709, 0.0045); | |
| hands.add(hourHand, minuteHand, secHand); | |
| const hub = lathe([new V2(0, 0), new V2(0.010, 0.001), new V2(0.011, 0.004), new V2(0.0065, 0.010), new V2(0.0025, 0.012), new V2(0, 0.013)], M.brass, 28); | |
| hub.rotation.x = Math.PI / 2; | |
| hub.position.set(0, dialCY, dialZ + 0.022); add(hub); | |
| anim.hour = hourHand; anim.minute = minuteHand; anim.second = secHand; | |
| // set classic 10:09 | |
| hourHand.position.z = -0.0008; | |
| minuteHand.position.z = 0.0008; | |
| hourHand.rotation.z = -((10 + 9 / 60) / 12) * Math.PI * 2; | |
| minuteHand.rotation.z = -(9 / 60) * Math.PI * 2; | |
| // gilded corner fans and maker's plaque on the arched dial plate | |
| const fanMat = M.brassAged.clone(); fanMat.side = THREE.DoubleSide; | |
| const fanL = new THREE.Mesh(shellGeometry(0.052, 11), fanMat); | |
| fanL.position.set(-0.158, 1.676, 0.208); fanL.rotation.z = 0.55; fanL.scale.y = 0.7; add(fanL); | |
| const fanR = new THREE.Mesh(shellGeometry(0.052, 11), fanMat); | |
| fanR.position.set(0.158, 1.676, 0.208); fanR.rotation.z = -0.55; fanR.scale.y = 0.7; add(fanR); | |
| const dialPlaque = new THREE.Mesh(new THREE.PlaneGeometry(0.118, 0.026), new THREE.MeshStandardMaterial({ | |
| map: M.plaqueTex, roughness: 0.34, metalness: 0.85, envMapIntensity: 1.2, | |
| })); | |
| dialPlaque.position.set(0, 1.683, 0.2085); add(dialPlaque); | |
| /* ===== pendulum & weights (inside trunk) ===== */ | |
| const pendPivot = new THREE.Group(); | |
| pendPivot.position.set(0, 1.43, 0.085); | |
| add(pendPivot); | |
| const rod = cyl(0.0045, 0.0045, 0.63, M.brass, 12); | |
| rod.position.y = -0.315; pendPivot.add(rod); | |
| const rodIn = box(0.008, 0.60, 0.003, M.steel); | |
| rodIn.position.set(0, -0.30, 0.002); pendPivot.add(rodIn); | |
| const bob = lathe([ | |
| new V2(0, 0), new V2(0.066, 0), new V2(0.074, 0.004), new V2(0.078, 0.012), | |
| new V2(0.078, 0.021), new V2(0.07, 0.028), new V2(0.03, 0.032), new V2(0, 0.033), | |
| ], M.brass, 56); | |
| bob.rotation.x = Math.PI / 2; | |
| bob.position.y = -0.635; pendPivot.add(bob); | |
| const bobRing = new THREE.Mesh(new THREE.TorusGeometry(0.069, 0.005, 12, 56), M.brassAged); | |
| bobRing.position.set(0, -0.635, 0.036); pendPivot.add(bobRing); | |
| const bobRing2 = new THREE.Mesh(new THREE.TorusGeometry(0.048, 0.0025, 8, 48), M.brassAged); | |
| bobRing2.position.set(0, -0.635, 0.0365); pendPivot.add(bobRing2); | |
| const suspension = new THREE.Mesh(new THREE.TorusGeometry(0.012, 0.003, 8, 20), M.brass); | |
| suspension.position.set(0, 0, 0.002); pendPivot.add(suspension); | |
| anim.pendulum = pendPivot; | |
| // weights | |
| for (const sx of [-1, 1]) { | |
| const w = lathe([ | |
| new V2(0, 0), new V2(0.028, 0), new V2(0.034, 0.005), new V2(0.035, 0.02), | |
| new V2(0.033, 0.07), new V2(0.036, 0.13), new V2(0.032, 0.16), | |
| new V2(0.022, 0.165), new V2(0, 0.165), | |
| ], M.brassAged, 36); | |
| w.position.set(sx * 0.105, 0.77, 0.07); add(w); | |
| // chain | |
| const curve = new THREE.CatmullRomCurve3([ | |
| new THREE.Vector3(sx * 0.105, 1.425, 0.07), | |
| new THREE.Vector3(sx * 0.105, 1.15, 0.072), | |
| new THREE.Vector3(sx * 0.105, 0.95, 0.07), | |
| new THREE.Vector3(sx * 0.105, 0.925, 0.07), | |
| ]); | |
| const chain = new THREE.Mesh(new THREE.TubeGeometry(curve, 24, 0.0022, 6, false), M.steel); | |
| add(chain); | |
| // chain links | |
| const linkGeo = new THREE.TorusGeometry(0.0065, 0.0016, 6, 12); | |
| const links = new THREE.InstancedMesh(linkGeo, M.brassAged, 14); | |
| for (let i = 0; i < 14; i++) { | |
| const t = i / 13; | |
| const y = 1.42 - t * 0.50; | |
| const m = new THREE.Matrix4(); | |
| const rot = new THREE.Matrix4().makeRotationY((i % 2) * Math.PI / 2); | |
| m.compose(new THREE.Vector3(sx * 0.105, y, 0.07), new THREE.Quaternion().setFromEuler(new THREE.Euler(0, (i % 2) * Math.PI / 2, 0)), new THREE.Vector3(1, 1, 1)); | |
| links.setMatrixAt(i, m); | |
| } | |
| add(links); | |
| } | |
| // chime rods | |
| for (let i = 0; i < 4; i++) { | |
| const r2 = cyl(0.003, 0.003, 0.22 + i * 0.02, M.brass, 6); | |
| r2.position.set(-0.16 + i * 0.035, 0.78 + (0.02 * i) / 2, -0.05); | |
| add(r2); | |
| } | |
| /* ===== cornice and dentils ===== */ | |
| add(rbox(0.67, 0.035, 0.44, M.mahoganyDark, 0.008)).position.y = 2.245; | |
| add(rbox(0.70, 0.025, 0.465, M.mahoganyLight, 0.006)).position.y = 2.272; | |
| add(rbox(0.665, 0.022, 0.44, M.mahoganyDark, 0.005)).position.y = 2.294; | |
| // dentils (instanced) | |
| const dentGeo = new RoundedBoxGeometry(0.018, 0.032, 0.026, 2, 0.003); | |
| const dentils = new THREE.InstancedMesh(dentGeo, M.mahoganyDark, 17 + 12); | |
| let di = 0; | |
| const dm4 = new THREE.Matrix4(); | |
| for (let i = 0; i < 17; i++) { | |
| const x = -0.32 + (i / 16) * 0.64; | |
| dm4.makeTranslation(x, 2.226, 0.228); | |
| dentils.setMatrixAt(di++, dm4); | |
| } | |
| for (const sx of [-1, 1]) for (let i = 0; i < 6; i++) { | |
| const z = 0.17 - i * 0.058; | |
| dm4.makeTranslation(sx * 0.326, 2.226, z); | |
| dentils.setMatrixAt(di++, dm4); | |
| } | |
| add(dentils); | |
| // holly band | |
| add(rbox(0.64, 0.005, 0.006, M.holly, 0.001)).position.set(0, 2.312, 0.221); | |
| /* ===== swan-neck pediment ===== */ | |
| const ped = new THREE.Shape(); | |
| ped.moveTo(-0.37, 2.30); | |
| ped.lineTo(-0.37, 2.345); | |
| ped.bezierCurveTo(-0.33, 2.40, -0.24, 2.42, -0.155, 2.445); | |
| ped.bezierCurveTo(-0.09, 2.465, -0.055, 2.49, -0.045, 2.53); | |
| ped.lineTo(0.045, 2.53); | |
| ped.bezierCurveTo(0.055, 2.49, 0.09, 2.465, 0.155, 2.445); | |
| ped.bezierCurveTo(0.24, 2.42, 0.33, 2.40, 0.37, 2.345); | |
| ped.lineTo(0.37, 2.30); | |
| ped.lineTo(-0.37, 2.30); | |
| const pediment = extrude(ped, 0.36, M.mahogany, 0.006); | |
| pediment.position.z = -0.18; | |
| add(pediment); | |
| // pediment front face framed with a moulded edge | |
| const pedEdgeShape = new THREE.Shape(); | |
| // scaled copy of ped outline, narrower, as raised border | |
| pedEdgeShape.moveTo(-0.33, 2.32); | |
| pedEdgeShape.lineTo(-0.33, 2.35); | |
| pedEdgeShape.bezierCurveTo(-0.29, 2.395, -0.21, 2.415, -0.135, 2.438); | |
| pedEdgeShape.bezierCurveTo(-0.075, 2.458, -0.04, 2.478, -0.03, 2.505); | |
| pedEdgeShape.lineTo(0.03, 2.505); | |
| pedEdgeShape.bezierCurveTo(0.04, 2.478, 0.075, 2.458, 0.135, 2.438); | |
| pedEdgeShape.bezierCurveTo(0.21, 2.415, 0.29, 2.395, 0.33, 2.35); | |
| pedEdgeShape.lineTo(0.33, 2.32); | |
| pedEdgeShape.lineTo(-0.33, 2.32); | |
| const pedB = extrude(pedEdgeShape, 0.018, M.mahoganyLight, 0.004); | |
| pedB.position.z = 0.188; add(pedB); | |
| // central crest block + rosette | |
| add(rbox(0.11, 0.06, 0.05, M.mahoganyDark, 0.006)).position.set(0, 2.535, 0.155); | |
| const crest = new THREE.Mesh(new THREE.TorusGeometry(0.032, 0.008, 12, 40), M.brass); | |
| crest.position.set(0, 2.565, 0.19); add(crest); | |
| const crestDot = new THREE.Mesh(new THREE.SphereGeometry(0.02, 20, 14), M.brass); | |
| crestDot.position.set(0, 2.565, 0.196); crestDot.scale.z = 0.5; add(crestDot); | |
| // sunburst rays around crest (instanced) | |
| const rayGeo = new THREE.BoxGeometry(0.003, 0.034, 0.004); | |
| const rays = new THREE.InstancedMesh(rayGeo, M.brass, 16); | |
| for (let i = 0; i < 16; i++) { | |
| const a = (i / 16) * Math.PI * 2; | |
| const m = new THREE.Matrix4(); | |
| m.compose(new THREE.Vector3(Math.cos(a) * 0.058, 2.565 + Math.sin(a) * 0.058, 0.188), | |
| new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, a - Math.PI / 2)), new THREE.Vector3(1, 1, 1)); | |
| rays.setMatrixAt(i, m); | |
| } | |
| add(rays); | |
| // finials | |
| const fin1 = finial(M.mahogany, 0.2, 0.042); fin1.position.set(0, 2.55, 0.0); add(fin1); | |
| const fin1Tip = new THREE.Mesh(new THREE.ConeGeometry(0.012, 0.06, 16), M.brass); | |
| fin1Tip.position.set(0, 2.80, 0); add(fin1Tip); | |
| for (const sx of [-1, 1]) { | |
| const f = finial(M.mahogany, 0.16, 0.036); | |
| f.position.set(sx * 0.315, 2.345, 0.08); add(f); | |
| const tip = new THREE.Mesh(new THREE.ConeGeometry(0.01, 0.05, 14), M.brass); | |
| tip.position.set(sx * 0.315, 2.545, 0.08); add(tip); | |
| const base = lathe([new V2(0, 0), new V2(0.048, 0), new V2(0.05, 0.008), new V2(0.036, 0.018), new V2(0.03, 0.026), new V2(0, 0.028)], M.brassAged, 24); | |
| base.position.set(sx * 0.315, 2.335, 0.08); add(base); | |
| // rosette on pediment ear | |
| const ros = new THREE.Mesh(new THREE.TorusGeometry(0.024, 0.006, 10, 28), M.brassAged); | |
| ros.position.set(sx * 0.265, 2.38, 0.19); add(ros); | |
| const rosDot = new THREE.Mesh(new THREE.SphereGeometry(0.012, 12, 8), M.brassAged); | |
| rosDot.position.set(sx * 0.265, 2.38, 0.196); rosDot.scale.z = 0.4; add(rosDot); | |
| } | |
| // side scrolls (tube along catmull-rom) on bonnet ends | |
| for (const sx of [-1, 1]) { | |
| const pts = [ | |
| new THREE.Vector3(sx * 0.37, 2.34, 0.17), | |
| new THREE.Vector3(sx * 0.35, 2.31, 0.19), | |
| new THREE.Vector3(sx * 0.33, 2.27, 0.2), | |
| new THREE.Vector3(sx * 0.345, 2.235, 0.2), | |
| new THREE.Vector3(sx * 0.365, 2.245, 0.19), | |
| new THREE.Vector3(sx * 0.368, 2.275, 0.18), | |
| ]; | |
| const curve = new THREE.CatmullRomCurve3(pts); | |
| const scroll = new THREE.Mesh(new THREE.TubeGeometry(curve, 32, 0.008, 8, false), M.mahoganyDark); | |
| add(scroll); | |
| } | |
| // carved garland under cornice: small leaves instanced | |
| const leafInst = new THREE.InstancedMesh(leafGeo, M.mahoganyDark, 10); | |
| for (let i = 0; i < 10; i++) { | |
| const x = -0.27 + i * 0.06; | |
| const m = new THREE.Matrix4(); | |
| const rot = (i % 2 ? 0.6 : -0.6); | |
| m.compose(new THREE.Vector3(x, 2.335, 0.19), new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, rot)), new THREE.Vector3(0.55, 0.55, 0.5)); | |
| leafInst.setMatrixAt(i, m); | |
| } | |
| add(leafInst); | |
| // top shadow/hidden inner | |
| const topCap = box(0.5, 0.01, 0.3, M.darkInterior); | |
| topCap.position.set(0, 1.455, 0.0); add(topCap); | |
| /* ===== back detailing ===== */ | |
| const bp1 = rbox(0.36, 0.94, 0.014, M.mahoganyDark, 0.005); | |
| bp1.position.set(0, 0.84, -0.172); add(bp1); | |
| const bp2 = rbox(0.30, 0.84, 0.008, M.mahogany, 0.004); | |
| bp2.position.set(0, 0.84, -0.181); add(bp2); | |
| for (const yy of [0.40, 1.28]) { | |
| const st = rbox(0.32, 0.004, 0.003, M.holly, 0.001); | |
| st.position.set(0, yy, -0.187); add(st); | |
| } | |
| const bh = rbox(0.40, 0.42, 0.014, M.mahoganyDark, 0.005); | |
| bh.position.set(0, 1.91, -0.203); add(bh); | |
| const bhi = rbox(0.33, 0.34, 0.008, M.mahogany, 0.004); | |
| bhi.position.set(0, 1.91, -0.212); add(bhi); | |
| // brass maker's plaque on back of hood | |
| const plaque = rbox(0.16, 0.045, 0.006, M.brassAged, 0.003); | |
| plaque.position.set(0, 1.62, -0.216); add(plaque); | |
| /* ===== animation update ===== */ | |
| anim.time = 0; | |
| group.userData.update = (dt, elapsed) => { | |
| anim.time += dt; | |
| // pendulum gentle swing | |
| if (anim.pendulum) anim.pendulum.rotation.z = Math.sin(elapsed * 2.05) * 0.055; | |
| // seconds hand smooth | |
| if (anim.second) anim.second.rotation.z = -(elapsed * Math.PI * 2) / 60; | |
| // moon disc rotates slowly | |
| if (anim.moon) anim.moon.rotation.z = -elapsed * 0.035; | |
| }; | |
| group.traverse((o) => { | |
| if (o.isMesh) { | |
| o.castShadow = true; | |
| o.receiveShadow = true; | |
| } | |
| }); | |
| return group; | |
| } | |