|
|
@@ -0,0 +1,3181 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="zh-CN">
|
|
|
+<head>
|
|
|
+<meta charset="utf-8">
|
|
|
+<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
|
+<meta name="theme-color" content="#0d1726">
|
|
|
+<title>壳体工坊 · Pocket Shell Studio</title>
|
|
|
+<link rel="stylesheet" href="https://miaoda.feishu.cn/fonts/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap">
|
|
|
+<script src="https://cdnjs.cloudflare.com/ajax/libs/babylonjs/7.54.3/babylon.js"
|
|
|
+ onerror="this.onerror=null;var s=document.createElement('script');s.src='https://fastly.jsdelivr.net/npm/babylonjs@7.54.3/babylon.js';document.head.appendChild(s);"></script>
|
|
|
+<style>
|
|
|
+:root{
|
|
|
+ --bg:#f1f3f7;--card:#ffffff;--ink:#0d1726;--sub:#68758a;--line:#e4e9f0;
|
|
|
+ --blue:#1f6feb;--cyan:#0aa2c0;--green:#0f9d58;--amber:#d97706;
|
|
|
+ --shadow:0 6px 24px rgba(15,23,42,.08);
|
|
|
+ --radius:16px;
|
|
|
+}
|
|
|
+*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
|
|
|
+html,body{margin:0;padding:0;background:var(--bg);color:var(--ink);
|
|
|
+ font-family:"Noto Sans SC",-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;
|
|
|
+ font-size:15px;line-height:1.55;-webkit-font-smoothing:antialiased}
|
|
|
+body{overscroll-behavior-y:contain}
|
|
|
+a{color:inherit;text-decoration:none}
|
|
|
+button{font-family:inherit;cursor:pointer}
|
|
|
+.wrap{max-width:620px;margin:0 auto;padding:0 16px calc(96px + env(safe-area-inset-bottom))}
|
|
|
+
|
|
|
+/* ============ 顶栏 ============ */
|
|
|
+.topbar{position:sticky;top:0;z-index:40;background:rgba(241,243,247,.86);backdrop-filter:blur(14px);
|
|
|
+ -webkit-backdrop-filter:blur(14px);border-bottom:1px solid rgba(228,233,240,.9)}
|
|
|
+.topbar .inner{max-width:620px;margin:0 auto;height:54px;display:flex;align-items:center;gap:10px;padding:0 12px}
|
|
|
+.iconbtn{width:34px;height:34px;border-radius:10px;border:1px solid var(--line);background:#fff;
|
|
|
+ display:flex;align-items:center;justify-content:center;color:var(--ink);font-size:16px;padding:0}
|
|
|
+.iconbtn:active{transform:scale(.96)}
|
|
|
+.tt{flex:1;min-width:0}
|
|
|
+.tt h1{margin:0;font-size:16px;font-weight:700;letter-spacing:.2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
|
+.tt p{margin:1px 0 0;font-size:11px;color:var(--sub);letter-spacing:.4px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
|
+.pill{font-size:11px;padding:4px 9px;border-radius:999px;background:#eef3fb;color:var(--blue);border:1px solid #dbe6fa;white-space:nowrap}
|
|
|
+
|
|
|
+/* ============ 首页 ============ */
|
|
|
+.hero{margin:14px 0 16px;border-radius:22px;padding:22px 20px 18px;color:#eaf1ff;position:relative;overflow:hidden;
|
|
|
+ background:radial-gradient(120% 130% at 0% 0%,#1b3a6b 0%,#0d1726 58%,#0a111c 100%);box-shadow:0 18px 40px rgba(13,23,38,.28)}
|
|
|
+.hero:after{content:"";position:absolute;right:-40px;top:-60px;width:220px;height:220px;border-radius:50%;
|
|
|
+ background:radial-gradient(circle,rgba(31,111,235,.55),rgba(31,111,235,0) 68%)}
|
|
|
+.hero .kicker{font-size:11px;letter-spacing:2px;color:#8fb6ff;text-transform:uppercase}
|
|
|
+.hero h2{margin:6px 0 8px;font-size:26px;line-height:1.25;font-weight:700;letter-spacing:.5px}
|
|
|
+.hero p{margin:0;font-size:12.5px;color:#a8bbd6;line-height:1.6;max-width:92%}
|
|
|
+.hero .stats{display:flex;gap:8px;margin-top:16px;flex-wrap:wrap}
|
|
|
+.stat{flex:1;min-width:92px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);border-radius:12px;padding:9px 10px}
|
|
|
+.stat b{display:block;font-size:16px;letter-spacing:.3px}
|
|
|
+.stat span{font-size:10.5px;color:#93a9c8}
|
|
|
+
|
|
|
+.sec{margin:22px 0 10px;display:flex;align-items:baseline;gap:8px}
|
|
|
+.sec h3{margin:0;font-size:14px;font-weight:700;letter-spacing:.4px}
|
|
|
+.sec span{font-size:11px;color:var(--sub)}
|
|
|
+
|
|
|
+.pcard{display:block;background:var(--card);border-radius:var(--radius);padding:14px;margin-bottom:12px;
|
|
|
+ border:1px solid var(--line);box-shadow:var(--shadow);transition:transform .16s ease}
|
|
|
+.pcard:active{transform:scale(.985)}
|
|
|
+.pcard .row{display:flex;gap:12px;align-items:flex-start}
|
|
|
+.thumb{width:74px;height:74px;flex:0 0 74px;border-radius:14px;position:relative;overflow:hidden;
|
|
|
+ background:linear-gradient(140deg,#101a29,#26374f);display:flex;align-items:center;justify-content:center}
|
|
|
+.thumb .shape{position:relative}
|
|
|
+.thumb .sq{width:40px;height:40px;border-radius:11px;background:linear-gradient(160deg,#f0d3d9,#c993a2);
|
|
|
+ box-shadow:inset 0 -6px 12px rgba(0,0,0,.18),0 4px 10px rgba(0,0,0,.35)}
|
|
|
+.thumb .sq:before,.thumb .sq:after{content:"";position:absolute;top:-9px;width:11px;height:14px;
|
|
|
+ background:linear-gradient(160deg,#e9c3cc,#a9768a);border-radius:6px 6px 2px 2px}
|
|
|
+.thumb .sq:before{left:3px;transform:rotate(-14deg)}
|
|
|
+.thumb .sq:after{right:3px;transform:rotate(14deg)}
|
|
|
+.thumb .disc{width:44px;height:44px;border-radius:50%;background:linear-gradient(160deg,#e9edf2,#a7b3c2);
|
|
|
+ box-shadow:inset 0 -5px 10px rgba(0,0,0,.18),0 6px 12px rgba(0,0,0,.3);display:flex;align-items:center;justify-content:center}
|
|
|
+.thumb .disc i{width:30px;height:30px;border-radius:50%;background:#0c1118;display:block}
|
|
|
+.thumb .puck{width:44px;height:26px;border-radius:12px;background:linear-gradient(160deg,#f4f6f9,#b9c2cd);
|
|
|
+ box-shadow:0 6px 12px rgba(0,0,0,.3);position:relative}
|
|
|
+.thumb .puck:after{content:"";position:absolute;right:-6px;top:8px;width:12px;height:12px;border-radius:50%;border:2px solid #d5dbe3}
|
|
|
+.thumb .lbl{position:absolute;left:6px;bottom:4px;font-size:8px;letter-spacing:.6px;color:#8093ab}
|
|
|
+.pinfo{flex:1;min-width:0}
|
|
|
+.pinfo h4{margin:0 0 3px;font-size:15px;font-weight:700;letter-spacing:.2px}
|
|
|
+.pinfo .dims{font-size:11px;color:var(--sub);font-variant-numeric:tabular-nums}
|
|
|
+.tagrow{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}
|
|
|
+.tag{font-size:10.5px;padding:3px 8px;border-radius:6px;background:#f3f6fa;border:1px solid var(--line);color:#4a5a70}
|
|
|
+.tag.b{background:#eef4fe;border-color:#d9e6fc;color:var(--blue)}
|
|
|
+.tag.g{background:#edfaf3;border-color:#cfeedd;color:#0c7a48}
|
|
|
+.enter{display:flex;align-items:center;gap:4px;color:var(--blue);font-size:12px;font-weight:500;margin-top:10px}
|
|
|
+.enter .arw{font-size:14px}
|
|
|
+
|
|
|
+.mini{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
|
|
+.minicard{background:#fff;border:1px solid var(--line);border-radius:14px;padding:13px;box-shadow:var(--shadow)}
|
|
|
+.minicard b{display:block;font-size:13.5px;margin-bottom:2px}
|
|
|
+.minicard span{font-size:11px;color:var(--sub);line-height:1.5;display:block}
|
|
|
+.minicard .n{font-size:10px;color:var(--blue);margin-top:8px;display:block}
|
|
|
+
|
|
|
+/* ============ 3D 舞台 ============ */
|
|
|
+.stage{margin:12px 0 0;border-radius:18px;overflow:hidden;position:relative;height:44vh;min-height:290px;max-height:420px;
|
|
|
+ background:radial-gradient(110% 110% at 20% 0%,#22344b 0%,#131e2c 48%,#0a1018 100%);
|
|
|
+ box-shadow:0 14px 30px rgba(13,23,38,.22);touch-action:none}
|
|
|
+.stage canvas{width:100%;height:100%;display:block;outline:none;touch-action:none}
|
|
|
+.stage-top{position:absolute;top:10px;left:10px;right:10px;display:flex;gap:6px;align-items:flex-start;pointer-events:none}
|
|
|
+.stage-top .badge{pointer-events:auto;font-size:10.5px;color:#d7e5ff;background:rgba(255,255,255,.1);
|
|
|
+ border:1px solid rgba(255,255,255,.16);border-radius:8px;padding:4px 8px;backdrop-filter:blur(6px)}
|
|
|
+.stage-top .spacer{flex:1}
|
|
|
+.stage-top .vbtn{pointer-events:auto;font-size:10.5px;color:#e8f1ff;background:rgba(255,255,255,.1);
|
|
|
+ border:1px solid rgba(255,255,255,.16);border-radius:8px;padding:4px 8px}
|
|
|
+.stage-top .vbtn.on{background:#1f6feb;border-color:#3f86ff;color:#fff}
|
|
|
+.stage-bottom{position:absolute;left:0;right:0;bottom:0;padding:8px 10px 10px;pointer-events:none;
|
|
|
+ background:linear-gradient(to top,rgba(6,11,18,.72),rgba(6,11,18,0))}
|
|
|
+.matrow{display:flex;gap:6px;overflow-x:auto;padding-bottom:2px;pointer-events:auto;scrollbar-width:none}
|
|
|
+.matrow::-webkit-scrollbar{display:none}
|
|
|
+.mat{flex:0 0 auto;display:flex;align-items:center;gap:5px;font-size:11px;color:#dbe7f7;
|
|
|
+ background:rgba(16,26,40,.72);border:1px solid rgba(255,255,255,.14);border-radius:999px;padding:4px 9px 4px 5px}
|
|
|
+.mat.on{background:#1f6feb;border-color:#4f92ff;color:#fff}
|
|
|
+.mat i{width:14px;height:14px;border-radius:50%;display:block;border:1px solid rgba(255,255,255,.35)}
|
|
|
+.dimlayer{position:absolute;inset:0;pointer-events:none;overflow:hidden}
|
|
|
+.dimtag{position:absolute;transform:translate(-50%,-50%);font-size:10px;line-height:1.1;color:#cfe6ff;
|
|
|
+ background:rgba(9,17,28,.78);border:1px solid rgba(120,190,255,.38);padding:2px 5px;border-radius:4px;
|
|
|
+ white-space:nowrap;font-variant-numeric:tabular-nums;letter-spacing:.2px}
|
|
|
+
|
|
|
+/* ============ 参数面板 / tabs ============ */
|
|
|
+.tabs{display:flex;gap:6px;overflow-x:auto;margin:14px 0 10px;padding-bottom:2px;scrollbar-width:none}
|
|
|
+.tabs::-webkit-scrollbar{display:none}
|
|
|
+.tab{flex:0 0 auto;font-size:12.5px;padding:8px 13px;border-radius:10px;border:1px solid var(--line);
|
|
|
+ background:#fff;color:var(--sub)}
|
|
|
+.tab.on{background:var(--ink);border-color:var(--ink);color:#fff}
|
|
|
+.panel{background:#fff;border:1px solid var(--line);border-radius:var(--radius);padding:14px;box-shadow:var(--shadow);margin-bottom:12px}
|
|
|
+.panel h5{margin:0 0 10px;font-size:13px;font-weight:700;display:flex;align-items:center;gap:6px}
|
|
|
+.panel h5 em{font-style:normal;font-size:10.5px;color:var(--sub);font-weight:400}
|
|
|
+.slider{margin:11px 0 14px}
|
|
|
+.slider .lab{display:flex;justify-content:space-between;font-size:12px;margin-bottom:5px}
|
|
|
+.slider .lab b{font-variant-numeric:tabular-nums;font-weight:600;color:var(--ink);flex:0 0 auto;margin-left:10px}
|
|
|
+.slider .lab span{color:var(--sub);min-width:0;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
|
|
|
+input[type=range]{-webkit-appearance:none;width:100%;height:26px;background:transparent;margin:0}
|
|
|
+input[type=range]::-webkit-slider-runnable-track{height:5px;border-radius:3px;
|
|
|
+ background:linear-gradient(90deg,#1f6feb var(--p,50%),#e6ebf2 var(--p,50%))}
|
|
|
+input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;margin-top:-7.5px;
|
|
|
+ border-radius:50%;background:#fff;border:2px solid #1f6feb;box-shadow:0 2px 6px rgba(31,111,235,.35)}
|
|
|
+input[type=range]::-moz-range-track{height:5px;border-radius:3px;background:#e6ebf2}
|
|
|
+input[type=range]::-moz-range-thumb{width:18px;height:18px;border-radius:50%;background:#fff;border:2px solid #1f6feb}
|
|
|
+.hint{font-size:11px;color:var(--sub);margin:6px 0 0;line-height:1.55}
|
|
|
+.btnrow{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
|
|
|
+.btn{font-size:12px;padding:8px 12px;border-radius:10px;border:1px solid var(--line);background:#fff;color:var(--ink)}
|
|
|
+.btn.pri{background:var(--blue);border-color:var(--blue);color:#fff}
|
|
|
+.btn.dark{background:var(--ink);border-color:var(--ink);color:#fff}
|
|
|
+.btn:active{transform:scale(.97)}
|
|
|
+
|
|
|
+/* 电子件卡 */
|
|
|
+.board{display:flex;gap:11px;border:1px solid var(--line);border-radius:12px;padding:11px;margin-bottom:10px;background:#fbfcfe}
|
|
|
+.board .bv{width:52px;height:52px;border-radius:50%;flex:0 0 52px;background:linear-gradient(150deg,#e8edf4,#b6c0cc);
|
|
|
+ display:flex;align-items:center;justify-content:center;box-shadow:inset 0 -4px 8px rgba(0,0,0,.15)}
|
|
|
+.board .bv i{width:34px;height:34px;border-radius:50%;background:#101720;display:block}
|
|
|
+.board .bi{flex:1;min-width:0}
|
|
|
+.board .bi b{font-size:13px;display:block;line-height:1.35}
|
|
|
+.board .bi span{font-size:11px;color:var(--sub);display:block;margin-top:2px}
|
|
|
+.board .bd{font-size:10.5px;color:#0c7a48;background:#edfaf3;border:1px solid #cfeedd;border-radius:6px;padding:2px 6px;margin-top:6px;display:inline-block}
|
|
|
+.kv{display:grid;grid-template-columns:auto 1fr;gap:3px 12px;font-size:11.5px;margin-top:8px;font-variant-numeric:tabular-nums}
|
|
|
+.kv dt{color:var(--sub)}
|
|
|
+.kv dd{margin:0;text-align:right;color:var(--ink)}
|
|
|
+
|
|
|
+/* 表格 */
|
|
|
+.tbl{width:100%;border-collapse:collapse;font-size:11.5px;font-variant-numeric:tabular-nums}
|
|
|
+.tbl th,.tbl td{border-bottom:1px solid var(--line);padding:7px 6px;text-align:left;vertical-align:top}
|
|
|
+.tbl th{color:var(--sub);font-weight:500;font-size:11px;background:#fafbfd}
|
|
|
+.tbl td.num{text-align:right;white-space:nowrap}
|
|
|
+.tbl tr:last-child td{border-bottom:none}
|
|
|
+.scrollx{overflow-x:auto;-webkit-overflow-scrolling:touch;margin:0 -14px;padding:0 14px}
|
|
|
+
|
|
|
+/* 爆炸/装配 */
|
|
|
+.steprow{display:flex;gap:9px;align-items:flex-start;padding:9px 0;border-bottom:1px solid var(--line)}
|
|
|
+.steprow:last-child{border-bottom:none}
|
|
|
+.stepno{width:22px;height:22px;border-radius:50%;background:#eef4fe;color:var(--blue);font-size:11px;
|
|
|
+ display:flex;align-items:center;justify-content:center;flex:0 0 22px;font-weight:600}
|
|
|
+.steprow b{font-size:12.5px;display:block}
|
|
|
+.steprow span{font-size:11px;color:var(--sub);display:block}
|
|
|
+.parts .pr{display:flex;justify-content:space-between;font-size:11.5px;padding:7px 0;border-bottom:1px dashed var(--line);gap:10px}
|
|
|
+.parts .pr:last-child{border-bottom:none}
|
|
|
+.parts .pr em{font-style:normal;color:var(--sub);font-size:10.5px;text-align:right}
|
|
|
+
|
|
|
+/* 知识库 */
|
|
|
+.acc{border:1px solid var(--line);border-radius:12px;background:#fff;margin-bottom:10px;overflow:hidden;box-shadow:var(--shadow)}
|
|
|
+.acc summary{list-style:none;padding:13px 14px;font-size:13px;font-weight:600;display:flex;align-items:center;gap:9px;cursor:pointer}
|
|
|
+.acc summary::-webkit-details-marker{display:none}
|
|
|
+.acc summary .ix{font-size:10.5px;color:var(--blue);background:#eef4fe;border:1px solid #dbe6fa;border-radius:6px;padding:1px 6px}
|
|
|
+.acc summary .chev{margin-left:auto;color:var(--sub);font-size:12px;transition:transform .2s}
|
|
|
+.acc[open] summary .chev{transform:rotate(180deg)}
|
|
|
+.acc .body{padding:0 14px 14px;font-size:12.5px;color:#31425a;line-height:1.68}
|
|
|
+.acc .body p{margin:8px 0}
|
|
|
+.acc .body ul{margin:8px 0;padding-left:18px}
|
|
|
+.acc .body li{margin:3px 0}
|
|
|
+.acc .body code{background:#f1f4f9;padding:1px 5px;border-radius:4px;font-size:11.5px}
|
|
|
+.note{border-left:3px solid var(--amber);background:#fff8ec;padding:9px 11px;border-radius:0 8px 8px 0;font-size:11.5px;color:#6b4a13;margin:10px 0;line-height:1.6}
|
|
|
+.ref{display:block;border:1px solid var(--line);border-radius:12px;padding:11px;margin-bottom:8px;background:#fbfcfe}
|
|
|
+.ref b{font-size:12.5px;display:block;word-break:break-all}
|
|
|
+.ref span{font-size:10.5px;color:var(--sub);word-break:break-all;display:block;margin-top:3px}
|
|
|
+textarea{width:100%;border:1px solid var(--line);border-radius:10px;padding:10px;font-size:12px;font-family:inherit;line-height:1.6;min-height:96px;resize:vertical;background:#fafbfd}
|
|
|
+
|
|
|
+.foot{text-align:center;font-size:10.5px;color:#9aa7ba;margin:26px 0 8px;line-height:1.7}
|
|
|
+#toast{position:fixed;left:50%;bottom:86px;transform:translateX(-50%) translateY(8px);z-index:70;background:rgba(17,26,40,.92);
|
|
|
+ color:#eaf2ff;font-size:12px;padding:9px 14px;border-radius:10px;opacity:0;transition:opacity .2s,transform .2s;pointer-events:none;max-width:80vw;text-align:center}
|
|
|
+#toast.on{opacity:1;transform:translateX(-50%) translateY(0)}
|
|
|
+
|
|
|
+/* 建模页:工艺 chips / 形体面板 / 数值控件 / 校验 */
|
|
|
+.chips{display:flex;gap:6px;flex-wrap:wrap;margin:2px 0 10px}
|
|
|
+.chip{font-size:11px;padding:6px 11px;border-radius:999px;border:1px solid var(--line);background:#fff;color:var(--sub)}
|
|
|
+.chip.on{background:var(--ink);border-color:var(--ink);color:#fff}
|
|
|
+.palette{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:4px 0 8px}
|
|
|
+.pbtn{display:flex;flex-direction:column;gap:2px;padding:10px 8px;border-radius:12px;border:1px solid var(--line);background:#fff;text-align:left}
|
|
|
+.pbtn b{font-size:11.5px;color:var(--ink);font-weight:600}
|
|
|
+.pbtn span{font-size:9.5px;color:var(--sub)}
|
|
|
+.pbtn:active{background:#f2f7fe}
|
|
|
+.nrows{margin:6px 0 2px}
|
|
|
+.nrow{display:flex;align-items:center;gap:7px;padding:5px 0}
|
|
|
+.nrow .nl{flex:1;font-size:11.5px;color:var(--ink)}
|
|
|
+.nrow .nb{width:27px;height:27px;border-radius:8px;border:1px solid var(--line);background:#fff;font-size:14px;line-height:1;color:var(--sub);flex:none}
|
|
|
+.nrow .ni{width:64px;text-align:center;font-size:12px;padding:5px 3px;border-radius:8px;border:1px solid var(--line);background:#fff;color:var(--ink);font-variant-numeric:tabular-nums}
|
|
|
+.nrow em{font-style:normal;font-size:10px;color:var(--sub);width:16px;flex:none}
|
|
|
+.chk{display:flex;gap:8px;font-size:11.5px;line-height:1.55;padding:7px 0;border-bottom:1px dashed var(--line);color:#31425a}
|
|
|
+.chk:last-child{border-bottom:none}
|
|
|
+.chk i{font-style:normal;width:15px;height:15px;border-radius:50%;flex:none;display:flex;align-items:center;justify-content:center;font-size:9px;color:#fff;background:#0f9d58;margin-top:2px}
|
|
|
+.chk.bad i{background:#dc2626}
|
|
|
+.chk.bad span{color:#9a3412}
|
|
|
+.pr{display:flex;justify-content:space-between;align-items:center;gap:10px;font-size:11.5px;padding:8px 0;border-bottom:1px dashed var(--line)}
|
|
|
+.pr.on{background:#eef4fe}
|
|
|
+.pr b{font-weight:600;color:var(--ink)}
|
|
|
+.pr span{display:block;color:var(--sub);font-size:10.5px;margin-top:2px}
|
|
|
+.pr .del{font-size:10px;padding:4px 9px;border-radius:8px;border:1px solid var(--line);background:#fff;color:#9a3412;flex:none}
|
|
|
+
|
|
|
+/* 底栏(项目内) */
|
|
|
+.bottom{position:fixed;left:0;right:0;bottom:0;z-index:45;padding:8px 12px calc(8px + env(safe-area-inset-bottom));
|
|
|
+ background:rgba(255,255,255,.92);backdrop-filter:blur(14px);border-top:1px solid var(--line);display:flex;gap:8px}
|
|
|
+.bottom .btn{flex:1;min-width:0;text-align:center;font-size:12px;padding:9px 4px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
|
+
|
|
|
+/* 加载 */
|
|
|
+#boot{position:fixed;inset:0;z-index:99;background:#0d1726;color:#dbe7f7;display:flex;flex-direction:column;
|
|
|
+ align-items:center;justify-content:center;gap:14px;font-size:12.5px;letter-spacing:.5px;transition:opacity .3s}
|
|
|
+#boot .ring{width:34px;height:34px;border-radius:50%;border:2px solid rgba(255,255,255,.18);border-top-color:#4f92ff;
|
|
|
+ animation:spin 1s linear infinite}
|
|
|
+@keyframes spin{to{transform:rotate(360deg)}}
|
|
|
+#boot.hide{opacity:0;pointer-events:none}
|
|
|
+@media (max-width:380px){ .hero h2{font-size:22px} .thumb{width:64px;height:64px;flex-basis:64px} }
|
|
|
+/* 移动端单屏:迷你舞台 + 底部编辑坞 */
|
|
|
+.stage.mini{margin:0 -12px;border-radius:0 0 18px 18px;
|
|
|
+ height:calc(100vh - var(--dockH,46vh) - 8px);min-height:170px;max-height:none;
|
|
|
+ position:sticky;top:0;z-index:20;box-shadow:0 8px 22px rgba(12,24,44,.10)}
|
|
|
+.stage.mini .badge{display:none}
|
|
|
+.stage.mini .stage-top{left:8px;right:8px}
|
|
|
+.stage.mini .vbtn{padding:4px 9px;font-size:10.5px}
|
|
|
+.stage.mini .matrow{max-width:calc(100% - 16px)}
|
|
|
+.dock{position:fixed;left:0;right:0;bottom:var(--kb,0px);z-index:56;max-width:760px;margin:0 auto;height:var(--dockH,46vh);transition:height .22s cubic-bezier(.32,.94,.36,1);
|
|
|
+ background:#fff;border-radius:18px 18px 0 0;box-shadow:0 -10px 30px rgba(10,24,46,.22);
|
|
|
+ display:flex;flex-direction:column;border-top:1px solid #dfe8f6;padding-bottom:env(safe-area-inset-bottom)}
|
|
|
+.dock .grab{height:24px;flex:none;display:flex;align-items:center;justify-content:center;touch-action:none;cursor:grab}
|
|
|
+.dock .grab i{width:42px;height:4px;border-radius:2px;background:#c9d6e8}
|
|
|
+.dock .dhead{flex:none;display:flex;align-items:center;gap:8px;padding:2px 12px 6px}
|
|
|
+.dock .dhead b{font-size:13px;color:var(--ink)}
|
|
|
+.dock .dhead .em{font-size:10.5px;color:var(--sub);margin-left:6px}
|
|
|
+.dock .dhead .x{margin-left:auto;font-size:11px;padding:5px 10px;border-radius:9px;border:1px solid var(--line);background:#fff;color:#33415c}
|
|
|
+.dock .dbody{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:0 12px 14px;overscroll-behavior:contain}
|
|
|
+.dock .dsec{display:flex;align-items:baseline;gap:8px;margin:10px 0 4px;font-size:12px;font-weight:600;color:var(--ink)}
|
|
|
+.dock .dsec em{font-style:normal;font-size:10px;font-weight:400;color:var(--sub)}
|
|
|
+.dock .nrows{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0 10px}
|
|
|
+.dock .nrow{padding:4px 0;border-bottom:1px dashed #eef2f8;align-items:center}
|
|
|
+.dock .nrow .lab{flex:0 0 46px;font-size:10px;overflow:hidden;white-space:nowrap}
|
|
|
+.dock .nrow{gap:4px}
|
|
|
+.dock .nrow .nb{width:24px;height:24px;font-size:11px}
|
|
|
+.dock .nrow .ni{width:auto;min-width:0;font-size:11.5px;padding:4px 4px}
|
|
|
+.dock .btnrow .btn{font-size:11px;padding:7px 9px}
|
|
|
+.dock .nrow .ni{flex:1;min-width:0}
|
|
|
+.dock .nrow em{display:none}
|
|
|
+.dock .nrow .lab{font-size:10.5px}
|
|
|
+.dock .prow{display:flex;gap:6px;overflow-x:auto;padding:2px 0 6px;-webkit-overflow-scrolling:touch}
|
|
|
+.dock .pco{flex:none;min-width:88px;padding:7px 9px;border-radius:12px;border:1px solid var(--line);background:#fbfdff;text-align:left}
|
|
|
+.dock .pco b{display:block;font-size:11.5px;color:var(--ink);font-weight:600;white-space:nowrap}
|
|
|
+.dock .pco span{display:block;font-size:9.5px;color:var(--sub);margin-top:2px;white-space:nowrap}
|
|
|
+.dock .pco.hot{border-color:#bfd7ff;background:#f2f7ff}
|
|
|
+.dock.fold{height:auto;padding-bottom:calc(6px + env(safe-area-inset-bottom))}
|
|
|
+.dock.fold .grab{display:none}
|
|
|
+.dock .dbody .chips{flex-wrap:nowrap;overflow-x:auto;padding-bottom:4px;scrollbar-width:none}
|
|
|
+.dock .dbody .chips::-webkit-scrollbar{display:none}
|
|
|
+.dock .chips .chip{flex:0 0 auto;white-space:nowrap;font-size:11px;padding:6px 11px}
|
|
|
+.dock .prow{scrollbar-width:none}
|
|
|
+.dock .prow::-webkit-scrollbar{display:none}
|
|
|
+.dockpad{height:50vh}
|
|
|
+
|
|
|
+/* 坞内快捷导航 + 数字输入 + 拖拽态 */
|
|
|
+.dock.drag{transition:none}
|
|
|
+.dock .dnav{flex:none;display:flex;gap:6px;padding:0 12px 8px;overflow-x:auto;scrollbar-width:none}
|
|
|
+.dock .dnav::-webkit-scrollbar{display:none}
|
|
|
+.dock .dnav button{flex:0 0 auto;font-size:10.5px;padding:5px 10px;border-radius:20px;border:1px solid var(--line);background:#fff;color:#33415c}
|
|
|
+.dock .dnav button.on{background:#eef4fe;border-color:#c9dcff;color:#1f5fd0}
|
|
|
+.dock .hbt{width:28px;height:28px;border-radius:9px;border:1px solid var(--line);background:#fff;color:#33415c;font-size:13px;display:flex;align-items:center;justify-content:center}
|
|
|
+.dock .hbt:disabled{opacity:.35}
|
|
|
+.dock .dhead .tools{margin-left:auto;display:flex;gap:6px;align-items:center}
|
|
|
+.slider .lab .sv{width:56px;flex:0 0 56px;text-align:right;font-size:12px;font-weight:600;color:var(--ink);
|
|
|
+ border:none;border-bottom:1px dashed #c8d5e8;background:transparent;padding:1px 0;font-variant-numeric:tabular-nums}
|
|
|
+.slider .lab .sv:focus{outline:none;border-bottom-color:#1f6feb}
|
|
|
+.stage.mini .dimlayer{font-size:9px}
|
|
|
+@supports (height:100dvh){.stage.mini{height:calc(100dvh - var(--dockH,46vh) - 8px)}}
|
|
|
+.ghint{position:absolute;left:50%;bottom:54px;transform:translateX(-50%);
|
|
|
+ font-size:10px;color:#cfe2ff;background:rgba(12,26,46,.62);border:1px solid rgba(120,170,255,.25);
|
|
|
+ padding:4px 10px;border-radius:20px;white-space:nowrap;pointer-events:none;animation:gh 5s ease forwards}
|
|
|
+@keyframes gh{0%{opacity:0}12%{opacity:1}70%{opacity:1}100%{opacity:0;visibility:hidden}}
|
|
|
+</style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+<div id="boot"><div class="ring"></div><div id="bootmsg">正在装载 3D 工程台…</div></div>
|
|
|
+
|
|
|
+<app-root></app-root>
|
|
|
+
|
|
|
+<script type="module">
|
|
|
+/* =========================================================
|
|
|
+ 数据层:项目参数 / 材质 / 工艺 / 电子件 / 知识库
|
|
|
+ 单位统一 mm;价格为 2026-11 深圳·东莞行情区间(仅供参考)
|
|
|
+ ========================================================= */
|
|
|
+
|
|
|
+const MATERIALS = {
|
|
|
+ 'sil-black': {name:'硅胶 哑光黑', albedo:'#22262c', metallic:0.0, rough:0.62, cc:0.20, cci:0.30, swatch:'#22262c', note:'邵氏 A50,喷手感油'},
|
|
|
+ 'sil-pink': {name:'硅胶 哑光藕粉', albedo:'#d8a8b4', metallic:0.0, rough:0.60, cc:0.20, cci:0.28, swatch:'#d8a8b4', note:'双色拼色 A 料'},
|
|
|
+ 'sil-mint': {name:'硅胶 雾青', albedo:'#9fc8bd', metallic:0.0, rough:0.60, cc:0.18, cci:0.24, swatch:'#9fc8bd'},
|
|
|
+ 'abs-gloss': {name:'ABS 光面白', albedo:'#eceef1', metallic:0.0, rough:0.26, cc:0.55, cci:0.45, swatch:'#eceef1', note:'注塑本色,可丝印'},
|
|
|
+ 'abs-matte': {name:'ABS 喷油哑光', albedo:'#dfe3e8', metallic:0.0, rough:0.58, cc:0.10, cci:0.18, swatch:'#dfe3e8', note:'喷橡胶漆,耐磨 500g 摩擦'},
|
|
|
+ 'abs-black': {name:'ABS 哑光黑', albedo:'#1f2328', metallic:0.0, rough:0.50, cc:0.12, cci:0.20, swatch:'#1f2328'},
|
|
|
+ 'pc-clear': {name:'PC 透明', albedo:'#dfeaf5', metallic:0.0, rough:0.08, cc:0.6, cci:0.5, swatch:'#cfe2f3', alpha:0.42},
|
|
|
+ 'alu-silver': {name:'6061 阳极银', albedo:'#c7cfd8', metallic:1.0, rough:0.24, cc:0.18, cci:0.42, swatch:'#c7cfd8', note:'喷砂+阳极 10~15μm'},
|
|
|
+ 'alu-sand': {name:'6061 喷砂银', albedo:'#c6ccd3', metallic:1.0, rough:0.60, cc:0.05, cci:0.12, swatch:'#c6ccd3'},
|
|
|
+ 'alu-black': {name:'6061 阳极黑', albedo:'#282c31', metallic:0.9, rough:0.36, cc:0.16, cci:0.30, swatch:'#282c31', note:'阳极后螺纹需二次回攻'},
|
|
|
+ 'alu-rose': {name:'6061 阳极玫瑰金', albedo:'#d9b49a', metallic:1.0, rough:0.30, cc:0.15, cci:0.35, swatch:'#d9b49a'}
|
|
|
+};
|
|
|
+
|
|
|
+/* 内固定材质(不参与材质切换) */
|
|
|
+const FIXED_MATS = {
|
|
|
+ glass: {albedo:'#070b10', metallic:0.3, rough:0.06, cc:0.9, cci:0.6},
|
|
|
+ pcb: {albedo:'#071d17', metallic:0.08, rough:0.78, env:0.28},
|
|
|
+ pcbDark:{albedo:'#0b1620', metallic:0.15, rough:0.62, env:0.3},
|
|
|
+ cell: {albedo:'#2b3138', metallic:0.15, rough:0.72},
|
|
|
+ brass: {albedo:'#b08d57', metallic:1.0, rough:0.34},
|
|
|
+ dark: {albedo:'#12161b', metallic:0.15, rough:0.5},
|
|
|
+ cut: {albedo:'#ff7a45', metallic:0.0, rough:0.55, alpha:0.42}
|
|
|
+};
|
|
|
+
|
|
|
+/* ---------------- 三个项目 ---------------- */
|
|
|
+const PROJECTS = {
|
|
|
+ silicone: {
|
|
|
+ id:'silicone', name:'小恶魔硅胶表壳', en:'SILICONE WATCH CASE',
|
|
|
+ ref:'HUAWEI GT4 / GT5 41mm · 双色拼色',
|
|
|
+ accent:'#c993a2',
|
|
|
+ summary:'包表式硅胶保护壳:外框一体模压、顶部双立体小角、侧边表冠避让。适合小批量双色拼色试产。',
|
|
|
+ tags:['硅胶模压','双色拼色','MOQ 500'],
|
|
|
+ params:[
|
|
|
+ {k:'w', n:'内腔宽', min:30, max:48, step:0.5, def:40.5, group:'腔体'},
|
|
|
+ {k:'d', n:'内腔高', min:30, max:48, step:0.5, def:40.5, group:'腔体'},
|
|
|
+ {k:'t', n:'壁厚', min:1.2, max:4, step:0.1, def:2.4, group:'腔体'},
|
|
|
+ {k:'h', n:'总高', min:8, max:16, step:0.2, def:11.5, group:'腔体'},
|
|
|
+ {k:'r', n:'内腔圆角', min:4, max:22, step:0.5, def:13, group:'腔体'},
|
|
|
+ {k:'hh', n:'小角高度', min:1, max:14, step:0.5, def:7, group:'双角'},
|
|
|
+ {k:'hg', n:'双角间距', min:8, max:36, step:0.5, def:22, group:'双角'},
|
|
|
+ {k:'hd', n:'角底直径', min:3, max:10, step:0.2, def:5.2, group:'双角'},
|
|
|
+ {k:'cr', n:'表冠凸出', min:0, max:3, step:0.1, def:1.4, group:'侧边'}
|
|
|
+ ],
|
|
|
+ materials:['sil-pink','sil-black','sil-mint','abs-gloss','alu-silver'],
|
|
|
+ parts:[
|
|
|
+ {id:'body', n:'硅胶壳体(空心圆角框)', q:'1', mat:'主材质', proc:'模压/液态硅胶', tol:'±0.10'},
|
|
|
+ {id:'floor', n:'底托(贴机身层)', q:'1', mat:'同壳体', proc:'同模一体', tol:'±0.10'},
|
|
|
+ {id:'hornL', n:'立体小角(左)', q:'1', mat:'B 色/同色', proc:'一体模压', tol:'±0.15'},
|
|
|
+ {id:'hornR', n:'立体小角(右)', q:'1', mat:'B 色/同色', proc:'一体模压', tol:'±0.15'},
|
|
|
+ {id:'screen', n:'屏幕视窗(透光面)', q:'1', mat:'PC 透明/裸屏', proc:'—', tol:'±0.05'},
|
|
|
+ {id:'crown', n:'表冠避让孔', q:'1', mat:'—', proc:'模压开孔', tol:'±0.15'}
|
|
|
+ ],
|
|
|
+ steps:[
|
|
|
+ {n:'壳体出模、去毛刺', d:'硅胶模压后修边,双角与框体一体,检查双角色差 ΔE≤1.5。'},
|
|
|
+ {n:'贴底托 / 装表体', d:'表体从内腔嵌入,壁厚 2.4mm 提供回弹夹持,不靠胶水。'},
|
|
|
+ {n:'屏幕视窗对位', d:'视窗与表盘贴合,四边留 0.15mm 缓冲,避免顶屏。'},
|
|
|
+ {n:'表冠穿孔校验', d:'表冠凸出位开孔,孔径比表冠大 0.3mm,保证按压不涩。'},
|
|
|
+ {n:'手感油 / 丝印', d:'表面喷手感油(哑光),logo 丝印或镭雕在底托背面。'}
|
|
|
+ ],
|
|
|
+ processes:[
|
|
|
+ {key:'sil-mold', n:'硅胶模压(钢模)', mold:2200, minQty:500, unit:[[500,5.2],[1000,4.2],[3000,3.4],[5000,2.9]], lead:'12~18 天', note:'双色需两套模/两次成型,模具费上浮 40%'},
|
|
|
+ {key:'vacuum', n:'真空复模(小批量验证)', mold:300, minQty:10, unit:[[10,26],[30,18],[100,12]], lead:'5~8 天', note:'硅胶模寿命 20~40 件,适合内测'},
|
|
|
+ {key:'cnc', n:'CNC 手板(ABS/铝)', mold:0, minQty:1, unit:[[1,90],[5,68],[20,46],[50,36]], lead:'3~7 天', note:'含编程调机,后处理另计'}
|
|
|
+ ],
|
|
|
+ notes:[
|
|
|
+ '硅胶最小壁厚建议 ≥1.2mm;本款 2.4mm 属回弹夹持区,低于 1.8mm 易松脱。',
|
|
|
+ '双角若与框体同色可一次成型;双色需双料注塑或二次硫化套色,单价上浮 15%~25%。',
|
|
|
+ '表壳包表,内腔尺寸需按实机 ±0.1mm 复测,不能只按官网标称开模。'
|
|
|
+ ],
|
|
|
+ tolerance:[['内腔宽/高','±0.10'],['壁厚','±0.08'],['双角位置','±0.20'],['孔位','±0.15'],['未注公差','ISO 2768-m']],
|
|
|
+ files:['STEP(AP214,含内腔曲面)','STL(弦高 0.05mm)','2D PDF A3 三视图 + 剖视','色卡 Pantone/劳尔号']
|
|
|
+ },
|
|
|
+
|
|
|
+ recorder: {
|
|
|
+ id:'recorder', name:'AI 录音豆外壳', en:'AI RECORDER PUCK',
|
|
|
+ ref:'Φ32 磁吸挂扣 · ABS 注塑',
|
|
|
+ accent:'#8fa3bd',
|
|
|
+ summary:'圆形豆状外壳:上盖穹顶、侧挂环、四麦孔阵列、Type-C 与单键。内部为自制 PCBA + 软包电芯。',
|
|
|
+ tags:['ABS 注塑','卡扣装配','MOQ 500'],
|
|
|
+ params:[
|
|
|
+ {k:'D', n:'外径', min:24, max:46, step:0.5, def:32, group:'主体'},
|
|
|
+ {k:'H', n:'总高', min:8, max:20, step:0.2, def:11.5, group:'主体'},
|
|
|
+ {k:'t', n:'壁厚', min:1.0, max:2.6, step:0.1, def:1.6, group:'主体'},
|
|
|
+ {k:'dm', n:'穹顶弧高', min:0, max:4, step:0.1, def:1.6, group:'主体'},
|
|
|
+ {k:'ld', n:'挂环孔径', min:3, max:10, step:0.5, def:4.5, group:'挂扣'},
|
|
|
+ {k:'lh', n:'挂环长度', min:2, max:8, step:0.5, def:4, group:'挂扣'}
|
|
|
+ ],
|
|
|
+ materials:['abs-gloss','abs-matte','abs-black','pc-clear','alu-silver','sil-black'],
|
|
|
+ parts:[
|
|
|
+ {id:'body', n:'下壳(含电池仓)', q:'1', mat:'主材质', proc:'注塑 / CNC', tol:'±0.10'},
|
|
|
+ {id:'lid', n:'上盖(穹顶+麦孔)', q:'1', mat:'主材质', proc:'注塑 / CNC', tol:'±0.10'},
|
|
|
+ {id:'loop', n:'侧挂环', q:'1', mat:'同壳体', proc:'一体/后装', tol:'±0.20'},
|
|
|
+ {id:'mic', n:'MEMS 麦孔 ×4', q:'4', mat:'—', proc:'钻孔 Ø1.0', tol:'±0.05'},
|
|
|
+ {id:'usbc', n:'Type-C 开口', q:'1', mat:'—', proc:'开孔 9.0×3.4', tol:'±0.08'},
|
|
|
+ {id:'btn', n:'功能按键', q:'1', mat:'同壳体', proc:'注塑 + 硅胶垫', tol:'±0.10'},
|
|
|
+ {id:'pcb', n:'主控板 Φ26', q:'1', mat:'FR-4', proc:'外购/自制', tol:'±0.15'},
|
|
|
+ {id:'cell', n:'软包电芯 402030', q:'1', mat:'锂电', proc:'外购 3.7V', tol:'±0.5'}
|
|
|
+ ],
|
|
|
+ steps:[
|
|
|
+ {n:'下壳装电芯', d:'402030 软包(4.0×20×30mm)卡入电池仓,留 5% 膨胀余量。'},
|
|
|
+ {n:'PCBA 卡扣固定', d:'Φ26 主板落在 3 处限位柱上,卡扣压紧,不用螺丝。'},
|
|
|
+ {n:'焊线 / 接口', d:'电池线走 MX1.25 或焊盘,Type-C 母座对准侧开口 ±0.1。'},
|
|
|
+ {n:'上盖合模', d:'上盖与下壳卡扣环扣合,麦孔朝上,环形密封槽可加防水胶。'},
|
|
|
+ {n:'挂环 + 老化测试', d:'挂环过 5kg 静拉,整机 2h 老化 + 麦克风灵敏度抽检。'}
|
|
|
+ ],
|
|
|
+ processes:[
|
|
|
+ {key:'abs-mold', n:'ABS 注塑(钢模)', mold:6500, minQty:500, unit:[[500,5.0],[1000,4.1],[3000,3.4],[5000,2.8]], lead:'15~20 天', note:'上下壳+按键三套模,含试模'},
|
|
|
+ {key:'vacuum', n:'真空复模', mold:300, minQty:10, unit:[[10,28],[30,19],[100,13]], lead:'5~8 天'},
|
|
|
+ {key:'cnc', n:'CNC 铝/ABS 手板', mold:0, minQty:1, unit:[[1,120],[5,86],[20,58],[50,44]], lead:'3~7 天'}
|
|
|
+ ],
|
|
|
+ notes:[
|
|
|
+ '麦孔阵列孔径 Ø1.0,孔后需 1.5mm 声腔,孔壁不能与壳体壁厚直接贯通。',
|
|
|
+ '卡扣合模需 0.5mm 过盈 + 单边 1° 导向角,否则量产装配良率掉到 80% 以下。',
|
|
|
+ '若走公模贴牌,MOQ 可降到 200 台整机;只做外观件仍按 500 套起。'
|
|
|
+ ],
|
|
|
+ tolerance:[['外径','±0.10'],['总高','±0.15'],['麦孔','±0.05'],['Type-C 开口','±0.08'],['未注公差','ISO 2768-m']],
|
|
|
+ files:['STEP(AP214 含卡扣)','STL 上下壳分件','2D PDF 含开孔坐标表','装配示意图(爆炸序)']
|
|
|
+ },
|
|
|
+
|
|
|
+ round: {
|
|
|
+ id:'round', name:'1.85″ 圆屏铝壳', en:'ROUND LCD AL CASE',
|
|
|
+ ref:'Φ61.6 × 14.6 · 参考微雪 1.85B',
|
|
|
+ accent:'#aab6c4',
|
|
|
+ summary:'电子吧唧造型:前框沉台固定 1.85″ 圆屏、后盖旋合、四颗 M2 铜柱锁板、侧边双麦与 Type-C。',
|
|
|
+ tags:['6061 CNC','沉台 ±0.03','阳极氧化'],
|
|
|
+ params:[
|
|
|
+ {k:'D', n:'外径', min:50, max:72, step:0.2, def:61.6, group:'主体'},
|
|
|
+ {k:'H', n:'总厚', min:11, max:20, step:0.2, def:14.6, group:'主体'},
|
|
|
+ {k:'t', n:'壁厚', min:1.4, max:3.2, step:0.1, def:2.0, group:'主体'},
|
|
|
+ {k:'sd', n:'屏可视径', min:38, max:54, step:0.2, def:45.68, group:'屏幕'},
|
|
|
+ {k:'bd', n:'黑边外径', min:44, max:58, step:0.2, def:55.0, group:'屏幕'},
|
|
|
+ {k:'dep', n:'屏边弧深(沉台R)', min:0.5, max:2.2, step:0.1, def:1.2, group:'CNC 工艺'},
|
|
|
+ {k:'rimR',n:'顶部凸圆 R(CNC)', min:0.6, max:3.4, step:0.1, def:1.8, group:'CNC 工艺'},
|
|
|
+ {k:'cham',n:'底边倒角 C(CNC)', min:0, max:1.2, step:0.1, def:0.5, group:'CNC 工艺'},
|
|
|
+ {k:'cap', n:'后盖厚', min:1.5, max:4, step:0.1, def:2.4, group:'后盖'}
|
|
|
+ ],
|
|
|
+ materials:['alu-silver','alu-sand','alu-black','alu-rose','abs-gloss'],
|
|
|
+ parts:[
|
|
|
+ {id:'bezel', n:'前框(沉台+螺纹)', q:'1', mat:'主材质', proc:'CNC 五轴 + 阳极', tol:'±0.05'},
|
|
|
+ {id:'glass', n:'1.85″ 屏(AA Ø45.68)', q:'1', mat:'外购模组', proc:'—', tol:'±0.10'},
|
|
|
+ {id:'black', n:'黑边装饰环 Ø55', q:'1', mat:'丝印/黑膜', proc:'—', tol:'±0.10'},
|
|
|
+ {id:'cap', n:'后盖(M54×1.5 示意)', q:'1', mat:'主材质', proc:'CNC + 阳极 + 回攻', tol:'±0.05'},
|
|
|
+ {id:'boss', n:'M2 铜柱 ×4', q:'4', mat:'黄铜嵌件', proc:'CNC 攻牙/嵌件', tol:'±0.05'},
|
|
|
+ {id:'pcb', n:'主控板 Φ44', q:'1', mat:'FR-4', proc:'微雪模组', tol:'±0.2'},
|
|
|
+ {id:'cell', n:'锂电 3.7V', q:'1', mat:'软包', proc:'外购', tol:'±0.5'},
|
|
|
+ {id:'side', n:'侧键 / Type-C / 双麦', q:'1', mat:'—', proc:'开孔 + 密封', tol:'±0.08'}
|
|
|
+ ],
|
|
|
+ steps:[
|
|
|
+ {n:'前框阳极 + 螺纹回攻', d:'阳极后 M54×1.5 必须二次回攻,否则后盖咬死。'},
|
|
|
+ {n:'屏入沉台', d:'沉台深 1.2mm,屏厚 1.0mm + 0.2mm 缓冲垫;深 0.1mm 即顶屏。'},
|
|
|
+ {n:'主板锁铜柱', d:'4×M2 铜柱同轴度 ≤0.05,板与壳间加绝缘垫避天线。'},
|
|
|
+ {n:'电池 + 走线', d:'电芯贴后盖,FPC 走侧槽,避开金属腔体谐振点。'},
|
|
|
+ {n:'后盖旋合', d:'M54×1.5 旋 2.5 圈到位,做 0.5m 跌落与气密抽检。'}
|
|
|
+ ],
|
|
|
+ processes:[
|
|
|
+ {key:'cnc-alu', n:'CNC 铝 6061(手板)', mold:0, minQty:1, unit:[[1,135],[5,98],[20,72],[50,58],[200,48]], lead:'5~10 天', note:'含编程,阳极 10~15 元/套另计'},
|
|
|
+ {key:'cnc-abs', n:'CNC ABS(验证用)', mold:0, minQty:1, unit:[[1,85],[5,60],[20,38],[50,28]], lead:'3~6 天', note:'螺纹易滑牙,不建议做量产件'},
|
|
|
+ {key:'die-cast',n:'压铸铝 + CNC 精修', mold:12000, minQty:1000, unit:[[1000,32],[3000,26],[5000,22]], lead:'25~35 天', note:'量产路径,需评估壁厚与阳极'}
|
|
|
+ ],
|
|
|
+ notes:[
|
|
|
+ '沉台深度公差 ±0.03 是整件成本核心,检测需三坐标或专用检具。',
|
|
|
+ '铝合金外壳会屏蔽 2.4G,天线区域必须开非金属窗或做塑胶拼接。',
|
|
|
+ '螺纹后盖在小批量下报废率高(15%~25%),可改 4×M2 螺丝锁盖降本 15~25 元/套。'
|
|
|
+ ],
|
|
|
+ tolerance:[['外径','±0.05'],['总厚','±0.10'],['沉台深','±0.03'],['铜柱同轴','≤0.05'],['螺纹','M54×1.5-6H(示意)']],
|
|
|
+ files:['STEP(AP214,含螺纹实体)','STL 分件','2D PDF 关键尺寸 + GD&T','阳极色板 / 膜厚要求']
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+/* ---------------- 电子件库 ---------------- */
|
|
|
+const BOARDS = [
|
|
|
+ {
|
|
|
+ id:'ws185', name:'微雪 ESP32-S3-Touch-LCD-1.85B', tag:'首选 · 成品模组',
|
|
|
+ od:'Ø61.6 × 14.6', screen:'1.85″ 圆屏 360×360', iface:'QSPI 屏 / I2C 触摸 / Type-C',
|
|
|
+ soc:'ESP32-S3R8 · 240MHz · 8MB PSRAM · 16MB Flash',
|
|
|
+ extra:'ES8311 编解码 + ES7210 回声消除 + 双麦阵列 + QMI8658 六轴 + BQ27220 电量 + PCF85063 RTC + MicroSD + MX1.25 电池口 + SH1.0×2',
|
|
|
+ price:'¥208.06 起(1 件,含税)', fit:'round',
|
|
|
+ note:'官方尺寸 Ø61.60 / Ø55.00 / 屏 AA Ø45.68 / 厚 14.60。带壳整机,直接拆壳复用最省事。',
|
|
|
+ source:'waveshare.net / docs.waveshare.net'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'ws128', name:'GC9A01 1.28″ 圆屏 + ESP32-S3 底板', tag:'低成本替代',
|
|
|
+ od:'Ø32.4 屏 / 底板 40×40(参考)', screen:'1.28″ 240×240', iface:'SPI 屏 / I2C',
|
|
|
+ soc:'ESP32-S3-WROOM-1(18×25.5×3.1)',
|
|
|
+ extra:'需自配麦克风与功放;无成品壳,需自己做结构',
|
|
|
+ price:'屏 ¥18~28 / 底板 ¥35~60', fit:'recorder',
|
|
|
+ note:'尺寸为常见模组值,采购前以实际规格书核对;适合做 Φ32 录音豆的主板。',
|
|
|
+ source:'通用模组,需核对'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'esp32s3', name:'ESP32-S3-WROOM-1 模组', tag:'核心件',
|
|
|
+ od:'18.0 × 25.5 × 3.1', screen:'—', iface:'2.4G WiFi + BLE5',
|
|
|
+ soc:'双核 LX7 240MHz · 8MB PSRAM 选配',
|
|
|
+ extra:'需底板:电源、麦克风、功放、充电管理',
|
|
|
+ price:'¥18~30', fit:'recorder',
|
|
|
+ note:'天线净空区 15mm 内不得有金属/电池,壳体需留塑胶窗。',
|
|
|
+ source:'Espressif 数据手册'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'mic', name:'INMP441 I2S MEMS 麦克风', tag:'拾音',
|
|
|
+ od:'15 × 14(模块,参考)', screen:'—', iface:'I2S',
|
|
|
+ soc:'—', extra:'信噪比 61dB,灵敏度 -26dBFS',
|
|
|
+ price:'¥5~9', fit:'recorder',
|
|
|
+ note:'麦孔 Ø1.0 + 后腔 1.5mm;四麦阵列间距建议 ≥8mm 做波束。',
|
|
|
+ source:'模块规格,需核对'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'amp', name:'MAX98357A I2S 功放', tag:'发声',
|
|
|
+ od:'模块 15 × 15(参考)', screen:'—', iface:'I2S + 2.5W',
|
|
|
+ soc:'—', extra:'D 类,需 8Ω 腔体喇叭',
|
|
|
+ price:'¥8~15', fit:'recorder',
|
|
|
+ note:'腔体扬声器与麦孔要隔离,否则回声消除压力大。',
|
|
|
+ source:'模块规格,需核对'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'cell402030', name:'软包锂电 402030', tag:'供电',
|
|
|
+ od:'4.0 × 20 × 30(厚×宽×长)', screen:'—', iface:'3.7V / 约 180~220mAh',
|
|
|
+ soc:'—', extra:'需保护板 + MX1.25 或焊线',
|
|
|
+ price:'¥6~10', fit:'recorder',
|
|
|
+ note:'留 5% 膨胀空间,远离发热器件 2mm 以上。',
|
|
|
+ source:'常见规格,需核对'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'cell103450', name:'软包锂电 103450', tag:'供电',
|
|
|
+ od:'10 × 34 × 50', screen:'—', iface:'3.7V / 约 1800~2000mAh',
|
|
|
+ soc:'—', extra:'适用 Φ61 圆屏机',
|
|
|
+ price:'¥12~18', fit:'round',
|
|
|
+ note:'厚度 10mm + 结构件,Φ61.6 / 14.6 机身内需精确排布。',
|
|
|
+ source:'常见规格,需核对'
|
|
|
+ }
|
|
|
+];
|
|
|
+
|
|
|
+/* ---------------- 知识库 ---------------- */
|
|
|
+const KB = [
|
|
|
+ {
|
|
|
+ id:'process', ix:'01', title:'七种壳体工艺对照(MOQ / 模具 / 单价 / 交期)',
|
|
|
+ body:[
|
|
|
+ ['table', ['工艺','典型 MOQ','一次性费用','单价区间','交期','适用'],[
|
|
|
+ ['硅胶模压(钢模)','500 套','¥1,800~3,500','¥2.5~6/套','12~18 天','量产软壳、包表、双色拼色'],
|
|
|
+ ['ABS/PC 注塑(钢模)','500 套','¥5,500~9,000','¥2.8~6/套','15~20 天','硬壳量产,外观件首选'],
|
|
|
+ ['压铸铝 + CNC','1,000 套','¥10,000~22,000','¥22~32/套','25~35 天','金属量产,需评估阳极'],
|
|
|
+ ['CNC 手板(铝/ABS)','1 件','无模具,收编程调机','¥28~135/套','3~10 天','样机、内测、小批量'],
|
|
|
+ ['真空复模(硅胶模)','10 件','¥200~400','¥12~28/套','5~8 天','10~100 件验证'],
|
|
|
+ ['3D 打印(SLA/FDM)','1 件','无','¥20~60/套','2~4 天','结构验证,不做外观件'],
|
|
|
+ ['公模贴牌','100~200 件','无','¥3~8/套','7~12 天','已有模具,只改色/丝印']
|
|
|
+ ]],
|
|
|
+ ['p','判断口径:一次性费用 ÷ 数量 + 单品价 = 单套综合成本。数量过 200~300 套后,CNC 的总成本通常反超「开模 + 注塑」。']
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'formats', ix:'02', title:'生产端到底要哪些文件格式(按工艺给清单)',
|
|
|
+ body:[
|
|
|
+ ['table', ['格式','用途','要给谁','注意'],[
|
|
|
+ ['STEP AP214/AP203','3D 实体,含曲面与螺纹','模具厂 / CNC 编程','首选。必须带内腔、卡扣、螺纹实体,不能只给网格'],
|
|
|
+ ['STL(弦高 0.05mm)','网格,快速评估与 3D 打印','手板厂 / 打印','只用于看形,不能直接开钢模'],
|
|
|
+ ['3MF','打印用,含颜色与单位','3D 打印','比 STL 稳,少破面'],
|
|
|
+ ['OBJ','带材质分组的网格','渲染 / 展示','不适合生产'],
|
|
|
+ ['DXF','2D 轮廓 / 开孔坐标','线切割、开孔','配合 2D 图纸使用'],
|
|
|
+ ['PDF A3 2D 图纸','三视图 + 剖视 + 尺寸 + GD&T','所有人','1:1 打印,标基准 A/B/C'],
|
|
|
+ ['BOM / CSV','零件、材质、数量、工艺','采购 / 报价','报价必须逐项回填'],
|
|
|
+ ['色卡 / 膜厚要求','阳极色号、Pantone、Ra','表面处理厂','不给色号一定返工']
|
|
|
+ ]],
|
|
|
+ ['p','给工厂的最小闭环:STEP + 2D PDF + 需求单(材质/工艺/公差/数量/表面处理)。只给 STL 或只给图片,正规厂会直接判定为「无法报价」。']
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'draw', ix:'03', title:'2D 图纸标注规范(手机端也能看懂的最小集)',
|
|
|
+ body:[
|
|
|
+ ['ul',[
|
|
|
+ '基准:主基准 A(底面)、B/C(两互相垂直的边或中心线),铜柱与孔位全部相对基准标注。',
|
|
|
+ '关键尺寸:沉台深、螺纹规格、壁厚、孔位坐标、装配间隙,逐项给公差。',
|
|
|
+ '未注公差:ABS/硅胶 ISO 2768-m;CNC 金属建议 ±0.1 或 2768-f。',
|
|
|
+ '形位公差:铜柱同轴度 ≤0.05,平面度 0.1,沉台对基准面平行度 0.05。',
|
|
|
+ '表面:Ra 标注(CNC 铝 Ra1.6,喷砂 Ra3.2),阳极膜厚 10~15μm。',
|
|
|
+ '螺纹:M54×1.5-6H(示意);标注「阳极后二次回攻」字样。',
|
|
|
+ '去毛刺、倒角 C0.3、脱模斜度 1°~2°,写在技术要求里而不是画在图上。'
|
|
|
+ ]],
|
|
|
+ ['note','本项目导出的是「需求描述单 + STL/OBJ + 尺寸表」,够工厂报价和评估;正式开模仍需要 STEP 或由工厂按图建模(建模费 ¥500~1,500)。']
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'dfm', ix:'04', title:'DFM 检查清单(开模前逐条过)',
|
|
|
+ body:[
|
|
|
+ ['table', ['项目','经验值','违反后果'],[
|
|
|
+ ['ABS 壁厚','1.2~2.0mm,均匀','缩水、变形、装配错位'],
|
|
|
+ ['硅胶壁厚','≥1.2mm,回弹区 2~3mm','夹持松脱、撕裂'],
|
|
|
+ ['拔模斜度','1°~2°(纹理面 3°)','拉伤、顶白'],
|
|
|
+ ['内圆角','≥0.5×壁厚','应力集中、开裂'],
|
|
|
+ ['卡扣','过盈 0.3~0.5mm + 1° 导向','装配良率 <80%'],
|
|
|
+ ['螺丝柱','M2 外径 Φ4.0,内孔 Φ1.6','滑牙、缩水'],
|
|
|
+ ['沉台','深公差 ±0.03,圆角 R0.2','顶碎屏 / 漏光'],
|
|
|
+ ['天线净空','15mm 内无金属与电池','WiFi 掉到 -75dBm'],
|
|
|
+ ['密封','槽宽 1.0 + 0.5mm 压缩量','气密不过'],
|
|
|
+ ['脱模','顶针位避开外观面','顶白不可修']
|
|
|
+ ]]
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'cost', ix:'05', title:'报价谈判口径(怎么问才不被糊)',
|
|
|
+ body:[
|
|
|
+ ['ul',[
|
|
|
+ '先问「模具费是否含试模、改模几次、模具归属」,不接受「模具费摊在单价里」的模糊说法。',
|
|
|
+ '要求分项:材料费 / 加工费 / 表面处理 / 包装 / 模具 / 打样,一口价无法比价。',
|
|
|
+ '问清 MOQ 是「模具起订」还是「后处理开机费」。喷油、阳极常有 20 件开机门槛。',
|
|
|
+ '问清公差是按图纸全检还是抽检,首件是否提供三坐标报告。',
|
|
|
+ '小批量先做手板(CNC/复模),确认装配与手感后再投钢模,避免 ¥6,500 打水漂。',
|
|
|
+ '报价单必须写有效期与含税/不含税,模具费通常单独开票。'
|
|
|
+ ]]
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'elec', ix:'06', title:'电子件选型原则:先用成熟开发板,别自己打板',
|
|
|
+ body:[
|
|
|
+ ['p','这一轮产品(录音豆 / 圆屏吧唧 / 表壳配件)全部走「成熟模组 + 焊接/接插件 + 结构固定」,把 PCB 风险降到最低。'],
|
|
|
+ ['ul',[
|
|
|
+ '圆屏机直接复用微雪 1.85B 整机:屏、触摸、双麦、功放、IMU、电量、RTC、Type-C、锂电口全部现成,只做外壳替换。',
|
|
|
+ '录音豆用 ESP32-S3-WROOM-1 + INMP441 + MAX98357A + TP4056 + 402030 电芯,飞线或洞洞板即可完成原型。',
|
|
|
+ '需要量产再把模组方案转成邮票孔底板(仍不打主控板),单板成本可压到 ¥25~40。',
|
|
|
+ '结构件必须给电子件留「装配余量 + 天线净空 + 声腔」,否则外壳做完装不进去。',
|
|
|
+ '接口固定优先卡扣/限位柱,其次 M2 螺丝;能不用胶就不用胶。'
|
|
|
+ ]],
|
|
|
+ ['note','电子件尺寸一律以官方图纸为准;本项目内的尺寸用于排布预演,打样前需实测。']
|
|
|
+ ]
|
|
|
+ }
|
|
|
+];
|
|
|
+
|
|
|
+KB.push({
|
|
|
+ id:'surface', ix:'07', title:'表面处理:阳极 / 喷油 / 镭雕怎么选',
|
|
|
+ body:[
|
|
|
+ ['table',['工艺','效果','成本','注意'],[
|
|
|
+ ['阳极氧化(铝)','金属质感、耐磨、绝缘','¥6~15/套(含前处理)','颜色批次色差 ΔE≤1.5;螺纹需二次回攻;膜厚 10~15μm'],
|
|
|
+ ['喷砂 + 阳极','细腻哑光金属','¥3~8/套 加价','砂号 120#~220#,同一批统一喷砂压力'],
|
|
|
+ ['喷橡胶漆(ABS)','类肤手感、遮缩水','¥1.5~3/套','耐磨 500g/100 次;边角易露底'],
|
|
|
+ ['UV 高光(ABS)','局部亮面','¥0.8~2/套','需专用治具,小批量分摊高'],
|
|
|
+ ['丝印 / 移印','logo、刻度','¥0.5~1.5/处','最小线宽 0.15,套色 ≤4 色'],
|
|
|
+ ['镭雕','永久标识、细字','¥0.3~0.8/处','浅色底要打深色底漆才清晰']
|
|
|
+ ]],
|
|
|
+ ['note','表面处理常有最小开机批次(喷油 20 件、阳极 50 件)。数量不足时会被收整批开机费,这也是「CNC 件突然报 MOQ」的常见原因。']
|
|
|
+ ]
|
|
|
+});
|
|
|
+KB.push({
|
|
|
+ id:'timeline', ix:'08', title:'从创意到量产的 6 个里程碑',
|
|
|
+ body:[
|
|
|
+ ['ul',[
|
|
|
+ 'M1 概念锁定:定外形尺寸、材质、装配方式,产出参数快照(本工具即可)。',
|
|
|
+ 'M2 手板验证:CNC/复模 1~5 套,装电子件实测干涉、手感、天线。',
|
|
|
+ 'M3 图纸冻结:补 STEP、2D 图纸、公差与 GD&T,供应商 DFM 回签。',
|
|
|
+ 'M4 开模试模:T1 试模件确认缩水/变形,T2 修模后做首件报告。',
|
|
|
+ 'M5 小批试产:50~200 套,跑装配良率与老化,锁定工艺参数。',
|
|
|
+ 'M6 量产:MOQ 起订,按 AQL 抽检,模具与治具归档。'
|
|
|
+ ]],
|
|
|
+ ['p','关键卡点:M2 不做就直接开模,是 80% 外观件返工的原因;M3 不给 STEP 只给图片,正规厂不会接。']
|
|
|
+ ]
|
|
|
+});
|
|
|
+
|
|
|
+KB.push({
|
|
|
+ id:'model', ix:'09', title:'工艺化轻量建模:为什么「自由雕刻」要按工艺分规则',
|
|
|
+ body:[
|
|
|
+ ['p','网页端没有实体布尔运算(不开 CSG 是怕曲面炸开),所以建模走「参数化主体 + 附加结构体」:主体由尺寸参数定义,内部筋、铜柱、开槽、开孔以独立结构件叠加,位置用毫米数值 + 吸附精确控制。'],
|
|
|
+ ['table',['工艺','自由度','必须在模型里标出来的东西'],
|
|
|
+ [['注塑 / 硅胶','高:筋、柱、槽都能加','拔模角、最小壁厚、筋厚、圆角、缩水率'],
|
|
|
+ ['CNC 铝','中:以减料为主','刀具半径(内角 R)、最小壁厚、深腔比、螺纹规格、基准与公差'],
|
|
|
+ ['真空复模','中:同注塑但更自由','收缩补偿 0.3%、壁厚 ≥1.2'],
|
|
|
+ ['压铸','低:拔模与料位受限','拔模 ≥1.5°、料位/渣包、后加工余量']]],
|
|
|
+ ['ul',[
|
|
|
+ '吸附口径:位置吸附 0.5 / 1 / 5 mm;「贴内壁」按内腔边界自动算 x/z,不留手算误差。',
|
|
|
+ '每加一个结构件都要能报出:位置(x,y,z)、外形尺寸、壁厚/筋厚、与内腔的余量。',
|
|
|
+ '余量 < 1mm 的结构件,注塑会粘模、CNC 会让刀,模型阶段就要报警。',
|
|
|
+ '导出时结构件随主体一起进 STL/OBJ,并在需求单里单列坐标表,工厂才能照着做。'
|
|
|
+ ]],
|
|
|
+ ['note','轻量建模的边界:能做「外形 + 内部支撑结构 + 开孔标记」,不能做真实刀路与模流分析;定稿仍要 STEP + 2D 图纸。']
|
|
|
+ ]
|
|
|
+});
|
|
|
+
|
|
|
+const REFS = [
|
|
|
+ {
|
|
|
+ id:'wx1', n:'微信公众号文章(待补录全文)',
|
|
|
+ u:'https://mp.weixin.qq.com/s/9mUdMT78YCpWuuqDSKU5QQ',
|
|
|
+ d:'该链接对自动抓取有 robots 限制,无法在网页端直接取回正文。已保留原始链接,并提供手动粘贴录入入口,录入后长期保存在本机。',
|
|
|
+ tag:'参考文章'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:'db1', n:'豆包对话记录(本项目前期讨论)',
|
|
|
+ u:'https://www.doubao.com/thread/xRkAJOJE74pwLYX2H',
|
|
|
+ d:'前期关于硅胶壳 / 录音豆 / 圆屏铝壳的 MOQ、CNC 与注塑报价讨论原始记录。',
|
|
|
+ tag:'对话存档'
|
|
|
+ }
|
|
|
+];
|
|
|
+/* =========================================================
|
|
|
+ 几何引擎:参数化壳体 + 材质 + 爆炸图 + 标注 + 导出
|
|
|
+ 1 单位 = 1 mm
|
|
|
+ ========================================================= */
|
|
|
+
|
|
|
+const STAGE = (function(){
|
|
|
+ const B = BABYLON;
|
|
|
+ const V3 = function(x,y,z){ return new B.Vector3(x,y,z); };
|
|
|
+
|
|
|
+ let engine=null, scene=null, camera=null, ground=null, root=null, dimRoot=null, shadowMat=null;
|
|
|
+ let host=null, canvas=null, readyFlag=false, pending=null;
|
|
|
+ let labels=[], labelEls=[];
|
|
|
+ const matCache={}, fixedCache={};
|
|
|
+ let cur={ project:'silicone', params:{}, material:'', explode:0, dims:true, cutForce:false };
|
|
|
+ let parts=[];
|
|
|
+ let customMap={}, cutaway=false, selCb=null, dragCb=null, custUid=1, solo=null;
|
|
|
+
|
|
|
+ /* ---------------- 材质 ---------------- */
|
|
|
+ function pbr(key,cfg){
|
|
|
+ if(matCache[key]) return matCache[key];
|
|
|
+ const m=new B.PBRMaterial('mat-'+key,scene);
|
|
|
+ m.albedoColor=B.Color3.FromHexString(cfg.albedo);
|
|
|
+ m.metallic=cfg.metallic!==undefined?cfg.metallic:0;
|
|
|
+ m.roughness=cfg.rough!==undefined?cfg.rough:0.5;
|
|
|
+ if(cfg.cc!==undefined){
|
|
|
+ m.clearCoat.isEnabled=true;
|
|
|
+ m.clearCoat.intensity=cfg.cc;
|
|
|
+ m.clearCoat.roughness=Math.max(0.03,1-(cfg.cci||0.35));
|
|
|
+ }
|
|
|
+ if(cfg.alpha!==undefined){
|
|
|
+ m.alpha=cfg.alpha;
|
|
|
+ m.transparencyMode=B.Material.MATERIAL_ALPHABLEND;
|
|
|
+ }
|
|
|
+ if(cfg.env!==undefined) m.environmentIntensity=cfg.env;
|
|
|
+ m.backFaceCulling=false;
|
|
|
+ matCache[key]=m;
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+ function fixed(key){
|
|
|
+ if(fixedCache[key]) return fixedCache[key];
|
|
|
+ fixedCache[key]=pbr('fx-'+key, FIXED_MATS[key]);
|
|
|
+ return fixedCache[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 半透明「透视」材质:爆炸/剖视时让内部结构可见 */
|
|
|
+ function ghost(key){
|
|
|
+ const gk='gh-'+key;
|
|
|
+ if(matCache[gk]) return matCache[gk];
|
|
|
+ const src=MATERIALS[key]||MATERIALS[PROJECTS[cur.project].materials[0]];
|
|
|
+ const cfg=Object.assign({},src,{alpha:0.30,env:0.2,cc:0.05});
|
|
|
+ return pbr(gk,cfg);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 2D 轮廓 ---------------- */
|
|
|
+ function roundedPath(w,h,r,seg){
|
|
|
+ const hw=w/2,hh=h/2;
|
|
|
+ r=Math.max(0.05,Math.min(r,Math.min(hw,hh)-0.02));
|
|
|
+ const pts=[];
|
|
|
+ const corners=[
|
|
|
+ {cx:hw-r,cz:hh-r,a0:0},
|
|
|
+ {cx:-(hw-r),cz:hh-r,a0:90},
|
|
|
+ {cx:-(hw-r),cz:-(hh-r),a0:180},
|
|
|
+ {cx:hw-r,cz:-(hh-r),a0:270}
|
|
|
+ ];
|
|
|
+ for(const c of corners){
|
|
|
+ for(let i=0;i<seg;i++){
|
|
|
+ const a=(c.a0+90*i/seg)*Math.PI/180;
|
|
|
+ pts.push({x:c.cx+r*Math.cos(a),z:c.cz+r*Math.sin(a)});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pts;
|
|
|
+ }
|
|
|
+
|
|
|
+ function radialN(p){ const l=Math.hypot(p.x,p.z)||1; return V3(p.x/l,0,p.z/l); }
|
|
|
+
|
|
|
+ function assemble(name,chunks,parent){
|
|
|
+ const pos=[],idx=[],nrm=[];
|
|
|
+ let base=0;
|
|
|
+ chunks.forEach(ch=>{
|
|
|
+ ch.p.forEach(v=>pos.push(v.x,v.y,v.z));
|
|
|
+ ch.n.forEach(v=>nrm.push(v.x,v.y,v.z));
|
|
|
+ ch.i.forEach(i=>idx.push(i+base));
|
|
|
+ base+=ch.p.length;
|
|
|
+ });
|
|
|
+ const vd=new B.VertexData();
|
|
|
+ vd.positions=pos; vd.indices=idx; vd.normals=nrm;
|
|
|
+ const mesh=new B.Mesh(name,scene);
|
|
|
+ vd.applyToMesh(mesh);
|
|
|
+ if(parent) mesh.parent=parent;
|
|
|
+ return mesh;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 环带(上下两个同点数轮廓) */
|
|
|
+ function ringStrip(ringA,yA,ringB,yB,nf){
|
|
|
+ const N=ringA.length,p=[],n=[],i=[];
|
|
|
+ for(let k=0;k<N;k++){
|
|
|
+ const a=ringA[k],b=ringB[k];
|
|
|
+ p.push(V3(a.x,yA,a.z),V3(b.x,yB,b.z));
|
|
|
+ n.push(nf(a,true),nf(b,false));
|
|
|
+ }
|
|
|
+ for(let k=0;k<N;k++){
|
|
|
+ const a1=k*2,b1=k*2+1,a2=((k+1)%N)*2,b2=((k+1)%N)*2+1;
|
|
|
+ i.push(a1,a2,b2,a1,b2,b1);
|
|
|
+ }
|
|
|
+ return {p,n,i};
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 空心圆角框(表壳类) */
|
|
|
+ function hollowFrame(name,spec,parent){
|
|
|
+ const {ow,od,orr,iw,id,irr,y0,y1,chamfer,seg}=spec;
|
|
|
+ const A=roundedPath(ow,od,orr,seg);
|
|
|
+ const Bc=roundedPath(ow,od,orr,seg);
|
|
|
+ const C=roundedPath(Math.max(1,ow-2*chamfer),Math.max(1,od-2*chamfer),Math.max(0.2,orr-chamfer),seg);
|
|
|
+ const D=roundedPath(iw,id,irr,seg);
|
|
|
+ const E=roundedPath(iw,id,irr,seg);
|
|
|
+ const ch=[];
|
|
|
+ ch.push(ringStrip(A,y0,Bc,y1-chamfer,p=>radialN(p)));
|
|
|
+ ch.push(ringStrip(Bc,y1-chamfer,C,y1,p=>{
|
|
|
+ const r=radialN(p); return V3(r.x*0.707,0.707,r.z*0.707);
|
|
|
+ }));
|
|
|
+ ch.push(ringStrip(C,y1,D,y1,()=>V3(0,1,0)));
|
|
|
+ ch.push(ringStrip(D,y1,E,y0,p=>{
|
|
|
+ const r=radialN(p); return V3(-r.x,0,-r.z);
|
|
|
+ }));
|
|
|
+ ch.push(ringStrip(E,y0,A,y0,()=>V3(0,-1,0)));
|
|
|
+ return assemble(name,ch,parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 实心圆角板 */
|
|
|
+ function solidSlab(name,spec,parent){
|
|
|
+ const {w,d,r,y0,y1,seg}=spec;
|
|
|
+ const A=roundedPath(w,d,r,seg);
|
|
|
+ const ch=[];
|
|
|
+ ch.push(ringStrip(A,y0,roundedPath(w,d,r,seg),y1,p=>radialN(p)));
|
|
|
+ const tp=[V3(0,y1,0)],tn=[V3(0,1,0)],ti=[];
|
|
|
+ A.forEach(p=>{ tp.push(V3(p.x,y1,p.z)); tn.push(V3(0,1,0)); });
|
|
|
+ for(let k=0;k<A.length;k++) ti.push(0,1+k,1+((k+1)%A.length));
|
|
|
+ ch.push({p:tp,n:tn,i:ti});
|
|
|
+ const bp=[V3(0,y0,0)],bn=[V3(0,-1,0)],bi=[];
|
|
|
+ A.forEach(p=>{ bp.push(V3(p.x,y0,p.z)); bn.push(V3(0,-1,0)); });
|
|
|
+ for(let k=0;k<A.length;k++) bi.push(0,1+((k+1)%A.length),1+k);
|
|
|
+ ch.push({p:bp,n:bn,i:bi});
|
|
|
+ return assemble(name,ch,parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 回转体:profile = [{r,y}] 闭合,按 CCW 给出(法线自动朝外) */
|
|
|
+ function revolve(name,profile,seg,parent){
|
|
|
+ const ch=[];
|
|
|
+ for(let k=0;k<profile.length;k++){
|
|
|
+ const p0=profile[k],p1=profile[(k+1)%profile.length];
|
|
|
+ const dr=p1.r-p0.r,dy=p1.y-p0.y,len=Math.hypot(dr,dy);
|
|
|
+ if(len<1e-4) continue;
|
|
|
+ const n2r=dy/len,n2y=-dr/len;
|
|
|
+ const pos=[],nrm=[],idx=[];
|
|
|
+ for(let j=0;j<seg;j++){
|
|
|
+ const th=j/seg*Math.PI*2, th2=((j+1)%seg)/seg*Math.PI*2;
|
|
|
+ const c0=Math.cos(th),s0=Math.sin(th),c1=Math.cos(th2),s1=Math.sin(th2);
|
|
|
+ pos.push(V3(p0.r*c0,p0.y,p0.r*s0),V3(p1.r*c0,p1.y,p1.r*s0),V3(p1.r*c1,p1.y,p1.r*s1),V3(p0.r*c1,p0.y,p0.r*s1));
|
|
|
+ nrm.push(V3(n2r*c0,n2y,n2r*s0),V3(n2r*c0,n2y,n2r*s0),V3(n2r*c1,n2y,n2r*s1),V3(n2r*c1,n2y,n2r*s1));
|
|
|
+ }
|
|
|
+ for(let j=0;j<seg;j++){
|
|
|
+ const b=j*4;
|
|
|
+ idx.push(b,b+1,b+2,b,b+2,b+3);
|
|
|
+ }
|
|
|
+ ch.push({p:pos,n:nrm,i:idx});
|
|
|
+ }
|
|
|
+ return assemble(name,ch,parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ function arcPts(cx,cy,r,a0,a1,n){
|
|
|
+ const out=[];
|
|
|
+ for(let i=0;i<=n;i++){
|
|
|
+ const a=(a0+(a1-a0)*i/n)*Math.PI/180;
|
|
|
+ out.push({r:cx+r*Math.cos(a),y:cy+r*Math.sin(a)});
|
|
|
+ }
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+ function dedupe(pts){
|
|
|
+ const out=[];
|
|
|
+ pts.forEach(p=>{
|
|
|
+ const last=out[out.length-1];
|
|
|
+ if(!last||Math.abs(last.r-p.r)>1e-4||Math.abs(last.y-p.y)>1e-4) out.push(p);
|
|
|
+ });
|
|
|
+ if(out.length>2){
|
|
|
+ const f=out[0],l=out[out.length-1];
|
|
|
+ if(Math.abs(f.r-l.r)<1e-4&&Math.abs(f.y-l.y)<1e-4) out.pop();
|
|
|
+ }
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 场景 ---------------- */
|
|
|
+ function init(canvasEl,hostEl){
|
|
|
+ canvas=canvasEl; host=hostEl;
|
|
|
+ engine=new B.Engine(canvas,true,{preserveDrawingBuffer:true,stencil:true,alpha:true},true);
|
|
|
+ engine.setHardwareScalingLevel(1/Math.min(2,window.devicePixelRatio||1));
|
|
|
+ scene=new B.Scene(engine);
|
|
|
+ scene.clearColor=new B.Color4(0,0,0,0);
|
|
|
+ scene.ambientColor=new B.Color3(0.16,0.18,0.22);
|
|
|
+
|
|
|
+ camera=new B.ArcRotateCamera('cam',-1.05,1.03,150,V3(0,0,0),scene);
|
|
|
+ camera.lowerRadiusLimit=18; camera.upperRadiusLimit=900;
|
|
|
+ camera.lowerBetaLimit=0.1; camera.upperBetaLimit=1.54;
|
|
|
+ camera.wheelDeltaPercentage=0.02;
|
|
|
+ camera.pinchDeltaPercentage=0.03;
|
|
|
+ camera.attachControl(canvas,true);
|
|
|
+ camera.minZ=0.1; camera.fov=0.75; camera.inertia=0.72;
|
|
|
+ camera.pinchZoom=true;
|
|
|
+ camera.panningSensibility=160;
|
|
|
+ camera.angularSensibilityX=760; camera.angularSensibilityY=760;
|
|
|
+ camera.useNaturalPinchZoom=true;
|
|
|
+ camera.allowUpsideDown=false;
|
|
|
+
|
|
|
+ const hemi=new B.HemisphericLight('hemi',V3(0.1,1,0.2),scene);
|
|
|
+ hemi.intensity=0.5;
|
|
|
+ hemi.groundColor=new B.Color3(0.10,0.12,0.16);
|
|
|
+ const d1=new B.DirectionalLight('d1',V3(-0.5,-1,-0.7),scene);
|
|
|
+ d1.intensity=1.5; d1.position=V3(140,200,160);
|
|
|
+ const d2=new B.DirectionalLight('d2',V3(0.8,-0.55,0.7),scene);
|
|
|
+ d2.intensity=0.85; d2.position=V3(-160,120,-180);
|
|
|
+
|
|
|
+ try{
|
|
|
+ const env=B.CubeTexture.CreateFromPrefilteredData('https://assets.babylonjs.com/environments/environmentSpecular.env',scene);
|
|
|
+ scene.environmentTexture=env;
|
|
|
+ scene.environmentIntensity=0.9;
|
|
|
+ }catch(e){ scene.environmentIntensity=0; }
|
|
|
+
|
|
|
+ const dt=new B.DynamicTexture('shadowTex',{width:256,height:256},scene,false);
|
|
|
+ const ctx=dt.getContext();
|
|
|
+ const g=ctx.createRadialGradient(128,128,6,128,128,126);
|
|
|
+ g.addColorStop(0,'rgba(0,0,0,0.55)');
|
|
|
+ g.addColorStop(0.4,'rgba(0,0,0,0.28)');
|
|
|
+ g.addColorStop(0.72,'rgba(0,0,0,0.09)');
|
|
|
+ g.addColorStop(1,'rgba(0,0,0,0)');
|
|
|
+ ctx.fillStyle=g; ctx.fillRect(0,0,256,256); dt.update();
|
|
|
+ ground=B.MeshBuilder.CreateGround('ground',{width:300,height:300},scene);
|
|
|
+ shadowMat=new B.StandardMaterial('shadowMat',scene);
|
|
|
+ shadowMat.diffuseTexture=dt; shadowMat.opacityTexture=dt;
|
|
|
+ shadowMat.emissiveColor=new B.Color3(0,0,0);
|
|
|
+ shadowMat.specularColor=new B.Color3(0,0,0);
|
|
|
+ shadowMat.disableLighting=true;
|
|
|
+ shadowMat.backFaceCulling=false;
|
|
|
+ ground.material=shadowMat; ground.isPickable=false;
|
|
|
+
|
|
|
+ engine.runRenderLoop(()=>{
|
|
|
+ if(scene) scene.render();
|
|
|
+ updateLabels();
|
|
|
+ });
|
|
|
+ new ResizeObserver(()=>engine.resize()).observe(host);
|
|
|
+ window.addEventListener('resize',()=>engine.resize());
|
|
|
+
|
|
|
+ readyFlag=true;
|
|
|
+ scene.onPointerObservable.add(pi=>{
|
|
|
+ if(pi.type===B.PointerEventTypes.POINTERDOUBLETAP){
|
|
|
+ const m2=pi.pickInfo&&pi.pickInfo.pickedMesh;
|
|
|
+ const md2=m2&&m2.metadata;
|
|
|
+ if(md2&&md2.part) focusPart(md2.part); else frame();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(pi.type!==B.PointerEventTypes.POINTERPICK) return;
|
|
|
+ const m=pi.pickInfo&&pi.pickInfo.pickedMesh;
|
|
|
+ if(!m) return;
|
|
|
+ const md=m.metadata||{};
|
|
|
+ if(!md.part){ if(selCb) selCb(null); return; }
|
|
|
+ highlight(md.part);
|
|
|
+ if(selCb) selCb(md.part,md.custom?m:null);
|
|
|
+ });
|
|
|
+ ensureLabelHost();
|
|
|
+ if(pending){ const p=pending; pending=null; load(p.project,p.params,p.material,p.explode); }
|
|
|
+ }
|
|
|
+
|
|
|
+ function ensureLabelHost(){
|
|
|
+ if(!host) return null;
|
|
|
+ let el=host.querySelector('.dimlayer');
|
|
|
+ if(!el){ el=document.createElement('div'); el.className='dimlayer'; host.appendChild(el); }
|
|
|
+ return el;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 标注 ---------------- */
|
|
|
+ function addDim(a,b,text,color){
|
|
|
+ if(!dimRoot) dimRoot=new B.TransformNode('dims',scene);
|
|
|
+ const col=B.Color3.FromHexString(color||'#7ec8ff');
|
|
|
+ const line=B.MeshBuilder.CreateLines('dl',{points:[a,b]},scene);
|
|
|
+ line.color=col; line.parent=dimRoot; line.isPickable=false;
|
|
|
+ const dir=b.subtract(a);
|
|
|
+ if(dir.length()>0.05){
|
|
|
+ const d=dir.normalize();
|
|
|
+ const perp=V3(-d.z,0.4,d.x);
|
|
|
+ if(perp.length()>0.05){
|
|
|
+ perp.normalize();
|
|
|
+ [a,b].forEach(pt=>{
|
|
|
+ const tick=B.MeshBuilder.CreateLines('tk',{points:[pt.add(perp.scale(2.0)),pt.subtract(perp.scale(2.0))]},scene);
|
|
|
+ tick.color=col; tick.parent=dimRoot; tick.isPickable=false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ labels.push({p:a.add(b).scale(0.5),t:text});
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 建模:三款 ---------------- */
|
|
|
+ function buildSilicone(p){
|
|
|
+ const g=new B.TransformNode('root',scene);
|
|
|
+ const seg=24;
|
|
|
+ const t=p.t, ow=p.w+2*t, od=p.d+2*t, y0=-p.h/2, y1=p.h/2;
|
|
|
+ const ir=Math.max(0.5,p.r), orr=ir+t;
|
|
|
+
|
|
|
+ const body=hollowFrame('body',{ow,od,orr,iw:p.w,id:p.d,irr:ir,y0,y1,chamfer:0.7,seg},g);
|
|
|
+ body.metadata={role:'body',part:'body'};
|
|
|
+
|
|
|
+ const floor=solidSlab('floor',{w:p.w-0.4,d:p.d-0.4,r:Math.max(0.5,ir-0.2),y0,y1:y0+1.2,seg},g);
|
|
|
+ floor.metadata={role:'body',part:'floor'};
|
|
|
+
|
|
|
+ const hx=p.hg/2, hz=-(od/2-3.0);
|
|
|
+ const hornL=B.MeshBuilder.CreateCylinder('hornL',{diameterBottom:p.hd,diameterTop:p.hd*0.28,height:p.hh,tessellation:18},scene);
|
|
|
+ hornL.position=V3(-hx,y1+p.hh/2-0.45,hz); hornL.rotation.x=-0.28; hornL.rotation.z=-0.10; hornL.parent=g;
|
|
|
+ hornL.metadata={role:'accent',part:'hornL'};
|
|
|
+ const hornR=B.MeshBuilder.CreateCylinder('hornR',{diameterBottom:p.hd,diameterTop:p.hd*0.28,height:p.hh,tessellation:18},scene);
|
|
|
+ hornR.position=V3(hx,y1+p.hh/2-0.45,hz); hornR.rotation.x=-0.28; hornR.rotation.z=0.10; hornR.parent=g;
|
|
|
+ hornR.metadata={role:'accent',part:'hornR'};
|
|
|
+
|
|
|
+ const screen=solidSlab('screen',{w:Math.max(6,p.w-2.8),d:Math.max(6,p.d-2.8),r:Math.max(0.4,ir-1.4),y0:y1-0.62,y1:y1-0.30,seg},g);
|
|
|
+ screen.metadata={role:'glass',part:'screen'};
|
|
|
+
|
|
|
+ const crown=B.MeshBuilder.CreateCylinder('crown',{diameter:3.2,height:2.2,tessellation:16},scene);
|
|
|
+ crown.rotation.z=Math.PI/2;
|
|
|
+ crown.position=V3(ow/2+p.cr*0.5,y0+p.h*0.55,0); crown.parent=g;
|
|
|
+ crown.metadata={role:'body',part:'crown'};
|
|
|
+
|
|
|
+ addDim(V3(-ow/2,y0-5.5,od/2+2.5),V3(ow/2,y0-5.5,od/2+2.5),'外宽 '+ow.toFixed(1));
|
|
|
+ addDim(V3(-(ow/2+4),y0-1,od/2+3),V3(-(ow/2+4),y1,od/2+3),'总高 '+p.h.toFixed(1));
|
|
|
+ addDim(V3(ow/2+11,y0-5.5,-od/2),V3(ow/2+11,y0-5.5,od/2),'外深 '+od.toFixed(1));
|
|
|
+ addDim(V3(-p.hg/2,y1+p.hh+2.0,hz),V3(p.hg/2,y1+p.hh+2.0,hz),'角距 '+p.hg.toFixed(1));
|
|
|
+
|
|
|
+ return {root:g,size:V3(ow,p.h+p.hh*2,od),parts:[
|
|
|
+ {id:'body',node:body,ex:V3(0,0,0)},
|
|
|
+ {id:'floor',node:floor,ex:V3(0,-14,0)},
|
|
|
+ {id:'hornL',node:hornL,ex:V3(-7,16,0)},
|
|
|
+ {id:'hornR',node:hornR,ex:V3(7,16,0)},
|
|
|
+ {id:'screen',node:screen,ex:V3(0,20,0)},
|
|
|
+ {id:'crown',node:crown,ex:V3(16,4,0)}
|
|
|
+ ]};
|
|
|
+ }
|
|
|
+
|
|
|
+ function buildRecorder(p){
|
|
|
+ const g=new B.TransformNode('root',scene);
|
|
|
+ const seg=48;
|
|
|
+ const ro=p.D/2, ri=ro-p.t, y0=-p.H/2, y1=p.H/2;
|
|
|
+ const r=Math.min(p.t*0.65,1.8);
|
|
|
+
|
|
|
+ const bodyProf=dedupe([
|
|
|
+ {r:ri,y:y0+r},
|
|
|
+ ...arcPts(ri+r,y0+r,r,180,270,3),
|
|
|
+ ...arcPts(ro-r,y0+r,r,270,360,3),
|
|
|
+ {r:ro,y:y1},
|
|
|
+ {r:ri,y:y1}
|
|
|
+ ]);
|
|
|
+ const body=revolve('body',bodyProf,seg,g);
|
|
|
+ body.metadata={role:'body',part:'body'};
|
|
|
+
|
|
|
+ const base=revolve('base',dedupe([
|
|
|
+ {r:0.6,y:y0},{r:Math.max(2,ro-1.2),y:y0},{r:Math.max(2,ro-1.2),y:y0+1.1},{r:0.6,y:y0+1.1}
|
|
|
+ ]),seg,g);
|
|
|
+ base.metadata={role:'body',part:'base'};
|
|
|
+
|
|
|
+ // 上盖穹顶
|
|
|
+ const dome=p.dm, lidPts=[{r:0.5,y:y1},{r:ro-0.2,y:y1}];
|
|
|
+ const steps=9;
|
|
|
+ for(let i=0;i<=steps;i++){
|
|
|
+ const a=i/steps*Math.PI/2;
|
|
|
+ lidPts.push({r:0.5+(ro-0.7)*Math.cos(a),y:y1+dome*Math.sin(a)});
|
|
|
+ }
|
|
|
+ const lid=revolve('lid',dedupe(lidPts),seg,g);
|
|
|
+ lid.metadata={role:'body',part:'lid'};
|
|
|
+
|
|
|
+ const loop=B.MeshBuilder.CreateTorus('loop',{diameter:p.ld+p.t*1.9,thickness:p.t*0.9,tessellation:28},scene);
|
|
|
+ loop.rotation.x=Math.PI/2;
|
|
|
+ loop.position=V3(ro+p.lh*0.55,y1-1.6,0); loop.parent=g;
|
|
|
+ loop.metadata={role:'body',part:'loop'};
|
|
|
+
|
|
|
+ const micMeshes=[];
|
|
|
+ const micR=Math.max(4,ro*0.4);
|
|
|
+ for(let i=0;i<4;i++){
|
|
|
+ const a=Math.PI/4+i*Math.PI/2;
|
|
|
+ const m=B.MeshBuilder.CreateCylinder('mic'+i,{diameter:1.0,height:1.8,tessellation:10},scene);
|
|
|
+ m.position=V3(Math.cos(a)*micR,y1+dome*0.72+0.2,Math.sin(a)*micR);
|
|
|
+ m.parent=g; m.material=fixed('dark');
|
|
|
+ m.metadata={role:'dark',part:'mic'};
|
|
|
+ micMeshes.push(m);
|
|
|
+ }
|
|
|
+
|
|
|
+ const usb=B.MeshBuilder.CreateBox('usbc',{width:1.4,height:3.2,depth:9.0},scene);
|
|
|
+ usb.position=V3(ro-0.4,y0+3.0,0); usb.parent=g; usb.material=fixed('dark');
|
|
|
+ usb.metadata={role:'dark',part:'usbc'};
|
|
|
+
|
|
|
+ const btn=B.MeshBuilder.CreateCylinder('btn',{diameter:3.6,height:1.2,tessellation:20},scene);
|
|
|
+ btn.rotation.z=Math.PI/2; btn.position=V3(-ro+0.1,y1-1.2,0); btn.parent=g;
|
|
|
+ btn.metadata={role:'body',part:'btn'};
|
|
|
+
|
|
|
+ const pcb=B.MeshBuilder.CreateCylinder('pcb',{diameter:Math.min(ro*2-5,26),height:1.2,tessellation:32},scene);
|
|
|
+ pcb.position=V3(0,y1-3.4,0); pcb.parent=g; pcb.material=fixed('pcb');
|
|
|
+ pcb.metadata={role:'pcb',part:'pcb'};
|
|
|
+
|
|
|
+ const cell=B.MeshBuilder.CreateCylinder('cell',{diameter:Math.min(ro*2-8,20),height:5.4,tessellation:28},scene);
|
|
|
+ cell.position=V3(0,y0+4.4,0); cell.parent=g; cell.material=fixed('cell');
|
|
|
+ cell.metadata={role:'cell',part:'cell'};
|
|
|
+
|
|
|
+ addDim(V3(-ro,y0-7,0),V3(ro,y0-7,0),'Ø'+p.D.toFixed(1));
|
|
|
+ addDim(V3(ro+9,y0,0),V3(ro+9,y1,0),'高 '+p.H.toFixed(1));
|
|
|
+ addDim(V3(0,y1+6,0),V3(ro+p.lh+2,y1+6,0),'挂环 '+p.lh.toFixed(1));
|
|
|
+
|
|
|
+ const ps=[
|
|
|
+ {id:'body',node:body,ex:V3(0,0,0)},
|
|
|
+ {id:'base',node:base,ex:V3(0,-16,0)},
|
|
|
+ {id:'cell',node:cell,ex:V3(0,2,0)},
|
|
|
+ {id:'pcb',node:pcb,ex:V3(0,14,0)},
|
|
|
+ {id:'lid',node:lid,ex:V3(0,26,0)},
|
|
|
+ {id:'loop',node:loop,ex:V3(18,2,0)},
|
|
|
+ {id:'btn',node:btn,ex:V3(-18,2,0)},
|
|
|
+ {id:'usbc',node:usb,ex:V3(16,-2,0)}
|
|
|
+ ];
|
|
|
+ micMeshes.forEach(m=>ps.push({id:'mic',node:m,ex:V3(0,30,0)}));
|
|
|
+ return {root:g,size:V3(p.D+10,p.H+p.dm, p.D),parts:ps};
|
|
|
+ }
|
|
|
+
|
|
|
+ function buildRound(p){
|
|
|
+ const g=new B.TransformNode('root',scene);
|
|
|
+ const seg=64;
|
|
|
+ const ro=p.D/2, y0=-p.H/2, y1=p.H/2, bd=p.bd/2, sd=p.sd/2, dep=p.dep;
|
|
|
+ const re=Math.min(3.0,p.t*1.3);
|
|
|
+
|
|
|
+ /* CNC 弧面:外壁 → 顶部凸圆 R → 极短平台 → 屏边凹圆 R → 沉台
|
|
|
+ 全部由工艺参数驱动,工厂按 rimR / dep / cham 直接编程 */
|
|
|
+ const rimR=Math.max(0.4,Math.min(p.rimR||1.8, (ro-bd)*0.55));
|
|
|
+ const cham=Math.max(0,Math.min(p.cham||0.5, (ro-bd)*0.35));
|
|
|
+ const seam=Math.max(0.5,Math.min(p.dep||1.2, ro-rimR-bd+0.02));
|
|
|
+ const flat=Math.max(0,ro-rimR-(bd+seam));
|
|
|
+ const bezelProf=dedupe([
|
|
|
+ {r:sd,y:y0},
|
|
|
+ {r:Math.max(sd,ro-cham),y:y0},
|
|
|
+ ...(cham>0.05?arcPts(ro-cham,y0+cham,cham,270,360,3):[{r:ro,y:y0}]),
|
|
|
+ {r:ro,y:y1-rimR},
|
|
|
+ ...arcPts(ro-rimR,y1-rimR,rimR,0,90,6),
|
|
|
+ ...(flat>0.15?[{r:bd+seam,y:y1}]:[]),
|
|
|
+ ...arcPts(bd+seam,y1-seam,seam,90,180,6),
|
|
|
+ {r:sd,y:y1-seam}
|
|
|
+ ]);
|
|
|
+ const bezel=revolve('bezel',bezelProf,seg,g);
|
|
|
+ bezel.metadata={role:'body',part:'bezel'};
|
|
|
+
|
|
|
+ const seatY=y1-seam;
|
|
|
+ const black=B.MeshBuilder.CreateCylinder('black',{diameter:p.bd-0.3,height:0.6,tessellation:seg},scene);
|
|
|
+ black.position=V3(0,seatY+0.3,0); black.parent=g; black.material=fixed('dark');
|
|
|
+ black.metadata={role:'dark',part:'black'};
|
|
|
+
|
|
|
+ const glass=B.MeshBuilder.CreateCylinder('glass',{diameter:p.sd+0.4,height:0.8,tessellation:seg},scene);
|
|
|
+ glass.position=V3(0,seatY+0.4,0); glass.parent=g; glass.material=fixed('glass');
|
|
|
+ glass.metadata={role:'glass',part:'glass'};
|
|
|
+
|
|
|
+ const capProf=dedupe([
|
|
|
+ {r:0.6,y:y0},
|
|
|
+ {r:ro-p.t-0.6,y:y0},
|
|
|
+ {r:ro-p.t-0.6,y:y0+p.cap-0.5},
|
|
|
+ ...arcPts(ro-p.t-1.1,y0+p.cap-0.5,0.5,0,90,2),
|
|
|
+ {r:0.6,y:y0+p.cap}
|
|
|
+ ]);
|
|
|
+ const cap=revolve('cap',capProf,seg,g);
|
|
|
+ cap.metadata={role:'body',part:'cap'};
|
|
|
+
|
|
|
+ const th=B.MeshBuilder.CreateTorus('thread',{diameter:p.D-p.t*2-1.6,thickness:0.9,tessellation:seg},scene);
|
|
|
+ th.position=V3(0,y0+p.cap+0.05,0); th.parent=g; th.material=fixed('dark');
|
|
|
+ th.metadata={role:'dark',part:'thread'};
|
|
|
+
|
|
|
+ const bosses=[];
|
|
|
+ for(let i=0;i<4;i++){
|
|
|
+ const a=Math.PI/4+i*Math.PI/2;
|
|
|
+ const b=B.MeshBuilder.CreateCylinder('boss'+i,{diameter:4.2,height:5.2,tessellation:14},scene);
|
|
|
+ b.position=V3(Math.cos(a)*(ro-9),y0+p.cap+2.8,Math.sin(a)*(ro-9));
|
|
|
+ b.parent=g; b.material=fixed('brass');
|
|
|
+ b.metadata={role:'brass',part:'boss'};
|
|
|
+ bosses.push(b);
|
|
|
+ }
|
|
|
+
|
|
|
+ const pcb=B.MeshBuilder.CreateCylinder('pcb',{diameter:Math.min(44,p.D-14),height:1.2,tessellation:40},scene);
|
|
|
+ pcb.position=V3(0,y1-dep-3.4,0); pcb.parent=g; pcb.material=fixed('pcbDark');
|
|
|
+ pcb.metadata={role:'pcb',part:'pcb'};
|
|
|
+
|
|
|
+ const cell=B.MeshBuilder.CreateCylinder('cell',{diameter:Math.min(36,p.D-22),height:5.0,tessellation:36},scene);
|
|
|
+ cell.position=V3(0,y0+p.cap+4.6,0); cell.parent=g; cell.material=fixed('cell');
|
|
|
+ cell.metadata={role:'cell',part:'cell'};
|
|
|
+
|
|
|
+ const sb=B.MeshBuilder.CreateBox('sbtn',{width:1.2,height:5.4,depth:2.0},scene);
|
|
|
+ sb.position=V3(ro-0.1,1.6,-2); sb.parent=g;
|
|
|
+ sb.metadata={role:'body',part:'sbtn'};
|
|
|
+
|
|
|
+ const usb=B.MeshBuilder.CreateBox('usbc',{width:1.5,height:3.2,depth:8.8},scene);
|
|
|
+ usb.position=V3(-ro+0.4,y0+5.4,0); usb.parent=g; usb.material=fixed('dark');
|
|
|
+ usb.metadata={role:'dark',part:'usbc'};
|
|
|
+
|
|
|
+ addDim(V3(-ro,y0-7,0),V3(ro,y0-7,0),'Ø'+p.D.toFixed(2));
|
|
|
+ addDim(V3(ro+6,y0,0),V3(ro+6,y1,0),'厚 '+p.H.toFixed(2));
|
|
|
+ addDim(V3(-sd,y1+8.5,0),V3(sd,y1+8.5,0),'屏 Ø'+p.sd.toFixed(2));
|
|
|
+
|
|
|
+ const ps=[
|
|
|
+ {id:'bezel',node:bezel,ex:V3(0,0,0)},
|
|
|
+ {id:'black',node:black,ex:V3(0,22,0)},
|
|
|
+ {id:'glass',node:glass,ex:V3(0,32,0)},
|
|
|
+ {id:'pcb',node:pcb,ex:V3(0,8,0)},
|
|
|
+ {id:'cell',node:cell,ex:V3(0,-10,0)},
|
|
|
+ {id:'cap',node:cap,ex:V3(0,-28,0)},
|
|
|
+ {id:'thread',node:th,ex:V3(0,-20,0)},
|
|
|
+ {id:'sbtn',node:sb,ex:V3(18,2,0)},
|
|
|
+ {id:'usbc',node:usb,ex:V3(-18,-2,0)}
|
|
|
+ ];
|
|
|
+ bosses.forEach(b=>ps.push({id:'boss',node:b,ex:V3(0,-16,0)}));
|
|
|
+ return {root:g,size:V3(p.D,p.H,p.D),parts:ps};
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 自定义结构件(轻量参数化建模) ---------------- */
|
|
|
+ /* 形体库:按工艺预置的标准件参数(M2/M2.5/M3 自攻预钻孔按常用规范) */
|
|
|
+ const PRIMS={
|
|
|
+ box: {n:'方块', d:{w:8, h:6, dd:8}, tag:'基础'},
|
|
|
+ cyl: {n:'圆柱', d:{dia:10,h:8}, tag:'基础'},
|
|
|
+ rib: {n:'加强筋', d:{w:14, h:5, dd:1.2}, tag:'基础'},
|
|
|
+ pocket:{n:'凹槽(铣削)', d:{w:10, h:2, dd:10}, tag:'基础'},
|
|
|
+ hole: {n:'开孔(钻孔)', d:{dia:3, h:1}, tag:'基础'},
|
|
|
+ boss2: {n:'螺丝柱 M2', d:{dia:4.0,h:7,dd:1.6},tag:'紧固'},
|
|
|
+ boss25:{n:'螺丝柱 M2.5', d:{dia:4.8,h:8,dd:2.1},tag:'紧固'},
|
|
|
+ boss3: {n:'螺丝柱 M3', d:{dia:5.6,h:9,dd:2.6},tag:'紧固'},
|
|
|
+ thru25:{n:'M2.5 过孔', d:{dia:2.7,h:1,dd:2.7},tag:'紧固'},
|
|
|
+ pin3: {n:'定位销 Ø3', d:{dia:3,h:4}, tag:'紧固'},
|
|
|
+ pad4: {n:'四角柱组 M2.5',d:{w:30,h:7,dd:30,dia:4.8,hd:2.1},tag:'腔体'},
|
|
|
+ wall: {n:'分隔墙', d:{w:20,h:6,dd:0.8}, tag:'腔体'},
|
|
|
+ tray: {n:'电池仓', d:{w:22,h:3,dd:18}, tag:'腔体'},
|
|
|
+ clip: {n:'卡扣', d:{w:5,h:4,dd:1.2}, tag:'腔体'}
|
|
|
+ };
|
|
|
+ const FASTEN_TYPES=['boss2','boss25','boss3','thru25','pin3','pad4'];
|
|
|
+
|
|
|
+ function cavInfo(){
|
|
|
+ const id=cur.project,p=cur.params;
|
|
|
+ if(id==='silicone') return {kind:'rect',w:p.w,d:p.d,h:p.h};
|
|
|
+ if(id==='recorder') return {kind:'cyl',r:(p.D-2*p.t)/2,h:p.H-1.2-p.dm};
|
|
|
+ return {kind:'cyl',r:(p.D-2*p.t)/2,h:p.H-p.cap-p.dep};
|
|
|
+ }
|
|
|
+
|
|
|
+ function newSpec(type){
|
|
|
+ const base=(PRIMS[type]||PRIMS.box).d;
|
|
|
+ const s={uid:custUid++,type:type,x:0,z:0,y:0,draft:1,snap:0.5,note:''};
|
|
|
+ Object.keys(base).forEach(k=>s[k]=base[k]);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 空心柱(螺丝柱 / 过孔):径向回转,内外壁 + 上下环面 */
|
|
|
+ function hollowBoss(name,od,pid,h,tess){
|
|
|
+ const ri=Math.max(0.25,pid/2), ro=Math.max(ri+0.4,od/2), hh=Math.max(0.2,h/2);
|
|
|
+ return revolve(name,[{r:ri,y:-hh},{r:ro,y:-hh},{r:ro,y:hh},{r:ri,y:hh}],tess||20,null);
|
|
|
+ }
|
|
|
+ function mergeAll(ms,name){
|
|
|
+ if(!ms.length) return null;
|
|
|
+ const mm=B.Mesh.MergeMeshes(ms,true,true);
|
|
|
+ if(mm) mm.name=name;
|
|
|
+ return mm||ms[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ function buildPrim(s){
|
|
|
+ const t=s.type;
|
|
|
+ let m=null;
|
|
|
+ const rect=(t==='box'||t==='pocket'||t==='rib'||t==='wall'||t==='clip');
|
|
|
+ if(rect){
|
|
|
+ m=B.MeshBuilder.CreateBox('c'+s.uid,{width:Math.max(0.2,s.w),height:Math.max(0.2,s.h),depth:Math.max(0.2,s.dd)},scene);
|
|
|
+ if(t==='rib'||t==='wall'){
|
|
|
+ const dr=Math.min(0.35,Math.tan(Math.max(0,s.draft||0)*Math.PI/180)*s.h/Math.max(1,s.dd)*1.6);
|
|
|
+ const pos=m.getVerticesData(B.VertexBuffer.PositionKind);
|
|
|
+ if(pos){ for(let i=0;i<pos.length;i+=3){ if(pos[i+1]>0){ pos[i]*=1-dr; pos[i+2]*=1-dr; } } }
|
|
|
+ m.updateVerticesData(B.VertexBuffer.PositionKind,pos);
|
|
|
+ }
|
|
|
+ }else if(t==='tray'){
|
|
|
+ const w=Math.max(4,s.w), dp=Math.max(4,s.dd), h=Math.max(1,s.h);
|
|
|
+ const tw=Math.min(1.4,Math.max(0.6,Math.min(w,dp)/12));
|
|
|
+ const ps=[];
|
|
|
+ const base=B.MeshBuilder.CreateBox('trb',{width:w,height:tw,depth:dp},scene);
|
|
|
+ base.position.y=-h/2+tw/2; ps.push(base);
|
|
|
+ [-1,1].forEach(sg=>{
|
|
|
+ const xw=B.MeshBuilder.CreateBox('trx',{width:tw,height:h,depth:dp},scene);
|
|
|
+ xw.position.x=sg*(w/2-tw/2); ps.push(xw);
|
|
|
+ const zw=B.MeshBuilder.CreateBox('trz',{width:w,height:h,depth:tw},scene);
|
|
|
+ zw.position.z=sg*(dp/2-tw/2); ps.push(zw);
|
|
|
+ });
|
|
|
+ m=mergeAll(ps,'c'+s.uid);
|
|
|
+ }else if(t==='pad4'){
|
|
|
+ const w=Math.max(8,s.w), dp=Math.max(8,s.dd), od=Math.max(2,s.dia||4.8);
|
|
|
+ const pid=Math.max(0.8,s.hd||2.1), h=Math.max(2,s.h);
|
|
|
+ const ps=[];
|
|
|
+ [-1,1].forEach(sx=>[-1,1].forEach(sz=>{
|
|
|
+ const b=hollowBoss('pb',od,pid,h,16);
|
|
|
+ b.position.x=sx*Math.max(0,w/2-od/2); b.position.z=sz*Math.max(0,dp/2-od/2);
|
|
|
+ ps.push(b);
|
|
|
+ }));
|
|
|
+ m=mergeAll(ps,'c'+s.uid);
|
|
|
+ }else if(t==='boss2'||t==='boss25'||t==='boss3'||t==='thru25'){
|
|
|
+ m=hollowBoss('c'+s.uid,Math.max(1.2,s.dia),Math.max(0.4,s.dd),Math.max(0.4,s.h),20);
|
|
|
+ }else if(t==='pin3'){
|
|
|
+ m=B.MeshBuilder.CreateCylinder('c'+s.uid,{diameter:Math.max(0.6,s.dia),height:Math.max(0.4,s.h),tessellation:20},scene);
|
|
|
+ }else{
|
|
|
+ m=B.MeshBuilder.CreateCylinder('c'+s.uid,{diameter:Math.max(0.4,s.dia),height:Math.max(0.2,s.h),tessellation:24},scene);
|
|
|
+ }
|
|
|
+ m.position=V3(s.x||0,s.y||0,s.z||0);
|
|
|
+ if(s.rot) m.rotation.y=s.rot*Math.PI/180;
|
|
|
+ const role=FASTEN_TYPES.indexOf(t)>=0?'brass':((t==='pocket'||t==='hole')?'cut':'body');
|
|
|
+ m.metadata={role:role,part:'c'+s.uid,custom:true,owner:s.owner||null};
|
|
|
+
|
|
|
+ const db=new B.PointerDragBehavior({dragPlaneNormal:V3(0,1,0)});
|
|
|
+ db.useObjectOrientationForDragging=false;
|
|
|
+ db.onDragStartObservable.add(()=>{ if(camera) camera.detachControl(); });
|
|
|
+ db.onDragEndObservable.add(()=>{ if(camera&&canvas) camera.attachControl(canvas,true); });
|
|
|
+ db.onDragObservable.add(()=>{
|
|
|
+ const st=Math.max(0.1,s.snap||0.5);
|
|
|
+ m.position.x=Math.round(m.position.x/st)*st;
|
|
|
+ m.position.z=Math.round(m.position.z/st)*st;
|
|
|
+ const cav=cavInfo();
|
|
|
+ const cw=s.w!==undefined?s.w:s.dia, cd=s.dd!==undefined?s.dd:s.dia;
|
|
|
+ if(cav.kind==='cyl'){
|
|
|
+ const r=Math.hypot(m.position.x,m.position.z);
|
|
|
+ const rr=cav.r-Math.max(cw,cd)/2-0.5;
|
|
|
+ if(r>0.2&&rr>0&&Math.abs(r-rr)<1.5){
|
|
|
+ m.position.x=Math.round((m.position.x/r*rr)*10)/10;
|
|
|
+ m.position.z=Math.round((m.position.z/r*rr)*10)/10;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ const xz=cav.d/2-cd/2-0.5, xx=cav.w/2-cw/2-0.5;
|
|
|
+ if(Math.abs(Math.abs(m.position.z)-xz)<1.5) m.position.z=(m.position.z<0?-1:1)*xz;
|
|
|
+ if(Math.abs(Math.abs(m.position.x)-xx)<1.5) m.position.x=(m.position.x<0?-1:1)*xx;
|
|
|
+ }
|
|
|
+ s.x=+m.position.x.toFixed(2); s.z=+m.position.z.toFixed(2);
|
|
|
+ if(dragCb) dragCb(s);
|
|
|
+ });
|
|
|
+ m.addBehavior(db);
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+
|
|
|
+ function buildCustom(parent){
|
|
|
+ labels.length=labels.length; // 保持已有标注
|
|
|
+ const list=customMap[cur.project]||[];
|
|
|
+ list.forEach(s=>{
|
|
|
+ const m=buildPrim(s);
|
|
|
+ m.parent=parent;
|
|
|
+ parts.push({id:'c'+s.uid,node:m,ex:V3(0,0,0),custom:true,spec:s});
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const OUTER={silicone:['body'],recorder:['body','lid'],round:['bezel','cap']};
|
|
|
+
|
|
|
+ /* ---------------- 材质应用 ---------------- */
|
|
|
+ function applyMaterial(key){
|
|
|
+ if(!root) return;
|
|
|
+ const cfg=MATERIALS[key]||MATERIALS[PROJECTS[cur.project].materials[0]];
|
|
|
+ if(!cfg) return;
|
|
|
+ const useKey=MATERIALS[key]?key:PROJECTS[cur.project].materials[0];
|
|
|
+ const bodyM=pbr(useKey,MATERIALS[useKey]);
|
|
|
+ const accentKey=useKey.indexOf('sil-')===0?'sil-black':useKey;
|
|
|
+ const accentM=pbr(accentKey,MATERIALS[accentKey]);
|
|
|
+ const outer=OUTER[cur.project]||[];
|
|
|
+ root.getChildMeshes().forEach(m=>{
|
|
|
+ const role=m.metadata&&m.metadata.role;
|
|
|
+ const pid=m.metadata&&m.metadata.part;
|
|
|
+ if(role==='body') m.material=(cutaway&&outer.indexOf(pid)>=0)?ghost(useKey):bodyM;
|
|
|
+ else if(role==='accent') m.material=accentM;
|
|
|
+ else if(role==='glass') m.material=fixed('glass');
|
|
|
+ else if(role==='pcb') m.material=fixed('pcb');
|
|
|
+ else if(role==='cell') m.material=fixed('cell');
|
|
|
+ else if(role==='brass') m.material=fixed('brass');
|
|
|
+ else if(role==='dark') m.material=fixed('dark');
|
|
|
+ else if(role==='cut') m.material=fixed('cut');
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 单件隔离编辑 ---------------- */
|
|
|
+ function applySolo(id){
|
|
|
+ if(!root) return;
|
|
|
+ root.getChildMeshes().forEach(m=>{
|
|
|
+ const md=m.metadata||{};
|
|
|
+ const keep=!id||md.part===id||md.owner===id;
|
|
|
+ m.setEnabled(!!keep);
|
|
|
+ });
|
|
|
+ if(dimRoot) dimRoot.setEnabled(!id&&cur.dims);
|
|
|
+ const layer=host&&host.querySelector('.dimlayer');
|
|
|
+ if(layer) layer.style.display=(!id&&cur.dims)?'block':'none';
|
|
|
+ }
|
|
|
+ function frameSolo(id){
|
|
|
+ if(!root||!camera) return;
|
|
|
+ const ms=root.getChildMeshes().filter(m=>m.metadata&&(m.metadata.part===id||m.metadata.owner===id)&&m.isEnabled());
|
|
|
+ if(!ms.length) return;
|
|
|
+ const bi=ms[0].getHierarchyBoundingVectors();
|
|
|
+ const c=bi.max.add(bi.min).scale(0.5);
|
|
|
+ const dim=Math.max(bi.max.x-bi.min.x,bi.max.y-bi.min.y,bi.max.z-bi.min.z);
|
|
|
+ camera.target=c;
|
|
|
+ camera.alpha=-0.95; camera.beta=1.16;
|
|
|
+ camera.radius=Math.max(34,dim*2.35);
|
|
|
+ camera.lowerRadiusLimit=Math.max(10,dim*0.6);
|
|
|
+ }
|
|
|
+ function focusPart(id){
|
|
|
+ if(!root||!camera) return;
|
|
|
+ const ms=root.getChildMeshes().filter(m=>m.metadata&&(m.metadata.part===id||m.metadata.owner===id)&&m.isEnabled());
|
|
|
+ if(!ms.length) return;
|
|
|
+ const bi=ms[0].getHierarchyBoundingVectors();
|
|
|
+ const c=bi.max.add(bi.min).scale(0.5);
|
|
|
+ const dim=Math.max(bi.max.x-bi.min.x,bi.max.y-bi.min.y,bi.max.z-bi.min.z);
|
|
|
+ camera.target=c;
|
|
|
+ camera.radius=Math.max(22,dim*2.1);
|
|
|
+ }
|
|
|
+
|
|
|
+ function setSolo(id){
|
|
|
+ solo=id||null;
|
|
|
+ if(!root) return;
|
|
|
+ cutaway=false;
|
|
|
+ applyMaterial(cur.material);
|
|
|
+ applySolo(solo);
|
|
|
+ if(solo) frameSolo(solo); else frame();
|
|
|
+ if(cur.hl&&solo&&cur.hl!==solo) highlight(solo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 组装/重建 ---------------- */
|
|
|
+ function rebuild(reframe){
|
|
|
+ if(!scene) return;
|
|
|
+ if(root){ root.dispose(); root=null; }
|
|
|
+ if(dimRoot){ dimRoot.dispose(); dimRoot=null; }
|
|
|
+ labels=[]; labelEls.forEach(e=>e.remove()); labelEls=[];
|
|
|
+ const proj=PROJECTS[cur.project];
|
|
|
+ const p={};
|
|
|
+ proj.params.forEach(x=>{ p[x.k]=x.def; });
|
|
|
+ Object.assign(p,cur.params||{});
|
|
|
+ const out=(cur.project==='silicone')?buildSilicone(p):(cur.project==='recorder')?buildRecorder(p):buildRound(p);
|
|
|
+ root=out.root; parts=out.parts;
|
|
|
+ buildCustom(root);
|
|
|
+ parts.forEach(pt=>{
|
|
|
+ if(!pt.node) return;
|
|
|
+ pt.basePos=pt.node.position.clone();
|
|
|
+ pt.node.metadata=Object.assign({},pt.node.metadata||{},{part:pt.id});
|
|
|
+ });
|
|
|
+ applyMaterial(cur.material);
|
|
|
+ applyExplode(cur.explode);
|
|
|
+ if(solo) applySolo(solo);
|
|
|
+ placeGround();
|
|
|
+ if(reframe!==false) frame();
|
|
|
+ refreshDims();
|
|
|
+ if(cur.hl) highlight(cur.hl);
|
|
|
+ }
|
|
|
+
|
|
|
+ function placeGround(){
|
|
|
+ if(!root||!ground) return;
|
|
|
+ const bi=root.getHierarchyBoundingVectors();
|
|
|
+ const dim=Math.max(bi.max.x-bi.min.x,bi.max.y-bi.min.y,bi.max.z-bi.min.z);
|
|
|
+ ground.position.y=bi.min.y-0.2;
|
|
|
+ ground.scaling.x=ground.scaling.z=Math.max(1,dim/60);
|
|
|
+ }
|
|
|
+
|
|
|
+ function frame(){
|
|
|
+ if(!root||!camera) return;
|
|
|
+ const bi=root.getHierarchyBoundingVectors();
|
|
|
+ const c=bi.max.add(bi.min).scale(0.5);
|
|
|
+ const dim=Math.max(bi.max.x-bi.min.x,bi.max.y-bi.min.y,bi.max.z-bi.min.z);
|
|
|
+ camera.target=c;
|
|
|
+ const aspect=(engine?engine.getRenderWidth():1)/Math.max(1,(engine?engine.getRenderHeight():1));
|
|
|
+ const pad=Math.max(1,1.18/Math.max(0.6,aspect));
|
|
|
+ camera.radius=Math.max(95,dim*1.98*pad);
|
|
|
+ camera.lowerRadiusLimit=Math.max(22,dim*0.85);
|
|
|
+ camera.upperRadiusLimit=Math.max(400,dim*7);
|
|
|
+ }
|
|
|
+
|
|
|
+ function applyExplode(v){
|
|
|
+ cur.explode=v||0;
|
|
|
+ parts.forEach(pt=>{
|
|
|
+ if(!pt.node||!pt.basePos) return;
|
|
|
+ pt.node.position=pt.basePos.add(pt.ex.scale(cur.explode));
|
|
|
+ });
|
|
|
+ const wantCut=!solo&&((cur.explode>0.2)||!!cur.cutForce);
|
|
|
+ if(wantCut!==cutaway){
|
|
|
+ cutaway=wantCut;
|
|
|
+ applyMaterial(cur.material);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function highlight(partId){
|
|
|
+ cur.hl=partId;
|
|
|
+ if(!root) return;
|
|
|
+ root.getChildMeshes().forEach(m=>{
|
|
|
+ m.renderOutline=false;
|
|
|
+ if(partId&&m.metadata&&m.metadata.part===partId){
|
|
|
+ m.renderOutline=true;
|
|
|
+ m.outlineColor=new B.Color3(0.25,0.75,1);
|
|
|
+ m.outlineWidth=0.9;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function setView(name){
|
|
|
+ if(!camera) return;
|
|
|
+ const map={iso:[-1.05,1.03],front:[-Math.PI/2,1.53],side:[0,1.53],top:[-Math.PI/2,0.17],low:[-0.55,1.38]};
|
|
|
+ const v=map[name]||map.iso;
|
|
|
+ let t=0; const fromA=camera.alpha,fromB=camera.beta,dur=0.42;
|
|
|
+ const obs=scene.onBeforeRenderObservable.add(()=>{
|
|
|
+ t+=engine.getDeltaTime()/1000;
|
|
|
+ const k=Math.min(1,t/dur), e=1-Math.pow(1-k,3);
|
|
|
+ camera.alpha=fromA+(v[0]-fromA)*e;
|
|
|
+ camera.beta=fromB+(v[1]-fromB)*e;
|
|
|
+ if(k>=1) scene.onBeforeRenderObservable.remove(obs);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function refreshDims(){
|
|
|
+ const layer=ensureLabelHost();
|
|
|
+ if(!layer) return;
|
|
|
+ layer.innerHTML=''; labelEls=[];
|
|
|
+ labels.forEach(l=>{
|
|
|
+ const d=document.createElement('div');
|
|
|
+ d.className='dimtag'; d.textContent=l.t;
|
|
|
+ layer.appendChild(d); labelEls.push(d);
|
|
|
+ });
|
|
|
+ layer.style.display=(cur.dims&&!solo)?'block':'none';
|
|
|
+ if(dimRoot) dimRoot.setEnabled(cur.dims&&!solo);
|
|
|
+ }
|
|
|
+
|
|
|
+ function setDims(on){
|
|
|
+ cur.dims=!!on;
|
|
|
+ const layer=host&&host.querySelector('.dimlayer');
|
|
|
+ if(layer) layer.style.display=cur.dims?'block':'none';
|
|
|
+ if(dimRoot) dimRoot.setEnabled(cur.dims);
|
|
|
+ }
|
|
|
+
|
|
|
+ let lastW=0,lastH=0;
|
|
|
+ function updateLabels(){
|
|
|
+ if(!camera||!labelEls.length) return;
|
|
|
+ const rw=engine.getRenderWidth(), rh=engine.getRenderHeight();
|
|
|
+ if(rw!==lastW||rh!==lastH){ lastW=rw; lastH=rh; }
|
|
|
+ const vp=camera.viewport.toGlobal(rw,rh);
|
|
|
+ const tm=scene.getTransformMatrix();
|
|
|
+ const cssW=host.clientWidth, cssH=host.clientHeight;
|
|
|
+ for(let i=0;i<labels.length;i++){
|
|
|
+ const el=labelEls[i]; if(!el) continue;
|
|
|
+ const pr=B.Vector3.Project(labels[i].p,B.Matrix.Identity(),tm,vp);
|
|
|
+ if(pr.z<0||pr.z>1){ el.style.opacity='0'; continue; }
|
|
|
+ el.style.opacity='1';
|
|
|
+ const x=Math.min(Math.max((pr.x/rw)*cssW,34),cssW-34);
|
|
|
+ const y=Math.min(Math.max((pr.y/rh)*cssH,16),cssH-16);
|
|
|
+ el.style.left=x.toFixed(1)+'px';
|
|
|
+ el.style.top=y.toFixed(1)+'px';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function load(projectId,params,material,explode){
|
|
|
+ if(!readyFlag){ pending={project:projectId,params:params,material:material,explode:explode}; return; }
|
|
|
+ cur.project=projectId;
|
|
|
+ cur.params=Object.assign({},params||{});
|
|
|
+ cur.material=material||PROJECTS[projectId].materials[0];
|
|
|
+ cur.explode=explode||0;
|
|
|
+ cur.hl=null;
|
|
|
+ rebuild();
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------------- 导出 ---------------- */
|
|
|
+ function collectMeshes(partId){
|
|
|
+ if(!root) return [];
|
|
|
+ const out=[];
|
|
|
+ root.getChildMeshes().forEach(m=>{
|
|
|
+ if(partId){
|
|
|
+ const md=m.metadata||{};
|
|
|
+ if(md.part!==partId&&md.owner!==partId) return;
|
|
|
+ }
|
|
|
+ if(!m.getTotalVertices()) return;
|
|
|
+ const role=m.metadata&&m.metadata.role;
|
|
|
+ const isCustom=!!(m.metadata&&m.metadata.custom);
|
|
|
+ if(role==='cut') return;
|
|
|
+ if(!isCustom&&(role==='dark'||role==='glass'||role==='brass'||role==='pcb'||role==='cell')) return;
|
|
|
+ out.push(m);
|
|
|
+ });
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ function exportMesh(kind,name,partId){
|
|
|
+ const meshes=collectMeshes(partId);
|
|
|
+ if(!meshes.length) return null;
|
|
|
+ if(kind==='stl'){
|
|
|
+ const lines=['solid '+name];
|
|
|
+ meshes.forEach(m=>{
|
|
|
+ const pos=m.getVerticesData(B.VertexBuffer.PositionKind);
|
|
|
+ const idx=m.getIndices();
|
|
|
+ m.computeWorldMatrix(true);
|
|
|
+ const wm=m.getWorldMatrix();
|
|
|
+ for(let i=0;i<idx.length;i+=3){
|
|
|
+ const a=B.Vector3.TransformCoordinates(V3(pos[idx[i]*3],pos[idx[i]*3+1],pos[idx[i]*3+2]),wm);
|
|
|
+ const b=B.Vector3.TransformCoordinates(V3(pos[idx[i+1]*3],pos[idx[i+1]*3+1],pos[idx[i+1]*3+2]),wm);
|
|
|
+ const c=B.Vector3.TransformCoordinates(V3(pos[idx[i+2]*3],pos[idx[i+2]*3+1],pos[idx[i+2]*3+2]),wm);
|
|
|
+ const n=B.Vector3.Cross(b.subtract(a),c.subtract(a));
|
|
|
+ if(n.length()<1e-8) continue;
|
|
|
+ n.normalize();
|
|
|
+ lines.push('facet normal '+n.x.toFixed(5)+' '+n.y.toFixed(5)+' '+n.z.toFixed(5),' outer loop');
|
|
|
+ [a,b,c].forEach(v=>lines.push(' vertex '+v.x.toFixed(4)+' '+v.y.toFixed(4)+' '+v.z.toFixed(4)));
|
|
|
+ lines.push(' endloop','endfacet');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ lines.push('endsolid '+name);
|
|
|
+ return {text:lines.join('\n'),ext:'stl'};
|
|
|
+ }
|
|
|
+ const out=['# Pocket Shell Studio · unit mm · '+name];
|
|
|
+ let voff=0;
|
|
|
+ meshes.forEach((m,mi)=>{
|
|
|
+ const pos=m.getVerticesData(B.VertexBuffer.PositionKind);
|
|
|
+ const nrm=m.getVerticesData(B.VertexBuffer.NormalKind);
|
|
|
+ const idx=m.getIndices();
|
|
|
+ m.computeWorldMatrix(true);
|
|
|
+ const wm=m.getWorldMatrix();
|
|
|
+ out.push('o '+name+'_'+((m.metadata&&m.metadata.part)||mi));
|
|
|
+ for(let i=0;i<pos.length;i+=3){
|
|
|
+ const v=B.Vector3.TransformCoordinates(V3(pos[i],pos[i+1],pos[i+2]),wm);
|
|
|
+ out.push('v '+v.x.toFixed(4)+' '+v.y.toFixed(4)+' '+v.z.toFixed(4));
|
|
|
+ }
|
|
|
+ for(let i=0;i<nrm.length;i+=3) out.push('vn '+nrm[i].toFixed(4)+' '+nrm[i+1].toFixed(4)+' '+nrm[i+2].toFixed(4));
|
|
|
+ for(let i=0;i<idx.length;i+=3){
|
|
|
+ const a=idx[i]+1+voff,b=idx[i+1]+1+voff,c=idx[i+2]+1+voff;
|
|
|
+ out.push('f '+a+'//'+a+' '+b+'//'+b+' '+c+'//'+c);
|
|
|
+ }
|
|
|
+ voff+=pos.length/3;
|
|
|
+ });
|
|
|
+ return {text:out.join('\n'),ext:'obj'};
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ init:init,
|
|
|
+ load:load,
|
|
|
+ setParams:function(p){ cur.params=Object.assign({},p); rebuild(false); },
|
|
|
+ setMaterial:function(k){ cur.material=k; applyMaterial(k); },
|
|
|
+ setExplode:function(v){ applyExplode(v); },
|
|
|
+ setSolo:function(id){ setSolo(id); },
|
|
|
+ isSolo:function(){ return solo; },
|
|
|
+ setCutaway:function(on){ cur.cutForce=!!on; cutaway=!!on||cur.explode>0.2; applyMaterial(cur.material); },
|
|
|
+ isCutaway:function(){ return cutaway; },
|
|
|
+ setDims:setDims,
|
|
|
+ setView:setView,
|
|
|
+ frame:function(){ frame(); },
|
|
|
+ focusPart:focusPart,
|
|
|
+ highlight:highlight,
|
|
|
+ /* ---- 自定义结构件 ---- */
|
|
|
+ PRIMS:PRIMS,
|
|
|
+ setCustom:function(projectId,list){
|
|
|
+ customMap[projectId]=(list||[]).map(s=>Object.assign({},s));
|
|
|
+ if(cur.project===projectId) rebuild(false);
|
|
|
+ },
|
|
|
+ customList:function(){ return (customMap[cur.project]||[]).map(s=>Object.assign({},s)); },
|
|
|
+ addCustom:function(type,patch){
|
|
|
+ const s=Object.assign(newSpec(type),patch||{});
|
|
|
+ (customMap[cur.project]=customMap[cur.project]||[]).push(s);
|
|
|
+ rebuild(false);
|
|
|
+ highlight('c'+s.uid);
|
|
|
+ return Object.assign({},s);
|
|
|
+ },
|
|
|
+ updateCustom:function(uid,patch){
|
|
|
+ const l=customMap[cur.project]||[];
|
|
|
+ const s=l.find(x=>x.uid===uid);
|
|
|
+ if(!s) return null;
|
|
|
+ Object.assign(s,patch||{});
|
|
|
+ rebuild(false);
|
|
|
+ highlight('c'+uid);
|
|
|
+ return Object.assign({},s);
|
|
|
+ },
|
|
|
+ removeCustom:function(uid){
|
|
|
+ const l=customMap[cur.project]||[];
|
|
|
+ const i=l.findIndex(x=>x.uid===uid);
|
|
|
+ if(i>=0) l.splice(i,1);
|
|
|
+ rebuild(false);
|
|
|
+ },
|
|
|
+ clearCustom:function(){ customMap[cur.project]=[]; rebuild(false); },
|
|
|
+ onSelect:function(cb){ selCb=cb; },
|
|
|
+ onDrag:function(cb){ dragCb=cb; },
|
|
|
+ snapshot:function(){ if(!engine) return null; scene.render(); return canvas.toDataURL('image/png'); },
|
|
|
+ exportSTL:function(n){ return exportMesh('stl',n); },
|
|
|
+ exportOBJ:function(n){ return exportMesh('obj',n); },
|
|
|
+ exportSTLPart:function(n,pid){ return exportMesh('stl',n,pid); },
|
|
|
+ exportOBJPart:function(n,pid){ return exportMesh('obj',n,pid); },
|
|
|
+ partIds:function(){ return parts.map(p=>({id:p.id,custom:!!p.custom})); },
|
|
|
+ parts:function(){ return parts; },
|
|
|
+ isReady:function(){ return readyFlag; }
|
|
|
+ };
|
|
|
+})();
|
|
|
+import { LitElement, html } from 'https://fastly.jsdelivr.net/npm/lit@3.1.2/+esm';
|
|
|
+
|
|
|
+/* =========================================================
|
|
|
+ 工具
|
|
|
+ ========================================================= */
|
|
|
+const f1=(n,d)=>{ d=d===undefined?1:d; return (Math.round(n*Math.pow(10,d))/Math.pow(10,d)).toFixed(d); };
|
|
|
+const defaultParams=(id)=>{
|
|
|
+ const o={}; PROJECTS[id].params.forEach(x=>o[x.k]=x.def); return o;
|
|
|
+};
|
|
|
+const getParamDefs=(id)=>PROJECTS[id].params;
|
|
|
+
|
|
|
+/* =========================================================
|
|
|
+ 工艺规则库:建模自由度按工艺分档
|
|
|
+ ========================================================= */
|
|
|
+const RULES={
|
|
|
+ injection:{name:'注塑(ABS/PC)',minWall:0.8,minRib:0.8,draft:1,items:[
|
|
|
+ ['最小壁厚','0.8 mm,薄壁区建议 1.0'],['拔模角','≥1°,外观面 ≥2°'],
|
|
|
+ ['内角圆角','R ≥ 0.5(避免应力集中)'],['筋厚','≥0.8,且 ≤ 主壁厚 0.8 倍'],
|
|
|
+ ['深宽比','≤ 3:1,超过需镶件'],['缩水','0.4%~0.6%,开模按此放量']]},
|
|
|
+ silicone:{name:'硅胶模压',minWall:1.2,minRib:1.0,draft:3,items:[
|
|
|
+ ['壁厚','1.5~3.0 mm(回弹夹持区)'],['脱模角','≥3°,双角根部 ≥5°'],
|
|
|
+ ['圆角','R ≥ 0.5,禁止尖角'],['硬度','30~70 Shore A'],['最小批次','500 套(钢模)']]},
|
|
|
+ cnc:{name:'CNC 铝 6061',minWall:1.0,minRib:1.0,draft:0,items:[
|
|
|
+ ['最小刀具','Ø2,内角 R≥1'],['最小壁厚','1.0 mm,薄壁变形需留余量'],
|
|
|
+ ['深腔','≤ 4× 刀径,超过需五轴'],['公差','±0.05 关键 / ±0.1 一般'],
|
|
|
+ ['螺纹','阳极后必须二次回攻'],['标注','基准 + 孔位坐标表,缺一不接单']]},
|
|
|
+ vac:{name:'真空复模',minWall:1.2,minRib:1.0,draft:1.5,items:[
|
|
|
+ ['壁厚','≥1.2 mm'],['收缩补偿','0.3%,模具按放大做'],['批量','10 套起,适合内测']]},
|
|
|
+ die:{name:'压铸铝',minWall:1.5,minRib:1.2,draft:1.5,items:[
|
|
|
+ ['壁厚','≥1.5 mm'],['拔模','≥1.5°'],['模具费','¥12,000 起'],['MOQ','1000 套']]}
|
|
|
+};
|
|
|
+const ruleKey=(proc)=>{
|
|
|
+ if(proc==='sil-mold') return 'silicone';
|
|
|
+ if(proc==='die-cast') return 'die';
|
|
|
+ if(proc==='vacuum') return 'vac';
|
|
|
+ if(String(proc).indexOf('cnc')===0) return 'cnc';
|
|
|
+ return 'injection';
|
|
|
+};
|
|
|
+const EXPORTABLE={silicone:['body','floor','hornL','hornR','crown'],recorder:['body','lid','loop','btn'],round:['bezel','cap','boss','sbtn']};
|
|
|
+const primDim=(s)=>s.w!==undefined?[s.w,s.dd,s.h]:[s.dia,s.dia,s.h];
|
|
|
+const CYL_TYPES=['cyl','hole','pin3','boss2','boss25','boss3','thru25'];
|
|
|
+const RECT_TYPES=['box','pocket','rib','wall','clip','tray'];
|
|
|
+const HOLLOW_TYPES=['boss2','boss25','boss3','thru25'];
|
|
|
+const STD_PILOT={boss2:1.6,boss25:2.1,boss3:2.6};
|
|
|
+const primSpecText=(k)=>{ const P=STAGE.PRIMS[k]; if(!P) return ''; if(k==='box')return '8×8×H6';
|
|
|
+ if(k==='cyl')return 'Ø10 × H8'; if(k==='rib')return '14×1.2×H5'; if(k==='pocket')return '10×10×H2';
|
|
|
+ if(k==='hole')return 'Ø3 孔'; if(HOLLOW_TYPES.indexOf(k)>=0)return 'Ø'+P.d.dia+' / 孔Ø'+P.d.dd;
|
|
|
+ if(k==='pin3')return 'Ø3 × H4'; if(k==='pad4')return '间距 '+P.d.w+',M2.5';
|
|
|
+ if(k==='wall')return '20×0.8×H6'; if(k==='tray')return '22×18×H3'; if(k==='clip')return '5×1.2×H4'; return ''; };
|
|
|
+
|
|
|
+function cavity(id,p){
|
|
|
+ if(id==='silicone') return {kind:'rect',w:p.w,d:p.d,h:p.h};
|
|
|
+ if(id==='recorder') return {kind:'cyl',r:(p.D-2*p.t)/2,h:p.H-1.2-p.dm};
|
|
|
+ return {kind:'cyl',r:(p.D-2*p.t)/2,h:p.H-p.cap-p.dep};
|
|
|
+}
|
|
|
+
|
|
|
+/* 结构件与内腔的最小余量(mm) */
|
|
|
+function clearanceTo(id,p,s){
|
|
|
+ const cw=s.w!==undefined?s.w:s.dia, cd=s.dd!==undefined?s.dd:s.dia;
|
|
|
+ if(id==='silicone') return Math.min(p.w/2-(Math.abs(s.x||0)+cw/2), p.d/2-(Math.abs(s.z||0)+cd/2));
|
|
|
+ const cav=cavity(id,p);
|
|
|
+ return cav.r-(Math.hypot(s.x||0,s.z||0)+Math.max(cw,cd)/2);
|
|
|
+}
|
|
|
+
|
|
|
+/* 模型校验:每个结构件按当前工艺逐条过 */
|
|
|
+function modelChecks(id,p,list,rk){
|
|
|
+ const out=[],rule=RULES[rk];
|
|
|
+ const cav=cavity(id,p);
|
|
|
+ if(id!=='silicone'&&p.t<rule.minWall) out.push({ok:false,t:'主壁厚 '+f1(p.t)+' mm 低于 '+rule.name+' 下限 '+rule.minWall+' mm'});
|
|
|
+ if(!list.length) out.push({ok:true,t:'尚无自定义结构件:当前只有参数化主体,内部支撑靠默认壳体'});
|
|
|
+ list.forEach(s=>{
|
|
|
+ const d=primDim(s), thin=Math.min(d[0],d[1]);
|
|
|
+ const nm=(STAGE.PRIMS[s.type]?STAGE.PRIMS[s.type].n:'件');
|
|
|
+ const cl=clearanceTo(id,p,s);
|
|
|
+ if((s.type==='rib'||s.type==='box'||s.type==='pocket')&&thin<rule.minRib)
|
|
|
+ out.push({ok:false,t:nm+' 厚 '+f1(thin,2)+' mm < '+rule.name+' 最小 '+rule.minRib+' mm(会缩水/让刀)'});
|
|
|
+ if(cl<1.0) out.push({ok:false,t:nm+' 距内壁只剩 '+f1(cl,1)+' mm(<1 mm,装配与脱模都会出问题)'});
|
|
|
+ else out.push({ok:true,t:nm+' 距内壁 '+f1(cl,1)+' mm,余量可用'});
|
|
|
+ if(rule.draft>0&&s.type==='rib'&&(s.draft||0)<rule.draft)
|
|
|
+ out.push({ok:false,t:nm+' 拔模 '+(s.draft||0)+'° < '+rule.draft+'°('+rule.name+' 会粘模)'});
|
|
|
+ if(rk==='cnc'&&(s.type==='pocket'||s.type==='hole'))
|
|
|
+ out.push({ok:true,t:nm+':需在 2D 图纸标刀具半径 R≥1 与孔位坐标'});
|
|
|
+ if(['boss2','boss25','boss3'].indexOf(s.type)>=0){
|
|
|
+ const wall=(s.dia-s.dd)/2, minW=rk==='cnc'?0.9:Math.max(0.9,rule.minRib*0.9);
|
|
|
+ if(wall<minW) out.push({ok:false,t:nm+' 柱壁 '+f1(wall,2)+' mm < '+f1(minW,1)+' mm,自攻牙会胀裂'});
|
|
|
+ else out.push({ok:true,t:nm+' 柱壁 '+f1(wall,2)+' mm,可攻牙(预钻 Ø'+f1(s.dd,1)+')'});
|
|
|
+ const std=STD_PILOT[s.type];
|
|
|
+ if(Math.abs(s.dd-std)>0.15) out.push({ok:false,t:nm+' 预钻孔 Ø'+f1(s.dd,1)+' 非标准(该规格应为 Ø'+std+')'});
|
|
|
+ }
|
|
|
+ if(s.type==='pad4'){
|
|
|
+ const wall=(s.dia-s.hd)/2;
|
|
|
+ if(wall<0.9) out.push({ok:false,t:nm+' 柱壁 '+f1(wall,2)+' mm 偏薄(<0.9)'});
|
|
|
+ out.push({ok:true,t:nm+' 四柱中心距 '+f1(s.w,1)+' × '+f1(s.dd,1)+',需与 PCB 孔位一致(±0.05)'});
|
|
|
+ }
|
|
|
+ if((s.type==='pocket'||s.type==='hole')&&s.h>Math.min(d[0],d[1])*2)
|
|
|
+ out.push({ok:false,t:nm+' 深宽比 '+f1(s.h/Math.max(1,thin),1)+':1 > 2:1,需分层铣/镶件'});
|
|
|
+ });
|
|
|
+ return out;
|
|
|
+}
|
|
|
+
|
|
|
+function derived(id,p){
|
|
|
+ if(id==='silicone'){
|
|
|
+ const ow=p.w+2*p.t, od=p.d+2*p.t;
|
|
|
+ const vol=(2*(p.w+p.d)*p.t*p.h)+(p.w*p.d*1.2);
|
|
|
+ return [
|
|
|
+ ['外宽 × 外深', f1(ow)+' × '+f1(od)+' mm'],
|
|
|
+ ['内腔净尺寸', f1(p.w)+' × '+f1(p.d)+' × '+f1(p.h)+' mm'],
|
|
|
+ ['内腔圆角', f1(p.r)+' mm'],
|
|
|
+ ['双角', f1(p.hh)+' mm 高 / Ø'+f1(p.hd)+' 底'],
|
|
|
+ ['单件估重(不含表体)', f1(vol/1000*1.2,1)+' g'],
|
|
|
+ ['夹持余量建议', '内腔 = 实机 + 0.1~0.3 mm']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if(id==='recorder'){
|
|
|
+ const inner=p.D-2*p.t, vol=Math.PI*p.D*p.t*p.H + Math.PI*(p.D*p.D/4)*1.2;
|
|
|
+ return [
|
|
|
+ ['外径 × 总高', 'Ø'+f1(p.D)+' × '+f1(p.H)+' mm'],
|
|
|
+ ['内腔可用', 'Ø'+f1(inner)+' × '+f1(p.H-1.2-p.dm)+' mm'],
|
|
|
+ ['上盖穹顶', f1(p.dm)+' mm'],
|
|
|
+ ['挂环', '孔径 Ø'+f1(p.ld)+' / 外伸 '+f1(p.lh)+' mm'],
|
|
|
+ ['单件估重(不含电子)', f1(vol/1000*1.05,1)+' g'],
|
|
|
+ ['PCB 建议', 'Φ'+f1(Math.min(inner-4,26))+' 以内,留 2mm 边距']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ const inner=p.D-2*p.t;
|
|
|
+ const vol=Math.PI*p.D*p.t*p.H;
|
|
|
+ return [
|
|
|
+ ['外径 × 总厚', 'Ø'+f1(p.D,2)+' × '+f1(p.H,2)+' mm'],
|
|
|
+ ['内腔可用', 'Ø'+f1(inner)+' × '+f1(p.H-p.cap-p.dep,2)+' mm'],
|
|
|
+ ['屏 / 黑边', 'Ø'+f1(p.sd,2)+' / Ø'+f1(p.bd,1)+',沉台 '+f1(p.dep)+' mm'],
|
|
|
+ ['屏占比', f1(p.sd/p.D*100,0)+'%'],
|
|
|
+ ['单件估重(铝壳)', f1(vol/1000*2.7,1)+' g'],
|
|
|
+ ['后盖', f1(p.cap,1)+' mm 厚 / 示意 M'+f1(inner+1,1)+'×1.5']
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
+function fitRows(id,p){
|
|
|
+ if(id==='round'){
|
|
|
+ const inner=p.D-2*p.t;
|
|
|
+ return [
|
|
|
+ ['屏 AA Ø45.68 vs 沉台开口 Ø'+f1(p.bd,1), p.bd>=45.68?'可通过':'需放大黑边'],
|
|
|
+ ['主板 Φ44 vs 内腔 Ø'+f1(inner,1), inner>=45?'可通过':'内腔不足,需减壁厚'],
|
|
|
+ ['屏厚 1.0 + 0.2 缓冲 vs 沉台 '+f1(p.dep), p.dep>=1.2?'OK':'偏浅,顶屏风险'],
|
|
|
+ ['锂电 103450(10 厚) vs 净高 '+f1(p.H-p.cap-p.dep,1), (p.H-p.cap-p.dep)>=11?'OK':'需改电芯']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if(id==='recorder'){
|
|
|
+ const inner=p.D-2*p.t;
|
|
|
+ return [
|
|
|
+ ['ESP32-S3-WROOM-1 18×25.5 vs 内腔 Ø'+f1(inner,1), inner>=28?'需改板形':'需底板切圆角'],
|
|
|
+ ['Φ26 PCB vs 内腔 Ø'+f1(inner,1), inner>=28?'OK':'需缩板'],
|
|
|
+ ['软包 402030(20 宽) vs Ø'+f1(inner,1), inner>=24?'OK':'需换电芯'],
|
|
|
+ ['Type-C 座 9.0 长 vs 壁厚 '+f1(p.t), '需侧开孔 9.2×3.6'],
|
|
|
+ ['麦孔声腔 1.5mm', p.H>=10?'OK':'腔体偏薄']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ const inner=p.w;
|
|
|
+ return [
|
|
|
+ ['表体 41.3×41.3 vs 内腔 '+f1(inner,1)+'×'+f1(p.d,1), inner>=41.5?'OK':'需按实机放大'],
|
|
|
+ ['表冠凸出 vs 开孔允许', p.cr>=1.2?'OK':'需加大开孔'],
|
|
|
+ ['壁厚回弹区 2~3mm', (p.t>=2&&p.t<=3)?'OK':'夹持偏弱'],
|
|
|
+ ['双角根部 Ø'+f1(p.hd)+' vs 顶面宽 '+f1((p.w+2*p.t-p.hg)/2,1), '需 ≥1mm 余量']
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
+function processTable(id,qty){
|
|
|
+ const rows=[];
|
|
|
+ PROJECTS[id].processes.forEach(pr=>{
|
|
|
+ let unit=null;
|
|
|
+ pr.unit.forEach(t=>{ if(qty>=t[0]) unit=t[1]; });
|
|
|
+ if(unit===null) unit=pr.unit[0][1];
|
|
|
+ const extra=pr.mold||0;
|
|
|
+ const total=extra+qty*unit;
|
|
|
+ rows.push({...pr,unitUsed:unit,per:total/qty,below:qty<pr.minQty,total});
|
|
|
+ });
|
|
|
+ return rows;
|
|
|
+}
|
|
|
+
|
|
|
+/* =========================================================
|
|
|
+ 规格单 / BOM 生成
|
|
|
+ ========================================================= */
|
|
|
+function specMarkdown(id,params,matKey,qty,customs){
|
|
|
+ const proj=PROJECTS[id], mat=MATERIALS[matKey]||MATERIALS[proj.materials[0]];
|
|
|
+ const L=[];
|
|
|
+ L.push('# 生产需求单 | '+proj.name);
|
|
|
+ L.push('');
|
|
|
+ L.push('- 参考型号:'+proj.ref);
|
|
|
+ L.push('- 版本:v1.4(壳体工坊自动生成)');
|
|
|
+ L.push('- 日期:'+new Date().toLocaleDateString('zh-CN'));
|
|
|
+ L.push('- 单位:mm;数量:'+qty+' 套(报价按此数量)');
|
|
|
+ L.push('- 币种:CNY,含 13% 增值税口径请供应商标注');
|
|
|
+ L.push('');
|
|
|
+ L.push('## 1. 关键尺寸(当前参数快照)');
|
|
|
+ L.push('');
|
|
|
+ L.push('| 参数 | 数值 | 说明 |');
|
|
|
+ L.push('| --- | --- | --- |');
|
|
|
+ proj.params.forEach(x=>{
|
|
|
+ L.push('| '+x.n+' ('+x.k+') | '+f1(params[x.k],2)+' mm | 范围 '+x.min+'~'+x.max+' |');
|
|
|
+ });
|
|
|
+ L.push('');
|
|
|
+ L.push('派生尺寸:');
|
|
|
+ derived(id,params).forEach(d=>L.push('- '+d[0]+':'+d[1]));
|
|
|
+ L.push('');
|
|
|
+ if(id==='round'){
|
|
|
+ L.push('> **CNC 弧面(按此编程)**:外壁顶部凸圆 R'+f1(params.rimR,2)+';屏边凹圆弧 R'+f1(params.dep,2)+'(沉台深 '+f1(params.dep,2)+');底边倒角 C'+f1(params.cham,2)+'。弧面用 R≥1 的球头/圆鼻刀连续走刀,过渡区不得有接刀痕与刀纹台阶。');
|
|
|
+ L.push('');
|
|
|
+ }
|
|
|
+ L.push('## 2. 外观与材质');
|
|
|
+ L.push('');
|
|
|
+ L.push('- 主体材质:'+mat.name+'('+(mat.note||'按工艺常规')+')');
|
|
|
+ L.push('- 表面处理:'+(id==='round'?'喷砂 + 阳极氧化 10~15μm;阳极后螺纹二次回攻':(id==='silicone'?'喷手感油(哑光);丝印/镭雕 logo 可选':'注塑本色或喷橡胶漆,耐磨 500g 摩擦')));
|
|
|
+ L.push('- 颜色:以提供的色卡为准(Pantone / 劳尔号),色差 ΔE ≤ 1.5');
|
|
|
+ L.push('- 外观面:无缩水、无顶白、无拉伤、无熔接线可见');
|
|
|
+ L.push('');
|
|
|
+ L.push('## 3. 公差与验收');
|
|
|
+ L.push('');
|
|
|
+ L.push('| 项目 | 要求 |');
|
|
|
+ L.push('| --- | --- |');
|
|
|
+ proj.tolerance.forEach(t=>L.push('| '+t[0]+' | '+t[1]+' |'));
|
|
|
+ L.push('| 首件 | 提供三坐标/影像仪报告 + 实配照片 |');
|
|
|
+ L.push('| 抽检 | AQL 1.0 外观 / 0.65 关键尺寸 |');
|
|
|
+ L.push('');
|
|
|
+ L.push('## 4. 工艺路线(请逐项报价)');
|
|
|
+ L.push('');
|
|
|
+ L.push('| 工艺 | MOQ | 一次性费用 | 单价 | 交期 | 备注 |');
|
|
|
+ L.push('| --- | --- | --- | --- | --- | --- |');
|
|
|
+ proj.processes.forEach(pr=>{
|
|
|
+ let unit=null; pr.unit.forEach(t=>{ if(qty>=t[0]) unit=t[1]; });
|
|
|
+ if(unit===null) unit=pr.unit[0][1];
|
|
|
+ L.push('| '+pr.n+' | '+pr.minQty+' | ¥'+pr.mold+' | ¥'+unit+'/套 | '+pr.lead+' | '+pr.note+' |');
|
|
|
+ });
|
|
|
+ L.push('');
|
|
|
+ L.push('> 数量 '+qty+' 套时的单套综合成本(含模具摊销):');
|
|
|
+ processTable(id,qty).forEach(r=>{
|
|
|
+ L.push('- '+r.n+':¥'+f1(r.per,1)+'/套'+(r.below?'(低于 MOQ,按最小批量摊)':''));
|
|
|
+ });
|
|
|
+ L.push('');
|
|
|
+ L.push('## 5. 零件清单(BOM 摘要)');
|
|
|
+ L.push('');
|
|
|
+ L.push('| # | 零件 | 数量 | 材质 | 工艺 | 公差 |');
|
|
|
+ L.push('| --- | --- | --- | --- | --- | --- |');
|
|
|
+ proj.parts.forEach((pt,i)=>L.push('| '+(i+1)+' | '+pt.n+' | '+pt.q+' | '+pt.mat+' | '+pt.proc+' | '+pt.tol+' |'));
|
|
|
+ L.push('');
|
|
|
+ L.push('');
|
|
|
+ L.push('## 5.5 自定义结构件(我方在网页端建模,需随主体一起加工)');
|
|
|
+ L.push('');
|
|
|
+ const cs=customs||[];
|
|
|
+ const rk=ruleKey((PROJECTS[id].processes[0]||{}).key);
|
|
|
+ if(!cs.length){
|
|
|
+ L.push('- 暂无自定义结构件;内部支撑结构按上方主参数与装配顺序推定。');
|
|
|
+ }else{
|
|
|
+ L.push('| # | 类型 | 坐标 x / y / z(mm,壳中心为原点) | 外形尺寸 | 工艺要求 |');
|
|
|
+ L.push('| --- | --- | --- | --- | --- |');
|
|
|
+ cs.forEach((s,i)=>{
|
|
|
+ const nm=STAGE.PRIMS[s.type]?STAGE.PRIMS[s.type].n:s.type;
|
|
|
+ const d=primDim(s);
|
|
|
+ const dim=(s.type==='cyl'||s.type==='boss'||s.type==='hole')
|
|
|
+ ? ('Ø'+f1(s.dia,2)+' × H'+f1(s.h,2))
|
|
|
+ : (f1(s.w,2)+' × '+f1(s.dd,2)+' × H'+f1(s.h,2));
|
|
|
+ let req='与主体同材质,去刀纹';
|
|
|
+ if(s.type==='rib'||s.type==='wall') req='拔模 '+(s.draft||0)+'°,壁厚 '+f1(d[1],2)+' mm,根部 R0.5';
|
|
|
+ else if(s.type==='boss2'||s.type==='boss25'||s.type==='boss3'){
|
|
|
+ const m=(s.type==='boss2'?'M2':s.type==='boss25'?'M2.5':'M3');
|
|
|
+ req=m+' 自攻牙:预钻 Ø'+f1(s.dd,2)+',柱径 Ø'+f1(s.dia,2)+',同轴度 ≤0.05'+(rk==='cnc'?',建议嵌铜螺母':'');
|
|
|
+ }
|
|
|
+ else if(s.type==='thru25') req='Ø'+f1(s.dia,2)+' 过孔(M2.5 螺钉),位置度 ±0.05';
|
|
|
+ else if(s.type==='pin3') req='Ø'+f1(s.dia,2)+' 定位销孔/销,H7 配合';
|
|
|
+ else if(s.type==='pad4') req='四角柱:中心距 '+f1(s.w,1)+'×'+f1(s.dd,1)+',M2.5 预钻 Ø'+f1(s.hd,2)+',与 PCB 孔位同轴 ±0.05';
|
|
|
+ else if(s.type==='pocket') req='铣削凹槽,内角 R≥1,深 '+f1(s.h,2)+' mm';
|
|
|
+ else if(s.type==='hole') req='钻孔 Ø'+f1(s.dia,2)+',位置度 ±0.05';
|
|
|
+ else if(s.type==='tray') req='电池仓:壁厚 0.8~1.2,底部 R0.5,留极耳缺口';
|
|
|
+ else if(s.type==='clip') req='卡扣:根部 R0.4,扣合量 0.3~0.5,需试插 50 次不疲劳';
|
|
|
+ L.push('| '+(i+1)+' | '+nm+' | '+f1(s.x,2)+' / '+f1(s.y,2)+' / '+f1(s.z,2)+' | '+dim+' | '+req+' |');
|
|
|
+ });
|
|
|
+ L.push('');
|
|
|
+ L.push('> 结构件已随主体一同写入 STL/OBJ;CNC 报价请按「上表坐标 + 刀具半径」评估,注塑请按壁厚/拔模评估。');
|
|
|
+ }
|
|
|
+ L.push('');
|
|
|
+ L.push('## 6. 装配顺序');
|
|
|
+ L.push('');
|
|
|
+ proj.steps.forEach((s,i)=>L.push((i+1)+'. **'+s.n+'**:'+s.d));
|
|
|
+ L.push('');
|
|
|
+ L.push('## 7. 交付文件(我方提供 / 需供应商确认)');
|
|
|
+ L.push('');
|
|
|
+ proj.files.forEach(f=>L.push('- [ ] '+f));
|
|
|
+ L.push('- [ ] 本需求单(PDF)+ STL/OBJ 预览网格');
|
|
|
+ L.push('- [ ] 色卡与表面处理样板');
|
|
|
+ L.push('');
|
|
|
+ L.push('## 8. 报价回填(请供应商填写)');
|
|
|
+ L.push('');
|
|
|
+ L.push('| 项目 | 供应商填写 |');
|
|
|
+ L.push('| --- | --- |');
|
|
|
+ ['模具费(含试模/改模次数)','单品单价(含税/不含税)','最小起订量 MOQ','打样费及抵扣规则','交期(打样/大货)','模具归属','包装方式与费用','有效期'].forEach(x=>L.push('| '+x+' | |'));
|
|
|
+ L.push('');
|
|
|
+ L.push('## 9. 待确认项');
|
|
|
+ L.push('');
|
|
|
+ proj.notes.forEach(n=>L.push('- '+n));
|
|
|
+ L.push('- 电子件尺寸以官方规格书为准,打样前需实机复测。');
|
|
|
+ L.push('');
|
|
|
+ L.push('---');
|
|
|
+ L.push('本需求单由「壳体工坊」根据当前 3D 参数快照生成;价格区间为深圳/东莞 2026-11 行情参考,不构成报价承诺。');
|
|
|
+ return L.join('\n');
|
|
|
+}
|
|
|
+
|
|
|
+function bomCSV(id,params,matKey){
|
|
|
+ const proj=PROJECTS[id], mat=MATERIALS[matKey]||MATERIALS[proj.materials[0]];
|
|
|
+ const rows=[['序号','零件','数量','材质','工艺','关键尺寸/公差','备注']];
|
|
|
+ proj.parts.forEach((pt,i)=>{
|
|
|
+ rows.push([i+1,pt.n,pt.q,pt.mat==='主材质'?mat.name:pt.mat,pt.proc,pt.tol,pt.id==='screen'?'视窗透光面':''].map(v=>'"'+String(v).replace(/"/g,'""')+'"').join(','));
|
|
|
+ });
|
|
|
+ return rows.join('\n');
|
|
|
+}
|
|
|
+
|
|
|
+function specJSON(id,params,matKey,qty,customs){
|
|
|
+ return JSON.stringify({
|
|
|
+ app:'Pocket Shell Studio',version:'1.4',exportedAt:new Date().toISOString(),unit:'mm',
|
|
|
+ project:{id,name:proj_name(id),ref:PROJECTS[id].ref},
|
|
|
+ material:MATERIALS[matKey],
|
|
|
+ params:params,derived:derived(id,params),customParts:customs||[],
|
|
|
+ qty:qty,processes:processTable(id,qty).map(r=>({name:r.n,mold:r.mold,unit:r.unitUsed,perSet:+r.per.toFixed(2),lead:r.lead,belowMOQ:r.below})),
|
|
|
+ parts:PROJECTS[id].parts,assembly:PROJECTS[id].steps,tolerance:PROJECTS[id].tolerance,files:PROJECTS[id].files
|
|
|
+ },null,2);
|
|
|
+}
|
|
|
+function proj_name(id){ return PROJECTS[id].name; }
|
|
|
+
|
|
|
+function fitSVG(id,p){
|
|
|
+ const S=150;
|
|
|
+ let maxMm, shapes=[], texts=[];
|
|
|
+ const push=(s)=>shapes.push(s);
|
|
|
+ if(id==='round'){
|
|
|
+ const ro=p.D/2, bd=p.bd/2, sd=p.sd/2;
|
|
|
+ maxMm=p.D*1.08;
|
|
|
+ push({t:'c',r:ro,s:'#1f6feb',w:1.6});
|
|
|
+ push({t:'c',r:bd,s:'#94a3b8',w:1,dash:true});
|
|
|
+ push({t:'c',r:sd,s:'#0f9d58',w:1.2});
|
|
|
+ for(let i=0;i<4;i++){const a2=Math.PI/4+i*Math.PI/2;push({t:'d',x:Math.cos(a2)*(ro-9),y:Math.sin(a2)*(ro-9),r:2.1,s:'#b08d57'});}
|
|
|
+ texts.push(['Ø'+f1(p.D,2),0,-ro-4]);
|
|
|
+ }else if(id==='recorder'){
|
|
|
+ const ro=p.D/2, ri=ro-p.t;
|
|
|
+ maxMm=p.D*1.35;
|
|
|
+ push({t:'c',r:ro,s:'#1f6feb',w:1.6});
|
|
|
+ push({t:'c',r:ri,s:'#94a3b8',w:1,dash:true});
|
|
|
+ push({t:'c',r:Math.min(ro-2.5,13),s:'#0f9d58',w:1.2});
|
|
|
+ const micR=Math.max(4,ro*0.4);
|
|
|
+ for(let i=0;i<4;i++){const a2=Math.PI/4+i*Math.PI/2;push({t:'d',x:Math.cos(a2)*micR,y:Math.sin(a2)*micR,r:1.2,s:'#0a0c10'});}
|
|
|
+ push({t:'r',x:ro-0.4,y:0,w:2.6,h:9,s:'#dc2626',sw:1});
|
|
|
+ texts.push(['Ø'+f1(p.D,1),0,-ro-4],['内腔 Ø'+f1(ri,1),ri*0.72,ri*0.72]);
|
|
|
+ }else{
|
|
|
+ const ow=p.w+2*p.t, od=p.d+2*p.t;
|
|
|
+ maxMm=Math.max(ow,od)*1.1;
|
|
|
+ push({t:'r',x:0,y:0,w:ow,h:od,s:'#1f6feb',w:1.6});
|
|
|
+ push({t:'r',x:0,y:0,w:p.w,h:p.d,s:'#94a3b8',w:1,dash:true});
|
|
|
+ push({t:'r',x:0,y:0,w:Math.max(6,p.w-2.8),h:Math.max(6,p.d-2.8),s:'#0f9d58',w:1.2});
|
|
|
+ texts.push(['外 '+f1(ow,1)+'×'+f1(od,1),0,-od/2-4],['内腔 '+f1(p.w,1)+'×'+f1(p.d,1),0,p.d/2+3.5],['屏视窗',0,0]);
|
|
|
+ }
|
|
|
+ const k=S/maxMm, cx=100, cy=100;
|
|
|
+ const toX=(v)=>cx+v*k, toY=(v)=>cy-v*k;
|
|
|
+ const body=shapes.map(s=>{
|
|
|
+ if(s.t==='c') return `<circle cx="${cx}" cy="${cy}" r="${(s.r*k).toFixed(2)}" fill="none" stroke="${s.s}" stroke-width="${s.w}" ${s.dash?'stroke-dasharray="4 3"':''}/>`;
|
|
|
+ if(s.t==='d') return `<circle cx="${toX(s.x).toFixed(2)}" cy="${toY(s.y).toFixed(2)}" r="${(s.r*k).toFixed(2)}" fill="${s.s}"/>`;
|
|
|
+ return `<rect x="${toX(-s.w/2).toFixed(2)}" y="${toY(s.h/2).toFixed(2)}" width="${(s.w*k).toFixed(2)}" height="${(s.h*k).toFixed(2)}" fill="none" stroke="${s.s}" stroke-width="${s.sw||1}" ${s.dash?'stroke-dasharray="4 3"':''}/>`;
|
|
|
+ }).join('');
|
|
|
+ const labels=texts.map(t=>`<text x="${toX(t[1])}" y="${toY(t[2])}" font-size="7.5" fill="#68758a" text-anchor="middle" font-family="Noto Sans SC,sans-serif">${t[0]}</text>`).join('');
|
|
|
+ return `<svg viewBox="0 0 200 200" width="100%" style="max-width:300px;display:block;margin:4px auto 10px">
|
|
|
+ <line x1="${cx}" y1="14" x2="${cx}" y2="186" stroke="#dbe3ec" stroke-width="0.6"/>
|
|
|
+ <line x1="14" y1="${cy}" x2="186" y2="${cy}" stroke="#dbe3ec" stroke-width="0.6"/>
|
|
|
+ ${body}${labels}</svg>`;
|
|
|
+}
|
|
|
+
|
|
|
+function saveFile(name,text,mime){
|
|
|
+ const blob=new Blob([text],{type:mime||'text/plain;charset=utf-8'});
|
|
|
+ const url=URL.createObjectURL(blob);
|
|
|
+ const a=document.createElement('a');
|
|
|
+ a.href=url; a.download=name; document.body.appendChild(a); a.click();
|
|
|
+ setTimeout(()=>{ URL.revokeObjectURL(url); a.remove(); },1200);
|
|
|
+}
|
|
|
+function saveDataURL(name,dataURL){
|
|
|
+ const a=document.createElement('a');
|
|
|
+ a.href=dataURL; a.download=name; document.body.appendChild(a); a.click();
|
|
|
+ setTimeout(()=>a.remove(),800);
|
|
|
+}
|
|
|
+
|
|
|
+function toast(msg){
|
|
|
+ let t=document.getElementById('toast');
|
|
|
+ if(!t){ t=document.createElement('div'); t.id='toast'; document.body.appendChild(t); }
|
|
|
+ t.textContent=msg; t.classList.add('on');
|
|
|
+ clearTimeout(window.__toastT);
|
|
|
+ window.__toastT=setTimeout(()=>t.classList.remove('on'),1900);
|
|
|
+}
|
|
|
+
|
|
|
+const buzz=(ms)=>{ try{ if(navigator.vibrate) navigator.vibrate(ms); }catch(e){} };
|
|
|
+const LS={
|
|
|
+ get(k,d){ try{ const v=localStorage.getItem(k); return v?JSON.parse(v):d; }catch(e){ return d; } },
|
|
|
+ set(k,v){ try{ localStorage.setItem(k,JSON.stringify(v)); }catch(e){} }
|
|
|
+};
|
|
|
+
|
|
|
+/* =========================================================
|
|
|
+ 3D 舞台组件
|
|
|
+ ========================================================= */
|
|
|
+class GlStage extends LitElement{
|
|
|
+ static properties={
|
|
|
+ project:{attribute:false}, params:{attribute:false}, material:{attribute:false},
|
|
|
+ explode:{attribute:false}, dims:{attribute:false}, hl:{attribute:false}, mini:{attribute:false}
|
|
|
+ };
|
|
|
+ createRenderRoot(){ return this; }
|
|
|
+ constructor(){ super(); this._initDone=false; this._view='iso'; }
|
|
|
+
|
|
|
+ firstUpdated(){
|
|
|
+ const canvas=this.querySelector('canvas');
|
|
|
+ const host=this.querySelector('.stage');
|
|
|
+ STAGE.init(canvas,host);
|
|
|
+ this._initDone=true;
|
|
|
+ STAGE.load(this.project,this.params,this.material,this.explode||0);
|
|
|
+ STAGE.setDims(this.dims!==false);
|
|
|
+ if(this.hl) STAGE.highlight(this.hl);
|
|
|
+ }
|
|
|
+ updated(ch){
|
|
|
+ if(!this._initDone) return;
|
|
|
+ if(ch.has('project')){ STAGE.load(this.project,this.params,this.material,this.explode||0); }
|
|
|
+ else if(ch.has('params')){ STAGE.setParams(this.params); }
|
|
|
+ if(ch.has('material')) STAGE.setMaterial(this.material);
|
|
|
+ if(ch.has('explode')) STAGE.setExplode(this.explode||0);
|
|
|
+ if(ch.has('dims')) STAGE.setDims(this.dims!==false);
|
|
|
+ if(ch.has('hl')) STAGE.highlight(this.hl);
|
|
|
+ }
|
|
|
+
|
|
|
+ pick(m){
|
|
|
+ this.dispatchEvent(new CustomEvent('mat-change',{detail:m,bubbles:true}));
|
|
|
+ }
|
|
|
+ view(v){
|
|
|
+ this._view=v; STAGE.setView(v);
|
|
|
+ this.querySelectorAll('.vbtn').forEach(b=>b.classList.toggle('on',b.dataset.v===v));
|
|
|
+ }
|
|
|
+ toggleDims(){
|
|
|
+ this.dispatchEvent(new CustomEvent('dims-change',{detail:!(this.dims!==false),bubbles:true}));
|
|
|
+ }
|
|
|
+ toggleExplode(){
|
|
|
+ const next=(this.explode||0)>0.3?0:0.85;
|
|
|
+ this.dispatchEvent(new CustomEvent('explode-change',{detail:next,bubbles:true}));
|
|
|
+ }
|
|
|
+
|
|
|
+ render(){
|
|
|
+ const proj=PROJECTS[this.project]||PROJECTS.silicone;
|
|
|
+ return html`
|
|
|
+ <div class="stage ${this.mini?'mini':''}">
|
|
|
+ <canvas></canvas>
|
|
|
+ <div class="stage-top">
|
|
|
+ <span class="badge">${proj.en}</span>
|
|
|
+ <span class="spacer"></span>
|
|
|
+ <button class="vbtn" data-v="iso" @click=${()=>this.view('iso')}>45°</button>
|
|
|
+ <button class="vbtn" data-v="front" @click=${()=>this.view('front')}>正视</button>
|
|
|
+ <button class="vbtn" data-v="top" @click=${()=>this.view('top')}>俯视</button>
|
|
|
+ <button class="vbtn" @click=${()=>STAGE.frame()}>适应</button>
|
|
|
+ <button class="vbtn ${this.dims!==false?'on':''}" @click=${()=>this.toggleDims()}>标注</button>
|
|
|
+ <button class="vbtn ${(this.explode||0)>0.3?'on':''}" @click=${()=>this.toggleExplode()}>爆炸</button>
|
|
|
+ </div>
|
|
|
+ ${this.mini?html`<div class="ghint">单指旋转 · 双指缩放 · 双击零件聚焦</div>`:''}
|
|
|
+ <div class="stage-bottom">
|
|
|
+ <div class="matrow">
|
|
|
+ ${proj.materials.map(k=>{
|
|
|
+ const m=MATERIALS[k];
|
|
|
+ return html`<div class="mat ${this.material===k?'on':''}" @click=${()=>this.pick(k)}>
|
|
|
+ <i style="background:${m.swatch}"></i>${m.name}</div>`;
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+}
|
|
|
+customElements.define('gl-stage',GlStage);
|
|
|
+
|
|
|
+/* =========================================================
|
|
|
+ 主应用
|
|
|
+ ========================================================= */
|
|
|
+class AppRoot extends LitElement{
|
|
|
+ createRenderRoot(){ return this; }
|
|
|
+ constructor(){
|
|
|
+ super();
|
|
|
+ this.state={
|
|
|
+ route:'hub', project:'silicone', tab:'look',
|
|
|
+ params:defaultParams('silicone'),
|
|
|
+ material:PROJECTS.silicone.materials[0],
|
|
|
+ explode:0, dims:true, hl:null, qty:500,
|
|
|
+ proc:'sil-mold', selUid:null, snap:0.5, solo:null, dockPx:0.46, dockSnap:'half'
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ connectedCallback(){
|
|
|
+ super.connectedCallback();
|
|
|
+ this._onHash=()=>this.routeFromHash();
|
|
|
+ window.addEventListener('hashchange',this._onHash);
|
|
|
+ this._onViewport=()=>{
|
|
|
+ const vv=window.visualViewport;
|
|
|
+ if(!vv) return;
|
|
|
+ const kb=Math.max(0,Math.round(window.innerHeight-vv.height-vv.offsetTop));
|
|
|
+ document.documentElement.style.setProperty('--kb',(kb>40?kb:0)+'px');
|
|
|
+ if(this.state&&this.state.tab==='mdl'&&!this._dragStart&&kb===0) this.applyDock(this.state.dockPx,false);
|
|
|
+ };
|
|
|
+ if(window.visualViewport){
|
|
|
+ window.visualViewport.addEventListener('resize',this._onViewport);
|
|
|
+ window.visualViewport.addEventListener('scroll',this._onViewport);
|
|
|
+ }
|
|
|
+ if(typeof STAGE!=='undefined' && STAGE.onSelect){
|
|
|
+ STAGE.onSelect((partId)=>{
|
|
|
+ if(!partId){ this.state.selUid=null; this.requestUpdate(); return; }
|
|
|
+ if(String(partId).indexOf('c')===0&&!isNaN(parseInt(String(partId).slice(1),10))){
|
|
|
+ this.state.selUid=parseInt(String(partId).slice(1),10);
|
|
|
+ this.requestUpdate();
|
|
|
+ buzz(8);
|
|
|
+ if(this.state.tab==='mdl'){
|
|
|
+ if(this.dockPx()<this.dockHeights().half-20) this.snapDock('half',true);
|
|
|
+ this.jumpDock('#dNum');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ STAGE.onDrag((s)=>{
|
|
|
+ this.persistCustom();
|
|
|
+ clearTimeout(this._dragT);
|
|
|
+ this._dragT=setTimeout(()=>this.requestUpdate(),160);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.routeFromHash();
|
|
|
+ }
|
|
|
+ disconnectedCallback(){ window.removeEventListener('hashchange',this._onHash); super.disconnectedCallback(); }
|
|
|
+
|
|
|
+ routeFromHash(){
|
|
|
+ const h=location.hash.replace(/^#\/?/,'');
|
|
|
+ if(h.indexOf('p/')===0){
|
|
|
+ const id=h.slice(2).split('?')[0]||'silicone';
|
|
|
+ const pid=PROJECTS[id]?id:'silicone';
|
|
|
+ const q=new URLSearchParams(h.split('?')[1]||'');
|
|
|
+ const saved=LS.get('ss.p.'+pid,null);
|
|
|
+ this.state.route='project';
|
|
|
+ this.state.project=pid;
|
|
|
+ this.state.params=Object.assign(defaultParams(pid),saved&&saved.params||{});
|
|
|
+ const qm=q.get('mat');
|
|
|
+ this.state.material=(qm&&MATERIALS[qm])?qm:((saved&&saved.material)||PROJECTS[pid].materials[0]);
|
|
|
+ const tabs=['look','asm','mdl','elec','proc','out'];
|
|
|
+ this.state.tab=tabs.indexOf(q.get('tab'))>=0?q.get('tab'):'look';
|
|
|
+ this.state.explode=Math.min(1,Math.max(0,parseFloat(q.get('ex')||'0')||0));
|
|
|
+ this.state.qty=Math.max(50,Math.min(5000,parseInt(q.get('qty')||'500',10)||500));
|
|
|
+ this.state.hl=q.get('hl')||null;
|
|
|
+ this.state.selUid=null;
|
|
|
+ this.state.solo=null;
|
|
|
+ this._hist=[]; this._redo=[];
|
|
|
+ this.state.proc=PROJECTS[pid].processes[0].key;
|
|
|
+ if(typeof STAGE!=='undefined'&&STAGE.setCustom){ STAGE.setCustom(pid,LS.get('ss.custom.'+pid,[])); STAGE.setSolo(null); }
|
|
|
+ if(this.state.tab==='mdl'){
|
|
|
+ const sn=LS.get('ss.dock','half');
|
|
|
+ this.state.dockSnap=sn; this.state.dockPx=(this.dockHeights()[sn]||this.dockHeights().half)/(window.innerHeight||800);
|
|
|
+ setTimeout(()=>{ this.applyDock(this.dockPx(),false); try{ STAGE.setCutaway(true); }catch(e){} },120);
|
|
|
+ }
|
|
|
+ }else if(h.indexOf('kb')===0){
|
|
|
+ this.state.route='kb';
|
|
|
+ }else{
|
|
|
+ this.state.route='hub';
|
|
|
+ }
|
|
|
+ this.requestUpdate();
|
|
|
+ window.scrollTo(0,0);
|
|
|
+ }
|
|
|
+
|
|
|
+ persist(){
|
|
|
+ LS.set('ss.p.'+this.state.project,{params:this.state.params,material:this.state.material});
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------- 底部编辑坞:三段高度 + 拖拽 ---------- */
|
|
|
+ dockHeights(){
|
|
|
+ const h=window.innerHeight||800;
|
|
|
+ return {peek:Math.round(h*0.20),half:Math.round(h*0.46),full:Math.round(h*0.72)};
|
|
|
+ }
|
|
|
+ dockPx(){ return Math.round(window.innerHeight*(this.state.dockPx||0.46)); }
|
|
|
+ applyDock(px,animate){
|
|
|
+ const v=Math.max(150,Math.min(Math.round(window.innerHeight*0.82),px));
|
|
|
+ document.documentElement.style.setProperty('--dockH',v+'px');
|
|
|
+ if(animate){ const el=this.querySelector('.dock'); if(el){ el.classList.add('drag'); requestAnimationFrame(()=>el.classList.remove('drag')); } }
|
|
|
+ }
|
|
|
+ snapDock(name,animate=false){
|
|
|
+ const hs=this.dockHeights(), px=hs[name]||hs.half;
|
|
|
+ this.state.dockPx=px/(window.innerHeight||800);
|
|
|
+ this.state.dockSnap=name;
|
|
|
+ LS.set('ss.dock',name);
|
|
|
+ this.applyDock(px,animate);
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ onGrabDown(e){
|
|
|
+ this._dragStart={y:e.clientY,h:this.dockPx()};
|
|
|
+ const el=e.currentTarget; try{ el.setPointerCapture(e.pointerId); }catch(err){}
|
|
|
+ const dock=this.querySelector('.dock'); if(dock) dock.classList.add('drag');
|
|
|
+ e.preventDefault();
|
|
|
+ }
|
|
|
+ onGrabMove(e){
|
|
|
+ if(!this._dragStart) return;
|
|
|
+ const h=this._dragStart.h+(this._dragStart.y-e.clientY);
|
|
|
+ this.applyDock(h,false);
|
|
|
+ }
|
|
|
+ onGrabUp(e){
|
|
|
+ if(!this._dragStart) return;
|
|
|
+ this._dragStart=null;
|
|
|
+ const dock=this.querySelector('.dock'); if(dock) dock.classList.remove('drag');
|
|
|
+ const hs=this.dockHeights(), cur=this.dockPx();
|
|
|
+ let best='half',bd=1e9;
|
|
|
+ ['peek','half','full'].forEach(k=>{ const dd=Math.abs(hs[k]-cur); if(dd<bd){ bd=dd; best=k; } });
|
|
|
+ this.snapDock(best,true);
|
|
|
+ buzz(6);
|
|
|
+ }
|
|
|
+ jumpDock(id){
|
|
|
+ this.updateComplete.then(()=>{
|
|
|
+ const body=this.querySelector('.dock .dbody'), el=this.querySelector(id);
|
|
|
+ if(!body||!el) return;
|
|
|
+ const top=el.getBoundingClientRect().top-body.getBoundingClientRect().top+body.scrollTop-8;
|
|
|
+ body.scrollTop=Math.max(0,top);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ openChecks(){ this.snapDock('half',true); this.jumpDock('#chkPanel'); }
|
|
|
+
|
|
|
+
|
|
|
+ /* ---------- 自定义结构件操作 ---------- */
|
|
|
+ custom(){ return (typeof STAGE!=='undefined'&&STAGE.customList)?STAGE.customList():[]; }
|
|
|
+ persistCustom(){ LS.set('ss.custom.'+this.state.project,this.custom()); }
|
|
|
+ selSpec(){
|
|
|
+ const uid=this.state.selUid;
|
|
|
+ return this.custom().find(s=>s.uid===uid)||null;
|
|
|
+ }
|
|
|
+ addPrim(type){
|
|
|
+ this.pushHist();
|
|
|
+ if(typeof STAGE==='undefined'||!STAGE.addCustom) return;
|
|
|
+ const s=STAGE.addCustom(type,{snap:this.state.snap,draft:(type==='rib'||type==='wall')?1:0,owner:this.state.solo||null});
|
|
|
+ this.state.selUid=s.uid;
|
|
|
+ this.state.tab='mdl';
|
|
|
+ if(this.dockPx()<this.dockHeights().half-20) this.snapDock('half',true);
|
|
|
+ this.persistCustom();
|
|
|
+ this.requestUpdate();
|
|
|
+ buzz(10);
|
|
|
+ this.jumpDock('#dNum');
|
|
|
+ }
|
|
|
+ setField(uid,k,v){
|
|
|
+ if(!isFinite(v)) return;
|
|
|
+ STAGE.updateCustom(uid,{[k]:v});
|
|
|
+ this.persistCustom();
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ nudge(uid,k,d){
|
|
|
+ const s=this.custom().find(x=>x.uid===uid); if(!s) return;
|
|
|
+ this.setField(uid,k,Math.round(((s[k]||0)+d)*100)/100);
|
|
|
+ }
|
|
|
+ place(uid,mode){
|
|
|
+ const s=this.custom().find(x=>x.uid===uid); if(!s) return;
|
|
|
+ this.pushHist();
|
|
|
+ const st=this.state, p=st.params, id=st.project;
|
|
|
+ const cav=cavity(id,p);
|
|
|
+ const w=s.w!==undefined?s.w:s.dia, d=s.dd!==undefined?s.dd:s.dia;
|
|
|
+ const patch={};
|
|
|
+ if(mode==='center'){ patch.x=0; patch.z=0; }
|
|
|
+ if(mode==='top'){ patch.y=Math.round((cav.h/2-Math.max(0.5,s.h)/2)*10)/10; }
|
|
|
+ if(mode==='bottom'){ patch.y=Math.round((-cav.h/2+Math.max(0.5,s.h)/2)*10)/10; }
|
|
|
+ if(mode==='wall'){
|
|
|
+ if(cav.kind==='rect'){
|
|
|
+ patch.z=Math.round((p.d/2-d/2-1)*10)/10;
|
|
|
+ patch.x=0;
|
|
|
+ }else{
|
|
|
+ const rr=Math.max(0,cav.r-Math.max(w,d)/2-1);
|
|
|
+ patch.x=Math.round(rr*10)/10; patch.z=0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ STAGE.updateCustom(uid,patch);
|
|
|
+ this.persistCustom();
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ delPrim(uid){
|
|
|
+ this.pushHist();
|
|
|
+ STAGE.removeCustom(uid);
|
|
|
+ this.state.selUid=null;
|
|
|
+ this.persistCustom();
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ dupPrim(uid){
|
|
|
+ const s=this.custom().find(x=>x.uid===uid); if(!s) return;
|
|
|
+ this.pushHist();
|
|
|
+ const c=Object.assign({},s); delete c.uid;
|
|
|
+ c.x=(s.x||0)+Math.min(6,Math.max(2,(s.w||s.dia||4)*0.6));
|
|
|
+ const n=STAGE.addCustom(s.type,c);
|
|
|
+ this.state.selUid=n.uid;
|
|
|
+ this.persistCustom();
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ setProc(k){ this.state.proc=k; this.requestUpdate(); }
|
|
|
+ setSoloTarget(pid){
|
|
|
+ if(pid&&this.state.dockPx&&this.dockPx()<this.dockHeights().half-20) this.snapDock('half',true);
|
|
|
+ buzz(6);
|
|
|
+ this.state.solo=pid||null;
|
|
|
+ STAGE.setSolo(pid||null);
|
|
|
+ this.state.selUid=null;
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ setSnap(v){ this.state.snap=v; this.requestUpdate(); }
|
|
|
+ clearPrims(){ STAGE.clearCustom(); this.state.selUid=null; this.persistCustom(); this.requestUpdate(); }
|
|
|
+ snapshot(){ return {params:Object.assign({},this.state.params),material:this.state.material,custom:this.custom()}; }
|
|
|
+ pushHist(){
|
|
|
+ this._hist=this._hist||[]; this._redo=this._redo||[];
|
|
|
+ this._hist.push(JSON.stringify(this.snapshot()));
|
|
|
+ if(this._hist.length>40) this._hist.shift();
|
|
|
+ this._redo.length=0;
|
|
|
+ }
|
|
|
+ applySnap(js){
|
|
|
+ const o=JSON.parse(js);
|
|
|
+ this.state.params=o.params||this.state.params;
|
|
|
+ this.state.material=o.material||this.state.material;
|
|
|
+ this.state.selUid=null;
|
|
|
+ STAGE.setCustom(this.state.project,o.custom||[]);
|
|
|
+ STAGE.setParams(this.state.params);
|
|
|
+ STAGE.setMaterial(this.state.material);
|
|
|
+ this.persist(); this.persistCustom();
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ undo(){
|
|
|
+ if(!this._hist||!this._hist.length) return;
|
|
|
+ this._redo=this._redo||[];
|
|
|
+ this._redo.push(JSON.stringify(this.snapshot()));
|
|
|
+ this.applySnap(this._hist.pop());
|
|
|
+ }
|
|
|
+ redo(){
|
|
|
+ if(!this._redo||!this._redo.length) return;
|
|
|
+ this._hist=this._hist||[];
|
|
|
+ this._hist.push(JSON.stringify(this.snapshot()));
|
|
|
+ this.applySnap(this._redo.pop());
|
|
|
+ }
|
|
|
+ canUndo(){ return !!(this._hist&&this._hist.length); }
|
|
|
+ canRedo(){ return !!(this._redo&&this._redo.length); }
|
|
|
+ arrayRing(uid,count){
|
|
|
+ const s=this.custom().find(x=>x.uid===uid); if(!s) return;
|
|
|
+ this.pushHist();
|
|
|
+ const cav=cavity(this.state.project,this.state.params);
|
|
|
+ let r=Math.hypot(s.x||0,s.z||0);
|
|
|
+ if(r<1) r=Math.max(4,(cav.kind==='cyl'?cav.r:Math.min(cav.w,cav.d)/2)*0.68);
|
|
|
+ const a0=Math.atan2(s.z||0,s.x||0);
|
|
|
+ for(let i=1;i<count;i++){
|
|
|
+ const a=a0+i*Math.PI*2/count;
|
|
|
+ const patch=Object.assign({},s); delete patch.uid;
|
|
|
+ patch.x=Math.round(r*Math.cos(a)*10)/10;
|
|
|
+ patch.z=Math.round(r*Math.sin(a)*10)/10;
|
|
|
+ patch.rot=((s.rot||0)+i*360/count)%360;
|
|
|
+ STAGE.addCustom(s.type,patch);
|
|
|
+ }
|
|
|
+ this.persistCustom(); this.requestUpdate();
|
|
|
+ }
|
|
|
+ savePartSTL(pid,label){
|
|
|
+ const r=STAGE.exportSTLPart(this.baseName()+'-'+String(label).replace(/[^\u4e00-\u9fa5A-Za-z0-9]/g,''),pid);
|
|
|
+ if(!r) return alert('该零件暂无可导出网格');
|
|
|
+ saveFile(this.baseName()+'-'+String(label).replace(/[^\u4e00-\u9fa5A-Za-z0-9]/g,'')+'.stl',r.text,'model/stl');
|
|
|
+ }
|
|
|
+ dismissTip(){ LS.set('ss.tips.mdl',true); this.requestUpdate(); }
|
|
|
+
|
|
|
+ go(hash){ location.hash=hash; }
|
|
|
+
|
|
|
+ onParam(k,e){
|
|
|
+ const v=parseFloat(e.target.value);
|
|
|
+ const def=getParamDefs(this.state.project).find(x=>x.k===k)||{min:0,max:1};
|
|
|
+ this.state.params[k]=v;
|
|
|
+ e.target.style.setProperty('--p',((v-def.min)/(def.max-def.min)*100)+'%');
|
|
|
+ const num=e.target.closest('.slider').querySelector('.sv');
|
|
|
+ if(num&&document.activeElement!==num) num.value=String(v);
|
|
|
+ this.previewParams();
|
|
|
+ }
|
|
|
+ /* 拖动滑块时 60fps 内只重建一次,手机上不卡 */
|
|
|
+ previewParams(){
|
|
|
+ this._pend=Object.assign({},this.state.params);
|
|
|
+ if(this._raf) return;
|
|
|
+ this._raf=requestAnimationFrame(()=>{
|
|
|
+ this._raf=0;
|
|
|
+ STAGE.setParams(this._pend);
|
|
|
+ this.refreshDerived();
|
|
|
+ });
|
|
|
+ clearTimeout(this._pt);
|
|
|
+ this._pt=setTimeout(()=>this.persist(),260);
|
|
|
+ }
|
|
|
+ onParamNum(k,e){
|
|
|
+ const def=getParamDefs(this.state.project).find(x=>x.k===k)||{min:0,max:1};
|
|
|
+ let v=parseFloat(e.target.value);
|
|
|
+ if(!isFinite(v)){ e.target.value=String(this.state.params[k]); return; }
|
|
|
+ v=Math.min(def.max,Math.max(def.min,v));
|
|
|
+ e.target.value=String(v);
|
|
|
+ this.state.params[k]=v;
|
|
|
+ if(this._raf){ cancelAnimationFrame(this._raf); this._raf=0; }
|
|
|
+ STAGE.setParams(this.state.params);
|
|
|
+ this.refreshDerived(); this.persist(); this.requestUpdate();
|
|
|
+ buzz(4);
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshDerived(){
|
|
|
+ const el=this.querySelector('#derived');
|
|
|
+ if(!el) return;
|
|
|
+ el.innerHTML=derived(this.state.project,this.state.params)
|
|
|
+ .map(d=>`<dt>${d[0]}</dt><dd>${d[1]}</dd>`).join('');
|
|
|
+ }
|
|
|
+
|
|
|
+ setTab(t){
|
|
|
+ this.state.tab=t; this.state.hl=null;
|
|
|
+ if(this.state.solo){ this.state.solo=null; STAGE.setSolo(null); }
|
|
|
+ STAGE.highlight(null);
|
|
|
+ if(t==='asm'&&this.state.explode<0.2){ this.state.explode=0.85; STAGE.setExplode(0.85); }
|
|
|
+ if(t==='mdl'){ STAGE.setCutaway(true); this.applyDock(this.dockPx(),false); }
|
|
|
+ else if(t!=='asm') STAGE.setCutaway(false);
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ onMat(e){ this.state.material=e.detail; this.persist(); this.requestUpdate(); }
|
|
|
+ onDims(e){ this.state.dims=e.detail; this.requestUpdate(); }
|
|
|
+ onExplode(e){ this.state.explode=e.detail; this.requestUpdate(); }
|
|
|
+
|
|
|
+ /* ---------- 渲染:首页 ---------- */
|
|
|
+ renderHub(){
|
|
|
+ return html`
|
|
|
+ <div class="wrap">
|
|
|
+ <div class="hero">
|
|
|
+ <div class="kicker">POCKET SHELL STUDIO</div>
|
|
|
+ <h2>壳体工坊<br>手机里的轻量 3D 外壳工程台</h2>
|
|
|
+ <p>Lit + Babylon.js 纯网页参数化建模:改尺寸、换材质、加筋/柱/槽、隔离单件编辑、看爆炸装配,导 STL/OBJ 与生产需求单。不用装 CAD。</p>
|
|
|
+ <div class="stats">
|
|
|
+ <div class="stat"><b>3</b><span>壳体项目</span></div>
|
|
|
+ <div class="stat"><b>7</b><span>工艺路线</b></span></div>
|
|
|
+ <div class="stat"><b>6</b><span>基础形体</b></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="sec"><h3>我的壳体项目</h3><span>点进去即操作台</span></div>
|
|
|
+ ${Object.keys(PROJECTS).map(id=>this.renderCard(id))}
|
|
|
+
|
|
|
+ <div class="sec"><h3>能力与资料</h3><span>项目外挂</span></div>
|
|
|
+ <div class="mini">
|
|
|
+ <div class="minicard" @click=${()=>this.go('#/kb')}>
|
|
|
+ <b>工艺知识库</b><span>工艺/MOQ/文件格式/DFM/报价口径,全部可回看</span>
|
|
|
+ <span class="n">6 篇 · 含对比表 →</span>
|
|
|
+ </div>
|
|
|
+ <div class="minicard" @click=${()=>this.go('#/kb')}>
|
|
|
+ <b>电子件库</b><span>微雪 1.85B、ESP32-S3、麦/功放/电芯选型与尺寸</span>
|
|
|
+ <span class="n">7 个模组 · 尺寸对照 →</span>
|
|
|
+ </div>
|
|
|
+ <div class="minicard" @click=${()=>this.go('#/p/recorder')}>
|
|
|
+ <b>爆炸装配</b><span>单操作台切换外观 / 结构 / 爆炸 / 导出</span>
|
|
|
+ <span class="n">爆炸 + 单件隔离 →</span>
|
|
|
+ </div>
|
|
|
+ <div class="minicard" @click=${()=>this.go('#/kb')}>
|
|
|
+ <b>参考文章</b><span>公众号原文归档入口(可粘贴补录全文)</span>
|
|
|
+ <span class="n">2 条参考 →</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="foot">参数与报价为前期调研口径,非供应商正式报价。<br>所有 3D 均在浏览器实时生成,未调用外部模型文件。</div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderCard(id){
|
|
|
+ const p=PROJECTS[id];
|
|
|
+ const cls=id==='silicone'?'sq':(id==='recorder'?'puck':'disc');
|
|
|
+ const dims=id==='silicone'?'41 / 45 mm · 硅胶'
|
|
|
+ :id==='recorder'?'Ø32 × 11.5 · ABS'
|
|
|
+ :'Ø61.6 × 14.6 · 铝';
|
|
|
+ return html`
|
|
|
+ <div class="pcard" @click=${()=>this.go('#/p/'+id)}>
|
|
|
+ <div class="row">
|
|
|
+ <div class="thumb">
|
|
|
+ <div class="shape ${cls}">${cls==='disc'?html`<i></i>`:''}</div>
|
|
|
+ <span class="lbl">${id==='silicone'?'SILICONE':(id==='recorder'?'PUCK':'ROUND')}</span>
|
|
|
+ </div>
|
|
|
+ <div class="pinfo">
|
|
|
+ <h4>${p.name}</h4>
|
|
|
+ <div class="dims">${dims}</div>
|
|
|
+ <div class="tagrow">
|
|
|
+ ${p.tags.map(t=>html`<span class="tag ${t.indexOf('MOQ')>=0?'b':''}">${t}</span>`)}
|
|
|
+ </div>
|
|
|
+ <div class="enter">进入操作台 <span class="arw">→</span></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------- 渲染:项目页 ---------- */
|
|
|
+ renderProject(){
|
|
|
+ const st=this.state, proj=PROJECTS[st.project];
|
|
|
+ const tabs=[['look','3D 外观'],['asm','结构与爆炸'],['mdl','建模'],['elec','电子件'],['proc','工艺报价'],['out','导出']];
|
|
|
+ return html`
|
|
|
+ <div class="topbar"><div class="inner">
|
|
|
+ <button class="iconbtn" @click=${()=>this.go('#/')}>←</button>
|
|
|
+ <div class="tt"><h1>${proj.name}</h1><p>${proj.ref}</p></div>
|
|
|
+ <span class="pill">${f1(st.params[proj.params[0].k],1)} mm</span>
|
|
|
+ </div></div>
|
|
|
+
|
|
|
+ <div class="wrap" style="padding-bottom:120px">
|
|
|
+ <div class="tabs">
|
|
|
+ ${tabs.map(([k,n])=>html`<div class="tab ${st.tab===k?'on':''}" @click=${()=>this.setTab(k)}>${n}</div>`)}
|
|
|
+ </div>
|
|
|
+ <gl-stage .project=${st.project} .params=${st.params} .material=${st.material} .mini=${st.tab==='mdl'}
|
|
|
+ .explode=${st.explode} .dims=${st.dims} .hl=${st.hl}
|
|
|
+ @mat-change=${e=>this.onMat(e)} @dims-change=${e=>this.onDims(e)} @explode-change=${e=>this.onExplode(e)}>
|
|
|
+ </gl-stage>
|
|
|
+
|
|
|
+ ${st.tab==='look'?this.renderLook():''}
|
|
|
+ ${st.tab==='asm'?this.renderAsm():''}
|
|
|
+ ${st.tab==='mdl'?this.renderModel():''}
|
|
|
+ ${st.tab==='elec'?this.renderElec():''}
|
|
|
+ ${st.tab==='proc'?this.renderProc():''}
|
|
|
+ ${st.tab==='out'?this.renderOut():''}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ ${st.tab==='mdl'?this.renderDock():html`
|
|
|
+ <div class="bottom">
|
|
|
+ <button class="btn" @click=${()=>this.savePNG()}>截图</button>
|
|
|
+ <button class="btn" @click=${()=>this.saveSTL()}>STL</button>
|
|
|
+ <button class="btn pri" @click=${()=>this.saveSpec()}>需求单</button>
|
|
|
+ </div>`}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ toggleDock(){ this.state.dockFold=!this.state.dockFold; this.requestUpdate(); }
|
|
|
+
|
|
|
+ renderDock(){
|
|
|
+ const st=this.state, proj=PROJECTS[st.project], list=this.custom();
|
|
|
+ const sel=list.find(s=>s.uid===st.selUid)||null;
|
|
|
+ const rk=ruleKey(st.proc), rule=RULES[rk];
|
|
|
+ const checks=modelChecks(st.project,st.params,list,rk);
|
|
|
+ const bad=checks.filter(c=>!c.ok).length;
|
|
|
+ const isCyl=!!sel&&CYL_TYPES.indexOf(sel.type)>=0;
|
|
|
+ const isPad=!!sel&&sel.type==='pad4';
|
|
|
+ const isRect=!!sel&&RECT_TYPES.indexOf(sel.type)>=0;
|
|
|
+ const isHollow=!!sel&&HOLLOW_TYPES.indexOf(sel.type)>=0;
|
|
|
+ const firstK=proj.params[0].k;
|
|
|
+ const geo=proj.params.filter(p=>p.k==='t'||p.group==='CNC 工艺'||(!sel&&p.k===firstK));
|
|
|
+ const geoTitle=(st.project==='round')?'工艺弧面':'工艺与主体';
|
|
|
+ const procName=({'cnc-alu':'CNC 铝','cnc-abs':'CNC ABS','die-cast':'压铸','abs-mold':'注塑','sil-mold':'硅胶','vacuum':'复模'}[st.proc])||rule.name;
|
|
|
+
|
|
|
+ if(st.dockFold) return html`
|
|
|
+ <div class="dock fold">
|
|
|
+ <div class="dhead" @click=${()=>this.toggleDock()}>
|
|
|
+ <b>${sel?STAGE.PRIMS[sel.type].n+' #'+sel.uid:(st.solo?'隔离 · '+this.soloName(st.solo):'编辑坞')}</b>
|
|
|
+ <span class="em">${bad?bad+' 项待改':'校验通过'}</span>
|
|
|
+ <div class="tools"><button class="x" @click=${e=>{e.stopPropagation();this.toggleDock();}}>展开编辑</button></div>
|
|
|
+ </div>
|
|
|
+ </div>`;
|
|
|
+
|
|
|
+ return html`
|
|
|
+ <div class="dock">
|
|
|
+ <div class="grab" @pointerdown=${e=>this.onGrabDown(e)} @pointermove=${e=>this.onGrabMove(e)}
|
|
|
+ @pointerup=${e=>this.onGrabUp(e)} @pointercancel=${e=>this.onGrabUp(e)}><i></i></div>
|
|
|
+ <div class="dhead">
|
|
|
+ <div><b>${sel?STAGE.PRIMS[sel.type].n+' #'+sel.uid:(st.solo?'单件隔离 · '+this.soloName(st.solo):'编辑坞')}</b>
|
|
|
+ <span class="em">${procName}${bad?' · '+bad+' 项待改':''}</span></div>
|
|
|
+ <div class="tools">
|
|
|
+ <button class="hbt" ?disabled=${!this.canUndo()} @click=${()=>{ this.undo(); buzz(6); }}>↶</button>
|
|
|
+ <button class="hbt" ?disabled=${!this.canRedo()} @click=${()=>{ this.redo(); buzz(6); }}>↷</button>
|
|
|
+ <button class="x" @click=${()=>this.snapDock('peek',true)}>收起</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="dnav">
|
|
|
+ <button @click=${()=>{ this.snapDock('half',true); this.jumpDock('#dTargets'); }}>选件</button>
|
|
|
+ <button @click=${()=>{ this.snapDock('half',true); this.jumpDock('#dNum'); }}>数值</button>
|
|
|
+ <button @click=${()=>{ this.snapDock('half',true); this.jumpDock('#dLib'); }}>形体库</button>
|
|
|
+ <button @click=${()=>this.openChecks()}>校验${bad?' · '+bad:''}</button>
|
|
|
+ <button @click=${()=>{ this.snapDock('full',true); buzz(6); }}>全屏</button>
|
|
|
+ <button @click=${()=>this.setTab('out')}>导出</button>
|
|
|
+ </div>
|
|
|
+ <div class="dbody">
|
|
|
+ <div class="chips" id="dTargets">
|
|
|
+ <button class="chip ${!st.solo?'on':''}" @click=${()=>this.setSoloTarget(null)}>整体</button>
|
|
|
+ ${proj.parts.filter(pt=>['pcb','cell','side','mic'].indexOf(pt.id)<0).map(pt=>html`
|
|
|
+ <button class="chip ${st.solo===pt.id?'on':''}" @click=${()=>this.setSoloTarget(pt.id)}>${pt.n.split('(')[0]}</button>`)}
|
|
|
+ ${list.map(s=>html`<button class="chip ${st.solo===('c'+s.uid)?'on':''}" @click=${()=>this.setSoloTarget('c'+s.uid)}>${STAGE.PRIMS[s.type].n}#${s.uid}</button>`)}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ ${sel?html`
|
|
|
+ <div class="dsec" id="dNum">数值 <em>吸附 ${st.snap} mm · 点数字可直接输入</em></div>
|
|
|
+ <div class="nrows">
|
|
|
+ ${this.numRow(sel,'x','X 位置')}
|
|
|
+ ${this.numRow(sel,'z','Z 位置')}
|
|
|
+ ${this.numRow(sel,'y','Y 高度')}
|
|
|
+ ${isCyl||isPad?this.numRow(sel,'dia','柱/孔外径',0.2):''}
|
|
|
+ ${isHollow?this.numRow(sel,'dd','预钻孔 Ø',0.1):''}
|
|
|
+ ${isPad?html`${this.numRow(sel,'w','X 向间距')}${this.numRow(sel,'dd','Z 向间距')}${this.numRow(sel,'hd','内孔 Ø',0.1)}`:''}
|
|
|
+ ${isRect?html`${this.numRow(sel,'w','长度')}${this.numRow(sel,'dd','厚度')}`:''}
|
|
|
+ ${this.numRow(sel,'h','高度',0.2)}
|
|
|
+ ${sel.type==='rib'||sel.type==='wall'?this.numRow(sel,'draft','拔模角(°)',0.5):''}
|
|
|
+ ${this.numRow(sel,'rot','绕 Y 转 °',5)}
|
|
|
+ </div>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn" @click=${()=>this.place(sel.uid,'center')}>居中</button>
|
|
|
+ <button class="btn" @click=${()=>this.place(sel.uid,'wall')}>贴内壁</button>
|
|
|
+ <button class="btn" @click=${()=>this.place(sel.uid,'top')}>贴顶</button>
|
|
|
+ <button class="btn" @click=${()=>this.place(sel.uid,'bottom')}>贴底</button>
|
|
|
+ </div>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn" @click=${()=>this.arrayRing(sel.uid,4)}>阵列 ×4</button>
|
|
|
+ <button class="btn" @click=${()=>this.arrayRing(sel.uid,6)}>×6</button>
|
|
|
+ <button class="btn" @click=${()=>this.arrayRing(sel.uid,8)}>×8</button>
|
|
|
+ <button class="btn" @click=${()=>this.dupPrim(sel.uid)}>复制</button>
|
|
|
+ <button class="btn" @click=${()=>this.delPrim(sel.uid)}>删除</button>
|
|
|
+ </div>
|
|
|
+ <div class="hint">距内壁 ${f1(clearanceTo(st.project,st.params,sel),1)} mm · ${STAGE.PRIMS[sel.type].n}${HOLLOW_TYPES.indexOf(sel.type)>=0?' 预钻孔已按标准给':''}</div>
|
|
|
+ `:html`
|
|
|
+ <div class="dsec">开始建模 <em>点下面任一个,直接加到壳里</em></div>
|
|
|
+ <div class="hint" style="margin:0 0 4px">建议先加一根「加强筋」看内壁,再加「螺丝柱 M2.5」定位主板。</div>`}
|
|
|
+
|
|
|
+ <div class="dsec" id="dLib">形体库 <em>标准件按规格预置</em></div>
|
|
|
+ <div class="prow">
|
|
|
+ ${Object.keys(STAGE.PRIMS).map(k=>html`
|
|
|
+ <button class="pco ${sel&&sel.type===k?'hot':''}" @click=${()=>this.addPrim(k)}>
|
|
|
+ <b>${STAGE.PRIMS[k].n}</b><span>${primSpecText(k)}</span>
|
|
|
+ </button>`)}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <details class="acc" id="dGeo" style="margin-top:8px">
|
|
|
+ <summary><span class="ix">G</span>${geoTitle}<span class="chev">▾</span></summary>
|
|
|
+ <div class="body">
|
|
|
+ ${geo.map(g=>html`
|
|
|
+ <div class="slider">
|
|
|
+ <div class="lab"><span>${g.n}</span>
|
|
|
+ <input class="sv" type="number" inputmode="decimal" min=${g.min} max=${g.max} step=${g.step}
|
|
|
+ .value=${String(st.params[g.k])} @change=${e=>this.onParamNum(g.k,e)}></div>
|
|
|
+ <input type="range" min=${g.min} max=${g.max} step=${g.step} .value=${String(st.params[g.k])}
|
|
|
+ style="--p:${(st.params[g.k]-g.min)/(g.max-g.min)*100}%"
|
|
|
+ @input=${e=>this.onParam(g.k,e)}>
|
|
|
+ </div>`)}
|
|
|
+ <div class="btnrow" style="align-items:center">
|
|
|
+ <span class="hint" style="margin:0">吸附</span>
|
|
|
+ ${[0.5,1,5].map(v=>html`<button class="chip ${st.snap===v?'on':''}" @click=${()=>this.setSnap(v)}>${v} mm</button>`)}
|
|
|
+ </div>
|
|
|
+ <div class="hint">${st.project==='round'?'三个弧面参数直接写进需求单,CNC 按它编程;数值变化时网格自动夹到不干涉的安全范围。':'壁厚与主尺寸改完,校验与报价同步重算。'}</div>
|
|
|
+ </div>
|
|
|
+ </details>
|
|
|
+
|
|
|
+ <details class="acc" id="dProc">
|
|
|
+ <summary><span class="ix">C</span>工艺约束 · ${rule.name}<em>${bad?bad+' 项需改':'通过'}</em><span class="chev">▾</span></summary>
|
|
|
+ <div class="body">
|
|
|
+ <div class="chips" style="flex-wrap:wrap">
|
|
|
+ ${proj.processes.map(pr=>html`<button class="chip ${st.proc===pr.key?'on':''}"
|
|
|
+ @click=${()=>this.setProc(pr.key)}>${({'cnc-alu':'CNC 铝','cnc-abs':'CNC ABS','die-cast':'压铸','abs-mold':'注塑','sil-mold':'硅胶','vacuum':'复模'}[pr.key])||pr.n}</button>`)}
|
|
|
+ </div>
|
|
|
+ <table class="tbl"><tbody>
|
|
|
+ ${rule.items.map(r=>html`<tr><td style="white-space:nowrap">${r[0]}</td><td style="text-align:left">${r[1]}</td></tr>`)}
|
|
|
+ </tbody></table>
|
|
|
+ <div class="hint">${rk==='cnc'?'CNC:结构件必须给坐标 + 刀具半径,内角 R 不得小于刀径一半。':'注塑/硅胶:壁厚、拔模、筋厚是硬约束。'}</div>
|
|
|
+ </div>
|
|
|
+ </details>
|
|
|
+
|
|
|
+ <details class="acc">
|
|
|
+ <summary><span class="ix">P</span>主体参数(全部外形)<span class="chev">▾</span></summary>
|
|
|
+ <div class="body">
|
|
|
+ ${proj.params.map(p=>html`
|
|
|
+ <div class="slider">
|
|
|
+ <div class="lab"><span>${p.n} <em style="font-style:normal;color:#9aa7ba">${p.group||''}</em></span>
|
|
|
+ <input class="sv" type="number" inputmode="decimal" min=${p.min} max=${p.max} step=${p.step}
|
|
|
+ .value=${String(st.params[p.k])} @change=${e=>this.onParamNum(p.k,e)}></div>
|
|
|
+ <input type="range" min=${p.min} max=${p.max} step=${p.step} .value=${String(st.params[p.k])}
|
|
|
+ style="--p:${(st.params[p.k]-p.min)/(p.max-p.min)*100}%"
|
|
|
+ @input=${e=>this.onParam(p.k,e)}>
|
|
|
+ </div>`)}
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn" @click=${()=>this.resetParams()}>恢复默认外形</button>
|
|
|
+ <button class="btn" @click=${()=>{ this.pushHist(); STAGE.clearCustom(); this.state.selUid=null; this.persistCustom(); this.requestUpdate(); }}>清空结构件</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </details>
|
|
|
+
|
|
|
+ <div class="panel" id="chkPanel" style="margin-top:10px">
|
|
|
+ <h5>模型校验 <em>${bad?bad+' 项需改':'全部通过'}</em></h5>
|
|
|
+ ${checks.map(c=>html`<div class="chk ${c.ok?'ok':'bad'}"><i>${c.ok?'✓':'!'}</i><span>${c.t}</span></div>`)}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel" id="dList">
|
|
|
+ <h5>结构件清单 <em>${list.length} 件</em></h5>
|
|
|
+ ${list.length?list.map(s=>{
|
|
|
+ const dim=(CYL_TYPES.indexOf(s.type)>=0)
|
|
|
+ ?('Ø'+f1(s.dia,1)+' × H'+f1(s.h,1))
|
|
|
+ :(f1(s.w,1)+'×'+f1(s.dd,1)+'×H'+f1(s.h,1));
|
|
|
+ return html`<div class="pr ${st.selUid===s.uid?'on':''}" @click=${()=>{ this.state.selUid=s.uid; STAGE.highlight('c'+s.uid); this.requestUpdate(); this.jumpDock('#dNum'); }}>
|
|
|
+ <div><b>${STAGE.PRIMS[s.type].n}</b><span>${dim} · x ${f1(s.x,1)} / y ${f1(s.y,1)} / z ${f1(s.z,1)}</span></div>
|
|
|
+ <button class="del" @click=${e=>{ e.stopPropagation(); this.delPrim(s.uid); }}>删</button>
|
|
|
+ </div>`;}):html`<div class="hint">还没有结构件。</div>`}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="hint" style="margin-top:10px">单指旋转 · 双指缩放/平移 · 双击零件聚焦;把手上下拖可改面板高度(≤20% 看整图)。</div>
|
|
|
+ </div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderLook(){
|
|
|
+ const st=this.state, proj=PROJECTS[st.project];
|
|
|
+ return html`
|
|
|
+ <div class="panel">
|
|
|
+ <h5>参数化外形 <em>拖动即重算曲面</em></h5>
|
|
|
+ ${proj.params.map(p=>html`
|
|
|
+ <div class="slider">
|
|
|
+ <div class="lab"><span>${p.n} <em style="font-style:normal;color:#9aa7ba">${p.group||''}</em></span><input class="sv" type="number" inputmode="decimal" min=${p.min} max=${p.max} step=${p.step}
|
|
|
+ .value=${String(st.params[p.k])} @change=${e=>this.onParamNum(p.k,e)}></div>
|
|
|
+ <input type="range" min=${p.min} max=${p.max} step=${p.step} .value=${String(st.params[p.k])}
|
|
|
+ style="--p:${(st.params[p.k]-p.min)/(p.max-p.min)*100}%"
|
|
|
+ @input=${e=>this.onParam(p.k,e)}>
|
|
|
+ </div>`)}
|
|
|
+ <div class="hint">数值为外形定义尺寸;修改后 3D 网格、标注、爆炸图、导出文件全部同步。</div>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn" @click=${()=>this.resetParams()}>恢复默认</button>
|
|
|
+ <button class="btn" @click=${()=>STAGE.setView('iso')}>回到 45°</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>派生尺寸 <em>实时</em></h5>
|
|
|
+ <dl class="kv" id="derived">
|
|
|
+ ${derived(st.project,st.params).map(d=>html`<dt>${d[0]}</dt><dd>${d[1]}</dd>`)}
|
|
|
+ </dl>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>材质与表面 <em>点选即换 PBR 材质</em></h5>
|
|
|
+ <div class="btnrow">
|
|
|
+ ${proj.materials.map(k=>html`<button class="btn ${st.material===k?'dark':''}"
|
|
|
+ @click=${()=>{ this.state.material=k; STAGE.setMaterial(k); this.persist(); this.requestUpdate(); }}>${MATERIALS[k].name}</button>`)}
|
|
|
+ </div>
|
|
|
+ <div class="hint">${MATERIALS[st.material]?(MATERIALS[st.material].note||'渲染为近似 PBR,实际以样板为准'):''}</div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderAsm(){
|
|
|
+ const st=this.state, proj=PROJECTS[st.project];
|
|
|
+ return html`
|
|
|
+ <div class="panel">
|
|
|
+ <h5>爆炸图 <em>拖动滑块分离零件</em></h5>
|
|
|
+ <div class="slider">
|
|
|
+ <div class="lab"><span>拆解程度</span><b>${Math.round(st.explode*100)}%</b></div>
|
|
|
+ <input type="range" min="0" max="1" step="0.05" .value=${String(st.explode)}
|
|
|
+ style="--p:${st.explode*100}%"
|
|
|
+ @input=${e=>{ this.state.explode=parseFloat(e.target.value); STAGE.setExplode(this.state.explode);
|
|
|
+ e.target.closest('.slider').querySelector('b').textContent=Math.round(this.state.explode*100)+'%';
|
|
|
+ this.querySelectorAll('.pitem').forEach(x=>x.classList.toggle('on',false)); }}>
|
|
|
+ </div>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn ${st.explode>0.3?'pri':''}" @click=${()=>{ this.state.explode=0.9; STAGE.setExplode(0.9); this.requestUpdate(); }}>一键爆炸</button>
|
|
|
+ <button class="btn" @click=${()=>{ this.state.explode=0; STAGE.setExplode(0); this.requestUpdate(); }}>合模复位</button>
|
|
|
+ <button class="btn" @click=${()=>{ const on=!STAGE.isCutaway(); STAGE.setCutaway(on); this.requestUpdate(); }}>${STAGE.isCutaway()?'恢复实心':'透视外壳'}</button>
|
|
|
+ </div>
|
|
|
+ <div class="hint">壳体是闭合件,内部结构默认被外壳挡住;爆炸超过 20% 时外壳自动半透明,才能看到电芯/主板/铜柱的相对位置。</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>零件清单 <em>点选高亮</em></h5>
|
|
|
+ <div class="parts">
|
|
|
+ ${proj.parts.map(pt=>html`
|
|
|
+ <div class="pr pitem ${st.hl===pt.id?'on':''}"
|
|
|
+ @click=${()=>{ this.state.hl=(st.hl===pt.id?null:pt.id); STAGE.highlight(this.state.hl); this.requestUpdate(); }}
|
|
|
+ style=${st.hl===pt.id?'background:#eef4fe':''}>
|
|
|
+ <span>${pt.n}</span><em>${pt.q} 件 · ${pt.proc}</em>
|
|
|
+ </div>`)}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>装配顺序 <em>${proj.steps.length} 步</em></h5>
|
|
|
+ ${proj.steps.map((s,i)=>html`
|
|
|
+ <div class="steprow">
|
|
|
+ <div class="stepno">${i+1}</div>
|
|
|
+ <div><b>${s.n}</b><span>${s.d}</span></div>
|
|
|
+ </div>`)}
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ soloName(pid){
|
|
|
+ const proj=PROJECTS[this.state.project];
|
|
|
+ if(String(pid)[0]==='c'){ const s=this.custom().find(x=>'c'+x.uid===pid); return s?(STAGE.PRIMS[s.type].n+' #'+s.uid):pid; }
|
|
|
+ const pt=proj.parts.find(x=>x.id===pid);
|
|
|
+ return pt?pt.n:pid;
|
|
|
+ }
|
|
|
+
|
|
|
+ procLabel(k){
|
|
|
+ const r=ruleKey(k);
|
|
|
+ return r==='injection'?'注塑':(r==='silicone'?'硅胶':(r==='cnc'?'CNC':(r==='vac'?'复模':'压铸')));
|
|
|
+ }
|
|
|
+
|
|
|
+ numRow(s,key,label,step){
|
|
|
+ const st=(key==='h'||key==='dia')?0.2:(this.state.snap||0.5);
|
|
|
+ return html`<div class="nrow">
|
|
|
+ <span class="nl">${label}</span>
|
|
|
+ <button class="nb" @click=${()=>this.nudge(s.uid,key,-step)}>−</button>
|
|
|
+ <input class="ni" type="number" step=${String(step)} .value=${String(s[key]!==undefined?s[key]:0)}
|
|
|
+ @change=${e=>this.setField(s.uid,key,parseFloat(e.target.value))}>
|
|
|
+ <button class="nb" @click=${()=>this.nudge(s.uid,key,step)}>+</button>
|
|
|
+ <em>mm</em>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderModel(){ return html`<div style="height:2px"></div>`; }
|
|
|
+
|
|
|
+ renderElec(){
|
|
|
+ const st=this.state;
|
|
|
+ const list=BOARDS.filter(b=>b.fit===st.project||b.id==='esp32s3'&&st.project==='recorder');
|
|
|
+ const rows=fitRows(st.project,st.params);
|
|
|
+ return html`
|
|
|
+ <div class="panel">
|
|
|
+ <h5>尺寸对照 <em>俯视 · mm</em></h5>
|
|
|
+ <div .innerHTML=${fitSVG(st.project,st.params)}></div>
|
|
|
+ <table class="tbl" style="margin-top:2px"><tbody>
|
|
|
+ ${(st.project==='round'?[
|
|
|
+ ['外形','Ø'+f1(st.params.D,2)+' mm'],['黑边开口','Ø'+f1(st.params.bd,1)+' mm'],
|
|
|
+ ['屏可视','Ø'+f1(st.params.sd,2)+' mm'],['主板','Ø44 mm'],['铜柱','4 × M2']]:[]).map(r=>html`<tr><td>${r[0]}</td><td class="num">${r[1]}</td></tr>`)}
|
|
|
+ ${(st.project==='recorder'?[
|
|
|
+ ['外形','Ø'+f1(st.params.D,1)+' mm'],['内腔','Ø'+f1(st.params.D-2*st.params.t,1)+' mm'],
|
|
|
+ ['主控板建议','Ø'+f1(Math.min(st.params.D-2*st.params.t-4,26),0)+' mm'],['电芯','402030 · 4×20×30'],
|
|
|
+ ['麦孔','4 × Ø1.0']]:[]).map(r=>html`<tr><td>${r[0]}</td><td class="num">${r[1]}</td></tr>`)}
|
|
|
+ ${(st.project==='silicone'?[
|
|
|
+ ['外形',''+f1(st.params.w+2*st.params.t,1)+' × '+f1(st.params.d+2*st.params.t,1)+' mm'],
|
|
|
+ ['内腔',''+f1(st.params.w,1)+' × '+f1(st.params.d,1)+' mm'],['屏视窗',''+f1(Math.max(6,st.params.w-2.8),1)+' × '+f1(Math.max(6,st.params.d-2.8),1)+' mm'],
|
|
|
+ ['表体','41.3 × 41.3(实机复测)']]:[]).map(r=>html`<tr><td>${r[0]}</td><td class="num">${r[1]}</td></tr>`)}
|
|
|
+ </tbody></table>
|
|
|
+ <div class="hint" style="display:flex;gap:10px;flex-wrap:wrap">
|
|
|
+ <span><i style="display:inline-block;width:12px;height:2px;background:#1f6feb;vertical-align:middle"></i> 外形</span>
|
|
|
+ <span><i style="display:inline-block;width:12px;height:2px;background:#94a3b8;vertical-align:middle"></i> 内腔</span>
|
|
|
+ <span><i style="display:inline-block;width:12px;height:2px;background:#0f9d58;vertical-align:middle"></i> 屏幕/主板</span>
|
|
|
+ <span><i style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#b08d57;vertical-align:middle"></i> 铜柱</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="panel">
|
|
|
+ <h5>空间校验 <em>壳体 vs 电子件</em></h5>
|
|
|
+ <div class="scrollx"><table class="tbl">
|
|
|
+ <thead><tr><th>校验项</th><th>结论</th></tr></thead>
|
|
|
+ <tbody>${rows.map(r=>html`<tr><td>${r[0]}</td><td>${r[1]}</td></tr>`)}</tbody>
|
|
|
+ </table></div>
|
|
|
+ <div class="hint">校验基于当前参数快照与公开规格;打样前请以官方图纸与实机复测。</div>
|
|
|
+ </div>
|
|
|
+ <div class="panel">
|
|
|
+ <h5>可选电子模组 <em>成熟开发板优先</em></h5>
|
|
|
+ ${list.map(b=>html`
|
|
|
+ <div class="board">
|
|
|
+ <div class="bv"><i></i></div>
|
|
|
+ <div class="bi">
|
|
|
+ <b>${b.name}</b>
|
|
|
+ <span>${b.od} · ${b.screen}</span>
|
|
|
+ <span>${b.iface}</span>
|
|
|
+ <span class="bd">${b.tag}</span>
|
|
|
+ <dl class="kv">
|
|
|
+ <dt>主控</dt><dd>${b.soc}</dd>
|
|
|
+ <dt>板载</dt><dd style="text-align:left">${b.extra}</dd>
|
|
|
+ <dt>参考价</dt><dd>${b.price}</dd>
|
|
|
+ </dl>
|
|
|
+ <div class="hint">${b.note}</div>
|
|
|
+ </div>
|
|
|
+ </div>`)}
|
|
|
+ <div class="hint">来源:${list.map(b=>b.source).join(' / ')}</div>
|
|
|
+ </div>
|
|
|
+ <div class="panel">
|
|
|
+ <h5>选型原则 <em>不打 PCB</em></h5>
|
|
|
+ ${KB.find(k=>k.id==='elec').body.map(item=>{
|
|
|
+ if(item[0]==='ul') return html`<ul style="font-size:12px;padding-left:18px;color:#31425a;line-height:1.7">${item[1].map(x=>html`<li>${x}</li>`)}</ul>`;
|
|
|
+ if(item[0]==='p') return html`<div class="hint">${item[1]}</div>`;
|
|
|
+ if(item[0]==='note') return html`<div class="note">${item[1]}</div>`;
|
|
|
+ return '';
|
|
|
+ })}
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderProc(){
|
|
|
+ const st=this.state, proj=PROJECTS[st.project];
|
|
|
+ const rows=processTable(st.project,st.qty);
|
|
|
+ return html`
|
|
|
+ <div class="panel">
|
|
|
+ <h5>批量与单套成本 <em>含模具摊销</em></h5>
|
|
|
+ <div class="slider">
|
|
|
+ <div class="lab"><span>下单数量</span><b>${st.qty} 套</b></div>
|
|
|
+ <input type="range" min="50" max="5000" step="50" .value=${String(st.qty)}
|
|
|
+ style="--p:${(st.qty-50)/4950*100}%"
|
|
|
+ @input=${e=>{ this.state.qty=parseInt(e.target.value,10);
|
|
|
+ e.target.closest('.slider').querySelector('b').textContent=this.state.qty+' 套';
|
|
|
+ const t=this.querySelector('#proctable'); if(t) t.innerHTML=this.procRowsHTML(); }}>
|
|
|
+ </div>
|
|
|
+ <div class="scrollx"><table class="tbl">
|
|
|
+ <thead><tr><th>工艺</th><th class="num">单价</th><th class="num">模具/一次性</th><th class="num">单套综合</th><th>交期</th></tr></thead>
|
|
|
+ <tbody id="proctable" .innerHTML=${this.procRowsHTML()}></tbody>
|
|
|
+ </table></div>
|
|
|
+ <div class="hint">综合 =(一次性费用 + 单价×数量)/ 数量。低于 MOQ 时按最小批量摊,实际会被拒单或加价。</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>工艺提示 <em>来自前期询价</em></h5>
|
|
|
+ ${proj.notes.map(n=>html`<div class="note">${n}</div>`)}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>公差表</h5>
|
|
|
+ <table class="tbl"><tbody>
|
|
|
+ ${proj.tolerance.map(t=>html`<tr><td>${t[0]}</td><td class="num">${t[1]}</td></tr>`)}
|
|
|
+ </tbody></table>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ procRowsHTML(){
|
|
|
+ const rows=processTable(this.state.project,this.state.qty);
|
|
|
+ return rows.map(r=>`<tr>
|
|
|
+ <td>${r.n}${r.below?'<br><span style="color:#d97706;font-size:10px">低于MOQ</span>':''}</td>
|
|
|
+ <td class="num">¥${f1(r.unitUsed,1)}</td>
|
|
|
+ <td class="num">¥${r.mold}</td>
|
|
|
+ <td class="num"><b>¥${f1(r.per,1)}</b></td>
|
|
|
+ <td>${r.lead}</td></tr>`).join('');
|
|
|
+ }
|
|
|
+
|
|
|
+ renderOut(){
|
|
|
+ const st=this.state, proj=PROJECTS[st.project];
|
|
|
+ return html`
|
|
|
+ <div class="panel">
|
|
|
+ <h5>导出 <em>直接存到手机</em></h5>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn dark" @click=${()=>this.saveSTL()}>STL 网格</button>
|
|
|
+ <button class="btn" @click=${()=>this.saveOBJ()}>OBJ 网格</button>
|
|
|
+ <button class="btn" @click=${()=>this.savePNG()}>PNG 截图</button>
|
|
|
+ </div>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn pri" @click=${()=>this.saveSpec()}>生产需求单 .md</button>
|
|
|
+ <button class="btn" @click=${()=>this.saveBOM()}>BOM .csv</button>
|
|
|
+ <button class="btn" @click=${()=>this.saveJSON()}>参数 .json</button>
|
|
|
+ </div>
|
|
|
+ <div class="hint">STL/OBJ 由当前 3D 网格直接生成(单位 mm,已按世界坐标烘焙)。手机浏览器会存到「下载」目录。</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>分件导出 <em>每件一个 STL,手机可逐个下载</em></h5>
|
|
|
+ <div class="chips">
|
|
|
+ ${proj.parts.filter(pt=>(EXPORTABLE[st.project]||[]).indexOf(pt.id)>=0).map(pt=>html`<button class="chip" @click=${()=>this.savePartSTL(pt.id,pt.n.split('(')[0])}>${pt.n.split('(')[0]} ↓</button>`)}
|
|
|
+ ${this.custom().map(s=>html`<button class="chip" @click=${()=>this.savePartSTL('c'+s.uid,STAGE.PRIMS[s.type].n+s.uid)}>${STAGE.PRIMS[s.type].n}#${s.uid} ↓</button>`)}
|
|
|
+ </div>
|
|
|
+ <div class="hint">整件 STL 供预览;分件 STL 给 CNC/开模按件编程。含玻璃、PCB、电芯等非加工件会自动排除。</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>给工厂的文件清单 <em>${proj.name}</em></h5>
|
|
|
+ <table class="tbl"><tbody>
|
|
|
+ ${proj.files.map(f=>html`<tr><td>${f}</td><td class="num">必备</td></tr>`)}
|
|
|
+ <tr><td>本需求单 + STL/OBJ 预览</td><td class="num">报价用</td></tr>
|
|
|
+ </tbody></table>
|
|
|
+ <div class="note">浏览器端无法生成 STEP 实体。开模/CNC 编程仍需 STEP(或由工厂按 2D 图纸建模,费用约 ¥500~1,500)。本工具输出的是「可报价、可评审」的完整包,不是可直接开模的最终文件。</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="panel">
|
|
|
+ <h5>当前快照</h5>
|
|
|
+ <dl class="kv">
|
|
|
+ ${derived(st.project,st.params).map(d=>html`<dt>${d[0]}</dt><dd>${d[1]}</dd>`)}
|
|
|
+ <dt>材质</dt><dd>${MATERIALS[st.material]?MATERIALS[st.material].name:''}</dd>
|
|
|
+ <dt>报价数量</dt><dd>${st.qty} 套</dd>
|
|
|
+ </dl>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------- 渲染:知识库 ---------- */
|
|
|
+ renderKB(){
|
|
|
+ const notes=LS.get('ss.refs.note',{});
|
|
|
+ return html`
|
|
|
+ <div class="topbar"><div class="inner">
|
|
|
+ <button class="iconbtn" @click=${()=>this.go('#/')}>←</button>
|
|
|
+ <div class="tt"><h1>工艺知识库</h1><p>壳体 · 工艺 · 文件 · 电子件 · 参考文章</p></div>
|
|
|
+ </div></div>
|
|
|
+ <div class="wrap">
|
|
|
+ <div class="hero" style="padding:18px 18px 16px">
|
|
|
+ <div class="kicker">KNOWLEDGE BASE</div>
|
|
|
+ <h2 style="font-size:20px">从创意到能报价,只差这一套口径</h2>
|
|
|
+ <p>工艺成本、MOQ 真相、文件格式、DFM 与电子件选型,全部按可执行口径整理,随时回看。</p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ ${KB.map(k=>html`
|
|
|
+ <details class="acc" ${k.id==='process'?'open':''}>
|
|
|
+ <summary><span class="ix">${k.ix}</span>${k.title}<span class="chev">▾</span></summary>
|
|
|
+ <div class="body">${this.renderKBItem(k)}</div>
|
|
|
+ </details>`)}
|
|
|
+
|
|
|
+ <div class="sec"><h3>参考文章 / 对话存档</h3><span>长期保存在本机</span></div>
|
|
|
+ ${REFS.map(r=>html`
|
|
|
+ <div class="acc">
|
|
|
+ <div style="padding:12px 14px">
|
|
|
+ <span class="tag b">${r.tag}</span>
|
|
|
+ <div class="ref" style="margin-top:8px;border:none;padding:0;background:transparent">
|
|
|
+ <b>${r.n}</b>
|
|
|
+ <span>${r.u}</span>
|
|
|
+ </div>
|
|
|
+ <div class="hint">${r.d}</div>
|
|
|
+ ${notes[r.id]?html`<details style="margin-top:8px">
|
|
|
+ <summary style="font-size:12px;color:#1f6feb">已录入正文(${notes[r.id].length} 字)· 点击展开</summary>
|
|
|
+ <div style="font-size:12px;line-height:1.7;white-space:pre-wrap;margin-top:8px;color:#31425a">${notes[r.id]}</div>
|
|
|
+ </details>`:''}
|
|
|
+ ${r.id==='wx1'?html`
|
|
|
+ <div style="margin-top:10px">
|
|
|
+ <textarea id="wxtext" placeholder="公众号有 robots 限制,无法自动抓取。把正文粘贴到这里,点保存即可长期归档在本机…"></textarea>
|
|
|
+ <div class="btnrow">
|
|
|
+ <button class="btn pri" @click=${()=>this.saveArticle()}>保存正文到本机</button>
|
|
|
+ <button class="btn" @click=${()=>{ const t=this.querySelector('#wxtext'); if(t) t.value=notes['wx1']||''; }}>读取已存</button>
|
|
|
+ </div>
|
|
|
+ </div>`:''}
|
|
|
+ </div>
|
|
|
+ </div>`)}
|
|
|
+
|
|
|
+ <div class="panel" style="margin-top:12px">
|
|
|
+ <h5>电子件速查 <em>${BOARDS.length} 个模组</em></h5>
|
|
|
+ ${BOARDS.map(b=>html`
|
|
|
+ <div style="padding:9px 0;border-bottom:1px dashed var(--line)">
|
|
|
+ <div style="display:flex;justify-content:space-between;gap:10px">
|
|
|
+ <b style="font-size:12px">${b.name}</b><span style="font-size:10.5px;color:#68758a;white-space:nowrap">${b.od}</span>
|
|
|
+ </div>
|
|
|
+ <div class="hint">${b.screen} · ${b.iface}</div>
|
|
|
+ </div>`)}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="foot">知识库内容为工程口径整理,价格为 2026-11 深圳/东莞行情参考。<br>引用文章版权归原作者;本页仅存链接与自录摘要。</div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderKBItem(k){
|
|
|
+ return k.body.map(item=>{
|
|
|
+ if(item[0]==='table'){
|
|
|
+ return html`<div class="scrollx"><table class="tbl">
|
|
|
+ <thead><tr>${item[1].map(h=>html`<th>${h}</th>`)}</tr></thead>
|
|
|
+ <tbody>${item[2].map(r=>html`<tr>${r.map(c=>html`<td>${c}</td>`)}</tr>`)}</tbody>
|
|
|
+ </table></div>`;
|
|
|
+ }
|
|
|
+ if(item[0]==='p') return html`<p>${item[1]}</p>`;
|
|
|
+ if(item[0]==='ul') return html`<ul>${item[1].map(x=>html`<li>${x}</li>`)}</ul>`;
|
|
|
+ if(item[0]==='note') return html`<div class="note">${item[1]}</div>`;
|
|
|
+ return '';
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ saveArticle(){
|
|
|
+ const t=this.querySelector('#wxtext');
|
|
|
+ if(!t||!t.value.trim()) return;
|
|
|
+ const notes=LS.get('ss.refs.note',{});
|
|
|
+ notes['wx1']=t.value.trim();
|
|
|
+ LS.set('ss.refs.note',notes);
|
|
|
+ alert('已保存到本机(清理浏览器数据会丢失,重要内容建议另存)');
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ---------- 导出动作 ---------- */
|
|
|
+ resetParams(){
|
|
|
+ this.state.params=defaultParams(this.state.project);
|
|
|
+ STAGE.setParams(this.state.params);
|
|
|
+ this.persist();
|
|
|
+ this.requestUpdate();
|
|
|
+ }
|
|
|
+ baseName(){
|
|
|
+ const proj=PROJECTS[this.state.project];
|
|
|
+ const d=new Date();
|
|
|
+ const stamp=d.getFullYear()+String(d.getMonth()+1).padStart(2,'0')+String(d.getDate()).padStart(2,'0');
|
|
|
+ return proj.name.replace(/[^\u4e00-\u9fa5A-Za-z0-9]/g,'')+'-'+stamp;
|
|
|
+ }
|
|
|
+ saveSTL(){
|
|
|
+ const r=STAGE.exportSTL(this.baseName());
|
|
|
+ if(!r) return alert('3D 尚未就绪');
|
|
|
+ saveFile(this.baseName()+'.stl',r.text,'model/stl');
|
|
|
+ toast('已导出 '+this.baseName()+'.stl('+(r.text.split('facet').length-1)+' 面)');
|
|
|
+ }
|
|
|
+ saveOBJ(){
|
|
|
+ const r=STAGE.exportOBJ(this.baseName());
|
|
|
+ if(!r) return alert('3D 尚未就绪');
|
|
|
+ saveFile(this.baseName()+'.obj',r.text,'text/plain');
|
|
|
+ toast('已导出 '+this.baseName()+'.obj');
|
|
|
+ }
|
|
|
+ savePNG(){
|
|
|
+ const url=STAGE.snapshot();
|
|
|
+ if(!url) return alert('3D 尚未就绪');
|
|
|
+ saveDataURL(this.baseName()+'.png',url);
|
|
|
+ toast('已保存当前视角截图');
|
|
|
+ }
|
|
|
+ saveSpec(){
|
|
|
+ const md=specMarkdown(this.state.project,this.state.params,this.state.material,this.state.qty,this.custom());
|
|
|
+ saveFile(this.baseName()+'-生产需求单.md',md,'text/markdown');
|
|
|
+ toast('需求单已生成('+md.length+' 字)');
|
|
|
+ }
|
|
|
+ saveBOM(){
|
|
|
+ saveFile(this.baseName()+'-BOM.csv','\ufeff'+bomCSV(this.state.project,this.state.params,this.state.material),'text/csv');
|
|
|
+ }
|
|
|
+ saveJSON(){
|
|
|
+ saveFile(this.baseName()+'.json',specJSON(this.state.project,this.state.params,this.state.material,this.state.qty,this.custom()),'application/json');
|
|
|
+ toast('参数 JSON 已导出');
|
|
|
+ }
|
|
|
+
|
|
|
+ render(){
|
|
|
+ if(this.state.route==='kb') return this.renderKB();
|
|
|
+ if(this.state.route==='project') return this.renderProject();
|
|
|
+ return this.renderHub();
|
|
|
+ }
|
|
|
+}
|
|
|
+customElements.define('app-root',AppRoot);
|
|
|
+
|
|
|
+window.SHELL={STAGE:STAGE,PROJECTS:PROJECTS,MATERIALS:MATERIALS,spec:specMarkdown,svg:fitSVG};
|
|
|
+
|
|
|
+/* 移除加载层 */
|
|
|
+const boot=document.getElementById('boot');
|
|
|
+if(boot){
|
|
|
+ setTimeout(()=>{ boot.classList.add('hide'); setTimeout(()=>boot.remove(),400); },220);
|
|
|
+}
|
|
|
+function bootFail(msg){
|
|
|
+ const b=document.getElementById('bootmsg');
|
|
|
+ if(b) b.textContent='加载失败:'+msg+'(请检查网络后刷新)';
|
|
|
+}
|
|
|
+window.addEventListener('unhandledrejection',e=>bootFail((e.reason&&e.reason.message)||'依赖未就绪'));
|
|
|
+window.addEventListener('error',e=>{ if(!customElements.get('app-root')) bootFail(e.message||'脚本错误'); });
|
|
|
+</script>
|
|
|
+</body>
|
|
|
+</html>
|