webXRControllerComponent.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import type { IMinimalMotionControllerObject, MotionControllerComponentType } from "./webXRAbstractMotionController";
  2. import { Observable } from "../../Misc/observable";
  3. import type { IDisposable } from "../../scene";
  4. /**
  5. * X-Y values for axes in WebXR
  6. */
  7. export interface IWebXRMotionControllerAxesValue {
  8. /**
  9. * The value of the x axis
  10. */
  11. x: number;
  12. /**
  13. * The value of the y-axis
  14. */
  15. y: number;
  16. }
  17. /**
  18. * changed / previous values for the values of this component
  19. */
  20. export interface IWebXRMotionControllerComponentChangesValues<T> {
  21. /**
  22. * current (this frame) value
  23. */
  24. current: T;
  25. /**
  26. * previous (last change) value
  27. */
  28. previous: T;
  29. }
  30. /**
  31. * Represents changes in the component between current frame and last values recorded
  32. */
  33. export interface IWebXRMotionControllerComponentChanges {
  34. /**
  35. * will be populated with previous and current values if axes changed
  36. */
  37. axes?: IWebXRMotionControllerComponentChangesValues<IWebXRMotionControllerAxesValue>;
  38. /**
  39. * will be populated with previous and current values if pressed changed
  40. */
  41. pressed?: IWebXRMotionControllerComponentChangesValues<boolean>;
  42. /**
  43. * will be populated with previous and current values if touched changed
  44. */
  45. touched?: IWebXRMotionControllerComponentChangesValues<boolean>;
  46. /**
  47. * will be populated with previous and current values if value changed
  48. */
  49. value?: IWebXRMotionControllerComponentChangesValues<number>;
  50. }
  51. /**
  52. * This class represents a single component (for example button or thumbstick) of a motion controller
  53. */
  54. export declare class WebXRControllerComponent implements IDisposable {
  55. /**
  56. * the id of this component
  57. */
  58. id: string;
  59. /**
  60. * the type of the component
  61. */
  62. type: MotionControllerComponentType;
  63. private _buttonIndex;
  64. private _axesIndices;
  65. private _axes;
  66. private _changes;
  67. private _currentValue;
  68. private _hasChanges;
  69. private _pressed;
  70. private _touched;
  71. /**
  72. * button component type
  73. */
  74. static BUTTON_TYPE: MotionControllerComponentType;
  75. /**
  76. * squeeze component type
  77. */
  78. static SQUEEZE_TYPE: MotionControllerComponentType;
  79. /**
  80. * Thumbstick component type
  81. */
  82. static THUMBSTICK_TYPE: MotionControllerComponentType;
  83. /**
  84. * Touchpad component type
  85. */
  86. static TOUCHPAD_TYPE: MotionControllerComponentType;
  87. /**
  88. * trigger component type
  89. */
  90. static TRIGGER_TYPE: MotionControllerComponentType;
  91. /**
  92. * If axes are available for this component (like a touchpad or thumbstick) the observers will be notified when
  93. * the axes data changes
  94. */
  95. onAxisValueChangedObservable: Observable<{
  96. x: number;
  97. y: number;
  98. }>;
  99. /**
  100. * Observers registered here will be triggered when the state of a button changes
  101. * State change is either pressed / touched / value
  102. */
  103. onButtonStateChangedObservable: Observable<WebXRControllerComponent>;
  104. /**
  105. * Creates a new component for a motion controller.
  106. * It is created by the motion controller itself
  107. *
  108. * @param id the id of this component
  109. * @param type the type of the component
  110. * @param _buttonIndex index in the buttons array of the gamepad
  111. * @param _axesIndices indices of the values in the axes array of the gamepad
  112. */
  113. constructor(
  114. /**
  115. * the id of this component
  116. */
  117. id: string,
  118. /**
  119. * the type of the component
  120. */
  121. type: MotionControllerComponentType, _buttonIndex?: number, _axesIndices?: number[]);
  122. /**
  123. * The current axes data. If this component has no axes it will still return an object { x: 0, y: 0 }
  124. */
  125. get axes(): IWebXRMotionControllerAxesValue;
  126. /**
  127. * Get the changes. Elements will be populated only if they changed with their previous and current value
  128. */
  129. get changes(): IWebXRMotionControllerComponentChanges;
  130. /**
  131. * Return whether or not the component changed the last frame
  132. */
  133. get hasChanges(): boolean;
  134. /**
  135. * is the button currently pressed
  136. */
  137. get pressed(): boolean;
  138. /**
  139. * is the button currently touched
  140. */
  141. get touched(): boolean;
  142. /**
  143. * Get the current value of this component
  144. */
  145. get value(): number;
  146. /**
  147. * Dispose this component
  148. */
  149. dispose(): void;
  150. /**
  151. * Are there axes correlating to this component
  152. * @returns true is axes data is available
  153. */
  154. isAxes(): boolean;
  155. /**
  156. * Is this component a button (hence - pressable)
  157. * @returns true if can be pressed
  158. */
  159. isButton(): boolean;
  160. /**
  161. * update this component using the gamepad object it is in. Called on every frame
  162. * @param nativeController the native gamepad controller object
  163. */
  164. update(nativeController: IMinimalMotionControllerObject): void;
  165. }