@2112-lab/central-plant 0.1.39 → 0.1.41

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 (45) hide show
  1. package/dist/bundle/index.js +7991 -7054
  2. package/dist/cjs/src/core/centralPlant.js +48 -3
  3. package/dist/cjs/src/core/centralPlantInternals.js +75 -566
  4. package/dist/cjs/src/core/sceneViewer.js +38 -13
  5. package/dist/cjs/src/index.js +6 -4
  6. package/dist/cjs/src/managers/components/pathfindingManager.js +75 -60
  7. package/dist/cjs/src/managers/components/transformOperationsManager.js +929 -0
  8. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +57 -1
  9. package/dist/cjs/src/managers/controls/transformControls.js +11 -3
  10. package/dist/cjs/src/managers/controls/transformControlsManager.js +563 -263
  11. package/dist/cjs/src/managers/pathfinding/ConnectorManager.js +385 -0
  12. package/dist/cjs/src/managers/pathfinding/PathIntersectionDetector.js +387 -0
  13. package/dist/cjs/src/managers/pathfinding/PathRenderingManager.js +401 -0
  14. package/dist/cjs/src/managers/pathfinding/pathfindingManager.js +378 -0
  15. package/dist/cjs/src/managers/pathfinding/sceneDataManager.js +256 -0
  16. package/dist/cjs/src/managers/scene/animationManager.js +145 -0
  17. package/dist/cjs/src/managers/scene/sceneExportManager.js +14 -13
  18. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +516 -21
  19. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +1 -8
  20. package/dist/cjs/src/managers/system/operationHistoryManager.js +414 -0
  21. package/dist/cjs/src/managers/system/settingsManager.js +2 -1
  22. package/dist/cjs/src/utils/objectTypes.js +5 -7
  23. package/dist/esm/src/core/centralPlant.js +48 -3
  24. package/dist/esm/src/core/centralPlantInternals.js +76 -567
  25. package/dist/esm/src/core/sceneViewer.js +38 -13
  26. package/dist/esm/src/index.js +4 -3
  27. package/dist/esm/src/managers/components/pathfindingManager.js +75 -60
  28. package/dist/esm/src/managers/components/transformOperationsManager.js +904 -0
  29. package/dist/esm/src/managers/controls/keyboardControlsManager.js +57 -1
  30. package/dist/esm/src/managers/controls/transformControls.js +11 -3
  31. package/dist/esm/src/managers/controls/transformControlsManager.js +564 -264
  32. package/dist/esm/src/managers/pathfinding/ConnectorManager.js +361 -0
  33. package/dist/esm/src/managers/pathfinding/PathIntersectionDetector.js +363 -0
  34. package/dist/esm/src/managers/pathfinding/PathRenderingManager.js +377 -0
  35. package/dist/esm/src/managers/pathfinding/pathfindingManager.js +374 -0
  36. package/dist/esm/src/managers/pathfinding/sceneDataManager.js +232 -0
  37. package/dist/esm/src/managers/scene/animationManager.js +141 -0
  38. package/dist/esm/src/managers/scene/sceneExportManager.js +14 -13
  39. package/dist/esm/src/managers/scene/sceneOperationsManager.js +516 -21
  40. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +1 -8
  41. package/dist/esm/src/managers/system/operationHistoryManager.js +409 -0
  42. package/dist/esm/src/managers/system/settingsManager.js +2 -1
  43. package/dist/esm/src/utils/objectTypes.js +5 -7
  44. package/dist/index.d.ts +2 -2
  45. package/package.json +1 -1
@@ -0,0 +1,378 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
6
+ require('three');
7
+ var pathfinder = require('@2112-lab/pathfinder');
8
+ var baseDisposable = require('../../core/baseDisposable.js');
9
+ var pathfindingData = require('../../core/pathfindingData.js');
10
+ var PathIntersectionDetector = require('./PathIntersectionDetector.js');
11
+ var sceneDataManager = require('./sceneDataManager.js');
12
+ var PathRenderingManager = require('./PathRenderingManager.js');
13
+ var ConnectorManager = require('./ConnectorManager.js');
14
+
15
+ var PathfindingManager = /*#__PURE__*/function (_BaseDisposable) {
16
+ function PathfindingManager(sceneViewer) {
17
+ var _this;
18
+ _rollupPluginBabelHelpers.classCallCheck(this, PathfindingManager);
19
+ _this = _rollupPluginBabelHelpers.callSuper(this, PathfindingManager);
20
+ _this.sceneViewer = sceneViewer;
21
+ _this.pathfinder = null;
22
+ _this.crosscubeTextureSet = null;
23
+ _this.pathfinderVersionInfo = null;
24
+
25
+ // Initialize scene data manager
26
+ _this.sceneDataManager = new sceneDataManager.SceneDataManager(sceneViewer);
27
+
28
+ // Initialize intersection detector
29
+ _this.intersectionDetector = new PathIntersectionDetector.PathIntersectionDetector(sceneViewer);
30
+
31
+ // Initialize rendering manager
32
+ _this.renderingManager = new PathRenderingManager.PathRenderingManager(sceneViewer);
33
+ _this.registerDisposable(_this.renderingManager);
34
+
35
+ // Initialize connector manager
36
+ _this.connectorManager = new ConnectorManager.ConnectorManager(sceneViewer);
37
+ _this.registerDisposable(_this.connectorManager);
38
+
39
+ // NEW: PathData store for business logic layer
40
+ _this.pathDataStore = new Map(); // pathId -> PathData
41
+
42
+ // Configuration for pathfinder grid
43
+ _this.pathfinderConfig = {
44
+ grid: {
45
+ size: 0.5,
46
+ safetyMargin: 0,
47
+ minSegmentLength: 0.5,
48
+ timeout: 1000
49
+ },
50
+ connectorBBoxSize: 0.1 // Default size for position-based connectors (Phase 2 Refactoring)
51
+ };
52
+ return _this;
53
+ }
54
+
55
+ /**
56
+ * Export path data as JSON
57
+ * @returns {Array<Object>} Array of serialized PathData objects
58
+ */
59
+ _rollupPluginBabelHelpers.inherits(PathfindingManager, _BaseDisposable);
60
+ return _rollupPluginBabelHelpers.createClass(PathfindingManager, [{
61
+ key: "exportData",
62
+ value: function exportData() {
63
+ var exportData = Array.from(this.pathDataStore.values()).map(function (pathData) {
64
+ return pathData.toJSON();
65
+ });
66
+ console.log("\uD83D\uDCE4 Exported ".concat(exportData.length, " path data objects"));
67
+ return exportData;
68
+ }
69
+
70
+ /**
71
+ * Import path data from JSON
72
+ * @param {Array<Object>} jsonArray - Array of serialized PathData objects
73
+ */
74
+ }, {
75
+ key: "importData",
76
+ value: function importData(jsonArray) {
77
+ var _this2 = this;
78
+ if (!Array.isArray(jsonArray)) {
79
+ console.error('❌ importData expects an array');
80
+ return;
81
+ }
82
+ this.pathDataStore.clear();
83
+ jsonArray.forEach(function (json) {
84
+ try {
85
+ var pathData = pathfindingData.PathData.fromJSON(json);
86
+ _this2.pathDataStore.set(pathData.pathId, pathData);
87
+ console.log("\uD83D\uDCE5 Imported PathData: ".concat(pathData.pathId));
88
+ } catch (error) {
89
+ console.error('❌ Error importing PathData:', error);
90
+ }
91
+ });
92
+ console.log("\u2705 Imported ".concat(this.pathDataStore.size, " path data objects"));
93
+ }
94
+
95
+ // ============================================================================
96
+ // END NEW ADAPTER METHODS
97
+ // ============================================================================
98
+
99
+ /**
100
+ * Core pathfinding logic shared across initialization and updates
101
+ */
102
+ }, {
103
+ key: "_executePathfinding",
104
+ value: function () {
105
+ var _executePathfinding2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(sceneData, connections) {
106
+ var _simplifiedSceneData$;
107
+ var options,
108
+ _options$context,
109
+ context,
110
+ connectionsCopy,
111
+ simplifiedSceneData,
112
+ pathfindingResult,
113
+ intersectionCheck,
114
+ _args = arguments;
115
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
116
+ while (1) switch (_context.n) {
117
+ case 0:
118
+ options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
119
+ options.createGateways, _options$context = options.context, context = _options$context === void 0 ? 'Pathfinding' : _options$context; // Create pathfinder instance with configuration only
120
+ this.pathfinder = new pathfinder.Pathfinder(this.pathfinderConfig);
121
+ this.sceneViewer.pathfinder = this.pathfinder;
122
+
123
+ // Ensure all matrices are up to date before bounding box calculations (for all pathfinding executions)
124
+ this.sceneViewer.scene.updateMatrixWorld(true);
125
+ console.log("\uD83D\uDD04 Updated matrix world for ".concat(context, " pathfinding execution"));
126
+
127
+ // Deep copy connections to prevent pathfinder from mutating the original
128
+ connectionsCopy = JSON.parse(JSON.stringify(connections));
129
+ simplifiedSceneData = JSON.parse(JSON.stringify(this.getSimplifiedSceneData()));
130
+ console.log('[Pathfinder] simplifiedSceneData length at creation:', (_simplifiedSceneData$ = simplifiedSceneData.children) === null || _simplifiedSceneData$ === void 0 ? void 0 : _simplifiedSceneData$.length);
131
+ console.log('[Pathfinder] simplifiedSceneData (deep clone for inspection):', JSON.parse(JSON.stringify(simplifiedSceneData)));
132
+
133
+ // Add debugging for pathfinder input
134
+ console.log('🔍 PATHFINDER DEBUGGING:');
135
+ console.log('🔗 [Pathfinder] Connections:', JSON.parse(JSON.stringify(connectionsCopy)));
136
+
137
+ // Find paths using v1.0.17 API (sceneData and connections separately)
138
+ // Pass deep copy to ensure pathfinder cannot mutate original connections
139
+ pathfindingResult = this.pathfinder.findPaths(simplifiedSceneData, connectionsCopy);
140
+ console.log('[Pathfinder] Found paths:', JSON.parse(JSON.stringify(pathfindingResult.paths)));
141
+ console.log('Generated gateways:', JSON.parse(JSON.stringify(pathfindingResult.gateways)));
142
+ console.log('Rewired connections:', JSON.parse(JSON.stringify(pathfindingResult.rewiredConnections)));
143
+ console.log("intersectionCheck input:", pathfindingResult.paths);
144
+
145
+ // Check for path intersections (including manual segments)
146
+ intersectionCheck = this.checkPathIntersections(pathfindingResult.paths, 0.2, true);
147
+ pathfindingResult.intersections = intersectionCheck;
148
+ console.log("intersectionCheck:", intersectionCheck);
149
+ console.log("intersectionCheck.hasIntersections:", intersectionCheck.hasIntersections);
150
+
151
+ // // Handle intersection detection - undo last operation if intersections found
152
+ // if (intersectionCheck.hasIntersections) {
153
+ // console.warn('⚠️ Path intersections detected! Attempting to undo last operation...');
154
+
155
+ // // Access operationHistoryManager through sceneViewer.managers.operationHistory
156
+ // const operationHistoryManager = this.sceneViewer?.managers?.operationHistory;
157
+
158
+ // if (operationHistoryManager) {
159
+ // const lastOp = operationHistoryManager.getLastOperation();
160
+
161
+ // if (lastOp) {
162
+ // console.warn(`⚠️ Intersection caused by operation: ${lastOp.operationName}`, lastOp.params);
163
+
164
+ // // Attempt to undo the operation
165
+ // const undoSuccess = operationHistoryManager.undoLastOperation();
166
+
167
+ // if (undoSuccess) {
168
+ // console.log('✅ Successfully undid operation that caused intersection');
169
+
170
+ // // Re-run pathfinding after undo to restore valid state
171
+ // console.log('🔄 Re-running pathfinding after undo...');
172
+
173
+ // // Note: We don't recursively call _executePathfinding here to avoid potential infinite loops
174
+ // // Instead, the calling code (updatePathfindingAfterTransform) will handle re-execution
175
+ // pathfindingResult.undoPerformed = true;
176
+ // pathfindingResult.undoneOperation = lastOp;
177
+ // } else {
178
+ // console.error('❌ Failed to undo operation that caused intersection');
179
+ // pathfindingResult.undoFailed = true;
180
+ // }
181
+ // } else {
182
+ // console.warn('⚠️ No operation in history to undo');
183
+ // }
184
+ // } else {
185
+ // console.error('❌ OperationHistoryManager not available for undo');
186
+ // console.error(' Available managers:', Object.keys(this.sceneViewer?.managers || {}));
187
+ // }
188
+ // }
189
+
190
+ // Create gateways in the scene if requested
191
+ if (options.createGateways && pathfindingResult.gateways) {
192
+ this.renderingManager.createGateways(pathfindingResult);
193
+ }
194
+ console.log("pathfindingResult.paths:", pathfindingResult.paths);
195
+
196
+ // Create pipe paths with materials using the paths from pathfinder
197
+ this.renderingManager.createPipePaths(pathfindingResult.paths, this.crosscubeTextureSet);
198
+ return _context.a(2, pathfindingResult);
199
+ }
200
+ }, _callee, this);
201
+ }));
202
+ function _executePathfinding(_x, _x2) {
203
+ return _executePathfinding2.apply(this, arguments);
204
+ }
205
+ return _executePathfinding;
206
+ }()
207
+ }, {
208
+ key: "getSimplifiedSceneData",
209
+ value: function getSimplifiedSceneData() {
210
+ return this.sceneDataManager.getSimplifiedSceneData();
211
+ }
212
+
213
+ /**
214
+ * Initialize pathfinder and create paths
215
+ */
216
+ }, {
217
+ key: "initializePathfinder",
218
+ value: (function () {
219
+ var _initializePathfinder = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2(data, crosscubeTextureSet) {
220
+ var pathfindingResult;
221
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
222
+ while (1) switch (_context2.n) {
223
+ case 0:
224
+ this.crosscubeTextureSet = crosscubeTextureSet;
225
+
226
+ // Use shared pathfinding logic with gateway creation enabled
227
+ _context2.n = 1;
228
+ return this._executePathfinding(data.scene, data.connections, {
229
+ createGateways: true,
230
+ context: 'Scene Loading'
231
+ });
232
+ case 1:
233
+ pathfindingResult = _context2.v;
234
+ // Update connections with rewired connections
235
+ if (pathfindingResult.rewiredConnections) {
236
+ // data.connections = pathfindingResult.rewiredConnections;
237
+ console.log('🔄 Updated connections with rewired connections:', data.connections);
238
+ }
239
+
240
+ // Return full result for potential additional processing
241
+ return _context2.a(2, pathfindingResult);
242
+ }
243
+ }, _callee2, this);
244
+ }));
245
+ function initializePathfinder(_x3, _x4) {
246
+ return _initializePathfinder.apply(this, arguments);
247
+ }
248
+ return initializePathfinder;
249
+ }()
250
+ /**
251
+ * Remove all computed objects from the scene (segments, elbows, and gateways)
252
+ */
253
+ )
254
+ }, {
255
+ key: "removeComputedObjects",
256
+ value: function removeComputedObjects() {
257
+ var sceneViewer = this.sceneViewer;
258
+ console.log("removeComputedObjects started");
259
+ var objectsToRemove = [];
260
+ sceneViewer.scene.traverse(function (obj) {
261
+ // Remove computed Segments (uppercase SEGMENT-)
262
+ if (obj.uuid && obj.uuid.startsWith("SEGMENT-")) {
263
+ console.log("[removeComputedObjects] to be removed: ".concat(obj.uuid, ")"));
264
+ objectsToRemove.push(obj);
265
+ }
266
+ // Remove computed Elbows
267
+ if (obj.userData && obj.userData.isPipeElbow && obj.userData.isDeclared !== true) {
268
+ console.log("[removeComputedObjects] to be removed: ".concat(obj.uuid, ")"));
269
+ objectsToRemove.push(obj);
270
+ }
271
+ // Also remove computed Gateways
272
+ if (obj.uuid && obj.uuid.includes("Gateway") && obj.userData && obj.userData.isDeclared !== true) {
273
+ console.log("[removeComputedObjects] to be removed: ".concat(obj.uuid));
274
+ objectsToRemove.push(obj);
275
+ }
276
+ });
277
+
278
+ // console.log(`[removeComputedObjects] objectsToRemove:`, objectsToRemove);
279
+
280
+ for (var _i = 0, _objectsToRemove = objectsToRemove; _i < _objectsToRemove.length; _i++) {
281
+ var obj = _objectsToRemove[_i];
282
+ sceneViewer.scene.remove(obj);
283
+ if (obj.geometry) obj.geometry.dispose();
284
+ if (obj.material) {
285
+ if (Array.isArray(obj.material)) {
286
+ obj.material.forEach(function (mat) {
287
+ return mat.dispose();
288
+ });
289
+ } else {
290
+ obj.material.dispose();
291
+ }
292
+ }
293
+ }
294
+ console.log("\u2705 Removed ".concat(objectsToRemove.length, " computed objects from scene (segments, elbows, and gateways)"));
295
+ }
296
+
297
+ /**
298
+ * Check for intersections between paths
299
+ * Delegates to PathIntersectionDetector for the actual detection logic
300
+ * @param {Array} paths - Array of path objects from pathfinder
301
+ * @param {number} tolerance - Distance tolerance for considering pipes as intersecting (default: 0.2)
302
+ * @param {boolean} includeManualSegments - Whether to include manual segments in the check (default: true)
303
+ * @returns {Object} Intersection results
304
+ * @property {boolean} hasIntersections - Whether any intersections were found
305
+ * @property {Array<Object>} intersections - Array of intersection details
306
+ * @property {number} count - Total number of intersections found
307
+ */
308
+ }, {
309
+ key: "checkPathIntersections",
310
+ value: function checkPathIntersections(paths) {
311
+ var tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.2;
312
+ var includeManualSegments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
313
+ return this.intersectionDetector.checkPathIntersections(paths, tolerance, includeManualSegments);
314
+ }
315
+
316
+ /**
317
+ * Update pathfinding after object transforms
318
+ */
319
+ }, {
320
+ key: "updatePathfindingAfterTransform",
321
+ value: (function () {
322
+ var _updatePathfindingAfterTransform = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3(currentSceneData) {
323
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
324
+ while (1) switch (_context3.n) {
325
+ case 0:
326
+ // Remove all existing paths from the scene
327
+ this.removeComputedObjects();
328
+ console.log('🔄 Starting pathfinding with updated scene data...');
329
+
330
+ // Note: Matrix updates and bounding box recomputation now handled in _executePathfinding
331
+ // Use shared pathfinding logic (no gateways needed for transform updates)
332
+ _context3.n = 1;
333
+ return this._executePathfinding(currentSceneData.scene, currentSceneData.connections, {
334
+ createGateways: true,
335
+ context: 'Transform Update'
336
+ });
337
+ case 1:
338
+ return _context3.a(2);
339
+ }
340
+ }, _callee3, this);
341
+ }));
342
+ function updatePathfindingAfterTransform(_x5) {
343
+ return _updatePathfindingAfterTransform.apply(this, arguments);
344
+ }
345
+ return updatePathfindingAfterTransform;
346
+ }()
347
+ /**
348
+ * Dispose of pathfinding resources
349
+ */
350
+ )
351
+ }, {
352
+ key: "dispose",
353
+ value: function dispose() {
354
+ console.log('🗑️ Disposing PathfindingManager...');
355
+
356
+ // Clear path data store
357
+ if (this.pathDataStore) {
358
+ this.pathDataStore.clear();
359
+ console.log('✅ Cleared pathDataStore');
360
+ }
361
+
362
+ // Remove computed objects
363
+ this.removeComputedObjects();
364
+
365
+ // Call parent dispose to clean up registered resources
366
+ _rollupPluginBabelHelpers.superPropGet(PathfindingManager, "dispose", this, 3)([]);
367
+
368
+ // Nullify properties
369
+ this.pathfinder = null;
370
+ this.crosscubeTextureSet = null;
371
+ this.pathfinderVersionInfo = null;
372
+ this.sceneViewer = null;
373
+ console.log('✅ PathfindingManager disposed');
374
+ }
375
+ }]);
376
+ }(baseDisposable.BaseDisposable);
377
+
378
+ exports.PathfindingManager = PathfindingManager;
@@ -0,0 +1,256 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var THREE = require('three');
7
+
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n["default"] = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
27
+
28
+ /**
29
+ * SceneDataManager
30
+ * Utility class for managing scene data transformations and queries
31
+ * Handles scene structure flattening, simplification, and object lookups
32
+ */
33
+ var SceneDataManager = /*#__PURE__*/function () {
34
+ function SceneDataManager(sceneViewer) {
35
+ _rollupPluginBabelHelpers.classCallCheck(this, SceneDataManager);
36
+ this.sceneViewer = sceneViewer;
37
+ }
38
+
39
+ /**
40
+ * Get simplified scene data for pathfinding
41
+ * Collects all objects with objectType, filters out computed objects,
42
+ * and calculates world bounding boxes
43
+ * @returns {Object} Simplified scene data with children array
44
+ */
45
+ return _rollupPluginBabelHelpers.createClass(SceneDataManager, [{
46
+ key: "getSimplifiedSceneData",
47
+ value: function getSimplifiedSceneData() {
48
+ // Collect all objects with objectType (flattened list from scene traversal)
49
+ // Filter out ALL computed objects - only include declared/source objects
50
+ var sceneDataNew = [];
51
+ this.sceneViewer.scene.traverse(function (obj) {
52
+ if (obj.userData && obj.userData.objectType) {
53
+ // Skip computed gateways (only include declared/manual gateways)
54
+ if (obj.userData.objectType === 'gateway' && !obj.userData.isDeclared) {
55
+ return;
56
+ }
57
+ sceneDataNew.push(obj);
58
+ }
59
+ });
60
+ console.log('🔗 [SceneDataManager] sceneDataNew (flattened):', sceneDataNew);
61
+
62
+ // Calculate world bounding boxes for each object individually (after flattening)
63
+ // This way we don't need to worry about children - each object is standalone
64
+ var simplifiedSceneData = {};
65
+ simplifiedSceneData.children = sceneDataNew.map(function (obj) {
66
+ var _obj$children;
67
+ var uuid = obj.uuid;
68
+
69
+ // Calculate world bounding box for this individual object
70
+ var worldBoundingBox = null;
71
+
72
+ // For meshes, calculate bbox from geometry only (ignoring children)
73
+ if (obj.isMesh && obj.geometry) {
74
+ try {
75
+ // Compute bounding box from geometry in world space
76
+ var bbox = new THREE__namespace.Box3();
77
+ obj.geometry.computeBoundingBox();
78
+ if (obj.geometry.boundingBox) {
79
+ // Transform local bbox to world space
80
+ bbox.copy(obj.geometry.boundingBox);
81
+ bbox.applyMatrix4(obj.matrixWorld);
82
+
83
+ // Only include valid bounding boxes
84
+ // Check if all components of min and max are finite numbers
85
+ var isValidBBox = !bbox.isEmpty() && isFinite(bbox.min.x) && isFinite(bbox.min.y) && isFinite(bbox.min.z) && isFinite(bbox.max.x) && isFinite(bbox.max.y) && isFinite(bbox.max.z);
86
+ if (isValidBBox) {
87
+ worldBoundingBox = {
88
+ min: bbox.min.toArray(),
89
+ max: bbox.max.toArray()
90
+ };
91
+ } else {
92
+ console.warn("\u26A0\uFE0F Invalid bounding box for ".concat(uuid, ", skipping"));
93
+ }
94
+ }
95
+ } catch (error) {
96
+ console.warn("\u26A0\uFE0F Failed to calculate bounding box for ".concat(uuid, ":"), error);
97
+ }
98
+ }
99
+ // For groups or objects with children, use setFromObject but only on this object
100
+ else if (obj.isGroup || ((_obj$children = obj.children) === null || _obj$children === void 0 ? void 0 : _obj$children.length) > 0) {
101
+ try {
102
+ var _bbox = new THREE__namespace.Box3().setFromObject(obj);
103
+
104
+ // Check if all components of min and max are finite numbers
105
+ var _isValidBBox = !_bbox.isEmpty() && isFinite(_bbox.min.x) && isFinite(_bbox.min.y) && isFinite(_bbox.min.z) && isFinite(_bbox.max.x) && isFinite(_bbox.max.y) && isFinite(_bbox.max.z);
106
+ if (_isValidBBox) {
107
+ worldBoundingBox = {
108
+ min: _bbox.min.toArray(),
109
+ max: _bbox.max.toArray()
110
+ };
111
+ }
112
+ } catch (error) {
113
+ console.warn("\u26A0\uFE0F Failed to calculate bounding box for ".concat(uuid, ":"), error);
114
+ }
115
+ }
116
+ var results = {
117
+ uuid: uuid,
118
+ userData: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, obj.userData), worldBoundingBox && {
119
+ worldBoundingBox: worldBoundingBox
120
+ })
121
+ };
122
+ if (obj.userData.objectType.includes('connector') || obj.userData.objectType === 'gateway') {
123
+ var worldPosition = new THREE__namespace.Vector3();
124
+ obj.getWorldPosition(worldPosition);
125
+ results.userData.position = [worldPosition.x, worldPosition.y, worldPosition.z];
126
+ }
127
+ return results;
128
+ });
129
+ return simplifiedSceneData;
130
+ }
131
+
132
+ /**
133
+ * Helper method to find an object in scene data by UUID
134
+ * @param {Object} sceneData - Scene data to search
135
+ * @param {string} uuid - UUID to find
136
+ * @returns {Object|null} Found object or null
137
+ */
138
+ }, {
139
+ key: "findObjectInSceneData",
140
+ value: function findObjectInSceneData(sceneData, uuid) {
141
+ var _searchChildren = function searchChildren(children) {
142
+ var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(children),
143
+ _step;
144
+ try {
145
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
146
+ var child = _step.value;
147
+ if (child.uuid === uuid) {
148
+ return child;
149
+ }
150
+ if (child.children) {
151
+ var found = _searchChildren(child.children);
152
+ if (found) return found;
153
+ }
154
+ }
155
+ } catch (err) {
156
+ _iterator.e(err);
157
+ } finally {
158
+ _iterator.f();
159
+ }
160
+ return null;
161
+ };
162
+ if (sceneData.children) {
163
+ return _searchChildren(sceneData.children);
164
+ }
165
+ return null;
166
+ }
167
+
168
+ /**
169
+ * Mark an object as declared (manual) in both the scene object and scene data
170
+ * @param {THREE.Object3D} object - The object to mark as declared
171
+ * @param {Object} currentSceneData - Current scene data
172
+ * @param {Object} additionalSceneDataProps - Additional properties to add to scene data (optional)
173
+ */
174
+ }, {
175
+ key: "markObjectAsDeclared",
176
+ value: function markObjectAsDeclared(object, currentSceneData) {
177
+ var additionalSceneDataProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
178
+ // Mark in the scene object
179
+ object.userData.isDeclared = true;
180
+
181
+ // Find and update in scene data
182
+ var foundInSceneData = false;
183
+ for (var i = 0; i < currentSceneData.scene.children.length; i++) {
184
+ var _object$userData, _child$userData;
185
+ var child = currentSceneData.scene.children[i];
186
+ if (child.uuid === object.uuid || child.uuid === ((_object$userData = object.userData) === null || _object$userData === void 0 ? void 0 : _object$userData.originalUuid) || object.uuid === ((_child$userData = child.userData) === null || _child$userData === void 0 ? void 0 : _child$userData.originalUuid)) {
187
+ var _object$userData2, _object$userData3;
188
+ if (!child.userData) child.userData = {};
189
+ child.userData.isDeclared = true;
190
+
191
+ // Update position in scene data
192
+ if (!child.position) {
193
+ child.position = {};
194
+ }
195
+ child.position.x = object.position.x;
196
+ child.position.y = object.position.y;
197
+ child.position.z = object.position.z;
198
+
199
+ // For gateways and connectors, also update userData.position array for pathfinder compatibility
200
+ if (((_object$userData2 = object.userData) === null || _object$userData2 === void 0 ? void 0 : _object$userData2.objectType) === 'gateway' || ((_object$userData3 = object.userData) === null || _object$userData3 === void 0 ? void 0 : _object$userData3.objectType) === 'connector') {
201
+ child.userData.position = [object.position.x, object.position.y, object.position.z];
202
+ }
203
+ console.log("\u2705 Marked object as declared and updated position in scene data: ".concat(child.uuid));
204
+ foundInSceneData = true;
205
+ break;
206
+ }
207
+ }
208
+
209
+ // If not found in scene data, add it
210
+ if (!foundInSceneData) {
211
+ var _object$userData4, _object$userData5, _object$userData6;
212
+ console.log("\u26A0\uFE0F Object ".concat(object.uuid, " not found in scene data, adding it now"));
213
+ var sceneDataObject = _rollupPluginBabelHelpers.objectSpread2({
214
+ uuid: object.uuid,
215
+ userData: _rollupPluginBabelHelpers.objectSpread2({
216
+ objectType: object.userData.objectType,
217
+ isDeclared: true
218
+ }, object.userData),
219
+ position: {
220
+ x: object.position.x,
221
+ y: object.position.y,
222
+ z: object.position.z
223
+ }
224
+ }, additionalSceneDataProps);
225
+
226
+ // For gateways and connectors, also add position array to userData for pathfinder compatibility
227
+ if (((_object$userData4 = object.userData) === null || _object$userData4 === void 0 ? void 0 : _object$userData4.objectType) === 'gateway' || ((_object$userData5 = object.userData) === null || _object$userData5 === void 0 ? void 0 : _object$userData5.objectType) === 'connector') {
228
+ sceneDataObject.userData.position = [object.position.x, object.position.y, object.position.z];
229
+ }
230
+
231
+ // For segments, initialize children array to hold connectors
232
+ if (((_object$userData6 = object.userData) === null || _object$userData6 === void 0 ? void 0 : _object$userData6.objectType) === 'segment') {
233
+ sceneDataObject.children = [];
234
+ console.log("\uD83D\uDCE6 Initialized children array for segment: ".concat(object.uuid));
235
+ }
236
+ currentSceneData.scene.children.push(sceneDataObject);
237
+ console.log("\u2705 Added object to scene data as declared: ".concat(object.uuid));
238
+ } else {
239
+ var _object$userData8;
240
+ // If segment was found in scene data, ensure it has a children array
241
+ var _child = currentSceneData.scene.children.find(function (c) {
242
+ var _object$userData7, _c$userData;
243
+ return c.uuid === object.uuid || c.uuid === ((_object$userData7 = object.userData) === null || _object$userData7 === void 0 ? void 0 : _object$userData7.originalUuid) || object.uuid === ((_c$userData = c.userData) === null || _c$userData === void 0 ? void 0 : _c$userData.originalUuid);
244
+ });
245
+ if (_child && ((_object$userData8 = object.userData) === null || _object$userData8 === void 0 ? void 0 : _object$userData8.objectType) === 'segment') {
246
+ if (!_child.children) {
247
+ _child.children = [];
248
+ console.log("\uD83D\uDCE6 Initialized children array for existing segment: ".concat(_child.uuid));
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }]);
254
+ }();
255
+
256
+ exports.SceneDataManager = SceneDataManager;