Spaces:
Running
Running
sceneSample: add B3 office patrol viewer, nav and count
Browse files- index.html +1 -1
- sceneSample/b3/viewer.html +266 -0
- sceneSample/index.html +1 -1
index.html
CHANGED
|
@@ -32,7 +32,7 @@ header{padding:26px 28px 6px}h1{margin:0 0 5px;font-size:23px}.sub{color:#9aa1ad
|
|
| 32 |
<a class="card" href="sceneSample/index.html">
|
| 33 |
<img src="sceneSample/cover.jpg" alt="Scene Sample">
|
| 34 |
<div class="m"><div class="t">Scene Sample</div>
|
| 35 |
-
<div class="r">Video paired with 3D scenes and the code that reproduces them ·
|
| 36 |
<span class="tag">3D · code ↔ video · access by approval</span></div>
|
| 37 |
</a>
|
| 38 |
<a class="card" href="motionSample/index.html">
|
|
|
|
| 32 |
<a class="card" href="sceneSample/index.html">
|
| 33 |
<img src="sceneSample/cover.jpg" alt="Scene Sample">
|
| 34 |
<div class="m"><div class="t">Scene Sample</div>
|
| 35 |
+
<div class="r">Video paired with 3D scenes and the code that reproduces them · 5 samples.<br>Native 3D (simulation, procedural Blender) and real-world video with reconstructed scenes and motion.</div>
|
| 36 |
<span class="tag">3D · code ↔ video · access by approval</span></div>
|
| 37 |
</a>
|
| 38 |
<a class="card" href="motionSample/index.html">
|
sceneSample/b3/viewer.html
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>Robot Ego Patrol Map</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root{--bg:#0b0e12;--panel:rgba(20,24,30,.86);--ink:#e3e7ec;--muted:#929ba7;--line:#2c333d;--accent:#7d9cf0;--auto:#4fd1c5;--idle:#8a95a5;--stall:#f2a541;--goal:#ff6b8a}
|
| 9 |
+
*{box-sizing:border-box}
|
| 10 |
+
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);font:13px/1.45 -apple-system,"Helvetica Neue",sans-serif;overflow:hidden}
|
| 11 |
+
#view{position:fixed;inset:0}
|
| 12 |
+
#view canvas{display:block;width:100%;height:100%;touch-action:none}
|
| 13 |
+
.panel{position:fixed;background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:10px 12px;backdrop-filter:blur(6px)}
|
| 14 |
+
#info{top:12px;left:12px;max-width:360px}
|
| 15 |
+
#info h1{font-size:15px;margin:0 0 4px}
|
| 16 |
+
#info .stat{color:var(--muted)}
|
| 17 |
+
#info .badges{display:flex;flex-wrap:wrap;gap:4px;margin:6px 0}
|
| 18 |
+
#info .badges span{background:#222831;border-radius:5px;padding:1px 6px;font-size:11.5px}
|
| 19 |
+
.row{display:flex;gap:6px;flex-wrap:wrap;margin-top:4px;align-items:center}
|
| 20 |
+
.lbl{margin-top:8px}
|
| 21 |
+
button{background:#222831;color:var(--ink);border:1px solid var(--line);border-radius:6px;padding:4px 9px;font:inherit;cursor:pointer}
|
| 22 |
+
button.on{border-color:var(--accent);color:var(--accent)}
|
| 23 |
+
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
|
| 24 |
+
input[type=range]{accent-color:var(--accent)}
|
| 25 |
+
#clip{width:120px}
|
| 26 |
+
#state{margin-top:8px;display:grid;grid-template-columns:auto 1fr;gap:1px 10px;font-size:12px}
|
| 27 |
+
#state dt{color:var(--muted)}#state dd{margin:0;text-align:right;font-variant-numeric:tabular-nums}
|
| 28 |
+
.pill{display:inline-block;padding:0 7px;border-radius:9px;font-size:11.5px}
|
| 29 |
+
.pill.auto{background:rgba(79,209,197,.18);color:var(--auto)}.pill.idle{background:rgba(138,149,165,.22)}.pill.stall{background:rgba(242,165,65,.2);color:var(--stall)}
|
| 30 |
+
#pip{top:12px;right:12px;width:min(36vw,420px);padding:6px}
|
| 31 |
+
#pip video{width:100%;display:block;border-radius:6px;background:#000;aspect-ratio:16/9}
|
| 32 |
+
#pip .cap{color:var(--muted);font-size:11.5px;margin-top:3px}
|
| 33 |
+
#bar{left:12px;right:12px;bottom:12px;display:grid;grid-template-columns:auto auto 1fr auto;gap:10px;align-items:center}
|
| 34 |
+
#bar input[type=range]{width:100%}
|
| 35 |
+
#chart{grid-column:1 / -1;width:100%;height:56px;display:block}
|
| 36 |
+
#time{font-variant-numeric:tabular-nums;color:var(--muted);min-width:110px;text-align:right}
|
| 37 |
+
.legend{display:flex;flex-wrap:wrap;gap:4px 12px;color:var(--muted);font-size:11.5px;margin-top:6px}
|
| 38 |
+
.legend i{display:inline-block;width:10px;height:3px;vertical-align:middle;margin-right:4px}
|
| 39 |
+
#msg{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);color:var(--muted)}
|
| 40 |
+
@media (max-width:720px){#pip{width:46vw}#info{max-width:50vw;font-size:12px}#state{display:none}}
|
| 41 |
+
</style>
|
| 42 |
+
<script src="../ss.js"></script><script>addEventListener("DOMContentLoaded",()=>SS.hydrate())</script>
|
| 43 |
+
<script type="importmap">
|
| 44 |
+
{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
|
| 45 |
+
"three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}
|
| 46 |
+
</script>
|
| 47 |
+
</head>
|
| 48 |
+
<body>
|
| 49 |
+
<div id="view"></div>
|
| 50 |
+
<div id="msg">Loading LiDAR map…</div>
|
| 51 |
+
<div class="panel" id="info">
|
| 52 |
+
<h1>Robot egocentric · office patrol → 3D LiDAR map + motion</h1>
|
| 53 |
+
<div class="stat" id="stats"></div>
|
| 54 |
+
<div class="badges"><span>360° LiDAR</span><span>LiDAR-inertial odometry</span><span>per-point deskew</span><span>moving people removed</span><span>nav goals + modes</span></div>
|
| 55 |
+
<div class="lbl">Colour</div>
|
| 56 |
+
<div class="row" id="colors"><button data-c="h" class="on">Height</button><button data-c="i">Reflectivity</button></div>
|
| 57 |
+
<div class="lbl">Display</div>
|
| 58 |
+
<div class="row"><label for="clip">Cut above</label><input id="clip" type="range" min="0.3" max="3.8" step="0.05" value="2.2"><span id="clipv" style="color:var(--muted)"></span></div>
|
| 59 |
+
<div class="row"><button id="t-floor" class="on">Floor</button><button id="t-edl" class="on">Depth shading</button></div>
|
| 60 |
+
<div class="lbl">View</div>
|
| 61 |
+
<div class="row" id="views"><button data-view="orbit">Overview</button><button data-view="top">Top</button><button data-view="follow">Follow robot</button></div>
|
| 62 |
+
<div class="legend"><span><i style="background:var(--auto)"></i>Path, autonomous</span><span><i style="background:var(--idle)"></i>Path, idle</span><span><i style="background:var(--stall)"></i>Stalled</span><span><i style="background:var(--goal)"></i>Nav goal</span></div>
|
| 63 |
+
<dl id="state">
|
| 64 |
+
<dt>Mode</dt><dd id="s-mode"></dd>
|
| 65 |
+
<dt>Speed / command</dt><dd id="s-v"></dd>
|
| 66 |
+
<dt>Distance so far</dt><dd id="s-d"></dd>
|
| 67 |
+
</dl>
|
| 68 |
+
</div>
|
| 69 |
+
<div class="panel" id="pip">
|
| 70 |
+
<video id="vid" data-ss-src="b3/data/front_camera.mp4" muted playsinline preload="auto"></video>
|
| 71 |
+
<div class="cap">Front camera (faces blurred), synced with the 3D timeline</div>
|
| 72 |
+
</div>
|
| 73 |
+
<div class="panel" id="bar">
|
| 74 |
+
<button id="play">▶ Play</button>
|
| 75 |
+
<button id="speed" title="Playback speed">4×</button>
|
| 76 |
+
<input id="slider" type="range" min="0" max="8905" value="0" step="1" aria-label="Frame">
|
| 77 |
+
<span id="time">0.0 s</span>
|
| 78 |
+
<canvas id="chart"></canvas>
|
| 79 |
+
</div>
|
| 80 |
+
<script type="module">
|
| 81 |
+
import * as THREE from 'three';
|
| 82 |
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
| 83 |
+
THREE.ColorManagement.enabled = false;
|
| 84 |
+
const $ = id => document.getElementById(id);
|
| 85 |
+
const V = '';
|
| 86 |
+
const BG = 0x0b0e12, FPS = 30;
|
| 87 |
+
|
| 88 |
+
const meta = await (await fetch('data/trajectory.json' + V)).json();
|
| 89 |
+
const T = meta.traj, N = T.t.length, DUR = meta.duration, FLOOR = meta.floor, CX = meta.center[0], CY = meta.center[1];
|
| 90 |
+
const NF = Math.round(DUR * FPS) + 1; $('slider').max = NF - 1;
|
| 91 |
+
|
| 92 |
+
/* ---------- renderer + eye-dome lighting ---------- */
|
| 93 |
+
const view = $('view');
|
| 94 |
+
const renderer = new THREE.WebGLRenderer({ antialias: false });
|
| 95 |
+
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
|
| 96 |
+
const PR = Math.min(devicePixelRatio, 2); renderer.setPixelRatio(PR);
|
| 97 |
+
view.appendChild(renderer.domElement);
|
| 98 |
+
const scene = new THREE.Scene(); scene.fog = new THREE.Fog(BG, 28, 75);
|
| 99 |
+
const camera = new THREE.PerspectiveCamera(45, 1, 0.1, 300);
|
| 100 |
+
const controls = new OrbitControls(camera, renderer.domElement);
|
| 101 |
+
controls.enableDamping = true; controls.dampingFactor = 0.12; controls.maxPolarAngle = Math.PI * 0.495; controls.minDistance = 1.5; controls.maxDistance = 90;
|
| 102 |
+
const P = (x, y, z) => new THREE.Vector3(x, z, -y);
|
| 103 |
+
|
| 104 |
+
let rt = null;
|
| 105 |
+
const edl = new THREE.ShaderMaterial({
|
| 106 |
+
uniforms: { tColor: { value: null }, tDepth: { value: null }, px: { value: new THREE.Vector2() }, near: { value: camera.near }, far: { value: camera.far }, bg: { value: new THREE.Color(BG) }, on: { value: 1 } },
|
| 107 |
+
vertexShader: 'varying vec2 vUv;void main(){vUv=uv;gl_Position=vec4(position.xy,0.,1.);}',
|
| 108 |
+
fragmentShader: `varying vec2 vUv;uniform sampler2D tColor,tDepth;uniform vec2 px;uniform float near,far,on;uniform vec3 bg;
|
| 109 |
+
float lz(vec2 uv){float d=texture2D(tDepth,uv).x;if(d>=1.0)return log2(far);float n=d*2.-1.;return log2((2.*near*far)/(far+near-n*(far-near)));}
|
| 110 |
+
void main(){vec4 c=texture2D(tColor,vUv);if(c.a<0.5){gl_FragColor=vec4(bg,1.);return;}
|
| 111 |
+
if(on<0.5){gl_FragColor=vec4(c.rgb,1.);return;}
|
| 112 |
+
float z0=lz(vUv),s=0.;
|
| 113 |
+
s+=max(0.,z0-lz(vUv+vec2(1.5,0)*px));s+=max(0.,z0-lz(vUv+vec2(-1.5,0)*px));s+=max(0.,z0-lz(vUv+vec2(0,1.5)*px));s+=max(0.,z0-lz(vUv+vec2(0,-1.5)*px));
|
| 114 |
+
s+=max(0.,z0-lz(vUv+vec2(1.05,1.05)*px));s+=max(0.,z0-lz(vUv+vec2(-1.05,1.05)*px));s+=max(0.,z0-lz(vUv+vec2(1.05,-1.05)*px));s+=max(0.,z0-lz(vUv+vec2(-1.05,-1.05)*px));
|
| 115 |
+
gl_FragColor=vec4(c.rgb*exp(-s/8.*260.),1.);}`,
|
| 116 |
+
depthTest: false, depthWrite: false });
|
| 117 |
+
const quadScene = new THREE.Scene(), quadCam = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
| 118 |
+
quadScene.add(new THREE.Mesh(new THREE.PlaneGeometry(2, 2), edl));
|
| 119 |
+
function resize() {
|
| 120 |
+
const w = innerWidth, h = innerHeight; renderer.setSize(w, h); camera.aspect = w / h; camera.updateProjectionMatrix();
|
| 121 |
+
if (rt) { rt.depthTexture.dispose(); rt.dispose(); }
|
| 122 |
+
const W = Math.max(1, Math.floor(w * PR)), H = Math.max(1, Math.floor(h * PR));
|
| 123 |
+
const dt = new THREE.DepthTexture(W, H); dt.type = THREE.UnsignedIntType;
|
| 124 |
+
rt = new THREE.WebGLRenderTarget(W, H, { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, depthTexture: dt });
|
| 125 |
+
edl.uniforms.tColor.value = rt.texture; edl.uniforms.tDepth.value = dt; edl.uniforms.px.value.set(1 / W, 1 / H);
|
| 126 |
+
drawChart();
|
| 127 |
+
}
|
| 128 |
+
addEventListener('resize', resize);
|
| 129 |
+
|
| 130 |
+
/* ---------- point cloud (binary PLY: float x,y,z, uchar intensity, uchar floor; sorted by z) ---------- */
|
| 131 |
+
const buf = await (await fetch('data/scene_lidar.ply' + V)).arrayBuffer();
|
| 132 |
+
const head = new TextDecoder().decode(new Uint8Array(buf, 0, 600));
|
| 133 |
+
const hEnd = head.indexOf('end_header\n') + 11, NP = +head.match(/element vertex (\d+)/)[1];
|
| 134 |
+
const dv = new DataView(buf, hEnd);
|
| 135 |
+
const pos = new Float32Array(NP * 3), colH = new Float32Array(NP * 3), colI = new Float32Array(NP * 3), zs = new Float32Array(NP);
|
| 136 |
+
const lin = h => [(h >> 16 & 255) / 255, (h >> 8 & 255) / 255, (h & 255) / 255].map(v => Math.pow(v, 2.2));
|
| 137 |
+
const stops = [[0, lin(0x2a5d7a)], [0.25, lin(0x2f8fa3)], [0.5, lin(0x67c9bf)], [0.7, lin(0xcfe6dc)], [0.85, lin(0xf0c27a)], [1, lin(0xe0805c)]];
|
| 138 |
+
function ramp(t) { t = Math.max(0, Math.min(1, t)); for (let k = 1; k < stops.length; k++) if (t <= stops[k][0]) { const a = stops[k - 1], b = stops[k], f = (t - a[0]) / (b[0] - a[0]); return [0, 1, 2].map(j => a[1][j] + (b[1][j] - a[1][j]) * f); } return stops.at(-1)[1]; }
|
| 139 |
+
const tmp = new THREE.Color();
|
| 140 |
+
let floorEnd = 0;
|
| 141 |
+
for (let n = 0; n < NP; n++) {
|
| 142 |
+
const o = n * 14, x = dv.getFloat32(o, true), y = dv.getFloat32(o + 4, true), z = dv.getFloat32(o + 8, true), it = dv.getUint8(o + 12), fl = dv.getUint8(o + 13);
|
| 143 |
+
pos[n * 3] = x; pos[n * 3 + 1] = z; pos[n * 3 + 2] = -y; zs[n] = z; if (fl) floorEnd = n + 1;
|
| 144 |
+
const g = Math.pow(Math.min(1, it / 110), 0.6);
|
| 145 |
+
let c; if (fl) { const v = 0.035 + 0.05 * g; c = [v, v * 1.08, v * 1.25]; } else c = ramp((z - FLOOR - 0.05) / 2.6);
|
| 146 |
+
colH.set(c.map(v => Math.pow(v, 1 / 2.2)), n * 3);
|
| 147 |
+
tmp.setHSL(0.55 - 0.47 * g, 0.55, 0.16 + 0.55 * g); colI[n * 3] = tmp.r; colI[n * 3 + 1] = tmp.g; colI[n * 3 + 2] = tmp.b;
|
| 148 |
+
}
|
| 149 |
+
const geo = new THREE.BufferGeometry();
|
| 150 |
+
geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
|
| 151 |
+
const colAttr = new THREE.BufferAttribute(colH.slice(), 3); geo.setAttribute('color', colAttr);
|
| 152 |
+
const pmat = new THREE.PointsMaterial({ size: 0.05, sizeAttenuation: true, vertexColors: true });
|
| 153 |
+
const cloud = new THREE.Points(geo, pmat); cloud.frustumCulled = false; scene.add(cloud);
|
| 154 |
+
$('msg').remove();
|
| 155 |
+
$('stats').textContent = `${(NP / 1e6).toFixed(2)} M points · 4 cm cells · ${DUR.toFixed(0)} s · ${meta.goals.length} nav goals`;
|
| 156 |
+
|
| 157 |
+
let showFloor = true;
|
| 158 |
+
function upper(v) { let lo = 0, hi = NP; while (lo < hi) { const m = (lo + hi) >> 1; if (zs[m] <= v) lo = m + 1; else hi = m; } return lo; }
|
| 159 |
+
function applyRange() { const top = upper(FLOOR + +$('clip').value), st = showFloor ? 0 : floorEnd; geo.setDrawRange(st, Math.max(0, top - st)); $('clipv').textContent = (+$('clip').value).toFixed(2) + ' m'; }
|
| 160 |
+
$('clip').oninput = applyRange; applyRange();
|
| 161 |
+
$('t-floor').onclick = e => { showFloor = !showFloor; e.target.classList.toggle('on', showFloor); applyRange(); };
|
| 162 |
+
$('t-edl').onclick = e => { const on = !edl.uniforms.on.value; edl.uniforms.on.value = on ? 1 : 0; e.target.classList.toggle('on', on); };
|
| 163 |
+
document.querySelectorAll('#colors button').forEach(b => b.onclick = () => {
|
| 164 |
+
colAttr.array.set(b.dataset.c === 'h' ? colH : colI); colAttr.needsUpdate = true;
|
| 165 |
+
document.querySelectorAll('#colors button').forEach(x => x.classList.toggle('on', x === b)); });
|
| 166 |
+
|
| 167 |
+
/* ---------- path, goals, robot ---------- */
|
| 168 |
+
const stalls = meta.segs.filter(s => s.label === 'stalled');
|
| 169 |
+
const inStall = t => stalls.some(s => t >= s.s && t <= s.e);
|
| 170 |
+
const cum = new Float32Array(N); for (let k = 1; k < N; k++) cum[k] = cum[k - 1] + Math.hypot(T.x[k] - T.x[k - 1], T.y[k] - T.y[k - 1]);
|
| 171 |
+
const stateAt = k => inStall(T.t[k]) ? 2 : (T.mode[k] === 1 ? 1 : 0);
|
| 172 |
+
const COL = [0x8a95a5, 0x4fd1c5, 0xf2a541];
|
| 173 |
+
for (let k = 0, s = 0; k <= N; k++) {
|
| 174 |
+
if (k === N || stateAt(k) !== stateAt(s)) {
|
| 175 |
+
const e = Math.min(k, N - 1), pts = [];
|
| 176 |
+
for (let j = s; j <= e; j += 2) pts.push(P(T.x[j], T.y[j], FLOOR + 0.08));
|
| 177 |
+
pts.push(P(T.x[e], T.y[e], FLOOR + 0.08));
|
| 178 |
+
if (pts.length >= 2 && cum[e] - cum[s] > 0.05)
|
| 179 |
+
scene.add(new THREE.Mesh(new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), Math.max(4, pts.length * 2), 0.045, 6, false), new THREE.MeshBasicMaterial({ color: COL[stateAt(s)], fog: false })));
|
| 180 |
+
s = k;
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
const fmt = s => { const m = Math.floor(s / 60); return m + ':' + (s - 60 * m).toFixed(1).padStart(4, '0'); };
|
| 184 |
+
meta.goals.forEach((g, i) => {
|
| 185 |
+
const mat = new THREE.MeshBasicMaterial({ color: 0xff6b8a, fog: false, side: THREE.DoubleSide });
|
| 186 |
+
const pole = new THREE.Mesh(new THREE.CylinderGeometry(0.03, 0.03, 1.6, 8), mat); pole.position.copy(P(g.x, g.y, FLOOR + 0.8)); scene.add(pole);
|
| 187 |
+
const ring = new THREE.Mesh(new THREE.RingGeometry(0.35, 0.45, 40), mat); ring.rotation.x = -Math.PI / 2; ring.position.copy(P(g.x, g.y, FLOOR + 0.03)); scene.add(ring);
|
| 188 |
+
const cv = document.createElement('canvas'); cv.width = 320; cv.height = 64; const cx = cv.getContext('2d');
|
| 189 |
+
cx.font = '500 30px ui-monospace, Menlo, monospace'; cx.fillStyle = '#ff6b8a'; cx.fillText('goal ' + (i + 1) + ' · set ' + fmt(g.t), 6, 42);
|
| 190 |
+
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: new THREE.CanvasTexture(cv), depthTest: false, fog: false })); sp.scale.set(2.5, 0.5, 1); sp.position.copy(P(g.x, g.y, FLOOR + 1.9 + i * 0.45)); scene.add(sp);
|
| 191 |
+
});
|
| 192 |
+
const robot = new THREE.Group();
|
| 193 |
+
robot.add(new THREE.Mesh(new THREE.BoxGeometry(0.7, 0.3, 0.35), new THREE.MeshBasicMaterial({ color: 0xffffff, fog: false })));
|
| 194 |
+
const nose = new THREE.Mesh(new THREE.ConeGeometry(0.14, 0.35, 16), new THREE.MeshBasicMaterial({ color: 0x4fd1c5, fog: false })); nose.rotation.z = -Math.PI / 2; nose.position.x = 0.52; robot.add(nose);
|
| 195 |
+
const halo = new THREE.Mesh(new THREE.RingGeometry(0.6, 0.66, 48), new THREE.MeshBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0.6, side: THREE.DoubleSide, fog: false })); halo.rotation.x = -Math.PI / 2; halo.position.y = -0.15; robot.add(halo);
|
| 196 |
+
scene.add(robot);
|
| 197 |
+
|
| 198 |
+
/* ---------- views ---------- */
|
| 199 |
+
let follow = false;
|
| 200 |
+
function setView(v) {
|
| 201 |
+
follow = v === 'follow';
|
| 202 |
+
if (v === 'orbit') { camera.position.copy(P(CX - 9, CY - 15, 12)); controls.target.copy(P(CX + 1, CY, FLOOR + 0.3)); }
|
| 203 |
+
if (v === 'top') { camera.position.copy(P(CX, CY + 0.01, 42)); controls.target.copy(P(CX, CY, FLOOR)); }
|
| 204 |
+
if (v === 'follow') { const k = cur, yw = T.yaw[k]; camera.position.copy(P(T.x[k] - 3.5 * Math.cos(yw), T.y[k] - 3.5 * Math.sin(yw), T.z[k] + 1.8)); controls.target.copy(P(T.x[k], T.y[k], T.z[k])); }
|
| 205 |
+
document.querySelectorAll('#views button').forEach(b => b.classList.toggle('on', b.dataset.view === v));
|
| 206 |
+
}
|
| 207 |
+
document.querySelectorAll('#views button').forEach(b => b.onclick = () => setView(b.dataset.view));
|
| 208 |
+
|
| 209 |
+
/* ---------- timeline chart: speed vs command, mode bands ---------- */
|
| 210 |
+
const chart = $('chart');
|
| 211 |
+
function drawChart() {
|
| 212 |
+
const r = chart.getBoundingClientRect(), W = Math.max(10, r.width * PR), H = 56 * PR; chart.width = W; chart.height = H;
|
| 213 |
+
const c = chart.getContext('2d'), X = t => t / DUR * W, vmax = 0.6, Y = v => H - 4 * PR - Math.max(0, Math.min(vmax, v)) / vmax * (H - 10 * PR);
|
| 214 |
+
c.fillStyle = 'rgba(79,209,197,.10)';
|
| 215 |
+
for (let k = 0, s = 0; k <= N; k++) if (k === N || T.mode[k] !== T.mode[s]) { if (T.mode[s] === 1) c.fillRect(X(T.t[s]), 0, X(T.t[Math.min(k, N - 1)]) - X(T.t[s]), H); s = k; }
|
| 216 |
+
c.fillStyle = 'rgba(242,165,65,.75)'; stalls.forEach(s => c.fillRect(X(s.s), H - 3 * PR, X(s.e) - X(s.s), 3 * PR));
|
| 217 |
+
c.fillStyle = '#ff6b8a'; meta.goals.forEach(g => c.fillRect(X(g.t) - PR, 0, 2 * PR, H));
|
| 218 |
+
const line = (arr, col, dash) => { c.strokeStyle = col; c.lineWidth = 1.3 * PR; c.setLineDash(dash); c.beginPath(); for (let k = 0; k < N; k++) { const x = X(T.t[k]), y = Y(arr[k]); k ? c.lineTo(x, y) : c.moveTo(x, y); } c.stroke(); c.setLineDash([]); };
|
| 219 |
+
line(T.cmd, 'rgba(146,155,167,.9)', [4 * PR, 3 * PR]); line(T.v, '#4fd1c5', []);
|
| 220 |
+
c.fillStyle = '#929ba7'; c.font = `${10 * PR}px -apple-system, sans-serif`; c.fillText('forward speed (solid) vs command (dashed), 0–0.6 m/s · amber = stalled · pink = goal set', 6 * PR, 11 * PR);
|
| 221 |
+
c.fillStyle = '#fff'; c.fillRect(X(T.t[cur]) - PR / 2, 0, PR, H);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/* ---------- playback: the video is the clock while playing ---------- */
|
| 225 |
+
const vid = $('vid'), slider = $('slider');
|
| 226 |
+
let cur = 0, frame = 0, playing = false;
|
| 227 |
+
const SPEEDS = [1, 2, 4, 8]; let spd = 4;
|
| 228 |
+
function idxAt(t) { let lo = 0, hi = N - 1; while (lo < hi) { const m = (lo + hi + 1) >> 1; if (T.t[m] <= t) lo = m; else hi = m - 1; } return lo; }
|
| 229 |
+
function setFrame(f, seekVideo) {
|
| 230 |
+
frame = Math.max(0, Math.min(NF - 1, f)); const t = frame / FPS; cur = idxAt(t); const k = cur;
|
| 231 |
+
const prev = robot.position.clone();
|
| 232 |
+
robot.position.copy(P(T.x[k], T.y[k], T.z[k])); robot.rotation.y = T.yaw[k];
|
| 233 |
+
if (follow) { const d = robot.position.clone().sub(prev); controls.target.add(d); camera.position.add(d); }
|
| 234 |
+
slider.value = frame; $('time').textContent = `${t.toFixed(1)} s / ${DUR.toFixed(0)} s`;
|
| 235 |
+
const st = inStall(t);
|
| 236 |
+
$('s-mode').innerHTML = st ? '<span class="pill stall">auto · stalled</span>' : T.mode[k] === 1 ? '<span class="pill auto">autonomous</span>' : '<span class="pill idle">idle</span>';
|
| 237 |
+
$('s-v').textContent = `${T.v[k].toFixed(2)} / ${T.cmd[k].toFixed(2)} m/s`;
|
| 238 |
+
$('s-d').textContent = cum[k].toFixed(1) + ' m';
|
| 239 |
+
if (seekVideo && vid.readyState >= 1) vid.currentTime = Math.min(vid.duration || DUR, t + 0.5 / FPS);
|
| 240 |
+
drawChart();
|
| 241 |
+
}
|
| 242 |
+
slider.oninput = () => { setFrame(+slider.value, true); };
|
| 243 |
+
$('play').onclick = () => {
|
| 244 |
+
playing = !playing; $('play').textContent = playing ? '❚❚ Pause' : '▶ Play';
|
| 245 |
+
if (playing) { if (frame >= NF - 1) setFrame(0, true); vid.playbackRate = spd; vid.play().catch(() => {}); } else vid.pause();
|
| 246 |
+
};
|
| 247 |
+
$('speed').onclick = () => { spd = SPEEDS[(SPEEDS.indexOf(spd) + 1) % SPEEDS.length]; $('speed').textContent = spd + '×'; vid.playbackRate = spd; };
|
| 248 |
+
vid.addEventListener('ended', () => { playing = false; $('play').textContent = '▶ Play'; });
|
| 249 |
+
vid.addEventListener('loadedmetadata', () => setFrame(frame, true));
|
| 250 |
+
|
| 251 |
+
resize(); setView('orbit'); setFrame(Math.round(150 * FPS), true);
|
| 252 |
+
let last = performance.now();
|
| 253 |
+
renderer.setAnimationLoop(now => {
|
| 254 |
+
const dt = (now - last) / 1000; last = now;
|
| 255 |
+
if (playing) {
|
| 256 |
+
if (vid.readyState >= 2 && !vid.paused) setFrame(Math.round(vid.currentTime * FPS), false);
|
| 257 |
+
else if (vid.readyState < 2) setFrame(frame + Math.round(dt * FPS * spd) || frame + 1, false);
|
| 258 |
+
}
|
| 259 |
+
halo.scale.setScalar(1 + 0.15 * Math.sin(now / 300));
|
| 260 |
+
controls.update();
|
| 261 |
+
renderer.setRenderTarget(rt); renderer.setClearColor(BG, 0); renderer.clear(); renderer.render(scene, camera);
|
| 262 |
+
renderer.setRenderTarget(null); renderer.render(quadScene, quadCam);
|
| 263 |
+
});
|
| 264 |
+
</script>
|
| 265 |
+
</body>
|
| 266 |
+
</html>
|
sceneSample/index.html
CHANGED
|
@@ -122,7 +122,7 @@ async function main() {
|
|
| 122 |
gate.hidden = true;
|
| 123 |
app.innerHTML = signOutLink(s) + `<nav>
|
| 124 |
<a href="#a1">A1 · Simulated robot, generated world</a><a href="#a2">A2 · Procedural scene from code</a>
|
| 125 |
-
<a href="#b1">B1 · Kitchen digital twin</a><a href="#b2">B2 · Robot egocentric</a><a href="#download">Download</a></nav>` + html;
|
| 126 |
app.hidden = false;
|
| 127 |
wireSignOut();
|
| 128 |
SS.hydrate(app);
|
|
|
|
| 122 |
gate.hidden = true;
|
| 123 |
app.innerHTML = signOutLink(s) + `<nav>
|
| 124 |
<a href="#a1">A1 · Simulated robot, generated world</a><a href="#a2">A2 · Procedural scene from code</a>
|
| 125 |
+
<a href="#b1">B1 · Kitchen digital twin</a><a href="#b2">B2 · Robot egocentric: restocking</a><a href="#b3">B3 · Robot egocentric: office patrol</a><a href="#download">Download</a></nav>` + html;
|
| 126 |
app.hidden = false;
|
| 127 |
wireSignOut();
|
| 128 |
SS.hydrate(app);
|