gizmoManager.d.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import type { Observer } from "../Misc/observable";
  2. import { Observable } from "../Misc/observable";
  3. import type { Nullable } from "../types";
  4. import type { PointerInfo } from "../Events/pointerEvents";
  5. import type { Scene, IDisposable } from "../scene";
  6. import type { Node } from "../node";
  7. import { AbstractMesh } from "../Meshes/abstractMesh";
  8. import type { Mesh } from "../Meshes/mesh";
  9. import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
  10. import { Color3 } from "../Maths/math.color";
  11. import { SixDofDragBehavior } from "../Behaviors/Meshes/sixDofDragBehavior";
  12. import type { GizmoAxisCache } from "./gizmo";
  13. import { GizmoCoordinatesMode } from "./gizmo";
  14. import type { IRotationGizmo } from "./rotationGizmo";
  15. import type { IPositionGizmo } from "./positionGizmo";
  16. import type { IScaleGizmo } from "./scaleGizmo";
  17. import type { IBoundingBoxGizmo } from "./boundingBoxGizmo";
  18. import type { TransformNode } from "../Meshes/transformNode";
  19. /**
  20. * Helps setup gizmo's in the scene to rotate/scale/position nodes
  21. */
  22. export declare class GizmoManager implements IDisposable {
  23. private _scene;
  24. /**
  25. * Gizmo's created by the gizmo manager, gizmo will be null until gizmo has been enabled for the first time
  26. */
  27. gizmos: {
  28. positionGizmo: Nullable<IPositionGizmo>;
  29. rotationGizmo: Nullable<IRotationGizmo>;
  30. scaleGizmo: Nullable<IScaleGizmo>;
  31. boundingBoxGizmo: Nullable<IBoundingBoxGizmo>;
  32. };
  33. /** When true, the gizmo will be detached from the current object when a pointer down occurs with an empty picked mesh */
  34. clearGizmoOnEmptyPointerEvent: boolean;
  35. /** When true (default), picking to attach a new mesh is enabled. This works in sync with inspector autopicking. */
  36. enableAutoPicking: boolean;
  37. /** Fires an event when the manager is attached to a mesh */
  38. onAttachedToMeshObservable: Observable<Nullable<AbstractMesh>>;
  39. /** Fires an event when the manager is attached to a node */
  40. onAttachedToNodeObservable: Observable<Nullable<Node>>;
  41. protected _gizmosEnabled: {
  42. positionGizmo: boolean;
  43. rotationGizmo: boolean;
  44. scaleGizmo: boolean;
  45. boundingBoxGizmo: boolean;
  46. };
  47. protected _pointerObservers: Observer<PointerInfo>[];
  48. protected _attachedMesh: Nullable<AbstractMesh>;
  49. protected _attachedNode: Nullable<Node>;
  50. protected _boundingBoxColor: Color3;
  51. protected _defaultUtilityLayer: UtilityLayerRenderer;
  52. protected _defaultKeepDepthUtilityLayer: UtilityLayerRenderer;
  53. protected _thickness: number;
  54. protected _scaleRatio: number;
  55. protected _coordinatesMode: GizmoCoordinatesMode;
  56. protected _additionalTransformNode?: TransformNode;
  57. /** Node Caching for quick lookup */
  58. private _gizmoAxisCache;
  59. /**
  60. * When bounding box gizmo is enabled, this can be used to track drag/end events
  61. */
  62. boundingBoxDragBehavior: SixDofDragBehavior;
  63. /**
  64. * Array of meshes which will have the gizmo attached when a pointer selected them. If null, all meshes are attachable. (Default: null)
  65. */
  66. attachableMeshes: Nullable<Array<AbstractMesh>>;
  67. /**
  68. * Array of nodes which will have the gizmo attached when a pointer selected them. If null, all nodes are attachable. (Default: null)
  69. */
  70. attachableNodes: Nullable<Array<Node>>;
  71. /**
  72. * If pointer events should perform attaching/detaching a gizmo, if false this can be done manually via attachToMesh/attachToNode. (Default: true)
  73. */
  74. usePointerToAttachGizmos: boolean;
  75. /**
  76. * Utility layer that the bounding box gizmo belongs to
  77. */
  78. get keepDepthUtilityLayer(): UtilityLayerRenderer;
  79. /**
  80. * Utility layer that all gizmos besides bounding box belong to
  81. */
  82. get utilityLayer(): UtilityLayerRenderer;
  83. /**
  84. * True when the mouse pointer is hovering a gizmo mesh
  85. */
  86. get isHovered(): boolean;
  87. /**
  88. * True when the mouse pointer is dragging a gizmo mesh
  89. */
  90. get isDragging(): boolean;
  91. /**
  92. * Ratio for the scale of the gizmo (Default: 1)
  93. */
  94. set scaleRatio(value: number);
  95. get scaleRatio(): number;
  96. /**
  97. * Set the coordinate system to use. By default it's local.
  98. * But it's possible for a user to tweak so its local for translation and world for rotation.
  99. * In that case, setting the coordinate system will change `updateGizmoRotationToMatchAttachedMesh` and `updateGizmoPositionToMatchAttachedMesh`
  100. */
  101. set coordinatesMode(coordinatesMode: GizmoCoordinatesMode);
  102. get coordinatesMode(): GizmoCoordinatesMode;
  103. /**
  104. * The mesh the gizmo's is attached to
  105. */
  106. get attachedMesh(): Nullable<AbstractMesh>;
  107. /**
  108. * The node the gizmo's is attached to
  109. */
  110. get attachedNode(): Nullable<Node>;
  111. /**
  112. * Additional transform node that will be used to transform all the gizmos
  113. */
  114. get additionalTransformNode(): TransformNode | undefined;
  115. /**
  116. * Instantiates a gizmo manager
  117. * @param _scene the scene to overlay the gizmos on top of
  118. * @param thickness display gizmo axis thickness
  119. * @param utilityLayer the layer where gizmos are rendered
  120. * @param keepDepthUtilityLayer the layer where occluded gizmos are rendered
  121. */
  122. constructor(_scene: Scene, thickness?: number, utilityLayer?: UtilityLayerRenderer, keepDepthUtilityLayer?: UtilityLayerRenderer);
  123. /**
  124. * @internal
  125. * Subscribes to pointer down events, for attaching and detaching mesh
  126. * @param scene The scene layer the observer will be added to
  127. * @returns the pointer observer
  128. */
  129. private _attachToMeshPointerObserver;
  130. /**
  131. * Attaches a set of gizmos to the specified mesh
  132. * @param mesh The mesh the gizmo's should be attached to
  133. */
  134. attachToMesh(mesh: Nullable<AbstractMesh>): void;
  135. /**
  136. * Attaches a set of gizmos to the specified node
  137. * @param node The node the gizmo's should be attached to
  138. */
  139. attachToNode(node: Nullable<Node>): void;
  140. /**
  141. * If the position gizmo is enabled
  142. */
  143. set positionGizmoEnabled(value: boolean);
  144. get positionGizmoEnabled(): boolean;
  145. /**
  146. * If the rotation gizmo is enabled
  147. */
  148. set rotationGizmoEnabled(value: boolean);
  149. get rotationGizmoEnabled(): boolean;
  150. /**
  151. * If the scale gizmo is enabled
  152. */
  153. set scaleGizmoEnabled(value: boolean);
  154. get scaleGizmoEnabled(): boolean;
  155. /**
  156. * If the boundingBox gizmo is enabled
  157. */
  158. set boundingBoxGizmoEnabled(value: boolean);
  159. get boundingBoxGizmoEnabled(): boolean;
  160. /**
  161. * Sets the additional transform applied to all the gizmos.
  162. * @See Gizmo.additionalTransformNode for more detail
  163. */
  164. set additionalTransformNode(node: TransformNode | undefined);
  165. private _setAdditionalTransformNode;
  166. /**
  167. * Builds Gizmo Axis Cache to enable features such as hover state preservation and graying out other axis during manipulation
  168. * @param gizmoAxisCache Gizmo axis definition used for reactive gizmo UI
  169. */
  170. addToAxisCache(gizmoAxisCache: Map<Mesh, GizmoAxisCache>): void;
  171. /**
  172. * Force release the drag action by code
  173. */
  174. releaseDrag(): void;
  175. /**
  176. * Disposes of the gizmo manager
  177. */
  178. dispose(): void;
  179. }