positionGizmo.d.ts 7.5 KB

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