← back to Quadrille Showroom
public/proto/v14-velvet-lounge.html
680 lines
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>VELVET LOUNGE · China Seas</title>
<style>
:root { --brass:#d8b779; --paper:#f1e8d6; }
* { box-sizing:border-box; margin:0; padding:0; }
html,body { height:100%; overflow:hidden; background:#0a0607; color:var(--paper);
font-family:"Helvetica Neue",Helvetica,Arial,sans-serif; -webkit-font-smoothing:antialiased; }
#app { position:fixed; inset:0; }
canvas { display:block; }
/* ---- masthead ---- */
.masthead { position:fixed; top:0; left:0; right:0; z-index:20; padding:80px 30px 46px;
pointer-events:none; text-align:center;
background:linear-gradient(180deg, rgba(10,6,7,.78) 0%, rgba(10,6,7,0) 100%); }
.masthead .kicker { font-size:11px; letter-spacing:.46em; text-transform:uppercase;
color:#b89a66; font-weight:600; }
.masthead h1 { font-family:Georgia,"Times New Roman",serif; font-size:clamp(26px,4.4vw,46px);
font-weight:400; letter-spacing:.14em; line-height:1; margin-top:9px; color:#f3ead8; }
.masthead h1 b { font-weight:700; color:#e9c98f; }
.masthead .sub { margin-top:10px; font-size:12px; letter-spacing:.05em; color:#9a8d76;
max-width:540px; margin-left:auto; margin-right:auto; }
/* ---- focused board caption ---- */
#caption { position:fixed; left:50%; bottom:96px; transform:translateX(-50%) translateY(14px);
z-index:22; text-align:center; opacity:0; transition:opacity .5s, transform .5s cubic-bezier(.2,.8,.2,1);
pointer-events:none; }
#caption.show { opacity:1; transform:translateX(-50%) translateY(0); }
#caption .cn { font-family:Georgia,serif; font-size:22px; letter-spacing:.02em; color:#f4ecdb;
text-shadow:0 2px 22px rgba(0,0,0,.92); }
#caption .cc { margin-top:5px; font-size:10.5px; letter-spacing:.34em; text-transform:uppercase; color:#c4a36a; }
#caption .cspec { margin-top:9px; font-size:11.5px; letter-spacing:.04em; color:#a59a85; }
#caption a.cta { pointer-events:auto; display:inline-block; margin-top:14px; padding:10px 26px;
border:1px solid rgba(216,183,121,.55); border-radius:28px; color:#e9c98f; font-size:10.5px;
letter-spacing:.24em; text-transform:uppercase; text-decoration:none; font-weight:700;
background:rgba(216,183,121,.07); transition:background .15s, transform .15s; }
#caption a.cta:hover { background:rgba(216,183,121,.2); transform:translateY(-1px); }
.hint { position:fixed; bottom:30px; left:50%; transform:translateX(-50%); z-index:20;
font-size:11px; letter-spacing:.3em; text-transform:uppercase; color:rgba(228,214,188,.42);
pointer-events:none; transition:opacity .6s; }
/* ---- FPS readout ---- */
#fps { position:fixed; bottom:14px; right:16px; z-index:25; font:600 11px/1.3 ui-monospace,Menlo,monospace;
color:#b89a66; background:rgba(14,9,10,.6); border:1px solid rgba(216,183,121,.25); border-radius:7px;
padding:6px 10px; letter-spacing:.04em; cursor:pointer; -webkit-user-select:none; user-select:none; }
#fps.off { opacity:.32; }
/* ---- loading ---- */
#boot { position:fixed; inset:0; z-index:50; display:flex; flex-direction:column;
align-items:center; justify-content:center; background:#0a0607; transition:opacity .9s; }
#boot .ring { width:44px; height:44px; border-radius:50%;
border:2px solid rgba(216,183,121,.18); border-top-color:#d8b779; animation:spin 1s linear infinite; }
#boot .lbl { margin-top:18px; font-size:11px; letter-spacing:.36em; text-transform:uppercase; color:#8a7d62; }
@keyframes spin { to { transform:rotate(360deg); } }
@media (max-width:720px){ .masthead .sub{display:none;} .masthead{padding-top:74px;} }
</style>
</head>
<body>
<div id="app"></div>
<div class="masthead">
<div class="kicker">Designer Wallcoverings · The Velvet Lounge</div>
<h1>VELVET <b>LOUNGE</b></h1>
<div class="sub">China Seas, set in a jewel-box salon — deep velvet walls, brass sconces, low warm light.
One board glides into the glow at a time, full pattern edge to edge. Drag to swing the bank.</div>
</div>
<div id="caption">
<div class="cn" id="cap_name">—</div>
<div class="cc" id="cap_coll">China Seas</div>
<div class="cspec" id="cap_spec">—</div>
<a class="cta" id="cap_cta" href="#" target="_blank" rel="noopener noreferrer">View Pattern →</a>
</div>
<div class="hint" id="hint">drag · click a board · scroll</div>
<div id="fps" title="Toggle FPS">— fps</div>
<div id="boot"><div class="ring"></div><div class="lbl" id="bootlbl">Lighting the sconces…</div></div>
<!-- r128 core (local) + r128 example modules (CDN, attach to global THREE) -->
<script src="./three.min.js"></script>
<script src="https://unpkg.com/three@0.128.0/examples/js/environments/RoomEnvironment.js"></script>
<script>
"use strict";
(function () {
const API = "/api/showroom/products?limit=50";
const app = document.getElementById("app");
const bootlbl = document.getElementById("bootlbl");
const W = ()=>window.innerWidth, H = ()=>window.innerHeight;
const clamp = (v,a,b)=>Math.max(a,Math.min(b,v));
const lerp = (a,b,t)=>a+(b-a)*t;
// -------------------------------------------------------------------------
// RENDERER (high-end baseline)
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias:true, powerPreference:"high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio||1, 2));
renderer.setSize(W(), H());
if ("outputColorSpace" in renderer) renderer.outputColorSpace = THREE.SRGBColorSpace;
else if ("outputEncoding" in renderer) renderer.outputEncoding = THREE.sRGBEncoding;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12; // a touch hot so the jewel tones glow, not muddy
if ("physicallyCorrectLights" in renderer) renderer.physicallyCorrectLights = true;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x0a0607, 1);
app.appendChild(renderer.domElement);
const MAX_ANISO = renderer.capabilities.getMaxAnisotropy();
var _glowTex = null; // shared additive-glow texture (hoisted; built lazily)
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0c0709);
// slight warm haze for plush depth (the "slight haze" the brief asks for)
scene.fog = new THREE.FogExp2(0x140a10, 0.026);
const camera = new THREE.PerspectiveCamera(46, W()/H(), 0.1, 200);
camera.position.set(0, 1.9, 9.0); // a touch higher & closer so velvet walls
camera.lookAt(0, 2.05, 0); // fill the frame, less muddy floor in view
// -------------------------------------------------------------------------
// PMREM ENVIRONMENT (RoomEnvironment) — so brass & gloss reflect richly
// -------------------------------------------------------------------------
(function buildEnv(){
try {
const pmrem = new THREE.PMREMGenerator(renderer);
const env = new THREE.RoomEnvironment();
const envMap = pmrem.fromScene(env, 0.04).texture;
scene.environment = envMap;
pmrem.dispose();
} catch(e){ /* env optional */ }
})();
// r128 sheen API: MeshPhysicalMaterial.sheen is a COLOR (or null), NOT the
// scalar sheen/sheenColor/sheenRoughness split that arrived in r132+. So we
// detect by whether assigning a Color sticks, and drive velvet plushness that way.
const SHEEN_OK = (function(){
try {
const m = new THREE.MeshPhysicalMaterial();
return ("sheen" in m) && !("sheenColor" in m); // r128-style sheen=Color
} catch(e){ return false; }
})();
// -------------------------------------------------------------------------
// LIGHTING — intimate, low-key, warm. A warm amber key + cool sapphire fill +
// warm rim, PLUS two brass-sconce point lights flanking the bank and a hero
// spotlight that follows the featured board.
// -------------------------------------------------------------------------
scene.add(new THREE.AmbientLight(0x241019, 0.5)); // warm plum base, low
const fill = new THREE.DirectionalLight(0x5a6fa0, 0.26); // cool sapphire fill from left
fill.position.set(-7, 6, 6); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffcaa0, 0.34); // warm rim from behind-right
rim.position.set(6, 4, -8); scene.add(rim);
// low warm wash from floor level so the emerald velvet glows from below the
// sconces rather than dying to black — keeps the lounge plush, not muddy-dark.
const uplight = new THREE.DirectionalLight(0xffb888, 0.16);
uplight.position.set(0, -2, 4); scene.add(uplight);
const key = new THREE.DirectionalLight(0xffe7c2, 0.34); // soft warm key
key.position.set(2, 9, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.near = 1; key.shadow.camera.far = 40;
key.shadow.camera.left = -10; key.shadow.camera.right = 10;
key.shadow.camera.top = 10; key.shadow.camera.bottom = -10;
key.shadow.bias = -0.0004; key.shadow.radius = 4;
scene.add(key);
// hero spotlight — warm, tight, casts the gallery shadow on the featured board
const spot = new THREE.SpotLight(0xffe2b4, 0, 18, Math.PI/7.0, 0.5, 1.3);
spot.position.set(0, 6.2, 5.4);
spot.castShadow = true;
spot.shadow.mapSize.set(2048, 2048);
spot.shadow.camera.near = 1; spot.shadow.camera.far = 24;
spot.shadow.bias = -0.0005; spot.shadow.radius = 5;
scene.add(spot);
const spotTarget = new THREE.Object3D(); scene.add(spotTarget);
spot.target = spotTarget;
// two brass wall-sconce point lights flanking the bank — warm pools of light
const sconceL = new THREE.PointLight(0xffb774, 6.5, 14, 2.0); sconceL.position.set(-6.4, 4.4, -2.0); scene.add(sconceL);
const sconceR = new THREE.PointLight(0xffb774, 6.5, 14, 2.0); sconceR.position.set( 6.4, 4.4, -2.0); scene.add(sconceR);
// -------------------------------------------------------------------------
// ROOM — deep jewel-tone VELVET walls (emerald / sapphire / oxblood), a warm
// dark herringbone-ish floor, brass sconce fixtures with emissive "glow".
// Velvet = high roughness + sheen (when supported) so the nap catches the rim.
// -------------------------------------------------------------------------
const FLOOR_Y = 0;
function makeVelvetMat(color, sheenColor){
const m = new THREE.MeshPhysicalMaterial({
color: color, roughness: 0.96, metalness: 0.0, envMapIntensity: 0.35
});
if (SHEEN_OK){
// r128: sheen is a Color — set it to the jewel highlight so the velvet nap
// catches the warm rim/sconce light at grazing angles (plush, not flat).
m.sheen = new THREE.Color(sheenColor);
}
return m;
}
// a soft vertical "drape" gradient + faint nap noise so velvet walls aren't flat
function makeVelvetRoughness(){
const c = document.createElement("canvas"); c.width = c.height = 256;
const x = c.getContext("2d");
x.fillStyle = "#f0f0f0"; x.fillRect(0,0,256,256);
const img = x.getImageData(0,0,256,256); const d = img.data;
for(let i=0;i<d.length;i+=4){ const n=(Math.random()*40)|0; d[i]=d[i+1]=d[i+2]=210+n; }
x.putImageData(img,0,0);
const t = new THREE.CanvasTexture(c); t.wrapS=t.wrapT=THREE.RepeatWrapping; t.repeat.set(4,4);
t.anisotropy = MAX_ANISO; return t;
}
const velvetRough = makeVelvetRoughness();
(function buildRoom(){
// BACK WALL — deep emerald velvet (the jewel anchor behind the bank).
// Slightly richer envMap so the nap glints under the sconces, not flat.
const backMat = makeVelvetMat(0x103a2c, 0x2a8062);
backMat.envMapIntensity = 0.5;
backMat.roughnessMap = velvetRough;
const back = new THREE.Mesh(new THREE.PlaneGeometry(60, 24), backMat);
back.position.set(0, 6, -7.5); back.receiveShadow = true; scene.add(back);
// SIDE WALLS — sapphire (left) + oxblood (right) for jewel-tone contrast
const leftMat = makeVelvetMat(0x122347, 0x2a4a8f);
leftMat.roughnessMap = velvetRough;
const left = new THREE.Mesh(new THREE.PlaneGeometry(40, 24), leftMat);
left.position.set(-14, 6, 2); left.rotation.y = Math.PI/2; left.receiveShadow = true; scene.add(left);
const rightMat = makeVelvetMat(0x3d1218, 0x7a2a36); // oxblood
rightMat.roughnessMap = velvetRough;
const right = new THREE.Mesh(new THREE.PlaneGeometry(40, 24), rightMat);
right.position.set(14, 6, 2); right.rotation.y = -Math.PI/2; right.receiveShadow = true; scene.add(right);
// CEILING — deep warm plum, near-matte, no bounce
const ceil = new THREE.Mesh(new THREE.PlaneGeometry(60, 40),
new THREE.MeshStandardMaterial({ color:0x14090f, roughness:1.0 }));
ceil.position.set(0, 13, 0); ceil.rotation.x = Math.PI/2; scene.add(ceil);
// FLOOR — warm dark wood, satin clearcoat so the brass + boards reflect softly
const floorMat = new THREE.MeshPhysicalMaterial({
color:0x18100b, roughness:0.42, metalness:0.0,
clearcoat:0.7, clearcoatRoughness:0.5, envMapIntensity:0.45
});
floorMat.roughnessMap = makeFloorRoughness();
floorMat.roughnessMap.wrapS = floorMat.roughnessMap.wrapT = THREE.RepeatWrapping;
floorMat.roughnessMap.repeat.set(10, 10);
const floor = new THREE.Mesh(new THREE.PlaneGeometry(60, 40), floorMat);
floor.rotation.x = -Math.PI/2; floor.position.y = FLOOR_Y; floor.receiveShadow = true;
scene.add(floor);
// a faint warm GLOW pool on the back wall behind each sconce (radial sprite-ish
// additive plane) — cheap fake-bloom so the sconces read as light sources.
addGlowPanel(-6.4, 4.4, -7.35, 0xffb262, 3.2);
addGlowPanel( 6.4, 4.4, -7.35, 0xffb262, 3.2);
// BRASS SCONCES — small emissive brass fixtures on the back wall
buildSconce(-6.4, 4.4);
buildSconce( 6.4, 4.4);
})();
// warm wood roughness streak
function makeFloorRoughness(){
const c = document.createElement("canvas"); c.width = c.height = 256;
const x = c.getContext("2d");
x.fillStyle = "#8a8a8a"; x.fillRect(0,0,256,256);
const img = x.getImageData(0,0,256,256); const d = img.data;
for(let i=0;i<d.length;i+=4){ const n=(Math.random()*60)|0; d[i]=d[i+1]=d[i+2]=120+n; }
x.putImageData(img,0,0);
const t = new THREE.CanvasTexture(c); t.anisotropy = MAX_ANISO; return t;
}
// additive radial glow texture (shared) for fake-bloom glow pools.
// var (hoisted, TDZ-safe) so the buildRoom IIFE above can call glowTexture().
function glowTexture(){
if(_glowTex) return _glowTex;
const c = document.createElement("canvas"); c.width=c.height=128;
const g = c.getContext("2d");
const grd = g.createRadialGradient(64,64,2, 64,64,64);
grd.addColorStop(0, "rgba(255,255,255,1)");
grd.addColorStop(0.35, "rgba(255,255,255,0.45)");
grd.addColorStop(1, "rgba(255,255,255,0)");
g.fillStyle = grd; g.fillRect(0,0,128,128);
_glowTex = new THREE.CanvasTexture(c); return _glowTex;
}
function addGlowPanel(x,y,z,color,size){
const m = new THREE.MeshBasicMaterial({
map: glowTexture(), color: color, transparent:true, opacity:0.55,
blending: THREE.AdditiveBlending, depthWrite:false, toneMapped:false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(size, size), m);
mesh.position.set(x,y,z); mesh.renderOrder = 2; scene.add(mesh);
}
// a brass wall sconce: a small emissive brass cup + a tiny additive flame glow
function buildSconce(x,y){
const brass = new THREE.MeshPhysicalMaterial({
color:0x8a6a2e, roughness:0.28, metalness:1.0,
clearcoat:0.6, clearcoatRoughness:0.3, envMapIntensity:1.2,
emissive:0x4a2f0c, emissiveIntensity:0.6
});
const arm = new THREE.Mesh(new THREE.CylinderGeometry(0.04,0.04,0.5,12), brass);
arm.position.set(x, y, -7.05); arm.rotation.x = Math.PI/2; scene.add(arm);
const cup = new THREE.Mesh(new THREE.ConeGeometry(0.16, 0.3, 14, 1, true), brass);
cup.position.set(x, y+0.05, -6.78); scene.add(cup);
// emissive "flame" core
const flameMat = new THREE.MeshBasicMaterial({ color:0xffd089, toneMapped:false });
const flame = new THREE.Mesh(new THREE.SphereGeometry(0.07, 10, 10), flameMat);
flame.position.set(x, y+0.16, -6.78); scene.add(flame);
// small additive halo right at the flame
const halo = new THREE.Mesh(new THREE.PlaneGeometry(1.0,1.0), new THREE.MeshBasicMaterial({
map: glowTexture(), color:0xffc070, transparent:true, opacity:0.7,
blending:THREE.AdditiveBlending, depthWrite:false, toneMapped:false
}));
halo.position.set(x, y+0.16, -6.7); halo.renderOrder = 3; scene.add(halo);
}
// -------------------------------------------------------------------------
// THE WING BANK — thin brass-framed boards, ~2" apart on an arc, side swivel.
// -------------------------------------------------------------------------
const BOARD_W = 1.46; // ~30" wide board face (world units; 1u ≈ 20.5")
const BOARD_H = 3.55; // ~6' tall
const FRAME_T = 0.045; // thin frame border thickness
const FRAME_D = 0.05; // frame depth
const GAP = 0.10; // ~2" between closed boards
const PITCH = BOARD_W + GAP;
const BANK_Z = -4.4; // closed boards rest here
const N_TARGET = 50;
const boards = []; // { group, faceMesh, data, idx, base x }
let products = [];
let focusIdx = 0;
// shared geometries / materials
const faceGeo = new THREE.PlaneGeometry(BOARD_W, BOARD_H);
// polished BRASS frame material — metalness + clearcoat per the brief
const frameMat = new THREE.MeshPhysicalMaterial({
color:0x9c7836, roughness:0.26, metalness:1.0,
clearcoat:0.55, clearcoatRoughness:0.28, envMapIntensity:1.25,
emissive:0x2a1c08, emissiveIntensity:0.35
});
function placeholderFace(){
return new THREE.MeshPhysicalMaterial({ color:0x1a1512, roughness:0.62, metalness:0.0, envMapIntensity:0.35 });
}
// board pivots on its LEFT edge (side swivel). Group origin = left hinge.
function buildBoard(idx){
const g = new THREE.Group();
const backing = new THREE.Mesh(
new THREE.BoxGeometry(BOARD_W + FRAME_T*1.6, BOARD_H + FRAME_T*1.6, 0.03),
new THREE.MeshStandardMaterial({ color:0x140f0c, roughness:0.85, metalness:0.05 })
);
backing.position.set(BOARD_W/2, BOARD_H/2 + 0.02, -0.02);
backing.castShadow = true; backing.receiveShadow = true;
g.add(backing);
const faceMat = placeholderFace();
const face = new THREE.Mesh(faceGeo, faceMat);
face.position.set(BOARD_W/2, BOARD_H/2 + 0.02, 0.012);
face.castShadow = false; face.receiveShadow = true;
face.userData.idx = idx;
g.add(face);
const fb = new THREE.BoxGeometry(BOARD_W + FRAME_T*2, FRAME_T, FRAME_D);
const fv = new THREE.BoxGeometry(FRAME_T, BOARD_H + FRAME_T*2, FRAME_D);
const top = new THREE.Mesh(fb, frameMat); top.position.set(BOARD_W/2, BOARD_H + FRAME_T/2 + 0.02, 0.02); top.castShadow = true;
const bot = new THREE.Mesh(fb, frameMat); bot.position.set(BOARD_W/2, FRAME_T/2 + 0.02, 0.02); bot.castShadow = true;
const lf = new THREE.Mesh(fv, frameMat); lf.position.set(-FRAME_T/2, BOARD_H/2 + 0.02, 0.02); lf.castShadow = true;
const rt = new THREE.Mesh(fv, frameMat); rt.position.set(BOARD_W + FRAME_T/2, BOARD_H/2 + 0.02, 0.02); rt.castShadow = true;
g.add(top, bot, lf, rt);
scene.add(g);
return { group:g, face, faceMat, idx, data:null, texLoaded:false, swivel:0 };
}
// -------------------------------------------------------------------------
// FLOOR REFLECTION — mirrored, dimmed clone of the featured board's face.
// -------------------------------------------------------------------------
const reflGeo = new THREE.PlaneGeometry(BOARD_W, BOARD_H);
const reflMat = new THREE.MeshBasicMaterial({ transparent:true, opacity:0.0, depthWrite:false, side:THREE.FrontSide });
const reflMesh = new THREE.Mesh(reflGeo, reflMat);
reflMesh.scale.y = -1;
reflMesh.renderOrder = 1;
scene.add(reflMesh);
// -------------------------------------------------------------------------
// TEXTURE LOADER — lazy: only load the featured board + a window of neighbours
// -------------------------------------------------------------------------
const texCache = new Map();
function imgURL(u){
if(!u) return null;
if(/cdn\.shopify\.com/.test(u) || /^\//.test(u)) return u;
return "/api/proxy/image?url=" + encodeURIComponent(u);
}
function loadTexture(url){
if(texCache.has(url)) return Promise.resolve(texCache.get(url));
return new Promise((resolve)=>{
const img = new Image(); img.crossOrigin = "anonymous";
img.onload = ()=>{
const tex = new THREE.Texture(img);
if("colorSpace" in tex) tex.colorSpace = THREE.SRGBColorSpace;
else tex.encoding = THREE.sRGBEncoding;
tex.anisotropy = MAX_ANISO;
tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
tex.repeat.set(1, 1.0);
tex.needsUpdate = true;
texCache.set(url, tex);
resolve(tex);
};
img.onerror = ()=>resolve(null);
img.src = url;
});
}
function ensureBoardTexture(b){
if(b.texLoaded || !b.data) return;
const url = imgURL(b.data.image || b.data.tile);
if(!url){ b.texLoaded = true; return; }
b.texLoaded = true;
loadTexture(url).then(tex=>{
if(!tex) return;
const m = new THREE.MeshPhysicalMaterial({
map:tex, roughness:0.56, metalness:0.0, clearcoat:0.10, clearcoatRoughness:0.6, envMapIntensity:0.35
});
b.face.material.dispose && b.face.material.dispose();
b.face.material = m; b.faceMat = m;
});
}
function refreshTextureWindow(){
const WIN = 4;
for(let i=0;i<boards.length;i++){
const d = Math.min(Math.abs(i-focusIdx), boards.length-Math.abs(i-focusIdx));
if(d <= WIN) ensureBoardTexture(boards[i]);
}
}
// -------------------------------------------------------------------------
// LAYOUT
// -------------------------------------------------------------------------
function arcZ(x){ return BANK_Z - Math.abs(x)*0.018; }
// -------------------------------------------------------------------------
// INTERACTION
// -------------------------------------------------------------------------
let pan = 0, targetFocus = 0;
const ray = new THREE.Raycaster();
const ndc = new THREE.Vector2();
function setFocus(i){
targetFocus = clamp(i, 0, boards.length-1);
focusIdx = Math.round(targetFocus);
refreshTextureWindow();
showCaption(boards[focusIdx]);
}
let dragging=false, dragX=0, focusStart=0, moved=0;
renderer.domElement.addEventListener("pointerdown",(e)=>{
dragging=true; moved=0; dragX=e.clientX; focusStart=targetFocus;
renderer.domElement.setPointerCapture(e.pointerId);
});
renderer.domElement.addEventListener("pointermove",(e)=>{
if(!dragging) return;
const dx = e.clientX - dragX; moved += Math.abs(dx);
targetFocus = clamp(focusStart - dx/120, 0, boards.length-1);
focusIdx = Math.round(targetFocus);
});
renderer.domElement.addEventListener("pointerup",(e)=>{
dragging=false;
if(moved < 6){ tryPick(e); }
else { setFocus(Math.round(targetFocus)); }
});
window.addEventListener("wheel",(e)=>{
e.preventDefault();
const dom = (Math.abs(e.deltaX)>Math.abs(e.deltaY))?e.deltaX:e.deltaY;
setFocus(Math.round(targetFocus) + (dom>0?1:-1));
}, { passive:false });
function tryPick(e){
const r = renderer.domElement.getBoundingClientRect();
ndc.x = ((e.clientX-r.left)/r.width)*2 - 1;
ndc.y = -((e.clientY-r.top)/r.height)*2 + 1;
ray.setFromCamera(ndc, camera);
const meshes = boards.map(b=>b.face);
const hits = ray.intersectObjects(meshes, false);
if(hits.length){
const idx = hits[0].object.userData.idx;
if(idx===focusIdx){ const d=boards[idx].data; if(d && d.store_url) window.open(d.store_url,"_blank","noopener"); }
else setFocus(idx);
}
}
// -------------------------------------------------------------------------
// CAPTION
// -------------------------------------------------------------------------
const capEl = document.getElementById("caption");
function showCaption(b){
if(!b || !b.data){ capEl.classList.remove("show"); return; }
const d = b.data;
document.getElementById("cap_name").textContent = d.pattern_name || d.title || "Untitled";
document.getElementById("cap_coll").textContent = (d.collection || d.vendor || "China Seas");
const bits = [];
if(d.width) bits.push(`${d.width}" wide`);
if(d.repeat) bits.push(`${d.repeat}" repeat`);
if(d.match_type) bits.push(d.match_type);
document.getElementById("cap_spec").textContent = bits.join(" · ") || "China Seas";
const cta = document.getElementById("cap_cta");
if(d.store_url){ cta.href = d.store_url; cta.style.display="inline-block"; }
else cta.style.display="none";
capEl.classList.add("show");
}
// -------------------------------------------------------------------------
// RESIZE
// -------------------------------------------------------------------------
window.addEventListener("resize", ()=>{
camera.aspect = W()/H(); camera.updateProjectionMatrix();
renderer.setSize(W(), H());
});
// -------------------------------------------------------------------------
// FPS readout + pause on hidden
// -------------------------------------------------------------------------
const fpsEl = document.getElementById("fps");
let fpsOn = true, frames=0, fpsT0=performance.now(), fpsVal=0;
fpsEl.addEventListener("click", ()=>{ fpsOn=!fpsOn; fpsEl.classList.toggle("off",!fpsOn); });
let running = true;
document.addEventListener("visibilitychange", ()=>{
running = !document.hidden;
if(running){ t0=performance.now(); requestAnimationFrame(tick); }
});
// -------------------------------------------------------------------------
// RENDER LOOP
// -------------------------------------------------------------------------
let t0 = performance.now();
function tick(now){
if(!running) return;
const dt = Math.min((now - t0)/1000, 0.05); t0 = now;
pan += (targetFocus - pan) * Math.min(1, dt*7.0);
const eased = pan;
// gentle candle-flicker on the sconce lights so the lounge feels alive
const fl = 1 + Math.sin(now*0.013)*0.05 + Math.sin(now*0.041)*0.03;
sconceL.intensity = 6.5*fl;
sconceR.intensity = 6.5*(2 - fl);
for(let i=0;i<boards.length;i++){
const b = boards[i];
const rel = i - eased;
const openAmt = clamp(1 - Math.abs(rel)*1.35, 0, 1);
const targetSwivel = (rel<0 ? 1 : -1) * (1-openAmt) * 1.0;
b.swivel += (targetSwivel - b.swivel)*Math.min(1,dt*9);
b.group.rotation.y = b.swivel;
const slotX = rel * PITCH;
const targetX = slotX - (BOARD_W/2) * Math.cos(b.swivel);
const targetZ = arcZ(slotX) + openAmt*1.55;
b.group.position.x += (targetX - b.group.position.x)*Math.min(1,dt*9);
b.group.position.z += (targetZ - b.group.position.z)*Math.min(1,dt*9);
b.group.position.y = 0;
// low-key chiaroscuro — only the featured board sits fully in the warm pool
const litTarget = 0.22 + 0.78*Math.pow(openAmt, 1.35);
if(b._lit===undefined) b._lit = litTarget;
b._lit += (litTarget - b._lit)*Math.min(1,dt*6);
if(b.faceMat){ b.faceMat.color.setScalar(b._lit); }
const farOff = Math.abs(rel) > 7;
b.group.visible = !farOff;
}
const front = boards[focusIdx];
if(front){
const fx = front.group.position.x + BOARD_W/2;
spotTarget.position.set(fx, BOARD_H*0.5, front.group.position.z);
spot.position.set(fx, 6.4, front.group.position.z + 5.2);
spot.intensity += ((HAS_PRODUCTS?8.5:0) - spot.intensity)*Math.min(1,dt*5);
if(front.faceMat && front.faceMat.map){
reflMat.map = front.faceMat.map;
reflMat.opacity += (0.14 - reflMat.opacity)*Math.min(1,dt*5);
reflMesh.position.set(fx, -BOARD_H/2 - 0.02, front.group.position.z + 0.02);
reflMesh.needsUpdate = true;
} else {
reflMat.opacity += (0 - reflMat.opacity)*Math.min(1,dt*5);
}
}
renderer.render(scene, camera);
frames++;
if(now - fpsT0 >= 500){
fpsVal = Math.round(frames*1000/(now-fpsT0)); frames=0; fpsT0=now;
if(fpsOn) fpsEl.textContent = fpsVal + " fps";
window.__VL_FPS = fpsVal;
}
requestAnimationFrame(tick);
}
// -------------------------------------------------------------------------
// BOOT
// -------------------------------------------------------------------------
let HAS_PRODUCTS = false;
async function start(){
try {
const res = await fetch(API);
const json = await res.json();
products = (json.products||[]).slice(0, N_TARGET);
} catch(e){
bootlbl.textContent = "Could not reach the catalog.";
console.error("fetch failed", e);
return;
}
if(!products.length){ bootlbl.textContent = "No products returned."; return; }
HAS_PRODUCTS = true;
for(let i=0;i<products.length;i++){
const b = buildBoard(i);
b.data = products[i];
b.group.position.set((i-0)*PITCH, 0, BANK_Z);
boards.push(b);
}
bootlbl.textContent = `Hanging ${boards.length} boards…`;
focusIdx = Math.min(2, boards.length-1);
pan = targetFocus = focusIdx;
refreshTextureWindow();
const featUrl = imgURL(boards[focusIdx].data.image || boards[focusIdx].data.tile);
await loadTexture(featUrl).catch(()=>null);
ensureBoardTexture(boards[focusIdx]);
showCaption(boards[focusIdx]);
window.__VL__ = {
boards: ()=>boards.length,
textured: ()=>boards.filter(b=>b.faceMat && b.faceMat.map).length,
focus: ()=>focusIdx,
fps: ()=>window.__VL_FPS||0,
ready: true
};
finishBoot();
requestAnimationFrame(tick);
}
function finishBoot(){
const boot = document.getElementById("boot");
boot.style.opacity = "0";
setTimeout(()=>boot.remove(), 950);
const hint = document.getElementById("hint");
setTimeout(()=>{ hint.style.opacity="0"; }, 6000);
}
start();
})();
</script>
<script>window.PROTO_META={"key":"V14","label":"V14 — Velvet Lounge","elements":[
{"n":1,"label":"Jewel-box salon — emerald / sapphire / oxblood velvet walls"},
{"n":2,"label":"Brass wall sconces with warm flame-glow pools"},
{"n":3,"label":"Intimate low-key warm key + sapphire fill + flicker"},
{"n":4,"label":"Thin brass-framed boards, ~2\" apart on a side swivel"},
{"n":5,"label":"Click a board → glides to center → full pattern face + soft floor reflection"}
]};</script>
<script src="./proto-chrome.js"></script>
</body>
</html>