@2112-lab/central-plant 0.3.16 → 0.3.18

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.
@@ -0,0 +1,111 @@
1
+ import { toConsumableArray as _toConsumableArray, slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
+
3
+ /**
4
+ * Utility function to update userData.direction for components after 90-degree rotation
5
+ * This function handles the direction vector transformation for connectors when their parent component is rotated
6
+ *
7
+ * @param {THREE.Object3D} component - The component that was rotated
8
+ * @param {string} axis - The axis of rotation ('x', 'y', or 'z')
9
+ * @param {number} degrees - The rotation angle in degrees (should be multiple of 90)
10
+ */
11
+ function updateDirectionAfterRotation(component, axis, degrees) {
12
+ if (!component) {
13
+ console.warn('⚠️ updateDirectionAfterRotation: No component provided');
14
+ return;
15
+ }
16
+
17
+ // Only handle 90-degree increments
18
+ if (degrees % 90 !== 0) {
19
+ console.warn('⚠️ updateDirectionAfterRotation: Only 90-degree increments are supported');
20
+ return;
21
+ }
22
+
23
+ // Normalize degrees to 0-360 range
24
+ var normalizedDegrees = (degrees % 360 + 360) % 360;
25
+ console.log("\uD83D\uDD04 Updating direction vectors for ".concat(component.name || component.uuid, " after ").concat(degrees, "\xB0 rotation around ").concat(axis, " axis"));
26
+
27
+ // Traverse all children (connectors) and update their direction vectors
28
+ component.traverse(function (child) {
29
+ var _child$userData, _child$userData2;
30
+ var childType = ((_child$userData = child.userData) === null || _child$userData === void 0 ? void 0 : _child$userData.objectType) || ((_child$userData2 = child.userData) === null || _child$userData2 === void 0 ? void 0 : _child$userData2.objectType);
31
+ if (child.userData && Array.isArray(child.userData.direction) && childType === 'connector') {
32
+ var originalDirection = _toConsumableArray(child.userData.direction);
33
+ var newDirection = rotateDirectionVector(originalDirection, axis, normalizedDegrees);
34
+
35
+ // Update the direction
36
+ child.userData.direction = newDirection;
37
+ console.log("\uD83D\uDCCD Updated connector ".concat(child.name || child.uuid, " direction:"), {
38
+ original: originalDirection,
39
+ new: newDirection,
40
+ rotationAxis: axis,
41
+ rotationDegrees: degrees
42
+ });
43
+ }
44
+ });
45
+ }
46
+
47
+ /**
48
+ * Rotate a direction vector by 90-degree increments around a specific axis
49
+ *
50
+ * @param {Array<number>} direction - The original direction vector [x, y, z]
51
+ * @param {string} axis - The axis of rotation ('x', 'y', or 'z')
52
+ * @param {number} degrees - The rotation angle in degrees (must be multiple of 90)
53
+ * @returns {Array<number>} The new direction vector [x, y, z]
54
+ */
55
+ function rotateDirectionVector(direction, axis, degrees) {
56
+ if (!Array.isArray(direction) || direction.length !== 3) {
57
+ console.warn('⚠️ rotateDirectionVector: Invalid direction vector');
58
+ return direction;
59
+ }
60
+ var _direction = _slicedToArray(direction, 3),
61
+ x = _direction[0],
62
+ y = _direction[1],
63
+ z = _direction[2];
64
+ var steps = degrees / 90; // Number of 90-degree steps
65
+
66
+ for (var i = 0; i < steps; i++) {
67
+ var newX = x,
68
+ newY = y,
69
+ newZ = z;
70
+ switch (axis) {
71
+ case 'x':
72
+ // Rotation around X-axis in Z-up system with flipped Y: Y becomes -Z, Z becomes Y
73
+ newY = -z;
74
+ newZ = y;
75
+ break;
76
+ case 'y':
77
+ // Rotation around Y-axis in Z-up system with flipped Y: X becomes Z, Z becomes -X
78
+ newX = z;
79
+ newZ = -x;
80
+ break;
81
+ case 'z':
82
+ // Rotation around Z-axis in Z-up system with flipped Y: X becomes -Y, Y becomes X
83
+ newX = -y;
84
+ newY = x;
85
+ break;
86
+ default:
87
+ console.warn("\u26A0\uFE0F rotateDirectionVector: Invalid axis '".concat(axis, "'"));
88
+ return direction;
89
+ }
90
+ x = newX;
91
+ y = newY;
92
+ z = newZ;
93
+ }
94
+ return [x, y, z];
95
+ }
96
+
97
+ /**
98
+ * Example usage in your rotate method:
99
+ *
100
+ * // After applying rotation to the component
101
+ * component.rotation[axis] += radians
102
+ *
103
+ * // Update direction vectors for connectors
104
+ * updateDirectionAfterRotation(component, axis, value)
105
+ *
106
+ * // Update matrices
107
+ * component.updateMatrix()
108
+ * component.updateMatrixWorld(true)
109
+ */
110
+
111
+ export { updateDirectionAfterRotation };
@@ -1,5 +1,6 @@
1
1
  import { createClass as _createClass, createForOfIteratorHelper as _createForOfIteratorHelper, construct as _construct, toConsumableArray as _toConsumableArray, slicedToArray as _slicedToArray, classCallCheck as _classCallCheck } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import * as THREE from 'three';
3
+ import { updateDirectionAfterRotation } from '../../helpers/directionUtils.js';
3
4
 
4
5
  var TransformOperationsManager = /*#__PURE__*/function () {
5
6
  /**
@@ -692,16 +693,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
692
693
  if (!component || degrees % 90 !== 0) {
693
694
  return;
694
695
  }
695
- console.log("\uD83D\uDD04 Updating connector directions after ".concat(degrees, "\xB0 rotation around ").concat(axis, " axis"));
696
696
 
697
- // Simple approach: just log that directions may need manual verification
698
- // In most cases, Three.js world matrices handle the actual positioning correctly
699
- component.traverse(function (child) {
700
- var _child$userData5, _child$userData6;
701
- if (((_child$userData5 = child.userData) === null || _child$userData5 === void 0 ? void 0 : _child$userData5.objectType) === 'connector' && (_child$userData6 = child.userData) !== null && _child$userData6 !== void 0 && _child$userData6.direction) {
702
- console.log("\uD83D\uDCCD Connector ".concat(child.uuid, " direction may need verification after rotation"));
703
- }
704
- });
697
+ // Use the direction utility to update direction vectors on Three.js connector objects
698
+ updateDirectionAfterRotation(component, axis, degrees);
705
699
  }
706
700
 
707
701
  /**
@@ -855,9 +849,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
855
849
 
856
850
  // Traverse scene to find all connectors
857
851
  this.sceneViewer.scene.traverse(function (child) {
858
- var _child$userData7;
852
+ var _child$userData5;
859
853
  // Check if this is a connector (component connector or manual segment connector)
860
- if (((_child$userData7 = child.userData) === null || _child$userData7 === void 0 ? void 0 : _child$userData7.objectType) === 'connector') {
854
+ if (((_child$userData5 = child.userData) === null || _child$userData5 === void 0 ? void 0 : _child$userData5.objectType) === 'connector') {
861
855
  // Get world position of connector
862
856
  var connectorWorldPos = new THREE.Vector3();
863
857
  child.getWorldPosition(connectorWorldPos);
@@ -908,8 +902,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
908
902
  // Find all child connectors of the segment in the Three.js scene
909
903
  var connectors = [];
910
904
  segment.traverse(function (child) {
911
- var _child$userData8;
912
- if (((_child$userData8 = child.userData) === null || _child$userData8 === void 0 ? void 0 : _child$userData8.objectType) === 'segment-connector') {
905
+ var _child$userData6;
906
+ if (((_child$userData6 = child.userData) === null || _child$userData6 === void 0 ? void 0 : _child$userData6.objectType) === 'segment-connector') {
913
907
  connectors.push(child);
914
908
  }
915
909
  });
@@ -973,17 +967,17 @@ var TransformOperationsManager = /*#__PURE__*/function () {
973
967
 
974
968
  // Check all segments in the scene
975
969
  this.sceneViewer.scene.traverse(function (child) {
976
- var _child$userData9, _child$userData0;
970
+ var _child$userData7, _child$userData8;
977
971
  // Skip the segment itself
978
972
  if (child.uuid === segment.uuid) {
979
973
  return;
980
974
  }
981
975
 
982
976
  // Only check computed segments in the scene
983
- if (((_child$userData9 = child.userData) === null || _child$userData9 === void 0 ? void 0 : _child$userData9.objectType) === 'segment' && (_child$userData0 = child.userData) !== null && _child$userData0 !== void 0 && _child$userData0.isDeclared) {
984
- var _segment$userData6, _child$userData1, _segment$userData7, _child$userData10;
977
+ if (((_child$userData7 = child.userData) === null || _child$userData7 === void 0 ? void 0 : _child$userData7.objectType) === 'segment' && (_child$userData8 = child.userData) !== null && _child$userData8 !== void 0 && _child$userData8.isDeclared) {
978
+ var _segment$userData6, _child$userData9, _segment$userData7, _child$userData0;
985
979
  // Check if segments are part of the same connection path
986
- var sameConnection = ((_segment$userData6 = segment.userData) === null || _segment$userData6 === void 0 ? void 0 : _segment$userData6.pathFrom) === ((_child$userData1 = child.userData) === null || _child$userData1 === void 0 ? void 0 : _child$userData1.pathFrom) && ((_segment$userData7 = segment.userData) === null || _segment$userData7 === void 0 ? void 0 : _segment$userData7.pathTo) === ((_child$userData10 = child.userData) === null || _child$userData10 === void 0 ? void 0 : _child$userData10.pathTo);
980
+ var sameConnection = ((_segment$userData6 = segment.userData) === null || _segment$userData6 === void 0 ? void 0 : _segment$userData6.pathFrom) === ((_child$userData9 = child.userData) === null || _child$userData9 === void 0 ? void 0 : _child$userData9.pathFrom) && ((_segment$userData7 = segment.userData) === null || _segment$userData7 === void 0 ? void 0 : _segment$userData7.pathTo) === ((_child$userData0 = child.userData) === null || _child$userData0 === void 0 ? void 0 : _child$userData0.pathTo);
987
981
 
988
982
  // Get endpoints of the other segment (use stored endpoints if available)
989
983
  var otherEndpoints = _this2.getSegmentEndpoints(child);
@@ -1204,11 +1198,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1204
1198
 
1205
1199
  // Traverse scene to find all component connectors
1206
1200
  this.sceneViewer.scene.traverse(function (child) {
1207
- var _child$userData11;
1201
+ var _child$userData1;
1208
1202
  if (collision) return; // Stop if collision already found
1209
1203
 
1210
1204
  // Check if this is a component connector (not a segment-connector)
1211
- if (((_child$userData11 = child.userData) === null || _child$userData11 === void 0 ? void 0 : _child$userData11.objectType) === 'connector') {
1205
+ if (((_child$userData1 = child.userData) === null || _child$userData1 === void 0 ? void 0 : _child$userData1.objectType) === 'connector') {
1212
1206
  var _segment$userData10, _segment$userData11;
1213
1207
  // Skip connectors that are connected to this segment (pathFrom or pathTo)
1214
1208
  var segmentPathFrom = (_segment$userData10 = segment.userData) === null || _segment$userData10 === void 0 ? void 0 : _segment$userData10.pathFrom;
@@ -1322,9 +1316,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1322
1316
 
1323
1317
  // Traverse scene to find all component connectors
1324
1318
  this.sceneViewer.scene.traverse(function (child) {
1325
- var _child$userData12;
1319
+ var _child$userData10;
1326
1320
  // Check if this is a component connector (not a segment-connector)
1327
- if (((_child$userData12 = child.userData) === null || _child$userData12 === void 0 ? void 0 : _child$userData12.objectType) === 'connector') {
1321
+ if (((_child$userData10 = child.userData) === null || _child$userData10 === void 0 ? void 0 : _child$userData10.objectType) === 'connector') {
1328
1322
  // Get world position of connector
1329
1323
  var connectorWorldPos = new THREE.Vector3();
1330
1324
  child.getWorldPosition(connectorWorldPos);
@@ -1381,11 +1375,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1381
1375
 
1382
1376
  // Traverse scene to find all components
1383
1377
  this.sceneViewer.scene.traverse(function (child) {
1384
- var _child$userData13, _child$userData14;
1378
+ var _child$userData11, _child$userData12;
1385
1379
  if (collision) return; // Stop if collision already found
1386
1380
 
1387
1381
  // Check if this is a component (equipment)
1388
- if (((_child$userData13 = child.userData) === null || _child$userData13 === void 0 ? void 0 : _child$userData13.objectType) === 'component' && (_child$userData14 = child.userData) !== null && _child$userData14 !== void 0 && _child$userData14.libraryId) {
1382
+ if (((_child$userData11 = child.userData) === null || _child$userData11 === void 0 ? void 0 : _child$userData11.objectType) === 'component' && (_child$userData12 = child.userData) !== null && _child$userData12 !== void 0 && _child$userData12.libraryId) {
1389
1383
  // Create bounding box for the component
1390
1384
  var componentBBox = new THREE.Box3().setFromObject(child);
1391
1385
 
@@ -1424,11 +1418,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1424
1418
 
1425
1419
  // Traverse scene to find all manual segments (isDeclared === true)
1426
1420
  this.sceneViewer.scene.traverse(function (child) {
1427
- var _child$userData15, _child$userData16;
1421
+ var _child$userData13, _child$userData14;
1428
1422
  if (collision) return; // Stop if collision already found
1429
1423
 
1430
1424
  // Only check manual segments (isDeclared === true)
1431
- if (((_child$userData15 = child.userData) === null || _child$userData15 === void 0 ? void 0 : _child$userData15.objectType) === 'segment' && ((_child$userData16 = child.userData) === null || _child$userData16 === void 0 ? void 0 : _child$userData16.isDeclared) === true) {
1425
+ if (((_child$userData13 = child.userData) === null || _child$userData13 === void 0 ? void 0 : _child$userData13.objectType) === 'segment' && ((_child$userData14 = child.userData) === null || _child$userData14 === void 0 ? void 0 : _child$userData14.isDeclared) === true) {
1432
1426
  // Get segment endpoints
1433
1427
  var segmentEndpoints = _this3.getSegmentEndpoints(child);
1434
1428
 
@@ -1517,11 +1511,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1517
1511
 
1518
1512
  // Traverse scene to find all manual segments (isDeclared === true)
1519
1513
  this.sceneViewer.scene.traverse(function (child) {
1520
- var _child$userData17, _child$userData18;
1514
+ var _child$userData15, _child$userData16;
1521
1515
  if (collision) return; // Stop if collision already found
1522
1516
 
1523
1517
  // Only check manual segments (isDeclared === true)
1524
- if (((_child$userData17 = child.userData) === null || _child$userData17 === void 0 ? void 0 : _child$userData17.objectType) === 'segment' && ((_child$userData18 = child.userData) === null || _child$userData18 === void 0 ? void 0 : _child$userData18.isDeclared) === true) {
1518
+ if (((_child$userData15 = child.userData) === null || _child$userData15 === void 0 ? void 0 : _child$userData15.objectType) === 'segment' && ((_child$userData16 = child.userData) === null || _child$userData16 === void 0 ? void 0 : _child$userData16.isDeclared) === true) {
1525
1519
  // Get segment endpoints
1526
1520
  var segmentEndpoints = _this4.getSegmentEndpoints(child);
1527
1521
 
@@ -1578,11 +1572,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1578
1572
 
1579
1573
  // Traverse scene to find all components
1580
1574
  this.sceneViewer.scene.traverse(function (child) {
1581
- var _child$userData19, _child$userData20;
1575
+ var _child$userData17, _child$userData18;
1582
1576
  if (collision) return; // Stop if collision already found
1583
1577
 
1584
1578
  // Check if this is a component (equipment)
1585
- if (((_child$userData19 = child.userData) === null || _child$userData19 === void 0 ? void 0 : _child$userData19.objectType) === 'component' && (_child$userData20 = child.userData) !== null && _child$userData20 !== void 0 && _child$userData20.libraryId) {
1579
+ if (((_child$userData17 = child.userData) === null || _child$userData17 === void 0 ? void 0 : _child$userData17.objectType) === 'component' && (_child$userData18 = child.userData) !== null && _child$userData18 !== void 0 && _child$userData18.libraryId) {
1586
1580
  // Try to get worldBoundingBox from userData first (most up-to-date)
1587
1581
  var bbox = null;
1588
1582
  if (child.userData.worldBoundingBox) {
@@ -1727,8 +1721,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1727
1721
  // Get the moved segment's connectors
1728
1722
  var movedConnectors = [];
1729
1723
  movedSegment.traverse(function (child) {
1730
- var _child$userData21;
1731
- if (((_child$userData21 = child.userData) === null || _child$userData21 === void 0 ? void 0 : _child$userData21.objectType) === 'segment-connector') {
1724
+ var _child$userData19;
1725
+ if (((_child$userData19 = child.userData) === null || _child$userData19 === void 0 ? void 0 : _child$userData19.objectType) === 'segment-connector') {
1732
1726
  movedConnectors.push(child);
1733
1727
  }
1734
1728
  });
@@ -1798,8 +1792,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1798
1792
  // Get all connectors of the adjacent segment
1799
1793
  var adjacentConnectors = [];
1800
1794
  adjacentSegment.traverse(function (child) {
1801
- var _child$userData22;
1802
- if (((_child$userData22 = child.userData) === null || _child$userData22 === void 0 ? void 0 : _child$userData22.objectType) === 'segment-connector') {
1795
+ var _child$userData20;
1796
+ if (((_child$userData20 = child.userData) === null || _child$userData20 === void 0 ? void 0 : _child$userData20.objectType) === 'segment-connector') {
1803
1797
  adjacentConnectors.push(child);
1804
1798
  }
1805
1799
  });
@@ -1922,8 +1916,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1922
1916
  // Also update child connectors' positions if they exist
1923
1917
  if (sceneDataComponent.children) {
1924
1918
  sceneDataComponent.children.forEach(function (child) {
1925
- var _child$userData23;
1926
- if (((_child$userData23 = child.userData) === null || _child$userData23 === void 0 ? void 0 : _child$userData23.objectType) === 'connector') {
1919
+ var _child$userData21;
1920
+ if (((_child$userData21 = child.userData) === null || _child$userData21 === void 0 ? void 0 : _child$userData21.objectType) === 'connector') {
1927
1921
  // Find the actual connector object in the scene
1928
1922
  var connectorObj = component.children.find(function (c) {
1929
1923
  var _c$userData;
@@ -1985,14 +1979,15 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1985
1979
  // Also update child connectors' positions if they exist (rotation moves them in world space)
1986
1980
  if (sceneDataComponent.children) {
1987
1981
  sceneDataComponent.children.forEach(function (child) {
1988
- var _child$userData24;
1989
- if (((_child$userData24 = child.userData) === null || _child$userData24 === void 0 ? void 0 : _child$userData24.objectType) === 'connector') {
1982
+ var _child$userData22;
1983
+ if (((_child$userData22 = child.userData) === null || _child$userData22 === void 0 ? void 0 : _child$userData22.objectType) === 'connector') {
1990
1984
  // Find the actual connector object in the scene
1991
1985
  var connectorObj = component.children.find(function (c) {
1992
1986
  var _c$userData2;
1993
1987
  return c.uuid === child.uuid || ((_c$userData2 = c.userData) === null || _c$userData2 === void 0 ? void 0 : _c$userData2.originalUuid) === child.uuid;
1994
1988
  });
1995
1989
  if (connectorObj) {
1990
+ var _connectorObj$userDat;
1996
1991
  // Get world position of connector
1997
1992
  var worldPos = new THREE.Vector3();
1998
1993
  connectorObj.getWorldPosition(worldPos);
@@ -2003,6 +1998,12 @@ var TransformOperationsManager = /*#__PURE__*/function () {
2003
1998
  }
2004
1999
  child.userData.position = [cleanValue(worldPos.x), cleanValue(worldPos.y), cleanValue(worldPos.z)];
2005
2000
  console.log(" \u21B3 Updated child connector ".concat(child.uuid, " position to [").concat(child.userData.position.join(', '), "]"));
2001
+
2002
+ // Update connector's direction in scene data from the Three.js object
2003
+ if ((_connectorObj$userDat = connectorObj.userData) !== null && _connectorObj$userDat !== void 0 && _connectorObj$userDat.direction && Array.isArray(connectorObj.userData.direction)) {
2004
+ child.userData.direction = _toConsumableArray(connectorObj.userData.direction);
2005
+ console.log(" \u21B3 Updated child connector ".concat(child.uuid, " direction to [").concat(child.userData.direction.join(', '), "]"));
2006
+ }
2006
2007
  }
2007
2008
  }
2008
2009
  });
@@ -2315,8 +2316,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
2315
2316
  // Check if either external connector belongs to the active segment
2316
2317
  var activeSegmentConnectors = [];
2317
2318
  activeSegment.traverse(function (child) {
2318
- var _child$userData25;
2319
- if (((_child$userData25 = child.userData) === null || _child$userData25 === void 0 ? void 0 : _child$userData25.objectType) === 'segment-connector') {
2319
+ var _child$userData23;
2320
+ if (((_child$userData23 = child.userData) === null || _child$userData23 === void 0 ? void 0 : _child$userData23.objectType) === 'segment-connector') {
2320
2321
  activeSegmentConnectors.push(child.uuid);
2321
2322
  }
2322
2323
  });
@@ -2364,8 +2365,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
2364
2365
  // Get all connectors of the active segment
2365
2366
  var activeConnectors = [];
2366
2367
  activeSegment.traverse(function (child) {
2367
- var _child$userData26;
2368
- if (((_child$userData26 = child.userData) === null || _child$userData26 === void 0 ? void 0 : _child$userData26.objectType) === 'segment-connector') {
2368
+ var _child$userData24;
2369
+ if (((_child$userData24 = child.userData) === null || _child$userData24 === void 0 ? void 0 : _child$userData24.objectType) === 'segment-connector') {
2369
2370
  activeConnectors.push(child);
2370
2371
  }
2371
2372
  });
@@ -420,6 +420,22 @@ var PathfindingManager = /*#__PURE__*/function (_BaseDisposable) {
420
420
  this.pathfinder = new Pathfinder(this.pathfinderConfig);
421
421
  this.sceneViewer.pathfinder = this.pathfinder;
422
422
 
423
+ // ── Early exit if no connections ───────────────────────────────────
424
+ // Skip expensive bounding box computation when there's nothing to connect
425
+ if (!(!connections || connections.length === 0)) {
426
+ _context.n = 1;
427
+ break;
428
+ }
429
+ console.log("\u23ED\uFE0F Skipping pathfinding - no connections [".concat(context, "]"));
430
+ return _context.a(2, {
431
+ paths: [],
432
+ gateways: [],
433
+ rewiredConnections: [],
434
+ metrics: {
435
+ total: 0
436
+ }
437
+ });
438
+ case 1:
423
439
  // ── Stage 1: Input Generation ──────────────────────────────────────
424
440
  inputGenStart = performance.now(); // Ensure all matrices are up to date before bounding box calculations (for all pathfinding executions)
425
441
  this.sceneViewer.scene.updateMatrixWorld(true);
@@ -1,4 +1,4 @@
1
- import { createClass as _createClass, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, createForOfIteratorHelper as _createForOfIteratorHelper, typeof as _typeof } from '../../../_virtual/_rollupPluginBabelHelpers.js';
1
+ import { createClass as _createClass, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray, typeof as _typeof, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, createForOfIteratorHelper as _createForOfIteratorHelper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import * as THREE from 'three';
3
3
  import { attachIODevicesToComponent } from '../../utils/ioDeviceUtils.js';
4
4
  import modelPreloader from '../../rendering/modelPreloader.js';
@@ -147,15 +147,23 @@ var ModelManager = /*#__PURE__*/function () {
147
147
  if (child.userData) {
148
148
  clonedConnector.userData = _objectSpread2({}, child.userData);
149
149
 
150
- // Deep copy critical data
150
+ // Deep copy critical data - handle both array [x,y,z] and object {x,y,z} formats
151
151
  if (child.userData.worldBoundingBox) {
152
+ var wbb = child.userData.worldBoundingBox;
152
153
  clonedConnector.userData.worldBoundingBox = {
153
- min: _toConsumableArray(child.userData.worldBoundingBox.min),
154
- max: _toConsumableArray(child.userData.worldBoundingBox.max)
154
+ min: Array.isArray(wbb.min) ? _toConsumableArray(wbb.min) : _objectSpread2({}, wbb.min),
155
+ max: Array.isArray(wbb.max) ? _toConsumableArray(wbb.max) : _objectSpread2({}, wbb.max)
155
156
  };
156
157
  }
157
158
  if (child.userData.direction) {
158
- clonedConnector.userData.direction = _toConsumableArray(child.userData.direction);
159
+ // Handle both array [x,y,z] and object {x,y,z} formats
160
+ if (Array.isArray(child.userData.direction)) {
161
+ clonedConnector.userData.direction = _toConsumableArray(child.userData.direction);
162
+ } else if (_typeof(child.userData.direction) === 'object') {
163
+ clonedConnector.userData.direction = _objectSpread2({}, child.userData.direction);
164
+ } else {
165
+ clonedConnector.userData.direction = child.userData.direction;
166
+ }
159
167
  }
160
168
 
161
169
  // Set originalUuid to match the actual uuid (maintains consistency)
@@ -186,6 +194,7 @@ var ModelManager = /*#__PURE__*/function () {
186
194
  _context2.n = 1;
187
195
  break;
188
196
  }
197
+ console.log("\uD83C\uDFAF GLB cache HIT: ".concat(modelKey));
189
198
  return _context2.a(2, gltfScene);
190
199
  case 1:
191
200
  // Check if preloading is in progress
@@ -194,6 +203,7 @@ var ModelManager = /*#__PURE__*/function () {
194
203
  _context2.n = 6;
195
204
  break;
196
205
  }
206
+ console.log("\u23F3 Waiting for preloader: ".concat(modelKey));
197
207
  _context2.p = 2;
198
208
  _context2.n = 3;
199
209
  return modelPreloader.preloadingPromise;
@@ -203,6 +213,7 @@ var ModelManager = /*#__PURE__*/function () {
203
213
  _context2.n = 4;
204
214
  break;
205
215
  }
216
+ console.log("\uD83C\uDFAF GLB cache HIT (after preload): ".concat(modelKey));
206
217
  return _context2.a(2, gltfScene);
207
218
  case 4:
208
219
  _context2.n = 6;
@@ -530,7 +541,7 @@ var ModelManager = /*#__PURE__*/function () {
530
541
  value: (function () {
531
542
  var _replaceWithGLBModels = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(libraryObjectsToReplace) {
532
543
  var _this3 = this;
533
- var glbLoadingPromises;
544
+ var startTime, glbLoadingPromises;
534
545
  return _regenerator().w(function (_context5) {
535
546
  while (1) switch (_context5.n) {
536
547
  case 0:
@@ -540,23 +551,29 @@ var ModelManager = /*#__PURE__*/function () {
540
551
  }
541
552
  return _context5.a(2);
542
553
  case 1:
554
+ startTime = performance.now();
543
555
  console.log("\uD83D\uDD04 Replacing ".concat(libraryObjectsToReplace.length, " objects with GLB models..."));
544
556
  glbLoadingPromises = libraryObjectsToReplace.map(function (_ref, index) {
545
557
  var basicObject = _ref.basicObject,
546
558
  jsonData = _ref.jsonData,
547
559
  componentData = _ref.componentData;
560
+ var modelStart = performance.now();
548
561
  return _this3.loadLibraryModel(basicObject, jsonData, componentData).then(function (libraryModel) {
562
+ var _jsonData$userData;
563
+ console.log("\u23F1\uFE0F GLB loaded: ".concat(((_jsonData$userData = jsonData.userData) === null || _jsonData$userData === void 0 ? void 0 : _jsonData$userData.libraryId) || jsonData.uuid, " in ").concat((performance.now() - modelStart).toFixed(0), "ms"));
549
564
  libraryObjectsToReplace[index].glbModel = libraryModel;
550
565
  return libraryModel;
551
566
  }).catch(function (error) {
552
- var _jsonData$userData;
553
- console.error("Failed to load ".concat((_jsonData$userData = jsonData.userData) === null || _jsonData$userData === void 0 ? void 0 : _jsonData$userData.libraryId, " GLB model:"), error);
567
+ var _jsonData$userData2;
568
+ console.error("Failed to load ".concat((_jsonData$userData2 = jsonData.userData) === null || _jsonData$userData2 === void 0 ? void 0 : _jsonData$userData2.libraryId, " GLB model:"), error);
554
569
  return basicObject;
555
570
  });
556
571
  });
557
572
  _context5.n = 2;
558
573
  return Promise.all(glbLoadingPromises);
559
574
  case 2:
575
+ console.log("\u23F1\uFE0F All GLB models loaded in ".concat((performance.now() - startTime).toFixed(0), "ms"));
576
+
560
577
  // Update world bounding boxes for loaded models and propagate to the live Three.js objects
561
578
  libraryObjectsToReplace.forEach(function (_ref2) {
562
579
  var jsonData = _ref2.jsonData,
@@ -680,9 +680,13 @@ var SceneOperationsManager = /*#__PURE__*/function () {
680
680
  value: (function () {
681
681
  var _loadSceneData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(data) {
682
682
  var isImported,
683
+ timers,
684
+ totalStart,
685
+ phaseStart,
683
686
  _yield$this$_createBa,
684
687
  crosscubeTextureSet,
685
688
  libraryObjectsToReplace,
689
+ totalTime,
686
690
  _args4 = arguments,
687
691
  _t3;
688
692
  return _regenerator().w(function (_context4) {
@@ -690,13 +694,20 @@ var SceneOperationsManager = /*#__PURE__*/function () {
690
694
  case 0:
691
695
  isImported = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : true;
692
696
  this.sceneViewer;
697
+ timers = {};
698
+ totalStart = performance.now();
693
699
  _context4.p = 1;
694
700
  console.log("Loading scene data (".concat(isImported ? 'imported' : 'default', ")..."));
695
701
 
696
702
  // Phase 1: Prepare scene
703
+ phaseStart = performance.now();
697
704
  _context4.n = 2;
698
705
  return this._prepareSceneForLoading(data, isImported);
699
706
  case 2:
707
+ timers.phase1_prepare = performance.now() - phaseStart;
708
+
709
+ // Phase 2: Load dependencies and create basic objects
710
+ phaseStart = performance.now();
700
711
  _context4.n = 3;
701
712
  return this._createBasicSceneObjects(data);
702
713
  case 3:
@@ -706,17 +717,33 @@ var SceneOperationsManager = /*#__PURE__*/function () {
706
717
  _yield$this$_createBa.materials;
707
718
  crosscubeTextureSet = _yield$this$_createBa.crosscubeTextureSet;
708
719
  libraryObjectsToReplace = _yield$this$_createBa.libraryObjectsToReplace;
720
+ timers.phase2_createObjects = performance.now() - phaseStart;
721
+
722
+ // Phase 3: Replace basic objects with GLB models (moved before pathfinding)
723
+ phaseStart = performance.now();
709
724
  _context4.n = 4;
710
725
  return this.modelManager.replaceWithGLBModels(libraryObjectsToReplace);
711
726
  case 4:
727
+ timers.phase3_glbModels = performance.now() - phaseStart;
728
+
729
+ // Phase 4: Setup pathfinding (moved after GLB loading for consistent bounding boxes)
730
+ phaseStart = performance.now();
712
731
  _context4.n = 5;
713
732
  return this._setupPathfinding(data, crosscubeTextureSet);
714
733
  case 5:
734
+ timers.phase4_pathfinding = performance.now() - phaseStart;
735
+
715
736
  // Phase 5: Finalize scene
737
+ phaseStart = performance.now();
716
738
  this._finalizeScene(data, crosscubeTextureSet, isImported);
739
+ timers.phase5_finalize = performance.now() - phaseStart;
717
740
 
718
741
  // Phase 6: Load behaviors (after GLB models are present so output objects can be resolved)
742
+ phaseStart = performance.now();
719
743
  this._processBehaviors(data);
744
+ timers.phase6_behaviors = performance.now() - phaseStart;
745
+ totalTime = performance.now() - totalStart;
746
+ console.log("\u23F1\uFE0F Scene Loading Performance:\n Phase 1 (Prepare) : ".concat(timers.phase1_prepare.toFixed(0), "ms\n Phase 2 (Create Objects): ").concat(timers.phase2_createObjects.toFixed(0), "ms\n Phase 3 (GLB Models) : ").concat(timers.phase3_glbModels.toFixed(0), "ms\n Phase 4 (Pathfinding) : ").concat(timers.phase4_pathfinding.toFixed(0), "ms\n Phase 5 (Finalize) : ").concat(timers.phase5_finalize.toFixed(0), "ms\n Phase 6 (Behaviors) : ").concat(timers.phase6_behaviors.toFixed(0), "ms\n \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n Total : ").concat(totalTime.toFixed(0), "ms"));
720
747
  console.log('✅ Scene loaded successfully');
721
748
 
722
749
  // Notify UI components (e.g. SceneHierarchy) that the scene is fully loaded
@@ -1,6 +1,7 @@
1
1
  import { createClass as _createClass, typeof as _typeof, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import * as THREE from 'three';
3
3
  import { GLTFLoader } from '../../node_modules/three/examples/jsm/loaders/GLTFLoader.js';
4
+ import { DRACOLoader } from '../../node_modules/three/examples/jsm/loaders/DRACOLoader.js';
4
5
 
5
6
  var ModelPreloader = /*#__PURE__*/function () {
6
7
  function ModelPreloader() {
@@ -8,13 +9,18 @@ var ModelPreloader = /*#__PURE__*/function () {
8
9
  this.modelCache = new Map(); // Cache for loaded models
9
10
  this.loadingPromises = new Map(); // Track ongoing loads to prevent duplicates
10
11
  this.gltfLoader = new GLTFLoader();
12
+
13
+ // Setup DRACO decoder for compressed GLB files
14
+ this.dracoLoader = new DRACOLoader();
15
+ this.dracoLoader.setDecoderPath('/draco/');
16
+ this.gltfLoader.setDRACOLoader(this.dracoLoader);
11
17
  this.isPreloading = false;
12
18
  this.preloadingPromise = null;
13
19
  this.componentDictionary = null;
14
20
  this.modelsBasePath = '/library/models/'; // Default local path
15
21
  this.urlResolver = null; // Optional function to resolve model URLs (for S3 authentication)
16
22
 
17
- console.log('🚀 ModelPreloader initialized with GLB support');
23
+ console.log('🚀 ModelPreloader initialized with GLB + DRACO support');
18
24
  }
19
25
 
20
26
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2112-lab/central-plant",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
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",