@2112-lab/central-plant 0.1.52 → 0.1.53

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.
@@ -239,6 +239,26 @@ function _objectSpread2(e) {
239
239
  }
240
240
  return e;
241
241
  }
242
+ function _objectWithoutProperties(e, t) {
243
+ if (null == e) return {};
244
+ var o,
245
+ r,
246
+ i = _objectWithoutPropertiesLoose(e, t);
247
+ if (Object.getOwnPropertySymbols) {
248
+ var n = Object.getOwnPropertySymbols(e);
249
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
250
+ }
251
+ return i;
252
+ }
253
+ function _objectWithoutPropertiesLoose(r, e) {
254
+ if (null == r) return {};
255
+ var t = {};
256
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
257
+ if (-1 !== e.indexOf(n)) continue;
258
+ t[n] = r[n];
259
+ }
260
+ return t;
261
+ }
242
262
  function _possibleConstructorReturn(t, e) {
243
263
  if (e && ("object" == typeof e || "function" == typeof e)) return e;
244
264
  if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
@@ -19759,7 +19779,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19759
19779
  }, {
19760
19780
  key: "updateSegmentConnectorPositions",
19761
19781
  value: function updateSegmentConnectorPositions(segment) {
19762
- var _this$sceneViewer4;
19782
+ var _this$sceneViewer4,
19783
+ _this = this;
19763
19784
  console.log("updateSegmentConnectorPositions started:", segment);
19764
19785
  if (!segment || !((_this$sceneViewer4 = this.sceneViewer) !== null && _this$sceneViewer4 !== void 0 && (_this$sceneViewer4 = _this$sceneViewer4.currentSceneData) !== null && _this$sceneViewer4 !== void 0 && _this$sceneViewer4.scene)) {
19765
19786
  console.warn('⚠️ updateSegmentConnectorPositions(): Missing segment or scene data');
@@ -19771,7 +19792,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19771
19792
  return Math.abs(value) < 1e-10 ? 0 : value;
19772
19793
  };
19773
19794
 
19774
- // Find all child connectors of the segment
19795
+ // Find all child connectors of the segment in the Three.js scene
19775
19796
  var connectors = [];
19776
19797
  segment.traverse(function (child) {
19777
19798
  var _child$userData8;
@@ -19785,29 +19806,14 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19785
19806
  }
19786
19807
  console.log("\uD83D\uDCCD Updating ".concat(connectors.length, " connector positions in scene data for segment ").concat(segment.uuid));
19787
19808
 
19788
- // First, find the segment in scene data
19789
- var sceneDataSegment = this.sceneViewer.currentSceneData.scene.children.find(function (child) {
19790
- var _segment$userData4;
19791
- return child.uuid === segment.uuid || child.uuid === ((_segment$userData4 = segment.userData) === null || _segment$userData4 === void 0 ? void 0 : _segment$userData4.originalUuid);
19792
- });
19793
- if (!sceneDataSegment) {
19794
- console.warn("\u26A0\uFE0F Segment ".concat(segment.uuid, " not found in scene data"));
19795
- return;
19796
- }
19797
- if (!sceneDataSegment.children || !Array.isArray(sceneDataSegment.children)) {
19798
- console.warn("\u26A0\uFE0F Segment ".concat(segment.uuid, " has no children array in scene data"));
19799
- return;
19800
- }
19801
- console.log("\u2705 Found segment in scene data with ".concat(sceneDataSegment.children.length, " children"));
19802
-
19803
- // Update each connector's position in scene data
19809
+ // Update each connector's position in scene data (connectors are at root level)
19804
19810
  connectors.forEach(function (connector) {
19805
19811
  // Get world position
19806
19812
  var worldPosition = new THREE__namespace.Vector3();
19807
19813
  connector.getWorldPosition(worldPosition);
19808
19814
 
19809
- // Find the connector in the segment's children array (not root scene.children)
19810
- var sceneDataConnector = sceneDataSegment.children.find(function (child) {
19815
+ // Find the connector at root level in scene data
19816
+ var sceneDataConnector = _this.sceneViewer.currentSceneData.scene.children.find(function (child) {
19811
19817
  var _connector$userData;
19812
19818
  return child.uuid === connector.uuid || child.uuid === ((_connector$userData = connector.userData) === null || _connector$userData === void 0 ? void 0 : _connector$userData.originalUuid);
19813
19819
  });
@@ -19816,9 +19822,14 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19816
19822
  sceneDataConnector.userData.position = [cleanPosition(worldPosition.x), cleanPosition(worldPosition.y), cleanPosition(worldPosition.z)];
19817
19823
  console.log("\u2705 Updated connector ".concat(connector.uuid, " position to [").concat(sceneDataConnector.userData.position.join(', '), "]"));
19818
19824
  } else {
19819
- console.warn("\u26A0\uFE0F Connector ".concat(connector.uuid, " not found in segment's children in scene data"));
19825
+ console.warn("\u26A0\uFE0F Connector ".concat(connector.uuid, " not found in scene data root level"));
19820
19826
  }
19821
19827
  });
19828
+
19829
+ // Update segment matrix and all connector matrices
19830
+ segment.updateMatrix();
19831
+ segment.updateMatrixWorld(true);
19832
+ console.log("\u2705 Updated matrices for segment ".concat(segment.uuid, " and its ").concat(connectors.length, " connectors"));
19822
19833
  }
19823
19834
 
19824
19835
  /**
@@ -19832,7 +19843,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19832
19843
  key: "checkSegmentIntersection",
19833
19844
  value: function checkSegmentIntersection(segment) {
19834
19845
  var _this$sceneViewer5,
19835
- _this = this;
19846
+ _this2 = this;
19836
19847
  if (!((_this$sceneViewer5 = this.sceneViewer) !== null && _this$sceneViewer5 !== void 0 && _this$sceneViewer5.scene)) {
19837
19848
  return false;
19838
19849
  }
@@ -19855,7 +19866,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19855
19866
  // Only check computed segments (isDeclared === false or undefined)
19856
19867
  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 ? void 0 : _child$userData0.isDeclared) !== true) {
19857
19868
  // Get endpoints of the computed segment
19858
- var computedEndpoints = _this.calculateSegmentEndpoints(child);
19869
+ var computedEndpoints = _this2.calculateSegmentEndpoints(child);
19859
19870
  var computedRadius = child.geometry.parameters.radiusTop || 0.05;
19860
19871
 
19861
19872
  // Combined radius threshold - segments intersect if closer than this
@@ -19880,7 +19891,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
19880
19891
  }
19881
19892
 
19882
19893
  // Calculate the minimum distance between the two line segments
19883
- var distance = _this.calculateSegmentToSegmentDistance(segmentEndpoints.start, segmentEndpoints.end, computedEndpoints.start, computedEndpoints.end);
19894
+ var distance = _this2.calculateSegmentToSegmentDistance(segmentEndpoints.start, segmentEndpoints.end, computedEndpoints.start, computedEndpoints.end);
19884
19895
 
19885
19896
  // Only flag as intersection if segments are closer than combined radius
19886
19897
  if (distance < combinedRadius) {
@@ -20219,7 +20230,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
20219
20230
  value: function snapSegmentConnectorsToNearbyEndpoints(movedSegment) {
20220
20231
  var _this$sceneViewer9,
20221
20232
  _this$sceneViewer0,
20222
- _this2 = this;
20233
+ _this3 = this;
20223
20234
  if (!movedSegment || !((_this$sceneViewer9 = this.sceneViewer) !== null && _this$sceneViewer9 !== void 0 && _this$sceneViewer9.scene)) {
20224
20235
  return [];
20225
20236
  }
@@ -20277,7 +20288,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
20277
20288
  // Find the adjacent connector in the scene
20278
20289
  var adjacentConnector = null;
20279
20290
  var adjacentSegment = null;
20280
- _this2.sceneViewer.scene.traverse(function (object) {
20291
+ _this3.sceneViewer.scene.traverse(function (object) {
20281
20292
  var _object$userData;
20282
20293
  if (object.uuid === pair.adjacentConnectorId && ((_object$userData = object.userData) === null || _object$userData === void 0 ? void 0 : _object$userData.objectType) === 'segment-connector') {
20283
20294
  adjacentConnector = object;
@@ -20326,12 +20337,12 @@ var TransformOperationsManager = /*#__PURE__*/function () {
20326
20337
  // Constrain movement to maintain orthogonal alignment
20327
20338
  // Horizontal segments: only adjust X and Y, keep Z constant
20328
20339
  // Vertical segments: only adjust Z, keep X and Y constant
20329
- var constrainedPosition = _this2.constrainPositionToOrthogonal(pair.newPosition, stationaryWorldPos, adjacentSegment);
20340
+ var constrainedPosition = _this3.constrainPositionToOrthogonal(pair.newPosition, stationaryWorldPos, adjacentSegment);
20330
20341
 
20331
20342
  // Recreate the segment mesh with new length using explicit endpoint positions
20332
20343
  // Pass the intended positions, not the connector objects (which may have temporary positions)
20333
20344
  // Pass movedSegment as activeSegment context so zero-length removal knows which segment to extend
20334
- _this2.recreateSegmentMeshWithNewLength(adjacentSegment, adjacentConnectors, constrainedPosition, stationaryWorldPos, movedSegment);
20345
+ _this3.recreateSegmentMeshWithNewLength(adjacentSegment, adjacentConnectors, constrainedPosition, stationaryWorldPos, movedSegment);
20335
20346
 
20336
20347
  // CRITICAL: After recreating the mesh, BOTH connectors need to be repositioned
20337
20348
  // because the segment's center and rotation have changed
@@ -20340,13 +20351,13 @@ var TransformOperationsManager = /*#__PURE__*/function () {
20340
20351
  var movingLocalPos = adjacentSegment.worldToLocal(constrainedPosition.clone());
20341
20352
  movingConnector.position.copy(movingLocalPos);
20342
20353
  movingConnector.updateMatrixWorld(true);
20343
- _this2.updateConnectorPositionInSceneData(movingConnector, constrainedPosition, adjacentSegment);
20354
+ _this3.updateConnectorPositionInSceneData(movingConnector, constrainedPosition, adjacentSegment);
20344
20355
 
20345
20356
  // Position stationary connector at its original world position
20346
20357
  var stationaryLocalPos = adjacentSegment.worldToLocal(stationaryWorldPos.clone());
20347
20358
  stationaryConnector.position.copy(stationaryLocalPos);
20348
20359
  stationaryConnector.updateMatrixWorld(true);
20349
- _this2.updateConnectorPositionInSceneData(stationaryConnector, stationaryWorldPos, adjacentSegment);
20360
+ _this3.updateConnectorPositionInSceneData(stationaryConnector, stationaryWorldPos, adjacentSegment);
20350
20361
 
20351
20362
  // Record this connection as satisfied
20352
20363
  satisfiedConnections.push({
@@ -20400,25 +20411,25 @@ var TransformOperationsManager = /*#__PURE__*/function () {
20400
20411
  value: function updateConnectorPositionInSceneData(connector, worldPosition, parentSegment) {
20401
20412
  var _this$sceneViewer1;
20402
20413
  // Update scene data if available
20403
- if (!((_this$sceneViewer1 = this.sceneViewer) !== null && _this$sceneViewer1 !== void 0 && _this$sceneViewer1.currentSceneData)) {
20414
+ if (!((_this$sceneViewer1 = this.sceneViewer) !== null && _this$sceneViewer1 !== void 0 && (_this$sceneViewer1 = _this$sceneViewer1.currentSceneData) !== null && _this$sceneViewer1 !== void 0 && _this$sceneViewer1.scene)) {
20404
20415
  return;
20405
20416
  }
20406
20417
  var cleanPosition = function cleanPosition(value) {
20407
20418
  return Math.abs(value) < 1e-10 ? 0 : value;
20408
20419
  };
20409
20420
 
20410
- // Find connector in scene data and update position
20411
- var segmentInSceneData = this.sceneViewer.currentSceneData.scene.children.find(function (child) {
20412
- return child.uuid === parentSegment.uuid;
20421
+ // Find the connector at root level in scene data
20422
+ // Manual segment connectors are stored at the root level, not nested under the segment
20423
+ var sceneDataConnector = this.sceneViewer.currentSceneData.scene.children.find(function (child) {
20424
+ var _connector$userData2;
20425
+ return child.uuid === connector.uuid || child.uuid === ((_connector$userData2 = connector.userData) === null || _connector$userData2 === void 0 ? void 0 : _connector$userData2.originalUuid);
20413
20426
  });
20414
- if (segmentInSceneData !== null && segmentInSceneData !== void 0 && segmentInSceneData.children) {
20415
- var connectorInSceneData = segmentInSceneData.children.find(function (child) {
20416
- return child.uuid === connector.uuid;
20417
- });
20418
- if (connectorInSceneData !== null && connectorInSceneData !== void 0 && connectorInSceneData.userData) {
20419
- connectorInSceneData.userData.position = [cleanPosition(worldPosition.x), cleanPosition(worldPosition.y), cleanPosition(worldPosition.z)];
20420
- console.log("\u2705 Updated connector ".concat(connector.uuid, " position in scene data to [").concat(connectorInSceneData.userData.position.join(', '), "]"));
20421
- }
20427
+ if (sceneDataConnector && sceneDataConnector.userData) {
20428
+ // Update position as array [x, y, z] for pathfinder compatibility
20429
+ sceneDataConnector.userData.position = [cleanPosition(worldPosition.x), cleanPosition(worldPosition.y), cleanPosition(worldPosition.z)];
20430
+ console.log("\u2705 Updated connector ".concat(connector.uuid, " position in scene data to [").concat(sceneDataConnector.userData.position.join(', '), "]"));
20431
+ } else {
20432
+ console.warn("\u26A0\uFE0F Connector ".concat(connector.uuid, " not found at root level in scene data"));
20422
20433
  }
20423
20434
  }
20424
20435
 
@@ -20610,135 +20621,167 @@ var TransformOperationsManager = /*#__PURE__*/function () {
20610
20621
  currentSceneData.connections = newConnections;
20611
20622
  console.log("\u2705 Updated connections: removed ".concat(removedConnections.length, ", added ").concat(externalId1 && externalId2 ? 1 : 0, ", total now: ").concat(newConnections.length));
20612
20623
 
20613
- // If there's an active segment (the one being translated), extend it to physically connect
20614
- if (activeSegment && externalId1 && externalId2) {
20615
- this._extendActiveSegmentToConnector(activeSegment, externalId1, externalId2, connector1Uuid, connector2Uuid);
20616
- }
20624
+ // Remove the segment's connectors from the scene and scene data
20625
+ connectors.forEach(function (connector) {
20626
+ var connectorUuid = connector.uuid;
20627
+
20628
+ // Remove connector from Three.js scene
20629
+ if (connector.parent) {
20630
+ connector.parent.remove(connector);
20631
+ console.log("\uD83D\uDDD1\uFE0F Removed connector ".concat(connectorUuid, " from Three.js scene"));
20632
+ }
20633
+
20634
+ // Dispose connector geometry and material
20635
+ if (connector.geometry) {
20636
+ connector.geometry.dispose();
20637
+ }
20638
+ if (connector.material) {
20639
+ if (Array.isArray(connector.material)) {
20640
+ connector.material.forEach(function (mat) {
20641
+ return mat.dispose();
20642
+ });
20643
+ } else {
20644
+ connector.material.dispose();
20645
+ }
20646
+ }
20647
+
20648
+ // Remove connector from scene data (connectors are at root level)
20649
+ if (currentSceneData.scene && currentSceneData.scene.children) {
20650
+ var connectorIndex = currentSceneData.scene.children.findIndex(function (child) {
20651
+ var _connector$userData3;
20652
+ return child.uuid === connectorUuid || child.uuid === ((_connector$userData3 = connector.userData) === null || _connector$userData3 === void 0 ? void 0 : _connector$userData3.originalUuid);
20653
+ });
20654
+ if (connectorIndex !== -1) {
20655
+ currentSceneData.scene.children.splice(connectorIndex, 1);
20656
+ console.log("\u2705 Removed connector ".concat(connectorUuid, " from scene data at index ").concat(connectorIndex));
20657
+ }
20658
+ }
20659
+ });
20617
20660
 
20618
20661
  // Remove the segment from the scene
20619
20662
  if (segment.parent) {
20620
20663
  segment.parent.remove(segment);
20664
+ console.log("\uD83D\uDDD1\uFE0F Removed segment ".concat(segment.uuid, " from Three.js scene"));
20621
20665
  }
20622
20666
 
20623
- // Dispose segment geometry and remove from scene data
20667
+ // Dispose segment geometry and material
20624
20668
  if (segment.geometry) {
20625
20669
  segment.geometry.dispose();
20626
20670
  }
20671
+ if (segment.material) {
20672
+ if (Array.isArray(segment.material)) {
20673
+ segment.material.forEach(function (mat) {
20674
+ return mat.dispose();
20675
+ });
20676
+ } else {
20677
+ segment.material.dispose();
20678
+ }
20679
+ }
20627
20680
 
20628
20681
  // Remove segment from scene data
20629
20682
  if (currentSceneData.scene && currentSceneData.scene.children) {
20630
20683
  var segmentIndex = currentSceneData.scene.children.findIndex(function (child) {
20631
- var _segment$userData5;
20632
- return child.uuid === segment.uuid || child.uuid === ((_segment$userData5 = segment.userData) === null || _segment$userData5 === void 0 ? void 0 : _segment$userData5.originalUuid);
20684
+ var _segment$userData4;
20685
+ return child.uuid === segment.uuid || child.uuid === ((_segment$userData4 = segment.userData) === null || _segment$userData4 === void 0 ? void 0 : _segment$userData4.originalUuid);
20633
20686
  });
20634
20687
  if (segmentIndex !== -1) {
20635
20688
  currentSceneData.scene.children.splice(segmentIndex, 1);
20636
20689
  console.log("\u2705 Removed segment from scene data at index ".concat(segmentIndex));
20637
20690
  }
20638
20691
  }
20639
- console.log("\u2705 Zero-length segment removed successfully: ".concat(segment.uuid));
20640
-
20641
- // Trigger path regeneration to create new segments for the merged connections
20642
- console.log('🔄 Triggering path regeneration to handle merged connections...');
20643
- if (sceneViewer && typeof sceneViewer.updatePaths === 'function') {
20644
- sceneViewer.updatePaths();
20645
- }
20646
- }
20647
-
20648
- /**
20649
- * Extend the active segment to physically connect with the connector on the other side
20650
- * @param {THREE.Object3D} activeSegment - The segment being translated (that caused the collapse)
20651
- * @param {string} externalId1 - First external connector UUID
20652
- * @param {string} externalId2 - Second external connector UUID
20653
- * @param {string} collapsedConnector1Uuid - First connector of the collapsed segment
20654
- * @param {string} collapsedConnector2Uuid - Second connector of the collapsed segment
20655
- * @private
20656
- */
20657
- }, {
20658
- key: "_extendActiveSegmentToConnector",
20659
- value: function _extendActiveSegmentToConnector(activeSegment, externalId1, externalId2, collapsedConnector1Uuid, collapsedConnector2Uuid) {
20660
- console.log("\uD83D\uDD17 Extending active segment ".concat(activeSegment.uuid, " to connect with external connector"));
20661
-
20662
- // Get the active segment's connectors
20663
- var activeConnectors = [];
20664
- activeSegment.traverse(function (child) {
20665
- var _child$userData15;
20666
- if (((_child$userData15 = child.userData) === null || _child$userData15 === void 0 ? void 0 : _child$userData15.objectType) === 'segment-connector') {
20667
- activeConnectors.push(child);
20668
- }
20669
- });
20670
- if (activeConnectors.length !== 2) {
20671
- console.warn("\u26A0\uFE0F Active segment doesn't have exactly 2 connectors, cannot extend");
20672
- return;
20673
- }
20674
-
20675
- // Determine which external connector is connected to the active segment
20676
- // and which one is on the other side (needs to be extended to)
20677
- var activeConnectorId = null;
20678
- var targetConnectorId = null;
20692
+ console.log("\u2705 Zero-length segment and its connectors removed successfully: ".concat(segment.uuid));
20679
20693
 
20680
- // Check if externalId1 or externalId2 is one of the active segment's connectors
20681
- var activeConnectorIds = activeConnectors.map(function (c) {
20682
- return c.uuid;
20683
- });
20684
- if (activeConnectorIds.includes(externalId1)) {
20685
- activeConnectorId = externalId1;
20686
- targetConnectorId = externalId2;
20687
- } else if (activeConnectorIds.includes(externalId2)) {
20688
- activeConnectorId = externalId2;
20689
- targetConnectorId = externalId1;
20690
- } else {
20691
- console.warn("\u26A0\uFE0F Neither external connector belongs to active segment - cannot extend");
20692
- return;
20693
- }
20694
- console.log("\uD83C\uDFAF Extending from active connector ".concat(activeConnectorId, " to target connector ").concat(targetConnectorId));
20694
+ // If there's an active segment being moved, extend it to connect to the external connector
20695
+ if (activeSegment && externalId1 && externalId2) {
20696
+ console.log('🔗 Extending active segment to maintain connection with external connector...');
20697
+
20698
+ // Find which connector belongs to the active segment
20699
+ var activeSegmentConnectorId = null;
20700
+ var externalConnectorToReach = null;
20701
+
20702
+ // Check if either external connector belongs to the active segment
20703
+ var activeSegmentConnectors = [];
20704
+ activeSegment.traverse(function (child) {
20705
+ var _child$userData15;
20706
+ if (((_child$userData15 = child.userData) === null || _child$userData15 === void 0 ? void 0 : _child$userData15.objectType) === 'segment-connector') {
20707
+ activeSegmentConnectors.push(child.uuid);
20708
+ }
20709
+ });
20710
+ if (activeSegmentConnectors.includes(externalId1)) {
20711
+ activeSegmentConnectorId = externalId1;
20712
+ externalConnectorToReach = externalId2;
20713
+ } else if (activeSegmentConnectors.includes(externalId2)) {
20714
+ activeSegmentConnectorId = externalId2;
20715
+ externalConnectorToReach = externalId1;
20716
+ }
20717
+ if (activeSegmentConnectorId && externalConnectorToReach) {
20718
+ console.log("\uD83D\uDCCD Active segment connector: ".concat(activeSegmentConnectorId));
20719
+ console.log("\uD83D\uDCCD External connector to reach: ".concat(externalConnectorToReach));
20720
+
20721
+ // Find the external connector object in the scene
20722
+ var externalConnectorObj = null;
20723
+ sceneViewer.scene.traverse(function (child) {
20724
+ if (child.uuid === externalConnectorToReach) {
20725
+ externalConnectorObj = child;
20726
+ }
20727
+ });
20728
+ if (externalConnectorObj) {
20729
+ // Get the external connector's world position
20730
+ var externalWorldPos = new THREE__namespace.Vector3();
20731
+ externalConnectorObj.getWorldPosition(externalWorldPos);
20732
+ console.log("\uD83C\uDFAF Extending active segment connector to position: [".concat(externalWorldPos.x.toFixed(3), ", ").concat(externalWorldPos.y.toFixed(3), ", ").concat(externalWorldPos.z.toFixed(3), "]"));
20733
+
20734
+ // Find the active segment's connector object
20735
+ var activeConnectorObj = null;
20736
+ activeSegment.traverse(function (child) {
20737
+ if (child.uuid === activeSegmentConnectorId) {
20738
+ activeConnectorObj = child;
20739
+ }
20740
+ });
20741
+ if (activeConnectorObj) {
20742
+ // Get all connectors of the active segment
20743
+ var activeConnectors = [];
20744
+ activeSegment.traverse(function (child) {
20745
+ var _child$userData16;
20746
+ if (((_child$userData16 = child.userData) === null || _child$userData16 === void 0 ? void 0 : _child$userData16.objectType) === 'segment-connector') {
20747
+ activeConnectors.push(child);
20748
+ }
20749
+ });
20695
20750
 
20696
- // Find the target connector in the scene
20697
- var targetConnector = null;
20698
- this.sceneViewer.scene.traverse(function (object) {
20699
- if (object.uuid === targetConnectorId) {
20700
- targetConnector = object;
20751
+ // Find the stationary connector (the one we're NOT moving)
20752
+ var stationaryConnector = activeConnectors.find(function (c) {
20753
+ return c.uuid !== activeSegmentConnectorId;
20754
+ });
20755
+ if (stationaryConnector && activeConnectors.length === 2) {
20756
+ var stationaryWorldPos = new THREE__namespace.Vector3();
20757
+ stationaryConnector.getWorldPosition(stationaryWorldPos);
20758
+
20759
+ // Recreate the active segment with new length to reach the external connector
20760
+ this.recreateSegmentMeshWithNewLength(activeSegment, activeConnectors, externalWorldPos, stationaryWorldPos);
20761
+
20762
+ // Update connector positions in scene data
20763
+ var movingLocalPos = activeSegment.worldToLocal(externalWorldPos.clone());
20764
+ activeConnectorObj.position.copy(movingLocalPos);
20765
+ activeConnectorObj.updateMatrixWorld(true);
20766
+ this.updateConnectorPositionInSceneData(activeConnectorObj, externalWorldPos, activeSegment);
20767
+ var stationaryLocalPos = activeSegment.worldToLocal(stationaryWorldPos.clone());
20768
+ stationaryConnector.position.copy(stationaryLocalPos);
20769
+ stationaryConnector.updateMatrixWorld(true);
20770
+ this.updateConnectorPositionInSceneData(stationaryConnector, stationaryWorldPos, activeSegment);
20771
+ console.log("\u2705 Active segment extended to connect with external connector");
20772
+ }
20773
+ }
20774
+ }
20775
+ } else {
20776
+ console.log('ℹ️ No active segment connector found in the connection - will regenerate paths instead');
20701
20777
  }
20702
- });
20703
- if (!targetConnector) {
20704
- console.warn("\u26A0\uFE0F Could not find target connector ".concat(targetConnectorId));
20705
- return;
20706
20778
  }
20707
20779
 
20708
- // Get target connector's world position
20709
- var targetWorldPos = new THREE__namespace.Vector3();
20710
- targetConnector.getWorldPosition(targetWorldPos);
20711
-
20712
- // Find which connector on the active segment needs to be moved
20713
- var movingConnector = activeConnectors.find(function (c) {
20714
- return c.uuid === activeConnectorId;
20715
- });
20716
- var stationaryConnector = activeConnectors.find(function (c) {
20717
- return c.uuid !== activeConnectorId;
20718
- });
20719
- if (!movingConnector || !stationaryConnector) {
20720
- console.warn("\u26A0\uFE0F Could not identify moving/stationary connectors");
20721
- return;
20780
+ // Trigger path regeneration to create new segments for any remaining unconnected endpoints
20781
+ console.log('🔄 Triggering path regeneration to handle any remaining connections...');
20782
+ if (sceneViewer && typeof sceneViewer.updatePaths === 'function') {
20783
+ sceneViewer.updatePaths();
20722
20784
  }
20723
-
20724
- // Get stationary connector's position
20725
- var stationaryWorldPos = new THREE__namespace.Vector3();
20726
- stationaryConnector.getWorldPosition(stationaryWorldPos);
20727
-
20728
- // Recreate the segment with new length to reach the target connector
20729
- console.log("\uD83D\uDCCF Extending active segment to reach target connector at [".concat(targetWorldPos.x.toFixed(2), ", ").concat(targetWorldPos.y.toFixed(2), ", ").concat(targetWorldPos.z.toFixed(2), "]"));
20730
- this.recreateSegmentMeshWithNewLength(activeSegment, activeConnectors, targetWorldPos, stationaryWorldPos);
20731
-
20732
- // Reposition both connectors after mesh recreation
20733
- var movingLocalPos = activeSegment.worldToLocal(targetWorldPos.clone());
20734
- movingConnector.position.copy(movingLocalPos);
20735
- movingConnector.updateMatrixWorld(true);
20736
- this.updateConnectorPositionInSceneData(movingConnector, targetWorldPos, activeSegment);
20737
- var stationaryLocalPos = activeSegment.worldToLocal(stationaryWorldPos.clone());
20738
- stationaryConnector.position.copy(stationaryLocalPos);
20739
- stationaryConnector.updateMatrixWorld(true);
20740
- this.updateConnectorPositionInSceneData(stationaryConnector, stationaryWorldPos, activeSegment);
20741
- console.log("\u2705 Active segment extended successfully to physically connect with target");
20742
20785
  }
20743
20786
  }]);
20744
20787
  }();
@@ -25185,6 +25228,7 @@ var PathRenderingManager = /*#__PURE__*/function (_BaseDisposable) {
25185
25228
  gatewayMesh.uuid = gateway.id;
25186
25229
 
25187
25230
  // Set userData to make gateways selectable
25231
+ // Note: No 'direction' attribute - gateways don't need it
25188
25232
  gatewayMesh.userData = {
25189
25233
  objectType: 'gateway',
25190
25234
  isDeclared: false,
@@ -25523,6 +25567,7 @@ var PathRenderingManager = /*#__PURE__*/function (_BaseDisposable) {
25523
25567
  }]);
25524
25568
  }(BaseDisposable);
25525
25569
 
25570
+ var _excluded$1 = ["direction"];
25526
25571
  var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25527
25572
  function ConnectorManager(sceneViewer) {
25528
25573
  var _this;
@@ -25577,6 +25622,7 @@ var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25577
25622
  connectorType: 'start',
25578
25623
  manualSegmentUuid: segment.uuid,
25579
25624
  isDeclared: true
25625
+ // Note: No 'direction' attribute - manual segment connectors don't need it
25580
25626
  };
25581
25627
 
25582
25628
  // Add start connector as child of segment
@@ -25597,6 +25643,7 @@ var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25597
25643
  connectorType: 'end',
25598
25644
  manualSegmentUuid: segment.uuid,
25599
25645
  isDeclared: true
25646
+ // Note: No 'direction' attribute - manual segment connectors don't need it
25600
25647
  };
25601
25648
 
25602
25649
  // Add end connector as child of segment
@@ -25639,6 +25686,7 @@ var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25639
25686
  /**
25640
25687
  * Add connectors to the scene and scene data
25641
25688
  * Note: Connectors are already children of the segment in the Three.js scene.
25689
+ * In scene data, they are added at the root level for faster pathfinder lookups.
25642
25690
  * @param {Array} connectors - Array of connector objects
25643
25691
  */
25644
25692
  }, {
@@ -25649,7 +25697,7 @@ var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25649
25697
  // Connectors are already children of the segment in Three.js, no need to add to scene
25650
25698
  console.log("\uD83D\uDD0C Connector already added as child of segment: ".concat(connector.uuid));
25651
25699
 
25652
- // Add to scene data structure as children of the segment (not at top level)
25700
+ // Add to scene data structure at root level for faster pathfinder lookups
25653
25701
  if (sceneViewer.currentSceneData && sceneViewer.currentSceneData.scene) {
25654
25702
  // Helper function to clean up floating-point precision errors
25655
25703
  var cleanPosition = function cleanPosition(value) {
@@ -25657,52 +25705,17 @@ var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25657
25705
  return Math.abs(value) < 1e-10 ? 0 : value;
25658
25706
  };
25659
25707
 
25660
- // Get world position for scene data (since connectors are now in local space)
25708
+ // Get world position for scene data (since connectors are in local space in Three.js)
25661
25709
  var worldPosition = new THREE__namespace.Vector3();
25662
25710
  connector.getWorldPosition(worldPosition);
25663
25711
 
25664
- // Get the segment UUID from connector's userData
25665
- var segmentUuid = connector.userData.manualSegmentUuid;
25666
- if (!segmentUuid) {
25667
- console.warn("\u26A0\uFE0F Connector ".concat(connector.uuid, " missing manualSegmentUuid, cannot add to scene data"));
25668
- return;
25669
- }
25670
-
25671
- // Find the segment in scene data
25672
- var _findSegment = function findSegment(children) {
25673
- var _iterator = _createForOfIteratorHelper(children),
25674
- _step;
25675
- try {
25676
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
25677
- var child = _step.value;
25678
- if (child.uuid === segmentUuid) {
25679
- return child;
25680
- }
25681
- if (child.children) {
25682
- var found = _findSegment(child.children);
25683
- if (found) return found;
25684
- }
25685
- }
25686
- } catch (err) {
25687
- _iterator.e(err);
25688
- } finally {
25689
- _iterator.f();
25690
- }
25691
- return null;
25692
- };
25693
- var segmentInSceneData = _findSegment(sceneViewer.currentSceneData.scene.children);
25694
- if (!segmentInSceneData) {
25695
- console.warn("\u26A0\uFE0F Could not find segment ".concat(segmentUuid, " in scene data for connector ").concat(connector.uuid));
25696
- return;
25697
- }
25698
-
25699
- // Ensure segment has a children array in scene data
25700
- if (!segmentInSceneData.children) {
25701
- segmentInSceneData.children = [];
25702
- }
25712
+ // Filter out 'direction' attribute - manual segment connectors don't need it
25713
+ var _ref = connector.userData || {};
25714
+ _ref.direction;
25715
+ var cleanedUserData = _objectWithoutProperties(_ref, _excluded$1);
25703
25716
  var sceneDataConnector = {
25704
25717
  uuid: connector.uuid,
25705
- userData: _objectSpread2(_objectSpread2({}, connector.userData), {}, {
25718
+ userData: _objectSpread2(_objectSpread2({}, cleanedUserData), {}, {
25706
25719
  isDeclared: true,
25707
25720
  // Mark manual segment connectors as declared
25708
25721
  // Position MUST be an array [x, y, z] for pathfinder compatibility
@@ -25710,9 +25723,10 @@ var ConnectorManager = /*#__PURE__*/function (_BaseDisposable) {
25710
25723
  })
25711
25724
  };
25712
25725
 
25713
- // Add connector as child of segment in scene data (not at top level)
25714
- segmentInSceneData.children.push(sceneDataConnector);
25715
- console.log("\uD83D\uDD0C Added connector to scene data as child of segment ".concat(segmentUuid, ": ").concat(connector.uuid));
25726
+ // Add connector at root level in scene data (not nested under segment)
25727
+ // This provides faster UUID lookups for the pathfinder
25728
+ sceneViewer.currentSceneData.scene.children.push(sceneDataConnector);
25729
+ console.log("\uD83D\uDD0C Added connector to scene data at root level: ".concat(connector.uuid));
25716
25730
  } else {
25717
25731
  console.warn('⚠️ Could not add connector to scene data - currentSceneData not available');
25718
25732
  }
@@ -26709,12 +26723,11 @@ var PathfindingManager = /*#__PURE__*/function (_BaseDisposable) {
26709
26723
  key: "_executePathfinding",
26710
26724
  value: function () {
26711
26725
  var _executePathfinding2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(sceneData, connections) {
26712
- var _simplifiedSceneData$;
26713
26726
  var options,
26714
26727
  _options$context,
26715
26728
  context,
26716
26729
  connectionsCopy,
26717
- simplifiedSceneData,
26730
+ sceneDataCopy,
26718
26731
  pathfindingResult,
26719
26732
  _args = arguments;
26720
26733
  return _regenerator().w(function (_context) {
@@ -26731,20 +26744,28 @@ var PathfindingManager = /*#__PURE__*/function (_BaseDisposable) {
26731
26744
 
26732
26745
  // Deep copy connections to prevent pathfinder from mutating the original
26733
26746
  connectionsCopy = JSON.parse(JSON.stringify(connections));
26734
- simplifiedSceneData = JSON.parse(JSON.stringify(this.getSimplifiedSceneData())); // Take snapshot before pathfinding execution (capture Three.js scene)
26735
- this.snapshotManager.takeSnapshot(this.sceneViewer.scene,
26736
- // Pass the actual Three.js scene
26737
- connectionsCopy, context);
26738
- console.log('[Pathfinder] simplifiedSceneData length at creation:', (_simplifiedSceneData$ = simplifiedSceneData.children) === null || _simplifiedSceneData$ === void 0 ? void 0 : _simplifiedSceneData$.length);
26739
- console.log('[Pathfinder] simplifiedSceneData (deep clone for inspection):', JSON.parse(JSON.stringify(simplifiedSceneData)));
26747
+ sceneDataCopy = JSON.parse(JSON.stringify(sceneData));
26748
+ console.log("[Pathfinder] sceneDataCopy:", sceneDataCopy);
26749
+
26750
+ // const simplifiedSceneData = JSON.parse(JSON.stringify( this.getSimplifiedSceneData() ));
26751
+
26752
+ // // Take snapshot before pathfinding execution (capture Three.js scene)
26753
+ // this.snapshotManager.takeSnapshot(
26754
+ // this.sceneViewer.scene, // Pass the actual Three.js scene
26755
+ // connectionsCopy,
26756
+ // context
26757
+ // );
26740
26758
 
26741
- // Add debugging for pathfinder input
26742
- console.log('🔍 PATHFINDER DEBUGGING:');
26743
- console.log('🔗 [Pathfinder] Connections:', JSON.parse(JSON.stringify(connectionsCopy)));
26759
+ // console.log('[Pathfinder] simplifiedSceneData length at creation:', simplifiedSceneData.children?.length);
26760
+ // console.log('[Pathfinder] simplifiedSceneData (deep clone for inspection):', JSON.parse(JSON.stringify(simplifiedSceneData)));
26761
+
26762
+ // // Add debugging for pathfinder input
26763
+ // console.log('🔍 PATHFINDER DEBUGGING:');
26764
+ // console.log('🔗 [Pathfinder] Connections:', JSON.parse(JSON.stringify(connectionsCopy)));
26744
26765
 
26745
26766
  // Find paths using v1.0.17 API (sceneData and connections separately)
26746
26767
  // Pass deep copy to ensure pathfinder cannot mutate original connections
26747
- pathfindingResult = this.pathfinder.findPaths(simplifiedSceneData, connectionsCopy);
26768
+ pathfindingResult = this.pathfinder.findPaths(sceneDataCopy, connectionsCopy);
26748
26769
  console.log('[Pathfinder] Found paths:', JSON.parse(JSON.stringify(pathfindingResult.paths)));
26749
26770
  console.log('Generated gateways:', JSON.parse(JSON.stringify(pathfindingResult.gateways)));
26750
26771
  console.log('Rewired connections:', JSON.parse(JSON.stringify(pathfindingResult.rewiredConnections)));
@@ -28181,6 +28202,8 @@ var SceneClearingUtility = /*#__PURE__*/function () {
28181
28202
  }]);
28182
28203
  }();
28183
28204
 
28205
+ var _excluded = ["direction"],
28206
+ _excluded2 = ["direction"];
28184
28207
  var SceneOperationsManager = /*#__PURE__*/function () {
28185
28208
  function SceneOperationsManager(sceneViewer) {
28186
28209
  _classCallCheck(this, SceneOperationsManager);
@@ -28733,7 +28756,12 @@ var SceneOperationsManager = /*#__PURE__*/function () {
28733
28756
  if (connectorData.position) {
28734
28757
  _connectorMesh.position.set(connectorData.position.x || 0, connectorData.position.y || 0, connectorData.position.z || 0);
28735
28758
  }
28736
- _connectorMesh.userData = _objectSpread2(_objectSpread2({}, connectorData.userData), {}, {
28759
+
28760
+ // Initialize userData (filter out 'direction' - manual segment connectors don't need it)
28761
+ var _ref = connectorData.userData || {};
28762
+ _ref.direction;
28763
+ var _cleanedUserData = _objectWithoutProperties(_ref, _excluded);
28764
+ _connectorMesh.userData = _objectSpread2(_objectSpread2({}, _cleanedUserData), {}, {
28737
28765
  originalUuid: connectorData.uuid,
28738
28766
  objectType: 'segment-connector',
28739
28767
  isManualSegmentConnector: true,
@@ -28752,8 +28780,11 @@ var SceneOperationsManager = /*#__PURE__*/function () {
28752
28780
  connectorMesh.position.set(connectorData.position.x || 0, connectorData.position.y || 0, connectorData.position.z || 0);
28753
28781
  }
28754
28782
 
28755
- // Initialize userData
28756
- connectorMesh.userData = _objectSpread2(_objectSpread2({}, connectorData.userData), {}, {
28783
+ // Initialize userData (filter out 'direction' - manual segment connectors don't need it)
28784
+ var _ref2 = connectorData.userData || {};
28785
+ _ref2.direction;
28786
+ var cleanedUserData = _objectWithoutProperties(_ref2, _excluded2);
28787
+ connectorMesh.userData = _objectSpread2(_objectSpread2({}, cleanedUserData), {}, {
28757
28788
  originalUuid: connectorData.uuid,
28758
28789
  objectType: 'segment-connector',
28759
28790
  isManualSegmentConnector: true,
@@ -33765,7 +33796,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
33765
33796
  * Initialize the CentralPlant manager
33766
33797
  *
33767
33798
  * @constructor
33768
- * @version 0.1.52
33799
+ * @version 0.1.53
33769
33800
  * @updated 2025-10-22
33770
33801
  *
33771
33802
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.