@babylonjs/core 8.3.1 → 8.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/Animations/animation.d.ts +4 -0
  2. package/Animations/animation.js +22 -13
  3. package/Animations/animation.js.map +1 -1
  4. package/Animations/animation.optimizations.d.ts +31 -0
  5. package/Animations/animation.optimizations.js +41 -0
  6. package/Animations/animation.optimizations.js.map +1 -0
  7. package/Animations/index.d.ts +1 -0
  8. package/Animations/index.js +1 -0
  9. package/Animations/index.js.map +1 -1
  10. package/Animations/pathCursor.js +3 -1
  11. package/Animations/pathCursor.js.map +1 -1
  12. package/Animations/runtimeAnimation.d.ts +3 -1
  13. package/Animations/runtimeAnimation.js +127 -116
  14. package/Animations/runtimeAnimation.js.map +1 -1
  15. package/Audio/audioSceneComponent.js +4 -4
  16. package/Audio/audioSceneComponent.js.map +1 -1
  17. package/Behaviors/Meshes/attachToBoxBehavior.js +6 -6
  18. package/Behaviors/Meshes/attachToBoxBehavior.js.map +1 -1
  19. package/Behaviors/Meshes/fadeInOutBehavior.js +3 -2
  20. package/Behaviors/Meshes/fadeInOutBehavior.js.map +1 -1
  21. package/Behaviors/Meshes/multiPointerScaleBehavior.js +6 -4
  22. package/Behaviors/Meshes/multiPointerScaleBehavior.js.map +1 -1
  23. package/Behaviors/Meshes/sixDofDragBehavior.js +3 -2
  24. package/Behaviors/Meshes/sixDofDragBehavior.js.map +1 -1
  25. package/Bones/skeleton.js +6 -6
  26. package/Bones/skeleton.js.map +1 -1
  27. package/Cameras/Inputs/followCameraKeyboardMoveInput.js +2 -2
  28. package/Cameras/Inputs/followCameraKeyboardMoveInput.js.map +1 -1
  29. package/Cameras/VR/vrExperienceHelper.js +2 -2
  30. package/Cameras/VR/vrExperienceHelper.js.map +1 -1
  31. package/Cameras/arcRotateCamera.js +6 -2
  32. package/Cameras/arcRotateCamera.js.map +1 -1
  33. package/Cameras/camera.js +2 -2
  34. package/Cameras/camera.js.map +1 -1
  35. package/Cameras/deviceOrientationCamera.js +3 -2
  36. package/Cameras/deviceOrientationCamera.js.map +1 -1
  37. package/Collisions/gpuPicker.d.ts +1 -0
  38. package/Collisions/gpuPicker.js +14 -4
  39. package/Collisions/gpuPicker.js.map +1 -1
  40. package/Debug/axesViewer.js +3 -2
  41. package/Debug/axesViewer.js.map +1 -1
  42. package/Debug/directionalLightFrustumViewer.js +4 -4
  43. package/Debug/directionalLightFrustumViewer.js.map +1 -1
  44. package/Debug/physicsViewer.js +7 -6
  45. package/Debug/physicsViewer.js.map +1 -1
  46. package/Debug/skeletonViewer.js +4 -4
  47. package/Debug/skeletonViewer.js.map +1 -1
  48. package/Engines/Processors/shaderCodeNode.js +2 -2
  49. package/Engines/Processors/shaderCodeNode.js.map +1 -1
  50. package/Engines/abstractEngine.d.ts +1 -0
  51. package/Engines/abstractEngine.js +14 -8
  52. package/Engines/abstractEngine.js.map +1 -1
  53. package/Engines/constants.d.ts +27 -5
  54. package/Engines/constants.js +27 -5
  55. package/Engines/constants.js.map +1 -1
  56. package/Engines/engine.js +8 -8
  57. package/Engines/engine.js.map +1 -1
  58. package/Engines/webgpuEngine.js +6 -2
  59. package/Engines/webgpuEngine.js.map +1 -1
  60. package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.js +2 -2
  61. package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.js.map +1 -1
  62. package/FlowGraph/Blocks/Data/flowGraphDataSwitchBlock.js +3 -2
  63. package/FlowGraph/Blocks/Data/flowGraphDataSwitchBlock.js.map +1 -1
  64. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js +3 -2
  65. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js.map +1 -1
  66. package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.js +2 -2
  67. package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.js.map +1 -1
  68. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSwitchBlock.js +3 -2
  69. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSwitchBlock.js.map +1 -1
  70. package/FlowGraph/flowGraphAsyncExecutionBlock.js +5 -3
  71. package/FlowGraph/flowGraphAsyncExecutionBlock.js.map +1 -1
  72. package/FlowGraph/flowGraphBlock.js +3 -2
  73. package/FlowGraph/flowGraphBlock.js.map +1 -1
  74. package/FlowGraph/flowGraphCoordinator.js +10 -6
  75. package/FlowGraph/flowGraphCoordinator.js.map +1 -1
  76. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +2 -2
  77. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
  78. package/FrameGraph/Node/nodeRenderGraphBlock.js +5 -4
  79. package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
  80. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +4 -3
  81. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
  82. package/Gamepads/gamepadManager.js +2 -2
  83. package/Gamepads/gamepadManager.js.map +1 -1
  84. package/Gizmos/axisDragGizmo.js +3 -2
  85. package/Gizmos/axisDragGizmo.js.map +1 -1
  86. package/Gizmos/axisScaleGizmo.js +6 -4
  87. package/Gizmos/axisScaleGizmo.js.map +1 -1
  88. package/Gizmos/boundingBoxGizmo.js +28 -26
  89. package/Gizmos/boundingBoxGizmo.js.map +1 -1
  90. package/Gizmos/cameraGizmo.js +6 -3
  91. package/Gizmos/cameraGizmo.js.map +1 -1
  92. package/Gizmos/gizmo.js +11 -10
  93. package/Gizmos/gizmo.js.map +1 -1
  94. package/Gizmos/gizmoManager.js +16 -12
  95. package/Gizmos/gizmoManager.js.map +1 -1
  96. package/Gizmos/lightGizmo.js +3 -2
  97. package/Gizmos/lightGizmo.js.map +1 -1
  98. package/Gizmos/planeDragGizmo.js +3 -2
  99. package/Gizmos/planeDragGizmo.js.map +1 -1
  100. package/Gizmos/planeRotationGizmo.js +3 -2
  101. package/Gizmos/planeRotationGizmo.js.map +1 -1
  102. package/Gizmos/positionGizmo.js +41 -28
  103. package/Gizmos/positionGizmo.js.map +1 -1
  104. package/Gizmos/rotationGizmo.js +26 -18
  105. package/Gizmos/rotationGizmo.js.map +1 -1
  106. package/Gizmos/scaleGizmo.js +47 -32
  107. package/Gizmos/scaleGizmo.js.map +1 -1
  108. package/Layers/effectLayerSceneComponent.js +4 -4
  109. package/Layers/effectLayerSceneComponent.js.map +1 -1
  110. package/Layers/layerSceneComponent.js +4 -4
  111. package/Layers/layerSceneComponent.js.map +1 -1
  112. package/LensFlares/lensFlareSystemSceneComponent.js +4 -4
  113. package/LensFlares/lensFlareSystemSceneComponent.js.map +1 -1
  114. package/Lights/Shadows/shadowGenerator.js +3 -3
  115. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  116. package/Lights/light.js +4 -4
  117. package/Lights/light.js.map +1 -1
  118. package/Loading/Plugins/babylonFileLoader.js +54 -46
  119. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  120. package/Loading/loadingScreen.js +4 -3
  121. package/Loading/loadingScreen.js.map +1 -1
  122. package/Loading/sceneLoader.js +15 -12
  123. package/Loading/sceneLoader.js.map +1 -1
  124. package/Materials/Node/Blocks/Dual/currentScreenBlock.js +9 -3
  125. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  126. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +11 -0
  127. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  128. package/Materials/Node/Blocks/Input/inputBlock.js +18 -31
  129. package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
  130. package/Materials/Node/Blocks/baseMathBlock.js +3 -1
  131. package/Materials/Node/Blocks/baseMathBlock.js.map +1 -1
  132. package/Materials/Node/Blocks/customBlock.js +53 -43
  133. package/Materials/Node/Blocks/customBlock.js.map +1 -1
  134. package/Materials/Node/Enums/nodeMaterialModes.d.ts +3 -1
  135. package/Materials/Node/Enums/nodeMaterialModes.js +2 -0
  136. package/Materials/Node/Enums/nodeMaterialModes.js.map +1 -1
  137. package/Materials/Node/nodeMaterial.d.ts +5 -0
  138. package/Materials/Node/nodeMaterial.js +33 -20
  139. package/Materials/Node/nodeMaterial.js.map +1 -1
  140. package/Materials/Node/nodeMaterialBlock.js +7 -4
  141. package/Materials/Node/nodeMaterialBlock.js.map +1 -1
  142. package/Materials/Node/nodeMaterialBuildState.d.ts +13 -2
  143. package/Materials/Node/nodeMaterialBuildState.js +72 -7
  144. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  145. package/Materials/Node/nodeMaterialDefault.d.ts +5 -0
  146. package/Materials/Node/nodeMaterialDefault.js +28 -0
  147. package/Materials/Node/nodeMaterialDefault.js.map +1 -1
  148. package/Materials/Textures/cubeTexture.js +3 -1
  149. package/Materials/Textures/cubeTexture.js.map +1 -1
  150. package/Materials/Textures/videoTexture.js +5 -4
  151. package/Materials/Textures/videoTexture.js.map +1 -1
  152. package/Materials/materialDefines.js +3 -1
  153. package/Materials/materialDefines.js.map +1 -1
  154. package/Materials/multiMaterial.js +3 -1
  155. package/Materials/multiMaterial.js.map +1 -1
  156. package/Materials/shaderMaterial.js +3 -2
  157. package/Materials/shaderMaterial.js.map +1 -1
  158. package/Materials/shadowDepthWrapper.js +6 -0
  159. package/Materials/shadowDepthWrapper.js.map +1 -1
  160. package/Materials/uniformBuffer.js +4 -0
  161. package/Materials/uniformBuffer.js.map +1 -1
  162. package/Meshes/Compression/dracoEncoder.js +2 -2
  163. package/Meshes/Compression/dracoEncoder.js.map +1 -1
  164. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +32 -15
  165. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  166. package/Meshes/GreasedLine/greasedLineMesh.js +6 -6
  167. package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
  168. package/Meshes/GreasedLine/greasedLineRibbonMesh.js +4 -3
  169. package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
  170. package/Meshes/Node/Blocks/mathBlock.js +3 -1
  171. package/Meshes/Node/Blocks/mathBlock.js.map +1 -1
  172. package/Meshes/Node/nodeGeometryBlock.js +8 -5
  173. package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
  174. package/Meshes/abstractMesh.js +2 -2
  175. package/Meshes/abstractMesh.js.map +1 -1
  176. package/Meshes/geodesicMesh.js +2 -2
  177. package/Meshes/geodesicMesh.js.map +1 -1
  178. package/Meshes/mesh.js +6 -6
  179. package/Meshes/mesh.js.map +1 -1
  180. package/Meshes/mesh.vertexData.functions.js +11 -10
  181. package/Meshes/mesh.vertexData.functions.js.map +1 -1
  182. package/Meshes/mesh.vertexData.subdivide.js +10 -10
  183. package/Meshes/mesh.vertexData.subdivide.js.map +1 -1
  184. package/Meshes/meshSimplification.js +10 -10
  185. package/Meshes/meshSimplification.js.map +1 -1
  186. package/Meshes/meshUtils.js +6 -3
  187. package/Meshes/meshUtils.js.map +1 -1
  188. package/Meshes/polygonMesh.js +10 -10
  189. package/Meshes/polygonMesh.js.map +1 -1
  190. package/Misc/PerformanceViewer/performanceViewerCollector.js +4 -4
  191. package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
  192. package/Misc/arrayTools.js +2 -2
  193. package/Misc/arrayTools.js.map +1 -1
  194. package/Misc/asyncLock.js +9 -9
  195. package/Misc/asyncLock.js.map +1 -1
  196. package/Misc/basis.js +4 -2
  197. package/Misc/basis.js.map +1 -1
  198. package/Misc/deepCopier.js +3 -2
  199. package/Misc/deepCopier.js.map +1 -1
  200. package/Misc/deepMerger.js +3 -2
  201. package/Misc/deepMerger.js.map +1 -1
  202. package/Misc/fileTools.js +4 -4
  203. package/Misc/fileTools.js.map +1 -1
  204. package/Misc/greasedLineTools.js +14 -13
  205. package/Misc/greasedLineTools.js.map +1 -1
  206. package/Misc/logger.js +3 -2
  207. package/Misc/logger.js.map +1 -1
  208. package/Misc/observable.d.ts +3 -2
  209. package/Misc/observable.extensions.js +4 -4
  210. package/Misc/observable.extensions.js.map +1 -1
  211. package/Misc/observable.js +5 -4
  212. package/Misc/observable.js.map +1 -1
  213. package/Misc/sceneSerializer.js +5 -4
  214. package/Misc/sceneSerializer.js.map +1 -1
  215. package/Misc/snapshotRenderingHelper.js +3 -1
  216. package/Misc/snapshotRenderingHelper.js.map +1 -1
  217. package/Misc/tags.js +2 -2
  218. package/Misc/tags.js.map +1 -1
  219. package/Misc/trajectoryClassifier.js +8 -8
  220. package/Misc/trajectoryClassifier.js.map +1 -1
  221. package/Particles/IParticleSystem.d.ts +1 -1
  222. package/Particles/IParticleSystem.js.map +1 -1
  223. package/Particles/baseParticleSystem.d.ts +11 -3
  224. package/Particles/baseParticleSystem.js +37 -3
  225. package/Particles/baseParticleSystem.js.map +1 -1
  226. package/Particles/gpuParticleSystem.js +1 -14
  227. package/Particles/gpuParticleSystem.js.map +1 -1
  228. package/Particles/particle.js +2 -2
  229. package/Particles/particle.js.map +1 -1
  230. package/Particles/particleSystem.js +15 -13
  231. package/Particles/particleSystem.js.map +1 -1
  232. package/Particles/thinParticleSystem.js +3 -16
  233. package/Particles/thinParticleSystem.js.map +1 -1
  234. package/Physics/physicsHelper.js +18 -14
  235. package/Physics/physicsHelper.js.map +1 -1
  236. package/Physics/v1/Plugins/ammoJSPlugin.js +10 -8
  237. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  238. package/Physics/v1/Plugins/cannonJSPlugin.js +13 -8
  239. package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -1
  240. package/Physics/v1/Plugins/oimoJSPlugin.js +9 -8
  241. package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -1
  242. package/Physics/v1/physicsEngine.js +4 -4
  243. package/Physics/v1/physicsEngine.js.map +1 -1
  244. package/Physics/v1/physicsImpostor.js +10 -21
  245. package/Physics/v1/physicsImpostor.js.map +1 -1
  246. package/Physics/v2/Plugins/havokPlugin.js +12 -10
  247. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  248. package/Physics/v2/ragdoll.js +4 -4
  249. package/Physics/v2/ragdoll.js.map +1 -1
  250. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js +3 -2
  251. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
  252. package/PostProcesses/RenderPipeline/postProcessRenderEffect.js +8 -6
  253. package/PostProcesses/RenderPipeline/postProcessRenderEffect.js.map +1 -1
  254. package/PostProcesses/depthOfFieldMergePostProcess.js +4 -3
  255. package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
  256. package/Rendering/GlobalIllumination/giRSMManager.js +6 -6
  257. package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
  258. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +14 -14
  259. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
  260. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +14 -12
  261. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
  262. package/Rendering/iblCdfGenerator.js +4 -4
  263. package/Rendering/iblCdfGenerator.js.map +1 -1
  264. package/Rendering/objectRenderer.js +2 -2
  265. package/Rendering/objectRenderer.js.map +1 -1
  266. package/Rendering/reflectiveShadowMap.js +7 -5
  267. package/Rendering/reflectiveShadowMap.js.map +1 -1
  268. package/ShadersWGSL/gaussianSplatting.vertex.js +1 -1
  269. package/ShadersWGSL/gaussianSplatting.vertex.js.map +1 -1
  270. package/Sprites/spriteMap.js +2 -2
  271. package/Sprites/spriteMap.js.map +1 -1
  272. package/XR/features/WebXRAbstractFeature.js +2 -2
  273. package/XR/features/WebXRAbstractFeature.js.map +1 -1
  274. package/XR/features/WebXRAnchorSystem.js +4 -4
  275. package/XR/features/WebXRAnchorSystem.js.map +1 -1
  276. package/XR/features/WebXRBackgroundRemover.js +3 -1
  277. package/XR/features/WebXRBackgroundRemover.js.map +1 -1
  278. package/XR/features/WebXRControllerMovement.js +6 -3
  279. package/XR/features/WebXRControllerMovement.js.map +1 -1
  280. package/XR/features/WebXRControllerPhysics.js +12 -7
  281. package/XR/features/WebXRControllerPhysics.js.map +1 -1
  282. package/XR/features/WebXRControllerPointerSelection.js +12 -7
  283. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  284. package/XR/features/WebXRControllerTeleportation.js +11 -7
  285. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  286. package/XR/features/WebXRDepthSensing.js +6 -6
  287. package/XR/features/WebXRDepthSensing.js.map +1 -1
  288. package/XR/features/WebXRHandTracking.js +60 -24
  289. package/XR/features/WebXRHandTracking.js.map +1 -1
  290. package/XR/features/WebXRHitTest.js +4 -4
  291. package/XR/features/WebXRHitTest.js.map +1 -1
  292. package/XR/features/WebXRImageTracking.js +2 -2
  293. package/XR/features/WebXRImageTracking.js.map +1 -1
  294. package/XR/features/WebXRLayers.js +2 -2
  295. package/XR/features/WebXRLayers.js.map +1 -1
  296. package/XR/features/WebXRNearInteraction.js +12 -7
  297. package/XR/features/WebXRNearInteraction.js.map +1 -1
  298. package/XR/features/WebXRRawCameraAccess.js +9 -4
  299. package/XR/features/WebXRRawCameraAccess.js.map +1 -1
  300. package/XR/features/WebXRSpaceWarp.js +2 -2
  301. package/XR/features/WebXRSpaceWarp.js.map +1 -1
  302. package/XR/motionController/webXRAbstractMotionController.js +19 -8
  303. package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
  304. package/XR/motionController/webXRGenericMotionController.js +2 -2
  305. package/XR/motionController/webXRGenericMotionController.js.map +1 -1
  306. package/XR/motionController/webXRHTCViveMotionController.js +5 -4
  307. package/XR/motionController/webXRHTCViveMotionController.js.map +1 -1
  308. package/XR/motionController/webXRMicrosoftMixedRealityController.js +9 -6
  309. package/XR/motionController/webXRMicrosoftMixedRealityController.js.map +1 -1
  310. package/XR/motionController/webXRMotionControllerManager.js +4 -4
  311. package/XR/motionController/webXRMotionControllerManager.js.map +1 -1
  312. package/XR/motionController/webXROculusTouchMotionController.js +5 -4
  313. package/XR/motionController/webXROculusTouchMotionController.js.map +1 -1
  314. package/XR/motionController/webXRProfiledMotionController.js +15 -10
  315. package/XR/motionController/webXRProfiledMotionController.js.map +1 -1
  316. package/XR/webXRCamera.js +3 -2
  317. package/XR/webXRCamera.js.map +1 -1
  318. package/XR/webXREnterExitUI.js +5 -4
  319. package/XR/webXREnterExitUI.js.map +1 -1
  320. package/XR/webXRExperienceHelper.js +2 -2
  321. package/XR/webXRExperienceHelper.js.map +1 -1
  322. package/XR/webXRFeaturesManager.js +10 -7
  323. package/XR/webXRFeaturesManager.js.map +1 -1
  324. package/XR/webXRInput.js +8 -8
  325. package/XR/webXRInput.js.map +1 -1
  326. package/XR/webXRInputSource.js +4 -1
  327. package/XR/webXRInputSource.js.map +1 -1
  328. package/XR/webXRRenderTargetTextureProvider.js +3 -1
  329. package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
  330. package/assetContainer.js +156 -135
  331. package/assetContainer.js.map +1 -1
  332. package/node.js +2 -2
  333. package/node.js.map +1 -1
  334. package/package.json +1 -1
  335. package/scene.js +18 -11
  336. package/scene.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAsEtC;;GAEG;AACH,MAAM,OAAO,gBAAgB;;AACzB;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;AAC1D;;GAEG;AACoB,mCAAkB,GAAG,uBAAuB,CAAC;AACpE;;GAEG;AACoB,yBAAQ,GAAG,aAAa,CAAC;AAChD;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,oCAAmB,GAAG,uBAAuB,CAAC;AACrE;;GAEG;AACoB,gCAAe,GAAG,oBAAoB,CAAC;AAC9D;;GAEG;AACoB,kCAA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AqB,CAAC,mBAAmB,CAAC;YACrE,IAAI,UAAU,EAAE,CAAC;gBACb,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;oBACnB,aAAa,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC;oBACtE,IAAI,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;wBAC5D,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACpD,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,aAAa,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC;oBACtE,IAAI,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;wBAC5D,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACpD,CAAC;gBACL,CAAC;YACL,CAAC;YACD,IAAI,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE,CAAC;gBAC1D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE,CAAC;gBACjF,aAAa,GAAG;oBACZ,GAAG,aAAa;oBAChB,GAAG,QAAQ;iBACd,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;;AA9UuB,uCAAkB,GAMtC,EAAE,AANoC,CAMnC;AAWP;;GAEG;AACqB,yCAAoB,GAA8B;IACtE,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,QAAQ;IAC3D,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,aAAa;CAC9D,AAH2C,CAG1C","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Observable } from \"core/Misc/observable\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;\r\n\r\n /**\r\n * Triggered when the feature is attached\r\n */\r\n onFeatureAttachObservable: Observable<IWebXRFeature>;\r\n /**\r\n * Triggered when the feature is detached\r\n */\r\n onFeatureDetachObservable: Observable<IWebXRFeature>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\";\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\";\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\";\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\";\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\";\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\";\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\";\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\";\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\";\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\";\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\";\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\";\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\";\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\";\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\";\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\";\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\";\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\";\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\";\r\n /**\r\n * The name of the WebXR Space Warp feature\r\n */\r\n public static readonly SPACE_WARP = \"xr-space-warp\";\r\n /**\r\n * The name of the WebXR Raw Camera Access feature\r\n */\r\n public static readonly RAW_CAMERA_ACCESS = \"xr-raw-camera-access\";\r\n}\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n });\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n this.getEnabledFeatures().forEach((featureName) => {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n const attached = feature.featureImplementation.attach();\r\n if (!attached) {\r\n Tools.Warn(`Feature ${featureName} failed to attach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n const detached = feature.featureImplementation.detach();\r\n if (!detached) {\r\n Tools.Warn(`Feature ${featureName} failed to detach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n this.getEnabledFeatures().forEach((feature) => {\r\n this.disableFeature(feature);\r\n });\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: string | { Name: string },\r\n version: number | string = \"latest\",\r\n moduleOptions: any = {},\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): IWebXRFeature {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature(featureName: string): IWebXRFeature {\r\n return this._features[featureName] && this._features[featureName].featureImplementation;\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit> {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRFeaturesManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRFeaturesManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAsEtC;;GAEG;AACH,MAAM,OAAO,gBAAgB;;AACzB;;GAEG;AACoB,8BAAa,GAAG,kBAAkB,CAAC;AAC1D;;GAEG;AACoB,mCAAkB,GAAG,uBAAuB,CAAC;AACpE;;GAEG;AACoB,yBAAQ,GAAG,aAAa,CAAC;AAChD;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;AACoB,oCAAmB,GAAG,uBAAuB,CAAC;AACrE;;GAEG;AACoB,gCAAe,GAAG,oBAAoB,CAAC;AAC9D;;GAEG;AACoB,kCAAiB,GAAG,iCAAiC,CAAC;AAC7E;;GAEG;AACoB,8BAAa,GAAG,6BAA6B,CAAC;AACrE;;GAEG;AACoB,+BAAc,GAAG,mBAAmB,CAAC;AAC5D;;GAEG;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,CAAC,QAAQ,EAAE,CAAC;oBACnB,aAAa,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC;oBACtE,IAAI,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;wBAC5D,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACpD,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,aAAa,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC;oBACtE,IAAI,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;wBAC5D,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACpD,CAAC;gBACL,CAAC;YACL,CAAC;YACD,IAAI,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE,CAAC;gBAC1D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC,yBAAyB,EAAE,CAAC;gBACjF,aAAa,GAAG;oBACZ,GAAG,aAAa;oBAChB,GAAG,QAAQ;iBACd,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;;AAjVuB,uCAAkB,GAMtC,EAAE,AANoC,CAMnC;AAWP;;GAEG;AACqB,yCAAoB,GAA8B;IACtE,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC,QAAQ;IAC3D,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,aAAa;CAC9D,AAH2C,CAG1C","sourcesContent":["import type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { Observable } from \"core/Misc/observable\";\r\n\r\n/**\r\n * Defining the interface required for a (webxr) feature\r\n */\r\nexport interface IWebXRFeature extends IDisposable {\r\n /**\r\n * Is this feature attached\r\n */\r\n attached: boolean;\r\n /**\r\n * Should auto-attach be disabled?\r\n */\r\n disableAutoAttach: boolean;\r\n\r\n /**\r\n * Attach the feature to the session\r\n * Will usually be called by the features manager\r\n *\r\n * @param force should attachment be forced (even when already attached)\r\n * @returns true if successful.\r\n */\r\n attach(force?: boolean): boolean;\r\n /**\r\n * Detach the feature from the session\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n detach(): boolean;\r\n\r\n /**\r\n * This function will be executed during before enabling the feature and can be used to not-allow enabling it.\r\n * Note that at this point the session has NOT started, so this is purely checking if the browser supports it\r\n *\r\n * @returns whether or not the feature is compatible in this environment\r\n */\r\n isCompatible(): boolean;\r\n\r\n /**\r\n * Was this feature disposed;\r\n */\r\n isDisposed: boolean;\r\n\r\n /**\r\n * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)\r\n */\r\n xrNativeFeatureName?: string;\r\n\r\n /**\r\n * A list of (Babylon WebXR) features this feature depends on\r\n */\r\n dependsOn?: string[];\r\n\r\n /**\r\n * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object\r\n */\r\n getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;\r\n\r\n /**\r\n * Triggered when the feature is attached\r\n */\r\n onFeatureAttachObservable: Observable<IWebXRFeature>;\r\n /**\r\n * Triggered when the feature is detached\r\n */\r\n onFeatureDetachObservable: Observable<IWebXRFeature>;\r\n}\r\n\r\n/**\r\n * A list of the currently available features without referencing them\r\n */\r\nexport class WebXRFeatureName {\r\n /**\r\n * The name of the anchor system feature\r\n */\r\n public static readonly ANCHOR_SYSTEM = \"xr-anchor-system\";\r\n /**\r\n * The name of the background remover feature\r\n */\r\n public static readonly BACKGROUND_REMOVER = \"xr-background-remover\";\r\n /**\r\n * The name of the hit test feature\r\n */\r\n public static readonly HIT_TEST = \"xr-hit-test\";\r\n /**\r\n * The name of the mesh detection feature\r\n */\r\n public static readonly MESH_DETECTION = \"xr-mesh-detection\";\r\n /**\r\n * physics impostors for xr controllers feature\r\n */\r\n public static readonly PHYSICS_CONTROLLERS = \"xr-physics-controller\";\r\n /**\r\n * The name of the plane detection feature\r\n */\r\n public static readonly PLANE_DETECTION = \"xr-plane-detection\";\r\n /**\r\n * The name of the pointer selection feature\r\n */\r\n public static readonly POINTER_SELECTION = \"xr-controller-pointer-selection\";\r\n /**\r\n * The name of the teleportation feature\r\n */\r\n public static readonly TELEPORTATION = \"xr-controller-teleportation\";\r\n /**\r\n * The name of the feature points feature.\r\n */\r\n public static readonly FEATURE_POINTS = \"xr-feature-points\";\r\n /**\r\n * The name of the hand tracking feature.\r\n */\r\n public static readonly HAND_TRACKING = \"xr-hand-tracking\";\r\n /**\r\n * The name of the image tracking feature\r\n */\r\n public static readonly IMAGE_TRACKING = \"xr-image-tracking\";\r\n /**\r\n * The name of the near interaction feature\r\n */\r\n public static readonly NEAR_INTERACTION = \"xr-near-interaction\";\r\n /**\r\n * The name of the DOM overlay feature\r\n */\r\n public static readonly DOM_OVERLAY = \"xr-dom-overlay\";\r\n /**\r\n * The name of the movement feature\r\n */\r\n public static readonly MOVEMENT = \"xr-controller-movement\";\r\n /**\r\n * The name of the light estimation feature\r\n */\r\n public static readonly LIGHT_ESTIMATION = \"xr-light-estimation\";\r\n /**\r\n * The name of the eye tracking feature\r\n */\r\n public static readonly EYE_TRACKING = \"xr-eye-tracking\";\r\n /**\r\n * The name of the walking locomotion feature\r\n */\r\n public static readonly WALKING_LOCOMOTION = \"xr-walking-locomotion\";\r\n /**\r\n * The name of the composition layers feature\r\n */\r\n public static readonly LAYERS = \"xr-layers\";\r\n /**\r\n * The name of the depth sensing feature\r\n */\r\n public static readonly DEPTH_SENSING = \"xr-depth-sensing\";\r\n /**\r\n * The name of the WebXR Space Warp feature\r\n */\r\n public static readonly SPACE_WARP = \"xr-space-warp\";\r\n /**\r\n * The name of the WebXR Raw Camera Access feature\r\n */\r\n public static readonly RAW_CAMERA_ACCESS = \"xr-raw-camera-access\";\r\n}\r\n\r\n/**\r\n * Defining the constructor of a feature. Used to register the modules.\r\n */\r\nexport type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;\r\n\r\n/**\r\n * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.\r\n * It is mainly used in AR sessions.\r\n *\r\n * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).\r\n */\r\nexport class WebXRFeaturesManager implements IDisposable {\r\n private static readonly _AvailableFeatures: {\r\n [name: string]: {\r\n stable: number;\r\n latest: number;\r\n [version: number]: WebXRFeatureConstructor;\r\n };\r\n } = {};\r\n\r\n private _features: {\r\n [name: string]: {\r\n featureImplementation: IWebXRFeature;\r\n version: number;\r\n enabled: boolean;\r\n required: boolean;\r\n };\r\n } = {};\r\n\r\n /**\r\n * The key is the feature to check and the value is the feature that conflicts.\r\n */\r\n private static readonly _ConflictingFeatures: { [key: string]: string } = {\r\n [WebXRFeatureName.TELEPORTATION]: WebXRFeatureName.MOVEMENT,\r\n [WebXRFeatureName.MOVEMENT]: WebXRFeatureName.TELEPORTATION,\r\n };\r\n\r\n /**\r\n * constructs a new features manages.\r\n *\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n */\r\n constructor(private _xrSessionManager: WebXRSessionManager) {\r\n // when session starts / initialized - attach\r\n this._xrSessionManager.onXRSessionInit.add(() => {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && !feature.featureImplementation.attached && !feature.featureImplementation.disableAutoAttach) {\r\n this.attachFeature(featureName);\r\n }\r\n }\r\n });\r\n\r\n // when session ends - detach\r\n this._xrSessionManager.onXRSessionEnded.add(() => {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n const feature = this._features[featureName];\r\n if (feature.enabled && feature.featureImplementation.attached) {\r\n // detach, but don't disable!\r\n this.detachFeature(featureName);\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Used to register a module. After calling this function a developer can use this feature in the scene.\r\n * Mainly used internally.\r\n *\r\n * @param featureName the name of the feature to register\r\n * @param constructorFunction the function used to construct the module\r\n * @param version the (babylon) version of the module\r\n * @param stable is that a stable version of this module\r\n */\r\n public static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version: number = 1, stable: boolean = false) {\r\n this._AvailableFeatures[featureName] = this._AvailableFeatures[featureName] || { latest: version };\r\n if (version > this._AvailableFeatures[featureName].latest) {\r\n this._AvailableFeatures[featureName].latest = version;\r\n }\r\n if (stable) {\r\n this._AvailableFeatures[featureName].stable = version;\r\n }\r\n this._AvailableFeatures[featureName][version] = constructorFunction;\r\n }\r\n\r\n /**\r\n * Returns a constructor of a specific feature.\r\n *\r\n * @param featureName the name of the feature to construct\r\n * @param version the version of the feature to load\r\n * @param xrSessionManager the xrSessionManager. Used to construct the module\r\n * @param options optional options provided to the module.\r\n * @returns a function that, when called, will return a new instance of this feature\r\n */\r\n public static ConstructFeature(featureName: string, version: number = 1, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature {\r\n const constructorFunction = this._AvailableFeatures[featureName][version];\r\n if (!constructorFunction) {\r\n // throw an error? return nothing?\r\n throw new Error(\"feature not found\");\r\n }\r\n\r\n return constructorFunction(xrSessionManager, options);\r\n }\r\n\r\n /**\r\n * Can be used to return the list of features currently registered\r\n *\r\n * @returns an Array of available features\r\n */\r\n public static GetAvailableFeatures() {\r\n return Object.keys(this._AvailableFeatures);\r\n }\r\n\r\n /**\r\n * Gets the versions available for a specific feature\r\n * @param featureName the name of the feature\r\n * @returns an array with the available versions\r\n */\r\n public static GetAvailableVersions(featureName: string) {\r\n return Object.keys(this._AvailableFeatures[featureName]);\r\n }\r\n\r\n /**\r\n * Return the latest unstable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetLatestVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].latest) || -1;\r\n }\r\n\r\n /**\r\n * Return the latest stable version of this feature\r\n * @param featureName the name of the feature to search\r\n * @returns the version number. if not found will return -1\r\n */\r\n public static GetStableVersionOfFeature(featureName: string): number {\r\n return (this._AvailableFeatures[featureName] && this._AvailableFeatures[featureName].stable) || -1;\r\n }\r\n\r\n /**\r\n * Attach a feature to the current session. Mainly used when session started to start the feature effect.\r\n * Can be used during a session to start a feature\r\n * @param featureName the name of feature to attach\r\n */\r\n public attachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.enabled && !feature.featureImplementation.attached) {\r\n const attached = feature.featureImplementation.attach();\r\n if (!attached) {\r\n Tools.Warn(`Feature ${featureName} failed to attach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Can be used inside a session or when the session ends to detach a specific feature\r\n * @param featureName the name of the feature to detach\r\n */\r\n public detachFeature(featureName: string) {\r\n const feature = this._features[featureName];\r\n if (feature && feature.featureImplementation.attached) {\r\n const detached = feature.featureImplementation.detach();\r\n if (!detached) {\r\n Tools.Warn(`Feature ${featureName} failed to detach`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Used to disable an already-enabled feature\r\n * The feature will be disposed and will be recreated once enabled.\r\n * @param featureName the feature to disable\r\n * @returns true if disable was successful\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public disableFeature(featureName: string | { Name: string }): boolean {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n const feature = this._features[name];\r\n if (feature && feature.enabled) {\r\n feature.enabled = false;\r\n this.detachFeature(name);\r\n feature.featureImplementation.dispose();\r\n delete this._features[name];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * dispose this features manager\r\n */\r\n public dispose(): void {\r\n const features = this.getEnabledFeatures();\r\n for (const featureName of features) {\r\n this.disableFeature(featureName);\r\n }\r\n }\r\n\r\n /**\r\n * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.\r\n * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.\r\n *\r\n * @param featureName the name of the feature to load or the class of the feature\r\n * @param version optional version to load. if not provided the latest version will be enabled\r\n * @param moduleOptions options provided to the module. Ses the module documentation / constructor\r\n * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible\r\n * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.\r\n * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.\r\n */\r\n public enableFeature(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n featureName: string | { Name: string },\r\n version: number | string = \"latest\",\r\n moduleOptions: any = {},\r\n attachIfPossible: boolean = true,\r\n required: boolean = true\r\n ): IWebXRFeature {\r\n const name = typeof featureName === \"string\" ? featureName : featureName.Name;\r\n let versionToLoad = 0;\r\n if (typeof version === \"string\") {\r\n if (!version) {\r\n throw new Error(`Error in provided version - ${name} (${version})`);\r\n }\r\n if (version === \"stable\") {\r\n versionToLoad = WebXRFeaturesManager.GetStableVersionOfFeature(name);\r\n } else if (version === \"latest\") {\r\n versionToLoad = WebXRFeaturesManager.GetLatestVersionOfFeature(name);\r\n } else {\r\n // try loading the number the string represents\r\n versionToLoad = +version;\r\n }\r\n if (versionToLoad === -1 || isNaN(versionToLoad)) {\r\n throw new Error(`feature not found - ${name} (${version})`);\r\n }\r\n } else {\r\n versionToLoad = version;\r\n }\r\n\r\n // check if there is a feature conflict\r\n const conflictingFeature = WebXRFeaturesManager._ConflictingFeatures[name];\r\n if (conflictingFeature !== undefined && this.getEnabledFeatures().indexOf(conflictingFeature) !== -1) {\r\n throw new Error(`Feature ${name} cannot be enabled while ${conflictingFeature} is enabled.`);\r\n }\r\n\r\n // check if already initialized\r\n const feature = this._features[name];\r\n const constructFunction = WebXRFeaturesManager.ConstructFeature(name, versionToLoad, this._xrSessionManager, moduleOptions);\r\n if (!constructFunction) {\r\n // report error?\r\n throw new Error(`feature not found - ${name}`);\r\n }\r\n\r\n /* If the feature is already enabled, detach and dispose it, and create a new one */\r\n if (feature) {\r\n this.disableFeature(name);\r\n }\r\n\r\n const constructed = constructFunction();\r\n if (constructed.dependsOn) {\r\n const dependentsFound = constructed.dependsOn.every((featureName) => !!this._features[featureName]);\r\n if (!dependentsFound) {\r\n throw new Error(`Dependant features missing. Make sure the following features are enabled - ${constructed.dependsOn.join(\", \")}`);\r\n }\r\n }\r\n if (constructed.isCompatible()) {\r\n this._features[name] = {\r\n featureImplementation: constructed,\r\n enabled: true,\r\n version: versionToLoad,\r\n required,\r\n };\r\n\r\n if (attachIfPossible) {\r\n // if session started already, request and enable\r\n if (this._xrSessionManager.session && !this._features[name].featureImplementation.attached) {\r\n // enable feature\r\n this.attachFeature(name);\r\n }\r\n } else {\r\n // disable auto-attach when session starts\r\n this._features[name].featureImplementation.disableAutoAttach = true;\r\n }\r\n\r\n return this._features[name].featureImplementation;\r\n } else {\r\n if (required) {\r\n throw new Error(\"required feature not compatible\");\r\n } else {\r\n Tools.Warn(`Feature ${name} not compatible with the current environment/browser and was not enabled.`);\r\n return constructed;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * get the implementation of an enabled feature.\r\n * @param featureName the name of the feature to load\r\n * @returns the feature class, if found\r\n */\r\n public getEnabledFeature(featureName: string): IWebXRFeature {\r\n return this._features[featureName] && this._features[featureName].featureImplementation;\r\n }\r\n\r\n /**\r\n * Get the list of enabled features\r\n * @returns an array of enabled features\r\n */\r\n public getEnabledFeatures() {\r\n return Object.keys(this._features);\r\n }\r\n\r\n /**\r\n * This function will extend the session creation configuration object with enabled features.\r\n * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,\r\n * according to the defined \"required\" variable, provided during enableFeature call\r\n * @param xrSessionInit the xr Session init object to extend\r\n *\r\n * @returns an extended XRSessionInit object\r\n */\r\n public async _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit> {\r\n const enabledFeatures = this.getEnabledFeatures();\r\n for (const featureName of enabledFeatures) {\r\n const feature = this._features[featureName];\r\n const nativeName = feature.featureImplementation.xrNativeFeatureName;\r\n if (nativeName) {\r\n if (feature.required) {\r\n xrSessionInit.requiredFeatures = xrSessionInit.requiredFeatures || [];\r\n if (xrSessionInit.requiredFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.requiredFeatures.push(nativeName);\r\n }\r\n } else {\r\n xrSessionInit.optionalFeatures = xrSessionInit.optionalFeatures || [];\r\n if (xrSessionInit.optionalFeatures.indexOf(nativeName) === -1) {\r\n xrSessionInit.optionalFeatures.push(nativeName);\r\n }\r\n }\r\n }\r\n if (feature.featureImplementation.getXRSessionInitExtension) {\r\n const extended = await feature.featureImplementation.getXRSessionInitExtension();\r\n xrSessionInit = {\r\n ...xrSessionInit,\r\n ...extended,\r\n };\r\n }\r\n }\r\n return xrSessionInit;\r\n }\r\n}\r\n"]}
package/XR/webXRInput.js CHANGED
@@ -49,9 +49,9 @@ export class WebXRInput {
49
49
  });
50
50
  this._frameObserver = this.xrSessionManager.onXRFrameObservable.add((frame) => {
51
51
  // Update controller pose info
52
- this.controllers.forEach((controller) => {
52
+ for (const controller of this.controllers) {
53
53
  controller.updateFromXRFrame(frame, this.xrSessionManager.referenceSpace, this.xrCamera, this.xrSessionManager);
54
- });
54
+ }
55
55
  });
56
56
  if (this._options.customControllersRepositoryURL) {
57
57
  WebXRMotionControllerManager.BaseRepositoryUrl = this._options.customControllersRepositoryURL;
@@ -89,27 +89,27 @@ export class WebXRInput {
89
89
  // Remove and dispose of controllers to be disposed
90
90
  const keepControllers = [];
91
91
  const removedControllers = [];
92
- this.controllers.forEach((c) => {
92
+ for (const c of this.controllers) {
93
93
  if (removeInputs.indexOf(c.inputSource) === -1) {
94
94
  keepControllers.push(c);
95
95
  }
96
96
  else {
97
97
  removedControllers.push(c);
98
98
  }
99
- });
99
+ }
100
100
  this.controllers = keepControllers;
101
- removedControllers.forEach((c) => {
101
+ for (const c of removedControllers) {
102
102
  this.onControllerRemovedObservable.notifyObservers(c);
103
103
  c.dispose();
104
- });
104
+ }
105
105
  }
106
106
  /**
107
107
  * Disposes of the object
108
108
  */
109
109
  dispose() {
110
- this.controllers.forEach((c) => {
110
+ for (const c of this.controllers) {
111
111
  c.dispose();
112
- });
112
+ }
113
113
  this.xrSessionManager.onXRFrameObservable.remove(this._frameObserver);
114
114
  this.xrSessionManager.onXRSessionInit.remove(this._sessionInitObserver);
115
115
  this.xrSessionManager.onXRSessionEnded.remove(this._sessionEndedObserver);
@@ -1 +1 @@
1
- {"version":3,"file":"webXRInput.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRInput.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAwC/F;;GAEG;AACH,MAAM,OAAO,UAAU;IAiBnB;;;;;OAKG;IACH;IACI;;OAEG;IACI,gBAAqC;IAC5C;;OAEG;IACI,QAAqB,EACX,WAA+B,EAAE;QAL3C,qBAAgB,GAAhB,gBAAgB,CAAqB;QAIrC,aAAQ,GAAR,QAAQ,CAAa;QACX,aAAQ,GAAR,QAAQ,CAAyB;QA/BtD;;WAEG;QACI,gBAAW,GAA4B,EAAE,CAAC;QAIjD;;WAEG;QACI,gCAA2B,GAAG,IAAI,UAAU,EAAoB,CAAC;QACxE;;WAEG;QACI,kCAA6B,GAAG,IAAI,UAAU,EAAoB,CAAC;QAyDlE,0BAAqB,GAAG,CAAC,KAA+B,EAAE,EAAE;YAChE,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9D,CAAC,CAAC;QAxCE,qCAAqC;QACrC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,CAAC,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I,CAAC,CAAC,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACJ,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,WAAW,GAAG,eAAe,CAAC;QACnC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,IAAI,CAAC,6BAA6B,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACtD,CAAC,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC3B,CAAC,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACxE,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC1E,IAAI,CAAC,2BAA2B,CAAC,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC,6BAA6B,CAAC,KAAK,EAAE,CAAC;QAE3C,6BAA6B;QAC7B,4BAA4B,CAAC,oBAAoB,EAAE,CAAC;IACxD,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport type { IWebXRControllerOptions } from \"./webXRInputSource\";\r\nimport { WebXRInputSource } from \"./webXRInputSource\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\n\r\n/**\r\n * The schema for initialization options of the XR Input class\r\n */\r\nexport interface IWebXRInputOptions {\r\n /**\r\n * If set to true no model will be automatically loaded\r\n */\r\n doNotLoadControllerMeshes?: boolean;\r\n\r\n /**\r\n * If set, this profile will be used for all controllers loaded (for example \"microsoft-mixed-reality\")\r\n * If not found, the xr input profile data will be used.\r\n * Profiles are defined here - https://github.com/immersive-web/webxr-input-profiles/\r\n */\r\n forceInputProfile?: string;\r\n\r\n /**\r\n * Do not send a request to the controller repository to load the profile.\r\n *\r\n * Instead, use the controllers available in babylon itself.\r\n */\r\n disableOnlineControllerRepository?: boolean;\r\n\r\n /**\r\n * A custom URL for the controllers repository\r\n */\r\n customControllersRepositoryURL?: string;\r\n\r\n /**\r\n * Should the controller model's components not move according to the user input\r\n */\r\n disableControllerAnimation?: boolean;\r\n\r\n /**\r\n * Optional options to pass to the controller. Will be overridden by the Input options where applicable\r\n */\r\n controllerOptions?: IWebXRControllerOptions;\r\n}\r\n/**\r\n * XR input used to track XR inputs such as controllers/rays\r\n */\r\nexport class WebXRInput implements IDisposable {\r\n /**\r\n * XR controllers being tracked\r\n */\r\n public controllers: Array<WebXRInputSource> = [];\r\n private _frameObserver: Nullable<Observer<any>>;\r\n private _sessionEndedObserver: Nullable<Observer<any>>;\r\n private _sessionInitObserver: Nullable<Observer<any>>;\r\n /**\r\n * Event when a controller has been connected/added\r\n */\r\n public onControllerAddedObservable = new Observable<WebXRInputSource>();\r\n /**\r\n * Event when a controller has been removed/disconnected\r\n */\r\n public onControllerRemovedObservable = new Observable<WebXRInputSource>();\r\n\r\n /**\r\n * Initializes the WebXRInput\r\n * @param xrSessionManager the xr session manager for this session\r\n * @param xrCamera the WebXR camera for this session. Mainly used for teleportation\r\n * @param _options = initialization options for this xr input\r\n */\r\n public constructor(\r\n /**\r\n * the xr session manager for this session\r\n */\r\n public xrSessionManager: WebXRSessionManager,\r\n /**\r\n * the WebXR camera for this session. Mainly used for teleportation\r\n */\r\n public xrCamera: WebXRCamera,\r\n private readonly _options: IWebXRInputOptions = {}\r\n ) {\r\n // Remove controllers when exiting XR\r\n this._sessionEndedObserver = this.xrSessionManager.onXRSessionEnded.add(() => {\r\n this._addAndRemoveControllers(\r\n [],\r\n this.controllers.map((c) => {\r\n return c.inputSource;\r\n })\r\n );\r\n });\r\n\r\n this._sessionInitObserver = this.xrSessionManager.onXRSessionInit.add((session) => {\r\n session.addEventListener(\"inputsourceschange\", this._onInputSourcesChange);\r\n });\r\n\r\n this._frameObserver = this.xrSessionManager.onXRFrameObservable.add((frame) => {\r\n // Update controller pose info\r\n this.controllers.forEach((controller) => {\r\n controller.updateFromXRFrame(frame, this.xrSessionManager.referenceSpace, this.xrCamera, this.xrSessionManager);\r\n });\r\n });\r\n\r\n if (this._options.customControllersRepositoryURL) {\r\n WebXRMotionControllerManager.BaseRepositoryUrl = this._options.customControllersRepositoryURL;\r\n }\r\n\r\n WebXRMotionControllerManager.UseOnlineRepository = !this._options.disableOnlineControllerRepository;\r\n if (WebXRMotionControllerManager.UseOnlineRepository) {\r\n // pre-load the profiles list to load the controllers quicker afterwards\r\n try {\r\n WebXRMotionControllerManager.UpdateProfilesList().catch(() => {\r\n WebXRMotionControllerManager.UseOnlineRepository = false;\r\n });\r\n } catch (e) {\r\n WebXRMotionControllerManager.UseOnlineRepository = false;\r\n }\r\n }\r\n }\r\n\r\n private _onInputSourcesChange = (event: XRInputSourceChangeEvent) => {\r\n this._addAndRemoveControllers(event.added, event.removed);\r\n };\r\n\r\n private _addAndRemoveControllers(addInputs: readonly XRInputSource[], removeInputs: readonly XRInputSource[]) {\r\n // Add controllers if they don't already exist\r\n const sources = this.controllers.map((c) => {\r\n return c.inputSource;\r\n });\r\n for (const input of addInputs) {\r\n if (sources.indexOf(input) === -1) {\r\n const controller = new WebXRInputSource(this.xrSessionManager.scene, input, {\r\n ...(this._options.controllerOptions || {}),\r\n forceControllerProfile: this._options.forceInputProfile,\r\n doNotLoadControllerMesh: this._options.doNotLoadControllerMeshes,\r\n disableMotionControllerAnimation: this._options.disableControllerAnimation,\r\n });\r\n this.controllers.push(controller);\r\n this.onControllerAddedObservable.notifyObservers(controller);\r\n }\r\n }\r\n\r\n // Remove and dispose of controllers to be disposed\r\n const keepControllers: Array<WebXRInputSource> = [];\r\n const removedControllers: Array<WebXRInputSource> = [];\r\n this.controllers.forEach((c) => {\r\n if (removeInputs.indexOf(c.inputSource) === -1) {\r\n keepControllers.push(c);\r\n } else {\r\n removedControllers.push(c);\r\n }\r\n });\r\n this.controllers = keepControllers;\r\n removedControllers.forEach((c) => {\r\n this.onControllerRemovedObservable.notifyObservers(c);\r\n c.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this.controllers.forEach((c) => {\r\n c.dispose();\r\n });\r\n this.xrSessionManager.onXRFrameObservable.remove(this._frameObserver);\r\n this.xrSessionManager.onXRSessionInit.remove(this._sessionInitObserver);\r\n this.xrSessionManager.onXRSessionEnded.remove(this._sessionEndedObserver);\r\n this.onControllerAddedObservable.clear();\r\n this.onControllerRemovedObservable.clear();\r\n\r\n // clear the controller cache\r\n WebXRMotionControllerManager.ClearControllerCache();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRInput.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRInput.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAwC/F;;GAEG;AACH,MAAM,OAAO,UAAU;IAiBnB;;;;;OAKG;IACH;IACI;;OAEG;IACI,gBAAqC;IAC5C;;OAEG;IACI,QAAqB,EACX,WAA+B,EAAE;QAL3C,qBAAgB,GAAhB,gBAAgB,CAAqB;QAIrC,aAAQ,GAAR,QAAQ,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IAAI,CAAC,6BAA6B,CAAC,KAAK,EAAE,CAAC;QAE3C,6BAA6B;QAC7B,4BAA4B,CAAC,oBAAoB,EAAE,CAAC;IACxD,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IDisposable } from \"../scene\";\r\nimport type { IWebXRControllerOptions } from \"./webXRInputSource\";\r\nimport { WebXRInputSource } from \"./webXRInputSource\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\n\r\n/**\r\n * The schema for initialization options of the XR Input class\r\n */\r\nexport interface IWebXRInputOptions {\r\n /**\r\n * If set to true no model will be automatically loaded\r\n */\r\n doNotLoadControllerMeshes?: boolean;\r\n\r\n /**\r\n * If set, this profile will be used for all controllers loaded (for example \"microsoft-mixed-reality\")\r\n * If not found, the xr input profile data will be used.\r\n * Profiles are defined here - https://github.com/immersive-web/webxr-input-profiles/\r\n */\r\n forceInputProfile?: string;\r\n\r\n /**\r\n * Do not send a request to the controller repository to load the profile.\r\n *\r\n * Instead, use the controllers available in babylon itself.\r\n */\r\n disableOnlineControllerRepository?: boolean;\r\n\r\n /**\r\n * A custom URL for the controllers repository\r\n */\r\n customControllersRepositoryURL?: string;\r\n\r\n /**\r\n * Should the controller model's components not move according to the user input\r\n */\r\n disableControllerAnimation?: boolean;\r\n\r\n /**\r\n * Optional options to pass to the controller. Will be overridden by the Input options where applicable\r\n */\r\n controllerOptions?: IWebXRControllerOptions;\r\n}\r\n/**\r\n * XR input used to track XR inputs such as controllers/rays\r\n */\r\nexport class WebXRInput implements IDisposable {\r\n /**\r\n * XR controllers being tracked\r\n */\r\n public controllers: Array<WebXRInputSource> = [];\r\n private _frameObserver: Nullable<Observer<any>>;\r\n private _sessionEndedObserver: Nullable<Observer<any>>;\r\n private _sessionInitObserver: Nullable<Observer<any>>;\r\n /**\r\n * Event when a controller has been connected/added\r\n */\r\n public onControllerAddedObservable = new Observable<WebXRInputSource>();\r\n /**\r\n * Event when a controller has been removed/disconnected\r\n */\r\n public onControllerRemovedObservable = new Observable<WebXRInputSource>();\r\n\r\n /**\r\n * Initializes the WebXRInput\r\n * @param xrSessionManager the xr session manager for this session\r\n * @param xrCamera the WebXR camera for this session. Mainly used for teleportation\r\n * @param _options = initialization options for this xr input\r\n */\r\n public constructor(\r\n /**\r\n * the xr session manager for this session\r\n */\r\n public xrSessionManager: WebXRSessionManager,\r\n /**\r\n * the WebXR camera for this session. Mainly used for teleportation\r\n */\r\n public xrCamera: WebXRCamera,\r\n private readonly _options: IWebXRInputOptions = {}\r\n ) {\r\n // Remove controllers when exiting XR\r\n this._sessionEndedObserver = this.xrSessionManager.onXRSessionEnded.add(() => {\r\n this._addAndRemoveControllers(\r\n [],\r\n this.controllers.map((c) => {\r\n return c.inputSource;\r\n })\r\n );\r\n });\r\n\r\n this._sessionInitObserver = this.xrSessionManager.onXRSessionInit.add((session) => {\r\n session.addEventListener(\"inputsourceschange\", this._onInputSourcesChange);\r\n });\r\n\r\n this._frameObserver = this.xrSessionManager.onXRFrameObservable.add((frame) => {\r\n // Update controller pose info\r\n for (const controller of this.controllers) {\r\n controller.updateFromXRFrame(frame, this.xrSessionManager.referenceSpace, this.xrCamera, this.xrSessionManager);\r\n }\r\n });\r\n\r\n if (this._options.customControllersRepositoryURL) {\r\n WebXRMotionControllerManager.BaseRepositoryUrl = this._options.customControllersRepositoryURL;\r\n }\r\n\r\n WebXRMotionControllerManager.UseOnlineRepository = !this._options.disableOnlineControllerRepository;\r\n if (WebXRMotionControllerManager.UseOnlineRepository) {\r\n // pre-load the profiles list to load the controllers quicker afterwards\r\n try {\r\n WebXRMotionControllerManager.UpdateProfilesList().catch(() => {\r\n WebXRMotionControllerManager.UseOnlineRepository = false;\r\n });\r\n } catch (e) {\r\n WebXRMotionControllerManager.UseOnlineRepository = false;\r\n }\r\n }\r\n }\r\n\r\n private _onInputSourcesChange = (event: XRInputSourceChangeEvent) => {\r\n this._addAndRemoveControllers(event.added, event.removed);\r\n };\r\n\r\n private _addAndRemoveControllers(addInputs: readonly XRInputSource[], removeInputs: readonly XRInputSource[]) {\r\n // Add controllers if they don't already exist\r\n const sources = this.controllers.map((c) => {\r\n return c.inputSource;\r\n });\r\n for (const input of addInputs) {\r\n if (sources.indexOf(input) === -1) {\r\n const controller = new WebXRInputSource(this.xrSessionManager.scene, input, {\r\n ...(this._options.controllerOptions || {}),\r\n forceControllerProfile: this._options.forceInputProfile,\r\n doNotLoadControllerMesh: this._options.doNotLoadControllerMeshes,\r\n disableMotionControllerAnimation: this._options.disableControllerAnimation,\r\n });\r\n this.controllers.push(controller);\r\n this.onControllerAddedObservable.notifyObservers(controller);\r\n }\r\n }\r\n\r\n // Remove and dispose of controllers to be disposed\r\n const keepControllers: Array<WebXRInputSource> = [];\r\n const removedControllers: Array<WebXRInputSource> = [];\r\n for (const c of this.controllers) {\r\n if (removeInputs.indexOf(c.inputSource) === -1) {\r\n keepControllers.push(c);\r\n } else {\r\n removedControllers.push(c);\r\n }\r\n }\r\n this.controllers = keepControllers;\r\n for (const c of removedControllers) {\r\n this.onControllerRemovedObservable.notifyObservers(c);\r\n c.dispose();\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n for (const c of this.controllers) {\r\n c.dispose();\r\n }\r\n this.xrSessionManager.onXRFrameObservable.remove(this._frameObserver);\r\n this.xrSessionManager.onXRSessionInit.remove(this._sessionInitObserver);\r\n this.xrSessionManager.onXRSessionEnded.remove(this._sessionEndedObserver);\r\n this.onControllerAddedObservable.clear();\r\n this.onControllerRemovedObservable.clear();\r\n\r\n // clear the controller cache\r\n WebXRMotionControllerManager.ClearControllerCache();\r\n }\r\n}\r\n"]}
@@ -59,7 +59,10 @@ export class WebXRInputSource {
59
59
  if (this._options.renderingGroupId) {
60
60
  // anything other than 0?
61
61
  this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;
62
- this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => (mesh.renderingGroupId = this._options.renderingGroupId));
62
+ const childMeshes = this.motionController.rootMesh.getChildMeshes(false);
63
+ for (const mesh of childMeshes) {
64
+ mesh.renderingGroupId = this._options.renderingGroupId;
65
+ }
63
66
  }
64
67
  this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);
65
68
  this.motionController.rootMesh.parent = this.grip || this.pointer;
@@ -1 +1 @@
1
- {"version":3,"file":"webXRInputSource.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRInputSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,IAAI,OAAO,GAAG,CAAC,CAAC;AA2BhB;;GAEG;AACH,MAAM,OAAO,gBAAgB;IA0CzB;;;;;;OAMG;IACH,YACY,MAAa;IACrB,sDAAsD;IAC/C,WAA0B,EACzB,WAAoC,EAAE;QAHtC,WAAM,GAAN,MAAM,CAAO;QAEd,gBAAW,GAAX,WAAW,CAAe;QACzB,aAAQ,GAAR,QAAQ,CAA8B;QApD1C,eAAU,GAAG,IAAI,OAAO,EAAE,CAAC;QAE3B,cAAS,GAAG,KAAK,CAAC;QAY1B;;;;WAIG;QACI,wBAAmB,GAAG,IAAI,UAAU,EAAoB,CAAC;QAChE;;;;WAIG;QACI,2BAAsB,GAAG,IAAI,UAAU,EAAgB,CAAC;QAC/D;;WAEG;QACI,qCAAgC,GAAG,IAAI,UAAU,EAAiC,CAAC;QAyBtF,IAAI,CAAC,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E,CAAC;gBACP,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;gBACpC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;gBAC/C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;gBAC9F,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;gBAC9F,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;oBACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC3B,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBACtC,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC1C,CAAC;YACL,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,kEAAkE;YAClE,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { Observable } from \"../Misc/observable\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { WebXRAbstractMotionController } from \"./motionController/webXRAbstractMotionController\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\n\r\nlet idCount = 0;\r\n\r\n/**\r\n * Configuration options for the WebXR controller creation\r\n */\r\nexport interface IWebXRControllerOptions {\r\n /**\r\n * Should the controller mesh be animated when a user interacts with it\r\n * The pressed buttons / thumbstick and touchpad animations will be disabled\r\n */\r\n disableMotionControllerAnimation?: boolean;\r\n /**\r\n * Do not load the controller mesh, in case a different mesh needs to be loaded.\r\n */\r\n doNotLoadControllerMesh?: boolean;\r\n /**\r\n * Force a specific controller type for this controller.\r\n * This can be used when creating your own profile or when testing different controllers\r\n */\r\n forceControllerProfile?: string;\r\n /**\r\n * Defines a rendering group ID for meshes that will be loaded.\r\n * This is for the default controllers only.\r\n */\r\n renderingGroupId?: number;\r\n}\r\n\r\n/**\r\n * Represents an XR controller\r\n */\r\nexport class WebXRInputSource {\r\n private _tmpVector = new Vector3();\r\n private _uniqueId: string;\r\n private _disposed = false;\r\n\r\n /**\r\n * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if that's the case only the pointer from the head will be available\r\n */\r\n public grip?: AbstractMesh;\r\n /**\r\n * If available, this is the gamepad object related to this controller.\r\n * Using this object it is possible to get click events and trackpad changes of the\r\n * webxr controller that is currently being used.\r\n */\r\n public motionController?: WebXRAbstractMotionController;\r\n /**\r\n * Event that fires when the controller is removed/disposed.\r\n * The object provided as event data is this controller, after associated assets were disposed.\r\n * uniqueId is still available.\r\n */\r\n public onDisposeObservable = new Observable<WebXRInputSource>();\r\n /**\r\n * Will be triggered when the mesh associated with the motion controller is done loading.\r\n * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh\r\n * A shortened version of controller -> motion controller -> on mesh loaded.\r\n */\r\n public onMeshLoadedObservable = new Observable<AbstractMesh>();\r\n /**\r\n * Observers registered here will trigger when a motion controller profile was assigned to this xr controller\r\n */\r\n public onMotionControllerInitObservable = new Observable<WebXRAbstractMotionController>();\r\n /**\r\n * Pointer which can be used to select objects or attach a visible laser to\r\n */\r\n public pointer: AbstractMesh;\r\n\r\n /**\r\n * The last XRPose the was calculated on the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRPose?: XRPose;\r\n\r\n /**\r\n * Creates the input source object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport\r\n * @param _scene the scene which the controller should be associated to\r\n * @param inputSource the underlying input source for the controller\r\n * @param _options options for this controller creation\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n /** The underlying input source for the controller */\r\n public inputSource: XRInputSource,\r\n private _options: IWebXRControllerOptions = {}\r\n ) {\r\n this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;\r\n\r\n this.pointer = new Mesh(`${this._uniqueId}-pointer`, _scene);\r\n this.pointer.rotationQuaternion = new Quaternion();\r\n\r\n if (this.inputSource.gripSpace) {\r\n this.grip = new Mesh(`${this._uniqueId}-grip`, this._scene);\r\n this.grip.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);\r\n\r\n // for now only load motion controllers if gamepad object available\r\n if (this.inputSource.gamepad && this.inputSource.targetRayMode === \"tracked-pointer\") {\r\n WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then(\r\n (motionController) => {\r\n this.motionController = motionController;\r\n this.onMotionControllerInitObservable.notifyObservers(motionController);\r\n // should the model be loaded?\r\n if (!this._options.doNotLoadControllerMesh && !this.motionController._doNotLoadControllerMesh) {\r\n this.motionController.loadModel().then((success) => {\r\n if (success && this.motionController && this.motionController.rootMesh) {\r\n if (this._options.renderingGroupId) {\r\n // anything other than 0?\r\n this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;\r\n this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => (mesh.renderingGroupId = this._options.renderingGroupId!));\r\n }\r\n this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);\r\n this.motionController.rootMesh.parent = this.grip || this.pointer;\r\n this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;\r\n }\r\n // make sure to dispose is the controller is already disposed\r\n if (this._disposed) {\r\n this.motionController?.dispose();\r\n }\r\n });\r\n }\r\n },\r\n () => {\r\n Tools.Warn(`Could not find a matching motion controller for the registered input source`);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Get this controllers unique id\r\n */\r\n public get uniqueId() {\r\n return this._uniqueId;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n if (this.grip) {\r\n this.grip.dispose(true);\r\n }\r\n if (this.motionController) {\r\n this.motionController.dispose();\r\n }\r\n this.pointer.dispose(true);\r\n this.onMotionControllerInitObservable.clear();\r\n this.onMeshLoadedObservable.clear();\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n this._disposed = true;\r\n }\r\n\r\n /**\r\n * Gets a world space ray coming from the pointer or grip\r\n * @param result the resulting ray\r\n * @param gripIfAvailable use the grip mesh instead of the pointer, if available\r\n */\r\n public getWorldPointerRayToRef(result: Ray, gripIfAvailable: boolean = false) {\r\n const object = gripIfAvailable && this.grip ? this.grip : this.pointer;\r\n Vector3.TransformNormalToRef(this._tmpVector, object.getWorldMatrix(), result.direction);\r\n result.direction.normalize();\r\n result.origin.copyFrom(object.absolutePosition);\r\n result.length = 1000;\r\n }\r\n\r\n /**\r\n * Updates the controller pose based on the given XRFrame\r\n * @param xrFrame xr frame to update the pose with\r\n * @param referenceSpace reference space to use\r\n * @param xrCamera the xr camera, used for parenting\r\n * @param xrSessionManager the session manager used to get the world reference system\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame, referenceSpace: XRReferenceSpace, xrCamera: WebXRCamera, xrSessionManager: WebXRSessionManager) {\r\n const pose = xrFrame.getPose(this.inputSource.targetRaySpace, referenceSpace);\r\n this._lastXRPose = pose;\r\n\r\n // Update the pointer mesh\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n this.pointer.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n const orientation = pose.transform.orientation;\r\n this.pointer.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.pointer.position.z *= -1;\r\n this.pointer.rotationQuaternion!.z *= -1;\r\n this.pointer.rotationQuaternion!.w *= -1;\r\n }\r\n this.pointer.parent = xrCamera.parent;\r\n this.pointer.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n\r\n // Update the grip mesh if it exists\r\n if (this.inputSource.gripSpace && this.grip) {\r\n const pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n const orientation = pose.transform.orientation;\r\n this.grip.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n this.grip.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.grip.position.z *= -1;\r\n this.grip.rotationQuaternion!.z *= -1;\r\n this.grip.rotationQuaternion!.w *= -1;\r\n }\r\n }\r\n this.grip.parent = xrCamera.parent;\r\n this.grip.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n if (this.motionController) {\r\n // either update buttons only or also position, if in gamepad mode\r\n this.motionController.updateFromXRFrame(xrFrame);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRInputSource.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRInputSource.ts"],"names":[],"mapp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,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;gBAC9F,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;oBACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC3B,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBACtC,IAAI,CAAC,IAAI,CAAC,kBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC1C,CAAC;YACL,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,kEAAkE;YAClE,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { Observable } from \"../Misc/observable\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Quaternion, Vector3 } from \"../Maths/math.vector\";\r\nimport type { Ray } from \"../Culling/ray\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { WebXRAbstractMotionController } from \"./motionController/webXRAbstractMotionController\";\r\nimport { WebXRMotionControllerManager } from \"./motionController/webXRMotionControllerManager\";\r\nimport { Tools } from \"../Misc/tools\";\r\nimport type { WebXRCamera } from \"./webXRCamera\";\r\nimport type { WebXRSessionManager } from \"./webXRSessionManager\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\n\r\nlet idCount = 0;\r\n\r\n/**\r\n * Configuration options for the WebXR controller creation\r\n */\r\nexport interface IWebXRControllerOptions {\r\n /**\r\n * Should the controller mesh be animated when a user interacts with it\r\n * The pressed buttons / thumbstick and touchpad animations will be disabled\r\n */\r\n disableMotionControllerAnimation?: boolean;\r\n /**\r\n * Do not load the controller mesh, in case a different mesh needs to be loaded.\r\n */\r\n doNotLoadControllerMesh?: boolean;\r\n /**\r\n * Force a specific controller type for this controller.\r\n * This can be used when creating your own profile or when testing different controllers\r\n */\r\n forceControllerProfile?: string;\r\n /**\r\n * Defines a rendering group ID for meshes that will be loaded.\r\n * This is for the default controllers only.\r\n */\r\n renderingGroupId?: number;\r\n}\r\n\r\n/**\r\n * Represents an XR controller\r\n */\r\nexport class WebXRInputSource {\r\n private _tmpVector = new Vector3();\r\n private _uniqueId: string;\r\n private _disposed = false;\r\n\r\n /**\r\n * Represents the part of the controller that is held. This may not exist if the controller is the head mounted display itself, if that's the case only the pointer from the head will be available\r\n */\r\n public grip?: AbstractMesh;\r\n /**\r\n * If available, this is the gamepad object related to this controller.\r\n * Using this object it is possible to get click events and trackpad changes of the\r\n * webxr controller that is currently being used.\r\n */\r\n public motionController?: WebXRAbstractMotionController;\r\n /**\r\n * Event that fires when the controller is removed/disposed.\r\n * The object provided as event data is this controller, after associated assets were disposed.\r\n * uniqueId is still available.\r\n */\r\n public onDisposeObservable = new Observable<WebXRInputSource>();\r\n /**\r\n * Will be triggered when the mesh associated with the motion controller is done loading.\r\n * It is also possible that this will never trigger (!) if no mesh was loaded, or if the developer decides to load a different mesh\r\n * A shortened version of controller -> motion controller -> on mesh loaded.\r\n */\r\n public onMeshLoadedObservable = new Observable<AbstractMesh>();\r\n /**\r\n * Observers registered here will trigger when a motion controller profile was assigned to this xr controller\r\n */\r\n public onMotionControllerInitObservable = new Observable<WebXRAbstractMotionController>();\r\n /**\r\n * Pointer which can be used to select objects or attach a visible laser to\r\n */\r\n public pointer: AbstractMesh;\r\n\r\n /**\r\n * The last XRPose the was calculated on the current XRFrame\r\n * @internal\r\n */\r\n public _lastXRPose?: XRPose;\r\n\r\n /**\r\n * Creates the input source object\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRInputControllerSupport\r\n * @param _scene the scene which the controller should be associated to\r\n * @param inputSource the underlying input source for the controller\r\n * @param _options options for this controller creation\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n /** The underlying input source for the controller */\r\n public inputSource: XRInputSource,\r\n private _options: IWebXRControllerOptions = {}\r\n ) {\r\n this._uniqueId = `controller-${idCount++}-${inputSource.targetRayMode}-${inputSource.handedness}`;\r\n\r\n this.pointer = new Mesh(`${this._uniqueId}-pointer`, _scene);\r\n this.pointer.rotationQuaternion = new Quaternion();\r\n\r\n if (this.inputSource.gripSpace) {\r\n this.grip = new Mesh(`${this._uniqueId}-grip`, this._scene);\r\n this.grip.rotationQuaternion = new Quaternion();\r\n }\r\n\r\n this._tmpVector.set(0, 0, this._scene.useRightHandedSystem ? -1.0 : 1.0);\r\n\r\n // for now only load motion controllers if gamepad object available\r\n if (this.inputSource.gamepad && this.inputSource.targetRayMode === \"tracked-pointer\") {\r\n WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then(\r\n (motionController) => {\r\n this.motionController = motionController;\r\n this.onMotionControllerInitObservable.notifyObservers(motionController);\r\n // should the model be loaded?\r\n if (!this._options.doNotLoadControllerMesh && !this.motionController._doNotLoadControllerMesh) {\r\n this.motionController.loadModel().then((success) => {\r\n if (success && this.motionController && this.motionController.rootMesh) {\r\n if (this._options.renderingGroupId) {\r\n // anything other than 0?\r\n this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;\r\n const childMeshes = this.motionController.rootMesh.getChildMeshes(false);\r\n for (const mesh of childMeshes) {\r\n mesh.renderingGroupId = this._options.renderingGroupId!;\r\n }\r\n }\r\n this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);\r\n this.motionController.rootMesh.parent = this.grip || this.pointer;\r\n this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;\r\n }\r\n // make sure to dispose is the controller is already disposed\r\n if (this._disposed) {\r\n this.motionController?.dispose();\r\n }\r\n });\r\n }\r\n },\r\n () => {\r\n Tools.Warn(`Could not find a matching motion controller for the registered input source`);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Get this controllers unique id\r\n */\r\n public get uniqueId() {\r\n return this._uniqueId;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n if (this.grip) {\r\n this.grip.dispose(true);\r\n }\r\n if (this.motionController) {\r\n this.motionController.dispose();\r\n }\r\n this.pointer.dispose(true);\r\n this.onMotionControllerInitObservable.clear();\r\n this.onMeshLoadedObservable.clear();\r\n this.onDisposeObservable.notifyObservers(this);\r\n this.onDisposeObservable.clear();\r\n this._disposed = true;\r\n }\r\n\r\n /**\r\n * Gets a world space ray coming from the pointer or grip\r\n * @param result the resulting ray\r\n * @param gripIfAvailable use the grip mesh instead of the pointer, if available\r\n */\r\n public getWorldPointerRayToRef(result: Ray, gripIfAvailable: boolean = false) {\r\n const object = gripIfAvailable && this.grip ? this.grip : this.pointer;\r\n Vector3.TransformNormalToRef(this._tmpVector, object.getWorldMatrix(), result.direction);\r\n result.direction.normalize();\r\n result.origin.copyFrom(object.absolutePosition);\r\n result.length = 1000;\r\n }\r\n\r\n /**\r\n * Updates the controller pose based on the given XRFrame\r\n * @param xrFrame xr frame to update the pose with\r\n * @param referenceSpace reference space to use\r\n * @param xrCamera the xr camera, used for parenting\r\n * @param xrSessionManager the session manager used to get the world reference system\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame, referenceSpace: XRReferenceSpace, xrCamera: WebXRCamera, xrSessionManager: WebXRSessionManager) {\r\n const pose = xrFrame.getPose(this.inputSource.targetRaySpace, referenceSpace);\r\n this._lastXRPose = pose;\r\n\r\n // Update the pointer mesh\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n this.pointer.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n const orientation = pose.transform.orientation;\r\n this.pointer.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.pointer.position.z *= -1;\r\n this.pointer.rotationQuaternion!.z *= -1;\r\n this.pointer.rotationQuaternion!.w *= -1;\r\n }\r\n this.pointer.parent = xrCamera.parent;\r\n this.pointer.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n\r\n // Update the grip mesh if it exists\r\n if (this.inputSource.gripSpace && this.grip) {\r\n const pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);\r\n if (pose) {\r\n const pos = pose.transform.position;\r\n const orientation = pose.transform.orientation;\r\n this.grip.position.set(pos.x, pos.y, pos.z).scaleInPlace(xrSessionManager.worldScalingFactor);\r\n this.grip.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);\r\n if (!this._scene.useRightHandedSystem) {\r\n this.grip.position.z *= -1;\r\n this.grip.rotationQuaternion!.z *= -1;\r\n this.grip.rotationQuaternion!.w *= -1;\r\n }\r\n }\r\n this.grip.parent = xrCamera.parent;\r\n this.grip.scaling.setAll(xrSessionManager.worldScalingFactor);\r\n }\r\n if (this.motionController) {\r\n // either update buttons only or also position, if in gamepad mode\r\n this.motionController.updateFromXRFrame(xrFrame);\r\n }\r\n }\r\n}\r\n"]}
@@ -65,7 +65,9 @@ export class WebXRLayerRenderTargetTextureProvider {
65
65
  return this._framebufferDimensions;
66
66
  }
67
67
  dispose() {
68
- this._renderTargetTextures.forEach((rtt) => rtt.dispose());
68
+ for (const rtt of this._renderTargetTextures) {
69
+ rtt.dispose();
70
+ }
69
71
  this._renderTargetTextures.length = 0;
70
72
  }
71
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webXRRenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRRenderTargetTextureProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAyB,MAAM,uCAAuC,CAAC;AA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IAClC,CAAC;IAEM,wBAAwB;QAC3B,OAAO,IAAI,CAAC,sBAAsB,CAAC;IACvC,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { Engine } from \"../Engines/engine\";\r\nimport { WebGLHardwareTexture } from \"../Engines/WebGL/webGLHardwareTexture\";\r\nimport type { WebGLRenderTargetWrapper } from \"../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { MultiviewRenderTarget } from \"../Materials/Textures/MultiviewRenderTarget\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\n\r\n/**\r\n * An interface for objects that provide render target textures for XR rendering.\r\n */\r\nexport interface IWebXRRenderTargetTextureProvider extends IDisposable {\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRLayer.\r\n * @internal\r\n */\r\nexport abstract class WebXRLayerRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n public abstract trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n public abstract getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n public abstract getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n\r\n protected _renderTargetTextures = new Array<RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n\r\n private _engine: Engine;\r\n\r\n constructor(\r\n private readonly _scene: Scene,\r\n public readonly layerWrapper: WebXRLayerWrapper\r\n ) {\r\n this._engine = _scene.getEngine() as Engine;\r\n }\r\n\r\n private _createInternalTexture(textureSize: { width: number; height: number }, texture: WebGLTexture): InternalTexture {\r\n const internalTexture = new InternalTexture(this._engine, InternalTextureSource.Unknown, true);\r\n internalTexture.width = textureSize.width;\r\n internalTexture.height = textureSize.height;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, this._engine._gl);\r\n internalTexture.isReady = true;\r\n return internalTexture;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n colorTexture?: WebGLTexture,\r\n depthStencilTexture?: WebGLTexture,\r\n multiview?: boolean\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 = multiview ? new MultiviewRenderTarget(this._scene, textureSize) : new RenderTargetTexture(\"XR renderTargetTexture\", textureSize, this._scene);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n renderTargetWrapper._samples = renderTargetTexture.samples;\r\n // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers\r\n if (framebuffer || !colorTexture) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n if (colorTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._colorTextureArray = colorTexture;\r\n } else {\r\n const internalTexture = this._createInternalTexture(textureSize, colorTexture);\r\n renderTargetWrapper.setTexture(internalTexture, 0);\r\n renderTargetTexture._texture = internalTexture;\r\n }\r\n }\r\n\r\n if (depthStencilTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n } else {\r\n renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture);\r\n }\r\n }\r\n\r\n renderTargetTexture.disableRescaling();\r\n\r\n this._renderTargetTextures.push(renderTargetTexture);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _destroyRenderTargetTexture(renderTargetTexture: RenderTargetTexture) {\r\n this._renderTargetTextures.splice(this._renderTargetTextures.indexOf(renderTargetTexture), 1);\r\n renderTargetTexture.dispose();\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return this._framebufferDimensions;\r\n }\r\n\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.length = 0;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRRenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRRenderTargetTextureProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAyB,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAgChF;;;GAGG;AACH,MAAM,OAAgB,qCAAqC;IAUvD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AC3C,GAAG,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,CAAC;CACJ","sourcesContent":["import type { Engine } from \"../Engines/engine\";\r\nimport { WebGLHardwareTexture } from \"../Engines/WebGL/webGLHardwareTexture\";\r\nimport type { WebGLRenderTargetWrapper } from \"../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { MultiviewRenderTarget } from \"../Materials/Textures/MultiviewRenderTarget\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Viewport } from \"../Maths/math.viewport\";\r\nimport type { IDisposable, Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\n\r\n/**\r\n * An interface for objects that provide render target textures for XR rendering.\r\n */\r\nexport interface IWebXRRenderTargetTextureProvider extends IDisposable {\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n}\r\n\r\n/**\r\n * Provides render target textures and other important rendering information for a given XRLayer.\r\n * @internal\r\n */\r\nexport abstract class WebXRLayerRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n public abstract trySetViewportForView(viewport: Viewport, view: XRView): boolean;\r\n public abstract getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture>;\r\n public abstract getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture>;\r\n\r\n protected _renderTargetTextures = new Array<RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n\r\n private _engine: Engine;\r\n\r\n constructor(\r\n private readonly _scene: Scene,\r\n public readonly layerWrapper: WebXRLayerWrapper\r\n ) {\r\n this._engine = _scene.getEngine() as Engine;\r\n }\r\n\r\n private _createInternalTexture(textureSize: { width: number; height: number }, texture: WebGLTexture): InternalTexture {\r\n const internalTexture = new InternalTexture(this._engine, InternalTextureSource.Unknown, true);\r\n internalTexture.width = textureSize.width;\r\n internalTexture.height = textureSize.height;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, this._engine._gl);\r\n internalTexture.isReady = true;\r\n return internalTexture;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n colorTexture?: WebGLTexture,\r\n depthStencilTexture?: WebGLTexture,\r\n multiview?: boolean\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 = multiview ? new MultiviewRenderTarget(this._scene, textureSize) : new RenderTargetTexture(\"XR renderTargetTexture\", textureSize, this._scene);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n renderTargetWrapper._samples = renderTargetTexture.samples;\r\n // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers\r\n if (framebuffer || !colorTexture) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n if (colorTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._colorTextureArray = colorTexture;\r\n } else {\r\n const internalTexture = this._createInternalTexture(textureSize, colorTexture);\r\n renderTargetWrapper.setTexture(internalTexture, 0);\r\n renderTargetTexture._texture = internalTexture;\r\n }\r\n }\r\n\r\n if (depthStencilTexture) {\r\n if (multiview) {\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n } else {\r\n renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture);\r\n }\r\n }\r\n\r\n renderTargetTexture.disableRescaling();\r\n\r\n this._renderTargetTextures.push(renderTargetTexture);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _destroyRenderTargetTexture(renderTargetTexture: RenderTargetTexture) {\r\n this._renderTargetTextures.splice(this._renderTargetTextures.indexOf(renderTargetTexture), 1);\r\n renderTargetTexture.dispose();\r\n }\r\n\r\n public getFramebufferDimensions(): Nullable<{ framebufferWidth: number; framebufferHeight: number }> {\r\n return this._framebufferDimensions;\r\n }\r\n\r\n public dispose() {\r\n for (const rtt of this._renderTargetTextures) {\r\n rtt.dispose();\r\n }\r\n this._renderTargetTextures.length = 0;\r\n }\r\n}\r\n"]}