@spiffcommerce/preview 3.6.2-rc.8 → 4.0.0
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/index.esm.js +1576 -38
- package/dist/index.umd.js +1 -0
- package/package.json +4 -6
- package/dist/_tslib.esm.js +0 -33
- package/dist/animation.esm.js +0 -1364
- package/dist/assetCache.esm.js +0 -6
- package/dist/assetCache.esm2.js +0 -825
- package/dist/blurPostProcess.esm.js +0 -327
- package/dist/bumpVertex.esm.js +0 -497
- package/dist/compatibilityOptions.esm.js +0 -68
- package/dist/configuration.esm.js +0 -121
- package/dist/core.esm.js +0 -8135
- package/dist/dynamicTexture.esm.js +0 -105
- package/dist/dynamicTexture.esm2.js +0 -238
- package/dist/easing.esm.js +0 -130
- package/dist/effectFallbacks.esm.js +0 -378
- package/dist/engine.esm.js +0 -25504
- package/dist/glbLoaderExtensions.esm.js +0 -690
- package/dist/glowLayer.esm.js +0 -1621
- package/dist/glowLayerManager.esm.js +0 -50
- package/dist/guid.esm.js +0 -21
- package/dist/hdrFilteringFunctions.esm.js +0 -816
- package/dist/helperFunctions.esm.js +0 -5145
- package/dist/material.esm.js +0 -115
- package/dist/material.esm2.js +0 -5245
- package/dist/math.axis.esm.js +0 -35
- package/dist/math.color.esm.js +0 -1661
- package/dist/math.path.esm.js +0 -15
- package/dist/math.size.esm.js +0 -137
- package/dist/mesh.esm.js +0 -11170
- package/dist/modelContainer.esm.js +0 -1895
- package/dist/node.esm.js +0 -795
- package/dist/pbrBRDFFunctions.esm.js +0 -124
- package/dist/pbrMaterial.esm.js +8 -8739
- package/dist/productAnimations.esm.js +0 -182
- package/dist/productCamera.esm.js +0 -14
- package/dist/productCamera.esm2.js +0 -3870
- package/dist/renderConstants.esm.js +0 -116
- package/dist/renderingPipeline.esm.js +0 -18
- package/dist/renderingPipeline.esm2.js +1 -3594
- package/dist/sceneLoaderFlags.esm.js +0 -51
- package/dist/types.esm.js +0 -30
- package/dist/variants.esm.js +0 -16
- package/dist/variants.esm2.js +0 -3097
- package/dist/webRequest.esm.js +0 -7777
|
@@ -1,1895 +0,0 @@
|
|
|
1
|
-
import { _ as __awaiter } from './_tslib.esm.js';
|
|
2
|
-
import { b as Vector2, V as Vector3, O as Observable, E as EngineStore, e as Vector4 } from './webRequest.esm.js';
|
|
3
|
-
import { a as Color3, C as Color4, R as RegisterClass, G as GetClass } from './math.color.esm.js';
|
|
4
|
-
import { L as Logger, f as AbstractActionManager, D as DeepCopier } from './engine.esm.js';
|
|
5
|
-
import { P as PBRMaterial } from './pbrMaterial.esm.js';
|
|
6
|
-
import { T as TransformNode, M as Mesh } from './mesh.esm.js';
|
|
7
|
-
import { g as getAssetContainer } from './assetCache.esm2.js';
|
|
8
|
-
import { attachDynamicTextures } from './dynamicTexture.esm.js';
|
|
9
|
-
import { generateGuid } from './guid.esm.js';
|
|
10
|
-
import { resetAnimationGroups, executeAnimationGroups } from './productAnimations.esm.js';
|
|
11
|
-
import { V as VariantManager, g as getAllMaterialsForInstance } from './variants.esm2.js';
|
|
12
|
-
import './helperFunctions.esm.js';
|
|
13
|
-
import './math.size.esm.js';
|
|
14
|
-
import './compatibilityOptions.esm.js';
|
|
15
|
-
import './hdrFilteringFunctions.esm.js';
|
|
16
|
-
import './pbrBRDFFunctions.esm.js';
|
|
17
|
-
import './math.axis.esm.js';
|
|
18
|
-
import './math.path.esm.js';
|
|
19
|
-
import './material.esm2.js';
|
|
20
|
-
import './node.esm.js';
|
|
21
|
-
import './bumpVertex.esm.js';
|
|
22
|
-
import './effectFallbacks.esm.js';
|
|
23
|
-
import './sceneLoaderFlags.esm.js';
|
|
24
|
-
import './dynamicTexture.esm2.js';
|
|
25
|
-
import './renderConstants.esm.js';
|
|
26
|
-
import './animation.esm.js';
|
|
27
|
-
import './easing.esm.js';
|
|
28
|
-
import './material.esm.js';
|
|
29
|
-
import './types.esm.js';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The action to be carried out following a trigger
|
|
33
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#available-actions
|
|
34
|
-
*/
|
|
35
|
-
class Action {
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new Action
|
|
38
|
-
* @param triggerOptions the trigger, with or without parameters, for the action
|
|
39
|
-
* @param condition an optional determinant of action
|
|
40
|
-
*/
|
|
41
|
-
constructor(
|
|
42
|
-
/** the trigger, with or without parameters, for the action */
|
|
43
|
-
triggerOptions, condition) {
|
|
44
|
-
this.triggerOptions = triggerOptions;
|
|
45
|
-
/**
|
|
46
|
-
* An event triggered prior to action being executed.
|
|
47
|
-
*/
|
|
48
|
-
this.onBeforeExecuteObservable = new Observable();
|
|
49
|
-
if (triggerOptions.parameter) {
|
|
50
|
-
this.trigger = triggerOptions.trigger;
|
|
51
|
-
this._triggerParameter = triggerOptions.parameter;
|
|
52
|
-
}
|
|
53
|
-
else if (triggerOptions.trigger) {
|
|
54
|
-
this.trigger = triggerOptions.trigger;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
this.trigger = triggerOptions;
|
|
58
|
-
}
|
|
59
|
-
this._nextActiveAction = this;
|
|
60
|
-
this._condition = condition;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Internal only
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
_prepare() { }
|
|
67
|
-
/**
|
|
68
|
-
* Gets the trigger parameter
|
|
69
|
-
* @returns the trigger parameter
|
|
70
|
-
*/
|
|
71
|
-
getTriggerParameter() {
|
|
72
|
-
return this._triggerParameter;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Sets the trigger parameter
|
|
76
|
-
* @param value defines the new trigger parameter
|
|
77
|
-
*/
|
|
78
|
-
setTriggerParameter(value) {
|
|
79
|
-
this._triggerParameter = value;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Internal only - Returns if the current condition allows to run the action
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
_evaluateConditionForCurrentFrame() {
|
|
86
|
-
const condition = this._condition;
|
|
87
|
-
if (!condition) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
const currentRenderId = this._actionManager.getScene().getRenderId();
|
|
91
|
-
// We cache the current evaluation for the current frame
|
|
92
|
-
if (condition._evaluationId !== currentRenderId) {
|
|
93
|
-
condition._evaluationId = currentRenderId;
|
|
94
|
-
condition._currentResult = condition.isValid();
|
|
95
|
-
}
|
|
96
|
-
return condition._currentResult;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Internal only - executes current action event
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
_executeCurrent(evt) {
|
|
103
|
-
const isConditionValid = this._evaluateConditionForCurrentFrame();
|
|
104
|
-
if (!isConditionValid) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
this.onBeforeExecuteObservable.notifyObservers(this);
|
|
108
|
-
this._nextActiveAction.execute(evt);
|
|
109
|
-
this.skipToNextActiveAction();
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Execute placeholder for child classes
|
|
113
|
-
* @param evt optional action event
|
|
114
|
-
*/
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
116
|
-
execute(evt) { }
|
|
117
|
-
/**
|
|
118
|
-
* Skips to next active action
|
|
119
|
-
*/
|
|
120
|
-
skipToNextActiveAction() {
|
|
121
|
-
if (this._nextActiveAction._child) {
|
|
122
|
-
if (!this._nextActiveAction._child._actionManager) {
|
|
123
|
-
this._nextActiveAction._child._actionManager = this._actionManager;
|
|
124
|
-
}
|
|
125
|
-
this._nextActiveAction = this._nextActiveAction._child;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
this._nextActiveAction = this;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Adds action to chain of actions, may be a DoNothingAction
|
|
133
|
-
* @param action defines the next action to execute
|
|
134
|
-
* @returns The action passed in
|
|
135
|
-
* @see https://www.babylonjs-playground.com/#1T30HR#0
|
|
136
|
-
*/
|
|
137
|
-
then(action) {
|
|
138
|
-
this._child = action;
|
|
139
|
-
action._actionManager = this._actionManager;
|
|
140
|
-
action._prepare();
|
|
141
|
-
return action;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Internal only
|
|
145
|
-
* @internal
|
|
146
|
-
*/
|
|
147
|
-
_getProperty(propertyPath) {
|
|
148
|
-
return this._actionManager._getProperty(propertyPath);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* @internal
|
|
152
|
-
*/
|
|
153
|
-
_getEffectiveTarget(target, propertyPath) {
|
|
154
|
-
return this._actionManager._getEffectiveTarget(target, propertyPath);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Serialize placeholder for child classes
|
|
158
|
-
* @param parent of child
|
|
159
|
-
* @returns the serialized object
|
|
160
|
-
*/
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
162
|
-
serialize(parent) { }
|
|
163
|
-
/**
|
|
164
|
-
* Internal only called by serialize
|
|
165
|
-
* @internal
|
|
166
|
-
*/
|
|
167
|
-
_serialize(serializedAction, parent) {
|
|
168
|
-
const serializationObject = {
|
|
169
|
-
type: 1,
|
|
170
|
-
children: [],
|
|
171
|
-
name: serializedAction.name,
|
|
172
|
-
properties: serializedAction.properties || [],
|
|
173
|
-
};
|
|
174
|
-
// Serialize child
|
|
175
|
-
if (this._child) {
|
|
176
|
-
this._child.serialize(serializationObject);
|
|
177
|
-
}
|
|
178
|
-
// Check if "this" has a condition
|
|
179
|
-
if (this._condition) {
|
|
180
|
-
const serializedCondition = this._condition.serialize();
|
|
181
|
-
serializedCondition.children.push(serializationObject);
|
|
182
|
-
if (parent) {
|
|
183
|
-
parent.children.push(serializedCondition);
|
|
184
|
-
}
|
|
185
|
-
return serializedCondition;
|
|
186
|
-
}
|
|
187
|
-
if (parent) {
|
|
188
|
-
parent.children.push(serializationObject);
|
|
189
|
-
}
|
|
190
|
-
return serializationObject;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Internal only
|
|
195
|
-
* @internal
|
|
196
|
-
*/
|
|
197
|
-
Action._SerializeValueAsString = (value) => {
|
|
198
|
-
if (typeof value === "number") {
|
|
199
|
-
return value.toString();
|
|
200
|
-
}
|
|
201
|
-
if (typeof value === "boolean") {
|
|
202
|
-
return value ? "true" : "false";
|
|
203
|
-
}
|
|
204
|
-
if (value instanceof Vector2) {
|
|
205
|
-
return value.x + ", " + value.y;
|
|
206
|
-
}
|
|
207
|
-
if (value instanceof Vector3) {
|
|
208
|
-
return value.x + ", " + value.y + ", " + value.z;
|
|
209
|
-
}
|
|
210
|
-
if (value instanceof Color3) {
|
|
211
|
-
return value.r + ", " + value.g + ", " + value.b;
|
|
212
|
-
}
|
|
213
|
-
if (value instanceof Color4) {
|
|
214
|
-
return value.r + ", " + value.g + ", " + value.b + ", " + value.a;
|
|
215
|
-
}
|
|
216
|
-
return value; // string
|
|
217
|
-
};
|
|
218
|
-
/**
|
|
219
|
-
* Internal only
|
|
220
|
-
* @internal
|
|
221
|
-
*/
|
|
222
|
-
Action._GetTargetProperty = (target) => {
|
|
223
|
-
return {
|
|
224
|
-
name: "target",
|
|
225
|
-
targetType: target._isMesh
|
|
226
|
-
? "MeshProperties"
|
|
227
|
-
: target._isLight
|
|
228
|
-
? "LightProperties"
|
|
229
|
-
: target._isCamera
|
|
230
|
-
? "CameraProperties"
|
|
231
|
-
: target._isMaterial
|
|
232
|
-
? "MaterialProperties"
|
|
233
|
-
: "SceneProperties",
|
|
234
|
-
value: target._isScene ? "Scene" : target.name,
|
|
235
|
-
};
|
|
236
|
-
};
|
|
237
|
-
RegisterClass("BABYLON.Action", Action);
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* A Condition applied to an Action
|
|
241
|
-
*/
|
|
242
|
-
class Condition {
|
|
243
|
-
/**
|
|
244
|
-
* Creates a new Condition
|
|
245
|
-
* @param actionManager the manager of the action the condition is applied to
|
|
246
|
-
*/
|
|
247
|
-
constructor(actionManager) {
|
|
248
|
-
this._actionManager = actionManager;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Check if the current condition is valid
|
|
252
|
-
* @returns a boolean
|
|
253
|
-
*/
|
|
254
|
-
isValid() {
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* @internal
|
|
259
|
-
*/
|
|
260
|
-
_getProperty(propertyPath) {
|
|
261
|
-
return this._actionManager._getProperty(propertyPath);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* @internal
|
|
265
|
-
*/
|
|
266
|
-
_getEffectiveTarget(target, propertyPath) {
|
|
267
|
-
return this._actionManager._getEffectiveTarget(target, propertyPath);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Serialize placeholder for child classes
|
|
271
|
-
* @returns the serialized object
|
|
272
|
-
*/
|
|
273
|
-
serialize() { }
|
|
274
|
-
/**
|
|
275
|
-
* @internal
|
|
276
|
-
*/
|
|
277
|
-
_serialize(serializedCondition) {
|
|
278
|
-
return {
|
|
279
|
-
type: 2,
|
|
280
|
-
children: [],
|
|
281
|
-
name: serializedCondition.name,
|
|
282
|
-
properties: serializedCondition.properties,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Defines specific conditional operators as extensions of Condition
|
|
288
|
-
*/
|
|
289
|
-
class ValueCondition extends Condition {
|
|
290
|
-
/**
|
|
291
|
-
* returns the number for IsEqual
|
|
292
|
-
*/
|
|
293
|
-
static get IsEqual() {
|
|
294
|
-
return ValueCondition._IsEqual;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Returns the number for IsDifferent
|
|
298
|
-
*/
|
|
299
|
-
static get IsDifferent() {
|
|
300
|
-
return ValueCondition._IsDifferent;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Returns the number for IsGreater
|
|
304
|
-
*/
|
|
305
|
-
static get IsGreater() {
|
|
306
|
-
return ValueCondition._IsGreater;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Returns the number for IsLesser
|
|
310
|
-
*/
|
|
311
|
-
static get IsLesser() {
|
|
312
|
-
return ValueCondition._IsLesser;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Creates a new ValueCondition
|
|
316
|
-
* @param actionManager manager for the action the condition applies to
|
|
317
|
-
* @param target for the action
|
|
318
|
-
* @param propertyPath path to specify the property of the target the conditional operator uses
|
|
319
|
-
* @param value the value compared by the conditional operator against the current value of the property
|
|
320
|
-
* @param operator the conditional operator, default ValueCondition.IsEqual
|
|
321
|
-
*/
|
|
322
|
-
constructor(actionManager, target,
|
|
323
|
-
/** path to specify the property of the target the conditional operator uses */
|
|
324
|
-
propertyPath,
|
|
325
|
-
/** the value compared by the conditional operator against the current value of the property */
|
|
326
|
-
value,
|
|
327
|
-
/** the conditional operator, default ValueCondition.IsEqual */
|
|
328
|
-
operator = ValueCondition.IsEqual) {
|
|
329
|
-
super(actionManager);
|
|
330
|
-
this.propertyPath = propertyPath;
|
|
331
|
-
this.value = value;
|
|
332
|
-
this.operator = operator;
|
|
333
|
-
this._target = target;
|
|
334
|
-
this._effectiveTarget = this._getEffectiveTarget(target, this.propertyPath);
|
|
335
|
-
this._property = this._getProperty(this.propertyPath);
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Compares the given value with the property value for the specified conditional operator
|
|
339
|
-
* @returns the result of the comparison
|
|
340
|
-
*/
|
|
341
|
-
isValid() {
|
|
342
|
-
switch (this.operator) {
|
|
343
|
-
case ValueCondition.IsGreater:
|
|
344
|
-
return this._effectiveTarget[this._property] > this.value;
|
|
345
|
-
case ValueCondition.IsLesser:
|
|
346
|
-
return this._effectiveTarget[this._property] < this.value;
|
|
347
|
-
case ValueCondition.IsEqual:
|
|
348
|
-
case ValueCondition.IsDifferent: {
|
|
349
|
-
let check;
|
|
350
|
-
if (this.value.equals) {
|
|
351
|
-
check = this.value.equals(this._effectiveTarget[this._property]);
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
check = this.value === this._effectiveTarget[this._property];
|
|
355
|
-
}
|
|
356
|
-
return this.operator === ValueCondition.IsEqual ? check : !check;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Serialize the ValueCondition into a JSON compatible object
|
|
363
|
-
* @returns serialization object
|
|
364
|
-
*/
|
|
365
|
-
serialize() {
|
|
366
|
-
return this._serialize({
|
|
367
|
-
name: "ValueCondition",
|
|
368
|
-
properties: [
|
|
369
|
-
Action._GetTargetProperty(this._target),
|
|
370
|
-
{ name: "propertyPath", value: this.propertyPath },
|
|
371
|
-
{ name: "value", value: Action._SerializeValueAsString(this.value) },
|
|
372
|
-
{ name: "operator", value: ValueCondition.GetOperatorName(this.operator) },
|
|
373
|
-
],
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Gets the name of the conditional operator for the ValueCondition
|
|
378
|
-
* @param operator the conditional operator
|
|
379
|
-
* @returns the name
|
|
380
|
-
*/
|
|
381
|
-
static GetOperatorName(operator) {
|
|
382
|
-
switch (operator) {
|
|
383
|
-
case ValueCondition._IsEqual:
|
|
384
|
-
return "IsEqual";
|
|
385
|
-
case ValueCondition._IsDifferent:
|
|
386
|
-
return "IsDifferent";
|
|
387
|
-
case ValueCondition._IsGreater:
|
|
388
|
-
return "IsGreater";
|
|
389
|
-
case ValueCondition._IsLesser:
|
|
390
|
-
return "IsLesser";
|
|
391
|
-
default:
|
|
392
|
-
return "";
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
ValueCondition._IsEqual = 0;
|
|
397
|
-
ValueCondition._IsDifferent = 1;
|
|
398
|
-
ValueCondition._IsGreater = 2;
|
|
399
|
-
ValueCondition._IsLesser = 3;
|
|
400
|
-
/**
|
|
401
|
-
* Defines a predicate condition as an extension of Condition
|
|
402
|
-
*/
|
|
403
|
-
class PredicateCondition extends Condition {
|
|
404
|
-
/**
|
|
405
|
-
* Creates a new PredicateCondition
|
|
406
|
-
* @param actionManager manager for the action the condition applies to
|
|
407
|
-
* @param predicate defines the predicate function used to validate the condition
|
|
408
|
-
*/
|
|
409
|
-
constructor(actionManager,
|
|
410
|
-
/** defines the predicate function used to validate the condition */
|
|
411
|
-
predicate) {
|
|
412
|
-
super(actionManager);
|
|
413
|
-
this.predicate = predicate;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* @returns the validity of the predicate condition
|
|
417
|
-
*/
|
|
418
|
-
isValid() {
|
|
419
|
-
return this.predicate();
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Defines a state condition as an extension of Condition
|
|
424
|
-
*/
|
|
425
|
-
class StateCondition extends Condition {
|
|
426
|
-
/**
|
|
427
|
-
* Creates a new StateCondition
|
|
428
|
-
* @param actionManager manager for the action the condition applies to
|
|
429
|
-
* @param target of the condition
|
|
430
|
-
* @param value to compare with target state
|
|
431
|
-
*/
|
|
432
|
-
constructor(actionManager, target,
|
|
433
|
-
/** Value to compare with target state */
|
|
434
|
-
value) {
|
|
435
|
-
super(actionManager);
|
|
436
|
-
this.value = value;
|
|
437
|
-
this._target = target;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Gets a boolean indicating if the current condition is met
|
|
441
|
-
* @returns the validity of the state
|
|
442
|
-
*/
|
|
443
|
-
isValid() {
|
|
444
|
-
return this._target.state === this.value;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Serialize the StateCondition into a JSON compatible object
|
|
448
|
-
* @returns serialization object
|
|
449
|
-
*/
|
|
450
|
-
serialize() {
|
|
451
|
-
return this._serialize({
|
|
452
|
-
name: "StateCondition",
|
|
453
|
-
properties: [Action._GetTargetProperty(this._target), { name: "value", value: this.value }],
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
RegisterClass("BABYLON.ValueCondition", ValueCondition);
|
|
458
|
-
RegisterClass("BABYLON.PredicateCondition", PredicateCondition);
|
|
459
|
-
RegisterClass("BABYLON.StateCondition", StateCondition);
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* This defines an action responsible to toggle a boolean once triggered.
|
|
463
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
464
|
-
*/
|
|
465
|
-
class SwitchBooleanAction extends Action {
|
|
466
|
-
/**
|
|
467
|
-
* Instantiate the action
|
|
468
|
-
* @param triggerOptions defines the trigger options
|
|
469
|
-
* @param target defines the object containing the boolean
|
|
470
|
-
* @param propertyPath defines the path to the boolean property in the target object
|
|
471
|
-
* @param condition defines the trigger related conditions
|
|
472
|
-
*/
|
|
473
|
-
constructor(triggerOptions, target, propertyPath, condition) {
|
|
474
|
-
super(triggerOptions, condition);
|
|
475
|
-
this.propertyPath = propertyPath;
|
|
476
|
-
this._target = this._effectiveTarget = target;
|
|
477
|
-
}
|
|
478
|
-
/** @internal */
|
|
479
|
-
_prepare() {
|
|
480
|
-
this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
|
|
481
|
-
this._property = this._getProperty(this.propertyPath);
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Execute the action toggle the boolean value.
|
|
485
|
-
*/
|
|
486
|
-
execute() {
|
|
487
|
-
this._effectiveTarget[this._property] = !this._effectiveTarget[this._property];
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Serializes the actions and its related information.
|
|
491
|
-
* @param parent defines the object to serialize in
|
|
492
|
-
* @returns the serialized object
|
|
493
|
-
*/
|
|
494
|
-
serialize(parent) {
|
|
495
|
-
return super._serialize({
|
|
496
|
-
name: "SwitchBooleanAction",
|
|
497
|
-
properties: [Action._GetTargetProperty(this._target), { name: "propertyPath", value: this.propertyPath }],
|
|
498
|
-
}, parent);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* This defines an action responsible to set a the state field of the target
|
|
503
|
-
* to a desired value once triggered.
|
|
504
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
505
|
-
*/
|
|
506
|
-
class SetStateAction extends Action {
|
|
507
|
-
/**
|
|
508
|
-
* Instantiate the action
|
|
509
|
-
* @param triggerOptions defines the trigger options
|
|
510
|
-
* @param target defines the object containing the state property
|
|
511
|
-
* @param value defines the value to store in the state field
|
|
512
|
-
* @param condition defines the trigger related conditions
|
|
513
|
-
*/
|
|
514
|
-
constructor(triggerOptions, target, value, condition) {
|
|
515
|
-
super(triggerOptions, condition);
|
|
516
|
-
this.value = value;
|
|
517
|
-
this._target = target;
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Execute the action and store the value on the target state property.
|
|
521
|
-
*/
|
|
522
|
-
execute() {
|
|
523
|
-
this._target.state = this.value;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Serializes the actions and its related information.
|
|
527
|
-
* @param parent defines the object to serialize in
|
|
528
|
-
* @returns the serialized object
|
|
529
|
-
*/
|
|
530
|
-
serialize(parent) {
|
|
531
|
-
return super._serialize({
|
|
532
|
-
name: "SetStateAction",
|
|
533
|
-
properties: [Action._GetTargetProperty(this._target), { name: "value", value: this.value }],
|
|
534
|
-
}, parent);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* This defines an action responsible to set a property of the target
|
|
539
|
-
* to a desired value once triggered.
|
|
540
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
541
|
-
*/
|
|
542
|
-
class SetValueAction extends Action {
|
|
543
|
-
/**
|
|
544
|
-
* Instantiate the action
|
|
545
|
-
* @param triggerOptions defines the trigger options
|
|
546
|
-
* @param target defines the object containing the property
|
|
547
|
-
* @param propertyPath defines the path of the property to set in the target
|
|
548
|
-
* @param value defines the value to set in the property
|
|
549
|
-
* @param condition defines the trigger related conditions
|
|
550
|
-
*/
|
|
551
|
-
constructor(triggerOptions, target, propertyPath, value, condition) {
|
|
552
|
-
super(triggerOptions, condition);
|
|
553
|
-
this.propertyPath = propertyPath;
|
|
554
|
-
this.value = value;
|
|
555
|
-
this._target = this._effectiveTarget = target;
|
|
556
|
-
}
|
|
557
|
-
/** @internal */
|
|
558
|
-
_prepare() {
|
|
559
|
-
this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
|
|
560
|
-
this._property = this._getProperty(this.propertyPath);
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Execute the action and set the targeted property to the desired value.
|
|
564
|
-
*/
|
|
565
|
-
execute() {
|
|
566
|
-
this._effectiveTarget[this._property] = this.value;
|
|
567
|
-
if (this._target.markAsDirty) {
|
|
568
|
-
this._target.markAsDirty(this._property);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Serializes the actions and its related information.
|
|
573
|
-
* @param parent defines the object to serialize in
|
|
574
|
-
* @returns the serialized object
|
|
575
|
-
*/
|
|
576
|
-
serialize(parent) {
|
|
577
|
-
return super._serialize({
|
|
578
|
-
name: "SetValueAction",
|
|
579
|
-
properties: [
|
|
580
|
-
Action._GetTargetProperty(this._target),
|
|
581
|
-
{ name: "propertyPath", value: this.propertyPath },
|
|
582
|
-
{ name: "value", value: Action._SerializeValueAsString(this.value) },
|
|
583
|
-
],
|
|
584
|
-
}, parent);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* This defines an action responsible to increment the target value
|
|
589
|
-
* to a desired value once triggered.
|
|
590
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
591
|
-
*/
|
|
592
|
-
class IncrementValueAction extends Action {
|
|
593
|
-
/**
|
|
594
|
-
* Instantiate the action
|
|
595
|
-
* @param triggerOptions defines the trigger options
|
|
596
|
-
* @param target defines the object containing the property
|
|
597
|
-
* @param propertyPath defines the path of the property to increment in the target
|
|
598
|
-
* @param value defines the value value we should increment the property by
|
|
599
|
-
* @param condition defines the trigger related conditions
|
|
600
|
-
*/
|
|
601
|
-
constructor(triggerOptions, target, propertyPath, value, condition) {
|
|
602
|
-
super(triggerOptions, condition);
|
|
603
|
-
this.propertyPath = propertyPath;
|
|
604
|
-
this.value = value;
|
|
605
|
-
this._target = this._effectiveTarget = target;
|
|
606
|
-
}
|
|
607
|
-
/** @internal */
|
|
608
|
-
_prepare() {
|
|
609
|
-
this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
|
|
610
|
-
this._property = this._getProperty(this.propertyPath);
|
|
611
|
-
if (typeof this._effectiveTarget[this._property] !== "number") {
|
|
612
|
-
Logger.Warn("Warning: IncrementValueAction can only be used with number values");
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Execute the action and increment the target of the value amount.
|
|
617
|
-
*/
|
|
618
|
-
execute() {
|
|
619
|
-
this._effectiveTarget[this._property] += this.value;
|
|
620
|
-
if (this._target.markAsDirty) {
|
|
621
|
-
this._target.markAsDirty(this._property);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Serializes the actions and its related information.
|
|
626
|
-
* @param parent defines the object to serialize in
|
|
627
|
-
* @returns the serialized object
|
|
628
|
-
*/
|
|
629
|
-
serialize(parent) {
|
|
630
|
-
return super._serialize({
|
|
631
|
-
name: "IncrementValueAction",
|
|
632
|
-
properties: [
|
|
633
|
-
Action._GetTargetProperty(this._target),
|
|
634
|
-
{ name: "propertyPath", value: this.propertyPath },
|
|
635
|
-
{ name: "value", value: Action._SerializeValueAsString(this.value) },
|
|
636
|
-
],
|
|
637
|
-
}, parent);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* This defines an action responsible to start an animation once triggered.
|
|
642
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
643
|
-
*/
|
|
644
|
-
class PlayAnimationAction extends Action {
|
|
645
|
-
/**
|
|
646
|
-
* Instantiate the action
|
|
647
|
-
* @param triggerOptions defines the trigger options
|
|
648
|
-
* @param target defines the target animation or animation name
|
|
649
|
-
* @param from defines from where the animation should start (animation frame)
|
|
650
|
-
* @param to defines where the animation should stop (animation frame)
|
|
651
|
-
* @param loop defines if the animation should loop or stop after the first play
|
|
652
|
-
* @param condition defines the trigger related conditions
|
|
653
|
-
*/
|
|
654
|
-
constructor(triggerOptions, target, from, to, loop, condition) {
|
|
655
|
-
super(triggerOptions, condition);
|
|
656
|
-
this.from = from;
|
|
657
|
-
this.to = to;
|
|
658
|
-
this.loop = loop;
|
|
659
|
-
this._target = target;
|
|
660
|
-
}
|
|
661
|
-
/** @internal */
|
|
662
|
-
_prepare() { }
|
|
663
|
-
/**
|
|
664
|
-
* Execute the action and play the animation.
|
|
665
|
-
*/
|
|
666
|
-
execute() {
|
|
667
|
-
const scene = this._actionManager.getScene();
|
|
668
|
-
scene.beginAnimation(this._target, this.from, this.to, this.loop);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Serializes the actions and its related information.
|
|
672
|
-
* @param parent defines the object to serialize in
|
|
673
|
-
* @returns the serialized object
|
|
674
|
-
*/
|
|
675
|
-
serialize(parent) {
|
|
676
|
-
return super._serialize({
|
|
677
|
-
name: "PlayAnimationAction",
|
|
678
|
-
properties: [
|
|
679
|
-
Action._GetTargetProperty(this._target),
|
|
680
|
-
{ name: "from", value: String(this.from) },
|
|
681
|
-
{ name: "to", value: String(this.to) },
|
|
682
|
-
{ name: "loop", value: Action._SerializeValueAsString(this.loop) || false },
|
|
683
|
-
],
|
|
684
|
-
}, parent);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* This defines an action responsible to stop an animation once triggered.
|
|
689
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
690
|
-
*/
|
|
691
|
-
class StopAnimationAction extends Action {
|
|
692
|
-
/**
|
|
693
|
-
* Instantiate the action
|
|
694
|
-
* @param triggerOptions defines the trigger options
|
|
695
|
-
* @param target defines the target animation or animation name
|
|
696
|
-
* @param condition defines the trigger related conditions
|
|
697
|
-
*/
|
|
698
|
-
constructor(triggerOptions, target, condition) {
|
|
699
|
-
super(triggerOptions, condition);
|
|
700
|
-
this._target = target;
|
|
701
|
-
}
|
|
702
|
-
/** @internal */
|
|
703
|
-
_prepare() { }
|
|
704
|
-
/**
|
|
705
|
-
* Execute the action and stop the animation.
|
|
706
|
-
*/
|
|
707
|
-
execute() {
|
|
708
|
-
const scene = this._actionManager.getScene();
|
|
709
|
-
scene.stopAnimation(this._target);
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Serializes the actions and its related information.
|
|
713
|
-
* @param parent defines the object to serialize in
|
|
714
|
-
* @returns the serialized object
|
|
715
|
-
*/
|
|
716
|
-
serialize(parent) {
|
|
717
|
-
return super._serialize({
|
|
718
|
-
name: "StopAnimationAction",
|
|
719
|
-
properties: [Action._GetTargetProperty(this._target)],
|
|
720
|
-
}, parent);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* This defines an action responsible that does nothing once triggered.
|
|
725
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
726
|
-
*/
|
|
727
|
-
class DoNothingAction extends Action {
|
|
728
|
-
/**
|
|
729
|
-
* Instantiate the action
|
|
730
|
-
* @param triggerOptions defines the trigger options
|
|
731
|
-
* @param condition defines the trigger related conditions
|
|
732
|
-
*/
|
|
733
|
-
constructor(triggerOptions = 0, condition) {
|
|
734
|
-
super(triggerOptions, condition);
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Execute the action and do nothing.
|
|
738
|
-
*/
|
|
739
|
-
execute() { }
|
|
740
|
-
/**
|
|
741
|
-
* Serializes the actions and its related information.
|
|
742
|
-
* @param parent defines the object to serialize in
|
|
743
|
-
* @returns the serialized object
|
|
744
|
-
*/
|
|
745
|
-
serialize(parent) {
|
|
746
|
-
return super._serialize({
|
|
747
|
-
name: "DoNothingAction",
|
|
748
|
-
properties: [],
|
|
749
|
-
}, parent);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* This defines an action responsible to trigger several actions once triggered.
|
|
754
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
755
|
-
*/
|
|
756
|
-
class CombineAction extends Action {
|
|
757
|
-
/**
|
|
758
|
-
* Instantiate the action
|
|
759
|
-
* @param triggerOptions defines the trigger options
|
|
760
|
-
* @param children defines the list of aggregated animations to run
|
|
761
|
-
* @param condition defines the trigger related conditions
|
|
762
|
-
* @param enableChildrenConditions defines if the children actions conditions should be check before execution
|
|
763
|
-
*/
|
|
764
|
-
constructor(triggerOptions, children, condition, enableChildrenConditions = true) {
|
|
765
|
-
super(triggerOptions, condition);
|
|
766
|
-
this.children = children;
|
|
767
|
-
this.enableChildrenConditions = enableChildrenConditions;
|
|
768
|
-
}
|
|
769
|
-
/** @internal */
|
|
770
|
-
_prepare() {
|
|
771
|
-
for (let index = 0; index < this.children.length; index++) {
|
|
772
|
-
this.children[index]._actionManager = this._actionManager;
|
|
773
|
-
this.children[index]._prepare();
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
/**
|
|
777
|
-
* Execute the action and executes all the aggregated actions.
|
|
778
|
-
* @param evt
|
|
779
|
-
*/
|
|
780
|
-
execute(evt) {
|
|
781
|
-
for (const action of this.children) {
|
|
782
|
-
if (!this.enableChildrenConditions || action._evaluateConditionForCurrentFrame()) {
|
|
783
|
-
action.execute(evt);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* Serializes the actions and its related information.
|
|
789
|
-
* @param parent defines the object to serialize in
|
|
790
|
-
* @returns the serialized object
|
|
791
|
-
*/
|
|
792
|
-
serialize(parent) {
|
|
793
|
-
const serializationObject = super._serialize({
|
|
794
|
-
name: "CombineAction",
|
|
795
|
-
properties: [],
|
|
796
|
-
combine: [],
|
|
797
|
-
}, parent);
|
|
798
|
-
for (let i = 0; i < this.children.length; i++) {
|
|
799
|
-
serializationObject.combine.push(this.children[i].serialize(null));
|
|
800
|
-
}
|
|
801
|
-
return serializationObject;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* This defines an action responsible to run code (external event) once triggered.
|
|
806
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
807
|
-
*/
|
|
808
|
-
class ExecuteCodeAction extends Action {
|
|
809
|
-
/**
|
|
810
|
-
* Instantiate the action
|
|
811
|
-
* @param triggerOptions defines the trigger options
|
|
812
|
-
* @param func defines the callback function to run
|
|
813
|
-
* @param condition defines the trigger related conditions
|
|
814
|
-
*/
|
|
815
|
-
constructor(triggerOptions, func, condition) {
|
|
816
|
-
super(triggerOptions, condition);
|
|
817
|
-
this.func = func;
|
|
818
|
-
}
|
|
819
|
-
/**
|
|
820
|
-
* Execute the action and run the attached code.
|
|
821
|
-
* @param evt
|
|
822
|
-
*/
|
|
823
|
-
execute(evt) {
|
|
824
|
-
this.func(evt);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* This defines an action responsible to set the parent property of the target once triggered.
|
|
829
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
830
|
-
*/
|
|
831
|
-
class SetParentAction extends Action {
|
|
832
|
-
/**
|
|
833
|
-
* Instantiate the action
|
|
834
|
-
* @param triggerOptions defines the trigger options
|
|
835
|
-
* @param target defines the target containing the parent property
|
|
836
|
-
* @param parent defines from where the animation should start (animation frame)
|
|
837
|
-
* @param condition defines the trigger related conditions
|
|
838
|
-
*/
|
|
839
|
-
constructor(triggerOptions, target, parent, condition) {
|
|
840
|
-
super(triggerOptions, condition);
|
|
841
|
-
this._target = target;
|
|
842
|
-
this._parent = parent;
|
|
843
|
-
}
|
|
844
|
-
/** @internal */
|
|
845
|
-
_prepare() { }
|
|
846
|
-
/**
|
|
847
|
-
* Execute the action and set the parent property.
|
|
848
|
-
*/
|
|
849
|
-
execute() {
|
|
850
|
-
if (this._target.parent === this._parent) {
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
const invertParentWorldMatrix = this._parent.getWorldMatrix().clone();
|
|
854
|
-
invertParentWorldMatrix.invert();
|
|
855
|
-
this._target.position = Vector3.TransformCoordinates(this._target.position, invertParentWorldMatrix);
|
|
856
|
-
this._target.parent = this._parent;
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Serializes the actions and its related information.
|
|
860
|
-
* @param parent defines the object to serialize in
|
|
861
|
-
* @returns the serialized object
|
|
862
|
-
*/
|
|
863
|
-
serialize(parent) {
|
|
864
|
-
return super._serialize({
|
|
865
|
-
name: "SetParentAction",
|
|
866
|
-
properties: [Action._GetTargetProperty(this._target), Action._GetTargetProperty(this._parent)],
|
|
867
|
-
}, parent);
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
RegisterClass("BABYLON.SetParentAction", SetParentAction);
|
|
871
|
-
RegisterClass("BABYLON.ExecuteCodeAction", ExecuteCodeAction);
|
|
872
|
-
RegisterClass("BABYLON.DoNothingAction", DoNothingAction);
|
|
873
|
-
RegisterClass("BABYLON.StopAnimationAction", StopAnimationAction);
|
|
874
|
-
RegisterClass("BABYLON.PlayAnimationAction", PlayAnimationAction);
|
|
875
|
-
RegisterClass("BABYLON.IncrementValueAction", IncrementValueAction);
|
|
876
|
-
RegisterClass("BABYLON.SetValueAction", SetValueAction);
|
|
877
|
-
RegisterClass("BABYLON.SetStateAction", SetStateAction);
|
|
878
|
-
RegisterClass("BABYLON.SetParentAction", SetParentAction);
|
|
879
|
-
RegisterClass("BABYLON.SwitchBooleanAction", SwitchBooleanAction);
|
|
880
|
-
RegisterClass("BABYLON.CombineAction", CombineAction);
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
* Action Manager manages all events to be triggered on a given mesh or the global scene.
|
|
884
|
-
* A single scene can have many Action Managers to handle predefined actions on specific meshes.
|
|
885
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions
|
|
886
|
-
*/
|
|
887
|
-
class ActionManager extends AbstractActionManager {
|
|
888
|
-
/**
|
|
889
|
-
* Creates a new action manager
|
|
890
|
-
* @param scene defines the hosting scene
|
|
891
|
-
*/
|
|
892
|
-
constructor(scene) {
|
|
893
|
-
super();
|
|
894
|
-
scene = scene || EngineStore.LastCreatedScene;
|
|
895
|
-
if (!scene) {
|
|
896
|
-
return;
|
|
897
|
-
}
|
|
898
|
-
this._scene = scene;
|
|
899
|
-
scene.actionManagers.push(this);
|
|
900
|
-
}
|
|
901
|
-
// Methods
|
|
902
|
-
/**
|
|
903
|
-
* Releases all associated resources
|
|
904
|
-
*/
|
|
905
|
-
dispose() {
|
|
906
|
-
const index = this._scene.actionManagers.indexOf(this);
|
|
907
|
-
for (let i = 0; i < this.actions.length; i++) {
|
|
908
|
-
const action = this.actions[i];
|
|
909
|
-
ActionManager.Triggers[action.trigger]--;
|
|
910
|
-
if (ActionManager.Triggers[action.trigger] === 0) {
|
|
911
|
-
delete ActionManager.Triggers[action.trigger];
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
if (index > -1) {
|
|
915
|
-
this._scene.actionManagers.splice(index, 1);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Gets hosting scene
|
|
920
|
-
* @returns the hosting scene
|
|
921
|
-
*/
|
|
922
|
-
getScene() {
|
|
923
|
-
return this._scene;
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Does this action manager handles actions of any of the given triggers
|
|
927
|
-
* @param triggers defines the triggers to be tested
|
|
928
|
-
* @returns a boolean indicating whether one (or more) of the triggers is handled
|
|
929
|
-
*/
|
|
930
|
-
hasSpecificTriggers(triggers) {
|
|
931
|
-
for (let index = 0; index < this.actions.length; index++) {
|
|
932
|
-
const action = this.actions[index];
|
|
933
|
-
if (triggers.indexOf(action.trigger) > -1) {
|
|
934
|
-
return true;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Does this action manager handles actions of any of the given triggers. This function takes two arguments for
|
|
941
|
-
* speed.
|
|
942
|
-
* @param triggerA defines the trigger to be tested
|
|
943
|
-
* @param triggerB defines the trigger to be tested
|
|
944
|
-
* @returns a boolean indicating whether one (or more) of the triggers is handled
|
|
945
|
-
*/
|
|
946
|
-
hasSpecificTriggers2(triggerA, triggerB) {
|
|
947
|
-
for (let index = 0; index < this.actions.length; index++) {
|
|
948
|
-
const action = this.actions[index];
|
|
949
|
-
if (triggerA == action.trigger || triggerB == action.trigger) {
|
|
950
|
-
return true;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return false;
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Does this action manager handles actions of a given trigger
|
|
957
|
-
* @param trigger defines the trigger to be tested
|
|
958
|
-
* @param parameterPredicate defines an optional predicate to filter triggers by parameter
|
|
959
|
-
* @returns whether the trigger is handled
|
|
960
|
-
*/
|
|
961
|
-
hasSpecificTrigger(trigger, parameterPredicate) {
|
|
962
|
-
for (let index = 0; index < this.actions.length; index++) {
|
|
963
|
-
const action = this.actions[index];
|
|
964
|
-
if (action.trigger === trigger) {
|
|
965
|
-
if (parameterPredicate) {
|
|
966
|
-
if (parameterPredicate(action.getTriggerParameter())) {
|
|
967
|
-
return true;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
else {
|
|
971
|
-
return true;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
return false;
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Does this action manager has pointer triggers
|
|
979
|
-
*/
|
|
980
|
-
get hasPointerTriggers() {
|
|
981
|
-
for (let index = 0; index < this.actions.length; index++) {
|
|
982
|
-
const action = this.actions[index];
|
|
983
|
-
if (action.trigger >= ActionManager.OnPickTrigger && action.trigger <= ActionManager.OnPointerOutTrigger) {
|
|
984
|
-
return true;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
return false;
|
|
988
|
-
}
|
|
989
|
-
/**
|
|
990
|
-
* Does this action manager has pick triggers
|
|
991
|
-
*/
|
|
992
|
-
get hasPickTriggers() {
|
|
993
|
-
for (let index = 0; index < this.actions.length; index++) {
|
|
994
|
-
const action = this.actions[index];
|
|
995
|
-
if (action.trigger >= ActionManager.OnPickTrigger && action.trigger <= ActionManager.OnPickUpTrigger) {
|
|
996
|
-
return true;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
return false;
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Registers an action to this action manager
|
|
1003
|
-
* @param action defines the action to be registered
|
|
1004
|
-
* @returns the action amended (prepared) after registration
|
|
1005
|
-
*/
|
|
1006
|
-
registerAction(action) {
|
|
1007
|
-
if (action.trigger === ActionManager.OnEveryFrameTrigger) {
|
|
1008
|
-
if (this.getScene().actionManager !== this) {
|
|
1009
|
-
Logger.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
|
|
1010
|
-
return null;
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
this.actions.push(action);
|
|
1014
|
-
this.getScene()._registeredActions++;
|
|
1015
|
-
if (ActionManager.Triggers[action.trigger]) {
|
|
1016
|
-
ActionManager.Triggers[action.trigger]++;
|
|
1017
|
-
}
|
|
1018
|
-
else {
|
|
1019
|
-
ActionManager.Triggers[action.trigger] = 1;
|
|
1020
|
-
}
|
|
1021
|
-
action._actionManager = this;
|
|
1022
|
-
action._prepare();
|
|
1023
|
-
return action;
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* Unregisters an action to this action manager
|
|
1027
|
-
* @param action defines the action to be unregistered
|
|
1028
|
-
* @returns a boolean indicating whether the action has been unregistered
|
|
1029
|
-
*/
|
|
1030
|
-
unregisterAction(action) {
|
|
1031
|
-
const index = this.actions.indexOf(action);
|
|
1032
|
-
if (index !== -1) {
|
|
1033
|
-
this.actions.splice(index, 1);
|
|
1034
|
-
ActionManager.Triggers[action.trigger] -= 1;
|
|
1035
|
-
if (ActionManager.Triggers[action.trigger] === 0) {
|
|
1036
|
-
delete ActionManager.Triggers[action.trigger];
|
|
1037
|
-
}
|
|
1038
|
-
action._actionManager = null;
|
|
1039
|
-
this.getScene()._registeredActions--;
|
|
1040
|
-
return true;
|
|
1041
|
-
}
|
|
1042
|
-
return false;
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Process a specific trigger
|
|
1046
|
-
* @param trigger defines the trigger to process
|
|
1047
|
-
* @param evt defines the event details to be processed
|
|
1048
|
-
*/
|
|
1049
|
-
processTrigger(trigger, evt) {
|
|
1050
|
-
for (let index = 0; index < this.actions.length; index++) {
|
|
1051
|
-
const action = this.actions[index];
|
|
1052
|
-
if (action.trigger === trigger) {
|
|
1053
|
-
if (evt) {
|
|
1054
|
-
if (trigger === ActionManager.OnKeyUpTrigger || trigger === ActionManager.OnKeyDownTrigger) {
|
|
1055
|
-
const parameter = action.getTriggerParameter();
|
|
1056
|
-
if (typeof parameter === "function") {
|
|
1057
|
-
if (!parameter(evt)) {
|
|
1058
|
-
continue;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
else if (parameter && parameter !== evt.sourceEvent.keyCode) {
|
|
1062
|
-
if (!parameter.toLowerCase) {
|
|
1063
|
-
continue;
|
|
1064
|
-
}
|
|
1065
|
-
const lowerCase = parameter.toLowerCase();
|
|
1066
|
-
if (lowerCase !== evt.sourceEvent.key) {
|
|
1067
|
-
const unicode = evt.sourceEvent.charCode ? evt.sourceEvent.charCode : evt.sourceEvent.keyCode;
|
|
1068
|
-
const actualkey = String.fromCharCode(unicode).toLowerCase();
|
|
1069
|
-
if (actualkey !== lowerCase) {
|
|
1070
|
-
continue;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
action._executeCurrent(evt);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
/**
|
|
1081
|
-
* @internal
|
|
1082
|
-
*/
|
|
1083
|
-
_getEffectiveTarget(target, propertyPath) {
|
|
1084
|
-
const properties = propertyPath.split(".");
|
|
1085
|
-
for (let index = 0; index < properties.length - 1; index++) {
|
|
1086
|
-
target = target[properties[index]];
|
|
1087
|
-
}
|
|
1088
|
-
return target;
|
|
1089
|
-
}
|
|
1090
|
-
/**
|
|
1091
|
-
* @internal
|
|
1092
|
-
*/
|
|
1093
|
-
_getProperty(propertyPath) {
|
|
1094
|
-
const properties = propertyPath.split(".");
|
|
1095
|
-
return properties[properties.length - 1];
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Serialize this manager to a JSON object
|
|
1099
|
-
* @param name defines the property name to store this manager
|
|
1100
|
-
* @returns a JSON representation of this manager
|
|
1101
|
-
*/
|
|
1102
|
-
serialize(name) {
|
|
1103
|
-
const root = {
|
|
1104
|
-
children: new Array(),
|
|
1105
|
-
name: name,
|
|
1106
|
-
type: 3,
|
|
1107
|
-
properties: new Array(), // Empty for root but required
|
|
1108
|
-
};
|
|
1109
|
-
for (let i = 0; i < this.actions.length; i++) {
|
|
1110
|
-
const triggerObject = {
|
|
1111
|
-
type: 0,
|
|
1112
|
-
children: new Array(),
|
|
1113
|
-
name: ActionManager.GetTriggerName(this.actions[i].trigger),
|
|
1114
|
-
properties: new Array(),
|
|
1115
|
-
};
|
|
1116
|
-
const triggerOptions = this.actions[i].triggerOptions;
|
|
1117
|
-
if (triggerOptions && typeof triggerOptions !== "number") {
|
|
1118
|
-
if (triggerOptions.parameter instanceof Node) {
|
|
1119
|
-
triggerObject.properties.push(Action._GetTargetProperty(triggerOptions.parameter));
|
|
1120
|
-
}
|
|
1121
|
-
else if (typeof triggerOptions.parameter === "object") {
|
|
1122
|
-
const parameter = {};
|
|
1123
|
-
DeepCopier.DeepCopy(triggerOptions.parameter, parameter, ["mesh"]);
|
|
1124
|
-
if (triggerOptions.parameter && triggerOptions.parameter.mesh) {
|
|
1125
|
-
parameter._meshId = triggerOptions.parameter.mesh.id;
|
|
1126
|
-
}
|
|
1127
|
-
triggerObject.properties.push({ name: "parameter", targetType: null, value: parameter });
|
|
1128
|
-
}
|
|
1129
|
-
else {
|
|
1130
|
-
triggerObject.properties.push({ name: "parameter", targetType: null, value: triggerOptions.parameter });
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
// Serialize child action, recursively
|
|
1134
|
-
this.actions[i].serialize(triggerObject);
|
|
1135
|
-
// Add serialized trigger
|
|
1136
|
-
root.children.push(triggerObject);
|
|
1137
|
-
}
|
|
1138
|
-
return root;
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Creates a new ActionManager from a JSON data
|
|
1142
|
-
* @param parsedActions defines the JSON data to read from
|
|
1143
|
-
* @param object defines the hosting mesh
|
|
1144
|
-
* @param scene defines the hosting scene
|
|
1145
|
-
*/
|
|
1146
|
-
static Parse(parsedActions, object, scene) {
|
|
1147
|
-
const actionManager = new ActionManager(scene);
|
|
1148
|
-
if (object === null) {
|
|
1149
|
-
scene.actionManager = actionManager;
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
-
object.actionManager = actionManager;
|
|
1153
|
-
}
|
|
1154
|
-
// instantiate a new object
|
|
1155
|
-
const instantiate = (name, params) => {
|
|
1156
|
-
const internalClassType = GetClass("BABYLON." + name);
|
|
1157
|
-
return internalClassType && new internalClassType(...params);
|
|
1158
|
-
};
|
|
1159
|
-
const parseParameter = (name, value, target, propertyPath) => {
|
|
1160
|
-
if (propertyPath === null) {
|
|
1161
|
-
// String, boolean or float
|
|
1162
|
-
const floatValue = parseFloat(value);
|
|
1163
|
-
if (value === "true" || value === "false") {
|
|
1164
|
-
return value === "true";
|
|
1165
|
-
}
|
|
1166
|
-
else {
|
|
1167
|
-
return isNaN(floatValue) ? value : floatValue;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
const effectiveTarget = propertyPath.split(".");
|
|
1171
|
-
const values = value.split(",");
|
|
1172
|
-
// Get effective Target
|
|
1173
|
-
for (let i = 0; i < effectiveTarget.length; i++) {
|
|
1174
|
-
target = target[effectiveTarget[i]];
|
|
1175
|
-
}
|
|
1176
|
-
// Return appropriate value with its type
|
|
1177
|
-
if (typeof target === "boolean") {
|
|
1178
|
-
return values[0] === "true";
|
|
1179
|
-
}
|
|
1180
|
-
if (typeof target === "string") {
|
|
1181
|
-
return values[0];
|
|
1182
|
-
}
|
|
1183
|
-
// Parameters with multiple values such as Vector3 etc.
|
|
1184
|
-
const split = new Array();
|
|
1185
|
-
for (let i = 0; i < values.length; i++) {
|
|
1186
|
-
split.push(parseFloat(values[i]));
|
|
1187
|
-
}
|
|
1188
|
-
if (target instanceof Vector3) {
|
|
1189
|
-
return Vector3.FromArray(split);
|
|
1190
|
-
}
|
|
1191
|
-
if (target instanceof Vector4) {
|
|
1192
|
-
return Vector4.FromArray(split);
|
|
1193
|
-
}
|
|
1194
|
-
if (target instanceof Color3) {
|
|
1195
|
-
return Color3.FromArray(split);
|
|
1196
|
-
}
|
|
1197
|
-
if (target instanceof Color4) {
|
|
1198
|
-
return Color4.FromArray(split);
|
|
1199
|
-
}
|
|
1200
|
-
return parseFloat(values[0]);
|
|
1201
|
-
};
|
|
1202
|
-
// traverse graph per trigger
|
|
1203
|
-
const traverse = (parsedAction, trigger, condition, action, combineArray = null) => {
|
|
1204
|
-
if (parsedAction.detached) {
|
|
1205
|
-
return;
|
|
1206
|
-
}
|
|
1207
|
-
const parameters = new Array();
|
|
1208
|
-
let target = null;
|
|
1209
|
-
let propertyPath = null;
|
|
1210
|
-
const combine = parsedAction.combine && parsedAction.combine.length > 0;
|
|
1211
|
-
// Parameters
|
|
1212
|
-
if (parsedAction.type === 2) {
|
|
1213
|
-
parameters.push(actionManager);
|
|
1214
|
-
}
|
|
1215
|
-
else {
|
|
1216
|
-
parameters.push(trigger);
|
|
1217
|
-
}
|
|
1218
|
-
if (combine) {
|
|
1219
|
-
const actions = new Array();
|
|
1220
|
-
for (let j = 0; j < parsedAction.combine.length; j++) {
|
|
1221
|
-
traverse(parsedAction.combine[j], ActionManager.NothingTrigger, condition, action, actions);
|
|
1222
|
-
}
|
|
1223
|
-
parameters.push(actions);
|
|
1224
|
-
}
|
|
1225
|
-
else {
|
|
1226
|
-
for (let i = 0; i < parsedAction.properties.length; i++) {
|
|
1227
|
-
let value = parsedAction.properties[i].value;
|
|
1228
|
-
const name = parsedAction.properties[i].name;
|
|
1229
|
-
const targetType = parsedAction.properties[i].targetType;
|
|
1230
|
-
if (name === "target") {
|
|
1231
|
-
if (targetType === "SceneProperties") {
|
|
1232
|
-
value = target = scene;
|
|
1233
|
-
}
|
|
1234
|
-
else if (targetType === "MaterialProperties") {
|
|
1235
|
-
value = target = scene.getMaterialByName(value);
|
|
1236
|
-
}
|
|
1237
|
-
else {
|
|
1238
|
-
value = target = scene.getNodeByName(value);
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
else if (name === "parent") {
|
|
1242
|
-
value = scene.getNodeByName(value);
|
|
1243
|
-
}
|
|
1244
|
-
else if (name === "sound") {
|
|
1245
|
-
// Can not externalize to component, so only checks for the presence off the API.
|
|
1246
|
-
if (scene.getSoundByName) {
|
|
1247
|
-
value = scene.getSoundByName(value);
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
else if (name !== "propertyPath") {
|
|
1251
|
-
if (parsedAction.type === 2 && name === "operator") {
|
|
1252
|
-
value = ValueCondition[value];
|
|
1253
|
-
}
|
|
1254
|
-
else {
|
|
1255
|
-
value = parseParameter(name, value, target, name === "value" ? propertyPath : null);
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
else {
|
|
1259
|
-
propertyPath = value;
|
|
1260
|
-
}
|
|
1261
|
-
parameters.push(value);
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
if (combineArray === null) {
|
|
1265
|
-
parameters.push(condition);
|
|
1266
|
-
}
|
|
1267
|
-
else {
|
|
1268
|
-
parameters.push(null);
|
|
1269
|
-
}
|
|
1270
|
-
// If interpolate value action
|
|
1271
|
-
if (parsedAction.name === "InterpolateValueAction") {
|
|
1272
|
-
const param = parameters[parameters.length - 2];
|
|
1273
|
-
parameters[parameters.length - 1] = param;
|
|
1274
|
-
parameters[parameters.length - 2] = condition;
|
|
1275
|
-
}
|
|
1276
|
-
// Action or condition(s) and not CombineAction
|
|
1277
|
-
let newAction = instantiate(parsedAction.name, parameters);
|
|
1278
|
-
if (newAction instanceof Condition && condition !== null) {
|
|
1279
|
-
const nothing = new DoNothingAction(trigger, condition);
|
|
1280
|
-
if (action) {
|
|
1281
|
-
action.then(nothing);
|
|
1282
|
-
}
|
|
1283
|
-
else {
|
|
1284
|
-
actionManager.registerAction(nothing);
|
|
1285
|
-
}
|
|
1286
|
-
action = nothing;
|
|
1287
|
-
}
|
|
1288
|
-
if (combineArray === null) {
|
|
1289
|
-
if (newAction instanceof Condition) {
|
|
1290
|
-
condition = newAction;
|
|
1291
|
-
newAction = action;
|
|
1292
|
-
}
|
|
1293
|
-
else {
|
|
1294
|
-
condition = null;
|
|
1295
|
-
if (action) {
|
|
1296
|
-
action.then(newAction);
|
|
1297
|
-
}
|
|
1298
|
-
else {
|
|
1299
|
-
actionManager.registerAction(newAction);
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
else {
|
|
1304
|
-
combineArray.push(newAction);
|
|
1305
|
-
}
|
|
1306
|
-
for (let i = 0; i < parsedAction.children.length; i++) {
|
|
1307
|
-
traverse(parsedAction.children[i], trigger, condition, newAction, null);
|
|
1308
|
-
}
|
|
1309
|
-
};
|
|
1310
|
-
// triggers
|
|
1311
|
-
for (let i = 0; i < parsedActions.children.length; i++) {
|
|
1312
|
-
let triggerParams;
|
|
1313
|
-
const trigger = parsedActions.children[i];
|
|
1314
|
-
if (trigger.properties.length > 0) {
|
|
1315
|
-
const param = trigger.properties[0].value;
|
|
1316
|
-
const value = trigger.properties[0].targetType === null ? param : scene.getMeshByName(param);
|
|
1317
|
-
if (value._meshId) {
|
|
1318
|
-
value.mesh = scene.getMeshById(value._meshId);
|
|
1319
|
-
}
|
|
1320
|
-
triggerParams = { trigger: ActionManager[trigger.name], parameter: value };
|
|
1321
|
-
}
|
|
1322
|
-
else {
|
|
1323
|
-
triggerParams = ActionManager[trigger.name];
|
|
1324
|
-
}
|
|
1325
|
-
for (let j = 0; j < trigger.children.length; j++) {
|
|
1326
|
-
if (!trigger.detached) {
|
|
1327
|
-
traverse(trigger.children[j], triggerParams, null, null);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* Get a trigger name by index
|
|
1334
|
-
* @param trigger defines the trigger index
|
|
1335
|
-
* @returns a trigger name
|
|
1336
|
-
*/
|
|
1337
|
-
static GetTriggerName(trigger) {
|
|
1338
|
-
switch (trigger) {
|
|
1339
|
-
case 0:
|
|
1340
|
-
return "NothingTrigger";
|
|
1341
|
-
case 1:
|
|
1342
|
-
return "OnPickTrigger";
|
|
1343
|
-
case 2:
|
|
1344
|
-
return "OnLeftPickTrigger";
|
|
1345
|
-
case 3:
|
|
1346
|
-
return "OnRightPickTrigger";
|
|
1347
|
-
case 4:
|
|
1348
|
-
return "OnCenterPickTrigger";
|
|
1349
|
-
case 5:
|
|
1350
|
-
return "OnPickDownTrigger";
|
|
1351
|
-
case 6:
|
|
1352
|
-
return "OnDoublePickTrigger"; // start;
|
|
1353
|
-
case 7:
|
|
1354
|
-
return "OnPickUpTrigger";
|
|
1355
|
-
case 8:
|
|
1356
|
-
return "OnLongPressTrigger";
|
|
1357
|
-
case 9:
|
|
1358
|
-
return "OnPointerOverTrigger";
|
|
1359
|
-
case 10:
|
|
1360
|
-
return "OnPointerOutTrigger";
|
|
1361
|
-
case 11:
|
|
1362
|
-
return "OnEveryFrameTrigger";
|
|
1363
|
-
case 12:
|
|
1364
|
-
return "OnIntersectionEnterTrigger";
|
|
1365
|
-
case 13:
|
|
1366
|
-
return "OnIntersectionExitTrigger";
|
|
1367
|
-
case 14:
|
|
1368
|
-
return "OnKeyDownTrigger";
|
|
1369
|
-
case 15:
|
|
1370
|
-
return "OnKeyUpTrigger";
|
|
1371
|
-
case 16:
|
|
1372
|
-
return "OnPickOutTrigger";
|
|
1373
|
-
default:
|
|
1374
|
-
return "";
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Nothing
|
|
1380
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1381
|
-
*/
|
|
1382
|
-
ActionManager.NothingTrigger = 0;
|
|
1383
|
-
/**
|
|
1384
|
-
* On pick
|
|
1385
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1386
|
-
*/
|
|
1387
|
-
ActionManager.OnPickTrigger = 1;
|
|
1388
|
-
/**
|
|
1389
|
-
* On left pick
|
|
1390
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1391
|
-
*/
|
|
1392
|
-
ActionManager.OnLeftPickTrigger = 2;
|
|
1393
|
-
/**
|
|
1394
|
-
* On right pick
|
|
1395
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1396
|
-
*/
|
|
1397
|
-
ActionManager.OnRightPickTrigger = 3;
|
|
1398
|
-
/**
|
|
1399
|
-
* On center pick
|
|
1400
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1401
|
-
*/
|
|
1402
|
-
ActionManager.OnCenterPickTrigger = 4;
|
|
1403
|
-
/**
|
|
1404
|
-
* On pick down
|
|
1405
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1406
|
-
*/
|
|
1407
|
-
ActionManager.OnPickDownTrigger = 5;
|
|
1408
|
-
/**
|
|
1409
|
-
* On double pick
|
|
1410
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1411
|
-
*/
|
|
1412
|
-
ActionManager.OnDoublePickTrigger = 6;
|
|
1413
|
-
/**
|
|
1414
|
-
* On pick up
|
|
1415
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1416
|
-
*/
|
|
1417
|
-
ActionManager.OnPickUpTrigger = 7;
|
|
1418
|
-
/**
|
|
1419
|
-
* On pick out.
|
|
1420
|
-
* This trigger will only be raised if you also declared a OnPickDown
|
|
1421
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1422
|
-
*/
|
|
1423
|
-
ActionManager.OnPickOutTrigger = 16;
|
|
1424
|
-
/**
|
|
1425
|
-
* On long press
|
|
1426
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1427
|
-
*/
|
|
1428
|
-
ActionManager.OnLongPressTrigger = 8;
|
|
1429
|
-
/**
|
|
1430
|
-
* On pointer over
|
|
1431
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1432
|
-
*/
|
|
1433
|
-
ActionManager.OnPointerOverTrigger = 9;
|
|
1434
|
-
/**
|
|
1435
|
-
* On pointer out
|
|
1436
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1437
|
-
*/
|
|
1438
|
-
ActionManager.OnPointerOutTrigger = 10;
|
|
1439
|
-
/**
|
|
1440
|
-
* On every frame
|
|
1441
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1442
|
-
*/
|
|
1443
|
-
ActionManager.OnEveryFrameTrigger = 11;
|
|
1444
|
-
/**
|
|
1445
|
-
* On intersection enter
|
|
1446
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1447
|
-
*/
|
|
1448
|
-
ActionManager.OnIntersectionEnterTrigger = 12;
|
|
1449
|
-
/**
|
|
1450
|
-
* On intersection exit
|
|
1451
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1452
|
-
*/
|
|
1453
|
-
ActionManager.OnIntersectionExitTrigger = 13;
|
|
1454
|
-
/**
|
|
1455
|
-
* On key down
|
|
1456
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1457
|
-
*/
|
|
1458
|
-
ActionManager.OnKeyDownTrigger = 14;
|
|
1459
|
-
/**
|
|
1460
|
-
* On key up
|
|
1461
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
|
|
1462
|
-
*/
|
|
1463
|
-
ActionManager.OnKeyUpTrigger = 15;
|
|
1464
|
-
|
|
1465
|
-
/**
|
|
1466
|
-
* Map animation groups to ModelAnimation objects.
|
|
1467
|
-
* @param groups Animation groups to map.
|
|
1468
|
-
* @param namePrefix Optional prefix to remove from animation names.
|
|
1469
|
-
* @returns Mapped animation objects.
|
|
1470
|
-
*/
|
|
1471
|
-
function mapAnimationGroups(groups, namePrefix = '') {
|
|
1472
|
-
return groups.map((group) => {
|
|
1473
|
-
return {
|
|
1474
|
-
name: group.name.substring(namePrefix.length),
|
|
1475
|
-
loop: group.loopAnimation,
|
|
1476
|
-
to: group.to,
|
|
1477
|
-
from: group.from,
|
|
1478
|
-
};
|
|
1479
|
-
});
|
|
1480
|
-
}
|
|
1481
|
-
class ModelContainerImpl {
|
|
1482
|
-
constructor(options) {
|
|
1483
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1484
|
-
this.metadata = new Map();
|
|
1485
|
-
this.materialSelectedObservable = new Observable();
|
|
1486
|
-
this.materialDeselectedObservable = new Observable();
|
|
1487
|
-
this.materialVariantObservable = new Observable();
|
|
1488
|
-
this.modelVariantObservable = new Observable();
|
|
1489
|
-
/**
|
|
1490
|
-
* A map of callbacks for material changes that should run when the scene has loaded.
|
|
1491
|
-
* [materialName, [variantKey, callback]]
|
|
1492
|
-
*/
|
|
1493
|
-
this.materialReadyToLoadCallbacks = new Map();
|
|
1494
|
-
/**
|
|
1495
|
-
* A map of callbacks for model changes that should run when the scene has loaded.
|
|
1496
|
-
* [variantKey, callback]
|
|
1497
|
-
*/
|
|
1498
|
-
this.modelReadyToLoadCallbacks = new Map();
|
|
1499
|
-
/**
|
|
1500
|
-
* A set of dynamic textures linked to workflow canvases, these textures
|
|
1501
|
-
* update themselves when changes are made to the underlying canvas
|
|
1502
|
-
*/
|
|
1503
|
-
this.dynamicTextures = new Map();
|
|
1504
|
-
/**
|
|
1505
|
-
* Queued material changes that should be applied when the current change is done.
|
|
1506
|
-
*/
|
|
1507
|
-
this.queuedMaterialChanges = new Map();
|
|
1508
|
-
/**
|
|
1509
|
-
* Material changes that are currently being applied.
|
|
1510
|
-
*/
|
|
1511
|
-
this.materialChangesInProgress = [];
|
|
1512
|
-
/**
|
|
1513
|
-
* Queued model changes that should be applied when the current change is done.
|
|
1514
|
-
*/
|
|
1515
|
-
this.queuedModelChanges = new Map();
|
|
1516
|
-
/**
|
|
1517
|
-
* Model changes that are currently being applied.
|
|
1518
|
-
*/
|
|
1519
|
-
this.modelChangesInProgress = [];
|
|
1520
|
-
this.animations = [];
|
|
1521
|
-
this.initialized = false;
|
|
1522
|
-
this.materials = [];
|
|
1523
|
-
const { enablePicking, modelDetails, previewService, progressHandler, scene, } = options;
|
|
1524
|
-
this.enablePicking = enablePicking;
|
|
1525
|
-
this.contextService = modelDetails.contextService;
|
|
1526
|
-
this.id = generateGuid();
|
|
1527
|
-
this.previewService = previewService;
|
|
1528
|
-
this.scene = scene;
|
|
1529
|
-
this.variantManager = new VariantManager(scene, this.renameClonedAsset.bind(this), this.setEnabled.bind(this));
|
|
1530
|
-
this.previewService.registerInitializedListener(() => __awaiter(this, void 0, void 0, function* () { return yield this.processQueuedEvents(); }));
|
|
1531
|
-
this.transformRoot = new TransformNode('root', this.scene);
|
|
1532
|
-
const importModel = () => __awaiter(this, void 0, void 0, function* () {
|
|
1533
|
-
this.assetContainer = yield getAssetContainer(modelDetails.model, scene, progressHandler);
|
|
1534
|
-
this.initialized = true;
|
|
1535
|
-
this.instantiate();
|
|
1536
|
-
return this;
|
|
1537
|
-
});
|
|
1538
|
-
this.importPromise = importModel();
|
|
1539
|
-
}
|
|
1540
|
-
//#region Interface implementation
|
|
1541
|
-
applyMaterialVariant(targetMaterial, key, material, removeWhenUndefined) {
|
|
1542
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1543
|
-
// If the scene hasn't finished loading yet, let's queue the material changes
|
|
1544
|
-
// up to have them play back when the scene is ready. NOTE: We queue using
|
|
1545
|
-
// option as a key, this prevents multiple options applying and making eachothers changes redundant.
|
|
1546
|
-
if (this.previewService.getSceneInitializationProgress() !== 100 ||
|
|
1547
|
-
!this.initialized) {
|
|
1548
|
-
if (this.materialReadyToLoadCallbacks.has(targetMaterial)) {
|
|
1549
|
-
const entry = this.materialReadyToLoadCallbacks.get(targetMaterial);
|
|
1550
|
-
entry === null || entry === void 0 ? void 0 : entry.set(key, this.applyMaterialVariant.bind(this, targetMaterial, key, material, removeWhenUndefined));
|
|
1551
|
-
}
|
|
1552
|
-
else {
|
|
1553
|
-
this.materialReadyToLoadCallbacks.set(targetMaterial, new Map());
|
|
1554
|
-
const newEntry = this.materialReadyToLoadCallbacks.get(targetMaterial);
|
|
1555
|
-
newEntry === null || newEntry === void 0 ? void 0 : newEntry.set(key, this.applyMaterialVariant.bind(this, targetMaterial, key, material, removeWhenUndefined));
|
|
1556
|
-
}
|
|
1557
|
-
return;
|
|
1558
|
-
}
|
|
1559
|
-
const applyChange = () => __awaiter(this, void 0, void 0, function* () {
|
|
1560
|
-
yield this.variantManager.applyMaterial(targetMaterial, material, (remainingCount, totalCount, taskName) => {
|
|
1561
|
-
this.materialVariantObservable.notifyObservers({
|
|
1562
|
-
remainingCount,
|
|
1563
|
-
totalCount,
|
|
1564
|
-
taskName,
|
|
1565
|
-
});
|
|
1566
|
-
}, removeWhenUndefined);
|
|
1567
|
-
});
|
|
1568
|
-
// If the material is already being changed, let's queue the change up
|
|
1569
|
-
if (this.materialChangesInProgress.includes(targetMaterial)) {
|
|
1570
|
-
if (this.queuedMaterialChanges.has(targetMaterial)) {
|
|
1571
|
-
const entry = this.queuedMaterialChanges.get(targetMaterial);
|
|
1572
|
-
entry === null || entry === void 0 ? void 0 : entry.set(key, applyChange);
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1575
|
-
this.queuedMaterialChanges.set(targetMaterial, new Map());
|
|
1576
|
-
const newEntry = this.queuedMaterialChanges.get(targetMaterial);
|
|
1577
|
-
newEntry === null || newEntry === void 0 ? void 0 : newEntry.set(key, applyChange);
|
|
1578
|
-
}
|
|
1579
|
-
return;
|
|
1580
|
-
}
|
|
1581
|
-
// Add the change to the in progress list and apply it.
|
|
1582
|
-
this.materialChangesInProgress.push(targetMaterial);
|
|
1583
|
-
yield applyChange();
|
|
1584
|
-
// Apply any queued changes for this material.
|
|
1585
|
-
if (this.queuedMaterialChanges.has(targetMaterial)) {
|
|
1586
|
-
const entry = this.queuedMaterialChanges.get(targetMaterial);
|
|
1587
|
-
entry.forEach((queuedChange) => __awaiter(this, void 0, void 0, function* () {
|
|
1588
|
-
yield queuedChange();
|
|
1589
|
-
}));
|
|
1590
|
-
this.queuedMaterialChanges.delete(targetMaterial);
|
|
1591
|
-
}
|
|
1592
|
-
this.materialChangesInProgress.splice(this.materialChangesInProgress.indexOf(targetMaterial), 1);
|
|
1593
|
-
this.configureGlowLayer();
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
applyModelVariant(key, modelDetails, replaceProductModel) {
|
|
1597
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1598
|
-
// If the scene hasn't finished loading yet, let's queue the model changes
|
|
1599
|
-
// up to have them play back when the scene is ready.
|
|
1600
|
-
if (!this.previewService.getIsInitialized() || !this.initialized) {
|
|
1601
|
-
this.modelReadyToLoadCallbacks.set(key, this.applyModelVariant.bind(this, key, modelDetails, replaceProductModel));
|
|
1602
|
-
return;
|
|
1603
|
-
}
|
|
1604
|
-
const createInstance = () => {
|
|
1605
|
-
return this.variantManager.applyModel(key, replaceProductModel, modelDetails === null || modelDetails === void 0 ? void 0 : modelDetails.model, (eventData) => {
|
|
1606
|
-
this.modelVariantObservable.notifyObservers(Object.assign(Object.assign({}, eventData), { key }));
|
|
1607
|
-
});
|
|
1608
|
-
};
|
|
1609
|
-
// If the model is already being changed, let's queue the change up
|
|
1610
|
-
if (this.modelChangesInProgress.includes(key)) {
|
|
1611
|
-
this.queuedModelChanges.set(key, createInstance);
|
|
1612
|
-
return;
|
|
1613
|
-
}
|
|
1614
|
-
// Model variant changes override each other, so
|
|
1615
|
-
// we need to make sure we're always using the latest one.
|
|
1616
|
-
const getLatestInstance = () => __awaiter(this, void 0, void 0, function* () {
|
|
1617
|
-
this.modelChangesInProgress.push(key);
|
|
1618
|
-
let instance = yield createInstance();
|
|
1619
|
-
// Apply any queued changes
|
|
1620
|
-
if (this.queuedModelChanges.has(key)) {
|
|
1621
|
-
const queuedChange = this.queuedModelChanges.get(key);
|
|
1622
|
-
instance = yield queuedChange();
|
|
1623
|
-
this.queuedModelChanges.delete(key);
|
|
1624
|
-
}
|
|
1625
|
-
this.modelChangesInProgress.splice(this.modelChangesInProgress.indexOf(key), 1);
|
|
1626
|
-
return instance;
|
|
1627
|
-
});
|
|
1628
|
-
// Add the change to the in progress list and apply it.
|
|
1629
|
-
const createdInstance = yield getLatestInstance();
|
|
1630
|
-
this.modelInstance &&
|
|
1631
|
-
resetAnimationGroups(this.modelInstance.animationGroups);
|
|
1632
|
-
if (!this.contextService) {
|
|
1633
|
-
this.contextService = modelDetails === null || modelDetails === void 0 ? void 0 : modelDetails.contextService;
|
|
1634
|
-
}
|
|
1635
|
-
if (createdInstance) {
|
|
1636
|
-
// Configure the model instance
|
|
1637
|
-
this.configureModelInstance(createdInstance);
|
|
1638
|
-
}
|
|
1639
|
-
else {
|
|
1640
|
-
this.configureGlowLayer();
|
|
1641
|
-
}
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
dispose() {
|
|
1645
|
-
var _a;
|
|
1646
|
-
this.destroyInstance();
|
|
1647
|
-
this.variantManager.dispose();
|
|
1648
|
-
this.dynamicTextures.forEach((texture) => texture === null || texture === void 0 ? void 0 : texture.dispose());
|
|
1649
|
-
this.dynamicTextures.clear();
|
|
1650
|
-
this.materials.forEach((material) => material && (material === null || material === void 0 ? void 0 : material.dispose()));
|
|
1651
|
-
this.materials = [];
|
|
1652
|
-
(_a = this.transformRoot) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
1653
|
-
this.transformRoot = undefined;
|
|
1654
|
-
this.previewService.modelUnloaded(this);
|
|
1655
|
-
}
|
|
1656
|
-
executeAnimation(animation) {
|
|
1657
|
-
if (!this.previewService.getIsInitialized()) {
|
|
1658
|
-
this.queuedModelAnimation = animation;
|
|
1659
|
-
return;
|
|
1660
|
-
}
|
|
1661
|
-
if (!this.modelInstance)
|
|
1662
|
-
return;
|
|
1663
|
-
executeAnimationGroups([
|
|
1664
|
-
...this.modelInstance.animationGroups,
|
|
1665
|
-
...this.variantManager.getAnimationGroups(),
|
|
1666
|
-
], animation.loop, animation.to, animation.from, animation.name ? this.renameClonedAsset(animation.name) : undefined);
|
|
1667
|
-
}
|
|
1668
|
-
getAnimations(includeVariants) {
|
|
1669
|
-
return [
|
|
1670
|
-
...this.animations,
|
|
1671
|
-
...(includeVariants
|
|
1672
|
-
? mapAnimationGroups(this.variantManager.getAnimationGroups(), this.renameClonedAsset(''))
|
|
1673
|
-
: []),
|
|
1674
|
-
];
|
|
1675
|
-
}
|
|
1676
|
-
getId() {
|
|
1677
|
-
return this.id;
|
|
1678
|
-
}
|
|
1679
|
-
listMaterials() {
|
|
1680
|
-
var _a;
|
|
1681
|
-
const materials = (_a = this.scene) === null || _a === void 0 ? void 0 : _a.materials.filter((mat) => mat.name.startsWith(this.id));
|
|
1682
|
-
if (!materials) {
|
|
1683
|
-
return [];
|
|
1684
|
-
}
|
|
1685
|
-
return materials.map((material) => {
|
|
1686
|
-
return {
|
|
1687
|
-
id: material.id,
|
|
1688
|
-
name: this.stripIdFromName(material.name),
|
|
1689
|
-
};
|
|
1690
|
-
});
|
|
1691
|
-
}
|
|
1692
|
-
registerMaterialSelectedCallback(callback) {
|
|
1693
|
-
this.materialSelectedObservable.add(callback);
|
|
1694
|
-
}
|
|
1695
|
-
unregisterMaterialSelectedCallback(callback) {
|
|
1696
|
-
this.materialSelectedObservable.removeCallback(callback);
|
|
1697
|
-
}
|
|
1698
|
-
registerMaterialDeselectedCallback(callback) {
|
|
1699
|
-
this.materialDeselectedObservable.add(callback);
|
|
1700
|
-
}
|
|
1701
|
-
unregisterMaterialDeselectedCallback(callback) {
|
|
1702
|
-
this.materialDeselectedObservable.removeCallback(callback);
|
|
1703
|
-
}
|
|
1704
|
-
get position() {
|
|
1705
|
-
return this.transformRoot.position;
|
|
1706
|
-
}
|
|
1707
|
-
set position(value) {
|
|
1708
|
-
this.transformRoot.position = new Vector3(value.x, value.y, value.z);
|
|
1709
|
-
}
|
|
1710
|
-
get rotation() {
|
|
1711
|
-
return this.transformRoot.rotation;
|
|
1712
|
-
}
|
|
1713
|
-
set rotation(value) {
|
|
1714
|
-
this.transformRoot.rotation = new Vector3(value.x, value.y, value.z);
|
|
1715
|
-
}
|
|
1716
|
-
get scale() {
|
|
1717
|
-
return this.transformRoot.scaling;
|
|
1718
|
-
}
|
|
1719
|
-
set scale(value) {
|
|
1720
|
-
this.transformRoot.scaling = new Vector3(value.x, value.y, value.z);
|
|
1721
|
-
}
|
|
1722
|
-
//#endregion
|
|
1723
|
-
//#region Custom implementation functions
|
|
1724
|
-
attachPickingHandler(model) {
|
|
1725
|
-
model.rootNodes.forEach((node) => {
|
|
1726
|
-
node.getChildMeshes(false).forEach((m) => {
|
|
1727
|
-
if (m.name === 'targetcube_t' || m.name === 'backgroundShell') {
|
|
1728
|
-
return;
|
|
1729
|
-
}
|
|
1730
|
-
if (!m.actionManager) {
|
|
1731
|
-
m.actionManager = new ActionManager(this.scene);
|
|
1732
|
-
}
|
|
1733
|
-
m.actionManager.registerAction(new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, (e) => {
|
|
1734
|
-
if (e.meshUnderPointer) {
|
|
1735
|
-
if (m.material) {
|
|
1736
|
-
this.materialSelectedObservable.notifyObservers({
|
|
1737
|
-
id: m.material.id,
|
|
1738
|
-
name: this.stripIdFromName(m.material.name),
|
|
1739
|
-
});
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}));
|
|
1743
|
-
m.actionManager.registerAction(new ExecuteCodeAction(ActionManager.OnPointerOutTrigger, () => {
|
|
1744
|
-
if (m.material) {
|
|
1745
|
-
this.materialDeselectedObservable.notifyObservers({
|
|
1746
|
-
id: m.material.id,
|
|
1747
|
-
name: this.stripIdFromName(m.material.name),
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
}));
|
|
1751
|
-
});
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
/**
|
|
1755
|
-
* Returns a promise which resolves when the model has been initialized.
|
|
1756
|
-
*/
|
|
1757
|
-
getInitializationPromise() {
|
|
1758
|
-
return this.importPromise;
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* Returns true if the model has been initialized.
|
|
1762
|
-
*/
|
|
1763
|
-
getIsInitialized() {
|
|
1764
|
-
return this.initialized;
|
|
1765
|
-
}
|
|
1766
|
-
getQueuedMaterialVariantCount() {
|
|
1767
|
-
return this.materialReadyToLoadCallbacks.size;
|
|
1768
|
-
}
|
|
1769
|
-
getQueuedModelVariantCount() {
|
|
1770
|
-
return this.modelReadyToLoadCallbacks.size;
|
|
1771
|
-
}
|
|
1772
|
-
configureGlowLayer() {
|
|
1773
|
-
// Enable glow layer if any materials use emission.
|
|
1774
|
-
const matPredicate = (mat) => mat instanceof PBRMaterial && mat.emissiveTexture !== null;
|
|
1775
|
-
const shouldEnableGlow = this.materials.some(matPredicate) ||
|
|
1776
|
-
this.variantManager.getAllMaterials().some(matPredicate);
|
|
1777
|
-
if (shouldEnableGlow) {
|
|
1778
|
-
this.previewService
|
|
1779
|
-
.getGlowLayerManager()
|
|
1780
|
-
.includeMeshes(this.getAllMeshes());
|
|
1781
|
-
}
|
|
1782
|
-
else {
|
|
1783
|
-
this.previewService
|
|
1784
|
-
.getGlowLayerManager()
|
|
1785
|
-
.removeMeshes(this.getAllMeshes());
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
configureModelInstance(modelInstance) {
|
|
1789
|
-
var _a;
|
|
1790
|
-
// Reset transform point
|
|
1791
|
-
const position = this.transformRoot.position;
|
|
1792
|
-
const rotation = this.transformRoot.rotation;
|
|
1793
|
-
const scale = this.transformRoot.scaling;
|
|
1794
|
-
this.transformRoot.position = Vector3.Zero();
|
|
1795
|
-
this.transformRoot.rotation = Vector3.Zero();
|
|
1796
|
-
this.transformRoot.scaling = Vector3.One();
|
|
1797
|
-
// Move the model to the transform root
|
|
1798
|
-
modelInstance.rootNodes.forEach((node) => {
|
|
1799
|
-
node.parent = this.transformRoot;
|
|
1800
|
-
});
|
|
1801
|
-
// Return the transform values
|
|
1802
|
-
this.transformRoot.position = position;
|
|
1803
|
-
this.transformRoot.rotation = rotation;
|
|
1804
|
-
this.transformRoot.scaling = scale;
|
|
1805
|
-
// Create & apply dynamic textures
|
|
1806
|
-
this.canvasPanels = ((_a = this.contextService) === null || _a === void 0 ? void 0 : _a.getAll()) || new Map();
|
|
1807
|
-
attachDynamicTextures(this.materials.concat(this.variantManager.getAllMaterials()), this.scene, this.canvasPanels, this.dynamicTextures, `${this.id}_`);
|
|
1808
|
-
// Register picking handler for the new instance
|
|
1809
|
-
if (this.enablePicking) {
|
|
1810
|
-
this.attachPickingHandler(modelInstance);
|
|
1811
|
-
}
|
|
1812
|
-
this.configureGlowLayer();
|
|
1813
|
-
}
|
|
1814
|
-
/**
|
|
1815
|
-
* Destroys the model instance.
|
|
1816
|
-
*/
|
|
1817
|
-
destroyInstance() {
|
|
1818
|
-
var _a;
|
|
1819
|
-
(_a = this.modelInstance) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
1820
|
-
this.modelInstance = undefined;
|
|
1821
|
-
}
|
|
1822
|
-
getAllMeshes() {
|
|
1823
|
-
var _a;
|
|
1824
|
-
return (_a = this.modelInstance) === null || _a === void 0 ? void 0 : _a.rootNodes.map((node) => node.getChildMeshes(false).filter((m) => m instanceof Mesh)).flat();
|
|
1825
|
-
}
|
|
1826
|
-
instantiate() {
|
|
1827
|
-
this.modelInstance = this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this), true);
|
|
1828
|
-
// Store the materials used by the model
|
|
1829
|
-
this.materials = getAllMaterialsForInstance(this.modelInstance);
|
|
1830
|
-
// Configure the new model instance
|
|
1831
|
-
this.configureModelInstance(this.modelInstance);
|
|
1832
|
-
this.animations = mapAnimationGroups(this.modelInstance.animationGroups, this.renameClonedAsset(''));
|
|
1833
|
-
// Potentially process any queued events
|
|
1834
|
-
// this will do nothing if the scene is not ready
|
|
1835
|
-
this.processQueuedEvents();
|
|
1836
|
-
}
|
|
1837
|
-
renameClonedAsset(name) {
|
|
1838
|
-
return `${this.id}_${name}`;
|
|
1839
|
-
}
|
|
1840
|
-
setEnabled(enabled) {
|
|
1841
|
-
if (enabled && !this.modelInstance) {
|
|
1842
|
-
this.instantiate();
|
|
1843
|
-
}
|
|
1844
|
-
else if (!enabled && this.modelInstance) {
|
|
1845
|
-
this.destroyInstance();
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
updateDynamicTextures() {
|
|
1849
|
-
var _a;
|
|
1850
|
-
// Update dynamic textures where canvas changes have been made.
|
|
1851
|
-
(_a = this.canvasPanels) === null || _a === void 0 ? void 0 : _a.forEach((canvasPanel, layoutKey) => {
|
|
1852
|
-
const dynamicTexture = this.dynamicTextures.get(layoutKey);
|
|
1853
|
-
if (dynamicTexture &&
|
|
1854
|
-
canvasPanel.getStaticContextDirty() &&
|
|
1855
|
-
dynamicTexture.isReady()) {
|
|
1856
|
-
dynamicTexture.update(false);
|
|
1857
|
-
canvasPanel.setStaticContextDirty(false);
|
|
1858
|
-
}
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
|
-
//#region Listeners
|
|
1862
|
-
registerMaterialVariantListener(listener) {
|
|
1863
|
-
this.materialVariantObservable.add(listener);
|
|
1864
|
-
}
|
|
1865
|
-
unregisterMaterialVariantListener(listener) {
|
|
1866
|
-
this.materialVariantObservable.removeCallback(listener);
|
|
1867
|
-
}
|
|
1868
|
-
registerModelVariantListener(listener) {
|
|
1869
|
-
this.modelVariantObservable.add(listener);
|
|
1870
|
-
}
|
|
1871
|
-
unregisterModelVariantListener(listener) {
|
|
1872
|
-
this.modelVariantObservable.removeCallback(listener);
|
|
1873
|
-
}
|
|
1874
|
-
//#endregion
|
|
1875
|
-
stripIdFromName(name) {
|
|
1876
|
-
return name.substring(this.id.length + 1);
|
|
1877
|
-
}
|
|
1878
|
-
processQueuedEvents() {
|
|
1879
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1880
|
-
if (!this.previewService.getIsInitialized()) {
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
yield Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).map((callbacks) => Array.from(callbacks.values()).map((callback) => callback())));
|
|
1884
|
-
this.materialReadyToLoadCallbacks.clear();
|
|
1885
|
-
yield Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((callback) => callback()));
|
|
1886
|
-
this.modelReadyToLoadCallbacks.clear();
|
|
1887
|
-
if (this.queuedModelAnimation) {
|
|
1888
|
-
this.executeAnimation(this.queuedModelAnimation);
|
|
1889
|
-
this.queuedModelAnimation = undefined;
|
|
1890
|
-
}
|
|
1891
|
-
});
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
export { ModelContainerImpl };
|