arcRotateCamera.d.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import { Observable } from "../Misc/observable";
  2. import type { Nullable } from "../types";
  3. import type { Scene } from "../scene";
  4. import { Matrix, Vector3, Vector2 } from "../Maths/math.vector";
  5. import type { AbstractMesh } from "../Meshes/abstractMesh";
  6. import { AutoRotationBehavior } from "../Behaviors/Cameras/autoRotationBehavior";
  7. import { BouncingBehavior } from "../Behaviors/Cameras/bouncingBehavior";
  8. import { FramingBehavior } from "../Behaviors/Cameras/framingBehavior";
  9. import { Camera } from "./camera";
  10. import { TargetCamera } from "./targetCamera";
  11. import { ArcRotateCameraInputsManager } from "../Cameras/arcRotateCameraInputsManager";
  12. import type { Collider } from "../Collisions/collider";
  13. import type { TransformNode } from "../Meshes/transformNode.js";
  14. /**
  15. * This represents an orbital type of camera.
  16. *
  17. * This camera always points towards a given target position and can be rotated around that target with the target as the centre of rotation. It can be controlled with cursors and mouse, or with touch events.
  18. * Think of this camera as one orbiting its target position, or more imaginatively as a spy satellite orbiting the earth. Its position relative to the target (earth) can be set by three parameters, alpha (radians) the longitudinal rotation, beta (radians) the latitudinal rotation and radius the distance from the target position.
  19. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#arc-rotate-camera
  20. */
  21. export declare class ArcRotateCamera extends TargetCamera {
  22. /**
  23. * Defines the rotation angle of the camera along the longitudinal axis.
  24. */
  25. alpha: number;
  26. /**
  27. * Defines the rotation angle of the camera along the latitudinal axis.
  28. */
  29. beta: number;
  30. /**
  31. * Defines the radius of the camera from it s target point.
  32. */
  33. radius: number;
  34. /**
  35. * Defines an override value to use as the parameter to setTarget.
  36. * This allows the parameter to be specified when animating the target (e.g. using FramingBehavior).
  37. */
  38. overrideCloneAlphaBetaRadius: Nullable<boolean>;
  39. protected _target: Vector3;
  40. protected _targetHost: Nullable<TransformNode>;
  41. /**
  42. * Defines the target point of the camera.
  43. * The camera looks towards it from the radius distance.
  44. */
  45. get target(): Vector3;
  46. set target(value: Vector3);
  47. /**
  48. * Defines the target transform node of the camera.
  49. * The camera looks towards it from the radius distance.
  50. * Please note that setting a target host will disable panning.
  51. */
  52. get targetHost(): Nullable<TransformNode>;
  53. set targetHost(value: Nullable<TransformNode>);
  54. /**
  55. * Return the current target position of the camera. This value is expressed in local space.
  56. * @returns the target position
  57. */
  58. getTarget(): Vector3;
  59. /**
  60. * Define the current local position of the camera in the scene
  61. */
  62. get position(): Vector3;
  63. set position(newPosition: Vector3);
  64. protected _upToYMatrix: Matrix;
  65. protected _yToUpMatrix: Matrix;
  66. /**
  67. * The vector the camera should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up())
  68. * Setting this will copy the given vector to the camera's upVector, and set rotation matrices to and from Y up.
  69. * DO NOT set the up vector using copyFrom or copyFromFloats, as this bypasses setting the above matrices.
  70. */
  71. set upVector(vec: Vector3);
  72. get upVector(): Vector3;
  73. /**
  74. * Sets the Y-up to camera up-vector rotation matrix, and the up-vector to Y-up rotation matrix.
  75. */
  76. setMatUp(): void;
  77. /**
  78. * Current inertia value on the longitudinal axis.
  79. * The bigger this number the longer it will take for the camera to stop.
  80. */
  81. inertialAlphaOffset: number;
  82. /**
  83. * Current inertia value on the latitudinal axis.
  84. * The bigger this number the longer it will take for the camera to stop.
  85. */
  86. inertialBetaOffset: number;
  87. /**
  88. * Current inertia value on the radius axis.
  89. * The bigger this number the longer it will take for the camera to stop.
  90. */
  91. inertialRadiusOffset: number;
  92. /**
  93. * Minimum allowed angle on the longitudinal axis.
  94. * This can help limiting how the Camera is able to move in the scene.
  95. */
  96. lowerAlphaLimit: Nullable<number>;
  97. /**
  98. * Maximum allowed angle on the longitudinal axis.
  99. * This can help limiting how the Camera is able to move in the scene.
  100. */
  101. upperAlphaLimit: Nullable<number>;
  102. /**
  103. * Minimum allowed angle on the latitudinal axis.
  104. * This can help limiting how the Camera is able to move in the scene.
  105. */
  106. lowerBetaLimit: Nullable<number>;
  107. /**
  108. * Maximum allowed angle on the latitudinal axis.
  109. * This can help limiting how the Camera is able to move in the scene.
  110. */
  111. upperBetaLimit: Nullable<number>;
  112. /**
  113. * Minimum allowed distance of the camera to the target (The camera can not get closer).
  114. * This can help limiting how the Camera is able to move in the scene.
  115. */
  116. lowerRadiusLimit: Nullable<number>;
  117. /**
  118. * Maximum allowed distance of the camera to the target (The camera can not get further).
  119. * This can help limiting how the Camera is able to move in the scene.
  120. */
  121. upperRadiusLimit: Nullable<number>;
  122. /**
  123. * Defines the current inertia value used during panning of the camera along the X axis.
  124. */
  125. inertialPanningX: number;
  126. /**
  127. * Defines the current inertia value used during panning of the camera along the Y axis.
  128. */
  129. inertialPanningY: number;
  130. /**
  131. * Defines the distance used to consider the camera in pan mode vs pinch/zoom.
  132. * Basically if your fingers moves away from more than this distance you will be considered
  133. * in pinch mode.
  134. */
  135. pinchToPanMaxDistance: number;
  136. /**
  137. * Defines the maximum distance the camera can pan.
  138. * This could help keeping the camera always in your scene.
  139. */
  140. panningDistanceLimit: Nullable<number>;
  141. /**
  142. * Defines the target of the camera before panning.
  143. */
  144. panningOriginTarget: Vector3;
  145. /**
  146. * Defines the value of the inertia used during panning.
  147. * 0 would mean stop inertia and one would mean no deceleration at all.
  148. */
  149. panningInertia: number;
  150. /**
  151. * Gets or Set the pointer angular sensibility along the X axis or how fast is the camera rotating.
  152. */
  153. get angularSensibilityX(): number;
  154. set angularSensibilityX(value: number);
  155. /**
  156. * Gets or Set the pointer angular sensibility along the Y axis or how fast is the camera rotating.
  157. */
  158. get angularSensibilityY(): number;
  159. set angularSensibilityY(value: number);
  160. /**
  161. * Gets or Set the pointer pinch precision or how fast is the camera zooming.
  162. */
  163. get pinchPrecision(): number;
  164. set pinchPrecision(value: number);
  165. /**
  166. * Gets or Set the pointer pinch delta percentage or how fast is the camera zooming.
  167. * It will be used instead of pinchPrecision if different from 0.
  168. * It defines the percentage of current camera.radius to use as delta when pinch zoom is used.
  169. */
  170. get pinchDeltaPercentage(): number;
  171. set pinchDeltaPercentage(value: number);
  172. /**
  173. * Gets or Set the pointer use natural pinch zoom to override the pinch precision
  174. * and pinch delta percentage.
  175. * When useNaturalPinchZoom is true, multi touch zoom will zoom in such
  176. * that any object in the plane at the camera's target point will scale
  177. * perfectly with finger motion.
  178. */
  179. get useNaturalPinchZoom(): boolean;
  180. set useNaturalPinchZoom(value: boolean);
  181. /**
  182. * Gets or Set the pointer panning sensibility or how fast is the camera moving.
  183. */
  184. get panningSensibility(): number;
  185. set panningSensibility(value: number);
  186. /**
  187. * Gets or Set the list of keyboard keys used to control beta angle in a positive direction.
  188. */
  189. get keysUp(): number[];
  190. set keysUp(value: number[]);
  191. /**
  192. * Gets or Set the list of keyboard keys used to control beta angle in a negative direction.
  193. */
  194. get keysDown(): number[];
  195. set keysDown(value: number[]);
  196. /**
  197. * Gets or Set the list of keyboard keys used to control alpha angle in a negative direction.
  198. */
  199. get keysLeft(): number[];
  200. set keysLeft(value: number[]);
  201. /**
  202. * Gets or Set the list of keyboard keys used to control alpha angle in a positive direction.
  203. */
  204. get keysRight(): number[];
  205. set keysRight(value: number[]);
  206. /**
  207. * Gets or Set the mouse wheel precision or how fast is the camera zooming.
  208. */
  209. get wheelPrecision(): number;
  210. set wheelPrecision(value: number);
  211. /**
  212. * Gets or Set the boolean value that controls whether or not the mouse wheel
  213. * zooms to the location of the mouse pointer or not. The default is false.
  214. */
  215. get zoomToMouseLocation(): boolean;
  216. set zoomToMouseLocation(value: boolean);
  217. /**
  218. * Gets or Set the mouse wheel delta percentage or how fast is the camera zooming.
  219. * It will be used instead of wheelPrecision if different from 0.
  220. * It defines the percentage of current camera.radius to use as delta when wheel zoom is used.
  221. */
  222. get wheelDeltaPercentage(): number;
  223. set wheelDeltaPercentage(value: number);
  224. /**
  225. * Defines how much the radius should be scaled while zooming on a particular mesh (through the zoomOn function)
  226. */
  227. zoomOnFactor: number;
  228. /**
  229. * Defines a screen offset for the camera position.
  230. */
  231. targetScreenOffset: Vector2;
  232. /**
  233. * Allows the camera to be completely reversed.
  234. * If false the camera can not arrive upside down.
  235. */
  236. allowUpsideDown: boolean;
  237. /**
  238. * Define if double tap/click is used to restore the previously saved state of the camera.
  239. */
  240. useInputToRestoreState: boolean;
  241. /** @internal */
  242. _viewMatrix: Matrix;
  243. /** @internal */
  244. _useCtrlForPanning: boolean;
  245. /** @internal */
  246. _panningMouseButton: number;
  247. /**
  248. * Defines the input associated to the camera.
  249. */
  250. inputs: ArcRotateCameraInputsManager;
  251. /** @internal */
  252. _reset: () => void;
  253. /**
  254. * Defines the allowed panning axis.
  255. */
  256. panningAxis: Vector3;
  257. protected _transformedDirection: Vector3;
  258. /**
  259. * Defines if camera will eliminate transform on y axis.
  260. */
  261. mapPanning: boolean;
  262. private _bouncingBehavior;
  263. /**
  264. * Gets the bouncing behavior of the camera if it has been enabled.
  265. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior
  266. */
  267. get bouncingBehavior(): Nullable<BouncingBehavior>;
  268. /**
  269. * Defines if the bouncing behavior of the camera is enabled on the camera.
  270. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#bouncing-behavior
  271. */
  272. get useBouncingBehavior(): boolean;
  273. set useBouncingBehavior(value: boolean);
  274. private _framingBehavior;
  275. /**
  276. * Gets the framing behavior of the camera if it has been enabled.
  277. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior
  278. */
  279. get framingBehavior(): Nullable<FramingBehavior>;
  280. /**
  281. * Defines if the framing behavior of the camera is enabled on the camera.
  282. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#framing-behavior
  283. */
  284. get useFramingBehavior(): boolean;
  285. set useFramingBehavior(value: boolean);
  286. private _autoRotationBehavior;
  287. /**
  288. * Gets the auto rotation behavior of the camera if it has been enabled.
  289. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior
  290. */
  291. get autoRotationBehavior(): Nullable<AutoRotationBehavior>;
  292. /**
  293. * Defines if the auto rotation behavior of the camera is enabled on the camera.
  294. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors/cameraBehaviors#autorotation-behavior
  295. */
  296. get useAutoRotationBehavior(): boolean;
  297. set useAutoRotationBehavior(value: boolean);
  298. /**
  299. * Observable triggered when the transform node target has been changed on the camera.
  300. */
  301. onMeshTargetChangedObservable: Observable<Nullable<TransformNode>>;
  302. /**
  303. * Event raised when the camera is colliding with a mesh.
  304. */
  305. onCollide: (collidedMesh: AbstractMesh) => void;
  306. /**
  307. * Defines whether the camera should check collision with the objects oh the scene.
  308. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#how-can-i-do-this-
  309. */
  310. checkCollisions: boolean;
  311. /**
  312. * Defines the collision radius of the camera.
  313. * This simulates a sphere around the camera.
  314. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#arcrotatecamera
  315. */
  316. collisionRadius: Vector3;
  317. protected _collider: Collider;
  318. protected _previousPosition: Vector3;
  319. protected _collisionVelocity: Vector3;
  320. protected _newPosition: Vector3;
  321. protected _previousAlpha: number;
  322. protected _previousBeta: number;
  323. protected _previousRadius: number;
  324. protected _collisionTriggered: boolean;
  325. protected _targetBoundingCenter: Nullable<Vector3>;
  326. private _computationVector;
  327. /**
  328. * Instantiates a new ArcRotateCamera in a given scene
  329. * @param name Defines the name of the camera
  330. * @param alpha Defines the camera rotation along the longitudinal axis
  331. * @param beta Defines the camera rotation along the latitudinal axis
  332. * @param radius Defines the camera distance from its target
  333. * @param target Defines the camera target
  334. * @param scene Defines the scene the camera belongs to
  335. * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active if not other active cameras have been defined
  336. */
  337. constructor(name: string, alpha: number, beta: number, radius: number, target: Vector3, scene?: Scene, setActiveOnSceneIfNoneActive?: boolean);
  338. /** @internal */
  339. _initCache(): void;
  340. /**
  341. * @internal
  342. */
  343. _updateCache(ignoreParentClass?: boolean): void;
  344. protected _getTargetPosition(): Vector3;
  345. private _storedAlpha;
  346. private _storedBeta;
  347. private _storedRadius;
  348. private _storedTarget;
  349. private _storedTargetScreenOffset;
  350. /**
  351. * Stores the current state of the camera (alpha, beta, radius and target)
  352. * @returns the camera itself
  353. */
  354. storeState(): Camera;
  355. /**
  356. * @internal
  357. * Restored camera state. You must call storeState() first
  358. */
  359. _restoreStateValues(): boolean;
  360. /** @internal */
  361. _isSynchronizedViewMatrix(): boolean;
  362. /**
  363. * Attach the input controls to a specific dom element to get the input from.
  364. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  365. */
  366. attachControl(noPreventDefault?: boolean): void;
  367. /**
  368. * Attach the input controls to a specific dom element to get the input from.
  369. * @param ignored defines an ignored parameter kept for backward compatibility.
  370. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  371. */
  372. attachControl(ignored: any, noPreventDefault?: boolean): void;
  373. /**
  374. * Attached controls to the current camera.
  375. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  376. * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls
  377. */
  378. attachControl(noPreventDefault: boolean, useCtrlForPanning: boolean): void;
  379. /**
  380. * Attached controls to the current camera.
  381. * @param ignored defines an ignored parameter kept for backward compatibility.
  382. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  383. * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls
  384. */
  385. attachControl(ignored: any, noPreventDefault: boolean, useCtrlForPanning: boolean): void;
  386. /**
  387. * Attached controls to the current camera.
  388. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  389. * @param useCtrlForPanning Defines whether ctrl is used for panning within the controls
  390. * @param panningMouseButton Defines whether panning is allowed through mouse click button
  391. */
  392. attachControl(noPreventDefault: boolean, useCtrlForPanning: boolean, panningMouseButton: number): void;
  393. /**
  394. * Detach the current controls from the specified dom element.
  395. */
  396. detachControl(): void;
  397. /** @internal */
  398. _checkInputs(): void;
  399. protected _checkLimits(): void;
  400. /**
  401. * Rebuilds angles (alpha, beta) and radius from the give position and target
  402. */
  403. rebuildAnglesAndRadius(): void;
  404. /**
  405. * Use a position to define the current camera related information like alpha, beta and radius
  406. * @param position Defines the position to set the camera at
  407. */
  408. setPosition(position: Vector3): void;
  409. /**
  410. * Defines the target the camera should look at.
  411. * This will automatically adapt alpha beta and radius to fit within the new target.
  412. * Please note that setting a target as a mesh will disable panning.
  413. * @param target Defines the new target as a Vector or a transform node
  414. * @param toBoundingCenter In case of a mesh target, defines whether to target the mesh position or its bounding information center
  415. * @param allowSamePosition If false, prevents reapplying the new computed position if it is identical to the current one (optim)
  416. * @param cloneAlphaBetaRadius If true, replicate the current setup (alpha, beta, radius) on the new target
  417. */
  418. setTarget(target: TransformNode | Vector3, toBoundingCenter?: boolean, allowSamePosition?: boolean, cloneAlphaBetaRadius?: boolean): void;
  419. /** @internal */
  420. _getViewMatrix(): Matrix;
  421. protected _onCollisionPositionChange: (collisionId: number, newPosition: Vector3, collidedMesh?: Nullable<AbstractMesh>) => void;
  422. /**
  423. * Zooms on a mesh to be at the min distance where we could see it fully in the current viewport.
  424. * @param meshes Defines the mesh to zoom on
  425. * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)
  426. */
  427. zoomOn(meshes?: AbstractMesh[], doNotUpdateMaxZ?: boolean): void;
  428. /**
  429. * Focus on a mesh or a bounding box. This adapts the target and maxRadius if necessary but does not update the current radius.
  430. * The target will be changed but the radius
  431. * @param meshesOrMinMaxVectorAndDistance Defines the mesh or bounding info to focus on
  432. * @param doNotUpdateMaxZ Defines whether or not maxZ should be updated whilst zooming on the mesh (this can happen if the mesh is big and the maxradius pretty small for instance)
  433. */
  434. focusOn(meshesOrMinMaxVectorAndDistance: AbstractMesh[] | {
  435. min: Vector3;
  436. max: Vector3;
  437. distance: number;
  438. }, doNotUpdateMaxZ?: boolean): void;
  439. /**
  440. * @override
  441. * Override Camera.createRigCamera
  442. * @param name the name of the camera
  443. * @param cameraIndex the index of the camera in the rig cameras array
  444. */
  445. createRigCamera(name: string, cameraIndex: number): Camera;
  446. /**
  447. * @internal
  448. * @override
  449. * Override Camera._updateRigCameras
  450. */
  451. _updateRigCameras(): void;
  452. /**
  453. * @internal
  454. */
  455. _calculateLowerRadiusFromModelBoundingSphere(minimumWorld: Vector3, maximumWorld: Vector3, radiusScale?: number): number;
  456. /**
  457. * Destroy the camera and release the current resources hold by it.
  458. */
  459. dispose(): void;
  460. /**
  461. * Gets the current object class name.
  462. * @returns the class name
  463. */
  464. getClassName(): string;
  465. }