@babylonjs/core 5.0.0-beta.8 → 5.0.0-beta.9

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 (39) hide show
  1. package/DeviceInput/InputDevices/deviceSourceManager.d.ts +20 -5
  2. package/DeviceInput/InputDevices/deviceSourceManager.js +68 -7
  3. package/DeviceInput/InputDevices/deviceSourceManager.js.map +1 -1
  4. package/DeviceInput/InputDevices/internalDeviceSourceManager.d.ts +15 -10
  5. package/DeviceInput/InputDevices/internalDeviceSourceManager.js +25 -31
  6. package/DeviceInput/InputDevices/internalDeviceSourceManager.js.map +1 -1
  7. package/DeviceInput/InputDevices/webDeviceInputSystem.d.ts +7 -6
  8. package/DeviceInput/InputDevices/webDeviceInputSystem.js +62 -33
  9. package/DeviceInput/InputDevices/webDeviceInputSystem.js.map +1 -1
  10. package/Engines/Extensions/engine.views.d.ts +7 -0
  11. package/Engines/Extensions/engine.views.js +12 -0
  12. package/Engines/Extensions/engine.views.js.map +1 -1
  13. package/Engines/nativeEngine.js +2 -1
  14. package/Engines/nativeEngine.js.map +1 -1
  15. package/Engines/thinEngine.js +2 -2
  16. package/Engines/thinEngine.js.map +1 -1
  17. package/Inputs/scene.inputManager.d.ts +0 -1
  18. package/Inputs/scene.inputManager.js +5 -5
  19. package/Inputs/scene.inputManager.js.map +1 -1
  20. package/Loading/sceneLoader.js +4 -3
  21. package/Loading/sceneLoader.js.map +1 -1
  22. package/Meshes/mesh.vertexData.d.ts +1 -1
  23. package/Meshes/mesh.vertexData.js +2 -1
  24. package/Meshes/mesh.vertexData.js.map +1 -1
  25. package/Misc/error.d.ts +51 -0
  26. package/Misc/error.js +66 -0
  27. package/Misc/error.js.map +1 -0
  28. package/Misc/fileTools.d.ts +4 -4
  29. package/Misc/fileTools.js +7 -7
  30. package/Misc/fileTools.js.map +1 -1
  31. package/Misc/index.d.ts +1 -0
  32. package/Misc/index.js +1 -0
  33. package/Misc/index.js.map +1 -1
  34. package/Particles/particleSystem.js +7 -1
  35. package/Particles/particleSystem.js.map +1 -1
  36. package/package.json +4 -4
  37. package/Misc/baseError.d.ts +0 -7
  38. package/Misc/baseError.js +0 -18
  39. package/Misc/baseError.js.map +0 -1
@@ -4,10 +4,11 @@ import { Nullable } from '../../types';
4
4
  import { Observable } from '../../Misc/observable';
5
5
  import { IDeviceEvent } from './inputInterfaces';
6
6
  import { DeviceSource } from './deviceSource';
7
+ import { IDisposable } from '../../scene';
7
8
  /**
8
9
  * Class to keep track of devices
9
10
  */
10
- export declare class DeviceSourceManager {
11
+ export declare class DeviceSourceManager implements IDisposable {
11
12
  /**
12
13
  * Observable to be triggered when after a device is connected, any new observers added will be triggered against already connected devices
13
14
  */
@@ -20,22 +21,36 @@ export declare class DeviceSourceManager {
20
21
  * Observable to be triggered when after a device is disconnected
21
22
  */
22
23
  readonly onDeviceDisconnectedObservable: Observable<DeviceSource<DeviceType>>;
23
- private _deviceSourceManager;
24
+ private _engine;
25
+ private _onDisposeObserver;
26
+ private _getDeviceSource;
27
+ private _getDeviceSources;
28
+ private _getDevices;
24
29
  /**
25
30
  * Gets a DeviceSource, given a type and slot
31
+ * @param deviceType Type of Device
32
+ * @param deviceSlot Slot or ID of device
33
+ * @returns DeviceSource
26
34
  */
27
- getDeviceSource: <T extends DeviceType>(deviceType: T, deviceSlot?: number) => Nullable<DeviceSource<T>>;
35
+ getDeviceSource<T extends DeviceType>(deviceType: T, deviceSlot?: number): Nullable<DeviceSource<T>>;
28
36
  /**
29
37
  * Gets an array of DeviceSource objects for a given device type
38
+ * @param deviceType Type of Device
39
+ * @returns All available DeviceSources of a given type
30
40
  */
31
- getDeviceSources: <T extends DeviceType>(deviceType: T) => ReadonlyArray<DeviceSource<T>>;
41
+ getDeviceSources<T extends DeviceType>(deviceType: T): ReadonlyArray<DeviceSource<T>>;
32
42
  /**
33
43
  * Returns a read-only list of all available devices
44
+ * @returns All available DeviceSources
34
45
  */
35
- getDevices: () => ReadonlyArray<DeviceSource<DeviceType>>;
46
+ getDevices(): ReadonlyArray<DeviceSource<DeviceType>>;
36
47
  /**
37
48
  * Default constructor
38
49
  * @param engine Used to get canvas (if applicable)
39
50
  */
40
51
  constructor(engine: Engine);
52
+ /**
53
+ * Dispose of DeviceSourceManager
54
+ */
55
+ dispose(): void;
41
56
  }
@@ -1,3 +1,4 @@
1
+ import { Observable } from '../../Misc/observable.js';
1
2
  import { InternalDeviceSourceManager } from './internalDeviceSourceManager.js';
2
3
  /**
3
4
  * Class to keep track of devices
@@ -8,14 +9,74 @@ var DeviceSourceManager = /** @class */ (function () {
8
9
  * @param engine Used to get canvas (if applicable)
9
10
  */
10
11
  function DeviceSourceManager(engine) {
11
- this._deviceSourceManager = InternalDeviceSourceManager._Create(engine);
12
- this.onDeviceConnectedObservable = this._deviceSourceManager.onDeviceConnectedObservable;
13
- this.onInputChangedObservable = this._deviceSourceManager.onInputChangedObservable;
14
- this.onDeviceDisconnectedObservable = this._deviceSourceManager.onDeviceDisconnectedObservable;
15
- this.getDeviceSource = this._deviceSourceManager.getDeviceSource;
16
- this.getDeviceSources = this._deviceSourceManager.getDeviceSources;
17
- this.getDevices = this._deviceSourceManager.getDevices;
12
+ var _this = this;
13
+ this._engine = engine;
14
+ if (!this._engine._deviceSourceManager) {
15
+ this._engine._deviceSourceManager = new InternalDeviceSourceManager(engine);
16
+ }
17
+ this._engine._deviceSourceManager._refCount++;
18
+ // Observables
19
+ this.onDeviceConnectedObservable = new Observable(function (observer) {
20
+ _this.getDevices().forEach(function (device) {
21
+ _this.onDeviceConnectedObservable.notifyObserver(observer, device);
22
+ });
23
+ });
24
+ this.onInputChangedObservable = new Observable();
25
+ this.onDeviceDisconnectedObservable = new Observable();
26
+ this._engine._deviceSourceManager.registerManager(this);
27
+ this._getDeviceSource = this._engine._deviceSourceManager.getDeviceSource;
28
+ this._getDeviceSources = this._engine._deviceSourceManager.getDeviceSources;
29
+ this._getDevices = this._engine._deviceSourceManager.getDevices;
30
+ this._onDisposeObserver = engine.onDisposeObservable.add(function () {
31
+ _this.dispose();
32
+ });
18
33
  }
34
+ // Public Functions
35
+ /**
36
+ * Gets a DeviceSource, given a type and slot
37
+ * @param deviceType Type of Device
38
+ * @param deviceSlot Slot or ID of device
39
+ * @returns DeviceSource
40
+ */
41
+ DeviceSourceManager.prototype.getDeviceSource = function (deviceType, deviceSlot) {
42
+ return this._getDeviceSource(deviceType, deviceSlot);
43
+ };
44
+ /**
45
+ * Gets an array of DeviceSource objects for a given device type
46
+ * @param deviceType Type of Device
47
+ * @returns All available DeviceSources of a given type
48
+ */
49
+ DeviceSourceManager.prototype.getDeviceSources = function (deviceType) {
50
+ return this._getDeviceSources(deviceType);
51
+ };
52
+ /**
53
+ * Returns a read-only list of all available devices
54
+ * @returns All available DeviceSources
55
+ */
56
+ DeviceSourceManager.prototype.getDevices = function () {
57
+ return this._getDevices();
58
+ };
59
+ /**
60
+ * Dispose of DeviceSourceManager
61
+ */
62
+ DeviceSourceManager.prototype.dispose = function () {
63
+ // Null out observable refs
64
+ this.onDeviceConnectedObservable.clear();
65
+ this.onInputChangedObservable.clear();
66
+ this.onDeviceDisconnectedObservable.clear();
67
+ // Null out function refs
68
+ this._getDeviceSource = function () { return null; };
69
+ this._getDeviceSources = function () { return []; };
70
+ this._getDevices = function () { return []; };
71
+ if (this._engine._deviceSourceManager) {
72
+ this._engine._deviceSourceManager.unregisterManager(this);
73
+ if (--this._engine._deviceSourceManager._refCount < 1) {
74
+ this._engine._deviceSourceManager.dispose();
75
+ delete this._engine._deviceSourceManager;
76
+ }
77
+ }
78
+ this._engine.onDisposeObservable.remove(this._onDisposeObserver);
79
+ };
19
80
  return DeviceSourceManager;
20
81
  }());
21
82
  export { DeviceSourceManager };
@@ -1 +1 @@
1
- {"version":3,"file":"deviceSourceManager.js","sourceRoot":"","sources":["../../../../sourceES6/core/DeviceInput/InputDevices/deviceSourceManager.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;GAEG;AACH;IAkCI;;;OAGG;IACH,6BAAY,MAAc;QACtB,IAAI,CAAC,oBAAoB,GAAG,2BAA2B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAExE,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,oBAAoB,CAAC,2BAA2B,CAAC;QACzF,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,oBAAoB,CAAC,wBAAwB,CAAC;QACnF,IAAI,CAAC,8BAA8B,GAAG,IAAI,CAAC,oBAAoB,CAAC,8BAA8B,CAAC;QAC/F,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC;QACjE,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,CAAC;QACnE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC;IAC3D,CAAC;IACL,0BAAC;AAAD,CAAC,AAhDD,IAgDC","sourcesContent":["import { Engine } from '../../Engines/engine';\nimport { DeviceType } from './deviceEnums';\nimport { Nullable } from '../../types';\nimport { Observable } from '../../Misc/observable';\nimport { IDeviceEvent } from './inputInterfaces';\nimport { DeviceSource } from './deviceSource';\nimport { InternalDeviceSourceManager } from './internalDeviceSourceManager';\n\n/**\n * Class to keep track of devices\n */\nexport class DeviceSourceManager {\n // Public Members\n /**\n * Observable to be triggered when after a device is connected, any new observers added will be triggered against already connected devices\n */\n public readonly onDeviceConnectedObservable: Observable<DeviceSource<DeviceType>>;\n /**\n * Observable to be triggered when a device's input is changed\n */\n public readonly onInputChangedObservable: Observable<IDeviceEvent>;\n /**\n * Observable to be triggered when after a device is disconnected\n */\n public readonly onDeviceDisconnectedObservable: Observable<DeviceSource<DeviceType>>;\n\n // Private Members\n private _deviceSourceManager: InternalDeviceSourceManager;\n\n // Public Functions\n /**\n * Gets a DeviceSource, given a type and slot\n */\n public getDeviceSource: <T extends DeviceType>(deviceType: T, deviceSlot?: number) => Nullable<DeviceSource<T>>;\n\n /**\n * Gets an array of DeviceSource objects for a given device type\n */\n public getDeviceSources: <T extends DeviceType>(deviceType: T) => ReadonlyArray<DeviceSource<T>>;\n\n /**\n * Returns a read-only list of all available devices\n */\n public getDevices: () => ReadonlyArray<DeviceSource<DeviceType>>;\n\n /**\n * Default constructor\n * @param engine Used to get canvas (if applicable)\n */\n constructor(engine: Engine) {\n this._deviceSourceManager = InternalDeviceSourceManager._Create(engine);\n\n this.onDeviceConnectedObservable = this._deviceSourceManager.onDeviceConnectedObservable;\n this.onInputChangedObservable = this._deviceSourceManager.onInputChangedObservable;\n this.onDeviceDisconnectedObservable = this._deviceSourceManager.onDeviceDisconnectedObservable;\n this.getDeviceSource = this._deviceSourceManager.getDeviceSource;\n this.getDeviceSources = this._deviceSourceManager.getDeviceSources;\n this.getDevices = this._deviceSourceManager.getDevices;\n }\n}\n"]}
1
+ {"version":3,"file":"deviceSourceManager.js","sourceRoot":"","sources":["../../../../sourceES6/core/DeviceInput/InputDevices/deviceSourceManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAY,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAI5E;;GAEG;AACH;IAmDI;;;OAGG;IACH,6BAAY,MAAc;QAA1B,iBAyBC;QAxBG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE;YACpC,IAAI,CAAC,OAAO,CAAC,oBAAoB,GAAG,IAAI,2BAA2B,CAAC,MAAM,CAAC,CAAC;SAC/E;QACD,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,EAAE,CAAC;QAE9C,cAAc;QACd,IAAI,CAAC,2BAA2B,GAAG,IAAI,UAAU,CAA2B,UAAC,QAAQ;YACjF,KAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,UAAC,MAAM;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AI,CAAC,8BAA8B,CAAC,KAAK,EAAE,CAAC;QAC5C,yBAAyB;QACzB,IAAI,CAAC,gBAAgB,GAAG,cAAQ,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,iBAAiB,GAAG,cAAQ,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,cAAQ,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE;YACnC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC1D,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,GAAG,CAAC,EAAE;gBACnD,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;gBAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;aAC5C;SACJ;QACD,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACrE,CAAC;IACL,0BAAC;AAAD,CAAC,AAxGD,IAwGC","sourcesContent":["import { Engine } from '../../Engines/engine';\nimport { DeviceType } from './deviceEnums';\nimport { Nullable } from '../../types';\nimport { Observable, Observer } from '../../Misc/observable';\nimport { IDeviceEvent } from './inputInterfaces';\nimport { DeviceSource } from './deviceSource';\nimport { InternalDeviceSourceManager } from './internalDeviceSourceManager';\nimport { IDisposable } from '../../scene';\nimport { ThinEngine } from '../../Engines/thinEngine';\n\n/**\n * Class to keep track of devices\n */\nexport class DeviceSourceManager implements IDisposable {\n // Public Members\n /**\n * Observable to be triggered when after a device is connected, any new observers added will be triggered against already connected devices\n */\n public readonly onDeviceConnectedObservable: Observable<DeviceSource<DeviceType>>;\n /**\n * Observable to be triggered when a device's input is changed\n */\n public readonly onInputChangedObservable: Observable<IDeviceEvent>;\n /**\n * Observable to be triggered when after a device is disconnected\n */\n public readonly onDeviceDisconnectedObservable: Observable<DeviceSource<DeviceType>>;\n\n // Private Members\n private _engine: Engine;\n private _onDisposeObserver: Nullable<Observer<ThinEngine>>;\n\n private _getDeviceSource: <T extends DeviceType>(deviceType: T, deviceSlot?: number) => Nullable<DeviceSource<T>>;\n private _getDeviceSources: <T extends DeviceType>(deviceType: T) => ReadonlyArray<DeviceSource<T>>;\n private _getDevices: () => ReadonlyArray<DeviceSource<DeviceType>>;\n\n // Public Functions\n /**\n * Gets a DeviceSource, given a type and slot\n * @param deviceType Type of Device\n * @param deviceSlot Slot or ID of device\n * @returns DeviceSource\n */\n public getDeviceSource<T extends DeviceType>(deviceType: T, deviceSlot?: number): Nullable<DeviceSource<T>> {\n return this._getDeviceSource(deviceType, deviceSlot);\n }\n\n /**\n * Gets an array of DeviceSource objects for a given device type\n * @param deviceType Type of Device\n * @returns All available DeviceSources of a given type\n */\n public getDeviceSources<T extends DeviceType>(deviceType: T): ReadonlyArray<DeviceSource<T>> {\n return this._getDeviceSources(deviceType);\n }\n\n /**\n * Returns a read-only list of all available devices\n * @returns All available DeviceSources\n */\n public getDevices(): ReadonlyArray<DeviceSource<DeviceType>> {\n return this._getDevices();\n }\n\n /**\n * Default constructor\n * @param engine Used to get canvas (if applicable)\n */\n constructor(engine: Engine) {\n this._engine = engine;\n if (!this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager = new InternalDeviceSourceManager(engine);\n }\n this._engine._deviceSourceManager._refCount++;\n\n // Observables\n this.onDeviceConnectedObservable = new Observable<DeviceSource<DeviceType>>((observer) => {\n this.getDevices().forEach((device) => {\n this.onDeviceConnectedObservable.notifyObserver(observer, device);\n });\n });\n this.onInputChangedObservable = new Observable<IDeviceEvent>();\n this.onDeviceDisconnectedObservable = new Observable<DeviceSource<DeviceType>>();\n\n this._engine._deviceSourceManager.registerManager(this);\n\n this._getDeviceSource = this._engine._deviceSourceManager.getDeviceSource;\n this._getDeviceSources = this._engine._deviceSourceManager.getDeviceSources;\n this._getDevices = this._engine._deviceSourceManager.getDevices;\n\n this._onDisposeObserver = engine.onDisposeObservable.add(() => {\n this.dispose();\n });\n }\n\n /**\n * Dispose of DeviceSourceManager\n */\n public dispose(): void {\n // Null out observable refs\n this.onDeviceConnectedObservable.clear();\n this.onInputChangedObservable.clear();\n this.onDeviceDisconnectedObservable.clear();\n // Null out function refs\n this._getDeviceSource = () => { return null; };\n this._getDeviceSources = () => { return []; };\n this._getDevices = () => { return []; };\n\n if (this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager.unregisterManager(this);\n if (--this._engine._deviceSourceManager._refCount < 1) {\n this._engine._deviceSourceManager.dispose();\n delete this._engine._deviceSourceManager;\n }\n }\n this._engine.onDisposeObservable.remove(this._onDisposeObserver);\n }\n}\n"]}
@@ -8,23 +8,28 @@ import { Engine } from '../../Engines/engine';
8
8
  declare module "../../Engines/engine" {
9
9
  interface Engine {
10
10
  /** @hidden */
11
- _deviceSourceManager: InternalDeviceSourceManager;
11
+ _deviceSourceManager?: InternalDeviceSourceManager;
12
12
  }
13
13
  }
14
14
  /** @hidden */
15
+ export interface IObservableManager {
16
+ onDeviceConnectedObservable: Observable<DeviceSource<DeviceType>>;
17
+ onInputChangedObservable: Observable<IDeviceEvent>;
18
+ onDeviceDisconnectedObservable: Observable<DeviceSource<DeviceType>>;
19
+ }
20
+ /** @hidden */
15
21
  export declare class InternalDeviceSourceManager implements IDisposable {
16
- readonly onDeviceConnectedObservable: Observable<DeviceSource<DeviceType>>;
17
- readonly onInputChangedObservable: Observable<IDeviceEvent>;
18
- readonly onDeviceDisconnectedObservable: Observable<DeviceSource<DeviceType>>;
19
22
  private readonly _devices;
20
23
  private readonly _firstDevice;
21
24
  private readonly _deviceInputSystem;
22
- private _oninputChangedObserver;
23
- static _Create(engine: Engine): InternalDeviceSourceManager;
24
- private constructor();
25
- getDeviceSource: <T extends DeviceType>(deviceType: T, deviceSlot?: number | undefined) => Nullable<DeviceSource<T>>;
26
- getDeviceSources: <T extends DeviceType>(deviceType: T) => readonly DeviceSource<T>[];
27
- getDevices: () => ReadonlyArray<DeviceSource<DeviceType>>;
25
+ private readonly _registeredManagers;
26
+ _refCount: number;
27
+ constructor(engine: Engine);
28
+ readonly getDeviceSource: <T extends DeviceType>(deviceType: T, deviceSlot?: number | undefined) => Nullable<DeviceSource<T>>;
29
+ readonly getDeviceSources: <T extends DeviceType>(deviceType: T) => readonly DeviceSource<T>[];
30
+ readonly getDevices: () => ReadonlyArray<DeviceSource<DeviceType>>;
31
+ readonly registerManager: (manager: IObservableManager) => void;
32
+ readonly unregisterManager: (manager: IObservableManager) => void;
28
33
  dispose(): void;
29
34
  /**
30
35
  * Function to add device name to device list
@@ -1,5 +1,4 @@
1
1
  import { DeviceType } from './deviceEnums.js';
2
- import { Observable } from '../../Misc/observable.js';
3
2
  import { NativeDeviceInputSystem } from './nativeDeviceInputSystem.js';
4
3
  import { WebDeviceInputSystem } from './webDeviceInputSystem.js';
5
4
  import { DeviceSource } from './deviceSource.js';
@@ -7,16 +6,8 @@ import { DeviceSource } from './deviceSource.js';
7
6
  var InternalDeviceSourceManager = /** @class */ (function () {
8
7
  function InternalDeviceSourceManager(engine) {
9
8
  var _this = this;
10
- // Public Members
11
- this.onDeviceConnectedObservable = new Observable(function (observer) {
12
- _this.getDevices().forEach(function (device) {
13
- if (device) {
14
- _this.onDeviceConnectedObservable.notifyObserver(observer, device);
15
- }
16
- });
17
- });
18
- this.onInputChangedObservable = new Observable();
19
- this.onDeviceDisconnectedObservable = new Observable();
9
+ this._registeredManagers = new Array();
10
+ this._refCount = 0;
20
11
  // Public Functions
21
12
  this.getDeviceSource = function (deviceType, deviceSlot) {
22
13
  if (deviceSlot === undefined) {
@@ -28,11 +19,6 @@ var InternalDeviceSourceManager = /** @class */ (function () {
28
19
  if (!_this._devices[deviceType] || _this._devices[deviceType][deviceSlot] === undefined) {
29
20
  return null;
30
21
  }
31
- if (!_this._oninputChangedObserver) {
32
- _this._oninputChangedObserver = _this.onInputChangedObservable.add(function (eventData) {
33
- _this._devices[eventData.deviceType][eventData.deviceSlot].onInputChangedObservable.notifyObservers(eventData);
34
- });
35
- }
36
22
  return _this._devices[deviceType][deviceSlot];
37
23
  };
38
24
  this.getDeviceSources = function (deviceType) {
@@ -45,6 +31,15 @@ var InternalDeviceSourceManager = /** @class */ (function () {
45
31
  });
46
32
  return deviceArray;
47
33
  };
34
+ this.registerManager = function (manager) {
35
+ _this._registeredManagers.push(manager);
36
+ };
37
+ this.unregisterManager = function (manager) {
38
+ var idx = _this._registeredManagers.indexOf(manager);
39
+ if (idx > -1) {
40
+ _this._registeredManagers.splice(idx, 1);
41
+ }
42
+ };
48
43
  var numberOfDeviceTypes = Object.keys(DeviceType).length / 2;
49
44
  this._devices = new Array(numberOfDeviceTypes);
50
45
  this._firstDevice = new Array(numberOfDeviceTypes);
@@ -56,29 +51,28 @@ var InternalDeviceSourceManager = /** @class */ (function () {
56
51
  }
57
52
  this._deviceInputSystem.onDeviceConnected = function (deviceType, deviceSlot) {
58
53
  _this._addDevice(deviceType, deviceSlot);
59
- _this.onDeviceConnectedObservable.notifyObservers(_this.getDeviceSource(deviceType, deviceSlot));
54
+ var deviceSource = _this.getDeviceSource(deviceType, deviceSlot);
55
+ for (var _i = 0, _a = _this._registeredManagers; _i < _a.length; _i++) {
56
+ var manager = _a[_i];
57
+ manager.onDeviceConnectedObservable.notifyObservers(deviceSource);
58
+ }
60
59
  };
61
60
  this._deviceInputSystem.onDeviceDisconnected = function (deviceType, deviceSlot) {
62
- var device = _this.getDeviceSource(deviceType, deviceSlot); // Grab local reference to use before removing from devices
61
+ var deviceSource = _this.getDeviceSource(deviceType, deviceSlot); // Grab local reference to use before removing from devices
63
62
  _this._removeDevice(deviceType, deviceSlot);
64
- _this.onDeviceDisconnectedObservable.notifyObservers(device);
63
+ for (var _i = 0, _a = _this._registeredManagers; _i < _a.length; _i++) {
64
+ var manager = _a[_i];
65
+ manager.onDeviceDisconnectedObservable.notifyObservers(deviceSource);
66
+ }
65
67
  };
66
68
  this._deviceInputSystem.onInputChanged = function (deviceEvent) {
67
- _this.onInputChangedObservable.notifyObservers(deviceEvent);
69
+ for (var _i = 0, _a = _this._registeredManagers; _i < _a.length; _i++) {
70
+ var manager = _a[_i];
71
+ manager.onInputChangedObservable.notifyObservers(deviceEvent);
72
+ }
68
73
  };
69
74
  }
70
- InternalDeviceSourceManager._Create = function (engine) {
71
- if (!engine._deviceSourceManager) {
72
- engine._deviceSourceManager = new InternalDeviceSourceManager(engine);
73
- engine.onDisposeObservable.add(function () {
74
- engine._deviceSourceManager.dispose();
75
- });
76
- }
77
- return engine._deviceSourceManager;
78
- };
79
75
  InternalDeviceSourceManager.prototype.dispose = function () {
80
- this.onDeviceConnectedObservable.clear();
81
- this.onDeviceDisconnectedObservable.clear();
82
76
  this._deviceInputSystem.dispose();
83
77
  };
84
78
  // Private Functions
@@ -1 +1 @@
1
- {"version":3,"file":"internalDeviceSourceManager.js","sourceRoot":"","sources":["../../../../sourceES6/core/DeviceInput/InputDevices/internalDeviceSourceManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAY,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAa9C,cAAc;AACd;IAgCI,qCAAoB,MAAc;QAAlC,iBA0BC;QAzDD,iBAAiB;QACD,gCAA2B,GAAG,IAAI,UAAU,CAA2B,UAAC,QAAQ;YAC5F,KAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,UAAC,MAAM;gBAC7B,IAAI,MAAM,EAAE;oBACR,KAAI,CAAC,2BAA2B,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CA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eviceType } from './deviceEnums';\r\nimport { Nullable } from '../../types';\r\nimport { Observable, Observer } from '../../Misc/observable';\r\nimport { IDeviceEvent, IDeviceInputSystem } from './inputInterfaces';\r\nimport { NativeDeviceInputSystem } from './nativeDeviceInputSystem';\r\nimport { WebDeviceInputSystem } from './webDeviceInputSystem';\r\nimport { DeviceSource } from './deviceSource';\r\nimport { INative } from '../../Engines/Native/nativeInterfaces';\r\nimport { Engine } from '../../Engines/engine';\r\n\r\ndeclare const _native: INative;\r\n\r\ndeclare module \"../../Engines/engine\" {\r\n interface Engine {\r\n /** @hidden */\r\n _deviceSourceManager: InternalDeviceSourceManager;\r\n }\r\n}\r\n\r\n/** @hidden */\r\nexport class InternalDeviceSourceManager implements IDisposable {\r\n // Public Members\r\n public readonly onDeviceConnectedObservable = new Observable<DeviceSource<DeviceType>>((observer) => {\r\n this.getDevices().forEach((device) => {\r\n if (device) {\r\n this.onDeviceConnectedObservable.notifyObserver(observer, device);\r\n }\r\n });\r\n });\r\n\r\n public readonly onInputChangedObservable = new Observable<IDeviceEvent>();\r\n\r\n public readonly onDeviceDisconnectedObservable = new Observable<DeviceSource<DeviceType>>();\r\n\r\n // Private Members\r\n private readonly _devices: Array<Array<DeviceSource<DeviceType>>>;\r\n private readonly _firstDevice: Array<number>;\r\n private readonly _deviceInputSystem: IDeviceInputSystem;\r\n\r\n private _oninputChangedObserver: Nullable<Observer<IDeviceEvent>>;\r\n\r\n public static _Create(engine: Engine): InternalDeviceSourceManager {\r\n if (!engine._deviceSourceManager) {\r\n engine._deviceSourceManager = new InternalDeviceSourceManager(engine);\r\n\r\n engine.onDisposeObservable.add(() => {\r\n engine._deviceSourceManager.dispose();\r\n });\r\n }\r\n return engine._deviceSourceManager;\r\n }\r\n\r\n private constructor(engine: Engine) {\r\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\r\n this._devices = new Array<Array<DeviceSource<DeviceType>>>(numberOfDeviceTypes);\r\n this._firstDevice = new Array<number>(numberOfDeviceTypes);\r\n\r\n if (typeof _native !== 'undefined') {\r\n this._deviceInputSystem = (_native.DeviceInputSystem) ? new NativeDeviceInputSystem(new _native.DeviceInputSystem()) : new NativeDeviceInputSystem();\r\n }\r\n else {\r\n this._deviceInputSystem = new WebDeviceInputSystem(engine);\r\n }\r\n\r\n this._deviceInputSystem.onDeviceConnected = (deviceType, deviceSlot) => {\r\n this._addDevice(deviceType, deviceSlot);\r\n this.onDeviceConnectedObservable.notifyObservers(this.getDeviceSource(deviceType, deviceSlot)!);\r\n };\r\n\r\n this._deviceInputSystem.onDeviceDisconnected = (deviceType, deviceSlot) => {\r\n const device = this.getDeviceSource(deviceType, deviceSlot)!; // Grab local reference to use before removing from devices\r\n this._removeDevice(deviceType, deviceSlot);\r\n this.onDeviceDisconnectedObservable.notifyObservers(device);\r\n };\r\n\r\n this._deviceInputSystem.onInputChanged = (deviceEvent) => {\r\n this.onInputChangedObservable.notifyObservers(deviceEvent);\r\n };\r\n }\r\n\r\n // Public Functions\r\n public getDeviceSource = <T extends DeviceType>(deviceType: T, deviceSlot?: number): Nullable<DeviceSource<T>> => {\r\n if (deviceSlot === undefined) {\r\n if (this._firstDevice[deviceType] === undefined) {\r\n return null;\r\n }\r\n\r\n deviceSlot = this._firstDevice[deviceType];\r\n }\r\n\r\n if (!this._devices[deviceType] || this._devices[deviceType][deviceSlot] === undefined) {\r\n return null;\r\n }\r\n\r\n if (!this._oninputChangedObserver) {\r\n this._oninputChangedObserver = this.onInputChangedObservable.add((eventData) => {\r\n this._devices[eventData.deviceType][eventData.deviceSlot].onInputChangedObservable.notifyObservers(eventData);\r\n });\r\n }\r\n\r\n return this._devices[deviceType][deviceSlot];\r\n }\r\n\r\n public getDeviceSources = <T extends DeviceType>(deviceType: T): ReadonlyArray<DeviceSource<T>> => {\r\n return this._devices[deviceType].filter((source) => { return !!source; });\r\n }\r\n\r\n public getDevices = (): ReadonlyArray<DeviceSource<DeviceType>> => {\r\n const deviceArray = new Array<DeviceSource<DeviceType>>();\r\n this._devices.forEach((deviceSet) => {\r\n deviceArray.push.apply(deviceArray, deviceSet);\r\n });\r\n\r\n return deviceArray;\r\n }\r\n\r\n public dispose(): void {\r\n this.onDeviceConnectedObservable.clear();\r\n this.onDeviceDisconnectedObservable.clear();\r\n this._deviceInputSystem.dispose();\r\n }\r\n\r\n // Private Functions\r\n /**\r\n * Function to add device name to device list\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n */\r\n private _addDevice(deviceType: DeviceType, deviceSlot: number): void {\r\n if (!this._devices[deviceType]) {\r\n this._devices[deviceType] = new Array<DeviceSource<DeviceType>>();\r\n }\r\n\r\n if (!this._devices[deviceType][deviceSlot]) {\r\n this._devices[deviceType][deviceSlot] = new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot);\r\n this._updateFirstDevices(deviceType);\r\n }\r\n }\r\n\r\n /**\r\n * Function to remove device name to device list\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n */\r\n private _removeDevice(deviceType: DeviceType, deviceSlot: number): void {\r\n if (this._devices[deviceType]?.[deviceSlot]) {\r\n delete this._devices[deviceType][deviceSlot];\r\n }\r\n // Even if we don't delete a device, we should still check for the first device as things may have gotten out of sync.\r\n this._updateFirstDevices(deviceType);\r\n }\r\n\r\n /**\r\n * Updates array storing first connected device of each type\r\n * @param type Type of Device\r\n */\r\n private _updateFirstDevices(type: DeviceType): void {\r\n switch (type) {\r\n case DeviceType.Keyboard:\r\n case DeviceType.Mouse:\r\n this._firstDevice[type] = 0;\r\n break;\r\n case DeviceType.Touch:\r\n case DeviceType.DualSense:\r\n case DeviceType.DualShock:\r\n case DeviceType.Xbox:\r\n case DeviceType.Switch:\r\n case DeviceType.Generic:\r\n delete this._firstDevice[type];\r\n const devices = this._devices[type];\r\n if (devices) {\r\n for (let i = 0; i < devices.length; i++) {\r\n if (devices[i]) {\r\n this._firstDevice[type] = i;\r\n break;\r\n }\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"internalDeviceSourceManager.js","sourceRoot":"","sources":["../../../../sourceES6/core/DeviceInput/InputDevices/internalDeviceSourceManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAoB9C,cAAc;AACd;IAUI,qCAAmB,MAAc;QAAjC,iBAiCC;QArCgB,wBAAmB,GAAG,IAAI,KAAK,EAAsB,CAAC;QAEhE,cAAS,GAAG,CAAC,CAAC;QAqCrB,mBAAmB;QACH,oBAAe,GAAG,UAAuB,UAAa,EAAE,UAAmB;YACvF,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC1B,IAAI,KAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;oBAC7C,OAAO,IAAI,CAAC;iBACf;gBAED,UAAU,GAAG,KAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;aAC9C;YAED,IAAI,CAAC,KAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,KAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;gBACnF,OAAO,IAAI,CAAC;aACf;YAED,OAAO,KAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,CAAC;QACjD,CAAC,CAAA;QAEe,qBAAgB,GAAG,UAAuB,UAAa;YACnE,OAAO,KAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,UAAC,MAAM,IAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9E,CAAC,CAAA;QAEe,eAAU,GAAG;YACzB,IAAM,WAAW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CAAC;gBACpC,IAAI,OAAO,EAAE;oBACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBACrC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;4BACZ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;4BAC5B,MAAM;yBACT;qBACJ;iBACJ;gBACD,MAAM;SACb;IACL,CAAC;IACL,kCAAC;AAAD,CAAC,AAtJD,IAsJC","sourcesContent":["import { IDisposable } from '../../scene';\r\nimport { DeviceType } from './deviceEnums';\r\nimport { Nullable } from '../../types';\r\nimport { Observable } from '../../Misc/observable';\r\nimport { IDeviceEvent, IDeviceInputSystem } from './inputInterfaces';\r\nimport { NativeDeviceInputSystem } from './nativeDeviceInputSystem';\r\nimport { WebDeviceInputSystem } from './webDeviceInputSystem';\r\nimport { DeviceSource } from './deviceSource';\r\nimport { INative } from '../../Engines/Native/nativeInterfaces';\r\nimport { Engine } from '../../Engines/engine';\r\n\r\ndeclare const _native: INative;\r\n\r\ndeclare module \"../../Engines/engine\" {\r\n interface Engine {\r\n /** @hidden */\r\n _deviceSourceManager?: InternalDeviceSourceManager;\r\n }\r\n}\r\n\r\n/** @hidden */\r\nexport interface IObservableManager {\r\n onDeviceConnectedObservable: Observable<DeviceSource<DeviceType>>;\r\n onInputChangedObservable: Observable<IDeviceEvent>;\r\n onDeviceDisconnectedObservable: Observable<DeviceSource<DeviceType>>;\r\n}\r\n\r\n/** @hidden */\r\nexport class InternalDeviceSourceManager implements IDisposable {\r\n // Private Members\r\n private readonly _devices: Array<Array<DeviceSource<DeviceType>>>;\r\n private readonly _firstDevice: Array<number>;\r\n private readonly _deviceInputSystem: IDeviceInputSystem;\r\n\r\n private readonly _registeredManagers = new Array<IObservableManager>();\r\n\r\n public _refCount = 0;\r\n\r\n public constructor(engine: Engine) {\r\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\r\n this._devices = new Array<Array<DeviceSource<DeviceType>>>(numberOfDeviceTypes);\r\n this._firstDevice = new Array<number>(numberOfDeviceTypes);\r\n\r\n if (typeof _native !== 'undefined') {\r\n this._deviceInputSystem = (_native.DeviceInputSystem) ? new NativeDeviceInputSystem(new _native.DeviceInputSystem()) : new NativeDeviceInputSystem();\r\n }\r\n else {\r\n this._deviceInputSystem = new WebDeviceInputSystem(engine);\r\n }\r\n\r\n this._deviceInputSystem.onDeviceConnected = (deviceType, deviceSlot) => {\r\n this._addDevice(deviceType, deviceSlot);\r\n const deviceSource = this.getDeviceSource(deviceType, deviceSlot)!;\r\n for (const manager of this._registeredManagers) {\r\n manager.onDeviceConnectedObservable.notifyObservers(deviceSource);\r\n }\r\n };\r\n\r\n this._deviceInputSystem.onDeviceDisconnected = (deviceType, deviceSlot) => {\r\n const deviceSource = this.getDeviceSource(deviceType, deviceSlot)!; // Grab local reference to use before removing from devices\r\n this._removeDevice(deviceType, deviceSlot);\r\n for (const manager of this._registeredManagers) {\r\n manager.onDeviceDisconnectedObservable.notifyObservers(deviceSource);\r\n }\r\n };\r\n\r\n this._deviceInputSystem.onInputChanged = (deviceEvent) => {\r\n for (const manager of this._registeredManagers) {\r\n manager.onInputChangedObservable.notifyObservers(deviceEvent);\r\n }\r\n };\r\n }\r\n\r\n // Public Functions\r\n public readonly getDeviceSource = <T extends DeviceType>(deviceType: T, deviceSlot?: number): Nullable<DeviceSource<T>> => {\r\n if (deviceSlot === undefined) {\r\n if (this._firstDevice[deviceType] === undefined) {\r\n return null;\r\n }\r\n\r\n deviceSlot = this._firstDevice[deviceType];\r\n }\r\n\r\n if (!this._devices[deviceType] || this._devices[deviceType][deviceSlot] === undefined) {\r\n return null;\r\n }\r\n\r\n return this._devices[deviceType][deviceSlot];\r\n }\r\n\r\n public readonly getDeviceSources = <T extends DeviceType>(deviceType: T): ReadonlyArray<DeviceSource<T>> => {\r\n return this._devices[deviceType].filter((source) => { return !!source; });\r\n }\r\n\r\n public readonly getDevices = (): ReadonlyArray<DeviceSource<DeviceType>> => {\r\n const deviceArray = new Array<DeviceSource<DeviceType>>();\r\n this._devices.forEach((deviceSet) => {\r\n deviceArray.push.apply(deviceArray, deviceSet);\r\n });\r\n\r\n return deviceArray;\r\n }\r\n\r\n public readonly registerManager = (manager: IObservableManager): void => {\r\n this._registeredManagers.push(manager);\r\n }\r\n\r\n public readonly unregisterManager = (manager: IObservableManager): void => {\r\n const idx = this._registeredManagers.indexOf(manager);\r\n\r\n if (idx > -1) {\r\n this._registeredManagers.splice(idx, 1);\r\n }\r\n }\r\n\r\n public dispose(): void {\r\n this._deviceInputSystem.dispose();\r\n }\r\n\r\n // Private Functions\r\n /**\r\n * Function to add device name to device list\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n */\r\n private _addDevice(deviceType: DeviceType, deviceSlot: number): void {\r\n if (!this._devices[deviceType]) {\r\n this._devices[deviceType] = new Array<DeviceSource<DeviceType>>();\r\n }\r\n\r\n if (!this._devices[deviceType][deviceSlot]) {\r\n this._devices[deviceType][deviceSlot] = new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot);\r\n this._updateFirstDevices(deviceType);\r\n }\r\n }\r\n\r\n /**\r\n * Function to remove device name to device list\r\n * @param deviceType Enum specifying device type\r\n * @param deviceSlot \"Slot\" or index that device is referenced in\r\n */\r\n private _removeDevice(deviceType: DeviceType, deviceSlot: number): void {\r\n if (this._devices[deviceType]?.[deviceSlot]) {\r\n delete this._devices[deviceType][deviceSlot];\r\n }\r\n // Even if we don't delete a device, we should still check for the first device as things may have gotten out of sync.\r\n this._updateFirstDevices(deviceType);\r\n }\r\n\r\n /**\r\n * Updates array storing first connected device of each type\r\n * @param type Type of Device\r\n */\r\n private _updateFirstDevices(type: DeviceType): void {\r\n switch (type) {\r\n case DeviceType.Keyboard:\r\n case DeviceType.Mouse:\r\n this._firstDevice[type] = 0;\r\n break;\r\n case DeviceType.Touch:\r\n case DeviceType.DualSense:\r\n case DeviceType.DualShock:\r\n case DeviceType.Xbox:\r\n case DeviceType.Switch:\r\n case DeviceType.Generic:\r\n delete this._firstDevice[type];\r\n const devices = this._devices[type];\r\n if (devices) {\r\n for (let i = 0; i < devices.length; i++) {\r\n if (devices[i]) {\r\n this._firstDevice[type] = i;\r\n break;\r\n }\r\n }\r\n }\r\n break;\r\n }\r\n }\r\n}\r\n"]}
@@ -25,6 +25,7 @@ export declare class WebDeviceInputSystem implements IDeviceInputSystem {
25
25
  private _pointerWheelEvent;
26
26
  private _pointerBlurEvent;
27
27
  private _wheelEventName;
28
+ private _eventsAttached;
28
29
  private _mouseId;
29
30
  private readonly _isUsingFirefox;
30
31
  private _activeTouchIds;
@@ -53,9 +54,13 @@ export declare class WebDeviceInputSystem implements IDeviceInputSystem {
53
54
  */
54
55
  dispose(): void;
55
56
  /**
56
- * Configures events to work with an engine's active element
57
+ * Enable listening for user input events
57
58
  */
58
- private _configureEvents;
59
+ private _enableEvents;
60
+ /**
61
+ * Disable listening for user input events
62
+ */
63
+ private _disableEvents;
59
64
  /**
60
65
  * Checks for existing connections to devices and register them, if necessary
61
66
  * Currently handles gamepads and mouse
@@ -118,8 +123,4 @@ export declare class WebDeviceInputSystem implements IDeviceInputSystem {
118
123
  * @returns DeviceType interpreted from event
119
124
  */
120
125
  private _getPointerType;
121
- /**
122
- * Remove events from active input element
123
- */
124
- private _removeEvents;
125
126
  }
@@ -7,6 +7,7 @@ var MAX_POINTER_INPUTS = Object.keys(PointerInput).length / 2;
7
7
  /** @hidden */
8
8
  var WebDeviceInputSystem = /** @class */ (function () {
9
9
  function WebDeviceInputSystem(engine) {
10
+ var _this = this;
10
11
  // Private Members
11
12
  this._inputs = [];
12
13
  this._keyboardActive = false;
@@ -20,6 +21,7 @@ var WebDeviceInputSystem = /** @class */ (function () {
20
21
  this._pointerUpEvent = function (evt) { };
21
22
  this._pointerWheelEvent = function (evt) { };
22
23
  this._pointerBlurEvent = function (evt) { };
24
+ this._eventsAttached = false;
23
25
  this._mouseId = -1;
24
26
  this._isUsingFirefox = DomManagement.IsNavigatorAvailable() && navigator.userAgent && navigator.userAgent.indexOf("Firefox") !== -1;
25
27
  this._maxTouchPoints = 0;
@@ -31,7 +33,13 @@ var WebDeviceInputSystem = /** @class */ (function () {
31
33
  this.onDeviceConnected = function (deviceType, deviceSlot) { };
32
34
  this.onDeviceDisconnected = function (deviceType, deviceSlot) { };
33
35
  this.onInputChanged = function (deviceEvent) { };
34
- this._configureEvents();
36
+ this._enableEvents();
37
+ // Set callback to enable event handler switching when inputElement changes
38
+ if (!this._engine._onEngineViewChanged) {
39
+ this._engine._onEngineViewChanged = function () {
40
+ _this._enableEvents();
41
+ };
42
+ }
35
43
  }
36
44
  Object.defineProperty(WebDeviceInputSystem.prototype, "onDeviceConnected", {
37
45
  get: function () {
@@ -90,26 +98,39 @@ var WebDeviceInputSystem = /** @class */ (function () {
90
98
  * Dispose of all the eventlisteners
91
99
  */
92
100
  WebDeviceInputSystem.prototype.dispose = function () {
93
- // Observables
101
+ // Callbacks
94
102
  this.onDeviceConnected = function () { };
95
103
  this.onDeviceDisconnected = function () { };
96
104
  this.onInputChanged = function () { };
105
+ delete this._engine._onEngineViewChanged;
97
106
  if (this._elementToAttachTo) {
98
- this._removeEvents();
99
- // Gamepad Events
100
- window.removeEventListener("gamepadconnected", this._gamepadConnectedEvent);
101
- window.removeEventListener("gamepaddisconnected", this._gamepadDisconnectedEvent);
107
+ this._disableEvents();
102
108
  }
103
109
  };
104
110
  /**
105
- * Configures events to work with an engine's active element
111
+ * Enable listening for user input events
106
112
  */
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
+ WebDeviceInputSystem.prototype._enableEvents = function () {
114
+ var inputElement = this === null || this === void 0 ? void 0 : this._engine.getInputElement();
115
+ if (inputElement && (!this._eventsAttached || this._elementToAttachTo !== inputElement)) {
116
+ // Remove events before adding to avoid double events or simultaneous events on multiple canvases
117
+ this._disableEvents();
118
+ // If the inputs array has already been created, zero it out to before setting up events
119
+ if (this._inputs) {
120
+ for (var _i = 0, _a = this._inputs; _i < _a.length; _i++) {
121
+ var inputs = _a[_i];
122
+ if (inputs) {
123
+ for (var deviceSlotKey in inputs) {
124
+ var deviceSlot = +deviceSlotKey;
125
+ var device = inputs[deviceSlot];
126
+ if (device) {
127
+ for (var inputIndex = 0; inputIndex < device.length; inputIndex++) {
128
+ device[inputIndex] = 0;
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
113
134
  }
114
135
  this._elementToAttachTo = inputElement;
115
136
  // Set tab index for the inputElement to the engine's canvasTabIndex, if and only if the element's tab index is -1
@@ -117,10 +138,36 @@ var WebDeviceInputSystem = /** @class */ (function () {
117
138
  this._handleKeyActions();
118
139
  this._handlePointerActions();
119
140
  this._handleGamepadActions();
141
+ this._eventsAttached = true;
120
142
  // Check for devices that are already connected but aren't registered. Currently, only checks for gamepads and mouse
121
143
  this._checkForConnectedDevices();
122
144
  }
123
145
  };
146
+ /**
147
+ * Disable listening for user input events
148
+ */
149
+ WebDeviceInputSystem.prototype._disableEvents = function () {
150
+ if (this._elementToAttachTo) {
151
+ // Blur Events
152
+ this._elementToAttachTo.removeEventListener("blur", this._keyboardBlurEvent);
153
+ this._elementToAttachTo.removeEventListener("blur", this._pointerBlurEvent);
154
+ // Keyboard Events
155
+ this._elementToAttachTo.removeEventListener("keydown", this._keyboardDownEvent);
156
+ this._elementToAttachTo.removeEventListener("keyup", this._keyboardUpEvent);
157
+ // Pointer Events
158
+ this._elementToAttachTo.removeEventListener(this._eventPrefix + "move", this._pointerMoveEvent);
159
+ this._elementToAttachTo.removeEventListener(this._eventPrefix + "down", this._pointerDownEvent);
160
+ this._elementToAttachTo.removeEventListener(this._eventPrefix + "up", this._pointerUpEvent);
161
+ this._elementToAttachTo.removeEventListener(this._wheelEventName, this._pointerWheelEvent);
162
+ // Gamepad Events
163
+ window.removeEventListener("gamepadconnected", this._gamepadConnectedEvent);
164
+ window.removeEventListener("gamepaddisconnected", this._gamepadDisconnectedEvent);
165
+ }
166
+ if (this._pointerInputClearObserver) {
167
+ this._engine.onEndFrameObservable.remove(this._pointerInputClearObserver);
168
+ }
169
+ this._eventsAttached = false;
170
+ };
124
171
  /**
125
172
  * Checks for existing connections to devices and register them, if necessary
126
173
  * Currently handles gamepads and mouse
@@ -269,7 +316,8 @@ var WebDeviceInputSystem = /** @class */ (function () {
269
316
  */
270
317
  WebDeviceInputSystem.prototype._handlePointerActions = function () {
271
318
  var _this = this;
272
- this._maxTouchPoints = (DomManagement.IsNavigatorAvailable() && navigator.maxTouchPoints) || 0;
319
+ // If maxTouchPoints is defined, use that value. Otherwise, allow for a minimum for supported gestures like pinch
320
+ this._maxTouchPoints = (DomManagement.IsNavigatorAvailable() && navigator.maxTouchPoints) || 2;
273
321
  if (!this._activeTouchIds) {
274
322
  this._activeTouchIds = new Array(this._maxTouchPoints);
275
323
  }
@@ -623,25 +671,6 @@ var WebDeviceInputSystem = /** @class */ (function () {
623
671
  }
624
672
  return deviceType;
625
673
  };
626
- /**
627
- * Remove events from active input element
628
- */
629
- WebDeviceInputSystem.prototype._removeEvents = function () {
630
- // Blur Events
631
- this._elementToAttachTo.removeEventListener("blur", this._keyboardBlurEvent);
632
- this._elementToAttachTo.removeEventListener("blur", this._pointerBlurEvent);
633
- // Keyboard Events
634
- this._elementToAttachTo.removeEventListener("keydown", this._keyboardDownEvent);
635
- this._elementToAttachTo.removeEventListener("keyup", this._keyboardUpEvent);
636
- // Pointer Events
637
- this._elementToAttachTo.removeEventListener(this._eventPrefix + "move", this._pointerMoveEvent);
638
- this._elementToAttachTo.removeEventListener(this._eventPrefix + "down", this._pointerDownEvent);
639
- this._elementToAttachTo.removeEventListener(this._eventPrefix + "up", this._pointerUpEvent);
640
- this._elementToAttachTo.removeEventListener(this._wheelEventName, this._pointerWheelEvent);
641
- if (this._pointerInputClearObserver) {
642
- this._engine.onEndFrameObservable.remove(this._pointerInputClearObserver);
643
- }
644
- };
645
674
  return WebDeviceInputSystem;
646
675
  }());
647
676
  export { WebDeviceInputSystem };