@2112-lab/central-plant 0.3.34 → 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inherits as _inherits, createClass as _createClass, createForOfIteratorHelper as _createForOfIteratorHelper, slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, superPropGet as _superPropGet, classCallCheck as _classCallCheck, callSuper as _callSuper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
1
|
+
import { inherits as _inherits, createClass as _createClass, createForOfIteratorHelper as _createForOfIteratorHelper, slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray, superPropGet as _superPropGet, classCallCheck as _classCallCheck, callSuper as _callSuper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import { BaseDisposable } from '../../core/baseDisposable.js';
|
|
4
4
|
|
|
@@ -18,6 +18,24 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
18
18
|
* }>
|
|
19
19
|
*/
|
|
20
20
|
_this._entries = new Map();
|
|
21
|
+
_this._crossComponentBehaviors = [];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Map: `${componentUuid}` → Array<{ id, input, outputs }>
|
|
25
|
+
* Component-level behaviors for intra-component io-device linking
|
|
26
|
+
*/
|
|
27
|
+
_this._componentBehaviors = new Map();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Injected by the host application to read and write I/O device state.
|
|
31
|
+
* Set via configure(). Shape:
|
|
32
|
+
* {
|
|
33
|
+
* getState(attachmentId, dataPointId) -> value | null,
|
|
34
|
+
* setState(attachmentId, dataPointId, value) -> void
|
|
35
|
+
* }
|
|
36
|
+
* @type {{ getState: Function, setState: Function } | null}
|
|
37
|
+
*/
|
|
38
|
+
_this._stateAdapter = null;
|
|
21
39
|
return _this;
|
|
22
40
|
}
|
|
23
41
|
|
|
@@ -115,29 +133,485 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
115
133
|
}, {
|
|
116
134
|
key: "triggerState",
|
|
117
135
|
value: function triggerState(attachmentId, dataPointId, value, parentUuid) {
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
136
|
+
var _this$_crossComponent;
|
|
137
|
+
console.log("[Behavior] triggerState called:", {
|
|
138
|
+
attachmentId: attachmentId,
|
|
139
|
+
dataPointId: dataPointId,
|
|
140
|
+
value: value,
|
|
141
|
+
parentUuid: parentUuid
|
|
142
|
+
});
|
|
143
|
+
if (parentUuid) {
|
|
144
|
+
var key = this._key(parentUuid, attachmentId);
|
|
145
|
+
var entries = this._entries.get(key);
|
|
146
|
+
if (entries) {
|
|
147
|
+
var _iterator2 = _createForOfIteratorHelper(entries),
|
|
148
|
+
_step2;
|
|
125
149
|
try {
|
|
126
|
-
for (
|
|
127
|
-
var entry =
|
|
150
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
151
|
+
var entry = _step2.value;
|
|
128
152
|
if (entry.anim.stateVariable !== dataPointId) continue;
|
|
129
153
|
this._applyAnimation(entry, value);
|
|
130
154
|
}
|
|
131
155
|
} catch (err) {
|
|
132
|
-
|
|
156
|
+
_iterator2.e(err);
|
|
133
157
|
} finally {
|
|
134
|
-
|
|
158
|
+
_iterator2.f();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
// Fallback when parentUuid is not provided: match by attachmentId suffix or exact key match
|
|
163
|
+
var suffix = "::".concat(attachmentId);
|
|
164
|
+
var _iterator3 = _createForOfIteratorHelper(this._entries.entries()),
|
|
165
|
+
_step3;
|
|
166
|
+
try {
|
|
167
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
168
|
+
var _step3$value = _slicedToArray(_step3.value, 2),
|
|
169
|
+
_key2 = _step3$value[0],
|
|
170
|
+
_entries = _step3$value[1];
|
|
171
|
+
if (_key2 === attachmentId || _key2.endsWith(suffix)) {
|
|
172
|
+
var _iterator4 = _createForOfIteratorHelper(_entries),
|
|
173
|
+
_step4;
|
|
174
|
+
try {
|
|
175
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
176
|
+
var _entry = _step4.value;
|
|
177
|
+
if (_entry.anim.stateVariable !== dataPointId) continue;
|
|
178
|
+
this._applyAnimation(_entry, value);
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
_iterator4.e(err);
|
|
182
|
+
} finally {
|
|
183
|
+
_iterator4.f();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} catch (err) {
|
|
188
|
+
_iterator3.e(err);
|
|
189
|
+
} finally {
|
|
190
|
+
_iterator3.f();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Evaluate component-level behaviors (intra-component io-device linking)
|
|
195
|
+
if (parentUuid && this._componentBehaviors.has(parentUuid)) {
|
|
196
|
+
var componentBehaviors = this._componentBehaviors.get(parentUuid);
|
|
197
|
+
console.log("[Behavior] Checking component-level behaviors for ".concat(parentUuid, " (count: ").concat(componentBehaviors.length, ")"));
|
|
198
|
+
this.triggerCrossComponentBehaviors(componentBehaviors, parentUuid, attachmentId, dataPointId, value);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Evaluate cross-component behaviors if any are registered
|
|
202
|
+
console.log("[Behavior] Checking cross-component behaviors (count: ".concat(((_this$_crossComponent = this._crossComponentBehaviors) === null || _this$_crossComponent === void 0 ? void 0 : _this$_crossComponent.length) || 0, ")"));
|
|
203
|
+
if (this._crossComponentBehaviors && this._crossComponentBehaviors.length > 0) {
|
|
204
|
+
this.triggerCrossComponentBehaviors(this._crossComponentBehaviors, parentUuid, attachmentId, dataPointId, value);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Register the root-level cross-component behaviors from the scene.
|
|
210
|
+
* Normalizes shorthand syntax to full format.
|
|
211
|
+
*
|
|
212
|
+
* @param {Array} behaviors
|
|
213
|
+
*/
|
|
214
|
+
}, {
|
|
215
|
+
key: "setCrossComponentBehaviors",
|
|
216
|
+
value: function setCrossComponentBehaviors(behaviors) {
|
|
217
|
+
var _this2 = this;
|
|
218
|
+
this._crossComponentBehaviors = (behaviors || []).map(function (b) {
|
|
219
|
+
return _this2._normalizeBehavior(b);
|
|
220
|
+
});
|
|
221
|
+
console.log("[Behavior] Loaded ".concat(this._crossComponentBehaviors.length, " cross-component behavior(s)"), this._crossComponentBehaviors);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Register component-level behaviors (intra-component io-device linking).
|
|
226
|
+
* These behaviors are defined in the smart component's JSON and link devices within the same component instance.
|
|
227
|
+
*
|
|
228
|
+
* @param {string} componentUuid - The UUID of the component
|
|
229
|
+
* @param {Array} behaviors - Array of behaviors in shorthand format
|
|
230
|
+
*/
|
|
231
|
+
}, {
|
|
232
|
+
key: "registerComponentBehaviors",
|
|
233
|
+
value: function registerComponentBehaviors(componentUuid, behaviors) {
|
|
234
|
+
var _this3 = this;
|
|
235
|
+
if (!behaviors || behaviors.length === 0) return;
|
|
236
|
+
var normalized = behaviors.map(function (b) {
|
|
237
|
+
return _this3._normalizeBehavior(b);
|
|
238
|
+
});
|
|
239
|
+
this._componentBehaviors.set(componentUuid, normalized);
|
|
240
|
+
console.log("[Behavior] Registered ".concat(normalized.length, " component-level behavior(s) for component ").concat(componentUuid), normalized);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Normalize behavior from shorthand to full format.
|
|
245
|
+
* Supports:
|
|
246
|
+
* - input: "attachment.state" → { attachment, state }
|
|
247
|
+
* - outputs: ["attachment.state", ...] → converted to individual behaviors
|
|
248
|
+
*
|
|
249
|
+
* @param {Object} behavior - Raw behavior from scene JSON
|
|
250
|
+
* @returns {Object} Normalized behavior
|
|
251
|
+
*/
|
|
252
|
+
}, {
|
|
253
|
+
key: "_normalizeBehavior",
|
|
254
|
+
value: function _normalizeBehavior(behavior) {
|
|
255
|
+
var normalized = _objectSpread2({}, behavior);
|
|
256
|
+
|
|
257
|
+
// Parse shorthand input: "attachment.state"
|
|
258
|
+
if (typeof behavior.input === 'string') {
|
|
259
|
+
var _behavior$input$split = behavior.input.split('.'),
|
|
260
|
+
_behavior$input$split2 = _slicedToArray(_behavior$input$split, 2),
|
|
261
|
+
attachment = _behavior$input$split2[0],
|
|
262
|
+
state = _behavior$input$split2[1];
|
|
263
|
+
normalized.input = {
|
|
264
|
+
attachment: attachment,
|
|
265
|
+
state: state
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Parse shorthand output/outputs
|
|
270
|
+
if (behavior.outputs) {
|
|
271
|
+
// Multiple outputs - expand to array
|
|
272
|
+
normalized._outputs = behavior.outputs.map(function (out) {
|
|
273
|
+
if (typeof out === 'string') {
|
|
274
|
+
var _out$split = out.split('.'),
|
|
275
|
+
_out$split2 = _slicedToArray(_out$split, 2),
|
|
276
|
+
_attachment = _out$split2[0],
|
|
277
|
+
_state = _out$split2[1];
|
|
278
|
+
return {
|
|
279
|
+
attachment: _attachment,
|
|
280
|
+
state: _state
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return out;
|
|
284
|
+
});
|
|
285
|
+
delete normalized.outputs;
|
|
286
|
+
} else if (typeof behavior.output === 'string') {
|
|
287
|
+
// Single output string
|
|
288
|
+
var _behavior$output$spli = behavior.output.split('.'),
|
|
289
|
+
_behavior$output$spli2 = _slicedToArray(_behavior$output$spli, 2),
|
|
290
|
+
_attachment2 = _behavior$output$spli2[0],
|
|
291
|
+
_state2 = _behavior$output$spli2[1];
|
|
292
|
+
normalized.output = {
|
|
293
|
+
attachment: _attachment2,
|
|
294
|
+
state: _state2
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
return normalized;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Find the parent component UUID for a given attachment ID.
|
|
302
|
+
* Searches the scene tree for the io-device with this attachment ID,
|
|
303
|
+
* then returns its parentComponentId.
|
|
304
|
+
*
|
|
305
|
+
* @param {string} attachmentId
|
|
306
|
+
* @returns {string|null} Component UUID or null if not found
|
|
307
|
+
*/
|
|
308
|
+
}, {
|
|
309
|
+
key: "_findComponentByAttachment",
|
|
310
|
+
value: function _findComponentByAttachment(attachmentId) {
|
|
311
|
+
var _this$sceneViewer;
|
|
312
|
+
if (!((_this$sceneViewer = this.sceneViewer) !== null && _this$sceneViewer !== void 0 && _this$sceneViewer.scene)) return null;
|
|
313
|
+
var scene = this.sceneViewer.scene;
|
|
314
|
+
var found = null;
|
|
315
|
+
scene.traverse(function (obj) {
|
|
316
|
+
var _obj$userData, _obj$userData2;
|
|
317
|
+
if (found) return;
|
|
318
|
+
// Find the io-device object with this attachmentId
|
|
319
|
+
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) {
|
|
320
|
+
found = obj.userData.parentComponentId;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
if (!found) {
|
|
324
|
+
console.warn("[Behavior] Could not find parent component for attachment \"".concat(attachmentId, "\""));
|
|
325
|
+
}
|
|
326
|
+
return found;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Inject a state adapter so cross-component behaviors can write I/O device state.
|
|
331
|
+
* Call this once after the host application's state store is ready.
|
|
332
|
+
*
|
|
333
|
+
* @param {{ getState: Function, setState: Function }} stateAdapter
|
|
334
|
+
* - getState(attachmentId, dataPointId) -> current value (any) | null
|
|
335
|
+
* - setState(attachmentId, dataPointId, value) -> void
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* // Sandbox (Vuex)
|
|
339
|
+
* ioBehaviorManager.configure({
|
|
340
|
+
* getState: (attId, dpId) =>
|
|
341
|
+
* store.getters['assetManagerStore/ioDeviceState'](attId)(dpId) ?? null,
|
|
342
|
+
* setState: (attId, dpId, value) =>
|
|
343
|
+
* store.dispatch('assetManagerStore/setIoDeviceState',
|
|
344
|
+
* { attachmentId: attId, dataPointId: dpId, value })
|
|
345
|
+
* })
|
|
346
|
+
*/
|
|
347
|
+
}, {
|
|
348
|
+
key: "configure",
|
|
349
|
+
value: function configure(stateAdapter) {
|
|
350
|
+
this._stateAdapter = stateAdapter || null;
|
|
351
|
+
console.log('[Behavior] State adapter configured:', !!this._stateAdapter);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Evaluate and apply cross-component behaviors loaded from the scene JSON.
|
|
356
|
+
*
|
|
357
|
+
* @param {Array} behaviors - Root-level behaviors array from the scene JSON
|
|
358
|
+
* @param {string} triggerParentUuid - Parent component UUID of the triggering device
|
|
359
|
+
* @param {string} triggerAttachmentId - Attachment ID of the triggering device
|
|
360
|
+
* @param {string} triggerStateId - The state variable ID that changed
|
|
361
|
+
* @param {*} value - The new state value
|
|
362
|
+
*/
|
|
363
|
+
}, {
|
|
364
|
+
key: "triggerCrossComponentBehaviors",
|
|
365
|
+
value: function triggerCrossComponentBehaviors(behaviors, triggerParentUuid, triggerAttachmentId, triggerStateId, value) {
|
|
366
|
+
if (!behaviors || !Array.isArray(behaviors)) {
|
|
367
|
+
console.log('[Behavior] No behaviors to evaluate');
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
console.log("[Behavior] Evaluating ".concat(behaviors.length, " behavior(s) for trigger: ").concat(triggerParentUuid, ".").concat(triggerAttachmentId, ".").concat(triggerStateId, " = ").concat(value));
|
|
371
|
+
var _iterator5 = _createForOfIteratorHelper(behaviors),
|
|
372
|
+
_step5;
|
|
373
|
+
try {
|
|
374
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
375
|
+
var behavior = _step5.value;
|
|
376
|
+
var input = behavior.input,
|
|
377
|
+
output = behavior.output,
|
|
378
|
+
_outputs = behavior._outputs,
|
|
379
|
+
conditions = behavior.conditions;
|
|
380
|
+
if (!input || !output && !_outputs) {
|
|
381
|
+
console.warn('[Behavior] Skipping behavior - missing input or output(s):', behavior);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Auto-lookup component if not specified
|
|
386
|
+
var inputComponent = input.component || this._findComponentByAttachment(input.attachment);
|
|
387
|
+
console.log("[Behavior] Checking behavior \"".concat(behavior.id, "\":"), {
|
|
388
|
+
inputMatch: inputComponent === triggerParentUuid,
|
|
389
|
+
attachmentMatch: input.attachment === triggerAttachmentId,
|
|
390
|
+
stateMatch: input.state === triggerStateId,
|
|
391
|
+
expected: {
|
|
392
|
+
component: inputComponent,
|
|
393
|
+
attachment: input.attachment,
|
|
394
|
+
state: input.state
|
|
395
|
+
},
|
|
396
|
+
actual: {
|
|
397
|
+
component: triggerParentUuid,
|
|
398
|
+
attachment: triggerAttachmentId,
|
|
399
|
+
state: triggerStateId
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// Verify that the input matches the triggering source
|
|
404
|
+
if (inputComponent === triggerParentUuid && input.attachment === triggerAttachmentId && input.state === triggerStateId) {
|
|
405
|
+
console.log("[Behavior] \u2713 Behavior \"".concat(behavior.id, "\" matched!"));
|
|
406
|
+
|
|
407
|
+
// Collect all outputs (single or multiple)
|
|
408
|
+
var outputs = _outputs || (output ? [output] : []);
|
|
409
|
+
|
|
410
|
+
// Process each output
|
|
411
|
+
var _iterator6 = _createForOfIteratorHelper(outputs),
|
|
412
|
+
_step6;
|
|
413
|
+
try {
|
|
414
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
415
|
+
var out = _step6.value;
|
|
416
|
+
// NEW: State-to-state pass-through pattern
|
|
417
|
+
if (out.state) {
|
|
418
|
+
// Auto-lookup output component if not specified
|
|
419
|
+
var outputComponent = out.component || this._findComponentByAttachment(out.attachment);
|
|
420
|
+
|
|
421
|
+
// Direct state mapping without conditions
|
|
422
|
+
if (this._stateAdapter) {
|
|
423
|
+
console.log("[Behavior] Dispatching state-to-state: ".concat(out.attachment, ".").concat(out.state, " = ").concat(value));
|
|
424
|
+
this._stateAdapter.setState(out.attachment, out.state, value);
|
|
425
|
+
console.log("[Behavior] \u2713 State-to-state triggered: ".concat(input.attachment, ".").concat(input.state, " (").concat(value, ") \u2192 ").concat(out.attachment, ".").concat(out.state));
|
|
426
|
+
|
|
427
|
+
// Trigger animations on the output component
|
|
428
|
+
// triggerState(attachmentId, dataPointId, value, parentUuid)
|
|
429
|
+
if (outputComponent) {
|
|
430
|
+
console.log("[Behavior] Triggering animations on output component: ".concat(outputComponent, ".").concat(out.attachment, ".").concat(out.state));
|
|
431
|
+
this.triggerState(out.attachment, out.state, value, outputComponent);
|
|
432
|
+
} else {
|
|
433
|
+
console.warn("[Behavior] Could not find component for attachment \"".concat(out.attachment, "\""));
|
|
434
|
+
}
|
|
435
|
+
} else {
|
|
436
|
+
console.warn('[Behavior] ✗ State adapter not configured for state-to-state behavior');
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// LEGACY: Mesh-based pattern with conditions
|
|
440
|
+
else if (conditions && out.child) {
|
|
441
|
+
console.log('[Behavior] Using legacy mesh-based pattern with conditions');
|
|
442
|
+
// Evaluate conditions
|
|
443
|
+
var _iterator7 = _createForOfIteratorHelper(conditions),
|
|
444
|
+
_step7;
|
|
445
|
+
try {
|
|
446
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
447
|
+
var condition = _step7.value;
|
|
448
|
+
if (this._evaluateCondition(condition.when, value)) {
|
|
449
|
+
// Apply actions to the target output component/attachment/child mesh
|
|
450
|
+
this._applyCrossComponentActions(out, condition.actions);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
} catch (err) {
|
|
454
|
+
_iterator7.e(err);
|
|
455
|
+
} finally {
|
|
456
|
+
_iterator7.f();
|
|
457
|
+
}
|
|
458
|
+
} else {
|
|
459
|
+
console.warn('[Behavior] Output has neither state nor (child + conditions):', out);
|
|
460
|
+
}
|
|
461
|
+
} // end outputs loop
|
|
462
|
+
} catch (err) {
|
|
463
|
+
_iterator6.e(err);
|
|
464
|
+
} finally {
|
|
465
|
+
_iterator6.f();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} catch (err) {
|
|
470
|
+
_iterator5.e(err);
|
|
471
|
+
} finally {
|
|
472
|
+
_iterator5.f();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Safely evaluate a condition expression.
|
|
478
|
+
*/
|
|
479
|
+
}, {
|
|
480
|
+
key: "_evaluateCondition",
|
|
481
|
+
value: function _evaluateCondition(whenExpr, value) {
|
|
482
|
+
try {
|
|
483
|
+
var fn = new Function('state', "return (".concat(whenExpr, ");"));
|
|
484
|
+
return fn({
|
|
485
|
+
value: value
|
|
486
|
+
});
|
|
487
|
+
} catch (err) {
|
|
488
|
+
console.warn("[IoBehaviorManager] Failed to evaluate condition: \"".concat(whenExpr, "\""), err);
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Resolve target output mesh and apply actions.
|
|
495
|
+
*/
|
|
496
|
+
}, {
|
|
497
|
+
key: "_applyCrossComponentActions",
|
|
498
|
+
value: function _applyCrossComponentActions(output, actions) {
|
|
499
|
+
var _this$sceneViewer2;
|
|
500
|
+
if (!actions || !Array.isArray(actions)) return;
|
|
501
|
+
|
|
502
|
+
// 1. Resolve output component
|
|
503
|
+
var scene = (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.scene;
|
|
504
|
+
if (!scene) return;
|
|
505
|
+
var componentModel = scene.getObjectByProperty('uuid', output.component) || scene.getObjectByProperty('name', output.component);
|
|
506
|
+
if (!componentModel) {
|
|
507
|
+
console.warn("[IoBehaviorManager] Output component \"".concat(output.component, "\" not found in scene"));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// 2. Resolve attachment model under the component
|
|
512
|
+
var deviceRoot = null;
|
|
513
|
+
componentModel.traverse(function (obj) {
|
|
514
|
+
var _obj$userData3;
|
|
515
|
+
if (!deviceRoot && ((_obj$userData3 = obj.userData) === null || _obj$userData3 === void 0 ? void 0 : _obj$userData3.attachmentId) === output.attachment) {
|
|
516
|
+
deviceRoot = obj;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
if (!deviceRoot) {
|
|
520
|
+
console.warn("[IoBehaviorManager] Output attachment \"".concat(output.attachment, "\" not found on component \"").concat(output.component, "\""));
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// 3. Resolve child mesh if specified
|
|
525
|
+
var targetObj = deviceRoot;
|
|
526
|
+
if (output.child) {
|
|
527
|
+
var foundChild = null;
|
|
528
|
+
deviceRoot.traverse(function (obj) {
|
|
529
|
+
if (!foundChild && obj.name === output.child) {
|
|
530
|
+
foundChild = obj;
|
|
135
531
|
}
|
|
532
|
+
});
|
|
533
|
+
if (foundChild) {
|
|
534
|
+
targetObj = foundChild;
|
|
535
|
+
} else {
|
|
536
|
+
console.warn("[IoBehaviorManager] Child \"".concat(output.child, "\" not found under attachment \"").concat(output.attachment, "\" on component \"").concat(output.component, "\""));
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// 4. Apply actions to targetObj
|
|
542
|
+
var _iterator8 = _createForOfIteratorHelper(actions),
|
|
543
|
+
_step8;
|
|
544
|
+
try {
|
|
545
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
546
|
+
var action = _step8.value;
|
|
547
|
+
this._applyCrossComponentAction(targetObj, action);
|
|
136
548
|
}
|
|
137
549
|
} catch (err) {
|
|
138
|
-
|
|
550
|
+
_iterator8.e(err);
|
|
139
551
|
} finally {
|
|
140
|
-
|
|
552
|
+
_iterator8.f();
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Apply a single action to the target mesh.
|
|
558
|
+
*/
|
|
559
|
+
}, {
|
|
560
|
+
key: "_applyCrossComponentAction",
|
|
561
|
+
value: function _applyCrossComponentAction(targetObj, action) {
|
|
562
|
+
var set = action.set,
|
|
563
|
+
value = action.value;
|
|
564
|
+
if (!set) return;
|
|
565
|
+
if (set.startsWith('material.')) {
|
|
566
|
+
var prop = set.slice(9);
|
|
567
|
+
targetObj.traverse(function (obj) {
|
|
568
|
+
if (!obj.isMesh || !obj.material) return;
|
|
569
|
+
if (!obj.userData._materialCloned) {
|
|
570
|
+
obj.material = obj.material.clone();
|
|
571
|
+
obj.userData._materialCloned = true;
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
if (prop === 'color') {
|
|
575
|
+
obj.material.color.set(value);
|
|
576
|
+
} else {
|
|
577
|
+
if (prop in obj.material) {
|
|
578
|
+
if (obj.material[prop] && typeof obj.material[prop].set === 'function') {
|
|
579
|
+
obj.material[prop].set(value);
|
|
580
|
+
} else {
|
|
581
|
+
obj.material[prop] = value;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
} catch (err) {
|
|
586
|
+
console.warn("[IoBehaviorManager] Failed to set material property \"".concat(prop, "\""), err);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
} else if (set === 'visible') {
|
|
590
|
+
targetObj.visible = !!value;
|
|
591
|
+
} else {
|
|
592
|
+
// General fallback path parsing (e.g. position.z)
|
|
593
|
+
var parts = set.split('.');
|
|
594
|
+
var current = targetObj;
|
|
595
|
+
for (var i = 0; i < parts.length - 1; i++) {
|
|
596
|
+
if (current && current[parts[i]]) {
|
|
597
|
+
current = current[parts[i]];
|
|
598
|
+
} else {
|
|
599
|
+
current = null;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (current) {
|
|
604
|
+
var lastPart = parts[parts.length - 1];
|
|
605
|
+
try {
|
|
606
|
+
if (current[lastPart] && typeof current[lastPart].set === 'function') {
|
|
607
|
+
current[lastPart].set(value);
|
|
608
|
+
} else {
|
|
609
|
+
current[lastPart] = value;
|
|
610
|
+
}
|
|
611
|
+
} catch (err) {
|
|
612
|
+
console.warn("[IoBehaviorManager] Failed to set property \"".concat(set, "\""), err);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
141
615
|
}
|
|
142
616
|
}
|
|
143
617
|
|
|
@@ -167,7 +641,7 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
167
641
|
}, {
|
|
168
642
|
key: "getAnimationDataPoints",
|
|
169
643
|
value: function getAnimationDataPoints(parentUuid, attachmentId) {
|
|
170
|
-
var
|
|
644
|
+
var _this4 = this;
|
|
171
645
|
var hitMesh = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
172
646
|
var key = this._key(parentUuid, attachmentId);
|
|
173
647
|
var entries = this._entries.get(key);
|
|
@@ -179,35 +653,35 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
179
653
|
var filtered = entries;
|
|
180
654
|
if (hitMesh) {
|
|
181
655
|
var matching = entries.filter(function (e) {
|
|
182
|
-
return
|
|
656
|
+
return _this4._isMeshOrDescendant(hitMesh, e.mesh);
|
|
183
657
|
});
|
|
184
658
|
if (matching.length > 0) filtered = matching;
|
|
185
659
|
}
|
|
186
660
|
|
|
187
661
|
// Collapse multiple mesh entries that share the same stateVariable
|
|
188
662
|
var seen = new Map(); // stateVariable → anim
|
|
189
|
-
var
|
|
190
|
-
|
|
663
|
+
var _iterator9 = _createForOfIteratorHelper(filtered),
|
|
664
|
+
_step9;
|
|
191
665
|
try {
|
|
192
|
-
for (
|
|
193
|
-
var anim =
|
|
666
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
667
|
+
var anim = _step9.value.anim;
|
|
194
668
|
if (!seen.has(anim.stateVariable)) {
|
|
195
669
|
seen.set(anim.stateVariable, anim);
|
|
196
670
|
}
|
|
197
671
|
}
|
|
198
672
|
} catch (err) {
|
|
199
|
-
|
|
673
|
+
_iterator9.e(err);
|
|
200
674
|
} finally {
|
|
201
|
-
|
|
675
|
+
_iterator9.f();
|
|
202
676
|
}
|
|
203
677
|
var dps = [];
|
|
204
|
-
var
|
|
205
|
-
|
|
678
|
+
var _iterator0 = _createForOfIteratorHelper(seen),
|
|
679
|
+
_step0;
|
|
206
680
|
try {
|
|
207
|
-
for (
|
|
208
|
-
var
|
|
209
|
-
stateVar =
|
|
210
|
-
_anim =
|
|
681
|
+
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
682
|
+
var _step0$value = _slicedToArray(_step0.value, 2),
|
|
683
|
+
stateVar = _step0$value[0],
|
|
684
|
+
_anim = _step0$value[1];
|
|
211
685
|
// Normalise stateType from AnimateDevicesDialog variants
|
|
212
686
|
var stateType = void 0;
|
|
213
687
|
var raw = (_anim.stateType || '').toLowerCase();
|
|
@@ -258,9 +732,9 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
258
732
|
});
|
|
259
733
|
}
|
|
260
734
|
} catch (err) {
|
|
261
|
-
|
|
735
|
+
_iterator0.e(err);
|
|
262
736
|
} finally {
|
|
263
|
-
|
|
737
|
+
_iterator0.f();
|
|
264
738
|
}
|
|
265
739
|
return dps;
|
|
266
740
|
}
|
|
@@ -295,19 +769,19 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
295
769
|
key: "unloadForComponent",
|
|
296
770
|
value: function unloadForComponent(parentUuid) {
|
|
297
771
|
var prefix = "".concat(parentUuid, "::");
|
|
298
|
-
var
|
|
299
|
-
|
|
772
|
+
var _iterator1 = _createForOfIteratorHelper(this._entries.keys()),
|
|
773
|
+
_step1;
|
|
300
774
|
try {
|
|
301
|
-
for (
|
|
302
|
-
var key =
|
|
775
|
+
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
776
|
+
var key = _step1.value;
|
|
303
777
|
if (key.startsWith(prefix)) {
|
|
304
778
|
this._entries.delete(key);
|
|
305
779
|
}
|
|
306
780
|
}
|
|
307
781
|
} catch (err) {
|
|
308
|
-
|
|
782
|
+
_iterator1.e(err);
|
|
309
783
|
} finally {
|
|
310
|
-
|
|
784
|
+
_iterator1.f();
|
|
311
785
|
}
|
|
312
786
|
}
|
|
313
787
|
}, {
|
|
@@ -391,11 +865,11 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
391
865
|
var mapping = this._resolveMapping(anim, value);
|
|
392
866
|
if (!mapping) return;
|
|
393
867
|
var types = anim.transformTypes || [];
|
|
394
|
-
var
|
|
395
|
-
|
|
868
|
+
var _iterator10 = _createForOfIteratorHelper(types),
|
|
869
|
+
_step10;
|
|
396
870
|
try {
|
|
397
|
-
for (
|
|
398
|
-
var type =
|
|
871
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
872
|
+
var type = _step10.value;
|
|
399
873
|
if (type === 'translation') {
|
|
400
874
|
this._applyTranslation(mesh, origPos, mapping.transform);
|
|
401
875
|
} else if (type === 'rotation') {
|
|
@@ -405,9 +879,9 @@ var IoBehaviorManager = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
405
879
|
}
|
|
406
880
|
}
|
|
407
881
|
} catch (err) {
|
|
408
|
-
|
|
882
|
+
_iterator10.e(err);
|
|
409
883
|
} finally {
|
|
410
|
-
|
|
884
|
+
_iterator10.f();
|
|
411
885
|
}
|
|
412
886
|
}
|
|
413
887
|
|