@configura/babylon-view 1.4.0-alpha.4 → 1.4.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 (125) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/animation/AnimatableObject.d.ts +8 -8
  4. package/dist/animation/AnimatableObject.js +3 -3
  5. package/dist/animation/animator/Animator.d.ts +33 -33
  6. package/dist/animation/animator/Animator.js +58 -58
  7. package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
  8. package/dist/animation/animator/AnimatorEasing.js +31 -31
  9. package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
  10. package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
  11. package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
  12. package/dist/animation/animator/AnimatorHighlight.js +32 -32
  13. package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
  14. package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
  15. package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
  16. package/dist/animation/animator/AnimatorQueue.js +57 -57
  17. package/dist/animation/animator/AnimatorScale.d.ts +8 -8
  18. package/dist/animation/animator/AnimatorScale.js +13 -13
  19. package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
  20. package/dist/animation/animator/AnimatorSpin.js +13 -13
  21. package/dist/animation/animator/EasingFunctions.d.ts +35 -35
  22. package/dist/animation/animator/EasingFunctions.js +137 -137
  23. package/dist/animation/coordinator/Coordinator.d.ts +28 -28
  24. package/dist/animation/coordinator/Coordinator.js +47 -47
  25. package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
  26. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +133 -133
  27. package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
  28. package/dist/animation/coordinator/CoordinatorIdentity.js +12 -12
  29. package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
  30. package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
  31. package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
  32. package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
  33. package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
  34. package/dist/animation/coordinator/CoordinatorPulseBounce.js +40 -40
  35. package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
  36. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +34 -34
  37. package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
  38. package/dist/animation/coordinator/CoordinatorPulseInflate.js +30 -30
  39. package/dist/camera/CameraCreator.d.ts +5 -5
  40. package/dist/camera/CameraCreator.js +4 -4
  41. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +26 -26
  42. package/dist/camera/CfgArcRotateCameraPointersInput.js +264 -264
  43. package/dist/camera/CfgOrbitalCamera.d.ts +68 -68
  44. package/dist/camera/CfgOrbitalCamera.js +250 -250
  45. package/dist/camera/CfgOrbitalCameraControlProps.d.ts +6 -6
  46. package/dist/camera/CfgOrbitalCameraControlProps.js +3 -3
  47. package/dist/camera/GradingApplier.d.ts +3 -3
  48. package/dist/camera/GradingApplier.js +48 -48
  49. package/dist/engine/EngineCreator.d.ts +3 -3
  50. package/dist/engine/EngineCreator.js +10 -10
  51. package/dist/geometry/CfgGeometry.d.ts +29 -29
  52. package/dist/geometry/CfgGeometry.js +146 -146
  53. package/dist/geometry/CfgMesh.d.ts +10 -10
  54. package/dist/geometry/CfgMesh.js +38 -38
  55. package/dist/geometry/geoSplitter.d.ts +8 -8
  56. package/dist/geometry/geoSplitter.js +192 -192
  57. package/dist/geometry/stretch/CfgMorphTarget.d.ts +15 -15
  58. package/dist/geometry/stretch/CfgMorphTarget.js +65 -65
  59. package/dist/geometry/stretch/CfgStretchData.d.ts +114 -114
  60. package/dist/geometry/stretch/CfgStretchData.js +340 -340
  61. package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +16 -16
  62. package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -95
  63. package/dist/index.d.ts +13 -13
  64. package/dist/index.js +13 -13
  65. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  66. package/dist/light/CfgDirectionalLight.js +18 -18
  67. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  68. package/dist/light/CfgHemisphericLight.js +17 -17
  69. package/dist/light/CfgPointLight.d.ts +8 -8
  70. package/dist/light/CfgPointLight.js +18 -18
  71. package/dist/light/DefaultLightRig.d.ts +19 -19
  72. package/dist/light/DefaultLightRig.js +77 -77
  73. package/dist/light/LightRigCreator.d.ts +9 -9
  74. package/dist/light/LightRigCreator.js +3 -3
  75. package/dist/material/CfgMaterial.d.ts +68 -68
  76. package/dist/material/CfgMaterial.js +482 -482
  77. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  78. package/dist/material/DummyMaterialCreator.js +15 -15
  79. package/dist/material/material.d.ts +18 -18
  80. package/dist/material/material.js +128 -128
  81. package/dist/material/texture.d.ts +14 -14
  82. package/dist/material/texture.js +306 -306
  83. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  84. package/dist/nodes/CfgContentRootNode.js +75 -75
  85. package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -55
  86. package/dist/nodes/CfgDeferredMeshNode.js +377 -377
  87. package/dist/nodes/CfgProductNode.d.ts +126 -126
  88. package/dist/nodes/CfgProductNode.js +578 -578
  89. package/dist/nodes/CfgSymNode.d.ts +50 -50
  90. package/dist/nodes/CfgSymNode.js +249 -249
  91. package/dist/nodes/CfgSymRootNode.d.ts +45 -45
  92. package/dist/nodes/CfgSymRootNode.js +220 -220
  93. package/dist/nodes/CfgTransformNode.d.ts +33 -33
  94. package/dist/nodes/CfgTransformNode.js +83 -83
  95. package/dist/scene/SceneCreator.d.ts +6 -6
  96. package/dist/scene/SceneCreator.js +22 -22
  97. package/dist/utilities/CfgBoundingBox.d.ts +21 -21
  98. package/dist/utilities/CfgBoundingBox.js +81 -81
  99. package/dist/utilities/anchor/anchor.d.ts +51 -51
  100. package/dist/utilities/anchor/anchor.js +136 -136
  101. package/dist/utilities/anchor/anchorMap.d.ts +20 -20
  102. package/dist/utilities/anchor/anchorMap.js +111 -111
  103. package/dist/utilities/utilities3D.d.ts +70 -70
  104. package/dist/utilities/utilities3D.js +265 -265
  105. package/dist/utilities/utilitiesColor.d.ts +18 -18
  106. package/dist/utilities/utilitiesColor.js +48 -48
  107. package/dist/utilities/utilitiesImage.d.ts +6 -6
  108. package/dist/utilities/utilitiesImage.js +107 -107
  109. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -7
  110. package/dist/utilities/utilitiesSymRootIdentifier.js +26 -26
  111. package/dist/view/BaseView.d.ts +78 -78
  112. package/dist/view/BaseView.js +297 -297
  113. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  114. package/dist/view/BaseViewConfiguration.js +8 -8
  115. package/dist/view/RenderEnv.d.ts +43 -43
  116. package/dist/view/RenderEnv.js +7 -7
  117. package/dist/view/SingleProductDefaultCameraView.d.ts +33 -33
  118. package/dist/view/SingleProductDefaultCameraView.js +141 -141
  119. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +46 -46
  120. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  121. package/dist/view/SingleProductView.d.ts +42 -42
  122. package/dist/view/SingleProductView.js +206 -206
  123. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  124. package/dist/view/SingleProductViewConfiguration.js +19 -19
  125. package/package.json +5 -5
@@ -1,264 +1,264 @@
1
- import { ArcRotateCameraPointersInput } from "@babylonjs/core/Cameras/Inputs/arcRotateCameraPointersInput.js";
2
- import "@babylonjs/core/Engines/Extensions/engine.webVR.js"; // isInVRExclusivePointerMode
3
- import { PointerEventTypes, } from "@babylonjs/core/Events/pointerEvents.js";
4
- import { Tools } from "@babylonjs/core/Misc/tools.js";
5
- /**
6
- * This class exists to workaround a severe touch input issue that exists on at least iOS 13.4 in
7
- * Babylon release 4.1.0 and possibly later.
8
- *
9
- * The main workaround is marked with "--- START OF WORKAROUND ---" in the source below.
10
- *
11
- * Most of the code below is copied from the Babylon source class BaseCameraPointersInput.ts,
12
- * which ArcRotateCameraPointersInput extends. Some additional private support code from
13
- * BaseCameraPointersInput is also included and suffixed with "CfgPatch".
14
- *
15
- * @warning: DO NOT do any other changes to this file! They WILL be lost when this workaround is no
16
- * longer needed.
17
- *
18
- * @todo Every time the babylon module is updated to a new release, test if the workaround is still
19
- * needed. If not, simply remove this file and update CfgOrbitalCamera.ts to not use it.
20
- */
21
- export class CfgArcRotateCameraPointersInput extends ArcRotateCameraPointersInput {
22
- constructor() {
23
- super(...arguments);
24
- this._observerCfgPatch = null;
25
- this._onLostFocusCfgPatch = null;
26
- this._pointA = null;
27
- this._pointB = null;
28
- }
29
- attachControl(noPreventDefault) {
30
- noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);
31
- var engine = this.camera.getEngine();
32
- const element = engine.getInputElement();
33
- var previousPinchSquaredDistance = 0;
34
- var previousMultiTouchPanPosition = null;
35
- this._pointA = null;
36
- this._pointB = null;
37
- this._altKey = false;
38
- this._ctrlKey = false;
39
- this._metaKey = false;
40
- this._shiftKey = false;
41
- this._buttonsPressed = 0;
42
- const pointerInput = (p, s) => {
43
- var evt = p.event;
44
- let isTouch = evt.pointerType === "touch";
45
- if (engine.isInVRExclusivePointerMode) {
46
- return;
47
- }
48
- if (p.type !== PointerEventTypes.POINTERMOVE &&
49
- this.buttons.indexOf(evt.button) === -1) {
50
- return;
51
- }
52
- let srcElement = (evt.srcElement || evt.target);
53
- this._altKey = evt.altKey;
54
- this._ctrlKey = evt.ctrlKey;
55
- this._metaKey = evt.metaKey;
56
- this._shiftKey = evt.shiftKey;
57
- this._buttonsPressed = evt.buttons;
58
- if (engine.isPointerLock) {
59
- let offsetX = evt.movementX ||
60
- evt.mozMovementX ||
61
- evt.webkitMovementX ||
62
- evt.msMovementX ||
63
- 0;
64
- let offsetY = evt.movementY ||
65
- evt.mozMovementY ||
66
- evt.webkitMovementY ||
67
- evt.msMovementY ||
68
- 0;
69
- this.onTouch(null, offsetX, offsetY);
70
- this._pointA = null;
71
- this._pointB = null;
72
- }
73
- else if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
74
- try {
75
- srcElement.setPointerCapture(evt.pointerId);
76
- }
77
- catch (e) {
78
- //Nothing to do with the error. Execution will continue.
79
- }
80
- if (this._pointA === null) {
81
- this._pointA = {
82
- x: evt.clientX,
83
- y: evt.clientY,
84
- pointerId: evt.pointerId,
85
- type: evt.pointerType,
86
- };
87
- }
88
- else if (this._pointB === null) {
89
- this._pointB = {
90
- x: evt.clientX,
91
- y: evt.clientY,
92
- pointerId: evt.pointerId,
93
- type: evt.pointerType,
94
- };
95
- }
96
- this.onButtonDown(evt);
97
- if (!noPreventDefault) {
98
- evt.preventDefault();
99
- element && element.focus();
100
- }
101
- }
102
- else if (p.type === PointerEventTypes.POINTERDOUBLETAP) {
103
- this.onDoubleTap(evt.pointerType);
104
- }
105
- else if (p.type === PointerEventTypes.POINTERUP && srcElement) {
106
- try {
107
- srcElement.releasePointerCapture(evt.pointerId);
108
- }
109
- catch (e) {
110
- //Nothing to do with the error.
111
- }
112
- if (!isTouch) {
113
- this._pointB = null; // Mouse and pen are mono pointer
114
- }
115
- //would be better to use pointers.remove(evt.pointerId) for multi-touch gestures,
116
- //but emptying completely pointers collection is required to fix a bug on iPhone :
117
- //when changing orientation while pinching camera,
118
- //one pointer stay pressed forever if we don't release all pointers
119
- //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
120
- if (engine._badOS) {
121
- this._pointA = this._pointB = null;
122
- }
123
- else {
124
- //only remove the impacted pointer in case of multi-touch allowing on most
125
- //platforms switching from rotate to zoom and pan seamlessly.
126
- if (this._pointB && this._pointA && this._pointA.pointerId === evt.pointerId) {
127
- this._pointA = this._pointB;
128
- this._pointB = null;
129
- }
130
- else if (this._pointA &&
131
- this._pointB &&
132
- this._pointB.pointerId === evt.pointerId) {
133
- this._pointB = null;
134
- }
135
- else {
136
- this._pointA = this._pointB = null;
137
- }
138
- }
139
- if (previousPinchSquaredDistance !== 0 || previousMultiTouchPanPosition) {
140
- // Previous pinch data is populated but a button has been lifted
141
- // so pinch has ended.
142
- this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, 0, // pinchSquaredDistance
143
- previousMultiTouchPanPosition, null // multiTouchPanPosition
144
- );
145
- previousPinchSquaredDistance = 0;
146
- previousMultiTouchPanPosition = null;
147
- }
148
- this.onButtonUp(evt);
149
- if (!noPreventDefault) {
150
- evt.preventDefault();
151
- }
152
- }
153
- else if (p.type === PointerEventTypes.POINTERMOVE) {
154
- if (!noPreventDefault) {
155
- evt.preventDefault();
156
- }
157
- // --- START OF WORKAROUND ---
158
- // At least iOS 13.4 has problems where some touches generates pointer move events
159
- // without a starting pointer down event nor a finishing pointer up. It appears
160
- // that the triggering cause is using two fingers at almost the same time.
161
- //
162
- // Babylon.js (version 4.1.0 as of this writing) does not gracefully handle this
163
- // but instead starts flickering between the two different touch points since it
164
- // does not validate that the pointerID matches the stored point A.
165
- //
166
- // Babylon also doesn't properly handle when more than two fingers gets pressed or
167
- // a third finger gets added, again starting to flicker between the touch points
168
- // since it only checks if the pointerID is "point A" and assumes that all other
169
- // touches are "point B".
170
- //
171
- // The short code snippet below provides some filtering and workarounds not yet
172
- // present in Babylon. All other code around this workaround comes from the release
173
- // version of Babylon 4.1.0, class ArcRotateCameraPointerInput.ts
174
- if (engine._badOS) {
175
- // Unknown touch when only one touch is registered, register as second touch
176
- if (this._pointA && !this._pointB && evt.pointerId !== this._pointA.pointerId) {
177
- this._pointB = {
178
- x: evt.clientX,
179
- y: evt.clientY,
180
- pointerId: evt.pointerId,
181
- type: evt.pointerType,
182
- };
183
- }
184
- }
185
- // The touch does not match either of the registered touches, ignore it
186
- if (!((this._pointA && this._pointA.pointerId === evt.pointerId) ||
187
- (this._pointB && this._pointB.pointerId === evt.pointerId))) {
188
- return;
189
- }
190
- // --- END OF WORKAROUND ---
191
- // One button down
192
- if (this._pointA && this._pointB === null) {
193
- var offsetX = evt.clientX - this._pointA.x;
194
- var offsetY = evt.clientY - this._pointA.y;
195
- this.onTouch(this._pointA, offsetX, offsetY);
196
- this._pointA.x = evt.clientX;
197
- this._pointA.y = evt.clientY;
198
- }
199
- // Two buttons down: pinch
200
- else if (this._pointA && this._pointB) {
201
- var ed = this._pointA.pointerId === evt.pointerId ? this._pointA : this._pointB;
202
- ed.x = evt.clientX;
203
- ed.y = evt.clientY;
204
- var distX = this._pointA.x - this._pointB.x;
205
- var distY = this._pointA.y - this._pointB.y;
206
- var pinchSquaredDistance = distX * distX + distY * distY;
207
- var multiTouchPanPosition = {
208
- x: (this._pointA.x + this._pointB.x) / 2,
209
- y: (this._pointA.y + this._pointB.y) / 2,
210
- pointerId: evt.pointerId,
211
- type: p.type,
212
- };
213
- this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition);
214
- previousMultiTouchPanPosition = multiTouchPanPosition;
215
- previousPinchSquaredDistance = pinchSquaredDistance;
216
- }
217
- }
218
- };
219
- this._observerCfgPatch = this.camera
220
- .getScene()
221
- .onPointerObservable.add(pointerInput, PointerEventTypes.POINTERDOWN |
222
- PointerEventTypes.POINTERUP |
223
- PointerEventTypes.POINTERMOVE);
224
- this._onLostFocusCfgPatch = () => {
225
- this._pointA = this._pointB = null;
226
- previousPinchSquaredDistance = 0;
227
- previousMultiTouchPanPosition = null;
228
- this.onLostFocus();
229
- };
230
- element &&
231
- element.addEventListener("contextmenu", this.onContextMenu.bind(this), false);
232
- let hostWindow = this.camera.getScene().getEngine().getHostWindow();
233
- if (hostWindow) {
234
- Tools.RegisterTopRootEvents(hostWindow, [
235
- { name: "blur", handler: this._onLostFocusCfgPatch },
236
- ]);
237
- }
238
- }
239
- detachControl(ignored) {
240
- if (this._onLostFocusCfgPatch) {
241
- let hostWindow = this.camera.getScene().getEngine().getHostWindow();
242
- if (hostWindow) {
243
- Tools.UnregisterTopRootEvents(hostWindow, [
244
- { name: "blur", handler: this._onLostFocusCfgPatch },
245
- ]);
246
- }
247
- }
248
- if (this._observerCfgPatch) {
249
- this.camera.getScene().onPointerObservable.remove(this._observerCfgPatch);
250
- this._observerCfgPatch = null;
251
- if (this.onContextMenu) {
252
- const inputElement = this.camera.getScene().getEngine().getInputElement();
253
- inputElement &&
254
- inputElement.removeEventListener("contextmenu", this.onContextMenu);
255
- }
256
- this._onLostFocusCfgPatch = null;
257
- }
258
- this._altKey = false;
259
- this._ctrlKey = false;
260
- this._metaKey = false;
261
- this._shiftKey = false;
262
- this._buttonsPressed = 0;
263
- }
264
- }
1
+ import { ArcRotateCameraPointersInput } from "@babylonjs/core/Cameras/Inputs/arcRotateCameraPointersInput.js";
2
+ import "@babylonjs/core/Engines/Extensions/engine.webVR.js"; // isInVRExclusivePointerMode
3
+ import { PointerEventTypes, } from "@babylonjs/core/Events/pointerEvents.js";
4
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
5
+ /**
6
+ * This class exists to workaround a severe touch input issue that exists on at least iOS 13.4 in
7
+ * Babylon release 4.1.0 and possibly later.
8
+ *
9
+ * The main workaround is marked with "--- START OF WORKAROUND ---" in the source below.
10
+ *
11
+ * Most of the code below is copied from the Babylon source class BaseCameraPointersInput.ts,
12
+ * which ArcRotateCameraPointersInput extends. Some additional private support code from
13
+ * BaseCameraPointersInput is also included and suffixed with "CfgPatch".
14
+ *
15
+ * @warning: DO NOT do any other changes to this file! They WILL be lost when this workaround is no
16
+ * longer needed.
17
+ *
18
+ * @todo Every time the babylon module is updated to a new release, test if the workaround is still
19
+ * needed. If not, simply remove this file and update CfgOrbitalCamera.ts to not use it.
20
+ */
21
+ export class CfgArcRotateCameraPointersInput extends ArcRotateCameraPointersInput {
22
+ constructor() {
23
+ super(...arguments);
24
+ this._observerCfgPatch = null;
25
+ this._onLostFocusCfgPatch = null;
26
+ this._pointA = null;
27
+ this._pointB = null;
28
+ }
29
+ attachControl(noPreventDefault) {
30
+ noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);
31
+ var engine = this.camera.getEngine();
32
+ const element = engine.getInputElement();
33
+ var previousPinchSquaredDistance = 0;
34
+ var previousMultiTouchPanPosition = null;
35
+ this._pointA = null;
36
+ this._pointB = null;
37
+ this._altKey = false;
38
+ this._ctrlKey = false;
39
+ this._metaKey = false;
40
+ this._shiftKey = false;
41
+ this._buttonsPressed = 0;
42
+ const pointerInput = (p, s) => {
43
+ var evt = p.event;
44
+ let isTouch = evt.pointerType === "touch";
45
+ if (engine.isInVRExclusivePointerMode) {
46
+ return;
47
+ }
48
+ if (p.type !== PointerEventTypes.POINTERMOVE &&
49
+ this.buttons.indexOf(evt.button) === -1) {
50
+ return;
51
+ }
52
+ let srcElement = (evt.srcElement || evt.target);
53
+ this._altKey = evt.altKey;
54
+ this._ctrlKey = evt.ctrlKey;
55
+ this._metaKey = evt.metaKey;
56
+ this._shiftKey = evt.shiftKey;
57
+ this._buttonsPressed = evt.buttons;
58
+ if (engine.isPointerLock) {
59
+ let offsetX = evt.movementX ||
60
+ evt.mozMovementX ||
61
+ evt.webkitMovementX ||
62
+ evt.msMovementX ||
63
+ 0;
64
+ let offsetY = evt.movementY ||
65
+ evt.mozMovementY ||
66
+ evt.webkitMovementY ||
67
+ evt.msMovementY ||
68
+ 0;
69
+ this.onTouch(null, offsetX, offsetY);
70
+ this._pointA = null;
71
+ this._pointB = null;
72
+ }
73
+ else if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
74
+ try {
75
+ srcElement.setPointerCapture(evt.pointerId);
76
+ }
77
+ catch (e) {
78
+ //Nothing to do with the error. Execution will continue.
79
+ }
80
+ if (this._pointA === null) {
81
+ this._pointA = {
82
+ x: evt.clientX,
83
+ y: evt.clientY,
84
+ pointerId: evt.pointerId,
85
+ type: evt.pointerType,
86
+ };
87
+ }
88
+ else if (this._pointB === null) {
89
+ this._pointB = {
90
+ x: evt.clientX,
91
+ y: evt.clientY,
92
+ pointerId: evt.pointerId,
93
+ type: evt.pointerType,
94
+ };
95
+ }
96
+ this.onButtonDown(evt);
97
+ if (!noPreventDefault) {
98
+ evt.preventDefault();
99
+ element && element.focus();
100
+ }
101
+ }
102
+ else if (p.type === PointerEventTypes.POINTERDOUBLETAP) {
103
+ this.onDoubleTap(evt.pointerType);
104
+ }
105
+ else if (p.type === PointerEventTypes.POINTERUP && srcElement) {
106
+ try {
107
+ srcElement.releasePointerCapture(evt.pointerId);
108
+ }
109
+ catch (e) {
110
+ //Nothing to do with the error.
111
+ }
112
+ if (!isTouch) {
113
+ this._pointB = null; // Mouse and pen are mono pointer
114
+ }
115
+ //would be better to use pointers.remove(evt.pointerId) for multi-touch gestures,
116
+ //but emptying completely pointers collection is required to fix a bug on iPhone :
117
+ //when changing orientation while pinching camera,
118
+ //one pointer stay pressed forever if we don't release all pointers
119
+ //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
120
+ if (engine._badOS) {
121
+ this._pointA = this._pointB = null;
122
+ }
123
+ else {
124
+ //only remove the impacted pointer in case of multi-touch allowing on most
125
+ //platforms switching from rotate to zoom and pan seamlessly.
126
+ if (this._pointB && this._pointA && this._pointA.pointerId === evt.pointerId) {
127
+ this._pointA = this._pointB;
128
+ this._pointB = null;
129
+ }
130
+ else if (this._pointA &&
131
+ this._pointB &&
132
+ this._pointB.pointerId === evt.pointerId) {
133
+ this._pointB = null;
134
+ }
135
+ else {
136
+ this._pointA = this._pointB = null;
137
+ }
138
+ }
139
+ if (previousPinchSquaredDistance !== 0 || previousMultiTouchPanPosition) {
140
+ // Previous pinch data is populated but a button has been lifted
141
+ // so pinch has ended.
142
+ this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, 0, // pinchSquaredDistance
143
+ previousMultiTouchPanPosition, null // multiTouchPanPosition
144
+ );
145
+ previousPinchSquaredDistance = 0;
146
+ previousMultiTouchPanPosition = null;
147
+ }
148
+ this.onButtonUp(evt);
149
+ if (!noPreventDefault) {
150
+ evt.preventDefault();
151
+ }
152
+ }
153
+ else if (p.type === PointerEventTypes.POINTERMOVE) {
154
+ if (!noPreventDefault) {
155
+ evt.preventDefault();
156
+ }
157
+ // --- START OF WORKAROUND ---
158
+ // At least iOS 13.4 has problems where some touches generates pointer move events
159
+ // without a starting pointer down event nor a finishing pointer up. It appears
160
+ // that the triggering cause is using two fingers at almost the same time.
161
+ //
162
+ // Babylon.js (version 4.1.0 as of this writing) does not gracefully handle this
163
+ // but instead starts flickering between the two different touch points since it
164
+ // does not validate that the pointerID matches the stored point A.
165
+ //
166
+ // Babylon also doesn't properly handle when more than two fingers gets pressed or
167
+ // a third finger gets added, again starting to flicker between the touch points
168
+ // since it only checks if the pointerID is "point A" and assumes that all other
169
+ // touches are "point B".
170
+ //
171
+ // The short code snippet below provides some filtering and workarounds not yet
172
+ // present in Babylon. All other code around this workaround comes from the release
173
+ // version of Babylon 4.1.0, class ArcRotateCameraPointerInput.ts
174
+ if (engine._badOS) {
175
+ // Unknown touch when only one touch is registered, register as second touch
176
+ if (this._pointA && !this._pointB && evt.pointerId !== this._pointA.pointerId) {
177
+ this._pointB = {
178
+ x: evt.clientX,
179
+ y: evt.clientY,
180
+ pointerId: evt.pointerId,
181
+ type: evt.pointerType,
182
+ };
183
+ }
184
+ }
185
+ // The touch does not match either of the registered touches, ignore it
186
+ if (!((this._pointA && this._pointA.pointerId === evt.pointerId) ||
187
+ (this._pointB && this._pointB.pointerId === evt.pointerId))) {
188
+ return;
189
+ }
190
+ // --- END OF WORKAROUND ---
191
+ // One button down
192
+ if (this._pointA && this._pointB === null) {
193
+ var offsetX = evt.clientX - this._pointA.x;
194
+ var offsetY = evt.clientY - this._pointA.y;
195
+ this.onTouch(this._pointA, offsetX, offsetY);
196
+ this._pointA.x = evt.clientX;
197
+ this._pointA.y = evt.clientY;
198
+ }
199
+ // Two buttons down: pinch
200
+ else if (this._pointA && this._pointB) {
201
+ var ed = this._pointA.pointerId === evt.pointerId ? this._pointA : this._pointB;
202
+ ed.x = evt.clientX;
203
+ ed.y = evt.clientY;
204
+ var distX = this._pointA.x - this._pointB.x;
205
+ var distY = this._pointA.y - this._pointB.y;
206
+ var pinchSquaredDistance = distX * distX + distY * distY;
207
+ var multiTouchPanPosition = {
208
+ x: (this._pointA.x + this._pointB.x) / 2,
209
+ y: (this._pointA.y + this._pointB.y) / 2,
210
+ pointerId: evt.pointerId,
211
+ type: p.type,
212
+ };
213
+ this.onMultiTouch(this._pointA, this._pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition);
214
+ previousMultiTouchPanPosition = multiTouchPanPosition;
215
+ previousPinchSquaredDistance = pinchSquaredDistance;
216
+ }
217
+ }
218
+ };
219
+ this._observerCfgPatch = this.camera
220
+ .getScene()
221
+ .onPointerObservable.add(pointerInput, PointerEventTypes.POINTERDOWN |
222
+ PointerEventTypes.POINTERUP |
223
+ PointerEventTypes.POINTERMOVE);
224
+ this._onLostFocusCfgPatch = () => {
225
+ this._pointA = this._pointB = null;
226
+ previousPinchSquaredDistance = 0;
227
+ previousMultiTouchPanPosition = null;
228
+ this.onLostFocus();
229
+ };
230
+ element &&
231
+ element.addEventListener("contextmenu", this.onContextMenu.bind(this), false);
232
+ let hostWindow = this.camera.getScene().getEngine().getHostWindow();
233
+ if (hostWindow) {
234
+ Tools.RegisterTopRootEvents(hostWindow, [
235
+ { name: "blur", handler: this._onLostFocusCfgPatch },
236
+ ]);
237
+ }
238
+ }
239
+ detachControl(ignored) {
240
+ if (this._onLostFocusCfgPatch) {
241
+ let hostWindow = this.camera.getScene().getEngine().getHostWindow();
242
+ if (hostWindow) {
243
+ Tools.UnregisterTopRootEvents(hostWindow, [
244
+ { name: "blur", handler: this._onLostFocusCfgPatch },
245
+ ]);
246
+ }
247
+ }
248
+ if (this._observerCfgPatch) {
249
+ this.camera.getScene().onPointerObservable.remove(this._observerCfgPatch);
250
+ this._observerCfgPatch = null;
251
+ if (this.onContextMenu) {
252
+ const inputElement = this.camera.getScene().getEngine().getInputElement();
253
+ inputElement &&
254
+ inputElement.removeEventListener("contextmenu", this.onContextMenu);
255
+ }
256
+ this._onLostFocusCfgPatch = null;
257
+ }
258
+ this._altKey = false;
259
+ this._ctrlKey = false;
260
+ this._metaKey = false;
261
+ this._shiftKey = false;
262
+ this._buttonsPressed = 0;
263
+ }
264
+ }