@babylonjs/core 7.11.2 → 7.11.3

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 (104) hide show
  1. package/Animations/animatable.d.ts +10 -10
  2. package/Animations/animatable.js +5 -5
  3. package/Animations/animatable.js.map +1 -1
  4. package/Animations/animationGroupMask.d.ts +2 -2
  5. package/Animations/animationGroupMask.js +1 -1
  6. package/Animations/animationGroupMask.js.map +1 -1
  7. package/Animations/easing.d.ts +2 -2
  8. package/Animations/easing.js +1 -1
  9. package/Animations/easing.js.map +1 -1
  10. package/Behaviors/Meshes/attachToBoxBehavior.d.ts +3 -3
  11. package/Behaviors/Meshes/attachToBoxBehavior.js +3 -3
  12. package/Behaviors/Meshes/attachToBoxBehavior.js.map +1 -1
  13. package/Cameras/Inputs/freeCameraMouseInput.d.ts +2 -2
  14. package/Cameras/Inputs/freeCameraMouseInput.js +1 -1
  15. package/Cameras/Inputs/freeCameraMouseInput.js.map +1 -1
  16. package/Cameras/Inputs/freeCameraTouchInput.d.ts +2 -2
  17. package/Cameras/Inputs/freeCameraTouchInput.js +1 -1
  18. package/Cameras/Inputs/freeCameraTouchInput.js.map +1 -1
  19. package/Culling/Helper/boundingInfoHelper.d.ts +28 -0
  20. package/Culling/Helper/boundingInfoHelper.js +178 -0
  21. package/Culling/Helper/boundingInfoHelper.js.map +1 -0
  22. package/Culling/Helper/webgl2BoundingHelper.d.ts +22 -0
  23. package/Culling/Helper/webgl2BoundingHelper.js +61 -0
  24. package/Culling/Helper/webgl2BoundingHelper.js.map +1 -0
  25. package/Culling/Octrees/octree.d.ts +2 -2
  26. package/Culling/Octrees/octree.js +1 -1
  27. package/Culling/Octrees/octree.js.map +1 -1
  28. package/Culling/index.d.ts +1 -0
  29. package/Culling/index.js +1 -0
  30. package/Culling/index.js.map +1 -1
  31. package/Culling/ray.d.ts +4 -4
  32. package/Culling/ray.js +2 -2
  33. package/Culling/ray.js.map +1 -1
  34. package/Debug/skeletonViewer.d.ts +6 -6
  35. package/Debug/skeletonViewer.js +3 -3
  36. package/Debug/skeletonViewer.js.map +1 -1
  37. package/DeviceInput/InputDevices/deviceSource.d.ts +2 -2
  38. package/DeviceInput/InputDevices/deviceSource.js +1 -1
  39. package/DeviceInput/InputDevices/deviceSource.js.map +1 -1
  40. package/Engines/Extensions/engine.transformFeedback.d.ts +5 -0
  41. package/Engines/Extensions/engine.transformFeedback.js +3 -0
  42. package/Engines/Extensions/engine.transformFeedback.js.map +1 -1
  43. package/Engines/abstractEngine.js +2 -2
  44. package/Engines/abstractEngine.js.map +1 -1
  45. package/Engines/nativeEngine.d.ts +7 -0
  46. package/Engines/nativeEngine.js +4 -1
  47. package/Engines/nativeEngine.js.map +1 -1
  48. package/Maths/math.color.d.ts +14 -14
  49. package/Maths/math.color.js +7 -7
  50. package/Maths/math.color.js.map +1 -1
  51. package/Maths/math.isovector.d.ts +4 -4
  52. package/Maths/math.isovector.js +2 -2
  53. package/Maths/math.isovector.js.map +1 -1
  54. package/Maths/math.vector.d.ts +12 -12
  55. package/Maths/math.vector.js +6 -6
  56. package/Maths/math.vector.js.map +1 -1
  57. package/Maths/math.vertexFormat.d.ts +10 -10
  58. package/Maths/math.vertexFormat.js +5 -5
  59. package/Maths/math.vertexFormat.js.map +1 -1
  60. package/Meshes/mesh.d.ts +4 -0
  61. package/Meshes/mesh.js +13 -4
  62. package/Meshes/mesh.js.map +1 -1
  63. package/Misc/observable.d.ts +6 -6
  64. package/Misc/observable.js +4 -4
  65. package/Misc/observable.js.map +1 -1
  66. package/Misc/sceneOptimizer.d.ts +3 -3
  67. package/Misc/sceneOptimizer.js +2 -2
  68. package/Misc/sceneOptimizer.js.map +1 -1
  69. package/Particles/EmitterTypes/coneParticleEmitter.d.ts +2 -2
  70. package/Particles/EmitterTypes/coneParticleEmitter.js +1 -1
  71. package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
  72. package/Particles/EmitterTypes/cylinderParticleEmitter.d.ts +8 -8
  73. package/Particles/EmitterTypes/cylinderParticleEmitter.js +4 -4
  74. package/Particles/EmitterTypes/cylinderParticleEmitter.js.map +1 -1
  75. package/Particles/EmitterTypes/hemisphericParticleEmitter.d.ts +6 -6
  76. package/Particles/EmitterTypes/hemisphericParticleEmitter.js +3 -3
  77. package/Particles/EmitterTypes/hemisphericParticleEmitter.js.map +1 -1
  78. package/Particles/EmitterTypes/sphereParticleEmitter.d.ts +6 -6
  79. package/Particles/EmitterTypes/sphereParticleEmitter.js +3 -3
  80. package/Particles/EmitterTypes/sphereParticleEmitter.js.map +1 -1
  81. package/Particles/pointsCloudSystem.d.ts +0 -1
  82. package/Particles/pointsCloudSystem.js +0 -1
  83. package/Particles/pointsCloudSystem.js.map +1 -1
  84. package/Shaders/gpuTransform.fragment.d.ts +5 -0
  85. package/Shaders/gpuTransform.fragment.js +11 -0
  86. package/Shaders/gpuTransform.fragment.js.map +1 -0
  87. package/Shaders/gpuTransform.vertex.d.ts +13 -0
  88. package/Shaders/gpuTransform.vertex.js +33 -0
  89. package/Shaders/gpuTransform.vertex.js.map +1 -0
  90. package/XR/features/WebXRBackgroundRemover.d.ts +2 -2
  91. package/XR/features/WebXRBackgroundRemover.js +1 -1
  92. package/XR/features/WebXRBackgroundRemover.js.map +1 -1
  93. package/XR/features/WebXRHitTest.d.ts +2 -2
  94. package/XR/features/WebXRHitTest.js +1 -1
  95. package/XR/features/WebXRHitTest.js.map +1 -1
  96. package/XR/features/WebXRHitTestLegacy.d.ts +2 -2
  97. package/XR/features/WebXRHitTestLegacy.js +1 -1
  98. package/XR/features/WebXRHitTestLegacy.js.map +1 -1
  99. package/XR/features/WebXRRawCameraAccess.js +0 -2
  100. package/XR/features/WebXRRawCameraAccess.js.map +1 -1
  101. package/XR/motionController/webXRAbstractMotionController.d.ts +2 -0
  102. package/XR/motionController/webXRAbstractMotionController.js +1 -0
  103. package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
  104. package/package.json +1 -1
@@ -1 +1 @@
1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CAAC,IAAI,EACjB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC,EACD,YAAY,CAAC,OAAO,EACpB,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3, Matrix, Quaternion } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRLegacyHitTestOptions, IWebXRLegacyHitResult, IWebXRHitTestFeature } from \"./WebXRHitTestLegacy\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Options used for hit testing (version 2)\r\n */\r\nexport interface IWebXRHitTestOptions extends IWebXRLegacyHitTestOptions {\r\n /**\r\n * Do not create a permanent hit test. Will usually be used when only\r\n * transient inputs are needed.\r\n */\r\n disablePermanentHitTest?: boolean;\r\n /**\r\n * Enable transient (for example touch-based) hit test inspections\r\n */\r\n enableTransientHitTest?: boolean;\r\n /**\r\n * Override the default transient hit test profile (generic-touchscreen).\r\n */\r\n transientHitTestProfile?: string;\r\n /**\r\n * Offset ray for the permanent hit test\r\n */\r\n offsetRay?: Vector3;\r\n /**\r\n * Offset ray for the transient hit test\r\n */\r\n transientOffsetRay?: Vector3;\r\n /**\r\n * Instead of using viewer space for hit tests, use the reference space defined in the session manager\r\n */\r\n useReferenceSpace?: boolean;\r\n\r\n /**\r\n * Override the default entity type(s) of the hit-test result\r\n */\r\n entityTypes?: XRHitTestTrackableType[];\r\n}\r\n\r\n/**\r\n * Interface defining the babylon result of hit-test\r\n */\r\nexport interface IWebXRHitResult extends IWebXRLegacyHitResult {\r\n /**\r\n * The input source that generated this hit test (if transient)\r\n */\r\n inputSource?: XRInputSource;\r\n /**\r\n * Is this a transient hit test\r\n */\r\n isTransient?: boolean;\r\n /**\r\n * Position of the hit test result\r\n */\r\n position: Vector3;\r\n /**\r\n * Rotation of the hit test result\r\n */\r\n rotationQuaternion: Quaternion;\r\n\r\n /**\r\n * The native hit test result\r\n */\r\n xrHitResult: XRHitTestResult;\r\n}\r\n\r\n/**\r\n * The currently-working hit-test module.\r\n * Hit test (or Ray-casting) is used to interact with the real world.\r\n * For further information read here - https://github.com/immersive-web/hit-test\r\n *\r\n * Tested on chrome (mobile) 80.\r\n */\r\nexport class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRHitResult> {\r\n private _tmpMat: Matrix = new Matrix();\r\n private _tmpPos: Vector3 = new Vector3();\r\n private _tmpQuat: Quaternion = new Quaternion();\r\n private _transientXrHitTestSource: Nullable<XRTransientInputHitTestSource>;\r\n // in XR space z-forward is negative\r\n private _xrHitTestSource: Nullable<XRHitTestSource>;\r\n private _initHitTestSource = (referenceSpace: XRReferenceSpace) => {\r\n if (!referenceSpace) {\r\n return;\r\n }\r\n const offsetRay = new XRRay(this.options.offsetRay || {});\r\n const hitTestOptions: XRHitTestOptionsInit = {\r\n space: this.options.useReferenceSpace ? referenceSpace : this._xrSessionManager.viewerReferenceSpace,\r\n offsetRay: offsetRay,\r\n };\r\n if (this.options.entityTypes) {\r\n hitTestOptions.entityTypes = this.options.entityTypes;\r\n }\r\n if (!hitTestOptions.space) {\r\n Tools.Warn(\"waiting for viewer reference space to initialize\");\r\n return;\r\n }\r\n this._xrSessionManager.session.requestHitTestSource!(hitTestOptions).then((hitTestSource) => {\r\n if (this._xrHitTestSource) {\r\n this._xrHitTestSource.cancel();\r\n }\r\n this._xrHitTestSource = hitTestSource;\r\n });\r\n };\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.HIT_TEST;\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 = 2;\r\n\r\n /**\r\n * When set to true, each hit test will have its own position/rotation objects\r\n * When set to false, position and rotation objects will be reused for each hit test. It is expected that\r\n * the developers will clone them or copy them as they see fit.\r\n */\r\n public autoCloneTransformation: boolean = false;\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n * Note - this will be called when results come back from the device. It can be an empty array!!\r\n */\r\n public onHitTestResultObservable: Observable<IWebXRHitResult[]> = new Observable();\r\n /**\r\n * Use this to temporarily pause hit test checks.\r\n */\r\n public paused: boolean = false;\r\n\r\n /**\r\n * Creates a new instance of the hit test feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRHitTestOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"hit-test\";\r\n Tools.Warn(\"Hit test is an experimental and unstable feature.\");\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n // Feature enabled, but not available\r\n if (!this._xrSessionManager.session.requestHitTestSource) {\r\n return false;\r\n }\r\n\r\n if (!this.options.disablePermanentHitTest) {\r\n if (this._xrSessionManager.referenceSpace) {\r\n this._initHitTestSource(this._xrSessionManager.referenceSpace);\r\n }\r\n this._xrSessionManager.onXRReferenceSpaceChanged.add(this._initHitTestSource);\r\n }\r\n if (this.options.enableTransientHitTest) {\r\n const offsetRay = new XRRay(this.options.transientOffsetRay || {});\r\n this._xrSessionManager.session.requestHitTestSourceForTransientInput!({\r\n profile: this.options.transientHitTestProfile || \"generic-touchscreen\",\r\n offsetRay,\r\n entityTypes: this.options.entityTypes,\r\n }).then((hitSource) => {\r\n this._transientXrHitTestSource = hitSource;\r\n });\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n if (this._xrHitTestSource) {\r\n this._xrHitTestSource.cancel();\r\n this._xrHitTestSource = null;\r\n }\r\n this._xrSessionManager.onXRReferenceSpaceChanged.removeCallback(this._initHitTestSource);\r\n if (this._transientXrHitTestSource) {\r\n this._transientXrHitTestSource.cancel();\r\n this._transientXrHitTestSource = null;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onHitTestResultObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n // make sure we do nothing if (async) not attached\r\n if (!this.attached || this.paused) {\r\n return;\r\n }\r\n\r\n if (this._xrHitTestSource) {\r\n const results = frame.getHitTestResults(this._xrHitTestSource);\r\n this._processWebXRHitTestResult(results);\r\n }\r\n if (this._transientXrHitTestSource) {\r\n const hitTestResultsPerInputSource = frame.getHitTestResultsForTransientInput(this._transientXrHitTestSource);\r\n\r\n hitTestResultsPerInputSource.forEach((resultsPerInputSource) => {\r\n this._processWebXRHitTestResult(resultsPerInputSource.results, resultsPerInputSource.inputSource);\r\n });\r\n }\r\n }\r\n\r\n private _processWebXRHitTestResult(hitTestResults: readonly XRHitTestResult[], inputSource?: XRInputSource) {\r\n const results: IWebXRHitResult[] = [];\r\n hitTestResults.forEach((hitTestResult) => {\r\n const pose = hitTestResult.getPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n const pos = pose.transform.position;\r\n const quat = pose.transform.orientation;\r\n this._tmpPos.set(pos.x, pos.y, pos.z).scaleInPlace(this._xrSessionManager.worldScalingFactor);\r\n this._tmpQuat.set(quat.x, quat.y, quat.z, quat.w);\r\n Matrix.FromFloat32ArrayToRefScaled(pose.transform.matrix, 0, 1, this._tmpMat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpPos.z *= -1;\r\n this._tmpQuat.z *= -1;\r\n this._tmpQuat.w *= -1;\r\n this._tmpMat.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n const result: IWebXRHitResult = {\r\n position: this.autoCloneTransformation ? this._tmpPos.clone() : this._tmpPos,\r\n rotationQuaternion: this.autoCloneTransformation ? this._tmpQuat.clone() : this._tmpQuat,\r\n transformationMatrix: this.autoCloneTransformation ? this._tmpMat.clone() : this._tmpMat,\r\n inputSource: inputSource,\r\n isTransient: !!inputSource,\r\n xrHitResult: hitTestResult,\r\n };\r\n results.push(result);\r\n });\r\n\r\n this.onHitTestResultObservable.notifyObservers(results);\r\n }\r\n}\r\n\r\n//register the plugin versions\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRHitTest.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRHitTest(xrSessionManager, options);\r\n },\r\n WebXRHitTest.Version,\r\n false\r\n);\r\n"]}
1
+ {"version":3,"file":"WebXRHitTest.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRHitTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAkEzC;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IA0DlD;;;;OAIG;IACH,YACI,iBAAsC;IACtC;;OAEG;IACa,UAAgC,EAAE;QAElD,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAFT,YAAO,GAAP,OAA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AAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ;gBACxF,oBAAoB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;gBACxF,WAAW,EAAE,WAAW;gBACxB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,WAAW,EAAE,aAAa;aAC7B,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,yBAAyB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;;AAhKD;;GAEG;AACoB,iBAAI,GAAG,gBAAgB,CAAC,QAAQ,AAA5B,CAA6B;AACxD;;;;GAIG;AACoB,oBAAO,GAAG,CAAC,AAAJ,CAAK;AA0JvC,8BAA8B;AAC9B,oBAAoB,CAAC,eAAe,CAChC,YAAY,CAAC,IAAI,EACjB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC,EACD,YAAY,CAAC,OAAO,EACpB,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3, Matrix, Quaternion } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRLegacyHitTestOptions, IWebXRLegacyHitResult, IWebXRHitTestFeature } from \"./WebXRHitTestLegacy\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Options used for hit testing (version 2)\r\n */\r\nexport interface IWebXRHitTestOptions extends IWebXRLegacyHitTestOptions {\r\n /**\r\n * Do not create a permanent hit test. Will usually be used when only\r\n * transient inputs are needed.\r\n */\r\n disablePermanentHitTest?: boolean;\r\n /**\r\n * Enable transient (for example touch-based) hit test inspections\r\n */\r\n enableTransientHitTest?: boolean;\r\n /**\r\n * Override the default transient hit test profile (generic-touchscreen).\r\n */\r\n transientHitTestProfile?: string;\r\n /**\r\n * Offset ray for the permanent hit test\r\n */\r\n offsetRay?: Vector3;\r\n /**\r\n * Offset ray for the transient hit test\r\n */\r\n transientOffsetRay?: Vector3;\r\n /**\r\n * Instead of using viewer space for hit tests, use the reference space defined in the session manager\r\n */\r\n useReferenceSpace?: boolean;\r\n\r\n /**\r\n * Override the default entity type(s) of the hit-test result\r\n */\r\n entityTypes?: XRHitTestTrackableType[];\r\n}\r\n\r\n/**\r\n * Interface defining the babylon result of hit-test\r\n */\r\nexport interface IWebXRHitResult extends IWebXRLegacyHitResult {\r\n /**\r\n * The input source that generated this hit test (if transient)\r\n */\r\n inputSource?: XRInputSource;\r\n /**\r\n * Is this a transient hit test\r\n */\r\n isTransient?: boolean;\r\n /**\r\n * Position of the hit test result\r\n */\r\n position: Vector3;\r\n /**\r\n * Rotation of the hit test result\r\n */\r\n rotationQuaternion: Quaternion;\r\n\r\n /**\r\n * The native hit test result\r\n */\r\n xrHitResult: XRHitTestResult;\r\n}\r\n\r\n/**\r\n * The currently-working hit-test module.\r\n * Hit test (or Ray-casting) is used to interact with the real world.\r\n * For further information read here - https://github.com/immersive-web/hit-test\r\n *\r\n * Tested on chrome (mobile) 80.\r\n */\r\nexport class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRHitResult> {\r\n private _tmpMat: Matrix = new Matrix();\r\n private _tmpPos: Vector3 = new Vector3();\r\n private _tmpQuat: Quaternion = new Quaternion();\r\n private _transientXrHitTestSource: Nullable<XRTransientInputHitTestSource>;\r\n // in XR space z-forward is negative\r\n private _xrHitTestSource: Nullable<XRHitTestSource>;\r\n private _initHitTestSource = (referenceSpace: XRReferenceSpace) => {\r\n if (!referenceSpace) {\r\n return;\r\n }\r\n const offsetRay = new XRRay(this.options.offsetRay || {});\r\n const hitTestOptions: XRHitTestOptionsInit = {\r\n space: this.options.useReferenceSpace ? referenceSpace : this._xrSessionManager.viewerReferenceSpace,\r\n offsetRay: offsetRay,\r\n };\r\n if (this.options.entityTypes) {\r\n hitTestOptions.entityTypes = this.options.entityTypes;\r\n }\r\n if (!hitTestOptions.space) {\r\n Tools.Warn(\"waiting for viewer reference space to initialize\");\r\n return;\r\n }\r\n this._xrSessionManager.session.requestHitTestSource!(hitTestOptions).then((hitTestSource) => {\r\n if (this._xrHitTestSource) {\r\n this._xrHitTestSource.cancel();\r\n }\r\n this._xrHitTestSource = hitTestSource;\r\n });\r\n };\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.HIT_TEST;\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 = 2;\r\n\r\n /**\r\n * When set to true, each hit test will have its own position/rotation objects\r\n * When set to false, position and rotation objects will be reused for each hit test. It is expected that\r\n * the developers will clone them or copy them as they see fit.\r\n */\r\n public autoCloneTransformation: boolean = false;\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n * Note - this will be called when results come back from the device. It can be an empty array!!\r\n */\r\n public onHitTestResultObservable: Observable<IWebXRHitResult[]> = new Observable();\r\n /**\r\n * Use this to temporarily pause hit test checks.\r\n */\r\n public paused: boolean = false;\r\n\r\n /**\r\n * Creates a new instance of the hit test feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * [Empty Object] options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRHitTestOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"hit-test\";\r\n Tools.Warn(\"Hit test is an experimental and unstable feature.\");\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n // Feature enabled, but not available\r\n if (!this._xrSessionManager.session.requestHitTestSource) {\r\n return false;\r\n }\r\n\r\n if (!this.options.disablePermanentHitTest) {\r\n if (this._xrSessionManager.referenceSpace) {\r\n this._initHitTestSource(this._xrSessionManager.referenceSpace);\r\n }\r\n this._xrSessionManager.onXRReferenceSpaceChanged.add(this._initHitTestSource);\r\n }\r\n if (this.options.enableTransientHitTest) {\r\n const offsetRay = new XRRay(this.options.transientOffsetRay || {});\r\n this._xrSessionManager.session.requestHitTestSourceForTransientInput!({\r\n profile: this.options.transientHitTestProfile || \"generic-touchscreen\",\r\n offsetRay,\r\n entityTypes: this.options.entityTypes,\r\n }).then((hitSource) => {\r\n this._transientXrHitTestSource = hitSource;\r\n });\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n if (this._xrHitTestSource) {\r\n this._xrHitTestSource.cancel();\r\n this._xrHitTestSource = null;\r\n }\r\n this._xrSessionManager.onXRReferenceSpaceChanged.removeCallback(this._initHitTestSource);\r\n if (this._transientXrHitTestSource) {\r\n this._transientXrHitTestSource.cancel();\r\n this._transientXrHitTestSource = null;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onHitTestResultObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n // make sure we do nothing if (async) not attached\r\n if (!this.attached || this.paused) {\r\n return;\r\n }\r\n\r\n if (this._xrHitTestSource) {\r\n const results = frame.getHitTestResults(this._xrHitTestSource);\r\n this._processWebXRHitTestResult(results);\r\n }\r\n if (this._transientXrHitTestSource) {\r\n const hitTestResultsPerInputSource = frame.getHitTestResultsForTransientInput(this._transientXrHitTestSource);\r\n\r\n hitTestResultsPerInputSource.forEach((resultsPerInputSource) => {\r\n this._processWebXRHitTestResult(resultsPerInputSource.results, resultsPerInputSource.inputSource);\r\n });\r\n }\r\n }\r\n\r\n private _processWebXRHitTestResult(hitTestResults: readonly XRHitTestResult[], inputSource?: XRInputSource) {\r\n const results: IWebXRHitResult[] = [];\r\n hitTestResults.forEach((hitTestResult) => {\r\n const pose = hitTestResult.getPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n const pos = pose.transform.position;\r\n const quat = pose.transform.orientation;\r\n this._tmpPos.set(pos.x, pos.y, pos.z).scaleInPlace(this._xrSessionManager.worldScalingFactor);\r\n this._tmpQuat.set(quat.x, quat.y, quat.z, quat.w);\r\n Matrix.FromFloat32ArrayToRefScaled(pose.transform.matrix, 0, 1, this._tmpMat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpPos.z *= -1;\r\n this._tmpQuat.z *= -1;\r\n this._tmpQuat.w *= -1;\r\n this._tmpMat.toggleModelMatrixHandInPlace();\r\n }\r\n\r\n const result: IWebXRHitResult = {\r\n position: this.autoCloneTransformation ? this._tmpPos.clone() : this._tmpPos,\r\n rotationQuaternion: this.autoCloneTransformation ? this._tmpQuat.clone() : this._tmpQuat,\r\n transformationMatrix: this.autoCloneTransformation ? this._tmpMat.clone() : this._tmpMat,\r\n inputSource: inputSource,\r\n isTransient: !!inputSource,\r\n xrHitResult: hitTestResult,\r\n };\r\n results.push(result);\r\n });\r\n\r\n this.onHitTestResultObservable.notifyObservers(results);\r\n }\r\n}\r\n\r\n//register the plugin versions\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRHitTest.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRHitTest(xrSessionManager, options);\r\n },\r\n WebXRHitTest.Version,\r\n false\r\n);\r\n"]}
@@ -46,7 +46,7 @@ export interface IWebXRLegacyHitResult {
46
46
  */
47
47
  export declare class WebXRHitTestLegacy extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRLegacyHitResult> {
48
48
  /**
49
- * options to use when constructing this feature
49
+ * [Empty Object] options to use when constructing this feature
50
50
  */
51
51
  readonly options: IWebXRLegacyHitTestOptions;
52
52
  private _direction;
@@ -78,7 +78,7 @@ export declare class WebXRHitTestLegacy extends WebXRAbstractFeature implements
78
78
  */
79
79
  constructor(_xrSessionManager: WebXRSessionManager,
80
80
  /**
81
- * options to use when constructing this feature
81
+ * [Empty Object] options to use when constructing this feature
82
82
  */
83
83
  options?: IWebXRLegacyHitTestOptions);
84
84
  /**
@@ -16,7 +16,7 @@ export class WebXRHitTestLegacy extends WebXRAbstractFeature {
16
16
  */
17
17
  constructor(_xrSessionManager,
18
18
  /**
19
- * options to use when constructing this feature
19
+ * [Empty Object] options to use when constructing this feature
20
20
  */
21
21
  options = {}) {
22
22
  super(_xrSessionManager);
@@ -1 +1 @@
1
- {"version":3,"file":"WebXRHitTestLegacy.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRHitTestLegacy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA0CzC;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,oBAAoB;IA2BxD;;;;OAIG;IACH,YACI,iBAAsC;IACtC;;OAEG;IACa,UAA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eaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3, Matrix } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n// the plugin is registered at the end of the file\r\n\r\n/**\r\n * An interface for all Hit test features\r\n */\r\nexport interface IWebXRHitTestFeature<T extends IWebXRLegacyHitResult> extends IWebXRFeature {\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n */\r\n onHitTestResultObservable: Observable<T[]>;\r\n}\r\n\r\n/**\r\n * Options used for hit testing\r\n */\r\nexport interface IWebXRLegacyHitTestOptions {\r\n /**\r\n * Only test when user interacted with the scene. Default - hit test every frame\r\n */\r\n testOnPointerDownOnly?: boolean;\r\n /**\r\n * The node to use to transform the local results to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n}\r\n\r\n/**\r\n * Interface defining the babylon result of raycasting/hit-test\r\n */\r\nexport interface IWebXRLegacyHitResult {\r\n /**\r\n * Transformation matrix that can be applied to a node that will put it in the hit point location\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native hit test result\r\n */\r\n xrHitResult: XRHitResult | XRHitTestResult;\r\n}\r\n\r\n/**\r\n * The currently-working hit-test module.\r\n * Hit test (or Ray-casting) is used to interact with the real world.\r\n * For further information read here - https://github.com/immersive-web/hit-test\r\n */\r\nexport class WebXRHitTestLegacy extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRLegacyHitResult> {\r\n // in XR space z-forward is negative\r\n private _direction = new Vector3(0, 0, -1);\r\n private _mat = new Matrix();\r\n private _onSelectEnabled = false;\r\n private _origin = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.HIT_TEST;\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 * Populated with the last native XR Hit Results\r\n */\r\n public lastNativeXRHitResults: XRHitResult[] = [];\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n */\r\n public onHitTestResultObservable: Observable<IWebXRLegacyHitResult[]> = new Observable();\r\n\r\n /**\r\n * Creates a new instance of the (legacy version) hit test feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRLegacyHitTestOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"hit-test\";\r\n Tools.Warn(\"A newer version of this plugin is available\");\r\n }\r\n\r\n /**\r\n * execute a hit test with an XR Ray\r\n *\r\n * @param xrSession a native xrSession that will execute this hit test\r\n * @param xrRay the ray (position and direction) to use for ray-casting\r\n * @param referenceSpace native XR reference space to use for the hit-test\r\n * @param filter filter function that will filter the results\r\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\r\n */\r\n public static XRHitTestWithRay(xrSession: XRSession, xrRay: XRRay, referenceSpace: XRReferenceSpace, filter?: (result: XRHitResult) => boolean): Promise<XRHitResult[]> {\r\n return xrSession.requestHitTest!(xrRay, referenceSpace).then((results) => {\r\n const filterFunction = filter || ((result) => !!result.hitMatrix);\r\n return results.filter(filterFunction);\r\n });\r\n }\r\n\r\n /**\r\n * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)\r\n * @param event the (select) event to use to select with\r\n * @param referenceSpace the reference space to use for this hit test\r\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\r\n */\r\n public static XRHitTestWithSelectEvent(event: XRInputSourceEvent, referenceSpace: XRReferenceSpace): Promise<XRHitResult[]> {\r\n const targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, referenceSpace);\r\n if (!targetRayPose) {\r\n return Promise.resolve([]);\r\n }\r\n const targetRay = new XRRay(targetRayPose.transform);\r\n\r\n return this.XRHitTestWithRay(event.frame.session, targetRay, referenceSpace);\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n if (this.options.testOnPointerDownOnly) {\r\n this._xrSessionManager.session.addEventListener(\"select\", this._onSelect, false);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n // disable select\r\n this._onSelectEnabled = false;\r\n this._xrSessionManager.session.removeEventListener(\"select\", this._onSelect);\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onHitTestResultObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n // make sure we do nothing if (async) not attached\r\n if (!this.attached || this.options.testOnPointerDownOnly) {\r\n return;\r\n }\r\n const pose = frame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, this._mat);\r\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, this._mat, this._origin);\r\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, -1, this._mat, this._direction);\r\n this._direction.subtractInPlace(this._origin);\r\n this._direction.normalize();\r\n const ray = new XRRay(\r\n <DOMPointReadOnly>{ x: this._origin.x, y: this._origin.y, z: this._origin.z, w: 0 },\r\n <DOMPointReadOnly>{ x: this._direction.x, y: this._direction.y, z: this._direction.z, w: 0 }\r\n );\r\n WebXRHitTestLegacy.XRHitTestWithRay(this._xrSessionManager.session, ray, this._xrSessionManager.referenceSpace).then(this._onHitTestResults);\r\n }\r\n\r\n private _onHitTestResults = (xrResults: XRHitResult[]) => {\r\n const mats = xrResults.map((result) => {\r\n const mat = Matrix.FromArray(result.hitMatrix);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n // if (this.options.coordinatesSpace === Space.WORLD) {\r\n if (this.options.worldParentNode) {\r\n mat.multiplyToRef(this.options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n return {\r\n xrHitResult: result,\r\n transformationMatrix: mat,\r\n };\r\n });\r\n\r\n this.lastNativeXRHitResults = xrResults;\r\n this.onHitTestResultObservable.notifyObservers(mats);\r\n };\r\n\r\n // can be done using pointerdown event, and xrSessionManager.currentFrame\r\n private _onSelect = (event: XRInputSourceEvent) => {\r\n if (!this._onSelectEnabled) {\r\n return;\r\n }\r\n WebXRHitTestLegacy.XRHitTestWithSelectEvent(event, this._xrSessionManager.referenceSpace);\r\n };\r\n}\r\n\r\n//register the plugin versions\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRHitTestLegacy.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRHitTestLegacy(xrSessionManager, options);\r\n },\r\n WebXRHitTestLegacy.Version,\r\n false\r\n);\r\n"]}
1
+ {"version":3,"file":"WebXRHitTestLegacy.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRHitTestLegacy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA0CzC;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,o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} from \"../webXRFeaturesManager\";\r\nimport { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Vector3, Matrix } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n// the plugin is registered at the end of the file\r\n\r\n/**\r\n * An interface for all Hit test features\r\n */\r\nexport interface IWebXRHitTestFeature<T extends IWebXRLegacyHitResult> extends IWebXRFeature {\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n */\r\n onHitTestResultObservable: Observable<T[]>;\r\n}\r\n\r\n/**\r\n * Options used for hit testing\r\n */\r\nexport interface IWebXRLegacyHitTestOptions {\r\n /**\r\n * Only test when user interacted with the scene. Default - hit test every frame\r\n */\r\n testOnPointerDownOnly?: boolean;\r\n /**\r\n * The node to use to transform the local results to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n}\r\n\r\n/**\r\n * Interface defining the babylon result of raycasting/hit-test\r\n */\r\nexport interface IWebXRLegacyHitResult {\r\n /**\r\n * Transformation matrix that can be applied to a node that will put it in the hit point location\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native hit test result\r\n */\r\n xrHitResult: XRHitResult | XRHitTestResult;\r\n}\r\n\r\n/**\r\n * The currently-working hit-test module.\r\n * Hit test (or Ray-casting) is used to interact with the real world.\r\n * For further information read here - https://github.com/immersive-web/hit-test\r\n */\r\nexport class WebXRHitTestLegacy extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRLegacyHitResult> {\r\n // in XR space z-forward is negative\r\n private _direction = new Vector3(0, 0, -1);\r\n private _mat = new Matrix();\r\n private _onSelectEnabled = false;\r\n private _origin = new Vector3(0, 0, 0);\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.HIT_TEST;\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 * Populated with the last native XR Hit Results\r\n */\r\n public lastNativeXRHitResults: XRHitResult[] = [];\r\n /**\r\n * Triggered when new babylon (transformed) hit test results are available\r\n */\r\n public onHitTestResultObservable: Observable<IWebXRLegacyHitResult[]> = new Observable();\r\n\r\n /**\r\n * Creates a new instance of the (legacy version) hit test feature\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options options to use when constructing this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n /**\r\n * [Empty Object] options to use when constructing this feature\r\n */\r\n public readonly options: IWebXRLegacyHitTestOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"hit-test\";\r\n Tools.Warn(\"A newer version of this plugin is available\");\r\n }\r\n\r\n /**\r\n * execute a hit test with an XR Ray\r\n *\r\n * @param xrSession a native xrSession that will execute this hit test\r\n * @param xrRay the ray (position and direction) to use for ray-casting\r\n * @param referenceSpace native XR reference space to use for the hit-test\r\n * @param filter filter function that will filter the results\r\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\r\n */\r\n public static XRHitTestWithRay(xrSession: XRSession, xrRay: XRRay, referenceSpace: XRReferenceSpace, filter?: (result: XRHitResult) => boolean): Promise<XRHitResult[]> {\r\n return xrSession.requestHitTest!(xrRay, referenceSpace).then((results) => {\r\n const filterFunction = filter || ((result) => !!result.hitMatrix);\r\n return results.filter(filterFunction);\r\n });\r\n }\r\n\r\n /**\r\n * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)\r\n * @param event the (select) event to use to select with\r\n * @param referenceSpace the reference space to use for this hit test\r\n * @returns a promise that resolves with an array of native XR hit result in xr coordinates system\r\n */\r\n public static XRHitTestWithSelectEvent(event: XRInputSourceEvent, referenceSpace: XRReferenceSpace): Promise<XRHitResult[]> {\r\n const targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, referenceSpace);\r\n if (!targetRayPose) {\r\n return Promise.resolve([]);\r\n }\r\n const targetRay = new XRRay(targetRayPose.transform);\r\n\r\n return this.XRHitTestWithRay(event.frame.session, targetRay, referenceSpace);\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n if (this.options.testOnPointerDownOnly) {\r\n this._xrSessionManager.session.addEventListener(\"select\", this._onSelect, false);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n // disable select\r\n this._onSelectEnabled = false;\r\n this._xrSessionManager.session.removeEventListener(\"select\", this._onSelect);\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onHitTestResultObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n // make sure we do nothing if (async) not attached\r\n if (!this.attached || this.options.testOnPointerDownOnly) {\r\n return;\r\n }\r\n const pose = frame.getViewerPose(this._xrSessionManager.referenceSpace);\r\n if (!pose) {\r\n return;\r\n }\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, this._mat);\r\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, this._mat, this._origin);\r\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, -1, this._mat, this._direction);\r\n this._direction.subtractInPlace(this._origin);\r\n this._direction.normalize();\r\n const ray = new XRRay(\r\n <DOMPointReadOnly>{ x: this._origin.x, y: this._origin.y, z: this._origin.z, w: 0 },\r\n <DOMPointReadOnly>{ x: this._direction.x, y: this._direction.y, z: this._direction.z, w: 0 }\r\n );\r\n WebXRHitTestLegacy.XRHitTestWithRay(this._xrSessionManager.session, ray, this._xrSessionManager.referenceSpace).then(this._onHitTestResults);\r\n }\r\n\r\n private _onHitTestResults = (xrResults: XRHitResult[]) => {\r\n const mats = xrResults.map((result) => {\r\n const mat = Matrix.FromArray(result.hitMatrix);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n // if (this.options.coordinatesSpace === Space.WORLD) {\r\n if (this.options.worldParentNode) {\r\n mat.multiplyToRef(this.options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n return {\r\n xrHitResult: result,\r\n transformationMatrix: mat,\r\n };\r\n });\r\n\r\n this.lastNativeXRHitResults = xrResults;\r\n this.onHitTestResultObservable.notifyObservers(mats);\r\n };\r\n\r\n // can be done using pointerdown event, and xrSessionManager.currentFrame\r\n private _onSelect = (event: XRInputSourceEvent) => {\r\n if (!this._onSelectEnabled) {\r\n return;\r\n }\r\n WebXRHitTestLegacy.XRHitTestWithSelectEvent(event, this._xrSessionManager.referenceSpace);\r\n };\r\n}\r\n\r\n//register the plugin versions\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRHitTestLegacy.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRHitTestLegacy(xrSessionManager, options);\r\n },\r\n WebXRHitTestLegacy.Version,\r\n false\r\n);\r\n"]}
@@ -111,9 +111,7 @@ export class WebXRRawCameraAccess extends WebXRAbstractFeature {
111
111
  const lp = this._glBinding?.getCameraImage(view.camera);
112
112
  if (!this._cachedInternalTextures[index]) {
113
113
  const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);
114
- internalTexture.isCube = true;
115
114
  internalTexture.invertY = false;
116
- // internalTexture._useSRGBBuffer = this.options.reflectionFormat === "srgba8";
117
115
  internalTexture.format = 5;
118
116
  internalTexture.generateMipMaps = true;
119
117
  internalTexture.type = 1;
@@ -1 +1 @@
1
- {"version":3,"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AAK,CAAC,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;SACjE;QACD,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;QACnD,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,UAAU,CAAC,QAAiB;QAClC,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC;QAE7D,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,OAAO;SACV;QACD,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC/B,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;QACH,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,2BAA2B,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACvE;IACL,CAAC;;AAnJD;;GAEG;AACoB,yBAAI,GAAG,gBAAgB,CAAC,iBAAiB,AAArC,CAAsC;AAEjE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AA4IvC,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { ThinEngine } from \"../../Engines\";\r\n\r\n/**\r\n * Options for raw camera access\r\n */\r\nexport interface IWebXRRawCameraAccessOptions {\r\n /**\r\n * Keep the created textures and metadata when detaching the feature.\r\n */\r\n doNotDisposeOnDetach?: boolean;\r\n}\r\n\r\n/**\r\n * WebXR Feature for WebXR raw camera access\r\n * @since 6.31.0\r\n * @see https://immersive-web.github.io/raw-camera-access/\r\n */\r\nexport class WebXRRawCameraAccess extends WebXRAbstractFeature {\r\n private _cachedInternalTextures: InternalTexture[] = [];\r\n /**\r\n * This is an array of camera views\r\n * Note that mostly the array will contain a single view\r\n * If you want to know the order of the views, use the `viewIndex` array\r\n */\r\n public texturesData: BaseTexture[] = [];\r\n /**\r\n * If needed, this array will contain the eye definition of each texture in `texturesArray`\r\n */\r\n public viewIndex: string[] = [];\r\n\r\n /**\r\n * If needed, this array will contain the camera's intrinsics\r\n * You can use this data to convert from camera space to screen space and vice versa\r\n */\r\n public cameraIntrinsics: {\r\n u0: number;\r\n v0: number;\r\n ax: number;\r\n ay: number;\r\n gamma: number;\r\n width: number;\r\n height: number;\r\n viewportX: number;\r\n viewportY: number;\r\n }[] = [];\r\n\r\n /**\r\n * An observable that will notify when the camera's textures are updated\r\n */\r\n public onTexturesUpdatedObservable: Observable<BaseTexture[]> = new Observable();\r\n\r\n private _glBinding?: XRWebGLBinding;\r\n private _glContext: WebGLRenderingContext;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.RAW_CAMERA_ACCESS;\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Creates a new instance of the feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for the Feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n public readonly options: IWebXRRawCameraAccessOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"camera-access\";\r\n }\r\n\r\n public override attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n this._glContext = (this._xrSessionManager.scene.getEngine() as ThinEngine)._gl;\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n this._glBinding = undefined;\r\n if (!this.options.doNotDisposeOnDetach) {\r\n this._cachedInternalTextures.forEach((t) => t.dispose());\r\n this.texturesData.forEach((t) => t.dispose());\r\n this._cachedInternalTextures.length = 0;\r\n this.texturesData.length = 0;\r\n this.cameraIntrinsics.length = 0;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onTexturesUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * @see https://github.com/immersive-web/raw-camera-access/blob/main/explainer.md\r\n * @param view the XRView to update\r\n * @param index the index of the view in the views array\r\n */\r\n private _updateCameraIntrinsics(view: XRView, index: number): void {\r\n const cameraViewport = {\r\n width: view.camera!.width,\r\n height: view.camera!.height,\r\n x: 0,\r\n y: 0,\r\n };\r\n const p = view.projectionMatrix;\r\n\r\n // Principal point in pixels (typically at or near the center of the viewport)\r\n const u0 = ((1 - p[8]) * cameraViewport.width) / 2 + cameraViewport.x;\r\n const v0 = ((1 - p[9]) * cameraViewport.height) / 2 + cameraViewport.y;\r\n\r\n // Focal lengths in pixels (these are equal for square pixels)\r\n const ax = (cameraViewport.width / 2) * p[0];\r\n const ay = (cameraViewport.height / 2) * p[5];\r\n\r\n // Skew factor in pixels (nonzero for rhomboid pixels)\r\n const gamma = (cameraViewport.width / 2) * p[4];\r\n this.cameraIntrinsics[index] = {\r\n u0,\r\n v0,\r\n ax,\r\n ay,\r\n gamma,\r\n width: cameraViewport.width,\r\n height: cameraViewport.height,\r\n viewportX: cameraViewport.x,\r\n viewportY: cameraViewport.y,\r\n };\r\n }\r\n\r\n private _updateInternalTextures(view: XRView, index = 0): boolean {\r\n if (!view.camera) {\r\n return false;\r\n }\r\n this.viewIndex[index] = view.eye;\r\n const lp = this._glBinding?.getCameraImage(view.camera);\r\n\r\n if (!this._cachedInternalTextures[index]) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);\r\n internalTexture.isCube = true;\r\n internalTexture.invertY = false;\r\n // internalTexture._useSRGBBuffer = this.options.reflectionFormat === \"srgba8\";\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = view.camera.width;\r\n internalTexture.height = view.camera.height;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._glContext);\r\n this._cachedInternalTextures[index] = internalTexture;\r\n // create the base texture\r\n const texture = new BaseTexture(this._xrSessionManager.scene);\r\n texture.name = `WebXR Raw Camera Access (${index})`;\r\n texture._texture = this._cachedInternalTextures[index];\r\n this.texturesData[index] = texture;\r\n // get the camera intrinsics\r\n this._updateCameraIntrinsics(view, index);\r\n } else {\r\n // make sure the webgl texture is updated. Should happen automatically\r\n this._cachedInternalTextures[index]._hardwareTexture?.set(lp);\r\n }\r\n this._cachedInternalTextures[index].isReady = true;\r\n return true;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (!pose || !pose.views) {\r\n return;\r\n }\r\n let updated = true;\r\n pose.views.forEach((view, index) => {\r\n updated = updated && this._updateInternalTextures(view, index);\r\n });\r\n if (updated) {\r\n this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRRawCameraAccess.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRRawCameraAccess(xrSessionManager, options);\r\n },\r\n WebXRRawCameraAccess.Version,\r\n false\r\n);\r\n"]}
1
+ {"version":3,"file":"WebXRRawCameraAccess.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRRawCameraAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAanE;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,oBAAoB;IAiD1D;;;;OAIG;IACH,YACI,iBAAsC,EACtB,UAAwC,EAAE;QAE1D,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAFT,YAAO,GAAP,OAAO,CAAmC;QAvDtD,4BAAuB,GAAsB,EAAE,CAAC;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;AACoB,yBAAI,GAAG,gBAAgB,CAAC,iBAAiB,AAArC,CAAsC;AAEjE;;;;GAIG;AACoB,4BAAO,GAAG,CAAC,AAAJ,CAAK;AA0IvC,oBAAoB,CAAC,eAAe,CAChC,oBAAoB,CAAC,IAAI,EACzB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC,EACD,oBAAoB,CAAC,OAAO,EAC5B,KAAK,CACR,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { ThinEngine } from \"../../Engines\";\r\n\r\n/**\r\n * Options for raw camera access\r\n */\r\nexport interface IWebXRRawCameraAccessOptions {\r\n /**\r\n * Keep the created textures and metadata when detaching the feature.\r\n */\r\n doNotDisposeOnDetach?: boolean;\r\n}\r\n\r\n/**\r\n * WebXR Feature for WebXR raw camera access\r\n * @since 6.31.0\r\n * @see https://immersive-web.github.io/raw-camera-access/\r\n */\r\nexport class WebXRRawCameraAccess extends WebXRAbstractFeature {\r\n private _cachedInternalTextures: InternalTexture[] = [];\r\n /**\r\n * This is an array of camera views\r\n * Note that mostly the array will contain a single view\r\n * If you want to know the order of the views, use the `viewIndex` array\r\n */\r\n public texturesData: BaseTexture[] = [];\r\n /**\r\n * If needed, this array will contain the eye definition of each texture in `texturesArray`\r\n */\r\n public viewIndex: string[] = [];\r\n\r\n /**\r\n * If needed, this array will contain the camera's intrinsics\r\n * You can use this data to convert from camera space to screen space and vice versa\r\n */\r\n public cameraIntrinsics: {\r\n u0: number;\r\n v0: number;\r\n ax: number;\r\n ay: number;\r\n gamma: number;\r\n width: number;\r\n height: number;\r\n viewportX: number;\r\n viewportY: number;\r\n }[] = [];\r\n\r\n /**\r\n * An observable that will notify when the camera's textures are updated\r\n */\r\n public onTexturesUpdatedObservable: Observable<BaseTexture[]> = new Observable();\r\n\r\n private _glBinding?: XRWebGLBinding;\r\n private _glContext: WebGLRenderingContext;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.RAW_CAMERA_ACCESS;\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Creates a new instance of the feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for the Feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n public readonly options: IWebXRRawCameraAccessOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"camera-access\";\r\n }\r\n\r\n public override attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n this._glContext = (this._xrSessionManager.scene.getEngine() as ThinEngine)._gl;\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._glContext);\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n this._glBinding = undefined;\r\n if (!this.options.doNotDisposeOnDetach) {\r\n this._cachedInternalTextures.forEach((t) => t.dispose());\r\n this.texturesData.forEach((t) => t.dispose());\r\n this._cachedInternalTextures.length = 0;\r\n this.texturesData.length = 0;\r\n this.cameraIntrinsics.length = 0;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n this.onTexturesUpdatedObservable.clear();\r\n }\r\n\r\n /**\r\n * @see https://github.com/immersive-web/raw-camera-access/blob/main/explainer.md\r\n * @param view the XRView to update\r\n * @param index the index of the view in the views array\r\n */\r\n private _updateCameraIntrinsics(view: XRView, index: number): void {\r\n const cameraViewport = {\r\n width: view.camera!.width,\r\n height: view.camera!.height,\r\n x: 0,\r\n y: 0,\r\n };\r\n const p = view.projectionMatrix;\r\n\r\n // Principal point in pixels (typically at or near the center of the viewport)\r\n const u0 = ((1 - p[8]) * cameraViewport.width) / 2 + cameraViewport.x;\r\n const v0 = ((1 - p[9]) * cameraViewport.height) / 2 + cameraViewport.y;\r\n\r\n // Focal lengths in pixels (these are equal for square pixels)\r\n const ax = (cameraViewport.width / 2) * p[0];\r\n const ay = (cameraViewport.height / 2) * p[5];\r\n\r\n // Skew factor in pixels (nonzero for rhomboid pixels)\r\n const gamma = (cameraViewport.width / 2) * p[4];\r\n this.cameraIntrinsics[index] = {\r\n u0,\r\n v0,\r\n ax,\r\n ay,\r\n gamma,\r\n width: cameraViewport.width,\r\n height: cameraViewport.height,\r\n viewportX: cameraViewport.x,\r\n viewportY: cameraViewport.y,\r\n };\r\n }\r\n\r\n private _updateInternalTextures(view: XRView, index = 0): boolean {\r\n if (!view.camera) {\r\n return false;\r\n }\r\n this.viewIndex[index] = view.eye;\r\n const lp = this._glBinding?.getCameraImage(view.camera);\r\n\r\n if (!this._cachedInternalTextures[index]) {\r\n const internalTexture = new InternalTexture(this._xrSessionManager.scene.getEngine(), InternalTextureSource.Unknown, true);\r\n internalTexture.invertY = false;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n internalTexture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR;\r\n internalTexture.width = view.camera.width;\r\n internalTexture.height = view.camera.height;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(lp, this._glContext);\r\n this._cachedInternalTextures[index] = internalTexture;\r\n // create the base texture\r\n const texture = new BaseTexture(this._xrSessionManager.scene);\r\n texture.name = `WebXR Raw Camera Access (${index})`;\r\n texture._texture = this._cachedInternalTextures[index];\r\n this.texturesData[index] = texture;\r\n // get the camera intrinsics\r\n this._updateCameraIntrinsics(view, index);\r\n } else {\r\n // make sure the webgl texture is updated. Should happen automatically\r\n this._cachedInternalTextures[index]._hardwareTexture?.set(lp);\r\n }\r\n this._cachedInternalTextures[index].isReady = true;\r\n return true;\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (!pose || !pose.views) {\r\n return;\r\n }\r\n let updated = true;\r\n pose.views.forEach((view, index) => {\r\n updated = updated && this._updateInternalTextures(view, index);\r\n });\r\n if (updated) {\r\n this.onTexturesUpdatedObservable.notifyObservers(this.texturesData);\r\n }\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRRawCameraAccess.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRRawCameraAccess(xrSessionManager, options);\r\n },\r\n WebXRRawCameraAccess.Version,\r\n false\r\n);\r\n"]}
@@ -227,6 +227,7 @@ export declare abstract class WebXRAbstractMotionController implements IDisposab
227
227
  handedness: MotionControllerHandedness;
228
228
  /**
229
229
  * @internal
230
+ * [false]
230
231
  */
231
232
  _doNotLoadControllerMesh: boolean;
232
233
  private _controllerCache?;
@@ -275,6 +276,7 @@ export declare abstract class WebXRAbstractMotionController implements IDisposab
275
276
  handedness: MotionControllerHandedness,
276
277
  /**
277
278
  * @internal
279
+ * [false]
278
280
  */
279
281
  _doNotLoadControllerMesh?: boolean, _controllerCache?: {
280
282
  filename: string;
@@ -34,6 +34,7 @@ export class WebXRAbstractMotionController {
34
34
  handedness,
35
35
  /**
36
36
  * @internal
37
+ * [false]
37
38
  */
38
39
  _doNotLoadControllerMesh = false, _controllerCache) {
39
40
  this.scene = scene;
@@ -1 +1 @@
1
- {"version":3,"file":"webXRAbstractMotionController.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/motionController/webXRAbstractMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAyNzC;;;;GAIG;AACH,MAAM,OAAgB,6BAA6B;IA4C/C;;;;;;;;OAQG;IACH;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,CAA4B;QAItC,6BAAwB,GAAxB,wBAAwB,CAAiB;QACxC,qBAAgB,GAAhB,gBAAgB,CAItB;QAzEE,mBAAc,GAAG,CAAC,EAAU,EAAE,EAAE;YACpC,IAAI,CAAC,EAAE,EAAE;gBACL,OAAO;aACV;YACD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAChD,MAAM,IAAI,GAAG,YAAY,C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,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":["../../../../../dev/core/src/XR/motionController/webXRAbstractMotionController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAyNzC;;;;GAIG;AACH,MAAM,OAAgB,6BAA6B;IA4C/C;;;;;;;;OAQG;IACH;IACI,gEAAgE;IACtD,KAAY;IACtB,gEAAgE;IACtD,MAA+B;IACzC;;OAEG;IACI,aAA6C;IACpD;;OAEG;IACI,UAAsC;IAC7C;;;OAGG;IACI,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XRControllerComponent\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { SceneLoader } from \"../../Loading/sceneLoader\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../../Meshes/mesh\";\r\n\r\n/**\r\n * Handedness type in xrInput profiles. These can be used to define layouts in the Layout Map.\r\n */\r\nexport type MotionControllerHandedness = \"none\" | \"left\" | \"right\";\r\n/**\r\n * The type of components available in motion controllers.\r\n * This is not the name of the component.\r\n */\r\nexport type MotionControllerComponentType = \"trigger\" | \"squeeze\" | \"touchpad\" | \"thumbstick\" | \"button\";\r\n\r\n/**\r\n * The state of a controller component\r\n */\r\nexport type MotionControllerComponentStateType = \"default\" | \"touched\" | \"pressed\";\r\n\r\n/**\r\n * The schema of motion controller layout.\r\n * No object will be initialized using this interface\r\n * This is used just to define the profile.\r\n */\r\nexport interface IMotionControllerLayout {\r\n /**\r\n * Path to load the assets. Usually relative to the base path\r\n */\r\n assetPath: string;\r\n /**\r\n * Available components (unsorted)\r\n */\r\n components: {\r\n /**\r\n * A map of component Ids\r\n */\r\n [componentId: string]: {\r\n /**\r\n * The type of input the component outputs\r\n */\r\n type: MotionControllerComponentType;\r\n /**\r\n * The indices of this component in the gamepad object\r\n */\r\n gamepadIndices: {\r\n /**\r\n * Index of button\r\n */\r\n button?: number;\r\n /**\r\n * If available, index of x-axis\r\n */\r\n xAxis?: number;\r\n /**\r\n * If available, index of y-axis\r\n */\r\n yAxis?: number;\r\n };\r\n /**\r\n * The mesh's root node name\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Animation definitions for this model\r\n */\r\n visualResponses: {\r\n [stateKey: string]: {\r\n /**\r\n * What property will be animated\r\n */\r\n componentProperty: \"xAxis\" | \"yAxis\" | \"button\" | \"state\";\r\n /**\r\n * What states influence this visual response\r\n */\r\n states: MotionControllerComponentStateType[];\r\n /**\r\n * Type of animation - movement or visibility\r\n */\r\n valueNodeProperty: \"transform\" | \"visibility\";\r\n /**\r\n * Base node name to move. Its position will be calculated according to the min and max nodes\r\n */\r\n valueNodeName?: string;\r\n /**\r\n * Minimum movement node\r\n */\r\n minNodeName?: string;\r\n /**\r\n * Max movement node\r\n */\r\n maxNodeName?: string;\r\n };\r\n };\r\n /**\r\n * If touch enabled, what is the name of node to display user feedback\r\n */\r\n touchPointNodeName?: string;\r\n };\r\n };\r\n /**\r\n * Is it xr standard mapping or not\r\n */\r\n gamepadMapping: \"\" | \"xr-standard\";\r\n /**\r\n * Base root node of this entire model\r\n */\r\n rootNodeName: string;\r\n /**\r\n * Defines the main button component id\r\n */\r\n selectComponentId: string;\r\n}\r\n\r\n/**\r\n * A definition for the layout map in the input profile\r\n */\r\nexport interface IMotionControllerLayoutMap {\r\n /**\r\n * Layouts with handedness type as a key\r\n */\r\n [handedness: string /* handedness */]: IMotionControllerLayout;\r\n}\r\n\r\n/**\r\n * The XR Input profile schema\r\n * Profiles can be found here:\r\n * https://github.com/immersive-web/webxr-input-profiles/tree/master/packages/registry/profiles\r\n */\r\nexport interface IMotionControllerProfile {\r\n /**\r\n * fallback profiles for this profileId\r\n */\r\n fallbackProfileIds: string[];\r\n /**\r\n * The layout map, with handedness as key\r\n */\r\n layouts: IMotionControllerLayoutMap;\r\n /**\r\n * The id of this profile\r\n * correlates to the profile(s) in the xrInput.profiles array\r\n */\r\n profileId: string;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller button animation\r\n * The meshes are provided to the _lerpButtonTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerButtonMeshMap {\r\n /**\r\n * the mesh that defines the pressed value mesh position.\r\n * This is used to find the max-position of this button\r\n */\r\n pressedMesh: AbstractMesh;\r\n /**\r\n * the mesh that defines the unpressed value mesh position.\r\n * This is used to find the min (or initial) position of this button\r\n */\r\n unpressedMesh: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when value changes\r\n */\r\n valueMesh: AbstractMesh;\r\n}\r\n\r\n/**\r\n * A helper-interface for the 3 meshes needed for controller axis animation.\r\n * This will be expanded when touchpad animations are fully supported\r\n * The meshes are provided to the _lerpAxisTransform function to calculate the current position of the value mesh\r\n */\r\nexport interface IMotionControllerMeshMap {\r\n /**\r\n * the mesh that defines the maximum value mesh position.\r\n */\r\n maxMesh?: AbstractMesh;\r\n /**\r\n * the mesh that defines the minimum value mesh position.\r\n */\r\n minMesh?: AbstractMesh;\r\n /**\r\n * The mesh that will be changed when axis value changes\r\n */\r\n valueMesh?: AbstractMesh;\r\n}\r\n\r\n/**\r\n * The elements needed for change-detection of the gamepad objects in motion controllers\r\n */\r\nexport interface IMinimalMotionControllerObject {\r\n /**\r\n * Available axes of this controller\r\n */\r\n axes: number[];\r\n /**\r\n * An array of available buttons\r\n */\r\n buttons: Array<{\r\n /**\r\n * Value of the button/trigger\r\n */\r\n value: number;\r\n /**\r\n * If the button/trigger is currently touched\r\n */\r\n touched: boolean;\r\n /**\r\n * If the button/trigger is currently pressed\r\n */\r\n pressed: boolean;\r\n }>;\r\n\r\n /**\r\n * EXPERIMENTAL haptic support.\r\n */\r\n hapticActuators?: Array<{\r\n pulse: (value: number, duration: number) => Promise<boolean>;\r\n }>;\r\n}\r\n\r\n/**\r\n * An Abstract Motion controller\r\n * This class receives an xrInput and a profile layout and uses those to initialize the components\r\n * Each component has an observable to check for changes in value and state\r\n */\r\nexport abstract class WebXRAbstractMotionController implements IDisposable {\r\n private _initComponent = (id: string) => {\r\n if (!id) {\r\n return;\r\n }\r\n const componentDef = this.layout.components[id];\r\n const type = componentDef.type;\r\n const buttonIndex = componentDef.gamepadIndices.button;\r\n // search for axes\r\n const axes: number[] = [];\r\n if (componentDef.gamepadIndices.xAxis !== undefined && componentDef.gamepadIndices.yAxis !== undefined) {\r\n axes.push(componentDef.gamepadIndices.xAxis, componentDef.gamepadIndices.yAxis);\r\n }\r\n\r\n this.components[id] = new WebXRControllerComponent(id, type, buttonIndex, axes);\r\n };\r\n\r\n private _modelReady: boolean = false;\r\n\r\n /**\r\n * A map of components (WebXRControllerComponent) in this motion controller\r\n * Components have a ComponentType and can also have both button and axis definitions\r\n */\r\n public readonly components: {\r\n [id: string]: WebXRControllerComponent;\r\n } = {};\r\n\r\n /**\r\n * Disable the model's animation. Can be set at any time.\r\n */\r\n public disableAnimation: boolean = false;\r\n /**\r\n * Observers registered here will be triggered when the model of this controller is done loading\r\n */\r\n public onModelLoadedObservable: Observable<WebXRAbstractMotionController> = new Observable();\r\n /**\r\n * The profile id of this motion controller\r\n */\r\n public abstract profileId: string;\r\n /**\r\n * The root mesh of the model. It is null if the model was not yet initialized\r\n */\r\n public rootMesh: Nullable<AbstractMesh>;\r\n\r\n /**\r\n * constructs a new abstract motion controller\r\n * @param scene the scene to which the model of the controller will be added\r\n * @param layout The profile layout to load\r\n * @param gamepadObject The gamepad object correlating to this controller\r\n * @param handedness handedness (left/right/none) of this controller\r\n * @param _doNotLoadControllerMesh set this flag to ignore the mesh loading\r\n * @param _controllerCache a cache holding controller models already loaded in this session\r\n */\r\n constructor(\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected scene: Scene,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected layout: IMotionControllerLayout,\r\n /**\r\n * The gamepad object correlating to this controller\r\n */\r\n public gamepadObject: IMinimalMotionControllerObject,\r\n /**\r\n * handedness (left/right/none) of this controller\r\n */\r\n public handedness: MotionControllerHandedness,\r\n /**\r\n * @internal\r\n * [false]\r\n */\r\n public _doNotLoadControllerMesh: boolean = false,\r\n private _controllerCache?: Array<{\r\n filename: string;\r\n path: string;\r\n meshes: AbstractMesh[];\r\n }>\r\n ) {\r\n // initialize the components\r\n if (layout.components) {\r\n Object.keys(layout.components).forEach(this._initComponent);\r\n }\r\n // Model is loaded in WebXRInput\r\n }\r\n\r\n /**\r\n * Dispose this controller, the model mesh and all its components\r\n */\r\n public dispose(): void {\r\n this.getComponentIds().forEach((id) => this.getComponent(id).dispose());\r\n if (this.rootMesh) {\r\n this.rootMesh.getChildren(undefined, true).forEach((node) => {\r\n node.setEnabled(false);\r\n });\r\n this.rootMesh.dispose(!!this._controllerCache, !this._controllerCache);\r\n }\r\n }\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/core",
3
- "version": "7.11.2",
3
+ "version": "7.11.3",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",