@2112-lab/central-plant 0.3.33 → 0.3.35
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 +621 -95
- package/dist/cjs/src/core/centralPlant.js +40 -14
- package/dist/cjs/src/core/centralPlantInternals.js +6 -0
- package/dist/cjs/src/core/sceneViewer.js +6 -24
- package/dist/cjs/src/managers/behaviors/IoBehaviorManager.js +515 -41
- package/dist/cjs/src/managers/controls/transformControlsManager.js +32 -10
- package/dist/cjs/src/managers/scene/modelManager.js +11 -5
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +11 -1
- package/dist/esm/src/core/centralPlant.js +40 -14
- package/dist/esm/src/core/centralPlantInternals.js +6 -0
- package/dist/esm/src/core/sceneViewer.js +6 -24
- package/dist/esm/src/managers/behaviors/IoBehaviorManager.js +516 -42
- package/dist/esm/src/managers/controls/transformControlsManager.js +32 -10
- package/dist/esm/src/managers/scene/modelManager.js +11 -5
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +11 -1
- package/package.json +1 -1
|
@@ -42,6 +42,24 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
42
42
|
* }>
|
|
43
43
|
*/
|
|
44
44
|
_this._entries = new Map();
|
|
45
|
+
_this._crossComponentBehaviors = [];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Map: `${componentUuid}` → Array<{ id, input, outputs }>
|
|
49
|
+
* Component-level behaviors for intra-component io-device linking
|
|
50
|
+
*/
|
|
51
|
+
_this._componentBehaviors = new Map();
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Injected by the host application to read and write I/O device state.
|
|
55
|
+
* Set via configure(). Shape:
|
|
56
|
+
* {
|
|
57
|
+
* getState(attachmentId, dataPointId) -> value | null,
|
|
58
|
+
* setState(attachmentId, dataPointId, value) -> void
|
|
59
|
+
* }
|
|
60
|
+
* @type {{ getState: Function, setState: Function } | null}
|
|
61
|
+
*/
|
|
62
|
+
_this._stateAdapter = null;
|
|
45
63
|
return _this;
|
|
46
64
|
}
|
|
47
65
|
|
|
@@ -139,29 +157,485 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
139
157
|
}, {
|
|
140
158
|
key: "triggerState",
|
|
141
159
|
value: function triggerState(attachmentId, dataPointId, value, parentUuid) {
|
|
142
|
-
var
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
var _this$_crossComponent;
|
|
161
|
+
console.log("[Behavior] triggerState called:", {
|
|
162
|
+
attachmentId: attachmentId,
|
|
163
|
+
dataPointId: dataPointId,
|
|
164
|
+
value: value,
|
|
165
|
+
parentUuid: parentUuid
|
|
166
|
+
});
|
|
167
|
+
if (parentUuid) {
|
|
168
|
+
var key = this._key(parentUuid, attachmentId);
|
|
169
|
+
var entries = this._entries.get(key);
|
|
170
|
+
if (entries) {
|
|
171
|
+
var _iterator2 = _rollupPluginBabelHelpers.createForOfIteratorHelper(entries),
|
|
172
|
+
_step2;
|
|
149
173
|
try {
|
|
150
|
-
for (
|
|
151
|
-
var entry =
|
|
174
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
175
|
+
var entry = _step2.value;
|
|
152
176
|
if (entry.anim.stateVariable !== dataPointId) continue;
|
|
153
177
|
this._applyAnimation(entry, value);
|
|
154
178
|
}
|
|
155
179
|
} catch (err) {
|
|
156
|
-
|
|
180
|
+
_iterator2.e(err);
|
|
157
181
|
} finally {
|
|
158
|
-
|
|
182
|
+
_iterator2.f();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
// Fallback when parentUuid is not provided: match by attachmentId suffix or exact key match
|
|
187
|
+
var suffix = "::".concat(attachmentId);
|
|
188
|
+
var _iterator3 = _rollupPluginBabelHelpers.createForOfIteratorHelper(this._entries.entries()),
|
|
189
|
+
_step3;
|
|
190
|
+
try {
|
|
191
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
192
|
+
var _step3$value = _rollupPluginBabelHelpers.slicedToArray(_step3.value, 2),
|
|
193
|
+
_key2 = _step3$value[0],
|
|
194
|
+
_entries = _step3$value[1];
|
|
195
|
+
if (_key2 === attachmentId || _key2.endsWith(suffix)) {
|
|
196
|
+
var _iterator4 = _rollupPluginBabelHelpers.createForOfIteratorHelper(_entries),
|
|
197
|
+
_step4;
|
|
198
|
+
try {
|
|
199
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
200
|
+
var _entry = _step4.value;
|
|
201
|
+
if (_entry.anim.stateVariable !== dataPointId) continue;
|
|
202
|
+
this._applyAnimation(_entry, value);
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
_iterator4.e(err);
|
|
206
|
+
} finally {
|
|
207
|
+
_iterator4.f();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} catch (err) {
|
|
212
|
+
_iterator3.e(err);
|
|
213
|
+
} finally {
|
|
214
|
+
_iterator3.f();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Evaluate component-level behaviors (intra-component io-device linking)
|
|
219
|
+
if (parentUuid && this._componentBehaviors.has(parentUuid)) {
|
|
220
|
+
var componentBehaviors = this._componentBehaviors.get(parentUuid);
|
|
221
|
+
console.log("[Behavior] Checking component-level behaviors for ".concat(parentUuid, " (count: ").concat(componentBehaviors.length, ")"));
|
|
222
|
+
this.triggerCrossComponentBehaviors(componentBehaviors, parentUuid, attachmentId, dataPointId, value);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Evaluate cross-component behaviors if any are registered
|
|
226
|
+
console.log("[Behavior] Checking cross-component behaviors (count: ".concat(((_this$_crossComponent = this._crossComponentBehaviors) === null || _this$_crossComponent === void 0 ? void 0 : _this$_crossComponent.length) || 0, ")"));
|
|
227
|
+
if (this._crossComponentBehaviors && this._crossComponentBehaviors.length > 0) {
|
|
228
|
+
this.triggerCrossComponentBehaviors(this._crossComponentBehaviors, parentUuid, attachmentId, dataPointId, value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Register the root-level cross-component behaviors from the scene.
|
|
234
|
+
* Normalizes shorthand syntax to full format.
|
|
235
|
+
*
|
|
236
|
+
* @param {Array} behaviors
|
|
237
|
+
*/
|
|
238
|
+
}, {
|
|
239
|
+
key: "setCrossComponentBehaviors",
|
|
240
|
+
value: function setCrossComponentBehaviors(behaviors) {
|
|
241
|
+
var _this2 = this;
|
|
242
|
+
this._crossComponentBehaviors = (behaviors || []).map(function (b) {
|
|
243
|
+
return _this2._normalizeBehavior(b);
|
|
244
|
+
});
|
|
245
|
+
console.log("[Behavior] Loaded ".concat(this._crossComponentBehaviors.length, " cross-component behavior(s)"), this._crossComponentBehaviors);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Register component-level behaviors (intra-component io-device linking).
|
|
250
|
+
* These behaviors are defined in the smart component's JSON and link devices within the same component instance.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} componentUuid - The UUID of the component
|
|
253
|
+
* @param {Array} behaviors - Array of behaviors in shorthand format
|
|
254
|
+
*/
|
|
255
|
+
}, {
|
|
256
|
+
key: "registerComponentBehaviors",
|
|
257
|
+
value: function registerComponentBehaviors(componentUuid, behaviors) {
|
|
258
|
+
var _this3 = this;
|
|
259
|
+
if (!behaviors || behaviors.length === 0) return;
|
|
260
|
+
var normalized = behaviors.map(function (b) {
|
|
261
|
+
return _this3._normalizeBehavior(b);
|
|
262
|
+
});
|
|
263
|
+
this._componentBehaviors.set(componentUuid, normalized);
|
|
264
|
+
console.log("[Behavior] Registered ".concat(normalized.length, " component-level behavior(s) for component ").concat(componentUuid), normalized);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Normalize behavior from shorthand to full format.
|
|
269
|
+
* Supports:
|
|
270
|
+
* - input: "attachment.state" → { attachment, state }
|
|
271
|
+
* - outputs: ["attachment.state", ...] → converted to individual behaviors
|
|
272
|
+
*
|
|
273
|
+
* @param {Object} behavior - Raw behavior from scene JSON
|
|
274
|
+
* @returns {Object} Normalized behavior
|
|
275
|
+
*/
|
|
276
|
+
}, {
|
|
277
|
+
key: "_normalizeBehavior",
|
|
278
|
+
value: function _normalizeBehavior(behavior) {
|
|
279
|
+
var normalized = _rollupPluginBabelHelpers.objectSpread2({}, behavior);
|
|
280
|
+
|
|
281
|
+
// Parse shorthand input: "attachment.state"
|
|
282
|
+
if (typeof behavior.input === 'string') {
|
|
283
|
+
var _behavior$input$split = behavior.input.split('.'),
|
|
284
|
+
_behavior$input$split2 = _rollupPluginBabelHelpers.slicedToArray(_behavior$input$split, 2),
|
|
285
|
+
attachment = _behavior$input$split2[0],
|
|
286
|
+
state = _behavior$input$split2[1];
|
|
287
|
+
normalized.input = {
|
|
288
|
+
attachment: attachment,
|
|
289
|
+
state: state
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Parse shorthand output/outputs
|
|
294
|
+
if (behavior.outputs) {
|
|
295
|
+
// Multiple outputs - expand to array
|
|
296
|
+
normalized._outputs = behavior.outputs.map(function (out) {
|
|
297
|
+
if (typeof out === 'string') {
|
|
298
|
+
var _out$split = out.split('.'),
|
|
299
|
+
_out$split2 = _rollupPluginBabelHelpers.slicedToArray(_out$split, 2),
|
|
300
|
+
_attachment = _out$split2[0],
|
|
301
|
+
_state = _out$split2[1];
|
|
302
|
+
return {
|
|
303
|
+
attachment: _attachment,
|
|
304
|
+
state: _state
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return out;
|
|
308
|
+
});
|
|
309
|
+
delete normalized.outputs;
|
|
310
|
+
} else if (typeof behavior.output === 'string') {
|
|
311
|
+
// Single output string
|
|
312
|
+
var _behavior$output$spli = behavior.output.split('.'),
|
|
313
|
+
_behavior$output$spli2 = _rollupPluginBabelHelpers.slicedToArray(_behavior$output$spli, 2),
|
|
314
|
+
_attachment2 = _behavior$output$spli2[0],
|
|
315
|
+
_state2 = _behavior$output$spli2[1];
|
|
316
|
+
normalized.output = {
|
|
317
|
+
attachment: _attachment2,
|
|
318
|
+
state: _state2
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return normalized;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Find the parent component UUID for a given attachment ID.
|
|
326
|
+
* Searches the scene tree for the io-device with this attachment ID,
|
|
327
|
+
* then returns its parentComponentId.
|
|
328
|
+
*
|
|
329
|
+
* @param {string} attachmentId
|
|
330
|
+
* @returns {string|null} Component UUID or null if not found
|
|
331
|
+
*/
|
|
332
|
+
}, {
|
|
333
|
+
key: "_findComponentByAttachment",
|
|
334
|
+
value: function _findComponentByAttachment(attachmentId) {
|
|
335
|
+
var _this$sceneViewer;
|
|
336
|
+
if (!((_this$sceneViewer = this.sceneViewer) !== null && _this$sceneViewer !== void 0 && _this$sceneViewer.scene)) return null;
|
|
337
|
+
var scene = this.sceneViewer.scene;
|
|
338
|
+
var found = null;
|
|
339
|
+
scene.traverse(function (obj) {
|
|
340
|
+
var _obj$userData, _obj$userData2;
|
|
341
|
+
if (found) return;
|
|
342
|
+
// Find the io-device object with this attachmentId
|
|
343
|
+
if (((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.objectType) === 'io-device' && ((_obj$userData2 = obj.userData) === null || _obj$userData2 === void 0 ? void 0 : _obj$userData2.attachmentId) === attachmentId) {
|
|
344
|
+
found = obj.userData.parentComponentId;
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
if (!found) {
|
|
348
|
+
console.warn("[Behavior] Could not find parent component for attachment \"".concat(attachmentId, "\""));
|
|
349
|
+
}
|
|
350
|
+
return found;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Inject a state adapter so cross-component behaviors can write I/O device state.
|
|
355
|
+
* Call this once after the host application's state store is ready.
|
|
356
|
+
*
|
|
357
|
+
* @param {{ getState: Function, setState: Function }} stateAdapter
|
|
358
|
+
* - getState(attachmentId, dataPointId) -> current value (any) | null
|
|
359
|
+
* - setState(attachmentId, dataPointId, value) -> void
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* // Sandbox (Vuex)
|
|
363
|
+
* ioBehaviorManager.configure({
|
|
364
|
+
* getState: (attId, dpId) =>
|
|
365
|
+
* store.getters['assetManagerStore/ioDeviceState'](attId)(dpId) ?? null,
|
|
366
|
+
* setState: (attId, dpId, value) =>
|
|
367
|
+
* store.dispatch('assetManagerStore/setIoDeviceState',
|
|
368
|
+
* { attachmentId: attId, dataPointId: dpId, value })
|
|
369
|
+
* })
|
|
370
|
+
*/
|
|
371
|
+
}, {
|
|
372
|
+
key: "configure",
|
|
373
|
+
value: function configure(stateAdapter) {
|
|
374
|
+
this._stateAdapter = stateAdapter || null;
|
|
375
|
+
console.log('[Behavior] State adapter configured:', !!this._stateAdapter);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Evaluate and apply cross-component behaviors loaded from the scene JSON.
|
|
380
|
+
*
|
|
381
|
+
* @param {Array} behaviors - Root-level behaviors array from the scene JSON
|
|
382
|
+
* @param {string} triggerParentUuid - Parent component UUID of the triggering device
|
|
383
|
+
* @param {string} triggerAttachmentId - Attachment ID of the triggering device
|
|
384
|
+
* @param {string} triggerStateId - The state variable ID that changed
|
|
385
|
+
* @param {*} value - The new state value
|
|
386
|
+
*/
|
|
387
|
+
}, {
|
|
388
|
+
key: "triggerCrossComponentBehaviors",
|
|
389
|
+
value: function triggerCrossComponentBehaviors(behaviors, triggerParentUuid, triggerAttachmentId, triggerStateId, value) {
|
|
390
|
+
if (!behaviors || !Array.isArray(behaviors)) {
|
|
391
|
+
console.log('[Behavior] No behaviors to evaluate');
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
console.log("[Behavior] Evaluating ".concat(behaviors.length, " behavior(s) for trigger: ").concat(triggerParentUuid, ".").concat(triggerAttachmentId, ".").concat(triggerStateId, " = ").concat(value));
|
|
395
|
+
var _iterator5 = _rollupPluginBabelHelpers.createForOfIteratorHelper(behaviors),
|
|
396
|
+
_step5;
|
|
397
|
+
try {
|
|
398
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
399
|
+
var behavior = _step5.value;
|
|
400
|
+
var input = behavior.input,
|
|
401
|
+
output = behavior.output,
|
|
402
|
+
_outputs = behavior._outputs,
|
|
403
|
+
conditions = behavior.conditions;
|
|
404
|
+
if (!input || !output && !_outputs) {
|
|
405
|
+
console.warn('[Behavior] Skipping behavior - missing input or output(s):', behavior);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Auto-lookup component if not specified
|
|
410
|
+
var inputComponent = input.component || this._findComponentByAttachment(input.attachment);
|
|
411
|
+
console.log("[Behavior] Checking behavior \"".concat(behavior.id, "\":"), {
|
|
412
|
+
inputMatch: inputComponent === triggerParentUuid,
|
|
413
|
+
attachmentMatch: input.attachment === triggerAttachmentId,
|
|
414
|
+
stateMatch: input.state === triggerStateId,
|
|
415
|
+
expected: {
|
|
416
|
+
component: inputComponent,
|
|
417
|
+
attachment: input.attachment,
|
|
418
|
+
state: input.state
|
|
419
|
+
},
|
|
420
|
+
actual: {
|
|
421
|
+
component: triggerParentUuid,
|
|
422
|
+
attachment: triggerAttachmentId,
|
|
423
|
+
state: triggerStateId
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// Verify that the input matches the triggering source
|
|
428
|
+
if (inputComponent === triggerParentUuid && input.attachment === triggerAttachmentId && input.state === triggerStateId) {
|
|
429
|
+
console.log("[Behavior] \u2713 Behavior \"".concat(behavior.id, "\" matched!"));
|
|
430
|
+
|
|
431
|
+
// Collect all outputs (single or multiple)
|
|
432
|
+
var outputs = _outputs || (output ? [output] : []);
|
|
433
|
+
|
|
434
|
+
// Process each output
|
|
435
|
+
var _iterator6 = _rollupPluginBabelHelpers.createForOfIteratorHelper(outputs),
|
|
436
|
+
_step6;
|
|
437
|
+
try {
|
|
438
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
439
|
+
var out = _step6.value;
|
|
440
|
+
// NEW: State-to-state pass-through pattern
|
|
441
|
+
if (out.state) {
|
|
442
|
+
// Auto-lookup output component if not specified
|
|
443
|
+
var outputComponent = out.component || this._findComponentByAttachment(out.attachment);
|
|
444
|
+
|
|
445
|
+
// Direct state mapping without conditions
|
|
446
|
+
if (this._stateAdapter) {
|
|
447
|
+
console.log("[Behavior] Dispatching state-to-state: ".concat(out.attachment, ".").concat(out.state, " = ").concat(value));
|
|
448
|
+
this._stateAdapter.setState(out.attachment, out.state, value);
|
|
449
|
+
console.log("[Behavior] \u2713 State-to-state triggered: ".concat(input.attachment, ".").concat(input.state, " (").concat(value, ") \u2192 ").concat(out.attachment, ".").concat(out.state));
|
|
450
|
+
|
|
451
|
+
// Trigger animations on the output component
|
|
452
|
+
// triggerState(attachmentId, dataPointId, value, parentUuid)
|
|
453
|
+
if (outputComponent) {
|
|
454
|
+
console.log("[Behavior] Triggering animations on output component: ".concat(outputComponent, ".").concat(out.attachment, ".").concat(out.state));
|
|
455
|
+
this.triggerState(out.attachment, out.state, value, outputComponent);
|
|
456
|
+
} else {
|
|
457
|
+
console.warn("[Behavior] Could not find component for attachment \"".concat(out.attachment, "\""));
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
console.warn('[Behavior] ✗ State adapter not configured for state-to-state behavior');
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
// LEGACY: Mesh-based pattern with conditions
|
|
464
|
+
else if (conditions && out.child) {
|
|
465
|
+
console.log('[Behavior] Using legacy mesh-based pattern with conditions');
|
|
466
|
+
// Evaluate conditions
|
|
467
|
+
var _iterator7 = _rollupPluginBabelHelpers.createForOfIteratorHelper(conditions),
|
|
468
|
+
_step7;
|
|
469
|
+
try {
|
|
470
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
471
|
+
var condition = _step7.value;
|
|
472
|
+
if (this._evaluateCondition(condition.when, value)) {
|
|
473
|
+
// Apply actions to the target output component/attachment/child mesh
|
|
474
|
+
this._applyCrossComponentActions(out, condition.actions);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
} catch (err) {
|
|
478
|
+
_iterator7.e(err);
|
|
479
|
+
} finally {
|
|
480
|
+
_iterator7.f();
|
|
481
|
+
}
|
|
482
|
+
} else {
|
|
483
|
+
console.warn('[Behavior] Output has neither state nor (child + conditions):', out);
|
|
484
|
+
}
|
|
485
|
+
} // end outputs loop
|
|
486
|
+
} catch (err) {
|
|
487
|
+
_iterator6.e(err);
|
|
488
|
+
} finally {
|
|
489
|
+
_iterator6.f();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
} catch (err) {
|
|
494
|
+
_iterator5.e(err);
|
|
495
|
+
} finally {
|
|
496
|
+
_iterator5.f();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Safely evaluate a condition expression.
|
|
502
|
+
*/
|
|
503
|
+
}, {
|
|
504
|
+
key: "_evaluateCondition",
|
|
505
|
+
value: function _evaluateCondition(whenExpr, value) {
|
|
506
|
+
try {
|
|
507
|
+
var fn = new Function('state', "return (".concat(whenExpr, ");"));
|
|
508
|
+
return fn({
|
|
509
|
+
value: value
|
|
510
|
+
});
|
|
511
|
+
} catch (err) {
|
|
512
|
+
console.warn("[IoBehaviorManager] Failed to evaluate condition: \"".concat(whenExpr, "\""), err);
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Resolve target output mesh and apply actions.
|
|
519
|
+
*/
|
|
520
|
+
}, {
|
|
521
|
+
key: "_applyCrossComponentActions",
|
|
522
|
+
value: function _applyCrossComponentActions(output, actions) {
|
|
523
|
+
var _this$sceneViewer2;
|
|
524
|
+
if (!actions || !Array.isArray(actions)) return;
|
|
525
|
+
|
|
526
|
+
// 1. Resolve output component
|
|
527
|
+
var scene = (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.scene;
|
|
528
|
+
if (!scene) return;
|
|
529
|
+
var componentModel = scene.getObjectByProperty('uuid', output.component) || scene.getObjectByProperty('name', output.component);
|
|
530
|
+
if (!componentModel) {
|
|
531
|
+
console.warn("[IoBehaviorManager] Output component \"".concat(output.component, "\" not found in scene"));
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// 2. Resolve attachment model under the component
|
|
536
|
+
var deviceRoot = null;
|
|
537
|
+
componentModel.traverse(function (obj) {
|
|
538
|
+
var _obj$userData3;
|
|
539
|
+
if (!deviceRoot && ((_obj$userData3 = obj.userData) === null || _obj$userData3 === void 0 ? void 0 : _obj$userData3.attachmentId) === output.attachment) {
|
|
540
|
+
deviceRoot = obj;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
if (!deviceRoot) {
|
|
544
|
+
console.warn("[IoBehaviorManager] Output attachment \"".concat(output.attachment, "\" not found on component \"").concat(output.component, "\""));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// 3. Resolve child mesh if specified
|
|
549
|
+
var targetObj = deviceRoot;
|
|
550
|
+
if (output.child) {
|
|
551
|
+
var foundChild = null;
|
|
552
|
+
deviceRoot.traverse(function (obj) {
|
|
553
|
+
if (!foundChild && obj.name === output.child) {
|
|
554
|
+
foundChild = obj;
|
|
159
555
|
}
|
|
556
|
+
});
|
|
557
|
+
if (foundChild) {
|
|
558
|
+
targetObj = foundChild;
|
|
559
|
+
} else {
|
|
560
|
+
console.warn("[IoBehaviorManager] Child \"".concat(output.child, "\" not found under attachment \"").concat(output.attachment, "\" on component \"").concat(output.component, "\""));
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// 4. Apply actions to targetObj
|
|
566
|
+
var _iterator8 = _rollupPluginBabelHelpers.createForOfIteratorHelper(actions),
|
|
567
|
+
_step8;
|
|
568
|
+
try {
|
|
569
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
570
|
+
var action = _step8.value;
|
|
571
|
+
this._applyCrossComponentAction(targetObj, action);
|
|
160
572
|
}
|
|
161
573
|
} catch (err) {
|
|
162
|
-
|
|
574
|
+
_iterator8.e(err);
|
|
163
575
|
} finally {
|
|
164
|
-
|
|
576
|
+
_iterator8.f();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Apply a single action to the target mesh.
|
|
582
|
+
*/
|
|
583
|
+
}, {
|
|
584
|
+
key: "_applyCrossComponentAction",
|
|
585
|
+
value: function _applyCrossComponentAction(targetObj, action) {
|
|
586
|
+
var set = action.set,
|
|
587
|
+
value = action.value;
|
|
588
|
+
if (!set) return;
|
|
589
|
+
if (set.startsWith('material.')) {
|
|
590
|
+
var prop = set.slice(9);
|
|
591
|
+
targetObj.traverse(function (obj) {
|
|
592
|
+
if (!obj.isMesh || !obj.material) return;
|
|
593
|
+
if (!obj.userData._materialCloned) {
|
|
594
|
+
obj.material = obj.material.clone();
|
|
595
|
+
obj.userData._materialCloned = true;
|
|
596
|
+
}
|
|
597
|
+
try {
|
|
598
|
+
if (prop === 'color') {
|
|
599
|
+
obj.material.color.set(value);
|
|
600
|
+
} else {
|
|
601
|
+
if (prop in obj.material) {
|
|
602
|
+
if (obj.material[prop] && typeof obj.material[prop].set === 'function') {
|
|
603
|
+
obj.material[prop].set(value);
|
|
604
|
+
} else {
|
|
605
|
+
obj.material[prop] = value;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
} catch (err) {
|
|
610
|
+
console.warn("[IoBehaviorManager] Failed to set material property \"".concat(prop, "\""), err);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
} else if (set === 'visible') {
|
|
614
|
+
targetObj.visible = !!value;
|
|
615
|
+
} else {
|
|
616
|
+
// General fallback path parsing (e.g. position.z)
|
|
617
|
+
var parts = set.split('.');
|
|
618
|
+
var current = targetObj;
|
|
619
|
+
for (var i = 0; i < parts.length - 1; i++) {
|
|
620
|
+
if (current && current[parts[i]]) {
|
|
621
|
+
current = current[parts[i]];
|
|
622
|
+
} else {
|
|
623
|
+
current = null;
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (current) {
|
|
628
|
+
var lastPart = parts[parts.length - 1];
|
|
629
|
+
try {
|
|
630
|
+
if (current[lastPart] && typeof current[lastPart].set === 'function') {
|
|
631
|
+
current[lastPart].set(value);
|
|
632
|
+
} else {
|
|
633
|
+
current[lastPart] = value;
|
|
634
|
+
}
|
|
635
|
+
} catch (err) {
|
|
636
|
+
console.warn("[IoBehaviorManager] Failed to set property \"".concat(set, "\""), err);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
165
639
|
}
|
|
166
640
|
}
|
|
167
641
|
|
|
@@ -191,7 +665,7 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
191
665
|
}, {
|
|
192
666
|
key: "getAnimationDataPoints",
|
|
193
667
|
value: function getAnimationDataPoints(parentUuid, attachmentId) {
|
|
194
|
-
var
|
|
668
|
+
var _this4 = this;
|
|
195
669
|
var hitMesh = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
196
670
|
var key = this._key(parentUuid, attachmentId);
|
|
197
671
|
var entries = this._entries.get(key);
|
|
@@ -203,35 +677,35 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
203
677
|
var filtered = entries;
|
|
204
678
|
if (hitMesh) {
|
|
205
679
|
var matching = entries.filter(function (e) {
|
|
206
|
-
return
|
|
680
|
+
return _this4._isMeshOrDescendant(hitMesh, e.mesh);
|
|
207
681
|
});
|
|
208
682
|
if (matching.length > 0) filtered = matching;
|
|
209
683
|
}
|
|
210
684
|
|
|
211
685
|
// Collapse multiple mesh entries that share the same stateVariable
|
|
212
686
|
var seen = new Map(); // stateVariable → anim
|
|
213
|
-
var
|
|
214
|
-
|
|
687
|
+
var _iterator9 = _rollupPluginBabelHelpers.createForOfIteratorHelper(filtered),
|
|
688
|
+
_step9;
|
|
215
689
|
try {
|
|
216
|
-
for (
|
|
217
|
-
var anim =
|
|
690
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
691
|
+
var anim = _step9.value.anim;
|
|
218
692
|
if (!seen.has(anim.stateVariable)) {
|
|
219
693
|
seen.set(anim.stateVariable, anim);
|
|
220
694
|
}
|
|
221
695
|
}
|
|
222
696
|
} catch (err) {
|
|
223
|
-
|
|
697
|
+
_iterator9.e(err);
|
|
224
698
|
} finally {
|
|
225
|
-
|
|
699
|
+
_iterator9.f();
|
|
226
700
|
}
|
|
227
701
|
var dps = [];
|
|
228
|
-
var
|
|
229
|
-
|
|
702
|
+
var _iterator0 = _rollupPluginBabelHelpers.createForOfIteratorHelper(seen),
|
|
703
|
+
_step0;
|
|
230
704
|
try {
|
|
231
|
-
for (
|
|
232
|
-
var
|
|
233
|
-
stateVar =
|
|
234
|
-
_anim =
|
|
705
|
+
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
706
|
+
var _step0$value = _rollupPluginBabelHelpers.slicedToArray(_step0.value, 2),
|
|
707
|
+
stateVar = _step0$value[0],
|
|
708
|
+
_anim = _step0$value[1];
|
|
235
709
|
// Normalise stateType from AnimateDevicesDialog variants
|
|
236
710
|
var stateType = void 0;
|
|
237
711
|
var raw = (_anim.stateType || '').toLowerCase();
|
|
@@ -282,9 +756,9 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
282
756
|
});
|
|
283
757
|
}
|
|
284
758
|
} catch (err) {
|
|
285
|
-
|
|
759
|
+
_iterator0.e(err);
|
|
286
760
|
} finally {
|
|
287
|
-
|
|
761
|
+
_iterator0.f();
|
|
288
762
|
}
|
|
289
763
|
return dps;
|
|
290
764
|
}
|
|
@@ -319,19 +793,19 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
319
793
|
key: "unloadForComponent",
|
|
320
794
|
value: function unloadForComponent(parentUuid) {
|
|
321
795
|
var prefix = "".concat(parentUuid, "::");
|
|
322
|
-
var
|
|
323
|
-
|
|
796
|
+
var _iterator1 = _rollupPluginBabelHelpers.createForOfIteratorHelper(this._entries.keys()),
|
|
797
|
+
_step1;
|
|
324
798
|
try {
|
|
325
|
-
for (
|
|
326
|
-
var key =
|
|
799
|
+
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
800
|
+
var key = _step1.value;
|
|
327
801
|
if (key.startsWith(prefix)) {
|
|
328
802
|
this._entries.delete(key);
|
|
329
803
|
}
|
|
330
804
|
}
|
|
331
805
|
} catch (err) {
|
|
332
|
-
|
|
806
|
+
_iterator1.e(err);
|
|
333
807
|
} finally {
|
|
334
|
-
|
|
808
|
+
_iterator1.f();
|
|
335
809
|
}
|
|
336
810
|
}
|
|
337
811
|
}, {
|
|
@@ -415,11 +889,11 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
415
889
|
var mapping = this._resolveMapping(anim, value);
|
|
416
890
|
if (!mapping) return;
|
|
417
891
|
var types = anim.transformTypes || [];
|
|
418
|
-
var
|
|
419
|
-
|
|
892
|
+
var _iterator10 = _rollupPluginBabelHelpers.createForOfIteratorHelper(types),
|
|
893
|
+
_step10;
|
|
420
894
|
try {
|
|
421
|
-
for (
|
|
422
|
-
var type =
|
|
895
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
896
|
+
var type = _step10.value;
|
|
423
897
|
if (type === 'translation') {
|
|
424
898
|
this._applyTranslation(mesh, origPos, mapping.transform);
|
|
425
899
|
} else if (type === 'rotation') {
|
|
@@ -429,9 +903,9 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
429
903
|
}
|
|
430
904
|
}
|
|
431
905
|
} catch (err) {
|
|
432
|
-
|
|
906
|
+
_iterator10.e(err);
|
|
433
907
|
} finally {
|
|
434
|
-
|
|
908
|
+
_iterator10.f();
|
|
435
909
|
}
|
|
436
910
|
}
|
|
437
911
|
|