Spaces:
Running
Running
File size: 11,955 Bytes
54a51e6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Robot Ego Reconstruction</title>
<style>
:root{--bg:#111110;--panel:rgba(24,24,22,.86);--ink:#ecebe6;--muted:#9a988f;--line:#3a3935;--accent:#7d9cf0;--left:#5aa9ff;--right:#ff9f43}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);font:13px/1.45 -apple-system,"Helvetica Neue",sans-serif;overflow:hidden}
#view{position:fixed;inset:0}
.panel{position:fixed;background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:10px 12px;backdrop-filter:blur(6px)}
#info{top:12px;left:12px;max-width:360px}
#info h1{font-size:15px;margin:0 0 4px}
#info .stat{color:var(--muted)}
#info .badges{display:flex;flex-wrap:wrap;gap:4px;margin:6px 0}
#info .badges span{background:#2a2a27;border-radius:5px;padding:1px 6px;font-size:11.5px}
#layers{margin-top:6px;display:flex;gap:6px;flex-wrap:wrap}
button{background:#2a2a27;color:var(--ink);border:1px solid var(--line);border-radius:6px;padding:4px 9px;font:inherit;cursor:pointer}
button.on{border-color:var(--accent);color:var(--accent)}
#pip{top:12px;right:12px;width:min(36vw,420px);padding:6px}
#pip video{width:100%;display:block;border-radius:6px;background:#000}
#pip .cap{color:var(--muted);font-size:11.5px;margin-top:3px}
#bar{left:12px;right:12px;bottom:12px;display:grid;grid-template-columns:auto 1fr auto;gap:10px;align-items:center}
#bar input[type=range]{width:100%}
#chart{grid-column:1 / -1;width:100%;height:56px;display:block}
#time{font-variant-numeric:tabular-nums;color:var(--muted);min-width:110px;text-align:right}
.legend{display:flex;gap:12px;color:var(--muted);font-size:11.5px;margin-top:4px}
.legend i{display:inline-block;width:10px;height:3px;vertical-align:middle;margin-right:4px}
#msg{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);color:var(--muted)}
@media (max-width:720px){#pip{width:46vw}#info{max-width:50vw;font-size:12px}}
</style>
<script src="../ss.js"></script><script>addEventListener("DOMContentLoaded",()=>SS.hydrate())</script>
<script type="importmap">
{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
"three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}
</script>
</head>
<body>
<div id="view"></div>
<div id="msg">Loading point cloud…</div>
<div class="panel" id="info">
<h1>Robot egocentric · shelf restocking → 3D scene + action</h1>
<div class="stat" id="stats"></div>
<div class="badges"><span>metric depth</span><span>full calibration</span><span>loop-closure de-drift</span><span>moving arm removed</span><span>1920px stereo colour</span></div>
<div>Scene points</div>
<div id="layers">
<button data-layer="rgb" class="on">RGB</button>
<button data-layer="lidar">LiDAR height</button>
<button data-layer="none">Hide</button>
</div>
<div style="margin-top:8px">View</div>
<div id="views" style="display:flex;gap:6px;margin-top:4px;flex-wrap:wrap">
<button data-view="orbit">Overview</button>
<button data-view="top">Top</button>
<button data-view="follow">Follow robot</button>
</div>
<div class="legend"><span><i style="background:var(--left)"></i>Left end-effector</span><span><i style="background:var(--right)"></i>Right end-effector</span><span><i style="background:#9be29b"></i>Base</span></div>
</div>
<div class="panel" id="pip">
<video id="vid" data-ss-src="b2/data/head_stereo_left.mp4" muted playsinline preload="auto"></video>
<div class="cap">Head stereo-left camera (faces blurred), synced with the 3D timeline</div>
</div>
<div class="panel" id="bar">
<button id="play">▶ Play</button>
<input id="slider" type="range" min="0" max="2411" value="0" step="1">
<span id="time">0.0 s</span>
<canvas id="chart"></canvas>
</div>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';
const V = '?v=1';
const view = document.getElementById('view');
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
view.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x111110);
const camera = new THREE.PerspectiveCamera(55, innerWidth / innerHeight, 0.02, 200);
camera.up.set(0, 0, 1);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
scene.add(new THREE.GridHelper(12, 24, 0x333331, 0x222220).rotateX(Math.PI / 2));
const [action, stats] = await Promise.all([
fetch('data/action.json' + V).then(r => r.json()),
fetch('data/recon_stats.json' + V).then(r => r.json())
]);
const F = action.frames, N = F.length, FPS = action.fps;
document.getElementById('stats').innerHTML =
`${stats.duration_s}s · ${N} frames @${FPS}Hz · scene ${(stats.scene_points / 1e6).toFixed(2)}M points<br>` +
`base path ${stats.base_path_m}m · right EE path ${stats.right_ee_path_m}m · drift residual ${stats.residual_before_cm}→${stats.residual_after_cm}cm`;
// point clouds
const loader = new PLYLoader();
function brighten(geo, k) {
const c = geo.getAttribute('color');
if (!c) return;
for (let i = 0; i < c.array.length; i++) c.array[i] = Math.min(1, c.array[i] * k);
c.needsUpdate = true;
}
const clouds = {};
function loadCloud(name, file, size, k) {
return new Promise((res, rej) => loader.load(file + V, geo => {
brighten(geo, k);
const pts = new THREE.Points(geo, new THREE.PointsMaterial({ size, vertexColors: true, sizeAttenuation: true }));
clouds[name] = pts; scene.add(pts); res(pts);
}, undefined, rej));
}
await loadCloud('rgb', 'data/scene_rgb.ply', 0.012, 1.7).catch(e => { document.getElementById('msg').textContent = 'Failed to load point cloud (serve this folder over http, see README): ' + e; });
document.getElementById('msg').remove();
loadCloud('lidar', 'data/scene.ply', 0.02, 1.0).then(p => { p.visible = false; });
// trajectories
function line(key, color) {
const pos = new Float32Array(N * 3);
F.forEach((f, i) => pos.set(f[key], i * 3));
const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.BufferAttribute(pos, 3));
g.setDrawRange(0, 1);
const l = new THREE.Line(g, new THREE.LineBasicMaterial({ color, transparent: true, opacity: 0.9 }));
scene.add(l); return l;
}
const baseZ = 0.02;
const basePos = F.map(f => [f.base[0], f.base[1], baseZ]);
const lineL = line('ee_l', 0x5aa9ff), lineR = line('ee_r', 0xff9f43);
const baseGeo = new THREE.BufferGeometry();
baseGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(basePos.flat()), 3));
const lineB = new THREE.Line(baseGeo, new THREE.LineBasicMaterial({ color: 0x9be29b })); scene.add(lineB);
// gripper markers: two jaws whose gap follows the gripper opening
function gripper(color) {
const g = new THREE.Group();
const m = new THREE.MeshBasicMaterial({ color });
const palm = new THREE.Mesh(new THREE.BoxGeometry(0.05, 0.02, 0.02), m);
const j1 = new THREE.Mesh(new THREE.BoxGeometry(0.012, 0.012, 0.06), m);
const j2 = j1.clone();
g.add(palm, j1, j2); g.userData = { j1, j2 }; scene.add(g); return g;
}
const gL = gripper(0x5aa9ff), gR = gripper(0xff9f43);
const robot = new THREE.Group();
const body = new THREE.Mesh(new THREE.BoxGeometry(0.55, 0.45, 0.04), new THREE.MeshBasicMaterial({ color: 0x9be29b, wireframe: true }));
body.position.z = 0.03;
const nose = new THREE.Mesh(new THREE.ConeGeometry(0.06, 0.16, 12), new THREE.MeshBasicMaterial({ color: 0x9be29b }));
nose.rotation.z = -Math.PI / 2; nose.position.set(0.34, 0, 0.03);
robot.add(body, nose); scene.add(robot);
const q = new THREE.Quaternion();
function setFrame(i) {
const f = F[i];
for (const [g, p, qq, open] of [[gL, f.ee_l, f.q_l, f.grip_l], [gR, f.ee_r, f.q_r, f.grip_r]]) {
g.position.set(...p);
q.set(qq[0], qq[1], qq[2], qq[3]); g.quaternion.copy(q);
const gap = 0.012 + 0.04 * open;
g.userData.j1.position.set(-gap, 0, 0.03); g.userData.j2.position.set(gap, 0, 0.03);
}
robot.position.set(f.base[0], f.base[1], 0); robot.rotation.z = f.base[2];
lineL.geometry.setDrawRange(0, i + 1); lineR.geometry.setDrawRange(0, i + 1);
baseGeo.setDrawRange(0, i + 1);
slider.value = i;
timeEl.textContent = `${f.t.toFixed(1)} s · #${i}`;
drawChart(i);
if (mode === 'follow') follow(f);
}
// gripper chart
const chart = document.getElementById('chart'), ctx = chart.getContext('2d');
function drawChart(i) {
const w = chart.width = chart.clientWidth * devicePixelRatio, h = chart.height = chart.clientHeight * devicePixelRatio;
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = '#9a988f'; ctx.font = `${10 * devicePixelRatio}px sans-serif`;
ctx.fillText('Gripper opening (up = open)', 4, 11 * devicePixelRatio);
for (const [key, col] of [['grip_l', '#5aa9ff'], ['grip_r', '#ff9f43']]) {
ctx.strokeStyle = col; ctx.lineWidth = 1.5 * devicePixelRatio; ctx.beginPath();
F.forEach((f, k) => { const x = k / (N - 1) * w, y = h - 3 - f[key] * (h - 16); k ? ctx.lineTo(x, y) : ctx.moveTo(x, y); });
ctx.stroke();
}
ctx.strokeStyle = '#ecebe6'; ctx.lineWidth = 1 * devicePixelRatio;
const x = i / (N - 1) * w; ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, h); ctx.stroke();
}
chart.addEventListener('click', e => seek(Math.round(e.offsetX / chart.clientWidth * (N - 1))));
// timeline + video sync (video is the clock while playing)
const slider = document.getElementById('slider'), timeEl = document.getElementById('time');
const vid = document.getElementById('vid'), playBtn = document.getElementById('play');
let frame = 0, playing = false;
function seek(i) { frame = Math.max(0, Math.min(N - 1, i)); vid.currentTime = (frame + 0.5) / FPS; setFrame(frame); }
slider.addEventListener('input', () => seek(+slider.value));
playBtn.onclick = () => {
playing = !playing;
playBtn.textContent = playing ? '❚❚ Pause' : '▶ Play';
if (playing) { if (frame >= N - 1) seek(0); vid.play().catch(() => {}); } else vid.pause();
};
vid.addEventListener('ended', () => { playing = false; playBtn.textContent = '▶ Play'; });
// cameras
let mode = 'orbit';
function setView(m) {
mode = m;
document.querySelectorAll('#views button').forEach(b => b.classList.toggle('on', b.dataset.view === m));
const c = new THREE.Vector3(0.6, 0.2, 0.8);
if (m === 'orbit') { camera.position.set(-2.6, -3.4, 3.0); controls.target.copy(c); }
if (m === 'top') { camera.position.set(0.6, 0.15, 7.5); controls.target.set(0.6, 0.2, 0); }
if (m === 'follow') follow(F[frame], true);
}
function follow(f, jump) {
const [x, y, yaw] = f.base;
const target = new THREE.Vector3(x + Math.cos(yaw) * 0.9, y + Math.sin(yaw) * 0.9, 0.85);
const eye = new THREE.Vector3(x - Math.cos(yaw) * 1.6, y - Math.sin(yaw) * 1.6, 1.9);
if (jump) { camera.position.copy(eye); controls.target.copy(target); return; }
camera.position.lerp(eye, 0.08); controls.target.lerp(target, 0.08);
}
document.querySelectorAll('#views button').forEach(b => b.onclick = () => setView(b.dataset.view));
document.querySelectorAll('#layers button').forEach(b => b.onclick = () => {
document.querySelectorAll('#layers button').forEach(x => x.classList.toggle('on', x === b));
for (const [k, p] of Object.entries(clouds)) p.visible = (k === b.dataset.layer);
});
setView('orbit'); setFrame(0);
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight); drawChart(frame);
});
renderer.setAnimationLoop(() => {
if (playing) {
const i = Math.min(N - 1, Math.floor(vid.currentTime * FPS));
if (i !== frame) { frame = i; setFrame(i); }
}
controls.update();
renderer.render(scene, camera);
});
</script>
</body>
</html>
|