@2112-lab/central-plant 0.3.27 → 0.3.29
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 +82 -911
- package/dist/cjs/src/core/centralPlant.js +8 -115
- package/dist/cjs/src/core/centralPlantInternals.js +13 -24
- package/dist/cjs/src/core/sceneViewer.js +4 -4
- package/dist/cjs/src/index.js +2 -4
- package/dist/cjs/src/managers/behaviors/IoBehaviorManager.js +571 -0
- package/dist/cjs/src/managers/scene/componentTooltipManager.js +17 -24
- package/dist/cjs/src/managers/scene/modelManager.js +8 -8
- package/dist/cjs/src/managers/scene/sceneExportManager.js +3 -29
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +12 -289
- package/dist/esm/src/core/centralPlant.js +8 -115
- package/dist/esm/src/core/centralPlantInternals.js +13 -24
- package/dist/esm/src/core/sceneViewer.js +4 -4
- package/dist/esm/src/index.js +1 -2
- package/dist/esm/src/managers/behaviors/IoBehaviorManager.js +547 -0
- package/dist/esm/src/managers/scene/componentTooltipManager.js +17 -24
- package/dist/esm/src/managers/scene/modelManager.js +8 -8
- package/dist/esm/src/managers/scene/sceneExportManager.js +4 -30
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +12 -289
- package/package.json +1 -1
|
@@ -53,7 +53,7 @@ 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, _this$sceneViewer,
|
|
56
|
+
var component, _jsonEntry$userData, _jsonEntry$userData2, _jsonEntry$userData3, originalProps, connectorChildren, gltfScene, libraryModel, _this$sceneViewer, ioBehavMgr, _loop, _i, _Object$entries, warmFn, _jsonEntry$userData4, _t;
|
|
57
57
|
return _regenerator().w(function (_context2) {
|
|
58
58
|
while (1) switch (_context2.n) {
|
|
59
59
|
case 0:
|
|
@@ -96,22 +96,22 @@ var ModelManager = /*#__PURE__*/function () {
|
|
|
96
96
|
_context2.n = 4;
|
|
97
97
|
return attachIODevicesToComponent(libraryModel, componentData, modelPreloader, originalProps.uuid);
|
|
98
98
|
case 4:
|
|
99
|
-
// Register
|
|
100
|
-
|
|
101
|
-
if (!
|
|
99
|
+
// Register behavior configs for each attached device
|
|
100
|
+
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;
|
|
101
|
+
if (!ioBehavMgr) {
|
|
102
102
|
_context2.n = 8;
|
|
103
103
|
break;
|
|
104
104
|
}
|
|
105
105
|
_loop = /*#__PURE__*/_regenerator().m(function _loop() {
|
|
106
|
-
var _modelPreloader$compo, _deviceData$
|
|
106
|
+
var _modelPreloader$compo, _deviceData$behaviorC;
|
|
107
107
|
var _Object$entries$_i, attachmentId, attachment, deviceData, deviceRoot;
|
|
108
108
|
return _regenerator().w(function (_context) {
|
|
109
109
|
while (1) switch (_context.n) {
|
|
110
110
|
case 0:
|
|
111
111
|
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), attachmentId = _Object$entries$_i[0], attachment = _Object$entries$_i[1];
|
|
112
112
|
deviceData = (_modelPreloader$compo = modelPreloader.componentDictionary) === null || _modelPreloader$compo === void 0 ? void 0 : _modelPreloader$compo[attachment.deviceId];
|
|
113
|
-
console.log("[ModelManager] attachment \"".concat(attachmentId, "\" \u2192 deviceId \"").concat(attachment.deviceId, "\" \u2192
|
|
114
|
-
if (deviceData !== null && deviceData !== void 0 && deviceData.
|
|
113
|
+
console.log("[ModelManager] attachment \"".concat(attachmentId, "\" \u2192 deviceId \"").concat(attachment.deviceId, "\" \u2192 behaviorConfig:"), (_deviceData$behaviorC = deviceData === null || deviceData === void 0 ? void 0 : deviceData.behaviorConfig) !== null && _deviceData$behaviorC !== void 0 ? _deviceData$behaviorC : 'NONE');
|
|
114
|
+
if (deviceData !== null && deviceData !== void 0 && deviceData.behaviorConfig) {
|
|
115
115
|
_context.n = 1;
|
|
116
116
|
break;
|
|
117
117
|
}
|
|
@@ -123,7 +123,7 @@ var ModelManager = /*#__PURE__*/function () {
|
|
|
123
123
|
if (!deviceRoot && ((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.attachmentId) === attachmentId) deviceRoot = obj;
|
|
124
124
|
});
|
|
125
125
|
if (deviceRoot) {
|
|
126
|
-
|
|
126
|
+
ioBehavMgr.loadBehaviors(attachmentId, deviceData.behaviorConfig, deviceRoot, originalProps.uuid);
|
|
127
127
|
}
|
|
128
128
|
case 2:
|
|
129
129
|
return _context.a(2);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createClass as _createClass,
|
|
1
|
+
import { createClass as _createClass, classCallCheck as _classCallCheck, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import 'three';
|
|
3
3
|
import { GLTFExporter } from '../../../node_modules/three/examples/jsm/exporters/GLTFExporter.js';
|
|
4
4
|
import { getHardcodedUuid } from '../../utils/nameUtils.js';
|
|
@@ -259,40 +259,14 @@ var SceneExportManager = /*#__PURE__*/function () {
|
|
|
259
259
|
}
|
|
260
260
|
});
|
|
261
261
|
|
|
262
|
-
// Helper function to extract behaviors from current scene data
|
|
263
|
-
var extractBehaviors = function extractBehaviors() {
|
|
264
|
-
var _this$sceneViewer, _this$sceneViewer2;
|
|
265
|
-
// Only export behaviors that are NOT re-derivable from a component's
|
|
266
|
-
// defaultBehaviors[]. All component/device default behaviors are
|
|
267
|
-
// reconstructed at load time by Step B of _processBehaviors() using the
|
|
268
|
-
// component dictionary, so writing compact behaviorRef entries for them
|
|
269
|
-
// would be redundant. The scene JSON behaviors[] array is reserved for
|
|
270
|
-
// any future scene-level overrides that cannot be derived from the asset.
|
|
271
|
-
if ((_this$sceneViewer = _this.sceneViewer) !== null && _this$sceneViewer !== void 0 && (_this$sceneViewer = _this$sceneViewer.managers) !== null && _this$sceneViewer !== void 0 && _this$sceneViewer.behaviorManager) {
|
|
272
|
-
return _this.sceneViewer.managers.behaviorManager.getBehaviors().filter(function (b) {
|
|
273
|
-
return !b._isDefaultBehavior;
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
// Fallback when BehaviorManager is not available: exclude any entry that
|
|
277
|
-
// was already a behaviorRef (it was derivable from the component asset)
|
|
278
|
-
// and exclude the legacy _isDefaultBehavior marker if present.
|
|
279
|
-
return (((_this$sceneViewer2 = _this.sceneViewer) === null || _this$sceneViewer2 === void 0 || (_this$sceneViewer2 = _this$sceneViewer2.currentSceneData) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.behaviors) || []).filter(function (b) {
|
|
280
|
-
return !b.behaviorRef && !b._isDefaultBehavior;
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
|
|
284
262
|
// Build the complete export data structure (matching central-plant-input.json format)
|
|
285
|
-
var
|
|
286
|
-
var exportData = _objectSpread2(_objectSpread2({
|
|
263
|
+
var exportData = {
|
|
287
264
|
version: '2.3',
|
|
288
|
-
connections: extractConnections()
|
|
289
|
-
}, behaviors.length > 0 ? {
|
|
290
|
-
behaviors: behaviors
|
|
291
|
-
} : {}), {}, {
|
|
265
|
+
connections: extractConnections(),
|
|
292
266
|
scene: {
|
|
293
267
|
children: sceneChildren
|
|
294
268
|
}
|
|
295
|
-
}
|
|
269
|
+
};
|
|
296
270
|
console.log('✅ Scene export completed:', exportData);
|
|
297
271
|
console.log("\uD83D\uDCCA Exported ".concat(sceneChildren.length, " components and ").concat(exportData.connections.length, " connections"));
|
|
298
272
|
return exportData;
|
|
@@ -737,13 +737,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
737
737
|
phaseStart = performance.now();
|
|
738
738
|
this._finalizeScene(data, crosscubeTextureSet, isImported);
|
|
739
739
|
timers.phase5_finalize = performance.now() - phaseStart;
|
|
740
|
-
|
|
741
|
-
// Phase 6: Load behaviors (after GLB models are present so output objects can be resolved)
|
|
742
|
-
phaseStart = performance.now();
|
|
743
|
-
this._processBehaviors(data);
|
|
744
|
-
timers.phase6_behaviors = performance.now() - phaseStart;
|
|
745
740
|
totalTime = performance.now() - totalStart;
|
|
746
|
-
console.log("\u23F1\uFE0F Scene Loading Performance:\n Phase 1 (Prepare) : ".concat(timers.phase1_prepare.toFixed(0), "ms\n Phase 2 (Create Objects): ").concat(timers.phase2_createObjects.toFixed(0), "ms\n Phase 3 (GLB Models) : ").concat(timers.phase3_glbModels.toFixed(0), "ms\n Phase 4 (Pathfinding) : ").concat(timers.phase4_pathfinding.toFixed(0), "ms\n Phase 5 (Finalize) : ").concat(timers.phase5_finalize.toFixed(0), "ms\n
|
|
741
|
+
console.log("\u23F1\uFE0F Scene Loading Performance:\n Phase 1 (Prepare) : ".concat(timers.phase1_prepare.toFixed(0), "ms\n Phase 2 (Create Objects): ").concat(timers.phase2_createObjects.toFixed(0), "ms\n Phase 3 (GLB Models) : ").concat(timers.phase3_glbModels.toFixed(0), "ms\n Phase 4 (Pathfinding) : ").concat(timers.phase4_pathfinding.toFixed(0), "ms\n Phase 5 (Finalize) : ").concat(timers.phase5_finalize.toFixed(0), "ms\n \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n Total : ").concat(totalTime.toFixed(0), "ms"));
|
|
747
742
|
console.log('✅ Scene loaded successfully');
|
|
748
743
|
|
|
749
744
|
// Notify UI components (e.g. SceneHierarchy) that the scene is fully loaded
|
|
@@ -1101,278 +1096,6 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1101
1096
|
}
|
|
1102
1097
|
}
|
|
1103
1098
|
|
|
1104
|
-
/**
|
|
1105
|
-
* Process behaviors from the scene data, expand any defaultBehaviors defined
|
|
1106
|
-
* on component dictionary entries, resolve behaviorRef entries against device
|
|
1107
|
-
* assets, inject per-instance component UUIDs, and hand the flat resolved
|
|
1108
|
-
* array to BehaviorManager.
|
|
1109
|
-
*
|
|
1110
|
-
* Resolution cascade:
|
|
1111
|
-
* 1. Explicit behaviors in data.behaviors — passed through as-is (behaviorRef
|
|
1112
|
-
* entries are resolved against the component/device dictionaries).
|
|
1113
|
-
* 2. defaultBehaviors[] on each placed smart component's dictionary entry —
|
|
1114
|
-
* expanded per instance with the instance UUID injected. Compact
|
|
1115
|
-
* behaviorRef-derived entries are tagged _isDefaultBehavior:true (the
|
|
1116
|
-
* exporter can re-derive them); full L2 behavior objects are tagged false
|
|
1117
|
-
* so they are exported verbatim and survive round-trips.
|
|
1118
|
-
*
|
|
1119
|
-
* @param {Object} data - Scene JSON data
|
|
1120
|
-
*/
|
|
1121
|
-
}, {
|
|
1122
|
-
key: "_processBehaviors",
|
|
1123
|
-
value: function _processBehaviors(data) {
|
|
1124
|
-
var _this$sceneViewer2,
|
|
1125
|
-
_this$sceneViewer$cen2,
|
|
1126
|
-
_this5 = this,
|
|
1127
|
-
_data$scene3;
|
|
1128
|
-
var behaviorManager = (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 || (_this$sceneViewer2 = _this$sceneViewer2.managers) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.behaviorManager;
|
|
1129
|
-
if (!behaviorManager) {
|
|
1130
|
-
console.warn('⚠️ _processBehaviors: BehaviorManager not available');
|
|
1131
|
-
return;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
// Obtain the component dictionary (extended = includes S3/smart components)
|
|
1135
|
-
var componentDictionary = ((_this$sceneViewer$cen2 = this.sceneViewer.centralPlant) === null || _this$sceneViewer$cen2 === void 0 || (_this$sceneViewer$cen2 = _this$sceneViewer$cen2.managers) === null || _this$sceneViewer$cen2 === void 0 || (_this$sceneViewer$cen2 = _this$sceneViewer$cen2.componentDataManager) === null || _this$sceneViewer$cen2 === void 0 ? void 0 : _this$sceneViewer$cen2.componentDictionary) || {};
|
|
1136
|
-
|
|
1137
|
-
// ── Step A: Resolve any behaviorRef entries from data.behaviors ─────────
|
|
1138
|
-
var explicitBehaviors = [];
|
|
1139
|
-
if (Array.isArray(data === null || data === void 0 ? void 0 : data.behaviors)) {
|
|
1140
|
-
data.behaviors.forEach(function (entry) {
|
|
1141
|
-
if (entry.behaviorRef) {
|
|
1142
|
-
var resolved = _this5._resolveBehaviorRef(entry, componentDictionary);
|
|
1143
|
-
if (resolved) explicitBehaviors.push(resolved);
|
|
1144
|
-
} else {
|
|
1145
|
-
explicitBehaviors.push(entry);
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
// Build a set of explicit behavior ids for deduplication
|
|
1151
|
-
var explicitIds = new Set(explicitBehaviors.map(function (b) {
|
|
1152
|
-
return b.id;
|
|
1153
|
-
}));
|
|
1154
|
-
|
|
1155
|
-
// Build a set of (component::attachment::state) tuples covered by explicit
|
|
1156
|
-
// behaviors. If an expanded default behavior would produce the SAME input
|
|
1157
|
-
// tuple, the explicit behavior is treated as the intentional override and
|
|
1158
|
-
// the default expansion is skipped. This prevents a component's built-in
|
|
1159
|
-
// switch→LED wiring from doubling-up when the user has deliberately authored
|
|
1160
|
-
// cross-component behaviors that re-wire the same switch.
|
|
1161
|
-
var explicitInputTuples = new Set(explicitBehaviors.filter(function (b) {
|
|
1162
|
-
var _b$input, _b$input2, _b$input3;
|
|
1163
|
-
return ((_b$input = b.input) === null || _b$input === void 0 ? void 0 : _b$input.component) && ((_b$input2 = b.input) === null || _b$input2 === void 0 ? void 0 : _b$input2.attachment) && ((_b$input3 = b.input) === null || _b$input3 === void 0 ? void 0 : _b$input3.state);
|
|
1164
|
-
}).map(function (b) {
|
|
1165
|
-
return "".concat(b.input.component, "::").concat(b.input.attachment, "::").concat(b.input.state);
|
|
1166
|
-
}));
|
|
1167
|
-
|
|
1168
|
-
// Build a set of instanceUuids already covered by behaviorRef entries in
|
|
1169
|
-
// data.behaviors (written by the exporter for smart component defaults).
|
|
1170
|
-
// Step B skips these instances to avoid loading the same behaviors twice —
|
|
1171
|
-
// once via Step A (resolved from data.behaviors refs) and once via Step B
|
|
1172
|
-
// (auto-expanded from the component dictionary).
|
|
1173
|
-
var coveredInstances = new Set();
|
|
1174
|
-
if (Array.isArray(data === null || data === void 0 ? void 0 : data.behaviors)) {
|
|
1175
|
-
data.behaviors.forEach(function (entry) {
|
|
1176
|
-
if (entry.behaviorRef && entry.component) {
|
|
1177
|
-
coveredInstances.add(entry.component);
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
// ── Step B: Walk placed components and expand their defaultBehaviors ─────
|
|
1183
|
-
var instanceBehaviors = [];
|
|
1184
|
-
if (Array.isArray(data === null || data === void 0 || (_data$scene3 = data.scene) === null || _data$scene3 === void 0 ? void 0 : _data$scene3.children)) {
|
|
1185
|
-
data.scene.children.forEach(function (child) {
|
|
1186
|
-
var _child$userData0, _compData$defaultBeha;
|
|
1187
|
-
var libraryId = (_child$userData0 = child.userData) === null || _child$userData0 === void 0 ? void 0 : _child$userData0.libraryId;
|
|
1188
|
-
if (!libraryId) return;
|
|
1189
|
-
var instanceUuid = child.uuid;
|
|
1190
|
-
// Skip instances whose defaults were already resolved by Step A
|
|
1191
|
-
// (they have explicit behaviorRef entries in data.behaviors).
|
|
1192
|
-
if (coveredInstances.has(instanceUuid)) return;
|
|
1193
|
-
var compData = componentDictionary[libraryId];
|
|
1194
|
-
if (!(compData !== null && compData !== void 0 && (_compData$defaultBeha = compData.defaultBehaviors) !== null && _compData$defaultBeha !== void 0 && _compData$defaultBeha.length)) return;
|
|
1195
|
-
compData.defaultBehaviors.forEach(function (template) {
|
|
1196
|
-
var _expanded$input, _expanded$input2, _expanded$input3;
|
|
1197
|
-
var expanded = _this5._expandDefaultBehavior(template, instanceUuid, componentDictionary);
|
|
1198
|
-
if (!expanded) return;
|
|
1199
|
-
// Skip if an explicit scene behavior already covers this id
|
|
1200
|
-
if (explicitIds.has(expanded.id)) return;
|
|
1201
|
-
// Skip if an explicit scene behavior already covers the same
|
|
1202
|
-
// (component, attachment, state) input tuple. This prevents a
|
|
1203
|
-
// component's built-in default wiring (e.g. switch → own LED) from
|
|
1204
|
-
// double-firing when the user has authored a cross-component override
|
|
1205
|
-
// that rewires the same switch to a different target.
|
|
1206
|
-
if ((_expanded$input = expanded.input) !== null && _expanded$input !== void 0 && _expanded$input.component && (_expanded$input2 = expanded.input) !== null && _expanded$input2 !== void 0 && _expanded$input2.attachment && (_expanded$input3 = expanded.input) !== null && _expanded$input3 !== void 0 && _expanded$input3.state) {
|
|
1207
|
-
var tuple = "".concat(expanded.input.component, "::").concat(expanded.input.attachment, "::").concat(expanded.input.state);
|
|
1208
|
-
if (explicitInputTuples.has(tuple)) return;
|
|
1209
|
-
}
|
|
1210
|
-
// All component defaultBehaviors are re-derivable from the component
|
|
1211
|
-
// asset at export time (via compact behaviorRef), so mark them all.
|
|
1212
|
-
expanded._isDefaultBehavior = true;
|
|
1213
|
-
instanceBehaviors.push(expanded);
|
|
1214
|
-
});
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
var allBehaviors = [].concat(explicitBehaviors, instanceBehaviors);
|
|
1218
|
-
if (allBehaviors.length === 0) return;
|
|
1219
|
-
behaviorManager.loadBehaviors(allBehaviors);
|
|
1220
|
-
console.log("\u2705 _processBehaviors: loaded ".concat(explicitBehaviors.length, " explicit + ").concat(instanceBehaviors.length, " default-expanded behavior(s)"));
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
/**
|
|
1224
|
-
* Register the defaultBehaviors of a single newly placed component instance
|
|
1225
|
-
* into the BehaviorManager. Called from addComponent() (drag-drop), where
|
|
1226
|
-
* _processBehaviors() (scene-load path) is not invoked.
|
|
1227
|
-
*
|
|
1228
|
-
* @param {Object} componentData - Entry from the component dictionary
|
|
1229
|
-
* @param {string} instanceUuid - UUID of the placed component (componentModel.uuid)
|
|
1230
|
-
*/
|
|
1231
|
-
}, {
|
|
1232
|
-
key: "registerBehaviorsForComponentInstance",
|
|
1233
|
-
value: function registerBehaviorsForComponentInstance(componentData, instanceUuid) {
|
|
1234
|
-
var _this$sceneViewer3,
|
|
1235
|
-
_componentData$defaul,
|
|
1236
|
-
_this$sceneViewer$cen3,
|
|
1237
|
-
_this6 = this;
|
|
1238
|
-
var behaviorManager = (_this$sceneViewer3 = this.sceneViewer) === null || _this$sceneViewer3 === void 0 || (_this$sceneViewer3 = _this$sceneViewer3.managers) === null || _this$sceneViewer3 === void 0 ? void 0 : _this$sceneViewer3.behaviorManager;
|
|
1239
|
-
if (!behaviorManager) return;
|
|
1240
|
-
if (!(componentData !== null && componentData !== void 0 && (_componentData$defaul = componentData.defaultBehaviors) !== null && _componentData$defaul !== void 0 && _componentData$defaul.length)) return;
|
|
1241
|
-
var componentDictionary = ((_this$sceneViewer$cen3 = this.sceneViewer.centralPlant) === null || _this$sceneViewer$cen3 === void 0 || (_this$sceneViewer$cen3 = _this$sceneViewer$cen3.managers) === null || _this$sceneViewer$cen3 === void 0 || (_this$sceneViewer$cen3 = _this$sceneViewer$cen3.componentDataManager) === null || _this$sceneViewer$cen3 === void 0 ? void 0 : _this$sceneViewer$cen3.componentDictionary) || {};
|
|
1242
|
-
var registered = 0;
|
|
1243
|
-
componentData.defaultBehaviors.forEach(function (template) {
|
|
1244
|
-
var expanded = _this6._expandDefaultBehavior(template, instanceUuid, componentDictionary);
|
|
1245
|
-
if (!expanded) return;
|
|
1246
|
-
expanded._isDefaultBehavior = true;
|
|
1247
|
-
behaviorManager.addBehavior(expanded);
|
|
1248
|
-
registered++;
|
|
1249
|
-
});
|
|
1250
|
-
if (registered > 0) {
|
|
1251
|
-
console.log("\u2705 registerBehaviorsForComponentInstance: registered ".concat(registered, " behavior(s) for instance ").concat(instanceUuid));
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
/**
|
|
1256
|
-
* Resolve a scene-level or component-level behaviorRef entry into a full
|
|
1257
|
-
* behavior definition by looking up the referenced template in the device
|
|
1258
|
-
* asset's defaultBehaviors[] and substituting 'self' with the real
|
|
1259
|
-
* attachmentId.
|
|
1260
|
-
*
|
|
1261
|
-
* Ref shape: { behaviorRef, deviceId, attachment, component? }
|
|
1262
|
-
*
|
|
1263
|
-
* @param {Object} ref
|
|
1264
|
-
* @param {Object} componentDictionary
|
|
1265
|
-
* @returns {Object|null} Resolved behavior or null if not found
|
|
1266
|
-
*/
|
|
1267
|
-
}, {
|
|
1268
|
-
key: "_resolveBehaviorRef",
|
|
1269
|
-
value: function _resolveBehaviorRef(ref, componentDictionary) {
|
|
1270
|
-
var _resolved$input, _resolved$output;
|
|
1271
|
-
if (!ref.behaviorRef) {
|
|
1272
|
-
console.warn('⚠️ _resolveBehaviorRef: missing behaviorRef', ref);
|
|
1273
|
-
return null;
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
// ── Component-level L2 ref: { behaviorRef, libraryId, component } ──────
|
|
1277
|
-
// The full behavior template lives on the smart component's defaultBehaviors[].
|
|
1278
|
-
// No 'self' substitution needed — attachment IDs are already real.
|
|
1279
|
-
if (ref.libraryId) {
|
|
1280
|
-
var compData = componentDictionary[ref.libraryId];
|
|
1281
|
-
if (!compData) {
|
|
1282
|
-
console.warn("\u26A0\uFE0F _resolveBehaviorRef: component \"".concat(ref.libraryId, "\" not in dictionary"));
|
|
1283
|
-
return null;
|
|
1284
|
-
}
|
|
1285
|
-
var _template = (compData.defaultBehaviors || []).find(function (b) {
|
|
1286
|
-
return b.id === ref.behaviorRef;
|
|
1287
|
-
});
|
|
1288
|
-
if (!_template) {
|
|
1289
|
-
console.warn("\u26A0\uFE0F _resolveBehaviorRef: behavior \"".concat(ref.behaviorRef, "\" not found on component \"").concat(ref.libraryId, "\""));
|
|
1290
|
-
return null;
|
|
1291
|
-
}
|
|
1292
|
-
var _resolved = JSON.parse(JSON.stringify(_template));
|
|
1293
|
-
_resolved.id = "".concat(_resolved.id, "::").concat(ref.component);
|
|
1294
|
-
if (ref.component) {
|
|
1295
|
-
_resolved.input = _objectSpread2(_objectSpread2({}, _resolved.input), {}, {
|
|
1296
|
-
component: ref.component
|
|
1297
|
-
});
|
|
1298
|
-
_resolved.output = _objectSpread2(_objectSpread2({}, _resolved.output), {}, {
|
|
1299
|
-
component: ref.component
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
return _resolved;
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
// ── Device-level L1 ref: { behaviorRef, deviceId, attachment, component } ─
|
|
1306
|
-
if (!ref.deviceId || !ref.attachment) {
|
|
1307
|
-
console.warn('⚠️ _resolveBehaviorRef: incomplete ref', ref);
|
|
1308
|
-
return null;
|
|
1309
|
-
}
|
|
1310
|
-
var deviceData = componentDictionary[ref.deviceId];
|
|
1311
|
-
if (!deviceData) {
|
|
1312
|
-
console.warn("\u26A0\uFE0F _resolveBehaviorRef: device \"".concat(ref.deviceId, "\" not in dictionary"));
|
|
1313
|
-
return null;
|
|
1314
|
-
}
|
|
1315
|
-
var template = (deviceData.defaultBehaviors || []).find(function (b) {
|
|
1316
|
-
return b.id === ref.behaviorRef;
|
|
1317
|
-
});
|
|
1318
|
-
if (!template) {
|
|
1319
|
-
console.warn("\u26A0\uFE0F _resolveBehaviorRef: behavior \"".concat(ref.behaviorRef, "\" not found on device \"").concat(ref.deviceId, "\""));
|
|
1320
|
-
return null;
|
|
1321
|
-
}
|
|
1322
|
-
// Deep clone and substitute 'self' -> real attachmentId
|
|
1323
|
-
var resolved = JSON.parse(JSON.stringify(template));
|
|
1324
|
-
resolved.id = "".concat(resolved.id, "::").concat(ref.attachment);
|
|
1325
|
-
if (((_resolved$input = resolved.input) === null || _resolved$input === void 0 ? void 0 : _resolved$input.attachment) === 'self') resolved.input.attachment = ref.attachment;
|
|
1326
|
-
if (((_resolved$output = resolved.output) === null || _resolved$output === void 0 ? void 0 : _resolved$output.attachment) === 'self') resolved.output.attachment = ref.attachment;
|
|
1327
|
-
// Inject component UUID guard if the ref carries one
|
|
1328
|
-
if (ref.component) {
|
|
1329
|
-
resolved.input = _objectSpread2(_objectSpread2({}, resolved.input), {}, {
|
|
1330
|
-
component: ref.component
|
|
1331
|
-
});
|
|
1332
|
-
resolved.output = _objectSpread2(_objectSpread2({}, resolved.output), {}, {
|
|
1333
|
-
component: ref.component
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
return resolved;
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
/**
|
|
1340
|
-
* Expand a single defaultBehaviors[] template entry for a specific component
|
|
1341
|
-
* instance placed in the scene.
|
|
1342
|
-
*
|
|
1343
|
-
* If the entry is a behaviorRef, it is first resolved against the device
|
|
1344
|
-
* library; otherwise it is treated as a full behavior definition.
|
|
1345
|
-
* In both cases the instanceUuid is injected as input.component and
|
|
1346
|
-
* output.component, and the behavior id is suffixed with ::instanceUuid.
|
|
1347
|
-
*
|
|
1348
|
-
* @param {Object} template - Entry from compData.defaultBehaviors[]
|
|
1349
|
-
* @param {string} instanceUuid - UUID of the placed component instance
|
|
1350
|
-
* @param {Object} componentDictionary
|
|
1351
|
-
* @returns {Object|null}
|
|
1352
|
-
*/
|
|
1353
|
-
}, {
|
|
1354
|
-
key: "_expandDefaultBehavior",
|
|
1355
|
-
value: function _expandDefaultBehavior(template, instanceUuid, componentDictionary) {
|
|
1356
|
-
var base;
|
|
1357
|
-
if (template.behaviorRef) {
|
|
1358
|
-
// Resolve the device ref first (substitutes 'self' -> attachment)
|
|
1359
|
-
base = this._resolveBehaviorRef(template, componentDictionary);
|
|
1360
|
-
if (!base) return null;
|
|
1361
|
-
} else {
|
|
1362
|
-
base = JSON.parse(JSON.stringify(template));
|
|
1363
|
-
}
|
|
1364
|
-
// Suffix the id so each instance gets a unique behavior id
|
|
1365
|
-
base.id = "".concat(base.id, "::").concat(instanceUuid);
|
|
1366
|
-
// Inject the instance UUID as the component scope guard
|
|
1367
|
-
base.input = _objectSpread2(_objectSpread2({}, base.input), {}, {
|
|
1368
|
-
component: instanceUuid
|
|
1369
|
-
});
|
|
1370
|
-
base.output = _objectSpread2(_objectSpread2({}, base.output), {}, {
|
|
1371
|
-
component: instanceUuid
|
|
1372
|
-
});
|
|
1373
|
-
return base;
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
1099
|
/**
|
|
1377
1100
|
* Save original world matrices for direction calculations
|
|
1378
1101
|
*/
|
|
@@ -1441,7 +1164,7 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1441
1164
|
key: "loadSceneFromData",
|
|
1442
1165
|
value: (function () {
|
|
1443
1166
|
var _loadSceneFromData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(data) {
|
|
1444
|
-
var _data$
|
|
1167
|
+
var _data$scene3, _data$scene4, _data$scene5, _data$scene6;
|
|
1445
1168
|
return _regenerator().w(function (_context9) {
|
|
1446
1169
|
while (1) switch (_context9.n) {
|
|
1447
1170
|
case 0:
|
|
@@ -1451,10 +1174,10 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1451
1174
|
dataType: _typeof(data),
|
|
1452
1175
|
hasScene: !!(data !== null && data !== void 0 && data.scene),
|
|
1453
1176
|
sceneType: _typeof(data === null || data === void 0 ? void 0 : data.scene),
|
|
1454
|
-
hasChildren: !!(data !== null && data !== void 0 && (_data$
|
|
1455
|
-
childrenType: data !== null && data !== void 0 && (_data$
|
|
1456
|
-
isArray: Array.isArray(data === null || data === void 0 || (_data$
|
|
1457
|
-
childrenLength: data === null || data === void 0 || (_data$
|
|
1177
|
+
hasChildren: !!(data !== null && data !== void 0 && (_data$scene3 = data.scene) !== null && _data$scene3 !== void 0 && _data$scene3.children),
|
|
1178
|
+
childrenType: data !== null && data !== void 0 && (_data$scene4 = data.scene) !== null && _data$scene4 !== void 0 && _data$scene4.children ? _typeof(data.scene.children) : 'undefined',
|
|
1179
|
+
isArray: Array.isArray(data === null || data === void 0 || (_data$scene5 = data.scene) === null || _data$scene5 === void 0 ? void 0 : _data$scene5.children),
|
|
1180
|
+
childrenLength: data === null || data === void 0 || (_data$scene6 = data.scene) === null || _data$scene6 === void 0 || (_data$scene6 = _data$scene6.children) === null || _data$scene6 === void 0 ? void 0 : _data$scene6.length,
|
|
1458
1181
|
dataKeys: data ? Object.keys(data) : [],
|
|
1459
1182
|
sceneKeys: data !== null && data !== void 0 && data.scene ? Object.keys(data.scene) : []
|
|
1460
1183
|
});
|
|
@@ -1585,8 +1308,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1585
1308
|
// Process children (connectors, etc.) if they exist
|
|
1586
1309
|
if (componentModel.children && componentModel.children.length > 0) {
|
|
1587
1310
|
componentModel.children.forEach(function (child) {
|
|
1588
|
-
var _child$
|
|
1589
|
-
var childType = ((_child$
|
|
1311
|
+
var _child$userData0, _child$userData1;
|
|
1312
|
+
var childType = ((_child$userData0 = child.userData) === null || _child$userData0 === void 0 ? void 0 : _child$userData0.objectType) || ((_child$userData1 = child.userData) === null || _child$userData1 === void 0 ? void 0 : _child$userData1.objectType);
|
|
1590
1313
|
if (childType === 'connector') {
|
|
1591
1314
|
var _child$geometry;
|
|
1592
1315
|
var childBoundingBox = new THREE.Box3().setFromObject(child);
|
|
@@ -1671,8 +1394,8 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1671
1394
|
if (segment.children && segment.children.length > 0) {
|
|
1672
1395
|
var childrenToRemove = _toConsumableArray(segment.children);
|
|
1673
1396
|
childrenToRemove.forEach(function (child) {
|
|
1674
|
-
var _child$
|
|
1675
|
-
if ((_child$
|
|
1397
|
+
var _child$userData10;
|
|
1398
|
+
if ((_child$userData10 = child.userData) !== null && _child$userData10 !== void 0 && _child$userData10.isPipeElbow) {
|
|
1676
1399
|
console.log("\uD83D\uDDD1\uFE0F Removing elbow child from segment before manualization: ".concat(child.uuid));
|
|
1677
1400
|
segment.remove(child);
|
|
1678
1401
|
if (child.geometry) child.geometry.dispose();
|
|
@@ -1823,7 +1546,7 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1823
1546
|
value: function _convertConnectedGatewaysToManual(connectors, currentSceneData) {
|
|
1824
1547
|
var _connectors$,
|
|
1825
1548
|
_segment$userData2,
|
|
1826
|
-
|
|
1549
|
+
_this5 = this;
|
|
1827
1550
|
console.log('🔍 Checking for connected gateways to convert to manual...');
|
|
1828
1551
|
var sceneViewer = this.sceneViewer;
|
|
1829
1552
|
var convertedGateways = [];
|
|
@@ -1860,7 +1583,7 @@ var SceneOperationsManager = /*#__PURE__*/function () {
|
|
|
1860
1583
|
console.log("\uD83D\uDD27 Found computed gateway at endpoint: ".concat(endpointObject.uuid, " - converting to manual"));
|
|
1861
1584
|
|
|
1862
1585
|
// Convert gateway to manual (declared) using manualizeGateway for consistency
|
|
1863
|
-
|
|
1586
|
+
_this5.manualizeGateway(endpointObject, currentSceneData);
|
|
1864
1587
|
convertedGateways.push(endpointObject);
|
|
1865
1588
|
} else if (((_endpointObject$userD5 = endpointObject.userData) === null || _endpointObject$userD5 === void 0 ? void 0 : _endpointObject$userD5.objectType) === 'gateway' && ((_endpointObject$userD6 = endpointObject.userData) === null || _endpointObject$userD6 === void 0 ? void 0 : _endpointObject$userD6.isDeclared) === true) {
|
|
1866
1589
|
console.log("\u2139\uFE0F Gateway ".concat(endpointObject.uuid, " is already declared (manual), skipping conversion"));
|