@babylonjs/core 6.7.0 → 6.8.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 (412) hide show
  1. package/Actions/abstractActionManager.js.map +1 -1
  2. package/Actions/action.js.map +1 -1
  3. package/Animations/animation.js.map +1 -1
  4. package/Animations/animationGroup.d.ts +5 -0
  5. package/Animations/animationGroup.js +12 -0
  6. package/Animations/animationGroup.js.map +1 -1
  7. package/Animations/easing.js.map +1 -1
  8. package/Audio/audioSceneComponent.js.map +1 -1
  9. package/Audio/sound.js.map +1 -1
  10. package/BakedVertexAnimation/bakedVertexAnimationManager.js.map +1 -1
  11. package/Behaviors/Cameras/bouncingBehavior.js.map +1 -1
  12. package/Behaviors/Cameras/framingBehavior.js.map +1 -1
  13. package/Behaviors/Meshes/fadeInOutBehavior.js.map +1 -1
  14. package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
  15. package/Bones/bone.js.map +1 -1
  16. package/Bones/boneIKController.js.map +1 -1
  17. package/Bones/boneLookController.js.map +1 -1
  18. package/Buffers/dataBuffer.js.map +1 -1
  19. package/Cameras/Inputs/BaseCameraMouseWheelInput.js.map +1 -1
  20. package/Cameras/Inputs/BaseCameraPointersInput.js.map +1 -1
  21. package/Cameras/Inputs/arcRotateCameraGamepadInput.js.map +1 -1
  22. package/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.js.map +1 -1
  23. package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js.map +1 -1
  24. package/Cameras/Inputs/arcRotateCameraPointersInput.js.map +1 -1
  25. package/Cameras/Inputs/flyCameraKeyboardInput.js.map +1 -1
  26. package/Cameras/Inputs/flyCameraMouseInput.js.map +1 -1
  27. package/Cameras/Inputs/followCameraKeyboardMoveInput.js.map +1 -1
  28. package/Cameras/Inputs/followCameraMouseWheelInput.js.map +1 -1
  29. package/Cameras/Inputs/followCameraPointersInput.js.map +1 -1
  30. package/Cameras/Inputs/freeCameraGamepadInput.js.map +1 -1
  31. package/Cameras/Inputs/freeCameraKeyboardMoveInput.js.map +1 -1
  32. package/Cameras/Inputs/freeCameraMouseInput.js.map +1 -1
  33. package/Cameras/Inputs/freeCameraTouchInput.js.map +1 -1
  34. package/Cameras/VR/vrExperienceHelper.js.map +1 -1
  35. package/Cameras/arcRotateCamera.js.map +1 -1
  36. package/Cameras/camera.js.map +1 -1
  37. package/Cameras/flyCamera.js.map +1 -1
  38. package/Cameras/followCamera.js.map +1 -1
  39. package/Cameras/freeCamera.js.map +1 -1
  40. package/Cameras/targetCamera.js.map +1 -1
  41. package/Collisions/collider.js.map +1 -1
  42. package/Compute/computeEffect.js.map +1 -1
  43. package/Compute/computeShader.js +1 -5
  44. package/Compute/computeShader.js.map +1 -1
  45. package/Culling/Octrees/octree.js.map +1 -1
  46. package/Culling/boundingBox.js.map +1 -1
  47. package/Culling/boundingInfo.js.map +1 -1
  48. package/Culling/boundingSphere.js.map +1 -1
  49. package/Culling/ray.d.ts +7 -2
  50. package/Culling/ray.js +8 -3
  51. package/Culling/ray.js.map +1 -1
  52. package/Debug/debugLayer.js +1 -9
  53. package/Debug/debugLayer.js.map +1 -1
  54. package/Debug/skeletonViewer.js.map +1 -1
  55. package/Engines/Extensions/engine.cubeTexture.js +1 -6
  56. package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
  57. package/Engines/Extensions/engine.multiRender.js.map +1 -1
  58. package/Engines/Extensions/engine.multiview.d.ts +6 -1
  59. package/Engines/Extensions/engine.multiview.js +27 -7
  60. package/Engines/Extensions/engine.multiview.js.map +1 -1
  61. package/Engines/Extensions/engine.renderTarget.js +1 -6
  62. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  63. package/Engines/Extensions/engine.renderTargetCube.js +1 -9
  64. package/Engines/Extensions/engine.renderTargetCube.js.map +1 -1
  65. package/Engines/Extensions/engine.webVR.js +1 -5
  66. package/Engines/Extensions/engine.webVR.js.map +1 -1
  67. package/Engines/Native/nativeInterfaces.d.ts +1 -0
  68. package/Engines/Native/nativeInterfaces.js.map +1 -1
  69. package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js +3 -0
  70. package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js.map +1 -1
  71. package/Engines/Processors/Expressions/shaderDefineExpression.d.ts +37 -0
  72. package/Engines/Processors/Expressions/shaderDefineExpression.js +57 -0
  73. package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
  74. package/Engines/Processors/shaderCodeInliner.js.map +1 -1
  75. package/Engines/Processors/shaderProcessor.js +34 -14
  76. package/Engines/Processors/shaderProcessor.js.map +1 -1
  77. package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +19 -0
  78. package/Engines/WebGL/webGLRenderTargetWrapper.js +20 -1
  79. package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
  80. package/Engines/WebGPU/Extensions/engine.cubeTexture.js +1 -7
  81. package/Engines/WebGPU/Extensions/engine.cubeTexture.js.map +1 -1
  82. package/Engines/WebGPU/Extensions/engine.renderTarget.js +1 -8
  83. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  84. package/Engines/WebGPU/Extensions/engine.renderTargetCube.js +1 -10
  85. package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
  86. package/Engines/WebGPU/webgpuCacheBindGroups.js.map +1 -1
  87. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  88. package/Engines/WebGPU/webgpuCacheSampler.js +1 -6
  89. package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
  90. package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
  91. package/Engines/WebGPU/webgpuTintWASM.js +1 -4
  92. package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
  93. package/Engines/engine.d.ts +8 -1
  94. package/Engines/engine.js.map +1 -1
  95. package/Engines/engineCapabilities.d.ts +2 -0
  96. package/Engines/engineCapabilities.js.map +1 -1
  97. package/Engines/nativeEngine.d.ts +2 -0
  98. package/Engines/nativeEngine.js +16 -0
  99. package/Engines/nativeEngine.js.map +1 -1
  100. package/Engines/nullEngine.js +1 -9
  101. package/Engines/nullEngine.js.map +1 -1
  102. package/Engines/thinEngine.js +7 -9
  103. package/Engines/thinEngine.js.map +1 -1
  104. package/Engines/webgpuEngine.js +3 -14
  105. package/Engines/webgpuEngine.js.map +1 -1
  106. package/Gamepads/Controllers/gearVRController.js.map +1 -1
  107. package/Gamepads/Controllers/oculusTouchController.js.map +1 -1
  108. package/Gamepads/Controllers/poseEnabledController.js.map +1 -1
  109. package/Gamepads/Controllers/windowsMotionController.js.map +1 -1
  110. package/Gamepads/gamepad.js.map +1 -1
  111. package/Gizmos/cameraGizmo.js.map +1 -1
  112. package/Gizmos/gizmo.js.map +1 -1
  113. package/Gizmos/lightGizmo.js.map +1 -1
  114. package/Gizmos/planeRotationGizmo.js.map +1 -1
  115. package/Helpers/environmentHelper.js +2 -8
  116. package/Helpers/environmentHelper.js.map +1 -1
  117. package/Helpers/textureDome.js.map +1 -1
  118. package/Inputs/scene.inputManager.js +4 -1
  119. package/Inputs/scene.inputManager.js.map +1 -1
  120. package/Layers/effectLayer.js +1 -8
  121. package/Layers/effectLayer.js.map +1 -1
  122. package/Layers/glowLayer.js +1 -12
  123. package/Layers/glowLayer.js.map +1 -1
  124. package/Layers/highlightLayer.js +1 -11
  125. package/Layers/highlightLayer.js.map +1 -1
  126. package/Legacy/legacy.js +1 -1
  127. package/Legacy/legacy.js.map +1 -1
  128. package/LensFlares/lensFlareSystem.js.map +1 -1
  129. package/Lights/Shadows/shadowGenerator.js +1 -4
  130. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  131. package/Lights/directionalLight.js.map +1 -1
  132. package/Lights/hemisphericLight.js.map +1 -1
  133. package/Lights/light.js.map +1 -1
  134. package/Lights/spotLight.js.map +1 -1
  135. package/Loading/loadingScreen.js.map +1 -1
  136. package/Loading/sceneLoader.d.ts +8 -8
  137. package/Loading/sceneLoader.js +35 -19
  138. package/Loading/sceneLoader.js.map +1 -1
  139. package/Materials/Background/backgroundMaterial.js.map +1 -1
  140. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +1 -1
  141. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  142. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  143. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +1 -1
  144. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  145. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  146. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
  147. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
  148. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  149. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  150. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  151. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  152. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  153. package/Materials/Node/Blocks/PBR/sheenBlock.js.map +1 -1
  154. package/Materials/Node/Blocks/addBlock.js +2 -0
  155. package/Materials/Node/Blocks/addBlock.js.map +1 -1
  156. package/Materials/Node/Blocks/clampBlock.js.map +1 -1
  157. package/Materials/Node/Blocks/cloudBlock.js.map +1 -1
  158. package/Materials/Node/Blocks/customBlock.d.ts +1 -0
  159. package/Materials/Node/Blocks/customBlock.js +18 -2
  160. package/Materials/Node/Blocks/customBlock.js.map +1 -1
  161. package/Materials/Node/Blocks/divideBlock.js +2 -0
  162. package/Materials/Node/Blocks/divideBlock.js.map +1 -1
  163. package/Materials/Node/Blocks/meshAttributeExistsBlock.js.map +1 -1
  164. package/Materials/Node/Blocks/multiplyBlock.js +2 -0
  165. package/Materials/Node/Blocks/multiplyBlock.js.map +1 -1
  166. package/Materials/Node/Blocks/remapBlock.js.map +1 -1
  167. package/Materials/Node/Blocks/subtractBlock.js +2 -0
  168. package/Materials/Node/Blocks/subtractBlock.js.map +1 -1
  169. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  170. package/Materials/Node/Blocks/worleyNoise3DBlock.js.map +1 -1
  171. package/Materials/Node/nodeMaterial.d.ts +6 -1
  172. package/Materials/Node/nodeMaterial.js +6 -10
  173. package/Materials/Node/nodeMaterial.js.map +1 -1
  174. package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
  175. package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
  176. package/Materials/PBR/pbrBaseMaterial.js +1 -5
  177. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  178. package/Materials/PBR/pbrBaseSimpleMaterial.js.map +1 -1
  179. package/Materials/PBR/pbrClearCoatConfiguration.js.map +1 -1
  180. package/Materials/PBR/pbrIridescenceConfiguration.js.map +1 -1
  181. package/Materials/PBR/pbrMaterial.d.ts +2 -1
  182. package/Materials/PBR/pbrMaterial.js +6 -13
  183. package/Materials/PBR/pbrMaterial.js.map +1 -1
  184. package/Materials/PBR/pbrMetallicRoughnessMaterial.js.map +1 -1
  185. package/Materials/PBR/pbrSheenConfiguration.js.map +1 -1
  186. package/Materials/PBR/pbrSpecularGlossinessMaterial.js.map +1 -1
  187. package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
  188. package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
  189. package/Materials/Textures/baseTexture.js.map +1 -1
  190. package/Materials/Textures/cubeTexture.js.map +1 -1
  191. package/Materials/Textures/equiRectangularCubeTexture.js.map +1 -1
  192. package/Materials/Textures/hdrCubeTexture.js.map +1 -1
  193. package/Materials/Textures/htmlElementTexture.js +1 -4
  194. package/Materials/Textures/htmlElementTexture.js.map +1 -1
  195. package/Materials/Textures/internalTexture.js.map +1 -1
  196. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  197. package/Materials/Textures/texture.js.map +1 -1
  198. package/Materials/Textures/videoTexture.js +9 -22
  199. package/Materials/Textures/videoTexture.js.map +1 -1
  200. package/Materials/colorCurves.js.map +1 -1
  201. package/Materials/effect.js.map +1 -1
  202. package/Materials/greasedLinePluginMaterial.d.ts +307 -0
  203. package/Materials/greasedLinePluginMaterial.js +553 -0
  204. package/Materials/greasedLinePluginMaterial.js.map +1 -0
  205. package/Materials/imageProcessingConfiguration.js.map +1 -1
  206. package/Materials/index.d.ts +1 -0
  207. package/Materials/index.js +1 -0
  208. package/Materials/index.js.map +1 -1
  209. package/Materials/material.d.ts +3 -0
  210. package/Materials/material.decalMapConfiguration.js.map +1 -1
  211. package/Materials/material.detailMapConfiguration.js.map +1 -1
  212. package/Materials/material.js +40 -5
  213. package/Materials/material.js.map +1 -1
  214. package/Materials/materialPluginBase.d.ts +2 -2
  215. package/Materials/materialPluginBase.js +2 -2
  216. package/Materials/materialPluginBase.js.map +1 -1
  217. package/Materials/materialPluginManager.d.ts +3 -2
  218. package/Materials/materialPluginManager.js +3 -1
  219. package/Materials/materialPluginManager.js.map +1 -1
  220. package/Materials/multiMaterial.js +1 -1
  221. package/Materials/multiMaterial.js.map +1 -1
  222. package/Materials/shaderMaterial.d.ts +23 -4
  223. package/Materials/shaderMaterial.js +41 -21
  224. package/Materials/shaderMaterial.js.map +1 -1
  225. package/Materials/standardMaterial.d.ts +2 -1
  226. package/Materials/standardMaterial.js +4 -1
  227. package/Materials/standardMaterial.js.map +1 -1
  228. package/Materials/uniformBuffer.js.map +1 -1
  229. package/Maths/math.vector.d.ts +2 -1
  230. package/Maths/math.vector.js +3 -2
  231. package/Maths/math.vector.js.map +1 -1
  232. package/Meshes/Builders/decalBuilder.js +4 -4
  233. package/Meshes/Builders/decalBuilder.js.map +1 -1
  234. package/Meshes/Builders/greasedLineBuilder.d.ts +105 -0
  235. package/Meshes/Builders/greasedLineBuilder.js +330 -0
  236. package/Meshes/Builders/greasedLineBuilder.js.map +1 -0
  237. package/Meshes/Builders/index.d.ts +1 -0
  238. package/Meshes/Builders/index.js +1 -0
  239. package/Meshes/Builders/index.js.map +1 -1
  240. package/Meshes/abstractMesh.d.ts +3 -2
  241. package/Meshes/abstractMesh.js +5 -3
  242. package/Meshes/abstractMesh.js.map +1 -1
  243. package/Meshes/greasedLineMesh.d.ts +189 -0
  244. package/Meshes/greasedLineMesh.js +437 -0
  245. package/Meshes/greasedLineMesh.js.map +1 -0
  246. package/Meshes/index.d.ts +1 -0
  247. package/Meshes/index.js +1 -0
  248. package/Meshes/index.js.map +1 -1
  249. package/Meshes/mesh.d.ts +4 -0
  250. package/Meshes/mesh.js +20 -10
  251. package/Meshes/mesh.js.map +1 -1
  252. package/Meshes/mesh.vertexData.js.map +1 -1
  253. package/Meshes/meshUVSpaceRenderer.js +1 -8
  254. package/Meshes/meshUVSpaceRenderer.js.map +1 -1
  255. package/Meshes/transformNode.js.map +1 -1
  256. package/Misc/basis.js.map +1 -1
  257. package/Misc/deepCopier.js +8 -2
  258. package/Misc/deepCopier.js.map +1 -1
  259. package/Misc/dumpTools.d.ts +4 -3
  260. package/Misc/dumpTools.js +5 -4
  261. package/Misc/dumpTools.js.map +1 -1
  262. package/Misc/environmentTextureTools.js +1 -1
  263. package/Misc/environmentTextureTools.js.map +1 -1
  264. package/Misc/fileTools.js +10 -10
  265. package/Misc/fileTools.js.map +1 -1
  266. package/Misc/greasedLineTools.d.ts +141 -0
  267. package/Misc/greasedLineTools.js +263 -0
  268. package/Misc/greasedLineTools.js.map +1 -0
  269. package/Misc/index.d.ts +1 -0
  270. package/Misc/index.js +1 -0
  271. package/Misc/index.js.map +1 -1
  272. package/Misc/khronosTextureContainer.js.map +1 -1
  273. package/Misc/observable.d.ts +11 -0
  274. package/Misc/observable.js +26 -1
  275. package/Misc/observable.js.map +1 -1
  276. package/Misc/sceneOptimizer.js.map +1 -1
  277. package/Misc/screenshotTools.d.ts +15 -5
  278. package/Misc/screenshotTools.js +23 -13
  279. package/Misc/screenshotTools.js.map +1 -1
  280. package/Misc/smartArray.js.map +1 -1
  281. package/Misc/tools.d.ts +21 -9
  282. package/Misc/tools.js +21 -9
  283. package/Misc/tools.js.map +1 -1
  284. package/Misc/videoRecorder.js +1 -4
  285. package/Misc/videoRecorder.js.map +1 -1
  286. package/Misc/virtualJoystick.js +1 -4
  287. package/Misc/virtualJoystick.js.map +1 -1
  288. package/Misc/webRequest.js.map +1 -1
  289. package/Morph/morphTarget.js.map +1 -1
  290. package/Morph/morphTargetManager.js.map +1 -1
  291. package/Offline/database.js.map +1 -1
  292. package/Particles/baseParticleSystem.js.map +1 -1
  293. package/Particles/gpuParticleSystem.d.ts +1 -0
  294. package/Particles/gpuParticleSystem.js +5 -8
  295. package/Particles/gpuParticleSystem.js.map +1 -1
  296. package/Particles/particle.js.map +1 -1
  297. package/Particles/particleSystem.js +1 -1
  298. package/Particles/particleSystem.js.map +1 -1
  299. package/Particles/particleSystemSet.js.map +1 -1
  300. package/Physics/physicsHelper.js +4 -4
  301. package/Physics/physicsHelper.js.map +1 -1
  302. package/Physics/physicsRaycastResult.d.ts +3 -1
  303. package/Physics/physicsRaycastResult.js +10 -1
  304. package/Physics/physicsRaycastResult.js.map +1 -1
  305. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  306. package/Physics/v1/physicsImpostor.js.map +1 -1
  307. package/Physics/v2/IPhysicsEnginePlugin.d.ts +10 -0
  308. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  309. package/Physics/v2/Plugins/havokPlugin.d.ts +3 -2
  310. package/Physics/v2/Plugins/havokPlugin.js +9 -6
  311. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  312. package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
  313. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  314. package/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline.js.map +1 -1
  315. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
  316. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
  317. package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
  318. package/PostProcesses/blackAndWhitePostProcess.js.map +1 -1
  319. package/PostProcesses/bloomMergePostProcess.js.map +1 -1
  320. package/PostProcesses/blurPostProcess.js.map +1 -1
  321. package/PostProcesses/circleOfConfusionPostProcess.js.map +1 -1
  322. package/PostProcesses/colorCorrectionPostProcess.js.map +1 -1
  323. package/PostProcesses/convolutionPostProcess.js.map +1 -1
  324. package/PostProcesses/depthOfFieldBlurPostProcess.js.map +1 -1
  325. package/PostProcesses/extractHighlightsPostProcess.js.map +1 -1
  326. package/PostProcesses/filterPostProcess.js.map +1 -1
  327. package/PostProcesses/grainPostProcess.js.map +1 -1
  328. package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
  329. package/PostProcesses/motionBlurPostProcess.js.map +1 -1
  330. package/PostProcesses/postProcess.js.map +1 -1
  331. package/PostProcesses/refractionPostProcess.js.map +1 -1
  332. package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
  333. package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
  334. package/PostProcesses/sharpenPostProcess.js.map +1 -1
  335. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  336. package/Probes/reflectionProbe.js.map +1 -1
  337. package/Rendering/boundingBoxRenderer.js +2 -4
  338. package/Rendering/boundingBoxRenderer.js.map +1 -1
  339. package/Rendering/depthPeelingRenderer.js.map +1 -1
  340. package/Rendering/depthRenderer.js.map +1 -1
  341. package/Rendering/geometryBufferRenderer.js.map +1 -1
  342. package/Rendering/outlineRenderer.js.map +1 -1
  343. package/Rendering/prePassRenderer.js.map +1 -1
  344. package/Rendering/renderingGroup.js.map +1 -1
  345. package/Rendering/renderingManager.js.map +1 -1
  346. package/Rendering/subSurfaceConfiguration.js.map +1 -1
  347. package/Rendering/utilityLayerRenderer.js.map +1 -1
  348. package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.js +4 -2
  349. package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.js.map +1 -1
  350. package/Shaders/ShadersInclude/pbrDebug.js +11 -2
  351. package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
  352. package/Shaders/velocity.fragment.d.ts +5 -0
  353. package/Shaders/velocity.fragment.js +13 -0
  354. package/Shaders/velocity.fragment.js.map +1 -0
  355. package/Shaders/velocity.vertex.d.ts +7 -0
  356. package/Shaders/velocity.vertex.js +23 -0
  357. package/Shaders/velocity.vertex.js.map +1 -0
  358. package/Sprites/spriteManager.js.map +1 -1
  359. package/XR/features/WebXRAnchorSystem.js.map +1 -1
  360. package/XR/features/WebXRBackgroundRemover.js.map +1 -1
  361. package/XR/features/WebXRControllerMovement.js.map +1 -1
  362. package/XR/features/WebXRControllerPhysics.js +4 -13
  363. package/XR/features/WebXRControllerPhysics.js.map +1 -1
  364. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  365. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  366. package/XR/features/WebXRDOMOverlay.js.map +1 -1
  367. package/XR/features/WebXRDepthSensing.js.map +1 -1
  368. package/XR/features/WebXREyeTracking.js.map +1 -1
  369. package/XR/features/WebXRFeaturePointSystem.js.map +1 -1
  370. package/XR/features/WebXRHandTracking.js +2 -8
  371. package/XR/features/WebXRHandTracking.js.map +1 -1
  372. package/XR/features/WebXRHitTest.js.map +1 -1
  373. package/XR/features/WebXRHitTestLegacy.js.map +1 -1
  374. package/XR/features/WebXRImageTracking.js.map +1 -1
  375. package/XR/features/WebXRLayers.js +18 -8
  376. package/XR/features/WebXRLayers.js.map +1 -1
  377. package/XR/features/WebXRLightEstimation.js.map +1 -1
  378. package/XR/features/WebXRMeshDetector.js.map +1 -1
  379. package/XR/features/WebXRNearInteraction.js.map +1 -1
  380. package/XR/features/WebXRPlaneDetector.js.map +1 -1
  381. package/XR/features/WebXRSpaceWarp.d.ts +138 -0
  382. package/XR/features/WebXRSpaceWarp.js +290 -0
  383. package/XR/features/WebXRSpaceWarp.js.map +1 -0
  384. package/XR/features/index.d.ts +1 -0
  385. package/XR/features/index.js +1 -0
  386. package/XR/features/index.js.map +1 -1
  387. package/XR/motionController/webXRAbstractMotionController.js +1 -4
  388. package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
  389. package/XR/motionController/webXRControllerComponent.js.map +1 -1
  390. package/XR/motionController/webXRGenericMotionController.js.map +1 -1
  391. package/XR/motionController/webXRHTCViveMotionController.js.map +1 -1
  392. package/XR/motionController/webXRMicrosoftMixedRealityController.js.map +1 -1
  393. package/XR/motionController/webXROculusTouchMotionController.js.map +1 -1
  394. package/XR/webXRCamera.js.map +1 -1
  395. package/XR/webXRDefaultExperience.js +6 -28
  396. package/XR/webXRDefaultExperience.js.map +1 -1
  397. package/XR/webXRFeaturesManager.d.ts +4 -0
  398. package/XR/webXRFeaturesManager.js +5 -4
  399. package/XR/webXRFeaturesManager.js.map +1 -1
  400. package/XR/webXRInput.js +1 -6
  401. package/XR/webXRInput.js.map +1 -1
  402. package/XR/webXRSessionManager.d.ts +4 -0
  403. package/XR/webXRSessionManager.js +6 -0
  404. package/XR/webXRSessionManager.js.map +1 -1
  405. package/abstractScene.js.map +1 -1
  406. package/assetContainer.js +1 -4
  407. package/assetContainer.js.map +1 -1
  408. package/node.js.map +1 -1
  409. package/package.json +2 -4
  410. package/scene.d.ts +5 -2
  411. package/scene.js +9 -12
  412. package/scene.js.map +1 -1
@@ -0,0 +1,290 @@
1
+ import { WebXRFeatureName, WebXRFeaturesManager } from "../webXRFeaturesManager.js";
2
+ import { WebXRAbstractFeature } from "./WebXRAbstractFeature.js";
3
+ import { Matrix } from "../../Maths/math.vector.js";
4
+ import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
5
+
6
+ import { ShaderMaterial } from "../../Materials/shaderMaterial.js";
7
+ import "../../Shaders/velocity.fragment.js";
8
+ import "../../Shaders/velocity.vertex.js";
9
+ /**
10
+ * Used for Space Warp render process
11
+ */
12
+ export class XRSpaceWarpRenderTarget extends RenderTargetTexture {
13
+ /**
14
+ * Creates a Space Warp render target
15
+ * @param motionVectorTexture WebGLTexture provided by WebGLSubImage
16
+ * @param depthStencilTexture WebGLTexture provided by WebGLSubImage
17
+ * @param scene scene used with the render target
18
+ * @param size the size of the render target (used for each view)
19
+ */
20
+ constructor(motionVectorTexture, depthStencilTexture, scene, size = 512) {
21
+ super("spacewarp rtt", size, scene, false, true, 2, false, undefined, false, false, true, undefined, true);
22
+ this._originalPairing = [];
23
+ this._previousWorldMatrices = [];
24
+ this._previousTransforms = [Matrix.Identity(), Matrix.Identity()];
25
+ this._renderTarget = this.getScene()
26
+ .getEngine()
27
+ .createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);
28
+ this._renderTarget._disposeOnlyFramebuffers = true;
29
+ this._texture = this._renderTarget.texture;
30
+ this._texture.isMultiview = true;
31
+ this._texture.format = 5;
32
+ if (scene) {
33
+ this._velocityMaterial = new ShaderMaterial("velocity shader material", scene, {
34
+ vertex: "velocity",
35
+ fragment: "velocity",
36
+ }, {
37
+ uniforms: ["world", "previousWorld", "viewProjection", "viewProjectionR", "previousViewProjection", "previousViewProjectionR"],
38
+ });
39
+ this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;
40
+ this._velocityMaterial.onBindObservable.add((mesh) => {
41
+ // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).
42
+ // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter
43
+ this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();
44
+ this._velocityMaterial.getEffect().setMatrix("previousWorld", this._previousWorldMatrices[mesh.uniqueId]);
45
+ this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();
46
+ // now set the scene's previous matrix
47
+ this._velocityMaterial.getEffect().setMatrix("previousViewProjection", this._previousTransforms[0]);
48
+ // multiview for sure
49
+ this._velocityMaterial.getEffect().setMatrix("previousViewProjectionR", this._previousTransforms[1]);
50
+ // store the previous (current, to be exact) transforms
51
+ this._previousTransforms[0].copyFrom(scene.getTransformMatrix());
52
+ this._previousTransforms[1].copyFrom(scene._transformMatrixR);
53
+ });
54
+ this._velocityMaterial.freeze();
55
+ }
56
+ }
57
+ /**
58
+ * {@inheritDoc}
59
+ */
60
+ render(useCameraPostProcess = false, dumpForDebug = false) {
61
+ // Swap to use velocity material
62
+ this._originalPairing.length = 0;
63
+ const scene = this.getScene();
64
+ // set the velocity material to render the velocity RTT
65
+ if (scene && this._velocityMaterial) {
66
+ scene.getActiveMeshes().forEach((mesh) => {
67
+ this._originalPairing.push([mesh, mesh.material]);
68
+ mesh.material = this._velocityMaterial;
69
+ });
70
+ }
71
+ super.render(useCameraPostProcess, dumpForDebug);
72
+ // Restore original materials
73
+ this._originalPairing.forEach((tuple) => {
74
+ tuple[0].material = tuple[1];
75
+ });
76
+ }
77
+ /**
78
+ * @internal
79
+ */
80
+ _bindFrameBuffer() {
81
+ if (!this._renderTarget) {
82
+ return;
83
+ }
84
+ this.getScene().getEngine().bindSpaceWarpFramebuffer(this._renderTarget);
85
+ }
86
+ /**
87
+ * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)
88
+ * @returns the view count
89
+ */
90
+ getViewCount() {
91
+ return 2;
92
+ }
93
+ /**
94
+ * {@inheritdoc}
95
+ */
96
+ dispose() {
97
+ super.dispose();
98
+ this._velocityMaterial.dispose();
99
+ this._previousTransforms.length = 0;
100
+ this._previousWorldMatrices.length = 0;
101
+ this._originalPairing.length = 0;
102
+ }
103
+ }
104
+ /**
105
+ * WebXR Space Warp Render Target Texture Provider
106
+ */
107
+ export class WebXRSpaceWarpRenderTargetTextureProvider {
108
+ constructor(_scene, _xrSessionManager, _xrWebGLBinding) {
109
+ this._scene = _scene;
110
+ this._xrSessionManager = _xrSessionManager;
111
+ this._xrWebGLBinding = _xrWebGLBinding;
112
+ this._lastSubImages = new Map();
113
+ this._renderTargetTextures = new Map();
114
+ this._engine = _scene.getEngine();
115
+ }
116
+ _getSubImageForView(view) {
117
+ const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();
118
+ if (!layerWrapper) {
119
+ throw new Error("For Space Warp, the base layer should be a WebXR Projection Layer.");
120
+ }
121
+ if (layerWrapper.layerType !== "XRProjectionLayer") {
122
+ throw new Error('For Space Warp, the base layer type should "XRProjectionLayer".');
123
+ }
124
+ const layer = layerWrapper.layer;
125
+ return this._xrWebGLBinding.getViewSubImage(layer, view);
126
+ }
127
+ _setViewportForSubImage(viewport, subImage) {
128
+ viewport.x = 0;
129
+ viewport.y = 0;
130
+ viewport.width = subImage.motionVectorTextureWidth;
131
+ viewport.height = subImage.motionVectorTextureHeight;
132
+ }
133
+ _createRenderTargetTexture(width, height, framebuffer, motionVectorTexture, depthStencilTexture) {
134
+ if (!this._engine) {
135
+ throw new Error("Engine is disposed");
136
+ }
137
+ const textureSize = { width, height };
138
+ // Create render target texture from the internal texture
139
+ const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);
140
+ const renderTargetWrapper = renderTargetTexture.renderTarget;
141
+ if (framebuffer) {
142
+ renderTargetWrapper._framebuffer = framebuffer;
143
+ }
144
+ // Create internal texture
145
+ renderTargetWrapper._colorTextureArray = motionVectorTexture;
146
+ renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;
147
+ renderTargetTexture.disableRescaling();
148
+ renderTargetTexture.renderListPredicate = () => true;
149
+ return renderTargetTexture;
150
+ }
151
+ _getRenderTargetForSubImage(subImage, view) {
152
+ const lastSubImage = this._lastSubImages.get(view);
153
+ let renderTargetTexture = this._renderTargetTextures.get(view.eye);
154
+ const width = subImage.motionVectorTextureWidth;
155
+ const height = subImage.motionVectorTextureHeight;
156
+ if (!renderTargetTexture || (lastSubImage === null || lastSubImage === void 0 ? void 0 : lastSubImage.textureWidth) !== width || (lastSubImage === null || lastSubImage === void 0 ? void 0 : lastSubImage.textureHeight) != height) {
157
+ renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture, subImage.depthStencilTexture);
158
+ this._renderTargetTextures.set(view.eye, renderTargetTexture);
159
+ this._framebufferDimensions = {
160
+ framebufferWidth: width,
161
+ framebufferHeight: height,
162
+ };
163
+ }
164
+ this._lastSubImages.set(view, subImage);
165
+ return renderTargetTexture;
166
+ }
167
+ /**
168
+ * {@inheritDoc}
169
+ */
170
+ trySetViewportForView(viewport, view) {
171
+ const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);
172
+ if (subImage) {
173
+ this._setViewportForSubImage(viewport, subImage);
174
+ return true;
175
+ }
176
+ return false;
177
+ }
178
+ /**
179
+ * Access the motion vector (which will turn on Space Warp)
180
+ * @param view the view to access the motion vector texture for
181
+ */
182
+ accessMotionVector(view) {
183
+ const subImage = this._getSubImageForView(view);
184
+ if (subImage) {
185
+ // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp
186
+ subImage.motionVectorTexture;
187
+ subImage.depthStencilTexture;
188
+ }
189
+ }
190
+ /**
191
+ * {@inheritDoc}
192
+ */
193
+ getRenderTargetTextureForEye(_eye) {
194
+ return null;
195
+ }
196
+ /**
197
+ * {@inheritDoc}
198
+ */
199
+ getRenderTargetTextureForView(view) {
200
+ const subImage = this._getSubImageForView(view);
201
+ if (subImage) {
202
+ return this._getRenderTargetForSubImage(subImage, view);
203
+ }
204
+ return null;
205
+ }
206
+ /**
207
+ * {@inheritDoc}
208
+ */
209
+ dispose() {
210
+ this._renderTargetTextures.forEach((rtt) => rtt.dispose());
211
+ this._renderTargetTextures.clear();
212
+ }
213
+ }
214
+ /**
215
+ * the WebXR Space Warp feature.
216
+ */
217
+ export class WebXRSpaceWarp extends WebXRAbstractFeature {
218
+ /**
219
+ * constructor for the space warp feature
220
+ * @param _xrSessionManager the xr session manager for this feature
221
+ */
222
+ constructor(_xrSessionManager) {
223
+ super(_xrSessionManager);
224
+ /**
225
+ * {@inheritdoc}
226
+ */
227
+ this.dependsOn = [WebXRFeatureName.LAYERS];
228
+ this.xrNativeFeatureName = "space-warp";
229
+ this._xrSessionManager.scene.needsPreviousWorldMatrices = true;
230
+ }
231
+ /**
232
+ * Attach this feature.
233
+ * Will usually be called by the features manager.
234
+ *
235
+ * @returns true if successful.
236
+ */
237
+ attach() {
238
+ if (!super.attach()) {
239
+ return false;
240
+ }
241
+ const engine = this._xrSessionManager.scene.getEngine();
242
+ this._glContext = engine._gl;
243
+ this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);
244
+ this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);
245
+ this._xrSessionManager.scene.onAfterRenderObservable.add(this._onAfterRender.bind(this));
246
+ return true;
247
+ }
248
+ _onAfterRender() {
249
+ if (this.attached && this._renderTargetTexture) {
250
+ this._renderTargetTexture.render(false, false);
251
+ }
252
+ }
253
+ /**
254
+ * {@inheritdoc}
255
+ */
256
+ isCompatible() {
257
+ return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;
258
+ }
259
+ /**
260
+ * {@inheritdoc}
261
+ */
262
+ dispose() {
263
+ super.dispose();
264
+ }
265
+ _onXRFrame(_xrFrame) {
266
+ const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);
267
+ if (!pose) {
268
+ return;
269
+ }
270
+ // get the first view to which we will create a texture (or update it)
271
+ const view = pose.views[0];
272
+ this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider.getRenderTargetTextureForView(view);
273
+ this.spaceWarpRTTProvider.accessMotionVector(view);
274
+ }
275
+ }
276
+ /**
277
+ * The module's name
278
+ */
279
+ WebXRSpaceWarp.Name = WebXRFeatureName.SPACE_WARP;
280
+ /**
281
+ * The (Babylon) version of this module.
282
+ * This is an integer representing the implementation version.
283
+ * This number does not correspond to the WebXR specs version
284
+ */
285
+ WebXRSpaceWarp.Version = 1;
286
+ //register the plugin
287
+ WebXRFeaturesManager.AddWebXRFeature(WebXRSpaceWarp.Name, (xrSessionManager) => {
288
+ return () => new WebXRSpaceWarp(xrSessionManager);
289
+ }, WebXRSpaceWarp.Version, false);
290
+ //# sourceMappingURL=WebXRSpaceWarp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebXRSpaceWarp.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/WebXRSpaceWarp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIhE,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAM5D;;;;;;OAMG;IACH,YAAY,mBAAiC,EAAE,mBAAiC,EAAE,KAAa,EAAE,OAAuE,GAAG;QACvK,KAAK,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,sBAAsB,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAZtI,qBAAgB,GAA8C,EAAE,CAAC;QACjE,2BAAsB,GAAkB,EAAE,CAAC;QAC3C,wBAAmB,GAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,C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AM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,oBAAqB,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;QACxH,IAAI,CAAC,oBAAqB,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;;AAtFD;;GAEG;AACoB,mBAAI,GAAG,gBAAgB,CAAC,UAAU,AAA9B,CAA+B;AAC1D;;;;GAIG;AACoB,sBAAO,GAAG,CAAC,AAAJ,CAAK;AAgFvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,cAAc,CAAC,IAAI,EACnB,CAAC,gBAAgB,EAAE,EAAE;IACjB,OAAO,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAAC;AACtD,CAAC,EACD,cAAc,CAAC,OAAO,EACtB,KAAK,CACR,CAAC","sourcesContent":["import type { Engine } from \"../../Engines/engine\";\r\nimport type { WebGLRenderTargetWrapper } from \"../../Engines/WebGL/webGLRenderTargetWrapper\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IWebXRRenderTargetTextureProvider } from \"../webXRRenderTargetTextureProvider\";\r\nimport type { Viewport } from \"../../Maths/math.viewport\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix } from \"../../Maths/math.vector\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { ShaderMaterial } from \"../../Materials/shaderMaterial\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Material } from \"../../Materials/material\";\r\n\r\nimport \"../../Shaders/velocity.fragment\";\r\nimport \"../../Shaders/velocity.vertex\";\r\n\r\n/**\r\n * Used for Space Warp render process\r\n */\r\nexport class XRSpaceWarpRenderTarget extends RenderTargetTexture {\r\n private _velocityMaterial: ShaderMaterial;\r\n private _originalPairing: Array<[AbstractMesh, Nullable<Material>]> = [];\r\n private _previousWorldMatrices: Array<Matrix> = [];\r\n private _previousTransforms: Matrix[] = [Matrix.Identity(), Matrix.Identity()];\r\n\r\n /**\r\n * Creates a Space Warp render target\r\n * @param motionVectorTexture WebGLTexture provided by WebGLSubImage\r\n * @param depthStencilTexture WebGLTexture provided by WebGLSubImage\r\n * @param scene scene used with the render target\r\n * @param size the size of the render target (used for each view)\r\n */\r\n constructor(motionVectorTexture: WebGLTexture, depthStencilTexture: WebGLTexture, scene?: Scene, size: number | { width: number; height: number } | { ratio: number } = 512) {\r\n super(\"spacewarp rtt\", size, scene, false, true, Constants.TEXTURETYPE_HALF_FLOAT, false, undefined, false, false, true, undefined, true);\r\n this._renderTarget = this.getScene()!\r\n .getEngine()\r\n .createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight(), motionVectorTexture, depthStencilTexture);\r\n (this._renderTarget as WebGLRenderTargetWrapper)._disposeOnlyFramebuffers = true;\r\n this._texture = this._renderTarget.texture!;\r\n this._texture.isMultiview = true;\r\n this._texture.format = Constants.TEXTUREFORMAT_RGBA;\r\n\r\n if (scene) {\r\n this._velocityMaterial = new ShaderMaterial(\r\n \"velocity shader material\",\r\n scene,\r\n {\r\n vertex: \"velocity\",\r\n fragment: \"velocity\",\r\n },\r\n {\r\n uniforms: [\"world\", \"previousWorld\", \"viewProjection\", \"viewProjectionR\", \"previousViewProjection\", \"previousViewProjectionR\"],\r\n }\r\n );\r\n this._velocityMaterial._materialHelperNeedsPreviousMatrices = true;\r\n this._velocityMaterial.onBindObservable.add((mesh) => {\r\n // mesh. getWorldMatrix can be incorrect under rare conditions (e.g. when using a effective mesh in the render function).\r\n // If the case arise that will require changing it we will need to change the bind process in the material class to also provide the world matrix as a parameter\r\n this._previousWorldMatrices[mesh.uniqueId] = this._previousWorldMatrices[mesh.uniqueId] || mesh.getWorldMatrix();\r\n this._velocityMaterial.getEffect().setMatrix(\"previousWorld\", this._previousWorldMatrices[mesh.uniqueId]);\r\n this._previousWorldMatrices[mesh.uniqueId] = mesh.getWorldMatrix();\r\n // now set the scene's previous matrix\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjection\", this._previousTransforms[0]);\r\n // multiview for sure\r\n this._velocityMaterial.getEffect().setMatrix(\"previousViewProjectionR\", this._previousTransforms[1]);\r\n\r\n // store the previous (current, to be exact) transforms\r\n this._previousTransforms[0].copyFrom(scene.getTransformMatrix());\r\n this._previousTransforms[1].copyFrom(scene._transformMatrixR);\r\n });\r\n this._velocityMaterial.freeze();\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public render(useCameraPostProcess: boolean = false, dumpForDebug: boolean = false): void {\r\n // Swap to use velocity material\r\n this._originalPairing.length = 0;\r\n const scene = this.getScene();\r\n // set the velocity material to render the velocity RTT\r\n if (scene && this._velocityMaterial) {\r\n scene.getActiveMeshes().forEach((mesh) => {\r\n this._originalPairing.push([mesh, mesh.material]);\r\n mesh.material = this._velocityMaterial;\r\n });\r\n }\r\n\r\n super.render(useCameraPostProcess, dumpForDebug);\r\n\r\n // Restore original materials\r\n this._originalPairing.forEach((tuple) => {\r\n tuple[0].material = tuple[1];\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _bindFrameBuffer() {\r\n if (!this._renderTarget) {\r\n return;\r\n }\r\n this.getScene()!.getEngine().bindSpaceWarpFramebuffer(this._renderTarget);\r\n }\r\n\r\n /**\r\n * Gets the number of views the corresponding to the texture (eg. a SpaceWarpRenderTarget will have > 1)\r\n * @returns the view count\r\n */\r\n public getViewCount() {\r\n return 2;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n this._velocityMaterial.dispose();\r\n this._previousTransforms.length = 0;\r\n this._previousWorldMatrices.length = 0;\r\n this._originalPairing.length = 0;\r\n }\r\n}\r\n\r\n/**\r\n * WebXR Space Warp Render Target Texture Provider\r\n */\r\nexport class WebXRSpaceWarpRenderTargetTextureProvider implements IWebXRRenderTargetTextureProvider {\r\n protected _lastSubImages = new Map<XRView, XRWebGLSubImage>();\r\n protected _renderTargetTextures = new Map<XREye, RenderTargetTexture>();\r\n protected _framebufferDimensions: Nullable<{ framebufferWidth: number; framebufferHeight: number }>;\r\n protected _engine: Engine;\r\n\r\n constructor(protected readonly _scene: Scene, protected readonly _xrSessionManager: WebXRSessionManager, protected readonly _xrWebGLBinding: XRWebGLBinding) {\r\n this._engine = _scene.getEngine();\r\n }\r\n\r\n private _getSubImageForView(view: XRView): XRWebGLSubImage {\r\n const layerWrapper = this._xrSessionManager._getBaseLayerWrapper();\r\n if (!layerWrapper) {\r\n throw new Error(\"For Space Warp, the base layer should be a WebXR Projection Layer.\");\r\n }\r\n if (layerWrapper.layerType !== \"XRProjectionLayer\") {\r\n throw new Error('For Space Warp, the base layer type should \"XRProjectionLayer\".');\r\n }\r\n const layer = layerWrapper.layer as XRProjectionLayer;\r\n return this._xrWebGLBinding.getViewSubImage(layer, view);\r\n }\r\n\r\n protected _setViewportForSubImage(viewport: Viewport, subImage: XRWebGLSubImage) {\r\n viewport.x = 0;\r\n viewport.y = 0;\r\n viewport.width = subImage.motionVectorTextureWidth!;\r\n viewport.height = subImage.motionVectorTextureHeight!;\r\n }\r\n\r\n protected _createRenderTargetTexture(\r\n width: number,\r\n height: number,\r\n framebuffer: Nullable<WebGLFramebuffer>,\r\n motionVectorTexture: WebGLTexture,\r\n depthStencilTexture: WebGLTexture\r\n ): RenderTargetTexture {\r\n if (!this._engine) {\r\n throw new Error(\"Engine is disposed\");\r\n }\r\n\r\n const textureSize = { width, height };\r\n\r\n // Create render target texture from the internal texture\r\n const renderTargetTexture = new XRSpaceWarpRenderTarget(motionVectorTexture, depthStencilTexture, this._scene, textureSize);\r\n const renderTargetWrapper = renderTargetTexture.renderTarget as WebGLRenderTargetWrapper;\r\n if (framebuffer) {\r\n renderTargetWrapper._framebuffer = framebuffer;\r\n }\r\n\r\n // Create internal texture\r\n renderTargetWrapper._colorTextureArray = motionVectorTexture;\r\n renderTargetWrapper._depthStencilTextureArray = depthStencilTexture;\r\n\r\n renderTargetTexture.disableRescaling();\r\n renderTargetTexture.renderListPredicate = () => true;\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n protected _getRenderTargetForSubImage(subImage: XRWebGLSubImage, view: XRView) {\r\n const lastSubImage = this._lastSubImages.get(view);\r\n let renderTargetTexture = this._renderTargetTextures.get(view.eye);\r\n\r\n const width = subImage.motionVectorTextureWidth!;\r\n const height = subImage.motionVectorTextureHeight!;\r\n\r\n if (!renderTargetTexture || lastSubImage?.textureWidth !== width || lastSubImage?.textureHeight != height) {\r\n renderTargetTexture = this._createRenderTargetTexture(width, height, null, subImage.motionVectorTexture!, subImage.depthStencilTexture!);\r\n this._renderTargetTextures.set(view.eye, renderTargetTexture);\r\n\r\n this._framebufferDimensions = {\r\n framebufferWidth: width,\r\n framebufferHeight: height,\r\n };\r\n }\r\n\r\n this._lastSubImages.set(view, subImage);\r\n\r\n return renderTargetTexture;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n const subImage = this._lastSubImages.get(view) || this._getSubImageForView(view);\r\n if (subImage) {\r\n this._setViewportForSubImage(viewport, subImage);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Access the motion vector (which will turn on Space Warp)\r\n * @param view the view to access the motion vector texture for\r\n */\r\n public accessMotionVector(view: XRView): void {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n // Meta Quest Browser uses accessing these textures as a sign for turning on Space Warp\r\n subImage.motionVectorTexture;\r\n subImage.depthStencilTexture;\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForEye(_eye: XREye): Nullable<RenderTargetTexture> {\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n const subImage = this._getSubImageForView(view);\r\n if (subImage) {\r\n return this._getRenderTargetForSubImage(subImage, view);\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * {@inheritDoc}\r\n */\r\n public dispose() {\r\n this._renderTargetTextures.forEach((rtt) => rtt.dispose());\r\n this._renderTargetTextures.clear();\r\n }\r\n}\r\n\r\n/**\r\n * the WebXR Space Warp feature.\r\n */\r\nexport class WebXRSpaceWarp extends WebXRAbstractFeature {\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.SPACE_WARP;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * The space warp provider\r\n */\r\n public spaceWarpRTTProvider: Nullable<WebXRSpaceWarpRenderTargetTextureProvider>;\r\n private _glContext: WebGLRenderingContext | WebGL2RenderingContext;\r\n private _xrWebGLBinding: XRWebGLBinding;\r\n private _renderTargetTexture: Nullable<RenderTargetTexture>;\r\n\r\n /**\r\n * constructor for the space warp feature\r\n * @param _xrSessionManager the xr session manager for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"space-warp\";\r\n this._xrSessionManager.scene.needsPreviousWorldMatrices = true;\r\n }\r\n\r\n /**\r\n * Attach this feature.\r\n * Will usually be called by the features manager.\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n this._glContext = engine._gl;\r\n this._xrWebGLBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n this.spaceWarpRTTProvider = new WebXRSpaceWarpRenderTargetTextureProvider(this._xrSessionManager.scene, this._xrSessionManager, this._xrWebGLBinding);\r\n\r\n this._xrSessionManager.scene.onAfterRenderObservable.add(this._onAfterRender.bind(this));\r\n\r\n return true;\r\n }\r\n\r\n private _onAfterRender(): void {\r\n if (this.attached && this._renderTargetTexture) {\r\n this._renderTargetTexture.render(false, false);\r\n }\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dependsOn: string[] = [WebXRFeatureName.LAYERS];\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public isCompatible(): boolean {\r\n return this._xrSessionManager.scene.getEngine().getCaps().colorBufferHalfFloat || false;\r\n }\r\n\r\n /**\r\n * {@inheritdoc}\r\n */\r\n public dispose(): void {\r\n super.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const pose = _xrFrame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n\r\n // get the first view to which we will create a texture (or update it)\r\n const view = pose.views[0];\r\n this._renderTargetTexture = this._renderTargetTexture || this.spaceWarpRTTProvider!.getRenderTargetTextureForView(view);\r\n this.spaceWarpRTTProvider!.accessMotionVector(view);\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRSpaceWarp.Name,\r\n (xrSessionManager) => {\r\n return () => new WebXRSpaceWarp(xrSessionManager);\r\n },\r\n WebXRSpaceWarp.Version,\r\n false\r\n);\r\n"]}
@@ -19,3 +19,4 @@ export * from "./WebXREyeTracking";
19
19
  export * from "./WebXRWalkingLocomotion";
20
20
  export * from "./WebXRLayers";
21
21
  export * from "./WebXRDepthSensing";
22
+ export * from "./WebXRSpaceWarp";
@@ -19,4 +19,5 @@ export * from "./WebXREyeTracking.js";
19
19
  export * from "./WebXRWalkingLocomotion.js";
20
20
  export * from "./WebXRLayers.js";
21
21
  export * from "./WebXRDepthSensing.js";
22
+ export * from "./WebXRSpaceWarp.js";
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./WebXRAbstractFeature\";\r\nexport * from \"./WebXRHitTestLegacy\";\r\nexport * from \"./WebXRAnchorSystem\";\r\nexport * from \"./WebXRPlaneDetector\";\r\nexport * from \"./WebXRBackgroundRemover\";\r\nexport * from \"./WebXRControllerTeleportation\";\r\nexport * from \"./WebXRControllerPointerSelection\";\r\nexport * from \"./WebXRControllerPhysics\";\r\nexport * from \"./WebXRHitTest\";\r\nexport * from \"./WebXRFeaturePointSystem\";\r\nexport * from \"./WebXRHandTracking\";\r\nexport * from \"./WebXRMeshDetector\";\r\nexport * from \"./WebXRImageTracking\";\r\nexport * from \"./WebXRNearInteraction\";\r\nexport * from \"./WebXRDOMOverlay\";\r\nexport * from \"./WebXRControllerMovement\";\r\nexport * from \"./WebXRLightEstimation\";\r\nexport * from \"./WebXREyeTracking\";\r\nexport * from \"./WebXRWalkingLocomotion\";\r\nexport * from \"./WebXRLayers\";\r\nexport * from \"./WebXRDepthSensing\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from \"./WebXRAbstractFeature\";\r\nexport * from \"./WebXRHitTestLegacy\";\r\nexport * from \"./WebXRAnchorSystem\";\r\nexport * from \"./WebXRPlaneDetector\";\r\nexport * from \"./WebXRBackgroundRemover\";\r\nexport * from \"./WebXRControllerTeleportation\";\r\nexport * from \"./WebXRControllerPointerSelection\";\r\nexport * from \"./WebXRControllerPhysics\";\r\nexport * from \"./WebXRHitTest\";\r\nexport * from \"./WebXRFeaturePointSystem\";\r\nexport * from \"./WebXRHandTracking\";\r\nexport * from \"./WebXRMeshDetector\";\r\nexport * from \"./WebXRImageTracking\";\r\nexport * from \"./WebXRNearInteraction\";\r\nexport * from \"./WebXRDOMOverlay\";\r\nexport * from \"./WebXRControllerMovement\";\r\nexport * from \"./WebXRLightEstimation\";\r\nexport * from \"./WebXREyeTracking\";\r\nexport * from \"./WebXRWalkingLocomotion\";\r\nexport * from \"./WebXRLayers\";\r\nexport * from \"./WebXRDepthSensing\";\r\nexport * from \"./WebXRSpaceWarp\";\r\n"]}
@@ -170,10 +170,7 @@ export class WebXRAbstractMotionController {
170
170
  }
171
171
  SceneLoader.ImportMesh("", loadingParams.path, loadingParams.filename, this.scene, (meshes) => {
172
172
  if (this._controllerCache) {
173
- this._controllerCache.push({
174
- ...loadingParams,
175
- meshes,
176
- });
173
+ this._controllerCache.push(Object.assign(Object.assign({}, loadingParams), { meshes }));
177
174
  }
178
175
  meshesLoaded(meshes);
179
176
  }, null, (_scene, message) => {
@@ -1 +1 @@
1
- {"version":3,"file":"webXRAbstractMotionController.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/motionController/webXRAbstractMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAyNzC;;;;GAIG;AACH,MAAM,OAAgB,6BAA6B;IA4C/C;;;;;;;;OAQG;IACH;IACI,gEAAgE;IACtD,KAAY;IACtB,gEAAgE;IACtD,MAA+B;IACzC;;OAEG;IACI,aAA6C;IACpD;;OAEG;IACI,UAAsC;IAC7C;;OAEG;IACI,2BAAoC,KAAK,EACxC,gBAIN;QAnBQ,UAAK,GAAL,KAAK,CAAO;QAEZ,WAAM,GAAN,MAAM,CAAyB;QAIlC,kBAAa,GAAb,aAAa,CAAgC;QAI7C,eAAU,GAAV,UAAU,CA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AC,kBAAkB,CAAC,CAAC;QAC/I,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjH,CAAC;IAED;;;OAGG;IACH,gEAAgE;IACtD,WAAW,CAAC,OAAgB;QAClC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACnB,OAAO;SACV;QACD,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IA+BO,0BAA0B;QAC9B,OAAO;YACH,QAAQ,EAAE,iBAAiB;YAC3B,IAAI,EAAE,4CAA4C;SACrD,CAAC;IACN,CAAC;IAEO,qBAAqB,CAAC,MAAsB;QAChD,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAE7E,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACd,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;gBACxB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC;CACJ","sourcesContent":["import type { IDisposable, Scene } from \"../../scene\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\n\r\n/**\r\n * Handedness type in xrInput profiles. These can be used to define layouts in the Layout Map.\r\n */\r\nexport type MotionControllerHandedness = \"none\" | \"left\" | \"right\";\r\n/**\r\n * The type of components available in motion controllers.\r\n * This is not the name of the component.\r\n */\r\nexport type MotionControllerComponentType = \"trigger\" | \"squeeze\" | \"touchpad\" | \"thumbstick\" | \"button\";\r\n\r\n/**\r\n * The state of a controller component\r\n */\r\nexport type MotionControllerComponentStateType = \"default\" | \"touched\" | \"pressed\";\r\n\r\n/**\r\n * The schema of motion controller layout.\r\n * No object will be initialized using this interface\r\n * This is used just to define the profile.\r\n */\r\nexport interface IMotionControllerLayout {\r\n /**\r\n * Path to load the assets. Usually relative to the base path\r\n */\r\n assetPath: string;\r\n /**\r\n * Available components (unsorted)\r\n */\r\n components: {\r\n /**\r\n * A map of component Ids\r\n */\r\n [componentId: string]: {\r\n /**\r\n * The type of input the component outputs\r\n */\r\n type: MotionControllerComponentType;\r\n /**\r\n * The indices of this component in the gamepad object\r\n */\r\n gamepadIndices: {\r\n /**\r\n * Index of button\r\n */\r\n button?: number;\r\n /**\r\n * If available, index of x-axis\r\n */\r\n xAxis?: number;\r\n /**\r\n * If available, index of y-axis\r\n */\r\n yAxis?: number;\r\n };\r\n /**\r\n * The mesh's root node name\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Animation definitions for this model\r\n */\r\n visualResponses: {\r\n [stateKey: string]: {\r\n /**\r\n * What property will be animated\r\n */\r\n componentProperty: \"xAxis\" | \"yAxis\" | \"button\" | \"state\";\r\n /**\r\n * What states influence this visual response\r\n */\r\n states: MotionControllerComponentStateType[];\r\n /**\r\n * Type of animation - movement or visibility\r\n */\r\n valueNodeProperty: \"transform\" | \"visibility\";\r\n /**\r\n * Base node name to move. Its position will be calculated according to the min and max nodes\r\n */\r\n valueNodeName?: string;\r\n /**\r\n * Minimum movement node\r\n */\r\n minNodeName?: string;\r\n /**\r\n * Max movement node\r\n */\r\n maxNodeName?: string;\r\n };\r\n };\r\n /**\r\n * If touch enabled, what is the name of node to display user feedback\r\n */\r\n touchPointNodeName?: string;\r\n };\r\n };\r\n /**\r\n * Is it xr standard mapping or not\r\n */\r\n gamepadMapping: \"\" | \"xr-standard\";\r\n /**\r\n * Base root node of this entire model\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Defines the main button component id\r\n */\r\n selectComponentId: string;\r\n}\r\n\r\n/**\r\n * A definition for the layout map in the input profile\r\n */\r\nexport interface IMotionControllerLayoutMap {\r\n /**\r\n * Layouts with handedness type as a key\r\n */\r\n [handedness: string /* handedness */]: IMotionControllerLayout;\r\n}\r\n\r\n/**\r\n * The XR Input profile schema\r\n * Profiles can be found here:\r\n * https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/registry/profiles\r\n */\r\nexport interface IMotionControllerProfile {\r\n /**\r\n * fallback profiles for this profileId\r\n */\r\n fallbackProfileIds: string[];\r\n /**\r\n * The layout map, with handedness as key\r\n */\r\n layouts: IMotionControllerLayoutMap;\r\n /**\r\n * The id of this profile\r\n * correlates to the profile(s) in the xrInput.profiles array\r\n */\r\n profileId: string;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller button animation\r\n * The meshes are provided to the _lerpButtonTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerButtonMeshMap {\r\n /**\r\n * the mesh that defines the pressed value mesh position.\r\n * This is used to find the max-position of this button\r\n */\r\n pressedMesh: AbstractMesh;\r\n /**\r\n * the mesh that defines the unpressed value mesh position.\r\n * This is used to find the min (or initial) position of this button\r\n */\r\n unpressedMesh: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when value changes\r\n */\r\n valueMesh: AbstractMesh;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller axis animation.\r\n * This will be expanded when touchpad animations are fully supported\r\n * The meshes are provided to the _lerpAxisTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerMeshMap {\r\n /**\r\n * the mesh that defines the maximum value mesh position.\r\n */\r\n maxMesh?: AbstractMesh;\r\n /**\r\n * the mesh that defines the minimum value mesh position.\r\n */\r\n minMesh?: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when axis value changes\r\n */\r\n valueMesh?: AbstractMesh;\r\n}\r\n\r\n/**\r\n * The elements needed for change-detection of the gamepad objects in motion controllers\r\n */\r\nexport interface IMinimalMotionControllerObject {\r\n /**\r\n * Available axes of this controller\r\n */\r\n axes: number[];\r\n /**\r\n * An array of available buttons\r\n */\r\n buttons: Array<{\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n }>;\r\n\r\n /**\r\n * EXPERIMENTAL haptic support.\r\n */\r\n hapticActuators?: Array<{\r\n pulse: (value: number, duration: number) => Promise<boolean>;\r\n }>;\r\n}\r\n\r\n/**\r\n * An Abstract Motion controller\r\n * This class receives an xrInput and a profile layout and uses those to initialize the components\r\n * Each component has an observable to check for changes in value and state\r\n */\r\nexport abstract class WebXRAbstractMotionController implements IDisposable {\r\n private _initComponent = (id: string) => {\r\n if (!id) {\r\n return;\r\n }\r\n const componentDef = this.layout.components[id];\r\n const type = componentDef.type;\r\n const buttonIndex = componentDef.gamepadIndices.button;\r\n // search for axes\r\n const axes: number[] = [];\r\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\r\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\r\n }\r\n\r\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\r\n };\r\n\r\n private _modelReady: boolean = false;\r\n\r\n /**\r\n * A map of components (WebXRControllerComponent) in this motion controller\r\n * Components have a ComponentType and can also have both button and axis definitions\r\n */\r\n public readonly components: {\r\n [id: string]: WebXRControllerComponent;\r\n } = {};\r\n\r\n /**\r\n * Disable the model's animation. Can be set at any time.\r\n */\r\n public disableAnimation: boolean = false;\r\n /**\r\n * Observers registered here will be triggered when the model of this controller is done loading\r\n */\r\n public onModelLoadedObservable: Observable<WebXRAbstractMotionController> = new Observable();\r\n /**\r\n * The profile id of this motion controller\r\n */\r\n public abstract profileId: string;\r\n /**\r\n * The root mesh of the model. It is null if the model was not yet initialized\r\n */\r\n public rootMesh: Nullable<AbstractMesh>;\r\n\r\n /**\r\n * constructs a new abstract motion controller\r\n * @param scene the scene to which the model of the controller will be added\r\n * @param layout The profile layout to load\r\n * @param gamepadObject The gamepad object correlating to this controller\r\n * @param handedness handedness (left/right/none) of this controller\r\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\r\n * @param _controllerCache a cache holding controller models already loaded in this session\r\n */\r\n constructor(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected scene: Scene,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected layout: IMotionControllerLayout,\r\n /**\r\n * The gamepad object correlating to this controller\r\n */\r\n public gamepadObject: IMinimalMotionControllerObject,\r\n /**\r\n * handedness (left/right/none) of this controller\r\n */\r\n public handedness: MotionControllerHandedness,\r\n /**\r\n * @internal\r\n */\r\n public _doNotLoadControllerMesh: boolean = false,\r\n private _controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n // initialize the components\r\n if (layout.components) {\r\n Object.keys(layout.components).forEach(this._initComponent);\r\n }\r\n // Model is loaded in WebXRInput\r\n }\r\n\r\n /**\r\n * Dispose this controller, the model mesh and all its components\r\n */\r\n public dispose(): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).dispose());\r\n if (this.rootMesh) {\r\n this.rootMesh.getChildren(undefined, true).forEach((node) => {\r\n node.setEnabled(false);\r\n });\r\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\r\n }\r\n }\r\n\r\n /**\r\n * Returns all components of specific type\r\n * @param type the type to search for\r\n * @returns an array of components with this type\r\n */\r\n public getAllComponentsOfType(type: MotionControllerComponentType): WebXRControllerComponent[] {\r\n return this.getComponentIds()\r\n .map((id) => this.components[id])\r\n .filter((component) => component.type === type);\r\n }\r\n\r\n /**\r\n * get a component based an its component id as defined in layout.components\r\n * @param id the id of the component\r\n * @returns the component correlates to the id or undefined if not found\r\n */\r\n public getComponent(id: string): WebXRControllerComponent {\r\n return this.components[id];\r\n }\r\n\r\n /**\r\n * Get the list of components available in this motion controller\r\n * @returns an array of strings correlating to available components\r\n */\r\n public getComponentIds(): string[] {\r\n return Object.keys(this.components);\r\n }\r\n\r\n /**\r\n * Get the first component of specific type\r\n * @param type type of component to find\r\n * @returns a controller component or null if not found\r\n */\r\n public getComponentOfType(type: MotionControllerComponentType): Nullable<WebXRControllerComponent> {\r\n return this.getAllComponentsOfType(type)[0] || null;\r\n }\r\n\r\n /**\r\n * Get the main (Select) component of this controller as defined in the layout\r\n * @returns the main component of this controller\r\n */\r\n public getMainComponent(): WebXRControllerComponent {\r\n return this.getComponent(this.layout.selectComponentId);\r\n }\r\n\r\n /**\r\n * Loads the model correlating to this controller\r\n * When the mesh is loaded, the onModelLoadedObservable will be triggered\r\n * @returns A promise fulfilled with the result of the model loading\r\n */\r\n public async loadModel(): Promise<boolean> {\r\n const useGeneric = !this._getModelLoadingConstraints();\r\n let loadingParams = this._getGenericFilenameAndPath();\r\n // Checking if GLB loader is present\r\n if (useGeneric) {\r\n Logger.Warn(\"Falling back to generic models\");\r\n } else {\r\n loadingParams = this._getFilenameAndPath();\r\n }\r\n return new Promise((resolve, reject) => {\r\n const meshesLoaded = (meshes: AbstractMesh[]) => {\r\n if (useGeneric) {\r\n this._getGenericParentMesh(meshes);\r\n } else {\r\n this._setRootMesh(meshes);\r\n }\r\n this._processLoadedModel(meshes);\r\n this._modelReady = true;\r\n this.onModelLoadedObservable.notifyObservers(this);\r\n resolve(true);\r\n };\r\n if (this._controllerCache) {\r\n // look for it in the cache\r\n const found = this._controllerCache.filter((c) => {\r\n return c.filename === loadingParams.filename && c.path === loadingParams.path;\r\n });\r\n if (found[0]) {\r\n found[0].meshes.forEach((mesh) => mesh.setEnabled(true));\r\n meshesLoaded(found[0].meshes);\r\n return;\r\n // found, don't continue to load\r\n }\r\n }\r\n SceneLoader.ImportMesh(\r\n \"\",\r\n loadingParams.path,\r\n loadingParams.filename,\r\n this.scene,\r\n (meshes) => {\r\n if (this._controllerCache) {\r\n this._controllerCache.push({\r\n ...loadingParams,\r\n meshes,\r\n });\r\n }\r\n meshesLoaded(meshes);\r\n },\r\n null,\r\n (_scene: Scene, message: string) => {\r\n Logger.Log(message);\r\n Logger.Warn(`Failed to retrieve controller model of type ${this.profileId} from the remote server: ${loadingParams.path}${loadingParams.filename}`);\r\n reject(message);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Update this model using the current XRFrame\r\n * @param xrFrame the current xr frame to use and update the model\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).update(this.gamepadObject));\r\n this.updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Backwards compatibility due to a deeply-integrated typo\r\n */\r\n public get handness() {\r\n return this.handedness;\r\n }\r\n\r\n /**\r\n * Pulse (vibrate) this controller\r\n * If the controller does not support pulses, this function will fail silently and return Promise<false> directly after called\r\n * Consecutive calls to this function will cancel the last pulse call\r\n *\r\n * @param value the strength of the pulse in 0.0...1.0 range\r\n * @param duration Duration of the pulse in milliseconds\r\n * @param hapticActuatorIndex optional index of actuator (will usually be 0)\r\n * @returns a promise that will send true when the pulse has ended and false if the device doesn't support pulse or an error accrued\r\n */\r\n public pulse(value: number, duration: number, hapticActuatorIndex: number = 0): Promise<boolean> {\r\n if (this.gamepadObject.hapticActuators && this.gamepadObject.hapticActuators[hapticActuatorIndex]) {\r\n return this.gamepadObject.hapticActuators[hapticActuatorIndex].pulse(value, duration);\r\n } else {\r\n return Promise.resolve(false);\r\n }\r\n }\r\n\r\n // Look through all children recursively. This will return null if no mesh exists with the given name.\r\n protected _getChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name === name, false)[0];\r\n }\r\n\r\n // Look through only immediate children. This will return null if no mesh exists with the given name.\r\n protected _getImmediateChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name == name, true)[0];\r\n }\r\n\r\n /**\r\n * Moves the axis on the controller mesh based on its current state\r\n * @param axisMap\r\n * @param axisValue the value of the axis which determines the meshes new position\r\n * @internal\r\n */\r\n protected _lerpTransform(axisMap: IMotionControllerMeshMap, axisValue: number, fixValueCoordinates?: boolean): void {\r\n if (!axisMap.minMesh || !axisMap.maxMesh || !axisMap.valueMesh) {\r\n return;\r\n }\r\n\r\n if (!axisMap.minMesh.rotationQuaternion || !axisMap.maxMesh.rotationQuaternion || !axisMap.valueMesh.rotationQuaternion) {\r\n return;\r\n }\r\n\r\n // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)\r\n const lerpValue = fixValueCoordinates ? axisValue * 0.5 + 0.5 : axisValue;\r\n Quaternion.SlerpToRef(axisMap.minMesh.rotationQuaternion, axisMap.maxMesh.rotationQuaternion, lerpValue, axisMap.valueMesh.rotationQuaternion);\r\n Vector3.LerpToRef(axisMap.minMesh.position, axisMap.maxMesh.position, lerpValue, axisMap.valueMesh.position);\r\n }\r\n\r\n /**\r\n * Update the model itself with the current frame data\r\n * @param xrFrame the frame to use for updating the model mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected updateModel(xrFrame: XRFrame): void {\r\n if (!this._modelReady) {\r\n return;\r\n }\r\n this._updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Get the filename and path for this controller's model\r\n * @returns a map of filename and path\r\n */\r\n protected abstract _getFilenameAndPath(): { filename: string; path: string };\r\n /**\r\n * This function is called before the mesh is loaded. It checks for loading constraints.\r\n * For example, this function can check if the GLB loader is available\r\n * If this function returns false, the generic controller will be loaded instead\r\n * @returns Is the client ready to load the mesh\r\n */\r\n protected abstract _getModelLoadingConstraints(): boolean;\r\n /**\r\n * This function will be called after the model was successfully loaded and can be used\r\n * for mesh transformations before it is available for the user\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _processLoadedModel(meshes: AbstractMesh[]): void;\r\n /**\r\n * Set the root mesh for this controller. Important for the WebXR controller class\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _setRootMesh(meshes: AbstractMesh[]): void;\r\n /**\r\n * A function executed each frame that updates the mesh (if needed)\r\n * @param xrFrame the current xrFrame\r\n */\r\n protected abstract _updateModel(xrFrame: XRFrame): void;\r\n\r\n private _getGenericFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n private _getGenericParentMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n meshes.forEach((mesh) => {\r\n if (!mesh.parent) {\r\n mesh.isPickable = false;\r\n mesh.setParent(this.rootMesh);\r\n }\r\n });\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRAbstractMotionController.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/motionController/webXRAbstractMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,O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AC,QAAQ,CAAC,CAAC;aACjC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC;CACJ","sourcesContent":["import type { IDisposable, Scene } from \"../../scene\";\r\nimport { WebXRControllerComponent } from \"./webXRControllerComponent\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\n\r\n/**\r\n * Handedness type in xrInput profiles. These can be used to define layouts in the Layout Map.\r\n */\r\nexport type MotionControllerHandedness = \"none\" | \"left\" | \"right\";\r\n/**\r\n * The type of components available in motion controllers.\r\n * This is not the name of the component.\r\n */\r\nexport type MotionControllerComponentType = \"trigger\" | \"squeeze\" | \"touchpad\" | \"thumbstick\" | \"button\";\r\n\r\n/**\r\n * The state of a controller component\r\n */\r\nexport type MotionControllerComponentStateType = \"default\" | \"touched\" | \"pressed\";\r\n\r\n/**\r\n * The schema of motion controller layout.\r\n * No object will be initialized using this interface\r\n * This is used just to define the profile.\r\n */\r\nexport interface IMotionControllerLayout {\r\n /**\r\n * Path to load the assets. Usually relative to the base path\r\n */\r\n assetPath: string;\r\n /**\r\n * Available components (unsorted)\r\n */\r\n components: {\r\n /**\r\n * A map of component Ids\r\n */\r\n [componentId: string]: {\r\n /**\r\n * The type of input the component outputs\r\n */\r\n type: MotionControllerComponentType;\r\n /**\r\n * The indices of this component in the gamepad object\r\n */\r\n gamepadIndices: {\r\n /**\r\n * Index of button\r\n */\r\n button?: number;\r\n /**\r\n * If available, index of x-axis\r\n */\r\n xAxis?: number;\r\n /**\r\n * If available, index of y-axis\r\n */\r\n yAxis?: number;\r\n };\r\n /**\r\n * The mesh's root node name\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Animation definitions for this model\r\n */\r\n visualResponses: {\r\n [stateKey: string]: {\r\n /**\r\n * What property will be animated\r\n */\r\n componentProperty: \"xAxis\" | \"yAxis\" | \"button\" | \"state\";\r\n /**\r\n * What states influence this visual response\r\n */\r\n states: MotionControllerComponentStateType[];\r\n /**\r\n * Type of animation - movement or visibility\r\n */\r\n valueNodeProperty: \"transform\" | \"visibility\";\r\n /**\r\n * Base node name to move. Its position will be calculated according to the min and max nodes\r\n */\r\n valueNodeName?: string;\r\n /**\r\n * Minimum movement node\r\n */\r\n minNodeName?: string;\r\n /**\r\n * Max movement node\r\n */\r\n maxNodeName?: string;\r\n };\r\n };\r\n /**\r\n * If touch enabled, what is the name of node to display user feedback\r\n */\r\n touchPointNodeName?: string;\r\n };\r\n };\r\n /**\r\n * Is it xr standard mapping or not\r\n */\r\n gamepadMapping: \"\" | \"xr-standard\";\r\n /**\r\n * Base root node of this entire model\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Defines the main button component id\r\n */\r\n selectComponentId: string;\r\n}\r\n\r\n/**\r\n * A definition for the layout map in the input profile\r\n */\r\nexport interface IMotionControllerLayoutMap {\r\n /**\r\n * Layouts with handedness type as a key\r\n */\r\n [handedness: string /* handedness */]: IMotionControllerLayout;\r\n}\r\n\r\n/**\r\n * The XR Input profile schema\r\n * Profiles can be found here:\r\n * https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/registry/profiles\r\n */\r\nexport interface IMotionControllerProfile {\r\n /**\r\n * fallback profiles for this profileId\r\n */\r\n fallbackProfileIds: string[];\r\n /**\r\n * The layout map, with handedness as key\r\n */\r\n layouts: IMotionControllerLayoutMap;\r\n /**\r\n * The id of this profile\r\n * correlates to the profile(s) in the xrInput.profiles array\r\n */\r\n profileId: string;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller button animation\r\n * The meshes are provided to the _lerpButtonTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerButtonMeshMap {\r\n /**\r\n * the mesh that defines the pressed value mesh position.\r\n * This is used to find the max-position of this button\r\n */\r\n pressedMesh: AbstractMesh;\r\n /**\r\n * the mesh that defines the unpressed value mesh position.\r\n * This is used to find the min (or initial) position of this button\r\n */\r\n unpressedMesh: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when value changes\r\n */\r\n valueMesh: AbstractMesh;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller axis animation.\r\n * This will be expanded when touchpad animations are fully supported\r\n * The meshes are provided to the _lerpAxisTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerMeshMap {\r\n /**\r\n * the mesh that defines the maximum value mesh position.\r\n */\r\n maxMesh?: AbstractMesh;\r\n /**\r\n * the mesh that defines the minimum value mesh position.\r\n */\r\n minMesh?: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when axis value changes\r\n */\r\n valueMesh?: AbstractMesh;\r\n}\r\n\r\n/**\r\n * The elements needed for change-detection of the gamepad objects in motion controllers\r\n */\r\nexport interface IMinimalMotionControllerObject {\r\n /**\r\n * Available axes of this controller\r\n */\r\n axes: number[];\r\n /**\r\n * An array of available buttons\r\n */\r\n buttons: Array<{\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n }>;\r\n\r\n /**\r\n * EXPERIMENTAL haptic support.\r\n */\r\n hapticActuators?: Array<{\r\n pulse: (value: number, duration: number) => Promise<boolean>;\r\n }>;\r\n}\r\n\r\n/**\r\n * An Abstract Motion controller\r\n * This class receives an xrInput and a profile layout and uses those to initialize the components\r\n * Each component has an observable to check for changes in value and state\r\n */\r\nexport abstract class WebXRAbstractMotionController implements IDisposable {\r\n private _initComponent = (id: string) => {\r\n if (!id) {\r\n return;\r\n }\r\n const componentDef = this.layout.components[id];\r\n const type = componentDef.type;\r\n const buttonIndex = componentDef.gamepadIndices.button;\r\n // search for axes\r\n const axes: number[] = [];\r\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\r\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\r\n }\r\n\r\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\r\n };\r\n\r\n private _modelReady: boolean = false;\r\n\r\n /**\r\n * A map of components (WebXRControllerComponent) in this motion controller\r\n * Components have a ComponentType and can also have both button and axis definitions\r\n */\r\n public readonly components: {\r\n [id: string]: WebXRControllerComponent;\r\n } = {};\r\n\r\n /**\r\n * Disable the model's animation. Can be set at any time.\r\n */\r\n public disableAnimation: boolean = false;\r\n /**\r\n * Observers registered here will be triggered when the model of this controller is done loading\r\n */\r\n public onModelLoadedObservable: Observable<WebXRAbstractMotionController> = new Observable();\r\n /**\r\n * The profile id of this motion controller\r\n */\r\n public abstract profileId: string;\r\n /**\r\n * The root mesh of the model. It is null if the model was not yet initialized\r\n */\r\n public rootMesh: Nullable<AbstractMesh>;\r\n\r\n /**\r\n * constructs a new abstract motion controller\r\n * @param scene the scene to which the model of the controller will be added\r\n * @param layout The profile layout to load\r\n * @param gamepadObject The gamepad object correlating to this controller\r\n * @param handedness handedness (left/right/none) of this controller\r\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\r\n * @param _controllerCache a cache holding controller models already loaded in this session\r\n */\r\n constructor(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected scene: Scene,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected layout: IMotionControllerLayout,\r\n /**\r\n * The gamepad object correlating to this controller\r\n */\r\n public gamepadObject: IMinimalMotionControllerObject,\r\n /**\r\n * handedness (left/right/none) of this controller\r\n */\r\n public handedness: MotionControllerHandedness,\r\n /**\r\n * @internal\r\n */\r\n public _doNotLoadControllerMesh: boolean = false,\r\n private _controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n // initialize the components\r\n if (layout.components) {\r\n Object.keys(layout.components).forEach(this._initComponent);\r\n }\r\n // Model is loaded in WebXRInput\r\n }\r\n\r\n /**\r\n * Dispose this controller, the model mesh and all its components\r\n */\r\n public dispose(): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).dispose());\r\n if (this.rootMesh) {\r\n this.rootMesh.getChildren(undefined, true).forEach((node) => {\r\n node.setEnabled(false);\r\n });\r\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\r\n }\r\n }\r\n\r\n /**\r\n * Returns all components of specific type\r\n * @param type the type to search for\r\n * @returns an array of components with this type\r\n */\r\n public getAllComponentsOfType(type: MotionControllerComponentType): WebXRControllerComponent[] {\r\n return this.getComponentIds()\r\n .map((id) => this.components[id])\r\n .filter((component) => component.type === type);\r\n }\r\n\r\n /**\r\n * get a component based an its component id as defined in layout.components\r\n * @param id the id of the component\r\n * @returns the component correlates to the id or undefined if not found\r\n */\r\n public getComponent(id: string): WebXRControllerComponent {\r\n return this.components[id];\r\n }\r\n\r\n /**\r\n * Get the list of components available in this motion controller\r\n * @returns an array of strings correlating to available components\r\n */\r\n public getComponentIds(): string[] {\r\n return Object.keys(this.components);\r\n }\r\n\r\n /**\r\n * Get the first component of specific type\r\n * @param type type of component to find\r\n * @returns a controller component or null if not found\r\n */\r\n public getComponentOfType(type: MotionControllerComponentType): Nullable<WebXRControllerComponent> {\r\n return this.getAllComponentsOfType(type)[0] || null;\r\n }\r\n\r\n /**\r\n * Get the main (Select) component of this controller as defined in the layout\r\n * @returns the main component of this controller\r\n */\r\n public getMainComponent(): WebXRControllerComponent {\r\n return this.getComponent(this.layout.selectComponentId);\r\n }\r\n\r\n /**\r\n * Loads the model correlating to this controller\r\n * When the mesh is loaded, the onModelLoadedObservable will be triggered\r\n * @returns A promise fulfilled with the result of the model loading\r\n */\r\n public async loadModel(): Promise<boolean> {\r\n const useGeneric = !this._getModelLoadingConstraints();\r\n let loadingParams = this._getGenericFilenameAndPath();\r\n // Checking if GLB loader is present\r\n if (useGeneric) {\r\n Logger.Warn(\"Falling back to generic models\");\r\n } else {\r\n loadingParams = this._getFilenameAndPath();\r\n }\r\n return new Promise((resolve, reject) => {\r\n const meshesLoaded = (meshes: AbstractMesh[]) => {\r\n if (useGeneric) {\r\n this._getGenericParentMesh(meshes);\r\n } else {\r\n this._setRootMesh(meshes);\r\n }\r\n this._processLoadedModel(meshes);\r\n this._modelReady = true;\r\n this.onModelLoadedObservable.notifyObservers(this);\r\n resolve(true);\r\n };\r\n if (this._controllerCache) {\r\n // look for it in the cache\r\n const found = this._controllerCache.filter((c) => {\r\n return c.filename === loadingParams.filename && c.path === loadingParams.path;\r\n });\r\n if (found[0]) {\r\n found[0].meshes.forEach((mesh) => mesh.setEnabled(true));\r\n meshesLoaded(found[0].meshes);\r\n return;\r\n // found, don't continue to load\r\n }\r\n }\r\n SceneLoader.ImportMesh(\r\n \"\",\r\n loadingParams.path,\r\n loadingParams.filename,\r\n this.scene,\r\n (meshes) => {\r\n if (this._controllerCache) {\r\n this._controllerCache.push({\r\n ...loadingParams,\r\n meshes,\r\n });\r\n }\r\n meshesLoaded(meshes);\r\n },\r\n null,\r\n (_scene: Scene, message: string) => {\r\n Logger.Log(message);\r\n Logger.Warn(`Failed to retrieve controller model of type ${this.profileId} from the remote server: ${loadingParams.path}${loadingParams.filename}`);\r\n reject(message);\r\n }\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Update this model using the current XRFrame\r\n * @param xrFrame the current xr frame to use and update the model\r\n */\r\n public updateFromXRFrame(xrFrame: XRFrame): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).update(this.gamepadObject));\r\n this.updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Backwards compatibility due to a deeply-integrated typo\r\n */\r\n public get handness() {\r\n return this.handedness;\r\n }\r\n\r\n /**\r\n * Pulse (vibrate) this controller\r\n * If the controller does not support pulses, this function will fail silently and return Promise<false> directly after called\r\n * Consecutive calls to this function will cancel the last pulse call\r\n *\r\n * @param value the strength of the pulse in 0.0...1.0 range\r\n * @param duration Duration of the pulse in milliseconds\r\n * @param hapticActuatorIndex optional index of actuator (will usually be 0)\r\n * @returns a promise that will send true when the pulse has ended and false if the device doesn't support pulse or an error accrued\r\n */\r\n public pulse(value: number, duration: number, hapticActuatorIndex: number = 0): Promise<boolean> {\r\n if (this.gamepadObject.hapticActuators && this.gamepadObject.hapticActuators[hapticActuatorIndex]) {\r\n return this.gamepadObject.hapticActuators[hapticActuatorIndex].pulse(value, duration);\r\n } else {\r\n return Promise.resolve(false);\r\n }\r\n }\r\n\r\n // Look through all children recursively. This will return null if no mesh exists with the given name.\r\n protected _getChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name === name, false)[0];\r\n }\r\n\r\n // Look through only immediate children. This will return null if no mesh exists with the given name.\r\n protected _getImmediateChildByName(node: AbstractMesh, name: string): AbstractMesh | undefined {\r\n return <AbstractMesh | undefined>node.getChildren((n) => n.name == name, true)[0];\r\n }\r\n\r\n /**\r\n * Moves the axis on the controller mesh based on its current state\r\n * @param axisMap\r\n * @param axisValue the value of the axis which determines the meshes new position\r\n * @internal\r\n */\r\n protected _lerpTransform(axisMap: IMotionControllerMeshMap, axisValue: number, fixValueCoordinates?: boolean): void {\r\n if (!axisMap.minMesh || !axisMap.maxMesh || !axisMap.valueMesh) {\r\n return;\r\n }\r\n\r\n if (!axisMap.minMesh.rotationQuaternion || !axisMap.maxMesh.rotationQuaternion || !axisMap.valueMesh.rotationQuaternion) {\r\n return;\r\n }\r\n\r\n // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)\r\n const lerpValue = fixValueCoordinates ? axisValue * 0.5 + 0.5 : axisValue;\r\n Quaternion.SlerpToRef(axisMap.minMesh.rotationQuaternion, axisMap.maxMesh.rotationQuaternion, lerpValue, axisMap.valueMesh.rotationQuaternion);\r\n Vector3.LerpToRef(axisMap.minMesh.position, axisMap.maxMesh.position, lerpValue, axisMap.valueMesh.position);\r\n }\r\n\r\n /**\r\n * Update the model itself with the current frame data\r\n * @param xrFrame the frame to use for updating the model mesh\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected updateModel(xrFrame: XRFrame): void {\r\n if (!this._modelReady) {\r\n return;\r\n }\r\n this._updateModel(xrFrame);\r\n }\r\n\r\n /**\r\n * Get the filename and path for this controller's model\r\n * @returns a map of filename and path\r\n */\r\n protected abstract _getFilenameAndPath(): { filename: string; path: string };\r\n /**\r\n * This function is called before the mesh is loaded. It checks for loading constraints.\r\n * For example, this function can check if the GLB loader is available\r\n * If this function returns false, the generic controller will be loaded instead\r\n * @returns Is the client ready to load the mesh\r\n */\r\n protected abstract _getModelLoadingConstraints(): boolean;\r\n /**\r\n * This function will be called after the model was successfully loaded and can be used\r\n * for mesh transformations before it is available for the user\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _processLoadedModel(meshes: AbstractMesh[]): void;\r\n /**\r\n * Set the root mesh for this controller. Important for the WebXR controller class\r\n * @param meshes the loaded meshes\r\n */\r\n protected abstract _setRootMesh(meshes: AbstractMesh[]): void;\r\n /**\r\n * A function executed each frame that updates the mesh (if needed)\r\n * @param xrFrame the current xrFrame\r\n */\r\n protected abstract _updateModel(xrFrame: XRFrame): void;\r\n\r\n private _getGenericFilenameAndPath(): { filename: string; path: string } {\r\n return {\r\n filename: \"generic.babylon\",\r\n path: \"https://controllers.babylonjs.com/generic/\",\r\n };\r\n }\r\n\r\n private _getGenericParentMesh(meshes: AbstractMesh[]): void {\r\n this.rootMesh = new Mesh(this.profileId + \" \" + this.handedness, this.scene);\r\n\r\n meshes.forEach((mesh) => {\r\n if (!mesh.parent) {\r\n mesh.isPickable = false;\r\n mesh.setParent(this.rootMesh);\r\n }\r\n });\r\n\r\n this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"webXRControllerComponent.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/motionController/webXRControllerComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAoDnD;;GAEG;AACH,MAAM,OAAO,wBAAwB;IA2CjC;;;;;;;;OAQG;IACH;IACI;;OAEG;IACI,EAAU;IACjB;;OAEG;IACI,IAAmC,EAClC,eAAuB,CAAC,CAAC,EACzB,eAAyB,EAAE;QAN5B,OAAE,GAAF,EAAE,CAAQ;QAIV,SAAI,GAAJ,IAAI,CAA+B;QAClC,iBAAY,GAAZ,YAAY,CAAa;QACzB,iBAAY,GAAZ,YAAY,CAAe;QA7D/B,UAAK,GAAoC;YAC7C,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;SACP,CAAC;QACM,aAAQ,GAA2C,EAAE,CAAC;QACtD,kBAAa,GAAW,CAAC,CAAC;QAC1B,gBAAW,GAAY,KAAK,CAAC;QAC7B,aAAQ,GAAY,KAAK,CAAC;QAC1B,aAAQ,GAAY,KAAK,CAAC;QAuBlC;;;WAGG;QACI,iCAA4B,GAAyC,IAAI,UAAU,EAAE,CAAC;QAC7F;;;WAGG;QACI,mCAA8B,GAAyC,IAAI,UAAU,EAAE,CAAC;IAsB5F,CAAC;IAEJ;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAA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W,qCAAY,GAAkC,SAAS,CAAC","sourcesContent":["import type { IMinimalMotionControllerObject, MotionControllerComponentType } from \"./webXRAbstractMotionController\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { IDisposable } from \"../../scene\";\r\n\r\n/**\r\n * X-Y values for axes in WebXR\r\n */\r\nexport interface IWebXRMotionControllerAxesValue {\r\n /**\r\n * The value of the x axis\r\n */\r\n x: number;\r\n /**\r\n * The value of the y-axis\r\n */\r\n y: number;\r\n}\r\n\r\n/**\r\n * changed / previous values for the values of this component\r\n */\r\nexport interface IWebXRMotionControllerComponentChangesValues<T> {\r\n /**\r\n * current (this frame) value\r\n */\r\n current: T;\r\n /**\r\n * previous (last change) value\r\n */\r\n previous: T;\r\n}\r\n\r\n/**\r\n * Represents changes in the component between current frame and last values recorded\r\n */\r\nexport interface IWebXRMotionControllerComponentChanges {\r\n /**\r\n * will be populated with previous and current values if axes changed\r\n */\r\n axes?: IWebXRMotionControllerComponentChangesValues<IWebXRMotionControllerAxesValue>;\r\n /**\r\n * will be populated with previous and current values if pressed changed\r\n */\r\n pressed?: IWebXRMotionControllerComponentChangesValues<boolean>;\r\n /**\r\n * will be populated with previous and current values if touched changed\r\n */\r\n touched?: IWebXRMotionControllerComponentChangesValues<boolean>;\r\n /**\r\n * will be populated with previous and current values if value changed\r\n */\r\n value?: IWebXRMotionControllerComponentChangesValues<number>;\r\n}\r\n/**\r\n * This class represents a single component (for example button or thumbstick) of a motion controller\r\n */\r\nexport class WebXRControllerComponent implements IDisposable {\r\n private _axes: IWebXRMotionControllerAxesValue = {\r\n x: 0,\r\n y: 0,\r\n };\r\n private _changes: IWebXRMotionControllerComponentChanges = {};\r\n private _currentValue: number = 0;\r\n private _hasChanges: boolean = false;\r\n private _pressed: boolean = false;\r\n private _touched: boolean = false;\r\n\r\n /**\r\n * button component type\r\n */\r\n public static BUTTON_TYPE: MotionControllerComponentType = \"button\";\r\n /**\r\n * squeeze component type\r\n */\r\n public static SQUEEZE_TYPE: MotionControllerComponentType = \"squeeze\";\r\n /**\r\n * Thumbstick component type\r\n */\r\n public static THUMBSTICK_TYPE: MotionControllerComponentType = \"thumbstick\";\r\n /**\r\n * Touchpad component type\r\n */\r\n public static TOUCHPAD_TYPE: MotionControllerComponentType = \"touchpad\";\r\n /**\r\n * trigger component type\r\n */\r\n public static TRIGGER_TYPE: MotionControllerComponentType = \"trigger\";\r\n\r\n /**\r\n * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when\r\n * the axes data changes\r\n */\r\n public onAxisValueChangedObservable: Observable<{ x: number; y: number }> = new Observable();\r\n /**\r\n * Observers registered here will be triggered when the state of a button changes\r\n * State change is either pressed / touched / value\r\n */\r\n public onButtonStateChangedObservable: Observable<WebXRControllerComponent> = new Observable();\r\n\r\n /**\r\n * Creates a new component for a motion controller.\r\n * It is created by the motion controller itself\r\n *\r\n * @param id the id of this component\r\n * @param type the type of the component\r\n * @param _buttonIndex index in the buttons array of the gamepad\r\n * @param _axesIndices indices of the values in the axes array of the gamepad\r\n */\r\n constructor(\r\n /**\r\n * the id of this component\r\n */\r\n public id: string,\r\n /**\r\n * the type of the component\r\n */\r\n public type: MotionControllerComponentType,\r\n private _buttonIndex: number = -1,\r\n private _axesIndices: number[] = []\r\n ) {}\r\n\r\n /**\r\n * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }\r\n */\r\n public get axes(): IWebXRMotionControllerAxesValue {\r\n return this._axes;\r\n }\r\n\r\n /**\r\n * Get the changes. Elements will be populated only if they changed with their previous and current value\r\n */\r\n public get changes(): IWebXRMotionControllerComponentChanges {\r\n return this._changes;\r\n }\r\n\r\n /**\r\n * Return whether or not the component changed the last frame\r\n */\r\n public get hasChanges(): boolean {\r\n return this._hasChanges;\r\n }\r\n\r\n /**\r\n * is the button currently pressed\r\n */\r\n public get pressed(): boolean {\r\n return this._pressed;\r\n }\r\n\r\n /**\r\n * is the button currently touched\r\n */\r\n public get touched(): boolean {\r\n return this._touched;\r\n }\r\n\r\n /**\r\n * Get the current value of this component\r\n */\r\n public get value(): number {\r\n return this._currentValue;\r\n }\r\n\r\n /**\r\n * Dispose this component\r\n */\r\n public dispose(): void {\r\n this.onAxisValueChangedObservable.clear();\r\n this.onButtonStateChangedObservable.clear();\r\n }\r\n\r\n /**\r\n * Are there axes correlating to this component\r\n * @returns true is axes data is available\r\n */\r\n public isAxes(): boolean {\r\n return this._axesIndices.length !== 0;\r\n }\r\n\r\n /**\r\n * Is this component a button (hence - pressable)\r\n * @returns true if can be pressed\r\n */\r\n public isButton(): boolean {\r\n return this._buttonIndex !== -1;\r\n }\r\n\r\n /**\r\n * update this component using the gamepad object it is in. Called on every frame\r\n * @param nativeController the native gamepad controller object\r\n */\r\n public update(nativeController: IMinimalMotionControllerObject) {\r\n let buttonUpdated = false;\r\n let axesUpdate = false;\r\n this._hasChanges = false;\r\n this._changes = {};\r\n\r\n if (this.isButton()) {\r\n const button = nativeController.buttons[this._buttonIndex];\r\n // defensive, in case a profile was forced\r\n if (!button) {\r\n return;\r\n }\r\n if (this._currentValue !== button.value) {\r\n this.changes.value = {\r\n current: button.value,\r\n previous: this._currentValue,\r\n };\r\n buttonUpdated = true;\r\n this._currentValue = button.value;\r\n }\r\n if (this._touched !== button.touched) {\r\n this.changes.touched = {\r\n current: button.touched,\r\n previous: this._touched,\r\n };\r\n buttonUpdated = true;\r\n this._touched = button.touched;\r\n }\r\n if (this._pressed !== button.pressed) {\r\n this.changes.pressed = {\r\n current: button.pressed,\r\n previous: this._pressed,\r\n };\r\n buttonUpdated = true;\r\n this._pressed = button.pressed;\r\n }\r\n }\r\n\r\n if (this.isAxes()) {\r\n if (this._axes.x !== nativeController.axes[this._axesIndices[0]]) {\r\n this.changes.axes = {\r\n current: {\r\n x: nativeController.axes[this._axesIndices[0]],\r\n y: this._axes.y,\r\n },\r\n previous: {\r\n x: this._axes.x,\r\n y: this._axes.y,\r\n },\r\n };\r\n this._axes.x = nativeController.axes[this._axesIndices[0]];\r\n axesUpdate = true;\r\n }\r\n\r\n if (this._axes.y !== nativeController.axes[this._axesIndices[1]]) {\r\n if (this.changes.axes) {\r\n this.changes.axes.current.y = nativeController.axes[this._axesIndices[1]];\r\n } else {\r\n this.changes.axes = {\r\n current: {\r\n x: this._axes.x,\r\n y: nativeController.axes[this._axesIndices[1]],\r\n },\r\n previous: {\r\n x: this._axes.x,\r\n y: this._axes.y,\r\n },\r\n };\r\n }\r\n this._axes.y = nativeController.axes[this._axesIndices[1]];\r\n axesUpdate = true;\r\n }\r\n }\r\n\r\n if (buttonUpdated) {\r\n this._hasChanges = true;\r\n this.onButtonStateChangedObservable.notifyObservers(this);\r\n }\r\n if (axesUpdate) {\r\n this._hasChanges = true;\r\n this.onAxisValueChangedObservable.notifyObservers(this._axes);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webXRControllerComponent.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/motionController/webXRControllerComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAoDnD;;GAEG;AACH,MAAM,OAAO,wBAAwB;IA2CjC;;;;;;;;OAQG;IACH;IACI;;OAEG;IACI,EAAU;IACjB;;OAEG;IACI,IAAmC,EAClC,eAAuB,CAAC,CAAC,EACzB,eAAyB,EAAE;QAN5B,OAAE,GAAF,EAAE,CAAQ;QAIV,SAAI,GAAJ,IAAI,CAA+B;QAClC,iBAAY,GAAZ,YAAY,CAAa;QACzB,iBAAY,GAAZ,YAAY,CAAe;QA7D/B,UAAK,GAAoC;YAC7C,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;SACP,CAAC;QACM,aAAQ,GAA2C,EAAE,CAAC;QACtD,kBAAa,GAAW,CAAC,CAAC;QAC1B,gBAAW,GAAY,KAAK,CAAC;QAC7B,aAAQ,GAAY,KAAK,CAAC;QAC1B,aAAQ,GAAY,KAAK,CAAC;QAuBlC;;;WAGG;QACI,iCAA4B,GAAyC,IAAI,UAAU,EAAE,C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AC,8BAA8B,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC7D;QACD,IAAI,UAAU,EAAE;YACZ,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjE;IACL,CAAC;;AA9MD;;GAEG;AACW,oCAAW,GAAkC,QAAQ,AAA1C,CAA2C;AACpE;;GAEG;AACW,qCAAY,GAAkC,SAAS,AAA3C,CAA4C;AACtE;;GAEG;AACW,wCAAe,GAAkC,YAAY,AAA9C,CAA+C;AAC5E;;GAEG;AACW,sCAAa,GAAkC,UAAU,AAA5C,CAA6C;AACxE;;GAEG;AACW,qCAAY,GAAkC,SAAS,AAA3C,CAA4C","sourcesContent":["import type { IMinimalMotionControllerObject, MotionControllerComponentType } from \"./webXRAbstractMotionController\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { IDisposable } from \"../../scene\";\r\n\r\n/**\r\n * X-Y values for axes in WebXR\r\n */\r\nexport interface IWebXRMotionControllerAxesValue {\r\n /**\r\n * The value of the x axis\r\n */\r\n x: number;\r\n /**\r\n * The value of the y-axis\r\n */\r\n y: number;\r\n}\r\n\r\n/**\r\n * changed / previous values for the values of this component\r\n */\r\nexport interface IWebXRMotionControllerComponentChangesValues<T> {\r\n /**\r\n * current (this frame) value\r\n */\r\n current: T;\r\n /**\r\n * previous (last change) value\r\n */\r\n previous: T;\r\n}\r\n\r\n/**\r\n * Represents changes in the component between current frame and last values recorded\r\n */\r\nexport interface IWebXRMotionControllerComponentChanges {\r\n /**\r\n * will be populated with previous and current values if axes changed\r\n */\r\n axes?: IWebXRMotionControllerComponentChangesValues<IWebXRMotionControllerAxesValue>;\r\n /**\r\n * will be populated with previous and current values if pressed changed\r\n */\r\n pressed?: IWebXRMotionControllerComponentChangesValues<boolean>;\r\n /**\r\n * will be populated with previous and current values if touched changed\r\n */\r\n touched?: IWebXRMotionControllerComponentChangesValues<boolean>;\r\n /**\r\n * will be populated with previous and current values if value changed\r\n */\r\n value?: IWebXRMotionControllerComponentChangesValues<number>;\r\n}\r\n/**\r\n * This class represents a single component (for example button or thumbstick) of a motion controller\r\n */\r\nexport class WebXRControllerComponent implements IDisposable {\r\n private _axes: IWebXRMotionControllerAxesValue = {\r\n x: 0,\r\n y: 0,\r\n };\r\n private _changes: IWebXRMotionControllerComponentChanges = {};\r\n private _currentValue: number = 0;\r\n private _hasChanges: boolean = false;\r\n private _pressed: boolean = false;\r\n private _touched: boolean = false;\r\n\r\n /**\r\n * button component type\r\n */\r\n public static BUTTON_TYPE: MotionControllerComponentType = \"button\";\r\n /**\r\n * squeeze component type\r\n */\r\n public static SQUEEZE_TYPE: MotionControllerComponentType = \"squeeze\";\r\n /**\r\n * Thumbstick component type\r\n */\r\n public static THUMBSTICK_TYPE: MotionControllerComponentType = \"thumbstick\";\r\n /**\r\n * Touchpad component type\r\n */\r\n public static TOUCHPAD_TYPE: MotionControllerComponentType = \"touchpad\";\r\n /**\r\n * trigger component type\r\n */\r\n public static TRIGGER_TYPE: MotionControllerComponentType = \"trigger\";\r\n\r\n /**\r\n * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when\r\n * the axes data changes\r\n */\r\n public onAxisValueChangedObservable: Observable<{ x: number; y: number }> = new Observable();\r\n /**\r\n * Observers registered here will be triggered when the state of a button changes\r\n * State change is either pressed / touched / value\r\n */\r\n public onButtonStateChangedObservable: Observable<WebXRControllerComponent> = new Observable();\r\n\r\n /**\r\n * Creates a new component for a motion controller.\r\n * It is created by the motion controller itself\r\n *\r\n * @param id the id of this component\r\n * @param type the type of the component\r\n * @param _buttonIndex index in the buttons array of the gamepad\r\n * @param _axesIndices indices of the values in the axes array of the gamepad\r\n */\r\n constructor(\r\n /**\r\n * the id of this component\r\n */\r\n public id: string,\r\n /**\r\n * the type of the component\r\n */\r\n public type: MotionControllerComponentType,\r\n private _buttonIndex: number = -1,\r\n private _axesIndices: number[] = []\r\n ) {}\r\n\r\n /**\r\n * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }\r\n */\r\n public get axes(): IWebXRMotionControllerAxesValue {\r\n return this._axes;\r\n }\r\n\r\n /**\r\n * Get the changes. Elements will be populated only if they changed with their previous and current value\r\n */\r\n public get changes(): IWebXRMotionControllerComponentChanges {\r\n return this._changes;\r\n }\r\n\r\n /**\r\n * Return whether or not the component changed the last frame\r\n */\r\n public get hasChanges(): boolean {\r\n return this._hasChanges;\r\n }\r\n\r\n /**\r\n * is the button currently pressed\r\n */\r\n public get pressed(): boolean {\r\n return this._pressed;\r\n }\r\n\r\n /**\r\n * is the button currently touched\r\n */\r\n public get touched(): boolean {\r\n return this._touched;\r\n }\r\n\r\n /**\r\n * Get the current value of this component\r\n */\r\n public get value(): number {\r\n return this._currentValue;\r\n }\r\n\r\n /**\r\n * Dispose this component\r\n */\r\n public dispose(): void {\r\n this.onAxisValueChangedObservable.clear();\r\n this.onButtonStateChangedObservable.clear();\r\n }\r\n\r\n /**\r\n * Are there axes correlating to this component\r\n * @returns true is axes data is available\r\n */\r\n public isAxes(): boolean {\r\n return this._axesIndices.length !== 0;\r\n }\r\n\r\n /**\r\n * Is this component a button (hence - pressable)\r\n * @returns true if can be pressed\r\n */\r\n public isButton(): boolean {\r\n return this._buttonIndex !== -1;\r\n }\r\n\r\n /**\r\n * update this component using the gamepad object it is in. Called on every frame\r\n * @param nativeController the native gamepad controller object\r\n */\r\n public update(nativeController: IMinimalMotionControllerObject) {\r\n let buttonUpdated = false;\r\n let axesUpdate = false;\r\n this._hasChanges = false;\r\n this._changes = {};\r\n\r\n if (this.isButton()) {\r\n const button = nativeController.buttons[this._buttonIndex];\r\n // defensive, in case a profile was forced\r\n if (!button) {\r\n return;\r\n }\r\n if (this._currentValue !== button.value) {\r\n this.changes.value = {\r\n current: button.value,\r\n previous: this._currentValue,\r\n };\r\n buttonUpdated = true;\r\n this._currentValue = button.value;\r\n }\r\n if (this._touched !== button.touched) {\r\n this.changes.touched = {\r\n current: button.touched,\r\n previous: this._touched,\r\n };\r\n buttonUpdated = true;\r\n this._touched = button.touched;\r\n }\r\n if (this._pressed !== button.pressed) {\r\n this.changes.pressed = {\r\n current: button.pressed,\r\n previous: this._pressed,\r\n };\r\n buttonUpdated = true;\r\n this._pressed = button.pressed;\r\n }\r\n }\r\n\r\n if (this.isAxes()) {\r\n if (this._axes.x !== nativeController.axes[this._axesIndices[0]]) {\r\n this.changes.axes = {\r\n current: {\r\n x: nativeController.axes[this._axesIndices[0]],\r\n y: this._axes.y,\r\n },\r\n previous: {\r\n x: this._axes.x,\r\n y: this._axes.y,\r\n },\r\n };\r\n this._axes.x = nativeController.axes[this._axesIndices[0]];\r\n axesUpdate = true;\r\n }\r\n\r\n if (this._axes.y !== nativeController.axes[this._axesIndices[1]]) {\r\n if (this.changes.axes) {\r\n this.changes.axes.current.y = nativeController.axes[this._axesIndices[1]];\r\n } else {\r\n this.changes.axes = {\r\n current: {\r\n x: this._axes.x,\r\n y: nativeController.axes[this._axesIndices[1]],\r\n },\r\n previous: {\r\n x: this._axes.x,\r\n y: this._axes.y,\r\n },\r\n };\r\n }\r\n this._axes.y = nativeController.axes[this._axesIndices[1]];\r\n axesUpdate = true;\r\n }\r\n }\r\n\r\n if (buttonUpdated) {\r\n this._hasChanges = true;\r\n this.onButtonStateChangedObservable.notifyObservers(this);\r\n }\r\n if (axesUpdate) {\r\n this._hasChanges = true;\r\n this.onAxisValueChangedObservable.notifyObservers(this._axes);\r\n }\r\n }\r\n}\r\n"]}