dsh-qizhoucnc-cam 1.3.13 → 1.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +176 -53
- package/index.js +18 -3
- package/model_tessellate.py +103 -44
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -314,15 +314,20 @@ window.__ModuleLoader__.load({
|
|
|
314
314
|
// scene 来自 /dsh-cam/model:{ bounds:{min,max}, faces:[{id,vertices,triangles,center,area}], edges:[{id,points}] }
|
|
315
315
|
// selected: { kind:'face'|'edge', id } | null;点击面/边时回传 onSelect。
|
|
316
316
|
// pivot: [x,y,z] 旋转轴心;默认取模型包围盒中心。旋转/缩放都围绕该点。
|
|
317
|
-
function ModelViewer3D({ scene, selected, onSelect, onAnnotate, pivot, features, locate, overlays, transform }) {
|
|
317
|
+
function ModelViewer3D({ scene, selected, selectedSet, onSelect, onAnnotate, onSelectMulti, pivot, features, locate, overlays, transform, maximized, onToggleMaximize }) {
|
|
318
318
|
const [view, setView] = React.useState(null);
|
|
319
|
-
const [maximized, setMaximized] = React.useState(false); // 放大模型视窗(全屏遮罩)
|
|
320
319
|
const drag = React.useRef(null);
|
|
321
320
|
// 单击/双击判定:记录上次点击的目标与时间(同目标 350ms 内再次点击 = 双击标注)
|
|
322
321
|
const clickState = React.useRef({ time: 0, kind: null, id: null });
|
|
323
322
|
const clickTimer = React.useRef(null);
|
|
324
323
|
const svgRef = React.useRef(null);
|
|
325
324
|
const W = 600, H = 460, cx = W / 2, cy = H / 2;
|
|
325
|
+
// 多选集合的命中映射:kind:id -> true
|
|
326
|
+
const selSetMap = React.useMemo(() => {
|
|
327
|
+
const m = {};
|
|
328
|
+
for (const s of (selectedSet || [])) m[s.kind + ':' + s.id] = true;
|
|
329
|
+
return m;
|
|
330
|
+
}, [selectedSet]);
|
|
326
331
|
const pv = pivot || [0, 0, 0];
|
|
327
332
|
// 主体模型的位移/旋转(与夹具/毛坯同款 transform):{ translate:[x,y,z], rotate:[rx,ry,rz] }
|
|
328
333
|
const xf = transform || null;
|
|
@@ -446,13 +451,14 @@ window.__ModuleLoader__.load({
|
|
|
446
451
|
const faceEls = [];
|
|
447
452
|
for (const f of scene.faces) {
|
|
448
453
|
const isSel = selected && selected.kind === 'face' && selected.id === f.id;
|
|
454
|
+
const isMultiSel = !!selSetMap['face:' + f.id];
|
|
449
455
|
const isFeat = featMap['face:' + f.id];
|
|
450
456
|
const isLoc = locateKey === 'face:' + f.id;
|
|
451
457
|
const shade = shadeOf(faceNormal(f));
|
|
452
458
|
const r = Math.round(96 * shade), g = Math.round(116 * shade), b = Math.round(140 * shade);
|
|
453
459
|
const baseFill = 'rgb(' + r + ',' + g + ',' + b + ')';
|
|
454
460
|
const hoverFill = 'rgb(' + Math.min(255, r + 42) + ',' + Math.min(255, g + 42) + ',' + Math.min(255, b + 42) + ')';
|
|
455
|
-
const fillColor = isLoc ? LOCATE_FILL : (isFeat ? FEAT_FILL : (isSel ? FACE_SELECTED : baseFill));
|
|
461
|
+
const fillColor = isLoc ? LOCATE_FILL : (isFeat ? FEAT_FILL : ((isSel || isMultiSel) ? FACE_SELECTED : baseFill));
|
|
456
462
|
let d = '';
|
|
457
463
|
for (const tri of f.triangles) {
|
|
458
464
|
const a = f.vertices[tri[0]], b = f.vertices[tri[1]], c = f.vertices[tri[2]];
|
|
@@ -465,18 +471,19 @@ window.__ModuleLoader__.load({
|
|
|
465
471
|
key: 'f' + f.id,
|
|
466
472
|
d,
|
|
467
473
|
fill: fillColor,
|
|
468
|
-
stroke: isLoc ? LOCATE_STROKE : (isFeat ? '#f97316' : (isSel ? '#f97316' : FACE_STROKE)),
|
|
469
|
-
strokeWidth: isLoc ? 2.4 : (isFeat ? 0.8 : 0.4), strokeLinejoin: 'round',
|
|
474
|
+
stroke: isLoc ? LOCATE_STROKE : (isFeat ? '#f97316' : ((isSel || isMultiSel) ? '#f97316' : FACE_STROKE)),
|
|
475
|
+
strokeWidth: isLoc ? 2.4 : (isFeat ? 0.8 : ((isSel || isMultiSel) ? 0.8 : 0.4)), strokeLinejoin: 'round',
|
|
470
476
|
style: { cursor: 'pointer' },
|
|
471
477
|
'data-hit': 'face', 'data-id': f.id,
|
|
472
|
-
onMouseEnter: (e) => { if (!isSel && !isFeat && !isLoc) e.currentTarget.setAttribute('fill', hoverFill); },
|
|
473
|
-
onMouseLeave: (e) => { if (!isSel && !isFeat && !isLoc) e.currentTarget.setAttribute('fill', baseFill); },
|
|
478
|
+
onMouseEnter: (e) => { if (!isSel && !isMultiSel && !isFeat && !isLoc) e.currentTarget.setAttribute('fill', hoverFill); },
|
|
479
|
+
onMouseLeave: (e) => { if (!isSel && !isMultiSel && !isFeat && !isLoc) e.currentTarget.setAttribute('fill', baseFill); },
|
|
474
480
|
}));
|
|
475
481
|
}
|
|
476
482
|
// edges as individual <polyline> for picking
|
|
477
483
|
const edgeEls = [];
|
|
478
484
|
for (const e of scene.edges) {
|
|
479
485
|
const isSel = selected && selected.kind === 'edge' && selected.id === e.id;
|
|
486
|
+
const isMultiSel = !!selSetMap['edge:' + e.id];
|
|
480
487
|
const isFeat = featMap['edge:' + e.id];
|
|
481
488
|
const isLoc = locateKey === 'edge:' + e.id;
|
|
482
489
|
let pts = '';
|
|
@@ -485,8 +492,8 @@ window.__ModuleLoader__.load({
|
|
|
485
492
|
key: 'e' + e.id,
|
|
486
493
|
points: pts,
|
|
487
494
|
fill: 'none',
|
|
488
|
-
stroke: isLoc ? LOCATE_STROKE : (isFeat ? '#f97316' : (isSel ? EDGE_SELECTED : EDGE_COLOR)),
|
|
489
|
-
strokeWidth: isLoc ? 4.4 : (isFeat ? 3.2 : (isSel ? 3 : 1.4)),
|
|
495
|
+
stroke: isLoc ? LOCATE_STROKE : (isFeat ? '#f97316' : ((isSel || isMultiSel) ? EDGE_SELECTED : EDGE_COLOR)),
|
|
496
|
+
strokeWidth: isLoc ? 4.4 : (isFeat ? 3.2 : ((isSel || isMultiSel) ? 3 : 1.4)),
|
|
490
497
|
strokeLinejoin: 'round', strokeLinecap: 'round',
|
|
491
498
|
style: { cursor: 'pointer' },
|
|
492
499
|
'data-hit': 'edge', 'data-id': e.id,
|
|
@@ -593,10 +600,18 @@ window.__ModuleLoader__.load({
|
|
|
593
600
|
return null;
|
|
594
601
|
};
|
|
595
602
|
// 单击/双击:同一面/边 350ms 内两次点击 = 双击(标注),否则单击(选中)。
|
|
596
|
-
|
|
603
|
+
// shiftKey=true 时走多选(Shift+点击),不做双击判定。
|
|
604
|
+
const fireClick = (hit, shiftKey) => {
|
|
597
605
|
if (!hit) return;
|
|
598
606
|
const now = Date.now();
|
|
599
607
|
const prev = clickState.current;
|
|
608
|
+
// Shift 多选:直接切换该面/边在多选集合中的状态(不触发双击标注)
|
|
609
|
+
if (shiftKey && typeof onSelectMulti === 'function') {
|
|
610
|
+
clearTimeout(clickTimer.current);
|
|
611
|
+
clickState.current = { time: 0, kind: null, id: null };
|
|
612
|
+
onSelectMulti({ kind: hit.kind, id: hit.id });
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
600
615
|
if (prev && prev.kind === hit.kind && prev.id === hit.id && (now - prev.time) < 350) {
|
|
601
616
|
clearTimeout(clickTimer.current);
|
|
602
617
|
clickState.current = { time: 0, kind: null, id: null };
|
|
@@ -648,8 +663,8 @@ window.__ModuleLoader__.load({
|
|
|
648
663
|
const d = drag.current;
|
|
649
664
|
drag.current = null;
|
|
650
665
|
if (d && !d.moved) {
|
|
651
|
-
// 未拖拽 =
|
|
652
|
-
fireClick(hitTest(e.clientX, e.clientY));
|
|
666
|
+
// 未拖拽 = 一次点击:命中面/边则触发单击/双击判定(Shift = 多选)
|
|
667
|
+
fireClick(hitTest(e.clientX, e.clientY), !!e.shiftKey);
|
|
653
668
|
}
|
|
654
669
|
};
|
|
655
670
|
const onWheel = (e) => { e.preventDefault(); setView((v) => ({ ...v, zoom: Math.max(0.05, Math.min(20, v.zoom * (e.deltaY < 0 ? 1.12 : 0.9))) })); };
|
|
@@ -666,13 +681,15 @@ window.__ModuleLoader__.load({
|
|
|
666
681
|
}, v.label);
|
|
667
682
|
const activeView = VIEWS.find((v) => Math.abs(v.yaw - view.yaw) < 1e-6 && Math.abs(v.pitch - view.pitch) < 1e-6);
|
|
668
683
|
|
|
684
|
+
const selCount = (selectedSet && selectedSet.length) || 0;
|
|
669
685
|
const selText = selected
|
|
670
|
-
? (selected.kind === 'face' ? '已选面 #' + selected.id + (selected.area ? ' · ' + Math.round(selected.area) + ' mm²' : '') : '已选边 #' + selected.id)
|
|
671
|
-
|
|
686
|
+
? (selected.kind === 'face' ? '已选面 #' + selected.id + (selected.area ? ' · ' + Math.round(selected.area) + ' mm²' : '') : '已选边 #' + selected.id)
|
|
687
|
+
+ (selCount > 1 ? ' 等 ' + selCount + ' 个(Shift 多选)' : '') + '(双击标注)'
|
|
688
|
+
: '单击选中面或边线,双击标注加工位置 · Shift+点击多选相同特征';
|
|
672
689
|
|
|
673
690
|
// 最大化按钮 + 恢复按钮(模型视窗放大/还原)
|
|
674
691
|
const maxBtn = h('button', {
|
|
675
|
-
onClick: () =>
|
|
692
|
+
onClick: () => (typeof onToggleMaximize === 'function' ? onToggleMaximize() : null),
|
|
676
693
|
title: maximized ? '还原模型视窗大小' : '放大模型视窗(全屏操作)',
|
|
677
694
|
style: {
|
|
678
695
|
marginLeft: 'auto', padding: '1px 8px', fontSize: 11, cursor: 'pointer', borderRadius: 5,
|
|
@@ -697,35 +714,6 @@ window.__ModuleLoader__.load({
|
|
|
697
714
|
h('g', null, edgeEls),
|
|
698
715
|
h('g', null, overlayEls));
|
|
699
716
|
|
|
700
|
-
// 放大:全屏遮罩里显示更大的模型视窗
|
|
701
|
-
if (maximized) {
|
|
702
|
-
return h('div', {
|
|
703
|
-
style: {
|
|
704
|
-
position: 'fixed', inset: 0, zIndex: 3100,
|
|
705
|
-
background: 'rgba(15, 23, 42, 0.6)',
|
|
706
|
-
display: 'flex', flexDirection: 'column', padding: 18,
|
|
707
|
-
},
|
|
708
|
-
onClick: () => setMaximized(false),
|
|
709
|
-
},
|
|
710
|
-
h('div', {
|
|
711
|
-
style: {
|
|
712
|
-
flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', gap: 6,
|
|
713
|
-
background: 'var(--dsw-alias-bg-base, #fff)', borderRadius: 12, padding: 12,
|
|
714
|
-
boxShadow: '0 24px 80px rgba(0,0,0,0.45)',
|
|
715
|
-
},
|
|
716
|
-
onClick: (e) => e.stopPropagation(),
|
|
717
|
-
},
|
|
718
|
-
h('div', { style: { display: 'flex', gap: 4, alignItems: 'center', flexWrap: 'wrap' } },
|
|
719
|
-
h('span', { style: { fontSize: 12, color: 'var(--dsw-alias-label-tertiary, #9ca3af)', marginRight: 2, fontWeight: 600 } }, '模型视窗'),
|
|
720
|
-
VIEWS.map((v) => viewBtn(v, activeView === v)),
|
|
721
|
-
maxBtn),
|
|
722
|
-
svgBlock({ flex: 1, minHeight: 0 }),
|
|
723
|
-
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 12 } },
|
|
724
|
-
h('span', { style: { flex: 1, color: selected ? 'var(--dsw-alias-brand-primary, #2563eb)' : 'var(--dsw-alias-label-tertiary, #9ca3af)', fontWeight: selected ? 600 : 400 } }, selText),
|
|
725
|
-
h('span', { style: { color: 'var(--dsw-alias-label-tertiary, #9ca3af)' } },
|
|
726
|
-
'拖拽=旋转 · Shift/右键=平移 · 滚轮=缩放 · 面 ' + scene.faces.length + ' · 边 ' + scene.edges.length))));
|
|
727
|
-
}
|
|
728
|
-
|
|
729
717
|
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, flex: 1, minHeight: 0 } },
|
|
730
718
|
h('div', { style: { display: 'flex', gap: 4, alignItems: 'center', flexWrap: 'wrap' } },
|
|
731
719
|
h('span', { style: { fontSize: 11, color: 'var(--dsw-alias-label-tertiary, #9ca3af)', marginRight: 2 } }, '视图'),
|
|
@@ -1016,7 +1004,11 @@ window.__ModuleLoader__.load({
|
|
|
1016
1004
|
// 模型视窗 / 刀路视窗切换 + 3D 模型 + 选面/选边标注
|
|
1017
1005
|
const [viewMode, setViewMode] = React.useState('toolpath'); // 'toolpath' | 'model'
|
|
1018
1006
|
const [modelScene, setModelScene] = React.useState(null);
|
|
1019
|
-
const [modelSelected, setModelSelected] = React.useState(null); // { kind, id, center?, area?, points? }
|
|
1007
|
+
const [modelSelected, setModelSelected] = React.useState(null); // { kind, id, center?, area?, points? } 主选中项
|
|
1008
|
+
// 多选(Shift+点击):同一类特征的多条选中 { kind, id, center?, area?, points? }
|
|
1009
|
+
const [modelSelectedSet, setModelSelectedSet] = React.useState([]);
|
|
1010
|
+
// 相同特征提示:检测到当前面/边有 N 个相同特征时弹出,可一键「一起标注」
|
|
1011
|
+
const [similarPrompt, setSimilarPrompt] = React.useState(null); // { kind, ids:[], count, label }
|
|
1020
1012
|
const [annotating, setAnnotating] = React.useState(false); // 双击后进入标注命名态(显示命名输入框)
|
|
1021
1013
|
const [modelLoading, setModelLoading] = React.useState(false);
|
|
1022
1014
|
const [modelFeatures, setModelFeatures] = React.useState([]);
|
|
@@ -1047,6 +1039,8 @@ window.__ModuleLoader__.load({
|
|
|
1047
1039
|
// 版本更新检查(右下角:版本号 / 更新提醒 / 手动更新)
|
|
1048
1040
|
const [versionInfo, setVersionInfo] = React.useState(null); // { current, latest, updateAvailable }
|
|
1049
1041
|
const [updating, setUpdating] = React.useState(false); // 是否正在执行更新
|
|
1042
|
+
// 模型视窗放大(全屏遮罩显示整个模型操作区:标注列表 + 视窗 + 轴心 + 设置面板 + 标注输入 + 夹具/毛坯)
|
|
1043
|
+
const [modelMaximized, setModelMaximized] = React.useState(false);
|
|
1050
1044
|
// 底部设置区(主体零件位移/旋转 + 夹具/毛坯)折叠/展开
|
|
1051
1045
|
const [setupCollapsed, setSetupCollapsed] = React.useState(false);
|
|
1052
1046
|
// FreeCAD 自动下载状态(未安装 FreeCAD 时展示进度并触发下载)
|
|
@@ -1205,6 +1199,8 @@ window.__ModuleLoader__.load({
|
|
|
1205
1199
|
if (d && d.ok && Array.isArray(d.faces)) {
|
|
1206
1200
|
setModelScene(d);
|
|
1207
1201
|
setModelSelected(null);
|
|
1202
|
+
setModelSelectedSet([]);
|
|
1203
|
+
setSimilarPrompt(null);
|
|
1208
1204
|
setAnnotating(false);
|
|
1209
1205
|
setMainTransform(null);
|
|
1210
1206
|
setMainTf({ translate: [0, 0, 0], rotate: [0, 0, 0] });
|
|
@@ -1220,6 +1216,58 @@ window.__ModuleLoader__.load({
|
|
|
1220
1216
|
.finally(() => { setBusy(false); setModelLoading(false); });
|
|
1221
1217
|
}, [post]);
|
|
1222
1218
|
|
|
1219
|
+
// ---- 多选(Shift+点击)与相同特征检测 ----
|
|
1220
|
+
// 选中集合的稳定键:kind:id
|
|
1221
|
+
const selKey = (s) => s.kind + ':' + s.id;
|
|
1222
|
+
// 在场景里找某个 kind:id 对应的面/边详情
|
|
1223
|
+
const sceneHitOf = React.useCallback((kind, id) => {
|
|
1224
|
+
if (!modelScene) return null;
|
|
1225
|
+
if (kind === 'face') return modelScene.faces.find((x) => x.id === id) || null;
|
|
1226
|
+
return modelScene.edges.find((x) => x.id === id) || null;
|
|
1227
|
+
}, [modelScene]);
|
|
1228
|
+
|
|
1229
|
+
// 计算与某面/边「相同特征」的其它面/边 id 列表(基于 tessellation 出的 shapeKey)。
|
|
1230
|
+
const similarIdsOf = React.useCallback((kind, id) => {
|
|
1231
|
+
if (!modelScene) return [];
|
|
1232
|
+
const arr = kind === 'face' ? modelScene.faces : modelScene.edges;
|
|
1233
|
+
const target = arr.find((x) => x.id === id);
|
|
1234
|
+
if (!target || !target.shapeKey) return [];
|
|
1235
|
+
return arr.filter((x) => x.shapeKey && x.shapeKey === target.shapeKey).map((x) => x.id);
|
|
1236
|
+
}, [modelScene]);
|
|
1237
|
+
|
|
1238
|
+
// 统一处理「选中」:单点=单选;Shift+点击=切换多选(限定同一 kind)。
|
|
1239
|
+
// 返回是否进入多选态(选中集合 > 1)。
|
|
1240
|
+
const applySelection = React.useCallback((sel, addToMulti) => {
|
|
1241
|
+
if (!sel) return;
|
|
1242
|
+
setModelSelected(sel);
|
|
1243
|
+
setAnnotating(false);
|
|
1244
|
+
setEditingFeatureId(null);
|
|
1245
|
+
if (addToMulti) {
|
|
1246
|
+
// Shift 多选:同一 kind 内切换
|
|
1247
|
+
setModelSelectedSet((prev) => {
|
|
1248
|
+
const sameKind = prev.filter((s) => s.kind === sel.kind);
|
|
1249
|
+
const idx = sameKind.findIndex((s) => selKey(s) === selKey(sel));
|
|
1250
|
+
if (idx >= 0) return sameKind.filter((s) => selKey(s) !== selKey(sel));
|
|
1251
|
+
return [...sameKind, sel];
|
|
1252
|
+
});
|
|
1253
|
+
} else {
|
|
1254
|
+
setModelSelectedSet([sel]);
|
|
1255
|
+
}
|
|
1256
|
+
setSimilarPrompt(null);
|
|
1257
|
+
}, []);
|
|
1258
|
+
|
|
1259
|
+
// 选中后检测相同特征:若该面/边有 >1 个相同 shapeKey,弹出「一起标注」提示。
|
|
1260
|
+
const detectSimilar = React.useCallback((kind, id) => {
|
|
1261
|
+
const ids = similarIdsOf(kind, id);
|
|
1262
|
+
if (ids.length > 1) {
|
|
1263
|
+
const n = ids.length;
|
|
1264
|
+
const label = kind === 'face' ? '个相同特征的面' : '条相同特征的边';
|
|
1265
|
+
setSimilarPrompt({ kind, ids, count: n, label });
|
|
1266
|
+
} else {
|
|
1267
|
+
setSimilarPrompt(null);
|
|
1268
|
+
}
|
|
1269
|
+
}, [similarIdsOf]);
|
|
1270
|
+
|
|
1223
1271
|
// 查询 FreeCAD 自动下载/安装状态
|
|
1224
1272
|
const checkFcStatus = React.useCallback(() => {
|
|
1225
1273
|
fetch('/dsh-cam/freecad').then((r) => r.json()).then((d) => {
|
|
@@ -1313,12 +1361,19 @@ window.__ModuleLoader__.load({
|
|
|
1313
1361
|
.catch(() => {});
|
|
1314
1362
|
}, []);
|
|
1315
1363
|
|
|
1316
|
-
//
|
|
1364
|
+
// 把当前选中的面/边作为「加工位置」标注,命名后写入识别文件。
|
|
1365
|
+
// 支持批量:refIds 存在时一次写入多条(Shift 多选 或「一起标注」)。
|
|
1317
1366
|
const addFeature = React.useCallback(() => {
|
|
1318
1367
|
if (!modelSelected) { setErr('请先在模型视窗中点击一个面或边线'); return; }
|
|
1319
1368
|
const name = featureName.trim();
|
|
1320
1369
|
if (!name) { setErr('请为这个加工位置填写名称'); return; }
|
|
1321
1370
|
setBusy(true); setErr(null);
|
|
1371
|
+
// 批量标注:优先取 similarPrompt.ids 或 modelSelectedSet 的 refIds
|
|
1372
|
+
const multi = similarPrompt && similarPrompt.kind === modelSelected.kind
|
|
1373
|
+
? similarPrompt.ids
|
|
1374
|
+
: (modelSelectedSet.length > 1 && modelSelectedSet.every((s) => s.kind === modelSelected.kind)
|
|
1375
|
+
? modelSelectedSet.map((s) => s.id)
|
|
1376
|
+
: null);
|
|
1322
1377
|
const body = {
|
|
1323
1378
|
model: modelFile,
|
|
1324
1379
|
name,
|
|
@@ -1326,6 +1381,7 @@ window.__ModuleLoader__.load({
|
|
|
1326
1381
|
refId: modelSelected.id,
|
|
1327
1382
|
note: featureNote.trim(),
|
|
1328
1383
|
};
|
|
1384
|
+
if (multi && multi.length > 1) body.refIds = multi;
|
|
1329
1385
|
// 二次修改:若正在编辑某条已有标注,走 update;否则新增
|
|
1330
1386
|
if (editingFeatureId) body.op = 'update', body.id = editingFeatureId;
|
|
1331
1387
|
post('/dsh-cam/feature', body)
|
|
@@ -1337,15 +1393,24 @@ window.__ModuleLoader__.load({
|
|
|
1337
1393
|
setEditingFeatureId(null);
|
|
1338
1394
|
setAnnotating(false);
|
|
1339
1395
|
setModelSelected(null);
|
|
1396
|
+
setModelSelectedSet([]);
|
|
1397
|
+
setSimilarPrompt(null);
|
|
1340
1398
|
} else setErr(d.error || '标注写入失败');
|
|
1341
1399
|
})
|
|
1342
1400
|
.catch((e) => setErr(String(e)))
|
|
1343
1401
|
.finally(() => setBusy(false));
|
|
1344
|
-
}, [post, modelFile, modelSelected, featureName, featureNote, editingFeatureId]);
|
|
1402
|
+
}, [post, modelFile, modelSelected, modelSelectedSet, similarPrompt, featureName, featureNote, editingFeatureId]);
|
|
1345
1403
|
|
|
1346
1404
|
// 从已有标注列表开始「二次修改」(重命名 / 改备注 / 重选目标)
|
|
1347
1405
|
const startEditFeature = React.useCallback((f) => {
|
|
1348
1406
|
setModelSelected({ kind: f.kind, id: f.refId });
|
|
1407
|
+
// 批量特征:恢复多选集合,让「已选 N 个」与高亮一致
|
|
1408
|
+
if (Array.isArray(f.refIds) && f.refIds.length > 1) {
|
|
1409
|
+
setModelSelectedSet(f.refIds.map((id) => ({ kind: f.kind, id })));
|
|
1410
|
+
} else {
|
|
1411
|
+
setModelSelectedSet([]);
|
|
1412
|
+
}
|
|
1413
|
+
setSimilarPrompt(null);
|
|
1349
1414
|
setFeatureName(f.name || '');
|
|
1350
1415
|
setFeatureNote(f.note || '');
|
|
1351
1416
|
setEditingFeatureId(f.id);
|
|
@@ -1728,7 +1793,31 @@ window.__ModuleLoader__.load({
|
|
|
1728
1793
|
h('div', { style: { flex: 1, overflow: 'hidden', padding: 10, display: 'flex', flexDirection: 'column', minHeight: 0 } },
|
|
1729
1794
|
err ? h('div', { style: { padding: 8, color: 'var(--dsw-alias-state-error-primary, #dc2626)', fontSize: 12, marginBottom: 8 } }, '错误:' + err) : null,
|
|
1730
1795
|
viewMode === 'model'
|
|
1731
|
-
? h('div', {
|
|
1796
|
+
? h('div', {
|
|
1797
|
+
style: {
|
|
1798
|
+
flex: 1, minHeight: 0, display: 'flex', flexDirection: 'row', gap: 8,
|
|
1799
|
+
// 放大:把整个模型操作区(标注列表 + 视窗 + 轴心 + 设置面板 + 标注输入 + 夹具/毛坯)
|
|
1800
|
+
// 原样铺到全屏,布局保持不变;position:fixed 相对视口定位,不受面板 overflow 裁剪。
|
|
1801
|
+
...(modelMaximized ? {
|
|
1802
|
+
position: 'fixed', inset: 0, zIndex: 3100,
|
|
1803
|
+
background: 'var(--dsw-alias-bg-base, #fff)',
|
|
1804
|
+
padding: 16, boxShadow: '0 24px 80px rgba(0,0,0,0.35)',
|
|
1805
|
+
} : {}),
|
|
1806
|
+
},
|
|
1807
|
+
},
|
|
1808
|
+
// 放大态:右上角浮动「还原」按钮 + 顶部标题条(点击遮罩语义一致)
|
|
1809
|
+
modelMaximized ? h('div', {
|
|
1810
|
+
style: {
|
|
1811
|
+
position: 'absolute', top: 12, right: 12, zIndex: 3101,
|
|
1812
|
+
display: 'flex', alignItems: 'center', gap: 8,
|
|
1813
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
h('span', { style: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-secondary, #6b7280)' } }, '模型视窗 · 放大'),
|
|
1816
|
+
h('button', {
|
|
1817
|
+
onClick: () => setModelMaximized(false),
|
|
1818
|
+
style: { ...btn, fontSize: 12, padding: '3px 12px', fontWeight: 600 },
|
|
1819
|
+
title: '还原模型视窗',
|
|
1820
|
+
}, '还原')) : null,
|
|
1732
1821
|
// 左侧:已标注加工位置列表
|
|
1733
1822
|
h('div', { style: { width: 168, flexShrink: 0, display: 'flex', flexDirection: 'column', borderRadius: 8, background: 'var(--dsw-alias-bg-layer-2, #f3f4f6)', border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)', padding: 8, overflow: 'hidden' } },
|
|
1734
1823
|
h('div', { style: { fontSize: 11, fontWeight: 700, color: 'var(--dsw-alias-label-primary, #111)', marginBottom: 4 } }, '已标注加工位置'),
|
|
@@ -1745,7 +1834,7 @@ window.__ModuleLoader__.load({
|
|
|
1745
1834
|
h('span', { style: { fontSize: 12, color: '#f97316' } }, f.kind === 'face' ? '▨' : '╱'),
|
|
1746
1835
|
h('div', { style: { display: 'flex', flexDirection: 'column', minWidth: 0, flex: 1 } },
|
|
1747
1836
|
h('span', { style: { fontWeight: 600, color: 'var(--dsw-alias-label-primary, #111)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, f.name),
|
|
1748
|
-
h('span', { style: { fontSize: 10, color: 'var(--dsw-alias-label-secondary, #6b7280)' } }, (f.kind === 'face' ? '面' : '边') + ' #' + f.refId + (f.note ? ' · ' + f.note : ''))),
|
|
1837
|
+
h('span', { style: { fontSize: 10, color: 'var(--dsw-alias-label-secondary, #6b7280)' } }, (f.kind === 'face' ? '面' : '边') + ' #' + f.refId + (Array.isArray(f.refIds) && f.refIds.length > 1 ? ' ×' + f.refIds.length : '') + (f.note ? ' · ' + f.note : ''))),
|
|
1749
1838
|
h('button', {
|
|
1750
1839
|
onClick: () => removeFeature(f),
|
|
1751
1840
|
title: '删除此标注',
|
|
@@ -1755,12 +1844,23 @@ window.__ModuleLoader__.load({
|
|
|
1755
1844
|
// 右侧:模型视窗 + 轴心 + 标注输入
|
|
1756
1845
|
h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' } },
|
|
1757
1846
|
h(ModelViewer3D, {
|
|
1758
|
-
scene: modelScene, selected: modelSelected, pivot: modelPivot, features: modelFeatures, locate: locateTarget,
|
|
1847
|
+
scene: modelScene, selected: modelSelected, selectedSet: modelSelectedSet, pivot: modelPivot, features: modelFeatures, locate: locateTarget,
|
|
1759
1848
|
transform: mainTransform,
|
|
1849
|
+
maximized: modelMaximized,
|
|
1850
|
+
onToggleMaximize: () => setModelMaximized((v) => !v),
|
|
1760
1851
|
overlays: assets.filter((a) => assetScenes[a.id]).map((a) => ({ asset: a, scene: assetScenes[a.id] })),
|
|
1761
|
-
onSelect: (sel) => {
|
|
1852
|
+
onSelect: (sel) => {
|
|
1853
|
+
applySelection(sel, false);
|
|
1854
|
+
detectSimilar(sel.kind, sel.id);
|
|
1855
|
+
},
|
|
1856
|
+
onSelectMulti: (sel) => {
|
|
1857
|
+
// Shift+点击:切换多选;不触发相同特征弹窗(多选本身就是手动选择)
|
|
1858
|
+
applySelection(sel, true);
|
|
1859
|
+
setSimilarPrompt(null);
|
|
1860
|
+
},
|
|
1762
1861
|
onAnnotate: (sel) => {
|
|
1763
1862
|
setModelSelected(sel);
|
|
1863
|
+
setModelSelectedSet([sel]);
|
|
1764
1864
|
setFeatureName('');
|
|
1765
1865
|
setFeatureNote('');
|
|
1766
1866
|
setEditingFeatureId(null);
|
|
@@ -1811,16 +1911,39 @@ window.__ModuleLoader__.load({
|
|
|
1811
1911
|
h('div', { style: { display: 'flex', gap: 6 } },
|
|
1812
1912
|
h('button', { style: btnPrimary, onClick: applyMainTransform }, '应用到位'),
|
|
1813
1913
|
h('button', { style: btn, onClick: resetMainTransform }, '复位'))),
|
|
1914
|
+
// 相同特征提示:检测到当前面/边有 N 个相同特征,可一键一起标注
|
|
1915
|
+
similarPrompt && !annotating
|
|
1916
|
+
? h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, padding: 8, marginTop: 6, borderRadius: 8, background: 'rgba(245,158,11,0.12)', border: '1px solid rgba(245,158,11,0.4)' } },
|
|
1917
|
+
h('span', { style: { flex: 1, fontSize: 11, color: '#92400e' } },
|
|
1918
|
+
'检测到当前' + (similarPrompt.kind === 'face' ? '面' : '边') + '有 ' + similarPrompt.count + ' ' + similarPrompt.label + ',是否一起标注?'),
|
|
1919
|
+
h('button', {
|
|
1920
|
+
onClick: () => {
|
|
1921
|
+
// 一起标注:把相同特征全部加入选中集合,并直接进入命名态
|
|
1922
|
+
const all = similarPrompt.ids.map((id) => ({ kind: similarPrompt.kind, id }));
|
|
1923
|
+
setModelSelectedSet(all);
|
|
1924
|
+
setModelSelected((similarPrompt.kind === 'face'
|
|
1925
|
+
? modelScene.faces.find((x) => x.id === similarPrompt.ids[0])
|
|
1926
|
+
: modelScene.edges.find((x) => x.id === similarPrompt.ids[0])) || { kind: similarPrompt.kind, id: similarPrompt.ids[0] });
|
|
1927
|
+
setFeatureName('');
|
|
1928
|
+
setFeatureNote('');
|
|
1929
|
+
setEditingFeatureId(null);
|
|
1930
|
+
setAnnotating(true);
|
|
1931
|
+
},
|
|
1932
|
+
style: { ...btnPrimary, fontSize: 11, padding: '3px 10px' },
|
|
1933
|
+
}, '一起标注'),
|
|
1934
|
+
h('button', { onClick: () => setSimilarPrompt(null), style: { ...btn, fontSize: 11, padding: '3px 10px' } }, '忽略'))
|
|
1935
|
+
: null,
|
|
1814
1936
|
modelSelected && annotating
|
|
1815
1937
|
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, padding: 8, marginTop: 6, borderRadius: 8, background: 'var(--dsw-alias-bg-layer-2, #f3f4f6)', border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)' } },
|
|
1816
1938
|
h('div', { style: { fontSize: 11, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #111)' } },
|
|
1817
|
-
(editingFeatureId ? '修改加工位置' : (modelSelected.kind === 'face' ? '标注加工面' : '标注加工边线')) + ' · 已选 #' + modelSelected.id
|
|
1939
|
+
(editingFeatureId ? '修改加工位置' : (modelSelected.kind === 'face' ? '标注加工面' : '标注加工边线')) + ' · 已选 #' + modelSelected.id
|
|
1940
|
+
+ (modelSelectedSet.length > 1 ? '(共 ' + modelSelectedSet.length + ' 个)' : '')),
|
|
1818
1941
|
h('div', { style: { display: 'flex', gap: 6 } },
|
|
1819
1942
|
h('input', { style: input, value: featureName, placeholder: '加工位置名称(必填)', onChange: (e) => setFeatureName(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter') addFeature(); } }),
|
|
1820
1943
|
h('input', { style: input, value: featureNote, placeholder: '备注(可选,如钻孔/铣面)', onChange: (e) => setFeatureNote(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter') addFeature(); } })),
|
|
1821
1944
|
h('div', { style: { display: 'flex', gap: 6, alignItems: 'center' } },
|
|
1822
1945
|
h('button', { style: btnPrimary, onClick: addFeature, disabled: busy }, editingFeatureId ? '保存修改' : '写入识别文件'),
|
|
1823
|
-
h('button', { style: btn, onClick: () => { setModelSelected(null); setAnnotating(false); setEditingFeatureId(null); } }, '取消')))
|
|
1946
|
+
h('button', { style: btn, onClick: () => { setModelSelected(null); setModelSelectedSet([]); setAnnotating(false); setEditingFeatureId(null); setSimilarPrompt(null); } }, '取消')))
|
|
1824
1947
|
: null,
|
|
1825
1948
|
// ---- 上传夹具 / 毛坯(供 AI 了解夹持与毛坯形状) ----
|
|
1826
1949
|
!setupCollapsed && h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, padding: 8, marginTop: 8, borderRadius: 8, background: 'var(--dsw-alias-bg-layer-2, #f3f4f6)', border: '1px solid var(--dsw-alias-border-l1, #e5e7eb)' } },
|
package/index.js
CHANGED
|
@@ -395,16 +395,22 @@ function saveFeatures(features) {
|
|
|
395
395
|
writeFileSync(FEATURE_FILE, JSON.stringify(features, null, 2), 'utf8');
|
|
396
396
|
} catch { /* ignore */ }
|
|
397
397
|
}
|
|
398
|
-
// append a named machining feature, keyed by model path; returns the updated list
|
|
398
|
+
// append a named machining feature, keyed by model path; returns the updated list.
|
|
399
|
+
// Supports batch annotate: feature.refIds (array) creates ONE feature record that
|
|
400
|
+
// points at multiple faces/edges (e.g. "4 个 Φ8 孔" 一起标注),feature.refId 为单个。
|
|
399
401
|
function appendFeature(modelPath, feature) {
|
|
400
402
|
const p = resolvePath(modelPath);
|
|
401
403
|
const all = loadFeatures();
|
|
402
404
|
const list = Array.isArray(all[p]) ? all[p] : [];
|
|
405
|
+
const refIds = Array.isArray(feature.refIds)
|
|
406
|
+
? feature.refIds.map((n) => Number(n) || 0).filter((n) => n > 0)
|
|
407
|
+
: [];
|
|
403
408
|
const item = {
|
|
404
409
|
id: feature.id ?? (Date.now().toString(36) + Math.random().toString(36).slice(2, 6)),
|
|
405
410
|
name: String(feature.name ?? '未命名'),
|
|
406
411
|
kind: feature.kind === 'edge' ? 'edge' : 'face',
|
|
407
|
-
refId: Number(feature.refId) || 0,
|
|
412
|
+
refId: refIds.length ? refIds[0] : (Number(feature.refId) || 0),
|
|
413
|
+
...(refIds.length ? { refIds } : {}),
|
|
408
414
|
note: String(feature.note ?? ''),
|
|
409
415
|
createdAt: feature.createdAt ?? new Date().toISOString(),
|
|
410
416
|
};
|
|
@@ -422,13 +428,22 @@ function updateFeature(modelPath, feature) {
|
|
|
422
428
|
const idx = list.findIndex((x) => x && x.id === feature.id);
|
|
423
429
|
if (idx < 0) return list;
|
|
424
430
|
const cur = list[idx];
|
|
425
|
-
|
|
431
|
+
const refIds = Array.isArray(feature.refIds)
|
|
432
|
+
? feature.refIds.map((n) => Number(n) || 0).filter((n) => n > 0)
|
|
433
|
+
: (Array.isArray(cur.refIds) ? cur.refIds : null);
|
|
434
|
+
const next = {
|
|
426
435
|
...cur,
|
|
427
436
|
name: feature.name !== undefined ? String(feature.name) : cur.name,
|
|
428
437
|
note: feature.note !== undefined ? String(feature.note) : cur.note,
|
|
429
438
|
kind: feature.kind === 'edge' ? 'edge' : (feature.kind === 'face' ? 'face' : cur.kind),
|
|
430
439
|
refId: feature.refId !== undefined ? Number(feature.refId) : cur.refId,
|
|
431
440
|
};
|
|
441
|
+
if (refIds && refIds.length > 1) {
|
|
442
|
+
next.refIds = refIds;
|
|
443
|
+
} else {
|
|
444
|
+
delete next.refIds;
|
|
445
|
+
}
|
|
446
|
+
list[idx] = next;
|
|
432
447
|
all[p] = list;
|
|
433
448
|
saveFeatures(all);
|
|
434
449
|
return list;
|
package/model_tessellate.py
CHANGED
|
@@ -5,18 +5,18 @@ Reuses the FreeCAD dependency already required by qizhouCNC_CAM: each solid
|
|
|
5
5
|
face is tessellated into its own triangle list (so the client can pick faces),
|
|
6
6
|
and every edge is discretized into a polyline (so the client can pick edges).
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
are
|
|
15
|
-
|
|
8
|
+
Two distinct per-element keys are emitted:
|
|
9
|
+
- a position-aware "merge key" (internal) — merges periodic surfaces split at
|
|
10
|
+
their seam (half cylinder/cone/sphere/torus) and half-circle edges back into
|
|
11
|
+
one pickable element. It MUST include position so two parallel holes never
|
|
12
|
+
merge (v1.3.15 fix).
|
|
13
|
+
- a position-INVARIANT "shapeKey" (emitted to the client) — groups faces/edges
|
|
14
|
+
that are the same FEATURE (e.g. four holes of the same diameter, or several
|
|
15
|
+
equal-size slots). The client uses it to offer "检测到 N 个相同特征,是否一起标注".
|
|
16
16
|
|
|
17
17
|
Output JSON is written to <out_path> so stdout stays clean.
|
|
18
18
|
"""
|
|
19
|
-
import os, sys, json
|
|
19
|
+
import os, sys, json
|
|
20
20
|
import FreeCAD, Part
|
|
21
21
|
|
|
22
22
|
|
|
@@ -29,8 +29,24 @@ def _pt(v):
|
|
|
29
29
|
return [round(float(v.x), 5), round(float(v.y), 5), round(float(v.z), 5)]
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def _vec3(v):
|
|
33
|
+
return (_r(v.x), _r(v.y), _r(v.z))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _axis(f):
|
|
37
|
+
"""Axis as a normalized 3-tuple, tolerant of the two half-surface axis directions
|
|
38
|
+
sometimes being negated relative to each other (still the same line)."""
|
|
39
|
+
a = f.Surface.Axis
|
|
40
|
+
ax = _vec3(a)
|
|
41
|
+
# canonicalize sign so +z and -z count as the same axis line
|
|
42
|
+
neg = tuple(-c for c in ax)
|
|
43
|
+
return ax if ax <= neg else neg
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ---- position-aware merge keys (used only internally, to rejoin seam splits) ----
|
|
47
|
+
|
|
32
48
|
def _surface_key(f):
|
|
33
|
-
"""
|
|
49
|
+
"""Identity of a periodic surface INCLUDING its position.
|
|
34
50
|
|
|
35
51
|
Returns None for non-periodic surfaces (planes etc.), which are never merged.
|
|
36
52
|
"""
|
|
@@ -38,31 +54,76 @@ def _surface_key(f):
|
|
|
38
54
|
t = type(s).__name__
|
|
39
55
|
try:
|
|
40
56
|
if t == 'Cylinder':
|
|
41
|
-
|
|
42
|
-
return ('cyl', _r(ax.x), _r(ax.y), _r(ax.z), _r(s.Radius))
|
|
57
|
+
return ('cyl', _vec3(s.Center), _axis(f), _r(s.Radius))
|
|
43
58
|
if t == 'Cone':
|
|
44
|
-
|
|
45
|
-
return ('cone', _r(ax.x), _r(ax.y), _r(ax.z), _r(s.SemiAngle))
|
|
59
|
+
return ('cone', _vec3(s.Center), _vec3(s.Apex), _axis(f), _r(s.SemiAngle))
|
|
46
60
|
if t == 'Sphere':
|
|
47
|
-
|
|
48
|
-
return ('sph', _r(c.x), _r(c.y), _r(c.z), _r(s.Radius))
|
|
61
|
+
return ('sph', _vec3(s.Center), _r(s.Radius))
|
|
49
62
|
if t == 'Toroid':
|
|
50
|
-
|
|
51
|
-
return ('tor', _r(ax.x), _r(ax.y), _r(ax.z), _r(s.MajorRadius), _r(s.MinorRadius))
|
|
63
|
+
return ('tor', _vec3(s.Center), _axis(f), _r(s.MajorRadius), _r(s.MinorRadius))
|
|
52
64
|
except Exception:
|
|
53
65
|
return None
|
|
54
66
|
return None
|
|
55
67
|
|
|
56
68
|
|
|
57
69
|
def _circle_key(e):
|
|
58
|
-
"""
|
|
70
|
+
"""Identity of a circle edge INCLUDING its position, or None."""
|
|
59
71
|
try:
|
|
60
72
|
c = e.Curve
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
except Exception:
|
|
74
|
+
return None
|
|
75
|
+
if c is None or not isinstance(c, Part.Circle):
|
|
76
|
+
return None
|
|
77
|
+
try:
|
|
78
|
+
return (_vec3(c.Center), _axis(e), _r(c.Radius))
|
|
79
|
+
except Exception:
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# ---- position-INVARIANT shape keys (emitted; group identical features) ----
|
|
84
|
+
|
|
85
|
+
def _face_shape_key(f):
|
|
86
|
+
"""A position-independent signature of a face's FEATURE type.
|
|
87
|
+
|
|
88
|
+
Two faces with the same shapeKey are "the same feature" (same size/shape),
|
|
89
|
+
just at a different location — e.g. two 8mm drilled holes, or two equal
|
|
90
|
+
pockets. Periodic surfaces key on their dimension params; planar faces key
|
|
91
|
+
on perimeter + area (a reasonable same-size/same-shape signature).
|
|
92
|
+
"""
|
|
93
|
+
s = f.Surface
|
|
94
|
+
t = type(s).__name__
|
|
95
|
+
try:
|
|
96
|
+
if t == 'Cylinder':
|
|
97
|
+
return 'cyl:r%.4f' % _r(s.Radius, 4)
|
|
98
|
+
if t == 'Cone':
|
|
99
|
+
return 'cone:r%.4f:a%.4f' % (_r(s.Radius, 4), _r(s.SemiAngle, 4))
|
|
100
|
+
if t == 'Sphere':
|
|
101
|
+
return 'sph:r%.4f' % _r(s.Radius, 4)
|
|
102
|
+
if t == 'Toroid':
|
|
103
|
+
return 'tor:R%.4f:r%.4f' % (_r(s.MajorRadius, 4), _r(s.MinorRadius, 4))
|
|
104
|
+
if t == 'Plane':
|
|
105
|
+
perim = sum(float(w.Length) for w in f.Wires)
|
|
106
|
+
return 'plane:p%.3f:a%.3f' % (_r(perim, 3), _r(f.Area, 3))
|
|
107
|
+
except Exception:
|
|
108
|
+
pass
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _edge_shape_key(e):
|
|
113
|
+
"""A position-independent signature of an edge's FEATURE type."""
|
|
114
|
+
try:
|
|
115
|
+
c = e.Curve
|
|
116
|
+
except Exception:
|
|
117
|
+
return None
|
|
118
|
+
if c is None:
|
|
119
|
+
return None
|
|
120
|
+
t = type(c).__name__
|
|
121
|
+
try:
|
|
122
|
+
if t == 'Circle':
|
|
123
|
+
return 'circle:r%.4f' % _r(c.Radius, 4)
|
|
124
|
+
if t == 'Line':
|
|
125
|
+
return 'line:l%.3f' % _r(e.Length, 3)
|
|
126
|
+
return 'edge:%s' % t
|
|
66
127
|
except Exception:
|
|
67
128
|
return None
|
|
68
129
|
|
|
@@ -79,7 +140,6 @@ def _discretize_full_circle(curve, tol):
|
|
|
79
140
|
return None
|
|
80
141
|
if not pts or len(pts) < 3:
|
|
81
142
|
return None
|
|
82
|
-
# ensure closed: repeat first point at the end
|
|
83
143
|
return [_pt(p) for p in pts] + [_pt(pts[0])]
|
|
84
144
|
|
|
85
145
|
|
|
@@ -88,9 +148,9 @@ def run(model_path, out_path, tol=0.1):
|
|
|
88
148
|
if shape is None:
|
|
89
149
|
raise RuntimeError("Could not read model: " + model_path)
|
|
90
150
|
|
|
91
|
-
# ---- 1) tessellate every face, remembering
|
|
92
|
-
raw_faces = []
|
|
93
|
-
for
|
|
151
|
+
# ---- 1) tessellate every face, remembering merge key + shape key ----
|
|
152
|
+
raw_faces = []
|
|
153
|
+
for f in shape.Faces:
|
|
94
154
|
try:
|
|
95
155
|
verts, tris = f.tessellate(tol)
|
|
96
156
|
except Exception:
|
|
@@ -114,11 +174,10 @@ def run(model_path, out_path, tol=0.1):
|
|
|
114
174
|
"triangles": [[int(t[0]), int(t[1]), int(t[2])] for t in tris],
|
|
115
175
|
"center": center,
|
|
116
176
|
"area": round(area, 3),
|
|
177
|
+
"shapeKey": _face_shape_key(f),
|
|
117
178
|
}))
|
|
118
179
|
|
|
119
180
|
# ---- 2) merge identical periodic faces (split cylinder/cone/sphere/torus) ----
|
|
120
|
-
# Only merge when >1 face shares a periodic identity (a genuine split);
|
|
121
|
-
# a single face is left untouched.
|
|
122
181
|
buckets = {}
|
|
123
182
|
order = []
|
|
124
183
|
for key, fd in raw_faces:
|
|
@@ -142,11 +201,11 @@ def run(model_path, out_path, tol=0.1):
|
|
|
142
201
|
faces.append({"id": fid, **group[0]})
|
|
143
202
|
fid += 1
|
|
144
203
|
continue
|
|
145
|
-
# merge several half-surfaces into one face
|
|
146
204
|
vertices = []
|
|
147
205
|
triangles = []
|
|
148
206
|
total_area = 0.0
|
|
149
207
|
wcenter = [0.0, 0.0, 0.0]
|
|
208
|
+
shape_key = group[0].get("shapeKey")
|
|
150
209
|
for g in group:
|
|
151
210
|
off = len(vertices)
|
|
152
211
|
vertices.extend(g["vertices"])
|
|
@@ -167,11 +226,12 @@ def run(model_path, out_path, tol=0.1):
|
|
|
167
226
|
"triangles": triangles,
|
|
168
227
|
"center": wcenter,
|
|
169
228
|
"area": round(total_area, 3),
|
|
229
|
+
"shapeKey": shape_key,
|
|
170
230
|
})
|
|
171
231
|
fid += 1
|
|
172
232
|
|
|
173
|
-
# ---- 3) discretize every edge, remembering
|
|
174
|
-
raw_edges = []
|
|
233
|
+
# ---- 3) discretize every edge, remembering merge key + shape key ----
|
|
234
|
+
raw_edges = []
|
|
175
235
|
for e in shape.Edges:
|
|
176
236
|
key = _circle_key(e)
|
|
177
237
|
try:
|
|
@@ -183,33 +243,33 @@ def run(model_path, out_path, tol=0.1):
|
|
|
183
243
|
continue
|
|
184
244
|
if not pts or len(pts) < 2:
|
|
185
245
|
continue
|
|
186
|
-
raw_edges.append((key, [_pt(p) for p in pts]))
|
|
246
|
+
raw_edges.append((key, [_pt(p) for p in pts], _edge_shape_key(e)))
|
|
187
247
|
|
|
188
248
|
# ---- 4) merge identical circle edges (split semicircles) into one loop ----
|
|
189
249
|
ebuckets = {}
|
|
190
250
|
eorder = []
|
|
191
|
-
for key, pts in raw_edges:
|
|
251
|
+
for key, pts, skey in raw_edges:
|
|
192
252
|
if key is None:
|
|
193
|
-
eorder.append(('solo', pts))
|
|
253
|
+
eorder.append(('solo', pts, skey))
|
|
194
254
|
continue
|
|
195
255
|
if key not in ebuckets:
|
|
196
256
|
ebuckets[key] = []
|
|
197
257
|
eorder.append(('circle', key))
|
|
198
|
-
ebuckets[key].append(pts)
|
|
258
|
+
ebuckets[key].append((pts, skey))
|
|
199
259
|
|
|
200
260
|
edges = []
|
|
201
261
|
eid = 1
|
|
202
|
-
for kind, payload in eorder:
|
|
262
|
+
for kind, payload, *rest in eorder:
|
|
203
263
|
if kind == 'solo':
|
|
204
|
-
edges.append({"id": eid, "points": payload})
|
|
264
|
+
edges.append({"id": eid, "points": payload, "shapeKey": rest[0]})
|
|
205
265
|
eid += 1
|
|
206
266
|
continue
|
|
207
267
|
group = ebuckets[payload]
|
|
268
|
+
skey = group[0][1]
|
|
208
269
|
if len(group) == 1:
|
|
209
|
-
edges.append({"id": eid, "points": group[0]})
|
|
270
|
+
edges.append({"id": eid, "points": group[0][0], "shapeKey": skey})
|
|
210
271
|
eid += 1
|
|
211
272
|
continue
|
|
212
|
-
# re-discretize as one full circle using the first member's curve
|
|
213
273
|
curve = None
|
|
214
274
|
for e in shape.Edges:
|
|
215
275
|
if _circle_key(e) == payload:
|
|
@@ -217,13 +277,12 @@ def run(model_path, out_path, tol=0.1):
|
|
|
217
277
|
break
|
|
218
278
|
merged = _discretize_full_circle(curve, tol) if curve is not None else None
|
|
219
279
|
if merged is None:
|
|
220
|
-
# fallback: concatenate the half loops (dedup endpoints)
|
|
221
280
|
merged = []
|
|
222
|
-
for pts in group:
|
|
281
|
+
for pts, _ in group:
|
|
223
282
|
for p in pts:
|
|
224
283
|
if not merged or merged[-1] != p:
|
|
225
284
|
merged.append(p)
|
|
226
|
-
edges.append({"id": eid, "points": merged})
|
|
285
|
+
edges.append({"id": eid, "points": merged, "shapeKey": skey})
|
|
227
286
|
eid += 1
|
|
228
287
|
|
|
229
288
|
bb = shape.BoundBox
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-qizhoucnc-cam",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"description": "CNC program (NC/CNC/G-code) toolpath recognition, 3D toolpath + 3D STEP model viewport (face/edge machining-position annotation), and a large editing view with quote-to-composer, for DeepSeek Harness (DSH). Made by Chengdu Qizhou Machinery Technology Co., Ltd., for research and study only.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|