@2112-lab/central-plant 0.3.46 → 0.3.47

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 (29) hide show
  1. package/dist/bundle/index.js +182 -92
  2. package/dist/cjs/src/core/centralPlant.js +3 -4
  3. package/dist/cjs/src/core/sceneViewer.js +0 -1
  4. package/dist/cjs/src/managers/behaviors/IoBehaviorManager.js +1 -2
  5. package/dist/cjs/src/managers/components/componentDataManager.js +0 -1
  6. package/dist/cjs/src/managers/controls/componentDragManager.js +2 -7
  7. package/dist/cjs/src/managers/pathfinding/pathfindingManager.js +55 -1
  8. package/dist/cjs/src/managers/scene/collisionManager.js +1 -2
  9. package/dist/cjs/src/managers/scene/componentTooltipManager.js +2 -3
  10. package/dist/cjs/src/managers/scene/sceneExportManager.js +30 -11
  11. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +21 -1
  12. package/dist/cjs/src/utils/behaviorDispatch.js +11 -42
  13. package/dist/cjs/src/utils/boundingBoxUtils.js +54 -8
  14. package/dist/cjs/src/utils/ioDeviceUtils.js +3 -9
  15. package/dist/esm/src/core/centralPlant.js +3 -4
  16. package/dist/esm/src/core/sceneViewer.js +0 -1
  17. package/dist/esm/src/managers/behaviors/IoBehaviorManager.js +1 -2
  18. package/dist/esm/src/managers/components/componentDataManager.js +0 -1
  19. package/dist/esm/src/managers/controls/componentDragManager.js +2 -7
  20. package/dist/esm/src/managers/pathfinding/pathfindingManager.js +56 -2
  21. package/dist/esm/src/managers/scene/collisionManager.js +1 -2
  22. package/dist/esm/src/managers/scene/componentTooltipManager.js +2 -3
  23. package/dist/esm/src/managers/scene/sceneExportManager.js +31 -12
  24. package/dist/esm/src/managers/scene/sceneOperationsManager.js +21 -1
  25. package/dist/esm/src/utils/behaviorDispatch.js +11 -42
  26. package/dist/esm/src/utils/boundingBoxUtils.js +55 -10
  27. package/dist/esm/src/utils/ioDeviceUtils.js +3 -9
  28. package/dist/index.d.ts +0 -6
  29. package/package.json +1 -1
@@ -1320,9 +1320,29 @@ var SceneOperationsManager = /*#__PURE__*/function () {
1320
1320
  min: boundingBox.min.toArray(),
1321
1321
  max: boundingBox.max.toArray()
1322
1322
  }
1323
- })
1323
+ }),
1324
+ children: [] // Initialize children array
1324
1325
  };
1325
1326
 
1327
+ // Collect children that are connectors
1328
+ if (componentModel.children) {
1329
+ componentModel.children.forEach(function (child) {
1330
+ if (child.userData && child.userData.objectType === 'connector') {
1331
+ componentSceneData.children.push({
1332
+ uuid: child.uuid,
1333
+ name: child.name,
1334
+ type: 'Mesh',
1335
+ position: {
1336
+ x: child.position.x,
1337
+ y: child.position.y,
1338
+ z: child.position.z
1339
+ },
1340
+ userData: _objectSpread2({}, child.userData)
1341
+ });
1342
+ }
1343
+ });
1344
+ }
1345
+
1326
1346
  // Add the component to the scene data
1327
1347
  if (!currentSceneData.scene.children) {
1328
1348
  currentSceneData.scene.children = [];
@@ -26,11 +26,11 @@ function getIoBehaviorManager(sceneViewer) {
26
26
 
27
27
  /**
28
28
  * Resolve tooltip/drag data points for an I/O device attachment.
29
- * Prefers behaviorConfig-driven animation data points; merges legacy ioConfig snapshot.
29
+ * Prefers behaviorConfig-driven animation data points.
30
30
  *
31
31
  * @param {string} parentUuid
32
32
  * @param {string} attachmentId
33
- * @param {Object} userData - io-device userData (may include dataPoints snapshot)
33
+ * @param {Object} userData - io-device userData
34
34
  * @param {import('../managers/behaviors/IoBehaviorManager.js').IoBehaviorManager|null} ioBehaviorManager
35
35
  * @param {THREE.Object3D|null} [hitMesh]
36
36
  * @returns {Object[]}
@@ -38,21 +38,7 @@ function getIoBehaviorManager(sceneViewer) {
38
38
  function resolveDataPoints(parentUuid, attachmentId, userData, ioBehaviorManager) {
39
39
  var hitMesh = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
40
40
  var fromAnimations = (ioBehaviorManager === null || ioBehaviorManager === void 0 ? void 0 : ioBehaviorManager.getAnimationDataPoints(parentUuid, attachmentId, hitMesh)) || [];
41
- if (fromAnimations.length) return fromAnimations;
42
- var legacy = (userData === null || userData === void 0 ? void 0 : userData.dataPoints) || [];
43
- return legacy.map(function (dp) {
44
- var _dp$defaultValue;
45
- return {
46
- id: dp.id || dp.name,
47
- name: dp.name || dp.id,
48
- stateType: dp.stateType || 'binary',
49
- stateConfig: dp.stateConfig || {},
50
- defaultValue: (_dp$defaultValue = dp.defaultValue) !== null && _dp$defaultValue !== void 0 ? _dp$defaultValue : null,
51
- direction: dp.direction || (userData === null || userData === void 0 ? void 0 : userData.ioDirection) || 'output'
52
- };
53
- }).filter(function (dp) {
54
- return dp.id;
55
- });
41
+ return fromAnimations;
56
42
  }
57
43
 
58
44
  /**
@@ -83,35 +69,18 @@ function applyDefaultIoDeviceStates(centralPlant) {
83
69
  if (seen.has(scopedKey)) return;
84
70
  seen.add(scopedKey);
85
71
  var dps = ioBehavMgr.getAnimationDataPoints(objParentUuid, objAttachmentId) || [];
86
- if (dps.length) {
87
- var _iterator = _createForOfIteratorHelper(dps),
88
- _step;
89
- try {
90
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
91
- var dp = _step.value;
92
- if (!(dp !== null && dp !== void 0 && dp.id) || dp.defaultValue === undefined || dp.defaultValue === null) continue;
93
- centralPlant.setIoDeviceState(objAttachmentId, dp.id, dp.defaultValue, objParentUuid);
94
- }
95
- } catch (err) {
96
- _iterator.e(err);
97
- } finally {
98
- _iterator.f();
99
- }
100
- return;
101
- }
102
- var _iterator2 = _createForOfIteratorHelper(obj.userData.dataPoints || []),
103
- _step2;
72
+ var _iterator = _createForOfIteratorHelper(dps),
73
+ _step;
104
74
  try {
105
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
106
- var _dp = _step2.value;
107
- var dpId = _dp.id || _dp.name;
108
- if (!dpId || _dp.defaultValue === undefined || _dp.defaultValue === null) continue;
109
- centralPlant.setIoDeviceState(objAttachmentId, dpId, _dp.defaultValue, objParentUuid);
75
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
76
+ var dp = _step.value;
77
+ if (!(dp !== null && dp !== void 0 && dp.id) || dp.defaultValue === undefined || dp.defaultValue === null) continue;
78
+ centralPlant.setIoDeviceState(objAttachmentId, dp.id, dp.defaultValue, objParentUuid);
110
79
  }
111
80
  } catch (err) {
112
- _iterator2.e(err);
81
+ _iterator.e(err);
113
82
  } finally {
114
- _iterator2.f();
83
+ _iterator.f();
115
84
  }
116
85
  });
117
86
  }
@@ -1,4 +1,4 @@
1
- import { createForOfIteratorHelper as _createForOfIteratorHelper, construct as _construct, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper, objectSpread2 as _objectSpread2, construct as _construct, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import * as THREE from 'three';
3
3
 
4
4
  /**
@@ -187,6 +187,51 @@ function computeIODeviceBoundingBoxes(componentObject) {
187
187
  return results;
188
188
  }
189
189
 
190
+ /**
191
+ * Computes individual world-space bounding boxes for each connector child
192
+ * of a component.
193
+ *
194
+ * @param {THREE.Object3D} componentObject - The component's Three.js object
195
+ * @returns {Array<{uuid: string, userData: Object, worldBoundingBox: {min: number[], max: number[]}}>}
196
+ * Array of connector bounding box descriptors ready for injection into scene data
197
+ */
198
+ function computeConnectorBoundingBoxes(componentObject) {
199
+ var results = [];
200
+ var _iterator2 = _createForOfIteratorHelper(componentObject.children),
201
+ _step2;
202
+ try {
203
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
204
+ var _child$userData2;
205
+ var child = _step2.value;
206
+ if (((_child$userData2 = child.userData) === null || _child$userData2 === void 0 ? void 0 : _child$userData2.objectType) !== 'connector') continue;
207
+ var bbox = new THREE.Box3().setFromObject(child);
208
+
209
+ // Fallback if mesh is too small or empty (sometimes connectors are just points)
210
+ if (bbox.isEmpty() || bbox.getSize(new THREE.Vector3()).length() < 0.01) {
211
+ var worldPos = new THREE.Vector3();
212
+ child.getWorldPosition(worldPos);
213
+ var size = 0.1;
214
+ bbox.setFromCenterAndSize(worldPos, new THREE.Vector3(size, size, size));
215
+ }
216
+ results.push({
217
+ uuid: child.uuid,
218
+ userData: _objectSpread2(_objectSpread2({}, child.userData), {}, {
219
+ objectType: 'connector'
220
+ }),
221
+ worldBoundingBox: {
222
+ min: [bbox.min.x, bbox.min.y, bbox.min.z],
223
+ max: [bbox.max.x, bbox.max.y, bbox.max.z]
224
+ }
225
+ });
226
+ }
227
+ } catch (err) {
228
+ _iterator2.e(err);
229
+ } finally {
230
+ _iterator2.f();
231
+ }
232
+ return results;
233
+ }
234
+
190
235
  /**
191
236
  * Creates bounding box helpers for a selected object. For smart components
192
237
  * (components with io-device children), this produces:
@@ -245,8 +290,8 @@ function createSelectionBoxHelpers(object) {
245
290
 
246
291
  // Check if this object has io-device children (smart component)
247
292
  var hasIODevices = (_object$children = object.children) === null || _object$children === void 0 ? void 0 : _object$children.some(function (child) {
248
- var _child$userData2;
249
- return ((_child$userData2 = child.userData) === null || _child$userData2 === void 0 ? void 0 : _child$userData2.objectType) === 'io-device';
293
+ var _child$userData3;
294
+ return ((_child$userData3 = child.userData) === null || _child$userData3 === void 0 ? void 0 : _child$userData3.objectType) === 'io-device';
250
295
  });
251
296
  if (hasIODevices) {
252
297
  // 1. Create filtered helper for the component body
@@ -283,11 +328,11 @@ function createSelectionBoxHelpers(object) {
283
328
  * @param {THREE.Scene} scene - The scene (for finding objects by uuid)
284
329
  */
285
330
  function updateSelectionBoxHelpers(helpers, selectedObjects, scene) {
286
- var _iterator2 = _createForOfIteratorHelper(helpers),
287
- _step2;
331
+ var _iterator3 = _createForOfIteratorHelper(helpers),
332
+ _step3;
288
333
  try {
289
334
  var _loop = function _loop() {
290
- var helper = _step2.value;
335
+ var helper = _step3.value;
291
336
  var _helper$userData = helper.userData,
292
337
  sourceObjectUuid = _helper$userData.sourceObjectUuid,
293
338
  isFiltered = _helper$userData.isFiltered,
@@ -318,14 +363,14 @@ function updateSelectionBoxHelpers(helpers, selectedObjects, scene) {
318
363
  helper.update();
319
364
  }
320
365
  };
321
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
366
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
322
367
  if (_loop()) continue;
323
368
  }
324
369
  } catch (err) {
325
- _iterator2.e(err);
370
+ _iterator3.e(err);
326
371
  } finally {
327
- _iterator2.f();
372
+ _iterator3.f();
328
373
  }
329
374
  }
330
375
 
331
- export { computeFilteredBoundingBox, computeFilteredBoundingBoxCached, computeIODeviceBoundingBoxes, createSelectionBoxHelpers, updateSelectionBoxHelpers };
376
+ export { computeConnectorBoundingBoxes, computeFilteredBoundingBox, computeFilteredBoundingBoxCached, computeIODeviceBoundingBoxes, createSelectionBoxHelpers, updateSelectionBoxHelpers };
@@ -23,7 +23,7 @@ function attachIODevicesToComponent(_x, _x2, _x3, _x4) {
23
23
  }
24
24
  function _attachIODevicesToComponent() {
25
25
  _attachIODevicesToComponent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(componentModel, componentData, modelPreloader, parentComponentId) {
26
- var attachedDevices, _i, _Object$entries, _Object$entries$_i, attachmentId, attachment, _modelPreloader$compo, _deviceData$ioConfig, _deviceData$ioConfig2, _deviceData$ioConfig3, _attachment$attachmen, _attachment$attachmen2, deviceData, cachedDevice, _modelPreloader$loadi, deviceModel, pos, rot, deg2rad, _t, _t2;
26
+ var attachedDevices, _i, _Object$entries, _Object$entries$_i, attachmentId, attachment, _modelPreloader$compo, _attachment$attachmen, _attachment$attachmen2, deviceData, cachedDevice, _modelPreloader$loadi, deviceModel, pos, rot, deg2rad, _t, _t2;
27
27
  return _regenerator().w(function (_context) {
28
28
  while (1) switch (_context.n) {
29
29
  case 0:
@@ -101,20 +101,14 @@ function _attachIODevicesToComponent() {
101
101
  // Name the device model
102
102
  deviceModel.name = "".concat(attachment.attachmentLabel || 'IO Device', " (").concat(attachmentId, ")");
103
103
 
104
- // Set user data for identification — include ioConfig data points so the
105
- // component tooltip can render state displays without an extra lookup.
104
+ // Set user data for identification
106
105
  deviceModel.userData = {
107
106
  objectType: 'io-device',
108
107
  deviceId: attachment.deviceId,
109
108
  attachmentId: attachmentId,
110
109
  attachmentLabel: attachment.attachmentLabel,
111
110
  parentComponentId: parentComponentId,
112
- deviceName: deviceData.name || '',
113
- // Snapshot of the device's data point definitions (stateType, stateConfig, direction, etc.)
114
- // ioConfig can use either 'states' (preferred) or legacy 'dataPoints' as the array key
115
- dataPoints: ((_deviceData$ioConfig = deviceData.ioConfig) === null || _deviceData$ioConfig === void 0 ? void 0 : _deviceData$ioConfig.states) || ((_deviceData$ioConfig2 = deviceData.ioConfig) === null || _deviceData$ioConfig2 === void 0 ? void 0 : _deviceData$ioConfig2.dataPoints) || [],
116
- // Device-level I/O direction: 'input' means the user can write state via the tooltip
117
- ioDirection: ((_deviceData$ioConfig3 = deviceData.ioConfig) === null || _deviceData$ioConfig3 === void 0 ? void 0 : _deviceData$ioConfig3.direction) || 'output'
111
+ deviceName: deviceData.name || ''
118
112
  };
119
113
 
120
114
  // Position at the attachment point
package/dist/index.d.ts CHANGED
@@ -35,11 +35,6 @@ export interface IoDeviceState {
35
35
  direction?: 'input' | 'output'
36
36
  }
37
37
 
38
- export interface IoDeviceConfig {
39
- direction: 'input' | 'output'
40
- states: IoDeviceState[]
41
- }
42
-
43
38
  export interface BehaviorMapping {
44
39
  stateValue: any
45
40
  transform?: { x?: number; y?: number; z?: number }
@@ -91,7 +86,6 @@ export interface IoDeviceAsset {
91
86
  uuid: string
92
87
  name: string
93
88
  assetType: 'I/O Device'
94
- ioConfig: IoDeviceConfig
95
89
  behaviorConfig?: BehaviorEntry[]
96
90
  meshNameMap?: Record<string, string>
97
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2112-lab/central-plant",
3
- "version": "0.3.46",
3
+ "version": "0.3.47",
4
4
  "description": "Utility modules for the Central Plant Application",
5
5
  "main": "dist/bundle/index.js",
6
6
  "module": "dist/esm/src/index.js",