Files
vibemake/examples/duck-left-assembly.html
Jerry 1c837766cd feat: integrate robot assembly and simulation with resilient loading
Add backend-driven assembly and simulation experiences, MAKE branding, mobile rendering budgets and desktop-only CAD/PCB routes. Improve logo loading progress, document image recovery and URDF request handling; include dev packaging and regression coverage.
2026-10-30 18:38:39 +08:00

89 lines
5.5 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>小鸭子 · 52 步装配预览</title>
<link rel="stylesheet" href="/css/fonts.css"><link rel="stylesheet" href="/css/style.css"><link rel="stylesheet" href="/css/assembly.css">
<script type="importmap">{"imports":{"three":"/vendor/three/build/three.module.min.js","three/addons/":"/vendor/three/examples/jsm/"}}</script>
<style>
main{max-width:1200px;margin:24px auto;padding:16px}h1{font-size:24px;margin:12px 0}p{color:var(--muted);line-height:1.7}
.stage{height:60vh;min-height:320px;background:radial-gradient(ellipse at 50% 45%,#363d47,#1e2329);border:1px solid #353a42;border-radius:20px;overflow:hidden;margin:20px 0;position:relative}
.stage canvas{display:block;width:100%;height:100%}.row{display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin:12px 0}.row label{display:flex;align-items:center;gap:12px}
select{background:#171c22;color:#fff;border:1px solid #3d434c;padding:10px;border-radius:10px;max-width:100%;min-height:44px}input{max-width:100%}.btn{min-height:44px}
output{color:var(--accent);font-size:13px}#phase{width:260px}#note{min-height:2em;font-size:14px}
@media(max-width:600px){main{padding:12px}.stage{height:50vh}.row label{width:100%}#steps{width:100%}}
</style>
</head>
<body><main>
<a href="/project/?id=gcw47xwyyhr8">← 小鸭子项目</a>
<h1>左腿 · 52 步装配</h1>
<p>当前上传文件的本地预览。选择任意步骤,拖动进度查看装入方向;后台需要上传新的步骤 JSON 后才会更新。</p>
<output id="status" aria-live="polite">正在加载模型…</output>
<div class="stage" id="stage"></div>
<div class="row">
<button class="btn" id="prev" disabled aria-label="上一步">←</button>
<select id="steps" aria-label="安装步骤" disabled></select>
<button class="btn" id="next" disabled aria-label="下一步">→</button>
<button class="btn btn-primary" id="replay" disabled>重播本步</button>
<button class="btn" id="reset" disabled>重置视角</button>
<button class="btn" id="community" disabled>社区播放器预览</button>
</div>
<div class="row"><label>动画进度 <input id="phase" type="range" min="0" max="100" value="100" disabled><output id="percent">100%</output></label></div>
<p id="note"></p>
</main>
<script type="module">
import { AssemblyViewer } from '/js/assembly-viewer.js';
import { loadPackage } from '/js/experience-packages.js';
import { openAssemblyPreview } from '/js/assembly.js';
const $ = id => document.getElementById(id);
const controller = new AbortController();
const url = '/deliverables/experience-packages/microduck-left-numbered/directions-52.json';
let viewer, config, notes, index = 0, timer;
function show(n) {
clearInterval(timer);
index = Math.max(0, Math.min(config.steps.length - 1, n));
$('steps').value = String(index);
viewer.setStep(index, false);
$('phase').value = '100'; $('percent').textContent = '100%';
$('prev').disabled = index === 0; $('next').disabled = index === config.steps.length - 1;
$('note').textContent = notes.steps[index].reason;
}
function scrub(progress) {
viewer.setStep(index, true);
viewer.setAnimationPaused(true);
const total = Math.max(0.55, ...viewer.transitions.map(t => t.duration));
for (const t of viewer.transitions) {
if (t.sample) t.sample(total * progress);
else t.instance.position.lerpVectors(t.from, t.target, progress);
}
viewer.renderer.shadowMap.needsUpdate = true;
viewer.loop.invalidate();
$('phase').value = String(Math.round(progress * 100));
$('percent').textContent = `${Math.round(progress * 100)}%`;
}
try {
[config, notes] = await Promise.all([
loadPackage(new URL(url, location.href).href, 'assembly', controller.signal),
fetch(url.replace('.json', '.notes.json'), { signal: controller.signal }).then(r => r.json()),
]);
viewer = new AssemblyViewer($('stage'));
await viewer.load(config, controller.signal, n => { $('status').textContent = `正在加载模型 ${n}%`; });
config.steps.forEach((s, i) => { const option = document.createElement('option'); option.value = i; option.textContent = `${i + 1} / 52 · ${s.label}`; $('steps').append(option); });
for (const id of ['steps', 'prev', 'next', 'replay', 'reset', 'community', 'phase']) $(id).disabled = false;
$('status').textContent = '52 步 · 72 个零件实例 · 原始材质';
$('steps').onchange = () => show(Number($('steps').value));
$('prev').onclick = () => show(index - 1); $('next').onclick = () => show(index + 1);
$('reset').onclick = () => viewer.resetView();
$('phase').oninput = () => { clearInterval(timer); scrub(Number($('phase').value) / 100); };
$('replay').onclick = () => {
clearInterval(timer); viewer.setStep(index, true);
$('phase').value = '0'; $('percent').textContent = '播放中';
timer = setInterval(() => { if (!viewer.transitions.length) { clearInterval(timer); $('phase').value = '100'; $('percent').textContent = '100%'; } }, 100);
};
$('community').onclick = () => openAssemblyPreview({ name: 'Microduck', assemblyManifestUrl: url }, { initialStep: index });
show(Number(new URLSearchParams(location.search).get('step') || 1) - 1);
} catch (e) { $('status').textContent = e.message; }
addEventListener('pagehide', () => { clearInterval(timer); controller.abort(); viewer?.dispose(); }, { once: true });
</script>
</body></html>