@2112-lab/central-plant 0.3.4 → 0.3.6

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.
@@ -1,9 +1,8 @@
1
- import { createClass as _createClass, objectSpread2 as _objectSpread2, construct as _construct, toConsumableArray as _toConsumableArray, objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, classCallCheck as _classCallCheck, createForOfIteratorHelper as _createForOfIteratorHelper, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, typeof as _typeof } from '../../../_virtual/_rollupPluginBabelHelpers.js';
1
+ import { createClass as _createClass, objectSpread2 as _objectSpread2, construct as _construct, toConsumableArray as _toConsumableArray, objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, typeof as _typeof } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import * as THREE from 'three';
3
3
  import { loadTextureSet } from '../environment/textureConfig.js';
4
4
  import { ModelManager } from './modelManager.js';
5
5
  import { SceneClearingUtility } from '../../utils/sceneClearingUtility.js';
6
- import { computeFilteredBoundingBox, computeIODeviceBoundingBoxes } from '../../utils/boundingBoxUtils.js';
7
6
 
8
7
  var _excluded = ["direction"],
9
8
  _excluded2 = ["direction"];
@@ -623,123 +622,52 @@ var SceneOperationsManager = /*#__PURE__*/function () {
623
622
  }
624
623
 
625
624
  /**
626
- * Helper function to compute world bounding boxes
627
- * For components: uses filtered bbox (excludes io-device and connector subtrees)
628
- * For io-devices: computes separate bounding boxes and injects them as children
625
+ * Sync world-space positions and isDeclared flags for gateways and connectors
626
+ * into the scene JSON data so the pathfinder can read them.
627
+ *
628
+ * Bounding boxes for components and segments are intentionally NOT computed here.
629
+ * They are computed (with matrix-hash caching) by
630
+ * PathfindingManager._enrichSceneDataWithBoundingBoxes(), which runs after GLB
631
+ * models are fully loaded and therefore produces correct values.
629
632
  */
630
633
  }, {
631
- key: "computeWorldBoundingBoxes",
632
- value: function computeWorldBoundingBoxes(data) {
633
- var component = this.sceneViewer;
634
- component.scene.traverse(function (object) {
635
- if (object.isMesh) {
636
- // Find the corresponding JSON object
637
- var jsonObject = null;
638
- var _findJsonObject = function findJsonObject(children) {
639
- var _iterator = _createForOfIteratorHelper(children),
640
- _step;
641
- try {
642
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
643
- var _object$userData, _child$userData4;
644
- var child = _step.value;
645
- // Enhanced matching logic with hardcoded UUID priority
646
-
647
- // Strategy 1: Direct hardcoded UUID match (HIGHEST PRIORITY)
648
- if (child.uuid === object.uuid || child.uuid === ((_object$userData = object.userData) === null || _object$userData === void 0 ? void 0 : _object$userData.originalUuid) || object.uuid === ((_child$userData4 = child.userData) === null || _child$userData4 === void 0 ? void 0 : _child$userData4.originalUuid)) {
649
- return child;
650
- }
651
-
652
- // Recursively search children
653
- if (child.children) {
654
- var found = _findJsonObject(child.children);
655
- if (found) return found;
656
- }
657
- }
658
- } catch (err) {
659
- _iterator.e(err);
660
- } finally {
661
- _iterator.f();
662
- }
663
- return null;
664
- };
665
- jsonObject = _findJsonObject(data.scene.children);
666
- if (jsonObject) {
667
- // Store in JSON userData for pathfinder (skip for gateways - they're just routing points)
668
- if (!jsonObject.userData) jsonObject.userData = {};
669
- if (jsonObject.userData.objectType === 'component') {
670
- // For components: compute filtered bounding box (excludes io-device and connector subtrees)
671
- var filteredBBox = computeFilteredBoundingBox(object, ['io-device', 'connector']);
672
- jsonObject.userData.worldBoundingBox = {
673
- min: filteredBBox.min.toArray(),
674
- max: filteredBBox.max.toArray()
675
- };
676
- console.log("Added filtered world bounding box for component:", jsonObject.userData.worldBoundingBox);
677
-
678
- // Compute and inject separate io-device bounding boxes as children
679
- var ioDeviceBBoxes = computeIODeviceBoundingBoxes(object);
680
- if (ioDeviceBBoxes.length > 0) {
681
- if (!jsonObject.children) jsonObject.children = [];
682
- ioDeviceBBoxes.forEach(function (deviceBBox) {
683
- var existingIndex = jsonObject.children.findIndex(function (c) {
684
- return c.uuid === deviceBBox.uuid;
685
- });
686
- if (existingIndex >= 0) {
687
- // Update existing entry
688
- if (!jsonObject.children[existingIndex].userData) jsonObject.children[existingIndex].userData = {};
689
- jsonObject.children[existingIndex].userData.objectType = 'io-device';
690
- jsonObject.children[existingIndex].userData.worldBoundingBox = deviceBBox.worldBoundingBox;
691
- } else {
692
- // Create new entry
693
- jsonObject.children.push({
694
- uuid: deviceBBox.uuid,
695
- userData: _objectSpread2(_objectSpread2({}, deviceBBox.userData), {}, {
696
- worldBoundingBox: deviceBBox.worldBoundingBox
697
- }),
698
- children: []
699
- });
700
- }
701
- });
702
- console.log("\uD83D\uDCE6 Injected ".concat(ioDeviceBBoxes.length, " io-device bbox(es) for component ").concat(jsonObject.uuid));
703
- }
704
- } else if (jsonObject.userData.objectType !== 'gateway') {
705
- // For non-component, non-gateway objects: standard bounding box
706
- var boundingBox = new THREE.Box3().setFromObject(object);
707
- jsonObject.userData.worldBoundingBox = {
708
- min: boundingBox.min.toArray(),
709
- max: boundingBox.max.toArray()
710
- };
711
- console.log("Added world bounding box:", jsonObject.userData.worldBoundingBox);
712
- }
713
-
714
- // For gateways and connectors, ensure userData.position exists in scene data
715
- // This is REQUIRED for pathfinder compatibility
716
- if (jsonObject.userData.objectType === 'gateway' || jsonObject.userData.objectType === 'connector') {
717
- // Use the object's world position (from Three.js mesh)
718
- var worldPos = new THREE.Vector3();
719
- object.getWorldPosition(worldPos);
720
-
721
- // ALWAYS update userData.position with world position
722
- // This is critical for manual segment connectors which start with local positions
723
- jsonObject.userData.position = [worldPos.x, worldPos.y, worldPos.z];
724
- console.log("\u2705 Set userData.position for ".concat(jsonObject.userData.objectType, " ").concat(jsonObject.uuid, ": [").concat(worldPos.x.toFixed(2), ", ").concat(worldPos.y.toFixed(2), ", ").concat(worldPos.z.toFixed(2), "]"));
725
-
726
- // For gateways, ensure isDeclared flag is in scene data
727
- if (jsonObject.userData.objectType === 'gateway') {
728
- if (jsonObject.userData.isDeclared === undefined) {
729
- jsonObject.userData.isDeclared = true;
730
- }
731
- }
732
-
733
- // For manual segment connectors, ensure isDeclared is set in scene data
734
- if (jsonObject.userData.objectType === 'segment-connector' && jsonObject.userData.isDeclared === undefined) {
735
- jsonObject.userData.isDeclared = true;
736
- console.log("\u2705 Set isDeclared=true for manual segment connector in scene data: ".concat(jsonObject.uuid));
737
- }
738
-
739
- // Also sync the mesh's userData.position (belt and suspenders approach)
740
- object.userData.position = [worldPos.x, worldPos.y, worldPos.z];
741
- }
634
+ key: "_syncPositionsForPathfinding",
635
+ value: function _syncPositionsForPathfinding(data) {
636
+ var scene = this.sceneViewer.scene;
637
+ var worldPos = new THREE.Vector3();
638
+ var syncPosition = function syncPosition(jsonObject) {
639
+ var _jsonObject$userData;
640
+ var object = scene.getObjectByProperty('uuid', jsonObject.uuid) || scene.getObjectByProperty('uuid', (_jsonObject$userData = jsonObject.userData) === null || _jsonObject$userData === void 0 ? void 0 : _jsonObject$userData.originalUuid);
641
+ if (!object) return;
642
+ object.getWorldPosition(worldPos);
643
+ var pos = [worldPos.x, worldPos.y, worldPos.z];
644
+ jsonObject.userData.position = pos;
645
+ object.userData.position = pos;
646
+ };
647
+ data.scene.children.forEach(function (jsonObject) {
648
+ var _jsonObject$userData2;
649
+ var type = (_jsonObject$userData2 = jsonObject.userData) === null || _jsonObject$userData2 === void 0 ? void 0 : _jsonObject$userData2.objectType;
650
+ if (type === 'gateway') {
651
+ syncPosition(jsonObject);
652
+ if (jsonObject.userData.isDeclared === undefined) {
653
+ jsonObject.userData.isDeclared = true;
742
654
  }
655
+ } else if (type === 'connector') {
656
+ syncPosition(jsonObject);
657
+ } else if (type === 'segment-connector') {
658
+ syncPosition(jsonObject);
659
+ if (jsonObject.userData.isDeclared === undefined) {
660
+ jsonObject.userData.isDeclared = true;
661
+ }
662
+ } else if (type === 'component' && Array.isArray(jsonObject.children)) {
663
+ // Connectors are injected as JSON children by _injectConnectorChildrenFromDictionary
664
+ // and their Three.js objects exist in the scene, created recursively by createSceneObject
665
+ jsonObject.children.forEach(function (childJson) {
666
+ var _childJson$userData;
667
+ if (((_childJson$userData = childJson.userData) === null || _childJson$userData === void 0 ? void 0 : _childJson$userData.objectType) === 'connector') {
668
+ syncPosition(childJson);
669
+ }
670
+ });
743
671
  }
744
672
  });
745
673
  }
@@ -904,10 +832,10 @@ var SceneOperationsManager = /*#__PURE__*/function () {
904
832
  var componentsProcessed = 0;
905
833
  var connectorsInjected = 0;
906
834
  data.scene.children.forEach(function (child) {
907
- var _child$userData5, _child$userData6, _child$userData7;
908
- var childType = ((_child$userData5 = child.userData) === null || _child$userData5 === void 0 ? void 0 : _child$userData5.objectType) || ((_child$userData6 = child.userData) === null || _child$userData6 === void 0 ? void 0 : _child$userData6.objectType);
835
+ var _child$userData4, _child$userData5, _child$userData6;
836
+ var childType = ((_child$userData4 = child.userData) === null || _child$userData4 === void 0 ? void 0 : _child$userData4.objectType) || ((_child$userData5 = child.userData) === null || _child$userData5 === void 0 ? void 0 : _child$userData5.objectType);
909
837
  // Only process components with libraryId
910
- if (childType === 'component' && (_child$userData7 = child.userData) !== null && _child$userData7 !== void 0 && _child$userData7.libraryId) {
838
+ if (childType === 'component' && (_child$userData6 = child.userData) !== null && _child$userData6 !== void 0 && _child$userData6.libraryId) {
911
839
  var libraryId = child.userData.libraryId;
912
840
  var dictEntry = componentDictionary[libraryId];
913
841
 
@@ -1064,23 +992,25 @@ var SceneOperationsManager = /*#__PURE__*/function () {
1064
992
  geometries = this.createSceneGeometries(data, componentDictionary); // Create basic objects and track GLB replacements
1065
993
  libraryObjectsToReplace = [];
1066
994
  data.scene.children.forEach(function (child, index) {
1067
- var _child$userData8, _child$userData9;
995
+ var _child$userData7, _child$userData8;
1068
996
  var createdObject = _this4.createSceneObject(child, geometries, materials, componentDictionary);
1069
997
  _this4.sceneViewer.scene.add(createdObject);
1070
998
 
1071
999
  // Track objects that need GLB model replacement
1072
- if ((_child$userData8 = child.userData) !== null && _child$userData8 !== void 0 && _child$userData8.libraryId && componentDictionary[(_child$userData9 = child.userData) === null || _child$userData9 === void 0 ? void 0 : _child$userData9.libraryId]) {
1073
- var _child$userData0;
1000
+ if ((_child$userData7 = child.userData) !== null && _child$userData7 !== void 0 && _child$userData7.libraryId && componentDictionary[(_child$userData8 = child.userData) === null || _child$userData8 === void 0 ? void 0 : _child$userData8.libraryId]) {
1001
+ var _child$userData9;
1074
1002
  libraryObjectsToReplace.push({
1075
1003
  basicObject: createdObject,
1076
1004
  jsonData: child,
1077
- componentData: componentDictionary[(_child$userData0 = child.userData) === null || _child$userData0 === void 0 ? void 0 : _child$userData0.libraryId]
1005
+ componentData: componentDictionary[(_child$userData9 = child.userData) === null || _child$userData9 === void 0 ? void 0 : _child$userData9.libraryId]
1078
1006
  });
1079
1007
  }
1080
1008
  });
1081
1009
 
1082
- // Compute bounding boxes for pathfinding
1083
- this.computeWorldBoundingBoxes(data);
1010
+ // Sync gateway/connector world positions into JSON before pathfinding.
1011
+ // Bounding boxes are computed later by PathfindingManager._enrichSceneDataWithBoundingBoxes
1012
+ // (after GLB models are loaded), so no bbox work is done here.
1013
+ this._syncPositionsForPathfinding(data);
1084
1014
  this._saveOriginalWorldMatrices(this.sceneViewer.scene);
1085
1015
  return _context6.a(2, {
1086
1016
  componentDictionary: componentDictionary,
@@ -1226,8 +1156,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
1226
1156
  var instanceBehaviors = [];
1227
1157
  if (Array.isArray(data === null || data === void 0 || (_data$scene3 = data.scene) === null || _data$scene3 === void 0 ? void 0 : _data$scene3.children)) {
1228
1158
  data.scene.children.forEach(function (child) {
1229
- var _child$userData1, _compData$defaultBeha;
1230
- var libraryId = (_child$userData1 = child.userData) === null || _child$userData1 === void 0 ? void 0 : _child$userData1.libraryId;
1159
+ var _child$userData0, _compData$defaultBeha;
1160
+ var libraryId = (_child$userData0 = child.userData) === null || _child$userData0 === void 0 ? void 0 : _child$userData0.libraryId;
1231
1161
  if (!libraryId) return;
1232
1162
  var instanceUuid = child.uuid;
1233
1163
  // Skip instances whose defaults were already resolved by Step A
@@ -1423,8 +1353,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
1423
1353
  key: "_saveOriginalWorldMatrices",
1424
1354
  value: function _saveOriginalWorldMatrices(scene) {
1425
1355
  scene.traverse(function (object) {
1426
- var _object$userData2;
1427
- if ((_object$userData2 = object.userData) !== null && _object$userData2 !== void 0 && _object$userData2.direction) {
1356
+ var _object$userData;
1357
+ if ((_object$userData = object.userData) !== null && _object$userData !== void 0 && _object$userData.direction) {
1428
1358
  var originalMatrix = new THREE.Matrix4();
1429
1359
  originalMatrix.copy(object.matrixWorld);
1430
1360
  }
@@ -1628,8 +1558,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
1628
1558
  // Process children (connectors, etc.) if they exist
1629
1559
  if (componentModel.children && componentModel.children.length > 0) {
1630
1560
  componentModel.children.forEach(function (child) {
1631
- var _child$userData10, _child$userData11;
1632
- var childType = ((_child$userData10 = child.userData) === null || _child$userData10 === void 0 ? void 0 : _child$userData10.objectType) || ((_child$userData11 = child.userData) === null || _child$userData11 === void 0 ? void 0 : _child$userData11.objectType);
1561
+ var _child$userData1, _child$userData10;
1562
+ var childType = ((_child$userData1 = child.userData) === null || _child$userData1 === void 0 ? void 0 : _child$userData1.objectType) || ((_child$userData10 = child.userData) === null || _child$userData10 === void 0 ? void 0 : _child$userData10.objectType);
1633
1563
  if (childType === 'connector') {
1634
1564
  var _child$geometry;
1635
1565
  var childBoundingBox = new THREE.Box3().setFromObject(child);
@@ -1714,8 +1644,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
1714
1644
  if (segment.children && segment.children.length > 0) {
1715
1645
  var childrenToRemove = _toConsumableArray(segment.children);
1716
1646
  childrenToRemove.forEach(function (child) {
1717
- var _child$userData12;
1718
- if ((_child$userData12 = child.userData) !== null && _child$userData12 !== void 0 && _child$userData12.isPipeElbow) {
1647
+ var _child$userData11;
1648
+ if ((_child$userData11 = child.userData) !== null && _child$userData11 !== void 0 && _child$userData11.isPipeElbow) {
1719
1649
  console.log("\uD83D\uDDD1\uFE0F Removing elbow child from segment before manualization: ".concat(child.uuid));
1720
1650
  segment.remove(child);
1721
1651
  if (child.geometry) child.geometry.dispose();