dsh-cad-studio 0.15.0 → 0.16.0
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/README.md +1 -0
- package/index.js +76 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ DeepSeek Harness 的 CAD 插件:**把 FreeCAD 桥接成给 AI 用的工具**
|
|
|
21
21
|
| 模型清单 | `cad_studio_scene`(`action: list / delete / rename`)——面板里那条列表就是它;探查脚本留下的卡片可以直接删 |
|
|
22
22
|
| 模型改名 / 复制 | `cad_studio_doc {action:"rename", name, to}` 与 `{action:"duplicate", name, to}`:改名会同步列表里的标题与 `docKey`,复制会得到一条独立的新场景(副本不继承运行历史与撤销栈);两者都可 `cad_studio_undo` 回退 |
|
|
23
23
|
| 几何自检 | `cad_studio_check {source}` 在导出/打印前问一次:是否有效实体、外壳是否闭合、每个实体体积多少,返回中文问题清单(零体积 / 外壳未闭合 / 几何无效 / 没有实体) |
|
|
24
|
+
| 打印网格 | `cad_studio_mesh {source, target:"…/x.stl"}` 三角化 + 去重合并点/面、修形变、统一法向,可选 `fillHoles`、`targetSize`(减面);回报修复前后的 facets/points,避免「导出成功但网格是碎的」 |
|
|
24
25
|
| 旋转体与凹槽 | `revolve` 的 `axis` 取草图平面内的轴(`"Y"` 或 `[0,1,0]`)才是实体;垂直轴(XY 草图的 Z)只会扫出零厚度圆环,插件会直接报错。凹槽=`{kind:"cut", with:{kind:"revolve", …}}`,不需要单独 op |
|
|
25
26
|
| 特征 → STEP | `cad_studio_export {model:"名字", target:"…/x.step"}` 或 `cad_studio_doc {action:"show", name, export:"…/x.step"}`;特征列表是源,STEP 是产物,不用自己复刻发射器 |
|
|
26
27
|
| 旧 dsh-cad 文档 | `cad_studio_legacy`(`action: list / show`)只读列出 `/app/.dsh-cad` 的文档、op 数与体数 |
|
package/index.js
CHANGED
|
@@ -1093,6 +1093,7 @@ print("${BEGIN}" + __json.dumps(_safe(_payload)) + "${END}", flush=True)\n`
|
|
|
1093
1093
|
const PRELUDE = `
|
|
1094
1094
|
import json, math
|
|
1095
1095
|
import Part, Import, FreeCAD
|
|
1096
|
+
import Mesh, MeshPart # only used by cad_studio_mesh, but a missing import here fails the whole job
|
|
1096
1097
|
Vector = FreeCAD.Vector
|
|
1097
1098
|
|
|
1098
1099
|
def _safe(v):
|
|
@@ -2450,6 +2451,81 @@ __out = {
|
|
|
2450
2451
|
},
|
|
2451
2452
|
})
|
|
2452
2453
|
|
|
2454
|
+
tool({
|
|
2455
|
+
name: 'cad_studio_mesh',
|
|
2456
|
+
description: 'Turn a solid into a printable mesh and clean it up: dedupe coincident points/facets, fix deformations, harmonize normals, optionally fill small holes or decimate to a facet budget, then write an STL. Reports facets/points before and after so you can see what the repair actually changed.',
|
|
2457
|
+
parameters: {
|
|
2458
|
+
type: 'object',
|
|
2459
|
+
properties: {
|
|
2460
|
+
source: { type: 'string', description: 'Existing model file (STEP/IGES/BREP/STL).' },
|
|
2461
|
+
code: { type: 'string', description: 'FreeCAD Python that binds `scene` or `export_shapes`.' },
|
|
2462
|
+
target: { type: 'string', description: 'Write the STL here (absolute path).' },
|
|
2463
|
+
deflection: { type: 'number', description: 'Linear deflection in mm (smaller = finer, default 0.2).' },
|
|
2464
|
+
angular: { type: 'number', description: 'Angular deflection in radians (default 0.5).' },
|
|
2465
|
+
targetSize: { type: 'integer', description: 'Decimate down to at most this many facets (optional).' },
|
|
2466
|
+
fillHoles: { type: 'number', description: 'Fill holes whose edges are shorter than this many mm (0 = skip, default 0).' },
|
|
2467
|
+
repair: { type: 'boolean', description: 'Dedupe points/facets, fix deformations, harmonize normals (default true).' },
|
|
2468
|
+
},
|
|
2469
|
+
additionalProperties: false,
|
|
2470
|
+
},
|
|
2471
|
+
output: {
|
|
2472
|
+
schema: { type: 'object', properties: { ok: { type: 'boolean' }, facets: { type: 'number' }, points: { type: 'number' }, bytes: { type: 'number' } } },
|
|
2473
|
+
render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }],
|
|
2474
|
+
},
|
|
2475
|
+
execute: async ({ source, code, target, deflection, angular, targetSize, fillHoles, repair }) => {
|
|
2476
|
+
if (!source && !code) return { ok: false, error: 'pass either source (a model file) or code (FreeCAD Python)' }
|
|
2477
|
+
if (!target) return { ok: false, error: 'target 是必填的:STL 写到哪里' }
|
|
2478
|
+
const defl = Number.isFinite(deflection) ? Number(deflection) : 0.2
|
|
2479
|
+
const ang = Number.isFinite(angular) ? Number(angular) : 0.5
|
|
2480
|
+
const size = Number.isInteger(targetSize) && targetSize > 0 ? targetSize : 0
|
|
2481
|
+
const hole = Number.isFinite(fillHoles) ? Number(fillHoles) : 0
|
|
2482
|
+
const doRepair = repair !== false
|
|
2483
|
+
const src = shapesFrom({ source, code })
|
|
2484
|
+
// Meshing is a different pipeline from the BRep checks: a shape can be a
|
|
2485
|
+
// valid solid and still mesh into duplicated points / flipped normals.
|
|
2486
|
+
const py = `${PRELUDE}
|
|
2487
|
+
${src}
|
|
2488
|
+
if not _shapes:
|
|
2489
|
+
__out = {"ok": False, "error": "nothing to mesh"}
|
|
2490
|
+
else:
|
|
2491
|
+
_body = _shapes[0] if len(_shapes) == 1 else Part.makeCompound(_shapes)
|
|
2492
|
+
_m = MeshPart.meshFromShape(Shape=_body, LinearDeflection=${JSON.stringify(defl)}, AngularDeflection=${JSON.stringify(ang)}, Relative=False)
|
|
2493
|
+
_before = {"facets": int(_m.CountFacets), "points": int(_m.CountPoints)}
|
|
2494
|
+
if ${doRepair ? 'True' : 'False'}:
|
|
2495
|
+
_m.removeDuplicatedPoints()
|
|
2496
|
+
_m.removeDuplicatedFacets()
|
|
2497
|
+
try:
|
|
2498
|
+
_m.fixDeformations()
|
|
2499
|
+
except Exception:
|
|
2500
|
+
pass
|
|
2501
|
+
_m.harmonizeNormals()
|
|
2502
|
+
if ${JSON.stringify(hole)} > 0:
|
|
2503
|
+
_m.fillupHoles(${JSON.stringify(hole)})
|
|
2504
|
+
_mid = {"facets": int(_m.CountFacets), "points": int(_m.CountPoints)}
|
|
2505
|
+
_decimated = False
|
|
2506
|
+
if ${JSON.stringify(size)} and _m.CountFacets > ${JSON.stringify(size)}:
|
|
2507
|
+
_m.decimate(${JSON.stringify(size)})
|
|
2508
|
+
_decimated = True
|
|
2509
|
+
_m.write(${JSON.stringify(String(target))})
|
|
2510
|
+
import os
|
|
2511
|
+
_bb = _body.BoundBox
|
|
2512
|
+
__out = {
|
|
2513
|
+
"ok": True,
|
|
2514
|
+
"target": ${JSON.stringify(String(target))},
|
|
2515
|
+
"bytes": int(os.path.getsize(${JSON.stringify(String(target))})),
|
|
2516
|
+
"facets": int(_m.CountFacets),
|
|
2517
|
+
"points": int(_m.CountPoints),
|
|
2518
|
+
"before": _before,
|
|
2519
|
+
"afterRepair": _mid,
|
|
2520
|
+
"decimated": _decimated,
|
|
2521
|
+
"repaired": ${doRepair ? 'True' : 'False'},
|
|
2522
|
+
"bbox": [round(_bb.XLength, 2), round(_bb.YLength, 2), round(_bb.ZLength, 2)],
|
|
2523
|
+
}
|
|
2524
|
+
`
|
|
2525
|
+
return bridge.run(py, { title: 'mesh', publishHint: false })
|
|
2526
|
+
},
|
|
2527
|
+
})
|
|
2528
|
+
|
|
2453
2529
|
tool({
|
|
2454
2530
|
name: 'cad_studio_section',
|
|
2455
2531
|
description: `Cross-section of a solid: slice it with a plane and report closed loops, area and perimeter; optionally write the outline as SVG (for laser/CNC nesting). Axis is X/Y/Z, at is the plane offset in mm.`,
|