WebXRDepthSensing.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { RawTexture } from "../../Materials/Textures/rawTexture";
  2. import type { WebXRSessionManager } from "../webXRSessionManager";
  3. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  4. import { Observable } from "../../Misc/observable";
  5. import type { Nullable } from "../../types";
  6. import { InternalTexture } from "../../Materials/Textures/internalTexture";
  7. export type WebXRDepthUsage = "cpu" | "gpu";
  8. export type WebXRDepthDataFormat = "ushort" | "float";
  9. /**
  10. * Options for Depth Sensing feature
  11. */
  12. export interface IWebXRDepthSensingOptions {
  13. /**
  14. * The desired depth sensing usage for the session
  15. */
  16. usagePreference: WebXRDepthUsage[];
  17. /**
  18. * The desired depth sensing data format for the session
  19. */
  20. dataFormatPreference: WebXRDepthDataFormat[];
  21. }
  22. type GetDepthInMetersType = (x: number, y: number) => number;
  23. /**
  24. * WebXR Feature for WebXR Depth Sensing Module
  25. * @since 5.49.1
  26. */
  27. export declare class WebXRDepthSensing extends WebXRAbstractFeature {
  28. readonly options: IWebXRDepthSensingOptions;
  29. private _width;
  30. private _height;
  31. private _rawValueToMeters;
  32. private _normDepthBufferFromNormView;
  33. private _cachedDepthBuffer;
  34. private _cachedWebGLTexture;
  35. private _cachedDepthImageTexture;
  36. /**
  37. * Width of depth data. If depth data is not exist, returns null.
  38. */
  39. get width(): Nullable<number>;
  40. /**
  41. * Height of depth data. If depth data is not exist, returns null.
  42. */
  43. get height(): Nullable<number>;
  44. /**
  45. * Scale factor by which the raw depth values must be multiplied in order to get the depths in meters.
  46. */
  47. get rawValueToMeters(): Nullable<number>;
  48. /**
  49. * An XRRigidTransform that needs to be applied when indexing into the depth buffer.
  50. */
  51. get normDepthBufferFromNormView(): Nullable<XRRigidTransform>;
  52. /**
  53. * Describes which depth-sensing usage ("cpu" or "gpu") is used.
  54. */
  55. get depthUsage(): WebXRDepthUsage;
  56. /**
  57. * Describes which depth sensing data format ("ushort" or "float") is used.
  58. */
  59. get depthDataFormat(): WebXRDepthDataFormat;
  60. /**
  61. * Latest cached InternalTexture which containing depth buffer information.
  62. * This can be used when the depth usage is "gpu".
  63. */
  64. get latestInternalTexture(): Nullable<InternalTexture>;
  65. /**
  66. * cached depth buffer
  67. */
  68. get latestDepthBuffer(): Nullable<ArrayBufferView>;
  69. /**
  70. * Event that notify when `DepthInformation.getDepthInMeters` is available.
  71. * `getDepthInMeters` method needs active XRFrame (not available for cached XRFrame)
  72. */
  73. onGetDepthInMetersAvailable: Observable<GetDepthInMetersType>;
  74. /**
  75. * Latest cached Texture of depth image which is made from the depth buffer data.
  76. */
  77. get latestDepthImageTexture(): Nullable<RawTexture>;
  78. /**
  79. * XRWebGLBinding which is used for acquiring WebGLDepthInformation
  80. */
  81. private _glBinding?;
  82. /**
  83. * The module's name
  84. */
  85. static readonly Name = "xr-depth-sensing";
  86. /**
  87. * The (Babylon) version of this module.
  88. * This is an integer representing the implementation version.
  89. * This number does not correspond to the WebXR specs version
  90. */
  91. static readonly Version = 1;
  92. /**
  93. * Creates a new instance of the depth sensing feature
  94. * @param _xrSessionManager the WebXRSessionManager
  95. * @param options options for WebXR Depth Sensing Feature
  96. */
  97. constructor(_xrSessionManager: WebXRSessionManager, options: IWebXRDepthSensingOptions);
  98. /**
  99. * attach this feature
  100. * Will usually be called by the features manager
  101. * @param force should attachment be forced (even when already attached)
  102. * @returns true if successful.
  103. */
  104. attach(force?: boolean | undefined): boolean;
  105. /**
  106. * Dispose this feature and all of the resources attached
  107. */
  108. dispose(): void;
  109. protected _onXRFrame(_xrFrame: XRFrame): void;
  110. private _updateDepthInformationAndTextureCPUDepthUsage;
  111. private _updateDepthInformationAndTextureWebGLDepthUsage;
  112. /**
  113. * Extends the session init object if needed
  114. * @returns augmentation object for the xr session init object.
  115. */
  116. getXRSessionInitExtension(): Promise<Partial<XRSessionInit>>;
  117. }
  118. export {};