WebXRHitTest.d.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import type { WebXRSessionManager } from "../webXRSessionManager";
  2. import { Observable } from "../../Misc/observable";
  3. import { Vector3, Quaternion } from "../../Maths/math.vector";
  4. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  5. import type { IWebXRLegacyHitTestOptions, IWebXRLegacyHitResult, IWebXRHitTestFeature } from "./WebXRHitTestLegacy";
  6. /**
  7. * Options used for hit testing (version 2)
  8. */
  9. export interface IWebXRHitTestOptions extends IWebXRLegacyHitTestOptions {
  10. /**
  11. * Do not create a permanent hit test. Will usually be used when only
  12. * transient inputs are needed.
  13. */
  14. disablePermanentHitTest?: boolean;
  15. /**
  16. * Enable transient (for example touch-based) hit test inspections
  17. */
  18. enableTransientHitTest?: boolean;
  19. /**
  20. * Override the default transient hit test profile (generic-touchscreen).
  21. */
  22. transientHitTestProfile?: string;
  23. /**
  24. * Offset ray for the permanent hit test
  25. */
  26. offsetRay?: Vector3;
  27. /**
  28. * Offset ray for the transient hit test
  29. */
  30. transientOffsetRay?: Vector3;
  31. /**
  32. * Instead of using viewer space for hit tests, use the reference space defined in the session manager
  33. */
  34. useReferenceSpace?: boolean;
  35. /**
  36. * Override the default entity type(s) of the hit-test result
  37. */
  38. entityTypes?: XRHitTestTrackableType[];
  39. }
  40. /**
  41. * Interface defining the babylon result of hit-test
  42. */
  43. export interface IWebXRHitResult extends IWebXRLegacyHitResult {
  44. /**
  45. * The input source that generated this hit test (if transient)
  46. */
  47. inputSource?: XRInputSource;
  48. /**
  49. * Is this a transient hit test
  50. */
  51. isTransient?: boolean;
  52. /**
  53. * Position of the hit test result
  54. */
  55. position: Vector3;
  56. /**
  57. * Rotation of the hit test result
  58. */
  59. rotationQuaternion: Quaternion;
  60. /**
  61. * The native hit test result
  62. */
  63. xrHitResult: XRHitTestResult;
  64. }
  65. /**
  66. * The currently-working hit-test module.
  67. * Hit test (or Ray-casting) is used to interact with the real world.
  68. * For further information read here - https://github.com/immersive-web/hit-test
  69. *
  70. * Tested on chrome (mobile) 80.
  71. */
  72. export declare class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRHitResult> {
  73. /**
  74. * options to use when constructing this feature
  75. */
  76. readonly options: IWebXRHitTestOptions;
  77. private _tmpMat;
  78. private _tmpPos;
  79. private _tmpQuat;
  80. private _transientXrHitTestSource;
  81. private _xrHitTestSource;
  82. private _initHitTestSource;
  83. /**
  84. * The module's name
  85. */
  86. static readonly Name = "xr-hit-test";
  87. /**
  88. * The (Babylon) version of this module.
  89. * This is an integer representing the implementation version.
  90. * This number does not correspond to the WebXR specs version
  91. */
  92. static readonly Version = 2;
  93. /**
  94. * When set to true, each hit test will have its own position/rotation objects
  95. * When set to false, position and rotation objects will be reused for each hit test. It is expected that
  96. * the developers will clone them or copy them as they see fit.
  97. */
  98. autoCloneTransformation: boolean;
  99. /**
  100. * Triggered when new babylon (transformed) hit test results are available
  101. * Note - this will be called when results come back from the device. It can be an empty array!!
  102. */
  103. onHitTestResultObservable: Observable<IWebXRHitResult[]>;
  104. /**
  105. * Use this to temporarily pause hit test checks.
  106. */
  107. paused: boolean;
  108. /**
  109. * Creates a new instance of the hit test feature
  110. * @param _xrSessionManager an instance of WebXRSessionManager
  111. * @param options options to use when constructing this feature
  112. */
  113. constructor(_xrSessionManager: WebXRSessionManager,
  114. /**
  115. * options to use when constructing this feature
  116. */
  117. options?: IWebXRHitTestOptions);
  118. /**
  119. * attach this feature
  120. * Will usually be called by the features manager
  121. *
  122. * @returns true if successful.
  123. */
  124. attach(): boolean;
  125. /**
  126. * detach this feature.
  127. * Will usually be called by the features manager
  128. *
  129. * @returns true if successful.
  130. */
  131. detach(): boolean;
  132. /**
  133. * Dispose this feature and all of the resources attached
  134. */
  135. dispose(): void;
  136. protected _onXRFrame(frame: XRFrame): void;
  137. private _processWebXRHitTestResult;
  138. }