Spaces:
Running
Running
Download index.html from Metaprime/Holodeckv9: direct link, hf CLI and curl.
- Browser
- Download file 21.2 kB
-
https://huggingface.co/spaces/Metaprime/Holodeckv9/resolve/main/index.html
- Command line
-
hf download hf://spaces/Metaprime/Holodeckv9/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Metaprime/Holodeckv9/resolve/main/index.html
21.2 kB
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Holodeck</title> | |
| <script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script> | |
| <style> | |
| #bead { | |
| position:fixed; bottom:35px; left:30px; width:38px; height:38px; | |
| background:rgba(255,30,30,0.08); | |
| border:2px solid #ff3366; | |
| border-radius:50%; | |
| box-shadow:0 0 18px #ff3366, 0 0 35px #ff3366, inset 0 0 12px rgba(255,255,255,0.3); | |
| z-index:1000; cursor:pointer; | |
| } | |
| #panel { | |
| position:fixed; bottom:88px; left:22px; width:205px; | |
| background:rgba(20,0,10,0.12); backdrop-filter:blur(18px); | |
| border:2px solid #ff3366; box-shadow:0 0 25px #ff3366, 0 0 45px #ff3366; | |
| border-radius:16px; padding:12px; display:none; flex-direction:column; gap:8px; | |
| z-index:1002; max-height:80vh; overflow-y:auto; | |
| } | |
| button { | |
| background:rgba(255,50,50,0.08); | |
| color:#ff99aa; | |
| border:1px solid #ff3366; | |
| box-shadow:0 0 12px #ff3366; | |
| padding:11px 12px; | |
| border-radius:10px; | |
| font-size:15px; | |
| text-align: left; | |
| } | |
| #videoContainer { | |
| position:fixed; bottom:170px; left:50%; transform:translateX(-50%); | |
| width:380px; display:none; z-index:1000; background:rgba(0,0,0,0.85); | |
| border-radius:12px; padding:8px; | |
| } | |
| #myVideo { width:100%; border-radius:8px; } | |
| .close-btn { | |
| position:absolute; top:12px; right:12px; color:white; font-size:24px; | |
| background:rgba(255,60,60,0.9); width:28px; height:28px; border-radius:50%; | |
| display:flex; align-items:center; justify-content:center; z-index:1001; | |
| } | |
| #glbStatus { | |
| position:fixed; bottom:35px; left:80px; color:#ff99aa; font-size:13px; | |
| z-index:1000; background:rgba(20,0,10,0.5); padding:6px 10px; border-radius:8px; | |
| border:1px solid #ff3366; display:none; | |
| } | |
| #joystick { | |
| position:fixed; bottom:35px; right:30px; width:84px; height:84px; | |
| border-radius:50%; border:2px solid #ff3366; | |
| background:rgba(255,30,30,0.08); | |
| box-shadow:0 0 18px #ff3366, 0 0 35px #ff3366, inset 0 0 12px rgba(255,255,255,0.15); | |
| z-index:1000; touch-action:none; user-select:none; | |
| } | |
| #joystickNub { | |
| position:absolute; top:50%; left:50%; width:36px; height:36px; | |
| margin:-18px 0 0 -18px; border-radius:50%; | |
| background:rgba(255,60,90,0.35); border:2px solid #ff99aa; | |
| box-shadow:0 0 12px #ff3366; | |
| pointer-events:none; | |
| } | |
| #joystickLabel { | |
| position:fixed; bottom:122px; right:38px; color:#ff99aa; font-size:11px; | |
| z-index:1000; letter-spacing:1px; opacity:0.8; pointer-events:none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <a-scene background="color: #000000" xr-mode-ui="enabled: false"> | |
| <a-sky id="sky" src="galaxy.jpg" material="side: back" hide-on-enter-ar></a-sky> | |
| <a-light type="ambient" color="#666"></a-light> | |
| <a-light type="directional" intensity="0.6" position="5 10 5"></a-light> | |
| <!-- GLB model mount point --> | |
| <a-entity id="glbRoot" position="0 1.4 -3"></a-entity> | |
| <!-- Camera rig: joystick moves this, look-controls/wasd still work on the camera inside it --> | |
| <a-entity id="cameraRig" position="0 0 0"> | |
| <a-camera id="mainCamera" position="0 1.6 0" look-controls wasd-controls></a-camera> | |
| </a-entity> | |
| </a-scene> | |
| <div id="joystickLabel">FWD / BACK</div> | |
| <div id="joystick"> | |
| <div id="joystickNub"></div> | |
| </div> | |
| <div id="bead" onclick="togglePanel()"></div> | |
| <div id="glbStatus"></div> | |
| <div id="panel"> | |
| <button onclick="launchSky()">🌌 Sky Launcher</button> | |
| <button onclick="Leftvideopanel()">⬅️ Add Left Screen</button> | |
| <button onclick="Rightvideopanel()">➡️ Add Right Screen</button> | |
| <button onclick="playSky()">▶️ Play Sky</button> | |
| <button onclick="pauseSky()">⏸️ Pause Sky</button> | |
| <button onclick="Mutesky()">🔇 Sky Mute</button> | |
| <button onclick="Mediaplayer()">📺 Browser Player</button> | |
| <button onclick="AIChat()">💬 AI Chat</button> | |
| <button onclick="setTunnelURL()">🔗 Set Tunnel URL</button> | |
| <button onclick="loadGLB('environment')">🏛️ Load Environment</button> | |
| <button onclick="loadGLB('character')">🧍 Load Character</button> | |
| <button onclick="loadGLB('object')">📦 Load Object</button> | |
| <button onclick="toggleGLBSpin()">🔄 Toggle Model Spin</button> | |
| <button onclick="scaleGLB(1.25)">➕ Scale Up</button> | |
| <button onclick="scaleGLB(0.8)">➖ Scale Down</button> | |
| <button onclick="moveGLB(-2)">⬆️ Move Further</button> | |
| <button onclick="moveGLB(2)">⬇️ Move Closer</button> | |
| <button onclick="clearGLB()">🗑️ Clear Model</button> | |
| <button onclick="enterVRMode()">🥽 Enter VR Mode</button> | |
| <button onclick="enterARMode()">📱 Enter AR Mode</button> | |
| </div> | |
| <div id="videoContainer"> | |
| <div class="close-btn" onclick="closeVideo()">×</div> | |
| <video id="myVideo" controls loop></video> | |
| </div> | |
| <input type="file" id="skyInput" accept="image/*,video/*" style="display:none;"> | |
| <input type="file" id="screenInput" accept="video/*" style="display:none;"> | |
| <input type="file" id="glbInput" accept=".glb,.gltf,model/gltf-binary" style="display:none;"> | |
| <script> | |
| let videos = []; | |
| let skyVideo = null; | |
| let screenVideo = null; | |
| let container = null; | |
| let currentGlbUrl = null; | |
| let glbSpinning = false; | |
| function togglePanel() { | |
| const panel = document.getElementById('panel'); | |
| panel.style.display = (panel.style.display === 'flex') ? 'none' : 'flex'; | |
| } | |
| function enterVRMode() { | |
| const scene = document.querySelector('a-scene'); | |
| if (scene) scene.enterVR(); | |
| } | |
| function enterARMode() { | |
| const scene = document.querySelector('a-scene'); | |
| const sky = document.getElementById('sky'); | |
| if (!scene) return; | |
| scene.enterAR().then(() => { | |
| console.log("✅ Entered AR Mode"); | |
| if (sky) sky.setAttribute('visible', false); | |
| }).catch(err => { | |
| console.error("AR failed to start:", err); | |
| alert("Could not start AR mode. Make sure you're on a supported device."); | |
| }); | |
| } | |
| function launchSky() { | |
| document.getElementById('skyInput').click(); | |
| } | |
| function Leftvideopanel() { | |
| document.getElementById('screenInput').click(); | |
| document.getElementById('screenInput').onchange = (e) => handleNewVideo(e, 'left'); | |
| } | |
| function Rightvideopanel() { | |
| document.getElementById('screenInput').click(); | |
| document.getElementById('screenInput').onchange = (e) => handleNewVideo(e, 'right'); | |
| } | |
| function Mediaplayer() { | |
| document.getElementById('screenInput').click(); | |
| document.getElementById('screenInput').onchange = (e) => handleBrowserVideo(e); | |
| } | |
| function handleNewVideo(e, side) { | |
| const file = e.target.files[0]; | |
| if (!file || !file.type.startsWith('video/')) return; | |
| const url = URL.createObjectURL(file); | |
| const scene = document.querySelector('a-scene'); | |
| const xPos = side === 'left' ? -5.2 : 5.2; | |
| const plane = document.createElement('a-plane'); | |
| plane.setAttribute('width', '10'); | |
| plane.setAttribute('height', '6'); | |
| plane.setAttribute('position', `${xPos} 4 -10`); | |
| plane.setAttribute('material', 'shader:flat; side:double; color:#fff'); | |
| scene.appendChild(plane); | |
| const video = document.createElement('video'); | |
| video.src = url; | |
| video.loop = true; | |
| video.volume = 0.7; | |
| video.muted = false; | |
| const texture = new THREE.VideoTexture(video); | |
| video.onloadeddata = function() { | |
| const mesh = plane.object3DMap.mesh; | |
| if (mesh && mesh.material) { | |
| mesh.material.map = texture; | |
| mesh.material.needsUpdate = true; | |
| } | |
| video.play(); | |
| }; | |
| video.load(); | |
| const videoData = { video: video, name: file.name, side: side }; | |
| videos.push(videoData); | |
| createControlButtons(videoData); | |
| } | |
| function handleBrowserVideo(e) { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| const url = URL.createObjectURL(file); | |
| screenVideo.src = url; | |
| container.style.display = 'block'; | |
| screenVideo.play(); | |
| } | |
| function createControlButtons(videoData) { | |
| const panel = document.getElementById('panel'); | |
| const label = document.createElement('div'); | |
| label.style.color = '#ff99aa'; | |
| label.style.fontSize = '14px'; | |
| label.style.padding = '4px 0 2px 0'; | |
| label.textContent = `${videoData.side.toUpperCase()} SCREEN`; | |
| panel.appendChild(label); | |
| const controls = document.createElement('div'); | |
| controls.style.display = 'flex'; | |
| controls.style.gap = '6px'; | |
| const playBtn = document.createElement('button'); | |
| playBtn.textContent = '▶️ / ⏸️'; | |
| playBtn.onclick = () => { | |
| if (videoData.video.paused) videoData.video.play(); | |
| else videoData.video.pause(); | |
| }; | |
| controls.appendChild(playBtn); | |
| const muteBtn = document.createElement('button'); | |
| muteBtn.textContent = '🔊 / 🔇'; | |
| muteBtn.onclick = () => { | |
| videoData.video.muted = !videoData.video.muted; | |
| }; | |
| controls.appendChild(muteBtn); | |
| panel.appendChild(controls); | |
| } | |
| function playSky() { | |
| if (skyVideo) skyVideo.play(); | |
| } | |
| function pauseSky() { | |
| if (skyVideo) skyVideo.pause(); | |
| } | |
| function Mutesky() { | |
| if (skyVideo) skyVideo.muted = !skyVideo.muted; | |
| } | |
| function closeVideo() { | |
| if (screenVideo) screenVideo.pause(); | |
| if (container) container.style.display = 'none'; | |
| } | |
| // Cloudflare Tunnel API Routing | |
| function AIChat() { | |
| let tunnelURL = localStorage.getItem('cf_tunnel_url'); | |
| if (!tunnelURL) { | |
| tunnelURL = prompt("Enter your active Cloudflare Tunnel URL (e.g., https://your-tunnel-name.trycloudflare.com):"); | |
| if (tunnelURL) { | |
| tunnelURL = tunnelURL.trim().replace(/\/$/, ""); // Format URL | |
| localStorage.setItem('cf_tunnel_url', tunnelURL); | |
| } else { | |
| return; | |
| } | |
| } | |
| window.location.href = tunnelURL; | |
| } | |
| function setTunnelURL() { | |
| const currentURL = localStorage.getItem('cf_tunnel_url') || ""; | |
| const newURL = prompt("Update Cloudflare Tunnel URL:", currentURL); | |
| if (newURL !== null) { | |
| const formattedURL = newURL.trim().replace(/\/$/, ""); | |
| if (formattedURL) { | |
| localStorage.setItem('cf_tunnel_url', formattedURL); | |
| alert("Tunnel URL saved: " + formattedURL); | |
| } else { | |
| localStorage.removeItem('cf_tunnel_url'); | |
| alert("Tunnel URL cleared."); | |
| } | |
| } | |
| } | |
| // ---------- GLB Viewer ---------- | |
| function glbStatus(msg, show) { | |
| const el = document.getElementById('glbStatus'); | |
| el.textContent = msg; | |
| el.style.display = show ? 'block' : 'none'; | |
| } | |
| function loadGLB(category) { | |
| glbCategory = category || 'object'; | |
| document.getElementById('glbInput').click(); | |
| } | |
| // Base viewing anchor: where the model is centered before manual nudges. | |
| let glbBasePos = { x: 0, y: 0, z: -6 }; | |
| let glbCurrentScale = 1; | |
| let glbZOffset = 0; | |
| let glbCategory = 'object'; | |
| // Different GLB categories need very different defaults: | |
| // - environments are big scenes that should sit on the ground, far back | |
| // - characters are human-scale, standing on the ground, closer up | |
| // - objects are small props, viewed near eye height like on a table | |
| const GLB_CATEGORY_CONFIG = { | |
| environment: { targetSize: 14, baseZ: -10, ground: true }, | |
| character: { targetSize: 1.8, baseZ: -3, ground: true }, | |
| object: { targetSize: 1.2, baseZ: -2, ground: false, eyeHeight: 1.4 } | |
| }; | |
| const GLB_CATEGORY_LABEL = { | |
| environment: 'Environment', | |
| character: 'Character', | |
| object: 'Object' | |
| }; | |
| function clearGLB() { | |
| const root = document.getElementById('glbRoot'); | |
| root.removeAttribute('gltf-model'); | |
| root.setAttribute('scale', '1 1 1'); | |
| root.setAttribute('rotation', '0 0 0'); | |
| root.setAttribute('position', '0 1.4 -3'); | |
| if (currentGlbUrl) { | |
| URL.revokeObjectURL(currentGlbUrl); | |
| currentGlbUrl = null; | |
| } | |
| glbSpinning = false; | |
| glbCurrentScale = 1; | |
| glbZOffset = 0; | |
| root.removeAttribute('animation__spin'); | |
| glbStatus('', false); | |
| } | |
| function toggleGLBSpin() { | |
| const root = document.getElementById('glbRoot'); | |
| glbSpinning = !glbSpinning; | |
| if (glbSpinning) { | |
| root.setAttribute('animation__spin', 'property: rotation; to: 0 360 0; loop: true; dur: 8000; easing: linear'); | |
| } else { | |
| root.removeAttribute('animation__spin'); | |
| } | |
| } | |
| function applyGLBTransform() { | |
| const root = document.getElementById('glbRoot'); | |
| const s = glbCurrentScale; | |
| root.setAttribute('scale', `${s} ${s} ${s}`); | |
| root.setAttribute('position', | |
| `${glbBasePos.x} ${glbBasePos.y} ${glbBasePos.z + glbZOffset}`); | |
| } | |
| function scaleGLB(factor) { | |
| if (!currentGlbUrl) return; | |
| glbCurrentScale *= factor; | |
| applyGLBTransform(); | |
| } | |
| function moveGLB(delta) { | |
| if (!currentGlbUrl) return; | |
| glbZOffset += delta; // negative = further away, positive = closer | |
| applyGLBTransform(); | |
| } | |
| document.getElementById('glbInput').addEventListener('change', function(e) { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| const name = file.name.toLowerCase(); | |
| if (!name.endsWith('.glb') && !name.endsWith('.gltf')) { | |
| alert('Please choose a .glb or .gltf file.'); | |
| return; | |
| } | |
| const cfg = GLB_CATEGORY_CONFIG[glbCategory] || GLB_CATEGORY_CONFIG.object; | |
| const categoryLabel = GLB_CATEGORY_LABEL[glbCategory] || 'Object'; | |
| glbStatus('Loading ' + categoryLabel + ': ' + file.name + '...', true); | |
| // clear any previous model/url first | |
| if (currentGlbUrl) { | |
| URL.revokeObjectURL(currentGlbUrl); | |
| } | |
| const url = URL.createObjectURL(file); | |
| currentGlbUrl = url; | |
| const root = document.getElementById('glbRoot'); | |
| root.removeAttribute('gltf-model'); | |
| // Load at identity transform so the bounding box we measure is pure | |
| // local geometry, uncontaminated by any previous position/scale. | |
| root.setAttribute('position', '0 0 0'); | |
| root.setAttribute('rotation', '0 0 0'); | |
| root.setAttribute('scale', '1 1 1'); | |
| glbCurrentScale = 1; | |
| glbZOffset = 0; | |
| const onLoaded = () => { | |
| const mesh = root.getObject3D('mesh'); | |
| if (mesh) { | |
| root.object3D.updateMatrixWorld(true); | |
| const box = new THREE.Box3().setFromObject(mesh); | |
| if (box.isEmpty() || !isFinite(box.min.x) || !isFinite(box.max.x)) { | |
| // Couldn't get a sane bounding box (rare, but happens with some | |
| // exports) - just show it at the category's default distance. | |
| glbBasePos = { x: 0, y: cfg.ground ? 0 : cfg.eyeHeight, z: cfg.baseZ }; | |
| glbCurrentScale = 1; | |
| applyGLBTransform(); | |
| glbStatus('Loaded (auto-fit skipped) - ' + categoryLabel + ': ' + file.name, true); | |
| root.removeEventListener('model-loaded', onLoaded); | |
| return; | |
| } | |
| const size = new THREE.Vector3(); | |
| box.getSize(size); | |
| const center = new THREE.Vector3(); | |
| box.getCenter(center); | |
| const maxDim = Math.max(size.x, size.y, size.z) || 1; | |
| const scale = cfg.targetSize / maxDim; | |
| // Set root's own position/scale directly (do NOT also move the | |
| // mesh child - that would double-apply the scale factor). | |
| glbCurrentScale = scale; | |
| glbBasePos = { | |
| x: -center.x * scale, | |
| // Grounded categories (environment/character): rest the model's | |
| // lowest point at y=0 instead of centering it, so it sits on | |
| // the floor rather than floating chest-high. | |
| y: cfg.ground ? -box.min.y * scale : (cfg.eyeHeight - center.y * scale), | |
| z: cfg.baseZ - (center.z * scale) | |
| }; | |
| glbZOffset = 0; | |
| applyGLBTransform(); | |
| } | |
| glbStatus('Loaded - ' + categoryLabel + ': ' + file.name, true); | |
| root.removeEventListener('model-loaded', onLoaded); | |
| }; | |
| const onError = () => { | |
| glbStatus('Failed to load ' + file.name, true); | |
| root.removeEventListener('model-error', onError); | |
| }; | |
| root.addEventListener('model-loaded', onLoaded); | |
| root.addEventListener('model-error', onError); | |
| root.setAttribute('gltf-model', url); | |
| if (glbSpinning) { | |
| root.setAttribute('animation__spin', 'property: rotation; to: 0 360 0; loop: true; dur: 8000; easing: linear'); | |
| } | |
| }); | |
| // ---------- Joystick: forward/backward navigation ---------- | |
| let joyValue = 0; // -1 (full back) .. 1 (full forward) | |
| let joyDragging = false; | |
| let joyPointerId = null; | |
| const JOY_MAX_PX = 32; // how far the nub can travel from center | |
| const JOY_MAX_SPEED = 3; // meters per second at full deflection | |
| function setupJoystick() { | |
| const stick = document.getElementById('joystick'); | |
| const nub = document.getElementById('joystickNub'); | |
| let startY = 0; | |
| function onDown(e) { | |
| joyDragging = true; | |
| joyPointerId = e.pointerId; | |
| startY = e.clientY; | |
| stick.setPointerCapture(e.pointerId); | |
| } | |
| function onMove(e) { | |
| if (!joyDragging || e.pointerId !== joyPointerId) return; | |
| let dy = e.clientY - startY; | |
| dy = Math.max(-JOY_MAX_PX, Math.min(JOY_MAX_PX, dy)); | |
| nub.style.transform = `translateY(${dy}px)`; | |
| // dragging up (negative dy) = forward (positive joyValue) | |
| joyValue = -dy / JOY_MAX_PX; | |
| } | |
| function onUp(e) { | |
| if (e.pointerId !== joyPointerId) return; | |
| joyDragging = false; | |
| joyPointerId = null; | |
| joyValue = 0; | |
| nub.style.transform = 'translateY(0px)'; | |
| } | |
| stick.addEventListener('pointerdown', onDown); | |
| stick.addEventListener('pointermove', onMove); | |
| stick.addEventListener('pointerup', onUp); | |
| stick.addEventListener('pointercancel', onUp); | |
| stick.addEventListener('pointerleave', (e) => { | |
| // only release if the pointer isn't captured (avoids killing drag on | |
| // fast finger movement near the edge of the small joystick hitbox) | |
| if (!joyDragging) onUp(e); | |
| }); | |
| } | |
| let lastFrameTime = null; | |
| function joystickTick(now) { | |
| if (lastFrameTime === null) lastFrameTime = now; | |
| const dt = (now - lastFrameTime) / 1000; | |
| lastFrameTime = now; | |
| if (joyValue !== 0) { | |
| const camera = document.getElementById('mainCamera'); | |
| const rig = document.getElementById('cameraRig'); | |
| if (camera && camera.object3D && rig && rig.object3D) { | |
| const dir = new THREE.Vector3(); | |
| camera.object3D.getWorldDirection(dir); | |
| dir.y = 0; // stay level with the ground rather than flying up/down when looking up/down | |
| if (dir.lengthSq() > 0.0001) { | |
| dir.normalize(); | |
| const step = joyValue * JOY_MAX_SPEED * dt; | |
| rig.object3D.position.addScaledVector(dir, step); | |
| } | |
| } | |
| } | |
| requestAnimationFrame(joystickTick); | |
| } | |
| // Sky Launcher Logic | |
| document.getElementById('skyInput').addEventListener('change', function(e) { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| const url = URL.createObjectURL(file); | |
| const isVideo = file.type.startsWith('video/'); | |
| if (isVideo) { | |
| if (skyVideo) skyVideo.pause(); | |
| skyVideo = document.createElement('video'); | |
| skyVideo.src = url; | |
| skyVideo.loop = true; | |
| skyVideo.muted = false; | |
| skyVideo.volume = 0.6; | |
| skyVideo.onloadeddata = () => { | |
| const mesh = document.getElementById('sky').getObject3D('mesh'); | |
| if (mesh && mesh.material) { | |
| const texture = new THREE.VideoTexture(skyVideo); | |
| texture.mapping = THREE.EquirectangularReflectionMapping; | |
| mesh.material.map = texture; | |
| mesh.material.needsUpdate = true; | |
| skyVideo.play(); | |
| } | |
| }; | |
| skyVideo.load(); | |
| } else { | |
| const loader = new THREE.TextureLoader(); | |
| loader.load(url, function(texture) { | |
| const mesh = document.getElementById('sky').getObject3D('mesh'); | |
| if (mesh && mesh.material) { | |
| texture.mapping = THREE.EquirectangularReflectionMapping; | |
| mesh.material.map = texture; | |
| mesh.material.needsUpdate = true; | |
| } | |
| }); | |
| } | |
| }); | |
| // Initialize | |
| window.onload = function() { | |
| screenVideo = document.getElementById('myVideo'); | |
| container = document.getElementById('videoContainer'); | |
| setupJoystick(); | |
| requestAnimationFrame(joystickTick); | |
| }; | |
| </script> | |
| </body> | |
| </html> | |