@babylonjs/gui 5.26.1 → 5.27.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.
Files changed (37) hide show
  1. package/2D/controls/inputText.d.ts +1 -1
  2. package/2D/controls/inputText.js +7 -27
  3. package/2D/controls/inputText.js.map +1 -1
  4. package/3D/controls/MRTK3/touchHolographicButton.d.ts +220 -0
  5. package/3D/controls/MRTK3/touchHolographicButton.js +859 -0
  6. package/3D/controls/MRTK3/touchHolographicButton.js.map +1 -0
  7. package/3D/controls/index.d.ts +4 -2
  8. package/3D/controls/index.js +5 -2
  9. package/3D/controls/index.js.map +1 -1
  10. package/3D/materials/mrdl/mrdlBackglowMaterial.d.ts +87 -0
  11. package/3D/materials/mrdl/mrdlBackglowMaterial.js +300 -0
  12. package/3D/materials/mrdl/mrdlBackglowMaterial.js.map +1 -0
  13. package/3D/materials/mrdl/mrdlFrontplateMaterial.d.ts +186 -0
  14. package/3D/materials/mrdl/mrdlFrontplateMaterial.js +530 -0
  15. package/3D/materials/mrdl/mrdlFrontplateMaterial.js.map +1 -0
  16. package/3D/materials/mrdl/mrdlInnerquadMaterial.d.ts +56 -0
  17. package/3D/materials/mrdl/mrdlInnerquadMaterial.js +228 -0
  18. package/3D/materials/mrdl/mrdlInnerquadMaterial.js.map +1 -0
  19. package/3D/materials/mrdl/shaders/mrdlBackglow.fragment.d.ts +5 -0
  20. package/3D/materials/mrdl/shaders/mrdlBackglow.fragment.js +9 -0
  21. package/3D/materials/mrdl/shaders/mrdlBackglow.fragment.js.map +1 -0
  22. package/3D/materials/mrdl/shaders/mrdlBackglow.vertex.d.ts +5 -0
  23. package/3D/materials/mrdl/shaders/mrdlBackglow.vertex.js +9 -0
  24. package/3D/materials/mrdl/shaders/mrdlBackglow.vertex.js.map +1 -0
  25. package/3D/materials/mrdl/shaders/mrdlFrontplate.fragment.d.ts +5 -0
  26. package/3D/materials/mrdl/shaders/mrdlFrontplate.fragment.js +9 -0
  27. package/3D/materials/mrdl/shaders/mrdlFrontplate.fragment.js.map +1 -0
  28. package/3D/materials/mrdl/shaders/mrdlFrontplate.vertex.d.ts +5 -0
  29. package/3D/materials/mrdl/shaders/mrdlFrontplate.vertex.js +9 -0
  30. package/3D/materials/mrdl/shaders/mrdlFrontplate.vertex.js.map +1 -0
  31. package/3D/materials/mrdl/shaders/mrdlInnerquad.fragment.d.ts +5 -0
  32. package/3D/materials/mrdl/shaders/mrdlInnerquad.fragment.js +9 -0
  33. package/3D/materials/mrdl/shaders/mrdlInnerquad.fragment.js.map +1 -0
  34. package/3D/materials/mrdl/shaders/mrdlInnerquad.vertex.d.ts +5 -0
  35. package/3D/materials/mrdl/shaders/mrdlInnerquad.vertex.js +9 -0
  36. package/3D/materials/mrdl/shaders/mrdlInnerquad.vertex.js.map +1 -0
  37. package/package.json +2 -2
@@ -0,0 +1,859 @@
1
+ import { AdvancedDynamicTexture } from "../../../2D/advancedDynamicTexture.js";
2
+ import { Animation } from "@babylonjs/core/Animations/animation.js";
3
+ import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
4
+ import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
5
+ import { Control } from "../../../2D/controls/control.js";
6
+ import { CreatePlane } from "@babylonjs/core/Meshes/Builders/planeBuilder.js";
7
+ import { CreateBox } from "@babylonjs/core/Meshes/Builders/boxBuilder.js";
8
+ import { DomManagement } from "@babylonjs/core/Misc/domManagement.js";
9
+ import { FadeInOutBehavior } from "@babylonjs/core/Behaviors/Meshes/fadeInOutBehavior.js";
10
+ import { Grid } from "../../../2D/controls/grid.js";
11
+ import { Image } from "../../../2D/controls/image.js";
12
+ import { MRDLBackglowMaterial } from "../../materials/mrdl/mrdlBackglowMaterial.js";
13
+ import { MRDLBackplateMaterial } from "../../materials/mrdl/mrdlBackplateMaterial.js";
14
+ import { MRDLFrontplateMaterial } from "../../materials/mrdl/mrdlFrontplateMaterial.js";
15
+ import { MRDLInnerquadMaterial } from "../../materials/mrdl/mrdlInnerquadMaterial.js";
16
+ import { Rectangle } from "../../../2D/controls/rectangle.js";
17
+ import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
18
+ import { StackPanel } from "../../../2D/controls/stackPanel.js";
19
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
20
+ import { TextBlock } from "../../../2D/controls/textBlock.js";
21
+ import { TouchButton3D } from "../touchButton3D.js";
22
+ import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
23
+ import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
24
+ /**
25
+ * Class used to create the mrtkv3 button
26
+ */
27
+ export class TouchHolographicButton extends TouchButton3D {
28
+ /**
29
+ * Creates a new button
30
+ * @param name defines the control name
31
+ * @param shareMaterials
32
+ */
33
+ constructor(name, shareMaterials = true) {
34
+ super(name);
35
+ /**
36
+ * Gets or sets the horizontal scaling for the button.
37
+ */
38
+ this.width = 1;
39
+ /**
40
+ * Gets or sets the vertical scaling for the button.
41
+ */
42
+ this.height = 1;
43
+ /**
44
+ * Gets or sets the bevel radius for the button.
45
+ */
46
+ this.radius = 0.14;
47
+ /**
48
+ * Gets or sets the font size of the button text in pixels.
49
+ * This is only adjustable for a button with width to height ratio greater than 1.
50
+ */
51
+ this.textSizeInPixels = 18;
52
+ /**
53
+ * Gets or sets the size of the button image in pixels.
54
+ * This is only adjustable for a button with width to height ratio greater than 1.
55
+ */
56
+ this.imageSizeInPixels = 40;
57
+ /**
58
+ * Gets or sets the color of the button plate.
59
+ */
60
+ this.plateMaterialColor = new Color3(0.4, 0.4, 0.4);
61
+ // Shared variables for meshes
62
+ /**
63
+ * Gets or sets the depth of the button's front plate.
64
+ * This variable determines the z scaling and z position for some of the button's meshes.
65
+ */
66
+ this.frontPlateDepth = 0.2;
67
+ /**
68
+ * Gets or sets the depth of the button's back plate.
69
+ * This variable determines the z scaling and z position for some of the button's meshes.
70
+ */
71
+ this.backPlateDepth = 0.04;
72
+ /**
73
+ * Gets or sets the offset value for button's back glow.
74
+ * This variable determines the x, y scaling of the button's meshes.
75
+ */
76
+ this.backGlowOffset = 0.1;
77
+ /**
78
+ * Gets or sets the value that determines the z scaling and z position for the innerQuad and BackGlow meshes.
79
+ */
80
+ this.flatPlaneDepth = 0.001;
81
+ /**
82
+ * Gets or sets the radius for FrontMaterial and innerQuadMaterial.
83
+ */
84
+ this.innerQuadRadius = this.radius - 0.04;
85
+ /**
86
+ * Gets or sets the color for innerQuadMaterial.
87
+ */
88
+ this.innerQuadColor = new Color4(0, 0, 0, 0);
89
+ /**
90
+ * Gets or sets the color for innerQuadMaterial for when it is toggled.
91
+ */
92
+ this.innerQuadToggledColor = new Color4(0.5197843, 0.6485234, 0.9607843, 0.6);
93
+ /**
94
+ * Gets or sets the color for innerQuadMaterial for when it is hovered.
95
+ */
96
+ this.innerQuadHoverColor = new Color4(1, 1, 1, 0.05);
97
+ /**
98
+ * Gets or sets the color for innerQuadMaterial for when it is toggled and hovered.
99
+ */
100
+ this.innerQuadToggledHoverColor = new Color4(0.5197843, 0.6485234, 0.9607843, 1);
101
+ this._isBackplateVisible = true;
102
+ // Materials
103
+ this._shareMaterials = true;
104
+ this._shareMaterials = shareMaterials;
105
+ this.pointerEnterAnimation = () => {
106
+ if (this._frontPlate && this._textPlate && !this.isToggleButton) {
107
+ this._performEnterExitAnimation(1);
108
+ }
109
+ if (this.isToggleButton && this._innerQuadMaterial) {
110
+ if (this.isToggled) {
111
+ this._innerQuadMaterial.color = this.innerQuadToggledHoverColor;
112
+ }
113
+ else {
114
+ this._innerQuadMaterial.color = this.innerQuadHoverColor;
115
+ }
116
+ }
117
+ };
118
+ this.pointerOutAnimation = () => {
119
+ if (this._frontPlate && this._textPlate && !this.isToggleButton) {
120
+ this._performEnterExitAnimation(-0.8);
121
+ }
122
+ if (this.isToggleButton && this._innerQuadMaterial) {
123
+ this._onToggle(this.isToggled);
124
+ }
125
+ };
126
+ this.pointerDownAnimation = () => {
127
+ // Do nothing
128
+ };
129
+ this.pointerUpAnimation = () => {
130
+ // Do nothing
131
+ };
132
+ this._pointerClickObserver = this.onPointerClickObservable.add(() => {
133
+ if (this._frontPlate && this._backGlow && !this.isActiveNearInteraction) {
134
+ this._performClickAnimation();
135
+ }
136
+ if (this.isToggleButton && this._innerQuadMaterial) {
137
+ this._onToggle(this.isToggled);
138
+ }
139
+ });
140
+ this._pointerEnterObserver = this.onPointerEnterObservable.add(() => {
141
+ this.pointerEnterAnimation();
142
+ });
143
+ this._pointerOutObserver = this.onPointerOutObservable.add(() => {
144
+ this.pointerOutAnimation();
145
+ });
146
+ this._toggleObserver = this.onToggleObservable.add((isToggled) => {
147
+ if (isToggled) {
148
+ this._innerQuadMaterial.color = this.innerQuadToggledColor;
149
+ }
150
+ else {
151
+ this._innerQuadMaterial.color = this.innerQuadColor;
152
+ }
153
+ });
154
+ }
155
+ _disposeTooltip() {
156
+ this._tooltipFade = null;
157
+ if (this._tooltipTextBlock) {
158
+ this._tooltipTextBlock.dispose();
159
+ }
160
+ if (this._tooltipTexture) {
161
+ this._tooltipTexture.dispose();
162
+ }
163
+ if (this._tooltipMesh) {
164
+ this._tooltipMesh.dispose();
165
+ }
166
+ this.onPointerEnterObservable.remove(this._tooltipHoverObserver);
167
+ this.onPointerOutObservable.remove(this._tooltipOutObserver);
168
+ }
169
+ /**
170
+ * Rendering ground id of all the mesh in the button
171
+ */
172
+ set renderingGroupId(id) {
173
+ this._backPlate.renderingGroupId = id;
174
+ this._textPlate.renderingGroupId = id;
175
+ this._frontPlate.renderingGroupId = id;
176
+ this._backGlow.renderingGroupId = id;
177
+ this._innerQuad.renderingGroupId = id;
178
+ if (this._tooltipMesh) {
179
+ this._tooltipMesh.renderingGroupId = id;
180
+ }
181
+ }
182
+ get renderingGroupId() {
183
+ return this._backPlate.renderingGroupId;
184
+ }
185
+ /**
186
+ * Gets the mesh used to render this control
187
+ */
188
+ get mesh() {
189
+ return this._backPlate;
190
+ }
191
+ /**
192
+ * Text to be displayed on the tooltip shown when hovering on the button. When set to null tooltip is disabled. (Default: null)
193
+ * Set this property after adding the button to the GUI3DManager
194
+ */
195
+ set tooltipText(text) {
196
+ if (!text) {
197
+ this._disposeTooltip();
198
+ return;
199
+ }
200
+ if (!this._tooltipFade) {
201
+ const rightHandedScene = this._backPlate._scene.useRightHandedSystem;
202
+ // Create tooltip with mesh and text
203
+ this._tooltipMesh = CreatePlane("", { size: 1 }, this._backPlate._scene);
204
+ this._tooltipMesh.position = Vector3.Down().scale(0.7).add(Vector3.Forward(rightHandedScene).scale(-0.15));
205
+ this._tooltipMesh.isPickable = false;
206
+ this._tooltipMesh.parent = this._frontPlateCollisionMesh;
207
+ // Create text texture for the tooltip
208
+ this._tooltipTexture = AdvancedDynamicTexture.CreateForMesh(this._tooltipMesh);
209
+ const tooltipBackground = new Rectangle();
210
+ tooltipBackground.height = 0.25;
211
+ tooltipBackground.width = 0.8;
212
+ tooltipBackground.cornerRadius = 25;
213
+ tooltipBackground.color = "#ffffff";
214
+ tooltipBackground.thickness = 20;
215
+ tooltipBackground.background = "#060668";
216
+ this._tooltipTexture.addControl(tooltipBackground);
217
+ this._tooltipTextBlock = new TextBlock();
218
+ this._tooltipTextBlock.color = "white";
219
+ this._tooltipTextBlock.fontSize = 100;
220
+ this._tooltipTexture.addControl(this._tooltipTextBlock);
221
+ // Add hover action to tooltip
222
+ this._tooltipFade = new FadeInOutBehavior();
223
+ this._tooltipFade.delay = 500;
224
+ this._tooltipMesh.addBehavior(this._tooltipFade);
225
+ this._tooltipHoverObserver = this.onPointerEnterObservable.add(() => {
226
+ if (this._tooltipFade) {
227
+ this._tooltipFade.fadeIn(true);
228
+ }
229
+ });
230
+ this._tooltipOutObserver = this.onPointerOutObservable.add(() => {
231
+ if (this._tooltipFade) {
232
+ this._tooltipFade.fadeIn(false);
233
+ }
234
+ });
235
+ }
236
+ if (this._tooltipTextBlock) {
237
+ this._tooltipTextBlock.text = text;
238
+ }
239
+ }
240
+ get tooltipText() {
241
+ return this._tooltipTextBlock?.text || null;
242
+ }
243
+ /**
244
+ * Gets or sets text for the button
245
+ */
246
+ get text() {
247
+ return this._text;
248
+ }
249
+ set text(value) {
250
+ if (this._text === value) {
251
+ return;
252
+ }
253
+ this._text = value;
254
+ this._rebuildContent();
255
+ }
256
+ /**
257
+ * Gets or sets subtext for a button with larger width
258
+ */
259
+ get subtext() {
260
+ return this._subtext;
261
+ }
262
+ set subtext(value) {
263
+ if (this._subtext === value) {
264
+ return;
265
+ }
266
+ this._subtext = value;
267
+ this._rebuildContent();
268
+ }
269
+ /**
270
+ * Gets or sets the image url for the button
271
+ */
272
+ get imageUrl() {
273
+ return this._imageUrl;
274
+ }
275
+ set imageUrl(value) {
276
+ if (this._imageUrl === value) {
277
+ return;
278
+ }
279
+ this._imageUrl = value;
280
+ this._rebuildContent();
281
+ }
282
+ /**
283
+ * Gets the back material used by this button
284
+ */
285
+ get backMaterial() {
286
+ return this._backMaterial;
287
+ }
288
+ /**
289
+ * Gets the front material used by this button
290
+ */
291
+ get frontMaterial() {
292
+ return this._frontMaterial;
293
+ }
294
+ /**
295
+ * Gets the back glow material used by this button
296
+ */
297
+ get backGlowMaterial() {
298
+ return this._backGlowMaterial;
299
+ }
300
+ /**
301
+ * Gets the inner quad material used by this button
302
+ */
303
+ get innerQuadMaterial() {
304
+ return this._innerQuadMaterial;
305
+ }
306
+ /**
307
+ * Gets the plate material used by this button
308
+ */
309
+ get plateMaterial() {
310
+ return this._plateMaterial;
311
+ }
312
+ /**
313
+ * Gets a boolean indicating if this button shares its material with other V3 Buttons
314
+ */
315
+ get shareMaterials() {
316
+ return this._shareMaterials;
317
+ }
318
+ /**
319
+ * Sets whether the backplate is visible or hidden. Hiding the backplate is not recommended without some sort of replacement
320
+ */
321
+ set isBackplateVisible(isVisible) {
322
+ if (this.mesh && this._backMaterial) {
323
+ if (isVisible && !this._isBackplateVisible) {
324
+ this._backPlate.visibility = 1;
325
+ }
326
+ else if (!isVisible && this._isBackplateVisible) {
327
+ this._backPlate.visibility = 0;
328
+ }
329
+ }
330
+ this._isBackplateVisible = isVisible;
331
+ }
332
+ _getTypeName() {
333
+ return "TouchHolographicButton";
334
+ }
335
+ _rebuildContent() {
336
+ let content;
337
+ if (this._getAspectRatio() <= 1) {
338
+ // align text and image vertically
339
+ content = this._alignContentVertically();
340
+ }
341
+ else {
342
+ // align text and image horizontally
343
+ content = this._alignContentHorizontally();
344
+ }
345
+ this.content = content;
346
+ }
347
+ _getAspectRatio() {
348
+ return this.width / this.height;
349
+ }
350
+ _alignContentVertically() {
351
+ const panel = new StackPanel();
352
+ panel.isVertical = true;
353
+ if (DomManagement.IsDocumentAvailable() && !!document.createElement) {
354
+ if (this._imageUrl) {
355
+ const image = new Image();
356
+ image.source = this._imageUrl;
357
+ image.heightInPixels = 180;
358
+ image.widthInPixels = 100;
359
+ image.paddingTopInPixels = 40;
360
+ image.paddingBottomInPixels = 40;
361
+ panel.addControl(image);
362
+ }
363
+ }
364
+ if (this._text) {
365
+ const text = new TextBlock();
366
+ text.text = this._text;
367
+ text.color = "white";
368
+ text.heightInPixels = 30;
369
+ text.fontSize = 24;
370
+ panel.addControl(text);
371
+ }
372
+ return panel;
373
+ }
374
+ _alignContentHorizontally() {
375
+ let totalPanelWidthInPixels = 240;
376
+ const padding = 15;
377
+ const contentContainer = new Rectangle();
378
+ contentContainer.widthInPixels = totalPanelWidthInPixels;
379
+ contentContainer.heightInPixels = totalPanelWidthInPixels;
380
+ contentContainer.color = "transparent";
381
+ contentContainer.setPaddingInPixels(padding, padding, padding, padding);
382
+ totalPanelWidthInPixels -= padding * 2;
383
+ const panel = new StackPanel();
384
+ panel.isVertical = false;
385
+ panel.scaleY = this._getAspectRatio();
386
+ if (DomManagement.IsDocumentAvailable() && !!document.createElement) {
387
+ if (this._imageUrl) {
388
+ const imageContainer = new Rectangle(`${this.name}_image`);
389
+ imageContainer.widthInPixels = this.imageSizeInPixels;
390
+ imageContainer.heightInPixels = this.imageSizeInPixels;
391
+ imageContainer.color = "transparent";
392
+ totalPanelWidthInPixels -= this.imageSizeInPixels;
393
+ const image = new Image();
394
+ image.source = this._imageUrl;
395
+ imageContainer.addControl(image);
396
+ panel.addControl(imageContainer);
397
+ }
398
+ }
399
+ if (this._text) {
400
+ const text = new TextBlock(`${this.name}_text`);
401
+ text.text = this._text;
402
+ text.color = "white";
403
+ text.fontSize = this.textSizeInPixels;
404
+ text.widthInPixels = totalPanelWidthInPixels;
405
+ if (this._imageUrl) {
406
+ text.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
407
+ text.paddingLeftInPixels = padding;
408
+ }
409
+ if (this._subtext) {
410
+ const textContainer = new Grid();
411
+ textContainer.addColumnDefinition(1);
412
+ textContainer.addRowDefinition(0.5);
413
+ textContainer.addRowDefinition(0.5);
414
+ textContainer.widthInPixels = totalPanelWidthInPixels;
415
+ textContainer.heightInPixels = 45;
416
+ const subtext = new TextBlock(`${this.name}_subtext`);
417
+ subtext.text = this._subtext;
418
+ subtext.color = "#EEEEEEAB";
419
+ subtext.fontSize = this.textSizeInPixels * 0.75;
420
+ subtext.fontWeight = "600";
421
+ if (this._imageUrl) {
422
+ subtext.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
423
+ subtext.paddingLeftInPixels = padding;
424
+ }
425
+ textContainer.addControl(text, 0);
426
+ textContainer.addControl(subtext, 1);
427
+ panel.addControl(textContainer);
428
+ }
429
+ else {
430
+ panel.addControl(text);
431
+ }
432
+ }
433
+ contentContainer.addControl(panel);
434
+ return contentContainer;
435
+ }
436
+ // Mesh association
437
+ _createNode(scene) {
438
+ this.name = this.name ?? "TouchHolographicButton";
439
+ const backPlateMesh = this._createBackPlate(scene);
440
+ const collisionMesh = this._createFrontPlate(scene);
441
+ const innerQuadMesh = this._createInnerQuad(scene);
442
+ const backGlowMesh = this._createBackGlow(scene);
443
+ this._frontPlateCollisionMesh = collisionMesh;
444
+ this._textPlate = super._createNode(scene);
445
+ this._textPlate.name = `${this.name}_textPlate`;
446
+ this._textPlate.isPickable = false;
447
+ this._textPlate.scaling.x = this.width;
448
+ this._textPlate.parent = collisionMesh;
449
+ this._backPlate = backPlateMesh;
450
+ this._backPlate.position = Vector3.Forward(scene.useRightHandedSystem).scale(this.backPlateDepth / 2);
451
+ this._backPlate.isPickable = false;
452
+ this._backPlate.addChild(collisionMesh);
453
+ this._backPlate.addChild(innerQuadMesh);
454
+ if (backGlowMesh) {
455
+ this._backPlate.addChild(backGlowMesh);
456
+ }
457
+ const tn = new TransformNode(`${this.name}_root`, scene);
458
+ this._backPlate.setParent(tn);
459
+ this.collisionMesh = collisionMesh;
460
+ this.collidableFrontDirection = this._backPlate.forward.negate(); // Mesh is facing the wrong way
461
+ return tn;
462
+ }
463
+ _createBackPlate(scene) {
464
+ const backPlateMesh = CreateBox(`${this.name}_backPlate`, {}, scene);
465
+ backPlateMesh.isPickable = false;
466
+ backPlateMesh.visibility = 0;
467
+ backPlateMesh.scaling.z = 0.2;
468
+ SceneLoader.ImportMeshAsync(undefined, TouchHolographicButton.MRTK_ASSET_BASE_URL, TouchHolographicButton.BACKPLATE_MODEL_FILENAME, scene).then((result) => {
469
+ const backPlateModel = result.meshes[1];
470
+ backPlateModel.visibility = 0;
471
+ if (this._isBackplateVisible) {
472
+ backPlateModel.visibility = 1;
473
+ backPlateModel.name = `${this.name}_backPlate`;
474
+ backPlateModel.isPickable = false;
475
+ backPlateModel.scaling.x = this.width;
476
+ backPlateModel.scaling.y = this.height;
477
+ backPlateModel.parent = backPlateMesh;
478
+ }
479
+ if (this._backMaterial) {
480
+ backPlateModel.material = this._backMaterial;
481
+ }
482
+ this._backPlate = backPlateModel;
483
+ });
484
+ return backPlateMesh;
485
+ }
486
+ _createFrontPlate(scene) {
487
+ const collisionMesh = CreateBox(`${this.name}_frontPlate`, {
488
+ width: this.width,
489
+ height: this.height,
490
+ depth: this.frontPlateDepth,
491
+ }, scene);
492
+ collisionMesh.isPickable = true;
493
+ collisionMesh.isNearPickable = true;
494
+ collisionMesh.visibility = 0;
495
+ collisionMesh.position = Vector3.Forward(scene.useRightHandedSystem).scale((this.backPlateDepth - this.frontPlateDepth) / 2);
496
+ SceneLoader.ImportMeshAsync(undefined, TouchHolographicButton.MRTK_ASSET_BASE_URL, TouchHolographicButton.FRONTPLATE_MODEL_FILENAME, scene).then((result) => {
497
+ const collisionPlate = CreateBox(`${this.name}_collisionPlate`, {
498
+ width: this.width,
499
+ height: this.height,
500
+ }, scene);
501
+ collisionPlate.isPickable = false;
502
+ collisionPlate.scaling.z = this.frontPlateDepth;
503
+ collisionPlate.visibility = 0;
504
+ collisionPlate.parent = collisionMesh;
505
+ this._collisionPlate = collisionPlate;
506
+ const frontPlateModel = result.meshes[1];
507
+ frontPlateModel.name = `${this.name}_frontPlate`;
508
+ frontPlateModel.isPickable = false;
509
+ frontPlateModel.scaling.x = this.width - this.backGlowOffset;
510
+ frontPlateModel.scaling.y = this.height - this.backGlowOffset;
511
+ frontPlateModel.position = Vector3.Forward(scene.useRightHandedSystem).scale(-0.5);
512
+ frontPlateModel.parent = collisionPlate;
513
+ if (this.isToggleButton) {
514
+ frontPlateModel.visibility = 0;
515
+ }
516
+ if (this._frontMaterial) {
517
+ frontPlateModel.material = this._frontMaterial;
518
+ }
519
+ this._textPlate.scaling.x = 1;
520
+ this._textPlate.parent = frontPlateModel;
521
+ this._frontPlate = frontPlateModel;
522
+ });
523
+ return collisionMesh;
524
+ }
525
+ _createInnerQuad(scene) {
526
+ const innerQuadMesh = CreateBox(`${this.name}_innerQuad`, {}, scene);
527
+ innerQuadMesh.isPickable = false;
528
+ innerQuadMesh.visibility = 0;
529
+ innerQuadMesh.scaling.z = this.flatPlaneDepth;
530
+ innerQuadMesh.position.z += this.backPlateDepth / 2 - this.flatPlaneDepth;
531
+ SceneLoader.ImportMeshAsync(undefined, TouchHolographicButton.MRTK_ASSET_BASE_URL, TouchHolographicButton.INNERQUAD_MODEL_FILENAME, scene).then((result) => {
532
+ const innerQuadModel = result.meshes[1];
533
+ innerQuadModel.name = `${this.name}_innerQuad`;
534
+ innerQuadModel.isPickable = false;
535
+ innerQuadModel.scaling.x = this.width - this.backGlowOffset;
536
+ innerQuadModel.scaling.y = this.height - this.backGlowOffset;
537
+ innerQuadModel.parent = innerQuadMesh;
538
+ if (this._innerQuadMaterial) {
539
+ innerQuadModel.material = this._innerQuadMaterial;
540
+ }
541
+ this._innerQuad = innerQuadModel;
542
+ });
543
+ return innerQuadMesh;
544
+ }
545
+ _createBackGlow(scene) {
546
+ if (this.isToggleButton) {
547
+ return;
548
+ }
549
+ const backGlowMesh = CreateBox(`${this.name}_backGlow`, {}, scene);
550
+ backGlowMesh.isPickable = false;
551
+ backGlowMesh.visibility = 0;
552
+ backGlowMesh.scaling.z = this.flatPlaneDepth;
553
+ backGlowMesh.position.z += this.backPlateDepth / 2 - this.flatPlaneDepth * 2;
554
+ SceneLoader.ImportMeshAsync(undefined, TouchHolographicButton.MRTK_ASSET_BASE_URL, TouchHolographicButton.BACKGLOW_MODEL_FILENAME, scene).then((result) => {
555
+ const backGlowModel = result.meshes[1];
556
+ backGlowModel.name = `${this.name}_backGlow`;
557
+ backGlowModel.isPickable = false;
558
+ backGlowModel.scaling.x = this.width - this.backGlowOffset;
559
+ backGlowModel.scaling.y = this.height - this.backGlowOffset;
560
+ backGlowModel.parent = backGlowMesh;
561
+ if (this._backGlowMaterial) {
562
+ backGlowModel.material = this._backGlowMaterial;
563
+ }
564
+ this._backGlow = backGlowModel;
565
+ });
566
+ return backGlowMesh;
567
+ }
568
+ _applyFacade(facadeTexture) {
569
+ this._plateMaterial.emissiveTexture = facadeTexture;
570
+ this._plateMaterial.opacityTexture = facadeTexture;
571
+ this._plateMaterial.diffuseColor = this.plateMaterialColor;
572
+ }
573
+ _performClickAnimation() {
574
+ const frameRate = 60;
575
+ const animationGroup = new AnimationGroup("Click Animation Group");
576
+ const animations = [
577
+ {
578
+ name: "backGlowMotion",
579
+ mesh: this._backGlow,
580
+ property: "material.motion",
581
+ keys: [
582
+ {
583
+ frame: 0,
584
+ values: [0, 0, 0],
585
+ },
586
+ {
587
+ frame: 20,
588
+ values: [1, 0.0144, 0.0144],
589
+ },
590
+ {
591
+ frame: 40,
592
+ values: [0.0027713229489760476, 0, 0],
593
+ },
594
+ {
595
+ frame: 45,
596
+ values: [0.0027713229489760476],
597
+ },
598
+ ],
599
+ },
600
+ {
601
+ name: "_collisionPlateZSlide",
602
+ mesh: this._collisionPlate,
603
+ property: "position.z",
604
+ keys: [
605
+ {
606
+ frame: 0,
607
+ values: [0.0, 0.0, 0.0],
608
+ },
609
+ {
610
+ frame: 20,
611
+ values: [Vector3.Forward(this._collisionPlate._scene.useRightHandedSystem).scale(this.frontPlateDepth / 2).z, 0.0, 0.0],
612
+ },
613
+ {
614
+ frame: 40,
615
+ values: [0.0, 0.005403332496794331],
616
+ },
617
+ {
618
+ frame: 45,
619
+ values: [0.0],
620
+ },
621
+ ],
622
+ },
623
+ {
624
+ name: "_collisionPlateZScale",
625
+ mesh: this._collisionPlate,
626
+ property: "scaling.z",
627
+ keys: [
628
+ {
629
+ frame: 0,
630
+ values: [this.frontPlateDepth, 0.0, 0.0],
631
+ },
632
+ {
633
+ frame: 20,
634
+ values: [this.backPlateDepth, 0.0, 0.0],
635
+ },
636
+ {
637
+ frame: 40,
638
+ values: [this.frontPlateDepth, 0.0054],
639
+ },
640
+ {
641
+ frame: 45,
642
+ values: [this.frontPlateDepth],
643
+ },
644
+ ],
645
+ },
646
+ ];
647
+ for (const animation of animations) {
648
+ const anim = new Animation(animation.name, animation.property, frameRate, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);
649
+ const animkeyFrames = [];
650
+ for (const key of animation.keys) {
651
+ animkeyFrames.push({
652
+ frame: key.frame,
653
+ value: key.values[0],
654
+ inTangent: key.values[1],
655
+ outTangent: key.values[2],
656
+ interpolation: key.values[3],
657
+ });
658
+ }
659
+ anim.setKeys(animkeyFrames);
660
+ if (!animation.mesh) {
661
+ continue;
662
+ }
663
+ animationGroup.addTargetedAnimation(anim, animation.mesh);
664
+ }
665
+ animationGroup.normalize(0, 45);
666
+ animationGroup.speedRatio = 1;
667
+ animationGroup.play();
668
+ }
669
+ _performEnterExitAnimation(speedRatio) {
670
+ const frameRate = 60;
671
+ const animationGroup = new AnimationGroup("Enter Exit Animation Group");
672
+ const animations = [
673
+ {
674
+ name: "frontPlateFadeOut",
675
+ mesh: this._frontPlate,
676
+ property: "material.fadeOut",
677
+ keys: [
678
+ {
679
+ frame: 0,
680
+ values: [0, 0, 0.025045314830017686, 0],
681
+ },
682
+ {
683
+ frame: 40,
684
+ values: [1.00205599570012, 0.025045314830017686, 0, 0],
685
+ },
686
+ ],
687
+ },
688
+ {
689
+ name: "textPlateZSlide",
690
+ mesh: this._textPlate,
691
+ property: "position.z",
692
+ keys: [
693
+ {
694
+ frame: 0,
695
+ values: [0, 0.0, 0.0],
696
+ },
697
+ {
698
+ frame: 40,
699
+ values: [Vector3.Forward(this._textPlate._scene.useRightHandedSystem).scale(-0.15).z, 0.0, 0.0],
700
+ },
701
+ ],
702
+ },
703
+ ];
704
+ for (const animation of animations) {
705
+ const anim = new Animation(animation.name, animation.property, frameRate, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);
706
+ const animkeyFrames = [];
707
+ for (const key of animation.keys) {
708
+ animkeyFrames.push({
709
+ frame: key.frame,
710
+ value: key.values[0],
711
+ inTangent: key.values[1],
712
+ outTangent: key.values[2],
713
+ interpolation: key.values[3],
714
+ });
715
+ }
716
+ anim.setKeys(animkeyFrames);
717
+ if (!animation.mesh) {
718
+ continue;
719
+ }
720
+ animationGroup.addTargetedAnimation(anim, animation.mesh);
721
+ }
722
+ animationGroup.normalize(0, 45);
723
+ animationGroup.speedRatio = speedRatio;
724
+ animationGroup.play();
725
+ }
726
+ _createBackMaterial(mesh) {
727
+ this._backMaterial = this._backMaterial ?? new MRDLBackplateMaterial(this.name + "backPlateMaterial", mesh.getScene());
728
+ this._backMaterial.absoluteSizes = true;
729
+ this._backMaterial.radius = this.radius;
730
+ this._backMaterial.lineWidth = 0.02;
731
+ }
732
+ _createFrontMaterial(mesh) {
733
+ this._frontMaterial = this._frontMaterial ?? new MRDLFrontplateMaterial(this.name + "Front Material", mesh.getScene());
734
+ this.frontMaterial.radius = this.innerQuadRadius;
735
+ this.frontMaterial.fadeOut = 0.0;
736
+ }
737
+ _createBackGlowMaterial(mesh) {
738
+ const glowRadius = this.radius + 0.04;
739
+ this._backGlowMaterial = this._backGlowMaterial ?? new MRDLBackglowMaterial(this.name + "Back Glow Material", mesh.getScene());
740
+ this._backGlowMaterial.bevelRadius = glowRadius;
741
+ this._backGlowMaterial.lineWidth = glowRadius;
742
+ this._backGlowMaterial.motion = 0.0;
743
+ }
744
+ _createInnerQuadMaterial(mesh) {
745
+ this._innerQuadMaterial = this._innerQuadMaterial ?? new MRDLInnerquadMaterial("inner_quad", mesh.getScene());
746
+ this._innerQuadMaterial.radius = this.innerQuadRadius;
747
+ if (this.isToggleButton) {
748
+ this._innerQuadMaterial.color = this.innerQuadColor;
749
+ }
750
+ }
751
+ _createPlateMaterial(mesh) {
752
+ this._plateMaterial = this._plateMaterial ?? new StandardMaterial(this.name + "Plate Material", mesh.getScene());
753
+ this._plateMaterial.specularColor = Color3.Black();
754
+ }
755
+ _onToggle(newState) {
756
+ super._onToggle(newState);
757
+ }
758
+ _affectMaterial(mesh) {
759
+ if (this._shareMaterials) {
760
+ // Back
761
+ if (!this._host._touchSharedMaterials["mrdlBackplateMaterial"]) {
762
+ this._createBackMaterial(mesh);
763
+ this._host._touchSharedMaterials["mrdlBackplateMaterial"] = this._backMaterial;
764
+ }
765
+ else {
766
+ this._backMaterial = this._host._touchSharedMaterials["mrdlBackplateMaterial"];
767
+ }
768
+ // Front
769
+ if (!this._host._touchSharedMaterials["mrdlFrontplateMaterial"]) {
770
+ this._createFrontMaterial(mesh);
771
+ this._host._touchSharedMaterials["mrdlFrontplateMaterial"] = this._frontMaterial;
772
+ }
773
+ else {
774
+ this._frontMaterial = this._host._touchSharedMaterials["mrdlFrontplateMaterial"];
775
+ }
776
+ // Back glow
777
+ if (!this._host._touchSharedMaterials["mrdlBackglowMaterial"]) {
778
+ this._createBackGlowMaterial(mesh);
779
+ this._host._touchSharedMaterials["mrdlBackglowMaterial"] = this._backGlowMaterial;
780
+ }
781
+ else {
782
+ this._backGlowMaterial = this._host._touchSharedMaterials["mrdlBackglowMaterial"];
783
+ }
784
+ // Inner quad
785
+ if (!this._host._touchSharedMaterials["mrdlInnerQuadMaterial"]) {
786
+ this._createInnerQuadMaterial(mesh);
787
+ this._host._touchSharedMaterials["mrdlInnerQuadMaterial"] = this._innerQuadMaterial;
788
+ }
789
+ else {
790
+ this._innerQuadMaterial = this._host._touchSharedMaterials["mrdlInnerQuadMaterial"];
791
+ }
792
+ }
793
+ else {
794
+ this._createBackMaterial(mesh);
795
+ this._createFrontMaterial(mesh);
796
+ this._createBackGlowMaterial(mesh);
797
+ this._createInnerQuadMaterial(mesh);
798
+ }
799
+ this._createPlateMaterial(mesh);
800
+ this._backPlate.material = this._backMaterial;
801
+ this._textPlate.material = this._plateMaterial;
802
+ if (!this._isBackplateVisible) {
803
+ this._backPlate.visibility = 0;
804
+ }
805
+ if (this._frontPlate) {
806
+ this._frontPlate.material = this._frontMaterial;
807
+ }
808
+ if (this._backGlow) {
809
+ this._backGlow.material = this._backGlowMaterial;
810
+ }
811
+ if (this._innerQuad) {
812
+ this._innerQuad.material = this._innerQuadMaterial;
813
+ }
814
+ this._rebuildContent();
815
+ }
816
+ /**
817
+ * Releases all associated resources
818
+ */
819
+ dispose() {
820
+ super.dispose(); // will dispose main mesh ie. back plate
821
+ this._disposeTooltip();
822
+ this.onPointerClickObservable.remove(this._pointerClickObserver);
823
+ this.onPointerEnterObservable.remove(this._pointerEnterObserver);
824
+ this.onPointerOutObservable.remove(this._pointerOutObserver);
825
+ this.onToggleObservable.remove(this._toggleObserver);
826
+ if (!this.shareMaterials) {
827
+ this._backMaterial.dispose();
828
+ this._frontMaterial.dispose();
829
+ this._plateMaterial.dispose();
830
+ this._backGlowMaterial.dispose();
831
+ this._innerQuadMaterial.dispose();
832
+ if (this._pickedPointObserver) {
833
+ this._host.onPickedPointChangedObservable.remove(this._pickedPointObserver);
834
+ this._pickedPointObserver = null;
835
+ }
836
+ }
837
+ }
838
+ }
839
+ /**
840
+ * Base Url for the frontplate model.
841
+ */
842
+ TouchHolographicButton.MRTK_ASSET_BASE_URL = "https://assets.babylonjs.com/meshes/MRTK/";
843
+ /**
844
+ * File name for the frontplate model.
845
+ */
846
+ TouchHolographicButton.FRONTPLATE_MODEL_FILENAME = "mrtk-fluent-frontplate.glb";
847
+ /**
848
+ * File name for the backplate model.
849
+ */
850
+ TouchHolographicButton.BACKPLATE_MODEL_FILENAME = "mrtk-fluent-backplate.glb";
851
+ /**
852
+ * File name for the backglow model.
853
+ */
854
+ TouchHolographicButton.BACKGLOW_MODEL_FILENAME = "mrtk-fluent-button.glb";
855
+ /**
856
+ * File name for the innerquad model.
857
+ */
858
+ TouchHolographicButton.INNERQUAD_MODEL_FILENAME = "SlateProximity.glb";
859
+ //# sourceMappingURL=touchHolographicButton.js.map