fix: close remaining CAD delivery review gaps

This commit is contained in:
2026-07-11 15:26:43 +08:00
parent 6c1336fa59
commit c12d1d57cb
11 changed files with 464 additions and 93 deletions

View File

@@ -26,6 +26,7 @@ from __future__ import annotations
import argparse
import base64
import gzip
import html as html_lib
import json
import struct
from pathlib import Path
@@ -66,10 +67,15 @@ def glb_extensions(path: Path) -> set[str]:
return set(document.get("extensionsUsed", []))
def script_json(value) -> str:
"""Serialize JSON for an inline script without allowing an early script close."""
return json.dumps(value, ensure_ascii=False).replace("</", "<\\/")
MAIN_JS = r"""
(async function(){
const $load = document.getElementById('load');
const fail = m => { $load.style.display='flex'; $load.innerHTML = '<div style="max-width:520px;text-align:center">加载失败:'+m+'</div>'; };
const fail = m => { $load.style.display='flex'; $load.textContent = '加载失败:'+m; };
window.addEventListener('error', e => fail(e.message));
window.addEventListener('unhandledrejection', e => fail(e.reason && e.reason.message || e.reason));
try {
@@ -161,8 +167,9 @@ MAIN_JS = r"""
head.appendChild(document.createTextNode(gname)); head.appendChild(btn); tg.appendChild(head);
GROUPS[gname].forEach(f => {
const l = document.createElement('label');
l.innerHTML = '<input id="cb_'+f[0]+'" type="checkbox" checked> '+f[0]+' '+f[1];
l.querySelector('input').onchange = e => { state.fl[f[0]]=e.target.checked; apply(); };
const input = document.createElement('input'); input.id='cb_'+f[0]; input.type='checkbox'; input.checked=true;
input.onchange = e => { state.fl[f[0]]=e.target.checked; apply(); };
l.appendChild(input); l.appendChild(document.createTextNode(' '+f[0]+' '+f[1]));
tg.appendChild(l);
});
}
@@ -173,8 +180,9 @@ MAIN_JS = r"""
for (const k in CATS) {
if (!used[k] || k==='trees') continue;
const l = document.createElement('label');
l.innerHTML = '<input type="checkbox" checked> '+CATS[k];
l.querySelector('input').onchange = e => { state.ct[k]=e.target.checked; apply(); };
const input = document.createElement('input'); input.type='checkbox'; input.checked=true;
input.onchange = e => { state.ct[k]=e.target.checked; apply(); };
l.appendChild(input); l.appendChild(document.createTextNode(' '+CATS[k]));
tg.appendChild(l);
}
const ray = new THREE.Raycaster(), ptr = new THREE.Vector2(), info = document.getElementById('info');
@@ -191,7 +199,10 @@ MAIN_JS = r"""
hi.material = hiMat.clone(); hi.material.emissive = new THREE.Color(0x2a6bd4); hi.material.emissiveIntensity = 0.55;
const p = (hi.name||'').split('__');
let fname=''; for (const gname in GROUPS) GROUPS[gname].forEach(f => { if (f[0]===p[0]) fname=f[1]; });
info.innerHTML = '<b>'+p[0]+'</b> '+fname+'<br>构件:'+(CATS[p[1]]||p[1])+' 节点:'+hi.name;
info.replaceChildren();
const strong=document.createElement('b'); strong.textContent=p[0]; info.appendChild(strong);
info.appendChild(document.createTextNode(' '+fname)); info.appendChild(document.createElement('br'));
info.appendChild(document.createTextNode('构件:'+(CATS[p[1]]||p[1])+' 节点:'+hi.name));
info.style.display = 'block';
invalidate();
});
@@ -261,21 +272,23 @@ def main() -> int:
for s in spec.get("floors", {}).get("TREES", {}).get("segments", {}).get("trees", [])
]
cats = {k: v.get("label", k) for k, v in spec.get("categories", {}).items()}
title = args.title or spec.get("project", {}).get("name", "CAD 建筑模型")
title = str(args.title or spec.get("project", {}).get("name", "CAD 建筑模型"))
escaped_title = html_lib.escape(title, quote=True)
escaped_subtitle = html_lib.escape(str(args.subtitle), quote=True)
main_js = (
MAIN_JS.replace("__GROUPS__", json.dumps(groups, ensure_ascii=False))
.replace("__CATS__", json.dumps(cats, ensure_ascii=False))
.replace("__TREES__", json.dumps(trees))
MAIN_JS.replace("__GROUPS__", script_json(groups))
.replace("__CATS__", script_json(cats))
.replace("__TREES__", script_json(trees))
)
sc_close = "</scr" + "ipt>"
html = (
'<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8">'
f"<title>{title} · 3D 查看器(离线版)</title>"
f"<title>{escaped_title} · 3D 查看器(离线版)</title>"
'<meta name="viewport" content="width=device-width, initial-scale=1">'
f"<style>{CSS}</style></head><body>"
'<div id="load">正在初始化…</div>'
f'<div id="panel"><h1>{title}</h1><div class="sub">{args.subtitle}</div><div id="tg"></div></div>'
f'<div id="panel"><h1>{escaped_title}</h1><div class="sub">{escaped_subtitle}</div><div id="tg"></div></div>'
'<div id="info"></div>'
'<div id="hint">拖动旋转 · 滚轮缩放 · 右键平移 · 点击构件查属性</div>'
+ "".join(