@2112-lab/central-plant 0.3.41 → 0.3.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/bundle/index.js +332 -123
  2. package/dist/cjs/src/core/centralPlant.js +41 -27
  3. package/dist/cjs/src/core/centralPlantInternals.js +3 -2
  4. package/dist/cjs/src/index.js +6 -0
  5. package/dist/cjs/src/managers/behaviors/IoBehaviorManager.js +1 -12
  6. package/dist/cjs/src/managers/controls/transformControls.js +2 -2
  7. package/dist/cjs/src/managers/controls/transformControlsManager.js +4 -7
  8. package/dist/cjs/src/managers/scene/modelManager.js +2 -2
  9. package/dist/cjs/src/utils/animationTransformUtils.js +10 -7
  10. package/dist/cjs/src/utils/behaviorDispatch.js +64 -0
  11. package/dist/cjs/src/utils/behaviorRegistration.js +12 -1
  12. package/dist/cjs/src/utils/behaviorSceneUtils.js +1 -1
  13. package/dist/cjs/src/utils/behaviorSchema.js +48 -0
  14. package/dist/cjs/src/utils/demoSceneUtils.js +91 -0
  15. package/dist/esm/src/core/centralPlant.js +41 -27
  16. package/dist/esm/src/core/centralPlantInternals.js +3 -2
  17. package/dist/esm/src/index.js +3 -2
  18. package/dist/esm/src/managers/behaviors/IoBehaviorManager.js +2 -13
  19. package/dist/esm/src/managers/controls/transformControls.js +2 -2
  20. package/dist/esm/src/managers/controls/transformControlsManager.js +4 -7
  21. package/dist/esm/src/managers/scene/modelManager.js +2 -2
  22. package/dist/esm/src/utils/animationTransformUtils.js +10 -7
  23. package/dist/esm/src/utils/behaviorDispatch.js +64 -1
  24. package/dist/esm/src/utils/behaviorRegistration.js +12 -1
  25. package/dist/esm/src/utils/behaviorSceneUtils.js +1 -1
  26. package/dist/esm/src/utils/behaviorSchema.js +49 -2
  27. package/dist/esm/src/utils/demoSceneUtils.js +85 -0
  28. package/dist/index.d.ts +16 -4
  29. package/package.json +1 -1
@@ -37,7 +37,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
37
37
  * Initialize the CentralPlant manager
38
38
  *
39
39
  * @constructor
40
- * @version 0.3.41
40
+ * @version 0.3.43
41
41
  * @updated 2025-10-22
42
42
  *
43
43
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -2529,7 +2529,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
2529
2529
  key: "importScene",
2530
2530
  value: (function () {
2531
2531
  var _importScene = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee10(jsonData) {
2532
- var validation, missingIds, resolved, _t4, _t5;
2532
+ var validation, embeddedCount, missingIds, resolved, _t4, _t5;
2533
2533
  return _rollupPluginBabelHelpers.regenerator().w(function (_context10) {
2534
2534
  while (1) switch (_context10.n) {
2535
2535
  case 0:
@@ -2550,64 +2550,78 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
2550
2550
  console.error('❌ Invalid scene data format:', validation.message);
2551
2551
  return _context10.a(2, false);
2552
2552
  case 2:
2553
+ if (!(jsonData.componentDefinitions && _rollupPluginBabelHelpers["typeof"](jsonData.componentDefinitions) === 'object')) {
2554
+ _context10.n = 4;
2555
+ break;
2556
+ }
2557
+ embeddedCount = Object.keys(jsonData.componentDefinitions).length;
2558
+ if (!(embeddedCount > 0)) {
2559
+ _context10.n = 4;
2560
+ break;
2561
+ }
2562
+ _context10.n = 3;
2563
+ return this.extendComponentDictionary(jsonData.componentDefinitions);
2564
+ case 3:
2565
+ console.log("\uD83D\uDCE6 importScene(): Applied ".concat(embeddedCount, " embedded component definition(s)"));
2566
+ case 4:
2553
2567
  if (!this._componentDefinitionResolver) {
2554
- _context10.n = 8;
2568
+ _context10.n = 10;
2555
2569
  break;
2556
2570
  }
2557
2571
  missingIds = this.getMissingLibraryIds(jsonData);
2558
2572
  if (!(missingIds.length > 0)) {
2559
- _context10.n = 8;
2573
+ _context10.n = 10;
2560
2574
  break;
2561
2575
  }
2562
- _context10.p = 3;
2576
+ _context10.p = 5;
2563
2577
  console.log("\uD83D\uDD0D importScene(): Resolving ".concat(missingIds.length, " missing component definition(s)..."));
2564
- _context10.n = 4;
2578
+ _context10.n = 6;
2565
2579
  return this._componentDefinitionResolver(missingIds);
2566
- case 4:
2580
+ case 6:
2567
2581
  resolved = _context10.v;
2568
2582
  if (!(resolved && _rollupPluginBabelHelpers["typeof"](resolved) === 'object' && Object.keys(resolved).length > 0)) {
2569
- _context10.n = 6;
2583
+ _context10.n = 8;
2570
2584
  break;
2571
2585
  }
2572
- _context10.n = 5;
2586
+ _context10.n = 7;
2573
2587
  return this.extendComponentDictionary(resolved);
2574
- case 5:
2588
+ case 7:
2575
2589
  console.log("\u2705 importScene(): Resolved ".concat(Object.keys(resolved).length, " component definition(s)"));
2576
- case 6:
2577
- _context10.n = 8;
2590
+ case 8:
2591
+ _context10.n = 10;
2578
2592
  break;
2579
- case 7:
2580
- _context10.p = 7;
2593
+ case 9:
2594
+ _context10.p = 9;
2581
2595
  _t4 = _context10.v;
2582
2596
  console.warn('⚠️ importScene(): Component definition resolver failed, continuing with existing dictionary:', _t4);
2583
- case 8:
2584
- _context10.n = 9;
2597
+ case 10:
2598
+ _context10.n = 11;
2585
2599
  return this.setImportedSceneData(jsonData);
2586
- case 9:
2600
+ case 11:
2587
2601
  if (!(this.sceneViewer && this.sceneViewer.sceneOperationsManager)) {
2588
- _context10.n = 11;
2602
+ _context10.n = 13;
2589
2603
  break;
2590
2604
  }
2591
- _context10.n = 10;
2605
+ _context10.n = 12;
2592
2606
  return this.sceneViewer.sceneOperationsManager.loadSceneFromData(jsonData);
2593
- case 10:
2607
+ case 12:
2594
2608
  console.log('✅ Scene imported successfully');
2595
2609
  return _context10.a(2, true);
2596
- case 11:
2610
+ case 13:
2597
2611
  console.error('❌ SceneViewer not available for scene loading');
2598
2612
  return _context10.a(2, false);
2599
- case 12:
2600
- _context10.n = 14;
2613
+ case 14:
2614
+ _context10.n = 16;
2601
2615
  break;
2602
- case 13:
2603
- _context10.p = 13;
2616
+ case 15:
2617
+ _context10.p = 15;
2604
2618
  _t5 = _context10.v;
2605
2619
  console.error('❌ Error importing scene:', _t5);
2606
2620
  return _context10.a(2, false);
2607
- case 14:
2621
+ case 16:
2608
2622
  return _context10.a(2);
2609
2623
  }
2610
- }, _callee10, this, [[3, 7], [1, 13]]);
2624
+ }, _callee10, this, [[5, 9], [1, 15]]);
2611
2625
  }));
2612
2626
  function importScene(_x6) {
2613
2627
  return _importScene.apply(this, arguments);
@@ -916,7 +916,8 @@ var CentralPlantInternals = /*#__PURE__*/function () {
916
916
  }, {
917
917
  key: "addComponent",
918
918
  value: function addComponent(libraryId) {
919
- var _this$centralPlant$sc6;
919
+ var _this$centralPlant$sc6,
920
+ _this2 = this;
920
921
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
921
922
  // Use centralized validation for component addition parameters
922
923
  var existingIds = this.getComponentIds();
@@ -1153,7 +1154,7 @@ var CentralPlantInternals = /*#__PURE__*/function () {
1153
1154
  var ioBehavMgr = (_this$centralPlant$sc8 = this.centralPlant.sceneViewer) === null || _this$centralPlant$sc8 === void 0 || (_this$centralPlant$sc8 = _this$centralPlant$sc8.managers) === null || _this$centralPlant$sc8 === void 0 ? void 0 : _this$centralPlant$sc8.ioBehaviorManager;
1154
1155
  ioDeviceUtils.attachIODevicesToComponent(componentModel, componentData, modelPreloader, componentId).then(function () {
1155
1156
  if (ioBehavMgr) {
1156
- behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, componentId, componentData, componentModel, modelPreloader.componentDictionary);
1157
+ behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, componentId, componentData, componentModel, modelPreloader.componentDictionary, _this2.centralPlant);
1157
1158
  }
1158
1159
  }).catch(function (err) {
1159
1160
  console.error("\u274C Error attaching IO devices for ".concat(libraryId, ":"), err);
@@ -18,6 +18,7 @@ var behaviorSchema = require('./utils/behaviorSchema.js');
18
18
  var behaviorRegistration = require('./utils/behaviorRegistration.js');
19
19
  var behaviorDispatch = require('./utils/behaviorDispatch.js');
20
20
  var behaviorSceneUtils = require('./utils/behaviorSceneUtils.js');
21
+ var demoSceneUtils = require('./utils/demoSceneUtils.js');
21
22
  var animationTransformUtils = require('./utils/animationTransformUtils.js');
22
23
  var componentManager = require('./managers/components/componentManager.js');
23
24
  var animationManager = require('./managers/scene/animationManager.js');
@@ -78,8 +79,10 @@ exports.buildIntraBehavior = behaviorSchema.buildIntraBehavior;
78
79
  exports.normalizeBehavior = behaviorSchema.normalizeBehavior;
79
80
  exports.parseCrossBehavior = behaviorSchema.parseCrossBehavior;
80
81
  exports.parseIntraBehavior = behaviorSchema.parseIntraBehavior;
82
+ exports.resolveAnimationDefaultValue = behaviorSchema.resolveAnimationDefaultValue;
81
83
  exports.registerBehaviorsForComponent = behaviorRegistration.registerBehaviorsForComponent;
82
84
  exports.reloadBehaviorsForDeviceAsset = behaviorRegistration.reloadBehaviorsForDeviceAsset;
85
+ exports.applyDefaultIoDeviceStates = behaviorDispatch.applyDefaultIoDeviceStates;
83
86
  exports.getIoBehaviorManager = behaviorDispatch.getIoBehaviorManager;
84
87
  exports.getScopedAttachmentKey = behaviorDispatch.getScopedAttachmentKey;
85
88
  exports.resolveDataPoints = behaviorDispatch.resolveDataPoints;
@@ -88,6 +91,9 @@ exports.loadCrossComponentBehaviors = behaviorSceneUtils.loadCrossComponentBehav
88
91
  exports.refreshSceneIntraBehaviors = behaviorSceneUtils.refreshSceneIntraBehaviors;
89
92
  exports.reregisterSceneBehaviors = behaviorSceneUtils.reregisterSceneBehaviors;
90
93
  exports.scanSceneIoEndpoints = behaviorSceneUtils.scanSceneIoEndpoints;
94
+ exports.collectSceneLibraryIds = demoSceneUtils.collectSceneLibraryIds;
95
+ exports.embedComponentDefinitions = demoSceneUtils.embedComponentDefinitions;
96
+ exports.getComponentDictionary = demoSceneUtils.getComponentDictionary;
91
97
  exports.applyModelRootTranslation = animationTransformUtils.applyModelRootTranslation;
92
98
  exports.applyModelRootTranslationFromWorldBase = animationTransformUtils.applyModelRootTranslationFromWorldBase;
93
99
  exports.modelOffsetToWorldDelta = animationTransformUtils.modelOffsetToWorldDelta;
@@ -619,18 +619,7 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
619
619
  stateConfig.max = Math.max.apply(Math, _rollupPluginBabelHelpers.toConsumableArray(nums));
620
620
  }
621
621
  }
622
-
623
- // Sensible default values
624
- var defaultValue = void 0;
625
- if (stateType === 'binary') {
626
- defaultValue = 0;
627
- } else if (stateType === 'enum') {
628
- var _stateConfig$options$, _stateConfig$options;
629
- defaultValue = (_stateConfig$options$ = (_stateConfig$options = stateConfig.options) === null || _stateConfig$options === void 0 ? void 0 : _stateConfig$options[0]) !== null && _stateConfig$options$ !== void 0 ? _stateConfig$options$ : '';
630
- } else {
631
- var _stateConfig$min;
632
- defaultValue = (_stateConfig$min = stateConfig.min) !== null && _stateConfig$min !== void 0 ? _stateConfig$min : 0;
633
- }
622
+ var defaultValue = behaviorSchema.resolveAnimationDefaultValue(_anim);
634
623
  dps.push({
635
624
  id: stateVar,
636
625
  name: _anim.name || stateVar,
@@ -514,8 +514,8 @@ var transformControls = /*#__PURE__*/function (_THREE$Object3D) {
514
514
  }, {
515
515
  key: "setMode",
516
516
  value: function setMode(mode) {
517
- if (mode === 'scale') {
518
- console.warn('transformControls: Scale mode has been removed. Using translate mode instead.');
517
+ if (mode !== 'translate') {
518
+ console.warn("transformControls: ".concat(mode, " mode is disabled. Locking to translate."));
519
519
  mode = 'translate';
520
520
  }
521
521
  this.mode = mode;
@@ -439,10 +439,6 @@ var TransformControlsManager = /*#__PURE__*/function () {
439
439
  // Translate mode
440
440
  _this3.setMode('translate');
441
441
  break;
442
- case 'KeyR':
443
- // Rotate mode
444
- _this3.setMode('rotate');
445
- break;
446
442
  }
447
443
  };
448
444
  window.addEventListener('keydown', this.eventHandlers.keydown);
@@ -1462,9 +1458,10 @@ var TransformControlsManager = /*#__PURE__*/function () {
1462
1458
  }, {
1463
1459
  key: "setMode",
1464
1460
  value: function setMode(mode) {
1465
- if (!['translate', 'rotate', 'scale'].includes(mode)) {
1466
- console.warn("\u26A0\uFE0F Invalid transform mode: ".concat(mode));
1467
- return;
1461
+ // Only allow translate mode - lock rotation and scale controls
1462
+ if (mode !== 'translate') {
1463
+ console.warn("\u26A0\uFE0F Transform mode ".concat(mode, " is disabled. Locking to translate."));
1464
+ mode = 'translate';
1468
1465
  }
1469
1466
  var previousMode = this.currentMode;
1470
1467
  this.currentMode = mode;
@@ -78,7 +78,7 @@ var ModelManager = /*#__PURE__*/function () {
78
78
  key: "loadLibraryModel",
79
79
  value: function () {
80
80
  var _loadLibraryModel = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(targetMesh, jsonEntry, componentData) {
81
- var component, _jsonEntry$userData, _jsonEntry$userData2, _jsonEntry$userData3, originalProps, connectorChildren, gltfScene, libraryModel, _this$sceneViewer, ioBehavMgr, warmFn, _jsonEntry$userData4, _t;
81
+ var component, _jsonEntry$userData, _jsonEntry$userData2, _jsonEntry$userData3, originalProps, connectorChildren, gltfScene, libraryModel, _this$sceneViewer, ioBehavMgr, _this$sceneViewer2, warmFn, _jsonEntry$userData4, _t;
82
82
  return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
83
83
  while (1) switch (_context.n) {
84
84
  case 0:
@@ -123,7 +123,7 @@ var ModelManager = /*#__PURE__*/function () {
123
123
  case 4:
124
124
  ioBehavMgr = (_this$sceneViewer = this.sceneViewer) === null || _this$sceneViewer === void 0 || (_this$sceneViewer = _this$sceneViewer.managers) === null || _this$sceneViewer === void 0 ? void 0 : _this$sceneViewer.ioBehaviorManager;
125
125
  if (ioBehavMgr) {
126
- behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, originalProps.uuid, componentData, libraryModel, modelPreloader["default"].componentDictionary);
126
+ behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, originalProps.uuid, componentData, libraryModel, modelPreloader["default"].componentDictionary, (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.centralPlant);
127
127
  }
128
128
  case 5:
129
129
  // Replace mesh in scene
@@ -33,13 +33,14 @@ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
33
33
  /**
34
34
  * @param {THREE.Object3D} modelRoot
35
35
  * @param {{ x?: number, y?: number, z?: number }|THREE.Vector3} offset
36
+ * @param {THREE.Quaternion} [customQuat] - Optional override for model orientation
36
37
  * @returns {THREE.Vector3}
37
38
  */
38
- function modelOffsetToWorldDelta(modelRoot, offset) {
39
+ function modelOffsetToWorldDelta(modelRoot, offset, customQuat) {
39
40
  var _offset$x, _offset$y, _offset$z;
40
41
  var v = offset instanceof THREE__namespace.Vector3 ? offset.clone() : new THREE__namespace.Vector3((_offset$x = offset === null || offset === void 0 ? void 0 : offset.x) !== null && _offset$x !== void 0 ? _offset$x : 0, (_offset$y = offset === null || offset === void 0 ? void 0 : offset.y) !== null && _offset$y !== void 0 ? _offset$y : 0, (_offset$z = offset === null || offset === void 0 ? void 0 : offset.z) !== null && _offset$z !== void 0 ? _offset$z : 0);
41
- var q = new THREE__namespace.Quaternion();
42
- modelRoot.getWorldQuaternion(q);
42
+ var q = customQuat ? customQuat.clone() : new THREE__namespace.Quaternion();
43
+ if (!customQuat) modelRoot.getWorldQuaternion(q);
43
44
  return v.applyQuaternion(q);
44
45
  }
45
46
 
@@ -50,14 +51,15 @@ function modelOffsetToWorldDelta(modelRoot, offset) {
50
51
  * @param {THREE.Object3D} modelRoot
51
52
  * @param {THREE.Vector3} origLocalPos
52
53
  * @param {{ x?: number, y?: number, z?: number }} modelOffset
54
+ * @param {THREE.Quaternion} [customQuat]
53
55
  */
54
- function applyModelRootTranslation(mesh, modelRoot, origLocalPos, modelOffset) {
56
+ function applyModelRootTranslation(mesh, modelRoot, origLocalPos, modelOffset, customQuat) {
55
57
  if (!mesh || !modelRoot || !origLocalPos) return;
56
58
  mesh.position.copy(origLocalPos);
57
59
  mesh.updateMatrixWorld(true);
58
60
  var origWorldPos = new THREE__namespace.Vector3();
59
61
  mesh.getWorldPosition(origWorldPos);
60
- var newWorldPos = origWorldPos.add(modelOffsetToWorldDelta(modelRoot, modelOffset));
62
+ var newWorldPos = origWorldPos.add(modelOffsetToWorldDelta(modelRoot, modelOffset, customQuat));
61
63
  if (mesh.parent) mesh.parent.worldToLocal(newWorldPos);
62
64
  mesh.position.copy(newWorldPos);
63
65
  }
@@ -69,10 +71,11 @@ function applyModelRootTranslation(mesh, modelRoot, origLocalPos, modelOffset) {
69
71
  * @param {THREE.Object3D} modelRoot
70
72
  * @param {THREE.Vector3} baseWorldPos
71
73
  * @param {{ x?: number, y?: number, z?: number }} modelOffset
74
+ * @param {THREE.Quaternion} [customQuat]
72
75
  */
73
- function applyModelRootTranslationFromWorldBase(mesh, modelRoot, baseWorldPos, modelOffset) {
76
+ function applyModelRootTranslationFromWorldBase(mesh, modelRoot, baseWorldPos, modelOffset, customQuat) {
74
77
  if (!mesh || !modelRoot || !baseWorldPos) return;
75
- var newWorldPos = baseWorldPos.clone().add(modelOffsetToWorldDelta(modelRoot, modelOffset));
78
+ var newWorldPos = baseWorldPos.clone().add(modelOffsetToWorldDelta(modelRoot, modelOffset, customQuat));
76
79
  if (mesh.parent) mesh.parent.worldToLocal(newWorldPos);
77
80
  mesh.position.copy(newWorldPos);
78
81
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
+
5
7
  /**
6
8
  * Shared I/O device state dispatch helpers used by centralPlant and componentTooltipManager.
7
9
  */
@@ -57,6 +59,68 @@ function resolveDataPoints(parentUuid, attachmentId, userData, ioBehaviorManager
57
59
  });
58
60
  }
59
61
 
62
+ /**
63
+ * Apply persisted default values for I/O device animation states in the live scene.
64
+ * Updates the state adapter (e.g. Vuex) and drives mesh animations via IoBehaviorManager.
65
+ *
66
+ * @param {Object} centralPlant
67
+ * @param {{ parentUuid?: string, attachmentId?: string }} [options]
68
+ */
69
+ function applyDefaultIoDeviceStates(centralPlant) {
70
+ var _centralPlant$sceneVi;
71
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
+ var parentUuid = options.parentUuid,
73
+ attachmentId = options.attachmentId;
74
+ var ioBehavMgr = getIoBehaviorManager(centralPlant === null || centralPlant === void 0 ? void 0 : centralPlant.sceneViewer);
75
+ var scene = centralPlant === null || centralPlant === void 0 || (_centralPlant$sceneVi = centralPlant.sceneViewer) === null || _centralPlant$sceneVi === void 0 ? void 0 : _centralPlant$sceneVi.scene;
76
+ if (!ioBehavMgr || !scene || typeof (centralPlant === null || centralPlant === void 0 ? void 0 : centralPlant.setIoDeviceState) !== 'function') return;
77
+ var seen = new Set();
78
+ scene.traverse(function (obj) {
79
+ var _obj$userData, _obj$parent;
80
+ if (((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.objectType) !== 'io-device') return;
81
+ var objParentUuid = obj.userData.parentComponentId || ((_obj$parent = obj.parent) === null || _obj$parent === void 0 ? void 0 : _obj$parent.uuid);
82
+ var objAttachmentId = obj.userData.attachmentId;
83
+ if (!objParentUuid || !objAttachmentId) return;
84
+ if (parentUuid && objParentUuid !== parentUuid) return;
85
+ if (attachmentId && objAttachmentId !== attachmentId) return;
86
+ var scopedKey = getScopedAttachmentKey(objAttachmentId, objParentUuid);
87
+ if (seen.has(scopedKey)) return;
88
+ seen.add(scopedKey);
89
+ var dps = ioBehavMgr.getAnimationDataPoints(objParentUuid, objAttachmentId) || [];
90
+ if (dps.length) {
91
+ var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(dps),
92
+ _step;
93
+ try {
94
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
95
+ var dp = _step.value;
96
+ if (!(dp !== null && dp !== void 0 && dp.id) || dp.defaultValue === undefined || dp.defaultValue === null) continue;
97
+ centralPlant.setIoDeviceState(objAttachmentId, dp.id, dp.defaultValue, objParentUuid);
98
+ }
99
+ } catch (err) {
100
+ _iterator.e(err);
101
+ } finally {
102
+ _iterator.f();
103
+ }
104
+ return;
105
+ }
106
+ var _iterator2 = _rollupPluginBabelHelpers.createForOfIteratorHelper(obj.userData.dataPoints || []),
107
+ _step2;
108
+ try {
109
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
110
+ var _dp = _step2.value;
111
+ var dpId = _dp.id || _dp.name;
112
+ if (!dpId || _dp.defaultValue === undefined || _dp.defaultValue === null) continue;
113
+ centralPlant.setIoDeviceState(objAttachmentId, dpId, _dp.defaultValue, objParentUuid);
114
+ }
115
+ } catch (err) {
116
+ _iterator2.e(err);
117
+ } finally {
118
+ _iterator2.f();
119
+ }
120
+ });
121
+ }
122
+
123
+ exports.applyDefaultIoDeviceStates = applyDefaultIoDeviceStates;
60
124
  exports.getIoBehaviorManager = getIoBehaviorManager;
61
125
  exports.getScopedAttachmentKey = getScopedAttachmentKey;
62
126
  exports.resolveDataPoints = resolveDataPoints;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var behaviorDispatch = require('./behaviorDispatch.js');
6
7
 
7
8
  /**
8
9
  * Register mesh animations and intra-component state links when a smart
@@ -13,8 +14,9 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
13
14
  * @param {Object} componentData - Smart component dictionary entry
14
15
  * @param {Object} componentModel - Root THREE.Object3D of the placed component
15
16
  * @param {Object} componentDictionary - modelPreloader.componentDictionary
17
+ * @param {Object} [centralPlant] - When provided, default animation states are applied after registration
16
18
  */
17
- function registerBehaviorsForComponent(ioBehavMgr, componentUuid, componentData, componentModel, componentDictionary) {
19
+ function registerBehaviorsForComponent(ioBehavMgr, componentUuid, componentData, componentModel, componentDictionary, centralPlant) {
18
20
  var _componentData$behavi;
19
21
  if (!ioBehavMgr || !componentData || !componentModel) {
20
22
  return;
@@ -44,6 +46,11 @@ function registerBehaviorsForComponent(ioBehavMgr, componentUuid, componentData,
44
46
  } else if (componentData.isSmart) {
45
47
  ioBehavMgr.registerComponentBehaviors(componentUuid, []);
46
48
  }
49
+ if (centralPlant) {
50
+ behaviorDispatch.applyDefaultIoDeviceStates(centralPlant, {
51
+ parentUuid: componentUuid
52
+ });
53
+ }
47
54
  }
48
55
 
49
56
  /**
@@ -69,6 +76,10 @@ function reloadBehaviorsForDeviceAsset(ioBehavMgr, deviceAssetId, componentDicti
69
76
  if (!parentUuid || !attachmentId) return;
70
77
  ioBehavMgr.unloadForAttachment(parentUuid, attachmentId);
71
78
  ioBehavMgr.loadBehaviors(attachmentId, deviceData.behaviorConfig, obj, parentUuid);
79
+ behaviorDispatch.applyDefaultIoDeviceStates(centralPlant, {
80
+ parentUuid: parentUuid,
81
+ attachmentId: attachmentId
82
+ });
72
83
  });
73
84
  }
74
85
 
@@ -144,7 +144,7 @@ function reregisterSceneBehaviors(centralPlant) {
144
144
  if (!libraryId) return;
145
145
  var componentData = dict[libraryId];
146
146
  if (!componentData) return;
147
- behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, obj.uuid, componentData, obj, dict);
147
+ behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, obj.uuid, componentData, obj, dict, centralPlant);
148
148
  });
149
149
  }
150
150
 
@@ -202,8 +202,56 @@ function parseCrossBehavior(behavior) {
202
202
  };
203
203
  }
204
204
 
205
+ /**
206
+ * Resolve the runtime default value for an animation behavior entry.
207
+ * Uses explicit `defaultValue` when present; otherwise infers from stateType and mappings.
208
+ *
209
+ * @param {Object} anim - Behavior entry from behaviorConfig
210
+ * @returns {boolean|string|number}
211
+ */
212
+ function resolveAnimationDefaultValue(anim) {
213
+ var _anim$stateConfig2, _anim$stateConfig3;
214
+ if (!anim) return null;
215
+ var rawType = (anim.stateType || '').toLowerCase();
216
+ var isBinary = rawType === 'binary' || rawType === 'boolean';
217
+ var isEnum = rawType === 'enum';
218
+ if (anim.defaultValue !== undefined && anim.defaultValue !== null) {
219
+ if (isBinary) return !!anim.defaultValue;
220
+ if (isEnum) return String(anim.defaultValue);
221
+ var n = Number(anim.defaultValue);
222
+ return Number.isNaN(n) ? 0 : n;
223
+ }
224
+ if (isBinary) return false;
225
+ if (isEnum) {
226
+ var _anim$stateConfig, _resolved$;
227
+ var _mappingValues = (anim.mappings || []).map(function (m) {
228
+ return m.stateValue;
229
+ }).filter(function (v) {
230
+ return v !== '' && v != null;
231
+ });
232
+ var options = (((_anim$stateConfig = anim.stateConfig) === null || _anim$stateConfig === void 0 ? void 0 : _anim$stateConfig.options) || []).filter(function (o) {
233
+ return o !== '';
234
+ });
235
+ var resolved = options.length ? options : _rollupPluginBabelHelpers.toConsumableArray(new Set(_mappingValues.map(String)));
236
+ return (_resolved$ = resolved[0]) !== null && _resolved$ !== void 0 ? _resolved$ : '';
237
+ }
238
+ var mappingValues = (anim.mappings || []).map(function (m) {
239
+ return m.stateValue;
240
+ });
241
+ var nums = mappingValues.map(Number).filter(function (n) {
242
+ return !Number.isNaN(n);
243
+ });
244
+ if (nums.length) return Math.min.apply(Math, _rollupPluginBabelHelpers.toConsumableArray(nums));
245
+ if (((_anim$stateConfig2 = anim.stateConfig) === null || _anim$stateConfig2 === void 0 ? void 0 : _anim$stateConfig2.min) !== undefined && ((_anim$stateConfig3 = anim.stateConfig) === null || _anim$stateConfig3 === void 0 ? void 0 : _anim$stateConfig3.min) !== null) {
246
+ var min = Number(anim.stateConfig.min);
247
+ return Number.isNaN(min) ? 0 : min;
248
+ }
249
+ return 0;
250
+ }
251
+
205
252
  exports.buildCrossBehavior = buildCrossBehavior;
206
253
  exports.buildIntraBehavior = buildIntraBehavior;
207
254
  exports.normalizeBehavior = normalizeBehavior;
208
255
  exports.parseCrossBehavior = parseCrossBehavior;
209
256
  exports.parseIntraBehavior = parseIntraBehavior;
257
+ exports.resolveAnimationDefaultValue = resolveAnimationDefaultValue;
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
+
7
+ var _excluded = ["componentDefinitions"];
8
+ /**
9
+ * Helpers for portable demo scene JSON (embedded component definitions).
10
+ */
11
+
12
+ function cloneDefinition(def) {
13
+ if (!def || _rollupPluginBabelHelpers["typeof"](def) !== 'object') return null;
14
+ try {
15
+ return JSON.parse(JSON.stringify(def));
16
+ } catch (_unused) {
17
+ return _rollupPluginBabelHelpers.objectSpread2({}, def);
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Collect unique library IDs referenced by scene nodes.
23
+ * @param {Object} sceneData
24
+ * @returns {string[]}
25
+ */
26
+ function collectSceneLibraryIds(sceneData) {
27
+ var _sceneData$scene;
28
+ var ids = new Set();
29
+ var _walk = function walk(nodes) {
30
+ if (!Array.isArray(nodes)) return;
31
+ nodes.forEach(function (node) {
32
+ var _node$userData;
33
+ var libraryId = node === null || node === void 0 || (_node$userData = node.userData) === null || _node$userData === void 0 ? void 0 : _node$userData.libraryId;
34
+ if (libraryId) ids.add(libraryId);
35
+ if (node.children) _walk(node.children);
36
+ });
37
+ };
38
+ _walk(sceneData === null || sceneData === void 0 || (_sceneData$scene = sceneData.scene) === null || _sceneData$scene === void 0 ? void 0 : _sceneData$scene.children);
39
+ return Array.from(ids);
40
+ }
41
+
42
+ /**
43
+ * Embed component/device definitions required by a scene into the JSON payload.
44
+ * @param {Object} sceneData
45
+ * @param {Record<string, Object>} componentDictionary
46
+ * @returns {Object}
47
+ */
48
+ function embedComponentDefinitions(sceneData) {
49
+ var componentDictionary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
50
+ if (!sceneData || _rollupPluginBabelHelpers["typeof"](sceneData) !== 'object') return sceneData;
51
+ var libraryIds = collectSceneLibraryIds(sceneData);
52
+ var componentDefinitions = {};
53
+ var deviceIds = new Set();
54
+ libraryIds.forEach(function (libraryId) {
55
+ var def = componentDictionary[libraryId];
56
+ if (!def) return;
57
+ componentDefinitions[libraryId] = cloneDefinition(def);
58
+ var attachedDevices = def.attachedDevices;
59
+ if (!attachedDevices || _rollupPluginBabelHelpers["typeof"](attachedDevices) !== 'object') return;
60
+ Object.values(attachedDevices).forEach(function (att) {
61
+ if (att !== null && att !== void 0 && att.deviceId) deviceIds.add(att.deviceId);
62
+ });
63
+ });
64
+ deviceIds.forEach(function (deviceId) {
65
+ if (componentDefinitions[deviceId]) return;
66
+ var deviceDef = componentDictionary[deviceId];
67
+ if (deviceDef) componentDefinitions[deviceId] = cloneDefinition(deviceDef);
68
+ });
69
+ if (!Object.keys(componentDefinitions).length) {
70
+ sceneData.componentDefinitions;
71
+ var rest = _rollupPluginBabelHelpers.objectWithoutProperties(sceneData, _excluded);
72
+ return rest;
73
+ }
74
+ return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, sceneData), {}, {
75
+ componentDefinitions: componentDefinitions
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Resolve the live component dictionary from a CentralPlant instance.
81
+ * @param {Object} centralPlant
82
+ * @returns {Record<string, Object>}
83
+ */
84
+ function getComponentDictionary(centralPlant) {
85
+ var _centralPlant$getUtil, _centralPlant$manager;
86
+ return (centralPlant === null || centralPlant === void 0 || (_centralPlant$getUtil = centralPlant.getUtility) === null || _centralPlant$getUtil === void 0 || (_centralPlant$getUtil = _centralPlant$getUtil.call(centralPlant, 'modelPreloader')) === null || _centralPlant$getUtil === void 0 ? void 0 : _centralPlant$getUtil.componentDictionary) || (centralPlant === null || centralPlant === void 0 || (_centralPlant$manager = centralPlant.managers) === null || _centralPlant$manager === void 0 || (_centralPlant$manager = _centralPlant$manager.componentDataManager) === null || _centralPlant$manager === void 0 ? void 0 : _centralPlant$manager.componentDictionary) || {};
87
+ }
88
+
89
+ exports.collectSceneLibraryIds = collectSceneLibraryIds;
90
+ exports.embedComponentDefinitions = embedComponentDefinitions;
91
+ exports.getComponentDictionary = getComponentDictionary;