@2112-lab/central-plant 0.1.4 → 0.1.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.
- package/dist/bundle/index.js +33146 -1
- package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
- package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
- package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
- package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
- package/dist/cjs/src/analysis/analysis.js +560 -1
- package/dist/cjs/src/analysis/testing.js +958 -1
- package/dist/cjs/src/core/centralPlant.js +1149 -1
- package/dist/cjs/src/core/debugLogger.js +175 -1
- package/dist/cjs/src/core/mathUtils.js +574 -1
- package/dist/cjs/src/core/nameUtils.js +93 -1
- package/dist/cjs/src/data/export.js +716 -1
- package/dist/cjs/src/data/import.js +380 -1
- package/dist/cjs/src/data/numerics.js +522 -1
- package/dist/cjs/src/helpers/sceneHelper.js +572 -1
- package/dist/cjs/src/index.js +69 -1
- package/dist/cjs/src/managers/components/animationManager.js +123 -1
- package/dist/cjs/src/managers/components/componentManager.js +332 -1
- package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
- package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
- package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
- package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
- package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
- package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
- package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
- package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
- package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
- package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
- package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
- package/dist/cjs/src/managers/system/disposalManager.js +444 -1
- package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
- package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
- package/dist/cjs/src/rendering/modelPreloader.js +369 -1
- package/dist/cjs/src/rendering/rendering2D.js +631 -1
- package/dist/cjs/src/rendering/rendering3D.js +685 -1
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
- package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
- package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
- package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
- package/dist/esm/src/analysis/analysis.js +536 -1
- package/dist/esm/src/analysis/testing.js +954 -1
- package/dist/esm/src/core/centralPlant.js +1144 -1
- package/dist/esm/src/core/debugLogger.js +167 -1
- package/dist/esm/src/core/mathUtils.js +570 -1
- package/dist/esm/src/core/nameUtils.js +87 -1
- package/dist/esm/src/data/export.js +712 -1
- package/dist/esm/src/data/import.js +356 -1
- package/dist/esm/src/data/numerics.js +518 -1
- package/dist/esm/src/helpers/sceneHelper.js +547 -1
- package/dist/esm/src/index.js +35 -1
- package/dist/esm/src/managers/components/animationManager.js +119 -1
- package/dist/esm/src/managers/components/componentManager.js +328 -1
- package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
- package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
- package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
- package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
- package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
- package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
- package/dist/esm/src/managers/environment/environmentManager.js +690 -1
- package/dist/esm/src/managers/environment/textureConfig.js +202 -1
- package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
- package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
- package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
- package/dist/esm/src/managers/system/disposalManager.js +440 -1
- package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
- package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
- package/dist/esm/src/rendering/modelPreloader.js +364 -1
- package/dist/esm/src/rendering/rendering2D.js +627 -1
- package/dist/esm/src/rendering/rendering3D.js +661 -1
- package/package.json +1 -1
|
@@ -1 +1,1509 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"t",{value:!0});var e=require("../../../_virtual/_rollupPluginBabelHelpers.js"),n=require("three"),r=require("../environment/textureConfig.js"),t=require("../../rendering/modelPreloader.js"),i=require("../../core/debugLogger.js");function a(e){if(e&&e.t)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,Object.freeze(n)}var o=a(n),u=function(){return e.createClass(function n(r){e.classCallCheck(this,n),this.sceneViewer=r},[{key:"clearSceneObjects",value:function(){var e=this.sceneViewer;this.deselectObject();var n=null;e.transformManager&&e.transformManager.transformControls&&(e.transformManager.setEnabled(!1),e.transformManager.transformControls.visible=!1,n=e.transformManager.transformControls);var r=[];e.scene.traverse(function(t){var i,a,o,u,c;0;var l=t===n||(null===(i=t.userData)||void 0===i?void 0:i.isTransformControls)||t.isTransformControls||t.type&&t.type.includes("TransformControls");l&&0,t===e.scene||null!==(a=t.userData)&&void 0!==a&&a.isBrickWall||null!==(o=t.userData)&&void 0!==o&&o.isBaseGround||null!==(u=t.userData)&&void 0!==u&&u.isBaseGrid||l||t.isLight||"PlaneGeometry"===(null===(c=t.geometry)||void 0===c?void 0:c.type)||r.push(t)}),r.forEach(function(n){e.scene.remove(n),n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(function(e){return e.dispose()}):n.material.dispose())}),e.selectedObjectForTransform=null,e.transformHistory&&(e.transformHistory=[]),e.transformManager&&e.transformManager.transformControls||e.initTransformControls(),this.ensureTransformControlsAttached(!1)}},{key:"ensureTransformControlsAttached",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],n=this.sceneViewer;if(n.transformManager){if(!n.transformManager.transformControls)return n.transformManager.createTransformControls(),void n.transformManager.setupEventListeners();n.transformManager.ensureSceneAttachment(e);!e&&n.transformManager.transformControls&&(n.transformManager.transformControls.visible=!1)}else n.initTransformControls()}},{key:"loadLibraryModel",value:(v=e.asyncToGenerator(e.regenerator().m(function n(r,a,u){var c,l,s,v,f,d,h,y,m,w,b,k,p,M,g,x;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:if(c=this.sceneViewer,n.p=1,i.modelLogger.info("Loading library GLB model for ".concat(null===(l=a.userData)||void 0===l?void 0:l.libraryId,"...")),i.modelLogger.debug("Starting to load GLB model from /library/models/".concat(u.modelKey)),f=r.parent,d=r.position.clone(),h=r.quaternion.clone(),y=r.scale.clone(),m=r.name,w=r.uuid,b=[],r.children.forEach(function(n){var r=n.geometry&&("CONNECTOR-GEO"===n.geometry.uuid||"SphereGeometry"===n.geometry.type&&n.geometry.parameters),t=n.name&&n.name.toLowerCase().includes("connector");if(r&&t){if(n.userData||(n.userData={}),!n.userData.worldBoundingBox){var i=(new o.Box3).setFromObject(n);n.userData.worldBoundingBox={min:i.min.toArray(),max:i.max.toArray()}}var a=n.clone();if(n.userData){a.userData={},n.userData.worldBoundingBox&&(a.userData.worldBoundingBox={min:e.toConsumableArray(n.userData.worldBoundingBox.min),max:e.toConsumableArray(n.userData.worldBoundingBox.max)}),n.userData.direction&&(a.userData.direction=e.toConsumableArray(n.userData.direction));for(var u=0,c=Object.entries(n.userData);u<c.length;u++){var l=e.slicedToArray(c[u],2),s=l[0],v=l[1];"worldBoundingBox"!==s&&"direction"!==s&&(a.userData[s]=v)}a.userData.originalUuid=n.uuid,void 0===a.userData.forExport&&(a.userData.forExport=!0),a.userData.componentType||(n.name&&n.name.toLowerCase().includes("connector")?a.userData.componentType="connector":n.name&&n.name.toLowerCase().includes("gateway")&&(a.userData.componentType="gateway"))}b.push(a)}}),!(k=t.default.getCachedModelWithDimensions(u.modelKey,null===(s=a.userData)||void 0===s?void 0:s.libraryId))){n.n=2;break}n.n=8;break;case 2:if(!t.default.getStatus().isPreloading){n.n=6;break}return n.p=3,n.n=4,t.default.preloadingPromise;case 4:k=t.default.getCachedModelWithDimensions(u.modelKey,null===(p=a.userData)||void 0===p?void 0:p.libraryId),n.n=6;break;case 5:n.p=5,n.v;case 6:if(k){n.n=8;break}return n.n=7,new Promise(function(e,n){c.gltfLoader.load("/library/models/".concat(u.modelKey),function(n){e(n)},function(e){},function(e){n(e)})});case 7:g=n.v,k=g.scene,null!==(M=a.userData)&&void 0!==M&&M.libraryId&&(k=t.default.addDimensionsToModel(k,a.userData.libraryId));case 8:return(x=k.isCachedClone?k:k.clone()).uuid=w,x.name=m,x.quaternion.copy(h),x.scale.copy(y),x.userData||(x.userData={}),x.userData.originalUuid=w,x.userData.componentType="component",x.userData.libraryId=null===(v=a.userData)||void 0===v?void 0:v.libraryId,u.boundingBox&&(x.userData.dimensions={x:u.boundingBox.x,y:u.boundingBox.y,z:u.boundingBox.z}),u.adaptedBoundingBox&&(x.userData.adaptedBoundingBox={x:u.adaptedBoundingBox.x,y:u.adaptedBoundingBox.y,z:u.adaptedBoundingBox.z}),a.position&&a.rotation?(x.position.set(a.position.x,a.position.y,a.position.z),x.rotation.set(o.MathUtils.degToRad(a.rotation.x),o.MathUtils.degToRad(a.rotation.y),o.MathUtils.degToRad(a.rotation.z))):x.position.copy(d),x.traverse(function(e){e.isMesh&&(e.castShadow=!0,e.receiveShadow=!0,e.material&&(e.material.envMapIntensity=1))}),b.forEach(function(e){x.add(e)}),x.children.forEach(function(e,n){e.name&&e.name.toLowerCase().includes("connector")}),x.children.length>0&&x.children.forEach(function(e,n){}),f&&f.add&&"function"==typeof f.add?(f.remove(r),f.add(x)):(c.scene.remove(r),c.scene.add(x)),n.a(2,x);case 9:return n.p=9,n.v,n.a(2,r)}},n,this,[[3,5],[1,9]])})),function(e,n,r){return v.apply(this,arguments)})},{key:"verifyModelPreloaderCache",value:(s=e.asyncToGenerator(e.regenerator().m(function n(){var r;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(!(r=t.default.getStatus()).isPreloading){e.n=4;break}return e.p=1,e.n=2,t.default.preloadingPromise;case 2:e.n=4;break;case 3:e.p=3,e.v;case 4:return e.a(2,r)}},n,null,[[1,3]])})),function(){return s.apply(this,arguments)})},{key:"preloadMissingModels",value:(l=e.asyncToGenerator(e.regenerator().m(function n(r,i){var a,o,u,c,l,s,v,f;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:return a=new Set,r.scene.object.children.forEach(function(e){var n,r;if(null!==(n=e.userData)&&void 0!==n&&n.libraryId&&i[null===(r=e.userData)||void 0===r?void 0:r.libraryId]){var t,o=i[null===(t=e.userData)||void 0===t?void 0:t.libraryId].modelKey;o&&a.add(o)}}),n.n=1,this.verifyModelPreloaderCache();case 1:if(o=n.v,u=o.cachedModels,!((c=Array.from(a).filter(function(e){return!u.includes(e)})).length>0)){n.n=11;break}l=e.createForOfIteratorHelper(c),n.p=2,l.s();case 3:if((s=l.n()).done){n.n=8;break}return v=s.value,n.p=4,n.n=5,t.default.preloadSingleModel(v);case 5:n.n=7;break;case 6:n.p=6,n.v;case 7:n.n=3;break;case 8:n.n=10;break;case 9:n.p=9,f=n.v,l.e(f);case 10:return n.p=10,l.f(),n.f(10);case 11:return n.a(2)}},n,this,[[4,6],[2,9,10,11]])})),function(e,n){return l.apply(this,arguments)})},{key:"createSceneMaterials",value:(c=e.asyncToGenerator(e.regenerator().m(function n(t){var i,a,o;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return i=this.sceneViewer,a={},o=null,e.p=1,e.n=2,r.loadTextureSet("light_metal",i.textureLoader);case 2:o=e.v,e.n=7;break;case 3:return e.p=3,e.v,e.p=4,e.n=5,r.loadTextureSet("gravel_embedded_concrete",i.textureLoader);case 5:o=e.v,e.n=7;break;case 6:e.p=6,e.v;case 7:return e.a(2,{materials:a,crosscubeTextureSet:o})}},n,this,[[4,6],[1,3]])})),function(e){return c.apply(this,arguments)})},{key:"createSceneGeometries",value:function(e,n){var r={};return e.scene.object.children.forEach(function(e){var t;if(null!==(t=e.userData)&&void 0!==t&&t.libraryId&&n[e.userData.libraryId]){var i=n[e.userData.libraryId].boundingBox,a=new o.BoxGeometry(i.x||1,i.y||1,i.z||1);r[e.geometry]=a}else{var u=e.uuid&&(e.uuid.toLowerCase().includes("connector")||e.uuid.toLowerCase().includes("gateway"));r[e.geometry]=u?new o.SphereGeometry(.1,16,16):new o.BoxGeometry(1,1,1)}}),r}},{key:"createSceneObject",value:function(n,r,t){var i=this,a=r[n.geometry],u=t[n.material];u||(u=new o.MeshPhysicalMaterial({color:12632256,roughness:.15,metalness:.9,emissive:0,envMapIntensity:1.5,transparent:!0,opacity:.8}));var c=new o.Mesh(a,u);if(c.uuid=n.uuid,c.name=n.name||n.uuid,c.userData||(c.userData={}),c.userData.originalUuid=n.uuid,n.userData&&(c.userData=e.objectSpread2({},n.userData),c.userData.componentType||(c.userData.libraryId?c.userData.componentType="component":n.uuid&&n.uuid.toLowerCase().includes("connector")?c.userData.componentType="connector":n.uuid&&n.uuid.toLowerCase().includes("gateway")&&(c.userData.componentType="gateway"))),c.isMesh&&(c.castShadow=!0,c.receiveShadow=!0),n.position&&c.position.set(n.position.x||0,n.position.y||0,n.position.z||0),n.rotation){var l=n.rotation.x*(Math.PI/180),s=n.rotation.y*(Math.PI/180),v=n.rotation.z*(Math.PI/180);c.rotation.set(l,s,v)}return n.scale&&c.scale.set(n.scale.x||1,n.scale.y||1,n.scale.z||1),n.children&&n.children.forEach(function(e){c.add(i.createSceneObject(e,r,t))}),c}},{key:"computeWorldBoundingBoxes",value:function(n){this.sceneViewer.scene.traverse(function(r){if(r.isMesh){var t=null,i=function(n){var t,a=e.createForOfIteratorHelper(n);try{for(a.s();!(t=a.n()).done;){var o,u,c=t.value;if(c.uuid===r.uuid||c.uuid===(null===(o=r.userData)||void 0===o?void 0:o.originalUuid)||r.uuid===(null===(u=c.userData)||void 0===u?void 0:u.originalUuid))return c;if(c.children){var l=i(c.children);if(l)return l}}}catch(e){a.e(e)}finally{a.f()}return null};if(t=i(n.scene.object.children)){var a=(new o.Box3).setFromObject(r);t.userData||(t.userData={}),t.userData.worldBoundingBox={min:a.min.toArray(),max:a.max.toArray()}}}})}},{key:"loadSceneData",value:(u=e.asyncToGenerator(e.regenerator().m(function n(r){var t,i,a,u,c,l,s,v,f,d,h,y,m=this,w=arguments;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return t=!(w.length>1&&void 0!==w[1])||w[1],i=this.sceneViewer,e.p=1,a=function(e){e.traverse(function(e){if(e.userData&&e.userData.direction){var n=new o.Matrix4;n.copy(e.matrixWorld),e.userData.worldMatrixOriginal=n.elements}})},t&&(i.transformManager&&i.transformManager.transformControls,this.clearSceneObjects()),i.currentSceneData=r,u={},e.p=2,e.n=3,fetch("./library/component-dictionary.json");case 3:return c=e.v,e.n=4,c.json();case 4:u=e.v,e.n=6;break;case 5:e.p=5,e.v;case 6:return e.n=7,this.preloadMissingModels(r,u);case 7:return e.n=8,this.createSceneMaterials(r);case 8:if(l=e.v,s=l.materials,v=l.crosscubeTextureSet,f=this.createSceneGeometries(r,u),d=[],r.scene.object.children.forEach(function(e,n){var r,t,a,o=m.createSceneObject(e,f,s);i.scene.add(o),null!==(r=e.userData)&&void 0!==r&&r.libraryId&&u[null===(t=e.userData)||void 0===t?void 0:t.libraryId]&&d.push({basicObject:o,jsonData:e,componentData:u[null===(a=e.userData)||void 0===a?void 0:a.libraryId]})}),this.computeWorldBoundingBoxes(r),a(i.scene),h=[],d.forEach(function(e,n){var r=e.basicObject,t=e.jsonData,i=e.componentData,a=m.loadLibraryModel(r,t,i).then(function(e){return d[n].glbModel=e,e}).catch(function(e){return r});h.push(a)}),!(h.length>0)){e.n=10;break}return e.n=9,Promise.all(h);case 9:"undefined"!=typeof window&&(y=new CustomEvent("sceneUpdateComplete",{detail:{timestamp:Date.now()}}),window.dispatchEvent(y));case 10:if(d.forEach(function(e,n){e.basicObject;var r=e.jsonData,t=(e.componentData,e.glbModel);t.userData.associatedJsonObject=r;var i=(new o.Box3).setFromObject(t);r.type="Mesh",r.userData.worldBoundingBox.min=i.min.toArray(),r.userData.worldBoundingBox.max=i.max.toArray()}),r.scene.object.children.push({uuid:"GROUND",type:"Mesh",name:"Ground",layers:1,matrix:[1,0,0,0,0,0,-1,0,0,1,0,0,0,-.01,0,1],up:[0,1,0],userData:{worldBoundingBox:{min:[-30,-.01,-30],max:[30,-.01,30]}}}),!i.pathfindingManager){e.n=11;break}return e.n=11,i.pathfindingManager.initializePathfinder(r,v);case 11:i.currentSceneData=r,i.crosscubeTextureSet=v,t&&(i.transformManager&&i.transformManager.transformControls?i.transformManager.transformControls&&(i.transformManager.transformControls.visible=!1):i.initTransformControls(),i.ensureTransformControlsAttached(!1),i.transformManager&&i.transformManager.transformControls&&(i.keepTransformControlsInactive(),i.transformManager.transformControls.visible=!1)),e.n=13;break;case 12:e.p=12,e.v;case 13:return e.a(2)}},n,this,[[2,5],[1,12]])})),function(e){return u.apply(this,arguments)})},{key:"loadScene",value:(a=e.asyncToGenerator(e.regenerator().m(function n(){var r,t,i,a;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return r=this.sceneViewer,e.p=1,t=r.$config.defaultCentralPlantUrl,e.n=2,fetch(t);case 2:return i=e.v,e.n=3,i.json();case 3:return a=e.v,r.currentSceneData=a,e.n=4,this.loadSceneData(a,!1);case 4:e.n=6;break;case 5:e.p=5,e.v;case 6:return e.a(2)}},n,this,[[1,5]])})),function(){return a.apply(this,arguments)})},{key:"loadSceneFromData",value:(n=e.asyncToGenerator(e.regenerator().m(function n(r){return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.loadSceneData(r,!0);case 1:return e.a(2)}},n,this)})),function(e){return n.apply(this,arguments)})},{key:"createEmptyScene",value:function(){var e=this.sceneViewer;e.transformManager&&e.transformManager.transformControls&&e.disableTransformControls(),this.clearSceneObjects(),e.transformManager&&e.transformManager.transformControls&&(e.transformManager.setEnabled(!1),e.transformManager.transformControls.visible=!1,e.transformManager.selectedObject&&e.transformManager.deselectObject())}},{key:"clearModelCache",value:function(){var e=this.sceneViewer;e.modelCache&&e.modelCache.clear(),e.loadingPromises&&e.loadingPromises.clear()}},{key:"deselectObject",value:function(){var e=this.sceneViewer;e.transformManager&&e.transformManager.deselectObject(),e.selectedObjectForTransform=null}},{key:"setupEventListeners",value:function(){var n,r,t,i,a=this;this.sceneViewer;var o=this.loadSceneFromData.bind(this);null===(n=window.$nuxt)||void 0===n||null===(r=n.$on)||void 0===r||r.call(n,"loadNewScene",function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o(r);case 1:return e.a(2)}},n)}));return function(e){return n.apply(this,arguments)}}()),null===(t=window.$nuxt)||void 0===t||null===(i=t.$on)||void 0===i||i.call(t,"createNewScene",function(){a.createEmptyScene()})}},{key:"updateSceneDataAfterTransform",value:function(n,r){var t,i,a=!1;if(this.sceneViewer.pathfindingManager.recomputeWorldBoundingBoxes(r),"gateway"===(null===(t=n.userData)||void 0===t?void 0:t.componentType)&&"computed"===(null===(i=n.userData)||void 0===i?void 0:i.origin)){var u;n.userData.origin="declared";for(var c=0;c<r.scene.object.children.length;c++){var l,s,v=r.scene.object.children[c];if(v.uuid===n.uuid||v.uuid===(null===(l=n.userData)||void 0===l?void 0:l.originalUuid)||n.uuid===(null===(s=v.userData)||void 0===s?void 0:s.originalUuid)){v.userData||(v.userData={}),v.userData.origin="declared";break}}if(null!==(u=n.userData)&&void 0!==u&&u.connections&&r.connections){var f=n.userData.connections,d=r.connections;f.removed&&Array.isArray(f.removed)&&(r.connections=d.filter(function(e){var n=f.removed.some(function(n){return n.from===e.from&&n.to===e.to||n.from===e.to&&n.to===e.from});return!n})),f.added&&Array.isArray(f.added)&&f.added.forEach(function(e){r.connections.some(function(n){return n.from===e.from&&n.to===e.to||n.from===e.to&&n.to===e.from})||r.connections.push(e)})}}for(var h=function(){var t,i,u,c,l=r.scene.object.children[y],s=!1;if(l.uuid!==n.uuid&&l.uuid!==(null===(t=n.userData)||void 0===t?void 0:t.originalUuid)&&n.uuid!==(null===(i=l.userData)||void 0===i?void 0:i.originalUuid)||(s=!0),!s&&null!==(u=n.userData)&&void 0!==u&&u.libraryId&&null!==(c=l.userData)&&void 0!==c&&c.libraryId&&n.userData.libraryId===l.userData.libraryId){if(l.position&&n.position){var v=Math.abs(n.position.x-l.position.x),f=Math.abs(n.position.y-l.position.y),d=Math.abs(n.position.z-l.position.z);v<1&&f<1&&d<1&&(s=!0)}}if(s){var h=(new o.Box3).setFromObject(n),m=function(n,r){return n&&r?n.map(function(n){var t=r.find(function(e){var r,t,i,a;if(e.uuid===n.uuid||e.uuid===(null===(r=n.userData)||void 0===r?void 0:r.originalUuid)||(null===(t=e.userData)||void 0===t?void 0:t.originalUuid)===n.uuid)return!0;if(null!==(i=e.userData)&&void 0!==i&&i.componentType&&null!==(a=n.userData)&&void 0!==a&&a.componentType&&e.userData.componentType===n.userData.componentType&&"connector"===e.userData.componentType){if(n.position&&e.position){var o=Math.abs(e.position.x-n.position.x),u=Math.abs(e.position.y-n.position.y),c=Math.abs(e.position.z-n.position.z);if(o<.1&&u<.1&&c<.1)return!0}}return!1});if(t&&t.isMesh){var i=(new o.Box3).setFromObject(t);return e.objectSpread2(e.objectSpread2({},n),{},{userData:e.objectSpread2(e.objectSpread2(e.objectSpread2({},n.userData),t.userData),{},{worldBoundingBox:{min:i.min.toArray(),max:i.max.toArray()}}),children:n.children?m(n.children,t.children):n.children})}return e.objectSpread2(e.objectSpread2({},n),{},{children:n.children?m(n.children,r):n.children})}):n};return n.traverse(function(e){if(e.userData&&e.userData.direction&&e.userData.worldMatrixOriginal){e.updateMatrixWorld(!0);var n=new o.Matrix4;n.copy(e.matrixWorld);var r=new o.Matrix4;r.elements=e.userData.worldMatrixOriginal;var t=new o.Matrix4,i=new o.Matrix4;t.extractRotation(n),i.extractRotation(r);var a=new o.Matrix4;a.copy(t),a.multiply(i.invert());var u=(new o.Vector3).fromArray(e.userData.direction);u.applyMatrix4(a),u.normalize();u.x=Math.abs(u.x)>.5?Math.sign(u.x):0,u.y=Math.abs(u.y)>.5?Math.sign(u.y):0,u.z=Math.abs(u.z)>.5?Math.sign(u.z):0,e.userData.direction=u.toArray(),e.userData.worldMatrixOriginal=n.elements}}),r.scene.object.children[y]=e.objectSpread2(e.objectSpread2({},l),{},{matrix:n.matrix.elements,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},userData:e.objectSpread2(e.objectSpread2({},l.userData),{},{worldBoundingBox:{min:h.min.toArray(),max:h.max.toArray()}}),children:l.children?m(l.children,n.children):l.children}),a=!0,1}},y=0;y<r.scene.object.children.length&&!h();y++);return!!a}}]);var n,a,u,c,l,s,v}();exports.SceneOperationsManager=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 textureConfig = require('../environment/textureConfig.js');
|
|
8
|
+
var modelPreloader = require('../../rendering/modelPreloader.js');
|
|
9
|
+
var debugLogger = require('../../core/debugLogger.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 SceneOperationsManager = /*#__PURE__*/function () {
|
|
32
|
+
function SceneOperationsManager(sceneViewer) {
|
|
33
|
+
_rollupPluginBabelHelpers.classCallCheck(this, SceneOperationsManager);
|
|
34
|
+
this.sceneViewer = sceneViewer;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Clear scene objects while preserving base environment
|
|
39
|
+
*/
|
|
40
|
+
return _rollupPluginBabelHelpers.createClass(SceneOperationsManager, [{
|
|
41
|
+
key: "clearSceneObjects",
|
|
42
|
+
value: function clearSceneObjects() {
|
|
43
|
+
var component = this.sceneViewer;
|
|
44
|
+
console.log('🧹 Starting scene clear operation...');
|
|
45
|
+
|
|
46
|
+
// First, deselect any currently selected object
|
|
47
|
+
this.deselectObject();
|
|
48
|
+
|
|
49
|
+
// Store reference to transform controls to ensure it's not removed
|
|
50
|
+
var transformControlsRef = null;
|
|
51
|
+
if (component.transformManager && component.transformManager.transformControls) {
|
|
52
|
+
// Explicitly disable transform controls before clearing
|
|
53
|
+
console.log('🔧 Disabling transform controls before scene clear');
|
|
54
|
+
component.transformManager.setEnabled(false);
|
|
55
|
+
component.transformManager.transformControls.visible = false;
|
|
56
|
+
transformControlsRef = component.transformManager.transformControls;
|
|
57
|
+
console.log('🔧 Stored reference to existing transform controls');
|
|
58
|
+
}
|
|
59
|
+
var objectsToRemove = [];
|
|
60
|
+
var transformControlsFound = 0;
|
|
61
|
+
var totalChildren = 0;
|
|
62
|
+
component.scene.traverse(function (child) {
|
|
63
|
+
var _child$userData, _child$userData2, _child$userData3, _child$userData4, _child$geometry;
|
|
64
|
+
totalChildren++;
|
|
65
|
+
|
|
66
|
+
// Check for transform controls using multiple detection methods
|
|
67
|
+
var isTransformControl = child === transformControlsRef || ((_child$userData = child.userData) === null || _child$userData === void 0 ? void 0 : _child$userData.isTransformControls) || child.isTransformControls || child.type && child.type.includes('TransformControls');
|
|
68
|
+
if (isTransformControl) {
|
|
69
|
+
transformControlsFound++;
|
|
70
|
+
console.log('🔧 Found transform controls, preserving:', child.constructor.uuid);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Remove imported scene objects but preserve base ground, walls, lights, and transform controls
|
|
74
|
+
if (child !== component.scene && !((_child$userData2 = child.userData) !== null && _child$userData2 !== void 0 && _child$userData2.isBrickWall) && !((_child$userData3 = child.userData) !== null && _child$userData3 !== void 0 && _child$userData3.isBaseGround) && !((_child$userData4 = child.userData) !== null && _child$userData4 !== void 0 && _child$userData4.isBaseGrid) && !isTransformControl && !child.isLight && ((_child$geometry = child.geometry) === null || _child$geometry === void 0 ? void 0 : _child$geometry.type) !== 'PlaneGeometry') {
|
|
75
|
+
objectsToRemove.push(child);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
console.log("\uD83D\uDCCA Scene analysis: ".concat(totalChildren, " total children, ").concat(transformControlsFound, " transform controls found, ").concat(objectsToRemove.length, " objects to remove"));
|
|
79
|
+
objectsToRemove.forEach(function (obj) {
|
|
80
|
+
component.scene.remove(obj);
|
|
81
|
+
if (obj.geometry) obj.geometry.dispose();
|
|
82
|
+
if (obj.material) {
|
|
83
|
+
if (Array.isArray(obj.material)) {
|
|
84
|
+
obj.material.forEach(function (mat) {
|
|
85
|
+
return mat.dispose();
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
obj.material.dispose();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Clear any references to removed objects
|
|
94
|
+
component.selectedObjectForTransform = null;
|
|
95
|
+
if (component.transformHistory) {
|
|
96
|
+
component.transformHistory = [];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Make sure transform controls exist after clearing
|
|
100
|
+
if (!component.transformManager || !component.transformManager.transformControls) {
|
|
101
|
+
console.log('🔧 Transform controls missing after scene clear, reinitializing...');
|
|
102
|
+
component.initTransformControls();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Ensure transform controls are still properly attached after scene operations
|
|
106
|
+
this.ensureTransformControlsAttached(false);
|
|
107
|
+
console.log('✅ Scene clear operation completed');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Ensure transform controls remain properly attached after scene operations
|
|
112
|
+
*/
|
|
113
|
+
}, {
|
|
114
|
+
key: "ensureTransformControlsAttached",
|
|
115
|
+
value: function ensureTransformControlsAttached() {
|
|
116
|
+
var allowVisible = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
117
|
+
var component = this.sceneViewer;
|
|
118
|
+
|
|
119
|
+
// Check if transform manager exists
|
|
120
|
+
if (!component.transformManager) {
|
|
121
|
+
console.log('🔧 No transform manager found, initializing transform controls...');
|
|
122
|
+
component.initTransformControls();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Check if transform controls exist in the manager
|
|
127
|
+
if (!component.transformManager.transformControls) {
|
|
128
|
+
console.log('🔧 Transform controls not found in manager, reinitializing...');
|
|
129
|
+
component.transformManager.createTransformControls();
|
|
130
|
+
component.transformManager.setupEventListeners();
|
|
131
|
+
console.log('✅ Transform controls recreated in manager');
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Use the TransformControlsManager's built-in method for reattachment
|
|
136
|
+
var wasReattached = component.transformManager.ensureSceneAttachment(allowVisible);
|
|
137
|
+
if (wasReattached) {
|
|
138
|
+
console.log('🔧 Transform controls were reattached after scene operation');
|
|
139
|
+
|
|
140
|
+
// Override visibility based on allowVisible parameter
|
|
141
|
+
if (!allowVisible && component.transformManager.transformControls) {
|
|
142
|
+
component.transformManager.transformControls.visible = false;
|
|
143
|
+
console.log('🔧 Forcing transform controls to be invisible during load');
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
console.log('✓ Transform controls are properly attached');
|
|
147
|
+
|
|
148
|
+
// Still ensure visibility is set correctly even if not reattached
|
|
149
|
+
if (!allowVisible && component.transformManager.transformControls) {
|
|
150
|
+
component.transformManager.transformControls.visible = false;
|
|
151
|
+
console.log('🔧 Ensuring transform controls remain invisible during load');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Load GLB model for library objects
|
|
158
|
+
*/
|
|
159
|
+
}, {
|
|
160
|
+
key: "loadLibraryModel",
|
|
161
|
+
value: (function () {
|
|
162
|
+
var _loadLibraryModel = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(targetMesh, jsonEntry, componentData) {
|
|
163
|
+
var component, _jsonEntry$userData, _jsonEntry$userData2, _jsonEntry$userData3, _jsonEntry$userData6, _jsonEntry$userData7, _jsonEntry$userData0, _jsonEntry$userData10, _jsonEntry$userData11, _jsonEntry$userData13, originalParent, originalPosition, originalQuaternion, originalScale, originalName, originalUuid, connectorChildren, gltfScene, preloaderStatus, _jsonEntry$userData4, _jsonEntry$userData5, gltf, libraryModel, _jsonEntry$userData8, _jsonEntry$userData9, _jsonEntry$userData1, _jsonEntry$userData12, _jsonEntry$userData14, _t, _t2;
|
|
164
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
|
|
165
|
+
while (1) switch (_context.n) {
|
|
166
|
+
case 0:
|
|
167
|
+
component = this.sceneViewer;
|
|
168
|
+
_context.p = 1;
|
|
169
|
+
debugLogger.modelLogger.info("Loading library GLB model for ".concat((_jsonEntry$userData = jsonEntry.userData) === null || _jsonEntry$userData === void 0 ? void 0 : _jsonEntry$userData.libraryId, "..."));
|
|
170
|
+
debugLogger.modelLogger.debug("Starting to load GLB model from /library/models/".concat(componentData.modelKey));
|
|
171
|
+
|
|
172
|
+
// Store parent reference BEFORE async operation to prevent it from becoming null
|
|
173
|
+
originalParent = targetMesh.parent;
|
|
174
|
+
originalPosition = targetMesh.position.clone();
|
|
175
|
+
originalQuaternion = targetMesh.quaternion.clone();
|
|
176
|
+
originalScale = targetMesh.scale.clone();
|
|
177
|
+
originalName = targetMesh.name;
|
|
178
|
+
originalUuid = targetMesh.uuid; // Store connector children before replacing the mesh
|
|
179
|
+
connectorChildren = [];
|
|
180
|
+
targetMesh.children.forEach(function (child) {
|
|
181
|
+
// More precise detection: check for CONNECTOR-GEO geometry
|
|
182
|
+
var isConnectorGeometry = child.geometry && (child.geometry.uuid === 'CONNECTOR-GEO' || child.geometry.type === 'SphereGeometry' && child.geometry.parameters);
|
|
183
|
+
var isConnectorByName = child.name && child.name.toLowerCase().includes('connector');
|
|
184
|
+
if (isConnectorGeometry && isConnectorByName) {
|
|
185
|
+
var _child$geometry2, _child$geometry3, _child$material, _child$material2;
|
|
186
|
+
console.log("\uD83D\uDD34 Found connector child to preserve:", {
|
|
187
|
+
name: child.name,
|
|
188
|
+
uuid: child.uuid,
|
|
189
|
+
geometryType: (_child$geometry2 = child.geometry) === null || _child$geometry2 === void 0 ? void 0 : _child$geometry2.type,
|
|
190
|
+
geometryUuid: (_child$geometry3 = child.geometry) === null || _child$geometry3 === void 0 ? void 0 : _child$geometry3.uuid,
|
|
191
|
+
materialUuid: (_child$material = child.material) === null || _child$material === void 0 ? void 0 : _child$material.uuid,
|
|
192
|
+
materialColor: (_child$material2 = child.material) === null || _child$material2 === void 0 || (_child$material2 = _child$material2.color) === null || _child$material2 === void 0 ? void 0 : _child$material2.getHex(),
|
|
193
|
+
hasUserData: !!child.userData,
|
|
194
|
+
userDataKeys: child.userData ? Object.keys(child.userData) : []
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Compute worldBoundingBox for connector BEFORE cloning
|
|
198
|
+
if (!child.userData) child.userData = {};
|
|
199
|
+
|
|
200
|
+
// Compute and store worldBoundingBox if not already present
|
|
201
|
+
if (!child.userData.worldBoundingBox) {
|
|
202
|
+
var boundingBox = new THREE__namespace.Box3().setFromObject(child);
|
|
203
|
+
child.userData.worldBoundingBox = {
|
|
204
|
+
min: boundingBox.min.toArray(),
|
|
205
|
+
max: boundingBox.max.toArray()
|
|
206
|
+
};
|
|
207
|
+
console.log("\uD83D\uDD34 Computed worldBoundingBox for connector ".concat(child.name, ":"), child.userData.worldBoundingBox);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Clone the connector and preserve userData
|
|
211
|
+
var clonedConnector = child.clone();
|
|
212
|
+
|
|
213
|
+
// Preserve pathfinder-critical userData during cloning
|
|
214
|
+
if (child.userData) {
|
|
215
|
+
clonedConnector.userData = {};
|
|
216
|
+
|
|
217
|
+
// Deep copy worldBoundingBox if it exists
|
|
218
|
+
if (child.userData.worldBoundingBox) {
|
|
219
|
+
clonedConnector.userData.worldBoundingBox = {
|
|
220
|
+
min: _rollupPluginBabelHelpers.toConsumableArray(child.userData.worldBoundingBox.min),
|
|
221
|
+
max: _rollupPluginBabelHelpers.toConsumableArray(child.userData.worldBoundingBox.max)
|
|
222
|
+
};
|
|
223
|
+
console.log("\uD83D\uDD34 Preserved worldBoundingBox for connector ".concat(child.name, ":"), clonedConnector.userData.worldBoundingBox);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Deep copy direction if it exists
|
|
227
|
+
if (child.userData.direction) {
|
|
228
|
+
clonedConnector.userData.direction = _rollupPluginBabelHelpers.toConsumableArray(child.userData.direction);
|
|
229
|
+
console.log("\uD83D\uDD34 Preserved direction for connector ".concat(child.name, ":"), clonedConnector.userData.direction);
|
|
230
|
+
}
|
|
231
|
+
// Copy other userData properties
|
|
232
|
+
for (var _i = 0, _Object$entries = Object.entries(child.userData); _i < _Object$entries.length; _i++) {
|
|
233
|
+
var _Object$entries$_i = _rollupPluginBabelHelpers.slicedToArray(_Object$entries[_i], 2),
|
|
234
|
+
key = _Object$entries$_i[0],
|
|
235
|
+
value = _Object$entries$_i[1];
|
|
236
|
+
if (key !== 'worldBoundingBox' && key !== 'direction') {
|
|
237
|
+
clonedConnector.userData[key] = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Preserve the hardcoded UUID from the original connector
|
|
242
|
+
clonedConnector.userData.originalUuid = child.uuid;
|
|
243
|
+
console.log("\uD83D\uDD27 Preserved hardcoded UUID for connector ".concat(child.name, ": ").concat(child.uuid));
|
|
244
|
+
|
|
245
|
+
// Ensure forExport is explicitly set for connectors if not already present
|
|
246
|
+
if (clonedConnector.userData.forExport === undefined) {
|
|
247
|
+
clonedConnector.userData.forExport = true;
|
|
248
|
+
console.log("\uD83D\uDD27 Set forExport=true for preserved connector ".concat(child.name));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Ensure componentType is set for connectors
|
|
252
|
+
if (!clonedConnector.userData.componentType) {
|
|
253
|
+
if (child.name && child.name.toLowerCase().includes('connector')) {
|
|
254
|
+
clonedConnector.userData.componentType = 'connector';
|
|
255
|
+
} else if (child.name && child.name.toLowerCase().includes('gateway')) {
|
|
256
|
+
clonedConnector.userData.componentType = 'gateway';
|
|
257
|
+
}
|
|
258
|
+
console.log("\uD83D\uDD27 Set componentType for ".concat(child.name, ": ").concat(clonedConnector.userData.componentType));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
connectorChildren.push(clonedConnector);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
console.log('🔍 Stored mesh references before async loading:', {
|
|
265
|
+
uuid: originalUuid,
|
|
266
|
+
name: originalName,
|
|
267
|
+
libraryId: (_jsonEntry$userData2 = jsonEntry.userData) === null || _jsonEntry$userData2 === void 0 ? void 0 : _jsonEntry$userData2.libraryId,
|
|
268
|
+
modelKey: componentData.modelKey,
|
|
269
|
+
hasParent: !!originalParent,
|
|
270
|
+
parentType: (originalParent === null || originalParent === void 0 ? void 0 : originalParent.type) || 'null',
|
|
271
|
+
parentUuid: (originalParent === null || originalParent === void 0 ? void 0 : originalParent.uuid) || 'null'
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Try to get model from global preloader cache first with dimensions
|
|
275
|
+
gltfScene = modelPreloader["default"].getCachedModelWithDimensions(componentData.modelKey, (_jsonEntry$userData3 = jsonEntry.userData) === null || _jsonEntry$userData3 === void 0 ? void 0 : _jsonEntry$userData3.libraryId);
|
|
276
|
+
if (!gltfScene) {
|
|
277
|
+
_context.n = 2;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
console.log("\uD83C\uDFAF Using preloaded model from global cache for ".concat(componentData.modelKey));
|
|
281
|
+
_context.n = 8;
|
|
282
|
+
break;
|
|
283
|
+
case 2:
|
|
284
|
+
console.log("\u26A0\uFE0F Model ".concat(componentData.modelKey, " not found in preloader cache, checking preloading status..."));
|
|
285
|
+
|
|
286
|
+
// Check if preloading is still in progress
|
|
287
|
+
preloaderStatus = modelPreloader["default"].getStatus();
|
|
288
|
+
console.log("\uD83D\uDD0D Preloader status:", preloaderStatus);
|
|
289
|
+
|
|
290
|
+
// If preloading is still active, wait for it to complete
|
|
291
|
+
if (!preloaderStatus.isPreloading) {
|
|
292
|
+
_context.n = 6;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
console.log("\u23F3 Preloading still in progress, waiting for completion...");
|
|
296
|
+
_context.p = 3;
|
|
297
|
+
_context.n = 4;
|
|
298
|
+
return modelPreloader["default"].preloadingPromise;
|
|
299
|
+
case 4:
|
|
300
|
+
console.log("\u2705 Preloading completed, retrying cache lookup...");
|
|
301
|
+
|
|
302
|
+
// Try cache again after preloading completes with dimensions
|
|
303
|
+
gltfScene = modelPreloader["default"].getCachedModelWithDimensions(componentData.modelKey, (_jsonEntry$userData4 = jsonEntry.userData) === null || _jsonEntry$userData4 === void 0 ? void 0 : _jsonEntry$userData4.libraryId);
|
|
304
|
+
if (gltfScene) {
|
|
305
|
+
console.log("\uD83C\uDFAF Successfully retrieved ".concat(componentData.modelKey, " from cache after waiting"));
|
|
306
|
+
}
|
|
307
|
+
_context.n = 6;
|
|
308
|
+
break;
|
|
309
|
+
case 5:
|
|
310
|
+
_context.p = 5;
|
|
311
|
+
_t = _context.v;
|
|
312
|
+
console.warn("\u26A0\uFE0F Preloading failed:", _t);
|
|
313
|
+
case 6:
|
|
314
|
+
if (gltfScene) {
|
|
315
|
+
_context.n = 8;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
console.log("\u26A0\uFE0F Model ".concat(componentData.modelKey, " still not in cache, falling back to direct load"));
|
|
319
|
+
|
|
320
|
+
// Fallback to direct loading if not in preloader cache
|
|
321
|
+
_context.n = 7;
|
|
322
|
+
return new Promise(function (resolve, reject) {
|
|
323
|
+
component.gltfLoader.load("/library/models/".concat(componentData.modelKey), function (gltf) {
|
|
324
|
+
console.log("\u2705 GLB loaded directly: ".concat(componentData.modelKey));
|
|
325
|
+
resolve(gltf);
|
|
326
|
+
}, function (progress) {
|
|
327
|
+
return console.log("Loading ".concat(componentData.modelKey, ": ").concat((progress.loaded / progress.total * 100).toFixed(0), "%"));
|
|
328
|
+
}, function (error) {
|
|
329
|
+
console.error("\u274C GLB loading error for ".concat(componentData.modelKey, ":"), error);
|
|
330
|
+
reject(error);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
case 7:
|
|
334
|
+
gltf = _context.v;
|
|
335
|
+
gltfScene = gltf.scene;
|
|
336
|
+
|
|
337
|
+
// Add dimensions to the directly loaded model
|
|
338
|
+
if ((_jsonEntry$userData5 = jsonEntry.userData) !== null && _jsonEntry$userData5 !== void 0 && _jsonEntry$userData5.libraryId) {
|
|
339
|
+
gltfScene = modelPreloader["default"].addDimensionsToModel(gltfScene, jsonEntry.userData.libraryId);
|
|
340
|
+
}
|
|
341
|
+
case 8:
|
|
342
|
+
console.log("\u2705 ".concat((_jsonEntry$userData6 = jsonEntry.userData) === null || _jsonEntry$userData6 === void 0 ? void 0 : _jsonEntry$userData6.libraryId, " GLB model ready for use"));
|
|
343
|
+
|
|
344
|
+
// Clone the model for this instance (since getCachedModel already clones, we may not need to clone again)
|
|
345
|
+
libraryModel = gltfScene.isCachedClone ? gltfScene : gltfScene.clone(); // Apply same transform as the original mesh using stored values
|
|
346
|
+
libraryModel.uuid = originalUuid;
|
|
347
|
+
libraryModel.name = originalName;
|
|
348
|
+
libraryModel.quaternion.copy(originalQuaternion);
|
|
349
|
+
libraryModel.scale.copy(originalScale);
|
|
350
|
+
|
|
351
|
+
// Set userData with componentType for export filtering and hardcoded UUID preservation
|
|
352
|
+
if (!libraryModel.userData) {
|
|
353
|
+
libraryModel.userData = {};
|
|
354
|
+
}
|
|
355
|
+
libraryModel.userData.originalUuid = originalUuid; // Preserve hardcoded UUID
|
|
356
|
+
libraryModel.userData.componentType = 'component';
|
|
357
|
+
libraryModel.userData.libraryId = (_jsonEntry$userData7 = jsonEntry.userData) === null || _jsonEntry$userData7 === void 0 ? void 0 : _jsonEntry$userData7.libraryId;
|
|
358
|
+
|
|
359
|
+
// Add dimensions from component dictionary if available
|
|
360
|
+
if (componentData.boundingBox) {
|
|
361
|
+
libraryModel.userData.dimensions = {
|
|
362
|
+
x: componentData.boundingBox.x,
|
|
363
|
+
y: componentData.boundingBox.y,
|
|
364
|
+
z: componentData.boundingBox.z
|
|
365
|
+
};
|
|
366
|
+
console.log("\uD83D\uDCCF Added dimensions to GLB model userData for ".concat((_jsonEntry$userData8 = jsonEntry.userData) === null || _jsonEntry$userData8 === void 0 ? void 0 : _jsonEntry$userData8.libraryId, ":"), libraryModel.userData.dimensions);
|
|
367
|
+
}
|
|
368
|
+
if (componentData.adaptedBoundingBox) {
|
|
369
|
+
libraryModel.userData.adaptedBoundingBox = {
|
|
370
|
+
x: componentData.adaptedBoundingBox.x,
|
|
371
|
+
y: componentData.adaptedBoundingBox.y,
|
|
372
|
+
z: componentData.adaptedBoundingBox.z
|
|
373
|
+
};
|
|
374
|
+
console.log("\uD83D\uDCCF Added dimensions to GLB model userData for ".concat((_jsonEntry$userData9 = jsonEntry.userData) === null || _jsonEntry$userData9 === void 0 ? void 0 : _jsonEntry$userData9.libraryId, ":"), libraryModel.userData.adaptedBoundingBox);
|
|
375
|
+
}
|
|
376
|
+
console.log("\uD83D\uDD27 Set componentType to 'component' for ".concat((_jsonEntry$userData0 = jsonEntry.userData) === null || _jsonEntry$userData0 === void 0 ? void 0 : _jsonEntry$userData0.libraryId, " GLB model"));
|
|
377
|
+
|
|
378
|
+
// Apply explicit position and rotation from JSON data if available
|
|
379
|
+
if (jsonEntry.position && jsonEntry.rotation) {
|
|
380
|
+
console.log("\uD83D\uDD04 Applying ".concat((_jsonEntry$userData1 = jsonEntry.userData) === null || _jsonEntry$userData1 === void 0 ? void 0 : _jsonEntry$userData1.libraryId, " specific position and rotation from JSON"));
|
|
381
|
+
|
|
382
|
+
// Apply explicit position values from JSON
|
|
383
|
+
libraryModel.position.set(jsonEntry.position.x, jsonEntry.position.y, jsonEntry.position.z);
|
|
384
|
+
console.log("\u2705 Applied position from JSON: (".concat(jsonEntry.position.x, ", ").concat(jsonEntry.position.y, ", ").concat(jsonEntry.position.z, ")"));
|
|
385
|
+
libraryModel.rotation.set(THREE__namespace.MathUtils.degToRad(jsonEntry.rotation.x), THREE__namespace.MathUtils.degToRad(jsonEntry.rotation.y), THREE__namespace.MathUtils.degToRad(jsonEntry.rotation.z));
|
|
386
|
+
console.log("\u2705 Applied rotation from JSON: (".concat(jsonEntry.rotation.x, "\xB0, ").concat(jsonEntry.rotation.y, "\xB0, ").concat(jsonEntry.rotation.z, "\xB0)"));
|
|
387
|
+
} else {
|
|
388
|
+
// For objects without position/rotation in JSON, use the original position
|
|
389
|
+
libraryModel.position.copy(originalPosition);
|
|
390
|
+
console.log('⚠️ No position/rotation data in JSON, using original position only');
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Enable shadows for all meshes in the model
|
|
394
|
+
libraryModel.traverse(function (child) {
|
|
395
|
+
if (child.isMesh) {
|
|
396
|
+
child.castShadow = true;
|
|
397
|
+
child.receiveShadow = true;
|
|
398
|
+
|
|
399
|
+
// Apply similar material properties if needed
|
|
400
|
+
if (child.material) {
|
|
401
|
+
child.material.envMapIntensity = 1.0;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Add preserved connector children to the GLB model
|
|
407
|
+
connectorChildren.forEach(function (connector) {
|
|
408
|
+
var _connector$userData, _connector$userData2, _connector$userData3, _connector$userData4;
|
|
409
|
+
console.log("\uD83D\uDD34 Adding preserved connector to GLB model:", {
|
|
410
|
+
name: connector.name,
|
|
411
|
+
uuid: connector.uuid,
|
|
412
|
+
hasUserData: !!connector.userData,
|
|
413
|
+
userDataKeys: connector.userData ? Object.keys(connector.userData) : [],
|
|
414
|
+
hasWorldBoundingBox: !!((_connector$userData = connector.userData) !== null && _connector$userData !== void 0 && _connector$userData.worldBoundingBox),
|
|
415
|
+
hasDirection: !!((_connector$userData2 = connector.userData) !== null && _connector$userData2 !== void 0 && _connector$userData2.direction),
|
|
416
|
+
worldBoundingBox: (_connector$userData3 = connector.userData) === null || _connector$userData3 === void 0 ? void 0 : _connector$userData3.worldBoundingBox,
|
|
417
|
+
direction: (_connector$userData4 = connector.userData) === null || _connector$userData4 === void 0 ? void 0 : _connector$userData4.direction
|
|
418
|
+
});
|
|
419
|
+
libraryModel.add(connector);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// VERIFICATION: Check that all added connectors have pathfinder data
|
|
423
|
+
console.log("\uD83D\uDD0D VERIFICATION: Checking GLB model ".concat((_jsonEntry$userData10 = jsonEntry.userData) === null || _jsonEntry$userData10 === void 0 ? void 0 : _jsonEntry$userData10.libraryId, " connectors for pathfinder data:"));
|
|
424
|
+
libraryModel.children.forEach(function (child, index) {
|
|
425
|
+
if (child.name && child.name.toLowerCase().includes('connector')) {
|
|
426
|
+
var _child$userData5, _child$userData6, _child$userData7, _child$userData8, _child$userData9;
|
|
427
|
+
console.log(" Connector ".concat(index, " (").concat(child.name, "):"), {
|
|
428
|
+
hasUserData: !!child.userData,
|
|
429
|
+
hasWorldBoundingBox: !!((_child$userData5 = child.userData) !== null && _child$userData5 !== void 0 && _child$userData5.worldBoundingBox),
|
|
430
|
+
hasDirection: !!((_child$userData6 = child.userData) !== null && _child$userData6 !== void 0 && _child$userData6.direction),
|
|
431
|
+
worldBoundingBox: (_child$userData7 = child.userData) === null || _child$userData7 === void 0 ? void 0 : _child$userData7.worldBoundingBox,
|
|
432
|
+
direction: (_child$userData8 = child.userData) === null || _child$userData8 === void 0 ? void 0 : _child$userData8.direction,
|
|
433
|
+
pathfinderReady: !!((_child$userData9 = child.userData) !== null && _child$userData9 !== void 0 && _child$userData9.worldBoundingBox) // Key indicator for pathfinder
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// DEBUG: Log the structure of the GLB model for transform controls debugging
|
|
439
|
+
console.log("\uD83D\uDD0D GLB Model Structure for ".concat((_jsonEntry$userData11 = jsonEntry.userData) === null || _jsonEntry$userData11 === void 0 ? void 0 : _jsonEntry$userData11.libraryId, ":"), {
|
|
440
|
+
name: libraryModel.name,
|
|
441
|
+
type: libraryModel.type,
|
|
442
|
+
isMesh: libraryModel.isMesh,
|
|
443
|
+
isObject3D: libraryModel.isObject3D,
|
|
444
|
+
isGroup: libraryModel.isGroup,
|
|
445
|
+
childCount: libraryModel.children.length,
|
|
446
|
+
uuid: libraryModel.uuid
|
|
447
|
+
});
|
|
448
|
+
if (libraryModel.children.length > 0) {
|
|
449
|
+
console.log("\uD83D\uDD0D GLB Model children for ".concat((_jsonEntry$userData12 = jsonEntry.userData) === null || _jsonEntry$userData12 === void 0 ? void 0 : _jsonEntry$userData12.libraryId, ":"));
|
|
450
|
+
libraryModel.children.forEach(function (child, index) {
|
|
451
|
+
var _child$geometry4;
|
|
452
|
+
console.log(" Child ".concat(index, ":"), {
|
|
453
|
+
name: child.name,
|
|
454
|
+
type: child.type,
|
|
455
|
+
isMesh: child.isMesh,
|
|
456
|
+
isObject3D: child.isObject3D,
|
|
457
|
+
isGroup: child.isGroup,
|
|
458
|
+
hasGeometry: !!child.geometry,
|
|
459
|
+
geometryType: (_child$geometry4 = child.geometry) === null || _child$geometry4 === void 0 ? void 0 : _child$geometry4.type,
|
|
460
|
+
visible: child.visible
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Remove the original simple mesh and add the detailed GLB model
|
|
466
|
+
// Use stored parent reference instead of current targetMesh.parent
|
|
467
|
+
if (originalParent && originalParent.add && typeof originalParent.add === 'function') {
|
|
468
|
+
console.log('🔄 Replacing mesh in stored parent:', originalParent.type || 'Unknown');
|
|
469
|
+
originalParent.remove(targetMesh);
|
|
470
|
+
originalParent.add(libraryModel);
|
|
471
|
+
} else {
|
|
472
|
+
console.log('🔄 Replacing mesh directly in scene (no valid parent found)');
|
|
473
|
+
component.scene.remove(targetMesh);
|
|
474
|
+
component.scene.add(libraryModel);
|
|
475
|
+
}
|
|
476
|
+
console.log("\uD83C\uDF89 ".concat((_jsonEntry$userData13 = jsonEntry.userData) === null || _jsonEntry$userData13 === void 0 ? void 0 : _jsonEntry$userData13.libraryId, " GLB model successfully rendered in scene"));
|
|
477
|
+
return _context.a(2, libraryModel);
|
|
478
|
+
case 9:
|
|
479
|
+
_context.p = 9;
|
|
480
|
+
_t2 = _context.v;
|
|
481
|
+
console.error("\u274C Error loading ".concat((_jsonEntry$userData14 = jsonEntry.userData) === null || _jsonEntry$userData14 === void 0 ? void 0 : _jsonEntry$userData14.libraryId, " GLB model:"), _t2);
|
|
482
|
+
console.log('⚠️ Keeping original mesh as fallback');
|
|
483
|
+
return _context.a(2, targetMesh);
|
|
484
|
+
}
|
|
485
|
+
}, _callee, this, [[3, 5], [1, 9]]);
|
|
486
|
+
}));
|
|
487
|
+
function loadLibraryModel(_x, _x2, _x3) {
|
|
488
|
+
return _loadLibraryModel.apply(this, arguments);
|
|
489
|
+
}
|
|
490
|
+
return loadLibraryModel;
|
|
491
|
+
}()
|
|
492
|
+
/**
|
|
493
|
+
* Helper function to verify model preloader cache
|
|
494
|
+
*/
|
|
495
|
+
)
|
|
496
|
+
}, {
|
|
497
|
+
key: "verifyModelPreloaderCache",
|
|
498
|
+
value: (function () {
|
|
499
|
+
var _verifyModelPreloaderCache = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2() {
|
|
500
|
+
var preloaderStatus, _t3;
|
|
501
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
|
|
502
|
+
while (1) switch (_context2.n) {
|
|
503
|
+
case 0:
|
|
504
|
+
console.log('🔍 Verifying model preloader cache state...');
|
|
505
|
+
preloaderStatus = modelPreloader["default"].getStatus();
|
|
506
|
+
console.log('📊 Current preloader status:', preloaderStatus);
|
|
507
|
+
|
|
508
|
+
// If preloading is still in progress, wait for completion
|
|
509
|
+
if (!preloaderStatus.isPreloading) {
|
|
510
|
+
_context2.n = 4;
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
console.log('⏳ Waiting for model preloading to complete...');
|
|
514
|
+
_context2.p = 1;
|
|
515
|
+
_context2.n = 2;
|
|
516
|
+
return modelPreloader["default"].preloadingPromise;
|
|
517
|
+
case 2:
|
|
518
|
+
console.log('✅ Model preloading completed');
|
|
519
|
+
_context2.n = 4;
|
|
520
|
+
break;
|
|
521
|
+
case 3:
|
|
522
|
+
_context2.p = 3;
|
|
523
|
+
_t3 = _context2.v;
|
|
524
|
+
console.warn('⚠️ Model preloading failed, some models may load directly:', _t3);
|
|
525
|
+
case 4:
|
|
526
|
+
return _context2.a(2, preloaderStatus);
|
|
527
|
+
}
|
|
528
|
+
}, _callee2, null, [[1, 3]]);
|
|
529
|
+
}));
|
|
530
|
+
function verifyModelPreloaderCache() {
|
|
531
|
+
return _verifyModelPreloaderCache.apply(this, arguments);
|
|
532
|
+
}
|
|
533
|
+
return verifyModelPreloaderCache;
|
|
534
|
+
}()
|
|
535
|
+
/**
|
|
536
|
+
* Helper function to preload missing models for a scene
|
|
537
|
+
*/
|
|
538
|
+
)
|
|
539
|
+
}, {
|
|
540
|
+
key: "preloadMissingModels",
|
|
541
|
+
value: (function () {
|
|
542
|
+
var _preloadMissingModels = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3(data, componentDictionary) {
|
|
543
|
+
var requiredModels, preloaderStatus, cachedModels, missingModels, _iterator, _step, modelKey, _t4, _t5;
|
|
544
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
|
|
545
|
+
while (1) switch (_context3.n) {
|
|
546
|
+
case 0:
|
|
547
|
+
requiredModels = new Set();
|
|
548
|
+
data.scene.object.children.forEach(function (child) {
|
|
549
|
+
var _child$userData0, _child$userData1;
|
|
550
|
+
if ((_child$userData0 = child.userData) !== null && _child$userData0 !== void 0 && _child$userData0.libraryId && componentDictionary[(_child$userData1 = child.userData) === null || _child$userData1 === void 0 ? void 0 : _child$userData1.libraryId]) {
|
|
551
|
+
var _child$userData10;
|
|
552
|
+
var modelKey = componentDictionary[(_child$userData10 = child.userData) === null || _child$userData10 === void 0 ? void 0 : _child$userData10.libraryId].modelKey;
|
|
553
|
+
if (modelKey) {
|
|
554
|
+
requiredModels.add(modelKey);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
console.log('🔍 Required models for this scene:', Array.from(requiredModels));
|
|
559
|
+
_context3.n = 1;
|
|
560
|
+
return this.verifyModelPreloaderCache();
|
|
561
|
+
case 1:
|
|
562
|
+
preloaderStatus = _context3.v;
|
|
563
|
+
cachedModels = preloaderStatus.cachedModels;
|
|
564
|
+
missingModels = Array.from(requiredModels).filter(function (model) {
|
|
565
|
+
return !cachedModels.includes(model);
|
|
566
|
+
});
|
|
567
|
+
if (!(missingModels.length > 0)) {
|
|
568
|
+
_context3.n = 11;
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
console.warn('⚠️ Some required models are not cached:', missingModels);
|
|
572
|
+
console.log('🔄 Attempting to preload missing models...');
|
|
573
|
+
|
|
574
|
+
// Preload missing models
|
|
575
|
+
_iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(missingModels);
|
|
576
|
+
_context3.p = 2;
|
|
577
|
+
_iterator.s();
|
|
578
|
+
case 3:
|
|
579
|
+
if ((_step = _iterator.n()).done) {
|
|
580
|
+
_context3.n = 8;
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
modelKey = _step.value;
|
|
584
|
+
_context3.p = 4;
|
|
585
|
+
_context3.n = 5;
|
|
586
|
+
return modelPreloader["default"].preloadSingleModel(modelKey);
|
|
587
|
+
case 5:
|
|
588
|
+
console.log("\u2705 Successfully preloaded missing model: ".concat(modelKey));
|
|
589
|
+
_context3.n = 7;
|
|
590
|
+
break;
|
|
591
|
+
case 6:
|
|
592
|
+
_context3.p = 6;
|
|
593
|
+
_t4 = _context3.v;
|
|
594
|
+
console.warn("\u274C Failed to preload missing model ".concat(modelKey, ":"), _t4);
|
|
595
|
+
case 7:
|
|
596
|
+
_context3.n = 3;
|
|
597
|
+
break;
|
|
598
|
+
case 8:
|
|
599
|
+
_context3.n = 10;
|
|
600
|
+
break;
|
|
601
|
+
case 9:
|
|
602
|
+
_context3.p = 9;
|
|
603
|
+
_t5 = _context3.v;
|
|
604
|
+
_iterator.e(_t5);
|
|
605
|
+
case 10:
|
|
606
|
+
_context3.p = 10;
|
|
607
|
+
_iterator.f();
|
|
608
|
+
return _context3.f(10);
|
|
609
|
+
case 11:
|
|
610
|
+
return _context3.a(2);
|
|
611
|
+
}
|
|
612
|
+
}, _callee3, this, [[4, 6], [2, 9, 10, 11]]);
|
|
613
|
+
}));
|
|
614
|
+
function preloadMissingModels(_x4, _x5) {
|
|
615
|
+
return _preloadMissingModels.apply(this, arguments);
|
|
616
|
+
}
|
|
617
|
+
return preloadMissingModels;
|
|
618
|
+
}()
|
|
619
|
+
/**
|
|
620
|
+
* Helper function to create materials with texture sets
|
|
621
|
+
*/
|
|
622
|
+
)
|
|
623
|
+
}, {
|
|
624
|
+
key: "createSceneMaterials",
|
|
625
|
+
value: (function () {
|
|
626
|
+
var _createSceneMaterials = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee4(data) {
|
|
627
|
+
var component, materials, crosscubeTextureSet, _t6, _t7;
|
|
628
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context4) {
|
|
629
|
+
while (1) switch (_context4.n) {
|
|
630
|
+
case 0:
|
|
631
|
+
component = this.sceneViewer;
|
|
632
|
+
materials = {}; // Load texture set for crosscube materials
|
|
633
|
+
crosscubeTextureSet = null;
|
|
634
|
+
_context4.p = 1;
|
|
635
|
+
_context4.n = 2;
|
|
636
|
+
return textureConfig.loadTextureSet('light_metal', component.textureLoader);
|
|
637
|
+
case 2:
|
|
638
|
+
crosscubeTextureSet = _context4.v;
|
|
639
|
+
console.log('Successfully loaded light metallic texture set');
|
|
640
|
+
_context4.n = 7;
|
|
641
|
+
break;
|
|
642
|
+
case 3:
|
|
643
|
+
_context4.p = 3;
|
|
644
|
+
_t6 = _context4.v;
|
|
645
|
+
console.warn('Could not load metallic texture, trying fallback:', _t6);
|
|
646
|
+
_context4.p = 4;
|
|
647
|
+
_context4.n = 5;
|
|
648
|
+
return textureConfig.loadTextureSet('gravel_embedded_concrete', component.textureLoader);
|
|
649
|
+
case 5:
|
|
650
|
+
crosscubeTextureSet = _context4.v;
|
|
651
|
+
console.log('Using fallback texture set');
|
|
652
|
+
_context4.n = 7;
|
|
653
|
+
break;
|
|
654
|
+
case 6:
|
|
655
|
+
_context4.p = 6;
|
|
656
|
+
_t7 = _context4.v;
|
|
657
|
+
console.warn('Could not load any texture set, using plain materials:', _t7);
|
|
658
|
+
case 7:
|
|
659
|
+
return _context4.a(2, {
|
|
660
|
+
materials: materials,
|
|
661
|
+
crosscubeTextureSet: crosscubeTextureSet
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}, _callee4, this, [[4, 6], [1, 3]]);
|
|
665
|
+
}));
|
|
666
|
+
function createSceneMaterials(_x6) {
|
|
667
|
+
return _createSceneMaterials.apply(this, arguments);
|
|
668
|
+
}
|
|
669
|
+
return createSceneMaterials;
|
|
670
|
+
}()
|
|
671
|
+
/**
|
|
672
|
+
* Helper function to create geometries from component library
|
|
673
|
+
*/
|
|
674
|
+
)
|
|
675
|
+
}, {
|
|
676
|
+
key: "createSceneGeometries",
|
|
677
|
+
value: function createSceneGeometries(data, componentDictionary) {
|
|
678
|
+
var geometries = {};
|
|
679
|
+
|
|
680
|
+
// Create geometries based on component library bounding boxes instead of JSON scene.geometries
|
|
681
|
+
data.scene.object.children.forEach(function (child) {
|
|
682
|
+
var _child$userData11;
|
|
683
|
+
if ((_child$userData11 = child.userData) !== null && _child$userData11 !== void 0 && _child$userData11.libraryId && componentDictionary[child.userData.libraryId]) {
|
|
684
|
+
var component = componentDictionary[child.userData.libraryId];
|
|
685
|
+
var boundingBox = component.boundingBox;
|
|
686
|
+
|
|
687
|
+
// Create a box geometry based on the component's bounding box
|
|
688
|
+
var geometry = new THREE__namespace.BoxGeometry(boundingBox.x || 1, boundingBox.y || 1, boundingBox.z || 1);
|
|
689
|
+
|
|
690
|
+
// Use the child's geometry UUID as the key
|
|
691
|
+
geometries[child.geometry] = geometry;
|
|
692
|
+
console.log("\uD83D\uDCE6 Created placeholder geometry for ".concat(child.userData.libraryId, ":"), boundingBox);
|
|
693
|
+
} else {
|
|
694
|
+
// For non-library objects (connectors, gateways), create shared sphere geometry
|
|
695
|
+
var isConnectorOrGateway = child.uuid && (child.uuid.toLowerCase().includes('connector') || child.uuid.toLowerCase().includes('gateway'));
|
|
696
|
+
if (isConnectorOrGateway) {
|
|
697
|
+
geometries[child.geometry] = new THREE__namespace.SphereGeometry(0.1, 16, 16);
|
|
698
|
+
} else {
|
|
699
|
+
// Default fallback geometry
|
|
700
|
+
geometries[child.geometry] = new THREE__namespace.BoxGeometry(1, 1, 1);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
return geometries;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Helper function to create object from scene data
|
|
709
|
+
*/
|
|
710
|
+
}, {
|
|
711
|
+
key: "createSceneObject",
|
|
712
|
+
value: function createSceneObject(obj, geometries, materials) {
|
|
713
|
+
var _this = this;
|
|
714
|
+
// Get geometry from our generated geometries
|
|
715
|
+
var geometry = geometries[obj.geometry];
|
|
716
|
+
|
|
717
|
+
// Create a default material if none exists for this object
|
|
718
|
+
var material = materials[obj.material];
|
|
719
|
+
if (!material) {
|
|
720
|
+
material = new THREE__namespace.MeshPhysicalMaterial({
|
|
721
|
+
color: 0xC0C0C0,
|
|
722
|
+
roughness: 0.15,
|
|
723
|
+
metalness: 0.9,
|
|
724
|
+
emissive: 0x000000,
|
|
725
|
+
envMapIntensity: 1.5,
|
|
726
|
+
transparent: true,
|
|
727
|
+
opacity: 0.8
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
var mesh = new THREE__namespace.Mesh(geometry, material);
|
|
731
|
+
|
|
732
|
+
// ALWAYS use the hardcoded UUID from JSON, never let Three.js auto-generate
|
|
733
|
+
mesh.uuid = obj.uuid;
|
|
734
|
+
mesh.name = obj.name || obj.uuid; // Prefer original name, fallback to UUID
|
|
735
|
+
|
|
736
|
+
// Store the original hardcoded UUID in userData for reference
|
|
737
|
+
if (!mesh.userData) mesh.userData = {};
|
|
738
|
+
mesh.userData.originalUuid = obj.uuid;
|
|
739
|
+
|
|
740
|
+
// Copy userData from JSON object to Three.js mesh
|
|
741
|
+
if (obj.userData) {
|
|
742
|
+
mesh.userData = _rollupPluginBabelHelpers.objectSpread2({}, obj.userData);
|
|
743
|
+
// Ensure componentType is set if missing (backward compatibility)
|
|
744
|
+
if (!mesh.userData.componentType) {
|
|
745
|
+
if (mesh.userData.libraryId) {
|
|
746
|
+
mesh.userData.componentType = 'component';
|
|
747
|
+
} else if (obj.uuid && obj.uuid.toLowerCase().includes('connector')) {
|
|
748
|
+
mesh.userData.componentType = 'connector';
|
|
749
|
+
} else if (obj.uuid && obj.uuid.toLowerCase().includes('gateway')) {
|
|
750
|
+
mesh.userData.componentType = 'gateway';
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
if (mesh.isMesh) {
|
|
755
|
+
mesh.castShadow = true;
|
|
756
|
+
mesh.receiveShadow = true;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// Use direct position, rotation, and scale attributes instead of matrix
|
|
760
|
+
if (obj.position) {
|
|
761
|
+
mesh.position.set(obj.position.x || 0, obj.position.y || 0, obj.position.z || 0);
|
|
762
|
+
}
|
|
763
|
+
if (obj.rotation) {
|
|
764
|
+
// Convert degrees to radians if rotation values are in degrees (common in JSON exports)
|
|
765
|
+
var rotX = obj.rotation.x * (Math.PI / 180);
|
|
766
|
+
var rotY = obj.rotation.y * (Math.PI / 180);
|
|
767
|
+
var rotZ = obj.rotation.z * (Math.PI / 180);
|
|
768
|
+
mesh.rotation.set(rotX, rotY, rotZ);
|
|
769
|
+
}
|
|
770
|
+
if (obj.scale) {
|
|
771
|
+
mesh.scale.set(obj.scale.x || 1, obj.scale.y || 1, obj.scale.z || 1);
|
|
772
|
+
}
|
|
773
|
+
if (obj.children) {
|
|
774
|
+
obj.children.forEach(function (child) {
|
|
775
|
+
mesh.add(_this.createSceneObject(child, geometries, materials));
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
return mesh;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Helper function to compute world bounding boxes
|
|
783
|
+
*/
|
|
784
|
+
}, {
|
|
785
|
+
key: "computeWorldBoundingBoxes",
|
|
786
|
+
value: function computeWorldBoundingBoxes(data) {
|
|
787
|
+
var component = this.sceneViewer;
|
|
788
|
+
component.scene.traverse(function (object) {
|
|
789
|
+
if (object.isMesh) {
|
|
790
|
+
// Find the corresponding JSON object
|
|
791
|
+
var jsonObject = null;
|
|
792
|
+
var _findJsonObject = function findJsonObject(children) {
|
|
793
|
+
var _iterator2 = _rollupPluginBabelHelpers.createForOfIteratorHelper(children),
|
|
794
|
+
_step2;
|
|
795
|
+
try {
|
|
796
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
797
|
+
var _object$userData, _child$userData12;
|
|
798
|
+
var child = _step2.value;
|
|
799
|
+
// Enhanced matching logic with hardcoded UUID priority
|
|
800
|
+
|
|
801
|
+
// Strategy 1: Direct hardcoded UUID match (HIGHEST PRIORITY)
|
|
802
|
+
if (child.uuid === object.uuid || child.uuid === ((_object$userData = object.userData) === null || _object$userData === void 0 ? void 0 : _object$userData.originalUuid) || object.uuid === ((_child$userData12 = child.userData) === null || _child$userData12 === void 0 ? void 0 : _child$userData12.originalUuid)) {
|
|
803
|
+
return child;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Recursively search children
|
|
807
|
+
if (child.children) {
|
|
808
|
+
var found = _findJsonObject(child.children);
|
|
809
|
+
if (found) return found;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
} catch (err) {
|
|
813
|
+
_iterator2.e(err);
|
|
814
|
+
} finally {
|
|
815
|
+
_iterator2.f();
|
|
816
|
+
}
|
|
817
|
+
return null;
|
|
818
|
+
};
|
|
819
|
+
jsonObject = _findJsonObject(data.scene.object.children);
|
|
820
|
+
if (jsonObject) {
|
|
821
|
+
// Compute world bounding box
|
|
822
|
+
var boundingBox = new THREE__namespace.Box3().setFromObject(object);
|
|
823
|
+
|
|
824
|
+
// Store in JSON userData for pathfinder
|
|
825
|
+
if (!jsonObject.userData) jsonObject.userData = {};
|
|
826
|
+
jsonObject.userData.worldBoundingBox = {
|
|
827
|
+
min: boundingBox.min.toArray(),
|
|
828
|
+
max: boundingBox.max.toArray()
|
|
829
|
+
};
|
|
830
|
+
console.log("Added world bounding box:", jsonObject.userData.worldBoundingBox);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Consolidated scene loading function
|
|
838
|
+
*/
|
|
839
|
+
}, {
|
|
840
|
+
key: "loadSceneData",
|
|
841
|
+
value: (function () {
|
|
842
|
+
var _loadSceneData = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee5(data) {
|
|
843
|
+
var _this2 = this;
|
|
844
|
+
var isImported,
|
|
845
|
+
component,
|
|
846
|
+
saveOriginalWorldMatrix,
|
|
847
|
+
componentDictionary,
|
|
848
|
+
dictResponse,
|
|
849
|
+
_yield$this$createSce,
|
|
850
|
+
materials,
|
|
851
|
+
crosscubeTextureSet,
|
|
852
|
+
geometries,
|
|
853
|
+
libraryObjectsToReplace,
|
|
854
|
+
glbLoadingPromises,
|
|
855
|
+
sceneCompleteEvent,
|
|
856
|
+
_args5 = arguments,
|
|
857
|
+
_t8,
|
|
858
|
+
_t9;
|
|
859
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context5) {
|
|
860
|
+
while (1) switch (_context5.n) {
|
|
861
|
+
case 0:
|
|
862
|
+
isImported = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : true;
|
|
863
|
+
component = this.sceneViewer; // TODO: Loading scene should awlays clear the scene first
|
|
864
|
+
_context5.p = 1;
|
|
865
|
+
saveOriginalWorldMatrix = function saveOriginalWorldMatrix(scene) {
|
|
866
|
+
scene.traverse(function (object) {
|
|
867
|
+
if (object.userData && object.userData.direction) {
|
|
868
|
+
// Create a new matrix to store the original world matrix
|
|
869
|
+
var originalMatrix = new THREE__namespace.Matrix4();
|
|
870
|
+
originalMatrix.copy(object.matrixWorld);
|
|
871
|
+
|
|
872
|
+
// Store in userData
|
|
873
|
+
object.userData.worldMatrixOriginal = originalMatrix.elements;
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
};
|
|
877
|
+
console.log("Loading scene data (".concat(isImported ? 'imported' : 'default', ")..."));
|
|
878
|
+
|
|
879
|
+
// Manage transform controls for imported scenes
|
|
880
|
+
if (isImported) {
|
|
881
|
+
if (component.transformManager && component.transformManager.transformControls) {
|
|
882
|
+
console.log('🔒 Preemptively disabling transform controls during scene load');
|
|
883
|
+
// component.keepTransformControlsInactive()
|
|
884
|
+
}
|
|
885
|
+
this.clearSceneObjects();
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// Store current scene data
|
|
889
|
+
component.currentSceneData = data;
|
|
890
|
+
|
|
891
|
+
// Load component dictionary for GLB model lookup
|
|
892
|
+
componentDictionary = {};
|
|
893
|
+
_context5.p = 2;
|
|
894
|
+
_context5.n = 3;
|
|
895
|
+
return fetch('./library/component-dictionary.json');
|
|
896
|
+
case 3:
|
|
897
|
+
dictResponse = _context5.v;
|
|
898
|
+
_context5.n = 4;
|
|
899
|
+
return dictResponse.json();
|
|
900
|
+
case 4:
|
|
901
|
+
componentDictionary = _context5.v;
|
|
902
|
+
console.log('✅ Component dictionary loaded:', componentDictionary);
|
|
903
|
+
_context5.n = 6;
|
|
904
|
+
break;
|
|
905
|
+
case 5:
|
|
906
|
+
_context5.p = 5;
|
|
907
|
+
_t8 = _context5.v;
|
|
908
|
+
console.warn('⚠️ Could not load component dictionary:', _t8);
|
|
909
|
+
case 6:
|
|
910
|
+
_context5.n = 7;
|
|
911
|
+
return this.preloadMissingModels(data, componentDictionary);
|
|
912
|
+
case 7:
|
|
913
|
+
_context5.n = 8;
|
|
914
|
+
return this.createSceneMaterials(data);
|
|
915
|
+
case 8:
|
|
916
|
+
_yield$this$createSce = _context5.v;
|
|
917
|
+
materials = _yield$this$createSce.materials;
|
|
918
|
+
crosscubeTextureSet = _yield$this$createSce.crosscubeTextureSet;
|
|
919
|
+
// Create geometries from component library instead of scene.geometries
|
|
920
|
+
geometries = this.createSceneGeometries(data, componentDictionary); // PHASE 1: Add basic scene objects first (for pathfinding)
|
|
921
|
+
console.log('🔍 PHASE 1: Creating basic scene objects for pathfinding. Total children:', data.scene.object.children.length);
|
|
922
|
+
libraryObjectsToReplace = [];
|
|
923
|
+
data.scene.object.children.forEach(function (child, index) {
|
|
924
|
+
var _child$userData13, _child$userData14;
|
|
925
|
+
console.log("\uD83D\uDD0D Processing child ".concat(index, ":"), child.uuid);
|
|
926
|
+
var createdObject = _this2.createSceneObject(child, geometries, materials);
|
|
927
|
+
component.scene.add(createdObject);
|
|
928
|
+
|
|
929
|
+
// Track objects that need GLB model replacement for later
|
|
930
|
+
if ((_child$userData13 = child.userData) !== null && _child$userData13 !== void 0 && _child$userData13.libraryId && componentDictionary[(_child$userData14 = child.userData) === null || _child$userData14 === void 0 ? void 0 : _child$userData14.libraryId]) {
|
|
931
|
+
var _child$userData15, _child$userData16;
|
|
932
|
+
console.log("\uD83D\uDCDD Marked ".concat((_child$userData15 = child.userData) === null || _child$userData15 === void 0 ? void 0 : _child$userData15.libraryId, " for GLB replacement after pathfinding"));
|
|
933
|
+
libraryObjectsToReplace.push({
|
|
934
|
+
basicObject: createdObject,
|
|
935
|
+
jsonData: child,
|
|
936
|
+
componentData: componentDictionary[(_child$userData16 = child.userData) === null || _child$userData16 === void 0 ? void 0 : _child$userData16.libraryId]
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
// PHASE 2: Compute world bounding boxes on basic objects
|
|
942
|
+
console.log('🔍 PHASE 2: Computing bounding boxes on basic objects for pathfinding');
|
|
943
|
+
this.computeWorldBoundingBoxes(data);
|
|
944
|
+
saveOriginalWorldMatrix(component.scene);
|
|
945
|
+
|
|
946
|
+
// PHASE 4: Now replace basic objects with detailed GLB models
|
|
947
|
+
console.log('🔍 PHASE 4: Starting GLB model replacements after pathfinding');
|
|
948
|
+
glbLoadingPromises = [];
|
|
949
|
+
libraryObjectsToReplace.forEach(function (_ref, index) {
|
|
950
|
+
var _jsonData$userData;
|
|
951
|
+
var basicObject = _ref.basicObject,
|
|
952
|
+
jsonData = _ref.jsonData,
|
|
953
|
+
componentData = _ref.componentData;
|
|
954
|
+
console.log("\uD83C\uDFAF Starting GLB model replacement for ".concat((_jsonData$userData = jsonData.userData) === null || _jsonData$userData === void 0 ? void 0 : _jsonData$userData.libraryId, "..."));
|
|
955
|
+
var glbPromise = _this2.loadLibraryModel(basicObject, jsonData, componentData).then(function (libraryModel) {
|
|
956
|
+
var _jsonData$userData2;
|
|
957
|
+
console.log("\uD83D\uDEB0 ".concat((_jsonData$userData2 = jsonData.userData) === null || _jsonData$userData2 === void 0 ? void 0 : _jsonData$userData2.libraryId, " GLB model successfully replaced"));
|
|
958
|
+
libraryObjectsToReplace[index].glbModel = libraryModel;
|
|
959
|
+
return libraryModel;
|
|
960
|
+
}).catch(function (error) {
|
|
961
|
+
var _jsonData$userData3;
|
|
962
|
+
console.error("Failed to load ".concat((_jsonData$userData3 = jsonData.userData) === null || _jsonData$userData3 === void 0 ? void 0 : _jsonData$userData3.libraryId, " GLB model:"), error);
|
|
963
|
+
return basicObject; // Return original object as fallback
|
|
964
|
+
});
|
|
965
|
+
glbLoadingPromises.push(glbPromise);
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
// Wait for all GLB models to load
|
|
969
|
+
if (!(glbLoadingPromises.length > 0)) {
|
|
970
|
+
_context5.n = 10;
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
console.log("\u23F3 Waiting for ".concat(glbLoadingPromises.length, " GLB models to load..."));
|
|
974
|
+
_context5.n = 9;
|
|
975
|
+
return Promise.all(glbLoadingPromises);
|
|
976
|
+
case 9:
|
|
977
|
+
console.log('✅ All GLB models loaded after pathfinding');
|
|
978
|
+
if (typeof window !== 'undefined') {
|
|
979
|
+
// Also dispatch a general scene initialization complete event
|
|
980
|
+
console.log('📡 Dispatching sceneUpdateComplete event');
|
|
981
|
+
sceneCompleteEvent = new CustomEvent('sceneUpdateComplete', {
|
|
982
|
+
detail: {
|
|
983
|
+
timestamp: Date.now()
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
window.dispatchEvent(sceneCompleteEvent);
|
|
987
|
+
}
|
|
988
|
+
case 10:
|
|
989
|
+
console.log('Scene loaded successfully');
|
|
990
|
+
console.log('[loadSceneData] Scene loaded successfully', component.scene);
|
|
991
|
+
libraryObjectsToReplace.forEach(function (_ref2, index) {
|
|
992
|
+
var basicObject = _ref2.basicObject,
|
|
993
|
+
jsonData = _ref2.jsonData,
|
|
994
|
+
componentData = _ref2.componentData,
|
|
995
|
+
glbModel = _ref2.glbModel;
|
|
996
|
+
// Display name
|
|
997
|
+
console.log('[loadSceneData] name', jsonData.uuid);
|
|
998
|
+
console.log('[loadSceneData] basicObject', basicObject);
|
|
999
|
+
console.log('[loadSceneData] jsonData', jsonData);
|
|
1000
|
+
console.log('[loadSceneData] componentData', componentData);
|
|
1001
|
+
console.log('[loadSceneData] glbModel', glbModel);
|
|
1002
|
+
glbModel.userData.associatedJsonObject = jsonData;
|
|
1003
|
+
|
|
1004
|
+
// Build worldBoundingBox from glbModel
|
|
1005
|
+
var worldBoundingBox = new THREE__namespace.Box3().setFromObject(glbModel);
|
|
1006
|
+
console.log('[loadSceneData] worldBoundingBox', worldBoundingBox);
|
|
1007
|
+
jsonData.type = 'Mesh';
|
|
1008
|
+
|
|
1009
|
+
// Update jsonData.userData.worldBoundingBox as array of numbers
|
|
1010
|
+
jsonData.userData.worldBoundingBox.min = worldBoundingBox.min.toArray();
|
|
1011
|
+
jsonData.userData.worldBoundingBox.max = worldBoundingBox.max.toArray();
|
|
1012
|
+
});
|
|
1013
|
+
console.log('[loadSceneData] data', data);
|
|
1014
|
+
|
|
1015
|
+
// Add ground to the data
|
|
1016
|
+
data.scene.object.children.push({
|
|
1017
|
+
uuid: "GROUND",
|
|
1018
|
+
type: "Mesh",
|
|
1019
|
+
name: "Ground",
|
|
1020
|
+
layers: 1,
|
|
1021
|
+
matrix: [1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, -0.01, 0, 1],
|
|
1022
|
+
up: [0, 1, 0],
|
|
1023
|
+
userData: {
|
|
1024
|
+
worldBoundingBox: {
|
|
1025
|
+
min: [-30, -0.01, -30],
|
|
1026
|
+
max: [30, -0.01, 30]
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
// PHASE 3: Initialize pathfinder and create paths BEFORE loading GLB models
|
|
1032
|
+
console.log('🔍 PHASE 3: Running pathfinder on basic scene geometry');
|
|
1033
|
+
|
|
1034
|
+
// Use pathfinding manager to handle pathfinding logic
|
|
1035
|
+
if (!component.pathfindingManager) {
|
|
1036
|
+
_context5.n = 11;
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
_context5.n = 11;
|
|
1040
|
+
return component.pathfindingManager.initializePathfinder(data, crosscubeTextureSet);
|
|
1041
|
+
case 11:
|
|
1042
|
+
console.log('✅ Pathfinding completed, pipes created');
|
|
1043
|
+
component.currentSceneData = data;
|
|
1044
|
+
component.crosscubeTextureSet = crosscubeTextureSet;
|
|
1045
|
+
|
|
1046
|
+
// Handle transform controls for imported scenes
|
|
1047
|
+
if (isImported) {
|
|
1048
|
+
// Ensure transform controls are properly initialized after scene load
|
|
1049
|
+
if (!component.transformManager || !component.transformManager.transformControls) {
|
|
1050
|
+
console.log('🔧 Re-initializing transform controls after scene load');
|
|
1051
|
+
component.initTransformControls();
|
|
1052
|
+
} else {
|
|
1053
|
+
// Keep transform controls invisible
|
|
1054
|
+
if (component.transformManager.transformControls) {
|
|
1055
|
+
component.transformManager.transformControls.visible = false;
|
|
1056
|
+
console.log('🔧 Making transform controls invisible after scene load');
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// Ensure transform controls are still properly attached to the scene after import
|
|
1061
|
+
component.ensureTransformControlsAttached(false);
|
|
1062
|
+
|
|
1063
|
+
// Keep transform controls inactive after loading scene data
|
|
1064
|
+
if (component.transformManager && component.transformManager.transformControls) {
|
|
1065
|
+
console.log('🔧 Keeping transform controls inactive after scene data load');
|
|
1066
|
+
component.keepTransformControlsInactive();
|
|
1067
|
+
component.transformManager.transformControls.visible = false;
|
|
1068
|
+
console.log('🔒 Final verification: transform controls visibility forced to false');
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
_context5.n = 13;
|
|
1072
|
+
break;
|
|
1073
|
+
case 12:
|
|
1074
|
+
_context5.p = 12;
|
|
1075
|
+
_t9 = _context5.v;
|
|
1076
|
+
console.error('Error loading scene data:', _t9);
|
|
1077
|
+
case 13:
|
|
1078
|
+
return _context5.a(2);
|
|
1079
|
+
}
|
|
1080
|
+
}, _callee5, this, [[2, 5], [1, 12]]);
|
|
1081
|
+
}));
|
|
1082
|
+
function loadSceneData(_x7) {
|
|
1083
|
+
return _loadSceneData.apply(this, arguments);
|
|
1084
|
+
}
|
|
1085
|
+
return loadSceneData;
|
|
1086
|
+
}()
|
|
1087
|
+
/**
|
|
1088
|
+
* Load default scene
|
|
1089
|
+
*/
|
|
1090
|
+
)
|
|
1091
|
+
}, {
|
|
1092
|
+
key: "loadScene",
|
|
1093
|
+
value: (function () {
|
|
1094
|
+
var _loadScene = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee6() {
|
|
1095
|
+
var component, defaultCentralPlantUrl, response, data, _t0;
|
|
1096
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context6) {
|
|
1097
|
+
while (1) switch (_context6.n) {
|
|
1098
|
+
case 0:
|
|
1099
|
+
component = this.sceneViewer;
|
|
1100
|
+
_context6.p = 1;
|
|
1101
|
+
defaultCentralPlantUrl = component.$config.defaultCentralPlantUrl;
|
|
1102
|
+
_context6.n = 2;
|
|
1103
|
+
return fetch(defaultCentralPlantUrl);
|
|
1104
|
+
case 2:
|
|
1105
|
+
response = _context6.v;
|
|
1106
|
+
_context6.n = 3;
|
|
1107
|
+
return response.json();
|
|
1108
|
+
case 3:
|
|
1109
|
+
data = _context6.v;
|
|
1110
|
+
// Store current scene data even for default scene
|
|
1111
|
+
component.currentSceneData = data;
|
|
1112
|
+
|
|
1113
|
+
// Use the consolidated scene loading function
|
|
1114
|
+
_context6.n = 4;
|
|
1115
|
+
return this.loadSceneData(data, false);
|
|
1116
|
+
case 4:
|
|
1117
|
+
_context6.n = 6;
|
|
1118
|
+
break;
|
|
1119
|
+
case 5:
|
|
1120
|
+
_context6.p = 5;
|
|
1121
|
+
_t0 = _context6.v;
|
|
1122
|
+
console.error('Error loading default scene:', _t0);
|
|
1123
|
+
case 6:
|
|
1124
|
+
return _context6.a(2);
|
|
1125
|
+
}
|
|
1126
|
+
}, _callee6, this, [[1, 5]]);
|
|
1127
|
+
}));
|
|
1128
|
+
function loadScene() {
|
|
1129
|
+
return _loadScene.apply(this, arguments);
|
|
1130
|
+
}
|
|
1131
|
+
return loadScene;
|
|
1132
|
+
}()
|
|
1133
|
+
/**
|
|
1134
|
+
* Load scene from imported JSON data
|
|
1135
|
+
*/
|
|
1136
|
+
)
|
|
1137
|
+
}, {
|
|
1138
|
+
key: "loadSceneFromData",
|
|
1139
|
+
value: (function () {
|
|
1140
|
+
var _loadSceneFromData = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee7(data) {
|
|
1141
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context7) {
|
|
1142
|
+
while (1) switch (_context7.n) {
|
|
1143
|
+
case 0:
|
|
1144
|
+
_context7.n = 1;
|
|
1145
|
+
return this.loadSceneData(data, true);
|
|
1146
|
+
case 1:
|
|
1147
|
+
return _context7.a(2);
|
|
1148
|
+
}
|
|
1149
|
+
}, _callee7, this);
|
|
1150
|
+
}));
|
|
1151
|
+
function loadSceneFromData(_x8) {
|
|
1152
|
+
return _loadSceneFromData.apply(this, arguments);
|
|
1153
|
+
}
|
|
1154
|
+
return loadSceneFromData;
|
|
1155
|
+
}()
|
|
1156
|
+
/**
|
|
1157
|
+
* Create empty scene with just the base environment
|
|
1158
|
+
*/
|
|
1159
|
+
)
|
|
1160
|
+
}, {
|
|
1161
|
+
key: "createEmptyScene",
|
|
1162
|
+
value: function createEmptyScene() {
|
|
1163
|
+
var component = this.sceneViewer;
|
|
1164
|
+
// Explicitly disable transform controls before clearing scene
|
|
1165
|
+
if (component.transformManager && component.transformManager.transformControls) {
|
|
1166
|
+
component.disableTransformControls();
|
|
1167
|
+
}
|
|
1168
|
+
this.clearSceneObjects();
|
|
1169
|
+
|
|
1170
|
+
// Make sure transform controls are fully disabled for empty scene
|
|
1171
|
+
if (component.transformManager && component.transformManager.transformControls) {
|
|
1172
|
+
// Double-check that transform controls are disabled and hidden
|
|
1173
|
+
component.transformManager.setEnabled(false);
|
|
1174
|
+
component.transformManager.transformControls.visible = false;
|
|
1175
|
+
|
|
1176
|
+
// Detach any selected object
|
|
1177
|
+
if (component.transformManager.selectedObject) {
|
|
1178
|
+
component.transformManager.deselectObject();
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
console.log('Created new empty scene with hidden transform controls');
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Clear the model cache to free up memory
|
|
1186
|
+
*/
|
|
1187
|
+
}, {
|
|
1188
|
+
key: "clearModelCache",
|
|
1189
|
+
value: function clearModelCache() {
|
|
1190
|
+
var component = this.sceneViewer;
|
|
1191
|
+
console.log('🧹 Clearing GLB model cache...');
|
|
1192
|
+
if (component.modelCache) {
|
|
1193
|
+
component.modelCache.clear();
|
|
1194
|
+
}
|
|
1195
|
+
if (component.loadingPromises) {
|
|
1196
|
+
component.loadingPromises.clear();
|
|
1197
|
+
}
|
|
1198
|
+
console.log('✅ Model cache cleared');
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* Deselect currently selected object
|
|
1203
|
+
*/
|
|
1204
|
+
}, {
|
|
1205
|
+
key: "deselectObject",
|
|
1206
|
+
value: function deselectObject() {
|
|
1207
|
+
var component = this.sceneViewer;
|
|
1208
|
+
if (component.transformManager) {
|
|
1209
|
+
component.transformManager.deselectObject();
|
|
1210
|
+
}
|
|
1211
|
+
component.selectedObjectForTransform = null;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Setup event listeners for scene loading
|
|
1216
|
+
*/
|
|
1217
|
+
}, {
|
|
1218
|
+
key: "setupEventListeners",
|
|
1219
|
+
value: function setupEventListeners() {
|
|
1220
|
+
var _window$$nuxt,
|
|
1221
|
+
_window$$nuxt$$on,
|
|
1222
|
+
_window$$nuxt2,
|
|
1223
|
+
_window$$nuxt2$$on,
|
|
1224
|
+
_this3 = this;
|
|
1225
|
+
this.sceneViewer;
|
|
1226
|
+
|
|
1227
|
+
// Listen for new scene data loading - bind 'this' to ensure proper context
|
|
1228
|
+
var boundLoadSceneFromData = this.loadSceneFromData.bind(this);
|
|
1229
|
+
|
|
1230
|
+
// Listen for loading new scene data
|
|
1231
|
+
(_window$$nuxt = window.$nuxt) === null || _window$$nuxt === void 0 || (_window$$nuxt$$on = _window$$nuxt.$on) === null || _window$$nuxt$$on === void 0 || _window$$nuxt$$on.call(_window$$nuxt, 'loadNewScene', /*#__PURE__*/function () {
|
|
1232
|
+
var _ref3 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee8(newSceneData) {
|
|
1233
|
+
return _rollupPluginBabelHelpers.regenerator().w(function (_context8) {
|
|
1234
|
+
while (1) switch (_context8.n) {
|
|
1235
|
+
case 0:
|
|
1236
|
+
_context8.n = 1;
|
|
1237
|
+
return boundLoadSceneFromData(newSceneData);
|
|
1238
|
+
case 1:
|
|
1239
|
+
return _context8.a(2);
|
|
1240
|
+
}
|
|
1241
|
+
}, _callee8);
|
|
1242
|
+
}));
|
|
1243
|
+
return function (_x9) {
|
|
1244
|
+
return _ref3.apply(this, arguments);
|
|
1245
|
+
};
|
|
1246
|
+
}());
|
|
1247
|
+
|
|
1248
|
+
// Listen for creating new empty scene
|
|
1249
|
+
(_window$$nuxt2 = window.$nuxt) === null || _window$$nuxt2 === void 0 || (_window$$nuxt2$$on = _window$$nuxt2.$on) === null || _window$$nuxt2$$on === void 0 || _window$$nuxt2$$on.call(_window$$nuxt2, 'createNewScene', function () {
|
|
1250
|
+
_this3.createEmptyScene();
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Update scene data after object transform
|
|
1256
|
+
*/
|
|
1257
|
+
}, {
|
|
1258
|
+
key: "updateSceneDataAfterTransform",
|
|
1259
|
+
value: function updateSceneDataAfterTransform(object, currentSceneData) {
|
|
1260
|
+
var _object$userData2, _object$userData3;
|
|
1261
|
+
var objectFound = false;
|
|
1262
|
+
console.log("onTransformEnd object.uuid:", object.uuid);
|
|
1263
|
+
|
|
1264
|
+
// Fix the bug of overlapping pipes connecting newly generated gateways
|
|
1265
|
+
this.sceneViewer.pathfindingManager.recomputeWorldBoundingBoxes(currentSceneData);
|
|
1266
|
+
|
|
1267
|
+
// Check if the object is a gateway and claim it as declared if origin is computed
|
|
1268
|
+
if (((_object$userData2 = object.userData) === null || _object$userData2 === void 0 ? void 0 : _object$userData2.componentType) === 'gateway' && ((_object$userData3 = object.userData) === null || _object$userData3 === void 0 ? void 0 : _object$userData3.origin) === 'computed') {
|
|
1269
|
+
var _object$userData5;
|
|
1270
|
+
console.log('🔧 Gateway with computed origin detected, claiming as declared:', object.uuid);
|
|
1271
|
+
object.userData.origin = 'declared';
|
|
1272
|
+
|
|
1273
|
+
// Also update the corresponding scene data object
|
|
1274
|
+
for (var i = 0; i < currentSceneData.scene.object.children.length; i++) {
|
|
1275
|
+
var _object$userData4, _child$userData17;
|
|
1276
|
+
var child = currentSceneData.scene.object.children[i];
|
|
1277
|
+
if (child.uuid === object.uuid || child.uuid === ((_object$userData4 = object.userData) === null || _object$userData4 === void 0 ? void 0 : _object$userData4.originalUuid) || object.uuid === ((_child$userData17 = child.userData) === null || _child$userData17 === void 0 ? void 0 : _child$userData17.originalUuid)) {
|
|
1278
|
+
if (!child.userData) child.userData = {};
|
|
1279
|
+
child.userData.origin = 'declared';
|
|
1280
|
+
break;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// Grab connections from the gateway's userData and filter removed/added connections
|
|
1285
|
+
if ((_object$userData5 = object.userData) !== null && _object$userData5 !== void 0 && _object$userData5.connections && currentSceneData.connections) {
|
|
1286
|
+
console.log('🔗 Processing gateway connections for filtering:', object.userData.connections);
|
|
1287
|
+
var gatewayConnections = object.userData.connections;
|
|
1288
|
+
var currentConnections = currentSceneData.connections;
|
|
1289
|
+
|
|
1290
|
+
// Filter out removed connections
|
|
1291
|
+
if (gatewayConnections.removed && Array.isArray(gatewayConnections.removed)) {
|
|
1292
|
+
console.log('🗑️ Filtering out removed connections:', gatewayConnections.removed);
|
|
1293
|
+
currentSceneData.connections = currentConnections.filter(function (connection) {
|
|
1294
|
+
var isRemoved = gatewayConnections.removed.some(function (removedConn) {
|
|
1295
|
+
return removedConn.from === connection.from && removedConn.to === connection.to || removedConn.from === connection.to && removedConn.to === connection.from;
|
|
1296
|
+
});
|
|
1297
|
+
if (isRemoved) {
|
|
1298
|
+
console.log("\uD83D\uDDD1\uFE0F Removed connection: ".concat(connection.from, " \u2192 ").concat(connection.to));
|
|
1299
|
+
}
|
|
1300
|
+
return !isRemoved;
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// Add new connections
|
|
1305
|
+
if (gatewayConnections.added && Array.isArray(gatewayConnections.added)) {
|
|
1306
|
+
console.log('➕ Adding new connections:', gatewayConnections.added);
|
|
1307
|
+
gatewayConnections.added.forEach(function (newConnection) {
|
|
1308
|
+
// Check if connection already exists to avoid duplicates
|
|
1309
|
+
var alreadyExists = currentSceneData.connections.some(function (conn) {
|
|
1310
|
+
return conn.from === newConnection.from && conn.to === newConnection.to || conn.from === newConnection.to && conn.to === newConnection.from;
|
|
1311
|
+
});
|
|
1312
|
+
if (!alreadyExists) {
|
|
1313
|
+
currentSceneData.connections.push(newConnection);
|
|
1314
|
+
console.log("\u2795 Added new connection: ".concat(newConnection.from, " \u2192 ").concat(newConnection.to));
|
|
1315
|
+
} else {
|
|
1316
|
+
console.log("\u26A0\uFE0F Connection already exists, skipping: ".concat(newConnection.from, " \u2192 ").concat(newConnection.to));
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
console.log('✅ Gateway connections processing completed. Total connections:', currentSceneData.connections.length);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// Update the corresponding child in currentSceneData with the transformed object
|
|
1325
|
+
var _loop = function _loop() {
|
|
1326
|
+
var _object$userData6, _child$userData18, _object$userData7, _child$userData19;
|
|
1327
|
+
var child = currentSceneData.scene.object.children[_i2];
|
|
1328
|
+
console.log("onTransformEnd child.uuid:", child.uuid);
|
|
1329
|
+
// Enhanced matching logic with hardcoded UUID priority
|
|
1330
|
+
var isMatch = false;
|
|
1331
|
+
|
|
1332
|
+
// Strategy 1: Direct hardcoded UUID match (HIGHEST PRIORITY)
|
|
1333
|
+
if (child.uuid === object.uuid || child.uuid === ((_object$userData6 = object.userData) === null || _object$userData6 === void 0 ? void 0 : _object$userData6.originalUuid) || object.uuid === ((_child$userData18 = child.userData) === null || _child$userData18 === void 0 ? void 0 : _child$userData18.originalUuid)) {
|
|
1334
|
+
isMatch = true;
|
|
1335
|
+
console.log('🎯 Matched by hardcoded UUID');
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// Strategy 4: Component type and library ID match
|
|
1339
|
+
if (!isMatch && (_object$userData7 = object.userData) !== null && _object$userData7 !== void 0 && _object$userData7.libraryId && (_child$userData19 = child.userData) !== null && _child$userData19 !== void 0 && _child$userData19.libraryId && object.userData.libraryId === child.userData.libraryId) {
|
|
1340
|
+
// For library components, also check position similarity
|
|
1341
|
+
var positionTolerance = 1.0; // Larger tolerance for main components
|
|
1342
|
+
if (child.position && object.position) {
|
|
1343
|
+
var dx = Math.abs(object.position.x - child.position.x);
|
|
1344
|
+
var dy = Math.abs(object.position.y - child.position.y);
|
|
1345
|
+
var dz = Math.abs(object.position.z - child.position.z);
|
|
1346
|
+
if (dx < positionTolerance && dy < positionTolerance && dz < positionTolerance) {
|
|
1347
|
+
isMatch = true;
|
|
1348
|
+
console.log('🎯 Matched by library ID and position similarity');
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
if (isMatch) {
|
|
1353
|
+
console.log('onTransformEnd found matching object:', 'UUID:', child.uuid);
|
|
1354
|
+
|
|
1355
|
+
// Also update the world bounding box directly from the transformed Three.js object
|
|
1356
|
+
var boundingBox = new THREE__namespace.Box3().setFromObject(object);
|
|
1357
|
+
|
|
1358
|
+
// Helper function to update children's world bounding boxes recursively
|
|
1359
|
+
var _updateChildrenBoundingBoxes = function updateChildrenBoundingBoxes(sceneDataChildren, threeJSChildren) {
|
|
1360
|
+
if (!sceneDataChildren || !threeJSChildren) return sceneDataChildren;
|
|
1361
|
+
return sceneDataChildren.map(function (sceneChild) {
|
|
1362
|
+
// Enhanced matching logic with hardcoded UUID priority
|
|
1363
|
+
var matchingThreeChild = threeJSChildren.find(function (threeChild) {
|
|
1364
|
+
var _sceneChild$userData, _threeChild$userData, _threeChild$userData2, _sceneChild$userData2;
|
|
1365
|
+
// Strategy 1: Direct hardcoded UUID match (HIGHEST PRIORITY)
|
|
1366
|
+
if (threeChild.uuid === sceneChild.uuid || threeChild.uuid === ((_sceneChild$userData = sceneChild.userData) === null || _sceneChild$userData === void 0 ? void 0 : _sceneChild$userData.originalUuid) || ((_threeChild$userData = threeChild.userData) === null || _threeChild$userData === void 0 ? void 0 : _threeChild$userData.originalUuid) === sceneChild.uuid) {
|
|
1367
|
+
return true;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// Strategy 4: Component type and position match (for connectors)
|
|
1371
|
+
if ((_threeChild$userData2 = threeChild.userData) !== null && _threeChild$userData2 !== void 0 && _threeChild$userData2.componentType && (_sceneChild$userData2 = sceneChild.userData) !== null && _sceneChild$userData2 !== void 0 && _sceneChild$userData2.componentType && threeChild.userData.componentType === sceneChild.userData.componentType && threeChild.userData.componentType === 'connector') {
|
|
1372
|
+
// For connectors, also check position similarity (within tolerance)
|
|
1373
|
+
var _positionTolerance = 0.1;
|
|
1374
|
+
if (sceneChild.position && threeChild.position) {
|
|
1375
|
+
var _dx = Math.abs(threeChild.position.x - sceneChild.position.x);
|
|
1376
|
+
var _dy = Math.abs(threeChild.position.y - sceneChild.position.y);
|
|
1377
|
+
var _dz = Math.abs(threeChild.position.z - sceneChild.position.z);
|
|
1378
|
+
if (_dx < _positionTolerance && _dy < _positionTolerance && _dz < _positionTolerance) {
|
|
1379
|
+
return true;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
return false;
|
|
1384
|
+
});
|
|
1385
|
+
if (matchingThreeChild && matchingThreeChild.isMesh) {
|
|
1386
|
+
// Calculate world bounding box for this child
|
|
1387
|
+
var childBoundingBox = new THREE__namespace.Box3().setFromObject(matchingThreeChild);
|
|
1388
|
+
console.log("\uD83D\uDD04 Updated bounding box for child: ".concat(sceneChild.uuid));
|
|
1389
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, sceneChild), {}, {
|
|
1390
|
+
userData: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, sceneChild.userData), matchingThreeChild.userData), {}, {
|
|
1391
|
+
worldBoundingBox: {
|
|
1392
|
+
min: childBoundingBox.min.toArray(),
|
|
1393
|
+
max: childBoundingBox.max.toArray()
|
|
1394
|
+
}
|
|
1395
|
+
}),
|
|
1396
|
+
// Recursively update nested children if they exist
|
|
1397
|
+
children: sceneChild.children ? _updateChildrenBoundingBoxes(sceneChild.children, matchingThreeChild.children) : sceneChild.children
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// If no matching Three.js object found, recurse into children anyway
|
|
1402
|
+
console.log("\u26A0\uFE0F No matching Three.js object found for scene child: (UUID: ".concat(sceneChild.uuid, ")"));
|
|
1403
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, sceneChild), {}, {
|
|
1404
|
+
children: sceneChild.children ? _updateChildrenBoundingBoxes(sceneChild.children, threeJSChildren) : sceneChild.children
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
};
|
|
1408
|
+
object.traverse(function (child) {
|
|
1409
|
+
if (child.userData && child.userData.direction && child.userData.worldMatrixOriginal) {
|
|
1410
|
+
// Get current world matrix
|
|
1411
|
+
child.updateMatrixWorld(true);
|
|
1412
|
+
var currentMatrix = new THREE__namespace.Matrix4();
|
|
1413
|
+
currentMatrix.copy(child.matrixWorld);
|
|
1414
|
+
|
|
1415
|
+
// Get original world matrix
|
|
1416
|
+
var originalMatrix = new THREE__namespace.Matrix4();
|
|
1417
|
+
originalMatrix.elements = child.userData.worldMatrixOriginal;
|
|
1418
|
+
console.log('onTransformEnd currentMatrix', currentMatrix);
|
|
1419
|
+
console.log('onTransformEnd originalMatrix', originalMatrix);
|
|
1420
|
+
|
|
1421
|
+
// Extract rotation matrices
|
|
1422
|
+
var currentRotation = new THREE__namespace.Matrix4();
|
|
1423
|
+
var originalRotation = new THREE__namespace.Matrix4();
|
|
1424
|
+
currentRotation.extractRotation(currentMatrix);
|
|
1425
|
+
originalRotation.extractRotation(originalMatrix);
|
|
1426
|
+
|
|
1427
|
+
// Calculate the rotational difference matrix
|
|
1428
|
+
var rotationDifference = new THREE__namespace.Matrix4();
|
|
1429
|
+
rotationDifference.copy(currentRotation);
|
|
1430
|
+
rotationDifference.multiply(originalRotation.invert());
|
|
1431
|
+
|
|
1432
|
+
// Create direction vector from array
|
|
1433
|
+
var directionVector = new THREE__namespace.Vector3().fromArray(child.userData.direction);
|
|
1434
|
+
|
|
1435
|
+
// Apply only the rotational difference to the direction vector
|
|
1436
|
+
directionVector.applyMatrix4(rotationDifference);
|
|
1437
|
+
|
|
1438
|
+
// Ensure the vector remains orthogonal and has only 0 or 1 components
|
|
1439
|
+
directionVector.normalize();
|
|
1440
|
+
console.log('onTransformEnd directionVector', directionVector);
|
|
1441
|
+
|
|
1442
|
+
// Round components to either 0 or 1
|
|
1443
|
+
var threshold = 0.5;
|
|
1444
|
+
directionVector.x = Math.abs(directionVector.x) > threshold ? Math.sign(directionVector.x) : 0;
|
|
1445
|
+
directionVector.y = Math.abs(directionVector.y) > threshold ? Math.sign(directionVector.y) : 0;
|
|
1446
|
+
directionVector.z = Math.abs(directionVector.z) > threshold ? Math.sign(directionVector.z) : 0;
|
|
1447
|
+
|
|
1448
|
+
// Update the direction in userData
|
|
1449
|
+
child.userData.direction = directionVector.toArray();
|
|
1450
|
+
|
|
1451
|
+
// Update the original world matrix for next transformation
|
|
1452
|
+
child.userData.worldMatrixOriginal = currentMatrix.elements;
|
|
1453
|
+
console.log('Updated direction:', {
|
|
1454
|
+
name: child.name,
|
|
1455
|
+
uuid: child.uuid,
|
|
1456
|
+
originalDirection: child.userData.direction,
|
|
1457
|
+
newDirection: directionVector.toArray(),
|
|
1458
|
+
rotationDifference: rotationDifference.elements
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
|
|
1463
|
+
// Update the main object and its children
|
|
1464
|
+
currentSceneData.scene.object.children[_i2] = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, child), {}, {
|
|
1465
|
+
matrix: object.matrix.elements,
|
|
1466
|
+
position: {
|
|
1467
|
+
x: object.position.x,
|
|
1468
|
+
y: object.position.y,
|
|
1469
|
+
z: object.position.z
|
|
1470
|
+
},
|
|
1471
|
+
rotation: {
|
|
1472
|
+
x: object.rotation.x,
|
|
1473
|
+
y: object.rotation.y,
|
|
1474
|
+
z: object.rotation.z
|
|
1475
|
+
},
|
|
1476
|
+
scale: {
|
|
1477
|
+
x: object.scale.x,
|
|
1478
|
+
y: object.scale.y,
|
|
1479
|
+
z: object.scale.z
|
|
1480
|
+
},
|
|
1481
|
+
userData: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, child.userData), {}, {
|
|
1482
|
+
worldBoundingBox: {
|
|
1483
|
+
min: boundingBox.min.toArray(),
|
|
1484
|
+
max: boundingBox.max.toArray()
|
|
1485
|
+
}
|
|
1486
|
+
}),
|
|
1487
|
+
// Update children's bounding boxes if they exist
|
|
1488
|
+
children: child.children ? _updateChildrenBoundingBoxes(child.children, object.children) : child.children
|
|
1489
|
+
});
|
|
1490
|
+
console.log('onTransformEnd updated child at index:', _i2, 'and its children');
|
|
1491
|
+
objectFound = true;
|
|
1492
|
+
return 1; // break
|
|
1493
|
+
// Exit loop once we find the match
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
for (var _i2 = 0; _i2 < currentSceneData.scene.object.children.length; _i2++) {
|
|
1497
|
+
if (_loop()) break;
|
|
1498
|
+
}
|
|
1499
|
+
if (!objectFound) {
|
|
1500
|
+
console.warn('⚠️ Could not find matching object in scene data for:', object.uuid);
|
|
1501
|
+
return false; // Don't proceed with pathfinding if we couldn't update the data
|
|
1502
|
+
}
|
|
1503
|
+
console.log('onTransformEnd worldBoundBox after:', JSON.parse(JSON.stringify(currentSceneData.scene.object.children[2].children[0].userData.worldBoundingBox)));
|
|
1504
|
+
return true;
|
|
1505
|
+
}
|
|
1506
|
+
}]);
|
|
1507
|
+
}();
|
|
1508
|
+
|
|
1509
|
+
exports.SceneOperationsManager = SceneOperationsManager;
|