scaleGizmo.d.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 { GizmoAnchorPoint, GizmoAxisCache, IGizmo } from "./gizmo";
  7. import { GizmoCoordinatesMode, Gizmo } from "./gizmo";
  8. import type { IAxisScaleGizmo } from "./axisScaleGizmo";
  9. import { AxisScaleGizmo } from "./axisScaleGizmo";
  10. import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
  11. import type { Mesh } from "../Meshes/mesh";
  12. import type { Node } from "../node";
  13. import type { PointerInfo } from "../Events/pointerEvents";
  14. import { StandardMaterial } from "../Materials/standardMaterial";
  15. import type { GizmoManager } from "./gizmoManager";
  16. import type { TransformNode } from "../Meshes/transformNode";
  17. /**
  18. * Interface for scale gizmo
  19. */
  20. export interface IScaleGizmo extends IGizmo {
  21. /** True when the mouse pointer is dragging a gizmo mesh */
  22. readonly isDragging: boolean;
  23. /** Internal gizmo used for interactions on the x axis */
  24. xGizmo: IAxisScaleGizmo;
  25. /** Internal gizmo used for interactions on the y axis */
  26. yGizmo: IAxisScaleGizmo;
  27. /** Internal gizmo used for interactions on the z axis */
  28. zGizmo: IAxisScaleGizmo;
  29. /** Internal gizmo used to scale all axis equally*/
  30. uniformScaleGizmo: IAxisScaleGizmo;
  31. /** Fires an event when any of it's sub gizmos are dragged */
  32. onDragStartObservable: Observable<unknown>;
  33. /** Fires an event when any of it's sub gizmos are being dragged */
  34. onDragObservable: Observable<unknown>;
  35. /** Fires an event when any of it's sub gizmos are released from dragging */
  36. onDragEndObservable: Observable<unknown>;
  37. /** Drag distance in babylon units that the gizmo will snap to when dragged */
  38. snapDistance: number;
  39. /** Incremental snap scaling. When true, with a snapDistance of 0.1, scaling will be 1.1,1.2,1.3 instead of, when false: 1.1,1.21,1.33,... */
  40. incrementalSnap: boolean;
  41. /** Sensitivity factor for dragging */
  42. sensitivity: number;
  43. /**
  44. * Builds Gizmo Axis Cache to enable features such as hover state preservation and graying out other axis during manipulation
  45. * @param mesh Axis gizmo mesh
  46. * @param cache Gizmo axis definition used for reactive gizmo UI
  47. */
  48. addToAxisCache(mesh: Mesh, cache: GizmoAxisCache): void;
  49. /**
  50. * Force release the drag action by code
  51. */
  52. releaseDrag(): void;
  53. /** Default material used to render when gizmo is not disabled or hovered */
  54. coloredMaterial: StandardMaterial;
  55. /** Material used to render when gizmo is hovered with mouse*/
  56. hoverMaterial: StandardMaterial;
  57. /** Material used to render when gizmo is disabled. typically grey.*/
  58. disableMaterial: StandardMaterial;
  59. }
  60. /**
  61. * Additional options for the scale gizmo
  62. */
  63. export interface ScaleGizmoOptions {
  64. /**
  65. * Additional transform applied to the gizmo.
  66. * @See Gizmo.additionalTransformNode for more detail
  67. */
  68. additionalTransformNode?: TransformNode;
  69. }
  70. /**
  71. * Gizmo that enables scaling a mesh along 3 axis
  72. */
  73. export declare class ScaleGizmo extends Gizmo implements IScaleGizmo {
  74. /**
  75. * Internal gizmo used for interactions on the x axis
  76. */
  77. xGizmo: IAxisScaleGizmo;
  78. /**
  79. * Internal gizmo used for interactions on the y axis
  80. */
  81. yGizmo: IAxisScaleGizmo;
  82. /**
  83. * Internal gizmo used for interactions on the z axis
  84. */
  85. zGizmo: IAxisScaleGizmo;
  86. /**
  87. * Internal gizmo used to scale all axis equally
  88. */
  89. uniformScaleGizmo: IAxisScaleGizmo;
  90. protected _meshAttached: Nullable<AbstractMesh>;
  91. protected _nodeAttached: Nullable<Node>;
  92. protected _snapDistance: number;
  93. protected _incrementalSnap: boolean;
  94. protected _uniformScalingMesh: Mesh;
  95. protected _octahedron: Mesh;
  96. protected _sensitivity: number;
  97. protected _coloredMaterial: StandardMaterial;
  98. protected _hoverMaterial: StandardMaterial;
  99. protected _disableMaterial: StandardMaterial;
  100. protected _observables: Observer<PointerInfo>[];
  101. /** Node Caching for quick lookup */
  102. protected _gizmoAxisCache: Map<Mesh, GizmoAxisCache>;
  103. /** Default material used to render when gizmo is not disabled or hovered */
  104. get coloredMaterial(): StandardMaterial;
  105. /** Material used to render when gizmo is hovered with mouse*/
  106. get hoverMaterial(): StandardMaterial;
  107. /** Material used to render when gizmo is disabled. typically grey.*/
  108. get disableMaterial(): StandardMaterial;
  109. /** Fires an event when any of it's sub gizmos are dragged */
  110. onDragStartObservable: Observable<unknown>;
  111. /** Fires an event when any of it's sub gizmos are being dragged */
  112. onDragObservable: Observable<unknown>;
  113. /** Fires an event when any of it's sub gizmos are released from dragging */
  114. onDragEndObservable: Observable<unknown>;
  115. get attachedMesh(): Nullable<AbstractMesh>;
  116. set attachedMesh(mesh: Nullable<AbstractMesh>);
  117. get attachedNode(): Nullable<Node>;
  118. set attachedNode(node: Nullable<Node>);
  119. set updateScale(value: boolean);
  120. get updateScale(): boolean;
  121. /**
  122. * True when the mouse pointer is hovering a gizmo mesh
  123. */
  124. get isHovered(): boolean;
  125. /**
  126. * True when the mouse pointer is dragging a gizmo mesh
  127. */
  128. get isDragging(): boolean;
  129. get additionalTransformNode(): TransformNode | undefined;
  130. set additionalTransformNode(transformNode: TransformNode | undefined);
  131. /**
  132. * Creates a ScaleGizmo
  133. * @param gizmoLayer The utility layer the gizmo will be added to
  134. * @param thickness display gizmo axis thickness
  135. * @param gizmoManager
  136. * @param options More options
  137. */
  138. constructor(gizmoLayer?: UtilityLayerRenderer, thickness?: number, gizmoManager?: GizmoManager, options?: ScaleGizmoOptions);
  139. /**
  140. * @internal
  141. * Create Geometry for Gizmo
  142. */
  143. protected _createUniformScaleMesh(): AxisScaleGizmo;
  144. set updateGizmoRotationToMatchAttachedMesh(value: boolean);
  145. get updateGizmoRotationToMatchAttachedMesh(): boolean;
  146. set anchorPoint(value: GizmoAnchorPoint);
  147. get anchorPoint(): GizmoAnchorPoint;
  148. /**
  149. * posture that the gizmo will be display
  150. * When set null, default value will be used (Quaternion(0, 0, 0, 1))
  151. */
  152. get customRotationQuaternion(): Nullable<Quaternion>;
  153. set customRotationQuaternion(customRotationQuaternion: Nullable<Quaternion>);
  154. /**
  155. * Set the coordinate system to use. By default it's local.
  156. * But it's possible for a user to tweak so its local for translation and world for rotation.
  157. * In that case, setting the coordinate system will change `updateGizmoRotationToMatchAttachedMesh` and `updateGizmoPositionToMatchAttachedMesh`
  158. */
  159. set coordinatesMode(coordinatesMode: GizmoCoordinatesMode);
  160. /**
  161. * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)
  162. */
  163. set snapDistance(value: number);
  164. get snapDistance(): number;
  165. /**
  166. * Incremental snap scaling (default is false). When true, with a snapDistance of 0.1, scaling will be 1.1,1.2,1.3 instead of, when false: 1.1,1.21,1.33,...
  167. */
  168. set incrementalSnap(value: boolean);
  169. get incrementalSnap(): boolean;
  170. /**
  171. * Ratio for the scale of the gizmo (Default: 1)
  172. */
  173. set scaleRatio(value: number);
  174. get scaleRatio(): number;
  175. /**
  176. * Sensitivity factor for dragging (Default: 1)
  177. */
  178. set sensitivity(value: number);
  179. get sensitivity(): number;
  180. /**
  181. * Builds Gizmo Axis Cache to enable features such as hover state preservation and graying out other axis during manipulation
  182. * @param mesh Axis gizmo mesh
  183. * @param cache Gizmo axis definition used for reactive gizmo UI
  184. */
  185. addToAxisCache(mesh: Mesh, cache: GizmoAxisCache): void;
  186. /**
  187. * Get the cache set with addToAxisCache for a specific mesh
  188. * @param mesh Axis gizmo mesh
  189. * @returns Gizmo axis definition used for reactive gizmo UI
  190. */
  191. getAxisCache(mesh: Mesh): GizmoAxisCache | undefined;
  192. /**
  193. * Force release the drag action by code
  194. */
  195. releaseDrag(): void;
  196. /**
  197. * Disposes of the gizmo
  198. */
  199. dispose(): void;
  200. }