Download app/static/index.html from dellweb3/build3d: direct link, hf CLI and curl.
- Browser
- Download file 76 kB
-
https://huggingface.co/spaces/dellweb3/build3d/resolve/main/app/static/index.html
- Command line
-
hf download hf://spaces/dellweb3/build3d/app/static/index.html
-
curl -L -o index.html https://huggingface.co/spaces/dellweb3/build3d/resolve/main/app/static/index.html
76 kB
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>建筑机器人绘图系统 · ArchRobot</title>
<style>
:root{ --red:#D6273B; --red2:#FCE9EA; --ink:#1B1F24; --sub:#5A6470; --line:#E4E8EE; --bg:#F5F7FA; --card:#FFFFFF; }
*{ margin:0; padding:0; box-sizing:border-box; }
body{ font-family:"Microsoft YaHei",system-ui,sans-serif; background:var(--bg); color:var(--ink); }
header{ background:var(--card); border-bottom:1px solid var(--line); padding:0 32px; display:flex; align-items:center; height:60px; gap:14px; position:sticky; top:0; z-index:9;}
.logo{ width:30px; height:30px; background:var(--red); border-radius:7px; display:flex; align-items:center; justify-content:center; color:#fff; font-weight:bold; font-size:15px;}
h1{ font-size:19px; letter-spacing:.5px;}
h1 small{ color:var(--sub); font-weight:normal; font-size:12px; margin-left:10px;}
nav{ margin-left:auto; display:flex; gap:4px; align-items:center;}
nav button{ border:none; background:none; padding:9px 16px; font-size:14px; color:var(--sub); cursor:pointer; border-radius:8px;}
nav button.active{ color:var(--red); background:var(--red2); font-weight:bold;}
.pill{ font-size:11px; color:#2FA35C; background:#E8F6EE; padding:4px 9px; border-radius:99px; margin-left:10px;}
.pill.bad{ color:var(--red); background:var(--red2);}
main{ max-width:1560px; margin:0 auto; padding:20px 32px 56px;}
.page{ display:none; } .page.show{ display:block; }
.grid-title{ font-size:13px; color:var(--sub); margin:6px 0 12px; display:flex; align-items:center; gap:8px;}
.grid-title b{ color:var(--ink); font-size:16px;}
.grid-title::before{ content:""; width:5px; height:18px; background:var(--red); border-radius:2px;}
.layout{ display:grid; grid-template-columns: 1fr 470px; gap:18px; align-items:start;}
/* 楼栋卡片 */
.blds{ display:grid; grid-template-columns:repeat(3,1fr); gap:12px;}
.bld{ background:var(--card); border:2px solid var(--line); border-radius:12px; padding:10px; cursor:pointer; transition:.15s;}
.bld:hover{ border-color:#EFA5A5; transform:translateY(-2px);}
.bld.sel{ border-color:var(--red); box-shadow:0 6px 18px rgba(214,39,59,.16);}
.bld .top{ display:flex; justify-content:space-between; align-items:baseline; margin-bottom:8px;}
.bld .top b{ font-size:14px;}
.bld .top span{ font-size:11px; color:var(--sub);}
.bld .strip{ display:grid; grid-template-columns:repeat(3,1fr); gap:3px;}
.bld .strip img{ width:100%; aspect-ratio:1.44; object-fit:cover; border:1px solid var(--line); border-radius:3px; background:#fff;}
.bld .strip img:nth-child(4){ grid-column:span 2; aspect-ratio:2.9; }
.bld .kv{ display:flex; gap:10px; margin-top:8px; font-size:11px; color:var(--sub);}
.bld .kv b{ color:var(--ink); font-size:12px;}
.badge-done{ background:var(--red); color:#fff; font-size:10px; padding:1px 7px; border-radius:99px;}
/* 详情面板 */
.panel{ background:var(--card); border:1px solid var(--line); border-radius:12px; padding:16px; position:sticky; top:76px;}
.panel h2{ font-size:15px; margin-bottom:10px; display:flex; align-items:center; gap:8px;}
.panel h2::before{ content:""; width:5px; height:16px; background:var(--red); border-radius:2px;}
#mainShot{ width:100%; aspect-ratio:1.44; object-fit:contain; background:#fff; border:1px solid var(--line); border-radius:8px;}
#shotRow{ display:grid; grid-template-columns:repeat(5,1fr); gap:5px; margin:8px 0 12px;}
#shotRow img{ width:100%; aspect-ratio:1.44; object-fit:cover; border:2px solid var(--line); border-radius:4px; cursor:pointer; background:#fff;}
#shotRow img.on{ border-color:var(--red);}
.meta{ display:grid; grid-template-columns:1fr 1fr; gap:6px; font-size:12px; margin-bottom:12px;}
.meta div{ background:var(--bg); border-radius:7px; padding:7px 9px;}
.meta span{ color:var(--sub); font-size:10px; display:block;}
.btn{ width:100%; border:none; border-radius:9px; padding:12px; font-size:14px; font-weight:bold; cursor:pointer; color:#fff; background:var(--red); display:block; text-align:center; text-decoration:none;}
.btn:hover{ filter:brightness(1.08);}
.btn:disabled{ background:#C9CFD8; cursor:not-allowed;}
.btn.ghost{ background:var(--card); color:var(--ink); border:1px solid var(--line); font-weight:normal;}
.btn.ghost:hover{ border-color:var(--red); color:var(--red);}
.btnrow{ display:flex; gap:7px; margin-top:7px;}
.btnrow .btn{ flex:1;}
#status{ margin-top:10px; font-size:12.5px; color:var(--sub); min-height:18px;}
#status .dot{ display:inline-block; width:8px; height:8px; border-radius:50%; background:#C9CFD8; margin-right:6px;}
#status.running .dot{ background:#E8A13B; animation:blink 1s infinite;}
#status.done .dot{ background:#2FA35C;} #status.error .dot{ background:var(--red);}
@keyframes blink{ 50%{opacity:.3}}
#progress{ height:4px; background:var(--line); border-radius:99px; overflow:hidden; margin-top:8px; display:none;}
#progress i{ display:block; height:100%; width:0; background:var(--red); transition:width .6s;}
#log{ margin-top:8px; font-family:Consolas,monospace; font-size:10.5px; color:var(--sub); background:var(--bg); border-radius:7px; padding:7px 9px; max-height:80px; overflow:auto; display:none; white-space:pre-wrap;}
/* 3D 查看器 */
.viewer-wrap{ margin-top:22px; background:var(--card); border:1px solid var(--line); border-radius:12px; overflow:hidden;}
.vhead{ display:flex; align-items:center; gap:10px; padding:12px 16px; border-bottom:1px solid var(--line); flex-wrap:wrap;}
.vhead h3{ font-size:15px; display:flex; align-items:center; gap:8px;}
.vhead h3::before{ content:""; width:5px; height:16px; background:var(--red); border-radius:2px;}
.vhead .tip{ font-size:11.5px; color:var(--sub); margin-left:auto;}
.vhead .chip{ font-size:11px; border:1px solid var(--line); border-radius:99px; padding:4px 10px; cursor:pointer; color:var(--sub); user-select:none;}
.vhead .chip.on{ border-color:var(--red); color:var(--red); background:var(--red2);}
.vgrid{ display:grid; grid-template-columns:1fr 300px;}
#viewer{ position:relative; height:520px; background:linear-gradient(#eef2f7,#f8fafc);}
#viewer canvas{ display:block; width:100%; height:100%;}
#vhint{ position:absolute; left:14px; bottom:12px; font-size:11.5px; color:#6b7787; background:rgba(255,255,255,.82); padding:5px 9px; border-radius:6px;}
#vempty{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; flex-direction:column; gap:8px; color:#8b95a3; font-size:13px; background:#f2f5f9;}
#props{ border-left:1px solid var(--line); padding:14px; height:520px; overflow:auto;}
#props h4{ font-size:13px; margin-bottom:8px; color:var(--sub); font-weight:normal;}
#propList{ font-size:12px;}
#propList .row{ display:flex; justify-content:space-between; padding:6px 0; border-bottom:1px dashed var(--line);}
#propList .row span:first-child{ color:var(--sub);}
#propList .row b{ font-weight:normal;}
.sel-card{ background:var(--red2); border:1px solid #F3C7CB; border-radius:8px; padding:10px 12px; margin-bottom:10px;}
.sel-card .t{ font-size:13px; font-weight:bold; color:#8E1626; margin-bottom:6px;}
.stat{ display:grid; grid-template-columns:1fr 1fr; gap:6px; margin-top:10px;}
.stat div{ background:var(--bg); border-radius:7px; padding:7px 9px; font-size:11px; color:var(--sub);}
.stat b{ display:block; font-size:15px; color:var(--ink);}
.empty-tip{ color:#9aa3b0; font-size:12px; line-height:1.9;}
/* 构件清单:整行可点,点了就聚焦(内墙会顺手开透视) */
.comp-row{ display:flex; justify-content:space-between; gap:8px; padding:4px 5px;
border-bottom:1px dashed #E4E8EE; cursor:pointer; border-radius:4px;}
.comp-row:hover{ background:var(--red2);}
.comp-row.active{ background:var(--red2); box-shadow:inset 2px 0 0 var(--red);}
.comp-row .cc{ color:#5A6470;}
.comp-row .ct{ color:var(--ink);}
.comp-row .ct.inner{ color:var(--red);}
/* 录屏聚焦模式:只留查看器 */
body.focus-viewer #page-work .layout{ display:none; }
body.focus-viewer #page-work .showcase{ display:none; }
body.focus-viewer #page-work .chat-wrap{ display:none; }
body.focus-viewer #page-work .viewer-wrap{ margin-top:6px; }
/* 录屏聚焦模式:只留对话(给演示片用,气泡能放大到看得清) */
body.focus-chat #page-work .layout{ display:none; }
body.focus-chat #page-work .showcase{ display:none; }
body.focus-chat #page-work .viewer-wrap{ display:none; }
body.focus-chat .chat-wrap{ margin-top:10px; }
body.focus-chat .chat-main{ height:640px; }
body.focus-chat .chat-log{ font-size:14.5px; }
body.focus-chat .chat-suggest .q{ font-size:13px; }
/* 图纸对话 */
.chat-wrap{ margin-top:22px; background:var(--card); border:1px solid var(--line); border-radius:12px; overflow:hidden;}
.chat-body{ display:grid; grid-template-columns:1fr 300px;}
.chat-main{ display:flex; flex-direction:column; height:452px;}
.chat-log{ flex:1; overflow:auto; padding:14px 16px; background:linear-gradient(#fbfcfd,#f6f8fb);}
.msg{ display:flex; margin-bottom:12px;}
.msg .bub{ max-width:88%; padding:10px 13px; border-radius:10px; font-size:13px; line-height:1.85; white-space:pre-wrap; word-break:break-word;}
.msg.u{ justify-content:flex-end;}
.msg.u .bub{ background:var(--red); color:#fff; border-bottom-right-radius:3px;}
.msg.a .bub{ background:#fff; border:1px solid var(--line); border-bottom-left-radius:3px;}
/* 气泡底部的小字:用时 / token / 引用,客户不关心是哪个模型,就不占地方 */
.msg.a .bub .meta{ display:block; grid-template-columns:none; gap:0; margin:8px 0 0; padding-top:7px;
border-top:1px dashed var(--line); font-size:10px; color:#9aa3b0; line-height:1.7;}
.msg.a .bub .meta .tag{ display:inline; background:none; border:none; padding:0; color:#9aa3b0; font-size:10px;}
/* 引用:可点,点开看到底取自哪个文件哪一块 */
.msg.a .bub .meta .cite, .cite{ display:inline-block; padding:1px 7px; margin:2px 4px 0 0; border-radius:10px;
border:1px solid #E3C9CD; background:#FCEFF1; color:#8E1626; font-size:10.5px; cursor:pointer;}
.cite:hover{ background:#F8DDE1;}
#citeMask{ position:fixed; inset:0; background:rgba(23,32,45,.42); display:none; z-index:80;}
#citeMask.on{ display:block;}
#citeBox{ position:fixed; left:50%; top:9vh; transform:translateX(-50%); width:min(760px,92vw);
max-height:78vh; overflow:auto; background:#fff; border-radius:12px; z-index:81; display:none;
box-shadow:0 18px 50px rgba(20,30,45,.24);}
#citeBox.on{ display:block;}
#citeBox header{ display:flex; justify-content:space-between; align-items:center;
padding:14px 18px; border-bottom:1px solid var(--line); font-size:13px; font-weight:bold;}
#citeBox header span{ font-weight:normal; color:var(--sub); font-size:11.5px; cursor:pointer;}
.cite-item{ padding:12px 18px; border-bottom:1px dashed var(--line);}
.cite-item.on{ background:#FFF7F8;}
.cite-item .h{ font-size:12.5px; color:var(--ink); margin-bottom:4px;}
.cite-item .h b{ color:#8E1626;}
.cite-item .f{ font-size:11px; color:#5A6470; font-family:Consolas,monospace; margin-bottom:6px;}
.cite-item pre{ margin:0; white-space:pre-wrap; font-size:11.5px; line-height:1.75; color:#3d4753;
background:#F7F9FC; border-radius:7px; padding:8px 10px;}
.cite-item .why{ font-size:10.5px; color:#9aa3b0; margin-top:5px;}
.msg.a .bub .meta b{ color:var(--red); font-weight:normal;}
.msg.a .bub .meta .tag{ display:inline-block; background:var(--red2); color:#8E1626; border-radius:99px; padding:1px 9px; margin-right:7px; font-size:10.5px;}
.msg.a .bub .meta span[title]{ cursor:help; border-bottom:1px dashed var(--line);}
.msg.a .bub.err{ border-color:#F3C7CB; background:var(--red2); color:#8E1626;}
.typing{ font-size:12.5px; color:var(--sub);}
.typing i{ display:inline-block; width:5px; height:5px; border-radius:50%; background:var(--red); margin-right:3px; animation:blink 1s infinite;}
.chat-suggest{ display:flex; flex-wrap:wrap; gap:6px; padding:10px 16px; border-top:1px solid var(--line); background:#fff;}
.chat-suggest .q{ font-size:12px; border:1px solid var(--line); border-radius:99px; padding:5px 11px; cursor:pointer; color:var(--sub); background:var(--bg); transition:.15s;}
.chat-suggest .q:hover{ border-color:var(--red); color:var(--red); background:var(--red2);}
.chat-input{ display:flex; gap:8px; padding:10px 16px 14px; border-top:1px solid var(--line); align-items:flex-end; background:#fff;}
.chat-input textarea{ flex:1; resize:none; border:1px solid var(--line); border-radius:9px; padding:9px 11px; font-size:13px; font-family:inherit; line-height:1.6; outline:none;}
.chat-input textarea:focus{ border-color:var(--red);}
.chat-input select{ border:1px solid var(--line); border-radius:9px; padding:9px 9px; font-size:12.5px; background:#fff; color:var(--ink); outline:none; max-width:168px;}
.chat-input .btn{ width:auto; padding:10px 18px;}
.chat-input .gate{ display:flex; align-items:center; gap:4px; font-size:11.5px; color:var(--sub); cursor:pointer; user-select:none;}
.chat-input .gate input{ accent-color:var(--red); }
.patchbox{ margin-top:6px; border-top:1px dashed var(--line); padding-top:6px; font-size:11.5px; color:var(--sub);}
.patchbox b{ color:var(--red); font-weight:normal;}
.chat-side{ border-left:1px solid var(--line); padding:14px 16px; font-size:12px; color:var(--sub); line-height:1.9; background:#fff; overflow:auto;}
.chat-side h4{ font-size:12px; color:var(--ink); margin:12px 0 5px; font-weight:bold;}
.chat-side h4:first-child{ margin-top:0;}
.chat-side ul{ padding-left:16px;}
.chat-side code{ font-family:Consolas,monospace; color:var(--red); font-size:11.5px;}
.chat-side .kbst{ background:var(--bg); border-radius:8px; padding:8px 10px; font-size:11.5px; line-height:1.8;}
/* 展示区 */
.showcase{ margin-top:22px; background:var(--card); border:1px solid var(--line); border-radius:12px; padding:20px 22px;}
.showcase h3{ font-size:16px; margin-bottom:4px; display:flex; align-items:center; gap:8px;}
.showcase h3::before{ content:""; width:5px; height:18px; background:var(--red); border-radius:2px;}
.showcase p.desc{ color:var(--sub); font-size:12.5px; margin:8px 0 14px; line-height:1.75;}
.cmp{ display:grid; grid-template-columns:repeat(4,1fr); gap:10px;}
.cmp figure{ background:var(--bg); border-radius:9px; padding:8px; text-align:center;}
.cmp img{ width:100%; border-radius:5px; background:#fff; aspect-ratio:1.44; object-fit:cover;}
.cmp figcaption{ font-size:11px; color:var(--sub); margin-top:6px;}
.cmp figcaption b{ color:var(--red);}
/* 演示片已从界面移除,视频作为独立交付物存放(不做站内播放) */
.warn{ background:var(--red2); border:1px solid #F3C7CB; color:#8E1626; border-radius:10px; padding:12px 16px; font-size:13px; margin:14px 0; display:none; line-height:1.7;}
.warn b{ display:block; margin-bottom:4px;}
/* 架构 / 闭环 */
.sheet{ background:var(--card); border:1px solid var(--line); border-radius:12px; padding:24px; margin-bottom:16px;}
.sheet h3{ font-size:17px; margin-bottom:6px;}
.sheet p.desc{ color:var(--sub); font-size:13px; margin-bottom:16px; line-height:1.75;}
.sheet p.desc b{ color:var(--ink);}
.loop{ display:grid; grid-template-columns:repeat(6,1fr); gap:10px; margin:18px 0 8px;}
.step{ background:var(--bg); border-radius:10px; padding:14px; position:relative; font-size:12.5px; line-height:1.7;}
.step b{ display:block; color:var(--red); font-size:12px; margin-bottom:6px;}
.step .n{ position:absolute; top:8px; right:10px; font-size:24px; font-weight:bold; color:#F0D3D6;}
.step.hot{ background:var(--red2); border:1px solid #F3C7CB;}
.arrow{ text-align:center; color:var(--red); font-size:19px; margin:2px 0 14px;}
.kv{ display:grid; grid-template-columns:repeat(4,1fr); gap:10px; margin-top:14px;}
.kv div{ background:var(--bg); border-radius:8px; padding:10px 12px; font-size:12px; color:var(--sub);}
.kv b{ display:block; font-size:17px; color:var(--ink); margin-bottom:2px;}
table.api{ width:100%; border-collapse:collapse; font-size:12.5px; margin-top:8px;}
table.api th,table.api td{ border-bottom:1px solid var(--line); padding:8px 10px; text-align:left;}
table.api th{ color:var(--sub); font-weight:normal; background:var(--bg);}
table.api code{ font-family:Consolas,monospace; color:var(--red);}
</style>
</head>
<body>
<header>
<div class="logo">建</div>
<h1>建筑机器人绘图系统<small>ArchRobot · 机器人测绘 → 多视角 2D 图纸 → Agent 编排 → 3D 模型</small></h1>
<span class="pill" id="health">检测本地服务中…</span>
<nav>
<button class="active" data-page="work">工作台</button>
<button data-page="arch">系统架构</button>
<button data-page="loop">业务闭环</button>
</nav>
</header>
<main>
<!-- 工作台 -->
<section class="page show" id="page-work">
<div class="warn" id="warnBox">
<b>当前不是通过本地服务打开</b>
地址栏应为 <code>http://127.0.0.1:8765/</code>。请双击 <code>D:\blend\app\start_server.bat</code>,
不要直接双击 index.html(file:// 协议禁止访问接口,点任何按钮都会报 Failed to fetch)。
</div>
<div class="layout">
<div>
<div class="grid-title"><b>图纸库</b>6 栋 · 每栋 5 个视角,共 30 张 · 点击选择</div>
<div class="blds" id="blds"></div>
</div>
<aside class="panel">
<h2 id="panelTitle">楼栋详情</h2>
<img id="mainShot" src="" alt="选择楼栋">
<div id="shotRow"></div>
<div class="meta" id="meta"></div>
<button class="btn" id="gen" disabled>调用 Blender 生成 3D 模型</button>
<div id="status"><span class="dot"></span><span id="statusText">等待选择楼栋</span></div>
<div id="progress"><i></i></div>
<div id="log"></div>
<div class="btnrow" id="resultRow" style="display:none">
<a class="btn ghost" id="dl" href="#" download>下载 .blend</a>
<button class="btn ghost" id="open">在 Blender 打开</button>
</div>
</aside>
</div>
<div class="viewer-wrap">
<div class="vhead">
<h3>三维模型 · 可拖动查看</h3>
<span class="chip" id="chipSpin">自动旋转</span>
<span class="chip" id="chipWire">线框</span>
<span class="chip" id="chipXray" title="外墙半透明,看内部隔墙与洞口">透视</span>
<span class="chip" id="chipFit">重置视角</span>
<span class="tip">左键拖动旋转 · 滚轮缩放 · 右键平移 · 点构件看参数并自动聚焦(内墙自动开透视)</span>
</div>
<div class="vgrid">
<div id="viewer">
<div id="vempty">尚无模型<br><span style="font-size:11.5px">左侧选择楼栋并点击「生成 3D 模型」</span></div>
<div id="vhint">模型来自 Blender 导出的 glTF,可 360° 旋转</div>
</div>
<aside id="props">
<h4>构件参数</h4>
<div class="sel-card" id="selCard" style="display:none">
<div class="t" id="selTitle">—</div>
<div id="selBody"></div>
</div>
<div class="empty-tip" id="propEmpty">点击模型中的任意构件,这里会显示它的真实参数(编号 / 类型 / 材质 / 尺寸 / 楼层)。</div>
<div class="stat" id="statBox"></div>
<h4 style="margin-top:14px">构件清单</h4>
<div id="compList" style="max-height:250px;overflow:auto;font-size:11.5px"></div>
</aside>
</div>
</div>
<div class="chat-wrap">
<div class="vhead">
<h3>图纸对话 · 知识库增强</h3>
<span class="chip" id="chatReset">清空对话</span>
<span class="tip" id="chatTip">正在加载引擎…</span>
</div>
<div class="chat-body">
<div class="chat-main">
<div class="chat-log" id="chatLog"></div>
<div class="chat-suggest" id="chatSuggest"></div>
<div class="chat-input">
<textarea id="chatText" rows="2" placeholder="问当前这栋楼:几层?洞口开在哪几个面?五个视角各管什么?"></textarea>
<div style="display:flex;flex-direction:column;gap:6px">
<select id="chatEngine" title="切换大模型引擎"></select>
<label class="gate" title="勾选后,这句话按「改参数」解析:大模型只出参数补丁,几何仍由 bpy 重建">
<input type="checkbox" id="chatBuild"> 改参数并重建
</label>
<button class="btn" id="chatSend">发送</button>
</div>
</div>
</div>
<aside class="chat-side">
<h4>怎么问最准</h4>
<ul>
<li>带上楼栋号可跨楼对比:<code>BLD-003 和 BLD-001 哪个面积大</code></li>
<li>问数字要问全集:<code>洞口一共几个,各在哪个面</code></li>
<li>问口径走知识库:<code>现在能交 IFC 吗</code></li>
</ul>
<h4>检索范围</h4>
<div class="kbst" id="kbStat">知识库加载中…</div>
<h4>为什么数得准</h4>
<div style="font-size:11.5px">数字全部来自图纸 JSON 与模型属性表的检索片段,大模型只负责组织语言,不算数、不推断。每条回答下方会列出命中的知识块,可回溯核对。</div>
</aside>
</div>
</div>
<div class="showcase">
<h3>同一份数据,两端产物</h3>
<p class="desc">左侧是 Agent 依据 5 个视角生成的二维图纸,右侧是 Blender 按同一份 JSON 自动建出的三维模型。上方查看器里的模型就是 Blender 导出的 glTF 文件本身——可以拖动、可以点构件看参数,不是截图。</p>
<div class="cmp">
<figure><img src="/static/thumbs/BLD-001-PLAN-01.png" alt="二维图纸"><figcaption><b>二维</b> · 首层平面</figcaption></figure>
<figure><img src="/output/BLD-001/render.png" alt="轴测渲染"><figcaption><b>三维</b> · 轴测渲染</figcaption></figure>
<figure><img src="/output/BLD-001/render_front.png" alt="正立面渲染"><figcaption><b>三维</b> · 正立面渲染</figcaption></figure>
<figure><img src="/output/BLD-001/render_top.png" alt="俯视渲染"><figcaption><b>三维</b> · 俯视渲染</figcaption></figure>
</div>
</div>
</section>
<!-- 系统架构 -->
<section class="page" id="page-arch">
<div class="sheet">
<h3>系统架构 · 六层,各管一件事</h3>
<p class="desc">对齐《中建东方 · 3D 建模 Agent 方案》的六层结构。本 Demo 落地的是 L2 解析(多视角图纸)、L4 编排(本地服务)、L5 执行(Blender 无头引擎)、L6 交付(GLB / .blend / 参数表)四层,L1 接入与 L3 知识层以参数化图纸库与构件规则替代。<b>服务只监听 127.0.0.1,数据不出本机。</b></p>
<svg viewBox="0 0 980 470" width="100%">
<defs>
<marker id="ah" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto">
<path d="M0,0 L9,4.5 L0,9 z" fill="#D6273B"/>
</marker>
</defs>
<rect x="24" y="30" width="196" height="96" rx="10" fill="#FFFFFF" stroke="#E4E8EE" stroke-width="2"/>
<rect x="24" y="30" width="196" height="28" rx="10" fill="#FCE9EA"/>
<text x="122" y="49" text-anchor="middle" font-size="13.5" font-weight="bold" fill="#D6273B">L1 接入</text>
<text x="122" y="76" text-anchor="middle" font-size="11.5" fill="#1B1F24">机器人测绘点云</text>
<text x="122" y="95" text-anchor="middle" font-size="11.5" fill="#1B1F24">多视角 2D 图纸</text>
<text x="122" y="114" text-anchor="middle" font-size="11.5" fill="#1B1F24">做法表 / 图集</text>
<rect x="256" y="30" width="196" height="96" rx="10" fill="#FFFFFF" stroke="#E4E8EE" stroke-width="2"/>
<rect x="256" y="30" width="196" height="28" rx="10" fill="#FCE9EA"/>
<text x="354" y="49" text-anchor="middle" font-size="13.5" font-weight="bold" fill="#D6273B">L2 解析</text>
<text x="354" y="76" text-anchor="middle" font-size="11.5" fill="#1B1F24">5 视角图纸解析</text>
<text x="354" y="95" text-anchor="middle" font-size="11.5" fill="#1B1F24">墙体 / 洞口 / 层高</text>
<text x="354" y="114" text-anchor="middle" font-size="11.5" fill="#1B1F24">约束点 3,690 个</text>
<rect x="488" y="30" width="196" height="96" rx="10" fill="#FFFFFF" stroke="#E4E8EE" stroke-width="2"/>
<rect x="488" y="30" width="196" height="28" rx="10" fill="#FCE9EA"/>
<text x="586" y="49" text-anchor="middle" font-size="13.5" font-weight="bold" fill="#D6273B">L3 知识</text>
<text x="586" y="76" text-anchor="middle" font-size="11.5" fill="#1B1F24">构件命名规范</text>
<text x="586" y="95" text-anchor="middle" font-size="11.5" fill="#1B1F24">材质 / 做法规则</text>
<text x="586" y="114" text-anchor="middle" font-size="11.5" fill="#1B1F24">参数优先级</text>
<rect x="720" y="30" width="236" height="96" rx="10" fill="#FFFFFF" stroke="#E4E8EE" stroke-width="2"/>
<rect x="720" y="30" width="236" height="28" rx="10" fill="#FCE9EA"/>
<text x="838" y="49" text-anchor="middle" font-size="13.5" font-weight="bold" fill="#D6273B">L4 编排 · 本地服务</text>
<text x="838" y="76" text-anchor="middle" font-size="11.5" fill="#1B1F24">Python HTTP :8765</text>
<text x="838" y="95" text-anchor="middle" font-size="11.5" fill="#1B1F24">任务队列 / 状态机</text>
<text x="838" y="114" text-anchor="middle" font-size="11.5" fill="#1B1F24">pending → running → done</text>
<rect x="24" y="196" width="452" height="104" rx="10" fill="#FFFFFF" stroke="#E4E8EE" stroke-width="2"/>
<rect x="24" y="196" width="452" height="28" rx="10" fill="#EDF1F6"/>
<text x="250" y="215" text-anchor="middle" font-size="13.5" font-weight="bold" fill="#3C4A5C">L5 执行 · Blender 无头引擎</text>
<text x="250" y="244" text-anchor="middle" font-size="11.5" fill="#1B1F24">bpy 墙体拉伸 · 布尔开洞 · 门窗构件 · 坡屋顶</text>
<text x="250" y="264" text-anchor="middle" font-size="11.5" fill="#1B1F24">每个构件写入编号 / 类型 / 材质 / 尺寸 / 楼层</text>
<text x="250" y="284" text-anchor="middle" font-size="11.5" fill="#1B1F24">Cycles CPU 三视角渲染(轴测 / 正立面 / 俯视)</text>
<rect x="504" y="196" width="452" height="104" rx="10" fill="#FFFFFF" stroke="#E4E8EE" stroke-width="2"/>
<rect x="504" y="196" width="452" height="28" rx="10" fill="#EDF1F6"/>
<text x="730" y="215" text-anchor="middle" font-size="13.5" font-weight="bold" fill="#3C4A5C">L6 交付 · 一个交付包</text>
<text x="730" y="244" text-anchor="middle" font-size="11.5" fill="#1B1F24">model.glb(网页可拖动、带构件参数)</text>
<text x="730" y="264" text-anchor="middle" font-size="11.5" fill="#1B1F24">model.blend(设计师继续编辑)</text>
<text x="730" y="284" text-anchor="middle" font-size="11.5" fill="#1B1F24">render.png ×3 + model_info.json(参数表)</text>
<line x1="220" y1="78" x2="250" y2="78" stroke="#D6273B" stroke-width="2" marker-end="url(#ah)"/>
<line x1="452" y1="78" x2="482" y2="78" stroke="#D6273B" stroke-width="2" marker-end="url(#ah)"/>
<line x1="684" y1="78" x2="714" y2="78" stroke="#D6273B" stroke-width="2" marker-end="url(#ah)"/>
<line x1="586" y1="130" x2="586" y2="160" stroke="#D6273B" stroke-width="2"/>
<line x1="586" y1="160" x2="250" y2="160" stroke="#D6273B" stroke-width="2"/>
<line x1="250" y1="160" x2="250" y2="190" stroke="#D6273B" stroke-width="2" marker-end="url(#ah)"/>
<line x1="586" y1="160" x2="730" y2="160" stroke="#D6273B" stroke-width="2"/>
<line x1="730" y1="160" x2="730" y2="190" stroke="#D6273B" stroke-width="2" marker-end="url(#ah)"/>
<rect x="24" y="340" width="932" height="104" rx="10" fill="#FCE9EA" stroke="#F3C7CB"/>
<text x="44" y="364" font-size="13" font-weight="bold" fill="#8E1626">多视角为什么更准</text>
<text x="44" y="388" font-size="11.5" fill="#1B1F24">平面图约束 XY 与洞口位置;正立面约束层高、窗台高、檐口标高;侧立面约束山墙轮廓与屋面坡度;剖面约束楼板厚度、墙厚与内部隔墙。</text>
<text x="44" y="410" font-size="11.5" fill="#1B1F24">5 个视角相互校验,任一视角缺失都会让模型在该自由度上"猜"——这与机器人从多个方向打点、点越多解算越稳是同一个道理。</text>
<text x="44" y="432" font-size="11.5" fill="#8E1626">本 Demo:6 栋 × 5 视角 = 30 张图纸,累计 3,690 个约束点。</text>
</svg>
</div>
<div class="sheet">
<h3>Agent 的边界:哪里调大模型,哪里坚决不调</h3>
<p class="desc">先把话说清楚:<b>本 Demo 跑起来没有调用任何大模型</b>。它是 Agent 的骨架——任务编排、队列、状态机、工具调用(subprocess 拉起 Blender)、失败重试、全过程留痕;执行体是确定性算法 bpy。<b>大模型只在"读不懂的语义"环节才有位置,几何生成不需要猜。</b></p>
<table class="api">
<tr><th style="width:220px">环节</th><th style="width:360px">判断 / 执行方式</th><th>本 Demo 现状</th></tr>
<tr><td>图纸清洗、图元识别</td><td>规则 + 几何算法,高置信自动、中置信给人确认</td><td>参数化图纸直接可解析,不调模型</td></tr>
<tr><td>几何建模(墙 / 洞口 / 屋面)</td><td>bpy 确定性执行,同样的输入必得同样的模型</td><td><b>已实现,不调模型</b></td></tr>
<tr><td>参数对齐(材质 / 做法 / 编号)</td><td>规则表 + 优先级(说明 > 做法表 > 标注 > 默认值)</td><td>规则内置,不调模型</td></tr>
<tr><td>中置信歧义(识别不了)</td><td>大模型读做法表与图集,给候选类型 + 依据,人点一下确认</td><td><b style="color:#D6273B">预留接口,当前未启用</b></td></tr>
<tr><td>自然语言问答与查改</td><td>大模型 + 工具调用,读 IFC 属性后作答</td><td><b style="color:#D6273B">预留接口,当前未启用</b></td></tr>
<tr><td>冲突裁决</td><td>人裁决,裁决结果回写成规则</td><td>预留</td></tr>
</table>
<p class="desc" style="margin:14px 0 0">两条纪律:一、<b>原始几何与属性数据不进大模型上下文</b>,模型只读结构化摘要;二、<b>每层可单独替换</b>,接不接大模型都能跑,接了只是把中置信项从"人工翻图"变成"点一下确认"。</p>
</div>
<div class="sheet">
<h3>接口清单 · 前端与编排层的契约</h3>
<p class="desc">全部为 HTTP 明文接口,仅绑定 127.0.0.1,不依赖任何外部服务与第三方库(three.js 已本地化)。</p>
<table class="api">
<tr><th style="width:250px">接口</th><th style="width:70px">方法</th><th>说明</th></tr>
<tr><td><code>/api/health</code></td><td>GET</td><td>健康检查:Blender 是否存在、楼栋数、图纸数、媒体目录</td></tr>
<tr><td><code>/api/buildings</code></td><td>GET</td><td>6 栋楼 + 每栋 5 个视角(编号 / 名称 / 约束说明 / 约束点数)</td></tr>
<tr><td><code>/api/state</code></td><td>GET</td><td>一次性返回所有楼栋建模状态,用于卡片打"已建模"标记</td></tr>
<tr><td><code>/api/generate</code></td><td>POST</td><td>下发建模任务,工作线程串行调用 Blender</td></tr>
<tr><td><code>/api/status/<id></code></td><td>GET</td><td>轮询任务状态;服务重启后从磁盘产物自动恢复 done</td></tr>
<tr><td><code>/api/model/<id></code></td><td>GET</td><td>构件清单与统计(供参数面板与构件列表)</td></tr>
<tr><td><code>/output/<id>/model.glb</code></td><td>GET</td><td>网页 3D 查看器加载的真实模型文件</td></tr>
<tr><td><code>/output/<id>/model.blend</code></td><td>GET</td><td>下载可编辑模型文件</td></tr>
</table>
</div>
</section>
<!-- 业务闭环 -->
<section class="page" id="page-loop">
<div class="sheet">
<h3>业务闭环 · 六个环节,第四环是卡点</h3>
<p class="desc">现场作业链是「测绘 → 出图 → 核审 → <b>2D 转 3D</b> → 参数确认 → 业务可用」。前三个环节都有成熟工具和明确责任人;第四环没有工具、没有标准动作,是整条链上唯一还靠"人读图"的环节——本 Demo 就是用 Agent 补这一环。</p>
<div class="loop">
<div class="step"><span class="n">1</span><b>现场测绘</b>机器人进场,采集点云、控制点与轴线</div>
<div class="step"><span class="n">2</span><b>2D 出图</b>在 CAD 上出平立剖,沿用既有制图标准</div>
<div class="step"><span class="n">3</span><b>工程师核审</b>尺寸、构造、做法逐项核对并签字</div>
<div class="step hot"><span class="n">4</span><b>2D 转 3D</b>Agent 读 5 个视角,重建墙柱板、楼层、轴网与洞口</div>
<div class="step"><span class="n">5</span><b>参数确认</b>材质、做法、专业接口写进构件属性</div>
<div class="step"><span class="n">6</span><b>业务可用</b>进入算量、加工、交底与验收</div>
</div>
<div class="arrow">↻ 第 5 步改参数后回到第 4 步,模型与图纸同步迭代</div>
<div class="kv">
<div><b>30 张</b>多视角二维图纸</div>
<div><b>3,690 个</b>几何约束点</div>
<div><b>1 次点击</b>触发全套建模渲染</div>
<div><b>100%</b>.blend / .glb 可编辑交付</div>
</div>
</div>
<div class="sheet">
<h3>与 PPT 方案的对应关系</h3>
<p class="desc">本 Demo 是《中建东方 · 3D 建模 Agent 方案》中「L2 解析 + L4 编排 + L5 执行 + L6 交付」的最小可跑通实现:编排层负责任务排队与状态机,执行层用 bpy 做确定性建模,交付层直接给出网页可查看的 glTF 与可继续编辑的 .blend。原始几何参数全程不进大模型上下文——<b>模型只认结构化输入</b>,与方案里两条设计纪律一致。</p>
</div>
</section>
</main>
<script src="/static/lib/three.min.js"></script>
<script src="/static/lib/OrbitControls.js"></script>
<script src="/static/lib/GLTFLoader.js"></script>
<script>
let BLDGS = [], SEL = null, timer = null, tick = 0;
const $ = s => document.querySelector(s);
/* 统一请求封装:服务重启/短暂抖动时自动重试,避免把 Failed to fetch 甩给用户 */
async function api(url, opt, retry = 4){
let last;
for (let i = 0; i < retry; i++){
try {
const r = await fetch(url, opt);
if (r.ok) return r;
last = new Error('HTTP ' + r.status);
if (r.status < 500) throw last; // 4xx 不重试
} catch(e){ last = e; }
await new Promise(s => setTimeout(s, 700));
}
throw last;
}
document.querySelectorAll('nav button').forEach(b => b.onclick = () => {
document.querySelectorAll('nav button').forEach(x => x.classList.remove('active'));
document.querySelectorAll('.page').forEach(x => x.classList.remove('show'));
b.classList.add('active');
$('#page-' + b.dataset.page).classList.add('show');
if (b.dataset.page === 'work' && renderer) resizeViewer();
});
/* ---------------- 3D 查看器 ---------------- */
let renderer, scene, camera, controls, root = null, raycaster, mouse, selected = null,
spin = false, wire = false, compMeshes = [], compByCode = {}, xray = false,
camFly = null, modelLoading = false, pendingFocus = null, modelReadyAt = 0;
const HL = 0xd6273b;
function initViewer(){
const box = $('#viewer');
renderer = new THREE.WebGLRenderer({antialias:true, alpha:false, preserveDrawingBuffer:true});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(box.clientWidth, box.clientHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.shadowMap.enabled = false;
box.insertBefore(renderer.domElement, box.firstChild);
scene = new THREE.Scene();
scene.background = new THREE.Color(0xeef2f7);
camera = new THREE.PerspectiveCamera(45, box.clientWidth / box.clientHeight, 0.1, 500);
camera.position.set(24, 18, 30);
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.08;
controls.minDistance = 3;
controls.maxDistance = 160;
controls.maxPolarAngle = Math.PI / 2.02;
controls.addEventListener('start', () => { camFly = null; }); // 用户一拖就交还控制权
scene.add(new THREE.HemisphereLight(0xffffff, 0x9fb0c4, 0.95));
const d1 = new THREE.DirectionalLight(0xffffff, 1.15); d1.position.set(18, 26, 16); scene.add(d1);
const d2 = new THREE.DirectionalLight(0xffffff, 0.45); d2.position.set(-16, 12, -14); scene.add(d2);
const grid = new THREE.GridHelper(120, 60, 0xc6d0dc, 0xdde4ec);
grid.position.y = -0.16; scene.add(grid);
raycaster = new THREE.Raycaster(); mouse = new THREE.Vector2();
renderer.domElement.addEventListener('pointerdown', e => { mouse.down = {x:e.clientX, y:e.clientY}; });
renderer.domElement.addEventListener('pointerup', onPick);
window.addEventListener('resize', resizeViewer);
animate();
// rAF 在后台标签页 / 无头截图里会被节流甚至停掉,兜底按 ~5fps 补帧,
// 保证「点了构件镜头飞过去」在切走再切回时画面不会停在半路。
setInterval(() => {
if (performance.now() - lastPaint > 220) paintFrame();
}, 220);
}
function resizeViewer(){
if (!renderer) return;
const box = $('#viewer');
const w = box.clientWidth, h = box.clientHeight;
if (!w || !h) return;
renderer.setSize(w, h);
camera.aspect = w / h;
camera.updateProjectionMatrix();
}
let lastPaint = 0;
function paintFrame(){
if (!renderer) return;
if (root && spin) root.rotation.y += 0.0045;
if (camFly) stepFly();
controls.update();
renderer.render(scene, camera);
lastPaint = performance.now();
}
function animate(){
requestAnimationFrame(animate);
paintFrame();
}
/* ---------- 聚焦:选中构件后自动绕到它正面 ---------- */
function stepFly(){
const t = Math.min(1, (performance.now() - camFly.t0) / camFly.dur);
const e = t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2; // easeInOutQuad
camera.position.lerpVectors(camFly.from, camFly.to, e);
controls.target.lerpVectors(camFly.tgtFrom, camFly.tgtTo, e);
if (t >= 1){ camFly = null; }
}
function flyTo(pos, target, dur){
dur = dur || 900;
camFly = {from: camera.position.clone(), to: pos.clone(),
tgtFrom: controls.target.clone(), tgtTo: target.clone(),
t0: performance.now(), dur: dur};
// rAF 在后台标签页/无头浏览器里会被节流甚至暂停,给一个到点兜底,
// 否则镜头会停在半路(截图、录屏、切走再切回都会踩到)。
clearTimeout(flyTo._t);
flyTo._t = setTimeout(() => {
if (!camFly) return;
camera.position.copy(camFly.to);
controls.target.copy(camFly.tgtTo);
camFly = null; DBN.fly++;
controls.update();
if (renderer) renderer.render(scene, camera); // rAF 停摆时也要出最后一帧
}, dur + 220);
}
function isInnerCode(c){
return isInnerComp({'构件类型': (c && (c.type || c['构件类型'])) || ''});
}
/* 内墙/隔墙:外面包着外墙,不透视就看不见里面的洞口 */
function isInnerComp(ud){
const t = (ud && (ud['构件类型'] || '')) + '';
return /内墙|隔墙|室内|楼梯|门洞/.test(t);
}
/* 透视:只把「外围护」(外墙 / 山墙 / 门窗 / 屋面板 / 楼板)变半透明,
内墙永远保持实体——客户要看的就是室内隔墙和它上面的洞口,把内墙也透掉就没意义了。 */
function setXray(on){
xray = !!on;
const btn = $('#chipXray');
if (btn) btn.classList.toggle('on', xray);
compMeshes.forEach(m => {
if (!m.material) return;
const inner = isInnerComp(m.userData);
const keep = (selected && m === selected) || inner; // 选中件与内墙都保持不透明
const dim = xray && !keep;
m.material.transparent = dim;
m.material.opacity = dim ? 0.1 : 1;
m.material.depthWrite = !dim;
m.material.needsUpdate = true;
m.renderOrder = dim ? 1 : 3; // 半透明的最后画,避免把内墙压在后面
});
}
/* 把某个构件变成焦点:高亮 + 镜头绕过去 + 内墙自动透视 */
let DBN = {focus:0, fly:0};
function focusComp(code, opts){
opts = opts || {}; DBN.focus++;
if (modelLoading){ pendingFocus = code; return true; } // 装载没完,先记下来
const m = compByCode[code];
if (!m) return false;
showProps(m);
const bb = new THREE.Box3().setFromObject(m);
const c = bb.getCenter(new THREE.Vector3());
const size = bb.getSize(new THREE.Vector3());
const span = Math.max(size.x, size.y, size.z) || 1;
// 视角方向:以「模型中心 → 构件」为主方向,墙体就绕到它外侧看,
// 扁平构件(楼板/屋面板)改成俯视,否则贴着面看不出东西。
const mb = new THREE.Box3().setFromObject(root);
const mc = mb.getCenter(new THREE.Vector3());
const inner = isInnerComp(m.userData);
let dir = c.clone().sub(mc);
dir.y = 0;
if (dir.lengthSq() < 0.04) dir.set(0, 0, 1);
dir.normalize();
const flat = size.y < Math.min(size.x, size.z) * 0.4;
let dist = Math.min(60, Math.max(4.5, span * 2.6));
let pos;
if (inner){
// 内墙:镜头钻进室内,站在墙的正前方(垂直于墙面),距离压到 2~3 米,
// 这样看到的是「这堵墙 + 墙上的洞口」,而不是隔着一层外墙看盒子。
const n = (size.x < size.z) ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 0, 1);
const toCenter = mc.clone().sub(c);
if (n.dot(toCenter) < 0) n.negate(); // 取朝向房子中心的一侧 = 室内侧
const din = Math.max(1.8, Math.min(3.6, span * 1.1));
pos = new THREE.Vector3(c.x + n.x * din, c.y + din * 0.32, c.z + n.z * din);
} else if (flat){
pos = new THREE.Vector3(c.x + dist * 0.35, c.y + dist * 1.15, c.z + dist * 0.85);
} else {
pos = new THREE.Vector3(c.x + dir.x * dist, c.y + dist * 0.42, c.z + dir.z * dist);
}
flyTo(pos, c, opts.dur || 900);
// 内墙一定要透视,否则看到的就是一堵外墙
if (inner && !xray) setXray(true);
if (!inner && xray && opts.autoXray) setXray(false);
const h = $('#vhint');
if (h){
const txt = '焦点:' + code + ' · ' +
(inner ? '内墙,镜头已进室内,外围护半透明' : '外围护构件') +
' · 视距 ' + (Math.round(pos.distanceTo(c) * 10) / 10) + ' m';
setTimeout(() => { h.textContent = txt; }, (opts.dur || 900) + 260);
}
return true;
}
function fitView(){
if (!root) return;
root.updateMatrixWorld(true);
let bb = new THREE.Box3();
const targets = compMeshes.length ? compMeshes : [root];
targets.forEach(o => bb.expandByObject(o));
if (bb.isEmpty()) bb.setFromObject(root);
const size = bb.getSize(new THREE.Vector3());
const c = bb.getCenter(new THREE.Vector3());
const r = Math.max(size.x, size.y, size.z) || 10;
// 三轴居中(不只是落地面),否则模型会偏到画面一角
root.position.x -= c.x;
root.position.z -= c.z;
root.position.y -= bb.min.y;
controls.target.set(0, size.y / 2, 0);
const dist = r * 1.75;
camera.position.set(dist * 0.62, dist * 0.52, dist * 0.86);
camera.near = r / 200; camera.far = r * 60; camera.updateProjectionMatrix();
controls.update();
fitView.last = {r: r, dist: dist, sx: size.x, sy: size.y, sz: size.z};
return fitView.last;
}
function clearModel(){
if (!root) return;
scene.remove(root);
root.traverse(o => {
if (o.isMesh){
o.geometry.dispose();
(Array.isArray(o.material) ? o.material : [o.material]).forEach(m => m.dispose());
}
});
root = null; selected = null; compMeshes = [];
}
function loadModel(pid){
const loader = new THREE.GLTFLoader();
const url = '/output/' + pid + '/model.glb?v=' + Date.now();
modelLoading = true;
$('#vempty').style.display = 'flex';
$('#vempty').innerHTML = '正在加载 ' + pid + ' 模型…';
loader.load(url, gltf => {
clearModel();
root = gltf.scene;
scene.add(root);
compMeshes = []; compByCode = {};
root.traverse(o => {
if (o.isMesh){
o.castShadow = false; o.receiveShadow = false;
if (o.material){
o.material = o.material.clone();
o.material.side = THREE.DoubleSide;
}
const ud = o.userData || {};
if (ud['构件编号']) {
compMeshes.push(o);
compByCode[ud['构件编号']] = o;
} else {
o.visible = false; // 隐藏场地等大平面,避免撑大包围盒
}
}
});
xray = false;
const xb = $('#chipXray'); if (xb) xb.classList.remove('on');
fitView();
const f = fitView.last || {};
$('#vhint').textContent = '构件 ' + compMeshes.length + ' 个 · 模型 ' +
(f.sx || 0).toFixed(1) + ' × ' + (f.sy || 0).toFixed(1) + ' × ' + (f.sz || 0).toFixed(1) +
' m · 视距 ' + (f.dist || 0).toFixed(1) + ' m · 可 360° 旋转';
$('#vempty').style.display = 'none';
loadInfo(pid);
// 模型装载期间用户/录屏脚本可能已经点了构件,等 fitView 落定再补做聚焦,
// 否则「先把镜头飞过去、随后又被 fitView 拽回全景」——画面会停在半路。
modelLoading = false;
modelReadyAt = performance.now();
if (pendingFocus){
const code = pendingFocus; pendingFocus = null;
setTimeout(() => focusComp(code), 60);
}
}, xhr => {
if (xhr.total) $('#vempty').innerHTML = '正在加载模型 ' + Math.round(xhr.loaded / xhr.total * 100) + '%';
}, err => {
modelLoading = false;
$('#vempty').style.display = 'flex';
$('#vempty').innerHTML = '模型尚未生成<br><span style="font-size:11.5px">点击左侧「生成 3D 模型」后自动加载</span>';
});
}
function onPick(e){
if (!root || !mouse.down) return;
const dx = e.clientX - mouse.down.x, dy = e.clientY - mouse.down.y;
mouse.down = null;
if (Math.hypot(dx, dy) > 5) return; // 判定为拖动,不做拾取
const rect = renderer.domElement.getBoundingClientRect();
mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(compMeshes, false);
if (!hits.length){ selected = null; $('#selCard').style.display = 'none'; $('#propEmpty').style.display = 'block'; if (xray) setXray(true); return; }
showProps(hits[0].object);
if (isInnerComp(hits[0].object.userData) && !xray) setXray(true);
}
/* 把构件参数渲染到右侧面板(供点击与自动演示共用) */
function showProps(obj){
if (!obj) return;
if (selected && selected !== obj && selected.material && selected.material.emissive){
selected.material.emissive.setHex(0x000000);
}
selected = obj;
if (selected.material && selected.material.emissive) selected.material.emissive.setHex(0x5a0d16);
if (xray) setXray(true); // 换选中构件时,把上一个的透明度还回去
const ud = selected.userData;
$('#selCard').style.display = 'block';
$('#propEmpty').style.display = 'none';
$('#selTitle').textContent = (ud['构件编号'] || '构件') + ' · ' + (ud['构件类型'] || '');
const rows = [['材质', ud['材质']], ['尺寸', ud['尺寸']], ['楼层', ud['楼层']],
['墙厚', ud['墙厚']], ['高度', ud['高度']], ['板厚', ud['板厚']],
['坡度', ud['坡度']], ['出檐', ud['出檐']]];
$('#selBody').innerHTML = rows.filter(r => r[1]).map(r =>
'<div class="row"><span>' + r[0] + '</span><b>' + r[1] + '</b></div>').join('');
// 清单里同步高亮,点模型和点清单两条路都指向同一条
document.querySelectorAll('#compList .comp-row').forEach(r =>
r.classList.toggle('active', r.dataset.code === (ud['构件编号'] || '')));
}
/* 录屏用:URL 带 ?demo=xxx 时自动进入某个真实状态(不造假数据) */
function scrollToViewer(){
const el = document.querySelector('.viewer-wrap');
const y = el.getBoundingClientRect().top + window.scrollY - 68;
window.scrollTo(0, Math.max(0, y));
}
function applyDemo(v){
const nav = p => document.querySelector('nav button[data-page="' + p + '"]').click();
if (v === 'arch'){ nav('arch'); return; }
if (v === 'loop'){ nav('loop'); return; }
if (v.startsWith('bld')){
const i = parseInt(v.slice(3), 10) - 1;
if (BLDGS[i]) select(BLDGS[i]);
return;
}
if (v === 'pick'){
document.body.classList.add('focus-viewer');
let n = 0;
const t = setInterval(() => {
n++;
if (compMeshes.length || n > 20){
clearInterval(t);
const obj = compMeshes.find(m => (m.userData['构件类型'] || '').indexOf('窗') >= 0) || compMeshes[0];
if (obj) showProps(obj);
}
}, 500);
}
if (v === 'viewer'){
document.body.classList.add('focus-viewer');
}
if (v === 'inner'){
// 录屏/自检用:聚焦一个内墙构件,验证「自动透视 + 洞口可见」
document.body.classList.add('focus-viewer');
const b = BLDGS.find(x => x.id === 'BLD-001');
if (b) select(b);
let n = 0;
const t = setInterval(() => {
n++;
const ready = !modelLoading && compMeshes.length > 0;
if (ready || n > 40){
clearInterval(t);
if (!ready) return;
const m = compMeshes.find(x => isInnerComp(x.userData));
if (m) focusComp(m.userData['构件编号']);
if (m && /dbg/.test(location.search)) {
const bb = new THREE.Box3().setFromObject(m);
const txt = JSON.stringify({
code: m.userData['构件编号'],
cam: [camera.position.x, camera.position.y, camera.position.z].map(v => +v.toFixed(2)),
tgt: [controls.target.x, controls.target.y, controls.target.z].map(v => +v.toFixed(2)),
min: [bb.min.x, bb.min.y, bb.min.z].map(v => +v.toFixed(2)),
max: [bb.max.x, bb.max.y, bb.max.z].map(v => +v.toFixed(2)),
dbg: DBN, loading: modelLoading, pending: pendingFocus, flying: !!camFly
});
const dump = () => { $('#vhint').textContent = txt; };
setTimeout(dump, 1500); setTimeout(dump, 3000);
}
}
}, 400);
}
if (v === 'patch2'){
// 录屏用:BLD-003 的「对话改参」版本(_BLD-003_V2)已重建好,直接切查看器看新版
document.body.classList.add('focus-viewer');
const b = BLDGS.find(x => x.id === 'BLD-003');
if (b) select(b);
setTimeout(() => loadModel('_BLD-003_V2'), 1500);
}
if (v === 'build'){
// 录屏用:切到 BLD-003,勾上「改参数并重建」,下发一句自然语言改参,等模型重建完
document.body.classList.add('focus-chat');
const b = BLDGS.find(x => x.id === 'BLD-003');
if (b) select(b);
setTimeout(() => {
const box = $('#chatBuild');
if (box) box.checked = true;
$('#chatText').value = '把这栋楼的层高改成 3.6 米,屋脊抬到 4.6 米,出檐加大到 0.9 米';
$('#chatSend').click();
setTimeout(() => {
const w = document.querySelector('.chat-wrap');
if (w) window.scrollTo(0, w.getBoundingClientRect().top + window.scrollY - 68);
const lg = $('#chatLog');
if (lg) lg.scrollTop = 0; // 录屏:让「提问 → 补丁差异」两条都露出来
}, 1200);
setTimeout(() => { const lg = $('#chatLog'); if (lg) lg.scrollTop = 0; }, 8000);
}, 1500);
}
if (v === 'chatbig'){ document.body.classList.add('focus-chat'); v = 'chat'; }
if (v === 'chat'){
// 录屏用:等预设问题出来,自动点第一条,把「检索 → 大模型回答」这一屏演出来
document.body.classList.remove('focus-viewer');
let n = 0;
const t = setInterval(() => {
n++;
const chip = document.querySelector('#chatSuggest .q');
if (chip || n > 20){
clearInterval(t);
if (chip) chip.click();
setTimeout(() => {
const w = document.querySelector('.chat-wrap');
if (w) window.scrollTo(0, w.getBoundingClientRect().top + window.scrollY - 68);
}, 600);
}
}, 400);
}
}
function loadInfo(pid){
api('/api/model/' + pid).then(r => r.json()).then(info => {
if (!info || !info.stats) return;
const s = info.stats;
$('#statBox').innerHTML =
'<div><b>' + (s['构件数'] || 0) + '</b>构件总数</div>' +
'<div><b>' + (s['墙段'] || 0) + '</b>墙段</div>' +
'<div><b>' + (s['门窗'] || 0) + '</b>门窗</div>' +
'<div><b>' + (s['楼板'] || 0) + '</b>楼板</div>';
const list = (info.components || []).slice(0, 80);
window.__comps = info.components || [];
// 清单可点:点一条 → 镜头绕过去把该构件当焦点;内墙自动开透视看内部洞口
$('#compList').innerHTML = list.map(c =>
'<div class="comp-row" data-code="' + esc(c.code) + '">' +
'<span class="cc">' + esc(c.code) + '</span>' +
'<span class="ct' + (isInnerCode(c) ? ' inner' : '') + '">' + esc(c.type) + '</span></div>').join('');
}).catch(() => {});
}
$('#chipSpin').onclick = e => { spin = !spin; e.target.classList.toggle('on', spin); };
$('#chipWire').onclick = e => {
wire = !wire; e.target.classList.toggle('on', wire);
if (!root) return;
root.traverse(o => { if (o.isMesh && o.material) o.material.wireframe = wire; });
};
$('#chipXray').onclick = () => { if (root) setXray(!xray); };
$('#chipFit').onclick = () => {
if (!root) return;
if (xray) setXray(false);
camFly = null;
fitView();
};
/* 构件清单点击 → 聚焦该构件(内墙自动透视) */
$('#compList').addEventListener('click', e => {
const row = e.target.closest ? e.target.closest('.comp-row') : null;
if (!row || !row.dataset.code) return;
if (!focusComp(row.dataset.code)){
// 模型还没加载/清单与模型不同步时,至少把参数卡显示出来
const c = (window.__comps || []).find(x => x.code === row.dataset.code);
if (c) { $('#selCard').style.display = 'block'; $('#propEmpty').style.display = 'none';
$('#selTitle').textContent = c.code + ' · ' + c.type;
$('#selBody').innerHTML = [['材质', c.mat], ['尺寸', c.size], ['楼层', c.level]]
.filter(r => r[1]).map(r => '<div class="row"><span>' + r[0] + '</span><b>' + r[1] + '</b></div>').join('');
}
}
});
/* 用户一拖动就把镜头动画停掉,别跟手感抢控制权(controls 在 initViewer 里创建) */
/* ---------------- 图纸库 ---------------- */
function setState(cls, txt){
const st = $('#status');
if (!st) return;
st.className = cls;
$('#statusText').textContent = txt;
}
function boot(){
if (location.protocol === 'file:'){
$('#warnBox').style.display = 'block';
$('#health').textContent = '未连接本地服务';
$('#health').className = 'pill bad';
$('#blds').innerHTML = '<div style="padding:24px;color:#8E1626;font-size:13px;line-height:1.9">' +
'图纸库需要本地服务提供数据。<br>请双击 <b>D:\\blend\\app\\start_server.bat</b>,' +
'再访问 <b>http://127.0.0.1:8765/</b></div>';
return;
}
initViewer();
api('/api/health').then(r => r.json()).then(h => {
const el = $('#health');
if (h.ok && h.blender){
el.textContent = '本地服务正常 · ' + h.buildings + ' 栋 / ' + h.plans + ' 张图纸 · Blender 就绪';
el.className = 'pill';
} else {
el.textContent = '服务已连 · Blender 未找到';
el.className = 'pill bad';
}
}).catch(() => {
$('#health').textContent = '服务无响应'; $('#health').className = 'pill bad';
$('#warnBox').style.display = 'block';
});
api('/api/buildings').then(r => r.json()).then(list => {
BLDGS = list;
const box = $('#blds');
box.innerHTML = '';
for (const b of BLDGS){
const d = document.createElement('div');
d.className = 'bld'; d.id = 'b-' + b.id;
d.innerHTML = '<div class="top"><b>' + b.id + '</b><span>' + b.name + '</span></div>' +
'<div class="strip">' + b.views.map(v =>
'<img src="/static/thumbs/' + v.file + '" alt="' + v.name + '" title="' + v.name + '">').join('') +
'</div><div class="kv"><span><b>' + b.floors + '</b> 层</span>' +
'<span><b>' + b.footprint[0] + '×' + b.footprint[1] + '</b> m</span>' +
'<span><b>' + b.points_total + '</b> 约束点</span></div>';
d.onclick = () => select(b);
box.appendChild(d);
}
return api('/api/state').then(r => r.json()).then(st => {
for (const pid in st){
if (st[pid] === 'done') markDone(pid);
}
// 默认选中第一个,已有产物则直接加载模型
if (BLDGS.length) select(BLDGS[0]);
const DEMO = new URLSearchParams(location.search).get('demo');
if (DEMO) setTimeout(() => applyDemo(DEMO), 800);
// 自检/录屏:?ask=问题 直接把这句话发出去(验证「答非所问」这类问题最省事)
const QS = new URLSearchParams(location.search);
const ASK = QS.get('ask');
if (ASK) setTimeout(() => {
document.body.classList.add('focus-chat');
const ta = $('#chatText'); if (ta) ta.value = ASK;
const btn = $('#chatSend'); if (btn) btn.click();
if (QS.get('cite')) setTimeout(() => { // 自检:顺手点开第一条引用看出处
const c = document.querySelector('#chatLog .cite');
if (c) c.click();
}, 9000);
}, 2200);
});
}).catch(e => {
$('#blds').innerHTML = '<div style="padding:24px;color:#8E1626;font-size:13px">图纸库加载失败:' + e + '</div>';
});
}
function markDone(pid){
const card = document.getElementById('b-' + pid);
if (!card || card.querySelector('.badge-done')) return;
const top = card.querySelector('.top');
const s = document.createElement('span');
s.className = 'badge-done'; s.textContent = '已建模';
top.appendChild(s);
}
function select(b){
SEL = b;
document.querySelectorAll('.bld').forEach(x => x.classList.remove('sel'));
const card = document.getElementById('b-' + b.id);
if (card) card.classList.add('sel');
$('#panelTitle').textContent = b.id + ' · ' + b.name;
$('#mainShot').src = '/static/thumbs/' + b.views[0].file;
$('#mainShot').dataset.code = b.views[0].code;
$('#shotRow').innerHTML = b.views.map((v, i) =>
'<img src="/static/thumbs/' + v.file + '" class="' + (i === 0 ? 'on' : '') +
'" title="' + v.name + '" data-src="/static/thumbs/' + v.file + '" alt="' + v.name + '">').join('');
$('#shotRow').querySelectorAll('img').forEach(im => im.onclick = () => {
$('#shotRow').querySelectorAll('img').forEach(x => x.classList.remove('on'));
im.classList.add('on');
$('#mainShot').src = im.dataset.src;
});
$('#meta').innerHTML =
'<div><span>楼栋编号</span>' + b.id + '</div>' +
'<div><span>层数</span>' + b.floors + ' 层</div>' +
'<div><span>轮廓尺寸</span>' + b.footprint[0] + ' × ' + b.footprint[1] + ' m</div>' +
'<div><span>视角 / 约束点</span>' + b.views.length + ' 个 / ' + b.points_total + '</div>' +
'<div style="grid-column:1/-1"><span>房间构成</span>' + b.rooms.join(' · ') + '</div>';
$('#gen').disabled = false;
clearInterval(timer);
// 对话跟着图纸走:换楼栋就换预设问题
try {
refreshSuggest(b.id);
if (CHAT.kb && !CHAT.offline) $('#chatTip').textContent =
'可用引擎 ' + CHAT.engines.length + ' 个 · 知识库 ' + CHAT.kb + ' 块 · 当前图纸 ' + b.id;
} catch(e){}
api('/api/status/' + b.id).then(r => r.json()).then(s => {
if (s.state === 'done'){
setState('done', '✔ 已有模型,可直接拖动查看');
$('#resultRow').style.display = 'flex';
$('#dl').href = '/output/' + b.id + '/model.blend';
loadModel(b.id);
} else if (s.state === 'running' || s.state === 'queued' || s.state === 'pending'){
setState('running', s.msg || '建模进行中...');
$('#resultRow').style.display = 'flex';
$('#progress').style.display = 'block';
$('#progress i').style.width = '45%';
$('#gen').disabled = true;
clearInterval(timer);
timer = setInterval(poll, 1500);
} else {
setState('', '已选 ' + b.views.length + ' 个视角,点击上方按钮生成');
$('#resultRow').style.display = 'none';
clearModel();
$('#vempty').style.display = 'flex';
$('#vempty').innerHTML = '尚无模型<br><span style="font-size:11.5px">点击「调用 Blender 生成 3D 模型」后自动加载</span>';
$('#statBox').innerHTML = ''; $('#compList').innerHTML = '';
}
});
}
$('#gen').onclick = async () => {
if (!SEL) return;
$('#gen').disabled = true;
$('#resultRow').style.display = 'none';
$('#progress').style.display = 'block';
$('#progress i').style.width = '4%';
tick = 0;
setState('running', '任务已提交,排队中...');
try {
await api('/api/generate', {method:'POST', headers:{'Content-Type':'application/json'},
body: JSON.stringify({id: SEL.id})});
} catch(e){
setState('error', '✘ 请求失败:' + e);
$('#gen').disabled = false; return;
}
clearInterval(timer);
timer = setInterval(poll, 1500);
poll();
};
async function poll(){
if (!SEL) return;
let s;
try { s = await (await api('/api/status/' + SEL.id)).json(); } catch(e){ return; }
tick++;
if (s.state === 'running'){
setState('running', s.msg || 'Blender 建模渲染中,约需 60~90 秒...');
$('#progress i').style.width = Math.min(90, 8 + tick * 4) + '%';
} else if (s.state === 'pending' || s.state === 'queued'){
setState('running', s.state === 'queued' ? '已入队,等待 Blender 空闲(多人提交会依次处理)...'
: '排队中(前面还有任务)...');
$('#progress i').style.width = Math.min(28, 4 + tick * 2) + '%';
} else if (s.state === 'done'){
clearInterval(timer);
$('#progress i').style.width = '100%';
setState('done', '✔ ' + (s.msg || '建模完成'));
$('#resultRow').style.display = 'flex';
$('#dl').href = '/output/' + SEL.id + '/model.blend';
$('#gen').disabled = false;
markDone(SEL.id);
loadModel(SEL.id);
if (s.log){ $('#log').style.display = 'block'; $('#log').textContent = s.log; }
} else if (s.state === 'error'){
clearInterval(timer);
setState('error', '✘ ' + (s.msg || '失败'));
$('#progress').style.display = 'none';
$('#gen').disabled = false;
if (s.log){ $('#log').style.display = 'block'; $('#log').textContent = s.log; }
}
}
$('#open').onclick = async () => {
if (!SEL) return;
setState('running', '正在启动 Blender 图形界面...');
try {
const r = await api('/api/open', {method:'POST', headers:{'Content-Type':'application/json'},
body: JSON.stringify({id: SEL.id})});
if (r.ok) setTimeout(() => setState('done', '✔ Blender 已启动,请在桌面窗口查看模型'), 1200);
else setState('error', '✘ 模型文件尚未生成');
} catch(e){ setState('error', '✘ ' + e); }
};
/* ---------------- 图纸对话(知识库 + 多引擎) ---------------- */
const CHAT = { engines: [], engine: '', history: [], busy: false, kb: 0,
offline: false, variant: null };
function esc(s){
return String(s == null ? '' : s).replace(/[&<>"]/g, c =>
({'&':'&','<':'<','>':'>','"':'"'}[c]));
}
function chatBubble(role, text, meta){
const log = $('#chatLog');
const d = document.createElement('div');
d.className = 'msg ' + (role === 'user' ? 'u' : 'a');
let extra = '';
if (meta){
if (meta.error){
d.className = 'msg a';
extra = '<div class="meta"><b>调用失败</b> · ' + esc(meta.error) + '</div>';
d.innerHTML = '<div class="bub err">' + esc(text) + extra + '</div>';
log.appendChild(d); log.scrollTop = log.scrollHeight; return;
}
const cs = (meta.citations || []);
const kinds = [];
cs.forEach(c => {
const k = c.kind_cn || c.kind;
if (k && kinds.indexOf(k) < 0) kinds.push(k);
});
const chips = cs.map((c, i) =>
'<span class="cite" data-i="' + i + '" title="' + esc(c.kind_cn + ':' + c.title) + '">' +
esc(c.kind_cn || c.kind || '依据') + '</span>').join('');
const bits = [];
if (meta.total_tokens) bits.push(meta.total_tokens + ' tokens');
if (meta.latency_ms) bits.push('用时 ' + (meta.latency_ms / 1000).toFixed(1) + 's');
if (meta.retrieved) bits.push('命中 ' + meta.retrieved + ' 块知识');
if (meta.degraded) bits.push('未接模型 · 按图纸参数表直答');
extra = '<div class="meta">' + esc(bits.join(' · ')) +
(cs.length ? '<br>依据(点开看出处):' + chips : '') +
(meta.note ? '<br>' + esc(meta.note) : '') +
'</div>';
}
d.innerHTML = '<div class="bub">' + esc(text) + extra + '</div>';
if (meta && meta.citations) d.__cites = meta.citations;
log.appendChild(d);
log.scrollTop = log.scrollHeight;
return d;
}
/* 点「依据」里的任一引用 → 弹出这一轮命中的全部出处,并高亮被点的那条:
标题、来源文件、原文片段、命中分。客户现场要能当场核对,不能只有四个字「方案口径」。 */
function showCites(cs, focus){
const box = $('#citeBox'), list = $('#citeList'), mask = $('#citeMask');
if (!box || !list) return;
list.innerHTML = (cs || []).map((c, i) =>
'<div class="cite-item' + (i === focus ? ' on' : '') + '" data-i="' + i + '">' +
'<div class="h"><b>' + esc(c.kind_cn || c.kind || '依据') + '</b> · ' + esc(c.title || '') + '</div>' +
'<div class="f">出处:' + esc(c.src || '') + (c.rows ? '(' + c.rows + ' 行)' : '') + '</div>' +
'<pre>' + esc(String(c.text || '(这条只有标题,没有正文)').slice(0, 1200)) + '</pre>' +
(c.score ? '<div class="why">召回得分 ' + c.score + (c.building ? ' · 楼栋 ' + esc(c.building) : '') + '</div>' : '') +
'</div>').join('');
const t = $('#citeTitle');
if (t) t.textContent = '本轮引用的 ' + (cs || []).length + ' 处出处';
box.classList.add('on'); mask.classList.add('on');
const cur = list.querySelector('.cite-item.on');
if (cur) cur.scrollIntoView({block: 'center'});
}
function hideCites(){
const box = $('#citeBox'), mask = $('#citeMask');
if (box) box.classList.remove('on');
if (mask) mask.classList.remove('on');
}
function chatTyping(text){
const log = $('#chatLog');
const d = document.createElement('div');
d.className = 'msg a';
d.id = 'chatTyping';
d.innerHTML = '<div class="bub"><span class="typing"><i></i> ' +
esc(text || '正在检索知识库并调用大模型…') + '</span></div>';
log.appendChild(d);
log.scrollTop = log.scrollHeight;
}
function setSuggest(list){
const box = $('#chatSuggest');
box.innerHTML = '';
(list || []).forEach(q => {
const s = document.createElement('span');
s.className = 'q';
s.textContent = q;
s.onclick = () => { $('#chatText').value = q; sendChat(); };
box.appendChild(s);
});
}
function refreshSuggest(pid){
if (!pid) return;
fetch('/api/chat/suggest?id=' + encodeURIComponent(pid))
.then(r => r.json()).then(d => setSuggest(d.questions))
.catch(() => setSuggest([]));
}
function initChat(){
fetch('/api/chat/engines').then(r => r.json()).then(d => {
CHAT.engines = d.engines || [];
CHAT.engine = d.default || (CHAT.engines[0] && CHAT.engines[0].id) || '';
CHAT.kb = (d.kb && d.kb.chunks) || 0;
const sel = $('#chatEngine');
sel.innerHTML = CHAT.engines.map(e =>
'<option value="' + esc(e.id) + '"' + (e.id === CHAT.engine ? ' selected' : '') + '>' +
esc(e.label) + '</option>').join('');
sel.onchange = () => { CHAT.engine = sel.value; };
CHAT.offline = !d.ready;
if (CHAT.offline){
// 线上演示(Space)没配密钥时降级为「知识库直查」:只做检索、不调模型,答案仍是图纸里的真实数字
sel.disabled = true;
$('#chatText').placeholder = '在线演示为图纸直答模式:问当前这栋楼的层数、层高、墙厚、轮廓、房间、洞口、屋面、构件、改参口径…';
$('#chatTip').textContent = '图纸直答 · ' + ((d.kb && d.kb.chunks) || 0) + ' 块知识 · 模型引擎未接入';
chatBubble('a', '当前部署未接入大模型,问答走「图纸直答」:系统认得出问的是哪个属性,直接从这栋楼的图纸参数表里取数回答,不调模型、也不给你一堆资料原文。\n层数、层高、墙厚、轮廓面积、房间分隔、门窗与内墙洞口、屋面坡度出檐山墙、构件总数与材质、五视角约束点、改参口径、导出格式,这些都能直答;超出范围的问题会明说答不了,而不是拿检索片段凑数。');
} else {
$('#chatTip').textContent =
'可用引擎 ' + CHAT.engines.length + ' 个 · 知识库 ' + CHAT.kb + ' 块 · 当前图纸 ' + (SEL ? SEL.id : '未选');
}
const k = d.kb || {};
const kinds = k.by_kind || {};
$('#kbStat').innerHTML = '共 <b>' + (k.chunks || 0) + '</b> 块知识 · ' + (k.tokens || 0) + ' 词元<br>' +
'楼栋档案 ' + (kinds.building || 0) + ' · 视角 ' + (kinds.view || 0) +
' · 构件清单 ' + (kinds.components || 0) + ' · 口径 ' + (kinds.rule || 0) + ' · FAQ ' + (kinds.faq || 0);
}).catch(() => {
$('#chatTip').textContent = '对话接口不可用(服务可能未更新)';
});
const ta = $('#chatText');
ta.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.shiftKey){ e.preventDefault(); sendChat(); }
});
$('#chatSend').onclick = () => sendChat();
$('#chatReset').onclick = () => {
CHAT.history = []; $('#chatLog').innerHTML = '';
if (SEL) refreshSuggest(SEL.id);
};
}
// 勾选「改参数并重建」时走这条路:大模型只出参数补丁,几何由 bpy 重建,
// 出来的是一版新模型(<楼栋号>-V2 后面加下划线,不进图纸列表),原图纸不动。
async function buildChat(q){
const t = document.getElementById('chatTyping');
try {
const r = await fetch('/api/chat/build', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({question: q, engine: CHAT.engine, building: SEL.id})
});
const d = await r.json();
if (t) t.remove();
// 服务端判定「这句不是改参」时会回落成普通问答,这里要按问答渲染,不能报错
if (d.intent === 'qa' && d.answer){
chatBubble('assistant', d.answer, d);
CHAT.history.push({role: 'user', content: q});
CHAT.history.push({role: 'assistant', content: d.answer});
return;
}
if (!d.ok){
const msg = d.answer || d.error || '未能解析';
chatBubble('assistant', msg, {error: d.hint || null});
if (d.hint) chatBubble('assistant', d.hint, null);
return;
}
const lines = (d.diff || []).map(x =>
x.name + ' ' + x.old + ' → ' + x.new + ' ' + x.unit);
const head = (d.answer || '已按新参数重建') + '\n\n' + lines.join('\n') + '\n\n';
let line = '重建中… 几何由 Blender 按新参数重算,约 40 秒';
const box = chatBubble('assistant', head + line,
{label: d.meta && d.meta.label, latency_ms: d.meta && d.meta.latency_ms,
total_tokens: d.meta && d.meta.total_tokens});
// 进度直接写回气泡的第一段文本(不另起 DOM,截图/录屏时不会被布局吃掉)
const bub = box.querySelector('.bub');
const paint = txt => { if (bub.firstChild) bub.firstChild.nodeValue = head + txt; };
let done = false;
for (let i = 0; i < 90; i++){
await new Promise(res => setTimeout(res, 4000));
const s = await fetch('/api/status/' + d.task).then(x => x.json()).catch(() => ({}));
if (s.state === 'done'){
paint('已重建 · ' + (s.msg || '') + ' · 查看器已切到新版模型(点下面恢复原图纸)');
const back = document.createElement('div');
back.textContent = '↩ 恢复原图纸';
back.style.cssText = 'margin-top:6px;color:var(--red);cursor:pointer;text-decoration:underline;font-size:11.5px';
back.onclick = () => { loadModel(SEL.id); CHAT.variant = null; };
bub.appendChild(back);
loadModel(d.task);
CHAT.variant = d.task;
done = true;
break;
}
if (s.state === 'error'){
paint('重建失败 · ' + (s.msg || ''));
done = true;
break;
}
paint('重建中… ' + (s.msg || ''));
}
if (!done) paint('重建超时 · 请稍后直接点左侧「生成 3D 模型」');
} catch (e){
if (t) t.remove();
chatBubble('assistant', '请求失败', {error: String(e)});
}
}
async function sendChat(){
if (CHAT.busy) return;
const ta = $('#chatText');
const q = (ta.value || '').trim();
if (!q) return;
ta.value = '';
chatBubble('user', q);
chatTyping(CHAT.offline ? '正在按图纸参数表取数…' : null);
CHAT.busy = true;
$('#chatSend').disabled = true;
try {
if ($('#chatBuild').checked && SEL){
await buildChat(q);
return;
}
const r = await fetch('/api/chat', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({question: q, engine: CHAT.engine,
building: SEL ? SEL.id : null, history: CHAT.history})
});
const d = await r.json();
const t = document.getElementById('chatTyping');
if (t) t.remove();
if (d.ok){
chatBubble('assistant', d.answer, d);
CHAT.history.push({role: 'user', content: q});
CHAT.history.push({role: 'assistant', content: d.answer});
if (CHAT.history.length > 8) CHAT.history = CHAT.history.slice(-8);
} else {
chatBubble('assistant', d.hint ? d.error + '\n' + d.hint : d.error, {error: d.error || '未知错误'});
}
} catch (e){
const t = document.getElementById('chatTyping');
if (t) t.remove();
chatBubble('assistant', '请求失败', {error: String(e)});
} finally {
CHAT.busy = false;
$('#chatSend').disabled = false;
}
}
/* 引用胶囊点击(事件委托,气泡是动态插入的) */
if ($('#chatLog')) $('#chatLog').addEventListener('click', e => {
const el = e.target.closest ? e.target.closest('.cite') : null;
if (!el) return;
const msg = el.closest('.msg');
if (!msg || !msg.__cites) return;
showCites(msg.__cites, parseInt(el.dataset.i, 10) || 0);
});
/* 关闭用委托绑定:脚本执行时弹层节点可能还没进 DOM,直接 onclick 会绑空 */
document.addEventListener('click', e => {
const t = e.target;
if (!t || !t.closest) return;
if (t.closest('#citeClose') || t.closest('#citeMask')) { hideCites(); return; }
if (t.closest('#citeBox') && !t.closest('.cite-item')) return; // 点弹层内部不关
});
document.addEventListener('keydown', e => { if (e.key === 'Escape') hideCites(); });
initChat();
boot();
</script>
<div id="citeMask"></div>
<div id="citeBox">
<header><div id="citeTitle">引用出处</div><span id="citeClose">关闭 ✕</span></header>
<div id="citeList"></div>
</div>
</body>
</html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>建筑机器人绘图系统 · ArchRobot</title>
<style>
:root{ --red:#D6273B; --red2:#FCE9EA; --ink:#1B1F24; --sub:#5A6470; --line:#E4E8EE; --bg:#F5F7FA; --card:#FFFFFF; }
*{ margin:0; padding:0; box-sizing:border-box; }
body{ font-family:"Microsoft YaHei",system-ui,sans-serif; background:var(--bg); color:var(--ink); }
header{ background:var(--card); border-bottom:1px solid var(--line); padding:0 32px; display:flex; align-items:center; height:60px; gap:14px; position:sticky; top:0; z-index:9;}
.logo{ width:30px; height:30px; background:var(--red); border-radius:7px; display:flex; align-items:center; justify-content:center; color:#fff; font-weight:bold; font-size:15px;}
h1{ font-size:19px; letter-spacing:.5px;}
h1 small{ color:var(--sub); font-weight:normal; font-size:12px; margin-left:10px;}
nav{ margin-left:auto; display:flex; gap:4px; align-items:center;}
nav button{ border:none; background:none; padding:9px 16px; font-size:14px; color:var(--sub); cursor:pointer; border-radius:8px;}
nav button.active{ color:var(--red); background:var(--red2); font-weight:bold;}
.pill{ font-size:11px; color:#2FA35C; background:#E8F6EE; padding:4px 9px; border-radius:99px; margin-left:10px;}
.pill.bad{ color:var(--red); background:var(--red2);}
main{ max-width:1560px; margin:0 auto; padding:20px 32px 56px;}
.page{ display:none; } .page.show{ display:block; }
.grid-title{ font-size:13px; color:var(--sub); margin:6px 0 12px; display:flex; align-items:center; gap:8px;}
.grid-title b{ color:var(--ink); font-size:16px;}
.grid-title::before{ content:""; width:5px; height:18px; background:var(--red); border-radius:2px;}
.layout{ display:grid; grid-template-columns: 1fr 470px; gap:18px; align-items:start;}
/* 楼栋卡片 */
.blds{ display:grid; grid-template-columns:repeat(3,1fr); gap:12px;}
.bld{ background:var(--card); border:2px solid var(--line); border-radius:12px; padding:10px; cursor:pointer; transition:.15s;}
.bld:hover{ border-color:#EFA5A5; transform:translateY(-2px);}
.bld.sel{ border-color:var(--red); box-shadow:0 6px 18px rgba(214,39,59,.16);}
.bld .top{ display:flex; justify-content:space-between; align-items:baseline; margin-bottom:8px;}
.bld .top b{ font-size:14px;}
.bld .top span{ font-size:11px; color:var(--sub);}
.bld .strip{ display:grid; grid-template-columns:repeat(3,1fr); gap:3px;}
.bld .strip img{ width:100%; aspect-ratio:1.44; object-fit:cover; border:1px solid var(--line); border-radius:3px; background:#fff;}
.bld .strip img:nth-child(4){ grid-column:span 2; aspect-ratio:2.9; }
.bld .kv{ display:flex; gap:10px; margin-top:8px; font-size:11px; color:var(--sub);}
.bld .kv b{ color:var(--ink); font-size:12px;}
.badge-done{ background:var(--red); color:#fff; font-size:10px; padding:1px 7px; border-radius:99px;}
/* 详情面板 */
.panel{ background:var(--card); border:1px solid var(--line); border-radius:12px; padding:16px; position:sticky; top:76px;}
.panel h2{ font-size:15px; margin-bottom:10px; display:flex; align-items:center; gap:8px;}
.panel h2::before{ content:""; width:5px; height:16px; background:var(--red); border-radius:2px;}
#mainShot{ width:100%; aspect-ratio:1.44; object-fit:contain; background:#fff; border:1px solid var(--line); border-radius:8px;}
#shotRow{ display:grid; grid-template-columns:repeat(5,1fr); gap:5px; margin:8px 0 12px;}
#shotRow img{ width:100%; aspect-ratio:1.44; object-fit:cover; border:2px solid var(--line); border-radius:4px; cursor:pointer; background:#fff;}
#shotRow img.on{ border-color:var(--red);}
.meta{ display:grid; grid-template-columns:1fr 1fr; gap:6px; font-size:12px; margin-bottom:12px;}
.meta div{ background:var(--bg); border-radius:7px; padding:7px 9px;}
.meta span{ color:var(--sub); font-size:10px; display:block;}
.btn{ width:100%; border:none; border-radius:9px; padding:12px; font-size:14px; font-weight:bold; cursor:pointer; color:#fff; background:var(--red); display:block; text-align:center; text-decoration:none;}
.btn:hover{ filter:brightness(1.08);}
.btn:disabled{ background:#C9CFD8; cursor:not-allowed;}
.btn.ghost{ background:var(--card); color:var(--ink); border:1px solid var(--line); font-weight:normal;}
.btn.ghost:hover{ border-color:var(--red); color:var(--red);}
.btnrow{ display:flex; gap:7px; margin-top:7px;}
.btnrow .btn{ flex:1;}
#status{ margin-top:10px; font-size:12.5px; color:var(--sub); min-height:18px;}
#status .dot{ display:inline-block; width:8px; height:8px; border-radius:50%; background:#C9CFD8; margin-right:6px;}
#status.running .dot{ background:#E8A13B; animation:blink 1s infinite;}
#status.done .dot{ background:#2FA35C;} #status.error .dot{ background:var(--red);}
@keyframes blink{ 50%{opacity:.3}}
#progress{ height:4px; background:var(--line); border-radius:99px; overflow:hidden; margin-top:8px; display:none;}
#progress i{ display:block; height:100%; width:0; background:var(--red); transition:width .6s;}
#log{ margin-top:8px; font-family:Consolas,monospace; font-size:10.5px; color:var(--sub); background:var(--bg); border-radius:7px; padding:7px 9px; max-height:80px; overflow:auto; display:none; white-space:pre-wrap;}
/* 3D 查看器 */
.viewer-wrap{ margin-top:22px; background:var(--card); border:1px solid var(--line); border-radius:12px; overflow:hidden;}
.vhead{ display:flex; align-items:center; gap:10px; padding:12px 16px; border-bottom:1px solid var(--line); flex-wrap:wrap;}
.vhead h3{ font-size:15px; display:flex; align-items:center; gap:8px;}
.vhead h3::before{ content:""; width:5px; height:16px; background:var(--red); border-radius:2px;}
.vhead .tip{ font-size:11.5px; color:var(--sub); margin-left:auto;}
.vhead .chip{ font-size:11px; border:1px solid var(--line); border-radius:99px; padding:4px 10px; cursor:pointer; color:var(--sub); user-select:none;}
.vhead .chip.on{ border-color:var(--red); color:var(--red); background:var(--red2);}
.vgrid{ display:grid; grid-template-columns:1fr 300px;}
#viewer{ position:relative; height:520px; background:linear-gradient(#eef2f7,#f8fafc);}
#viewer canvas{ display:block; width:100%; height:100%;}
#vhint{ position:absolute; left:14px; bottom:12px; font-size:11.5px; color:#6b7787; background:rgba(255,255,255,.82); padding:5px 9px; border-radius:6px;}
#vempty{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; flex-direction:column; gap:8px; color:#8b95a3; font-size:13px; background:#f2f5f9;}
#props{ border-left:1px solid var(--line); padding:14px; height:520px; overflow:auto;}
#props h4{ font-size:13px; margin-bottom:8px; color:var(--sub); font-weight:normal;}
#propList{ font-size:12px;}
#propList .row{ display:flex; justify-content:space-between; padding:6px 0; border-bottom:1px dashed var(--line);}
#propList .row span:first-child{ color:var(--sub);}
#propList .row b{ font-weight:normal;}
.sel-card{ background:var(--red2); border:1px solid #F3C7CB; border-radius:8px; padding:10px 12px; margin-bottom:10px;}
.sel-card .t{ font-size:13px; font-weight:bold; color:#8E1626; margin-bottom:6px;}
.stat{ display:grid; grid-template-columns:1fr 1fr; gap:6px; margin-top:10px;}
.stat div{ background:var(--bg); border-radius:7px; padding:7px 9px; font-size:11px; color:var(--sub);}
.stat b{ display:block; font-size:15px; color:var(--ink);}
.empty-tip{ color:#9aa3b0; font-size:12px; line-height:1.9;}
/* 构件清单:整行可点,点了就聚焦(内墙会顺手开透视) */
.comp-row{ display:flex; justify-content:space-between; gap:8px; padding:4px 5px;
border-bottom:1px dashed #E4E8EE; cursor:pointer; border-radius:4px;}
.comp-row:hover{ background:var(--red2);}
.comp-row.active{ background:var(--red2); box-shadow:inset 2px 0 0 var(--red);}
.comp-row .cc{ color:#5A6470;}
.comp-row .ct{ color:var(--ink);}