feat(web): draggable floating panels and a non-hanging tutorial demo open
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

- add a shared useDraggablePanel hook (pointer capture, clamping, offset
  persistence in localStorage, double-click / button / menu reset) and use it
  for the tutorial step panel, the quick toolbar, the adjust-last-operation
  panel and the robot tool drawer
- quick toolbar drags out of the dock into a compact floating bar and can be
  folded; robot tool scrim is transparent and click-through so the 3D scene
  stays visible and usable while the tool is open
- 窗口 > 恢复默认面板位置 clears every stored panel offset
- fix a pre-existing hang: tutorial demo scene opens went through the
  "save current project?" prompt and waited forever; course demos now persist
  the current OPFS project like the dialog's 保存后继续 and continue
- PBR tutorial spec: demos must not auto-download .blend (OPFS-only rule)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-23 21:43:40 +08:00
parent cb2829cad1
commit 2c8449f422
15 changed files with 716 additions and 92 deletions

View File

@@ -5,6 +5,7 @@ import {sha256Hex} from '../../../protocol/render-assets';
import {exportGLB} from '../../../protocol/glb-export';
import {parseRobotURDF,resolveRobotFiles,type RobotModel} from './urdf';
import workflow from './robot-workflow.py?raw';
import {useDraggablePanel} from '../app/use-draggable-panel';
interface Result {schemaVersion:1;model:RobotModel;assembled:boolean;angles:Record<string,number>;checks:{name:string;status:string;stepRadians:number;maxWorldDelta:number;descendants:number}[];objects:string[];matrices:Record<string,{parent:string|null;local:number[];world:number[]}>}
type Applied=Awaited<ReturnType<WebEngineClient['applyServerBlendResult']>>;
@@ -18,6 +19,8 @@ export function RobotTool({client,snapshot,onApplied,onStart,onSave,onClose}:Pro
const [result,setResult]=useState<Result|null>(null),[angles,setAngles]=useState<Record<string,number>>({}),[error,setError]=useState(''),[status,setStatus]=useState('等待输入');
const [busy,setBusy]=useState(false),[ready,setReady]=useState(false),[verified,setVerified]=useState(false),[exports,setExports]=useState<string[]>([]);
const currentHash=useRef(''),revision=useRef<number|null>(null),abort=useRef<AbortController|null>(null),mounted=useRef(true),operation=useRef(false),panelRef=useRef<HTMLElement>(null);
/* The drawer can be moved away from the model it is driving. */
const drag=useDraggablePanel('robot-tool');
useEffect(()=>{mounted.current=true;const previous=document.activeElement as HTMLElement|null;panelRef.current?.querySelector<HTMLButtonElement>('button')?.focus();return()=>{mounted.current=false;abort.current?.abort();previous?.focus();};},[]);
useEffect(()=>{if(result&&snapshot?.revision!==revision.current){setVerified(false);setStatus('场景已变化,请读取项目机器人');}},[snapshot?.revision,result]);
const run=async(fn:()=>Promise<void>)=>{
@@ -87,8 +90,8 @@ export function RobotTool({client,snapshot,onApplied,onStart,onSave,onClose}:Pro
const controls=Array.from(panelRef.current?.querySelectorAll<HTMLElement>('button:not(:disabled),input:not(:disabled),[tabindex="0"]')??[]).filter(el=>el.getClientRects().length);
const first=controls[0],last=controls.at(-1);if(event.shiftKey&&document.activeElement===first){event.preventDefault();last?.focus();}else if(!event.shiftKey&&document.activeElement===last){event.preventDefault();first?.focus();}
}}}>
<section ref={panelRef} className="robot-tool" role="dialog" aria-modal="true" aria-label="六轴机器人工具">
<header><h2>六轴机器人</h2><button aria-label="关闭机器人工具" title="关闭" disabled={busy} onClick={onClose}>×</button></header>
<section ref={panelRef} className="robot-tool" role="dialog" aria-modal="true" aria-label="六轴机器人工具" data-draggable-panel="robot-tool" data-panel-offset={`${drag.offset.x},${drag.offset.y}`} style={{transform:`translate(${drag.offset.x}px, ${drag.offset.y}px)`}}>
<header {...drag.handle} title="拖动标题栏可移动工具面板,双击复位"><h2><span className="robot-tool-grip" aria-hidden="true">⠿</span> 六轴机器人</h2><button aria-label="复位机器人工具位置" title="复位位置" disabled={drag.offset.x===0&&drag.offset.y===0} onClick={drag.reset}>⌖</button><button aria-label="关闭机器人工具" title="关闭" disabled={busy} onClick={onClose}>×</button></header>
<div className="robot-tool-body">
<section><h3>1 · 模型与资源</h3><div className="robot-tool-actions"><button disabled={busy} onClick={preset}>加载 ABB IRB120 样例</button><button disabled={busy||!snapshot} onClick={()=>void run(()=>execute('inspect'))}>读取项目机器人</button></div>
<label>URDF 文件<input aria-label="机器人 URDF 文件" type="file" accept=".urdf,.xml" disabled={busy} onChange={e=>{const file=e.target.files?.[0];if(file)void run(async()=>{invalidate();setModel(null);const next=parseRobotURDF(await file.text());setModel(next);setStatus('URDF 已读取');});}}/></label>

View File

@@ -1,6 +1,8 @@
.robot-tool-backdrop{position:fixed;inset:0;z-index:1200;background:#0003;display:flex;justify-content:flex-end;padding:36px 12px 16px;box-sizing:border-box}
.robot-tool{width:580px;max-width:100%;display:flex;flex-direction:column;min-height:0;background:#252827;color:#e4e8e5;border:1px solid #737b76;box-shadow:0 8px 25px #0005}
.robot-tool header{display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #555e58;padding:10px 14px}.robot-tool h2{font-size:17px;margin:0}.robot-tool header button{width:28px;height:28px;padding:0;font-size:20px}
/* Transparent, click-through scrim: the 3D scene stays visible and usable while
* the drawer is open, so the user can watch the robot react to the tool. */
.robot-tool-backdrop{position:fixed;inset:0;z-index:1200;background:transparent;display:flex;justify-content:flex-end;padding:36px 12px 16px;box-sizing:border-box;pointer-events:none}
.robot-tool{pointer-events:auto;width:580px;max-width:100%;display:flex;flex-direction:column;min-height:0;background:#252827;color:#e4e8e5;border:1px solid #737b76;box-shadow:0 8px 25px #0005}
.robot-tool header{display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #555e58;padding:10px 14px;cursor:grab;touch-action:none;user-select:none}.robot-tool header:active{cursor:grabbing}.robot-tool-grip{color:#8d968f;letter-spacing:-1px}.robot-tool h2{font-size:17px;margin:0}.robot-tool header button{width:28px;height:28px;padding:0;font-size:20px}.robot-tool header button[disabled]{opacity:.4;cursor:default}
.robot-tool-body{overflow:auto;min-height:0;padding:0 14px}.robot-tool-body>section{padding:12px 0;border-bottom:1px solid #4e5550}.robot-tool h3{font-size:13px;margin:0 0 10px;color:#c6dace}.robot-tool label{display:flex;align-items:center;gap:8px;margin:7px 0;font-size:12px;flex-wrap:wrap}.robot-tool input{min-width:0;max-width:100%;color:inherit}.robot-tool input[type=file]{flex:1;min-width:150px;font-size:11px}
.robot-tool button{background:#444d47;color:#edf2ee;border:1px solid #78867b;border-radius:3px;padding:6px 9px;cursor:pointer;font-size:12px}.robot-tool button:disabled{opacity:.45;cursor:default}.robot-tool button:hover:enabled{background:#54645a}.robot-tool button:focus-visible,.robot-tool input:focus-visible{outline:2px solid #bfcf79;outline-offset:2px}.robot-tool-actions{display:flex;gap:7px;flex-wrap:wrap;margin:7px 0}
.robot-tool-summary{color:#bad5c4;font-size:11px;padding-top:6px}.robot-tool table{width:100%;border-collapse:collapse;font-size:11px;table-layout:fixed}.robot-tool th,.robot-tool td{text-align:left;padding:6px 3px;border-bottom:1px solid #414942;overflow-wrap:anywhere}.robot-tool th:nth-child(2){width:40%}.robot-tool small{display:block;color:#a4b1a8;font-size:10px}