WebXRControllerPhysics.d.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  2. import type { WebXRInputSource } from "../webXRInputSource";
  3. import { PhysicsImpostor } from "../../Physics/v1/physicsImpostor";
  4. import type { WebXRInput } from "../webXRInput";
  5. import type { WebXRSessionManager } from "../webXRSessionManager";
  6. import type { Nullable } from "../../types";
  7. /**
  8. * Options for the controller physics feature
  9. */
  10. export declare class IWebXRControllerPhysicsOptions {
  11. /**
  12. * Should the headset get its own impostor
  13. */
  14. enableHeadsetImpostor?: boolean;
  15. /**
  16. * Optional parameters for the headset impostor
  17. */
  18. headsetImpostorParams?: {
  19. /**
  20. * The type of impostor to create. Default is sphere
  21. */
  22. impostorType: number;
  23. /**
  24. * the size of the impostor. Defaults to 10cm
  25. */
  26. impostorSize?: number | {
  27. width: number;
  28. height: number;
  29. depth: number;
  30. };
  31. /**
  32. * Friction definitions
  33. */
  34. friction?: number;
  35. /**
  36. * Restitution
  37. */
  38. restitution?: number;
  39. };
  40. /**
  41. * The physics properties of the future impostors
  42. */
  43. physicsProperties?: {
  44. /**
  45. * If set to true, a mesh impostor will be created when the controller mesh was loaded
  46. * Note that this requires a physics engine that supports mesh impostors!
  47. */
  48. useControllerMesh?: boolean;
  49. /**
  50. * The type of impostor to create. Default is sphere
  51. */
  52. impostorType?: number;
  53. /**
  54. * the size of the impostor. Defaults to 10cm
  55. */
  56. impostorSize?: number | {
  57. width: number;
  58. height: number;
  59. depth: number;
  60. };
  61. /**
  62. * Friction definitions
  63. */
  64. friction?: number;
  65. /**
  66. * Restitution
  67. */
  68. restitution?: number;
  69. };
  70. /**
  71. * the xr input to use with this pointer selection
  72. */
  73. xrInput: WebXRInput;
  74. }
  75. /**
  76. * Add physics impostor to your webxr controllers,
  77. * including naive calculation of their linear and angular velocity
  78. */
  79. export declare class WebXRControllerPhysics extends WebXRAbstractFeature {
  80. private readonly _options;
  81. private _attachController;
  82. private _createPhysicsImpostor;
  83. private _controllers;
  84. private _debugMode;
  85. private _delta;
  86. private _headsetImpostor?;
  87. private _headsetMesh?;
  88. private _lastTimestamp;
  89. private _tmpQuaternion;
  90. private _tmpVector;
  91. /**
  92. * The module's name
  93. */
  94. static readonly Name = "xr-physics-controller";
  95. /**
  96. * The (Babylon) version of this module.
  97. * This is an integer representing the implementation version.
  98. * This number does not correspond to the webxr specs version
  99. */
  100. static readonly Version = 1;
  101. /**
  102. * Construct a new Controller Physics Feature
  103. * @param _xrSessionManager the corresponding xr session manager
  104. * @param _options options to create this feature with
  105. */
  106. constructor(_xrSessionManager: WebXRSessionManager, _options: IWebXRControllerPhysicsOptions);
  107. /**
  108. * @internal
  109. * enable debugging - will show console outputs and the impostor mesh
  110. */
  111. _enablePhysicsDebug(): void;
  112. /**
  113. * Manually add a controller (if no xrInput was provided or physics engine was not enabled)
  114. * @param xrController the controller to add
  115. */
  116. addController(xrController: WebXRInputSource): void;
  117. /**
  118. * attach this feature
  119. * Will usually be called by the features manager
  120. *
  121. * @returns true if successful.
  122. */
  123. attach(): boolean;
  124. /**
  125. * detach this feature.
  126. * Will usually be called by the features manager
  127. *
  128. * @returns true if successful.
  129. */
  130. detach(): boolean;
  131. /**
  132. * Get the headset impostor, if enabled
  133. * @returns the impostor
  134. */
  135. getHeadsetImpostor(): PhysicsImpostor | undefined;
  136. /**
  137. * Get the physics impostor of a specific controller.
  138. * The impostor is not attached to a mesh because a mesh for each controller is not obligatory
  139. * @param controller the controller or the controller id of which to get the impostor
  140. * @returns the impostor or null
  141. */
  142. getImpostorForController(controller: WebXRInputSource | string): Nullable<PhysicsImpostor>;
  143. /**
  144. * Update the physics properties provided in the constructor
  145. * @param newProperties the new properties object
  146. * @param newProperties.impostorType
  147. * @param newProperties.impostorSize
  148. * @param newProperties.friction
  149. * @param newProperties.restitution
  150. */
  151. setPhysicsProperties(newProperties: {
  152. impostorType?: number;
  153. impostorSize?: number | {
  154. width: number;
  155. height: number;
  156. depth: number;
  157. };
  158. friction?: number;
  159. restitution?: number;
  160. }): void;
  161. protected _onXRFrame(_xrFrame: any): void;
  162. private _detachController;
  163. }