@2112-lab/central-plant 0.1.4 → 0.1.5

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 (87) hide show
  1. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
  2. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
  3. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
  4. package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
  5. package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
  6. package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
  7. package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
  8. package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
  9. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
  10. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
  11. package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
  12. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
  13. package/dist/cjs/src/analysis/analysis.js +560 -1
  14. package/dist/cjs/src/analysis/testing.js +958 -1
  15. package/dist/cjs/src/core/centralPlant.js +1149 -1
  16. package/dist/cjs/src/core/debugLogger.js +175 -1
  17. package/dist/cjs/src/core/mathUtils.js +574 -1
  18. package/dist/cjs/src/core/nameUtils.js +93 -1
  19. package/dist/cjs/src/data/export.js +716 -1
  20. package/dist/cjs/src/data/import.js +380 -1
  21. package/dist/cjs/src/data/numerics.js +522 -1
  22. package/dist/cjs/src/helpers/sceneHelper.js +572 -1
  23. package/dist/cjs/src/index.js +69 -1
  24. package/dist/cjs/src/managers/components/animationManager.js +123 -1
  25. package/dist/cjs/src/managers/components/componentManager.js +332 -1
  26. package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
  27. package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
  28. package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
  29. package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
  30. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
  31. package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
  32. package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
  33. package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
  34. package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
  35. package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
  36. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
  37. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
  38. package/dist/cjs/src/managers/system/disposalManager.js +444 -1
  39. package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
  40. package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
  41. package/dist/cjs/src/rendering/modelPreloader.js +369 -1
  42. package/dist/cjs/src/rendering/rendering2D.js +631 -1
  43. package/dist/cjs/src/rendering/rendering3D.js +685 -1
  44. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
  45. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
  46. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
  47. package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
  48. package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
  49. package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
  50. package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
  51. package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
  52. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
  53. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
  54. package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
  55. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
  56. package/dist/esm/src/analysis/analysis.js +536 -1
  57. package/dist/esm/src/analysis/testing.js +954 -1
  58. package/dist/esm/src/core/centralPlant.js +1144 -1
  59. package/dist/esm/src/core/debugLogger.js +167 -1
  60. package/dist/esm/src/core/mathUtils.js +570 -1
  61. package/dist/esm/src/core/nameUtils.js +87 -1
  62. package/dist/esm/src/data/export.js +712 -1
  63. package/dist/esm/src/data/import.js +356 -1
  64. package/dist/esm/src/data/numerics.js +518 -1
  65. package/dist/esm/src/helpers/sceneHelper.js +547 -1
  66. package/dist/esm/src/index.js +35 -1
  67. package/dist/esm/src/managers/components/animationManager.js +119 -1
  68. package/dist/esm/src/managers/components/componentManager.js +328 -1
  69. package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
  70. package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
  71. package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
  72. package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
  73. package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
  74. package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
  75. package/dist/esm/src/managers/environment/environmentManager.js +690 -1
  76. package/dist/esm/src/managers/environment/textureConfig.js +202 -1
  77. package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
  78. package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
  79. package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
  80. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
  81. package/dist/esm/src/managers/system/disposalManager.js +440 -1
  82. package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
  83. package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
  84. package/dist/esm/src/rendering/modelPreloader.js +364 -1
  85. package/dist/esm/src/rendering/rendering2D.js +627 -1
  86. package/dist/esm/src/rendering/rendering3D.js +661 -1
  87. package/package.json +1 -1
@@ -1 +1,1441 @@
1
- "use strict";Object.defineProperty(exports,"t",{value:!0});var e=require("../../../_virtual/_rollupPluginBabelHelpers.js"),n=require("three"),t=require("../../../node_modules/@2112-lab/pathfinder/dist/index.esm.js"),r=require("../../core/debugLogger.js"),i=require("../../core/nameUtils.js");function o(e){if(e&&e.t)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}}),n.default=e,Object.freeze(n)}var a=o(n),u=function(){return e.createClass(function n(t){e.classCallCheck(this,n),this.sceneViewer=t,this.pathfinder=null,this.crosscubeTextureSet=null,this.pathfinderVersionInfo=null,this.pathfinderConfig={grid:{size:.5,safetyMargin:0,minSegmentLength:.5,timeout:1e3}}},[{key:"getPathfinderVersionInfo",value:(l=e.asyncToGenerator(e.regenerator().m(function n(){var t;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(!this.pathfinderVersionInfo){e.n=1;break}return e.a(2,this.pathfinderVersionInfo);case 1:return t={version:"1.0.17",detectionMethod:"hardcoded-fallback",timestamp:(new Date).toISOString()},this.pathfinderVersionInfo=t,e.a(2,t)}},n,this)})),function(){return l.apply(this,arguments)})},{key:"logPathfinderVersion",value:(c=e.asyncToGenerator(e.regenerator().m(function n(){var t,i,o,a=arguments;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return t=a.length>0&&void 0!==a[0]?a[0]:"Unknown Context",e.p=1,e.n=2,this.getPathfinderVersionInfo();case 2:i=e.v,r.pathfinderLogger.info("[".concat(t,"] Pathfinder Module Information:"),{version:i.version,detectionMethod:i.detectionMethod,context:t,timestamp:i.timestamp,pathfinderInstance:!!this.pathfinder}),e.n=4;break;case 3:e.p=3,o=e.v,r.pathfinderLogger.error("[".concat(t,"] Failed to get pathfinder version:"),o);case 4:return e.a(2)}},n,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"getPathColor",value:function(e){var n=["#468e49","#245e29","#2e80d2","#1d51a1"];return n[e%n.length]}},{key:"_executePathfinding",value:(s=e.asyncToGenerator(e.regenerator().m(function n(r,i){var o,u,s,c,l,v,f,d=this,h=arguments;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return u=(o=h.length>2&&void 0!==h[2]?h[2]:{}).createGateways,s=void 0!==u&&u,c=o.context,l=void 0===c?"Pathfinding":c,e.n=1,this.logPathfinderVersion(l);case 1:return this.pathfinder=new t.Pathfinder(this.pathfinderConfig),this.sceneViewer.pathfinder=this.pathfinder,r.object.children=r.object.children.filter(function(e){return"computed"!==e.userData.origin}),v=this.pathfinder.findPaths(r,i),s&&v.gateways&&v.gateways.forEach(function(e){if(e.position){var n=new a.Mesh(new a.SphereGeometry(.15,16,16),new a.MeshStandardMaterial({color:16777215,roughness:.7,metalness:.3,emissive:0}));n.position.copy(e.position),n.name=e.id,n.uuid=e.id,n.userData={componentType:"gateway",forExport:!0,gatewayId:e.id,originalUuid:e.id,origin:"computed",connections:e.connections},d.sceneViewer.scene.add(n)}}),f=this.mergeColinearPaths(v.paths),this.createPipePaths(f,this.crosscubeTextureSet),e.a(2,v)}},n,this)})),function(e,n){return s.apply(this,arguments)})},{key:"initializePathfinder",value:(u=e.asyncToGenerator(e.regenerator().m(function n(t,r){var i;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return this.crosscubeTextureSet=r,e.n=1,this.i(t.scene,t.connections,{createGateways:!0,context:"Scene Loading"});case 1:return(i=e.v).rewiredConnections,e.a(2,i)}},n,this)})),function(e,n){return u.apply(this,arguments)})},{key:"removeComputedObjects",value:function(){var e=this.sceneViewer,n=[];e.scene.traverse(function(e){if(e.name&&e.name.includes("Polyline")){var t=!1,r=[];if(e.traverse(function(e){e.userData&&e.userData.isPipeSegment&&e.userData.isManuallyPositioned&&(t=!0,r.push(e))}),t){var i=[];e.traverse(function(e){(e.userData&&e.userData.isPipeSegment&&!e.userData.isManuallyPositioned||e.userData&&e.userData.isPipeElbow)&&i.push(e)}),i.forEach(function(n){e.remove(n),n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(function(e){return e.dispose()}):n.material.dispose())}),0===e.children.length&&n.push(e)}else n.push(e)}e.userData&&"computed"===e.userData.origin&&n.push(e)});for(var t=0,r=n;t<r.length;t++){var i=r[t];e.scene.remove(i),i.geometry&&i.geometry.dispose(),i.material&&(Array.isArray(i.material)?i.material.forEach(function(e){return e.dispose()}):i.material.dispose())}}},{key:"createPipeMaterial",value:function(n,t){if(n){var r=e.objectSpread2(e.objectSpread2({},n.config.materialProps),{},{color:this.getPathColor(t),map:n.textures.diffuse,normalMap:n.textures.normal,roughnessMap:n.textures.roughness,metalness:.2,roughness:.9,clearcoat:.2,clearcoatRoughness:.2,envMapIntensity:.6,reflectivity:.4});r.normalScale&&Array.isArray(r.normalScale)&&(r.normalScale=e.construct(a.Vector2,e.toConsumableArray(r.normalScale)));var i=new a.MeshPhysicalMaterial(r);return[i.map,i.normalMap,i.roughnessMap].filter(Boolean).forEach(function(e){e.wrapS=e.wrapT=a.RepeatWrapping,e.repeat.set(2*n.config.repeat.x,2*n.config.repeat.y)}),i}return new a.MeshPhysicalMaterial({color:this.getPathColor(t),metalness:.9,roughness:.7,clearcoat:.1,clearcoatRoughness:.3,envMapIntensity:1.5,reflectivity:.3})}},{key:"createPipePaths",value:function(e,n){var t=this,r=this.sceneViewer;e.forEach(function(e,i){if(e.path&&e.path.length>=2){var o=new a.Object3D;o.name="Polyline ".concat(e.from,"-").concat(e.to);for(var u=t.createPipeMaterial(n,i),s=e.path.map(function(e){return e instanceof a.Vector3?e.clone():Array.isArray(e)?(new a.Vector3).fromArray(e):void 0!==e.x&&void 0!==e.y&&void 0!==e.z?new a.Vector3(e.x,e.y,e.z):new a.Vector3(0,0,0)}),c=function(n){var c=s[n],l=s[n+1],v=(new a.Vector3).subVectors(l,c),f=v.length();if(f<1e-6)return 0;var d=!1;if(r.scene.traverse(function(t){t.userData&&t.userData.isPipeSegment&&t.userData.isManuallyPositioned&&t.userData.segmentId==="pipe-segment-".concat(e.from,"-").concat(e.to,"-").concat(n)&&(d=!0)}),d)return 0;var h=new a.CylinderGeometry(.1,.1,f,8,1,!1),y=new a.Mesh(h,u);y.position.copy(c).add(l).multiplyScalar(.5);var m=new a.Quaternion,p=new a.Vector3(0,1,0);m.setFromUnitVectors(p,v.clone().normalize()),y.quaternion.copy(m),y.castShadow=!0,y.receiveShadow=!0;var g="pipe-segment-".concat(e.from,"-").concat(e.to,"-").concat(n);if(y.name="Pipe Segment ".concat(n+1,": ").concat(e.from,"-").concat(e.to),y.userData={isPipeSegment:!0,segmentId:g,segmentIndex:n,pathFrom:e.from,pathTo:e.to,pathIndex:i,length:f.toFixed(2),component:{type:"PipeSegment",attributes:{length:{key:"Length",value:f.toFixed(2),unit:"m"}}}},o.add(y),n<s.length-2){var w=s[n+1].clone().sub(s[n]).normalize(),k=s[n+2].clone().sub(s[n+1]).normalize(),b=w.angleTo(k);if(b>Math.PI/36){var x=t.createElbowGeometry(s[n],s[n+1],s[n+2],.1);if(x){var P=new a.Mesh(x,u);P.castShadow=!0,P.receiveShadow=!0;var M="pipe-elbow-".concat(e.from,"-").concat(e.to,"-").concat(n);P.name="Pipe Elbow ".concat(n+1,": ").concat(e.from,"-").concat(e.to),P.userData={isPipeElbow:!0,elbowId:M,elbowIndex:n,pathFrom:e.from,pathTo:e.to,pathIndex:i,angle:(180*b/Math.PI).toFixed(1),component:{type:"PipeElbow",attributes:{angle:{key:"Bend Angle",value:(180*b/Math.PI).toFixed(1),unit:"°"}}}},o.add(P)}}}},l=0;l<s.length-1;l++)c(l);o.name="Polyline",r.scene.add(o)}})}},{key:"handleManualSegmentTransformation",value:function(e,n){if(e&&e.userData&&e.userData.isPipeSegment){var t=this.calculateSegmentEndpoints(e),r=this.createSegmentConnectors(e,t);this.addConnectorsToScene(r),this.convertConnectedGatewaysToManual(r,n);var i=this.findOriginalConnection(e,n.connections);i&&(this.restructureConnections(i,r,n),e.userData.isManuallyPositioned=!0,e.userData.manualConnectors=r.map(function(e){return e.uuid}),this.addManualSegmentToSceneData(e))}}},{key:"convertConnectedGatewaysToManual",value:function(e,n){var t,r,i=this,o=this.sceneViewer,a=[],u=null!==(t=e[0])&&void 0!==t&&null!==(t=t.userData)&&void 0!==t&&t.manualSegmentUuid?o.scene.getObjectByProperty("uuid",e[0].userData.manualSegmentUuid):null;u&&null!==(r=u.userData)&&void 0!==r&&r.isPipeSegment&&([u.userData.pathFrom,u.userData.pathTo].forEach(function(e){var t,r,u=null;(o.scene.traverse(function(n){var t;n.uuid!==e&&(null===(t=n.userData)||void 0===t?void 0:t.originalUuid)!==e||(u=n)}),u)&&("gateway"===(null===(t=u.userData)||void 0===t?void 0:t.componentType)&&"computed"===(null===(r=u.userData)||void 0===r?void 0:r.origin)&&(i.convertGatewayToManual(u,n),a.push(u)))}),a.length)}},{key:"convertGatewayToManual",value:function(e,n){var t;e.userData.origin="declared";for(var r=0;r<n.scene.object.children.length;r++){var i,o,a=n.scene.object.children[r];if(a.uuid===e.uuid||a.uuid===(null===(i=e.userData)||void 0===i?void 0:i.originalUuid)||e.uuid===(null===(o=a.userData)||void 0===o?void 0:o.originalUuid)){a.userData||(a.userData={}),a.userData.origin="declared";break}}if(null!==(t=e.userData)&&void 0!==t&&t.connections&&n.connections){var u=e.userData.connections,s=n.connections;u.removed&&Array.isArray(u.removed)&&(n.connections=s.filter(function(e){var n=u.removed.some(function(n){return n.from===e.from&&n.to===e.to||n.from===e.to&&n.to===e.from});return!n})),u.added&&Array.isArray(u.added)&&u.added.forEach(function(e){n.connections.some(function(n){return n.from===e.from&&n.to===e.to||n.from===e.to&&n.to===e.from})||n.connections.push(e)})}}},{key:"findOriginalConnection",value:function(e,n){var t=e.userData,r=t.pathFrom,i=t.pathTo,o=n.find(function(e){return e.from===r&&e.to===i||e.from===i&&e.to===r});if(o)return o;var a=this.sceneViewer,u=null,s=null;if(a.scene.traverse(function(e){var n,t;e.uuid!==r&&(null===(n=e.userData)||void 0===n?void 0:n.originalUuid)!==r||(u=e),e.uuid!==i&&(null===(t=e.userData)||void 0===t?void 0:t.originalUuid)!==i||(s=e)}),u&&s&&(o=n.find(function(e){return e.from===u.uuid&&e.to===s.uuid||e.from===s.uuid&&e.to===u.uuid})))return o;var c=n.filter(function(e){var n,t,o=e.from===r||e.from===i,u=e.to===r||e.to===i,s="gateway"===(null===(n=a.scene.getObjectByProperty("uuid",e.from))||void 0===n||null===(n=n.userData)||void 0===n?void 0:n.componentType),c="gateway"===(null===(t=a.scene.getObjectByProperty("uuid",e.to))||void 0===t||null===(t=t.userData)||void 0===t?void 0:t.componentType);return o||u||s||c});return c.length>0?c[0]:null}},{key:"calculateSegmentEndpoints",value:function(e){var n=e.geometry.parameters.height||1,t=new a.Vector3,r=new a.Vector3,i=new a.Vector3(0,1,0);return i.applyQuaternion(e.quaternion),t.copy(e.position).sub(i.clone().multiplyScalar(n/2)),r.copy(e.position).add(i.clone().multiplyScalar(n/2)),{start:t,end:r}}},{key:"createSegmentConnectors",value:function(e,n){var t=e.userData.segmentId,r=[],i=new a.Mesh(new a.SphereGeometry(.2,16,16),new a.MeshStandardMaterial({color:65280,roughness:.7,metalness:.3,emissive:13056}));i.position.copy(n.start),i.uuid="".concat(t,"-connector-start"),i.name="Manual Segment Start Connector: ".concat(e.name),i.userData={componentType:"connector",forExport:!0,isManualSegmentConnector:!0,segmentId:t,connectorType:"start",manualSegmentUuid:e.uuid};var o=new a.Mesh(new a.SphereGeometry(.2,16,16),new a.MeshStandardMaterial({color:16711680,roughness:.7,metalness:.3,emissive:3342336}));return o.position.copy(n.end),o.uuid="".concat(t,"-connector-end"),o.name="Manual Segment End Connector: ".concat(e.name),o.userData={componentType:"connector",forExport:!0,isManualSegmentConnector:!0,segmentId:t,connectorType:"end",manualSegmentUuid:e.uuid},r.push(i,o),r}},{key:"addConnectorsToScene",value:function(n){var t=this.sceneViewer;n.forEach(function(n){if(t.scene.add(n),t.currentSceneData&&t.currentSceneData.scene&&t.currentSceneData.scene.object){var r={uuid:n.uuid,name:n.name,type:n.type,userData:e.objectSpread2({},n.userData),position:{x:n.position.x,y:n.position.y,z:n.position.z},rotation:{x:n.rotation.x,y:n.rotation.y,z:n.rotation.z},scale:{x:n.scale.x,y:n.scale.y,z:n.scale.z},geometry:"CONNECTOR-GEO"};t.currentSceneData.scene.object.children.push(r)}})}},{key:"addManualSegmentToSceneData",value:function(n){var t=this.sceneViewer;if(t.currentSceneData&&t.currentSceneData.scene&&t.currentSceneData.scene.object){var r={uuid:n.uuid,name:n.name,type:n.type,userData:e.objectSpread2({},n.userData),position:{x:n.position.x,y:n.position.y,z:n.position.z},rotation:{x:n.rotation.x,y:n.rotation.y,z:n.rotation.z},scale:{x:n.scale.x,y:n.scale.y,z:n.scale.z}};t.currentSceneData.scene.object.children.push(r)}}},{key:"restructureConnections",value:function(n,t,r){var i=e.slicedToArray(t,2),o=i[0],a=i[1],u=r.connections.findIndex(function(e){return e.from===n.from&&e.to===n.to||e.from===n.to&&e.to===n.from});if(-1!==u){r.connections.splice(u,1);var s={from:n.from,to:o.uuid},c={from:a.uuid,to:n.to};r.connections.push(s,c),this.sceneViewer.currentSceneData&&(this.sceneViewer.currentSceneData.connections=e.toConsumableArray(r.connections))}}},{key:"createElbowGeometry",value:function(e,n,t,r){try{var i=3*r,o=this.createElbowCurve(e,n,t,i);return new a.TubeGeometry(o,12,r,8,!1)}catch(e){return null}}},{key:"createElbowCurve",value:function(e,n,t,r){var i=n.clone().sub(e).normalize(),o=t.clone().sub(n).normalize(),u=.001*r,s=n.clone().sub(i.clone().multiplyScalar(u)),c=n.clone().add(o.clone().multiplyScalar(u)),l=n.clone();return new a.QuadraticBezierCurve3(s,l,c)}},{key:"recomputeWorldBoundingBoxes",value:function(n){this.sceneViewer.scene.traverse(function(t){if(t.isMesh){var r=null,o=function(n){var r,a=e.createForOfIteratorHelper(n);try{for(a.s();!(r=a.n()).done;){var u,s,c=r.value;if(c.uuid===t.uuid||c.uuid===(null===(u=t.userData)||void 0===u?void 0:u.originalUuid)||t.uuid===(null===(s=c.userData)||void 0===s?void 0:s.originalUuid))return c;if(t.name&&c.name){var l=i.generateUuidFromName(t.name),v=i.generateUuidFromName(c.name);if(l===v||l===c.uuid||v===t.uuid)return c}if(t.name&&c.name&&t.name===c.name)return c;if(c.children){var f=o(c.children);if(f)return f}}}catch(e){a.e(e)}finally{a.f()}return null};if(r=o(n.scene.object.children)){var u=(new a.Box3).setFromObject(t);r.userData||(r.userData={}),r.userData.worldBoundingBox={min:u.min.toArray(),max:u.max.toArray()},r.userData.origin||(r.userData.origin=t.userData.origin),r.userData.direction||(r.userData.direction=t.userData.direction),r.userData.group||(r.userData.group=t.userData.group),r.userData.connections||(r.userData.connections=t.userData.connections),t.userData.associatedJsonObject=r}}})}},{key:"updatePathfindingWithConnections",value:(o=e.asyncToGenerator(e.regenerator().m(function n(t){var r,i;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:if((r=this.sceneViewer).currentSceneData){n.n=1;break}return n.a(2,!1);case 1:return this.removeComputedObjects(),(i=JSON.parse(JSON.stringify(r.currentSceneData))).connections=e.toConsumableArray(t),n.n=2,this.i(i.scene,i.connections,{createGateways:!1,context:"Connections Update"});case 2:return r.currentSceneData=i,n.a(2,!0)}},n,this)})),function(e){return o.apply(this,arguments)})},{key:"updatePathfindingAfterTransform",value:(n=e.asyncToGenerator(e.regenerator().m(function n(t){return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return this.removeComputedObjects(),e.n=1,this.i(t.scene,t.connections,{createGateways:!0,context:"Transform Update"});case 1:return e.a(2)}},n,this)})),function(e){return n.apply(this,arguments)})},{key:"dispose",value:function(){this.removeComputedObjects(),this.pathfinder=null,this.crosscubeTextureSet=null,this.pathfinderVersionInfo=null,r.logger.info("PathfindingManager disposed")}},{key:"mergeColinearPaths",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.001,t=JSON.parse(JSON.stringify(e));return t.forEach(function(e){if(e.path&&!(e.path.length<=2)){var t=e.path.map(function(e){return e instanceof a.Vector3?e.clone():Array.isArray(e)?(new a.Vector3).fromArray(e):void 0!==e.x&&void 0!==e.y&&void 0!==e.z?new a.Vector3(e.x,e.y,e.z):new a.Vector3(0,0,0)});if(!(t.length<=2)){for(var r=[t[0]],i=0,o=function(){var e=t[i],o=t[i+1],u=(new a.Vector3).subVectors(o,e);if(u.length()<1e-6)return i++,1;u.normalize();for(var s=i+2;s<t.length;){var c=t[s],l=(new a.Vector3).subVectors(c,e);if(l.length()<1e-6)s++;else{l.normalize();var v=u.dot(l);if(!(Math.abs(v-1)<n))break;o=c,s++}}o.equals(e)||r.push(o);var f=t.findIndex(function(e,n){return n>i&&e.equals(o)});-1===f?i++:i=f};i<t.length-1;)o();var u=r.map(function(n){return Array.isArray(e.path[0])?[n.x,n.y,n.z]:void 0!==e.path[0].x?{x:n.x,y:n.y,z:n.z}:n});e.path=u;t.length,r.length}}}),t}}]);var n,o,u,s,c,l}();exports.PathfindingManager=u;
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
+ var index_esm = require('../../../node_modules/@2112-lab/pathfinder/dist/index.esm.js');
8
+ var debugLogger = require('../../core/debugLogger.js');
9
+ var nameUtils = require('../../core/nameUtils.js');
10
+
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n["default"] = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
30
+
31
+ var PathfindingManager = /*#__PURE__*/function () {
32
+ function PathfindingManager(sceneViewer) {
33
+ _rollupPluginBabelHelpers.classCallCheck(this, PathfindingManager);
34
+ this.sceneViewer = sceneViewer;
35
+ this.pathfinder = null;
36
+ this.crosscubeTextureSet = null;
37
+ this.pathfinderVersionInfo = null;
38
+ // Configuration for pathfinder grid
39
+ this.pathfinderConfig = {
40
+ grid: {
41
+ size: 0.5,
42
+ safetyMargin: 0,
43
+ minSegmentLength: 0.5,
44
+ timeout: 1000
45
+ }
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Get pathfinder version information
51
+ */
52
+ return _rollupPluginBabelHelpers.createClass(PathfindingManager, [{
53
+ key: "getPathfinderVersionInfo",
54
+ value: (function () {
55
+ var _getPathfinderVersionInfo = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee() {
56
+ var versionInfo;
57
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
58
+ while (1) switch (_context.n) {
59
+ case 0:
60
+ if (!this.pathfinderVersionInfo) {
61
+ _context.n = 1;
62
+ break;
63
+ }
64
+ return _context.a(2, this.pathfinderVersionInfo);
65
+ case 1:
66
+ versionInfo = {
67
+ version: '1.0.17',
68
+ detectionMethod: 'hardcoded-fallback',
69
+ timestamp: new Date().toISOString()
70
+ };
71
+ this.pathfinderVersionInfo = versionInfo;
72
+ return _context.a(2, versionInfo);
73
+ }
74
+ }, _callee, this);
75
+ }));
76
+ function getPathfinderVersionInfo() {
77
+ return _getPathfinderVersionInfo.apply(this, arguments);
78
+ }
79
+ return getPathfinderVersionInfo;
80
+ }()
81
+ /**
82
+ * Log pathfinder version information
83
+ */
84
+ )
85
+ }, {
86
+ key: "logPathfinderVersion",
87
+ value: (function () {
88
+ var _logPathfinderVersion = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2() {
89
+ var context,
90
+ versionInfo,
91
+ _args2 = arguments,
92
+ _t;
93
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
94
+ while (1) switch (_context2.n) {
95
+ case 0:
96
+ context = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : 'Unknown Context';
97
+ _context2.p = 1;
98
+ _context2.n = 2;
99
+ return this.getPathfinderVersionInfo();
100
+ case 2:
101
+ versionInfo = _context2.v;
102
+ debugLogger.pathfinderLogger.info("[".concat(context, "] Pathfinder Module Information:"), {
103
+ version: versionInfo.version,
104
+ detectionMethod: versionInfo.detectionMethod,
105
+ context: context,
106
+ timestamp: versionInfo.timestamp,
107
+ pathfinderInstance: !!this.pathfinder
108
+ });
109
+ _context2.n = 4;
110
+ break;
111
+ case 3:
112
+ _context2.p = 3;
113
+ _t = _context2.v;
114
+ debugLogger.pathfinderLogger.error("[".concat(context, "] Failed to get pathfinder version:"), _t);
115
+ case 4:
116
+ return _context2.a(2);
117
+ }
118
+ }, _callee2, this, [[1, 3]]);
119
+ }));
120
+ function logPathfinderVersion() {
121
+ return _logPathfinderVersion.apply(this, arguments);
122
+ }
123
+ return logPathfinderVersion;
124
+ }()
125
+ /**
126
+ * Get path colors for visual distinction
127
+ */
128
+ )
129
+ }, {
130
+ key: "getPathColor",
131
+ value: function getPathColor(index) {
132
+ var colors = ['#468e49', '#245e29', '#2e80d2', '#1d51a1'];
133
+ return colors[index % colors.length];
134
+ }
135
+
136
+ /**
137
+ * Core pathfinding logic shared across initialization and updates
138
+ */
139
+ }, {
140
+ key: "_executePathfinding",
141
+ value: (function () {
142
+ var _executePathfinding2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3(sceneData, connections) {
143
+ var _this = this;
144
+ var options,
145
+ _options$createGatewa,
146
+ createGateways,
147
+ _options$context,
148
+ context,
149
+ pathfindingResult,
150
+ optimizedPaths,
151
+ _args3 = arguments;
152
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
153
+ while (1) switch (_context3.n) {
154
+ case 0:
155
+ options = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
156
+ _options$createGatewa = options.createGateways, createGateways = _options$createGatewa === void 0 ? false : _options$createGatewa, _options$context = options.context, context = _options$context === void 0 ? 'Pathfinding' : _options$context; // Log pathfinder version information
157
+ _context3.n = 1;
158
+ return this.logPathfinderVersion(context);
159
+ case 1:
160
+ // Create pathfinder instance with configuration only
161
+ this.pathfinder = new index_esm.Pathfinder(this.pathfinderConfig);
162
+ this.sceneViewer.pathfinder = this.pathfinder;
163
+
164
+ // Add debugging for pathfinder input
165
+ if (context === 'Scene Loading') {
166
+ console.log('🔍 PATHFINDER DEBUGGING:');
167
+ console.log('🔗 Connections:', connections);
168
+ console.log('🏗️ Scene structure:', JSON.parse(JSON.stringify(sceneData.object)));
169
+ }
170
+
171
+ // Remove from sceneData objects that are origin: computed
172
+ sceneData.object.children = sceneData.object.children.filter(function (child) {
173
+ return child.userData.origin !== 'computed';
174
+ });
175
+
176
+ // Add debugging for pathfinder input
177
+ console.log('🔍 PATHFINDER DEBUGGING:');
178
+ console.log('🔗 Connections:', JSON.parse(JSON.stringify(connections)));
179
+ console.log('🏗️ Scene structure:', JSON.parse(JSON.stringify(sceneData.object)));
180
+
181
+ // Find paths using v1.0.17 API (scene and connections separately)
182
+ pathfindingResult = this.pathfinder.findPaths(sceneData, connections);
183
+ console.log('Found paths:', JSON.parse(JSON.stringify(pathfindingResult.paths)));
184
+ console.log('Generated gateways:', JSON.parse(JSON.stringify(pathfindingResult.gateways)));
185
+ console.log('Rewired connections:', JSON.parse(JSON.stringify(pathfindingResult.rewiredConnections)));
186
+
187
+ // Create gateways in the scene if requested
188
+ if (createGateways && pathfindingResult.gateways) {
189
+ pathfindingResult.gateways.forEach(function (gateway) {
190
+ if (gateway.position) {
191
+ // Create gateway mesh using shared geometry and material
192
+ var gatewayMesh = new THREE__namespace.Mesh(new THREE__namespace.SphereGeometry(0.15, 16, 16), new THREE__namespace.MeshStandardMaterial({
193
+ color: 0xFFFFFF,
194
+ roughness: 0.7,
195
+ metalness: 0.3,
196
+ emissive: 0
197
+ }));
198
+ gatewayMesh.position.copy(gateway.position);
199
+ gatewayMesh.name = gateway.id;
200
+ gatewayMesh.uuid = gateway.id;
201
+
202
+ // Set userData to make gateways selectable
203
+ gatewayMesh.userData = {
204
+ componentType: 'gateway',
205
+ forExport: true,
206
+ gatewayId: gateway.id,
207
+ originalUuid: gateway.id,
208
+ origin: 'computed',
209
+ connections: gateway.connections
210
+ };
211
+
212
+ // Add to scene using editor command
213
+ _this.sceneViewer.scene.add(gatewayMesh);
214
+ console.log("\uD83D\uDD27 Created selectable gateway: ".concat(gateway.id, " with componentType='gateway'"));
215
+ }
216
+ });
217
+ }
218
+ console.log("pathfindingResult.paths:", pathfindingResult.paths);
219
+
220
+ // Preprocess paths to merge colinear segments
221
+ optimizedPaths = this.mergeColinearPaths(pathfindingResult.paths);
222
+ console.log('Path optimization complete. Creating pipe paths...');
223
+
224
+ // Create pipe paths with materials using the optimized paths
225
+ this.createPipePaths(optimizedPaths, this.crosscubeTextureSet);
226
+ return _context3.a(2, pathfindingResult);
227
+ }
228
+ }, _callee3, this);
229
+ }));
230
+ function _executePathfinding(_x, _x2) {
231
+ return _executePathfinding2.apply(this, arguments);
232
+ }
233
+ return _executePathfinding;
234
+ }()
235
+ /**
236
+ * Initialize pathfinder and create paths
237
+ */
238
+ )
239
+ }, {
240
+ key: "initializePathfinder",
241
+ value: (function () {
242
+ var _initializePathfinder = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee4(data, crosscubeTextureSet) {
243
+ var pathfindingResult;
244
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context4) {
245
+ while (1) switch (_context4.n) {
246
+ case 0:
247
+ this.crosscubeTextureSet = crosscubeTextureSet;
248
+
249
+ // Use shared pathfinding logic with gateway creation enabled
250
+ _context4.n = 1;
251
+ return this._executePathfinding(data.scene, data.connections, {
252
+ createGateways: true,
253
+ context: 'Scene Loading'
254
+ });
255
+ case 1:
256
+ pathfindingResult = _context4.v;
257
+ // Update connections with rewired connections
258
+ if (pathfindingResult.rewiredConnections) {
259
+ // data.connections = pathfindingResult.rewiredConnections;
260
+ console.log('🔄 Updated connections with rewired connections:', data.connections);
261
+ }
262
+
263
+ // Return full result for potential additional processing
264
+ return _context4.a(2, pathfindingResult);
265
+ }
266
+ }, _callee4, this);
267
+ }));
268
+ function initializePathfinder(_x3, _x4) {
269
+ return _initializePathfinder.apply(this, arguments);
270
+ }
271
+ return initializePathfinder;
272
+ }()
273
+ /**
274
+ * Remove all computed objects from the scene (polyline paths and gateways)
275
+ */
276
+ )
277
+ }, {
278
+ key: "removeComputedObjects",
279
+ value: function removeComputedObjects() {
280
+ var component = this.sceneViewer;
281
+ console.log("removeComputedObjects started");
282
+ var objectsToRemove = [];
283
+ component.scene.traverse(function (obj) {
284
+ // Check the name property instead of uuid, as UUIDs are auto-generated
285
+ if (obj.name && obj.name.includes("Polyline")) {
286
+ console.log("removeComputedObjects ".concat(obj.name, " (uuid: ").concat(obj.uuid, ") found"));
287
+
288
+ // Check if this polyline contains manually transformed segments
289
+ var hasManualSegments = false;
290
+ var manualSegments = [];
291
+ obj.traverse(function (child) {
292
+ if (child.userData && child.userData.isPipeSegment && child.userData.isManuallyPositioned) {
293
+ hasManualSegments = true;
294
+ manualSegments.push(child);
295
+ console.log("\uD83D\uDD12 Found manually positioned pipe segment: ".concat(child.name));
296
+ }
297
+ });
298
+ if (!hasManualSegments) {
299
+ // No manual segments, remove the entire polyline
300
+ objectsToRemove.push(obj);
301
+ } else {
302
+ // Has manual segments, preserve only the manual ones and remove the rest
303
+ console.log("\uD83D\uDD12 Processing polyline with ".concat(manualSegments.length, " manual segments: ").concat(obj.name));
304
+
305
+ // Remove non-manual segments and elbows from the polyline
306
+ var segmentsToRemove = [];
307
+ obj.traverse(function (child) {
308
+ if (child.userData && child.userData.isPipeSegment && !child.userData.isManuallyPositioned) {
309
+ segmentsToRemove.push(child);
310
+ console.log("\uD83D\uDDD1\uFE0F Marking non-manual segment for removal: ".concat(child.name));
311
+ } else if (child.userData && child.userData.isPipeElbow) {
312
+ segmentsToRemove.push(child);
313
+ console.log("\uD83D\uDDD1\uFE0F Marking pipe elbow for removal: ".concat(child.name));
314
+ }
315
+ });
316
+
317
+ // Remove the non-manual segments
318
+ segmentsToRemove.forEach(function (segment) {
319
+ obj.remove(segment);
320
+ if (segment.geometry) segment.geometry.dispose();
321
+ if (segment.material) {
322
+ if (Array.isArray(segment.material)) {
323
+ segment.material.forEach(function (mat) {
324
+ return mat.dispose();
325
+ });
326
+ } else {
327
+ segment.material.dispose();
328
+ }
329
+ }
330
+ console.log("\uD83D\uDDD1\uFE0F Removed non-manual segment: ".concat(segment.name));
331
+ });
332
+
333
+ // If the polyline is now empty, remove it too
334
+ if (obj.children.length === 0) {
335
+ objectsToRemove.push(obj);
336
+ console.log("\uD83D\uDDD1\uFE0F Polyline is now empty, marking for removal: ".concat(obj.name));
337
+ } else {
338
+ console.log("\uD83D\uDD12 Preserved polyline with ".concat(obj.children.length, " manual segments: ").concat(obj.name));
339
+ }
340
+ }
341
+ }
342
+ // Also remove objects with computed origin (like gateways)
343
+ if (obj.userData && obj.userData.origin === 'computed') {
344
+ console.log("removeComputedObjects computed object ".concat(obj.name || obj.type, " (uuid: ").concat(obj.uuid, ") found"));
345
+ objectsToRemove.push(obj);
346
+ }
347
+ });
348
+ for (var _i = 0, _objectsToRemove = objectsToRemove; _i < _objectsToRemove.length; _i++) {
349
+ var obj = _objectsToRemove[_i];
350
+ component.scene.remove(obj);
351
+ if (obj.geometry) obj.geometry.dispose();
352
+ if (obj.material) {
353
+ if (Array.isArray(obj.material)) {
354
+ obj.material.forEach(function (mat) {
355
+ return mat.dispose();
356
+ });
357
+ } else {
358
+ obj.material.dispose();
359
+ }
360
+ }
361
+ }
362
+ console.log("\u2705 Removed ".concat(objectsToRemove.length, " objects from scene (polylines and computed objects)"));
363
+ }
364
+
365
+ /**
366
+ * Material factory function to reduce duplication
367
+ */
368
+ }, {
369
+ key: "createPipeMaterial",
370
+ value: function createPipeMaterial(crosscubeTextureSet, pathIndex) {
371
+ if (crosscubeTextureSet) {
372
+ var materialProps = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, crosscubeTextureSet.config.materialProps), {}, {
373
+ color: this.getPathColor(pathIndex),
374
+ map: crosscubeTextureSet.textures.diffuse,
375
+ normalMap: crosscubeTextureSet.textures.normal,
376
+ roughnessMap: crosscubeTextureSet.textures.roughness,
377
+ metalness: 0.2,
378
+ roughness: 0.9,
379
+ clearcoat: 0.2,
380
+ clearcoatRoughness: 0.2,
381
+ envMapIntensity: 0.6,
382
+ reflectivity: 0.4
383
+ });
384
+
385
+ // Handle normalScale conversion to Vector2
386
+ if (materialProps.normalScale && Array.isArray(materialProps.normalScale)) {
387
+ materialProps.normalScale = _rollupPluginBabelHelpers.construct(THREE__namespace.Vector2, _rollupPluginBabelHelpers.toConsumableArray(materialProps.normalScale));
388
+ }
389
+ var material = new THREE__namespace.MeshPhysicalMaterial(materialProps);
390
+
391
+ // Configure texture wrapping and repeat
392
+ var pipeTextures = [material.map, material.normalMap, material.roughnessMap].filter(Boolean);
393
+ pipeTextures.forEach(function (texture) {
394
+ texture.wrapS = texture.wrapT = THREE__namespace.RepeatWrapping;
395
+ texture.repeat.set(crosscubeTextureSet.config.repeat.x * 2, crosscubeTextureSet.config.repeat.y * 2);
396
+ });
397
+ return material;
398
+ } else {
399
+ return new THREE__namespace.MeshPhysicalMaterial({
400
+ color: this.getPathColor(pathIndex),
401
+ metalness: 0.9,
402
+ roughness: 0.7,
403
+ clearcoat: 0.1,
404
+ clearcoatRoughness: 0.3,
405
+ envMapIntensity: 1.5,
406
+ reflectivity: 0.3
407
+ });
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Helper function to create pipe paths
413
+ */
414
+ }, {
415
+ key: "createPipePaths",
416
+ value: function createPipePaths(paths, crosscubeTextureSet) {
417
+ var _this2 = this;
418
+ var component = this.sceneViewer;
419
+ paths.forEach(function (pathData, index) {
420
+ if (pathData.path && pathData.path.length >= 2) {
421
+ var polyline = new THREE__namespace.Object3D();
422
+ polyline.name = "Polyline ".concat(pathData.from, "-").concat(pathData.to);
423
+ var pipeRadius = 0.1;
424
+ var pipeMaterial = _this2.createPipeMaterial(crosscubeTextureSet, index);
425
+
426
+ // Convert path points to Vector3 objects for consistent handling
427
+ var pathPoints = pathData.path.map(function (point) {
428
+ if (point instanceof THREE__namespace.Vector3) {
429
+ return point.clone();
430
+ } else if (Array.isArray(point)) {
431
+ return new THREE__namespace.Vector3().fromArray(point);
432
+ } else if (point.x !== undefined && point.y !== undefined && point.z !== undefined) {
433
+ return new THREE__namespace.Vector3(point.x, point.y, point.z);
434
+ } else {
435
+ console.warn('Unknown point format in createPipePaths:', point);
436
+ return new THREE__namespace.Vector3(0, 0, 0);
437
+ }
438
+ });
439
+
440
+ // Create one cylinder per segment (after colinear optimization, this should be minimal segments)
441
+ var _loop = function _loop(j) {
442
+ var start = pathPoints[j];
443
+ var end = pathPoints[j + 1];
444
+ var direction = new THREE__namespace.Vector3().subVectors(end, start);
445
+ var length = direction.length();
446
+
447
+ // Skip zero-length segments
448
+ if (length < 1e-6) {
449
+ console.warn("Skipping zero-length segment in path ".concat(pathData.from, "-").concat(pathData.to));
450
+ return 0; // continue
451
+ }
452
+
453
+ // Check if this segment has been manually positioned
454
+ var isManuallyPositioned = false;
455
+ component.scene.traverse(function (sceneObj) {
456
+ if (sceneObj.userData && sceneObj.userData.isPipeSegment && sceneObj.userData.isManuallyPositioned) {
457
+ if (sceneObj.userData.segmentId === "pipe-segment-".concat(pathData.from, "-").concat(pathData.to, "-").concat(j)) {
458
+ isManuallyPositioned = true;
459
+ }
460
+ }
461
+ });
462
+ if (isManuallyPositioned) {
463
+ console.log("\uD83D\uDD12 Skipping segment creation for manually positioned segment: ".concat(pathData.from, "-").concat(pathData.to, " segment ").concat(j));
464
+ return 0; // continue
465
+ }
466
+ var cylinderGeometry = new THREE__namespace.CylinderGeometry(pipeRadius, pipeRadius, length, 8, 1, false);
467
+ var cylinder = new THREE__namespace.Mesh(cylinderGeometry, pipeMaterial);
468
+ cylinder.position.copy(start).add(end).multiplyScalar(0.5);
469
+ var quaternion = new THREE__namespace.Quaternion();
470
+ var up = new THREE__namespace.Vector3(0, 1, 0);
471
+ quaternion.setFromUnitVectors(up, direction.clone().normalize());
472
+ cylinder.quaternion.copy(quaternion);
473
+ cylinder.castShadow = true;
474
+ cylinder.receiveShadow = true;
475
+
476
+ // Make pipe segments selectable and add identifying data
477
+ var segmentId = "pipe-segment-".concat(pathData.from, "-").concat(pathData.to, "-").concat(j);
478
+ cylinder.name = "Pipe Segment ".concat(j + 1, ": ").concat(pathData.from, "-").concat(pathData.to);
479
+
480
+ // Add userData to make pipe segments selectable and for tooltip display
481
+ cylinder.userData = {
482
+ isPipeSegment: true,
483
+ segmentId: segmentId,
484
+ segmentIndex: j,
485
+ pathFrom: pathData.from,
486
+ pathTo: pathData.to,
487
+ pathIndex: index,
488
+ length: length.toFixed(2),
489
+ // Add component data structure for tooltips
490
+ component: {
491
+ type: 'PipeSegment',
492
+ attributes: {
493
+ length: {
494
+ key: 'Length',
495
+ value: length.toFixed(2),
496
+ unit: 'm'
497
+ }
498
+ // connection: {
499
+ // key: 'Connection',
500
+ // value: `${pathData.from} → ${pathData.to}`
501
+ // }
502
+ }
503
+ }
504
+ };
505
+ polyline.add(cylinder);
506
+
507
+ // Add smooth elbow joints only at actual direction changes (not at every point)
508
+ if (j < pathPoints.length - 2) {
509
+ var currentSegment = pathPoints[j + 1].clone().sub(pathPoints[j]).normalize();
510
+ var nextSegment = pathPoints[j + 2].clone().sub(pathPoints[j + 1]).normalize();
511
+
512
+ // Check if there's actually a direction change (not just continuing straight)
513
+ var angle = currentSegment.angleTo(nextSegment);
514
+ var minAngle = Math.PI / 36; // 5 degrees minimum for creating an elbow
515
+
516
+ if (angle > minAngle) {
517
+ var elbowGeometry = _this2.createElbowGeometry(pathPoints[j], pathPoints[j + 1], pathPoints[j + 2], pipeRadius);
518
+ if (elbowGeometry) {
519
+ var elbow = new THREE__namespace.Mesh(elbowGeometry, pipeMaterial);
520
+ elbow.castShadow = true;
521
+ elbow.receiveShadow = true;
522
+
523
+ // Make elbows selectable as well
524
+ var elbowId = "pipe-elbow-".concat(pathData.from, "-").concat(pathData.to, "-").concat(j);
525
+ elbow.name = "Pipe Elbow ".concat(j + 1, ": ").concat(pathData.from, "-").concat(pathData.to);
526
+
527
+ // Add userData for elbows too
528
+ elbow.userData = {
529
+ isPipeElbow: true,
530
+ elbowId: elbowId,
531
+ elbowIndex: j,
532
+ pathFrom: pathData.from,
533
+ pathTo: pathData.to,
534
+ pathIndex: index,
535
+ angle: (angle * 180 / Math.PI).toFixed(1),
536
+ // Add component data for tooltips
537
+ component: {
538
+ type: 'PipeElbow',
539
+ attributes: {
540
+ angle: {
541
+ key: 'Bend Angle',
542
+ value: (angle * 180 / Math.PI).toFixed(1),
543
+ unit: '°'
544
+ }
545
+ }
546
+ }
547
+ };
548
+ polyline.add(elbow);
549
+ }
550
+ }
551
+ }
552
+ },
553
+ _ret;
554
+ for (var j = 0; j < pathPoints.length - 1; j++) {
555
+ _ret = _loop(j);
556
+ if (_ret === 0) continue;
557
+ }
558
+ polyline.name = "Polyline";
559
+ component.scene.add(polyline);
560
+ console.log("\u2705 Created pipe path ".concat(pathData.from, "-").concat(pathData.to, " with ").concat(pathPoints.length - 1, " segments"));
561
+ }
562
+ });
563
+ }
564
+
565
+ /**
566
+ * Handle manual segment transformation by creating connectors and restructuring connections
567
+ * @param {THREE.Object3D} segment - The transformed pipe segment
568
+ * @param {Object} currentSceneData - Current scene data with connections
569
+ */
570
+ }, {
571
+ key: "handleManualSegmentTransformation",
572
+ value: function handleManualSegmentTransformation(segment, currentSceneData) {
573
+ if (!segment || !segment.userData || !segment.userData.isPipeSegment) {
574
+ console.log('❌ Object is not a pipe segment:', {
575
+ isObject: !!segment,
576
+ hasUserData: !!(segment && segment.userData),
577
+ isPipeSegment: !!(segment && segment.userData && segment.userData.isPipeSegment)
578
+ });
579
+ return;
580
+ }
581
+ console.log('🔧 Handling manual segment transformation:', segment.name);
582
+
583
+ // Calculate segment endpoints in world coordinates
584
+ var segmentEndpoints = this.calculateSegmentEndpoints(segment);
585
+ console.log('📍 Segment endpoints:', segmentEndpoints);
586
+
587
+ // Create connectors at the segment endpoints
588
+ var connectors = this.createSegmentConnectors(segment, segmentEndpoints);
589
+ console.log('🔌 Created connectors:', connectors);
590
+
591
+ // Add connectors to the scene
592
+ this.addConnectorsToScene(connectors);
593
+
594
+ // Check and convert connected gateways to manual (declared) BEFORE finding original connection
595
+ this.convertConnectedGatewaysToManual(connectors, currentSceneData);
596
+
597
+ // Find the original connection that this segment belongs to (after gateways are converted)
598
+ var originalConnection = this.findOriginalConnection(segment, currentSceneData.connections);
599
+ if (!originalConnection) {
600
+ console.warn('⚠️ Could not find original connection for segment:', segment.name);
601
+ return;
602
+ }
603
+ console.log('🔍 Found original connection:', originalConnection);
604
+
605
+ // Restructure connections
606
+ this.restructureConnections(originalConnection, connectors, currentSceneData);
607
+
608
+ // Mark segment as manually positioned
609
+ segment.userData.isManuallyPositioned = true;
610
+ segment.userData.manualConnectors = connectors.map(function (c) {
611
+ return c.uuid;
612
+ });
613
+
614
+ // Add the manually positioned segment to scene data
615
+ this.addManualSegmentToSceneData(segment);
616
+ console.log('✅ Manual segment transformation completed');
617
+ }
618
+
619
+ /**
620
+ * Check and convert gateways at the original path endpoints to manual (declared)
621
+ * @param {Array} connectors - Array of connector objects (used to get segment reference)
622
+ * @param {Object} currentSceneData - Current scene data
623
+ */
624
+ }, {
625
+ key: "convertConnectedGatewaysToManual",
626
+ value: function convertConnectedGatewaysToManual(connectors, currentSceneData) {
627
+ var _connectors$,
628
+ _segment$userData,
629
+ _this3 = this;
630
+ console.log('🔍 Checking for connected gateways to convert to manual...');
631
+ var component = this.sceneViewer;
632
+ var convertedGateways = [];
633
+
634
+ // Get the segment from the first connector's userData
635
+ var segment = (_connectors$ = connectors[0]) !== null && _connectors$ !== void 0 && (_connectors$ = _connectors$.userData) !== null && _connectors$ !== void 0 && _connectors$.manualSegmentUuid ? component.scene.getObjectByProperty('uuid', connectors[0].userData.manualSegmentUuid) : null;
636
+ if (!segment || !((_segment$userData = segment.userData) !== null && _segment$userData !== void 0 && _segment$userData.isPipeSegment)) {
637
+ console.log('❌ Could not find segment for gateway conversion');
638
+ return;
639
+ }
640
+ var pathFrom = segment.userData.pathFrom;
641
+ var pathTo = segment.userData.pathTo;
642
+ console.log("\uD83D\uDD0D Checking original path endpoints for gateways: ".concat(pathFrom, " \u2192 ").concat(pathTo));
643
+
644
+ // Check the original path endpoints for gateways
645
+ [pathFrom, pathTo].forEach(function (endpointUuid) {
646
+ console.log("\uD83D\uDD0D Checking endpoint: ".concat(endpointUuid));
647
+
648
+ // Find the object in the scene that corresponds to this endpoint
649
+ var endpointObject = null;
650
+ component.scene.traverse(function (obj) {
651
+ var _obj$userData;
652
+ if (obj.uuid === endpointUuid || ((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.originalUuid) === endpointUuid) {
653
+ endpointObject = obj;
654
+ }
655
+ });
656
+ if (endpointObject) {
657
+ var _endpointObject$userD, _endpointObject$userD2, _endpointObject$userD3, _endpointObject$userD4;
658
+ console.log("\uD83D\uDD0D Found endpoint object: ".concat(endpointObject.name, " (").concat(endpointObject.uuid, ") - componentType: ").concat((_endpointObject$userD = endpointObject.userData) === null || _endpointObject$userD === void 0 ? void 0 : _endpointObject$userD.componentType, ", origin: ").concat((_endpointObject$userD2 = endpointObject.userData) === null || _endpointObject$userD2 === void 0 ? void 0 : _endpointObject$userD2.origin));
659
+
660
+ // Check if this endpoint is a gateway that needs to be converted to manual
661
+ if (((_endpointObject$userD3 = endpointObject.userData) === null || _endpointObject$userD3 === void 0 ? void 0 : _endpointObject$userD3.componentType) === 'gateway' && ((_endpointObject$userD4 = endpointObject.userData) === null || _endpointObject$userD4 === void 0 ? void 0 : _endpointObject$userD4.origin) === 'computed') {
662
+ console.log("\uD83D\uDD27 Found computed gateway at endpoint: ".concat(endpointObject.name, " (").concat(endpointObject.uuid, ")"));
663
+
664
+ // Convert gateway to manual (declared)
665
+ _this3.convertGatewayToManual(endpointObject, currentSceneData);
666
+ convertedGateways.push(endpointObject);
667
+ }
668
+ } else {
669
+ console.log("\u26A0\uFE0F Could not find object for endpoint: ".concat(endpointUuid));
670
+ }
671
+ });
672
+ if (convertedGateways.length > 0) {
673
+ console.log("\u2705 Converted ".concat(convertedGateways.length, " gateways to manual:"), convertedGateways.map(function (g) {
674
+ return g.name;
675
+ }));
676
+ } else {
677
+ console.log('ℹ️ No connected gateways found to convert');
678
+ }
679
+ }
680
+
681
+ /**
682
+ * Convert a gateway from computed to manual (declared) - reusing logic from sceneOperationsManager
683
+ * @param {THREE.Object3D} gateway - The gateway object to convert
684
+ * @param {Object} currentSceneData - Current scene data
685
+ */
686
+ }, {
687
+ key: "convertGatewayToManual",
688
+ value: function convertGatewayToManual(gateway, currentSceneData) {
689
+ var _gateway$userData2;
690
+ console.log("\uD83D\uDD27 Converting gateway from computed to declared: ".concat(gateway.name, " (").concat(gateway.uuid, ")"));
691
+
692
+ // Change origin from computed to declared
693
+ gateway.userData.origin = 'declared';
694
+
695
+ // Update the corresponding scene data object
696
+ for (var i = 0; i < currentSceneData.scene.object.children.length; i++) {
697
+ var _gateway$userData, _child$userData;
698
+ var child = currentSceneData.scene.object.children[i];
699
+ if (child.uuid === gateway.uuid || child.uuid === ((_gateway$userData = gateway.userData) === null || _gateway$userData === void 0 ? void 0 : _gateway$userData.originalUuid) || gateway.uuid === ((_child$userData = child.userData) === null || _child$userData === void 0 ? void 0 : _child$userData.originalUuid)) {
700
+ if (!child.userData) child.userData = {};
701
+ child.userData.origin = 'declared';
702
+ console.log("\u2705 Updated scene data gateway origin to declared: ".concat(child.uuid));
703
+ break;
704
+ }
705
+ }
706
+
707
+ // Process gateway connections (same logic as in sceneOperationsManager)
708
+ if ((_gateway$userData2 = gateway.userData) !== null && _gateway$userData2 !== void 0 && _gateway$userData2.connections && currentSceneData.connections) {
709
+ console.log('🔗 Processing gateway connections for filtering:', gateway.userData.connections);
710
+ var gatewayConnections = gateway.userData.connections;
711
+ var currentConnections = currentSceneData.connections;
712
+
713
+ // Filter out removed connections
714
+ if (gatewayConnections.removed && Array.isArray(gatewayConnections.removed)) {
715
+ console.log('🗑️ Filtering out removed connections:', gatewayConnections.removed);
716
+ currentSceneData.connections = currentConnections.filter(function (connection) {
717
+ var isRemoved = gatewayConnections.removed.some(function (removedConn) {
718
+ return removedConn.from === connection.from && removedConn.to === connection.to || removedConn.from === connection.to && removedConn.to === connection.from;
719
+ });
720
+ if (isRemoved) {
721
+ console.log("\uD83D\uDDD1\uFE0F Removed connection: ".concat(connection.from, " \u2192 ").concat(connection.to));
722
+ }
723
+ return !isRemoved;
724
+ });
725
+ }
726
+
727
+ // Add new connections
728
+ if (gatewayConnections.added && Array.isArray(gatewayConnections.added)) {
729
+ console.log('➕ Adding new connections:', gatewayConnections.added);
730
+ gatewayConnections.added.forEach(function (newConnection) {
731
+ // Check if connection already exists to avoid duplicates
732
+ var alreadyExists = currentSceneData.connections.some(function (conn) {
733
+ return conn.from === newConnection.from && conn.to === newConnection.to || conn.from === newConnection.to && conn.to === newConnection.from;
734
+ });
735
+ if (!alreadyExists) {
736
+ currentSceneData.connections.push(newConnection);
737
+ console.log("\u2795 Added new connection: ".concat(newConnection.from, " \u2192 ").concat(newConnection.to));
738
+ } else {
739
+ console.log("\u26A0\uFE0F Connection already exists, skipping: ".concat(newConnection.from, " \u2192 ").concat(newConnection.to));
740
+ }
741
+ });
742
+ }
743
+ console.log('✅ Gateway connections processing completed. Total connections:', currentSceneData.connections.length);
744
+ }
745
+ console.log("\u2705 Gateway ".concat(gateway.name, " successfully converted to manual (declared)"));
746
+ }
747
+
748
+ /**
749
+ * Find the original connection that a segment belongs to
750
+ * @param {THREE.Object3D} segment - The pipe segment
751
+ * @param {Array} connections - Array of connections
752
+ * @returns {Object|null} The original connection or null
753
+ */
754
+ }, {
755
+ key: "findOriginalConnection",
756
+ value: function findOriginalConnection(segment, connections) {
757
+ var _fromObject$userData, _toObject$userData;
758
+ var segmentData = segment.userData;
759
+ var pathFrom = segmentData.pathFrom;
760
+ var pathTo = segmentData.pathTo;
761
+ console.log('🔍 Looking for connection:', {
762
+ pathFrom: pathFrom,
763
+ pathTo: pathTo
764
+ });
765
+ console.log('🔍 Available connections:', connections);
766
+
767
+ // First try: direct connection match
768
+ var foundConnection = connections.find(function (conn) {
769
+ return conn.from === pathFrom && conn.to === pathTo || conn.from === pathTo && conn.to === pathFrom;
770
+ });
771
+ if (foundConnection) {
772
+ console.log('🔍 Found direct connection match:', foundConnection);
773
+ return foundConnection;
774
+ }
775
+
776
+ // Second try: look for connections that might involve gateways
777
+ // This can happen when the original connection involves a gateway that was computed
778
+ console.log('🔍 No direct match found, checking for gateway-involved connections...');
779
+ var component = this.sceneViewer;
780
+
781
+ // Look for objects in the scene that might be the pathFrom or pathTo
782
+ var fromObject = null;
783
+ var toObject = null;
784
+ component.scene.traverse(function (obj) {
785
+ var _obj$userData2, _obj$userData3;
786
+ if (obj.uuid === pathFrom || ((_obj$userData2 = obj.userData) === null || _obj$userData2 === void 0 ? void 0 : _obj$userData2.originalUuid) === pathFrom) {
787
+ fromObject = obj;
788
+ }
789
+ if (obj.uuid === pathTo || ((_obj$userData3 = obj.userData) === null || _obj$userData3 === void 0 ? void 0 : _obj$userData3.originalUuid) === pathTo) {
790
+ toObject = obj;
791
+ }
792
+ });
793
+ console.log('🔍 Scene objects found:', {
794
+ fromObject: fromObject ? {
795
+ uuid: fromObject.uuid,
796
+ name: fromObject.name,
797
+ componentType: (_fromObject$userData = fromObject.userData) === null || _fromObject$userData === void 0 ? void 0 : _fromObject$userData.componentType
798
+ } : null,
799
+ toObject: toObject ? {
800
+ uuid: toObject.uuid,
801
+ name: toObject.name,
802
+ componentType: (_toObject$userData = toObject.userData) === null || _toObject$userData === void 0 ? void 0 : _toObject$userData.componentType
803
+ } : null
804
+ });
805
+
806
+ // If we found the objects, look for connections involving their UUIDs
807
+ if (fromObject && toObject) {
808
+ foundConnection = connections.find(function (conn) {
809
+ return conn.from === fromObject.uuid && conn.to === toObject.uuid || conn.from === toObject.uuid && conn.to === fromObject.uuid;
810
+ });
811
+ if (foundConnection) {
812
+ console.log('🔍 Found connection via object UUIDs:', foundConnection);
813
+ return foundConnection;
814
+ }
815
+ }
816
+
817
+ // Third try: look for any connection that might be related to this segment
818
+ // This is a fallback for cases where the connection structure is complex
819
+ console.log('🔍 Trying fallback: looking for any connection that might be related...');
820
+
821
+ // Look for connections that might involve the segment's path information
822
+ var possibleConnections = connections.filter(function (conn) {
823
+ var _component$scene$getO, _component$scene$getO2;
824
+ // Check if either end of the connection might be related to our segment
825
+ var fromMatches = conn.from === pathFrom || conn.from === pathTo;
826
+ var toMatches = conn.to === pathFrom || conn.to === pathTo;
827
+
828
+ // Also check if the connection involves any gateway or component that might be related
829
+ var fromIsGateway = ((_component$scene$getO = component.scene.getObjectByProperty('uuid', conn.from)) === null || _component$scene$getO === void 0 || (_component$scene$getO = _component$scene$getO.userData) === null || _component$scene$getO === void 0 ? void 0 : _component$scene$getO.componentType) === 'gateway';
830
+ var toIsGateway = ((_component$scene$getO2 = component.scene.getObjectByProperty('uuid', conn.to)) === null || _component$scene$getO2 === void 0 || (_component$scene$getO2 = _component$scene$getO2.userData) === null || _component$scene$getO2 === void 0 ? void 0 : _component$scene$getO2.componentType) === 'gateway';
831
+ return fromMatches || toMatches || fromIsGateway || toIsGateway;
832
+ });
833
+ if (possibleConnections.length > 0) {
834
+ console.log('🔍 Found possible related connections:', possibleConnections);
835
+ // Return the first one as a best guess
836
+ return possibleConnections[0];
837
+ }
838
+ console.log('❌ No connection found for segment');
839
+ return null;
840
+ }
841
+
842
+ /**
843
+ * Calculate the start and end points of a pipe segment in world coordinates
844
+ * @param {THREE.Object3D} segment - The pipe segment
845
+ * @returns {Object} Object with start and end points
846
+ */
847
+ }, {
848
+ key: "calculateSegmentEndpoints",
849
+ value: function calculateSegmentEndpoints(segment) {
850
+ // Get the segment's geometry to determine its length and orientation
851
+ var geometry = segment.geometry;
852
+ var length = geometry.parameters.height || 1;
853
+
854
+ // Calculate start and end points based on segment position and orientation
855
+ var startPoint = new THREE__namespace.Vector3();
856
+ var endPoint = new THREE__namespace.Vector3();
857
+
858
+ // Get the segment's direction vector
859
+ var direction = new THREE__namespace.Vector3(0, 1, 0);
860
+ direction.applyQuaternion(segment.quaternion);
861
+
862
+ // Calculate start point (half length back from center)
863
+ startPoint.copy(segment.position).sub(direction.clone().multiplyScalar(length / 2));
864
+
865
+ // Calculate end point (half length forward from center)
866
+ endPoint.copy(segment.position).add(direction.clone().multiplyScalar(length / 2));
867
+ return {
868
+ start: startPoint,
869
+ end: endPoint
870
+ };
871
+ }
872
+
873
+ /**
874
+ * Create connector objects at segment endpoints
875
+ * @param {THREE.Object3D} segment - The pipe segment
876
+ * @param {Object} endpoints - Object with start and end points
877
+ * @returns {Array} Array of connector objects
878
+ */
879
+ }, {
880
+ key: "createSegmentConnectors",
881
+ value: function createSegmentConnectors(segment, endpoints) {
882
+ var segmentData = segment.userData;
883
+ var segmentId = segmentData.segmentId;
884
+ var connectors = [];
885
+
886
+ // Create start connector
887
+ var startConnector = new THREE__namespace.Mesh(new THREE__namespace.SphereGeometry(0.2, 16, 16), new THREE__namespace.MeshStandardMaterial({
888
+ color: 0x00FF00,
889
+ roughness: 0.7,
890
+ metalness: 0.3,
891
+ emissive: 0x003300
892
+ }));
893
+ startConnector.position.copy(endpoints.start);
894
+ startConnector.uuid = "".concat(segmentId, "-connector-start");
895
+ startConnector.name = "Manual Segment Start Connector: ".concat(segment.name);
896
+ startConnector.userData = {
897
+ componentType: 'connector',
898
+ forExport: true,
899
+ isManualSegmentConnector: true,
900
+ segmentId: segmentId,
901
+ connectorType: 'start',
902
+ manualSegmentUuid: segment.uuid
903
+ };
904
+
905
+ // Create end connector
906
+ var endConnector = new THREE__namespace.Mesh(new THREE__namespace.SphereGeometry(0.2, 16, 16), new THREE__namespace.MeshStandardMaterial({
907
+ color: 0xFF0000,
908
+ roughness: 0.7,
909
+ metalness: 0.3,
910
+ emissive: 0x330000
911
+ }));
912
+ endConnector.position.copy(endpoints.end);
913
+ endConnector.uuid = "".concat(segmentId, "-connector-end");
914
+ endConnector.name = "Manual Segment End Connector: ".concat(segment.name);
915
+ endConnector.userData = {
916
+ componentType: 'connector',
917
+ forExport: true,
918
+ isManualSegmentConnector: true,
919
+ segmentId: segmentId,
920
+ connectorType: 'end',
921
+ manualSegmentUuid: segment.uuid
922
+ };
923
+ connectors.push(startConnector, endConnector);
924
+ return connectors;
925
+ }
926
+
927
+ /**
928
+ * Add connectors to the scene and scene data
929
+ * @param {Array} connectors - Array of connector objects
930
+ */
931
+ }, {
932
+ key: "addConnectorsToScene",
933
+ value: function addConnectorsToScene(connectors) {
934
+ var component = this.sceneViewer;
935
+ connectors.forEach(function (connector) {
936
+ // Add to Three.js scene
937
+ component.scene.add(connector);
938
+ console.log("\uD83D\uDD0C Added connector to Three.js scene: ".concat(connector.name));
939
+
940
+ // Add to scene data structure
941
+ if (component.currentSceneData && component.currentSceneData.scene && component.currentSceneData.scene.object) {
942
+ var sceneDataConnector = {
943
+ uuid: connector.uuid,
944
+ name: connector.name,
945
+ type: connector.type,
946
+ userData: _rollupPluginBabelHelpers.objectSpread2({}, connector.userData),
947
+ position: {
948
+ x: connector.position.x,
949
+ y: connector.position.y,
950
+ z: connector.position.z
951
+ },
952
+ rotation: {
953
+ x: connector.rotation.x,
954
+ y: connector.rotation.y,
955
+ z: connector.rotation.z
956
+ },
957
+ scale: {
958
+ x: connector.scale.x,
959
+ y: connector.scale.y,
960
+ z: connector.scale.z
961
+ },
962
+ geometry: 'CONNECTOR-GEO'
963
+ };
964
+ component.currentSceneData.scene.object.children.push(sceneDataConnector);
965
+ console.log("\uD83D\uDD0C Added connector to scene data: ".concat(connector.name));
966
+ } else {
967
+ console.warn('⚠️ Could not add connector to scene data - currentSceneData not available');
968
+ }
969
+ });
970
+ }
971
+
972
+ /**
973
+ * Add manually positioned segment to scene data
974
+ * @param {THREE.Object3D} segment - The manually positioned pipe segment
975
+ */
976
+ }, {
977
+ key: "addManualSegmentToSceneData",
978
+ value: function addManualSegmentToSceneData(segment) {
979
+ var component = this.sceneViewer;
980
+ if (!component.currentSceneData || !component.currentSceneData.scene || !component.currentSceneData.scene.object) {
981
+ console.warn('⚠️ Could not add manual segment to scene data - currentSceneData not available');
982
+ return;
983
+ }
984
+
985
+ // Create scene data representation of the segment
986
+ var sceneDataSegment = {
987
+ uuid: segment.uuid,
988
+ name: segment.name,
989
+ type: segment.type,
990
+ userData: _rollupPluginBabelHelpers.objectSpread2({}, segment.userData),
991
+ position: {
992
+ x: segment.position.x,
993
+ y: segment.position.y,
994
+ z: segment.position.z
995
+ },
996
+ rotation: {
997
+ x: segment.rotation.x,
998
+ y: segment.rotation.y,
999
+ z: segment.rotation.z
1000
+ },
1001
+ scale: {
1002
+ x: segment.scale.x,
1003
+ y: segment.scale.y,
1004
+ z: segment.scale.z
1005
+ }
1006
+ };
1007
+
1008
+ // Add to scene data children
1009
+ component.currentSceneData.scene.object.children.push(sceneDataSegment);
1010
+ console.log("\uD83D\uDD27 Added manual segment to scene data: ".concat(segment.name));
1011
+ }
1012
+
1013
+ /**
1014
+ * Restructure connections to use the new connectors
1015
+ * @param {Object} originalConnection - The original connection
1016
+ * @param {Array} connectors - Array of connector objects
1017
+ * @param {Object} currentSceneData - Current scene data
1018
+ */
1019
+ }, {
1020
+ key: "restructureConnections",
1021
+ value: function restructureConnections(originalConnection, connectors, currentSceneData) {
1022
+ var _connectors = _rollupPluginBabelHelpers.slicedToArray(connectors, 2),
1023
+ startConnector = _connectors[0],
1024
+ endConnector = _connectors[1];
1025
+ console.log('🔗 Restructuring connections...');
1026
+ console.log('🔗 Original connection:', originalConnection);
1027
+ console.log('🔗 Start connector:', startConnector.uuid);
1028
+ console.log('🔗 End connector:', endConnector.uuid);
1029
+
1030
+ // Find the original connection in the connections array
1031
+ var connectionIndex = currentSceneData.connections.findIndex(function (conn) {
1032
+ return conn.from === originalConnection.from && conn.to === originalConnection.to || conn.from === originalConnection.to && conn.to === originalConnection.from;
1033
+ });
1034
+ if (connectionIndex === -1) {
1035
+ console.warn('⚠️ Could not find original connection in connections array');
1036
+ return;
1037
+ }
1038
+ console.log("\uD83D\uDD17 Found original connection at index: ".concat(connectionIndex));
1039
+
1040
+ // Remove the original connection
1041
+ currentSceneData.connections.splice(connectionIndex, 1);
1042
+ console.log("\uD83D\uDDD1\uFE0F Removed original connection: ".concat(originalConnection.from, " \u2192 ").concat(originalConnection.to));
1043
+
1044
+ // Add two new connections
1045
+ var newConnection1 = {
1046
+ from: originalConnection.from,
1047
+ to: startConnector.uuid
1048
+ };
1049
+ var newConnection2 = {
1050
+ from: endConnector.uuid,
1051
+ to: originalConnection.to
1052
+ };
1053
+ currentSceneData.connections.push(newConnection1, newConnection2);
1054
+ console.log("\u2795 Added new connections:");
1055
+ console.log(" ".concat(newConnection1.from, " \u2192 ").concat(newConnection1.to));
1056
+ console.log(" ".concat(newConnection2.from, " \u2192 ").concat(newConnection2.to));
1057
+
1058
+ // Update the component's current scene data
1059
+ if (this.sceneViewer.currentSceneData) {
1060
+ this.sceneViewer.currentSceneData.connections = _rollupPluginBabelHelpers.toConsumableArray(currentSceneData.connections);
1061
+ console.log('✅ Updated component currentSceneData connections');
1062
+ }
1063
+ console.log('🔗 Connection restructuring completed');
1064
+ }
1065
+
1066
+ /**
1067
+ * Create smooth elbow geometry to connect two pipe segments (optimized for 90-degree angles)
1068
+ * @param {THREE.Vector3} point1 - First point (before the joint)
1069
+ * @param {THREE.Vector3} point2 - Joint point (center of the elbow)
1070
+ * @param {THREE.Vector3} point3 - Third point (after the joint)
1071
+ * @param {number} radius - Pipe radius
1072
+ * @returns {THREE.BufferGeometry} Elbow geometry
1073
+ */
1074
+ }, {
1075
+ key: "createElbowGeometry",
1076
+ value: function createElbowGeometry(point1, point2, point3, radius) {
1077
+ try {
1078
+ // Fixed elbow radius for 90-degree bends (simplified)
1079
+ var elbowRadius = radius * 3;
1080
+
1081
+ // Create a curve for the 90-degree elbow
1082
+ var curve = this.createElbowCurve(point1, point2, point3, elbowRadius);
1083
+
1084
+ // Fixed tubular segments for 90-degree bends (quarter circle)
1085
+ var tubularSegments = 12; // Good balance for smooth 90° curves
1086
+ var radialSegments = 8;
1087
+ var closed = false;
1088
+ var elbowGeometry = new THREE__namespace.TubeGeometry(curve, tubularSegments, radius, radialSegments, closed);
1089
+ return elbowGeometry;
1090
+ } catch (error) {
1091
+ console.warn('Failed to create elbow geometry:', error);
1092
+ return null;
1093
+ }
1094
+ }
1095
+
1096
+ /**
1097
+ * Create a smooth curve for the 90-degree elbow joint (simplified)
1098
+ * @param {THREE.Vector3} point1 - First point
1099
+ * @param {THREE.Vector3} point2 - Joint point
1100
+ * @param {THREE.Vector3} point3 - Third point
1101
+ * @param {number} elbowRadius - Radius of the elbow curve
1102
+ * @returns {THREE.Curve} Curve for the elbow
1103
+ */
1104
+ }, {
1105
+ key: "createElbowCurve",
1106
+ value: function createElbowCurve(point1, point2, point3, elbowRadius) {
1107
+ // Calculate direction vectors
1108
+ var dir1 = point2.clone().sub(point1).normalize();
1109
+ var dir2 = point3.clone().sub(point2).normalize();
1110
+
1111
+ // For 90-degree bends, we can use a simpler approach with a quarter circle
1112
+ // The curve radius is proportional to the elbow radius
1113
+ var curveRadius = elbowRadius * 0.001;
1114
+
1115
+ // Calculate the offset distance from the joint point
1116
+ var offset = curveRadius;
1117
+
1118
+ // Calculate start and end points of the curve (offset from the joint)
1119
+ var curveStart = point2.clone().sub(dir1.clone().multiplyScalar(offset));
1120
+ var curveEnd = point2.clone().add(dir2.clone().multiplyScalar(offset));
1121
+
1122
+ // For a 90-degree bend, the control point is at the corner
1123
+ // We can use a quadratic bezier curve for simplicity
1124
+ var controlPoint = point2.clone();
1125
+
1126
+ // Create a quadratic bezier curve (simpler than cubic for 90° bends)
1127
+ var curve = new THREE__namespace.QuadraticBezierCurve3(curveStart, controlPoint, curveEnd);
1128
+ return curve;
1129
+ }
1130
+
1131
+ /**
1132
+ * Recompute world bounding boxes after transforms
1133
+ */
1134
+ }, {
1135
+ key: "recomputeWorldBoundingBoxes",
1136
+ value: function recomputeWorldBoundingBoxes(currentSceneData) {
1137
+ var component = this.sceneViewer;
1138
+ component.scene.traverse(function (object) {
1139
+ if (object.isMesh) {
1140
+ // Find the corresponding JSON object
1141
+ var jsonObject = null;
1142
+ var _findJsonObject = function findJsonObject(children) {
1143
+ var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(children),
1144
+ _step;
1145
+ try {
1146
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1147
+ var _object$userData, _child$userData2;
1148
+ var child = _step.value;
1149
+ // Enhanced matching logic with hardcoded UUID priority
1150
+
1151
+ // Strategy 1: Direct hardcoded UUID match (HIGHEST PRIORITY)
1152
+ if (child.uuid === object.uuid || child.uuid === ((_object$userData = object.userData) === null || _object$userData === void 0 ? void 0 : _object$userData.originalUuid) || object.uuid === ((_child$userData2 = child.userData) === null || _child$userData2 === void 0 ? void 0 : _child$userData2.originalUuid)) {
1153
+ return child;
1154
+ }
1155
+
1156
+ // Strategy 2: Name-based UUID match (FALLBACK)
1157
+ if (object.name && child.name) {
1158
+ var objectGeneratedUuid = nameUtils.generateUuidFromName(object.name);
1159
+ var childGeneratedUuid = nameUtils.generateUuidFromName(child.name);
1160
+ if (objectGeneratedUuid === childGeneratedUuid || objectGeneratedUuid === child.uuid || childGeneratedUuid === object.uuid) {
1161
+ return child;
1162
+ }
1163
+ }
1164
+
1165
+ // Strategy 3: Name match
1166
+ if (object.name && child.name && object.name === child.name) {
1167
+ return child;
1168
+ }
1169
+
1170
+ // Recursively search children
1171
+ if (child.children) {
1172
+ var found = _findJsonObject(child.children);
1173
+ if (found) return found;
1174
+ }
1175
+ }
1176
+ } catch (err) {
1177
+ _iterator.e(err);
1178
+ } finally {
1179
+ _iterator.f();
1180
+ }
1181
+ return null;
1182
+ };
1183
+ jsonObject = _findJsonObject(currentSceneData.scene.object.children);
1184
+ if (jsonObject) {
1185
+ // Compute world bounding box
1186
+ var boundingBox = new THREE__namespace.Box3().setFromObject(object);
1187
+
1188
+ // Store in JSON userData for pathfinder
1189
+ if (!jsonObject.userData) jsonObject.userData = {};
1190
+ jsonObject.userData.worldBoundingBox = {
1191
+ min: boundingBox.min.toArray(),
1192
+ max: boundingBox.max.toArray()
1193
+ };
1194
+ if (!jsonObject.userData.origin) jsonObject.userData.origin = object.userData.origin;
1195
+ if (!jsonObject.userData.direction) jsonObject.userData.direction = object.userData.direction;
1196
+ if (!jsonObject.userData.group) jsonObject.userData.group = object.userData.group;
1197
+ if (!jsonObject.userData.connections) jsonObject.userData.connections = object.userData.connections;
1198
+ object.userData.associatedJsonObject = jsonObject;
1199
+ console.log("Added world bounding box for ".concat(jsonObject.name, ":"), jsonObject.userData.worldBoundingBox);
1200
+ }
1201
+ }
1202
+ });
1203
+ } /**
1204
+ * Update pathfinding with new connections data
1205
+ */
1206
+ }, {
1207
+ key: "updatePathfindingWithConnections",
1208
+ value: (function () {
1209
+ var _updatePathfindingWithConnections = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee5(newConnections) {
1210
+ var _component$currentSce, _component$currentSce2, _component$currentSce3, _updatedSceneData$sce;
1211
+ var component, updatedSceneData;
1212
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context5) {
1213
+ while (1) switch (_context5.n) {
1214
+ case 0:
1215
+ console.log('[A] updatePathfindingWithConnections');
1216
+ component = this.sceneViewer; // Check if we have current scene data to work with
1217
+ if (component.currentSceneData) {
1218
+ _context5.n = 1;
1219
+ break;
1220
+ }
1221
+ console.warn('⚠️ No current scene data available for pathfinder update');
1222
+ return _context5.a(2, false);
1223
+ case 1:
1224
+ // Remove all existing paths from the scene
1225
+ this.removeComputedObjects();
1226
+ console.log('🔄 Updating pathfinder with new connections:', newConnections);
1227
+ console.log('🔍 Current scene data structure:', {
1228
+ hasConnections: !!component.currentSceneData.connections,
1229
+ connectionsCount: ((_component$currentSce = component.currentSceneData.connections) === null || _component$currentSce === void 0 ? void 0 : _component$currentSce.length) || 0,
1230
+ hasScene: !!component.currentSceneData.scene,
1231
+ hasSceneObject: !!((_component$currentSce2 = component.currentSceneData.scene) !== null && _component$currentSce2 !== void 0 && _component$currentSce2.object),
1232
+ childrenCount: ((_component$currentSce3 = component.currentSceneData.scene) === null || _component$currentSce3 === void 0 || (_component$currentSce3 = _component$currentSce3.object) === null || _component$currentSce3 === void 0 || (_component$currentSce3 = _component$currentSce3.children) === null || _component$currentSce3 === void 0 ? void 0 : _component$currentSce3.length) || 0
1233
+ });
1234
+
1235
+ // Create a deep copy of the current scene data to avoid mutations
1236
+ updatedSceneData = JSON.parse(JSON.stringify(component.currentSceneData)); // Update the connections in the copied scene data
1237
+ updatedSceneData.connections = _rollupPluginBabelHelpers.toConsumableArray(newConnections);
1238
+ console.log('🔍 Updated scene data for pathfinder:', {
1239
+ connectionsCount: updatedSceneData.connections.length,
1240
+ connections: updatedSceneData.connections,
1241
+ hasScene: !!updatedSceneData.scene,
1242
+ childrenCount: ((_updatedSceneData$sce = updatedSceneData.scene) === null || _updatedSceneData$sce === void 0 || (_updatedSceneData$sce = _updatedSceneData$sce.object) === null || _updatedSceneData$sce === void 0 || (_updatedSceneData$sce = _updatedSceneData$sce.children) === null || _updatedSceneData$sce === void 0 ? void 0 : _updatedSceneData$sce.length) || 0
1243
+ });
1244
+
1245
+ // Use shared pathfinding logic (no gateways needed for updates)
1246
+ _context5.n = 2;
1247
+ return this._executePathfinding(updatedSceneData.scene, updatedSceneData.connections, {
1248
+ createGateways: false,
1249
+ context: 'Connections Update'
1250
+ });
1251
+ case 2:
1252
+ // Update the component's current scene data to reflect the changes
1253
+ component.currentSceneData = updatedSceneData;
1254
+ console.log('✅ Pathfinding updated successfully with new connections');
1255
+ return _context5.a(2, true);
1256
+ }
1257
+ }, _callee5, this);
1258
+ }));
1259
+ function updatePathfindingWithConnections(_x5) {
1260
+ return _updatePathfindingWithConnections.apply(this, arguments);
1261
+ }
1262
+ return updatePathfindingWithConnections;
1263
+ }()
1264
+ /**
1265
+ * Update pathfinding after object transforms
1266
+ */
1267
+ )
1268
+ }, {
1269
+ key: "updatePathfindingAfterTransform",
1270
+ value: (function () {
1271
+ var _updatePathfindingAfterTransform = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee6(currentSceneData) {
1272
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context6) {
1273
+ while (1) switch (_context6.n) {
1274
+ case 0:
1275
+ // Remove all existing paths from the scene
1276
+ this.removeComputedObjects();
1277
+ console.log('🔄 Starting pathfinding with updated scene data...');
1278
+
1279
+ // Use shared pathfinding logic (no gateways needed for transform updates)
1280
+ _context6.n = 1;
1281
+ return this._executePathfinding(currentSceneData.scene, currentSceneData.connections, {
1282
+ createGateways: true,
1283
+ context: 'Transform Update'
1284
+ });
1285
+ case 1:
1286
+ return _context6.a(2);
1287
+ }
1288
+ }, _callee6, this);
1289
+ }));
1290
+ function updatePathfindingAfterTransform(_x6) {
1291
+ return _updatePathfindingAfterTransform.apply(this, arguments);
1292
+ }
1293
+ return updatePathfindingAfterTransform;
1294
+ }()
1295
+ /**
1296
+ * Dispose of pathfinding resources
1297
+ */
1298
+ )
1299
+ }, {
1300
+ key: "dispose",
1301
+ value: function dispose() {
1302
+ this.removeComputedObjects();
1303
+ this.pathfinder = null;
1304
+ this.crosscubeTextureSet = null;
1305
+ this.pathfinderVersionInfo = null;
1306
+ debugLogger.logger.info('PathfindingManager disposed');
1307
+ }
1308
+
1309
+ /**
1310
+ * Merges colinear segments in path data to optimize pipe creation
1311
+ * @param {Array} paths - Array of path objects from pathfinder
1312
+ * @param {Number} tolerance - Angular tolerance for considering segments colinear (default: ~0.57 degrees)
1313
+ * @returns {Array} Optimized paths with merged colinear segments
1314
+ */
1315
+ }, {
1316
+ key: "mergeColinearPaths",
1317
+ value: function mergeColinearPaths(paths) {
1318
+ var tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.001;
1319
+ // Create a deep copy of paths to avoid modifying the original
1320
+ var optimizedPaths = JSON.parse(JSON.stringify(paths));
1321
+ optimizedPaths.forEach(function (pathData) {
1322
+ if (!pathData.path || pathData.path.length <= 2) {
1323
+ return; // Skip paths with 0-2 points (no optimization needed)
1324
+ }
1325
+
1326
+ // Convert path points to THREE.Vector3 objects for easier processing
1327
+ var originalPath = pathData.path.map(function (point) {
1328
+ if (point instanceof THREE__namespace.Vector3) {
1329
+ return point.clone();
1330
+ } else if (Array.isArray(point)) {
1331
+ return new THREE__namespace.Vector3().fromArray(point);
1332
+ } else if (point.x !== undefined && point.y !== undefined && point.z !== undefined) {
1333
+ return new THREE__namespace.Vector3(point.x, point.y, point.z);
1334
+ } else {
1335
+ console.warn('Unknown point format:', point);
1336
+ return new THREE__namespace.Vector3(0, 0, 0);
1337
+ }
1338
+ });
1339
+ if (originalPath.length <= 2) {
1340
+ return; // Skip after conversion if still too few points
1341
+ }
1342
+ var newPath = [originalPath[0]]; // Start with the first point
1343
+
1344
+ // Iterate through segments starting from the first segment
1345
+ var i = 0;
1346
+ var _loop2 = function _loop2() {
1347
+ var segmentStart = originalPath[i];
1348
+ var segmentEnd = originalPath[i + 1];
1349
+
1350
+ // Calculate initial direction vector
1351
+ var currentDir = new THREE__namespace.Vector3().subVectors(segmentEnd, segmentStart);
1352
+ var initialLength = currentDir.length();
1353
+
1354
+ // Skip zero-length segments
1355
+ if (initialLength < 1e-6) {
1356
+ i++;
1357
+ return 1; // continue
1358
+ }
1359
+ currentDir.normalize();
1360
+
1361
+ // Look ahead to find all colinear points
1362
+ var j = i + 2;
1363
+ while (j < originalPath.length) {
1364
+ var nextPoint = originalPath[j];
1365
+
1366
+ // Check if the line from segmentStart to nextPoint is colinear with currentDir
1367
+ var testDir = new THREE__namespace.Vector3().subVectors(nextPoint, segmentStart);
1368
+ var testLength = testDir.length();
1369
+ if (testLength < 1e-6) {
1370
+ // Skip zero-length vectors
1371
+ j++;
1372
+ continue;
1373
+ }
1374
+ testDir.normalize();
1375
+
1376
+ // Check colinearity using dot product (should be very close to 1 for same direction)
1377
+ var dot = currentDir.dot(testDir);
1378
+ var isColinear = Math.abs(dot - 1) < tolerance;
1379
+ if (isColinear) {
1380
+ // Extend the segment to this point
1381
+ segmentEnd = nextPoint;
1382
+ j++;
1383
+ } else {
1384
+ // Not colinear, stop extending this segment
1385
+ break;
1386
+ }
1387
+ }
1388
+
1389
+ // Add the final point of this merged segment (unless it's the start point)
1390
+ if (!segmentEnd.equals(segmentStart)) {
1391
+ newPath.push(segmentEnd);
1392
+ }
1393
+
1394
+ // Move to the next unprocessed point
1395
+ // Find the index of segmentEnd in the original path
1396
+ var nextIndex = originalPath.findIndex(function (point, idx) {
1397
+ return idx > i && point.equals(segmentEnd);
1398
+ });
1399
+ if (nextIndex === -1) {
1400
+ // If we can't find it, just increment by 1 (fallback)
1401
+ i++;
1402
+ } else {
1403
+ i = nextIndex;
1404
+ }
1405
+ };
1406
+ while (i < originalPath.length - 1) {
1407
+ if (_loop2()) continue;
1408
+ }
1409
+
1410
+ // Convert back to the original format (arrays if input was arrays)
1411
+ var outputPath = newPath.map(function (point) {
1412
+ if (Array.isArray(pathData.path[0])) {
1413
+ return [point.x, point.y, point.z];
1414
+ } else if (pathData.path[0].x !== undefined) {
1415
+ return {
1416
+ x: point.x,
1417
+ y: point.y,
1418
+ z: point.z
1419
+ };
1420
+ } else {
1421
+ return point;
1422
+ }
1423
+ });
1424
+
1425
+ // Replace the original path with the optimized one
1426
+ pathData.path = outputPath;
1427
+
1428
+ // Log the optimization results
1429
+ var reduction = originalPath.length - newPath.length;
1430
+ if (reduction > 0) {
1431
+ console.log("\u2705 Optimized path ".concat(pathData.from, "-").concat(pathData.to, ": ") + "Reduced ".concat(originalPath.length, " points to ").concat(newPath.length, " ") + "(".concat(Math.round(reduction / originalPath.length * 100), "% reduction)"));
1432
+ } else {
1433
+ console.log("\u27A1\uFE0F Path ".concat(pathData.from, "-").concat(pathData.to, ": No optimization possible ") + "(".concat(originalPath.length, " points)"));
1434
+ }
1435
+ });
1436
+ return optimizedPaths;
1437
+ }
1438
+ }]);
1439
+ }();
1440
+
1441
+ exports.PathfindingManager = PathfindingManager;