threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ICamera.ts 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {Camera, Vector3} from 'three'
  2. import {IObject3D, IObject3DEvent, IObject3DEventTypes, IObject3DUserData, IObjectSetDirtyOptions} from './IObject'
  3. import {IShaderPropertiesUpdater} from '../materials'
  4. import {ICameraControls, TControlsCtor} from './camera/ICameraControls'
  5. import {CameraView, ICameraView} from './camera/CameraView'
  6. /**
  7. * Available modes for {@link ICamera.controlsMode} property.
  8. * This is defined just for autocomplete, these and any other control type can be added by plugins
  9. */
  10. export type TCameraControlsMode = '' | 'orbit' | 'deviceOrientation' | 'firstPerson' | 'pointerLock' | string
  11. export interface ICameraUserData extends IObject3DUserData {
  12. autoNearFar?: boolean // default = true
  13. minNearPlane?: number // default = 0.2
  14. maxFarPlane?: number // default = 1000
  15. autoLookAtTarget?: boolean // default = false, only for when controls and interactions are disabled
  16. __lastScale?: Vector3,
  17. __isMainCamera?: boolean,
  18. __cameraSetup?: boolean,
  19. // [key: string]: any // commented for noe
  20. }
  21. export interface ICamera<E extends ICameraEvent = ICameraEvent, ET extends ICameraEventTypes = ICameraEventTypes> extends Camera<E, ET>, IObject3D<E, ET>, IShaderPropertiesUpdater {
  22. assetType: 'camera'
  23. readonly isCamera: true
  24. setDirty(options?: ICameraSetDirtyOptions): void;
  25. readonly isMainCamera: boolean;
  26. readonly isPerspectiveCamera?: boolean;
  27. readonly isOrthographicCamera?: boolean;
  28. activateMain(options?: Partial<ICameraEvent>, _internal?: boolean, _refresh?: boolean): void;
  29. deactivateMain(options?: Partial<ICameraEvent>, _internal?: boolean, _refresh?: boolean): void;
  30. /**
  31. * @deprecated use `this` instead
  32. */
  33. cameraObject: this
  34. readonly controls: ICameraControls|undefined;
  35. // getControls<T extends TControls>(): T|undefined;
  36. refreshTarget(): void;
  37. refreshAspect(setDirty?: boolean): void;
  38. /**
  39. * Target of camera, in world(global) coordinates.
  40. */
  41. target: Vector3,
  42. /**
  43. * Local position of camera.
  44. */
  45. position: Vector3,
  46. readonly interactionsEnabled: boolean;
  47. setInteractions(enabled: boolean, by: string): void;
  48. /**
  49. * Check whether user can interact with this camera.
  50. * Interactions can be enabled/disabled in a variety of ways,
  51. * like {@link setInteractions}, {@link controlsMode}, {@link isMainCamera} property
  52. */
  53. readonly canUserInteract: boolean;
  54. zoom: number;
  55. /**
  56. * Camera frustum aspect ratio, window width divided by window height.
  57. * It can be managed internally if {@link autoAspect} is true.
  58. * @default 1
  59. */
  60. aspect: number;
  61. /**
  62. * Automatically manage aspect ratio based on window/canvas size.
  63. */
  64. autoAspect: boolean;
  65. controlsMode?: TCameraControlsMode; // todo add more.
  66. // controlsEnabled: boolean; // use controlsMode = '' instead
  67. /**
  68. * Automatically managed when {@link autoNearFar} is `true`. See also {@link minNearPlane}
  69. */
  70. near: number;
  71. /**
  72. * Automatically managed when {@link autoNearFar} is `true`. See also {@link maxFarPlane}
  73. */
  74. far: number;
  75. // also in userData
  76. autoNearFar: boolean // default = true
  77. minNearPlane: number // default = 0.2
  78. maxFarPlane: number // default = 1000
  79. // todo
  80. // Note: for userData: add _ in front of for private use, which is preserved while cloning but not serialisation, and __ for private use, which is not preserved while cloning and serialisation
  81. userData: ICameraUserData
  82. /**
  83. * @deprecated use {@link isMainCamera} instead
  84. */
  85. isActiveCamera: boolean;
  86. setControlsCtor(key: string, ctor: TControlsCtor, replace?: boolean): void;
  87. removeControlsCtor(key: string): void;
  88. refreshCameraControls(setDirty?: boolean): void
  89. updateProjectionMatrix(): void
  90. fov?: number
  91. getView<T extends ICameraView = CameraView>(worldSpace?: boolean, cameraView?: T): T
  92. setView(view: ICameraView): void
  93. /**
  94. * Set camera view from another camera.
  95. * @param camera
  96. * @param distanceFromTarget - default = 4
  97. * @param worldSpace - default = true
  98. */
  99. setViewFromCamera(camera: ICamera|Camera, distanceFromTarget?: number, worldSpace?: boolean): void
  100. /**
  101. * Dispatches the `setView` event which triggers the main camera to set its view to this camera's view.
  102. * @param eventOptions
  103. */
  104. setViewToMain(eventOptions: Partial<ICameraEvent>): void
  105. // region inherited type fixes
  106. // re-declaring from IObject3D because: https://github.com/microsoft/TypeScript/issues/16936
  107. traverse(callback: (object: IObject3D) => void): void
  108. traverseVisible(callback: (object: IObject3D) => void): void
  109. traverseAncestors(callback: (object: IObject3D) => void): void
  110. getObjectById<T extends IObject3D = IObject3D>(id: number): T | undefined
  111. getObjectByName<T extends IObject3D = IObject3D>(name: string): T | undefined
  112. getObjectByProperty<T extends IObject3D = IObject3D>(name: string, value: string): T | undefined
  113. copy(source: this, recursive?: boolean, distanceFromTarget?: number, worldSpace?: boolean, ...args: any[]): this
  114. clone(recursive?: boolean): this
  115. add(...object: IObject3D[]): this
  116. remove(...object: IObject3D[]): this
  117. parent: IObject3D | null
  118. children: IObject3D[]
  119. // endregion
  120. }
  121. export type ICameraEventTypes = IObject3DEventTypes | 'update'// | string
  122. export type ICameraEvent = Omit<IObject3DEvent, 'type'> & {
  123. type: ICameraEventTypes
  124. camera?: ICamera | null
  125. // change?: string
  126. }
  127. export type ICameraSetDirtyOptions = IObjectSetDirtyOptions