rotationGizmo.d.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import type { Observer } from "../Misc/observable";
  2. import { Observable } from "../Misc/observable";
  3. import type { Nullable } from "../types";
  4. import type { Quaternion } from "../Maths/math.vector";
  5. import { Color3 } from "../Maths/math.color";
  6. import type { AbstractMesh } from "../Meshes/abstractMesh";
  7. import type { Mesh } from "../Meshes/mesh";
  8. import type { GizmoAnchorPoint, GizmoCoordinatesMode, GizmoAxisCache, IGizmo } from "./gizmo";
  9. import { Gizmo } from "./gizmo";
  10. import type { IPlaneRotationGizmo } from "./planeRotationGizmo";
  11. import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
  12. import type { Node } from "../node";
  13. import type { PointerInfo } from "../Events/pointerEvents";
  14. import type { TransformNode } from "../Meshes/transformNode";
  15. import type { GizmoManager } from "./gizmoManager";
  16. /**
  17. * Interface for rotation gizmo
  18. */
  19. export interface IRotationGizmo extends IGizmo {
  20. /** True when the mouse pointer is dragging a gizmo mesh */
  21. readonly isDragging: boolean;
  22. /** Internal gizmo used for interactions on the x axis */
  23. xGizmo: IPlaneRotationGizmo;
  24. /** Internal gizmo used for interactions on the y axis */
  25. yGizmo: IPlaneRotationGizmo;
  26. /** Internal gizmo used for interactions on the z axis */
  27. zGizmo: IPlaneRotationGizmo;
  28. /** Fires an event when any of it's sub gizmos are dragged */
  29. onDragStartObservable: Observable<unknown>;
  30. /** Fires an event when any of it's sub gizmos are being dragged */
  31. onDragObservable: Observable<unknown>;
  32. /** Fires an event when any of it's sub gizmos are released from dragging */
  33. onDragEndObservable: Observable<unknown>;
  34. /** Drag distance in babylon units that the gizmo will snap to when dragged */
  35. snapDistance: number;
  36. /** Custom sensitivity value for the drag strength */
  37. sensitivity: number;
  38. /**
  39. * Builds Gizmo Axis Cache to enable features such as hover state preservation and graying out other axis during manipulation
  40. * @param mesh Axis gizmo mesh
  41. * @param cache Gizmo axis definition used for reactive gizmo UI
  42. */
  43. addToAxisCache(mesh: Mesh, cache: GizmoAxisCache): void;
  44. /**
  45. * Force release the drag action by code
  46. */
  47. releaseDrag(): void;
  48. }
  49. /**
  50. * Options for each individual plane rotation gizmo contained within RotationGizmo
  51. * @since 5.0.0
  52. */
  53. export interface PlaneRotationGizmoOptions {
  54. /**
  55. * Color to use for the plane rotation gizmo
  56. */
  57. color?: Color3;
  58. }
  59. /**
  60. * Additional options for each rotation gizmo
  61. */
  62. export interface RotationGizmoOptions {
  63. /**
  64. * When set, the gizmo will always appear the same size no matter where the camera is (default: true)
  65. */
  66. updateScale?: boolean;
  67. /**
  68. * Specific options for xGizmo
  69. */
  70. xOptions?: PlaneRotationGizmoOptions;
  71. /**
  72. * Specific options for yGizmo
  73. */
  74. yOptions?: PlaneRotationGizmoOptions;
  75. /**
  76. * Specific options for zGizmo
  77. */
  78. zOptions?: PlaneRotationGizmoOptions;
  79. /**
  80. * Additional transform applied to the gizmo.
  81. * @See Gizmo.additionalTransformNode for more detail
  82. */
  83. additionalTransformNode?: TransformNode;
  84. }
  85. /**
  86. * Gizmo that enables rotating a mesh along 3 axis
  87. */
  88. export declare class RotationGizmo extends Gizmo implements IRotationGizmo {
  89. /**
  90. * Internal gizmo used for interactions on the x axis
  91. */
  92. xGizmo: IPlaneRotationGizmo;
  93. /**
  94. * Internal gizmo used for interactions on the y axis
  95. */
  96. yGizmo: IPlaneRotationGizmo;
  97. /**
  98. * Internal gizmo used for interactions on the z axis
  99. */
  100. zGizmo: IPlaneRotationGizmo;
  101. /** Fires an event when any of it's sub gizmos are dragged */
  102. onDragStartObservable: Observable<unknown>;
  103. /** Fires an event when any of it's sub gizmos are being dragged */
  104. onDragObservable: Observable<unknown>;
  105. /** Fires an event when any of it's sub gizmos are released from dragging */
  106. onDragEndObservable: Observable<unknown>;
  107. protected _meshAttached: Nullable<AbstractMesh>;
  108. protected _nodeAttached: Nullable<Node>;
  109. protected _observables: Observer<PointerInfo>[];
  110. protected _sensitivity: number;
  111. /** Node Caching for quick lookup */
  112. protected _gizmoAxisCache: Map<Mesh, GizmoAxisCache>;
  113. get attachedMesh(): Nullable<AbstractMesh>;
  114. set attachedMesh(mesh: Nullable<AbstractMesh>);
  115. get attachedNode(): Nullable<Node>;
  116. set attachedNode(node: Nullable<Node>);
  117. protected _checkBillboardTransform(): void;
  118. /**
  119. * Sensitivity factor for dragging (Default: 1)
  120. */
  121. set sensitivity(value: number);
  122. get sensitivity(): number;
  123. /**
  124. * True when the mouse pointer is hovering a gizmo mesh
  125. */
  126. get isHovered(): boolean;
  127. /**
  128. * True when the mouse pointer is dragging a gizmo mesh
  129. */
  130. get isDragging(): boolean;
  131. get additionalTransformNode(): TransformNode | undefined;
  132. set additionalTransformNode(transformNode: TransformNode | undefined);
  133. /**
  134. * Creates a RotationGizmo
  135. * @param gizmoLayer The utility layer the gizmo will be added to
  136. * @param tessellation Amount of tessellation to be used when creating rotation circles
  137. * @param useEulerRotation Use and update Euler angle instead of quaternion
  138. * @param thickness display gizmo axis thickness
  139. * @param gizmoManager Gizmo manager
  140. * @param options More options
  141. */
  142. constructor(gizmoLayer?: UtilityLayerRenderer, tessellation?: number, useEulerRotation?: boolean, thickness?: number, gizmoManager?: GizmoManager, options?: RotationGizmoOptions);
  143. /**
  144. * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)
  145. * NOTE: This is only possible for meshes with uniform scaling, as otherwise it's not possible to decompose the rotation
  146. */
  147. set updateGizmoRotationToMatchAttachedMesh(value: boolean);
  148. get updateGizmoRotationToMatchAttachedMesh(): boolean;
  149. set updateGizmoPositionToMatchAttachedMesh(value: boolean);
  150. get updateGizmoPositionToMatchAttachedMesh(): boolean;
  151. set anchorPoint(value: GizmoAnchorPoint);
  152. get anchorPoint(): GizmoAnchorPoint;
  153. /**
  154. * Set the coordinate system to use. By default it's local.
  155. * But it's possible for a user to tweak so its local for translation and world for rotation.
  156. * In that case, setting the coordinate system will change `updateGizmoRotationToMatchAttachedMesh` and `updateGizmoPositionToMatchAttachedMesh`
  157. */
  158. set coordinatesMode(coordinatesMode: GizmoCoordinatesMode);
  159. set updateScale(value: boolean);
  160. get updateScale(): boolean;
  161. /**
  162. * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)
  163. */
  164. set snapDistance(value: number);
  165. get snapDistance(): number;
  166. /**
  167. * Ratio for the scale of the gizmo (Default: 1)
  168. */
  169. set scaleRatio(value: number);
  170. get scaleRatio(): number;
  171. /**
  172. * posture that the gizmo will be display
  173. * When set null, default value will be used (Quaternion(0, 0, 0, 1))
  174. */
  175. get customRotationQuaternion(): Nullable<Quaternion>;
  176. set customRotationQuaternion(customRotationQuaternion: Nullable<Quaternion>);
  177. /**
  178. * Builds Gizmo Axis Cache to enable features such as hover state preservation and graying out other axis during manipulation
  179. * @param mesh Axis gizmo mesh
  180. * @param cache Gizmo axis definition used for reactive gizmo UI
  181. */
  182. addToAxisCache(mesh: Mesh, cache: GizmoAxisCache): void;
  183. /**
  184. * Force release the drag action by code
  185. */
  186. releaseDrag(): void;
  187. /**
  188. * Disposes of the gizmo
  189. */
  190. dispose(): void;
  191. /**
  192. * CustomMeshes are not supported by this gizmo
  193. */
  194. setCustomMesh(): void;
  195. }