@configura/babylon-view 1.3.0-alpha.1 → 1.3.0-alpha.2

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