WebXRHitTestLegacy.d.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import type { IWebXRFeature } from "../webXRFeaturesManager";
  2. import type { WebXRSessionManager } from "../webXRSessionManager";
  3. import { Observable } from "../../Misc/observable";
  4. import { Matrix } from "../../Maths/math.vector";
  5. import type { TransformNode } from "../../Meshes/transformNode";
  6. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  7. /**
  8. * An interface for all Hit test features
  9. */
  10. export interface IWebXRHitTestFeature<T extends IWebXRLegacyHitResult> extends IWebXRFeature {
  11. /**
  12. * Triggered when new babylon (transformed) hit test results are available
  13. */
  14. onHitTestResultObservable: Observable<T[]>;
  15. }
  16. /**
  17. * Options used for hit testing
  18. */
  19. export interface IWebXRLegacyHitTestOptions {
  20. /**
  21. * Only test when user interacted with the scene. Default - hit test every frame
  22. */
  23. testOnPointerDownOnly?: boolean;
  24. /**
  25. * The node to use to transform the local results to world coordinates
  26. */
  27. worldParentNode?: TransformNode;
  28. }
  29. /**
  30. * Interface defining the babylon result of raycasting/hit-test
  31. */
  32. export interface IWebXRLegacyHitResult {
  33. /**
  34. * Transformation matrix that can be applied to a node that will put it in the hit point location
  35. */
  36. transformationMatrix: Matrix;
  37. /**
  38. * The native hit test result
  39. */
  40. xrHitResult: XRHitResult | XRHitTestResult;
  41. }
  42. /**
  43. * The currently-working hit-test module.
  44. * Hit test (or Ray-casting) is used to interact with the real world.
  45. * For further information read here - https://github.com/immersive-web/hit-test
  46. */
  47. export declare class WebXRHitTestLegacy extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRLegacyHitResult> {
  48. /**
  49. * options to use when constructing this feature
  50. */
  51. readonly options: IWebXRLegacyHitTestOptions;
  52. private _direction;
  53. private _mat;
  54. private _onSelectEnabled;
  55. private _origin;
  56. /**
  57. * The module's name
  58. */
  59. static readonly Name = "xr-hit-test";
  60. /**
  61. * The (Babylon) version of this module.
  62. * This is an integer representing the implementation version.
  63. * This number does not correspond to the WebXR specs version
  64. */
  65. static readonly Version = 1;
  66. /**
  67. * Populated with the last native XR Hit Results
  68. */
  69. lastNativeXRHitResults: XRHitResult[];
  70. /**
  71. * Triggered when new babylon (transformed) hit test results are available
  72. */
  73. onHitTestResultObservable: Observable<IWebXRLegacyHitResult[]>;
  74. /**
  75. * Creates a new instance of the (legacy version) hit test feature
  76. * @param _xrSessionManager an instance of WebXRSessionManager
  77. * @param options options to use when constructing this feature
  78. */
  79. constructor(_xrSessionManager: WebXRSessionManager,
  80. /**
  81. * options to use when constructing this feature
  82. */
  83. options?: IWebXRLegacyHitTestOptions);
  84. /**
  85. * execute a hit test with an XR Ray
  86. *
  87. * @param xrSession a native xrSession that will execute this hit test
  88. * @param xrRay the ray (position and direction) to use for ray-casting
  89. * @param referenceSpace native XR reference space to use for the hit-test
  90. * @param filter filter function that will filter the results
  91. * @returns a promise that resolves with an array of native XR hit result in xr coordinates system
  92. */
  93. static XRHitTestWithRay(xrSession: XRSession, xrRay: XRRay, referenceSpace: XRReferenceSpace, filter?: (result: XRHitResult) => boolean): Promise<XRHitResult[]>;
  94. /**
  95. * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)
  96. * @param event the (select) event to use to select with
  97. * @param referenceSpace the reference space to use for this hit test
  98. * @returns a promise that resolves with an array of native XR hit result in xr coordinates system
  99. */
  100. static XRHitTestWithSelectEvent(event: XRInputSourceEvent, referenceSpace: XRReferenceSpace): Promise<XRHitResult[]>;
  101. /**
  102. * attach this feature
  103. * Will usually be called by the features manager
  104. *
  105. * @returns true if successful.
  106. */
  107. attach(): boolean;
  108. /**
  109. * detach this feature.
  110. * Will usually be called by the features manager
  111. *
  112. * @returns true if successful.
  113. */
  114. detach(): boolean;
  115. /**
  116. * Dispose this feature and all of the resources attached
  117. */
  118. dispose(): void;
  119. protected _onXRFrame(frame: XRFrame): void;
  120. private _onHitTestResults;
  121. private _onSelect;
  122. }