@2112-lab/central-plant 0.3.21 → 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { createClass as _createClass, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray, typeof as _typeof, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, createForOfIteratorHelper as _createForOfIteratorHelper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
1
+ import { createClass as _createClass, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray, typeof as _typeof, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, regeneratorValues as _regeneratorValues, slicedToArray as _slicedToArray, createForOfIteratorHelper as _createForOfIteratorHelper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import * as THREE from 'three';
3
3
  import { attachIODevicesToComponent } from '../../utils/ioDeviceUtils.js';
4
4
  import modelPreloader from '../../rendering/modelPreloader.js';
@@ -53,12 +53,12 @@ var ModelManager = /*#__PURE__*/function () {
53
53
  key: "loadLibraryModel",
54
54
  value: function () {
55
55
  var _loadLibraryModel = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(targetMesh, jsonEntry, componentData) {
56
- var component, _jsonEntry$userData, _jsonEntry$userData2, _jsonEntry$userData3, originalProps, connectorChildren, gltfScene, libraryModel, _jsonEntry$userData4, _t;
57
- return _regenerator().w(function (_context) {
58
- while (1) switch (_context.n) {
56
+ var component, _jsonEntry$userData, _jsonEntry$userData2, _jsonEntry$userData3, originalProps, connectorChildren, gltfScene, libraryModel, _this$sceneViewer, ioAnimMgr, _loop, _i, _Object$entries, _jsonEntry$userData4, _t;
57
+ return _regenerator().w(function (_context2) {
58
+ while (1) switch (_context2.n) {
59
59
  case 0:
60
60
  component = this.sceneViewer;
61
- _context.p = 1;
61
+ _context2.p = 1;
62
62
  console.log("Loading library GLB model for ".concat((_jsonEntry$userData = jsonEntry.userData) === null || _jsonEntry$userData === void 0 ? void 0 : _jsonEntry$userData.libraryId, "..."));
63
63
 
64
64
  // Store original mesh properties before async operation
@@ -71,16 +71,16 @@ var ModelManager = /*#__PURE__*/function () {
71
71
  uuid: targetMesh.uuid
72
72
  }; // Preserve connector children (pass parent UUID for proper connector UUID generation)
73
73
  connectorChildren = this._preserveConnectorChildren(targetMesh, originalProps.uuid); // Get model from cache or load directly
74
- _context.n = 2;
74
+ _context2.n = 2;
75
75
  return this._getLibraryModel(componentData.modelKey, (_jsonEntry$userData2 = jsonEntry.userData) === null || _jsonEntry$userData2 === void 0 ? void 0 : _jsonEntry$userData2.libraryId);
76
76
  case 2:
77
- gltfScene = _context.v;
77
+ gltfScene = _context2.v;
78
78
  if (gltfScene) {
79
- _context.n = 3;
79
+ _context2.n = 3;
80
80
  break;
81
81
  }
82
82
  console.warn("\u26A0\uFE0F Could not load model ".concat(componentData.modelKey, ", keeping original mesh"));
83
- return _context.a(2, targetMesh);
83
+ return _context2.a(2, targetMesh);
84
84
  case 3:
85
85
  // Configure the loaded model
86
86
  libraryModel = this._configureLibraryModel(gltfScene, jsonEntry, componentData, originalProps); // Add preserved connectors
@@ -90,23 +90,74 @@ var ModelManager = /*#__PURE__*/function () {
90
90
 
91
91
  // Attach IO devices for smart components (import flow)
92
92
  if (!(componentData.isSmart && componentData.attachedDevices)) {
93
- _context.n = 4;
93
+ _context2.n = 8;
94
94
  break;
95
95
  }
96
- _context.n = 4;
96
+ _context2.n = 4;
97
97
  return attachIODevicesToComponent(libraryModel, componentData, modelPreloader, originalProps.uuid);
98
98
  case 4:
99
+ // Register animation configs for each attached device
100
+ ioAnimMgr = (_this$sceneViewer = this.sceneViewer) === null || _this$sceneViewer === void 0 || (_this$sceneViewer = _this$sceneViewer.managers) === null || _this$sceneViewer === void 0 ? void 0 : _this$sceneViewer.ioAnimationManager;
101
+ if (!ioAnimMgr) {
102
+ _context2.n = 8;
103
+ break;
104
+ }
105
+ _loop = /*#__PURE__*/_regenerator().m(function _loop() {
106
+ var _modelPreloader$compo;
107
+ var _Object$entries$_i, attachmentId, attachment, deviceData, deviceRoot;
108
+ return _regenerator().w(function (_context) {
109
+ while (1) switch (_context.n) {
110
+ case 0:
111
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), attachmentId = _Object$entries$_i[0], attachment = _Object$entries$_i[1];
112
+ deviceData = (_modelPreloader$compo = modelPreloader.componentDictionary) === null || _modelPreloader$compo === void 0 ? void 0 : _modelPreloader$compo[attachment.deviceId];
113
+ if (deviceData !== null && deviceData !== void 0 && deviceData.animationConfig) {
114
+ _context.n = 1;
115
+ break;
116
+ }
117
+ return _context.a(2, 1);
118
+ case 1:
119
+ deviceRoot = null;
120
+ libraryModel.traverse(function (obj) {
121
+ var _obj$userData;
122
+ if (!deviceRoot && ((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.attachmentId) === attachmentId) deviceRoot = obj;
123
+ });
124
+ if (deviceRoot) {
125
+ ioAnimMgr.loadAnimations(attachmentId, deviceData.animationConfig, deviceRoot, originalProps.uuid);
126
+ }
127
+ case 2:
128
+ return _context.a(2);
129
+ }
130
+ }, _loop);
131
+ });
132
+ _i = 0, _Object$entries = Object.entries(componentData.attachedDevices);
133
+ case 5:
134
+ if (!(_i < _Object$entries.length)) {
135
+ _context2.n = 8;
136
+ break;
137
+ }
138
+ return _context2.d(_regeneratorValues(_loop()), 6);
139
+ case 6:
140
+ if (!_context2.v) {
141
+ _context2.n = 7;
142
+ break;
143
+ }
144
+ return _context2.a(3, 7);
145
+ case 7:
146
+ _i++;
147
+ _context2.n = 5;
148
+ break;
149
+ case 8:
99
150
  // Replace mesh in scene
100
151
  this._replaceMeshInScene(targetMesh, libraryModel, originalProps.parent, component);
101
152
  console.log("\uD83C\uDF89 ".concat((_jsonEntry$userData3 = jsonEntry.userData) === null || _jsonEntry$userData3 === void 0 ? void 0 : _jsonEntry$userData3.libraryId, " GLB model successfully rendered in scene"));
102
- return _context.a(2, libraryModel);
103
- case 5:
104
- _context.p = 5;
105
- _t = _context.v;
153
+ return _context2.a(2, libraryModel);
154
+ case 9:
155
+ _context2.p = 9;
156
+ _t = _context2.v;
106
157
  console.error("\u274C Error loading ".concat((_jsonEntry$userData4 = jsonEntry.userData) === null || _jsonEntry$userData4 === void 0 ? void 0 : _jsonEntry$userData4.libraryId, " GLB model:"), _t);
107
- return _context.a(2, targetMesh);
158
+ return _context2.a(2, targetMesh);
108
159
  }
109
- }, _callee, this, [[1, 5]]);
160
+ }, _callee, this, [[1, 9]]);
110
161
  }));
111
162
  function loadLibraryModel(_x, _x2, _x3) {
112
163
  return _loadLibraryModel.apply(this, arguments);
@@ -185,84 +236,84 @@ var ModelManager = /*#__PURE__*/function () {
185
236
  var _getLibraryModel2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(modelKey, libraryId) {
186
237
  var _this2 = this;
187
238
  var gltfScene, preloaderStatus, modelPath, gltf, _t2, _t3, _t4;
188
- return _regenerator().w(function (_context2) {
189
- while (1) switch (_context2.n) {
239
+ return _regenerator().w(function (_context3) {
240
+ while (1) switch (_context3.n) {
190
241
  case 0:
191
242
  // Try cache first
192
243
  gltfScene = modelPreloader.getCachedModelWithDimensions(modelKey, libraryId);
193
244
  if (!gltfScene) {
194
- _context2.n = 1;
245
+ _context3.n = 1;
195
246
  break;
196
247
  }
197
248
  console.log("\uD83C\uDFAF GLB cache HIT: ".concat(modelKey));
198
- return _context2.a(2, gltfScene);
249
+ return _context3.a(2, gltfScene);
199
250
  case 1:
200
251
  // Check if preloading is in progress
201
252
  preloaderStatus = modelPreloader.getStatus();
202
253
  if (!preloaderStatus.isPreloading) {
203
- _context2.n = 6;
254
+ _context3.n = 6;
204
255
  break;
205
256
  }
206
257
  console.log("\u23F3 Waiting for preloader: ".concat(modelKey));
207
- _context2.p = 2;
208
- _context2.n = 3;
258
+ _context3.p = 2;
259
+ _context3.n = 3;
209
260
  return modelPreloader.preloadingPromise;
210
261
  case 3:
211
262
  gltfScene = modelPreloader.getCachedModelWithDimensions(modelKey, libraryId);
212
263
  if (!gltfScene) {
213
- _context2.n = 4;
264
+ _context3.n = 4;
214
265
  break;
215
266
  }
216
267
  console.log("\uD83C\uDFAF GLB cache HIT (after preload): ".concat(modelKey));
217
- return _context2.a(2, gltfScene);
268
+ return _context3.a(2, gltfScene);
218
269
  case 4:
219
- _context2.n = 6;
270
+ _context3.n = 6;
220
271
  break;
221
272
  case 5:
222
- _context2.p = 5;
223
- _t2 = _context2.v;
273
+ _context3.p = 5;
274
+ _t2 = _context3.v;
224
275
  console.warn("\u26A0\uFE0F Preloading failed:", _t2);
225
276
  case 6:
226
- _context2.p = 6;
277
+ _context3.p = 6;
227
278
  if (!modelPreloader.urlResolver) {
228
- _context2.n = 11;
279
+ _context3.n = 11;
229
280
  break;
230
281
  }
231
- _context2.p = 7;
232
- _context2.n = 8;
282
+ _context3.p = 7;
283
+ _context3.n = 8;
233
284
  return modelPreloader.urlResolver(modelKey);
234
285
  case 8:
235
- modelPath = _context2.v;
286
+ modelPath = _context3.v;
236
287
  console.log("\uD83D\uDD17 Resolved URL for ".concat(modelKey));
237
- _context2.n = 10;
288
+ _context3.n = 10;
238
289
  break;
239
290
  case 9:
240
- _context2.p = 9;
241
- _t3 = _context2.v;
291
+ _context3.p = 9;
292
+ _t3 = _context3.v;
242
293
  console.warn("\u26A0\uFE0F URL resolver failed for ".concat(modelKey, ", falling back to local path:"), _t3);
243
294
  modelPath = "".concat(modelPreloader.modelsBasePath).concat(modelKey);
244
295
  case 10:
245
- _context2.n = 12;
296
+ _context3.n = 12;
246
297
  break;
247
298
  case 11:
248
299
  modelPath = "".concat(modelPreloader.modelsBasePath).concat(modelKey);
249
300
  case 12:
250
301
  console.log("\uD83D\uDCC2 Fallback loading from: ".concat(modelPath));
251
- _context2.n = 13;
302
+ _context3.n = 13;
252
303
  return new Promise(function (resolve, reject) {
253
304
  _this2.sceneViewer.gltfLoader.load(modelPath, resolve, undefined, reject);
254
305
  });
255
306
  case 13:
256
- gltf = _context2.v;
307
+ gltf = _context3.v;
257
308
  if (libraryId) {
258
309
  modelPreloader.cacheModel(modelKey, gltf.scene.clone(), libraryId);
259
310
  }
260
- return _context2.a(2, gltf.scene);
311
+ return _context3.a(2, gltf.scene);
261
312
  case 14:
262
- _context2.p = 14;
263
- _t4 = _context2.v;
313
+ _context3.p = 14;
314
+ _t4 = _context3.v;
264
315
  console.error("Failed to load model ".concat(modelKey, ":"), _t4);
265
- return _context2.a(2, null);
316
+ return _context3.a(2, null);
266
317
  }
267
318
  }, _callee2, null, [[7, 9], [6, 14], [2, 5]]);
268
319
  }));
@@ -369,8 +420,8 @@ var ModelManager = /*#__PURE__*/function () {
369
420
  value: (function () {
370
421
  var _verifyModelPreloaderCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
371
422
  var preloaderStatus, _t5;
372
- return _regenerator().w(function (_context3) {
373
- while (1) switch (_context3.n) {
423
+ return _regenerator().w(function (_context4) {
424
+ while (1) switch (_context4.n) {
374
425
  case 0:
375
426
  console.log('🔍 Verifying model preloader cache state...');
376
427
  preloaderStatus = modelPreloader.getStatus();
@@ -378,23 +429,23 @@ var ModelManager = /*#__PURE__*/function () {
378
429
 
379
430
  // If preloading is still in progress, wait for completion
380
431
  if (!preloaderStatus.isPreloading) {
381
- _context3.n = 4;
432
+ _context4.n = 4;
382
433
  break;
383
434
  }
384
435
  console.log('⏳ Waiting for model preloading to complete...');
385
- _context3.p = 1;
386
- _context3.n = 2;
436
+ _context4.p = 1;
437
+ _context4.n = 2;
387
438
  return modelPreloader.preloadingPromise;
388
439
  case 2:
389
440
  console.log('✅ Model preloading completed');
390
- _context3.n = 4;
441
+ _context4.n = 4;
391
442
  break;
392
443
  case 3:
393
- _context3.p = 3;
394
- _t5 = _context3.v;
444
+ _context4.p = 3;
445
+ _t5 = _context4.v;
395
446
  console.warn('⚠️ Model preloading failed, some models may load directly:', _t5);
396
447
  case 4:
397
- return _context3.a(2, preloaderStatus);
448
+ return _context4.a(2, preloaderStatus);
398
449
  }
399
450
  }, _callee3, null, [[1, 3]]);
400
451
  }));
@@ -412,11 +463,11 @@ var ModelManager = /*#__PURE__*/function () {
412
463
  value: (function () {
413
464
  var _preloadMissingModels = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(data, componentDictionary) {
414
465
  var _data$scene, _data$scene2, requiredModels, preloaderStatus, cachedModels, missingModels, basePath, modelUrls, _iterator, _step, modelKey, _t6, _t7;
415
- return _regenerator().w(function (_context4) {
416
- while (1) switch (_context4.n) {
466
+ return _regenerator().w(function (_context5) {
467
+ while (1) switch (_context5.n) {
417
468
  case 0:
418
469
  if (!(!data || !data.scene || !Array.isArray(data.scene.children))) {
419
- _context4.n = 1;
470
+ _context5.n = 1;
420
471
  break;
421
472
  }
422
473
  console.warn('⚠️ Invalid scene data structure in preloadMissingModels:', {
@@ -425,7 +476,7 @@ var ModelManager = /*#__PURE__*/function () {
425
476
  hasChildren: !!(data !== null && data !== void 0 && (_data$scene = data.scene) !== null && _data$scene !== void 0 && _data$scene.children),
426
477
  childrenType: data !== null && data !== void 0 && (_data$scene2 = data.scene) !== null && _data$scene2 !== void 0 && _data$scene2.children ? _typeof(data.scene.children) : 'undefined'
427
478
  });
428
- return _context4.a(2);
479
+ return _context5.a(2);
429
480
  case 1:
430
481
  requiredModels = new Set();
431
482
  console.log("\uD83D\uDD0D Checking ".concat(data.scene.children.length, " scene objects for required models..."));
@@ -447,10 +498,10 @@ var ModelManager = /*#__PURE__*/function () {
447
498
  }
448
499
  });
449
500
  console.log('🔍 Required models for this scene (Set):', Array.from(requiredModels));
450
- _context4.n = 2;
501
+ _context5.n = 2;
451
502
  return this.verifyModelPreloaderCache();
452
503
  case 2:
453
- preloaderStatus = _context4.v;
504
+ preloaderStatus = _context5.v;
454
505
  cachedModels = preloaderStatus.cachedModels;
455
506
  console.log('ModelPreloader cached models:', cachedModels);
456
507
 
@@ -481,7 +532,7 @@ var ModelManager = /*#__PURE__*/function () {
481
532
  });
482
533
  }
483
534
  if (!(missingModels.length > 0)) {
484
- _context4.n = 12;
535
+ _context5.n = 12;
485
536
  break;
486
537
  }
487
538
  console.warn('⚠️ Some required models are not cached:', missingModels);
@@ -489,41 +540,41 @@ var ModelManager = /*#__PURE__*/function () {
489
540
 
490
541
  // Preload missing models (Main in-memory preloader)
491
542
  _iterator = _createForOfIteratorHelper(missingModels);
492
- _context4.p = 3;
543
+ _context5.p = 3;
493
544
  _iterator.s();
494
545
  case 4:
495
546
  if ((_step = _iterator.n()).done) {
496
- _context4.n = 9;
547
+ _context5.n = 9;
497
548
  break;
498
549
  }
499
550
  modelKey = _step.value;
500
- _context4.p = 5;
501
- _context4.n = 6;
551
+ _context5.p = 5;
552
+ _context5.n = 6;
502
553
  return modelPreloader.preloadSingleModel(modelKey);
503
554
  case 6:
504
555
  console.log("\u2705 Successfully preloaded missing model: ".concat(modelKey));
505
- _context4.n = 8;
556
+ _context5.n = 8;
506
557
  break;
507
558
  case 7:
508
- _context4.p = 7;
509
- _t6 = _context4.v;
559
+ _context5.p = 7;
560
+ _t6 = _context5.v;
510
561
  console.warn("\u274C Failed to preload missing model ".concat(modelKey, ":"), _t6);
511
562
  case 8:
512
- _context4.n = 4;
563
+ _context5.n = 4;
513
564
  break;
514
565
  case 9:
515
- _context4.n = 11;
566
+ _context5.n = 11;
516
567
  break;
517
568
  case 10:
518
- _context4.p = 10;
519
- _t7 = _context4.v;
569
+ _context5.p = 10;
570
+ _t7 = _context5.v;
520
571
  _iterator.e(_t7);
521
572
  case 11:
522
- _context4.p = 11;
573
+ _context5.p = 11;
523
574
  _iterator.f();
524
- return _context4.f(11);
575
+ return _context5.f(11);
525
576
  case 12:
526
- return _context4.a(2);
577
+ return _context5.a(2);
527
578
  }
528
579
  }, _callee4, this, [[5, 7], [3, 10, 11, 12]]);
529
580
  }));
@@ -542,14 +593,14 @@ var ModelManager = /*#__PURE__*/function () {
542
593
  var _replaceWithGLBModels = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(libraryObjectsToReplace) {
543
594
  var _this3 = this;
544
595
  var startTime, glbLoadingPromises;
545
- return _regenerator().w(function (_context5) {
546
- while (1) switch (_context5.n) {
596
+ return _regenerator().w(function (_context6) {
597
+ while (1) switch (_context6.n) {
547
598
  case 0:
548
599
  if (!(libraryObjectsToReplace.length === 0)) {
549
- _context5.n = 1;
600
+ _context6.n = 1;
550
601
  break;
551
602
  }
552
- return _context5.a(2);
603
+ return _context6.a(2);
553
604
  case 1:
554
605
  startTime = performance.now();
555
606
  console.log("\uD83D\uDD04 Replacing ".concat(libraryObjectsToReplace.length, " objects with GLB models..."));
@@ -569,7 +620,7 @@ var ModelManager = /*#__PURE__*/function () {
569
620
  return basicObject;
570
621
  });
571
622
  });
572
- _context5.n = 2;
623
+ _context6.n = 2;
573
624
  return Promise.all(glbLoadingPromises);
574
625
  case 2:
575
626
  console.log("\u23F1\uFE0F All GLB models loaded in ".concat((performance.now() - startTime).toFixed(0), "ms"));
@@ -612,7 +663,7 @@ var ModelManager = /*#__PURE__*/function () {
612
663
  }));
613
664
  }
614
665
  case 3:
615
- return _context5.a(2);
666
+ return _context6.a(2);
616
667
  }
617
668
  }, _callee5);
618
669
  }));
@@ -647,26 +698,26 @@ var ModelManager = /*#__PURE__*/function () {
647
698
  value: (function () {
648
699
  var _loadComponentDictionary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
649
700
  var response, dict, _t8;
650
- return _regenerator().w(function (_context6) {
651
- while (1) switch (_context6.n) {
701
+ return _regenerator().w(function (_context7) {
702
+ while (1) switch (_context7.n) {
652
703
  case 0:
653
- _context6.p = 0;
704
+ _context7.p = 0;
654
705
  console.log('🔄 ModelManager loading component dictionary...');
655
- _context6.n = 1;
706
+ _context7.n = 1;
656
707
  return fetch('/library/component-dictionary.json');
657
708
  case 1:
658
- response = _context6.v;
659
- _context6.n = 2;
709
+ response = _context7.v;
710
+ _context7.n = 2;
660
711
  return response.json();
661
712
  case 2:
662
- dict = _context6.v;
713
+ dict = _context7.v;
663
714
  console.log('✅ ModelManager loaded dictionary:', Object.keys(dict).length, 'entries');
664
- return _context6.a(2, dict);
715
+ return _context7.a(2, dict);
665
716
  case 3:
666
- _context6.p = 3;
667
- _t8 = _context6.v;
717
+ _context7.p = 3;
718
+ _t8 = _context7.v;
668
719
  console.warn('⚠️ Could not load component dictionary:', _t8);
669
- return _context6.a(2, {});
720
+ return _context7.a(2, {});
670
721
  }
671
722
  }, _callee6, null, [[0, 3]]);
672
723
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2112-lab/central-plant",
3
- "version": "0.3.21",
3
+ "version": "0.3.23",
4
4
  "description": "Utility modules for the Central Plant Application",
5
5
  "main": "dist/bundle/index.js",
6
6
  "module": "dist/esm/src/index.js",
@@ -31,7 +31,7 @@
31
31
  "author": "CentralPlant Team",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@2112-lab/pathfinder": "^1.0.38",
34
+ "@2112-lab/pathfinder": "^1.0.39",
35
35
  "stats.js": "^0.17.0",
36
36
  "three": "^0.177.0"
37
37
  },