@onerjs/core 8.27.14 → 8.28.1
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.
- package/Behaviors/Meshes/handConstraintBehavior.js.map +1 -1
- package/Buffers/bufferUtils.d.ts +1 -2
- package/Buffers/bufferUtils.js +3 -4
- package/Buffers/bufferUtils.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/Textures/texture.js +9 -2
- package/Materials/Textures/texture.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.js +1 -1
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/geometry.js +1 -1
- package/Meshes/geometry.js.map +1 -1
- package/Particles/gpuParticleSystem.js +2 -1
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/thinParticleSystem.js +4 -3
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +5 -0
- package/Physics/v2/physicsAggregate.js +26 -0
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +6 -1
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Shaders/geometry.fragment.js +3 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/geometry.vertex.js +10 -2
- package/Shaders/geometry.vertex.js.map +1 -1
- package/ShadersWGSL/geometry.fragment.js +3 -1
- package/ShadersWGSL/geometry.fragment.js.map +1 -1
- package/ShadersWGSL/geometry.vertex.js +10 -2
- package/ShadersWGSL/geometry.vertex.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.d.ts +1 -1
- package/XR/features/WebXRBackgroundRemover.d.ts +1 -1
- package/XR/features/WebXRControllerMovement.d.ts +1 -1
- package/XR/features/WebXRControllerPhysics.d.ts +1 -1
- package/XR/features/WebXRControllerPointerSelection.d.ts +1 -1
- package/XR/features/WebXRControllerTeleportation.d.ts +1 -1
- package/XR/features/WebXRDOMOverlay.d.ts +1 -1
- package/XR/features/WebXRDepthSensing.d.ts +1 -1
- package/XR/features/WebXREyeTracking.d.ts +1 -1
- package/XR/features/WebXRFeaturePointSystem.d.ts +1 -1
- package/XR/features/WebXRHandTracking.d.ts +1 -1
- package/XR/features/WebXRHitTest.d.ts +1 -1
- package/XR/features/WebXRHitTestLegacy.d.ts +1 -1
- package/XR/features/WebXRImageTracking.d.ts +1 -1
- package/XR/features/WebXRLayers.d.ts +1 -1
- package/XR/features/WebXRLightEstimation.d.ts +1 -1
- package/XR/features/WebXRMeshDetector.d.ts +1 -1
- package/XR/features/WebXRNearInteraction.d.ts +1 -1
- package/XR/features/WebXRPlaneDetector.d.ts +1 -1
- package/XR/features/WebXRRawCameraAccess.d.ts +1 -1
- package/XR/features/WebXRSpaceWarp.d.ts +1 -1
- package/XR/webXRDefaultExperience.js +1 -1
- package/XR/webXRDefaultExperience.js.map +1 -1
- package/XR/webXRFeaturesManager.d.ts +116 -27
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
import type { WebXRSessionManager } from "./webXRSessionManager.js";
|
|
2
|
-
import type { IDisposable } from "../scene.js";
|
|
3
1
|
import type { Observable } from "../Misc/observable.js";
|
|
2
|
+
import type { IDisposable } from "../scene.js";
|
|
3
|
+
import type { IWebXRAnchorSystemOptions, WebXRAnchorSystem } from "./features/WebXRAnchorSystem.js";
|
|
4
|
+
import type { IWebXRBackgroundRemoverOptions, WebXRBackgroundRemover } from "./features/WebXRBackgroundRemover.js";
|
|
5
|
+
import type { IWebXRControllerMovementOptions, WebXRControllerMovement } from "./features/WebXRControllerMovement.js";
|
|
6
|
+
import type { IWebXRControllerPhysicsOptions, WebXRControllerPhysics } from "./features/WebXRControllerPhysics.js";
|
|
7
|
+
import type { IWebXRControllerPointerSelectionOptions, WebXRControllerPointerSelection } from "./features/WebXRControllerPointerSelection.js";
|
|
8
|
+
import type { IWebXRTeleportationOptions, WebXRMotionControllerTeleportation } from "./features/WebXRControllerTeleportation.js";
|
|
9
|
+
import type { IWebXRDepthSensingOptions, WebXRDepthSensing } from "./features/WebXRDepthSensing.js";
|
|
10
|
+
import type { IWebXRDomOverlayOptions, WebXRDomOverlay } from "./features/WebXRDOMOverlay.js";
|
|
11
|
+
import type { WebXREyeTracking } from "./features/WebXREyeTracking.js";
|
|
12
|
+
import type { WebXRFeaturePointSystem } from "./features/WebXRFeaturePointSystem.js";
|
|
13
|
+
import type { IWebXRHandTrackingOptions, WebXRHandTracking } from "./features/WebXRHandTracking.js";
|
|
14
|
+
import type { IWebXRHitTestOptions, WebXRHitTest } from "./features/WebXRHitTest.js";
|
|
15
|
+
import type { IWebXRImageTrackingOptions, WebXRImageTracking } from "./features/WebXRImageTracking.js";
|
|
16
|
+
import type { IWebXRLayersOptions, WebXRLayers } from "./features/WebXRLayers.js";
|
|
17
|
+
import type { IWebXRLightEstimationOptions, WebXRLightEstimation } from "./features/WebXRLightEstimation.js";
|
|
18
|
+
import type { IWebXRMeshDetectorOptions, WebXRMeshDetector } from "./features/WebXRMeshDetector.js";
|
|
19
|
+
import type { IWebXRNearInteractionOptions, WebXRNearInteraction } from "./features/WebXRNearInteraction.js";
|
|
20
|
+
import type { IWebXRPlaneDetectorOptions, WebXRPlaneDetector } from "./features/WebXRPlaneDetector.js";
|
|
21
|
+
import type { IWebXRRawCameraAccessOptions, WebXRRawCameraAccess } from "./features/WebXRRawCameraAccess.js";
|
|
22
|
+
import type { WebXRSpaceWarp } from "./features/WebXRSpaceWarp.js";
|
|
23
|
+
import type { IWebXRWalkingLocomotionOptions, WebXRWalkingLocomotion } from "./features/WebXRWalkingLocomotion.js";
|
|
24
|
+
import type { WebXRSessionManager } from "./webXRSessionManager.js";
|
|
4
25
|
/**
|
|
5
26
|
* Defining the interface required for a (webxr) feature
|
|
6
27
|
*/
|
|
@@ -67,88 +88,155 @@ export declare class WebXRFeatureName {
|
|
|
67
88
|
/**
|
|
68
89
|
* The name of the anchor system feature
|
|
69
90
|
*/
|
|
70
|
-
static readonly ANCHOR_SYSTEM
|
|
91
|
+
static readonly ANCHOR_SYSTEM: "xr-anchor-system";
|
|
71
92
|
/**
|
|
72
93
|
* The name of the background remover feature
|
|
73
94
|
*/
|
|
74
|
-
static readonly BACKGROUND_REMOVER
|
|
95
|
+
static readonly BACKGROUND_REMOVER: "xr-background-remover";
|
|
75
96
|
/**
|
|
76
97
|
* The name of the hit test feature
|
|
77
98
|
*/
|
|
78
|
-
static readonly HIT_TEST
|
|
99
|
+
static readonly HIT_TEST: "xr-hit-test";
|
|
79
100
|
/**
|
|
80
101
|
* The name of the mesh detection feature
|
|
81
102
|
*/
|
|
82
|
-
static readonly MESH_DETECTION
|
|
103
|
+
static readonly MESH_DETECTION: "xr-mesh-detection";
|
|
83
104
|
/**
|
|
84
105
|
* physics impostors for xr controllers feature
|
|
85
106
|
*/
|
|
86
|
-
static readonly PHYSICS_CONTROLLERS
|
|
107
|
+
static readonly PHYSICS_CONTROLLERS: "xr-physics-controller";
|
|
87
108
|
/**
|
|
88
109
|
* The name of the plane detection feature
|
|
89
110
|
*/
|
|
90
|
-
static readonly PLANE_DETECTION
|
|
111
|
+
static readonly PLANE_DETECTION: "xr-plane-detection";
|
|
91
112
|
/**
|
|
92
113
|
* The name of the pointer selection feature
|
|
93
114
|
*/
|
|
94
|
-
static readonly POINTER_SELECTION
|
|
115
|
+
static readonly POINTER_SELECTION: "xr-controller-pointer-selection";
|
|
95
116
|
/**
|
|
96
117
|
* The name of the teleportation feature
|
|
97
118
|
*/
|
|
98
|
-
static readonly TELEPORTATION
|
|
119
|
+
static readonly TELEPORTATION: "xr-controller-teleportation";
|
|
99
120
|
/**
|
|
100
121
|
* The name of the feature points feature.
|
|
101
122
|
*/
|
|
102
|
-
static readonly FEATURE_POINTS
|
|
123
|
+
static readonly FEATURE_POINTS: "xr-feature-points";
|
|
103
124
|
/**
|
|
104
125
|
* The name of the hand tracking feature.
|
|
105
126
|
*/
|
|
106
|
-
static readonly HAND_TRACKING
|
|
127
|
+
static readonly HAND_TRACKING: "xr-hand-tracking";
|
|
107
128
|
/**
|
|
108
129
|
* The name of the image tracking feature
|
|
109
130
|
*/
|
|
110
|
-
static readonly IMAGE_TRACKING
|
|
131
|
+
static readonly IMAGE_TRACKING: "xr-image-tracking";
|
|
111
132
|
/**
|
|
112
133
|
* The name of the near interaction feature
|
|
113
134
|
*/
|
|
114
|
-
static readonly NEAR_INTERACTION
|
|
135
|
+
static readonly NEAR_INTERACTION: "xr-near-interaction";
|
|
115
136
|
/**
|
|
116
137
|
* The name of the DOM overlay feature
|
|
117
138
|
*/
|
|
118
|
-
static readonly DOM_OVERLAY
|
|
139
|
+
static readonly DOM_OVERLAY: "xr-dom-overlay";
|
|
119
140
|
/**
|
|
120
141
|
* The name of the movement feature
|
|
121
142
|
*/
|
|
122
|
-
static readonly MOVEMENT
|
|
143
|
+
static readonly MOVEMENT: "xr-controller-movement";
|
|
123
144
|
/**
|
|
124
145
|
* The name of the light estimation feature
|
|
125
146
|
*/
|
|
126
|
-
static readonly LIGHT_ESTIMATION
|
|
147
|
+
static readonly LIGHT_ESTIMATION: "xr-light-estimation";
|
|
127
148
|
/**
|
|
128
149
|
* The name of the eye tracking feature
|
|
129
150
|
*/
|
|
130
|
-
static readonly EYE_TRACKING
|
|
151
|
+
static readonly EYE_TRACKING: "xr-eye-tracking";
|
|
131
152
|
/**
|
|
132
153
|
* The name of the walking locomotion feature
|
|
133
154
|
*/
|
|
134
|
-
static readonly WALKING_LOCOMOTION
|
|
155
|
+
static readonly WALKING_LOCOMOTION: "xr-walking-locomotion";
|
|
135
156
|
/**
|
|
136
157
|
* The name of the composition layers feature
|
|
137
158
|
*/
|
|
138
|
-
static readonly LAYERS
|
|
159
|
+
static readonly LAYERS: "xr-layers";
|
|
139
160
|
/**
|
|
140
161
|
* The name of the depth sensing feature
|
|
141
162
|
*/
|
|
142
|
-
static readonly DEPTH_SENSING
|
|
163
|
+
static readonly DEPTH_SENSING: "xr-depth-sensing";
|
|
143
164
|
/**
|
|
144
165
|
* The name of the WebXR Space Warp feature
|
|
145
166
|
*/
|
|
146
|
-
static readonly SPACE_WARP
|
|
167
|
+
static readonly SPACE_WARP: "xr-space-warp";
|
|
147
168
|
/**
|
|
148
169
|
* The name of the WebXR Raw Camera Access feature
|
|
149
170
|
*/
|
|
150
|
-
static readonly RAW_CAMERA_ACCESS
|
|
171
|
+
static readonly RAW_CAMERA_ACCESS: "xr-raw-camera-access";
|
|
172
|
+
}
|
|
173
|
+
export type WebXRFeatureNameType = (typeof WebXRFeatureName)[Exclude<keyof typeof WebXRFeatureName, "prototype">];
|
|
174
|
+
export interface IWebXRFeatureNameTypeMap {
|
|
175
|
+
[WebXRFeatureName.ANCHOR_SYSTEM]: WebXRAnchorSystem;
|
|
176
|
+
[WebXRFeatureName.BACKGROUND_REMOVER]: WebXRBackgroundRemover;
|
|
177
|
+
[WebXRFeatureName.DEPTH_SENSING]: WebXRDepthSensing;
|
|
178
|
+
[WebXRFeatureName.DOM_OVERLAY]: WebXRDomOverlay;
|
|
179
|
+
[WebXRFeatureName.EYE_TRACKING]: WebXREyeTracking;
|
|
180
|
+
[WebXRFeatureName.FEATURE_POINTS]: WebXRFeaturePointSystem;
|
|
181
|
+
[WebXRFeatureName.HAND_TRACKING]: WebXRHandTracking;
|
|
182
|
+
[WebXRFeatureName.HIT_TEST]: WebXRHitTest;
|
|
183
|
+
[WebXRFeatureName.IMAGE_TRACKING]: WebXRImageTracking;
|
|
184
|
+
[WebXRFeatureName.LAYERS]: WebXRLayers;
|
|
185
|
+
[WebXRFeatureName.LIGHT_ESTIMATION]: WebXRLightEstimation;
|
|
186
|
+
[WebXRFeatureName.MESH_DETECTION]: WebXRMeshDetector;
|
|
187
|
+
[WebXRFeatureName.MOVEMENT]: WebXRControllerMovement;
|
|
188
|
+
[WebXRFeatureName.NEAR_INTERACTION]: WebXRNearInteraction;
|
|
189
|
+
[WebXRFeatureName.PHYSICS_CONTROLLERS]: WebXRControllerPhysics;
|
|
190
|
+
[WebXRFeatureName.PLANE_DETECTION]: WebXRPlaneDetector;
|
|
191
|
+
[WebXRFeatureName.POINTER_SELECTION]: WebXRControllerPointerSelection;
|
|
192
|
+
[WebXRFeatureName.RAW_CAMERA_ACCESS]: WebXRRawCameraAccess;
|
|
193
|
+
[WebXRFeatureName.SPACE_WARP]: WebXRSpaceWarp;
|
|
194
|
+
[WebXRFeatureName.TELEPORTATION]: WebXRMotionControllerTeleportation;
|
|
195
|
+
[WebXRFeatureName.WALKING_LOCOMOTION]: WebXRWalkingLocomotion;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Maps feature names to their corresponding options interfaces.
|
|
199
|
+
*/
|
|
200
|
+
export interface IWebXRFeatureNameOptionsMap {
|
|
201
|
+
[WebXRFeatureName.ANCHOR_SYSTEM]: IWebXRAnchorSystemOptions;
|
|
202
|
+
[WebXRFeatureName.BACKGROUND_REMOVER]: IWebXRBackgroundRemoverOptions;
|
|
203
|
+
[WebXRFeatureName.DEPTH_SENSING]: IWebXRDepthSensingOptions;
|
|
204
|
+
[WebXRFeatureName.DOM_OVERLAY]: IWebXRDomOverlayOptions;
|
|
205
|
+
[WebXRFeatureName.EYE_TRACKING]: undefined;
|
|
206
|
+
[WebXRFeatureName.FEATURE_POINTS]: undefined;
|
|
207
|
+
[WebXRFeatureName.HAND_TRACKING]: IWebXRHandTrackingOptions;
|
|
208
|
+
[WebXRFeatureName.HIT_TEST]: IWebXRHitTestOptions;
|
|
209
|
+
[WebXRFeatureName.IMAGE_TRACKING]: IWebXRImageTrackingOptions;
|
|
210
|
+
[WebXRFeatureName.LAYERS]: IWebXRLayersOptions;
|
|
211
|
+
[WebXRFeatureName.LIGHT_ESTIMATION]: IWebXRLightEstimationOptions;
|
|
212
|
+
[WebXRFeatureName.MESH_DETECTION]: IWebXRMeshDetectorOptions;
|
|
213
|
+
[WebXRFeatureName.MOVEMENT]: IWebXRControllerMovementOptions;
|
|
214
|
+
[WebXRFeatureName.NEAR_INTERACTION]: IWebXRNearInteractionOptions;
|
|
215
|
+
[WebXRFeatureName.PHYSICS_CONTROLLERS]: IWebXRControllerPhysicsOptions;
|
|
216
|
+
[WebXRFeatureName.PLANE_DETECTION]: IWebXRPlaneDetectorOptions;
|
|
217
|
+
[WebXRFeatureName.POINTER_SELECTION]: IWebXRControllerPointerSelectionOptions;
|
|
218
|
+
[WebXRFeatureName.RAW_CAMERA_ACCESS]: IWebXRRawCameraAccessOptions;
|
|
219
|
+
[WebXRFeatureName.SPACE_WARP]: undefined;
|
|
220
|
+
[WebXRFeatureName.TELEPORTATION]: IWebXRTeleportationOptions;
|
|
221
|
+
[WebXRFeatureName.WALKING_LOCOMOTION]: IWebXRWalkingLocomotionOptions;
|
|
151
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Helper type that expands/flattens a type to show its properties inline in IntelliSense
|
|
225
|
+
*/
|
|
226
|
+
type Expand<T> = T extends infer O ? {
|
|
227
|
+
[K in keyof O]: O[K];
|
|
228
|
+
} : never;
|
|
229
|
+
/**
|
|
230
|
+
* Helper type to resolve the specific feature type based on the feature name,
|
|
231
|
+
* or fallback to IWebXRFeature if the feature name is not in the type map.
|
|
232
|
+
*/
|
|
233
|
+
export type ResolveWebXRFeature<T extends WebXRFeatureNameType> = T extends keyof IWebXRFeatureNameTypeMap ? IWebXRFeatureNameTypeMap[T] : IWebXRFeature;
|
|
234
|
+
/**
|
|
235
|
+
* Helper type to resolve the options type for a specific feature based on the feature name,
|
|
236
|
+
* or fallback to any if the feature name is not in the type map.
|
|
237
|
+
* The Expand utility type flattens the interface to show properties inline in IntelliSense.
|
|
238
|
+
*/
|
|
239
|
+
export type ResolveWebXRFeatureOptions<T extends WebXRFeatureNameType> = T extends keyof IWebXRFeatureNameOptionsMap ? IWebXRFeatureNameOptionsMap[T] extends undefined ? undefined : Expand<IWebXRFeatureNameOptionsMap[T]> : any;
|
|
152
240
|
/**
|
|
153
241
|
* Defining the constructor of a feature. Used to register the modules.
|
|
154
242
|
*/
|
|
@@ -252,15 +340,15 @@ export declare class WebXRFeaturesManager implements IDisposable {
|
|
|
252
340
|
* @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.
|
|
253
341
|
* @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.
|
|
254
342
|
*/
|
|
255
|
-
enableFeature(featureName:
|
|
256
|
-
Name:
|
|
257
|
-
}, version?: number | string, moduleOptions?:
|
|
343
|
+
enableFeature<T extends WebXRFeatureNameType>(featureName: T | {
|
|
344
|
+
Name: T;
|
|
345
|
+
}, version?: number | string, moduleOptions?: ResolveWebXRFeatureOptions<T>, attachIfPossible?: boolean, required?: boolean): ResolveWebXRFeature<T>;
|
|
258
346
|
/**
|
|
259
347
|
* get the implementation of an enabled feature.
|
|
260
348
|
* @param featureName the name of the feature to load
|
|
261
349
|
* @returns the feature class, if found
|
|
262
350
|
*/
|
|
263
|
-
getEnabledFeature(featureName:
|
|
351
|
+
getEnabledFeature<T extends WebXRFeatureNameType>(featureName: T): ResolveWebXRFeature<T>;
|
|
264
352
|
/**
|
|
265
353
|
* Get the list of enabled features
|
|
266
354
|
* @returns an array of enabled features
|
|
@@ -276,3 +364,4 @@ export declare class WebXRFeaturesManager implements IDisposable {
|
|
|
276
364
|
*/
|
|
277
365
|
_extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit>;
|
|
278
366
|
}
|
|
367
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAsEtC;;GAEG;AACH,MAAM,OAAO,gBAAgB;;AACzB;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;AAC1D;;GAEG;AACoB,mCAAkB,GAAG,uBAAuB,CAAC;AACpE;;GAEG;AACoB,yBAAQ,GAAG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,GAA8B;IACtE,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,QAAQ;IAC3D,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,aAAa;CAC9D,AAH2C,CAG1C","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Observable } from \"core/Misc/observable\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;\r\n\r\n /**\r\n * Triggered when the feature is attached\r\n */\r\n onFeatureAttachObservable: Observable<IWebXRFeature>;\r\n /**\r\n * Triggered when the feature is detached\r\n */\r\n onFeatureDetachObservable: Observable<IWebXRFeature>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\";\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\";\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\";\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\";\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\";\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\";\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\";\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\";\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\";\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\";\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\";\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\";\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\";\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\";\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\";\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\";\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\";\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\";\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\";\r\n /**\r\n * The name of the WebXR Space Warp feature\r\n */\r\n public static readonly SPACE_WARP = \"xr-space-warp\";\r\n /**\r\n * The name of the WebXR Raw Camera Access feature\r\n */\r\n public static readonly RAW_CAMERA_ACCESS = \"xr-raw-camera-access\";\r\n}\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n }\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n const attached = feature.featureImplementation.attach();\r\n if (!attached) {\r\n Tools.Warn(`Feature ${featureName} failed to attach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n const detached = feature.featureImplementation.detach();\r\n if (!detached) {\r\n Tools.Warn(`Feature ${featureName} failed to detach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n this.disableFeature(featureName);\r\n }\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: string | { Name: string },\r\n version: number | string = \"latest\",\r\n moduleOptions: any = {},\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): IWebXRFeature {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature(featureName: string): IWebXRFeature {\r\n return this._features[featureName] && this._features[featureName].featureImplementation;\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit> {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n // eslint-disable-next-line no-await-in-loop\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AA4FtC;;GAEG;AACH,MAAM,OAAO,gBAAgB;;AACzB;;GAEG;AACoB,8BAAa,GAAG,kBAA2B,CAAC;AACnE;;GAEG;AACoB,mCAAkB,GAAG,uBAAgC,CAAC;AAC7E;;GAEG;AACoB,yBAAQ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,yCAAoB,GAA8B;IACtE,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,QAAQ;IAC3D,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,aAAa;CAC9D,AAH2C,CAG1C","sourcesContent":["import type { Observable } from \"core/Misc/observable\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport type { IWebXRAnchorSystemOptions, WebXRAnchorSystem } from \"./features/WebXRAnchorSystem\";\r\nimport type { IWebXRBackgroundRemoverOptions, WebXRBackgroundRemover } from \"./features/WebXRBackgroundRemover\";\r\nimport type { IWebXRControllerMovementOptions, WebXRControllerMovement } from \"./features/WebXRControllerMovement\";\r\nimport type { IWebXRControllerPhysicsOptions, WebXRControllerPhysics } from \"./features/WebXRControllerPhysics\";\r\nimport type { IWebXRControllerPointerSelectionOptions, WebXRControllerPointerSelection } from \"./features/WebXRControllerPointerSelection\";\r\nimport type { IWebXRTeleportationOptions, WebXRMotionControllerTeleportation } from \"./features/WebXRControllerTeleportation\";\r\nimport type { IWebXRDepthSensingOptions, WebXRDepthSensing } from \"./features/WebXRDepthSensing\";\r\nimport type { IWebXRDomOverlayOptions, WebXRDomOverlay } from \"./features/WebXRDOMOverlay\";\r\nimport type { WebXREyeTracking } from \"./features/WebXREyeTracking\";\r\nimport type { WebXRFeaturePointSystem } from \"./features/WebXRFeaturePointSystem\";\r\nimport type { IWebXRHandTrackingOptions, WebXRHandTracking } from \"./features/WebXRHandTracking\";\r\nimport type { IWebXRHitTestOptions, WebXRHitTest } from \"./features/WebXRHitTest\";\r\nimport type { IWebXRImageTrackingOptions, WebXRImageTracking } from \"./features/WebXRImageTracking\";\r\nimport type { IWebXRLayersOptions, WebXRLayers } from \"./features/WebXRLayers\";\r\nimport type { IWebXRLightEstimationOptions, WebXRLightEstimation } from \"./features/WebXRLightEstimation\";\r\nimport type { IWebXRMeshDetectorOptions, WebXRMeshDetector } from \"./features/WebXRMeshDetector\";\r\nimport type { IWebXRNearInteractionOptions, WebXRNearInteraction } from \"./features/WebXRNearInteraction\";\r\nimport type { IWebXRPlaneDetectorOptions, WebXRPlaneDetector } from \"./features/WebXRPlaneDetector\";\r\nimport type { IWebXRRawCameraAccessOptions, WebXRRawCameraAccess } from \"./features/WebXRRawCameraAccess\";\r\nimport type { WebXRSpaceWarp } from \"./features/WebXRSpaceWarp\";\r\nimport type { IWebXRWalkingLocomotionOptions, WebXRWalkingLocomotion } from \"./features/WebXRWalkingLocomotion\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;\r\n\r\n /**\r\n * Triggered when the feature is attached\r\n */\r\n onFeatureAttachObservable: Observable<IWebXRFeature>;\r\n /**\r\n * Triggered when the feature is detached\r\n */\r\n onFeatureDetachObservable: Observable<IWebXRFeature>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\" as const;\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\" as const;\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\" as const;\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\" as const;\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\" as const;\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\" as const;\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\" as const;\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\" as const;\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\" as const;\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\" as const;\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\" as const;\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\" as const;\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\" as const;\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\" as const;\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\" as const;\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\" as const;\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\" as const;\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\" as const;\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\" as const;\r\n /**\r\n * The name of the WebXR Space Warp feature\r\n */\r\n public static readonly SPACE_WARP = \"xr-space-warp\" as const;\r\n /**\r\n * The name of the WebXR Raw Camera Access feature\r\n */\r\n public static readonly RAW_CAMERA_ACCESS = \"xr-raw-camera-access\" as const;\r\n}\r\n\r\nexport type WebXRFeatureNameType = (typeof WebXRFeatureName)[Exclude<keyof typeof WebXRFeatureName, \"prototype\">];\r\n\r\nexport interface IWebXRFeatureNameTypeMap {\r\n [WebXRFeatureName.ANCHOR_SYSTEM]: WebXRAnchorSystem;\r\n [WebXRFeatureName.BACKGROUND_REMOVER]: WebXRBackgroundRemover;\r\n [WebXRFeatureName.DEPTH_SENSING]: WebXRDepthSensing;\r\n [WebXRFeatureName.DOM_OVERLAY]: WebXRDomOverlay;\r\n [WebXRFeatureName.EYE_TRACKING]: WebXREyeTracking;\r\n [WebXRFeatureName.FEATURE_POINTS]: WebXRFeaturePointSystem;\r\n [WebXRFeatureName.HAND_TRACKING]: WebXRHandTracking;\r\n [WebXRFeatureName.HIT_TEST]: WebXRHitTest;\r\n [WebXRFeatureName.IMAGE_TRACKING]: WebXRImageTracking;\r\n [WebXRFeatureName.LAYERS]: WebXRLayers;\r\n [WebXRFeatureName.LIGHT_ESTIMATION]: WebXRLightEstimation;\r\n [WebXRFeatureName.MESH_DETECTION]: WebXRMeshDetector;\r\n [WebXRFeatureName.MOVEMENT]: WebXRControllerMovement;\r\n [WebXRFeatureName.NEAR_INTERACTION]: WebXRNearInteraction;\r\n [WebXRFeatureName.PHYSICS_CONTROLLERS]: WebXRControllerPhysics;\r\n [WebXRFeatureName.PLANE_DETECTION]: WebXRPlaneDetector;\r\n [WebXRFeatureName.POINTER_SELECTION]: WebXRControllerPointerSelection;\r\n [WebXRFeatureName.RAW_CAMERA_ACCESS]: WebXRRawCameraAccess;\r\n [WebXRFeatureName.SPACE_WARP]: WebXRSpaceWarp;\r\n [WebXRFeatureName.TELEPORTATION]: WebXRMotionControllerTeleportation;\r\n [WebXRFeatureName.WALKING_LOCOMOTION]: WebXRWalkingLocomotion;\r\n}\r\n\r\n/**\r\n * Maps feature names to their corresponding options interfaces.\r\n */\r\nexport interface IWebXRFeatureNameOptionsMap {\r\n [WebXRFeatureName.ANCHOR_SYSTEM]: IWebXRAnchorSystemOptions;\r\n [WebXRFeatureName.BACKGROUND_REMOVER]: IWebXRBackgroundRemoverOptions;\r\n [WebXRFeatureName.DEPTH_SENSING]: IWebXRDepthSensingOptions;\r\n [WebXRFeatureName.DOM_OVERLAY]: IWebXRDomOverlayOptions;\r\n [WebXRFeatureName.EYE_TRACKING]: undefined;\r\n [WebXRFeatureName.FEATURE_POINTS]: undefined;\r\n [WebXRFeatureName.HAND_TRACKING]: IWebXRHandTrackingOptions;\r\n [WebXRFeatureName.HIT_TEST]: IWebXRHitTestOptions;\r\n [WebXRFeatureName.IMAGE_TRACKING]: IWebXRImageTrackingOptions;\r\n [WebXRFeatureName.LAYERS]: IWebXRLayersOptions;\r\n [WebXRFeatureName.LIGHT_ESTIMATION]: IWebXRLightEstimationOptions;\r\n [WebXRFeatureName.MESH_DETECTION]: IWebXRMeshDetectorOptions;\r\n [WebXRFeatureName.MOVEMENT]: IWebXRControllerMovementOptions;\r\n [WebXRFeatureName.NEAR_INTERACTION]: IWebXRNearInteractionOptions;\r\n [WebXRFeatureName.PHYSICS_CONTROLLERS]: IWebXRControllerPhysicsOptions;\r\n [WebXRFeatureName.PLANE_DETECTION]: IWebXRPlaneDetectorOptions;\r\n [WebXRFeatureName.POINTER_SELECTION]: IWebXRControllerPointerSelectionOptions;\r\n [WebXRFeatureName.RAW_CAMERA_ACCESS]: IWebXRRawCameraAccessOptions;\r\n [WebXRFeatureName.SPACE_WARP]: undefined;\r\n [WebXRFeatureName.TELEPORTATION]: IWebXRTeleportationOptions;\r\n [WebXRFeatureName.WALKING_LOCOMOTION]: IWebXRWalkingLocomotionOptions;\r\n}\r\n\r\n/**\r\n * Helper type that expands/flattens a type to show its properties inline in IntelliSense\r\n */\r\ntype Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;\r\n\r\n/**\r\n * Helper type to resolve the specific feature type based on the feature name,\r\n * or fallback to IWebXRFeature if the feature name is not in the type map.\r\n */\r\nexport type ResolveWebXRFeature<T extends WebXRFeatureNameType> = T extends keyof IWebXRFeatureNameTypeMap ? IWebXRFeatureNameTypeMap[T] : IWebXRFeature;\r\n\r\n/**\r\n * Helper type to resolve the options type for a specific feature based on the feature name,\r\n * or fallback to any if the feature name is not in the type map.\r\n * The Expand utility type flattens the interface to show properties inline in IntelliSense.\r\n */\r\nexport type ResolveWebXRFeatureOptions<T extends WebXRFeatureNameType> = T extends keyof IWebXRFeatureNameOptionsMap\r\n ? IWebXRFeatureNameOptionsMap[T] extends undefined\r\n ? undefined\r\n : Expand<IWebXRFeatureNameOptionsMap[T]>\r\n : any;\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n }\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n const attached = feature.featureImplementation.attach();\r\n if (!attached) {\r\n Tools.Warn(`Feature ${featureName} failed to attach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n const detached = feature.featureImplementation.detach();\r\n if (!detached) {\r\n Tools.Warn(`Feature ${featureName} failed to detach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n this.disableFeature(featureName);\r\n }\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature<T extends WebXRFeatureNameType>(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: T | { Name: T },\r\n version: number | string = \"latest\",\r\n moduleOptions: ResolveWebXRFeatureOptions<T> = {} as ResolveWebXRFeatureOptions<T>,\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): ResolveWebXRFeature<T> {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation as ResolveWebXRFeature<T>;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed as ResolveWebXRFeature<T>;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature<T extends WebXRFeatureNameType>(featureName: T): ResolveWebXRFeature<T> {\r\n return this._features[featureName] && (this._features[featureName].featureImplementation as ResolveWebXRFeature<T>);\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit> {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n // eslint-disable-next-line no-await-in-loop\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n"]}
|