Fix FP/VR visibility in iframe, speed control, pointer lock
Browse files- Add FP and JOIN buttons to index.html controls bar
- Forward toggle-fp and show-join messages to 3d iframe
- Add pointer-lock, xr-spatial-tracking, fullscreen to iframe allow
- Click overlay for pointer lock (user gesture required)
- Fix speed control: set simSpeed immediately before async API call
- Prevent speed flickering at 10x/50x
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Files changed (2)
- web/3d.html+17-2
- web/index.html+7-11
191 unmodified lines1921931941951961972704 unmodified lines29022903290429052906290729083 unmodified lines29122913291429152916291729182919292029213 unmodified lines292529262927292829292930200 unmodified lines313131323133313431353136191 unmodified lines<div id="fp-hint" style="display:none;position:fixed;bottom:60px;left:50%;transform:translateX(-50%);background:rgba(0,0,0,0.7);color:#fff;padding:8px 16px;border-radius:8px;font-size:13px;z-index:50;text-align:center">WASD — move · Mouse — look · ESC — exit · E — interact</div><div id="player-login"><h2>JOIN SOCI CITY</h2>2704 unmodified linesfpControls.addEventListener('unlock', () => {document.getElementById('fp-crosshair').style.display = 'none';if (fpMode) {setTimeout(() => { if (fpMode) fpControls.lock(); }, 200);}});3 unmodified linesfpCamera.aspect = window.innerWidth / window.innerHeight;fpCamera.updateProjectionMatrix();controls.enabled = false;fpControls.lock();fpClock.start();document.getElementById('btn-fp').classList.add('active');document.getElementById('btn-fp').title = 'Exit first-person';}function exitFPMode() {3 unmodified linesfpClock.stop();document.getElementById('fp-crosshair').style.display = 'none';document.getElementById('fp-hint').style.display = 'none';document.getElementById('btn-fp').classList.remove('active');document.getElementById('btn-fp').title = 'First-person view';}200 unmodified linesif (e.data?.type === 'zoom-out') zoomOut();if (e.data?.type === 'reset-camera') resetCamera();if (e.data?.type === 'set-speed') setDemoSpeed(e.data.multiplier);});}connectWebSocket();191 unmodified lines1921931941951961971981992002012022032042704 unmodified lines29092910291129122913291429153 unmodified lines2919292029212922292329242925292629272928292929302931293229333 unmodified lines2937293829392940294129422943200 unmodified lines31443145314631473148314931503151191 unmodified lines<div id="fp-hint" style="display:none;position:fixed;bottom:60px;left:50%;transform:translateX(-50%);background:rgba(0,0,0,0.7);color:#fff;padding:8px 16px;border-radius:8px;font-size:13px;z-index:50;text-align:center">WASD — move · Mouse — look · ESC — exit · E — interact</div><div id="fp-click-overlay" style="display:none;position:fixed;inset:0;background:rgba(0,0,0,0.6);z-index:250;cursor:pointer;display:none;align-items:center;justify-content:center"><div style="text-align:center;color:#fff"><div style="font-size:48px;margin-bottom:16px">👁</div><div style="font-size:20px;font-weight:300;letter-spacing:2px">CLICK TO ENTER FIRST-PERSON</div><div style="font-size:13px;color:#aaa;margin-top:8px">WASD — move · Mouse — look · ESC — exit</div></div></div><div id="player-login"><h2>JOIN SOCI CITY</h2>2704 unmodified linesfpControls.addEventListener('unlock', () => {document.getElementById('fp-crosshair').style.display = 'none';if (fpMode) {document.getElementById('fp-click-overlay').style.display = 'flex';}});3 unmodified linesfpCamera.aspect = window.innerWidth / window.innerHeight;fpCamera.updateProjectionMatrix();controls.enabled = false;fpClock.start();document.getElementById('btn-fp').classList.add('active');document.getElementById('btn-fp').title = 'Exit first-person';const overlay = document.getElementById('fp-click-overlay');overlay.style.display = 'flex';overlay.onclick = () => {overlay.style.display = 'none';fpControls.lock();};}function exitFPMode() {3 unmodified linesfpClock.stop();document.getElementById('fp-crosshair').style.display = 'none';document.getElementById('fp-hint').style.display = 'none';document.getElementById('fp-click-overlay').style.display = 'none';document.getElementById('btn-fp').classList.remove('active');document.getElementById('btn-fp').title = 'First-person view';}200 unmodified linesif (e.data?.type === 'zoom-out') zoomOut();if (e.data?.type === 'reset-camera') resetCamera();if (e.data?.type === 'set-speed') setDemoSpeed(e.data.multiplier);if (e.data?.type === 'toggle-fp') window._toggleFP();if (e.data?.type === 'show-join') window._showJoin();});}connectWebSocket();
292 unmodified lines2932942952962972982 unmodified lines3013023033043053063072941 unmodified lines3249325032513252325332543255325632573258325932603261326232633264326532663267292 unmodified lines<button class="ctrl-btn" onclick="send3d('zoom-in')" title="Zoom In (scroll in 3D view)">+</button><button class="ctrl-btn" onclick="send3d('zoom-out')" title="Zoom Out (scroll in 3D view)">-</button><button class="ctrl-btn" onclick="send3d('reset-camera')" title="Reset 3D camera">Fit</button></span><span id="api-calls">API: 0</span><span id="cost">$0.00</span>2 unmodified lines</div><div id="main"><div id="viewport-3d"><iframe id="city3d" allow="autoplay"></iframe><script>document.getElementById('city3d').src = location.protocol === 'file:' ? '3d.html' : '/3d';</script><div id="tooltip" style="z-index:200"></div><div id="toast-container"></div>2941 unmodified lines}async function setSpeed(mult) {try {const res = await fetch(`${API_BASE}/controls/speed?multiplier=${mult}`, { method: 'POST' });if (res.ok) {const data = await res.json();simSpeed = data.speed;updateControlsUI();send3dSpeed(simSpeed);return;}} catch(e) {}simSpeed = mult;updateControlsUI();send3dSpeed(mult);}function updateControlsUI() {292 unmodified lines2932942952962972982993003012 unmodified lines3043053063073083093102941 unmodified lines325232533254325532563257325832593260326132623263292 unmodified lines<button class="ctrl-btn" onclick="send3d('zoom-in')" title="Zoom In (scroll in 3D view)">+</button><button class="ctrl-btn" onclick="send3d('zoom-out')" title="Zoom Out (scroll in 3D view)">-</button><button class="ctrl-btn" onclick="send3d('reset-camera')" title="Reset 3D camera">Fit</button><span style="color:#1a3a6e;margin:0 4px">│</span><button class="ctrl-btn" id="btn-fp-main" onclick="send3d('toggle-fp')" title="First-person view">👁 FP</button><button class="ctrl-btn" id="btn-join-main" onclick="send3d('show-join')" title="Join as player">JOIN</button></span><span id="api-calls">API: 0</span><span id="cost">$0.00</span>2 unmodified lines</div><div id="main"><div id="viewport-3d"><iframe id="city3d" allow="autoplay; pointer-lock; xr-spatial-tracking; fullscreen"></iframe><script>document.getElementById('city3d').src = location.protocol === 'file:' ? '3d.html' : '/3d';</script><div id="tooltip" style="z-index:200"></div><div id="toast-container"></div>2941 unmodified lines}async function setSpeed(mult) {simSpeed = mult;updateControlsUI();send3dSpeed(mult);try {await fetch(`${API_BASE}/controls/speed?multiplier=${mult}`, { method: 'POST' });} catch(e) {}}function updateControlsUI() {
web/3d.html+17-2
web/index.html+7-11