Initial commit: step2urdf tool with handtuned JSON import.
Includes FastAPI backend, vendored step2urdf frontend, and A7 handtuned arm JSON for URDF generation.
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
const state = {
|
||||
jobId: null,
|
||||
draft: null,
|
||||
};
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
function pretty(obj) {
|
||||
return JSON.stringify(obj, null, 2);
|
||||
}
|
||||
|
||||
async function refreshHealth() {
|
||||
const el = $("health");
|
||||
try {
|
||||
const res = await fetch("/api/health");
|
||||
const data = await res.json();
|
||||
const z = data.zhipu_configured ? `智谱 OK (${data.zhipu_model})` : "智谱未配置";
|
||||
const g = data.geometry?.available ? "几何后端可用" : "几何后端未装(占位 mesh)";
|
||||
el.textContent = `${z} · ${g}`;
|
||||
el.className = "pill " + (data.zhipu_configured ? "ok" : "warn");
|
||||
} catch (e) {
|
||||
el.textContent = "后端未连接";
|
||||
el.className = "pill warn";
|
||||
}
|
||||
}
|
||||
|
||||
$("btnParse").addEventListener("click", async () => {
|
||||
const file = $("file").files?.[0];
|
||||
if (!file) {
|
||||
$("parseOut").textContent = "请先选择 STEP 文件";
|
||||
$("parseOut").classList.add("error");
|
||||
return;
|
||||
}
|
||||
$("parseOut").classList.remove("error");
|
||||
$("parseOut").textContent = "解析中…";
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
try {
|
||||
const res = await fetch("/api/parse", { method: "POST", body: fd });
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
const data = await res.json();
|
||||
state.jobId = data.job_id;
|
||||
$("btnPropose").disabled = false;
|
||||
$("parseOut").textContent = pretty({
|
||||
job_id: data.job_id,
|
||||
root_name: data.root_name,
|
||||
product_count: data.product_names?.length,
|
||||
product_names: data.product_names,
|
||||
stats: data.stats,
|
||||
});
|
||||
} catch (e) {
|
||||
$("parseOut").textContent = String(e);
|
||||
$("parseOut").classList.add("error");
|
||||
}
|
||||
});
|
||||
|
||||
$("btnPropose").addEventListener("click", async () => {
|
||||
if (!state.jobId) return;
|
||||
$("proposeOut").classList.remove("error");
|
||||
$("proposeOut").textContent = "调用智谱中(可能需要几十秒)…";
|
||||
try {
|
||||
const res = await fetch("/api/propose", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
job_id: state.jobId,
|
||||
profile: $("profile").value,
|
||||
robot_name: $("robotName").value || "A7",
|
||||
extra_hint: $("hint").value || "",
|
||||
}),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
const draft = await res.json();
|
||||
state.draft = draft;
|
||||
$("draftEditor").value = pretty(draft);
|
||||
$("btnExport").disabled = false;
|
||||
$("proposeOut").textContent = `links=${draft.links?.length || 0}, joints=${draft.joints?.length || 0}\n` +
|
||||
(draft.notes || []).map((n) => `- ${n}`).join("\n");
|
||||
} catch (e) {
|
||||
$("proposeOut").textContent = String(e);
|
||||
$("proposeOut").classList.add("error");
|
||||
}
|
||||
});
|
||||
|
||||
$("btnExport").addEventListener("click", async () => {
|
||||
if (!state.jobId) return;
|
||||
$("exportOut").classList.remove("error");
|
||||
try {
|
||||
const draft = JSON.parse($("draftEditor").value);
|
||||
state.draft = draft;
|
||||
const res = await fetch("/api/export", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
job_id: state.jobId,
|
||||
draft,
|
||||
include_meshes: true,
|
||||
}),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
const meta = await res.json();
|
||||
$("exportOut").textContent = pretty(meta);
|
||||
const name = draft.name || "robot";
|
||||
const a = $("dlLink");
|
||||
a.hidden = false;
|
||||
a.href = `/api/jobs/${state.jobId}/download/${encodeURIComponent(name)}`;
|
||||
a.textContent = `下载 ${name}.urdf`;
|
||||
} catch (e) {
|
||||
$("exportOut").textContent = String(e);
|
||||
$("exportOut").classList.add("error");
|
||||
}
|
||||
});
|
||||
|
||||
refreshHealth();
|
||||
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Legacy UI — step2urdf-tool</title>
|
||||
<link rel="stylesheet" href="/legacy/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="hero">
|
||||
<div>
|
||||
<p class="eyebrow">LEGACY</p>
|
||||
<h1>旧版静态 UI(已降级)</h1>
|
||||
<p class="sub">
|
||||
主界面请用 step2urdf 前端:开发时打开
|
||||
<a href="http://127.0.0.1:5678">http://127.0.0.1:5678</a>
|
||||
(Vite + 智谱建议关节 + 导出 URDF)。本页仅保留调试。
|
||||
</p>
|
||||
</div>
|
||||
<div id="health" class="pill">checking…</div>
|
||||
</header>
|
||||
|
||||
<section class="panel">
|
||||
<h2>1. 上传 STEP</h2>
|
||||
<div class="row">
|
||||
<input id="file" type="file" accept=".step,.stp,.STEP,.STP" />
|
||||
<button id="btnParse" class="primary">解析</button>
|
||||
</div>
|
||||
<pre id="parseOut" class="code muted">等待上传…</pre>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2>2. 智谱关节提案</h2>
|
||||
<div class="grid2">
|
||||
<label>Profile
|
||||
<select id="profile">
|
||||
<option value="a7" selected>a7(先试机械臂)</option>
|
||||
<option value="generic">generic(后续其他 STEP)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>机器人名
|
||||
<input id="robotName" value="A7" />
|
||||
</label>
|
||||
</div>
|
||||
<label>额外提示
|
||||
<textarea id="hint" rows="2" placeholder="可选:关节数量、固定件说明…"></textarea>
|
||||
</label>
|
||||
<button id="btnPropose" class="primary">调用智谱</button>
|
||||
<pre id="draftOut" class="code muted">等待提案…</pre>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2>3. 导出 URDF(服务端草稿)</h2>
|
||||
<button id="btnExport" class="primary">导出</button>
|
||||
<pre id="exportOut" class="code muted">等待导出…</pre>
|
||||
</section>
|
||||
</div>
|
||||
<script src="/legacy/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,149 @@
|
||||
:root {
|
||||
--bg0: #0f1412;
|
||||
--bg1: #18211c;
|
||||
--ink: #e8f0ea;
|
||||
--muted: #9bb0a2;
|
||||
--accent: #c4f54b;
|
||||
--accent2: #5ee0a0;
|
||||
--line: rgba(232, 240, 234, 0.12);
|
||||
--danger: #ff7a7a;
|
||||
--font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
|
||||
--font-body: "IBM Plex Sans", "Noto Sans SC", "Segoe UI", sans-serif;
|
||||
--font-mono: "IBM Plex Mono", "SF Mono", ui-monospace, monospace;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
html, body {
|
||||
margin: 0;
|
||||
min-height: 100%;
|
||||
background:
|
||||
radial-gradient(1200px 600px at 10% -10%, rgba(94, 224, 160, 0.18), transparent 55%),
|
||||
radial-gradient(900px 500px at 100% 0%, rgba(196, 245, 75, 0.12), transparent 50%),
|
||||
linear-gradient(165deg, var(--bg0), #121a16 40%, #0c100e);
|
||||
color: var(--ink);
|
||||
font-family: var(--font-body);
|
||||
}
|
||||
|
||||
.page {
|
||||
width: min(980px, calc(100% - 2rem));
|
||||
margin: 0 auto;
|
||||
padding: 2.2rem 0 4rem;
|
||||
}
|
||||
|
||||
.hero {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: var(--accent2);
|
||||
font-size: 0.75rem;
|
||||
margin: 0 0 0.4rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-family: var(--font-display);
|
||||
font-weight: 560;
|
||||
font-size: clamp(2rem, 4vw, 2.8rem);
|
||||
margin: 0;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.sub { color: var(--muted); margin: 0.55rem 0 0; max-width: 36rem; }
|
||||
|
||||
.pill {
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(255,255,255,0.03);
|
||||
padding: 0.55rem 0.8rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.82rem;
|
||||
color: var(--muted);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pill.ok { color: var(--accent2); border-color: rgba(94,224,160,0.35); }
|
||||
.pill.warn { color: #ffd27a; border-color: rgba(255,210,122,0.35); }
|
||||
|
||||
.panel {
|
||||
border: 1px solid var(--line);
|
||||
background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
|
||||
border-radius: 18px;
|
||||
padding: 1.15rem 1.2rem 1.25rem;
|
||||
margin-bottom: 1rem;
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
.panel h2 {
|
||||
margin: 0 0 0.9rem;
|
||||
font-size: 1.05rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.row { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; margin: 0.6rem 0; }
|
||||
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
|
||||
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }
|
||||
|
||||
label {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.86rem;
|
||||
color: var(--muted);
|
||||
margin: 0.45rem 0;
|
||||
}
|
||||
|
||||
input[type="text"], input:not([type]), input[type="file"], select, textarea {
|
||||
width: 100%;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(0,0,0,0.28);
|
||||
color: var(--ink);
|
||||
border-radius: 10px;
|
||||
padding: 0.65rem 0.75rem;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
textarea {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.82rem;
|
||||
line-height: 1.45;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
button, .ghost {
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
padding: 0.62rem 1.05rem;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button.primary {
|
||||
background: linear-gradient(120deg, var(--accent), var(--accent2));
|
||||
color: #102016;
|
||||
font-weight: 650;
|
||||
}
|
||||
button:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
.ghost {
|
||||
color: var(--accent2);
|
||||
border: 1px solid rgba(94,224,160,0.35);
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.code {
|
||||
margin: 0.7rem 0 0;
|
||||
padding: 0.85rem;
|
||||
border-radius: 12px;
|
||||
background: rgba(0,0,0,0.35);
|
||||
border: 1px solid var(--line);
|
||||
overflow: auto;
|
||||
max-height: 260px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.78rem;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.muted { color: var(--muted); }
|
||||
.error { color: var(--danger); }
|
||||
Reference in New Issue
Block a user