@babylonjs/core 7.9.0 → 7.10.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/Audio/Interfaces/IAudioEngine.d.ts +2 -0
- package/Audio/Interfaces/IAudioEngine.js.map +1 -1
- package/Audio/audioEngine.d.ts +2 -0
- package/Audio/audioEngine.js +12 -0
- package/Audio/audioEngine.js.map +1 -1
- package/Behaviors/Cameras/framingBehavior.d.ts +1 -1
- package/Behaviors/Cameras/framingBehavior.js +1 -1
- package/Behaviors/Cameras/framingBehavior.js.map +1 -1
- package/Behaviors/Meshes/baseSixDofDragBehavior.d.ts +5 -5
- package/Behaviors/Meshes/baseSixDofDragBehavior.js +4 -4
- package/Behaviors/Meshes/baseSixDofDragBehavior.js.map +1 -1
- package/Collisions/gpuPicker.d.ts +38 -0
- package/Collisions/gpuPicker.js +244 -0
- package/Collisions/gpuPicker.js.map +1 -0
- package/Collisions/index.d.ts +1 -0
- package/Collisions/index.js +1 -0
- package/Collisions/index.js.map +1 -1
- package/Debug/physicsViewer.d.ts +4 -2
- package/Debug/physicsViewer.js +16 -4
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.d.ts +1 -1
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js +7 -3
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.cubeTexture.d.ts +3 -2
- package/Engines/Extensions/engine.cubeTexture.js +2 -2
- package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.views.d.ts +1 -0
- package/Engines/Extensions/engine.views.js +3 -0
- package/Engines/Extensions/engine.views.js.map +1 -0
- package/Engines/WebGPU/Extensions/engine.cubeTexture.d.ts +3 -2
- package/Engines/WebGPU/Extensions/engine.cubeTexture.js +2 -2
- package/Engines/WebGPU/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.videoTexture.js +12 -4
- package/Engines/WebGPU/Extensions/engine.videoTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +2 -3
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/nativeEngine.d.ts +2 -1
- package/Engines/nativeEngine.js +7 -2
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +8 -7
- package/Engines/thinEngine.js.map +1 -1
- package/Gizmos/boundingBoxGizmo.d.ts +6 -5
- package/Gizmos/boundingBoxGizmo.js +5 -5
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Gizmos/lightGizmo.js +1 -2
- package/Gizmos/lightGizmo.js.map +1 -1
- package/Helpers/environmentHelper.js +2 -0
- package/Helpers/environmentHelper.js.map +1 -1
- package/Layers/layer.js +5 -3
- package/Layers/layer.js.map +1 -1
- package/Loading/Plugins/babylonFileLoader.js +1 -1
- package/Loading/Plugins/babylonFileLoader.js.map +1 -1
- package/Materials/Node/Blocks/Dual/currentScreenBlock.js +13 -4
- package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.js +12 -3
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +2 -2
- package/Materials/Node/nodeMaterial.js +11 -11
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Textures/cubeTexture.d.ts +38 -3
- package/Materials/Textures/cubeTexture.js +36 -14
- package/Materials/Textures/cubeTexture.js.map +1 -1
- package/Materials/Textures/internalTexture.js +1 -1
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/material.d.ts +1 -1
- package/Materials/material.js.map +1 -1
- package/Materials/pushMaterial.d.ts +1 -1
- package/Materials/pushMaterial.js.map +1 -1
- package/Materials/shaderMaterial.d.ts +1 -1
- package/Materials/shaderMaterial.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +0 -2
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +15 -11
- package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +6 -16
- package/Meshes/abstractMesh.js +5 -21
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/mesh.js +2 -2
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/mesh.vertexData.js +19 -1
- package/Meshes/mesh.vertexData.js.map +1 -1
- package/Meshes/transformNode.d.ts +14 -0
- package/Meshes/transformNode.js +20 -0
- package/Meshes/transformNode.js.map +1 -1
- package/Particles/EmitterTypes/coneParticleEmitter.d.ts +60 -0
- package/Particles/EmitterTypes/coneParticleEmitter.js +88 -0
- package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
- package/Particles/IParticleSystem.d.ts +2 -1
- package/Particles/IParticleSystem.js.map +1 -1
- package/Particles/baseParticleSystem.d.ts +2 -1
- package/Particles/baseParticleSystem.js +3 -0
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +2 -1
- package/Particles/gpuParticleSystem.js +6 -1
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.d.ts +2 -1
- package/Particles/particleSystem.functions.d.ts +2 -1
- package/Particles/particleSystem.functions.js +4 -1
- package/Particles/particleSystem.functions.js.map +1 -1
- package/Particles/particleSystem.js +10 -2
- package/Particles/particleSystem.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +3 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +14 -0
- package/Physics/v2/Plugins/havokPlugin.js +42 -18
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsEngine.d.ts +14 -0
- package/Physics/v2/physicsEngine.js +20 -0
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Rendering/edgesRenderer.js +2 -1
- package/Rendering/edgesRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/lineUboDeclaration.d.ts +7 -0
- package/Shaders/ShadersInclude/lineUboDeclaration.js +14 -0
- package/Shaders/ShadersInclude/lineUboDeclaration.js.map +1 -0
- package/Shaders/ShadersInclude/lineVertexDeclaration.d.ts +5 -0
- package/Shaders/ShadersInclude/lineVertexDeclaration.js +11 -0
- package/Shaders/ShadersInclude/lineVertexDeclaration.js.map +1 -0
- package/Shaders/gpuUpdateParticles.vertex.js +12 -2
- package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
- package/Shaders/line.vertex.d.ts +2 -0
- package/Shaders/line.vertex.js +5 -2
- package/Shaders/line.vertex.js.map +1 -1
- package/Shaders/picking.fragment.d.ts +5 -0
- package/Shaders/picking.fragment.js +20 -0
- package/Shaders/picking.fragment.js.map +1 -0
- package/Shaders/picking.vertex.d.ts +11 -0
- package/Shaders/picking.vertex.js +34 -0
- package/Shaders/picking.vertex.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/shadowsFragmentFunctions.js +1 -1
- package/ShadersWGSL/ShadersInclude/shadowsFragmentFunctions.js.map +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js +11 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
- package/XR/features/WebXRControllerMovement.d.ts +14 -1
- package/XR/features/WebXRControllerMovement.js +21 -3
- package/XR/features/WebXRControllerMovement.js.map +1 -1
- package/XR/webXRExperienceHelper.js +3 -0
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/XR/webXRInputSource.d.ts +1 -1
- package/XR/webXRInputSource.js +3 -3
- package/XR/webXRInputSource.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRControllerMovement.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRControllerMovement.ts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WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { IWebXRMotionControllerAxesValue, IWebXRMotionControllerComponentChangesValues } from \"../motionController/webXRControllerComponent\";\r\nimport { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport { Matrix, Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { MotionControllerComponentType } from \"../motionController/webXRAbstractMotionController\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * The options container for the controller movement module\r\n */\r\nexport interface IWebXRControllerMovementOptions {\r\n /**\r\n * Override default behaviour and provide your own movement controls\r\n */\r\n customRegistrationConfigurations?: WebXRControllerMovementRegistrationConfiguration[];\r\n /**\r\n * Is movement enabled\r\n */\r\n movementEnabled?: boolean;\r\n /**\r\n * Camera direction follows view pose and movement by default will move independently of the viewer's pose.\r\n */\r\n movementOrientationFollowsViewerPose: boolean;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n movementSpeed?: number;\r\n /**\r\n * Minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n movementThreshold?: number;\r\n /**\r\n * Is rotation enabled\r\n */\r\n rotationEnabled?: boolean;\r\n /**\r\n * Minimum threshold the controller's thumstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n rotationThreshold?: number;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n rotationSpeed?: number;\r\n /**\r\n * Babylon XR Input class for controller\r\n */\r\n xrInput: WebXRInput;\r\n}\r\n\r\n/**\r\n * Feature context is used in handlers and on each XR frame to control the camera movement/direction.\r\n */\r\nexport type WebXRControllerMovementFeatureContext = {\r\n movementEnabled: boolean;\r\n movementOrientationFollowsViewerPose: boolean;\r\n movementSpeed: number;\r\n movementThreshold: number;\r\n rotationEnabled: boolean;\r\n rotationSpeed: number;\r\n rotationThreshold: number;\r\n};\r\n\r\n/**\r\n * Current state of Movements shared across components and handlers.\r\n */\r\nexport type WebXRControllerMovementState = {\r\n moveX: number;\r\n moveY: number;\r\n rotateX: number;\r\n rotateY: number;\r\n};\r\n\r\n/**\r\n * Button of Axis Handler must be specified.\r\n */\r\nexport type WebXRControllerMovementRegistrationConfiguration = {\r\n /**\r\n * handlers are filtered to these types only\r\n */\r\n allowedComponentTypes?: MotionControllerComponentType[];\r\n /**\r\n * For registering movement to specific hand only. Useful if your app has a \"main hand\" and \"off hand\" for determining the functionality of a controller.\r\n */\r\n forceHandedness?: XRHandedness;\r\n /**\r\n * For main component only (useful for buttons and may not trigger axis changes).\r\n */\r\n mainComponentOnly?: boolean;\r\n /**\r\n * Additional predicate to apply to controllers to restrict a handler being added.\r\n */\r\n componentSelectionPredicate?: (xrController: WebXRInputSource) => Nullable<WebXRControllerComponent>;\r\n} & (\r\n | {\r\n /**\r\n * Called when axis changes occur.\r\n */\r\n axisChangedHandler: (\r\n axes: IWebXRMotionControllerAxesValue,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n | {\r\n /**\r\n * Called when the button state changes.\r\n */\r\n buttonChangedhandler: (\r\n pressed: IWebXRMotionControllerComponentChangesValues<boolean>,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n);\r\n\r\ntype RegisteredComponent = {\r\n registrationConfiguration: WebXRControllerMovementRegistrationConfiguration;\r\n component: WebXRControllerComponent;\r\n onAxisChangedObserver?: Nullable<Observer<IWebXRMotionControllerAxesValue>>;\r\n onButtonChangedObserver?: Nullable<Observer<WebXRControllerComponent>>;\r\n};\r\n\r\n/**\r\n * This is a movement feature to be used with WebXR-enabled motion controllers.\r\n * When enabled and attached, the feature will allow a user to move around and rotate in the scene using\r\n * the input of the attached controllers.\r\n */\r\nexport class WebXRControllerMovement extends WebXRAbstractFeature {\r\n private _controllers: {\r\n [controllerUniqueId: string]: {\r\n xrController: WebXRInputSource;\r\n registeredComponents: RegisteredComponent[];\r\n };\r\n } = {};\r\n\r\n private _currentRegistrationConfigurations: WebXRControllerMovementRegistrationConfiguration[] = [];\r\n // Feature configuration is syncronized - this is passed to all handlers (reduce GC pressure).\r\n private _featureContext: WebXRControllerMovementFeatureContext;\r\n // forward direction for movement, which may differ from viewer pose.\r\n private _movementDirection: Quaternion = new Quaternion();\r\n private _movementState: WebXRControllerMovementState;\r\n private _xrInput: WebXRInput;\r\n\r\n // unused\r\n private _tmpRotationMatrix: Matrix = Matrix.Identity();\r\n private _tmpTranslationDirection: Vector3 = new Vector3();\r\n private _tmpMovementTranslation: Vector3 = new Vector3();\r\n private _tempCacheQuaternion: Quaternion = new Quaternion();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.MOVEMENT;\r\n\r\n /**\r\n * Standard controller configurations.\r\n */\r\n public static readonly REGISTRATIONS: { [key: string]: WebXRControllerMovementRegistrationConfiguration[] } = {\r\n default: [\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"left\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.rotateX = Math.abs(axes.x) > featureContext.rotationThreshold ? axes.x : 0;\r\n movementState.rotateY = Math.abs(axes.y) > featureContext.rotationThreshold ? axes.y : 0;\r\n },\r\n },\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"right\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.moveX = Math.abs(axes.x) > featureContext.movementThreshold ? axes.x : 0;\r\n movementState.moveY = Math.abs(axes.y) > featureContext.movementThreshold ? axes.y : 0;\r\n },\r\n },\r\n ],\r\n };\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Current movement direction. Will be null before XR Frames have been processed.\r\n */\r\n public get movementDirection(): Quaternion {\r\n return this._movementDirection;\r\n }\r\n\r\n /**\r\n * Is movement enabled\r\n */\r\n public get movementEnabled(): boolean {\r\n return this._featureContext.movementEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether movement is enabled or not\r\n * @param enabled is movement enabled\r\n */\r\n public set movementEnabled(enabled: boolean) {\r\n this._featureContext.movementEnabled = enabled;\r\n }\r\n\r\n /**\r\n * If movement follows viewer pose\r\n */\r\n public get movementOrientationFollowsViewerPose(): boolean {\r\n return this._featureContext.movementOrientationFollowsViewerPose;\r\n }\r\n\r\n /**\r\n * Sets whether movement follows viewer pose\r\n * @param followsPose is movement should follow viewer pose\r\n */\r\n public set movementOrientationFollowsViewerPose(followsPose: boolean) {\r\n this._featureContext.movementOrientationFollowsViewerPose = followsPose;\r\n }\r\n\r\n /**\r\n * Gets movement speed\r\n */\r\n public get movementSpeed(): number {\r\n return this._featureContext.movementSpeed;\r\n }\r\n\r\n /**\r\n * Sets movement speed\r\n * @param movementSpeed movement speed\r\n */\r\n public set movementSpeed(movementSpeed: number) {\r\n this._featureContext.movementSpeed = movementSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n public get movementThreshold(): number {\r\n return this._featureContext.movementThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n * @param movementThreshold new threshold\r\n */\r\n public set movementThreshold(movementThreshold: number) {\r\n this._featureContext.movementThreshold = movementThreshold;\r\n }\r\n\r\n /**\r\n * Is rotation enabled\r\n */\r\n public get rotationEnabled(): boolean {\r\n return this._featureContext.rotationEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether rotation is enabled or not\r\n * @param enabled is rotation enabled\r\n */\r\n public set rotationEnabled(enabled: boolean) {\r\n this._featureContext.rotationEnabled = enabled;\r\n }\r\n\r\n /**\r\n * Gets rotation speed factor\r\n */\r\n public get rotationSpeed(): number {\r\n return this._featureContext.rotationSpeed;\r\n }\r\n\r\n /**\r\n * Sets rotation speed factor (1.0 is default)\r\n * @param rotationSpeed new rotation speed factor\r\n */\r\n public set rotationSpeed(rotationSpeed: number) {\r\n this._featureContext.rotationSpeed = rotationSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n public get rotationThreshold(): number {\r\n return this._featureContext.rotationThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n * @param threshold new threshold\r\n */\r\n public set rotationThreshold(threshold: number) {\r\n this._featureContext.rotationThreshold = threshold;\r\n }\r\n /**\r\n * constructs a new movement controller system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, options: IWebXRControllerMovementOptions) {\r\n super(_xrSessionManager);\r\n\r\n if (!options || options.xrInput === undefined) {\r\n Tools.Error('WebXRControllerMovement feature requires \"xrInput\" option.');\r\n return;\r\n }\r\n\r\n if (Array.isArray(options.customRegistrationConfigurations)) {\r\n this._currentRegistrationConfigurations = options.customRegistrationConfigurations;\r\n } else {\r\n this._currentRegistrationConfigurations = WebXRControllerMovement.REGISTRATIONS.default;\r\n }\r\n\r\n // synchronized from feature setter properties\r\n this._featureContext = {\r\n movementEnabled: options.movementEnabled || true,\r\n movementOrientationFollowsViewerPose: options.movementOrientationFollowsViewerPose ?? true,\r\n movementSpeed: options.movementSpeed ?? 1,\r\n movementThreshold: options.movementThreshold ?? 0.25,\r\n rotationEnabled: options.rotationEnabled ?? true,\r\n rotationSpeed: options.rotationSpeed ?? 1.0,\r\n rotationThreshold: options.rotationThreshold ?? 0.25,\r\n };\r\n\r\n this._movementState = {\r\n moveX: 0,\r\n moveY: 0,\r\n rotateX: 0,\r\n rotateY: 0,\r\n };\r\n\r\n this._xrInput = options.xrInput;\r\n }\r\n\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n this._xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._xrInput.onControllerRemovedObservable, (controller: WebXRInputSource) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n this._controllers = {};\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Occurs on every XR frame.\r\n * @param _xrFrame\r\n */\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n if (!this.attached) {\r\n return;\r\n }\r\n\r\n if (this._movementState.rotateX !== 0 && this._featureContext.rotationEnabled) {\r\n // smooth rotation\r\n const deltaMillis = this._xrSessionManager.scene.getEngine().getDeltaTime();\r\n const rotationY = deltaMillis * 0.001 * this._featureContext.rotationSpeed * this._movementState.rotateX * (this._xrSessionManager.scene.useRightHandedSystem ? -1 : 1);\r\n\r\n if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n this._xrInput.xrCamera.rotationQuaternion.multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else {\r\n // movement orientation direction does not affect camera. We use rotation speed multiplier\r\n // otherwise need to implement inertia and constraints for same feel as TargetCamera.\r\n\r\n Quaternion.RotationYawPitchRollToRef(rotationY * 3.0, 0, 0, this._tempCacheQuaternion);\r\n this._movementDirection.multiplyInPlace(this._tempCacheQuaternion);\r\n }\r\n } else if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._movementDirection.copyFrom(this._xrInput.xrCamera.rotationQuaternion);\r\n }\r\n\r\n if ((this._movementState.moveX || this._movementState.moveY) && this._featureContext.movementEnabled) {\r\n Matrix.FromQuaternionToRef(this._movementDirection, this._tmpRotationMatrix);\r\n this._tmpTranslationDirection.set(this._movementState.moveX, 0, this._movementState.moveY * (this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0));\r\n // move according to forward direction based on camera speed\r\n Vector3.TransformCoordinatesToRef(this._tmpTranslationDirection, this._tmpRotationMatrix, this._tmpMovementTranslation);\r\n this._tmpMovementTranslation.scaleInPlace(this._xrInput.xrCamera._computeLocalCameraSpeed() * this._featureContext.movementSpeed);\r\n\r\n this._xrInput.xrCamera.cameraDirection.addInPlace(this._tmpMovementTranslation);\r\n }\r\n }\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n registeredComponents: [],\r\n };\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n\r\n // movement controller only available to gamepad-enabled input sources.\r\n if (controllerData.xrController.inputSource.targetRayMode === \"tracked-pointer\" && controllerData.xrController.inputSource.gamepad) {\r\n // motion controller support\r\n const initController = () => {\r\n if (xrController.motionController) {\r\n for (const registration of this._currentRegistrationConfigurations) {\r\n let component: Nullable<WebXRControllerComponent> = null;\r\n\r\n if (registration.allowedComponentTypes) {\r\n for (const componentType of registration.allowedComponentTypes) {\r\n const componentOfType = xrController.motionController.getComponentOfType(componentType);\r\n if (componentOfType !== null) {\r\n component = componentOfType;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (registration.mainComponentOnly) {\r\n const mainComponent = xrController.motionController.getMainComponent();\r\n if (mainComponent === null) {\r\n continue;\r\n }\r\n component = mainComponent;\r\n }\r\n\r\n if (typeof registration.componentSelectionPredicate === \"function\") {\r\n // if does not match we do want to ignore a previously found component\r\n component = registration.componentSelectionPredicate(xrController);\r\n }\r\n\r\n if (component && registration.forceHandedness) {\r\n if (xrController.inputSource.handedness !== registration.forceHandedness) {\r\n continue; // do not register\r\n }\r\n }\r\n\r\n if (component === null) {\r\n continue; // do not register\r\n }\r\n\r\n const registeredComponent: RegisteredComponent = {\r\n registrationConfiguration: registration,\r\n component,\r\n };\r\n controllerData.registeredComponents.push(registeredComponent);\r\n\r\n if (\"axisChangedHandler\" in registration) {\r\n registeredComponent.onAxisChangedObserver = component.onAxisValueChangedObservable.add((axesData) => {\r\n registration.axisChangedHandler(axesData, this._movementState, this._featureContext, this._xrInput);\r\n });\r\n }\r\n\r\n if (\"buttonChangedhandler\" in registration) {\r\n registeredComponent.onButtonChangedObserver = component.onButtonStateChangedObservable.add(() => {\r\n if (component!.changes.pressed) {\r\n registration.buttonChangedhandler(component!.changes.pressed, this._movementState, this._featureContext, this._xrInput);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n };\r\n\r\n if (xrController.motionController) {\r\n initController();\r\n } else {\r\n xrController.onMotionControllerInitObservable.addOnce(() => {\r\n initController();\r\n });\r\n }\r\n }\r\n };\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n\r\n for (const registeredComponent of controllerData.registeredComponents) {\r\n if (registeredComponent.onAxisChangedObserver) {\r\n registeredComponent.component.onAxisValueChangedObservable.remove(registeredComponent.onAxisChangedObserver);\r\n }\r\n if (registeredComponent.onButtonChangedObserver) {\r\n registeredComponent.component.onButtonStateChangedObservable.remove(registeredComponent.onButtonChangedObserver);\r\n }\r\n }\r\n\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerMovement.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerMovement(xrSessionManager, options);\r\n },\r\n WebXRControllerMovement.Version,\r\n true\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRControllerMovement.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRControllerMovement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAsIzC;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,oBAAoB;IA0D7D;;OAEG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH,IAAW,eAAe,CAAC,OAAgB;QACvC,IAAI,CAAC,eAAe,CAAC,eAAe,GAAG,OAAO,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,IAAW,oCAAoC;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,oCAAo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C,wBAAwB,CAAC,eAAe,EAAE,wBAAwB,CAAC,aAAa,CAAC;YACzG,eAAe,EAAE,OAAO;YACxB,kBAAkB,EAAE,CAAC,IAAqC,EAAE,aAA2C,EAAE,cAAqD,EAAE,EAAE;gBAC9J,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvF,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3F,CAAC;SACJ;KACJ;CACJ,AAnBmC,CAmBlC;AAEF;;;;GAIG;AACoB,+BAAO,GAAG,CAAC,AAAJ,CAAK;AA0VvC,oBAAoB,CAAC,eAAe,CAChC,uBAAuB,CAAC,IAAI,EAC5B,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,uBAAuB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC,EACD,uBAAuB,CAAC,OAAO,EAC/B,IAAI,CACP,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { IWebXRMotionControllerAxesValue, IWebXRMotionControllerComponentChangesValues } from \"../motionController/webXRControllerComponent\";\r\nimport { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport { Matrix, Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { MotionControllerComponentType } from \"../motionController/webXRAbstractMotionController\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * The options container for the controller movement module\r\n */\r\nexport interface IWebXRControllerMovementOptions {\r\n /**\r\n * Override default behaviour and provide your own movement controls\r\n */\r\n customRegistrationConfigurations?: WebXRControllerMovementRegistrationConfiguration[];\r\n /**\r\n * Is movement enabled\r\n */\r\n movementEnabled?: boolean;\r\n /**\r\n * Camera direction follows view pose and movement by default will move independently of the viewer's pose.\r\n */\r\n movementOrientationFollowsViewerPose: boolean;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n movementSpeed?: number;\r\n /**\r\n * Minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n movementThreshold?: number;\r\n /**\r\n * Is rotation enabled\r\n */\r\n rotationEnabled?: boolean;\r\n /**\r\n * Minimum threshold the controller's thumstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n rotationThreshold?: number;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n rotationSpeed?: number;\r\n /**\r\n * Babylon XR Input class for controller\r\n */\r\n xrInput: WebXRInput;\r\n\r\n /**\r\n * If movement orientation should follow controller orientation instead of viewer pose.\r\n * Make sure to set movementOrientationFollowsViewerPose to false, otherwise it will be ignored.\r\n */\r\n movementOrientationFollowsController: boolean;\r\n\r\n /**\r\n * If orientation follows the controller, this is the preferred handedness to use for forward movement.\r\n * If not set (or handedness not found), the handedness will be selected by the controller triggering the movement.\r\n * Note that this only works if movementOrientationFollowsController is true.\r\n */\r\n orientationPreferredHandedness?: XRHandedness;\r\n}\r\n\r\n/**\r\n * Feature context is used in handlers and on each XR frame to control the camera movement/direction.\r\n */\r\nexport type WebXRControllerMovementFeatureContext = {\r\n movementEnabled: boolean;\r\n movementOrientationFollowsViewerPose: boolean;\r\n movementOrientationFollowsController: boolean;\r\n orientationPreferredHandedness?: XRHandedness;\r\n movementSpeed: number;\r\n movementThreshold: number;\r\n rotationEnabled: boolean;\r\n rotationSpeed: number;\r\n rotationThreshold: number;\r\n};\r\n\r\n/**\r\n * Current state of Movements shared across components and handlers.\r\n */\r\nexport type WebXRControllerMovementState = {\r\n moveX: number;\r\n moveY: number;\r\n rotateX: number;\r\n rotateY: number;\r\n};\r\n\r\n/**\r\n * Button of Axis Handler must be specified.\r\n */\r\nexport type WebXRControllerMovementRegistrationConfiguration = {\r\n /**\r\n * handlers are filtered to these types only\r\n */\r\n allowedComponentTypes?: MotionControllerComponentType[];\r\n /**\r\n * For registering movement to specific hand only. Useful if your app has a \"main hand\" and \"off hand\" for determining the functionality of a controller.\r\n */\r\n forceHandedness?: XRHandedness;\r\n /**\r\n * For main component only (useful for buttons and may not trigger axis changes).\r\n */\r\n mainComponentOnly?: boolean;\r\n /**\r\n * Additional predicate to apply to controllers to restrict a handler being added.\r\n */\r\n componentSelectionPredicate?: (xrController: WebXRInputSource) => Nullable<WebXRControllerComponent>;\r\n} & (\r\n | {\r\n /**\r\n * Called when axis changes occur.\r\n */\r\n axisChangedHandler: (\r\n axes: IWebXRMotionControllerAxesValue,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n | {\r\n /**\r\n * Called when the button state changes.\r\n */\r\n buttonChangedHandler: (\r\n pressed: IWebXRMotionControllerComponentChangesValues<boolean>,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n);\r\n\r\ntype RegisteredComponent = {\r\n registrationConfiguration: WebXRControllerMovementRegistrationConfiguration;\r\n component: WebXRControllerComponent;\r\n onAxisChangedObserver?: Nullable<Observer<IWebXRMotionControllerAxesValue>>;\r\n onButtonChangedObserver?: Nullable<Observer<WebXRControllerComponent>>;\r\n};\r\n\r\n/**\r\n * This is a movement feature to be used with WebXR-enabled motion controllers.\r\n * When enabled and attached, the feature will allow a user to move around and rotate in the scene using\r\n * the input of the attached controllers.\r\n */\r\nexport class WebXRControllerMovement extends WebXRAbstractFeature {\r\n private _controllers: {\r\n [controllerUniqueId: string]: {\r\n xrController: WebXRInputSource;\r\n registeredComponents: RegisteredComponent[];\r\n };\r\n } = {};\r\n\r\n private _currentRegistrationConfigurations: WebXRControllerMovementRegistrationConfiguration[] = [];\r\n // Feature configuration is synchronized - this is passed to all handlers (reduce GC pressure).\r\n private _featureContext: WebXRControllerMovementFeatureContext;\r\n // forward direction for movement, which may differ from viewer pose.\r\n private _movementDirection: Quaternion = new Quaternion();\r\n private _movementState: WebXRControllerMovementState;\r\n private _xrInput: WebXRInput;\r\n\r\n // unused\r\n private _tmpRotationMatrix: Matrix = Matrix.Identity();\r\n private _tmpTranslationDirection: Vector3 = new Vector3();\r\n private _tmpMovementTranslation: Vector3 = new Vector3();\r\n private _tempCacheQuaternion: Quaternion = new Quaternion();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.MOVEMENT;\r\n\r\n /**\r\n * Standard controller configurations.\r\n */\r\n public static readonly REGISTRATIONS: { [key: string]: WebXRControllerMovementRegistrationConfiguration[] } = {\r\n default: [\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"left\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.rotateX = Math.abs(axes.x) > featureContext.rotationThreshold ? axes.x : 0;\r\n movementState.rotateY = Math.abs(axes.y) > featureContext.rotationThreshold ? axes.y : 0;\r\n },\r\n },\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"right\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.moveX = Math.abs(axes.x) > featureContext.movementThreshold ? axes.x : 0;\r\n movementState.moveY = Math.abs(axes.y) > featureContext.movementThreshold ? axes.y : 0;\r\n },\r\n },\r\n ],\r\n };\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Current movement direction. Will be null before XR Frames have been processed.\r\n */\r\n public get movementDirection(): Quaternion {\r\n return this._movementDirection;\r\n }\r\n\r\n /**\r\n * Is movement enabled\r\n */\r\n public get movementEnabled(): boolean {\r\n return this._featureContext.movementEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether movement is enabled or not\r\n * @param enabled is movement enabled\r\n */\r\n public set movementEnabled(enabled: boolean) {\r\n this._featureContext.movementEnabled = enabled;\r\n }\r\n\r\n /**\r\n * If movement follows viewer pose\r\n */\r\n public get movementOrientationFollowsViewerPose(): boolean {\r\n return this._featureContext.movementOrientationFollowsViewerPose;\r\n }\r\n\r\n /**\r\n * Sets whether movement follows viewer pose\r\n * @param followsPose is movement should follow viewer pose\r\n */\r\n public set movementOrientationFollowsViewerPose(followsPose: boolean) {\r\n this._featureContext.movementOrientationFollowsViewerPose = followsPose;\r\n }\r\n\r\n /**\r\n * Gets movement speed\r\n */\r\n public get movementSpeed(): number {\r\n return this._featureContext.movementSpeed;\r\n }\r\n\r\n /**\r\n * Sets movement speed\r\n * @param movementSpeed movement speed\r\n */\r\n public set movementSpeed(movementSpeed: number) {\r\n this._featureContext.movementSpeed = movementSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n public get movementThreshold(): number {\r\n return this._featureContext.movementThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n * @param movementThreshold new threshold\r\n */\r\n public set movementThreshold(movementThreshold: number) {\r\n this._featureContext.movementThreshold = movementThreshold;\r\n }\r\n\r\n /**\r\n * Is rotation enabled\r\n */\r\n public get rotationEnabled(): boolean {\r\n return this._featureContext.rotationEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether rotation is enabled or not\r\n * @param enabled is rotation enabled\r\n */\r\n public set rotationEnabled(enabled: boolean) {\r\n this._featureContext.rotationEnabled = enabled;\r\n }\r\n\r\n /**\r\n * Gets rotation speed factor\r\n */\r\n public get rotationSpeed(): number {\r\n return this._featureContext.rotationSpeed;\r\n }\r\n\r\n /**\r\n * Sets rotation speed factor (1.0 is default)\r\n * @param rotationSpeed new rotation speed factor\r\n */\r\n public set rotationSpeed(rotationSpeed: number) {\r\n this._featureContext.rotationSpeed = rotationSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n public get rotationThreshold(): number {\r\n return this._featureContext.rotationThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n * @param threshold new threshold\r\n */\r\n public set rotationThreshold(threshold: number) {\r\n this._featureContext.rotationThreshold = threshold;\r\n }\r\n /**\r\n * constructs a new movement controller system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, options: IWebXRControllerMovementOptions) {\r\n super(_xrSessionManager);\r\n\r\n if (!options || options.xrInput === undefined) {\r\n Tools.Error('WebXRControllerMovement feature requires \"xrInput\" option.');\r\n return;\r\n }\r\n\r\n if (Array.isArray(options.customRegistrationConfigurations)) {\r\n this._currentRegistrationConfigurations = options.customRegistrationConfigurations;\r\n } else {\r\n this._currentRegistrationConfigurations = WebXRControllerMovement.REGISTRATIONS.default;\r\n }\r\n\r\n // synchronized from feature setter properties\r\n this._featureContext = {\r\n movementEnabled: options.movementEnabled || true,\r\n movementOrientationFollowsViewerPose: options.movementOrientationFollowsViewerPose ?? true,\r\n movementOrientationFollowsController: options.movementOrientationFollowsController ?? false,\r\n orientationPreferredHandedness: options.orientationPreferredHandedness,\r\n movementSpeed: options.movementSpeed ?? 1,\r\n movementThreshold: options.movementThreshold ?? 0.25,\r\n rotationEnabled: options.rotationEnabled ?? true,\r\n rotationSpeed: options.rotationSpeed ?? 1.0,\r\n rotationThreshold: options.rotationThreshold ?? 0.25,\r\n };\r\n\r\n this._movementState = {\r\n moveX: 0,\r\n moveY: 0,\r\n rotateX: 0,\r\n rotateY: 0,\r\n };\r\n\r\n this._xrInput = options.xrInput;\r\n }\r\n\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n this._xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._xrInput.onControllerRemovedObservable, (controller: WebXRInputSource) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n this._controllers = {};\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Occurs on every XR frame.\r\n * @param _xrFrame\r\n */\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n if (!this.attached) {\r\n return;\r\n }\r\n\r\n if (this._movementState.rotateX !== 0 && this._featureContext.rotationEnabled) {\r\n // smooth rotation\r\n const deltaMillis = this._xrSessionManager.scene.getEngine().getDeltaTime();\r\n const rotationY = deltaMillis * 0.001 * this._featureContext.rotationSpeed * this._movementState.rotateX * (this._xrSessionManager.scene.useRightHandedSystem ? -1 : 1);\r\n\r\n if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n this._xrInput.xrCamera.rotationQuaternion.multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else if (this._featureContext.movementOrientationFollowsController) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n // get the correct controller\r\n const handedness = this._featureContext.orientationPreferredHandedness || \"right\";\r\n const key =\r\n Object.keys(this._controllers).find((key) => this._controllers[key]?.xrController?.inputSource.handedness === handedness) || Object.keys(this._controllers)[0];\r\n const controller = this._controllers[key];\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n (controller?.xrController.pointer.rotationQuaternion || Quaternion.Identity()).multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else {\r\n // movement orientation direction does not affect camera. We use rotation speed multiplier\r\n // otherwise need to implement inertia and constraints for same feel as TargetCamera.\r\n\r\n Quaternion.RotationYawPitchRollToRef(rotationY * 3.0, 0, 0, this._tempCacheQuaternion);\r\n this._movementDirection.multiplyInPlace(this._tempCacheQuaternion);\r\n }\r\n } else if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._movementDirection.copyFrom(this._xrInput.xrCamera.rotationQuaternion);\r\n } else if (this._featureContext.movementOrientationFollowsController) {\r\n // get the correct controller\r\n const handedness = this._featureContext.orientationPreferredHandedness || \"right\";\r\n const key =\r\n Object.keys(this._controllers).find((key) => this._controllers[key]?.xrController.inputSource.handedness === handedness) || Object.keys(this._controllers)[0];\r\n const controller = this._controllers[key];\r\n this._movementDirection.copyFrom(controller?.xrController.pointer.rotationQuaternion || Quaternion.Identity());\r\n }\r\n\r\n if ((this._movementState.moveX || this._movementState.moveY) && this._featureContext.movementEnabled) {\r\n Matrix.FromQuaternionToRef(this._movementDirection, this._tmpRotationMatrix);\r\n this._tmpTranslationDirection.set(this._movementState.moveX, 0, this._movementState.moveY * (this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0));\r\n // move according to forward direction based on camera speed\r\n Vector3.TransformCoordinatesToRef(this._tmpTranslationDirection, this._tmpRotationMatrix, this._tmpMovementTranslation);\r\n this._tmpMovementTranslation.scaleInPlace(this._xrInput.xrCamera._computeLocalCameraSpeed() * this._featureContext.movementSpeed);\r\n\r\n this._xrInput.xrCamera.cameraDirection.addInPlace(this._tmpMovementTranslation);\r\n }\r\n }\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n registeredComponents: [],\r\n };\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n\r\n // movement controller only available to gamepad-enabled input sources.\r\n if (controllerData.xrController.inputSource.targetRayMode === \"tracked-pointer\" && controllerData.xrController.inputSource.gamepad) {\r\n // motion controller support\r\n const initController = () => {\r\n if (xrController.motionController) {\r\n for (const registration of this._currentRegistrationConfigurations) {\r\n let component: Nullable<WebXRControllerComponent> = null;\r\n\r\n if (registration.allowedComponentTypes) {\r\n for (const componentType of registration.allowedComponentTypes) {\r\n const componentOfType = xrController.motionController.getComponentOfType(componentType);\r\n if (componentOfType !== null) {\r\n component = componentOfType;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (registration.mainComponentOnly) {\r\n const mainComponent = xrController.motionController.getMainComponent();\r\n if (mainComponent === null) {\r\n continue;\r\n }\r\n component = mainComponent;\r\n }\r\n\r\n if (typeof registration.componentSelectionPredicate === \"function\") {\r\n // if does not match we do want to ignore a previously found component\r\n component = registration.componentSelectionPredicate(xrController);\r\n }\r\n\r\n if (component && registration.forceHandedness) {\r\n if (xrController.inputSource.handedness !== registration.forceHandedness) {\r\n continue; // do not register\r\n }\r\n }\r\n\r\n if (component === null) {\r\n continue; // do not register\r\n }\r\n\r\n const registeredComponent: RegisteredComponent = {\r\n registrationConfiguration: registration,\r\n component,\r\n };\r\n controllerData.registeredComponents.push(registeredComponent);\r\n\r\n if (\"axisChangedHandler\" in registration) {\r\n registeredComponent.onAxisChangedObserver = component.onAxisValueChangedObservable.add((axesData) => {\r\n registration.axisChangedHandler(axesData, this._movementState, this._featureContext, this._xrInput);\r\n });\r\n }\r\n\r\n if (\"buttonChangedHandler\" in registration) {\r\n registeredComponent.onButtonChangedObserver = component.onButtonStateChangedObservable.add((component) => {\r\n if (component.changes.pressed) {\r\n registration.buttonChangedHandler(component.changes.pressed, this._movementState, this._featureContext, this._xrInput);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n };\r\n\r\n if (xrController.motionController) {\r\n initController();\r\n } else {\r\n xrController.onMotionControllerInitObservable.addOnce(() => {\r\n initController();\r\n });\r\n }\r\n }\r\n };\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n\r\n for (const registeredComponent of controllerData.registeredComponents) {\r\n if (registeredComponent.onAxisChangedObserver) {\r\n registeredComponent.component.onAxisValueChangedObservable.remove(registeredComponent.onAxisChangedObserver);\r\n }\r\n if (registeredComponent.onButtonChangedObserver) {\r\n registeredComponent.component.onButtonStateChangedObservable.remove(registeredComponent.onButtonChangedObserver);\r\n }\r\n }\r\n\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerMovement.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerMovement(xrSessionManager, options);\r\n },\r\n WebXRControllerMovement.Version,\r\n true\r\n);\r\n"]}
|
|
@@ -6,6 +6,7 @@ import { WebXRFeatureName, WebXRFeaturesManager } from "./webXRFeaturesManager.j
|
|
|
6
6
|
import { Logger } from "../Misc/logger.js";
|
|
7
7
|
import { UniversalCamera } from "../Cameras/universalCamera.js";
|
|
8
8
|
import { Quaternion, Vector3 } from "../Maths/math.vector.js";
|
|
9
|
+
import { Engine } from "../Engines/engine.js";
|
|
9
10
|
/**
|
|
10
11
|
* Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)
|
|
11
12
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers
|
|
@@ -139,6 +140,8 @@ export class WebXRExperienceHelper {
|
|
|
139
140
|
this.camera.rotationQuaternion.set(0, 0, 0, 1);
|
|
140
141
|
this.onInitialXRPoseSetObservable.notifyObservers(this.camera);
|
|
141
142
|
}
|
|
143
|
+
// Vision Pro suspends the audio context when entering XR, so we resume it here if needed.
|
|
144
|
+
Engine.audioEngine?._resumeAudioContextOnStateChange();
|
|
142
145
|
this.sessionManager.onXRSessionEnded.addOnce(() => {
|
|
143
146
|
// when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set
|
|
144
147
|
if (this.state !== WebXRState.EXITING_XR) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRExperienceHelper.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRExperienceHelper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAiB3D;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAkC9B;;;OAGG;IACH,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AI,CAAC,MAAM,CAAC,gCAAgC,CAAC,IAAI,CAAC,YAAa,CAAC,CAAC;QACjE,IAAI,CAAC,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAEO,SAAS,CAAC,GAAe;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,GAAG,EAAE;YACpB,OAAO;SACV;QACD,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;QACjB,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"./webXRFeaturesManager\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { UniversalCamera } from \"../Cameras/universalCamera\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\nexport interface WebXRSpectatorModeOption {\r\n /**\r\n * Expected refresh rate (frames per sec) for a spectator camera.\r\n */\r\n fps?: number;\r\n /**\r\n * The index of rigCameras array in a WebXR camera.\r\n */\r\n preferredCameraIndex?: number;\r\n}\r\n\r\n/**\r\n * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers\r\n */\r\nexport class WebXRExperienceHelper implements IDisposable {\r\n private _nonVRCamera: Nullable<Camera> = null;\r\n private _attachedToElement: boolean = false;\r\n private _spectatorCamera: Nullable<UniversalCamera> = null;\r\n private _originalSceneAutoClear = true;\r\n private _supported = false;\r\n private _spectatorMode = false;\r\n private _lastTimestamp = 0;\r\n\r\n /**\r\n * Camera used to render xr content\r\n */\r\n public camera: WebXRCamera;\r\n /** A features manager for this xr session */\r\n public featuresManager: WebXRFeaturesManager;\r\n /**\r\n * Observers registered here will be triggered after the camera's initial transformation is set\r\n * This can be used to set a different ground level or an extra rotation.\r\n *\r\n * Note that ground level is considered to be at 0. The height defined by the XR camera will be added\r\n * to the position set after this observable is done executing.\r\n */\r\n public onInitialXRPoseSetObservable = new Observable<WebXRCamera>();\r\n /**\r\n * Fires when the state of the experience helper has changed\r\n */\r\n public onStateChangedObservable = new Observable<WebXRState>();\r\n /** Session manager used to keep track of xr session */\r\n public sessionManager: WebXRSessionManager;\r\n /**\r\n * The current state of the XR experience (eg. transitioning, in XR or not in XR)\r\n */\r\n public state: WebXRState = WebXRState.NOT_IN_XR;\r\n\r\n /**\r\n * Creates a WebXRExperienceHelper\r\n * @param _scene The scene the helper should be created in\r\n */\r\n private constructor(private _scene: Scene) {\r\n this.sessionManager = new WebXRSessionManager(_scene);\r\n this.camera = new WebXRCamera(\"webxr\", _scene, this.sessionManager);\r\n this.featuresManager = new WebXRFeaturesManager(this.sessionManager);\r\n\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Creates the experience helper\r\n * @param scene the scene to attach the experience helper to\r\n * @returns a promise for the experience helper\r\n */\r\n public static CreateAsync(scene: Scene): Promise<WebXRExperienceHelper> {\r\n const helper = new WebXRExperienceHelper(scene);\r\n return helper.sessionManager\r\n .initializeAsync()\r\n .then(() => {\r\n helper._supported = true;\r\n return helper;\r\n })\r\n .catch((e) => {\r\n helper._setState(WebXRState.NOT_IN_XR);\r\n helper.dispose();\r\n throw e;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n this.exitXRAsync();\r\n this.camera.dispose();\r\n this.onStateChangedObservable.clear();\r\n this.onInitialXRPoseSetObservable.clear();\r\n this.sessionManager.dispose();\r\n this._spectatorCamera?.dispose();\r\n if (this._nonVRCamera) {\r\n this._scene.activeCamera = this._nonVRCamera;\r\n }\r\n }\r\n\r\n /**\r\n * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)\r\n * @param sessionMode options for the XR session\r\n * @param referenceSpaceType frame of reference of the XR session\r\n * @param renderTarget the output canvas that will be used to enter XR mode\r\n * @param sessionCreationOptions optional XRSessionInit object to init the session with\r\n * @returns promise that resolves after xr mode has entered\r\n */\r\n public async enterXRAsync(\r\n sessionMode: XRSessionMode,\r\n referenceSpaceType: XRReferenceSpaceType,\r\n renderTarget: WebXRRenderTarget = this.sessionManager.getWebXRRenderTarget(),\r\n sessionCreationOptions: XRSessionInit = {}\r\n ): Promise<WebXRSessionManager> {\r\n if (!this._supported) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"WebXR not supported in this browser or environment\";\r\n }\r\n this._setState(WebXRState.ENTERING_XR);\r\n if (referenceSpaceType !== \"viewer\" && referenceSpaceType !== \"local\") {\r\n sessionCreationOptions.optionalFeatures = sessionCreationOptions.optionalFeatures || [];\r\n sessionCreationOptions.optionalFeatures.push(referenceSpaceType);\r\n }\r\n sessionCreationOptions = await this.featuresManager._extendXRSessionInitObject(sessionCreationOptions);\r\n // we currently recommend \"unbounded\" space in AR (#7959)\r\n if (sessionMode === \"immersive-ar\" && referenceSpaceType !== \"unbounded\") {\r\n Logger.Warn(\"We recommend using 'unbounded' reference space type when using 'immersive-ar' session mode\");\r\n }\r\n // make sure that the session mode is supported\r\n try {\r\n await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);\r\n await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);\r\n\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.camera.maxZ || 10000,\r\n depthNear: this.camera.minZ,\r\n };\r\n\r\n // The layers feature will have already initialized the xr session's layers on session init.\r\n if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {\r\n const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);\r\n xrRenderState.baseLayer = baseLayer;\r\n }\r\n\r\n this.sessionManager.updateRenderState(xrRenderState);\r\n // run the render loop\r\n this.sessionManager.runXRRenderLoop();\r\n // Cache pre xr scene settings\r\n this._originalSceneAutoClear = this._scene.autoClear;\r\n this._nonVRCamera = this._scene.activeCamera;\r\n this._attachedToElement = !!this._nonVRCamera?.inputs?.attachedToElement;\r\n this._nonVRCamera?.detachControl();\r\n\r\n this._scene.activeCamera = this.camera;\r\n // do not compensate when AR session is used\r\n if (sessionMode !== \"immersive-ar\") {\r\n this._nonXRToXRCamera();\r\n } else {\r\n // Kept here, TODO - check if needed\r\n this._scene.autoClear = false;\r\n this.camera.compensateOnFirstFrame = false;\r\n // reset the camera's position to the origin\r\n this.camera.position.set(0, 0, 0);\r\n this.camera.rotationQuaternion.set(0, 0, 0, 1);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n this.sessionManager.onXRSessionEnded.addOnce(() => {\r\n // when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set\r\n if (this.state !== WebXRState.EXITING_XR) {\r\n this._setState(WebXRState.EXITING_XR);\r\n }\r\n // Reset camera rigs output render target to ensure sessions render target is not drawn after it ends\r\n this.camera.rigCameras.forEach((c) => {\r\n c.outputRenderTarget = null;\r\n });\r\n\r\n // Restore scene settings\r\n this._scene.autoClear = this._originalSceneAutoClear;\r\n this._scene.activeCamera = this._nonVRCamera;\r\n if (this._attachedToElement && this._nonVRCamera) {\r\n this._nonVRCamera.attachControl(!!this._nonVRCamera.inputs.noPreventDefault);\r\n }\r\n if (sessionMode !== \"immersive-ar\" && this.camera.compensateOnFirstFrame) {\r\n if ((<any>this._nonVRCamera).setPosition) {\r\n (<any>this._nonVRCamera).setPosition(this.camera.position);\r\n } else {\r\n this._nonVRCamera!.position.copyFrom(this.camera.position);\r\n }\r\n }\r\n\r\n this._setState(WebXRState.NOT_IN_XR);\r\n });\r\n\r\n // Wait until the first frame arrives before setting state to in xr\r\n this.sessionManager.onXRFrameObservable.addOnce(() => {\r\n this._setState(WebXRState.IN_XR);\r\n });\r\n return this.sessionManager;\r\n } catch (e) {\r\n Logger.Log(e);\r\n Logger.Log(e.message);\r\n this._setState(WebXRState.NOT_IN_XR);\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Exits XR mode and returns the scene to its original state\r\n * @returns promise that resolves after xr mode has exited\r\n */\r\n public exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return Promise.resolve();\r\n }\r\n this._setState(WebXRState.EXITING_XR);\r\n return this.sessionManager.exitXRAsync();\r\n }\r\n\r\n /**\r\n * Enable spectator mode for desktop VR experiences.\r\n * When spectator mode is enabled a camera will be attached to the desktop canvas and will\r\n * display the first rig camera's view on the desktop canvas.\r\n * Please note that this will degrade performance, as it requires another camera render.\r\n * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.\r\n * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.\r\n */\r\n public enableSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n if (!this._spectatorMode) {\r\n this._spectatorMode = true;\r\n this._switchSpectatorMode(options);\r\n }\r\n }\r\n\r\n /**\r\n * Disable spectator mode for desktop VR experiences.\r\n */\r\n public disableSpecatatorMode(): void {\r\n if (this._spectatorMode) {\r\n this._spectatorMode = false;\r\n this._switchSpectatorMode();\r\n }\r\n }\r\n\r\n private _switchSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n const fps = options?.fps ? options.fps : 1000.0;\r\n const refreshRate = (1.0 / fps) * 1000.0;\r\n const cameraIndex = options?.preferredCameraIndex ? options?.preferredCameraIndex : 0;\r\n\r\n const updateSpectatorCamera = () => {\r\n if (this._spectatorCamera) {\r\n const delta = this.sessionManager.currentTimestamp - this._lastTimestamp;\r\n if (delta >= refreshRate) {\r\n this._lastTimestamp = this.sessionManager.currentTimestamp;\r\n this._spectatorCamera.position.copyFrom(this.camera.rigCameras[cameraIndex].globalPosition);\r\n this._spectatorCamera.rotationQuaternion.copyFrom(this.camera.rigCameras[cameraIndex].absoluteRotation);\r\n }\r\n }\r\n };\r\n if (this._spectatorMode) {\r\n if (cameraIndex >= this.camera.rigCameras.length) {\r\n throw new Error(\"the preferred camera index is beyond the length of rig camera array.\");\r\n }\r\n const onStateChanged = () => {\r\n if (this.state === WebXRState.IN_XR) {\r\n this._spectatorCamera = new UniversalCamera(\"webxr-spectator\", Vector3.Zero(), this._scene);\r\n this._spectatorCamera.rotationQuaternion = new Quaternion();\r\n this._scene.activeCameras = [this.camera, this._spectatorCamera];\r\n this.sessionManager.onXRFrameObservable.add(updateSpectatorCamera);\r\n this._scene.onAfterRenderCameraObservable.add((camera) => {\r\n if (camera === this.camera) {\r\n // reset the dimensions object for correct resizing\r\n (this._scene.getEngine() as ThinEngine).framebufferDimensionsObject = null;\r\n }\r\n });\r\n } else if (this.state === WebXRState.EXITING_XR) {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = null;\r\n }\r\n };\r\n this.onStateChangedObservable.add(onStateChanged);\r\n onStateChanged();\r\n } else {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = [this.camera];\r\n }\r\n }\r\n\r\n private _nonXRToXRCamera() {\r\n this.camera.setTransformationFromNonVRCamera(this._nonVRCamera!);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n private _setState(val: WebXRState) {\r\n if (this.state === val) {\r\n return;\r\n }\r\n this.state = val;\r\n this.onStateChangedObservable.notifyObservers(this.state);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,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,EAAE;wBACrD,IAAI,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE;4BACxB,mDAAmD;4BAClD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAiB,CAAC,2BAA2B,GAAG,IAAI,CAAC;yBAC9E;oBACL,CAAC,CAAC,CAAC;iBACN;qBAAM,IAAI,IAAI,CAAC,KAAK,KAAK,UAAU,CAAC,UAAU,EAAE;oBAC7C,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;oBAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC;iBACpC;YACL,CAAC,CAAC;YACF,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAClD,cAAc,EAAE,CAAC;SACpB;aAAM;YACH,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;YAC9E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC7C;IACL,CAAC;IAEO,gBAAgB;QACpB,IAAI,CAAC,MAAM,CAAC,gCAAgC,CAAC,IAAI,CAAC,YAAa,CAAC,CAAC;QACjE,IAAI,CAAC,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAEO,SAAS,CAAC,GAAe;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,GAAG,EAAE;YACpB,OAAO;SACV;QACD,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;QACjB,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRState } from \"./webXRTypes\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"./webXRFeaturesManager\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { UniversalCamera } from \"../Cameras/universalCamera\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport { Engine } from \"../Engines/engine\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\n\r\n/**\r\n * Options for setting up XR spectator camera.\r\n */\r\nexport interface WebXRSpectatorModeOption {\r\n /**\r\n * Expected refresh rate (frames per sec) for a spectator camera.\r\n */\r\n fps?: number;\r\n /**\r\n * The index of rigCameras array in a WebXR camera.\r\n */\r\n preferredCameraIndex?: number;\r\n}\r\n\r\n/**\r\n * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers\r\n */\r\nexport class WebXRExperienceHelper implements IDisposable {\r\n private _nonVRCamera: Nullable<Camera> = null;\r\n private _attachedToElement: boolean = false;\r\n private _spectatorCamera: Nullable<UniversalCamera> = null;\r\n private _originalSceneAutoClear = true;\r\n private _supported = false;\r\n private _spectatorMode = false;\r\n private _lastTimestamp = 0;\r\n\r\n /**\r\n * Camera used to render xr content\r\n */\r\n public camera: WebXRCamera;\r\n /** A features manager for this xr session */\r\n public featuresManager: WebXRFeaturesManager;\r\n /**\r\n * Observers registered here will be triggered after the camera's initial transformation is set\r\n * This can be used to set a different ground level or an extra rotation.\r\n *\r\n * Note that ground level is considered to be at 0. The height defined by the XR camera will be added\r\n * to the position set after this observable is done executing.\r\n */\r\n public onInitialXRPoseSetObservable = new Observable<WebXRCamera>();\r\n /**\r\n * Fires when the state of the experience helper has changed\r\n */\r\n public onStateChangedObservable = new Observable<WebXRState>();\r\n /** Session manager used to keep track of xr session */\r\n public sessionManager: WebXRSessionManager;\r\n /**\r\n * The current state of the XR experience (eg. transitioning, in XR or not in XR)\r\n */\r\n public state: WebXRState = WebXRState.NOT_IN_XR;\r\n\r\n /**\r\n * Creates a WebXRExperienceHelper\r\n * @param _scene The scene the helper should be created in\r\n */\r\n private constructor(private _scene: Scene) {\r\n this.sessionManager = new WebXRSessionManager(_scene);\r\n this.camera = new WebXRCamera(\"webxr\", _scene, this.sessionManager);\r\n this.featuresManager = new WebXRFeaturesManager(this.sessionManager);\r\n\r\n _scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Creates the experience helper\r\n * @param scene the scene to attach the experience helper to\r\n * @returns a promise for the experience helper\r\n */\r\n public static CreateAsync(scene: Scene): Promise<WebXRExperienceHelper> {\r\n const helper = new WebXRExperienceHelper(scene);\r\n return helper.sessionManager\r\n .initializeAsync()\r\n .then(() => {\r\n helper._supported = true;\r\n return helper;\r\n })\r\n .catch((e) => {\r\n helper._setState(WebXRState.NOT_IN_XR);\r\n helper.dispose();\r\n throw e;\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the experience helper\r\n */\r\n public dispose() {\r\n this.exitXRAsync();\r\n this.camera.dispose();\r\n this.onStateChangedObservable.clear();\r\n this.onInitialXRPoseSetObservable.clear();\r\n this.sessionManager.dispose();\r\n this._spectatorCamera?.dispose();\r\n if (this._nonVRCamera) {\r\n this._scene.activeCamera = this._nonVRCamera;\r\n }\r\n }\r\n\r\n /**\r\n * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)\r\n * @param sessionMode options for the XR session\r\n * @param referenceSpaceType frame of reference of the XR session\r\n * @param renderTarget the output canvas that will be used to enter XR mode\r\n * @param sessionCreationOptions optional XRSessionInit object to init the session with\r\n * @returns promise that resolves after xr mode has entered\r\n */\r\n public async enterXRAsync(\r\n sessionMode: XRSessionMode,\r\n referenceSpaceType: XRReferenceSpaceType,\r\n renderTarget: WebXRRenderTarget = this.sessionManager.getWebXRRenderTarget(),\r\n sessionCreationOptions: XRSessionInit = {}\r\n ): Promise<WebXRSessionManager> {\r\n if (!this._supported) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"WebXR not supported in this browser or environment\";\r\n }\r\n this._setState(WebXRState.ENTERING_XR);\r\n if (referenceSpaceType !== \"viewer\" && referenceSpaceType !== \"local\") {\r\n sessionCreationOptions.optionalFeatures = sessionCreationOptions.optionalFeatures || [];\r\n sessionCreationOptions.optionalFeatures.push(referenceSpaceType);\r\n }\r\n sessionCreationOptions = await this.featuresManager._extendXRSessionInitObject(sessionCreationOptions);\r\n // we currently recommend \"unbounded\" space in AR (#7959)\r\n if (sessionMode === \"immersive-ar\" && referenceSpaceType !== \"unbounded\") {\r\n Logger.Warn(\"We recommend using 'unbounded' reference space type when using 'immersive-ar' session mode\");\r\n }\r\n // make sure that the session mode is supported\r\n try {\r\n await this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);\r\n await this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);\r\n\r\n const xrRenderState: XRRenderStateInit = {\r\n // if maxZ is 0 it should be \"Infinity\", but it doesn't work with the WebXR API. Setting to a large number.\r\n depthFar: this.camera.maxZ || 10000,\r\n depthNear: this.camera.minZ,\r\n };\r\n\r\n // The layers feature will have already initialized the xr session's layers on session init.\r\n if (!this.featuresManager.getEnabledFeature(WebXRFeatureName.LAYERS)) {\r\n const baseLayer = await renderTarget.initializeXRLayerAsync(this.sessionManager.session);\r\n xrRenderState.baseLayer = baseLayer;\r\n }\r\n\r\n this.sessionManager.updateRenderState(xrRenderState);\r\n // run the render loop\r\n this.sessionManager.runXRRenderLoop();\r\n // Cache pre xr scene settings\r\n this._originalSceneAutoClear = this._scene.autoClear;\r\n this._nonVRCamera = this._scene.activeCamera;\r\n this._attachedToElement = !!this._nonVRCamera?.inputs?.attachedToElement;\r\n this._nonVRCamera?.detachControl();\r\n\r\n this._scene.activeCamera = this.camera;\r\n // do not compensate when AR session is used\r\n if (sessionMode !== \"immersive-ar\") {\r\n this._nonXRToXRCamera();\r\n } else {\r\n // Kept here, TODO - check if needed\r\n this._scene.autoClear = false;\r\n this.camera.compensateOnFirstFrame = false;\r\n // reset the camera's position to the origin\r\n this.camera.position.set(0, 0, 0);\r\n this.camera.rotationQuaternion.set(0, 0, 0, 1);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n // Vision Pro suspends the audio context when entering XR, so we resume it here if needed.\r\n Engine.audioEngine?._resumeAudioContextOnStateChange();\r\n\r\n this.sessionManager.onXRSessionEnded.addOnce(() => {\r\n // when using the back button and not the exit button (default on mobile), the session is ending but the EXITING state was not set\r\n if (this.state !== WebXRState.EXITING_XR) {\r\n this._setState(WebXRState.EXITING_XR);\r\n }\r\n // Reset camera rigs output render target to ensure sessions render target is not drawn after it ends\r\n this.camera.rigCameras.forEach((c) => {\r\n c.outputRenderTarget = null;\r\n });\r\n\r\n // Restore scene settings\r\n this._scene.autoClear = this._originalSceneAutoClear;\r\n this._scene.activeCamera = this._nonVRCamera;\r\n if (this._attachedToElement && this._nonVRCamera) {\r\n this._nonVRCamera.attachControl(!!this._nonVRCamera.inputs.noPreventDefault);\r\n }\r\n if (sessionMode !== \"immersive-ar\" && this.camera.compensateOnFirstFrame) {\r\n if ((<any>this._nonVRCamera).setPosition) {\r\n (<any>this._nonVRCamera).setPosition(this.camera.position);\r\n } else {\r\n this._nonVRCamera!.position.copyFrom(this.camera.position);\r\n }\r\n }\r\n\r\n this._setState(WebXRState.NOT_IN_XR);\r\n });\r\n\r\n // Wait until the first frame arrives before setting state to in xr\r\n this.sessionManager.onXRFrameObservable.addOnce(() => {\r\n this._setState(WebXRState.IN_XR);\r\n });\r\n return this.sessionManager;\r\n } catch (e) {\r\n Logger.Log(e);\r\n Logger.Log(e.message);\r\n this._setState(WebXRState.NOT_IN_XR);\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Exits XR mode and returns the scene to its original state\r\n * @returns promise that resolves after xr mode has exited\r\n */\r\n public exitXRAsync() {\r\n // only exit if state is IN_XR\r\n if (this.state !== WebXRState.IN_XR) {\r\n return Promise.resolve();\r\n }\r\n this._setState(WebXRState.EXITING_XR);\r\n return this.sessionManager.exitXRAsync();\r\n }\r\n\r\n /**\r\n * Enable spectator mode for desktop VR experiences.\r\n * When spectator mode is enabled a camera will be attached to the desktop canvas and will\r\n * display the first rig camera's view on the desktop canvas.\r\n * Please note that this will degrade performance, as it requires another camera render.\r\n * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.\r\n * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.\r\n */\r\n public enableSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n if (!this._spectatorMode) {\r\n this._spectatorMode = true;\r\n this._switchSpectatorMode(options);\r\n }\r\n }\r\n\r\n /**\r\n * Disable spectator mode for desktop VR experiences.\r\n */\r\n public disableSpecatatorMode(): void {\r\n if (this._spectatorMode) {\r\n this._spectatorMode = false;\r\n this._switchSpectatorMode();\r\n }\r\n }\r\n\r\n private _switchSpectatorMode(options?: WebXRSpectatorModeOption): void {\r\n const fps = options?.fps ? options.fps : 1000.0;\r\n const refreshRate = (1.0 / fps) * 1000.0;\r\n const cameraIndex = options?.preferredCameraIndex ? options?.preferredCameraIndex : 0;\r\n\r\n const updateSpectatorCamera = () => {\r\n if (this._spectatorCamera) {\r\n const delta = this.sessionManager.currentTimestamp - this._lastTimestamp;\r\n if (delta >= refreshRate) {\r\n this._lastTimestamp = this.sessionManager.currentTimestamp;\r\n this._spectatorCamera.position.copyFrom(this.camera.rigCameras[cameraIndex].globalPosition);\r\n this._spectatorCamera.rotationQuaternion.copyFrom(this.camera.rigCameras[cameraIndex].absoluteRotation);\r\n }\r\n }\r\n };\r\n if (this._spectatorMode) {\r\n if (cameraIndex >= this.camera.rigCameras.length) {\r\n throw new Error(\"the preferred camera index is beyond the length of rig camera array.\");\r\n }\r\n const onStateChanged = () => {\r\n if (this.state === WebXRState.IN_XR) {\r\n this._spectatorCamera = new UniversalCamera(\"webxr-spectator\", Vector3.Zero(), this._scene);\r\n this._spectatorCamera.rotationQuaternion = new Quaternion();\r\n this._scene.activeCameras = [this.camera, this._spectatorCamera];\r\n this.sessionManager.onXRFrameObservable.add(updateSpectatorCamera);\r\n this._scene.onAfterRenderCameraObservable.add((camera) => {\r\n if (camera === this.camera) {\r\n // reset the dimensions object for correct resizing\r\n (this._scene.getEngine() as ThinEngine).framebufferDimensionsObject = null;\r\n }\r\n });\r\n } else if (this.state === WebXRState.EXITING_XR) {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = null;\r\n }\r\n };\r\n this.onStateChangedObservable.add(onStateChanged);\r\n onStateChanged();\r\n } else {\r\n this.sessionManager.onXRFrameObservable.removeCallback(updateSpectatorCamera);\r\n this._scene.activeCameras = [this.camera];\r\n }\r\n }\r\n\r\n private _nonXRToXRCamera() {\r\n this.camera.setTransformationFromNonVRCamera(this._nonVRCamera!);\r\n this.onInitialXRPoseSetObservable.notifyObservers(this.camera);\r\n }\r\n\r\n private _setState(val: WebXRState) {\r\n if (this.state === val) {\r\n return;\r\n }\r\n this.state = val;\r\n this.onStateChangedObservable.notifyObservers(this.state);\r\n }\r\n}\r\n"]}
|
package/XR/webXRInputSource.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from "../Misc/observable";
|
|
2
|
-
import { AbstractMesh } from "../Meshes/abstractMesh";
|
|
2
|
+
import type { AbstractMesh } from "../Meshes/abstractMesh";
|
|
3
3
|
import type { Ray } from "../Culling/ray";
|
|
4
4
|
import type { Scene } from "../scene";
|
|
5
5
|
import type { WebXRAbstractMotionController } from "./motionController/webXRAbstractMotionController";
|
package/XR/webXRInputSource.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Observable } from "../Misc/observable.js";
|
|
2
|
-
import { AbstractMesh } from "../Meshes/abstractMesh.js";
|
|
3
2
|
import { Quaternion, Vector3 } from "../Maths/math.vector.js";
|
|
4
3
|
import { WebXRMotionControllerManager } from "./motionController/webXRMotionControllerManager.js";
|
|
5
4
|
import { Tools } from "../Misc/tools.js";
|
|
5
|
+
import { Mesh } from "../Meshes/mesh.js";
|
|
6
6
|
let idCount = 0;
|
|
7
7
|
/**
|
|
8
8
|
* Represents an XR controller
|
|
@@ -40,10 +40,10 @@ export class WebXRInputSource {
|
|
|
40
40
|
*/
|
|
41
41
|
this.onMotionControllerInitObservable = new Observable();
|
|
42
42
|
this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;
|
|
43
|
-
this.pointer = new
|
|
43
|
+
this.pointer = new Mesh(`${this._uniqueId}-pointer`, _scene);
|
|
44
44
|
this.pointer.rotationQuaternion = new Quaternion();
|
|
45
45
|
if (this.inputSource.gripSpace) {
|
|
46
|
-
this.grip = new
|
|
46
|
+
this.grip = new Mesh(`${this._uniqueId}-grip`, this._scene);
|
|
47
47
|
this.grip.rotationQuaternion = new Quaternion();
|
|
48
48
|
}
|
|
49
49
|
this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRInputSource.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRInputSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC,IAAI,OAAO,GAAG,CAAC,CAAC;AA2BhB;;GAEG;AACH,MAAM,OAAO,gBAAgB;IA0CzB;;;;;;OAMG;IACH,YACY,MAAa;IACrB,sDAAsD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AgB,EAAE;YACvB,kEAAkE;YAClE,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;SACpD;IACL,CAAC;CACJ","sourcesContent":["import { Observable } from \"../Misc/observable\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { WebXRAbstractMotionController } from \"./motionController/webXRAbstractMotionController\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\n\r\nlet idCount = 0;\r\n\r\n/**\r\n * Configuration options for the WebXR controller creation\r\n */\r\nexport interface IWebXRControllerOptions {\r\n /**\r\n * Should the controller mesh be animated when a user interacts with it\r\n * The pressed buttons / thumbstick and touchpad animations will be disabled\r\n */\r\n disableMotionControllerAnimation?: boolean;\r\n /**\r\n * Do not load the controller mesh, in case a different mesh needs to be loaded.\r\n */\r\n doNotLoadControllerMesh?: boolean;\r\n /**\r\n * Force a specific controller type for this controller.\r\n * This can be used when creating your own profile or when testing different controllers\r\n */\r\n forceControllerProfile?: string;\r\n /**\r\n * Defines a rendering group ID for meshes that will be loaded.\r\n * This is for the default controllers only.\r\n */\r\n renderingGroupId?: number;\r\n}\r\n\r\n/**\r\n * Represents an XR controller\r\n */\r\nexport class WebXRInputSource {\r\n private _tmpVector = new Vector3();\r\n private _uniqueId: string;\r\n private _disposed = false;\r\n\r\n /**\r\n * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if that's the case only the pointer from the head will be available\r\n */\r\n public grip?: AbstractMesh;\r\n /**\r\n * If available, this is the gamepad object related to this controller.\r\n * Using this object it is possible to get click events and trackpad changes of the\r\n * webxr controller that is currently being used.\r\n */\r\n public motionController?: WebXRAbstractMotionController;\r\n /**\r\n * Event that fires when the controller is removed/disposed.\r\n * The object provided as event data is this controller, after associated assets were disposed.\r\n * uniqueId is still available.\r\n */\r\n public onDisposeObservable = new Observable<WebXRInputSource>();\r\n /**\r\n * Will be triggered when the mesh associated with the motion controller is done loading.\r\n * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh\r\n * A shortened version of controller -> motion controller -> on mesh loaded.\r\n */\r\n public onMeshLoadedObservable = new Observable<AbstractMesh>();\r\n /**\r\n * Observers registered here will trigger when a motion controller profile was assigned to this xr controller\r\n */\r\n public onMotionControllerInitObservable = new Observable<WebXRAbstractMotionController>();\r\n /**\r\n * Pointer which can be used to select objects or attach a visible laser to\r\n */\r\n public pointer: AbstractMesh;\r\n\r\n /**\r\n * The last XRPose the was calculated on the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRPose?: XRPose;\r\n\r\n /**\r\n * Creates the input source object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport\r\n * @param _scene the scene which the controller should be associated to\r\n * @param inputSource the underlying input source for the controller\r\n * @param _options options for this controller creation\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n /** The underlying input source for the controller */\r\n public inputSource: XRInputSource,\r\n private _options: IWebXRControllerOptions = {}\r\n ) {\r\n this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;\r\n\r\n this.pointer = new AbstractMesh(`${this._uniqueId}-pointer`, _scene);\r\n this.pointer.rotationQuaternion = new Quaternion();\r\n\r\n if (this.inputSource.gripSpace) {\r\n this.grip = new AbstractMesh(`${this._uniqueId}-grip`, this._scene);\r\n this.grip.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);\r\n\r\n // for now only load motion controllers if gamepad object available\r\n if (this.inputSource.gamepad && this.inputSource.targetRayMode === \"tracked-pointer\") {\r\n WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then(\r\n (motionController) => {\r\n this.motionController = motionController;\r\n this.onMotionControllerInitObservable.notifyObservers(motionController);\r\n // should the model be loaded?\r\n if (!this._options.doNotLoadControllerMesh && !this.motionController._doNotLoadControllerMesh) {\r\n this.motionController.loadModel().then((success) => {\r\n if (success && this.motionController && this.motionController.rootMesh) {\r\n if (this._options.renderingGroupId) {\r\n // anything other than 0?\r\n this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;\r\n this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => (mesh.renderingGroupId = this._options.renderingGroupId!));\r\n }\r\n this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);\r\n this.motionController.rootMesh.parent = this.grip || this.pointer;\r\n this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;\r\n }\r\n // make sure to dispose is the controller is already disposed\r\n if (this._disposed) {\r\n this.motionController?.dispose();\r\n }\r\n });\r\n }\r\n },\r\n () => {\r\n Tools.Warn(`Could not find a matching motion controller for the registered input source`);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Get this controllers unique id\r\n */\r\n public get uniqueId() {\r\n return this._uniqueId;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n if (this.grip) {\r\n this.grip.dispose(true);\r\n }\r\n if (this.motionController) {\r\n this.motionController.dispose();\r\n }\r\n this.pointer.dispose(true);\r\n this.onMotionControllerInitObservable.clear();\r\n this.onMeshLoadedObservable.clear();\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n this._disposed = true;\r\n }\r\n\r\n /**\r\n * Gets a world space ray coming from the pointer or grip\r\n * @param result the resulting ray\r\n * @param gripIfAvailable use the grip mesh instead of the pointer, if available\r\n */\r\n public getWorldPointerRayToRef(result: Ray, gripIfAvailable: boolean = false) {\r\n const object = gripIfAvailable && this.grip ? this.grip : this.pointer;\r\n Vector3.TransformNormalToRef(this._tmpVector, object.getWorldMatrix(), result.direction);\r\n result.direction.normalize();\r\n result.origin.copyFrom(object.absolutePosition);\r\n result.length = 1000;\r\n }\r\n\r\n /**\r\n * Updates the controller pose based on the given XRFrame\r\n * @param xrFrame xr frame to update the pose with\r\n * @param referenceSpace reference space to use\r\n * @param xrCamera the xr camera, used for parenting\r\n * @param xrSessionManager the session manager used to get the world reference system\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame, referenceSpace: XRReferenceSpace, xrCamera: WebXRCamera, xrSessionManager: WebXRSessionManager) {\r\n const pose = xrFrame.getPose(this.inputSource.targetRaySpace, referenceSpace);\r\n this._lastXRPose = pose;\r\n\r\n // Update the pointer mesh\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n this.pointer.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n const orientation = pose.transform.orientation;\r\n this.pointer.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.pointer.position.z *= -1;\r\n this.pointer.rotationQuaternion!.z *= -1;\r\n this.pointer.rotationQuaternion!.w *= -1;\r\n }\r\n this.pointer.parent = xrCamera.parent;\r\n this.pointer.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n\r\n // Update the grip mesh if it exists\r\n if (this.inputSource.gripSpace && this.grip) {\r\n const pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n const orientation = pose.transform.orientation;\r\n this.grip.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n this.grip.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.grip.position.z *= -1;\r\n this.grip.rotationQuaternion!.z *= -1;\r\n this.grip.rotationQuaternion!.w *= -1;\r\n }\r\n }\r\n this.grip.parent = xrCamera.parent;\r\n this.grip.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n if (this.motionController) {\r\n // either update buttons only or also position, if in gamepad mode\r\n this.motionController.updateFromXRFrame(xrFrame);\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRInputSource.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRInputSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,IAAI,OAAO,GAAG,CAAC,CAAC;AA2BhB;;GAEG;AACH,MAAM,OAAO,gBAAgB;IA0CzB;;;;;;OAMG;IACH,YACY,MAAa;IACrB,sDAAsD;IAC/C,WAA0B,EACzB,WAAoC,EAAE;QAHtC,WAAM,GAAN,MAAM,CAAO;QAEd,gBAAW,GAAX,WAAW,CAAe;QACzB,aAAQ,GAAR,QAAQ,CAA8B;QApD1C,eAAU,GAAG,IAAI,OAAO,EAAE,CAAC;QAE3B,cAAS,GAAG,KAAK,CAAC;QAY1B;;;;WAIG;QACI,wBAAmB,GAAG,IAAI,UAAU,EAAoB,CAAC;QAChE;;;;WAIG;QACI,2BAAsB,GAAG,IAAI,UAAU,EAAgB,CAAC;QAC/D;;WAEG;QACI,qCAAgC,GAAG,IAAI,UAAU,EAAiC,CAAC;QAyBtF,IAAI,CAAC,SAAS,GAAG,cAAc,OAAO,EAAE,IAAI,WAAW,CAAC,aAAa,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;QAElG,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,UAAU,EAAE,MAAM,CAAC,CAAC;QAC7D,IAAI,CAA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C,kBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;gBAC9F,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE;oBACnC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC3B,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBACtC,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;iBACzC;aACJ;YACD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;SACjE;QACD,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACvB,kEAAkE;YAClE,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;SACpD;IACL,CAAC;CACJ","sourcesContent":["import { Observable } from \"../Misc/observable\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { WebXRAbstractMotionController } from \"./motionController/webXRAbstractMotionController\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\n\r\nlet idCount = 0;\r\n\r\n/**\r\n * Configuration options for the WebXR controller creation\r\n */\r\nexport interface IWebXRControllerOptions {\r\n /**\r\n * Should the controller mesh be animated when a user interacts with it\r\n * The pressed buttons / thumbstick and touchpad animations will be disabled\r\n */\r\n disableMotionControllerAnimation?: boolean;\r\n /**\r\n * Do not load the controller mesh, in case a different mesh needs to be loaded.\r\n */\r\n doNotLoadControllerMesh?: boolean;\r\n /**\r\n * Force a specific controller type for this controller.\r\n * This can be used when creating your own profile or when testing different controllers\r\n */\r\n forceControllerProfile?: string;\r\n /**\r\n * Defines a rendering group ID for meshes that will be loaded.\r\n * This is for the default controllers only.\r\n */\r\n renderingGroupId?: number;\r\n}\r\n\r\n/**\r\n * Represents an XR controller\r\n */\r\nexport class WebXRInputSource {\r\n private _tmpVector = new Vector3();\r\n private _uniqueId: string;\r\n private _disposed = false;\r\n\r\n /**\r\n * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if that's the case only the pointer from the head will be available\r\n */\r\n public grip?: AbstractMesh;\r\n /**\r\n * If available, this is the gamepad object related to this controller.\r\n * Using this object it is possible to get click events and trackpad changes of the\r\n * webxr controller that is currently being used.\r\n */\r\n public motionController?: WebXRAbstractMotionController;\r\n /**\r\n * Event that fires when the controller is removed/disposed.\r\n * The object provided as event data is this controller, after associated assets were disposed.\r\n * uniqueId is still available.\r\n */\r\n public onDisposeObservable = new Observable<WebXRInputSource>();\r\n /**\r\n * Will be triggered when the mesh associated with the motion controller is done loading.\r\n * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh\r\n * A shortened version of controller -> motion controller -> on mesh loaded.\r\n */\r\n public onMeshLoadedObservable = new Observable<AbstractMesh>();\r\n /**\r\n * Observers registered here will trigger when a motion controller profile was assigned to this xr controller\r\n */\r\n public onMotionControllerInitObservable = new Observable<WebXRAbstractMotionController>();\r\n /**\r\n * Pointer which can be used to select objects or attach a visible laser to\r\n */\r\n public pointer: AbstractMesh;\r\n\r\n /**\r\n * The last XRPose the was calculated on the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRPose?: XRPose;\r\n\r\n /**\r\n * Creates the input source object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport\r\n * @param _scene the scene which the controller should be associated to\r\n * @param inputSource the underlying input source for the controller\r\n * @param _options options for this controller creation\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n /** The underlying input source for the controller */\r\n public inputSource: XRInputSource,\r\n private _options: IWebXRControllerOptions = {}\r\n ) {\r\n this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;\r\n\r\n this.pointer = new Mesh(`${this._uniqueId}-pointer`, _scene);\r\n this.pointer.rotationQuaternion = new Quaternion();\r\n\r\n if (this.inputSource.gripSpace) {\r\n this.grip = new Mesh(`${this._uniqueId}-grip`, this._scene);\r\n this.grip.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);\r\n\r\n // for now only load motion controllers if gamepad object available\r\n if (this.inputSource.gamepad && this.inputSource.targetRayMode === \"tracked-pointer\") {\r\n WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then(\r\n (motionController) => {\r\n this.motionController = motionController;\r\n this.onMotionControllerInitObservable.notifyObservers(motionController);\r\n // should the model be loaded?\r\n if (!this._options.doNotLoadControllerMesh && !this.motionController._doNotLoadControllerMesh) {\r\n this.motionController.loadModel().then((success) => {\r\n if (success && this.motionController && this.motionController.rootMesh) {\r\n if (this._options.renderingGroupId) {\r\n // anything other than 0?\r\n this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;\r\n this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => (mesh.renderingGroupId = this._options.renderingGroupId!));\r\n }\r\n this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);\r\n this.motionController.rootMesh.parent = this.grip || this.pointer;\r\n this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;\r\n }\r\n // make sure to dispose is the controller is already disposed\r\n if (this._disposed) {\r\n this.motionController?.dispose();\r\n }\r\n });\r\n }\r\n },\r\n () => {\r\n Tools.Warn(`Could not find a matching motion controller for the registered input source`);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Get this controllers unique id\r\n */\r\n public get uniqueId() {\r\n return this._uniqueId;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n if (this.grip) {\r\n this.grip.dispose(true);\r\n }\r\n if (this.motionController) {\r\n this.motionController.dispose();\r\n }\r\n this.pointer.dispose(true);\r\n this.onMotionControllerInitObservable.clear();\r\n this.onMeshLoadedObservable.clear();\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n this._disposed = true;\r\n }\r\n\r\n /**\r\n * Gets a world space ray coming from the pointer or grip\r\n * @param result the resulting ray\r\n * @param gripIfAvailable use the grip mesh instead of the pointer, if available\r\n */\r\n public getWorldPointerRayToRef(result: Ray, gripIfAvailable: boolean = false) {\r\n const object = gripIfAvailable && this.grip ? this.grip : this.pointer;\r\n Vector3.TransformNormalToRef(this._tmpVector, object.getWorldMatrix(), result.direction);\r\n result.direction.normalize();\r\n result.origin.copyFrom(object.absolutePosition);\r\n result.length = 1000;\r\n }\r\n\r\n /**\r\n * Updates the controller pose based on the given XRFrame\r\n * @param xrFrame xr frame to update the pose with\r\n * @param referenceSpace reference space to use\r\n * @param xrCamera the xr camera, used for parenting\r\n * @param xrSessionManager the session manager used to get the world reference system\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame, referenceSpace: XRReferenceSpace, xrCamera: WebXRCamera, xrSessionManager: WebXRSessionManager) {\r\n const pose = xrFrame.getPose(this.inputSource.targetRaySpace, referenceSpace);\r\n this._lastXRPose = pose;\r\n\r\n // Update the pointer mesh\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n this.pointer.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n const orientation = pose.transform.orientation;\r\n this.pointer.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.pointer.position.z *= -1;\r\n this.pointer.rotationQuaternion!.z *= -1;\r\n this.pointer.rotationQuaternion!.w *= -1;\r\n }\r\n this.pointer.parent = xrCamera.parent;\r\n this.pointer.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n\r\n // Update the grip mesh if it exists\r\n if (this.inputSource.gripSpace && this.grip) {\r\n const pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n const orientation = pose.transform.orientation;\r\n this.grip.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n this.grip.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.grip.position.z *= -1;\r\n this.grip.rotationQuaternion!.z *= -1;\r\n this.grip.rotationQuaternion!.w *= -1;\r\n }\r\n }\r\n this.grip.parent = xrCamera.parent;\r\n this.grip.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n if (this.motionController) {\r\n // either update buttons only or also position, if in gamepad mode\r\n this.motionController.updateFromXRFrame(xrFrame);\r\n }\r\n }\r\n}\r\n"]}
|