@babylonjs/core 5.0.0-beta.3 → 5.0.0-beta.4

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 (78) hide show
  1. package/Culling/ray.d.ts +6 -4
  2. package/Culling/ray.js +31 -10
  3. package/Culling/ray.js.map +1 -1
  4. package/DeviceInput/Helpers/eventFactory.d.ts +1 -1
  5. package/DeviceInput/Helpers/eventFactory.js.map +1 -1
  6. package/DeviceInput/InputDevices/deviceSource.d.ts +35 -0
  7. package/DeviceInput/InputDevices/deviceSource.js +38 -0
  8. package/DeviceInput/InputDevices/deviceSource.js.map +1 -0
  9. package/DeviceInput/InputDevices/deviceSourceManager.d.ts +14 -72
  10. package/DeviceInput/InputDevices/deviceSourceManager.js +10 -180
  11. package/DeviceInput/InputDevices/deviceSourceManager.js.map +1 -1
  12. package/DeviceInput/{Interfaces → InputDevices}/inputInterfaces.d.ts +1 -5
  13. package/DeviceInput/{Interfaces → InputDevices}/inputInterfaces.js +0 -0
  14. package/DeviceInput/InputDevices/inputInterfaces.js.map +1 -0
  15. package/DeviceInput/InputDevices/internalDeviceSourceManager.d.ts +46 -0
  16. package/DeviceInput/InputDevices/internalDeviceSourceManager.js +143 -0
  17. package/DeviceInput/InputDevices/internalDeviceSourceManager.js.map +1 -0
  18. package/DeviceInput/{Implementations → InputDevices}/nativeDeviceInputSystem.d.ts +3 -7
  19. package/DeviceInput/{Implementations → InputDevices}/nativeDeviceInputSystem.js +9 -15
  20. package/DeviceInput/InputDevices/nativeDeviceInputSystem.js.map +1 -0
  21. package/DeviceInput/{Implementations → InputDevices}/webDeviceInputSystem.d.ts +11 -15
  22. package/DeviceInput/{Implementations → InputDevices}/webDeviceInputSystem.js +84 -65
  23. package/DeviceInput/InputDevices/webDeviceInputSystem.js.map +1 -0
  24. package/DeviceInput/index.d.ts +1 -5
  25. package/DeviceInput/index.js +1 -5
  26. package/DeviceInput/index.js.map +1 -1
  27. package/Engines/Native/nativeInterfaces.d.ts +1 -1
  28. package/Engines/Native/nativeInterfaces.js.map +1 -1
  29. package/Engines/engine.d.ts +0 -5
  30. package/Engines/engine.js +0 -4
  31. package/Engines/engine.js.map +1 -1
  32. package/Engines/engineCapabilities.d.ts +2 -0
  33. package/Engines/engineCapabilities.js.map +1 -1
  34. package/Engines/nativeEngine.js +1 -0
  35. package/Engines/nativeEngine.js.map +1 -1
  36. package/Engines/nullEngine.js +1 -0
  37. package/Engines/nullEngine.js.map +1 -1
  38. package/Engines/thinEngine.d.ts +10 -1
  39. package/Engines/thinEngine.js +26 -14
  40. package/Engines/thinEngine.js.map +1 -1
  41. package/Engines/webgpuEngine.d.ts +0 -4
  42. package/Engines/webgpuEngine.js +2 -10
  43. package/Engines/webgpuEngine.js.map +1 -1
  44. package/Inputs/scene.inputManager.d.ts +1 -1
  45. package/Inputs/scene.inputManager.js +5 -8
  46. package/Inputs/scene.inputManager.js.map +1 -1
  47. package/Loading/Plugins/babylonFileLoader.js +40 -5
  48. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  49. package/Meshes/abstractMesh.d.ts +4 -0
  50. package/Meshes/abstractMesh.js +12 -0
  51. package/Meshes/abstractMesh.js.map +1 -1
  52. package/Meshes/mesh.js +13 -0
  53. package/Meshes/mesh.js.map +1 -1
  54. package/Misc/fileTools.js +1 -1
  55. package/Misc/fileTools.js.map +1 -1
  56. package/Misc/index.d.ts +1 -0
  57. package/Misc/index.js +1 -0
  58. package/Misc/index.js.map +1 -1
  59. package/Particles/gpuParticleSystem.js +2 -1
  60. package/Particles/gpuParticleSystem.js.map +1 -1
  61. package/Physics/Plugins/ammoJSPlugin.d.ts +5 -1
  62. package/Physics/Plugins/ammoJSPlugin.js +12 -7
  63. package/Physics/Plugins/ammoJSPlugin.js.map +1 -1
  64. package/Physics/physicsEngine.d.ts +1 -0
  65. package/Physics/physicsEngine.js +3 -1
  66. package/Physics/physicsEngine.js.map +1 -1
  67. package/XR/features/WebXRControllerPointerSelection.js +15 -9
  68. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  69. package/package.json +16 -13
  70. package/scene.d.ts +2 -1
  71. package/scene.js +3 -1
  72. package/scene.js.map +1 -1
  73. package/DeviceInput/Implementations/nativeDeviceInputSystem.js.map +0 -1
  74. package/DeviceInput/Implementations/webDeviceInputSystem.js.map +0 -1
  75. package/DeviceInput/Interfaces/inputInterfaces.js.map +0 -1
  76. package/DeviceInput/deviceInputSystem.d.ts +0 -60
  77. package/DeviceInput/deviceInputSystem.js +0 -84
  78. package/DeviceInput/deviceInputSystem.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { DeviceEventFactory } from "../Helpers/eventFactory.js";
2
- import { DeviceType } from "../InputDevices/deviceEnums.js";
2
+ import { DeviceType } from "./deviceEnums.js";
3
3
  /** @hidden */
4
- var NativeDeviceInputSystemImpl = /** @class */ (function () {
5
- function NativeDeviceInputSystemImpl(nativeInput) {
4
+ var NativeDeviceInputSystem = /** @class */ (function () {
5
+ function NativeDeviceInputSystem(nativeInput) {
6
6
  var _this = this;
7
7
  this.onDeviceConnected = function (deviceType, deviceSlot) { };
8
8
  this.onDeviceDisconnected = function (deviceType, deviceSlot) { };
@@ -25,12 +25,6 @@ var NativeDeviceInputSystemImpl = /** @class */ (function () {
25
25
  _this.onInputChanged(deviceEvent);
26
26
  };
27
27
  }
28
- /**
29
- * Configures events to work with an engine's active element
30
- */
31
- NativeDeviceInputSystemImpl.prototype.configureEvents = function () {
32
- // Do nothing
33
- };
34
28
  // Public functions
35
29
  /**
36
30
  * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.
@@ -39,7 +33,7 @@ var NativeDeviceInputSystemImpl = /** @class */ (function () {
39
33
  * @param inputIndex Id of input to be checked
40
34
  * @returns Current value of input
41
35
  */
42
- NativeDeviceInputSystemImpl.prototype.pollInput = function (deviceType, deviceSlot, inputIndex) {
36
+ NativeDeviceInputSystem.prototype.pollInput = function (deviceType, deviceSlot, inputIndex) {
43
37
  return this._nativeInput.pollInput(deviceType, deviceSlot, inputIndex);
44
38
  };
45
39
  /**
@@ -47,14 +41,14 @@ var NativeDeviceInputSystemImpl = /** @class */ (function () {
47
41
  * @param deviceType Type of device to check for
48
42
  * @returns bool with status of device's existence
49
43
  */
50
- NativeDeviceInputSystemImpl.prototype.isDeviceAvailable = function (deviceType) {
44
+ NativeDeviceInputSystem.prototype.isDeviceAvailable = function (deviceType) {
51
45
  //TODO: FIx native side first
52
46
  return (deviceType === DeviceType.Mouse || deviceType === DeviceType.Touch);
53
47
  };
54
48
  /**
55
49
  * Dispose of all the observables
56
50
  */
57
- NativeDeviceInputSystemImpl.prototype.dispose = function () {
51
+ NativeDeviceInputSystem.prototype.dispose = function () {
58
52
  this.onDeviceConnected = function () { };
59
53
  this.onDeviceDisconnected = function () { };
60
54
  this.onInputChanged = function () { };
@@ -63,7 +57,7 @@ var NativeDeviceInputSystemImpl = /** @class */ (function () {
63
57
  * For versions of BabylonNative that don't have the NativeInput plugin initialized, create a dummy version
64
58
  * @returns Object with dummy functions
65
59
  */
66
- NativeDeviceInputSystemImpl.prototype._createDummyNativeInput = function () {
60
+ NativeDeviceInputSystem.prototype._createDummyNativeInput = function () {
67
61
  var nativeInput = {
68
62
  onDeviceConnected: function (deviceType, deviceSlot) { },
69
63
  onDeviceDisconnected: function (deviceType, deviceSlot) { },
@@ -74,7 +68,7 @@ var NativeDeviceInputSystemImpl = /** @class */ (function () {
74
68
  };
75
69
  return nativeInput;
76
70
  };
77
- return NativeDeviceInputSystemImpl;
71
+ return NativeDeviceInputSystem;
78
72
  }());
79
- export { NativeDeviceInputSystemImpl };
73
+ export { NativeDeviceInputSystem };
80
74
  //# sourceMappingURL=nativeDeviceInputSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeDeviceInputSystem.js","sourceRoot":"","sources":["../../../../sourceES6/core/DeviceInput/InputDevices/nativeDeviceInputSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,cAAc;AACd;IAOI,iCAAmB,WAA0B;QAA7C,iBAuBC;QA7BM,sBAAiB,GAAG,UAAC,UAAsB,EAAE,UAAkB,IAAO,CAAC,CAAC;QACxE,yBAAoB,GAAG,UAAC,UAAsB,EAAE,UAAkB,IAAO,CAAC,CAAC;QAC3E,mBAAc,GAAG,UAAC,WAAyB,IAAO,CAAC,CAAC;QAKvD,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAElE,IAAI,CAAC,YAAY,CAAC,iBAAiB,GAAG,UAAC,UAAU,EAAE,UAAU;YACzD,KAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QACnD,CAAC,CAAC;QAEF,IAAI,CAAC,YAAY,CAAC,oBAAoB,GAAG,UAAC,UAAU,EAAE,UAAU;YAC5D,KAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QACtD,CAAC,CAAC;QAEF,IAAI,CAAC,YAAY,CAAC,cAAc,GAAG,UAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS;YAC1G,IAAM,GAAG,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,KAAI,CAAC,CAAC;YAEzG,IAAI,WAAW,GAAG,GAAmB,CAAC;YACtC,WAAW,CAAC,UAAU,GAAG,UAAU,CAAC;YACpC,WAAW,CAAC,UAAU,GAAG,UAAU,CAAC;YACpC,WAAW,CAAC,UAAU,GAAG,UAAU,CAAC;YACpC,WAAW,CAAC,aAAa,GAAG,aAAa,CAAC;YAC1C,WAAW,CAAC,YAAY,GAAG,YAAY,CAAC;YAExC,KAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACrC,CAAC,CAAC;IACN,CAAC;IAED,mBAAmB;IACnB;;;;;;OAMG;IACI,2CAAS,GAAhB,UAAiB,UAAsB,EAAE,UAAkB,EAAE,UAAkB;QAC3E,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACI,mDAAiB,GAAxB,UAAyB,UAAsB;QAC3C,6BAA6B;QAC7B,OAAO,CAAC,UAAU,KAAK,UAAU,CAAC,KAAK,IAAI,UAAU,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC;IAED;;OAEG;IACI,yCAAO,GAAd;QACI,IAAI,CAAC,iBAAiB,GAAG,cAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,oBAAoB,GAAG,cAAQ,CAAC,CAAC;QACtC,IAAI,CAAC,cAAc,GAAG,cAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACK,yDAAuB,GAA/B;QACI,IAAI,WAAW,GAAG;YACd,iBAAiB,EAAE,UAAC,UAAsB,EAAE,UAAkB,IAAO,CAAC;YACtE,oBAAoB,EAAE,UAAC,UAAsB,EAAE,UAAkB,IAAO,CAAC;YACzE,cAAc,EAAE,UAAC,UAAsB,EAAE,UAAkB,EAAE,UAAkB,EAAE,aAA+B,EAAE,YAA8B,EAAE,SAAe,IAAO,CAAC;YACzK,SAAS,EAAE,cAAQ,OAAO,CAAC,CAAC,CAAC,CAAC;YAC9B,iBAAiB,EAAE,cAAQ,OAAO,KAAK,CAAC,CAAC,CAAC;YAC1C,OAAO,EAAE,cAAQ,CAAC;SACrB,CAAC;QAEF,OAAO,WAAW,CAAC;IACvB,CAAC;IACL,8BAAC;AAAD,CAAC,AA/ED,IA+EC","sourcesContent":["import { Nullable } from \"../../types\";\r\nimport { DeviceEventFactory } from \"../Helpers/eventFactory\";\r\nimport { DeviceType } from \"./deviceEnums\";\r\nimport { IDeviceEvent, IDeviceInputSystem, INativeInput } from \"./inputInterfaces\";\r\n\r\n/** @hidden */\r\nexport class NativeDeviceInputSystem implements IDeviceInputSystem {\r\n public onDeviceConnected = (deviceType: DeviceType, deviceSlot: number) => { };\r\n public onDeviceDisconnected = (deviceType: DeviceType, deviceSlot: number) => { };\r\n public onInputChanged = (deviceEvent: IDeviceEvent) => { };\r\n\r\n private readonly _nativeInput: INativeInput;\r\n\r\n public constructor(nativeInput?: INativeInput) {\r\n this._nativeInput = nativeInput || this._createDummyNativeInput();\r\n\r\n this._nativeInput.onDeviceConnected = (deviceType, deviceSlot) => {\r\n this.onDeviceConnected(deviceType, deviceSlot);\r\n };\r\n\r\n this._nativeInput.onDeviceDisconnected = (deviceType, deviceSlot) => {\r\n this.onDeviceDisconnected(deviceType, deviceSlot);\r\n };\r\n\r\n this._nativeInput.onInputChanged = (deviceType, deviceSlot, inputIndex, previousState, currentState, eventData) => {\r\n const evt = DeviceEventFactory.CreateDeviceEvent(deviceType, deviceSlot, inputIndex, currentState, this);\r\n\r\n let deviceEvent = evt as IDeviceEvent;\r\n deviceEvent.deviceType = deviceType;\r\n deviceEvent.deviceSlot = deviceSlot;\r\n deviceEvent.inputIndex = inputIndex;\r\n deviceEvent.previousState = previousState;\r\n deviceEvent.currentState = currentState;\r\n\r\n this.onInputChanged(deviceEvent);\r\n };\r\n }\r\n\r\n // Public functions\r\n /**\r\n * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.\r\n * @param deviceType Enum specifiying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n * @param inputIndex Id of input to be checked\r\n * @returns Current value of input\r\n */\r\n public pollInput(deviceType: DeviceType, deviceSlot: number, inputIndex: number): number {\r\n return this._nativeInput.pollInput(deviceType, deviceSlot, inputIndex);\r\n }\r\n\r\n /**\r\n * Check for a specific device in the DeviceInputSystem\r\n * @param deviceType Type of device to check for\r\n * @returns bool with status of device's existence\r\n */\r\n public isDeviceAvailable(deviceType: DeviceType): boolean {\r\n //TODO: FIx native side first\r\n return (deviceType === DeviceType.Mouse || deviceType === DeviceType.Touch);\r\n }\r\n\r\n /**\r\n * Dispose of all the observables\r\n */\r\n public dispose(): void {\r\n this.onDeviceConnected = () => { };\r\n this.onDeviceDisconnected = () => { };\r\n this.onInputChanged = () => { };\r\n }\r\n\r\n /**\r\n * For versions of BabylonNative that don't have the NativeInput plugin initialized, create a dummy version\r\n * @returns Object with dummy functions\r\n */\r\n private _createDummyNativeInput() {\r\n let nativeInput = {\r\n onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => { },\r\n onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => { },\r\n onInputChanged: (deviceType: DeviceType, deviceSlot: number, inputIndex: number, previousState: Nullable<number>, currentState: Nullable<number>, eventData?: any) => { },\r\n pollInput: () => { return 0; },\r\n isDeviceAvailable: () => { return false; },\r\n dispose: () => { },\r\n };\r\n\r\n return nativeInput;\r\n }\r\n}"]}
@@ -1,8 +1,8 @@
1
1
  import { Engine } from "../../Engines/engine";
2
- import { DeviceType } from "../InputDevices/deviceEnums";
3
- import { IDeviceEvent, IDeviceInputSystem } from "../Interfaces/inputInterfaces";
2
+ import { DeviceType } from "./deviceEnums";
3
+ import { IDeviceEvent, IDeviceInputSystem } from "./inputInterfaces";
4
4
  /** @hidden */
5
- export declare class WebDeviceInputSystemImpl implements IDeviceInputSystem {
5
+ export declare class WebDeviceInputSystem implements IDeviceInputSystem {
6
6
  /** onDeviceConnected property */
7
7
  set onDeviceConnected(callback: (deviceType: DeviceType, deviceSlot: number) => void);
8
8
  get onDeviceConnected(): (deviceType: DeviceType, deviceSlot: number) => void;
@@ -13,8 +13,8 @@ export declare class WebDeviceInputSystemImpl implements IDeviceInputSystem {
13
13
  private _keyboardActive;
14
14
  private _pointerActive;
15
15
  private _elementToAttachTo;
16
- private _engine;
17
- private _usingSafari;
16
+ private readonly _engine;
17
+ private readonly _usingSafari;
18
18
  private _onDeviceConnected;
19
19
  private _keyboardDownEvent;
20
20
  private _keyboardUpEvent;
@@ -26,22 +26,14 @@ export declare class WebDeviceInputSystemImpl implements IDeviceInputSystem {
26
26
  private _pointerBlurEvent;
27
27
  private _wheelEventName;
28
28
  private _mouseId;
29
- private _isUsingFirefox;
29
+ private readonly _isUsingFirefox;
30
30
  private _activeTouchIds;
31
- private _rollingTouchId;
31
+ private _maxTouchPoints;
32
32
  private _pointerInputClearObserver;
33
33
  private _gamepadConnectedEvent;
34
34
  private _gamepadDisconnectedEvent;
35
- /** Max number of keycodes */
36
- static MAX_KEYCODES: number;
37
- /** Max number of pointer inputs */
38
- static MAX_POINTER_INPUTS: number;
39
35
  private _eventPrefix;
40
36
  constructor(engine: Engine);
41
- /**
42
- * Configures events to work with an engine's active element
43
- */
44
- configureEvents(): void;
45
37
  /**
46
38
  * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.
47
39
  * @param deviceType Enum specifiying device type
@@ -60,6 +52,10 @@ export declare class WebDeviceInputSystemImpl implements IDeviceInputSystem {
60
52
  * Dispose of all the eventlisteners
61
53
  */
62
54
  dispose(): void;
55
+ /**
56
+ * Configures events to work with an engine's active element
57
+ */
58
+ private _configureEvents;
63
59
  /**
64
60
  * Checks for existing connections to devices and register them, if necessary
65
61
  * Currently handles gamepads and mouse
@@ -1,9 +1,12 @@
1
+ import { DomManagement } from "../../Misc/domManagement.js";
1
2
  import { Tools } from "../../Misc/tools.js";
2
3
  import { DeviceEventFactory } from "../Helpers/eventFactory.js";
3
- import { DeviceType, PointerInput } from "../InputDevices/deviceEnums.js";
4
+ import { DeviceType, PointerInput } from "./deviceEnums.js";
5
+ var MAX_KEYCODES = 255;
6
+ var MAX_POINTER_INPUTS = Object.keys(PointerInput).length / 2;
4
7
  /** @hidden */
5
- var WebDeviceInputSystemImpl = /** @class */ (function () {
6
- function WebDeviceInputSystemImpl(engine) {
8
+ var WebDeviceInputSystem = /** @class */ (function () {
9
+ function WebDeviceInputSystem(engine) {
7
10
  // Private Members
8
11
  this._inputs = [];
9
12
  this._keyboardActive = false;
@@ -18,10 +21,8 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
18
21
  this._pointerWheelEvent = function (evt) { };
19
22
  this._pointerBlurEvent = function (evt) { };
20
23
  this._mouseId = -1;
21
- this._isUsingFirefox = navigator && navigator.userAgent && navigator.userAgent.indexOf("Firefox") !== -1;
22
- // Array to store active Pointer ID values; prevents issues with negative pointerIds
23
- this._activeTouchIds = [];
24
- this._rollingTouchId = 0; // Rolling ID number to assign; emulates Chrome assignment
24
+ this._isUsingFirefox = DomManagement.IsNavigatorAvailable() && navigator.userAgent && navigator.userAgent.indexOf("Firefox") !== -1;
25
+ this._maxTouchPoints = 0;
25
26
  this._pointerInputClearObserver = null;
26
27
  this._gamepadConnectedEvent = function (evt) { };
27
28
  this._gamepadDisconnectedEvent = function (evt) { };
@@ -30,9 +31,9 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
30
31
  this.onDeviceConnected = function (deviceType, deviceSlot) { };
31
32
  this.onDeviceDisconnected = function (deviceType, deviceSlot) { };
32
33
  this.onInputChanged = function (deviceEvent) { };
33
- this.configureEvents();
34
+ this._configureEvents();
34
35
  }
35
- Object.defineProperty(WebDeviceInputSystemImpl.prototype, "onDeviceConnected", {
36
+ Object.defineProperty(WebDeviceInputSystem.prototype, "onDeviceConnected", {
36
37
  get: function () {
37
38
  return this._onDeviceConnected;
38
39
  },
@@ -55,26 +56,6 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
55
56
  enumerable: false,
56
57
  configurable: true
57
58
  });
58
- /**
59
- * Configures events to work with an engine's active element
60
- */
61
- WebDeviceInputSystemImpl.prototype.configureEvents = function () {
62
- var inputElement = this._engine.getInputElement();
63
- if (inputElement && this._elementToAttachTo !== inputElement) {
64
- // If the engine's input element has changed, unregister events from previous element
65
- if (this._elementToAttachTo) {
66
- this._removeEvents();
67
- }
68
- this._elementToAttachTo = inputElement;
69
- // Set tab index for the inputElement to the engine's canvasTabIndex, if and only if the element's tab index is -1
70
- this._elementToAttachTo.tabIndex = (this._elementToAttachTo.tabIndex !== -1) ? this._elementToAttachTo.tabIndex : this._engine.canvasTabIndex;
71
- this._handleKeyActions();
72
- this._handlePointerActions();
73
- this._handleGamepadActions();
74
- // Check for devices that are already connected but aren't registered. Currently, only checks for gamepads and mouse
75
- this._checkForConnectedDevices();
76
- }
77
- };
78
59
  // Public functions
79
60
  /**
80
61
  * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.
@@ -83,7 +64,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
83
64
  * @param inputIndex Id of input to be checked
84
65
  * @returns Current value of input
85
66
  */
86
- WebDeviceInputSystemImpl.prototype.pollInput = function (deviceType, deviceSlot, inputIndex) {
67
+ WebDeviceInputSystem.prototype.pollInput = function (deviceType, deviceSlot, inputIndex) {
87
68
  var device = this._inputs[deviceType][deviceSlot];
88
69
  if (!device) {
89
70
  throw "Unable to find device " + DeviceType[deviceType];
@@ -102,13 +83,13 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
102
83
  * @param deviceType Type of device to check for
103
84
  * @returns bool with status of device's existence
104
85
  */
105
- WebDeviceInputSystemImpl.prototype.isDeviceAvailable = function (deviceType) {
86
+ WebDeviceInputSystem.prototype.isDeviceAvailable = function (deviceType) {
106
87
  return (this._inputs[deviceType] !== undefined);
107
88
  };
108
89
  /**
109
90
  * Dispose of all the eventlisteners
110
91
  */
111
- WebDeviceInputSystemImpl.prototype.dispose = function () {
92
+ WebDeviceInputSystem.prototype.dispose = function () {
112
93
  // Observables
113
94
  this.onDeviceConnected = function () { };
114
95
  this.onDeviceDisconnected = function () { };
@@ -120,11 +101,31 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
120
101
  window.removeEventListener("gamepaddisconnected", this._gamepadDisconnectedEvent);
121
102
  }
122
103
  };
104
+ /**
105
+ * Configures events to work with an engine's active element
106
+ */
107
+ WebDeviceInputSystem.prototype._configureEvents = function () {
108
+ var inputElement = this._engine.getInputElement();
109
+ if (inputElement && this._elementToAttachTo !== inputElement) {
110
+ // If the engine's input element has changed, unregister events from previous element
111
+ if (this._elementToAttachTo) {
112
+ this._removeEvents();
113
+ }
114
+ this._elementToAttachTo = inputElement;
115
+ // Set tab index for the inputElement to the engine's canvasTabIndex, if and only if the element's tab index is -1
116
+ this._elementToAttachTo.tabIndex = (this._elementToAttachTo.tabIndex !== -1) ? this._elementToAttachTo.tabIndex : this._engine.canvasTabIndex;
117
+ this._handleKeyActions();
118
+ this._handlePointerActions();
119
+ this._handleGamepadActions();
120
+ // Check for devices that are already connected but aren't registered. Currently, only checks for gamepads and mouse
121
+ this._checkForConnectedDevices();
122
+ }
123
+ };
123
124
  /**
124
125
  * Checks for existing connections to devices and register them, if necessary
125
126
  * Currently handles gamepads and mouse
126
127
  */
127
- WebDeviceInputSystemImpl.prototype._checkForConnectedDevices = function () {
128
+ WebDeviceInputSystem.prototype._checkForConnectedDevices = function () {
128
129
  if (navigator.getGamepads) {
129
130
  var gamepads = navigator.getGamepads();
130
131
  for (var _i = 0, gamepads_1 = gamepads; _i < gamepads_1.length; _i++) {
@@ -146,7 +147,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
146
147
  * Add a gamepad to the DeviceInputSystem
147
148
  * @param gamepad A single DOM Gamepad object
148
149
  */
149
- WebDeviceInputSystemImpl.prototype._addGamePad = function (gamepad) {
150
+ WebDeviceInputSystem.prototype._addGamePad = function (gamepad) {
150
151
  var deviceType = this._getGamepadDeviceType(gamepad.id);
151
152
  var deviceSlot = gamepad.index;
152
153
  this._registerDevice(deviceType, deviceSlot, gamepad.buttons.length + gamepad.axes.length);
@@ -160,9 +161,9 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
160
161
  * @param currentX Current X at point of adding
161
162
  * @param currentY Current Y at point of adding
162
163
  */
163
- WebDeviceInputSystemImpl.prototype._addPointerDevice = function (deviceType, deviceSlot, currentX, currentY) {
164
+ WebDeviceInputSystem.prototype._addPointerDevice = function (deviceType, deviceSlot, currentX, currentY) {
164
165
  this._pointerActive = true;
165
- this._registerDevice(deviceType, deviceSlot, WebDeviceInputSystemImpl.MAX_POINTER_INPUTS);
166
+ this._registerDevice(deviceType, deviceSlot, MAX_POINTER_INPUTS);
166
167
  var pointer = this._inputs[deviceType][deviceSlot]; /* initialize our pointer position immediately after registration */
167
168
  pointer[0] = currentX;
168
169
  pointer[1] = currentY;
@@ -173,7 +174,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
173
174
  * @param deviceSlot "Slot" or index that device is referenced in
174
175
  * @param numberOfInputs Number of input entries to create for given device
175
176
  */
176
- WebDeviceInputSystemImpl.prototype._registerDevice = function (deviceType, deviceSlot, numberOfInputs) {
177
+ WebDeviceInputSystem.prototype._registerDevice = function (deviceType, deviceSlot, numberOfInputs) {
177
178
  if (deviceSlot === undefined) {
178
179
  throw "Unable to register device " + DeviceType[deviceType] + " to undefined slot.";
179
180
  }
@@ -194,7 +195,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
194
195
  * @param deviceType Enum specifiying device type
195
196
  * @param deviceSlot "Slot" or index that device is referenced in
196
197
  */
197
- WebDeviceInputSystemImpl.prototype._unregisterDevice = function (deviceType, deviceSlot) {
198
+ WebDeviceInputSystem.prototype._unregisterDevice = function (deviceType, deviceSlot) {
198
199
  if (this._inputs[deviceType][deviceSlot]) {
199
200
  delete this._inputs[deviceType][deviceSlot];
200
201
  this.onDeviceDisconnected(deviceType, deviceSlot);
@@ -203,12 +204,12 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
203
204
  /**
204
205
  * Handle all actions that come from keyboard interaction
205
206
  */
206
- WebDeviceInputSystemImpl.prototype._handleKeyActions = function () {
207
+ WebDeviceInputSystem.prototype._handleKeyActions = function () {
207
208
  var _this = this;
208
209
  this._keyboardDownEvent = (function (evt) {
209
210
  if (!_this._keyboardActive) {
210
211
  _this._keyboardActive = true;
211
- _this._registerDevice(DeviceType.Keyboard, 0, WebDeviceInputSystemImpl.MAX_KEYCODES);
212
+ _this._registerDevice(DeviceType.Keyboard, 0, MAX_KEYCODES);
212
213
  }
213
214
  var kbKey = _this._inputs[DeviceType.Keyboard][0];
214
215
  if (kbKey) {
@@ -225,7 +226,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
225
226
  this._keyboardUpEvent = (function (evt) {
226
227
  if (!_this._keyboardActive) {
227
228
  _this._keyboardActive = true;
228
- _this._registerDevice(DeviceType.Keyboard, 0, WebDeviceInputSystemImpl.MAX_KEYCODES);
229
+ _this._registerDevice(DeviceType.Keyboard, 0, MAX_KEYCODES);
229
230
  }
230
231
  var kbKey = _this._inputs[DeviceType.Keyboard][0];
231
232
  if (kbKey) {
@@ -264,8 +265,15 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
264
265
  /**
265
266
  * Handle all actions that come from pointer interaction
266
267
  */
267
- WebDeviceInputSystemImpl.prototype._handlePointerActions = function () {
268
+ WebDeviceInputSystem.prototype._handlePointerActions = function () {
268
269
  var _this = this;
270
+ this._maxTouchPoints = (DomManagement.IsNavigatorAvailable() && navigator.maxTouchPoints) || 0;
271
+ if (!this._activeTouchIds) {
272
+ this._activeTouchIds = new Array(this._maxTouchPoints);
273
+ }
274
+ for (var i = 0; i < this._maxTouchPoints; i++) {
275
+ this._activeTouchIds[i] = -1;
276
+ }
269
277
  this._pointerMoveEvent = (function (evt) {
270
278
  var deviceType = _this._getPointerType(evt);
271
279
  var deviceSlot = (deviceType === DeviceType.Mouse) ? 0 : _this._activeTouchIds.indexOf(evt.pointerId);
@@ -330,8 +338,16 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
330
338
  var deviceType = _this._getPointerType(evt);
331
339
  var deviceSlot = (deviceType === DeviceType.Mouse) ? 0 : evt.pointerId;
332
340
  if (deviceType === DeviceType.Touch) {
333
- deviceSlot = _this._rollingTouchId++;
334
- _this._activeTouchIds[deviceSlot] = evt.pointerId;
341
+ var idx = _this._activeTouchIds.indexOf(-1);
342
+ if (idx >= 0) {
343
+ deviceSlot = idx;
344
+ _this._activeTouchIds[idx] = evt.pointerId;
345
+ }
346
+ else {
347
+ // We can't find an open slot to store new pointer so just return (can only support max number of touches)
348
+ Tools.Warn("Max number of touches exceeded. Ignoring touches in excess of " + _this._maxTouchPoints);
349
+ return;
350
+ }
335
351
  }
336
352
  if (!_this._inputs[deviceType]) {
337
353
  _this._inputs[deviceType] = {};
@@ -339,6 +355,9 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
339
355
  if (!_this._inputs[deviceType][deviceSlot]) {
340
356
  _this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);
341
357
  }
358
+ else if (deviceType === DeviceType.Touch) {
359
+ _this.onDeviceConnected(deviceType, deviceSlot);
360
+ }
342
361
  var pointer = _this._inputs[deviceType][deviceSlot];
343
362
  if (pointer) {
344
363
  var previousHorizontal = pointer[PointerInput.Horizontal];
@@ -400,6 +419,14 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
400
419
  var _a, _b, _c, _d, _e;
401
420
  var deviceType = _this._getPointerType(evt);
402
421
  var deviceSlot = (deviceType === DeviceType.Mouse) ? 0 : _this._activeTouchIds.indexOf(evt.pointerId);
422
+ if (deviceType === DeviceType.Touch) {
423
+ if (deviceSlot === -1) {
424
+ return;
425
+ }
426
+ else {
427
+ _this._activeTouchIds[deviceSlot] = -1;
428
+ }
429
+ }
403
430
  var pointer = (_a = _this._inputs[deviceType]) === null || _a === void 0 ? void 0 : _a[deviceSlot];
404
431
  if (pointer && pointer[evt.button + 2] !== 0) {
405
432
  var previousHorizontal = pointer[PointerInput.Horizontal];
@@ -433,11 +460,8 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
433
460
  _this._elementToAttachTo.releasePointerCapture(evt.pointerId);
434
461
  }
435
462
  _this.onInputChanged(deviceEvent);
436
- // We don't want to unregister the mouse because we may miss input data when a mouse is moving after a click
437
- if (deviceType !== DeviceType.Mouse) {
438
- var idToRemove = _this._activeTouchIds.indexOf(evt.pointerId);
439
- delete _this._activeTouchIds[idToRemove];
440
- _this._unregisterDevice(deviceType, deviceSlot);
463
+ if (deviceType === DeviceType.Touch) {
464
+ _this.onDeviceDisconnected(deviceType, deviceSlot);
441
465
  }
442
466
  }
443
467
  });
@@ -497,7 +521,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
497
521
  if ((_d = (_c = _this._elementToAttachTo).hasPointerCapture) === null || _d === void 0 ? void 0 : _d.call(_c, pointerId)) {
498
522
  _this._elementToAttachTo.releasePointerCapture(pointerId);
499
523
  }
500
- if (((_e = pointer[deviceSlot]) === null || _e === void 0 ? void 0 : _e[PointerInput.LeftClick]) === 1) {
524
+ if (pointerId !== -1 && ((_e = pointer[deviceSlot]) === null || _e === void 0 ? void 0 : _e[PointerInput.LeftClick]) === 1) {
501
525
  pointer[deviceSlot][PointerInput.LeftClick] = 0;
502
526
  var evt_3 = DeviceEventFactory.CreateDeviceEvent(DeviceType.Touch, pointerId, PointerInput.LeftClick, 1, _this, _this._elementToAttachTo);
503
527
  var deviceEvent = evt_3;
@@ -507,11 +531,10 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
507
531
  deviceEvent.currentState = pointer[deviceSlot][PointerInput.LeftClick];
508
532
  deviceEvent.previousState = 1;
509
533
  _this.onInputChanged(deviceEvent);
510
- _this._unregisterDevice(DeviceType.Touch, deviceSlot);
534
+ _this._activeTouchIds[deviceSlot] = -1;
535
+ _this.onDeviceDisconnected(DeviceType.Touch, deviceSlot);
511
536
  }
512
537
  }
513
- // Clear all active touches
514
- while (_this._activeTouchIds.pop() !== undefined) { }
515
538
  }
516
539
  });
517
540
  this._pointerWheelEvent = (function (evt) {
@@ -522,7 +545,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
522
545
  }
523
546
  if (!_this._inputs[deviceType][deviceSlot]) {
524
547
  _this._pointerActive = true;
525
- _this._registerDevice(deviceType, deviceSlot, WebDeviceInputSystemImpl.MAX_POINTER_INPUTS);
548
+ _this._registerDevice(deviceType, deviceSlot, MAX_POINTER_INPUTS);
526
549
  }
527
550
  var pointer = _this._inputs[deviceType][deviceSlot];
528
551
  if (pointer) {
@@ -576,7 +599,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
576
599
  /**
577
600
  * Handle all actions that come from gamepad interaction
578
601
  */
579
- WebDeviceInputSystemImpl.prototype._handleGamepadActions = function () {
602
+ WebDeviceInputSystem.prototype._handleGamepadActions = function () {
580
603
  var _this = this;
581
604
  this._gamepadConnectedEvent = (function (evt) {
582
605
  _this._addGamePad(evt.gamepad);
@@ -598,7 +621,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
598
621
  * @param deviceSlot "Slot" or index that device is referenced in
599
622
  * @param inputIndex Id of input to be checked
600
623
  */
601
- WebDeviceInputSystemImpl.prototype._updateDevice = function (deviceType, deviceSlot, inputIndex) {
624
+ WebDeviceInputSystem.prototype._updateDevice = function (deviceType, deviceSlot, inputIndex) {
602
625
  // Gamepads
603
626
  var gp = navigator.getGamepads()[deviceSlot];
604
627
  if (gp && deviceType === this._gamepads[deviceSlot]) {
@@ -616,7 +639,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
616
639
  * @param deviceName Name of Device from DeviceInputSystem
617
640
  * @returns DeviceType enum value
618
641
  */
619
- WebDeviceInputSystemImpl.prototype._getGamepadDeviceType = function (deviceName) {
642
+ WebDeviceInputSystem.prototype._getGamepadDeviceType = function (deviceName) {
620
643
  if (deviceName.indexOf("054c") !== -1 && deviceName.indexOf("0ce6") === -1) { // DualShock 4 Gamepad
621
644
  return DeviceType.DualShock;
622
645
  }
@@ -633,7 +656,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
633
656
  * @param evt PointerEvent to evaluate
634
657
  * @returns DeviceType interpreted from event
635
658
  */
636
- WebDeviceInputSystemImpl.prototype._getPointerType = function (evt) {
659
+ WebDeviceInputSystem.prototype._getPointerType = function (evt) {
637
660
  var deviceType = DeviceType.Mouse;
638
661
  if (evt.pointerType === "touch" || evt.pointerType === "pen" || evt.touches) {
639
662
  deviceType = DeviceType.Touch;
@@ -643,7 +666,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
643
666
  /**
644
667
  * Remove events from active input element
645
668
  */
646
- WebDeviceInputSystemImpl.prototype._removeEvents = function () {
669
+ WebDeviceInputSystem.prototype._removeEvents = function () {
647
670
  // Blur Events
648
671
  this._elementToAttachTo.removeEventListener("blur", this._keyboardBlurEvent);
649
672
  this._elementToAttachTo.removeEventListener("blur", this._pointerBlurEvent);
@@ -663,11 +686,7 @@ var WebDeviceInputSystemImpl = /** @class */ (function () {
663
686
  }
664
687
  }
665
688
  };
666
- /** Max number of keycodes */
667
- WebDeviceInputSystemImpl.MAX_KEYCODES = 255;
668
- /** Max number of pointer inputs */
669
- WebDeviceInputSystemImpl.MAX_POINTER_INPUTS = Object.keys(PointerInput).length / 2;
670
- return WebDeviceInputSystemImpl;
689
+ return WebDeviceInputSystem;
671
690
  }());
672
- export { WebDeviceInputSystemImpl };
691
+ export { WebDeviceInputSystem };
673
692
  //# sourceMappingURL=webDeviceInputSystem.js.map