@babylonjs/core 8.3.0 → 8.4.0
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/Animations/animation.d.ts +4 -0
- package/Animations/animation.js +22 -13
- package/Animations/animation.js.map +1 -1
- package/Animations/animation.optimizations.d.ts +31 -0
- package/Animations/animation.optimizations.js +41 -0
- package/Animations/animation.optimizations.js.map +1 -0
- package/Animations/index.d.ts +1 -0
- package/Animations/index.js +1 -0
- package/Animations/index.js.map +1 -1
- package/Animations/pathCursor.js +3 -1
- package/Animations/pathCursor.js.map +1 -1
- package/Animations/runtimeAnimation.d.ts +3 -1
- package/Animations/runtimeAnimation.js +127 -116
- package/Animations/runtimeAnimation.js.map +1 -1
- package/Audio/audioSceneComponent.js +4 -4
- package/Audio/audioSceneComponent.js.map +1 -1
- package/Behaviors/Meshes/attachToBoxBehavior.js +6 -6
- package/Behaviors/Meshes/attachToBoxBehavior.js.map +1 -1
- package/Behaviors/Meshes/fadeInOutBehavior.js +3 -2
- package/Behaviors/Meshes/fadeInOutBehavior.js.map +1 -1
- package/Behaviors/Meshes/multiPointerScaleBehavior.js +6 -4
- package/Behaviors/Meshes/multiPointerScaleBehavior.js.map +1 -1
- package/Behaviors/Meshes/sixDofDragBehavior.js +3 -2
- package/Behaviors/Meshes/sixDofDragBehavior.js.map +1 -1
- package/Bones/skeleton.js +6 -6
- package/Bones/skeleton.js.map +1 -1
- package/Cameras/Inputs/followCameraKeyboardMoveInput.js +2 -2
- package/Cameras/Inputs/followCameraKeyboardMoveInput.js.map +1 -1
- package/Cameras/VR/vrExperienceHelper.js +2 -2
- package/Cameras/VR/vrExperienceHelper.js.map +1 -1
- package/Cameras/arcRotateCamera.js +6 -2
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Cameras/camera.js +2 -2
- package/Cameras/camera.js.map +1 -1
- package/Cameras/deviceOrientationCamera.js +3 -2
- package/Cameras/deviceOrientationCamera.js.map +1 -1
- package/Collisions/gpuPicker.d.ts +1 -0
- package/Collisions/gpuPicker.js +9 -0
- package/Collisions/gpuPicker.js.map +1 -1
- package/Debug/axesViewer.js +3 -2
- package/Debug/axesViewer.js.map +1 -1
- package/Debug/directionalLightFrustumViewer.js +4 -4
- package/Debug/directionalLightFrustumViewer.js.map +1 -1
- package/Debug/physicsViewer.js +7 -6
- package/Debug/physicsViewer.js.map +1 -1
- package/Debug/skeletonViewer.js +4 -4
- package/Debug/skeletonViewer.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +6 -7
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Processors/shaderCodeNode.js +2 -2
- package/Engines/Processors/shaderCodeNode.js.map +1 -1
- package/Engines/abstractEngine.d.ts +1 -0
- package/Engines/abstractEngine.js +14 -8
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +27 -5
- package/Engines/constants.js +27 -5
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.js +8 -8
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.js +13 -27
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +6 -2
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.js +2 -2
- package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphDataSwitchBlock.js +3 -2
- package/FlowGraph/Blocks/Data/flowGraphDataSwitchBlock.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js +3 -2
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.js +2 -2
- package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSwitchBlock.js +3 -2
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSwitchBlock.js.map +1 -1
- package/FlowGraph/flowGraphAsyncExecutionBlock.js +5 -3
- package/FlowGraph/flowGraphAsyncExecutionBlock.js.map +1 -1
- package/FlowGraph/flowGraphBlock.js +3 -2
- package/FlowGraph/flowGraphBlock.js.map +1 -1
- package/FlowGraph/flowGraphCoordinator.js +10 -6
- package/FlowGraph/flowGraphCoordinator.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +2 -2
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraphBlock.js +5 -4
- package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +4 -3
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
- package/Gamepads/gamepadManager.js +2 -2
- package/Gamepads/gamepadManager.js.map +1 -1
- package/Gizmos/axisDragGizmo.js +3 -2
- package/Gizmos/axisDragGizmo.js.map +1 -1
- package/Gizmos/axisScaleGizmo.js +6 -4
- package/Gizmos/axisScaleGizmo.js.map +1 -1
- package/Gizmos/boundingBoxGizmo.js +28 -26
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Gizmos/cameraGizmo.js +6 -3
- package/Gizmos/cameraGizmo.js.map +1 -1
- package/Gizmos/gizmo.js +11 -10
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/gizmoManager.js +16 -12
- package/Gizmos/gizmoManager.js.map +1 -1
- package/Gizmos/lightGizmo.js +3 -2
- package/Gizmos/lightGizmo.js.map +1 -1
- package/Gizmos/planeDragGizmo.js +3 -2
- package/Gizmos/planeDragGizmo.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +3 -2
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Gizmos/positionGizmo.js +41 -28
- package/Gizmos/positionGizmo.js.map +1 -1
- package/Gizmos/rotationGizmo.js +26 -18
- package/Gizmos/rotationGizmo.js.map +1 -1
- package/Gizmos/scaleGizmo.js +47 -32
- package/Gizmos/scaleGizmo.js.map +1 -1
- package/Layers/effectLayerSceneComponent.js +4 -4
- package/Layers/effectLayerSceneComponent.js.map +1 -1
- package/Layers/layerSceneComponent.js +4 -4
- package/Layers/layerSceneComponent.js.map +1 -1
- package/LensFlares/lensFlareSystemSceneComponent.js +4 -4
- package/LensFlares/lensFlareSystemSceneComponent.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.js +3 -3
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Lights/light.js +4 -4
- package/Lights/light.js.map +1 -1
- package/Loading/Plugins/babylonFileLoader.js +54 -46
- package/Loading/Plugins/babylonFileLoader.js.map +1 -1
- package/Loading/loadingScreen.js +4 -3
- package/Loading/loadingScreen.js.map +1 -1
- package/Loading/sceneLoader.js +15 -12
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Node/Blocks/Dual/currentScreenBlock.js +9 -3
- package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +11 -0
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/Input/inputBlock.js +18 -31
- package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
- package/Materials/Node/Blocks/baseMathBlock.js +3 -1
- package/Materials/Node/Blocks/baseMathBlock.js.map +1 -1
- package/Materials/Node/Blocks/customBlock.js +53 -43
- package/Materials/Node/Blocks/customBlock.js.map +1 -1
- package/Materials/Node/Enums/nodeMaterialModes.d.ts +3 -1
- package/Materials/Node/Enums/nodeMaterialModes.js +2 -0
- package/Materials/Node/Enums/nodeMaterialModes.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +5 -0
- package/Materials/Node/nodeMaterial.js +33 -20
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBlock.js +7 -4
- package/Materials/Node/nodeMaterialBlock.js.map +1 -1
- package/Materials/Node/nodeMaterialBuildState.d.ts +13 -2
- package/Materials/Node/nodeMaterialBuildState.js +72 -7
- package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
- package/Materials/Node/nodeMaterialDefault.d.ts +5 -0
- package/Materials/Node/nodeMaterialDefault.js +28 -0
- package/Materials/Node/nodeMaterialDefault.js.map +1 -1
- package/Materials/Textures/cubeTexture.js +3 -1
- package/Materials/Textures/cubeTexture.js.map +1 -1
- package/Materials/Textures/videoTexture.js +5 -4
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Materials/materialDefines.js +3 -1
- package/Materials/materialDefines.js.map +1 -1
- package/Materials/multiMaterial.js +3 -1
- package/Materials/multiMaterial.js.map +1 -1
- package/Materials/shaderMaterial.js +3 -2
- package/Materials/shaderMaterial.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.js +2 -2
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +8 -8
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineMesh.js +6 -6
- package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js +4 -3
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
- package/Meshes/Node/Blocks/mathBlock.js +3 -1
- package/Meshes/Node/Blocks/mathBlock.js.map +1 -1
- package/Meshes/Node/nodeGeometryBlock.js +8 -5
- package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
- package/Meshes/abstractMesh.js +2 -2
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/geodesicMesh.js +2 -2
- package/Meshes/geodesicMesh.js.map +1 -1
- package/Meshes/mesh.js +6 -6
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/mesh.vertexData.functions.js +11 -10
- package/Meshes/mesh.vertexData.functions.js.map +1 -1
- package/Meshes/mesh.vertexData.subdivide.js +10 -10
- package/Meshes/mesh.vertexData.subdivide.js.map +1 -1
- package/Meshes/meshSimplification.js +10 -10
- package/Meshes/meshSimplification.js.map +1 -1
- package/Meshes/meshUtils.js +6 -3
- package/Meshes/meshUtils.js.map +1 -1
- package/Meshes/polygonMesh.js +10 -10
- package/Meshes/polygonMesh.js.map +1 -1
- package/Misc/PerformanceViewer/performanceViewerCollector.js +4 -4
- package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
- package/Misc/arrayTools.js +2 -2
- package/Misc/arrayTools.js.map +1 -1
- package/Misc/asyncLock.js +9 -9
- package/Misc/asyncLock.js.map +1 -1
- package/Misc/basis.js +4 -2
- package/Misc/basis.js.map +1 -1
- package/Misc/deepCopier.js +3 -2
- package/Misc/deepCopier.js.map +1 -1
- package/Misc/deepMerger.js +3 -2
- package/Misc/deepMerger.js.map +1 -1
- package/Misc/fileTools.js +4 -4
- package/Misc/fileTools.js.map +1 -1
- package/Misc/greasedLineTools.js +14 -13
- package/Misc/greasedLineTools.js.map +1 -1
- package/Misc/logger.js +3 -2
- package/Misc/logger.js.map +1 -1
- package/Misc/observable.extensions.js +4 -4
- package/Misc/observable.extensions.js.map +1 -1
- package/Misc/sceneSerializer.js +5 -4
- package/Misc/sceneSerializer.js.map +1 -1
- package/Misc/snapshotRenderingHelper.js +3 -1
- package/Misc/snapshotRenderingHelper.js.map +1 -1
- package/Misc/tags.js +2 -2
- package/Misc/tags.js.map +1 -1
- package/Misc/trajectoryClassifier.js +8 -8
- package/Misc/trajectoryClassifier.js.map +1 -1
- package/Particles/IParticleSystem.d.ts +1 -1
- package/Particles/IParticleSystem.js.map +1 -1
- package/Particles/baseParticleSystem.d.ts +11 -3
- package/Particles/baseParticleSystem.js +37 -3
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.js +1 -14
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particle.js +2 -2
- package/Particles/particle.js.map +1 -1
- package/Particles/particleSystem.js +15 -13
- package/Particles/particleSystem.js.map +1 -1
- package/Particles/thinParticleSystem.js +3 -16
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Physics/physicsHelper.js +18 -14
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/v1/Plugins/ammoJSPlugin.js +10 -8
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
- package/Physics/v1/Plugins/cannonJSPlugin.js +13 -8
- package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -1
- package/Physics/v1/Plugins/oimoJSPlugin.js +9 -8
- package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -1
- package/Physics/v1/physicsEngine.js +4 -4
- package/Physics/v1/physicsEngine.js.map +1 -1
- package/Physics/v1/physicsImpostor.js +10 -21
- package/Physics/v1/physicsImpostor.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js +12 -10
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/ragdoll.js +4 -4
- package/Physics/v2/ragdoll.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js +3 -2
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderEffect.js +8 -6
- package/PostProcesses/RenderPipeline/postProcessRenderEffect.js.map +1 -1
- package/PostProcesses/depthOfFieldMergePostProcess.js +4 -3
- package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
- package/Rendering/GlobalIllumination/giRSMManager.js +6 -6
- package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +14 -14
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +14 -12
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
- package/Rendering/iblCdfGenerator.js +4 -4
- package/Rendering/iblCdfGenerator.js.map +1 -1
- package/Rendering/objectRenderer.js +2 -2
- package/Rendering/objectRenderer.js.map +1 -1
- package/Rendering/reflectiveShadowMap.js +7 -5
- package/Rendering/reflectiveShadowMap.js.map +1 -1
- package/Sprites/spriteMap.js +2 -2
- package/Sprites/spriteMap.js.map +1 -1
- package/XR/features/WebXRAbstractFeature.js +2 -2
- package/XR/features/WebXRAbstractFeature.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.js +4 -4
- package/XR/features/WebXRAnchorSystem.js.map +1 -1
- package/XR/features/WebXRBackgroundRemover.js +3 -1
- package/XR/features/WebXRBackgroundRemover.js.map +1 -1
- package/XR/features/WebXRControllerMovement.js +6 -3
- package/XR/features/WebXRControllerMovement.js.map +1 -1
- package/XR/features/WebXRControllerPhysics.js +12 -7
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRControllerPointerSelection.js +12 -7
- package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
- package/XR/features/WebXRControllerTeleportation.js +11 -7
- package/XR/features/WebXRControllerTeleportation.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js +6 -6
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/features/WebXRHandTracking.js +60 -24
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/XR/features/WebXRHitTest.js +4 -4
- package/XR/features/WebXRHitTest.js.map +1 -1
- package/XR/features/WebXRImageTracking.js +2 -2
- package/XR/features/WebXRImageTracking.js.map +1 -1
- package/XR/features/WebXRLayers.js +2 -2
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js +12 -7
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/features/WebXRRawCameraAccess.js +9 -4
- package/XR/features/WebXRRawCameraAccess.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.js +2 -2
- package/XR/features/WebXRSpaceWarp.js.map +1 -1
- package/XR/motionController/webXRAbstractMotionController.js +19 -8
- package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
- package/XR/motionController/webXRGenericMotionController.js +2 -2
- package/XR/motionController/webXRGenericMotionController.js.map +1 -1
- package/XR/motionController/webXRHTCViveMotionController.js +5 -4
- package/XR/motionController/webXRHTCViveMotionController.js.map +1 -1
- package/XR/motionController/webXRMicrosoftMixedRealityController.js +9 -6
- package/XR/motionController/webXRMicrosoftMixedRealityController.js.map +1 -1
- package/XR/motionController/webXRMotionControllerManager.js +4 -4
- package/XR/motionController/webXRMotionControllerManager.js.map +1 -1
- package/XR/motionController/webXROculusTouchMotionController.js +5 -4
- package/XR/motionController/webXROculusTouchMotionController.js.map +1 -1
- package/XR/motionController/webXRProfiledMotionController.js +15 -10
- package/XR/motionController/webXRProfiledMotionController.js.map +1 -1
- package/XR/webXRCamera.js +3 -2
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXREnterExitUI.js +5 -4
- package/XR/webXREnterExitUI.js.map +1 -1
- package/XR/webXRExperienceHelper.js +2 -2
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/XR/webXRFeaturesManager.js +10 -7
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRInput.js +8 -8
- package/XR/webXRInput.js.map +1 -1
- package/XR/webXRInputSource.js +4 -1
- package/XR/webXRInputSource.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js +3 -1
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/assetContainer.js +156 -135
- package/assetContainer.js.map +1 -1
- package/node.js +2 -2
- package/node.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +18 -11
- package/scene.js.map +1 -1
|
@@ -55,8 +55,12 @@ export class WebXRRawCameraAccess extends WebXRAbstractFeature {
|
|
|
55
55
|
}
|
|
56
56
|
this._glBinding = undefined;
|
|
57
57
|
if (!this.options.doNotDisposeOnDetach) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
for (const t of this._cachedInternalTextures) {
|
|
59
|
+
t.dispose();
|
|
60
|
+
}
|
|
61
|
+
for (const t of this.texturesData) {
|
|
62
|
+
t.dispose();
|
|
63
|
+
}
|
|
60
64
|
this._cachedInternalTextures.length = 0;
|
|
61
65
|
this.texturesData.length = 0;
|
|
62
66
|
this.cameraIntrinsics.length = 0;
|
|
@@ -144,9 +148,10 @@ export class WebXRRawCameraAccess extends WebXRAbstractFeature {
|
|
|
144
148
|
return;
|
|
145
149
|
}
|
|
146
150
|
let updated = true;
|
|
147
|
-
pose.views.
|
|
151
|
+
for (let index = 0; index < pose.views.length; index++) {
|
|
152
|
+
const view = pose.views[index];
|
|
148
153
|
updated = updated && this._updateInternalTextures(view, index);
|
|
149
|
-
}
|
|
154
|
+
}
|
|
150
155
|
if (updated) {
|
|
151
156
|
this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);
|
|
152
157
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRRawCameraAccess.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRRawCameraAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAyB,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAanE;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,oBAAoB;IAiD1D;;;;OAIG;IACH,YACI,iBAAsC,EACtB,UAAwC,EAAE;QAE1D,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAFT,YAAO,GAAP,OAAO,CAAmC;QAvDtD,4BAAuB,GAAsB,EAAE,CAAC;QACxD;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,IAAI,CAAC,YAAY,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;;AAjJD;;GAEG;AACoB,yBAAI,GAAG,gBAAgB,CAAC,iBAAiB,AAArC,CAAsC;AAEjE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AA0IvC,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { ThinEngine } from \"../../Engines\";\r\n\r\n/**\r\n * Options for raw camera access\r\n */\r\nexport interface IWebXRRawCameraAccessOptions {\r\n /**\r\n * Keep the created textures and metadata when detaching the feature.\r\n */\r\n doNotDisposeOnDetach?: boolean;\r\n}\r\n\r\n/**\r\n * WebXR Feature for WebXR raw camera access\r\n * @since 6.31.0\r\n * @see https://immersive-web.github.io/raw-camera-access/\r\n */\r\nexport class WebXRRawCameraAccess extends WebXRAbstractFeature {\r\n private _cachedInternalTextures: InternalTexture[] = [];\r\n /**\r\n * This is an array of camera views\r\n * Note that mostly the array will contain a single view\r\n * If you want to know the order of the views, use the `viewIndex` array\r\n */\r\n public texturesData: BaseTexture[] = [];\r\n /**\r\n * If needed, this array will contain the eye definition of each texture in `texturesArray`\r\n */\r\n public viewIndex: string[] = [];\r\n\r\n /**\r\n * If needed, this array will contain the camera's intrinsics\r\n * You can use this data to convert from camera space to screen space and vice versa\r\n */\r\n public cameraIntrinsics: {\r\n u0: number;\r\n v0: number;\r\n ax: number;\r\n ay: number;\r\n gamma: number;\r\n width: number;\r\n height: number;\r\n viewportX: number;\r\n viewportY: number;\r\n }[] = [];\r\n\r\n /**\r\n * An observable that will notify when the camera's textures are updated\r\n */\r\n public onTexturesUpdatedObservable: Observable<BaseTexture[]> = new Observable();\r\n\r\n private _glBinding?: XRWebGLBinding;\r\n private _glContext: WebGLRenderingContext;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.RAW_CAMERA_ACCESS;\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 * Creates a new instance of the feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for the Feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n public readonly options: IWebXRRawCameraAccessOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"camera-access\";\r\n }\r\n\r\n public override attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n this._glContext = (this._xrSessionManager.scene.getEngine() as ThinEngine)._gl;\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\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 this._glBinding = undefined;\r\n if (!this.options.doNotDisposeOnDetach) {\r\n this._cachedInternalTextures.forEach((t) => t.dispose());\r\n this.texturesData.forEach((t) => t.dispose());\r\n this._cachedInternalTextures.length = 0;\r\n this.texturesData.length = 0;\r\n this.cameraIntrinsics.length = 0;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onTexturesUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * @see https://github.com/immersive-web/raw-camera-access/blob/main/explainer.md\r\n * @param view the XRView to update\r\n * @param index the index of the view in the views array\r\n */\r\n private _updateCameraIntrinsics(view: XRView, index: number): void {\r\n const cameraViewport = {\r\n width: view.camera!.width,\r\n height: view.camera!.height,\r\n x: 0,\r\n y: 0,\r\n };\r\n const p = view.projectionMatrix;\r\n\r\n // Principal point in pixels (typically at or near the center of the viewport)\r\n const u0 = ((1 - p[8]) * cameraViewport.width) / 2 + cameraViewport.x;\r\n const v0 = ((1 - p[9]) * cameraViewport.height) / 2 + cameraViewport.y;\r\n\r\n // Focal lengths in pixels (these are equal for square pixels)\r\n const ax = (cameraViewport.width / 2) * p[0];\r\n const ay = (cameraViewport.height / 2) * p[5];\r\n\r\n // Skew factor in pixels (nonzero for rhomboid pixels)\r\n const gamma = (cameraViewport.width / 2) * p[4];\r\n this.cameraIntrinsics[index] = {\r\n u0,\r\n v0,\r\n ax,\r\n ay,\r\n gamma,\r\n width: cameraViewport.width,\r\n height: cameraViewport.height,\r\n viewportX: cameraViewport.x,\r\n viewportY: cameraViewport.y,\r\n };\r\n }\r\n\r\n private _updateInternalTextures(view: XRView, index = 0): boolean {\r\n if (!view.camera) {\r\n return false;\r\n }\r\n this.viewIndex[index] = view.eye;\r\n const lp = this._glBinding?.getCameraImage(view.camera);\r\n\r\n if (!this._cachedInternalTextures[index]) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);\r\n internalTexture.invertY = false;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = view.camera.width;\r\n internalTexture.height = view.camera.height;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._glContext);\r\n this._cachedInternalTextures[index] = internalTexture;\r\n // create the base texture\r\n const texture = new BaseTexture(this._xrSessionManager.scene);\r\n texture.name = `WebXR Raw Camera Access (${index})`;\r\n texture._texture = this._cachedInternalTextures[index];\r\n this.texturesData[index] = texture;\r\n // get the camera intrinsics\r\n this._updateCameraIntrinsics(view, index);\r\n } else {\r\n // make sure the webgl texture is updated. Should happen automatically\r\n this._cachedInternalTextures[index]._hardwareTexture?.set(lp);\r\n }\r\n this._cachedInternalTextures[index].isReady = true;\r\n return true;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (!pose || !pose.views) {\r\n return;\r\n }\r\n let updated = true;\r\n pose.views.forEach((view, index) => {\r\n updated = updated && this._updateInternalTextures(view, index);\r\n });\r\n if (updated) {\r\n this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRRawCameraAccess.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRRawCameraAccess(xrSessionManager, options);\r\n },\r\n WebXRRawCameraAccess.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRRawCameraAccess.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRRawCameraAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC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BAAiB,CAAC,cAAc,CAAC;QAE7D,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO;QACX,CAAC;QACD,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACrD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC/B,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACV,IAAI,CAAC,2BAA2B,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;;AAtJD;;GAEG;AACoB,yBAAI,GAAG,gBAAgB,CAAC,iBAAiB,AAArC,CAAsC;AAEjE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AA+IvC,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { ThinEngine } from \"../../Engines\";\r\n\r\n/**\r\n * Options for raw camera access\r\n */\r\nexport interface IWebXRRawCameraAccessOptions {\r\n /**\r\n * Keep the created textures and metadata when detaching the feature.\r\n */\r\n doNotDisposeOnDetach?: boolean;\r\n}\r\n\r\n/**\r\n * WebXR Feature for WebXR raw camera access\r\n * @since 6.31.0\r\n * @see https://immersive-web.github.io/raw-camera-access/\r\n */\r\nexport class WebXRRawCameraAccess extends WebXRAbstractFeature {\r\n private _cachedInternalTextures: InternalTexture[] = [];\r\n /**\r\n * This is an array of camera views\r\n * Note that mostly the array will contain a single view\r\n * If you want to know the order of the views, use the `viewIndex` array\r\n */\r\n public texturesData: BaseTexture[] = [];\r\n /**\r\n * If needed, this array will contain the eye definition of each texture in `texturesArray`\r\n */\r\n public viewIndex: string[] = [];\r\n\r\n /**\r\n * If needed, this array will contain the camera's intrinsics\r\n * You can use this data to convert from camera space to screen space and vice versa\r\n */\r\n public cameraIntrinsics: {\r\n u0: number;\r\n v0: number;\r\n ax: number;\r\n ay: number;\r\n gamma: number;\r\n width: number;\r\n height: number;\r\n viewportX: number;\r\n viewportY: number;\r\n }[] = [];\r\n\r\n /**\r\n * An observable that will notify when the camera's textures are updated\r\n */\r\n public onTexturesUpdatedObservable: Observable<BaseTexture[]> = new Observable();\r\n\r\n private _glBinding?: XRWebGLBinding;\r\n private _glContext: WebGLRenderingContext;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.RAW_CAMERA_ACCESS;\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 * Creates a new instance of the feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for the Feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n public readonly options: IWebXRRawCameraAccessOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"camera-access\";\r\n }\r\n\r\n public override attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n this._glContext = (this._xrSessionManager.scene.getEngine() as ThinEngine)._gl;\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\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 this._glBinding = undefined;\r\n if (!this.options.doNotDisposeOnDetach) {\r\n for (const t of this._cachedInternalTextures) {\r\n t.dispose();\r\n }\r\n for (const t of this.texturesData) {\r\n t.dispose();\r\n }\r\n this._cachedInternalTextures.length = 0;\r\n this.texturesData.length = 0;\r\n this.cameraIntrinsics.length = 0;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onTexturesUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * @see https://github.com/immersive-web/raw-camera-access/blob/main/explainer.md\r\n * @param view the XRView to update\r\n * @param index the index of the view in the views array\r\n */\r\n private _updateCameraIntrinsics(view: XRView, index: number): void {\r\n const cameraViewport = {\r\n width: view.camera!.width,\r\n height: view.camera!.height,\r\n x: 0,\r\n y: 0,\r\n };\r\n const p = view.projectionMatrix;\r\n\r\n // Principal point in pixels (typically at or near the center of the viewport)\r\n const u0 = ((1 - p[8]) * cameraViewport.width) / 2 + cameraViewport.x;\r\n const v0 = ((1 - p[9]) * cameraViewport.height) / 2 + cameraViewport.y;\r\n\r\n // Focal lengths in pixels (these are equal for square pixels)\r\n const ax = (cameraViewport.width / 2) * p[0];\r\n const ay = (cameraViewport.height / 2) * p[5];\r\n\r\n // Skew factor in pixels (nonzero for rhomboid pixels)\r\n const gamma = (cameraViewport.width / 2) * p[4];\r\n this.cameraIntrinsics[index] = {\r\n u0,\r\n v0,\r\n ax,\r\n ay,\r\n gamma,\r\n width: cameraViewport.width,\r\n height: cameraViewport.height,\r\n viewportX: cameraViewport.x,\r\n viewportY: cameraViewport.y,\r\n };\r\n }\r\n\r\n private _updateInternalTextures(view: XRView, index = 0): boolean {\r\n if (!view.camera) {\r\n return false;\r\n }\r\n this.viewIndex[index] = view.eye;\r\n const lp = this._glBinding?.getCameraImage(view.camera);\r\n\r\n if (!this._cachedInternalTextures[index]) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);\r\n internalTexture.invertY = false;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = view.camera.width;\r\n internalTexture.height = view.camera.height;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._glContext);\r\n this._cachedInternalTextures[index] = internalTexture;\r\n // create the base texture\r\n const texture = new BaseTexture(this._xrSessionManager.scene);\r\n texture.name = `WebXR Raw Camera Access (${index})`;\r\n texture._texture = this._cachedInternalTextures[index];\r\n this.texturesData[index] = texture;\r\n // get the camera intrinsics\r\n this._updateCameraIntrinsics(view, index);\r\n } else {\r\n // make sure the webgl texture is updated. Should happen automatically\r\n this._cachedInternalTextures[index]._hardwareTexture?.set(lp);\r\n }\r\n this._cachedInternalTextures[index].isReady = true;\r\n return true;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (!pose || !pose.views) {\r\n return;\r\n }\r\n let updated = true;\r\n for (let index = 0; index < pose.views.length; index++) {\r\n const view = pose.views[index];\r\n updated = updated && this._updateInternalTextures(view, index);\r\n }\r\n if (updated) {\r\n this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRRawCameraAccess.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRRawCameraAccess(xrSessionManager, options);\r\n },\r\n WebXRRawCameraAccess.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -65,9 +65,9 @@ export class XRSpaceWarpRenderTarget extends RenderTargetTexture {
|
|
|
65
65
|
}
|
|
66
66
|
super.render(useCameraPostProcess, dumpForDebug);
|
|
67
67
|
// Restore original materials
|
|
68
|
-
this._originalPairing
|
|
68
|
+
for (const tuple of this._originalPairing) {
|
|
69
69
|
tuple[0].material = tuple[1];
|
|
70
|
-
}
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRSpaceWarp.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRSpaceWarp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AAIvC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ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C,EACD,cAAc,CAAC,OAAO,EACtB,KAAK,CACR,CAAC","sourcesContent":["import type { Engine } from \"../../Engines/engine\";\r\nimport type { WebGLRenderTargetWrapper } from \"../../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IWebXRRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { ShaderMaterial } from \"../../Materials/shaderMaterial\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Material } from \"../../Materials/material\";\r\nimport \"../../Shaders/velocity.fragment\";\r\nimport \"../../Shaders/velocity.vertex\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\n\r\n/**\r\n * Used for Space Warp render process\r\n */\r\nexport class XRSpaceWarpRenderTarget extends RenderTargetTexture {\r\n private _velocityMaterial: ShaderMaterial;\r\n private _originalPairing: Array<[AbstractMesh, Nullable<Material>]> = [];\r\n private _previousWorldMatrices: Array<Matrix> = [];\r\n private _previousTransforms: Matrix[] = [Matrix.Identity(), Matrix.Identity()];\r\n\r\n /**\r\n * Creates a Space Warp render target\r\n * @param motionVectorTexture WebGLTexture provided by WebGLSubImage\r\n * @param depthStencilTexture WebGLTexture provided by WebGLSubImage\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(motionVectorTexture: WebGLTexture, depthStencilTexture: WebGLTexture, scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"spacewarp rtt\", size, scene, false, true, Constants.TEXTURETYPE_HALF_FLOAT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = (this.getScene()!.getEngine() as Engine).createMultiviewRenderTargetTexture(\r\n this.getRenderWidth(),\r\n this.getRenderHeight(),\r\n motionVectorTexture,\r\n depthStencilTexture\r\n );\r\n (this._renderTarget as WebGLRenderTargetWrapper)._disposeOnlyFramebuffers = true;\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n\r\n if (scene) {\r\n this._velocityMaterial = new ShaderMaterial(\r\n \"velocity shader material\",\r\n scene,\r\n {\r\n vertex: \"velocity\",\r\n fragment: \"velocity\",\r\n },\r\n {\r\n uniforms: [\"world\", \"previousWorld\", \"viewProjection\", \"viewProjectionR\", \"previousViewProjection\", \"previousViewProjectionR\"],\r\n }\r\n );\r\n this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;\r\n this._velocityMaterial.onBindObservable.add((mesh) => {\r\n // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).\r\n // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter\r\n this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();\r\n this._velocityMaterial.getEffect().setMatrix(\"previousWorld\", this._previousWorldMatrices[mesh.uniqueId]);\r\n this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();\r\n // now set the scene's previous matrix\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjection\", this._previousTransforms[0]);\r\n // multiview for sure\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjectionR\", this._previousTransforms[1]);\r\n\r\n // store the previous (current, to be exact) transforms\r\n this._previousTransforms[0].copyFrom(scene.getTransformMatrix());\r\n this._previousTransforms[1].copyFrom(scene._transformMatrixR);\r\n });\r\n this._velocityMaterial.freeze();\r\n }\r\n }\r\n\r\n public override render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n (this.getScene()!.getEngine() as Engine).bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public override getViewCount() {\r\n return 2;\r\n }\r\n\r\n public override dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(\r\n protected readonly _scene: Scene,\r\n protected readonly _xrSessionManager: WebXRSessionManager,\r\n protected readonly _xrWebGLBinding: XRWebGLBinding\r\n ) {\r\n this._engine = _scene.getEngine() as Engine;\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\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 * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n private _onAfterRenderObserver: Nullable<Observer<Scene>> = null;\r\n\r\n /**\r\n * constructor for the space warp feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"space-warp\";\r\n this._xrSessionManager.scene.needsPreviousWorldMatrices = true;\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = (engine as ThinEngine)._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);\r\n\r\n this._onAfterRenderObserver = this._xrSessionManager.scene.onAfterRenderObservable.add(() => this._onAfterRender());\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n this._xrSessionManager.scene.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n return super.detach();\r\n }\r\n\r\n private _onAfterRender(): void {\r\n if (this.attached && this._renderTargetTexture) {\r\n this._renderTargetTexture.render(false, false);\r\n }\r\n }\r\n\r\n public override dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n public override isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n public override dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRSpaceWarp.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRSpaceWarp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AAIvC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAM5D;;;;;;OAMG;IACH,YAAY,mBAAiC,EAAE,mBAAiC,EAAE,KAAa,EAAE,OAAuE,GAAG;QACvK,KAAK,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,sBAAsB,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAA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Y;QACxB,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,oBAAoB,IAAI,KAAK,CAAC;IAC5F,CAAC;IAEe,OAAO;QACnB,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAES,UAAU,CAAC,QAAiB;QAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO;QACX,CAAC;QAED,sEAAsE;QACtE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,oBAAqB,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;QACxH,IAAI,CAAC,oBAAqB,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;;AAnFD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,AAA9B,CAA+B;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,AAAJ,CAAK;AA6EvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,cAAc,CAAC,IAAI,EACnB,CAAC,gBAAgB,EAAE,EAAE;IACjB,OAAO,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAAC;AACtD,CAAC,EACD,cAAc,CAAC,OAAO,EACtB,KAAK,CACR,CAAC","sourcesContent":["import type { Engine } from \"../../Engines/engine\";\r\nimport type { WebGLRenderTargetWrapper } from \"../../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IWebXRRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { ShaderMaterial } from \"../../Materials/shaderMaterial\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Material } from \"../../Materials/material\";\r\nimport \"../../Shaders/velocity.fragment\";\r\nimport \"../../Shaders/velocity.vertex\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\n\r\n/**\r\n * Used for Space Warp render process\r\n */\r\nexport class XRSpaceWarpRenderTarget extends RenderTargetTexture {\r\n private _velocityMaterial: ShaderMaterial;\r\n private _originalPairing: Array<[AbstractMesh, Nullable<Material>]> = [];\r\n private _previousWorldMatrices: Array<Matrix> = [];\r\n private _previousTransforms: Matrix[] = [Matrix.Identity(), Matrix.Identity()];\r\n\r\n /**\r\n * Creates a Space Warp render target\r\n * @param motionVectorTexture WebGLTexture provided by WebGLSubImage\r\n * @param depthStencilTexture WebGLTexture provided by WebGLSubImage\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(motionVectorTexture: WebGLTexture, depthStencilTexture: WebGLTexture, scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"spacewarp rtt\", size, scene, false, true, Constants.TEXTURETYPE_HALF_FLOAT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = (this.getScene()!.getEngine() as Engine).createMultiviewRenderTargetTexture(\r\n this.getRenderWidth(),\r\n this.getRenderHeight(),\r\n motionVectorTexture,\r\n depthStencilTexture\r\n );\r\n (this._renderTarget as WebGLRenderTargetWrapper)._disposeOnlyFramebuffers = true;\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n\r\n if (scene) {\r\n this._velocityMaterial = new ShaderMaterial(\r\n \"velocity shader material\",\r\n scene,\r\n {\r\n vertex: \"velocity\",\r\n fragment: \"velocity\",\r\n },\r\n {\r\n uniforms: [\"world\", \"previousWorld\", \"viewProjection\", \"viewProjectionR\", \"previousViewProjection\", \"previousViewProjectionR\"],\r\n }\r\n );\r\n this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;\r\n this._velocityMaterial.onBindObservable.add((mesh) => {\r\n // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).\r\n // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter\r\n this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();\r\n this._velocityMaterial.getEffect().setMatrix(\"previousWorld\", this._previousWorldMatrices[mesh.uniqueId]);\r\n this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();\r\n // now set the scene's previous matrix\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjection\", this._previousTransforms[0]);\r\n // multiview for sure\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjectionR\", this._previousTransforms[1]);\r\n\r\n // store the previous (current, to be exact) transforms\r\n this._previousTransforms[0].copyFrom(scene.getTransformMatrix());\r\n this._previousTransforms[1].copyFrom(scene._transformMatrixR);\r\n });\r\n this._velocityMaterial.freeze();\r\n }\r\n }\r\n\r\n public override render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n for (const tuple of this._originalPairing) {\r\n tuple[0].material = tuple[1];\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n (this.getScene()!.getEngine() as Engine).bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public override getViewCount() {\r\n return 2;\r\n }\r\n\r\n public override dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(\r\n protected readonly _scene: Scene,\r\n protected readonly _xrSessionManager: WebXRSessionManager,\r\n protected readonly _xrWebGLBinding: XRWebGLBinding\r\n ) {\r\n this._engine = _scene.getEngine() as Engine;\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\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 * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n private _onAfterRenderObserver: Nullable<Observer<Scene>> = null;\r\n\r\n /**\r\n * constructor for the space warp feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"space-warp\";\r\n this._xrSessionManager.scene.needsPreviousWorldMatrices = true;\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = (engine as ThinEngine)._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);\r\n\r\n this._onAfterRenderObserver = this._xrSessionManager.scene.onAfterRenderObservable.add(() => this._onAfterRender());\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n this._xrSessionManager.scene.onAfterRenderObservable.remove(this._onAfterRenderObserver);\r\n return super.detach();\r\n }\r\n\r\n private _onAfterRender(): void {\r\n if (this.attached && this._renderTargetTexture) {\r\n this._renderTargetTexture.render(false, false);\r\n }\r\n }\r\n\r\n public override dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n public override isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n public override dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
|
|
@@ -73,7 +73,10 @@ export class WebXRAbstractMotionController {
|
|
|
73
73
|
this.onModelLoadedObservable = new Observable();
|
|
74
74
|
// initialize the components
|
|
75
75
|
if (layout.components) {
|
|
76
|
-
Object.keys(layout.components)
|
|
76
|
+
const keys = Object.keys(layout.components);
|
|
77
|
+
for (const key of keys) {
|
|
78
|
+
this._initComponent(key);
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
// Model is loaded in WebXRInput
|
|
79
82
|
}
|
|
@@ -81,11 +84,15 @@ export class WebXRAbstractMotionController {
|
|
|
81
84
|
* Dispose this controller, the model mesh and all its components
|
|
82
85
|
*/
|
|
83
86
|
dispose() {
|
|
84
|
-
|
|
87
|
+
const ids = this.getComponentIds();
|
|
88
|
+
for (const id of ids) {
|
|
89
|
+
this.getComponent(id).dispose();
|
|
90
|
+
}
|
|
85
91
|
if (this.rootMesh) {
|
|
86
|
-
this.rootMesh.getChildren(undefined, true)
|
|
92
|
+
const nodes = this.rootMesh.getChildren(undefined, true);
|
|
93
|
+
for (const node of nodes) {
|
|
87
94
|
node.setEnabled(false);
|
|
88
|
-
}
|
|
95
|
+
}
|
|
89
96
|
this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);
|
|
90
97
|
}
|
|
91
98
|
this.onModelLoadedObservable.clear();
|
|
@@ -164,7 +171,9 @@ export class WebXRAbstractMotionController {
|
|
|
164
171
|
return c.filename === loadingParams.filename && c.path === loadingParams.path;
|
|
165
172
|
});
|
|
166
173
|
if (found[0]) {
|
|
167
|
-
found[0].meshes
|
|
174
|
+
for (const mesh of found[0].meshes) {
|
|
175
|
+
mesh.setEnabled(true);
|
|
176
|
+
}
|
|
168
177
|
meshesLoaded(found[0].meshes);
|
|
169
178
|
return;
|
|
170
179
|
// found, don't continue to load
|
|
@@ -190,7 +199,9 @@ export class WebXRAbstractMotionController {
|
|
|
190
199
|
* @param xrFrame the current xr frame to use and update the model
|
|
191
200
|
*/
|
|
192
201
|
updateFromXRFrame(xrFrame) {
|
|
193
|
-
|
|
202
|
+
for (const id of this.getComponentIds()) {
|
|
203
|
+
this.getComponent(id).update(this.gamepadObject);
|
|
204
|
+
}
|
|
194
205
|
this.updateModel(xrFrame);
|
|
195
206
|
}
|
|
196
207
|
/**
|
|
@@ -262,12 +273,12 @@ export class WebXRAbstractMotionController {
|
|
|
262
273
|
}
|
|
263
274
|
_getGenericParentMesh(meshes) {
|
|
264
275
|
this.rootMesh = new Mesh(this.profileId + " " + this.handedness, this.scene);
|
|
265
|
-
|
|
276
|
+
for (const mesh of meshes) {
|
|
266
277
|
if (!mesh.parent) {
|
|
267
278
|
mesh.isPickable = false;
|
|
268
279
|
mesh.setParent(this.rootMesh);
|
|
269
280
|
}
|
|
270
|
-
}
|
|
281
|
+
}
|
|
271
282
|
this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);
|
|
272
283
|
}
|
|
273
284
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRAbstractMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRAbstractMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAyNzC;;;;GAIG;AACH,MAAM,OAAgB,6BAA6B;IA4C/C;;;;;;;;OAQG;IACH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AAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACf,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;gBACxB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC;CACJ","sourcesContent":["import type { IDisposable, Scene } from \"../../scene\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\n\r\n/**\r\n * Handedness type in xrInput profiles. These can be used to define layouts in the Layout Map.\r\n */\r\nexport type MotionControllerHandedness = \"none\" | \"left\" | \"right\";\r\n/**\r\n * The type of components available in motion controllers.\r\n * This is not the name of the component.\r\n */\r\nexport type MotionControllerComponentType = \"trigger\" | \"squeeze\" | \"touchpad\" | \"thumbstick\" | \"button\";\r\n\r\n/**\r\n * The state of a controller component\r\n */\r\nexport type MotionControllerComponentStateType = \"default\" | \"touched\" | \"pressed\";\r\n\r\n/**\r\n * The schema of motion controller layout.\r\n * No object will be initialized using this interface\r\n * This is used just to define the profile.\r\n */\r\nexport interface IMotionControllerLayout {\r\n /**\r\n * Path to load the assets. Usually relative to the base path\r\n */\r\n assetPath: string;\r\n /**\r\n * Available components (unsorted)\r\n */\r\n components: {\r\n /**\r\n * A map of component Ids\r\n */\r\n [componentId: string]: {\r\n /**\r\n * The type of input the component outputs\r\n */\r\n type: MotionControllerComponentType;\r\n /**\r\n * The indices of this component in the gamepad object\r\n */\r\n gamepadIndices: {\r\n /**\r\n * Index of button\r\n */\r\n button?: number;\r\n /**\r\n * If available, index of x-axis\r\n */\r\n xAxis?: number;\r\n /**\r\n * If available, index of y-axis\r\n */\r\n yAxis?: number;\r\n };\r\n /**\r\n * The mesh's root node name\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Animation definitions for this model\r\n */\r\n visualResponses: {\r\n [stateKey: string]: {\r\n /**\r\n * What property will be animated\r\n */\r\n componentProperty: \"xAxis\" | \"yAxis\" | \"button\" | \"state\";\r\n /**\r\n * What states influence this visual response\r\n */\r\n states: MotionControllerComponentStateType[];\r\n /**\r\n * Type of animation - movement or visibility\r\n */\r\n valueNodeProperty: \"transform\" | \"visibility\";\r\n /**\r\n * Base node name to move. Its position will be calculated according to the min and max nodes\r\n */\r\n valueNodeName?: string;\r\n /**\r\n * Minimum movement node\r\n */\r\n minNodeName?: string;\r\n /**\r\n * Max movement node\r\n */\r\n maxNodeName?: string;\r\n };\r\n };\r\n /**\r\n * If touch enabled, what is the name of node to display user feedback\r\n */\r\n touchPointNodeName?: string;\r\n };\r\n };\r\n /**\r\n * Is it xr standard mapping or not\r\n */\r\n gamepadMapping: \"\" | \"xr-standard\";\r\n /**\r\n * Base root node of this entire model\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Defines the main button component id\r\n */\r\n selectComponentId: string;\r\n}\r\n\r\n/**\r\n * A definition for the layout map in the input profile\r\n */\r\nexport interface IMotionControllerLayoutMap {\r\n /**\r\n * Layouts with handedness type as a key\r\n */\r\n [handedness: string /* handedness */]: IMotionControllerLayout;\r\n}\r\n\r\n/**\r\n * The XR Input profile schema\r\n * Profiles can be found here:\r\n * https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/registry/profiles\r\n */\r\nexport interface IMotionControllerProfile {\r\n /**\r\n * fallback profiles for this profileId\r\n */\r\n fallbackProfileIds: string[];\r\n /**\r\n * The layout map, with handedness as key\r\n */\r\n layouts: IMotionControllerLayoutMap;\r\n /**\r\n * The id of this profile\r\n * correlates to the profile(s) in the xrInput.profiles array\r\n */\r\n profileId: string;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller button animation\r\n * The meshes are provided to the _lerpButtonTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerButtonMeshMap {\r\n /**\r\n * the mesh that defines the pressed value mesh position.\r\n * This is used to find the max-position of this button\r\n */\r\n pressedMesh: AbstractMesh;\r\n /**\r\n * the mesh that defines the unpressed value mesh position.\r\n * This is used to find the min (or initial) position of this button\r\n */\r\n unpressedMesh: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when value changes\r\n */\r\n valueMesh: AbstractMesh;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller axis animation.\r\n * This will be expanded when touchpad animations are fully supported\r\n * The meshes are provided to the _lerpAxisTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerMeshMap {\r\n /**\r\n * the mesh that defines the maximum value mesh position.\r\n */\r\n maxMesh?: AbstractMesh;\r\n /**\r\n * the mesh that defines the minimum value mesh position.\r\n */\r\n minMesh?: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when axis value changes\r\n */\r\n valueMesh?: AbstractMesh;\r\n}\r\n\r\n/**\r\n * The elements needed for change-detection of the gamepad objects in motion controllers\r\n */\r\nexport interface IMinimalMotionControllerObject {\r\n /**\r\n * Available axes of this controller\r\n */\r\n axes: number[];\r\n /**\r\n * An array of available buttons\r\n */\r\n buttons: Array<{\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n }>;\r\n\r\n /**\r\n * EXPERIMENTAL haptic support.\r\n */\r\n hapticActuators?: Array<{\r\n pulse: (value: number, duration: number) => Promise<boolean>;\r\n }>;\r\n}\r\n\r\n/**\r\n * An Abstract Motion controller\r\n * This class receives an xrInput and a profile layout and uses those to initialize the components\r\n * Each component has an observable to check for changes in value and state\r\n */\r\nexport abstract class WebXRAbstractMotionController implements IDisposable {\r\n private _initComponent = (id: string) => {\r\n if (!id) {\r\n return;\r\n }\r\n const componentDef = this.layout.components[id];\r\n const type = componentDef.type;\r\n const buttonIndex = componentDef.gamepadIndices.button;\r\n // search for axes\r\n const axes: number[] = [];\r\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\r\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\r\n }\r\n\r\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\r\n };\r\n\r\n private _modelReady: boolean = false;\r\n\r\n /**\r\n * A map of components (WebXRControllerComponent) in this motion controller\r\n * Components have a ComponentType and can also have both button and axis definitions\r\n */\r\n public readonly components: {\r\n [id: string]: WebXRControllerComponent;\r\n } = {};\r\n\r\n /**\r\n * Disable the model's animation. Can be set at any time.\r\n */\r\n public disableAnimation: boolean = false;\r\n /**\r\n * Observers registered here will be triggered when the model of this controller is done loading\r\n */\r\n public onModelLoadedObservable: Observable<WebXRAbstractMotionController> = new Observable();\r\n /**\r\n * The profile id of this motion controller\r\n */\r\n public abstract profileId: string;\r\n /**\r\n * The root mesh of the model. It is null if the model was not yet initialized\r\n */\r\n public rootMesh: Nullable<AbstractMesh>;\r\n\r\n /**\r\n * constructs a new abstract motion controller\r\n * @param scene the scene to which the model of the controller will be added\r\n * @param layout The profile layout to load\r\n * @param gamepadObject The gamepad object correlating to this controller\r\n * @param handedness handedness (left/right/none) of this controller\r\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\r\n * @param _controllerCache a cache holding controller models already loaded in this session\r\n */\r\n constructor(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected scene: Scene,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected layout: IMotionControllerLayout,\r\n /**\r\n * The gamepad object correlating to this controller\r\n */\r\n public gamepadObject: IMinimalMotionControllerObject,\r\n /**\r\n * handedness (left/right/none) of this controller\r\n */\r\n public handedness: MotionControllerHandedness,\r\n /**\r\n * @internal\r\n * [false]\r\n */\r\n public _doNotLoadControllerMesh: boolean = false,\r\n private _controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n // initialize the components\r\n if (layout.components) {\r\n Object.keys(layout.components).forEach(this._initComponent);\r\n }\r\n // Model is loaded in WebXRInput\r\n }\r\n\r\n /**\r\n * Dispose this controller, the model mesh and all its components\r\n */\r\n public dispose(): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).dispose());\r\n if (this.rootMesh) {\r\n this.rootMesh.getChildren(undefined, true).forEach((node) => {\r\n node.setEnabled(false);\r\n });\r\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\r\n }\r\n this.onModelLoadedObservable.clear();\r\n }\r\n\r\n /**\r\n * Returns all components of specific type\r\n * @param type the type to search for\r\n * @returns an array of components with this type\r\n */\r\n public getAllComponentsOfType(type: MotionControllerComponentType): WebXRControllerComponent[] {\r\n return this.getComponentIds()\r\n .map((id) => this.components[id])\r\n .filter((component) => component.type === type);\r\n }\r\n\r\n /**\r\n * get a component based an its component id as defined in layout.components\r\n * @param id the id of the component\r\n * @returns the component correlates to the id or undefined if not found\r\n */\r\n public getComponent(id: string): WebXRControllerComponent {\r\n return this.components[id];\r\n }\r\n\r\n /**\r\n * Get the list of components available in this motion controller\r\n * @returns an array of strings correlating to available components\r\n */\r\n public getComponentIds(): string[] {\r\n return Object.keys(this.components);\r\n }\r\n\r\n /**\r\n * Get the first component of specific type\r\n * @param type type of component to find\r\n * @returns a controller component or null if not found\r\n */\r\n public getComponentOfType(type: MotionControllerComponentType): Nullable<WebXRControllerComponent> {\r\n return this.getAllComponentsOfType(type)[0] || null;\r\n }\r\n\r\n /**\r\n * Get the main (Select) component of this controller as defined in the layout\r\n * @returns the main component of this controller\r\n */\r\n public getMainComponent(): WebXRControllerComponent {\r\n return this.getComponent(this.layout.selectComponentId);\r\n }\r\n\r\n /**\r\n * Loads the model correlating to this controller\r\n * When the mesh is loaded, the onModelLoadedObservable will be triggered\r\n * @returns A promise fulfilled with the result of the model loading\r\n */\r\n public async loadModel(): Promise<boolean> {\r\n const useGeneric = !this._getModelLoadingConstraints();\r\n let loadingParams = this._getGenericFilenameAndPath();\r\n // Checking if GLB loader is present\r\n if (useGeneric) {\r\n Logger.Warn(\"Falling back to generic models\");\r\n } else {\r\n loadingParams = this._getFilenameAndPath();\r\n }\r\n return new Promise((resolve, reject) => {\r\n const meshesLoaded = (meshes: AbstractMesh[]) => {\r\n if (useGeneric) {\r\n this._getGenericParentMesh(meshes);\r\n } else {\r\n this._setRootMesh(meshes);\r\n }\r\n this._processLoadedModel(meshes);\r\n this._modelReady = true;\r\n this.onModelLoadedObservable.notifyObservers(this);\r\n resolve(true);\r\n };\r\n if (this._controllerCache) {\r\n // look for it in the cache\r\n const found = this._controllerCache.filter((c) => {\r\n return c.filename === loadingParams.filename && c.path === loadingParams.path;\r\n });\r\n if (found[0]) {\r\n found[0].meshes.forEach((mesh) => mesh.setEnabled(true));\r\n meshesLoaded(found[0].meshes);\r\n return;\r\n // found, don't continue to load\r\n }\r\n }\r\n SceneLoader.ImportMesh(\r\n \"\",\r\n loadingParams.path,\r\n loadingParams.filename,\r\n this.scene,\r\n (meshes) => {\r\n if (this._controllerCache) {\r\n this._controllerCache.push({\r\n ...loadingParams,\r\n meshes,\r\n });\r\n }\r\n meshesLoaded(meshes);\r\n },\r\n null,\r\n (_scene: Scene, message: string) => {\r\n Logger.Log(message);\r\n Logger.Warn(`Failed to retrieve controller model of type ${this.profileId} from the remote server: ${loadingParams.path}${loadingParams.filename}`);\r\n reject(message);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Update this model using the current XRFrame\r\n * @param xrFrame the current xr frame to use and update the model\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).update(this.gamepadObject));\r\n this.updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Backwards compatibility due to a deeply-integrated typo\r\n */\r\n public get handness() {\r\n return this.handedness;\r\n }\r\n\r\n /**\r\n * Pulse (vibrate) this controller\r\n * If the controller does not support pulses, this function will fail silently and return Promise<false> directly after called\r\n * Consecutive calls to this function will cancel the last pulse call\r\n *\r\n * @param value the strength of the pulse in 0.0...1.0 range\r\n * @param duration Duration of the pulse in milliseconds\r\n * @param hapticActuatorIndex optional index of actuator (will usually be 0)\r\n * @returns a promise that will send true when the pulse has ended and false if the device doesn't support pulse or an error accrued\r\n */\r\n public pulse(value: number, duration: number, hapticActuatorIndex: number = 0): Promise<boolean> {\r\n if (this.gamepadObject.hapticActuators && this.gamepadObject.hapticActuators[hapticActuatorIndex]) {\r\n return this.gamepadObject.hapticActuators[hapticActuatorIndex].pulse(value, duration);\r\n } else {\r\n return Promise.resolve(false);\r\n }\r\n }\r\n\r\n // Look through all children recursively. This will return null if no mesh exists with the given name.\r\n protected _getChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name === name, false)[0];\r\n }\r\n\r\n // Look through only immediate children. This will return null if no mesh exists with the given name.\r\n protected _getImmediateChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name == name, true)[0];\r\n }\r\n\r\n /**\r\n * Moves the axis on the controller mesh based on its current state\r\n * @param axisMap\r\n * @param axisValue the value of the axis which determines the meshes new position\r\n * @internal\r\n */\r\n protected _lerpTransform(axisMap: IMotionControllerMeshMap, axisValue: number, fixValueCoordinates?: boolean): void {\r\n if (!axisMap.minMesh || !axisMap.maxMesh || !axisMap.valueMesh) {\r\n return;\r\n }\r\n\r\n if (!axisMap.minMesh.rotationQuaternion || !axisMap.maxMesh.rotationQuaternion || !axisMap.valueMesh.rotationQuaternion) {\r\n return;\r\n }\r\n\r\n // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)\r\n const lerpValue = fixValueCoordinates ? axisValue * 0.5 + 0.5 : axisValue;\r\n Quaternion.SlerpToRef(axisMap.minMesh.rotationQuaternion, axisMap.maxMesh.rotationQuaternion, lerpValue, axisMap.valueMesh.rotationQuaternion);\r\n Vector3.LerpToRef(axisMap.minMesh.position, axisMap.maxMesh.position, lerpValue, axisMap.valueMesh.position);\r\n }\r\n\r\n /**\r\n * Update the model itself with the current frame data\r\n * @param xrFrame the frame to use for updating the model mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected updateModel(xrFrame: XRFrame): void {\r\n if (!this._modelReady) {\r\n return;\r\n }\r\n this._updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Get the filename and path for this controller's model\r\n * @returns a map of filename and path\r\n */\r\n protected abstract _getFilenameAndPath(): { filename: string; path: string };\r\n /**\r\n * This function is called before the mesh is loaded. It checks for loading constraints.\r\n * For example, this function can check if the GLB loader is available\r\n * If this function returns false, the generic controller will be loaded instead\r\n * @returns Is the client ready to load the mesh\r\n */\r\n protected abstract _getModelLoadingConstraints(): boolean;\r\n /**\r\n * This function will be called after the model was successfully loaded and can be used\r\n * for mesh transformations before it is available for the user\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _processLoadedModel(meshes: AbstractMesh[]): void;\r\n /**\r\n * Set the root mesh for this controller. Important for the WebXR controller class\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _setRootMesh(meshes: AbstractMesh[]): void;\r\n /**\r\n * A function executed each frame that updates the mesh (if needed)\r\n * @param xrFrame the current xrFrame\r\n */\r\n protected abstract _updateModel(xrFrame: XRFrame): void;\r\n\r\n private _getGenericFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n private _getGenericParentMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n meshes.forEach((mesh) => {\r\n if (!mesh.parent) {\r\n mesh.isPickable = false;\r\n mesh.setParent(this.rootMesh);\r\n }\r\n });\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRAbstractMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRAbstractMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAyNzC;;;;GAIG;AACH,MAAM,OAAgB,6BAA6B;IA4C/C;;;;;;;;OAQG;IACH;IACI,gEAAgE;IACtD,KAAY;IACtB,gEAAgE;IACtD,MAA+B;IACzC;;OAEG;IACI,aAA6C;IACpD;;OAEG;IACI,UAAsC;IAC7C;;;OAGG;IACI,2BAAoC,KAAK,EACxC,gBAIN;QApBQ,UAAK,GAAL,KAAK,CAAO;QAEZ,WAAM,GAAN,MAAM,CAAyB;QAIlC,kBAAa,GAAb,aAAa,CAAgC;QAI7C,eAAU,GAAV,UAAU,CAA4B;QAKtC,6BAAwB,GAAxB,wBAAwB,CAAiB;QACxC,qBAAgB,GAAhB,gBAAgB,CAItB;QA1EE,mBAAc,GAAG,CAAC,EAAU,EAAE,EAAE;YACpC,IAAI,CAAC,EAAE,EAAE,CAAC;gBACN,OAAO;YACX,CAAC;YACD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CA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ControllerComponent\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\n\r\n/**\r\n * Handedness type in xrInput profiles. These can be used to define layouts in the Layout Map.\r\n */\r\nexport type MotionControllerHandedness = \"none\" | \"left\" | \"right\";\r\n/**\r\n * The type of components available in motion controllers.\r\n * This is not the name of the component.\r\n */\r\nexport type MotionControllerComponentType = \"trigger\" | \"squeeze\" | \"touchpad\" | \"thumbstick\" | \"button\";\r\n\r\n/**\r\n * The state of a controller component\r\n */\r\nexport type MotionControllerComponentStateType = \"default\" | \"touched\" | \"pressed\";\r\n\r\n/**\r\n * The schema of motion controller layout.\r\n * No object will be initialized using this interface\r\n * This is used just to define the profile.\r\n */\r\nexport interface IMotionControllerLayout {\r\n /**\r\n * Path to load the assets. Usually relative to the base path\r\n */\r\n assetPath: string;\r\n /**\r\n * Available components (unsorted)\r\n */\r\n components: {\r\n /**\r\n * A map of component Ids\r\n */\r\n [componentId: string]: {\r\n /**\r\n * The type of input the component outputs\r\n */\r\n type: MotionControllerComponentType;\r\n /**\r\n * The indices of this component in the gamepad object\r\n */\r\n gamepadIndices: {\r\n /**\r\n * Index of button\r\n */\r\n button?: number;\r\n /**\r\n * If available, index of x-axis\r\n */\r\n xAxis?: number;\r\n /**\r\n * If available, index of y-axis\r\n */\r\n yAxis?: number;\r\n };\r\n /**\r\n * The mesh's root node name\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Animation definitions for this model\r\n */\r\n visualResponses: {\r\n [stateKey: string]: {\r\n /**\r\n * What property will be animated\r\n */\r\n componentProperty: \"xAxis\" | \"yAxis\" | \"button\" | \"state\";\r\n /**\r\n * What states influence this visual response\r\n */\r\n states: MotionControllerComponentStateType[];\r\n /**\r\n * Type of animation - movement or visibility\r\n */\r\n valueNodeProperty: \"transform\" | \"visibility\";\r\n /**\r\n * Base node name to move. Its position will be calculated according to the min and max nodes\r\n */\r\n valueNodeName?: string;\r\n /**\r\n * Minimum movement node\r\n */\r\n minNodeName?: string;\r\n /**\r\n * Max movement node\r\n */\r\n maxNodeName?: string;\r\n };\r\n };\r\n /**\r\n * If touch enabled, what is the name of node to display user feedback\r\n */\r\n touchPointNodeName?: string;\r\n };\r\n };\r\n /**\r\n * Is it xr standard mapping or not\r\n */\r\n gamepadMapping: \"\" | \"xr-standard\";\r\n /**\r\n * Base root node of this entire model\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Defines the main button component id\r\n */\r\n selectComponentId: string;\r\n}\r\n\r\n/**\r\n * A definition for the layout map in the input profile\r\n */\r\nexport interface IMotionControllerLayoutMap {\r\n /**\r\n * Layouts with handedness type as a key\r\n */\r\n [handedness: string /* handedness */]: IMotionControllerLayout;\r\n}\r\n\r\n/**\r\n * The XR Input profile schema\r\n * Profiles can be found here:\r\n * https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/registry/profiles\r\n */\r\nexport interface IMotionControllerProfile {\r\n /**\r\n * fallback profiles for this profileId\r\n */\r\n fallbackProfileIds: string[];\r\n /**\r\n * The layout map, with handedness as key\r\n */\r\n layouts: IMotionControllerLayoutMap;\r\n /**\r\n * The id of this profile\r\n * correlates to the profile(s) in the xrInput.profiles array\r\n */\r\n profileId: string;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller button animation\r\n * The meshes are provided to the _lerpButtonTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerButtonMeshMap {\r\n /**\r\n * the mesh that defines the pressed value mesh position.\r\n * This is used to find the max-position of this button\r\n */\r\n pressedMesh: AbstractMesh;\r\n /**\r\n * the mesh that defines the unpressed value mesh position.\r\n * This is used to find the min (or initial) position of this button\r\n */\r\n unpressedMesh: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when value changes\r\n */\r\n valueMesh: AbstractMesh;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller axis animation.\r\n * This will be expanded when touchpad animations are fully supported\r\n * The meshes are provided to the _lerpAxisTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerMeshMap {\r\n /**\r\n * the mesh that defines the maximum value mesh position.\r\n */\r\n maxMesh?: AbstractMesh;\r\n /**\r\n * the mesh that defines the minimum value mesh position.\r\n */\r\n minMesh?: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when axis value changes\r\n */\r\n valueMesh?: AbstractMesh;\r\n}\r\n\r\n/**\r\n * The elements needed for change-detection of the gamepad objects in motion controllers\r\n */\r\nexport interface IMinimalMotionControllerObject {\r\n /**\r\n * Available axes of this controller\r\n */\r\n axes: number[];\r\n /**\r\n * An array of available buttons\r\n */\r\n buttons: Array<{\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n }>;\r\n\r\n /**\r\n * EXPERIMENTAL haptic support.\r\n */\r\n hapticActuators?: Array<{\r\n pulse: (value: number, duration: number) => Promise<boolean>;\r\n }>;\r\n}\r\n\r\n/**\r\n * An Abstract Motion controller\r\n * This class receives an xrInput and a profile layout and uses those to initialize the components\r\n * Each component has an observable to check for changes in value and state\r\n */\r\nexport abstract class WebXRAbstractMotionController implements IDisposable {\r\n private _initComponent = (id: string) => {\r\n if (!id) {\r\n return;\r\n }\r\n const componentDef = this.layout.components[id];\r\n const type = componentDef.type;\r\n const buttonIndex = componentDef.gamepadIndices.button;\r\n // search for axes\r\n const axes: number[] = [];\r\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\r\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\r\n }\r\n\r\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\r\n };\r\n\r\n private _modelReady: boolean = false;\r\n\r\n /**\r\n * A map of components (WebXRControllerComponent) in this motion controller\r\n * Components have a ComponentType and can also have both button and axis definitions\r\n */\r\n public readonly components: {\r\n [id: string]: WebXRControllerComponent;\r\n } = {};\r\n\r\n /**\r\n * Disable the model's animation. Can be set at any time.\r\n */\r\n public disableAnimation: boolean = false;\r\n /**\r\n * Observers registered here will be triggered when the model of this controller is done loading\r\n */\r\n public onModelLoadedObservable: Observable<WebXRAbstractMotionController> = new Observable();\r\n /**\r\n * The profile id of this motion controller\r\n */\r\n public abstract profileId: string;\r\n /**\r\n * The root mesh of the model. It is null if the model was not yet initialized\r\n */\r\n public rootMesh: Nullable<AbstractMesh>;\r\n\r\n /**\r\n * constructs a new abstract motion controller\r\n * @param scene the scene to which the model of the controller will be added\r\n * @param layout The profile layout to load\r\n * @param gamepadObject The gamepad object correlating to this controller\r\n * @param handedness handedness (left/right/none) of this controller\r\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\r\n * @param _controllerCache a cache holding controller models already loaded in this session\r\n */\r\n constructor(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected scene: Scene,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected layout: IMotionControllerLayout,\r\n /**\r\n * The gamepad object correlating to this controller\r\n */\r\n public gamepadObject: IMinimalMotionControllerObject,\r\n /**\r\n * handedness (left/right/none) of this controller\r\n */\r\n public handedness: MotionControllerHandedness,\r\n /**\r\n * @internal\r\n * [false]\r\n */\r\n public _doNotLoadControllerMesh: boolean = false,\r\n private _controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n // initialize the components\r\n if (layout.components) {\r\n const keys = Object.keys(layout.components);\r\n for (const key of keys) {\r\n this._initComponent(key);\r\n }\r\n }\r\n // Model is loaded in WebXRInput\r\n }\r\n\r\n /**\r\n * Dispose this controller, the model mesh and all its components\r\n */\r\n public dispose(): void {\r\n const ids = this.getComponentIds();\r\n for (const id of ids) {\r\n this.getComponent(id).dispose();\r\n }\r\n if (this.rootMesh) {\r\n const nodes = this.rootMesh.getChildren(undefined, true);\r\n for (const node of nodes) {\r\n node.setEnabled(false);\r\n }\r\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\r\n }\r\n this.onModelLoadedObservable.clear();\r\n }\r\n\r\n /**\r\n * Returns all components of specific type\r\n * @param type the type to search for\r\n * @returns an array of components with this type\r\n */\r\n public getAllComponentsOfType(type: MotionControllerComponentType): WebXRControllerComponent[] {\r\n return this.getComponentIds()\r\n .map((id) => this.components[id])\r\n .filter((component) => component.type === type);\r\n }\r\n\r\n /**\r\n * get a component based an its component id as defined in layout.components\r\n * @param id the id of the component\r\n * @returns the component correlates to the id or undefined if not found\r\n */\r\n public getComponent(id: string): WebXRControllerComponent {\r\n return this.components[id];\r\n }\r\n\r\n /**\r\n * Get the list of components available in this motion controller\r\n * @returns an array of strings correlating to available components\r\n */\r\n public getComponentIds(): string[] {\r\n return Object.keys(this.components);\r\n }\r\n\r\n /**\r\n * Get the first component of specific type\r\n * @param type type of component to find\r\n * @returns a controller component or null if not found\r\n */\r\n public getComponentOfType(type: MotionControllerComponentType): Nullable<WebXRControllerComponent> {\r\n return this.getAllComponentsOfType(type)[0] || null;\r\n }\r\n\r\n /**\r\n * Get the main (Select) component of this controller as defined in the layout\r\n * @returns the main component of this controller\r\n */\r\n public getMainComponent(): WebXRControllerComponent {\r\n return this.getComponent(this.layout.selectComponentId);\r\n }\r\n\r\n /**\r\n * Loads the model correlating to this controller\r\n * When the mesh is loaded, the onModelLoadedObservable will be triggered\r\n * @returns A promise fulfilled with the result of the model loading\r\n */\r\n public async loadModel(): Promise<boolean> {\r\n const useGeneric = !this._getModelLoadingConstraints();\r\n let loadingParams = this._getGenericFilenameAndPath();\r\n // Checking if GLB loader is present\r\n if (useGeneric) {\r\n Logger.Warn(\"Falling back to generic models\");\r\n } else {\r\n loadingParams = this._getFilenameAndPath();\r\n }\r\n return new Promise((resolve, reject) => {\r\n const meshesLoaded = (meshes: AbstractMesh[]) => {\r\n if (useGeneric) {\r\n this._getGenericParentMesh(meshes);\r\n } else {\r\n this._setRootMesh(meshes);\r\n }\r\n this._processLoadedModel(meshes);\r\n this._modelReady = true;\r\n this.onModelLoadedObservable.notifyObservers(this);\r\n resolve(true);\r\n };\r\n if (this._controllerCache) {\r\n // look for it in the cache\r\n const found = this._controllerCache.filter((c) => {\r\n return c.filename === loadingParams.filename && c.path === loadingParams.path;\r\n });\r\n if (found[0]) {\r\n for (const mesh of found[0].meshes) {\r\n mesh.setEnabled(true);\r\n }\r\n meshesLoaded(found[0].meshes);\r\n return;\r\n // found, don't continue to load\r\n }\r\n }\r\n SceneLoader.ImportMesh(\r\n \"\",\r\n loadingParams.path,\r\n loadingParams.filename,\r\n this.scene,\r\n (meshes) => {\r\n if (this._controllerCache) {\r\n this._controllerCache.push({\r\n ...loadingParams,\r\n meshes,\r\n });\r\n }\r\n meshesLoaded(meshes);\r\n },\r\n null,\r\n (_scene: Scene, message: string) => {\r\n Logger.Log(message);\r\n Logger.Warn(`Failed to retrieve controller model of type ${this.profileId} from the remote server: ${loadingParams.path}${loadingParams.filename}`);\r\n reject(message);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Update this model using the current XRFrame\r\n * @param xrFrame the current xr frame to use and update the model\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame): void {\r\n for (const id of this.getComponentIds()) {\r\n this.getComponent(id).update(this.gamepadObject);\r\n }\r\n this.updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Backwards compatibility due to a deeply-integrated typo\r\n */\r\n public get handness() {\r\n return this.handedness;\r\n }\r\n\r\n /**\r\n * Pulse (vibrate) this controller\r\n * If the controller does not support pulses, this function will fail silently and return Promise<false> directly after called\r\n * Consecutive calls to this function will cancel the last pulse call\r\n *\r\n * @param value the strength of the pulse in 0.0...1.0 range\r\n * @param duration Duration of the pulse in milliseconds\r\n * @param hapticActuatorIndex optional index of actuator (will usually be 0)\r\n * @returns a promise that will send true when the pulse has ended and false if the device doesn't support pulse or an error accrued\r\n */\r\n public pulse(value: number, duration: number, hapticActuatorIndex: number = 0): Promise<boolean> {\r\n if (this.gamepadObject.hapticActuators && this.gamepadObject.hapticActuators[hapticActuatorIndex]) {\r\n return this.gamepadObject.hapticActuators[hapticActuatorIndex].pulse(value, duration);\r\n } else {\r\n return Promise.resolve(false);\r\n }\r\n }\r\n\r\n // Look through all children recursively. This will return null if no mesh exists with the given name.\r\n protected _getChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name === name, false)[0];\r\n }\r\n\r\n // Look through only immediate children. This will return null if no mesh exists with the given name.\r\n protected _getImmediateChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name == name, true)[0];\r\n }\r\n\r\n /**\r\n * Moves the axis on the controller mesh based on its current state\r\n * @param axisMap\r\n * @param axisValue the value of the axis which determines the meshes new position\r\n * @internal\r\n */\r\n protected _lerpTransform(axisMap: IMotionControllerMeshMap, axisValue: number, fixValueCoordinates?: boolean): void {\r\n if (!axisMap.minMesh || !axisMap.maxMesh || !axisMap.valueMesh) {\r\n return;\r\n }\r\n\r\n if (!axisMap.minMesh.rotationQuaternion || !axisMap.maxMesh.rotationQuaternion || !axisMap.valueMesh.rotationQuaternion) {\r\n return;\r\n }\r\n\r\n // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)\r\n const lerpValue = fixValueCoordinates ? axisValue * 0.5 + 0.5 : axisValue;\r\n Quaternion.SlerpToRef(axisMap.minMesh.rotationQuaternion, axisMap.maxMesh.rotationQuaternion, lerpValue, axisMap.valueMesh.rotationQuaternion);\r\n Vector3.LerpToRef(axisMap.minMesh.position, axisMap.maxMesh.position, lerpValue, axisMap.valueMesh.position);\r\n }\r\n\r\n /**\r\n * Update the model itself with the current frame data\r\n * @param xrFrame the frame to use for updating the model mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected updateModel(xrFrame: XRFrame): void {\r\n if (!this._modelReady) {\r\n return;\r\n }\r\n this._updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Get the filename and path for this controller's model\r\n * @returns a map of filename and path\r\n */\r\n protected abstract _getFilenameAndPath(): { filename: string; path: string };\r\n /**\r\n * This function is called before the mesh is loaded. It checks for loading constraints.\r\n * For example, this function can check if the GLB loader is available\r\n * If this function returns false, the generic controller will be loaded instead\r\n * @returns Is the client ready to load the mesh\r\n */\r\n protected abstract _getModelLoadingConstraints(): boolean;\r\n /**\r\n * This function will be called after the model was successfully loaded and can be used\r\n * for mesh transformations before it is available for the user\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _processLoadedModel(meshes: AbstractMesh[]): void;\r\n /**\r\n * Set the root mesh for this controller. Important for the WebXR controller class\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _setRootMesh(meshes: AbstractMesh[]): void;\r\n /**\r\n * A function executed each frame that updates the mesh (if needed)\r\n * @param xrFrame the current xrFrame\r\n */\r\n protected abstract _updateModel(xrFrame: XRFrame): void;\r\n\r\n private _getGenericFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n private _getGenericParentMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n for (const mesh of meshes) {\r\n if (!mesh.parent) {\r\n mesh.isPickable = false;\r\n mesh.setParent(this.rootMesh);\r\n }\r\n }\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n}\r\n"]}
|
|
@@ -24,12 +24,12 @@ export class WebXRGenericTriggerMotionController extends WebXRAbstractMotionCont
|
|
|
24
24
|
}
|
|
25
25
|
_setRootMesh(meshes) {
|
|
26
26
|
this.rootMesh = new Mesh(this.profileId + " " + this.handedness, this.scene);
|
|
27
|
-
|
|
27
|
+
for (const mesh of meshes) {
|
|
28
28
|
mesh.isPickable = false;
|
|
29
29
|
if (!mesh.parent) {
|
|
30
30
|
mesh.setParent(this.rootMesh);
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);
|
|
34
34
|
}
|
|
35
35
|
_updateModel() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRGenericMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRGenericMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,mCAAoC,SAAQ,6BAA6B;IAQlF,YAAY,KAAY,EAAE,aAA6C,EAAE,UAAsC;QAC3G,KAAK,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;QAHvE,cAAS,GAAG,mCAAmC,CAAC,SAAS,CAAC;IAIjE,CAAC;IAES,mBAAmB;QACzB,OAAO;YACH,QAAQ,EAAE,iBAAiB;YAC3B,IAAI,EAAE,4CAA4C;SACrD,CAAC;IACN,CAAC;IAES,2BAA2B;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,6DAA6D;IACnD,mBAAmB,CAAC,MAAsB;QAChD,gBAAgB;IACpB,CAAC;IAES,YAAY,CAAC,MAAsB;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAE7E,MAAM,
|
|
1
|
+
{"version":3,"file":"webXRGenericMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRGenericMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,mCAAoC,SAAQ,6BAA6B;IAQlF,YAAY,KAAY,EAAE,aAA6C,EAAE,UAAsC;QAC3G,KAAK,CAAC,KAAK,EAAE,oBAAoB,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;QAHvE,cAAS,GAAG,mCAAmC,CAAC,SAAS,CAAC;IAIjE,CAAC;IAES,mBAAmB;QACzB,OAAO;YACH,QAAQ,EAAE,iBAAiB;YAC3B,IAAI,EAAE,4CAA4C;SACrD,CAAC;IACN,CAAC;IAES,2BAA2B;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,6DAA6D;IACnD,mBAAmB,CAAC,MAAsB;QAChD,gBAAgB;IACpB,CAAC;IAES,YAAY,CAAC,MAAsB;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAE7E,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,UAA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MotionControllerLayoutMap } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\n\r\n/**\r\n * A generic trigger-only motion controller for WebXR\r\n */\r\nexport class WebXRGenericTriggerMotionController extends WebXRAbstractMotionController {\r\n /**\r\n * Static version of the profile id of this controller\r\n */\r\n public static ProfileId = \"generic-trigger\";\r\n\r\n public profileId = WebXRGenericTriggerMotionController.ProfileId;\r\n\r\n constructor(scene: Scene, gamepadObject: IMinimalMotionControllerObject, handedness: MotionControllerHandedness) {\r\n super(scene, GenericTriggerLayout[handedness], gamepadObject, handedness);\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n return true;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _processLoadedModel(meshes: AbstractMesh[]): void {\r\n // nothing to do\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n for (const mesh of meshes) {\r\n mesh.isPickable = false;\r\n if (!mesh.parent) {\r\n mesh.setParent(this.rootMesh);\r\n }\r\n }\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n\r\n protected _updateModel(): void {\r\n // no-op\r\n }\r\n}\r\n\r\n// https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/generic/generic-trigger-touchpad-thumbstick.json\r\nconst GenericTriggerLayout: IMotionControllerLayoutMap = {\r\n left: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"generic-trigger-left\",\r\n assetPath: \"left.glb\",\r\n },\r\n right: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"generic-trigger-right\",\r\n assetPath: \"right.glb\",\r\n },\r\n none: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"generic-trigger-none\",\r\n assetPath: \"none.glb\",\r\n },\r\n};\r\n"]}
|
|
@@ -28,7 +28,8 @@ export class WebXRHTCViveMotionController extends WebXRAbstractMotionController
|
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
_processLoadedModel(_meshes) {
|
|
31
|
-
this.getComponentIds()
|
|
31
|
+
const ids = this.getComponentIds();
|
|
32
|
+
for (const id of ids) {
|
|
32
33
|
const comp = id && this.getComponent(id);
|
|
33
34
|
if (comp) {
|
|
34
35
|
comp.onButtonStateChangedObservable.add((component) => {
|
|
@@ -46,13 +47,13 @@ export class WebXRHTCViveMotionController extends WebXRAbstractMotionController
|
|
|
46
47
|
}
|
|
47
48
|
}, undefined, true);
|
|
48
49
|
}
|
|
49
|
-
}
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
_setRootMesh(meshes) {
|
|
52
53
|
this.rootMesh = new Mesh(this.profileId + " " + this.handedness, this.scene);
|
|
53
|
-
|
|
54
|
+
for (const mesh of meshes) {
|
|
54
55
|
mesh.isPickable = false;
|
|
55
|
-
}
|
|
56
|
+
}
|
|
56
57
|
this._modelRootNode = meshes[1];
|
|
57
58
|
this._modelRootNode.parent = this.rootMesh;
|
|
58
59
|
if (!this.scene.useRightHandedSystem) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRHTCViveMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRHTCViveMotionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,6BAA6B;IAc3E;;;;;OAKG;IACH,YAAY,KAAY,EAAE,aAA6C,EAAE,UAAsC;QAC3G,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;QAThE,cAAS,GAAG,UAAU,CAAC;IAU9B,CAAC;IAES,mBAAmB;QACzB,MAAM,QAAQ,GAAG,4BAA4B,CAAC,cAAc,CAAC;QAC7D,MAAM,IAAI,GAAG,4BAA4B,CAAC,cAAc,CAAC;QAEzD,OAAO;YACH,QAAQ;YACR,IAAI;SACP,CAAC;IACN,CAAC;IAES,2BAA2B;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,mBAAmB,CAAC,OAAuB;QACjD,IAAI,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CA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;aACtB;YACD,sBAAsB,EAAE;gBACpB,IAAI,EAAE,UAAU;gBAChB,cAAc,EAAE;oBACZ,MAAM,EAAE,CAAC;oBACT,KAAK,EAAE,CAAC;oBACR,KAAK,EAAE,CAAC;iBACX;gBACD,YAAY,EAAE,sBAAsB;gBACpC,eAAe,EAAE,EAAE;aACtB;YACD,IAAI,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,cAAc,EAAE;oBACZ,MAAM,EAAE,CAAC;iBACZ;gBACD,YAAY,EAAE,MAAM;gBACpB,eAAe,EAAE,EAAE;aACtB;SACJ;QACD,cAAc,EAAE,aAAa;QAC7B,YAAY,EAAE,eAAe;QAC7B,SAAS,EAAE,UAAU;KACxB;CACJ,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { IMotionControllerLayoutMap, IMinimalMotionControllerObject, MotionControllerHandedness } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport { WebXRMotionControllerManager } from \"./webXRMotionControllerManager\";\r\n\r\n/**\r\n * The motion controller class for the standard HTC-Vive controllers\r\n */\r\nexport class WebXRHTCViveMotionController extends WebXRAbstractMotionController {\r\n private _modelRootNode: AbstractMesh;\r\n\r\n /**\r\n * The base url used to load the left and right controller models\r\n */\r\n public static MODEL_BASE_URL: string = \"https://controllers.babylonjs.com/vive/\";\r\n /**\r\n * File name for the controller model.\r\n */\r\n public static MODEL_FILENAME: string = \"wand.babylon\";\r\n\r\n public profileId = \"htc-vive\";\r\n\r\n /**\r\n * Create a new Vive motion controller object\r\n * @param scene the scene to use to create this controller\r\n * @param gamepadObject the corresponding gamepad object\r\n * @param handedness the handedness of the controller\r\n */\r\n constructor(scene: Scene, gamepadObject: IMinimalMotionControllerObject, handedness: MotionControllerHandedness) {\r\n super(scene, HTCViveLayout[handedness], gamepadObject, handedness);\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n const filename = WebXRHTCViveMotionController.MODEL_FILENAME;\r\n const path = WebXRHTCViveMotionController.MODEL_BASE_URL;\r\n\r\n return {\r\n filename,\r\n path,\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n return true;\r\n }\r\n\r\n protected _processLoadedModel(_meshes: AbstractMesh[]): void {\r\n this.getComponentIds().forEach((id) => {\r\n const comp = id && this.getComponent(id);\r\n if (comp) {\r\n comp.onButtonStateChangedObservable.add(\r\n (component) => {\r\n if (!this.rootMesh || this.disableAnimation) {\r\n return;\r\n }\r\n\r\n switch (id) {\r\n case \"xr-standard-trigger\":\r\n (<AbstractMesh>this._modelRootNode.getChildren()[6]).rotation.x = -component.value * 0.15;\r\n return;\r\n case \"xr-standard-touchpad\":\r\n return;\r\n case \"xr-standard-squeeze\":\r\n return;\r\n }\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n });\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n meshes.forEach((mesh) => {\r\n mesh.isPickable = false;\r\n });\r\n this._modelRootNode = meshes[1];\r\n this._modelRootNode.parent = this.rootMesh;\r\n if (!this.scene.useRightHandedSystem) {\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n }\r\n\r\n protected _updateModel(): void {\r\n // no-op. model is updated using observables.\r\n }\r\n}\r\n\r\n// register the profile\r\nWebXRMotionControllerManager.RegisterController(\"htc-vive\", (xrInput: XRInputSource, scene: Scene) => {\r\n return new WebXRHTCViveMotionController(scene, <any>xrInput.gamepad, xrInput.handedness);\r\n});\r\n\r\n// WebXRMotionControllerManager.RegisterController(\"htc-vive-legacy\", (xrInput: XRInputSource, scene: Scene) => {\r\n// return new WebXRHTCViveMotionController(scene, <any>(xrInput.gamepad), xrInput.handedness, true);\r\n// });\r\n\r\nconst HTCViveLayout: IMotionControllerLayoutMap = {\r\n left: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-squeeze\": {\r\n type: \"squeeze\",\r\n gamepadIndices: {\r\n button: 1,\r\n },\r\n rootNodeName: \"xr_standard_squeeze\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-touchpad\": {\r\n type: \"touchpad\",\r\n gamepadIndices: {\r\n button: 2,\r\n xAxis: 0,\r\n yAxis: 1,\r\n },\r\n rootNodeName: \"xr_standard_touchpad\",\r\n visualResponses: {},\r\n },\r\n menu: {\r\n type: \"button\",\r\n gamepadIndices: {\r\n button: 4,\r\n },\r\n rootNodeName: \"menu\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"htc_vive_none\",\r\n assetPath: \"none.glb\",\r\n },\r\n right: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-squeeze\": {\r\n type: \"squeeze\",\r\n gamepadIndices: {\r\n button: 1,\r\n },\r\n rootNodeName: \"xr_standard_squeeze\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-touchpad\": {\r\n type: \"touchpad\",\r\n gamepadIndices: {\r\n button: 2,\r\n xAxis: 0,\r\n yAxis: 1,\r\n },\r\n rootNodeName: \"xr_standard_touchpad\",\r\n visualResponses: {},\r\n },\r\n menu: {\r\n type: \"button\",\r\n gamepadIndices: {\r\n button: 4,\r\n },\r\n rootNodeName: \"menu\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"htc_vive_none\",\r\n assetPath: \"none.glb\",\r\n },\r\n none: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-squeeze\": {\r\n type: \"squeeze\",\r\n gamepadIndices: {\r\n button: 1,\r\n },\r\n rootNodeName: \"xr_standard_squeeze\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-touchpad\": {\r\n type: \"touchpad\",\r\n gamepadIndices: {\r\n button: 2,\r\n xAxis: 0,\r\n yAxis: 1,\r\n },\r\n rootNodeName: \"xr_standard_touchpad\",\r\n visualResponses: {},\r\n },\r\n menu: {\r\n type: \"button\",\r\n gamepadIndices: {\r\n button: 4,\r\n },\r\n rootNodeName: \"menu\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"htc-vive-none\",\r\n assetPath: \"none.glb\",\r\n },\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRHTCViveMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRHTCViveMotionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,6BAA6B;IAc3E;;;;;OAKG;IACH,YAAY,KAAY,EAAE,aAA6C,EAAE,UAAsC;QAC3G,KAAK,CAAC,KAAK,EAAE,aAAa,C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eAAe;QAC7B,SAAS,EAAE,UAAU;KACxB;IACD,IAAI,EAAE;QACF,iBAAiB,EAAE,qBAAqB;QACxC,UAAU,EAAE;YACR,qBAAqB,EAAE;gBACnB,IAAI,EAAE,SAAS;gBACf,cAAc,EAAE;oBACZ,MAAM,EAAE,CAAC;iBACZ;gBACD,YAAY,EAAE,qBAAqB;gBACnC,eAAe,EAAE,EAAE;aACtB;YACD,qBAAqB,EAAE;gBACnB,IAAI,EAAE,SAAS;gBACf,cAAc,EAAE;oBACZ,MAAM,EAAE,CAAC;iBACZ;gBACD,YAAY,EAAE,qBAAqB;gBACnC,eAAe,EAAE,EAAE;aACtB;YACD,sBAAsB,EAAE;gBACpB,IAAI,EAAE,UAAU;gBAChB,cAAc,EAAE;oBACZ,MAAM,EAAE,CAAC;oBACT,KAAK,EAAE,CAAC;oBACR,KAAK,EAAE,CAAC;iBACX;gBACD,YAAY,EAAE,sBAAsB;gBACpC,eAAe,EAAE,EAAE;aACtB;YACD,IAAI,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,cAAc,EAAE;oBACZ,MAAM,EAAE,CAAC;iBACZ;gBACD,YAAY,EAAE,MAAM;gBACpB,eAAe,EAAE,EAAE;aACtB;SACJ;QACD,cAAc,EAAE,aAAa;QAC7B,YAAY,EAAE,eAAe;QAC7B,SAAS,EAAE,UAAU;KACxB;CACJ,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { IMotionControllerLayoutMap, IMinimalMotionControllerObject, MotionControllerHandedness } from \"./webXRAbstractMotionController\";\r\nimport { WebXRAbstractMotionController } from \"./webXRAbstractMotionController\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport { WebXRMotionControllerManager } from \"./webXRMotionControllerManager\";\r\n\r\n/**\r\n * The motion controller class for the standard HTC-Vive controllers\r\n */\r\nexport class WebXRHTCViveMotionController extends WebXRAbstractMotionController {\r\n private _modelRootNode: AbstractMesh;\r\n\r\n /**\r\n * The base url used to load the left and right controller models\r\n */\r\n public static MODEL_BASE_URL: string = \"https://controllers.babylonjs.com/vive/\";\r\n /**\r\n * File name for the controller model.\r\n */\r\n public static MODEL_FILENAME: string = \"wand.babylon\";\r\n\r\n public profileId = \"htc-vive\";\r\n\r\n /**\r\n * Create a new Vive motion controller object\r\n * @param scene the scene to use to create this controller\r\n * @param gamepadObject the corresponding gamepad object\r\n * @param handedness the handedness of the controller\r\n */\r\n constructor(scene: Scene, gamepadObject: IMinimalMotionControllerObject, handedness: MotionControllerHandedness) {\r\n super(scene, HTCViveLayout[handedness], gamepadObject, handedness);\r\n }\r\n\r\n protected _getFilenameAndPath(): { filename: string; path: string } {\r\n const filename = WebXRHTCViveMotionController.MODEL_FILENAME;\r\n const path = WebXRHTCViveMotionController.MODEL_BASE_URL;\r\n\r\n return {\r\n filename,\r\n path,\r\n };\r\n }\r\n\r\n protected _getModelLoadingConstraints(): boolean {\r\n return true;\r\n }\r\n\r\n protected _processLoadedModel(_meshes: AbstractMesh[]): void {\r\n const ids = this.getComponentIds();\r\n\r\n for (const id of ids) {\r\n const comp = id && this.getComponent(id);\r\n if (comp) {\r\n comp.onButtonStateChangedObservable.add(\r\n (component) => {\r\n if (!this.rootMesh || this.disableAnimation) {\r\n return;\r\n }\r\n\r\n switch (id) {\r\n case \"xr-standard-trigger\":\r\n (<AbstractMesh>this._modelRootNode.getChildren()[6]).rotation.x = -component.value * 0.15;\r\n return;\r\n case \"xr-standard-touchpad\":\r\n return;\r\n case \"xr-standard-squeeze\":\r\n return;\r\n }\r\n },\r\n undefined,\r\n true\r\n );\r\n }\r\n }\r\n }\r\n\r\n protected _setRootMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n for (const mesh of meshes) {\r\n mesh.isPickable = false;\r\n }\r\n this._modelRootNode = meshes[1];\r\n this._modelRootNode.parent = this.rootMesh;\r\n if (!this.scene.useRightHandedSystem) {\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n }\r\n\r\n protected _updateModel(): void {\r\n // no-op. model is updated using observables.\r\n }\r\n}\r\n\r\n// register the profile\r\nWebXRMotionControllerManager.RegisterController(\"htc-vive\", (xrInput: XRInputSource, scene: Scene) => {\r\n return new WebXRHTCViveMotionController(scene, <any>xrInput.gamepad, xrInput.handedness);\r\n});\r\n\r\n// WebXRMotionControllerManager.RegisterController(\"htc-vive-legacy\", (xrInput: XRInputSource, scene: Scene) => {\r\n// return new WebXRHTCViveMotionController(scene, <any>(xrInput.gamepad), xrInput.handedness, true);\r\n// });\r\n\r\nconst HTCViveLayout: IMotionControllerLayoutMap = {\r\n left: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-squeeze\": {\r\n type: \"squeeze\",\r\n gamepadIndices: {\r\n button: 1,\r\n },\r\n rootNodeName: \"xr_standard_squeeze\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-touchpad\": {\r\n type: \"touchpad\",\r\n gamepadIndices: {\r\n button: 2,\r\n xAxis: 0,\r\n yAxis: 1,\r\n },\r\n rootNodeName: \"xr_standard_touchpad\",\r\n visualResponses: {},\r\n },\r\n menu: {\r\n type: \"button\",\r\n gamepadIndices: {\r\n button: 4,\r\n },\r\n rootNodeName: \"menu\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"htc_vive_none\",\r\n assetPath: \"none.glb\",\r\n },\r\n right: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-squeeze\": {\r\n type: \"squeeze\",\r\n gamepadIndices: {\r\n button: 1,\r\n },\r\n rootNodeName: \"xr_standard_squeeze\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-touchpad\": {\r\n type: \"touchpad\",\r\n gamepadIndices: {\r\n button: 2,\r\n xAxis: 0,\r\n yAxis: 1,\r\n },\r\n rootNodeName: \"xr_standard_touchpad\",\r\n visualResponses: {},\r\n },\r\n menu: {\r\n type: \"button\",\r\n gamepadIndices: {\r\n button: 4,\r\n },\r\n rootNodeName: \"menu\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"htc_vive_none\",\r\n assetPath: \"none.glb\",\r\n },\r\n none: {\r\n selectComponentId: \"xr-standard-trigger\",\r\n components: {\r\n \"xr-standard-trigger\": {\r\n type: \"trigger\",\r\n gamepadIndices: {\r\n button: 0,\r\n },\r\n rootNodeName: \"xr_standard_trigger\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-squeeze\": {\r\n type: \"squeeze\",\r\n gamepadIndices: {\r\n button: 1,\r\n },\r\n rootNodeName: \"xr_standard_squeeze\",\r\n visualResponses: {},\r\n },\r\n \"xr-standard-touchpad\": {\r\n type: \"touchpad\",\r\n gamepadIndices: {\r\n button: 2,\r\n xAxis: 0,\r\n yAxis: 1,\r\n },\r\n rootNodeName: \"xr_standard_touchpad\",\r\n visualResponses: {},\r\n },\r\n menu: {\r\n type: \"button\",\r\n gamepadIndices: {\r\n button: 4,\r\n },\r\n rootNodeName: \"menu\",\r\n visualResponses: {},\r\n },\r\n },\r\n gamepadMapping: \"xr-standard\",\r\n rootNodeName: \"htc-vive-none\",\r\n assetPath: \"none.glb\",\r\n },\r\n};\r\n"]}
|