boundingBoxGizmo.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 } from "../scene";
  6. import { Vector3 } from "../Maths/math.vector";
  7. import { AbstractMesh } from "../Meshes/abstractMesh";
  8. import type { Mesh } from "../Meshes/mesh";
  9. import { PointerDragBehavior } from "../Behaviors/Meshes/pointerDragBehavior";
  10. import type { IGizmo } from "./gizmo";
  11. import { Gizmo } from "./gizmo";
  12. import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
  13. import { StandardMaterial } from "../Materials/standardMaterial";
  14. import { Color3 } from "../Maths/math.color";
  15. /**
  16. * Interface for bounding box gizmo
  17. */
  18. export interface IBoundingBoxGizmo extends IGizmo {
  19. /**
  20. * If child meshes should be ignored when calculating the bounding box. This should be set to true to avoid perf hits with heavily nested meshes.
  21. */
  22. ignoreChildren: boolean;
  23. /**
  24. * Returns true if a descendant should be included when computing the bounding box. When null, all descendants are included. If ignoreChildren is set this will be ignored.
  25. */
  26. includeChildPredicate: Nullable<(abstractMesh: AbstractMesh) => boolean>;
  27. /** The size of the rotation spheres attached to the bounding box */
  28. rotationSphereSize: number;
  29. /** The size of the scale boxes attached to the bounding box */
  30. scaleBoxSize: number;
  31. /**
  32. * If set, the rotation spheres and scale boxes will increase in size based on the distance away from the camera to have a consistent screen size
  33. * Note : fixedDragMeshScreenSize takes precedence over fixedDragMeshBoundsSize if both are true
  34. */
  35. fixedDragMeshScreenSize: boolean;
  36. /**
  37. * If set, the rotation spheres and scale boxes will increase in size based on the size of the bounding box
  38. * Note : fixedDragMeshScreenSize takes precedence over fixedDragMeshBoundsSize if both are true
  39. */
  40. fixedDragMeshBoundsSize: boolean;
  41. /**
  42. * The distance away from the object which the draggable meshes should appear world sized when fixedDragMeshScreenSize is set to true
  43. */
  44. fixedDragMeshScreenSizeDistanceFactor: number;
  45. /** True when a rotation sphere or scale box or a attached mesh is dragged */
  46. readonly isDragging: boolean;
  47. /** Fired when a rotation sphere or scale box is dragged */
  48. onDragStartObservable: Observable<{}>;
  49. /** Fired when a scale box is dragged */
  50. onScaleBoxDragObservable: Observable<{}>;
  51. /** Fired when a scale box drag is ended */
  52. onScaleBoxDragEndObservable: Observable<{}>;
  53. /** Fired when a rotation sphere is dragged */
  54. onRotationSphereDragObservable: Observable<{}>;
  55. /** Fired when a rotation sphere drag is ended */
  56. onRotationSphereDragEndObservable: Observable<{}>;
  57. /** Relative bounding box pivot used when scaling the attached node. */
  58. scalePivot: Nullable<Vector3>;
  59. /** Scale factor vector used for masking some axis */
  60. axisFactor: Vector3;
  61. /** Scale factor scalar affecting all axes' drag speed */
  62. scaleDragSpeed: number;
  63. /**
  64. * Sets the color of the bounding box gizmo
  65. * @param color the color to set
  66. */
  67. setColor(color: Color3): void;
  68. /** Returns an array containing all boxes used for scaling (in increasing x, y and z orders) */
  69. getScaleBoxes(): AbstractMesh[];
  70. /** Updates the bounding box information for the Gizmo */
  71. updateBoundingBox(): void;
  72. /**
  73. * Enables rotation on the specified axis and disables rotation on the others
  74. * @param axis The list of axis that should be enabled (eg. "xy" or "xyz")
  75. */
  76. setEnabledRotationAxis(axis: string): void;
  77. /**
  78. * Enables/disables scaling
  79. * @param enable if scaling should be enabled
  80. * @param homogeneousScaling defines if scaling should only be homogeneous
  81. */
  82. setEnabledScaling(enable: boolean, homogeneousScaling?: boolean): void;
  83. /** Enables a pointer drag behavior on the bounding box of the gizmo */
  84. enableDragBehavior(): void;
  85. /**
  86. * Force release the drag action by code
  87. */
  88. releaseDrag(): void;
  89. /** Default material used to render when gizmo is not disabled or hovered */
  90. coloredMaterial: StandardMaterial;
  91. /** Material used to render when gizmo is hovered with mouse*/
  92. hoverMaterial: StandardMaterial;
  93. /** Drag distance in babylon units that the gizmo will snap scaling to when dragged */
  94. scalingSnapDistance: number;
  95. /** Drag distance in babylon units that the gizmo will snap rotation to when dragged */
  96. rotationSnapDistance: number;
  97. }
  98. /**
  99. * Bounding box gizmo
  100. */
  101. export declare class BoundingBoxGizmo extends Gizmo implements IBoundingBoxGizmo {
  102. protected _lineBoundingBox: AbstractMesh;
  103. protected _rotateSpheresParent: AbstractMesh;
  104. protected _scaleBoxesParent: AbstractMesh;
  105. protected _boundingDimensions: Vector3;
  106. protected _renderObserver: Nullable<Observer<Scene>>;
  107. protected _pointerObserver: Nullable<Observer<PointerInfo>>;
  108. protected _scaleDragSpeed: number;
  109. protected _rotateSpheresDragBehaviors: Array<PointerDragBehavior>;
  110. protected _scaleBoxesDragBehaviors: Array<PointerDragBehavior>;
  111. /**
  112. * boolean updated when a rotation sphere or scale box is dragged
  113. */
  114. protected _dragging: boolean;
  115. private _tmpQuaternion;
  116. private _tmpVector;
  117. private _tmpRotationMatrix;
  118. private _incrementalStartupValue;
  119. private _incrementalAnchorStartupValue;
  120. /**
  121. * If child meshes should be ignored when calculating the bounding box. This should be set to true to avoid perf hits with heavily nested meshes (Default: false)
  122. */
  123. ignoreChildren: boolean;
  124. /**
  125. * Returns true if a descendant should be included when computing the bounding box. When null, all descendants are included. If ignoreChildren is set this will be ignored. (Default: null)
  126. */
  127. includeChildPredicate: Nullable<(abstractMesh: AbstractMesh) => boolean>;
  128. /**
  129. * The size of the rotation spheres attached to the bounding box (Default: 0.1)
  130. */
  131. rotationSphereSize: number;
  132. /**
  133. * The size of the scale boxes attached to the bounding box (Default: 0.1)
  134. */
  135. scaleBoxSize: number;
  136. /**
  137. * If set, the rotation spheres and scale boxes will increase in size based on the distance away from the camera to have a consistent screen size (Default: false)
  138. * Note : fixedDragMeshScreenSize takes precedence over fixedDragMeshBoundsSize if both are true
  139. */
  140. fixedDragMeshScreenSize: boolean;
  141. /**
  142. * If set, the rotation spheres and scale boxes will increase in size based on the size of the bounding box
  143. * Note : fixedDragMeshScreenSize takes precedence over fixedDragMeshBoundsSize if both are true
  144. */
  145. fixedDragMeshBoundsSize: boolean;
  146. /**
  147. * The distance away from the object which the draggable meshes should appear world sized when fixedDragMeshScreenSize is set to true (default: 10)
  148. */
  149. fixedDragMeshScreenSizeDistanceFactor: number;
  150. /**
  151. * Drag distance in babylon units that the gizmo will snap scaling to when dragged
  152. */
  153. scalingSnapDistance: number;
  154. /**
  155. * Drag distance in babylon units that the gizmo will snap rotation to when dragged
  156. */
  157. rotationSnapDistance: number;
  158. /**
  159. * Fired when a rotation sphere or scale box is dragged
  160. */
  161. onDragStartObservable: Observable<{}>;
  162. /**
  163. * Fired when a scale box is dragged
  164. */
  165. onScaleBoxDragObservable: Observable<{}>;
  166. /**
  167. * Fired when a scale box drag is ended
  168. */
  169. onScaleBoxDragEndObservable: Observable<{}>;
  170. /**
  171. * Fired when a rotation sphere is dragged
  172. */
  173. onRotationSphereDragObservable: Observable<{}>;
  174. /**
  175. * Fired when a rotation sphere drag is ended
  176. */
  177. onRotationSphereDragEndObservable: Observable<{}>;
  178. /**
  179. * Relative bounding box pivot used when scaling the attached node. When null object with scale from the opposite corner. 0.5,0.5,0.5 for center and 0.5,0,0.5 for bottom (Default: null)
  180. */
  181. scalePivot: Nullable<Vector3>;
  182. /**
  183. * Scale factor used for masking some axis
  184. */
  185. protected _axisFactor: Vector3;
  186. /**
  187. * 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,...
  188. */
  189. incrementalSnap: boolean;
  190. /**
  191. * Sets the axis factor
  192. * @param factor the Vector3 value
  193. */
  194. set axisFactor(factor: Vector3);
  195. /**
  196. * Gets the axis factor
  197. * @returns the Vector3 factor value
  198. */
  199. get axisFactor(): Vector3;
  200. /**
  201. * Sets scale drag speed value
  202. * @param value the new speed value
  203. */
  204. set scaleDragSpeed(value: number);
  205. /**
  206. * Gets scale drag speed
  207. * @returns the scale speed number
  208. */
  209. get scaleDragSpeed(): number;
  210. /**
  211. * Mesh used as a pivot to rotate the attached node
  212. */
  213. protected _anchorMesh: AbstractMesh;
  214. protected _existingMeshScale: Vector3;
  215. protected _dragMesh: Nullable<Mesh>;
  216. protected _pointerDragBehavior: PointerDragBehavior;
  217. protected _coloredMaterial: StandardMaterial;
  218. protected _hoverColoredMaterial: StandardMaterial;
  219. /** Default material used to render when gizmo is not disabled or hovered */
  220. get coloredMaterial(): StandardMaterial;
  221. /** Material used to render when gizmo is hovered with mouse*/
  222. get hoverMaterial(): StandardMaterial;
  223. /**
  224. * Get the pointerDragBehavior
  225. */
  226. get pointerDragBehavior(): PointerDragBehavior;
  227. /** True when a rotation sphere or scale box or a attached mesh is dragged */
  228. get isDragging(): boolean;
  229. /**
  230. * Sets the color of the bounding box gizmo
  231. * @param color the color to set
  232. */
  233. setColor(color: Color3): void;
  234. /**
  235. * Creates an BoundingBoxGizmo
  236. * @param color The color of the gizmo
  237. * @param gizmoLayer The utility layer the gizmo will be added to
  238. */
  239. constructor(color?: Color3, gizmoLayer?: UtilityLayerRenderer);
  240. protected _attachedNodeChanged(value: Nullable<AbstractMesh>): void;
  241. protected _selectNode(selectedMesh: Nullable<Mesh>): void;
  242. protected _unhoverMeshOnTouchUp(pointerInfo: Nullable<PointerInfo>, selectedMesh: AbstractMesh): void;
  243. /**
  244. * returns an array containing all boxes used for scaling (in increasing x, y and z orders)
  245. * @returns array of scaling boxes
  246. */
  247. getScaleBoxes(): AbstractMesh[];
  248. /**
  249. * Updates the bounding box information for the Gizmo
  250. */
  251. updateBoundingBox(): void;
  252. protected _updateRotationSpheres(): void;
  253. protected _updateScaleBoxes(): void;
  254. /**
  255. * Enables rotation on the specified axis and disables rotation on the others
  256. * @param axis The list of axis that should be enabled (eg. "xy" or "xyz")
  257. */
  258. setEnabledRotationAxis(axis: string): void;
  259. /**
  260. * Enables/disables scaling
  261. * @param enable if scaling should be enabled
  262. * @param homogeneousScaling defines if scaling should only be homogeneous
  263. */
  264. setEnabledScaling(enable: boolean, homogeneousScaling?: boolean): void;
  265. protected _updateDummy(): void;
  266. /**
  267. * Enables a pointer drag behavior on the bounding box of the gizmo
  268. */
  269. enableDragBehavior(): void;
  270. /**
  271. * Force release the drag action by code
  272. */
  273. releaseDrag(): void;
  274. /**
  275. * Disposes of the gizmo
  276. */
  277. dispose(): void;
  278. /**
  279. * Makes a mesh not pickable and wraps the mesh inside of a bounding box mesh that is pickable. (This is useful to avoid picking within complex geometry)
  280. * @param mesh the mesh to wrap in the bounding box mesh and make not pickable
  281. * @returns the bounding box mesh with the passed in mesh as a child
  282. */
  283. static MakeNotPickableAndWrapInBoundingBox(mesh: Mesh): Mesh;
  284. /**
  285. * CustomMeshes are not supported by this gizmo
  286. */
  287. setCustomMesh(): void;
  288. }