threepipe
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ICamera.ts 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {Camera, Vector3} from 'three'
  2. import {IObject3D, IObject3DEventMap, 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' | 'threeFirstPerson' | 'pointerLock' | string
  11. export interface ICameraUserData extends IObject3DUserData {
  12. /**
  13. * Automatically calculate near and far planes based on the scene bounding box.
  14. */
  15. autoNearFar?: boolean
  16. /**
  17. * Minimum near plane distance. (when {@link autoNearFar} is true)
  18. * Or the near plane distance when {@link autoNearFar} is false.
  19. * @default 0.2
  20. */
  21. minNearPlane?: number
  22. /**
  23. * Maximum far plane distance. (when {@link autoNearFar} is true)
  24. * Or the far plane distance when {@link autoNearFar} is false.
  25. * @default 1000
  26. */
  27. maxFarPlane?: number
  28. /**
  29. * Automatically rotate camera to look at(lookAt) the target.
  30. * Only for when controls and interactions are disabled.
  31. * @default false
  32. */
  33. autoLookAtTarget?: boolean
  34. /**
  35. * Automatically move the camera(dolly) based on the scene size when the field of view(fov) changes.
  36. * Works when controls are enabled or autoLookAtTarget is true.
  37. *
  38. * Note - The camera must be added to RootScene for this to work
  39. */
  40. dollyFov?: boolean
  41. /**
  42. * Disable jitter for this camera. (for {@link SSAAPlugin})
  43. * @default false
  44. */
  45. disableJitter?: boolean
  46. __lastScale?: Vector3,
  47. __isMainCamera?: boolean,
  48. __cameraSetup?: boolean,
  49. // [key: string]: any // commented for noe
  50. }
  51. export interface ICamera<TE extends ICameraEventMap = ICameraEventMap> extends Camera<TE>, IObject3D<TE>, IShaderPropertiesUpdater {
  52. assetType: 'camera'
  53. readonly isCamera: true
  54. setDirty(options?: ICameraSetDirtyOptions): void;
  55. readonly isMainCamera: boolean;
  56. readonly isPerspectiveCamera?: boolean;
  57. readonly isOrthographicCamera?: boolean;
  58. activateMain(options?: Omit<ICameraEventMap['activateMain'], 'bubbleToParent'>, _internal?: boolean, _refresh?: boolean): void;
  59. deactivateMain(options?: Omit<ICameraEventMap['activateMain'], 'bubbleToParent'>, _internal?: boolean, _refresh?: boolean): void;
  60. /**
  61. * @deprecated use `this` instead
  62. */
  63. cameraObject: this
  64. readonly controls: ICameraControls|undefined;
  65. // getControls<T extends TControls>(): T|undefined;
  66. refreshTarget(): void;
  67. refreshAspect(setDirty?: boolean): void;
  68. /**
  69. * Target of camera, in world(global) coordinates.
  70. */
  71. target: Vector3,
  72. /**
  73. * Local position of camera.
  74. */
  75. position: Vector3,
  76. readonly interactionsEnabled: boolean;
  77. setInteractions(enabled: boolean, by: string, setDirty?: boolean): void;
  78. /**
  79. * Check whether user can interact with this camera.
  80. * Interactions can be enabled/disabled in a variety of ways,
  81. * like {@link setInteractions}, {@link controlsMode}, {@link isMainCamera} property
  82. */
  83. readonly canUserInteract: boolean;
  84. zoom: number;
  85. /**
  86. * Camera frustum aspect ratio, window width divided by window height.
  87. * It can be managed internally if {@link autoAspect} is true.
  88. * @default 1
  89. */
  90. aspect: number;
  91. /**
  92. * Automatically manage aspect ratio based on window/canvas size.
  93. */
  94. autoAspect: boolean;
  95. controlsMode?: TCameraControlsMode; // todo add more.
  96. // controlsEnabled: boolean; // use controlsMode = '' instead
  97. /**
  98. * Automatically managed when {@link autoNearFar} is `true`. See also {@link minNearPlane}
  99. */
  100. near: number;
  101. /**
  102. * Automatically managed when {@link autoNearFar} is `true`. See also {@link maxFarPlane}
  103. */
  104. far: number;
  105. // also in userData
  106. autoNearFar: boolean // default = true
  107. minNearPlane: number // default = 0.2
  108. maxFarPlane: number // default = 1000
  109. // todo
  110. // 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
  111. userData: ICameraUserData
  112. /**
  113. * @deprecated use {@link isMainCamera} instead
  114. */
  115. isActiveCamera: boolean;
  116. setControlsCtor(key: string, ctor: TControlsCtor, replace?: boolean): void;
  117. removeControlsCtor(key: string): void;
  118. refreshCameraControls(setDirty?: boolean): void
  119. updateProjectionMatrix(): void
  120. fov?: number
  121. getView<T extends ICameraView = CameraView>(worldSpace?: boolean, cameraView?: T): T
  122. setView(view: ICameraView): void
  123. /**
  124. * Set camera view from another camera.
  125. * @param camera
  126. * @param distanceFromTarget - default = 4
  127. * @param worldSpace - default = true
  128. */
  129. setViewFromCamera(camera: ICamera|Camera, distanceFromTarget?: number, worldSpace?: boolean): void
  130. /**
  131. * Dispatches the `setView` event which triggers the main camera to set its view to this camera's view.
  132. * @param eventOptions
  133. */
  134. setViewToMain(eventOptions: Pick<ICameraEventMap['setView'], 'ui'>): void
  135. /**
  136. * Set the canvas which is used as dom element in controls, etc.
  137. * This is done by the viewer/scene when main camera is changed
  138. * @param canvas
  139. * @param refresh
  140. */
  141. setCanvas(canvas: HTMLCanvasElement|undefined, refresh?: boolean): void; // todo make optional
  142. // region inherited type fixes
  143. // re-declaring from IObject3D because: https://github.com/microsoft/TypeScript/issues/16936
  144. traverse(callback: (object: IObject3D) => void): void
  145. traverseVisible(callback: (object: IObject3D) => void): void
  146. traverseAncestors(callback: (object: IObject3D) => void): void
  147. getObjectById<T extends IObject3D = IObject3D>(id: number): T | undefined
  148. getObjectByName<T extends IObject3D = IObject3D>(name: string): T | undefined
  149. getObjectByProperty<T extends IObject3D = IObject3D>(name: string, value: string): T | undefined
  150. copy(source: this, recursive?: boolean, distanceFromTarget?: number, worldSpace?: boolean, ...args: any[]): this
  151. clone(recursive?: boolean): this
  152. add(...object: IObject3D[]): this
  153. remove(...object: IObject3D[]): this
  154. parent: IObject3D | null
  155. children: IObject3D[]
  156. // endregion
  157. }
  158. // export type ICameraEventTypes = IObject3DEventTypes | 'update'// | string
  159. // export type ICameraEvent = Omit<IObject3DEvent, 'type'> & {
  160. // type: ICameraEventTypes
  161. // camera?: ICamera | null
  162. // // change?: string
  163. // }
  164. export type ICameraSetDirtyOptions = IObjectSetDirtyOptions
  165. export interface ICameraEventMap extends IObject3DEventMap {
  166. update: {
  167. camera: ICamera
  168. bubbleToParent: false
  169. // todo
  170. } & ICameraSetDirtyOptions
  171. }