dsh-cad-studio 0.10.0 → 0.11.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.
Files changed (2) hide show
  1. package/index.js +7 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2333,6 +2333,7 @@ else:
2333
2333
  code: { type: 'string', description: 'FreeCAD Python that binds `scene` or `export_shapes`.' },
2334
2334
  from: { type: 'array', items: { type: 'number' }, description: 'First point [x,y,z] for a distance measurement.' },
2335
2335
  to: { type: 'array', items: { type: 'number' }, description: 'Second point [x,y,z].' },
2336
+ density: { type: 'number', description: 'Material density in g/cm3 (e.g. 2.70 aluminium, 1.24 PLA, 7.85 steel) — adds mass in grams.' },
2336
2337
  },
2337
2338
  additionalProperties: false,
2338
2339
  },
@@ -2340,7 +2341,7 @@ else:
2340
2341
  schema: { type: 'object', properties: { ok: { type: 'boolean' }, volume: { type: 'number' }, area: { type: 'number' } } },
2341
2342
  render: (_a, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }],
2342
2343
  },
2343
- execute: async ({ source, code, from, to }) => {
2344
+ execute: async ({ source, code, from, to, density }) => {
2344
2345
  if (!source && !code) return { ok: false, error: 'pass either source (a model file) or code (FreeCAD Python)' }
2345
2346
  const src = shapesFrom({ source, code })
2346
2347
  const pair = Array.isArray(from) && Array.isArray(to) && from.length === 3 && to.length === 3
@@ -2362,6 +2363,11 @@ else:
2362
2363
  "faces": sum(len(x.Faces) for x in _shapes),
2363
2364
  "edges": sum(len(x.Edges) for x in _shapes),
2364
2365
  }
2366
+ _rho = float(${Number.isFinite(density) ? density : 0})
2367
+ if _rho > 0:
2368
+ # volume is mm3; 1000 mm3 = 1 cm3, density is g/cm3
2369
+ __out["density_g_cm3"] = _rho
2370
+ __out["mass_g"] = round(sum(x.Volume for x in _shapes) / 1000.0 * _rho, 3)
2365
2371
  ${pair ? ` __out["distance"] = round((FreeCAD.Vector(${JSON.stringify(from)}) - FreeCAD.Vector(${JSON.stringify(to)})).Length, 3)` : ''}
2366
2372
  `
2367
2373
  return bridge.run(py, { title: 'measure', publishHint: false })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cad-studio",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "CAD Studio — FreeCAD 桥(给 AI 的 14 个工具)+ Web 右栏 3D 面板:建模/装配/关节运动/出图/多页签查看",
6
6
  "exports": {