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.

пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import {IDisposable} from 'ts-browser-helpers'
  2. import {IMaterial} from './IMaterial'
  3. import {Event, Object3D} from 'three'
  4. import {ChangeEvent, IUiConfigContainer, UiObjectConfig} from 'uiconfig.js'
  5. import {IGeometry, IGeometryEvent} from './IGeometry'
  6. import {IImportResultUserData} from '../assetmanager'
  7. import {GLTF} from 'three/examples/jsm/loaders/GLTFLoader.js'
  8. export type IObject3DEventTypes = 'dispose' | 'materialUpdate' | 'objectUpdate' | 'textureUpdate' | 'geometryChanged' |
  9. 'materialChanged' | 'geometryUpdate' | 'added' | 'removed' | 'select' | 'beforeDeserialize' |
  10. 'setView' | 'activateMain' | 'cameraUpdate' // from camera
  11. // | string
  12. export interface IObject3DEvent<T extends string = IObject3DEventTypes> extends Event {
  13. type: T
  14. object?: IObject3D // object that triggered the event, target might be parent in case of bubbleToParent
  15. bubbleToParent?: boolean // bubble event to parent root
  16. change?: string
  17. material?: IMaterial|undefined|IMaterial[] // from materialUpdate and materialChanged
  18. oldMaterial?: IMaterial|undefined|IMaterial[] // from materialChanged
  19. geometry?: IGeometry|undefined // from geometryUpdate, geometryChanged
  20. oldGeometry?: IGeometry|undefined // from geometryChanged
  21. source?: any
  22. }
  23. export interface ISetDirtyCommonOptions {
  24. /**
  25. * Trigger UI Config Refresh along with setDirty.
  26. * Default `true`. Set to `false` to prevent UI Config refresh.
  27. */
  28. refreshUi?: boolean
  29. /**
  30. * Enable/disable frame fade using {@link FrameFadePlugin}
  31. * Default `true`. when the plugin is enabled and has corresponding flags enabled
  32. */
  33. frameFade?: boolean // for plugins
  34. /**
  35. * Duration for `frameFade` in ms. Check {@link FrameFadePlugin} for more details.
  36. */
  37. fadeDuration?: number // for plugins
  38. /**
  39. * Event from uiconfig.js when some value changes from the UI.
  40. */
  41. uiChangeEvent?: ChangeEvent,
  42. }
  43. export interface IObjectSetDirtyOptions extends ISetDirtyCommonOptions{
  44. bubbleToParent?: boolean // bubble event to parent root
  45. change?: string
  46. refreshScene?: boolean // update scene after setting dirty
  47. geometryChanged?: boolean // whether to refresh stuff like ground.
  48. /**
  49. * @deprecated use {@link refreshScene} instead
  50. */
  51. sceneUpdate?: boolean // update scene after setting dirty
  52. [key: string]: any
  53. }
  54. export interface IObjectProcessor { // todo, should be viewer
  55. processObject: (object: IObject3D) => void
  56. }
  57. export interface IObject3DUserData extends IImportResultUserData {
  58. uuid?: string
  59. /**
  60. * When true, this object will not be exported when exporting the scene with {@link AssetExporter.exportObject}
  61. */
  62. excludeFromExport?: boolean
  63. autoCentered?: boolean
  64. isCentered?: boolean
  65. autoScaleRadius?: number
  66. autoScaled?: boolean
  67. geometriesCentered?: boolean
  68. /**
  69. * should this object be taken into account when calculating bounding box, default true
  70. */
  71. bboxVisible?: boolean
  72. /**
  73. * Is centered in a parent object.
  74. */
  75. pseudoCentered?: boolean
  76. license?: string
  77. /**
  78. * When false, this object will not be selectable when clicking on it.
  79. */
  80. userSelectable?: boolean
  81. /**
  82. * see {@link GLTFAnimationPlugin}
  83. */
  84. // eslint-disable-next-line @typescript-eslint/naming-convention
  85. gltfAnim_SyncMaxDuration?: boolean
  86. // region root scene model root
  87. /**
  88. * is it modelRoot in RootScene, used during serialization nad traversing ancestors
  89. */
  90. rootSceneModelRoot?: boolean
  91. __gltfAsset?: GLTF['asset']
  92. __gltfExtras?: GLTF['userData']
  93. // endregion
  94. __objectSetup?: boolean
  95. __meshSetup?: boolean
  96. // [key: string]: any // commented for noe
  97. // legacy
  98. /**
  99. * @deprecated
  100. */
  101. dispose?: any
  102. /**
  103. * @deprecated
  104. */
  105. setMaterial?: any
  106. /**
  107. * @deprecated
  108. */
  109. setGeometry?: any
  110. /**
  111. * @deprecated
  112. */
  113. setDirty?: any
  114. /**
  115. * Used in {@link GLTFObject3DExtrasExtension} and {@link iObjectCommons.upgradeObject3D}
  116. */
  117. __keepShadowDef?: boolean
  118. /**
  119. * Events that should be bubbled to parent root without the need to set bubbleToParent in the event.
  120. * todo: remove support for this
  121. */
  122. __autoBubbleToParentEvents?: string[]
  123. }
  124. export interface IObject3D<E extends Event = IObject3DEvent, ET = IObject3DEventTypes> extends Object3D<E, ET>, IUiConfigContainer, IDisposable {
  125. assetType: 'model' | 'light' | 'camera' | 'widget'
  126. isLight?: boolean
  127. isCamera?: boolean
  128. isMesh?: boolean
  129. isLine?: boolean
  130. isLineSegments?: boolean
  131. // isGroup?: boolean
  132. isScene?: boolean
  133. // isHelper?: boolean
  134. isWidget?: boolean
  135. readonly isObject3D: true
  136. material?: IMaterial | IMaterial[]
  137. /**
  138. * Same as material but always returns an array.
  139. */
  140. readonly materials?: IMaterial[]
  141. // eslint-disable-next-line @typescript-eslint/naming-convention
  142. _currentMaterial?: IMaterial | IMaterial[] | null
  143. geometry?: IGeometry
  144. morphTargetDictionary?: Record<string, number>
  145. morphTargetInfluences?: number[]
  146. updateMorphTargets?(): void
  147. // eslint-disable-next-line @typescript-eslint/naming-convention
  148. _currentGeometry?: IGeometry | null
  149. /**
  150. * Dispatches 'objectUpdate' event on object.
  151. * @param e
  152. */
  153. setDirty(e?: IObjectSetDirtyOptions): void
  154. /**
  155. * Parent/Ancestor of this object to bubble events to. This is set internally by setupObject3D.
  156. */
  157. parentRoot?: IObject3D | null
  158. uiConfig?: UiObjectConfig
  159. refreshUi(): void
  160. // 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
  161. userData: IObject3DUserData
  162. /**
  163. *
  164. * @param autoScaleRadius - optional (taken from userData.autoScaleRadius by default)
  165. * @param isCentered - optional (taken from userData.isCentered by default)
  166. * @param setDirty - true by default
  167. */
  168. autoScale?<T extends IObject3D>(autoScaleRadius?: number, isCentered?: boolean, setDirty?: boolean): T
  169. /**
  170. *
  171. * @param setDirty - calls {@link setDirty} @default true
  172. */
  173. autoCenter?<T extends IObject3D>(setDirty?: boolean): T
  174. /**
  175. * @deprecated use object directly
  176. */
  177. modelObject: this
  178. // eslint-disable-next-line @typescript-eslint/naming-convention
  179. _onGeometryUpdate?: (e: IGeometryEvent<'geometryUpdate'>) => void
  180. objectProcessor?: IObjectProcessor
  181. // __disposed?: boolean
  182. /**
  183. *
  184. * @param removeFromParent - remove from parent. Default true
  185. */
  186. dispose(removeFromParent?: boolean): void;
  187. // region inherited type fixes
  188. traverse(callback: (object: IObject3D) => void): void
  189. traverseVisible(callback: (object: IObject3D) => void): void
  190. traverseAncestors(callback: (object: IObject3D) => void): void
  191. getObjectById<T extends IObject3D = IObject3D>(id: number): T | undefined
  192. getObjectByName<T extends IObject3D = IObject3D>(name: string): T | undefined
  193. getObjectByProperty<T extends IObject3D = IObject3D>(name: string, value: string): T | undefined
  194. copy(source: this, recursive?: boolean, ...args: any[]): this
  195. clone(recursive?: boolean): this
  196. add(...object: Object3D[]): this
  197. remove(...object: IObject3D[]): this
  198. parent: IObject3D | null
  199. children: IObject3D[]
  200. // endregion
  201. }