WebXRImageTracking.d.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import type { WebXRSessionManager } from "../webXRSessionManager";
  2. import { Observable } from "../../Misc/observable";
  3. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  4. import { Matrix } from "../../Maths/math.vector";
  5. import type { Nullable } from "../../types";
  6. /**
  7. * Options interface for the background remover plugin
  8. */
  9. export interface IWebXRImageTrackingOptions {
  10. /**
  11. * A required array with images to track
  12. */
  13. images: {
  14. /**
  15. * The source of the image. can be a URL or an image bitmap
  16. */
  17. src: string | ImageBitmap;
  18. /**
  19. * The estimated width in the real world (in meters)
  20. */
  21. estimatedRealWorldWidth: number;
  22. }[];
  23. }
  24. /**
  25. * An object representing an image tracked by the system
  26. */
  27. export interface IWebXRTrackedImage {
  28. /**
  29. * The ID of this image (which is the same as the position in the array that was used to initialize the feature)
  30. */
  31. id: number;
  32. /**
  33. * Is the transformation provided emulated. If it is, the system "guesses" its real position. Otherwise it can be considered as exact position.
  34. */
  35. emulated?: boolean;
  36. /**
  37. * Just in case it is needed - the image bitmap that is being tracked
  38. */
  39. originalBitmap: ImageBitmap;
  40. /**
  41. * The native XR result image tracking result, untouched
  42. */
  43. xrTrackingResult?: XRImageTrackingResult;
  44. /**
  45. * Width in real world (meters)
  46. */
  47. realWorldWidth?: number;
  48. /**
  49. * A transformation matrix of this current image in the current reference space.
  50. */
  51. transformationMatrix: Matrix;
  52. /**
  53. * The width/height ratio of this image. can be used to calculate the size of the detected object/image
  54. */
  55. ratio?: number;
  56. }
  57. /**
  58. * Image tracking for immersive AR sessions.
  59. * Providing a list of images and their estimated widths will enable tracking those images in the real world.
  60. */
  61. export declare class WebXRImageTracking extends WebXRAbstractFeature {
  62. /**
  63. * read-only options to be used in this module
  64. */
  65. readonly options: IWebXRImageTrackingOptions;
  66. /**
  67. * The module's name
  68. */
  69. static readonly Name = "xr-image-tracking";
  70. /**
  71. * The (Babylon) version of this module.
  72. * This is an integer representing the implementation version.
  73. * This number does not correspond to the WebXR specs version
  74. */
  75. static readonly Version = 1;
  76. /**
  77. * This will be triggered if the underlying system deems an image untrackable.
  78. * The index is the index of the image from the array used to initialize the feature.
  79. */
  80. onUntrackableImageFoundObservable: Observable<number>;
  81. /**
  82. * An image was deemed trackable, and the system will start tracking it.
  83. */
  84. onTrackableImageFoundObservable: Observable<IWebXRTrackedImage>;
  85. /**
  86. * The image was found and its state was updated.
  87. */
  88. onTrackedImageUpdatedObservable: Observable<IWebXRTrackedImage>;
  89. private _trackableScoreStatus;
  90. private _trackedImages;
  91. private _originalTrackingRequest;
  92. /**
  93. * constructs the image tracking feature
  94. * @param _xrSessionManager the session manager for this module
  95. * @param options read-only options to be used in this module
  96. */
  97. constructor(_xrSessionManager: WebXRSessionManager,
  98. /**
  99. * read-only options to be used in this module
  100. */
  101. options: IWebXRImageTrackingOptions);
  102. /**
  103. * attach this feature
  104. * Will usually be called by the features manager
  105. *
  106. * @returns true if successful.
  107. */
  108. attach(): boolean;
  109. /**
  110. * detach this feature.
  111. * Will usually be called by the features manager
  112. *
  113. * @returns true if successful.
  114. */
  115. detach(): boolean;
  116. /**
  117. * Get a tracked image by its ID.
  118. *
  119. * @param id the id of the image to load (position in the init array)
  120. * @returns a trackable image, if exists in this location
  121. */
  122. getTrackedImageById(id: number): Nullable<IWebXRTrackedImage>;
  123. /**
  124. * Dispose this feature and all of the resources attached
  125. */
  126. dispose(): void;
  127. /**
  128. * Extends the session init object if needed
  129. * @returns augmentation object fo the xr session init object.
  130. */
  131. getXRSessionInitExtension(): Promise<Partial<XRSessionInit>>;
  132. protected _onXRFrame(_xrFrame: XRFrame): void;
  133. private _checkScoresAsync;
  134. }