Files
Robot_Arm/src/build_viewer.py
T
cbb d8f6c69406 feat(arm): P04顶缘改R3圆角+竖直前壁消除刀刃状凸起,并带上承压面R35圆腔等未提交改动
用户截图圈的"非常尖的凸起"实测是顶面前沿一条刀刃:2026-10-04 把前脸改成与顶面
相切的 Hermite 弧面,但只有 9.0mm 的 Y 预算却要吸收 120.5mm 落差,90° 转弯全挤在
起点——离开顶面 0.28mm 就转到 45°,起始曲率半径 0.571mm,Y=164.32 处顶面与前脸之间
料厚只剩 0.027mm。2026-10-05 的起点加密又抹掉了第一段 57° 折线那层意外钝化。
且历次只碰前缘一条棱,顶面左缘(X=11.5)与后缘(Y=91.5)仍是 89° 直棱。

现改为常规形状:顶面 -> 前侧 R3 圆角 -> 竖直前壁 Y=164.5 直落到 Z=566 -> Hermite
(两端切线沿 -Z,G1) 顺收到 (155.5,526);顶面后缘对称再倒 R3,弧心切点按背面那条
0.24° 斜线取值以免露出台阶。crest 不再是独立最外凸点,尖从根上消失。

代价与核验:P04 体积 276.2 -> 296.2 cm3(+20.0,填掉原内凹腔);Y 最大仍 164.5,
与 P03 止脱环 R36.5/顶646.5 的齐平不变;13/13 单实体、静态干涉 8/8 零、97 颗螺钉。
J1 扫掠半径由 51.6 增至 57.2mm,动态行程数据(collide.json/travel.json)待重扫。

同时带上上一轮未提交的改动:承压面让位腔改 R35 圆腔、主腔统一 BAY_R=30.50、
M2/M3 前端压盖与围挡敞口侧切除、build_viewer 三副本逐个写盘(避免浏览器独占锁
导致"改了源码网页没变")。
2026-10-07 02:27:38 +08:00

80 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
"""Assemble the single-file viewer: three.js (inline, no CDN) + mesh data + 2D sheets."""
import io
import json
import os
import sys
try:
sys.stdout.reconfigure(encoding="utf-8")
except Exception:
pass
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from armcore import WEB, DOCS, WORKSPACE
SRC = os.path.dirname(os.path.abspath(__file__))
import time
def rebuild_viewer():
print("=" * 80, flush=True)
print("【第五阶段 5/5】打包单文件三维交互查看器 (机器人手臂3D查看器.html)...", flush=True)
print("=" * 80, flush=True)
t0 = time.time()
print(" - 读取 Three.js 离线 3D 渲染内核...", end="", flush=True)
three = io.open(WEB + "/three_inline.js", encoding="utf-8").read()
assert len(three) > 400000, len(three)
print(f" 完成 ({len(three)/1024:.0f} KB) ✓", flush=True)
print(" - 读取几何网格与关节运动学数据...", end="", flush=True)
data = io.open(WEB + "/mesh_arm.json", encoding="utf-8").read()
sheets = io.open(WEB + "/sheets.jsdata", encoding="utf-8").read()
trv = io.open(DOCS + "/travel.json", encoding="utf-8").read() if os.path.exists(
DOCS + "/travel.json") else "[]"
col = io.open(DOCS + "/collide.json", encoding="utf-8").read() if os.path.exists(
DOCS + "/collide.json") else '{"caps":[],"parts":{}}'
screws = io.open(DOCS + "/screws.json", encoding="utf-8").read() if os.path.exists(
DOCS + "/screws.json") else "[]"
ik_solver = io.open(WEB + "/arm-ik-solver.js", encoding="utf-8").read()
ik_glue = io.open(WEB + "/ik-glue.js", encoding="utf-8").read()
tpl = io.open(SRC + "/viewer_tpl.html", encoding="utf-8").read()
print(f" 完成 ({len(data)/1024:.0f} KB) ✓", flush=True)
print(" - 打包生成全内置单文件 HTML...", end="", flush=True)
out = (tpl.replace("/*__THREE__*/", three)
.replace("/*__DATA__*/", data)
.replace("/*__SHEETS__*/", sheets)
.replace("/*__TRAVEL__*/", trv)
.replace("/*__COLLIDE__*/", col)
.replace("/*__SCREWS__*/", screws)
.replace("/*__IKSOLVER__*/", ik_solver)
.replace("/*__IKGLUE__*/", ik_glue))
assert "/*__" not in out, [l for l in out.split("\n") if "/*__" in l][:3]
dst = WEB + "/机器人手臂3D查看器.html"
# 【2026-10-06】三个副本逐个写、逐个报错,不要一把梭。
# 原来三行连写,任一份被浏览器独占(Windows 上打开中的 html 是独占锁)就抛异常,
# 而调用方 arm_model.py 把整个 rebuild_viewer() 包在 try/except 里,
# 于是只写成功第一份、另外两份静默停在旧版本 —— 表现为"代码改了但网页没变"。
# 实测就是这个坑:18:52 那次 dst 是新的,web/index.html 和根目录那份还停在 18:12。
ok, failed = True, []
for path in (dst, WEB + "/index.html", WORKSPACE + "/机器人手臂3D查看器.html"):
try:
io.open(path, "w", encoding="utf-8").write(out)
except Exception as e:
ok = False
failed.append("%s (%s)" % (path, e))
sz_mb = os.path.getsize(dst) / 1e6
print(f" 完成 ({sz_mb:.2f} MB, 耗时: {time.time()-t0:.2f}s) ✓", flush=True)
if failed:
print("!! 以下副本写入失败(多半是浏览器正打开着该文件,Windows 独占锁):", flush=True)
for f in failed:
print(" - %s" % f, flush=True)
print(" 关掉对应页面后重跑 python src/build_viewer.py 即可。\n", flush=True)
else:
print(f"-> 3D查看器已更新至: {dst}、{WEB}/index.html 与 根目录/机器人手臂3D查看器.html\n",
flush=True)
if __name__ == "__main__":
rebuild_viewer()
os._exit(0)