dsh-cad-studio 0.2.0 → 0.2.2
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 +7 -1
- package/client.js +132 -33
- package/index.js +54 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,10 +31,16 @@ DeepSeek Harness 的 CAD 插件:**把 FreeCAD 桥接成给 AI 用的工具**
|
|
|
31
31
|
2. **自己装**:`apt install freecad`,然后在插件配置里留空 `freecadPath`(自动探测 `/usr/bin/freecadcmd` 等 5 个位置)或显式指定。
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
+
# 从 npm 装(推荐)
|
|
35
|
+
dsh plugin --profile web add dsh-cad-studio
|
|
36
|
+
|
|
37
|
+
# 或从源码目录装
|
|
34
38
|
dsh plugin --profile web add /path/to/dsh-cad-studio
|
|
35
|
-
#
|
|
39
|
+
# 装完重启 dsh 使 host 侧工具挂载;client 侧刷新页面即可
|
|
36
40
|
```
|
|
37
41
|
|
|
42
|
+
npm 包:<https://www.npmjs.com/package/dsh-cad-studio>(`dsh plugin` / DSH 插件市场按包名解析,发布到 npm 即可被装到)。
|
|
43
|
+
|
|
38
44
|
配置项(cordis 配置):
|
|
39
45
|
|
|
40
46
|
| 键 | 默认 | 说明 |
|
package/client.js
CHANGED
|
@@ -100,7 +100,13 @@ window.__ModuleLoader__.load({
|
|
|
100
100
|
background: 'transparent', color: skin.color, fontSize: 12, lineHeight: 1,
|
|
101
101
|
cursor: 'pointer',
|
|
102
102
|
}),
|
|
103
|
-
tabs: { display: 'flex', alignItems: 'center', gap: 3, flex: '1 1 auto', minWidth: 0, overflow: '
|
|
103
|
+
tabs: { position: 'relative', display: 'flex', alignItems: 'center', gap: 3, flex: '1 1 auto', minWidth: 0, overflow: 'visible', '--cad-tab-basis': 'calc((100% - 50px - 26px - 18px) / 5)' },
|
|
104
|
+
// Anchor the "+" menu to the strip's right edge: because "+" is the
|
|
105
|
+
// last thing in the row, this keeps the menu hanging off that button
|
|
106
|
+
// as tabs open and close.
|
|
107
|
+
addMenu: { position: 'absolute', top: 'calc(100% + 4px)', zIndex: 40, width: 224, maxHeight: 300, overflowY: 'auto', display: 'flex', flexDirection: 'column', padding: 3, borderRadius: 8, border: '1px solid', boxShadow: '0 10px 26px rgba(0,0,0,.32)' },
|
|
108
|
+
addRow: (active) => ({ display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0, padding: '5px 7px', borderRadius: 6, border: 'none', background: active ? 'rgba(77,107,254,.16)' : 'transparent', textAlign: 'left', cursor: 'pointer', font: 'inherit' }),
|
|
109
|
+
addHint: { padding: '6px 8px', fontSize: 10.5, opacity: 0.6 },
|
|
104
110
|
// A model tab is laid out at the width it would have with five tabs open
|
|
105
111
|
// (--cad-tab-basis on the strip), so adding the first one does not stretch
|
|
106
112
|
// it across the whole strip and the row never reflows as tabs come and go.
|
|
@@ -1191,6 +1197,14 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1191
1197
|
const activityRef = useRef(null)
|
|
1192
1198
|
const [fresh, setFresh] = useState(false)
|
|
1193
1199
|
const seenRef = useRef('')
|
|
1200
|
+
// "+" owns its own dropdown (it is anchored to the button); the rail's
|
|
1201
|
+
// folder opens the models panel, where a click switches the model shown
|
|
1202
|
+
// by the current view instead of opening another tab.
|
|
1203
|
+
const [addOpen, setAddOpen] = useState(false)
|
|
1204
|
+
const [addAlign, setAddAlign] = useState('left')
|
|
1205
|
+
const addBtnRef = useRef(null)
|
|
1206
|
+
const [activityPin, setActivityPin] = useState(null)
|
|
1207
|
+
const activityPinRef = useRef(null)
|
|
1194
1208
|
const [picked, setPicked] = useState('')
|
|
1195
1209
|
const revealedRef = useRef('')
|
|
1196
1210
|
const [payload, setPayload] = useState(null)
|
|
@@ -1296,6 +1310,35 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1296
1310
|
showScene(scene, { tabKey })
|
|
1297
1311
|
}
|
|
1298
1312
|
|
|
1313
|
+
/**
|
|
1314
|
+
* The folder's click: change what the current view shows, in place.
|
|
1315
|
+
* A focused model tab is retargeted to the picked model (same tab, no
|
|
1316
|
+
* new one); on the live tab the pick is pinned there until the session
|
|
1317
|
+
* publishes something new, at which point the live view takes over
|
|
1318
|
+
* again.
|
|
1319
|
+
*/
|
|
1320
|
+
const switchModel = async (id) => {
|
|
1321
|
+
if (!id) return
|
|
1322
|
+
const scene = await loadScene(id)
|
|
1323
|
+
if (!scene) return
|
|
1324
|
+
const meta = scenes.find((sc) => sc.id === id) || { id, title: scene.title || id }
|
|
1325
|
+
const title = shortName(meta) || id
|
|
1326
|
+
rememberView(activeRef.current, payloadRef.current)
|
|
1327
|
+
const tab = openTabsRef.current.find((t) => t.key === activeRef.current)
|
|
1328
|
+
if (tab) {
|
|
1329
|
+
const next = openTabsRef.current.map((t) => (t.key === tab.key ? { ...t, id, title } : t))
|
|
1330
|
+
openTabsRef.current = next
|
|
1331
|
+
setOpenTabs(next)
|
|
1332
|
+
showScene(scene, { tabKey: tab.key })
|
|
1333
|
+
return
|
|
1334
|
+
}
|
|
1335
|
+
const pin = { id, title }
|
|
1336
|
+
activityPinRef.current = pin
|
|
1337
|
+
setActivityPin(pin)
|
|
1338
|
+
setFresh(false)
|
|
1339
|
+
showScene(scene, { tabKey: 'activity' })
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1299
1342
|
const focusTab = async (key) => {
|
|
1300
1343
|
if (key === activeRef.current) return
|
|
1301
1344
|
rememberView(activeRef.current, payloadRef.current)
|
|
@@ -1352,6 +1395,25 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1352
1395
|
}
|
|
1353
1396
|
}, [payload])
|
|
1354
1397
|
|
|
1398
|
+
// The "+" dropdown is a transient popover: Esc or a click anywhere else
|
|
1399
|
+
// dismisses it (the folder panel behind it is the one that stays put).
|
|
1400
|
+
useEffect(() => {
|
|
1401
|
+
if (!addOpen) return undefined
|
|
1402
|
+
const onDown = (event) => {
|
|
1403
|
+
const el = event.target
|
|
1404
|
+
if (!el || typeof el.closest !== 'function') return
|
|
1405
|
+
if (el.closest('[data-cad-addmenu]') || el.closest('[data-cad-tab-add]')) return
|
|
1406
|
+
setAddOpen(false)
|
|
1407
|
+
}
|
|
1408
|
+
const onKey = (event) => { if (event.key === 'Escape') setAddOpen(false) }
|
|
1409
|
+
document.addEventListener('mousedown', onDown, true)
|
|
1410
|
+
document.addEventListener('keydown', onKey, true)
|
|
1411
|
+
return () => {
|
|
1412
|
+
document.removeEventListener('mousedown', onDown, true)
|
|
1413
|
+
document.removeEventListener('keydown', onKey, true)
|
|
1414
|
+
}
|
|
1415
|
+
}, [addOpen])
|
|
1416
|
+
|
|
1355
1417
|
useEffect(() => {
|
|
1356
1418
|
let alive = true
|
|
1357
1419
|
const tick = async () => {
|
|
@@ -1386,24 +1448,31 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1386
1448
|
setActivity(act)
|
|
1387
1449
|
}
|
|
1388
1450
|
if (!actId) return
|
|
1389
|
-
|
|
1451
|
+
// A model updates in place: same scene id, new timestamp. Watch the
|
|
1452
|
+
// pair so driving a joint refreshes the viewport instead of being
|
|
1453
|
+
// mistaken for "nothing changed".
|
|
1454
|
+
const stamp = `${actId}@${(act && act.at) || ''}`
|
|
1455
|
+
// Something new was published by this session: the pinned model on
|
|
1456
|
+
// the live tab goes back to following the session.
|
|
1457
|
+
if (activityPinRef.current && activityPinRef.current.id !== actId) {
|
|
1458
|
+
activityPinRef.current = null
|
|
1459
|
+
setActivityPin(null)
|
|
1460
|
+
}
|
|
1461
|
+
if (stamp !== seenRef.current) {
|
|
1390
1462
|
const had = Boolean(seenRef.current)
|
|
1391
|
-
seenRef.current =
|
|
1392
|
-
|
|
1463
|
+
seenRef.current = stamp
|
|
1464
|
+
const focused = openTabsRef.current.find((t) => t.key === activeRef.current)
|
|
1465
|
+
const showsIt = activeRef.current === 'activity' || (focused && focused.id === actId)
|
|
1466
|
+
if (showsIt) {
|
|
1467
|
+
const tabKey = activeRef.current
|
|
1393
1468
|
const scene = await loadScene(actId)
|
|
1394
|
-
if (scene && alive && activeRef.current ===
|
|
1395
|
-
rememberView(
|
|
1396
|
-
showScene(scene, { tabKey
|
|
1469
|
+
if (scene && alive && activeRef.current === tabKey) {
|
|
1470
|
+
rememberView(tabKey, payloadRef.current)
|
|
1471
|
+
showScene(scene, { tabKey })
|
|
1397
1472
|
}
|
|
1398
1473
|
} else if (had) {
|
|
1399
1474
|
setFresh(true) // a model tab is focused: flag that activity moved on
|
|
1400
1475
|
}
|
|
1401
|
-
} else if (activeRef.current === 'activity' && visibleIdRef.current !== actId) {
|
|
1402
|
-
const scene = await loadScene(actId)
|
|
1403
|
-
if (scene && alive && activeRef.current === 'activity') {
|
|
1404
|
-
rememberView('activity', payloadRef.current)
|
|
1405
|
-
showScene(scene, { tabKey: 'activity' })
|
|
1406
|
-
}
|
|
1407
1476
|
}
|
|
1408
1477
|
} catch (err) {
|
|
1409
1478
|
const msg = String((err && err.message) || err)
|
|
@@ -1512,9 +1581,10 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1512
1581
|
// The scene payload carries its own assembly block, so the panel never
|
|
1513
1582
|
// guesses which joints belong to what it is looking at.
|
|
1514
1583
|
const assembly = payload && payload.assembly ? payload.assembly : null
|
|
1515
|
-
const applyScene = async (id) => {
|
|
1584
|
+
const applyScene = async (id, at) => {
|
|
1516
1585
|
const scene = await loadScene(id)
|
|
1517
1586
|
if (!scene) return
|
|
1587
|
+
if (at) seenRef.current = `${id}@${at}`
|
|
1518
1588
|
// Driving a joint or the explode slider is an action the user took on
|
|
1519
1589
|
// the model they are looking at, so that tab follows the republished
|
|
1520
1590
|
// scene; the live tab keeps following the session instead.
|
|
@@ -1538,7 +1608,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1538
1608
|
})
|
|
1539
1609
|
if (!res.ok) return null
|
|
1540
1610
|
const out = await res.json()
|
|
1541
|
-
if (out && out.sceneId) await applyScene(out.sceneId)
|
|
1611
|
+
if (out && out.sceneId) await applyScene(out.sceneId, out.at)
|
|
1542
1612
|
return out
|
|
1543
1613
|
} catch { return null }
|
|
1544
1614
|
}
|
|
@@ -1638,7 +1708,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
1638
1708
|
return null
|
|
1639
1709
|
}
|
|
1640
1710
|
setFeatError('')
|
|
1641
|
-
if (out.sceneId) await applyScene(out.sceneId)
|
|
1711
|
+
if (out.sceneId) await applyScene(out.sceneId, out.at)
|
|
1642
1712
|
return out
|
|
1643
1713
|
} catch (error) {
|
|
1644
1714
|
setFeatError(String((error && error.message) || error))
|
|
@@ -2150,8 +2220,8 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2150
2220
|
type: 'button',
|
|
2151
2221
|
'data-cad-scene': sc.id,
|
|
2152
2222
|
style: styles.modelRow(sc.id === activeModel),
|
|
2153
|
-
title:
|
|
2154
|
-
onClick: () => {
|
|
2223
|
+
title: `切换到 ${shortName(sc)}(替换当前视图里的模型,不新开页签)`,
|
|
2224
|
+
onClick: () => { switchModel(sc.id) },
|
|
2155
2225
|
}, [
|
|
2156
2226
|
h('span', { key: 'n', style: { ...styles.modelName, fontWeight: sc.id === activeModel ? 600 : 400 } }, shortName(sc)),
|
|
2157
2227
|
h('span', { key: 'm', style: styles.modelMeta }, `${(sc.at ? new Date(sc.at).toLocaleTimeString('zh-CN', { hour12: false }) : '')} · ${sc.instances || 0} 实例 · ${sc.parts || 0} 零件`),
|
|
@@ -2226,20 +2296,49 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2226
2296
|
}, '×')
|
|
2227
2297
|
: null,
|
|
2228
2298
|
])),
|
|
2229
|
-
// "+"
|
|
2230
|
-
//
|
|
2231
|
-
//
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2299
|
+
// "+" is its own control with its own dropdown, anchored to the
|
|
2300
|
+
// button: the rail's folder switches the current model in place and
|
|
2301
|
+
// stays open, "+" always makes a new tab and closes itself.
|
|
2302
|
+
h('span', { key: 'addwrap', style: { position: 'relative', display: 'inline-flex', flex: '0 0 auto' } }, [
|
|
2303
|
+
openTabs.length < MAX_TABS
|
|
2304
|
+
? h('button', {
|
|
2305
|
+
key: 'add',
|
|
2306
|
+
type: 'button',
|
|
2307
|
+
'data-cad-tab-add': '1',
|
|
2308
|
+
'aria-label': '新增模型页签',
|
|
2309
|
+
'aria-expanded': addOpen ? 'true' : 'false',
|
|
2310
|
+
style: { ...styles.barBtn(panelSkin), marginLeft: 2 },
|
|
2311
|
+
title: `新开一个模型页签(每次选一个模型就加一个,最多 ${MAX_TABS} 个)`,
|
|
2312
|
+
ref: addBtnRef,
|
|
2313
|
+
onClick: () => {
|
|
2314
|
+
// Open toward whichever side has room, so the menu never
|
|
2315
|
+
// lands under the page content beside the pane.
|
|
2316
|
+
const rect = addBtnRef.current ? addBtnRef.current.getBoundingClientRect() : null
|
|
2317
|
+
setAddAlign(rect && rect.right + 232 > window.innerWidth ? 'right' : 'left')
|
|
2318
|
+
setAddOpen((open) => !open)
|
|
2319
|
+
},
|
|
2320
|
+
}, '+')
|
|
2321
|
+
: null,
|
|
2322
|
+
addOpen
|
|
2323
|
+
? h('div', {
|
|
2324
|
+
key: 'addmenu',
|
|
2325
|
+
'data-cad-addmenu': '1',
|
|
2326
|
+
style: { ...styles.addMenu, ...(addAlign === 'right' ? { right: 0, left: 'auto' } : { left: 0, right: 'auto' }), background: panelSkin.background, borderColor: panelSkin.borderColor, color: panelSkin.color },
|
|
2327
|
+
}, scenes.length
|
|
2328
|
+
? scenes.map((sc) => h('button', {
|
|
2329
|
+
key: sc.id,
|
|
2330
|
+
type: 'button',
|
|
2331
|
+
'data-cad-add-scene': sc.id,
|
|
2332
|
+
style: styles.addRow(sc.id === activeModel),
|
|
2333
|
+
title: `${shortName(sc)}(${sc.instances || 0} 实例 · ${sc.parts || 0} 零件)`,
|
|
2334
|
+
onClick: () => { setAddOpen(false); openModel(sc.id) },
|
|
2335
|
+
}, [
|
|
2336
|
+
h('span', { key: 'n', style: { ...styles.modelName, fontWeight: sc.id === activeModel ? 600 : 400 } }, shortName(sc)),
|
|
2337
|
+
h('span', { key: 'm', style: styles.modelMeta }, `${sc.instances || 0} 实例 · ${sc.parts || 0} 零件`),
|
|
2338
|
+
]))
|
|
2339
|
+
: h('div', { key: 'none', style: styles.addHint }, '还没有别的模型'))
|
|
2340
|
+
: null,
|
|
2341
|
+
]),
|
|
2243
2342
|
]),
|
|
2244
2343
|
]),
|
|
2245
2344
|
error ? h('div', { key: 'err', style: styles.warn }, error) : null,
|
|
@@ -2256,7 +2355,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
|
|
|
2256
2355
|
'data-cad-rail': item.id,
|
|
2257
2356
|
'aria-pressed': panel === item.id ? 'true' : 'false',
|
|
2258
2357
|
title: item.label,
|
|
2259
|
-
onClick: () => setPanel((p) => (p === item.id ? '' : item.id)),
|
|
2358
|
+
onClick: () => { setAddOpen(false); setPanel((p) => (p === item.id ? '' : item.id)) },
|
|
2260
2359
|
}, h(RailIcon, { name: item.id })))),
|
|
2261
2360
|
h('div', { key: 'main', style: { flex: '1 1 auto', minWidth: 0, position: 'relative', display: 'flex', flexDirection: 'column' } }, [
|
|
2262
2361
|
payload
|
package/index.js
CHANGED
|
@@ -451,8 +451,17 @@ class FreeCadBridge {
|
|
|
451
451
|
} catch {}
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
-
|
|
454
|
+
/**
|
|
455
|
+
* Publish a scene for the panel to show.
|
|
456
|
+
*
|
|
457
|
+
* `opts.docKey` names the *model* the scene belongs to (an assembly, a
|
|
458
|
+
* feature model). Re-publishing the same docKey updates that model in place —
|
|
459
|
+
* same scene id, same list row, fresh geometry — instead of stacking a new
|
|
460
|
+
* entry in the models list every time a joint is dragged.
|
|
461
|
+
*/
|
|
462
|
+
async publishScene(scene, title, session = this.currentSession ?? '', opts = {}) {
|
|
455
463
|
if (session) this.lastSession = session
|
|
464
|
+
const docKey = typeof opts.docKey === 'string' ? opts.docKey : ''
|
|
456
465
|
await this.hydrateHistory()
|
|
457
466
|
// Scene ids are the on-disk filenames: after a restart the counter must
|
|
458
467
|
// resume above whatever is already published, or the first new scene would
|
|
@@ -467,7 +476,14 @@ class FreeCadBridge {
|
|
|
467
476
|
}
|
|
468
477
|
} catch {}
|
|
469
478
|
}
|
|
470
|
-
|
|
479
|
+
let id = ''
|
|
480
|
+
if (docKey) {
|
|
481
|
+
const prev = this.history.find((h) => h.docKey === docKey)
|
|
482
|
+
if (prev) id = prev.id
|
|
483
|
+
}
|
|
484
|
+
if (!id && typeof opts.id === 'string' && /^scene-\d+$/.test(opts.id)) id = opts.id
|
|
485
|
+
if (!id) id = `scene-${++this.seq}`
|
|
486
|
+
else this.seq = Math.max(this.seq, Number(id.slice('scene-'.length)))
|
|
471
487
|
this.scenes.set(id, scene)
|
|
472
488
|
// Count what the viewport shows: per-instance totals and only the parts an
|
|
473
489
|
// instance actually references (a scene may carry unreferenced parts).
|
|
@@ -491,6 +507,7 @@ class FreeCadBridge {
|
|
|
491
507
|
parts: usedParts.size,
|
|
492
508
|
triangles,
|
|
493
509
|
volume,
|
|
510
|
+
...(docKey ? { docKey } : {}),
|
|
494
511
|
}
|
|
495
512
|
this.history = [stats, ...this.history.filter((h) => h.id !== id)].slice(0, 30)
|
|
496
513
|
this.latest = { id, title, at: stats.at, scene }
|
|
@@ -500,9 +517,16 @@ class FreeCadBridge {
|
|
|
500
517
|
return { id, stats }
|
|
501
518
|
}
|
|
502
519
|
|
|
520
|
+
/** Reserve the id before publishing, so the scene can carry `asm:<id>`. */
|
|
521
|
+
reserveAssemblyId() {
|
|
522
|
+
return `asm-${++this.assemblySeq}`
|
|
523
|
+
}
|
|
524
|
+
|
|
503
525
|
/** Register the base placements of a published assembly so joints can move it. */
|
|
504
|
-
registerAssembly({ title, sceneId, scene, joints }) {
|
|
505
|
-
const id = `asm-${++this.assemblySeq}`
|
|
526
|
+
registerAssembly({ title, sceneId, scene, joints, id: givenId }) {
|
|
527
|
+
const id = givenId ?? `asm-${++this.assemblySeq}`
|
|
528
|
+
const seq = /^asm-(\d+)$/.exec(id)
|
|
529
|
+
if (seq) this.assemblySeq = Math.max(this.assemblySeq, Number(seq[1]))
|
|
506
530
|
const record = {
|
|
507
531
|
id,
|
|
508
532
|
title,
|
|
@@ -551,7 +575,12 @@ class FreeCadBridge {
|
|
|
551
575
|
/** Recompute instance placements from base + joints + explode, then publish. */
|
|
552
576
|
async republishAssembly(record, titleSuffix) {
|
|
553
577
|
const scene = assembleScene(record)
|
|
554
|
-
const
|
|
578
|
+
const title = titleSuffix ? `${record.title} · ${titleSuffix}` : record.title
|
|
579
|
+
// In place: the assembly owns one scene id and one row in the models list.
|
|
580
|
+
const published = await this.publishScene(scene, title, this.currentSession ?? '', {
|
|
581
|
+
docKey: `asm:${record.id}`,
|
|
582
|
+
id: record.sceneId,
|
|
583
|
+
})
|
|
555
584
|
record.sceneId = published.id
|
|
556
585
|
return published
|
|
557
586
|
}
|
|
@@ -588,7 +617,7 @@ class FreeCadBridge {
|
|
|
588
617
|
return null
|
|
589
618
|
}
|
|
590
619
|
|
|
591
|
-
async run(code, { title, publishHint = true, meta = null } = {}) {
|
|
620
|
+
async run(code, { title, publishHint = true, meta = null, docKey = '', sceneId = '' } = {}) {
|
|
592
621
|
const bin = this.refresh()
|
|
593
622
|
if (!bin) {
|
|
594
623
|
return { ok: false, error: 'freecadcmd not found; set freecadPath in the plugin config' }
|
|
@@ -660,7 +689,7 @@ print("${BEGIN}" + __json.dumps(_safe(_payload)) + "${END}", flush=True)\n`
|
|
|
660
689
|
// `meta` rides inside the scene payload: the panel reads the feature list
|
|
661
690
|
// (and the assembly block) from there instead of calling a tool per frame.
|
|
662
691
|
const scene = meta ? { ...value.scene, ...meta } : value.scene
|
|
663
|
-
const published = await this.publishScene(scene, title ?? value.title ?? 'untitled')
|
|
692
|
+
const published = await this.publishScene(scene, title ?? value.title ?? 'untitled', this.currentSession ?? '', { docKey, id: sceneId })
|
|
664
693
|
value.sceneId = published.id
|
|
665
694
|
delete value.scene
|
|
666
695
|
}
|
|
@@ -1417,12 +1446,15 @@ if _TARGET:
|
|
|
1417
1446
|
__out["exported"] = _TARGET
|
|
1418
1447
|
__out["bytes"] = os.path.getsize(_TARGET)
|
|
1419
1448
|
`
|
|
1420
|
-
|
|
1449
|
+
// Allocate the assembly id before publishing: the scene carries `asm:<id>`
|
|
1450
|
+
// so later joint moves rewrite this same entry instead of adding one.
|
|
1451
|
+
const asmId = bridge.reserveAssemblyId()
|
|
1452
|
+
const out = await bridge.run(py, { title: title ?? 'assembly', docKey: `asm:${asmId}` })
|
|
1421
1453
|
if (!out.ok || !out.sceneId) return out
|
|
1422
1454
|
// Keep the base placements: without them a joint has nothing to move.
|
|
1423
1455
|
const scene = bridge.scenes.get(out.sceneId)
|
|
1424
1456
|
if (!scene) return out
|
|
1425
|
-
const record = bridge.registerAssembly({ title: assembly || title || 'assembly', sceneId: out.sceneId, scene, joints: [] })
|
|
1457
|
+
const record = bridge.registerAssembly({ id: asmId, title: assembly || title || 'assembly', sceneId: out.sceneId, scene, joints: [] })
|
|
1426
1458
|
for (const spec of joints ?? []) {
|
|
1427
1459
|
try {
|
|
1428
1460
|
bridge.setJoint(record, spec)
|
|
@@ -1697,7 +1729,13 @@ if _TARGET:
|
|
|
1697
1729
|
const meta = isFeatures ? { model: doc.name, features: publicFeatures(doc) } : null
|
|
1698
1730
|
doc.run = (doc.run ?? 0) + 1
|
|
1699
1731
|
doc.updatedAt = new Date().toISOString()
|
|
1700
|
-
|
|
1732
|
+
// One row per model: a rebuild rewrites the model's existing scene.
|
|
1733
|
+
const out = await bridge.run(code, {
|
|
1734
|
+
title: doc.name,
|
|
1735
|
+
meta,
|
|
1736
|
+
docKey: `model:${doc.name}`,
|
|
1737
|
+
sceneId: doc.stats?.sceneId || '',
|
|
1738
|
+
})
|
|
1701
1739
|
if (out.ok === false) return { ...out, name: doc.name, params: doc.params }
|
|
1702
1740
|
doc.stats = {
|
|
1703
1741
|
volume: out.volume ?? null,
|
|
@@ -2089,7 +2127,10 @@ if _TARGET:
|
|
|
2089
2127
|
const candidates = resolved.modelsDir ? [resolved.modelsDir, ...bridge.modelsCandidates()] : bridge.modelsCandidates()
|
|
2090
2128
|
const modelsDir = candidates.find((d) => existsSync(join(d, `${body.model}.json`))) || candidates[0] || modelsDirFor(undefined)
|
|
2091
2129
|
const result = await runFeatureAction(body, modelsDir)
|
|
2092
|
-
|
|
2130
|
+
// Tell the panel when the model was republished, so its poller can
|
|
2131
|
+
// recognise the in-place update it triggered itself.
|
|
2132
|
+
const entry = result && result.sceneId ? bridge.history.find((h) => h.id === result.sceneId) : null
|
|
2133
|
+
return send(200, JSON.stringify(entry ? { ...result, at: entry.at } : result))
|
|
2093
2134
|
} catch (error) {
|
|
2094
2135
|
return send(400, JSON.stringify({ ok: false, error: String(error?.message ?? error) }))
|
|
2095
2136
|
}
|
|
@@ -2157,12 +2198,12 @@ if _TARGET:
|
|
|
2157
2198
|
const moved = live.driveJoint(record, jointId, body?.value)
|
|
2158
2199
|
if (!moved) return send(400, JSON.stringify({ error: 'bad joint or value' }))
|
|
2159
2200
|
const published = await live.republishAssembly(record, `${moved.id} ${round6(moved.value)}`)
|
|
2160
|
-
return send(200, JSON.stringify({ ok: true, sceneId: published.id, joint: moved.id, value: round6(moved.value) }))
|
|
2201
|
+
return send(200, JSON.stringify({ ok: true, sceneId: published.id, at: published.stats.at, joint: moved.id, value: round6(moved.value) }))
|
|
2161
2202
|
}
|
|
2162
2203
|
const next = live.setExplode(record, body?.factor ?? 1)
|
|
2163
2204
|
if (next === null) return send(400, JSON.stringify({ error: 'bad factor' }))
|
|
2164
2205
|
const published = await live.republishAssembly(record, next ? `爆炸 ${round6(next)}` : '合拢')
|
|
2165
|
-
return send(200, JSON.stringify({ ok: true, sceneId: published.id, explode: round6(next) }))
|
|
2206
|
+
return send(200, JSON.stringify({ ok: true, sceneId: published.id, at: published.stats.at, explode: round6(next) }))
|
|
2166
2207
|
}
|
|
2167
2208
|
if (url.pathname.startsWith(`${ROUTE_PREFIX}/scene/`)) {
|
|
2168
2209
|
const id = decodeURIComponent(url.pathname.slice(`${ROUTE_PREFIX}/scene/`.length))
|