babylon.viewer.module.d.ts 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. /// <reference path="./babylon.d.ts"/>
  2. /// <reference path="./babylon.glTF2Interface.d.ts"/>
  3. /// <reference path="./babylonjs.loaders.d.ts"/>
  4. declare module "babylonjs-loaders"{ export=BABYLON;}
  5. // Generated by dts-bundle v0.7.3
  6. // Dependencies for this module:
  7. // ../../../../Tools/Gulp/babylonjs
  8. // ../../../../Tools/Gulp/babylonjs-loaders
  9. declare module 'babylonjs-viewer' {
  10. import { mapperManager } from 'babylonjs-viewer/configuration/mappers';
  11. import { viewerGlobals } from 'babylonjs-viewer/configuration/globals';
  12. import { viewerManager } from 'babylonjs-viewer/viewer/viewerManager';
  13. import { DefaultViewer } from 'babylonjs-viewer/viewer/defaultViewer';
  14. import { AbstractViewer } from 'babylonjs-viewer/viewer/viewer';
  15. import { telemetryManager } from 'babylonjs-viewer/managers/telemetryManager';
  16. import { ModelLoader } from 'babylonjs-viewer/loader/modelLoader';
  17. import { ViewerModel, ModelState } from 'babylonjs-viewer/model/viewerModel';
  18. import { AnimationPlayMode, AnimationState } from 'babylonjs-viewer/model/modelAnimation';
  19. import { ILoaderPlugin } from 'babylonjs-viewer/loader/plugins/loaderPlugin';
  20. /**
  21. * BabylonJS Viewer
  22. *
  23. * An HTML-Based viewer for 3D models, based on BabylonJS and its extensions.
  24. */
  25. import * as BABYLON from 'babylonjs';
  26. import 'babylonjs-loaders';
  27. import 'pepjs';
  28. import { InitTags } from 'babylonjs-viewer/initializer';
  29. let disableInit: boolean;
  30. /**
  31. * Dispose all viewers currently registered
  32. */
  33. function disposeAll(): void;
  34. const Version: string;
  35. export { BABYLON, Version, InitTags, DefaultViewer, AbstractViewer, viewerGlobals, telemetryManager, disableInit, viewerManager, mapperManager, disposeAll, ModelLoader, ViewerModel, AnimationPlayMode, AnimationState, ModelState, ILoaderPlugin };
  36. export * from 'babylonjs-viewer/configuration';
  37. }
  38. declare module 'babylonjs-viewer/configuration/mappers' {
  39. import { ViewerConfiguration } from 'babylonjs-viewer/configuration/configuration';
  40. /**
  41. * This is the mapper's interface. Implement this function to create your own mapper and register it at the mapper manager
  42. */
  43. export interface IMapper {
  44. map(rawSource: any): ViewerConfiguration;
  45. }
  46. /**
  47. * The MapperManager manages the different implemented mappers.
  48. * It allows the user to register new mappers as well and use them to parse their own configuration data
  49. */
  50. export class MapperManager {
  51. /**
  52. * The default mapper is the JSON mapper.
  53. */
  54. static DefaultMapper: string;
  55. constructor();
  56. /**
  57. * Get a specific configuration mapper.
  58. *
  59. * @param type the name of the mapper to load
  60. */
  61. getMapper(type: string): IMapper;
  62. /**
  63. * Use this functio to register your own configuration mapper.
  64. * After a mapper is registered, it can be used to parse the specific type fo configuration to the standard ViewerConfiguration.
  65. * @param type the name of the mapper. This will be used to define the configuration type and/or to get the mapper
  66. * @param mapper The implemented mapper
  67. */
  68. registerMapper(type: string, mapper: IMapper): void;
  69. /**
  70. * Dispose the mapper manager and all of its mappers.
  71. */
  72. dispose(): void;
  73. }
  74. /**
  75. * mapperManager is a singleton of the type MapperManager.
  76. * The mapperManager can be disposed directly with calling mapperManager.dispose()
  77. * or indirectly with using BabylonViewer.disposeAll()
  78. */
  79. export let mapperManager: MapperManager;
  80. }
  81. declare module 'babylonjs-viewer/configuration/globals' {
  82. export class ViewerGlobals {
  83. disableInit: boolean;
  84. disableWebGL2Support: boolean;
  85. readonly version: string;
  86. }
  87. export let viewerGlobals: ViewerGlobals;
  88. }
  89. declare module 'babylonjs-viewer/viewer/viewerManager' {
  90. import { Observable } from 'babylonjs';
  91. import { AbstractViewer } from 'babylonjs-viewer/viewer/viewer';
  92. /**
  93. * The viewer manager is the container for all viewers currently registered on this page.
  94. * It is possible to have more than one viewer on a single page.
  95. */
  96. export class ViewerManager {
  97. /**
  98. * A callback that will be triggered when a new viewer was added
  99. */
  100. onViewerAdded: (viewer: AbstractViewer) => void;
  101. /**
  102. * Will notify when a new viewer was added
  103. */
  104. onViewerAddedObservable: Observable<AbstractViewer>;
  105. /**
  106. * Will notify when a viewer was removed (disposed)
  107. */
  108. onViewerRemovedObservable: Observable<string>;
  109. constructor();
  110. /**
  111. * Adding a new viewer to the viewer manager and start tracking it.
  112. * @param viewer the viewer to add
  113. */
  114. addViewer(viewer: AbstractViewer): void;
  115. /**
  116. * remove a viewer from the viewer manager
  117. * @param viewer the viewer to remove
  118. */
  119. removeViewer(viewer: AbstractViewer): void;
  120. /**
  121. * Get a viewer by its baseId (if the container element has an ID, it is the this is. if not, a random id was assigned)
  122. * @param id the id of the HTMl element (or the viewer's, if none provided)
  123. */
  124. getViewerById(id: string): AbstractViewer;
  125. /**
  126. * Get a viewer using a container element
  127. * @param element the HTML element to search viewers associated with
  128. */
  129. getViewerByHTMLElement(element: HTMLElement): AbstractViewer | undefined;
  130. /**
  131. * Get a promise that will fullfil when this viewer was initialized.
  132. * Since viewer initialization and template injection is asynchronous, using the promise will guaranty that
  133. * you will get the viewer after everything was already configured.
  134. * @param id the viewer id to find
  135. */
  136. getViewerPromiseById(id: string): Promise<AbstractViewer>;
  137. /**
  138. * dispose the manager and all of its associated viewers
  139. */
  140. dispose(): void;
  141. }
  142. export let viewerManager: ViewerManager;
  143. }
  144. declare module 'babylonjs-viewer/viewer/defaultViewer' {
  145. import { ViewerConfiguration, IModelConfiguration } from 'babylonjs-viewer/configuration';
  146. import { Template } from 'babylonjs-viewer/templating/templateManager';
  147. import { AbstractViewer } from 'babylonjs-viewer/viewer/viewer';
  148. import { ViewerModel } from 'babylonjs-viewer/model/viewerModel';
  149. /**
  150. * The Default viewer is the default implementation of the AbstractViewer.
  151. * It uses the templating system to render a new canvas and controls.
  152. */
  153. export class DefaultViewer extends AbstractViewer {
  154. containerElement: HTMLElement;
  155. /**
  156. * Create a new default viewer
  157. * @param containerElement the element in which the templates will be rendered
  158. * @param initialConfiguration the initial configuration. Defaults to extending the default configuration
  159. */
  160. constructor(containerElement: HTMLElement, initialConfiguration?: ViewerConfiguration);
  161. /**
  162. * This will be executed when the templates initialize.
  163. */
  164. protected _onTemplatesLoaded(): Promise<AbstractViewer>;
  165. toggleHD(): void;
  166. /**
  167. * Toggle fullscreen of the entire viewer
  168. */
  169. toggleFullscreen: () => void;
  170. /**
  171. * Preparing the container element to present the viewer
  172. */
  173. protected _prepareContainerElement(): void;
  174. /**
  175. * This function will configure the templates and update them after a model was loaded
  176. * It is mainly responsible to changing the title and subtitle etc'.
  177. * @param model the model to be used to configure the templates by
  178. */
  179. protected _configureTemplate(model?: ViewerModel): void;
  180. /**
  181. * This will load a new model to the default viewer
  182. * overriding the AbstractViewer's loadModel.
  183. * The scene will automatically be cleared of the old models, if exist.
  184. * @param model the configuration object (or URL) to load.
  185. */
  186. loadModel(model?: string | File | IModelConfiguration): Promise<ViewerModel>;
  187. /**
  188. * Show the overlay and the defined sub-screen.
  189. * Mainly used for help and errors
  190. * @param subScreen the name of the subScreen. Those can be defined in the configuration object
  191. */
  192. showOverlayScreen(subScreen: string): Promise<string> | Promise<Template>;
  193. /**
  194. * Hide the overlay screen.
  195. */
  196. hideOverlayScreen(): Promise<string> | Promise<Template>;
  197. /**
  198. * show the viewer (in case it was hidden)
  199. *
  200. * @param visibilityFunction an optional function to execute in order to show the container
  201. */
  202. show(visibilityFunction?: ((template: Template) => Promise<Template>)): Promise<Template>;
  203. /**
  204. * hide the viewer (in case it is visible)
  205. *
  206. * @param visibilityFunction an optional function to execute in order to hide the container
  207. */
  208. hide(visibilityFunction?: ((template: Template) => Promise<Template>)): Promise<Template>;
  209. /**
  210. * Show the loading screen.
  211. * The loading screen can be configured using the configuration object
  212. */
  213. showLoadingScreen(): Promise<string> | Promise<Template>;
  214. /**
  215. * Hide the loading screen
  216. */
  217. hideLoadingScreen(): Promise<string> | Promise<Template>;
  218. dispose(): void;
  219. protected _onConfigurationLoaded(configuration: ViewerConfiguration): void;
  220. }
  221. }
  222. declare module 'babylonjs-viewer/viewer/viewer' {
  223. import { SceneManager } from 'babylonjs-viewer/managers/sceneManager';
  224. import { ConfigurationLoader } from 'babylonjs-viewer/configuration/loader';
  225. import { Observable, Engine, Scene, SceneLoaderProgressEvent, ISceneLoaderPlugin, ISceneLoaderPluginAsync } from 'babylonjs';
  226. import { ViewerConfiguration, IObserversConfiguration, IModelConfiguration } from 'babylonjs-viewer/configuration';
  227. import { ViewerModel } from 'babylonjs-viewer/model/viewerModel';
  228. import { ModelLoader } from 'babylonjs-viewer/loader/modelLoader';
  229. import { ObservablesManager } from 'babylonjs-viewer/managers/observablesManager';
  230. import { ConfigurationContainer } from 'babylonjs-viewer/configuration/configurationContainer';
  231. import { TemplateManager } from 'babylonjs-viewer/templating/templateManager';
  232. /**
  233. * The AbstractViewr is the center of Babylon's viewer.
  234. * It is the basic implementation of the default viewer and is responsible of loading and showing the model and the templates
  235. */
  236. export abstract class AbstractViewer {
  237. containerElement: HTMLElement;
  238. /**
  239. * The corresponsing template manager of this viewer.
  240. */
  241. templateManager: TemplateManager;
  242. /**
  243. * Babylon Engine corresponding with this viewer
  244. */
  245. engine: Engine;
  246. /**
  247. * The ID of this viewer. it will be generated randomly or use the HTML Element's ID.
  248. */
  249. readonly baseId: string;
  250. /**
  251. * The last loader used to load a model.
  252. * @deprecated
  253. */
  254. lastUsedLoader: ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  255. /**
  256. * The ModelLoader instance connected with this viewer.
  257. */
  258. modelLoader: ModelLoader;
  259. /**
  260. * A flag that controls whether or not the render loop should be executed
  261. */
  262. runRenderLoop: boolean;
  263. /**
  264. * The scene manager connected with this viewer instance
  265. */
  266. sceneManager: SceneManager;
  267. /**
  268. * Will notify when the scene was initialized
  269. */
  270. readonly onSceneInitObservable: Observable<Scene>;
  271. /**
  272. * will notify when the engine was initialized
  273. */
  274. readonly onEngineInitObservable: Observable<Engine>;
  275. /**
  276. * Will notify when a new model was added to the scene.
  277. * Note that added does not neccessarily mean loaded!
  278. */
  279. readonly onModelAddedObservable: Observable<ViewerModel>;
  280. /**
  281. * will notify after every model load
  282. */
  283. readonly onModelLoadedObservable: Observable<ViewerModel>;
  284. /**
  285. * will notify when any model notify of progress
  286. */
  287. readonly onModelLoadProgressObservable: Observable<SceneLoaderProgressEvent>;
  288. /**
  289. * will notify when any model load failed.
  290. */
  291. readonly onModelLoadErrorObservable: Observable<{
  292. message: string;
  293. exception: any;
  294. }>;
  295. /**
  296. * Will notify when a model was removed from the scene;
  297. */
  298. readonly onModelRemovedObservable: Observable<ViewerModel>;
  299. /**
  300. * will notify when a new loader was initialized.
  301. * Used mainly to know when a model starts loading.
  302. */
  303. readonly onLoaderInitObservable: Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync>;
  304. /**
  305. * Observers registered here will be executed when the entire load process has finished.
  306. */
  307. readonly onInitDoneObservable: Observable<AbstractViewer>;
  308. /**
  309. * Functions added to this observable will be executed on each frame rendered.
  310. */
  311. readonly onFrameRenderedObservable: Observable<AbstractViewer>;
  312. observablesManager: ObservablesManager;
  313. /**
  314. * The canvas associated with this viewer
  315. */
  316. protected _canvas: HTMLCanvasElement;
  317. /**
  318. * The (single) canvas of this viewer
  319. */
  320. readonly canvas: HTMLCanvasElement;
  321. /**
  322. * is this viewer disposed?
  323. */
  324. protected _isDisposed: boolean;
  325. /**
  326. * registered onBeforeRender functions.
  327. * This functions are also registered at the native scene. The reference can be used to unregister them.
  328. */
  329. protected _registeredOnBeforeRenderFunctions: Array<() => void>;
  330. /**
  331. * The configuration loader of this viewer
  332. */
  333. protected _configurationLoader: ConfigurationLoader;
  334. /**
  335. * Is the viewer already initialized. for internal use.
  336. */
  337. protected _isInit: boolean;
  338. protected _configurationContainer: ConfigurationContainer;
  339. readonly configurationContainer: ConfigurationContainer;
  340. constructor(containerElement: HTMLElement, initialConfiguration?: ViewerConfiguration);
  341. /**
  342. * get the baseId of this viewer
  343. */
  344. getBaseId(): string;
  345. /**
  346. * Do we have a canvas to render on, and is it a part of the scene
  347. */
  348. isCanvasInDOM(): boolean;
  349. /**
  350. * Set the viewer's background rendering flag.
  351. */
  352. renderInBackground: boolean;
  353. /**
  354. * Get the configuration object. This is a reference only.
  355. * The configuration can ONLY be updated using the updateConfiguration function.
  356. * changing this object will have no direct effect on the scene.
  357. */
  358. readonly configuration: ViewerConfiguration;
  359. /**
  360. * force resizing the engine.
  361. */
  362. forceResize(): void;
  363. protected _hdToggled: boolean;
  364. toggleHD(): void;
  365. /**
  366. * The resize function that will be registered with the window object
  367. */
  368. protected _resize: () => void;
  369. protected _onConfigurationLoaded(configuration: ViewerConfiguration): void;
  370. /**
  371. * Force a single render loop execution.
  372. */
  373. forceRender(): void;
  374. /**
  375. * render loop that will be executed by the engine
  376. */
  377. protected _render: (force?: boolean) => void;
  378. /**
  379. * Takes a screenshot of the scene and returns it as a base64 encoded png.
  380. * @param callback optional callback that will be triggered when screenshot is done.
  381. * @param width Optional screenshot width (default to 512).
  382. * @param height Optional screenshot height (default to 512).
  383. * @returns a promise with the screenshot data
  384. */
  385. takeScreenshot(callback?: (data: string) => void, width?: number, height?: number): Promise<string>;
  386. /**
  387. * Update the current viewer configuration with new values.
  388. * Only provided information will be updated, old configuration values will be kept.
  389. * If this.configuration was manually changed, you can trigger this function with no parameters,
  390. * and the entire configuration will be updated.
  391. * @param newConfiguration the partial configuration to update
  392. *
  393. */
  394. updateConfiguration(newConfiguration?: Partial<ViewerConfiguration>): void;
  395. /**
  396. * this is used to register native functions using the configuration object.
  397. * This will configure the observers.
  398. * @param observersConfiguration observers configuration
  399. */
  400. protected _configureObservers(observersConfiguration: IObserversConfiguration): void;
  401. /**
  402. * Dispoe the entire viewer including the scene and the engine
  403. */
  404. dispose(): void;
  405. /**
  406. * This will prepare the container element for the viewer
  407. */
  408. protected abstract _prepareContainerElement(): any;
  409. /**
  410. * This function will execute when the HTML templates finished initializing.
  411. * It should initialize the engine and continue execution.
  412. *
  413. * @returns {Promise<AbstractViewer>} The viewer object will be returned after the object was loaded.
  414. */
  415. protected _onTemplatesLoaded(): Promise<AbstractViewer>;
  416. /**
  417. * This will force the creation of an engine and a scene.
  418. * It will also load a model if preconfigured.
  419. * But first - it will load the extendible onTemplateLoaded()!
  420. */
  421. protected _onTemplateLoaded(): Promise<AbstractViewer>;
  422. /**
  423. * Initialize the engine. Retruns a promise in case async calls are needed.
  424. *
  425. * @protected
  426. * @returns {Promise<Engine>}
  427. * @memberof Viewer
  428. */
  429. protected _initEngine(): Promise<Engine>;
  430. /**
  431. * Initialize a model loading. The returned object (a ViewerModel object) will be loaded in the background.
  432. * The difference between this and loadModel is that loadModel will fulfill the promise when the model finished loading.
  433. *
  434. * @param modelConfig model configuration to use when loading the model.
  435. * @param clearScene should the scene be cleared before loading this model
  436. * @returns a ViewerModel object that is not yet fully loaded.
  437. */
  438. initModel(modelConfig: string | File | IModelConfiguration, clearScene?: boolean): ViewerModel;
  439. /**
  440. * load a model using the provided configuration.
  441. * This function, as opposed to initModel, will return a promise that resolves when the model is loaded, and rejects with error.
  442. * If you want to attach to the observables of the model, use initModle instead.
  443. *
  444. * @param modelConfig the model configuration or URL to load.
  445. * @param clearScene Should the scene be cleared before loading the model
  446. * @returns a Promise the fulfills when the model finished loading successfully.
  447. */
  448. loadModel(modelConfig: string | File | IModelConfiguration, clearScene?: boolean): Promise<ViewerModel>;
  449. protected _initTelemetryEvents(): void;
  450. /**
  451. * Injects all the spectre shader in the babylon shader store
  452. */
  453. protected _injectCustomShaders(): void;
  454. }
  455. }
  456. declare module 'babylonjs-viewer/managers/telemetryManager' {
  457. import { Engine, Observable } from "babylonjs";
  458. /**
  459. * The data structure of a telemetry event.
  460. */
  461. export interface TelemetryData {
  462. event: string;
  463. session: string;
  464. date: Date;
  465. now: number;
  466. viewerId?: string;
  467. detail: any;
  468. }
  469. /**
  470. * Receives Telemetry events and raises events to the API
  471. */
  472. export class TelemetryManager {
  473. onEventBroadcastedObservable: Observable<TelemetryData>;
  474. /**
  475. * Receives a telemetry event
  476. * @param event The name of the Telemetry event
  477. * @param details An additional value, or an object containing a list of property/value pairs
  478. */
  479. readonly broadcast: (event: string, viewerId?: string | undefined, details?: any) => void;
  480. /**
  481. * Log a Telemetry event for errors raised on the WebGL context.
  482. * @param engine The Babylon engine with the WebGL context.
  483. */
  484. flushWebGLErrors(engine: Engine, viewerId?: string): void;
  485. /**
  486. * Enable or disable telemetry events
  487. * @param enabled Boolan, true if events are enabled
  488. */
  489. enable: boolean;
  490. /**
  491. * Returns the current session ID or creates one if it doesn't exixt
  492. * @return The current session ID
  493. */
  494. readonly session: string;
  495. /**
  496. * Disposes the telemetry manager
  497. */
  498. dispose(): void;
  499. }
  500. export const telemetryManager: TelemetryManager;
  501. }
  502. declare module 'babylonjs-viewer/loader/modelLoader' {
  503. import { IModelConfiguration } from "babylonjs-viewer/configuration/interfaces/modelConfiguration";
  504. import { ViewerModel } from "babylonjs-viewer/model/viewerModel";
  505. import { ILoaderPlugin } from 'babylonjs-viewer/loader/plugins';
  506. import { ObservablesManager } from "babylonjs-viewer/managers/observablesManager";
  507. import { ConfigurationContainer } from "babylonjs-viewer/configuration/configurationContainer";
  508. /**
  509. * An instance of the class is in charge of loading the model correctly.
  510. * This class will continously be expended with tasks required from the specific loaders Babylon has.
  511. *
  512. * A Model loader is unique per (Abstract)Viewer. It is being generated by the viewer
  513. */
  514. export class ModelLoader {
  515. /**
  516. * Create a new Model loader
  517. * @param _viewer the viewer using this model loader
  518. */
  519. constructor(_observablesManager: ObservablesManager, _configurationContainer?: ConfigurationContainer | undefined);
  520. /**
  521. * Adds a new plugin to the loader process.
  522. *
  523. * @param plugin the plugin name or the plugin itself
  524. */
  525. addPlugin(plugin: ILoaderPlugin | string): void;
  526. /**
  527. * Load a model using predefined configuration
  528. * @param modelConfiguration the modelConfiguration to use to load the model
  529. */
  530. load(modelConfiguration: IModelConfiguration): ViewerModel;
  531. cancelLoad(model: ViewerModel): void;
  532. /**
  533. * dispose the model loader.
  534. * If loaders are registered and are in the middle of loading, they will be disposed and the request(s) will be cancelled.
  535. */
  536. dispose(): void;
  537. }
  538. }
  539. declare module 'babylonjs-viewer/model/viewerModel' {
  540. import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, AnimationGroup, AbstractMesh, Observable, SceneLoaderProgressEvent, ParticleSystem, Skeleton, IDisposable, Nullable, Animation, Material } from "babylonjs";
  541. import { GLTF2 } from "babylonjs-loaders";
  542. import { IModelConfiguration } from "babylonjs-viewer/configuration/interfaces/modelConfiguration";
  543. import { IModelAnimation } from "babylonjs-viewer/model/modelAnimation";
  544. import { ObservablesManager } from "babylonjs-viewer/managers/observablesManager";
  545. import { ConfigurationContainer } from "babylonjs-viewer/configuration/configurationContainer";
  546. /**
  547. * The current state of the model
  548. */
  549. export enum ModelState {
  550. INIT = 0,
  551. LOADING = 1,
  552. LOADED = 2,
  553. ENTRY = 3,
  554. ENTRYDONE = 4,
  555. COMPLETE = 5,
  556. CANCELED = 6,
  557. ERROR = 7,
  558. }
  559. /**
  560. * The viewer model is a container for all assets representing a sngle loaded model.
  561. */
  562. export class ViewerModel implements IDisposable {
  563. /**
  564. * The loader used to load this model.
  565. */
  566. loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  567. /**
  568. * This model's root mesh (the parent of all other meshes).
  569. * This mesh does not(!) exist in the meshes array.
  570. */
  571. rootMesh: AbstractMesh;
  572. /**
  573. * ParticleSystems connected to this model
  574. */
  575. particleSystems: Array<ParticleSystem>;
  576. /**
  577. * Skeletons defined in this model
  578. */
  579. skeletons: Array<Skeleton>;
  580. /**
  581. * The current model animation.
  582. * On init, this will be undefined.
  583. */
  584. currentAnimation: IModelAnimation;
  585. /**
  586. * Observers registered here will be executed when the model is done loading
  587. */
  588. onLoadedObservable: Observable<ViewerModel>;
  589. /**
  590. * Observers registered here will be executed when the loader notified of a progress event
  591. */
  592. onLoadProgressObservable: Observable<SceneLoaderProgressEvent>;
  593. /**
  594. * Observers registered here will be executed when the loader notified of an error.
  595. */
  596. onLoadErrorObservable: Observable<{
  597. message: string;
  598. exception: any;
  599. }>;
  600. /**
  601. * Will be executed after the model finished loading and complete, including entry animation and lod
  602. */
  603. onCompleteObservable: Observable<ViewerModel>;
  604. /**
  605. * Observers registered here will be executed every time the model is being configured.
  606. * This can be used to extend the model's configuration without extending the class itself
  607. */
  608. onAfterConfigure: Observable<ViewerModel>;
  609. /**
  610. * The current model state (loaded, error, etc)
  611. */
  612. state: ModelState;
  613. /**
  614. * A loadID provided by the modelLoader, unique to ths (Abstract)Viewer instance.
  615. */
  616. loadId: number;
  617. loadInfo: GLTF2.IAsset;
  618. constructor(_observablesManager: ObservablesManager, modelConfiguration: IModelConfiguration, _configurationContainer?: ConfigurationContainer | undefined);
  619. shadowsRenderedAfterLoad: boolean;
  620. getViewerId(): string | undefined;
  621. /**
  622. * Set whether this model is enabled or not.
  623. */
  624. enabled: boolean;
  625. loaderDone: boolean;
  626. /**
  627. * Add a mesh to this model.
  628. * Any mesh that has no parent will be provided with the root mesh as its new parent.
  629. *
  630. * @param mesh the new mesh to add
  631. * @param triggerLoaded should this mesh trigger the onLoaded observable. Used when adding meshes manually.
  632. */
  633. addMesh(mesh: AbstractMesh, triggerLoaded?: boolean): Promise<ViewerModel> | undefined;
  634. /**
  635. * get the list of meshes (excluding the root mesh)
  636. */
  637. readonly meshes: AbstractMesh[];
  638. /**
  639. * (Re-)set the model's entire configuration
  640. * @param newConfiguration the new configuration to replace the new one
  641. */
  642. configuration: IModelConfiguration;
  643. /**
  644. * Update the current configuration with new values.
  645. * Configuration will not be overwritten, but merged with the new configuration.
  646. * Priority is to the new configuration
  647. * @param newConfiguration the configuration to be merged into the current configuration;
  648. */
  649. updateConfiguration(newConfiguration: Partial<IModelConfiguration>): void;
  650. /**
  651. * Add a new animation group to this model.
  652. * @param animationGroup the new animation group to be added
  653. */
  654. addAnimationGroup(animationGroup: AnimationGroup): void;
  655. /**
  656. * Get the ModelAnimation array
  657. */
  658. getAnimations(): Array<IModelAnimation>;
  659. /**
  660. * Get the animations' names. Using the names you can play a specific animation.
  661. */
  662. getAnimationNames(): Array<string>;
  663. /**
  664. * Get an animation by the provided name. Used mainly when playing n animation.
  665. * @param name the name of the animation to find
  666. */
  667. protected _getAnimationByName(name: string): Nullable<IModelAnimation>;
  668. /**
  669. * Choose an initialized animation using its name and start playing it
  670. * @param name the name of the animation to play
  671. * @returns The model aniamtion to be played.
  672. */
  673. playAnimation(name: string): IModelAnimation;
  674. setCurrentAnimationByName(name: string): IModelAnimation;
  675. /**
  676. * Apply a material configuration to a material
  677. * @param material Material to apply configuration to
  678. */
  679. _applyModelMaterialConfiguration(material: Material): void;
  680. /**
  681. * Begin @animations with the specified @easingFunction
  682. * @param animations The BABYLON Animations to begin
  683. * @param duration of transition, in seconds
  684. * @param easingFunction An easing function to apply
  685. * @param easingMode A easing mode to apply to the easingFunction
  686. * @param onAnimationEnd Call back trigger at the end of the animation.
  687. */
  688. transitionTo(animations: Animation[], duration: number, easingFunction: any, easingMode: number | undefined, onAnimationEnd: () => void): void;
  689. /**
  690. * Stops and removes all animations that have been applied to the model
  691. */
  692. stopAllAnimations(): void;
  693. /**
  694. * Will remove this model from the viewer (but NOT dispose it).
  695. */
  696. remove(): void;
  697. /**
  698. * Dispose this model, including all of its associated assets.
  699. */
  700. dispose(): void;
  701. }
  702. }
  703. declare module 'babylonjs-viewer/model/modelAnimation' {
  704. import { AnimationGroup, Vector3 } from "babylonjs";
  705. /**
  706. * Animation play mode enum - is the animation looping or playing once
  707. */
  708. export const enum AnimationPlayMode {
  709. ONCE = 0,
  710. LOOP = 1,
  711. }
  712. /**
  713. * An enum representing the current state of an animation object
  714. */
  715. export const enum AnimationState {
  716. INIT = 0,
  717. PLAYING = 1,
  718. PAUSED = 2,
  719. STOPPED = 3,
  720. ENDED = 4,
  721. }
  722. /**
  723. * The different type of easing functions available
  724. */
  725. export const enum EasingFunction {
  726. Linear = 0,
  727. CircleEase = 1,
  728. BackEase = 2,
  729. BounceEase = 3,
  730. CubicEase = 4,
  731. ElasticEase = 5,
  732. ExponentialEase = 6,
  733. PowerEase = 7,
  734. QuadraticEase = 8,
  735. QuarticEase = 9,
  736. QuinticEase = 10,
  737. SineEase = 11,
  738. }
  739. /**
  740. * Defines a simple animation to be applied to a model (scale).
  741. */
  742. export interface ModelAnimationConfiguration {
  743. /**
  744. * Time of animation, in seconds
  745. */
  746. time: number;
  747. /**
  748. * Scale to apply
  749. */
  750. scaling?: Vector3;
  751. /**
  752. * Easing function to apply
  753. * See SPECTRE.EasingFunction
  754. */
  755. easingFunction?: number;
  756. /**
  757. * An Easing mode to apply to the easing function
  758. * See BABYLON.EasingFunction
  759. */
  760. easingMode?: number;
  761. }
  762. /**
  763. * This interface can be implemented to define new types of ModelAnimation objects.
  764. */
  765. export interface IModelAnimation {
  766. /**
  767. * Current animation state (playing, stopped etc')
  768. */
  769. readonly state: AnimationState;
  770. /**
  771. * the name of the animation
  772. */
  773. readonly name: string;
  774. /**
  775. * Get the max numbers of frame available in the animation group
  776. *
  777. * In correlation to an arry, this would be ".length"
  778. */
  779. readonly frames: number;
  780. /**
  781. * Get the current frame playing right now.
  782. * This can be used to poll the frame currently playing (and, for exmaple, display a progress bar with the data)
  783. *
  784. * In correlation to an array, this would be the current index
  785. */
  786. readonly currentFrame: number;
  787. /**
  788. * Animation's FPS value
  789. */
  790. readonly fps: number;
  791. /**
  792. * Get or set the animation's speed ration (Frame-to-fps)
  793. */
  794. speedRatio: number;
  795. /**
  796. * Gets or sets the aimation's play mode.
  797. */
  798. playMode: AnimationPlayMode;
  799. /**
  800. * Start the animation
  801. */
  802. start(): any;
  803. /**
  804. * Stop the animation.
  805. * This will fail silently if the animation group is already stopped.
  806. */
  807. stop(): any;
  808. /**
  809. * Pause the animation
  810. * This will fail silently if the animation is not currently playing
  811. */
  812. pause(): any;
  813. /**
  814. * Reset this animation
  815. */
  816. reset(): any;
  817. /**
  818. * Restart the animation
  819. */
  820. restart(): any;
  821. /**
  822. * Go to a specific
  823. * @param frameNumber the frame number to go to
  824. */
  825. goToFrame(frameNumber: number): any;
  826. /**
  827. * Dispose this animation
  828. */
  829. dispose(): any;
  830. }
  831. /**
  832. * The GroupModelAnimation is an implementation of the IModelAnimation interface using BABYLON's
  833. * native GroupAnimation class.
  834. */
  835. export class GroupModelAnimation implements IModelAnimation {
  836. /**
  837. * Create a new GroupModelAnimation object using an AnimationGroup object
  838. * @param _animationGroup The aniamtion group to base the class on
  839. */
  840. constructor(_animationGroup: AnimationGroup);
  841. /**
  842. * Get the animation's name
  843. */
  844. readonly name: string;
  845. /**
  846. * Get the current animation's state
  847. */
  848. readonly state: AnimationState;
  849. /**
  850. * Sets the speed ratio to use for all animations
  851. */
  852. speedRatio: number;
  853. /**
  854. * Get the max numbers of frame available in the animation group
  855. *
  856. * In correlation to an arry, this would be ".length"
  857. */
  858. readonly frames: number;
  859. /**
  860. * Get the current frame playing right now.
  861. * This can be used to poll the frame currently playing (and, for exmaple, display a progress bar with the data)
  862. *
  863. * In correlation to an array, this would be the current index
  864. */
  865. readonly currentFrame: number;
  866. /**
  867. * Get the FPS value of this animation
  868. */
  869. readonly fps: number;
  870. /**
  871. * Set the play mode.
  872. * If the animation is played, it will continue playing at least once more, depending on the new play mode set.
  873. * If the animation is not set, the will be initialized and will wait for the user to start playing it.
  874. */
  875. playMode: AnimationPlayMode;
  876. /**
  877. * Reset the animation group
  878. */
  879. reset(): void;
  880. /**
  881. * Restart the animation group
  882. */
  883. restart(): void;
  884. /**
  885. *
  886. * @param frameNumber Go to a specific frame in the animation
  887. */
  888. goToFrame(frameNumber: number): void;
  889. /**
  890. * Start playing the animation.
  891. */
  892. start(): void;
  893. /**
  894. * Pause the animation
  895. */
  896. pause(): void;
  897. /**
  898. * Stop the animation.
  899. * This will fail silently if the animation group is already stopped.
  900. */
  901. stop(): void;
  902. /**
  903. * Dispose this animation object.
  904. */
  905. dispose(): void;
  906. }
  907. }
  908. declare module 'babylonjs-viewer/loader/plugins/loaderPlugin' {
  909. import { ViewerModel } from "babylonjs-viewer/model/viewerModel";
  910. import { IGLTFLoaderExtension, IGLTFLoaderData } from "babylonjs-loaders";
  911. import { AbstractMesh, ISceneLoaderPlugin, ISceneLoaderPluginAsync, SceneLoaderProgressEvent, BaseTexture, Material } from "babylonjs";
  912. /**
  913. * This interface defines the structure of a loader plugin.
  914. * Any of those functions will be called if (!) the loader supports those callbacks.
  915. * Any loader supports onInit, onLoaded, onError and onProgress.
  916. */
  917. export interface ILoaderPlugin {
  918. onInit?: (loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync, model: ViewerModel) => void;
  919. onLoaded?: (model: ViewerModel) => void;
  920. onError?: (message: string, exception?: any) => void;
  921. onProgress?: (progressEvent: SceneLoaderProgressEvent) => void;
  922. onExtensionLoaded?: (extension: IGLTFLoaderExtension) => void;
  923. onParsed?: (parsedData: IGLTFLoaderData) => void;
  924. onMeshLoaded?: (mesh: AbstractMesh) => void;
  925. onTextureLoaded?: (texture: BaseTexture) => void;
  926. onMaterialLoaded?: (material: Material) => void;
  927. onComplete?: () => void;
  928. }
  929. }
  930. declare module 'babylonjs-viewer/initializer' {
  931. /**
  932. * Will attach an init function the the DOMContentLoaded event.
  933. * The init function will be removed automatically after the event was triggered.
  934. */
  935. export function initListeners(): void;
  936. /**
  937. * Select all HTML tags on the page that match the selector and initialize a viewer
  938. *
  939. * @param selector the selector to initialize the viewer on (default is 'babylon')
  940. */
  941. export function InitTags(selector?: string): void;
  942. }
  943. declare module 'babylonjs-viewer/configuration' {
  944. export * from 'babylonjs-viewer/configuration/configuration';
  945. export * from 'babylonjs-viewer/configuration/interfaces';
  946. }
  947. declare module 'babylonjs-viewer/configuration/configuration' {
  948. import { EngineOptions } from 'babylonjs';
  949. import { IObserversConfiguration, IModelConfiguration, ISceneConfiguration, ISceneOptimizerConfiguration, ICameraConfiguration, ISkyboxConfiguration, IGroundConfiguration, ILightConfiguration, IDefaultRenderingPipelineConfiguration, ITemplateConfiguration } from 'babylonjs-viewer/configuration/interfaces';
  950. export function getConfigurationKey(key: string, configObject: any): any;
  951. export interface ViewerConfiguration {
  952. version?: string;
  953. extends?: string;
  954. pageUrl?: string;
  955. configuration?: string | {
  956. url?: string;
  957. payload?: any;
  958. mapper?: string;
  959. };
  960. observers?: IObserversConfiguration;
  961. canvasElement?: string;
  962. model?: IModelConfiguration | string;
  963. scene?: ISceneConfiguration;
  964. optimizer?: ISceneOptimizerConfiguration | boolean;
  965. camera?: ICameraConfiguration;
  966. skybox?: boolean | ISkyboxConfiguration;
  967. ground?: boolean | IGroundConfiguration;
  968. lights?: {
  969. [name: string]: number | boolean | ILightConfiguration;
  970. };
  971. engine?: {
  972. renderInBackground?: boolean;
  973. antialiasing?: boolean;
  974. disableResize?: boolean;
  975. engineOptions?: EngineOptions;
  976. adaptiveQuality?: boolean;
  977. hdEnabled?: boolean;
  978. };
  979. templates?: {
  980. main: ITemplateConfiguration;
  981. [key: string]: ITemplateConfiguration;
  982. };
  983. customShaders?: {
  984. shaders?: {
  985. [key: string]: string;
  986. };
  987. includes?: {
  988. [key: string]: string;
  989. };
  990. };
  991. loaderPlugins?: {
  992. extendedMaterial?: boolean;
  993. msftLod?: boolean;
  994. telemetry?: boolean;
  995. minecraft?: boolean;
  996. [propName: string]: boolean | undefined;
  997. };
  998. lab?: {
  999. flashlight?: boolean | {
  1000. exponent?: number;
  1001. angle?: number;
  1002. intensity?: number;
  1003. diffuse?: {
  1004. r: number;
  1005. g: number;
  1006. b: number;
  1007. };
  1008. specular?: {
  1009. r: number;
  1010. g: number;
  1011. b: number;
  1012. };
  1013. };
  1014. hideLoadingDelay?: number;
  1015. assetsRootURL?: string;
  1016. environmentMainColor?: {
  1017. r: number;
  1018. g: number;
  1019. b: number;
  1020. };
  1021. environmentMap?: {
  1022. /**
  1023. * Environment map texture path in relative to the asset folder.
  1024. */
  1025. texture: string;
  1026. /**
  1027. * Default rotation to apply to the environment map.
  1028. */
  1029. rotationY: number;
  1030. /**
  1031. * Tint level of the main color on the environment map.
  1032. */
  1033. tintLevel: number;
  1034. };
  1035. defaultRenderingPipelines?: boolean | IDefaultRenderingPipelineConfiguration;
  1036. globalLightRotation?: number;
  1037. };
  1038. }
  1039. }
  1040. declare module 'babylonjs-viewer/templating/templateManager' {
  1041. import { Observable } from 'babylonjs';
  1042. import { EventManager } from 'babylonjs-viewer/templating/eventManager';
  1043. import { ITemplateConfiguration } from 'babylonjs-viewer/configuration/interfaces';
  1044. /**
  1045. * The object sent when an event is triggered
  1046. */
  1047. export interface EventCallback {
  1048. event: Event;
  1049. template: Template;
  1050. selector: string;
  1051. payload?: any;
  1052. }
  1053. /**
  1054. * The template manager, a member of the viewer class, will manage the viewer's templates and generate the HTML.
  1055. * The template manager managers a single viewer and can be seen as the collection of all sub-templates of the viewer.
  1056. */
  1057. export class TemplateManager {
  1058. containerElement: HTMLElement;
  1059. /**
  1060. * Will be triggered when any template is initialized
  1061. */
  1062. onTemplateInit: Observable<Template>;
  1063. /**
  1064. * Will be triggered when any template is fully loaded
  1065. */
  1066. onTemplateLoaded: Observable<Template>;
  1067. /**
  1068. * Will be triggered when a template state changes
  1069. */
  1070. onTemplateStateChange: Observable<Template>;
  1071. /**
  1072. * Will be triggered when all templates finished loading
  1073. */
  1074. onAllLoaded: Observable<TemplateManager>;
  1075. /**
  1076. * Will be triggered when any event on any template is triggered.
  1077. */
  1078. onEventTriggered: Observable<EventCallback>;
  1079. /**
  1080. * This template manager's event manager. In charge of callback registrations to native event types
  1081. */
  1082. eventManager: EventManager;
  1083. constructor(containerElement: HTMLElement);
  1084. /**
  1085. * Initialize the template(s) for the viewer. Called bay the Viewer class
  1086. * @param templates the templates to be used to initialize the main template
  1087. */
  1088. initTemplate(templates: {
  1089. [key: string]: ITemplateConfiguration;
  1090. }): Promise<void>;
  1091. /**
  1092. * Get the canvas in the template tree.
  1093. * There must be one and only one canvas inthe template.
  1094. */
  1095. getCanvas(): HTMLCanvasElement | null;
  1096. /**
  1097. * Get a specific template from the template tree
  1098. * @param name the name of the template to load
  1099. */
  1100. getTemplate(name: string): Template | undefined;
  1101. /**
  1102. * Dispose the template manager
  1103. */
  1104. dispose(): void;
  1105. }
  1106. /**
  1107. * This class represents a single template in the viewer's template tree.
  1108. * An example for a template is a single canvas, an overlay (containing sub-templates) or the navigation bar.
  1109. * A template is injected using the template manager in the correct position.
  1110. * The template is rendered using Handlebars and can use Handlebars' features (such as parameter injection)
  1111. *
  1112. * For further information please refer to the documentation page, https://doc.babylonjs.com
  1113. */
  1114. export class Template {
  1115. name: string;
  1116. /**
  1117. * Will be triggered when the template is loaded
  1118. */
  1119. onLoaded: Observable<Template>;
  1120. /**
  1121. * will be triggered when the template is appended to the tree
  1122. */
  1123. onAppended: Observable<Template>;
  1124. /**
  1125. * Will be triggered when the template's state changed (shown, hidden)
  1126. */
  1127. onStateChange: Observable<Template>;
  1128. /**
  1129. * Will be triggered when an event is triggered on ths template.
  1130. * The event is a native browser event (like mouse or pointer events)
  1131. */
  1132. onEventTriggered: Observable<EventCallback>;
  1133. /**
  1134. * is the template loaded?
  1135. */
  1136. isLoaded: boolean;
  1137. /**
  1138. * This is meant to be used to track the show and hide functions.
  1139. * This is NOT (!!) a flag to check if the element is actually visible to the user.
  1140. */
  1141. isShown: boolean;
  1142. /**
  1143. * Is this template a part of the HTML tree (the template manager injected it)
  1144. */
  1145. isInHtmlTree: boolean;
  1146. /**
  1147. * The HTML element containing this template
  1148. */
  1149. parent: HTMLElement;
  1150. /**
  1151. * A promise that is fulfilled when the template finished loading.
  1152. */
  1153. initPromise: Promise<Template>;
  1154. constructor(name: string, _configuration: ITemplateConfiguration);
  1155. /**
  1156. * Some templates have parameters (like background color for example).
  1157. * The parameters are provided to Handlebars which in turn generates the template.
  1158. * This function will update the template with the new parameters
  1159. *
  1160. * Note that when updating parameters the events will be registered again (after being cleared).
  1161. *
  1162. * @param params the new template parameters
  1163. */
  1164. updateParams(params: {
  1165. [key: string]: string | number | boolean | object;
  1166. }, append?: boolean): void;
  1167. /**
  1168. * Get the template'S configuration
  1169. */
  1170. readonly configuration: ITemplateConfiguration;
  1171. /**
  1172. * A template can be a parent element for other templates or HTML elements.
  1173. * This function will deliver all child HTML elements of this template.
  1174. */
  1175. getChildElements(): Array<string>;
  1176. /**
  1177. * Appending the template to a parent HTML element.
  1178. * If a parent is already set and you wish to replace the old HTML with new one, forceRemove should be true.
  1179. * @param parent the parent to which the template is added
  1180. * @param forceRemove if the parent already exists, shoud the template be removed from it?
  1181. */
  1182. appendTo(parent: HTMLElement, forceRemove?: boolean): void;
  1183. /**
  1184. * Show the template using the provided visibilityFunction, or natively using display: flex.
  1185. * The provided function returns a promise that should be fullfilled when the element is shown.
  1186. * Since it is a promise async operations are more than possible.
  1187. * See the default viewer for an opacity example.
  1188. * @param visibilityFunction The function to execute to show the template.
  1189. */
  1190. show(visibilityFunction?: (template: Template) => Promise<Template>): Promise<Template>;
  1191. /**
  1192. * Hide the template using the provided visibilityFunction, or natively using display: none.
  1193. * The provided function returns a promise that should be fullfilled when the element is hidden.
  1194. * Since it is a promise async operations are more than possible.
  1195. * See the default viewer for an opacity example.
  1196. * @param visibilityFunction The function to execute to show the template.
  1197. */
  1198. hide(visibilityFunction?: (template: Template) => Promise<Template>): Promise<Template>;
  1199. /**
  1200. * Dispose this template
  1201. */
  1202. dispose(): void;
  1203. }
  1204. }
  1205. declare module 'babylonjs-viewer/managers/sceneManager' {
  1206. import { Scene, ArcRotateCamera, Engine, Light, SceneOptimizer, EnvironmentHelper, Color3, Observable, DefaultRenderingPipeline, Nullable } from 'babylonjs';
  1207. import { ILightConfiguration, ISceneConfiguration, ISceneOptimizerConfiguration, ICameraConfiguration, ISkyboxConfiguration, ViewerConfiguration, IGroundConfiguration, IModelConfiguration } from 'babylonjs-viewer/configuration';
  1208. import { ViewerModel } from 'babylonjs-viewer/model/viewerModel';
  1209. import { ViewerLabs } from 'babylonjs-viewer/labs/viewerLabs';
  1210. import { ObservablesManager } from 'babylonjs-viewer/managers/observablesManager';
  1211. import { ConfigurationContainer } from 'babylonjs-viewer/configuration/configurationContainer';
  1212. /**
  1213. * This interface describes the structure of the variable sent with the configuration observables of the scene manager.
  1214. * O - the type of object we are dealing with (Light, ArcRotateCamera, Scene, etc')
  1215. * T - the configuration type
  1216. */
  1217. export interface IPostConfigurationCallback<OBJ, CONF> {
  1218. newConfiguration: CONF;
  1219. sceneManager: SceneManager;
  1220. object: OBJ;
  1221. model?: ViewerModel;
  1222. }
  1223. export class SceneManager {
  1224. /**
  1225. * Will notify when the scene was initialized
  1226. */
  1227. onSceneInitObservable: Observable<Scene>;
  1228. /**
  1229. * Will notify after the scene was configured. Can be used to further configure the scene
  1230. */
  1231. onSceneConfiguredObservable: Observable<IPostConfigurationCallback<Scene, ISceneConfiguration>>;
  1232. /**
  1233. * Will notify after the scene optimized was configured. Can be used to further configure the scene optimizer
  1234. */
  1235. onSceneOptimizerConfiguredObservable: Observable<IPostConfigurationCallback<SceneOptimizer, ISceneOptimizerConfiguration | boolean>>;
  1236. /**
  1237. * Will notify after the camera was configured. Can be used to further configure the camera
  1238. */
  1239. onCameraConfiguredObservable: Observable<IPostConfigurationCallback<ArcRotateCamera, ICameraConfiguration>>;
  1240. /**
  1241. * Will notify after the lights were configured. Can be used to further configure lights
  1242. */
  1243. onLightsConfiguredObservable: Observable<IPostConfigurationCallback<Array<Light>, {
  1244. [name: string]: ILightConfiguration | boolean | number;
  1245. }>>;
  1246. /**
  1247. * Will notify after the model(s) were configured. Can be used to further configure models
  1248. */
  1249. onModelsConfiguredObservable: Observable<IPostConfigurationCallback<Array<ViewerModel>, IModelConfiguration>>;
  1250. /**
  1251. * Will notify after the envirnoment was configured. Can be used to further configure the environment
  1252. */
  1253. onEnvironmentConfiguredObservable: Observable<IPostConfigurationCallback<EnvironmentHelper, {
  1254. skybox?: ISkyboxConfiguration | boolean;
  1255. ground?: IGroundConfiguration | boolean;
  1256. }>>;
  1257. /**
  1258. * The Babylon Scene of this viewer
  1259. */
  1260. scene: Scene;
  1261. /**
  1262. * The camera used in this viewer
  1263. */
  1264. camera: ArcRotateCamera;
  1265. /**
  1266. * Babylon's scene optimizer
  1267. */
  1268. sceneOptimizer: SceneOptimizer;
  1269. /**
  1270. * Models displayed in this viewer.
  1271. */
  1272. models: Array<ViewerModel>;
  1273. /**
  1274. * Babylon's environment helper of this viewer
  1275. */
  1276. environmentHelper?: EnvironmentHelper;
  1277. protected _defaultHighpTextureType: number;
  1278. protected _shadowGeneratorBias: number;
  1279. protected _defaultPipelineTextureType: number;
  1280. /**
  1281. * The maximum number of shadows supported by the curent viewer
  1282. */
  1283. protected _maxShadows: number;
  1284. /**
  1285. * The labs variable consists of objects that will have their API change.
  1286. * Please be careful when using labs in production.
  1287. */
  1288. labs: ViewerLabs;
  1289. readonly defaultRenderingPipeline: Nullable<DefaultRenderingPipeline>;
  1290. constructor(_engine: Engine, _configurationContainer: ConfigurationContainer, _observablesManager?: ObservablesManager | undefined);
  1291. /**
  1292. * Returns a boolean representing HDR support
  1293. */
  1294. readonly isHdrSupported: boolean;
  1295. /**
  1296. * Return the main color defined in the configuration.
  1297. */
  1298. readonly mainColor: Color3;
  1299. readonly reflectionColor: Color3;
  1300. animationBlendingEnabled: boolean;
  1301. readonly observablesManager: ObservablesManager | undefined;
  1302. /**
  1303. * Should shadows be rendered every frame, or only once and stop.
  1304. * This can be used to optimize a scene.
  1305. *
  1306. * Not that the shadows will NOT disapear but will remain in place.
  1307. * @param process if true shadows will be updated once every frame. if false they will stop being updated.
  1308. */
  1309. processShadows: boolean;
  1310. groundEnabled: boolean;
  1311. /**
  1312. * sets wether the reflection is disabled.
  1313. */
  1314. groundMirrorEnabled: boolean;
  1315. defaultRenderingPipelineEnabled: boolean;
  1316. /**
  1317. * Sets the engine flags to unlock all babylon features.
  1318. * Can also be configured using the scene.flags configuration object
  1319. */
  1320. unlockBabylonFeatures(): void;
  1321. /**
  1322. * initialize the scene. Calling this function again will dispose the old scene, if exists.
  1323. */
  1324. initScene(sceneConfiguration?: ISceneConfiguration, optimizerConfiguration?: boolean | ISceneOptimizerConfiguration): Promise<Scene>;
  1325. clearScene(clearModels?: boolean, clearLights?: boolean): void;
  1326. /**
  1327. * This will update the scene's configuration, including camera, lights, environment.
  1328. * @param newConfiguration the delta that should be configured. This includes only the changes
  1329. * @param globalConfiguration The global configuration object, after the new configuration was merged into it
  1330. */
  1331. updateConfiguration(newConfiguration: Partial<ViewerConfiguration>): void;
  1332. bloomEnabled: boolean;
  1333. fxaaEnabled: boolean;
  1334. /**
  1335. * internally configure the scene using the provided configuration.
  1336. * The scene will not be recreated, but just updated.
  1337. * @param sceneConfig the (new) scene configuration
  1338. */
  1339. protected _configureScene(sceneConfig: ISceneConfiguration): void;
  1340. /**
  1341. * Configure the scene optimizer.
  1342. * The existing scene optimizer will be disposed and a new one will be created.
  1343. * @param optimizerConfig the (new) optimizer configuration
  1344. */
  1345. protected _configureOptimizer(optimizerConfig: ISceneOptimizerConfiguration | boolean): void;
  1346. /**
  1347. * (Re) configure the camera. The camera will only be created once and from this point will only be reconfigured.
  1348. * @param cameraConfig the new camera configuration
  1349. * @param model optionally use the model to configure the camera.
  1350. */
  1351. protected _configureCamera(cameraConfig?: ICameraConfiguration): void;
  1352. protected _configureEnvironment(skyboxConifguration?: ISkyboxConfiguration | boolean, groundConfiguration?: IGroundConfiguration | boolean): void;
  1353. /**
  1354. * configure the lights.
  1355. *
  1356. * @param lightsConfiguration the (new) light(s) configuration
  1357. * @param model optionally use the model to configure the camera.
  1358. */
  1359. protected _configureLights(lightsConfiguration?: {
  1360. [name: string]: ILightConfiguration | boolean | number;
  1361. }): void;
  1362. /**
  1363. * Gets the shadow map blur kernel according to the light configuration.
  1364. * @param light The light used to generate the shadows
  1365. * @param bufferSize The size of the shadow map
  1366. * @return the kernel blur size
  1367. */
  1368. getBlurKernel(light: BABYLON.IShadowLight, bufferSize: number): number;
  1369. /**
  1370. * Alters render settings to reduce features based on hardware feature limitations
  1371. * @param enableHDR Allows the viewer to run in HDR mode.
  1372. */
  1373. protected _handleHardwareLimitations(enableHDR?: boolean): void;
  1374. /**
  1375. * Dispoe the entire viewer including the scene and the engine
  1376. */
  1377. dispose(): void;
  1378. }
  1379. }
  1380. declare module 'babylonjs-viewer/configuration/loader' {
  1381. import { ViewerConfiguration } from 'babylonjs-viewer/configuration/configuration';
  1382. /**
  1383. * The configuration loader will load the configuration object from any source and will use the defined mapper to
  1384. * parse the object and return a conform ViewerConfiguration.
  1385. * It is a private member of the scene.
  1386. */
  1387. export class ConfigurationLoader {
  1388. constructor(_enableCache?: boolean);
  1389. /**
  1390. * load a configuration object that is defined in the initial configuration provided.
  1391. * The viewer configuration can extend different types of configuration objects and have an extra configuration defined.
  1392. *
  1393. * @param initConfig the initial configuration that has the definitions of further configuration to load.
  1394. * @param callback an optional callback that will be called sync, if noconfiguration needs to be loaded or configuration is payload-only
  1395. * @returns A promise that delivers the extended viewer configuration, when done.
  1396. */
  1397. loadConfiguration(initConfig?: ViewerConfiguration, callback?: (config: ViewerConfiguration) => void): Promise<ViewerConfiguration>;
  1398. /**
  1399. * Dispose the configuration loader. This will cancel file requests, if active.
  1400. */
  1401. dispose(): void;
  1402. }
  1403. }
  1404. declare module 'babylonjs-viewer/managers/observablesManager' {
  1405. import { Observable, Scene, Engine, SceneLoaderProgressEvent, ISceneLoaderPlugin, ISceneLoaderPluginAsync } from "babylonjs";
  1406. import { ViewerModel } from "babylonjs-viewer/model/viewerModel";
  1407. export class ObservablesManager {
  1408. /**
  1409. * Will notify when the scene was initialized
  1410. */
  1411. onSceneInitObservable: Observable<Scene>;
  1412. /**
  1413. * will notify when the engine was initialized
  1414. */
  1415. onEngineInitObservable: Observable<Engine>;
  1416. /**
  1417. * Will notify when a new model was added to the scene.
  1418. * Note that added does not neccessarily mean loaded!
  1419. */
  1420. onModelAddedObservable: Observable<ViewerModel>;
  1421. /**
  1422. * will notify after every model load
  1423. */
  1424. onModelLoadedObservable: Observable<ViewerModel>;
  1425. /**
  1426. * will notify when any model notify of progress
  1427. */
  1428. onModelLoadProgressObservable: Observable<SceneLoaderProgressEvent>;
  1429. /**
  1430. * will notify when any model load failed.
  1431. */
  1432. onModelLoadErrorObservable: Observable<{
  1433. message: string;
  1434. exception: any;
  1435. }>;
  1436. /**
  1437. * Will notify when a model was removed from the scene;
  1438. */
  1439. onModelRemovedObservable: Observable<ViewerModel>;
  1440. /**
  1441. * will notify when a new loader was initialized.
  1442. * Used mainly to know when a model starts loading.
  1443. */
  1444. onLoaderInitObservable: Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync>;
  1445. /**
  1446. * Observers registered here will be executed when the entire load process has finished.
  1447. */
  1448. onViewerInitDoneObservable: Observable<any>;
  1449. /**
  1450. * Functions added to this observable will be executed on each frame rendered.
  1451. */
  1452. onFrameRenderedObservable: Observable<any>;
  1453. constructor();
  1454. dispose(): void;
  1455. }
  1456. }
  1457. declare module 'babylonjs-viewer/configuration/configurationContainer' {
  1458. import { ViewerConfiguration } from 'babylonjs-viewer/configuration/configuration';
  1459. import { Color3, Scene } from 'babylonjs';
  1460. export class ConfigurationContainer {
  1461. configuration: ViewerConfiguration;
  1462. viewerId: string;
  1463. mainColor: Color3;
  1464. reflectionColor: Color3;
  1465. scene?: Scene;
  1466. }
  1467. }
  1468. declare module 'babylonjs-viewer/configuration/interfaces/modelConfiguration' {
  1469. import { IModelAnimationConfiguration } from "babylonjs-viewer/configuration/interfaces/modelAnimationConfiguration";
  1470. export interface IModelConfiguration {
  1471. id?: string;
  1472. url?: string;
  1473. root?: string;
  1474. file?: string | File;
  1475. loader?: string;
  1476. position?: {
  1477. x: number;
  1478. y: number;
  1479. z: number;
  1480. };
  1481. rotation?: {
  1482. x: number;
  1483. y: number;
  1484. z: number;
  1485. w?: number;
  1486. };
  1487. scaling?: {
  1488. x: number;
  1489. y: number;
  1490. z: number;
  1491. };
  1492. parentObjectIndex?: number;
  1493. castShadow?: boolean;
  1494. receiveShadows?: boolean;
  1495. normalize?: boolean | {
  1496. center?: boolean;
  1497. unitSize?: boolean;
  1498. parentIndex?: number;
  1499. };
  1500. title?: string;
  1501. subtitle?: string;
  1502. thumbnail?: string;
  1503. animation?: {
  1504. autoStart?: boolean | string;
  1505. playOnce?: boolean;
  1506. autoStartIndex?: number;
  1507. };
  1508. entryAnimation?: IModelAnimationConfiguration;
  1509. exitAnimation?: IModelAnimationConfiguration;
  1510. material?: {
  1511. directEnabled?: boolean;
  1512. directIntensity?: number;
  1513. emissiveIntensity?: number;
  1514. environmentIntensity?: number;
  1515. [propName: string]: any;
  1516. };
  1517. /**
  1518. * Rotation offset axis definition
  1519. */
  1520. rotationOffsetAxis?: {
  1521. x: number;
  1522. y: number;
  1523. z: number;
  1524. };
  1525. /**
  1526. * the offset angle
  1527. */
  1528. rotationOffsetAngle?: number;
  1529. loaderConfiguration?: {
  1530. maxLODsToLoad?: number;
  1531. progressiveLoading?: boolean;
  1532. };
  1533. }
  1534. }
  1535. declare module 'babylonjs-viewer/loader/plugins' {
  1536. import { TelemetryLoaderPlugin } from "babylonjs-viewer/loader/plugins/telemetryLoaderPlugin";
  1537. import { ILoaderPlugin } from "babylonjs-viewer/loader/plugins/loaderPlugin";
  1538. import { MSFTLodLoaderPlugin } from 'babylonjs-viewer/loader/plugins/msftLodLoaderPlugin';
  1539. import { ApplyMaterialConfigPlugin } from 'babylonjs-viewer/loader/plugins/applyMaterialConfig';
  1540. import { ExtendedMaterialLoaderPlugin } from 'babylonjs-viewer/loader/plugins/extendedMaterialLoaderPlugin';
  1541. export { TelemetryLoaderPlugin, ILoaderPlugin, MSFTLodLoaderPlugin, ApplyMaterialConfigPlugin, ExtendedMaterialLoaderPlugin };
  1542. /**
  1543. * Get a loader plugin according to its name.
  1544. * The plugin will be cached and will be reused if called for again.
  1545. *
  1546. * @param name the name of the plugin
  1547. */
  1548. export function getLoaderPluginByName(name: string): ILoaderPlugin;
  1549. /**
  1550. *
  1551. */
  1552. export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
  1553. }
  1554. declare module 'babylonjs-viewer/configuration/interfaces' {
  1555. export * from 'babylonjs-viewer/configuration/interfaces/cameraConfiguration';
  1556. export * from 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration';
  1557. export * from 'babylonjs-viewer/configuration/interfaces/defaultRenderingPipelineConfiguration';
  1558. export * from 'babylonjs-viewer/configuration/interfaces/groundConfiguration';
  1559. export * from 'babylonjs-viewer/configuration/interfaces/imageProcessingConfiguration';
  1560. export * from 'babylonjs-viewer/configuration/interfaces/lightConfiguration';
  1561. export * from 'babylonjs-viewer/configuration/interfaces/modelAnimationConfiguration';
  1562. export * from 'babylonjs-viewer/configuration/interfaces/modelConfiguration';
  1563. export * from 'babylonjs-viewer/configuration/interfaces/observersConfiguration';
  1564. export * from 'babylonjs-viewer/configuration/interfaces/sceneConfiguration';
  1565. export * from 'babylonjs-viewer/configuration/interfaces/sceneOptimizerConfiguration';
  1566. export * from 'babylonjs-viewer/configuration/interfaces/skyboxConfiguration';
  1567. export * from 'babylonjs-viewer/configuration/interfaces/templateConfiguration';
  1568. }
  1569. declare module 'babylonjs-viewer/templating/eventManager' {
  1570. import { EventCallback, TemplateManager } from "babylonjs-viewer/templating/templateManager";
  1571. /**
  1572. * The EventManager is in charge of registering user interctions with the viewer.
  1573. * It is used in the TemplateManager
  1574. */
  1575. export class EventManager {
  1576. constructor(_templateManager: TemplateManager);
  1577. /**
  1578. * Register a new callback to a specific template.
  1579. * The best example for the usage can be found in the DefaultViewer
  1580. *
  1581. * @param templateName the templateName to register the event to
  1582. * @param callback The callback to be executed
  1583. * @param eventType the type of event to register
  1584. * @param selector an optional selector. if not defined the parent object in the template will be selected
  1585. */
  1586. registerCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
  1587. /**
  1588. * This will remove a registered event from the defined template.
  1589. * Each one of the variables apart from the template name are optional, but one must be provided.
  1590. *
  1591. * @param templateName the templateName
  1592. * @param callback the callback to remove (optional)
  1593. * @param eventType the event type to remove (optional)
  1594. * @param selector the selector from which to remove the event (optional)
  1595. */
  1596. unregisterCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
  1597. /**
  1598. * Dispose the event manager
  1599. */
  1600. dispose(): void;
  1601. }
  1602. }
  1603. declare module 'babylonjs-viewer/labs/viewerLabs' {
  1604. import { PBREnvironment } from "babylonjs-viewer/labs/environmentSerializer";
  1605. import { ShadowLight, Vector3, Scene } from 'babylonjs';
  1606. /**
  1607. * The ViewerLabs class will hold functions that are not (!) backwards compatible.
  1608. * The APIs in all labs-related classes and configuration might change.
  1609. * Once stable, lab features will be moved to the publis API and configuration object.
  1610. */
  1611. export class ViewerLabs {
  1612. constructor(_scene: Scene);
  1613. assetsRootURL: string;
  1614. environment: PBREnvironment;
  1615. /**
  1616. * Loads an environment map from a given URL
  1617. * @param url URL of environment map
  1618. * @param onSuccess Callback fired after environment successfully applied to the scene
  1619. * @param onProgress Callback fired at progress events while loading the environment map
  1620. * @param onError Callback fired when the load fails
  1621. */
  1622. loadEnvironment(url: string, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1623. /**
  1624. * Loads an environment map from a given URL
  1625. * @param buffer ArrayBuffer containing environment map
  1626. * @param onSuccess Callback fired after environment successfully applied to the scene
  1627. * @param onProgress Callback fired at progress events while loading the environment map
  1628. * @param onError Callback fired when the load fails
  1629. */
  1630. loadEnvironment(buffer: ArrayBuffer, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1631. /**
  1632. * Sets the environment to an already loaded environment
  1633. * @param env PBREnvironment instance
  1634. * @param onSuccess Callback fired after environment successfully applied to the scene
  1635. * @param onProgress Callback fired at progress events while loading the environment map
  1636. * @param onError Callback fired when the load fails
  1637. */
  1638. loadEnvironment(env: PBREnvironment, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1639. /**
  1640. * Applies an `EnvironmentMapConfiguration` to the scene
  1641. * @param environmentMapConfiguration Environment map configuration to apply
  1642. */
  1643. applyEnvironmentMapConfiguration(rotationY?: number): void;
  1644. /**
  1645. * Get an environment asset url by using the configuration if the path is not absolute.
  1646. * @param url Asset url
  1647. * @returns The Asset url using the `environmentAssetsRootURL` if the url is not an absolute path.
  1648. */
  1649. getAssetUrl(url: string): string;
  1650. rotateShadowLight(shadowLight: ShadowLight, amount: number, point?: Vector3, axis?: Vector3, target?: Vector3): void;
  1651. }
  1652. }
  1653. declare module 'babylonjs-viewer/configuration/interfaces/modelAnimationConfiguration' {
  1654. /**
  1655. * Defines an animation to be applied to a model (translation, scale or rotation).
  1656. */
  1657. export interface IModelAnimationConfiguration {
  1658. /**
  1659. * Time of animation, in seconds
  1660. */
  1661. time?: number;
  1662. /**
  1663. * Scale to apply
  1664. */
  1665. scaling?: {
  1666. x: number;
  1667. y: number;
  1668. z: number;
  1669. };
  1670. /**
  1671. * Easing function to apply
  1672. */
  1673. easingFunction?: number;
  1674. /**
  1675. * An Easing mode to apply to the easing function
  1676. * See BABYLON.EasingFunction
  1677. */
  1678. easingMode?: number;
  1679. }
  1680. }
  1681. declare module 'babylonjs-viewer/loader/plugins/telemetryLoaderPlugin' {
  1682. import { ILoaderPlugin } from "babylonjs-viewer/loader/plugins/loaderPlugin";
  1683. import { ViewerModel } from "babylonjs-viewer/model/viewerModel";
  1684. import { ISceneLoaderPlugin, ISceneLoaderPluginAsync } from "babylonjs";
  1685. export class TelemetryLoaderPlugin implements ILoaderPlugin {
  1686. onInit(loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync, model: ViewerModel): void;
  1687. onLoaded(model: ViewerModel): void;
  1688. onError(message: string, exception: any): void;
  1689. onComplete(): void;
  1690. }
  1691. }
  1692. declare module 'babylonjs-viewer/loader/plugins/msftLodLoaderPlugin' {
  1693. import { ILoaderPlugin } from "babylonjs-viewer/loader/plugins/loaderPlugin";
  1694. import { ViewerModel } from "babylonjs-viewer/model/viewerModel";
  1695. import { ISceneLoaderPlugin, ISceneLoaderPluginAsync } from "babylonjs";
  1696. import { IGLTFLoaderExtension } from "babylonjs-loaders";
  1697. /**
  1698. * A loder plugin to use MSFT_lod extension correctly (glTF)
  1699. */
  1700. export class MSFTLodLoaderPlugin implements ILoaderPlugin {
  1701. onInit(loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync, model: ViewerModel): void;
  1702. onExtensionLoaded(extension: IGLTFLoaderExtension): void;
  1703. }
  1704. }
  1705. declare module 'babylonjs-viewer/loader/plugins/applyMaterialConfig' {
  1706. import { ILoaderPlugin } from "babylonjs-viewer/loader/plugins/loaderPlugin";
  1707. import { ViewerModel } from "babylonjs-viewer/model/viewerModel";
  1708. import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, Material } from "babylonjs";
  1709. /**
  1710. * Force-apply material configuration right after a material was loaded.
  1711. */
  1712. export class ApplyMaterialConfigPlugin implements ILoaderPlugin {
  1713. onInit(loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync, model: ViewerModel): void;
  1714. onMaterialLoaded(material: Material): void;
  1715. }
  1716. }
  1717. declare module 'babylonjs-viewer/loader/plugins/extendedMaterialLoaderPlugin' {
  1718. import { ILoaderPlugin } from "babylonjs-viewer/loader/plugins/loaderPlugin";
  1719. import { Material } from "babylonjs";
  1720. /**
  1721. * A (PBR) material will be extended using this function.
  1722. * This function will hold extra default configuration for the viewer, if not implemented in Babylon itself.
  1723. */
  1724. export class ExtendedMaterialLoaderPlugin implements ILoaderPlugin {
  1725. onMaterialLoaded(baseMaterial: Material): void;
  1726. }
  1727. }
  1728. declare module 'babylonjs-viewer/configuration/interfaces/cameraConfiguration' {
  1729. export interface ICameraConfiguration {
  1730. position?: {
  1731. x: number;
  1732. y: number;
  1733. z: number;
  1734. };
  1735. rotation?: {
  1736. x: number;
  1737. y: number;
  1738. z: number;
  1739. w: number;
  1740. };
  1741. fov?: number;
  1742. fovMode?: number;
  1743. minZ?: number;
  1744. maxZ?: number;
  1745. inertia?: number;
  1746. exposure?: number;
  1747. pinchPrecision?: number;
  1748. behaviors?: {
  1749. [name: string]: boolean | number | ICameraBehaviorConfiguration;
  1750. };
  1751. disableCameraControl?: boolean;
  1752. disableCtrlForPanning?: boolean;
  1753. disableAutoFocus?: boolean;
  1754. [propName: string]: any;
  1755. }
  1756. export interface ICameraBehaviorConfiguration {
  1757. type: number;
  1758. [propName: string]: any;
  1759. }
  1760. }
  1761. declare module 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration' {
  1762. /**
  1763. * The Color Grading Configuration groups the different settings used to define the color grading used in the viewer.
  1764. */
  1765. export interface IColorGradingConfiguration {
  1766. /**
  1767. * Transform data string, encoded as determined by transformDataFormat.
  1768. */
  1769. transformData: string;
  1770. /**
  1771. * The encoding format of TransformData (currently only raw-base16 is supported).
  1772. */
  1773. transformDataFormat: string;
  1774. /**
  1775. * The weight of the transform
  1776. */
  1777. transformWeight: number;
  1778. /**
  1779. * Color curve colorFilterHueGlobal value
  1780. */
  1781. colorFilterHueGlobal: number;
  1782. /**
  1783. * Color curve colorFilterHueShadows value
  1784. */
  1785. colorFilterHueShadows: number;
  1786. /**
  1787. * Color curve colorFilterHueMidtones value
  1788. */
  1789. colorFilterHueMidtones: number;
  1790. /**
  1791. * Color curve colorFilterHueHighlights value
  1792. */
  1793. colorFilterHueHighlights: number;
  1794. /**
  1795. * Color curve colorFilterDensityGlobal value
  1796. */
  1797. colorFilterDensityGlobal: number;
  1798. /**
  1799. * Color curve colorFilterDensityShadows value
  1800. */
  1801. colorFilterDensityShadows: number;
  1802. /**
  1803. * Color curve colorFilterDensityMidtones value
  1804. */
  1805. colorFilterDensityMidtones: number;
  1806. /**
  1807. * Color curve colorFilterDensityHighlights value
  1808. */
  1809. colorFilterDensityHighlights: number;
  1810. /**
  1811. * Color curve saturationGlobal value
  1812. */
  1813. saturationGlobal: number;
  1814. /**
  1815. * Color curve saturationShadows value
  1816. */
  1817. saturationShadows: number;
  1818. /**
  1819. * Color curve saturationMidtones value
  1820. */
  1821. saturationMidtones: number;
  1822. /**
  1823. * Color curve saturationHighlights value
  1824. */
  1825. saturationHighlights: number;
  1826. /**
  1827. * Color curve exposureGlobal value
  1828. */
  1829. exposureGlobal: number;
  1830. /**
  1831. * Color curve exposureShadows value
  1832. */
  1833. exposureShadows: number;
  1834. /**
  1835. * Color curve exposureMidtones value
  1836. */
  1837. exposureMidtones: number;
  1838. /**
  1839. * Color curve exposureHighlights value
  1840. */
  1841. exposureHighlights: number;
  1842. }
  1843. }
  1844. declare module 'babylonjs-viewer/configuration/interfaces/defaultRenderingPipelineConfiguration' {
  1845. import { DepthOfFieldEffectBlurLevel } from 'babylonjs';
  1846. export interface IDefaultRenderingPipelineConfiguration {
  1847. sharpenEnabled?: boolean;
  1848. bloomEnabled?: boolean;
  1849. bloomThreshold?: number;
  1850. depthOfFieldEnabled?: boolean;
  1851. depthOfFieldBlurLevel?: DepthOfFieldEffectBlurLevel;
  1852. fxaaEnabled?: boolean;
  1853. imageProcessingEnabled?: boolean;
  1854. defaultPipelineTextureType?: number;
  1855. bloomScale?: number;
  1856. chromaticAberrationEnabled?: boolean;
  1857. grainEnabled?: boolean;
  1858. bloomKernel?: number;
  1859. hardwareScaleLevel?: number;
  1860. bloomWeight?: number;
  1861. hdr?: boolean;
  1862. samples?: number;
  1863. glowLayerEnabled?: boolean;
  1864. }
  1865. }
  1866. declare module 'babylonjs-viewer/configuration/interfaces/groundConfiguration' {
  1867. export interface IGroundConfiguration {
  1868. size?: number;
  1869. receiveShadows?: boolean;
  1870. shadowLevel?: number;
  1871. shadowOnly?: boolean;
  1872. mirror?: boolean | {
  1873. sizeRatio?: number;
  1874. blurKernel?: number;
  1875. amount?: number;
  1876. fresnelWeight?: number;
  1877. fallOffDistance?: number;
  1878. textureType?: number;
  1879. };
  1880. texture?: string;
  1881. color?: {
  1882. r: number;
  1883. g: number;
  1884. b: number;
  1885. };
  1886. opacity?: number;
  1887. material?: {
  1888. [propName: string]: any;
  1889. };
  1890. }
  1891. }
  1892. declare module 'babylonjs-viewer/configuration/interfaces/imageProcessingConfiguration' {
  1893. export interface IImageProcessingConfiguration {
  1894. colorGradingEnabled?: boolean;
  1895. colorCurvesEnabled?: boolean;
  1896. colorCurves?: {
  1897. globalHue?: number;
  1898. globalDensity?: number;
  1899. globalSaturation?: number;
  1900. globalExposure?: number;
  1901. highlightsHue?: number;
  1902. highlightsDensity?: number;
  1903. highlightsSaturation?: number;
  1904. highlightsExposure?: number;
  1905. midtonesHue?: number;
  1906. midtonesDensity?: number;
  1907. midtonesSaturation?: number;
  1908. midtonesExposure?: number;
  1909. shadowsHue?: number;
  1910. shadowsDensity?: number;
  1911. shadowsSaturation?: number;
  1912. shadowsExposure?: number;
  1913. };
  1914. colorGradingWithGreenDepth?: boolean;
  1915. colorGradingBGR?: boolean;
  1916. exposure?: number;
  1917. toneMappingEnabled?: boolean;
  1918. contrast?: number;
  1919. vignetteEnabled?: boolean;
  1920. vignetteStretch?: number;
  1921. vignetteCentreX?: number;
  1922. vignetteCentreY?: number;
  1923. vignetteWeight?: number;
  1924. vignetteColor?: {
  1925. r: number;
  1926. g: number;
  1927. b: number;
  1928. a?: number;
  1929. };
  1930. vignetteCameraFov?: number;
  1931. vignetteBlendMode?: number;
  1932. vignetteM?: boolean;
  1933. applyByPostProcess?: boolean;
  1934. isEnabled?: boolean;
  1935. }
  1936. }
  1937. declare module 'babylonjs-viewer/configuration/interfaces/lightConfiguration' {
  1938. export interface ILightConfiguration {
  1939. type: number;
  1940. name?: string;
  1941. disabled?: boolean;
  1942. position?: {
  1943. x: number;
  1944. y: number;
  1945. z: number;
  1946. };
  1947. target?: {
  1948. x: number;
  1949. y: number;
  1950. z: number;
  1951. };
  1952. direction?: {
  1953. x: number;
  1954. y: number;
  1955. z: number;
  1956. };
  1957. diffuse?: {
  1958. r: number;
  1959. g: number;
  1960. b: number;
  1961. };
  1962. specular?: {
  1963. r: number;
  1964. g: number;
  1965. b: number;
  1966. };
  1967. intensity?: number;
  1968. intensityMode?: number;
  1969. radius?: number;
  1970. shadownEnabled?: boolean;
  1971. shadowConfig?: {
  1972. useBlurExponentialShadowMap?: boolean;
  1973. useBlurCloseExponentialShadowMap?: boolean;
  1974. useKernelBlur?: boolean;
  1975. blurKernel?: number;
  1976. blurScale?: number;
  1977. minZ?: number;
  1978. maxZ?: number;
  1979. frustumSize?: number;
  1980. angleScale?: number;
  1981. frustumEdgeFalloff?: number;
  1982. [propName: string]: any;
  1983. };
  1984. spotAngle?: number;
  1985. shadowFieldOfView?: number;
  1986. shadowBufferSize?: number;
  1987. shadowFrustumSize?: number;
  1988. shadowMinZ?: number;
  1989. shadowMaxZ?: number;
  1990. [propName: string]: any;
  1991. behaviors?: {
  1992. [name: string]: number | {
  1993. type: number;
  1994. [propName: string]: any;
  1995. };
  1996. };
  1997. }
  1998. }
  1999. declare module 'babylonjs-viewer/configuration/interfaces/observersConfiguration' {
  2000. export interface IObserversConfiguration {
  2001. onEngineInit?: string;
  2002. onSceneInit?: string;
  2003. onModelLoaded?: string;
  2004. }
  2005. }
  2006. declare module 'babylonjs-viewer/configuration/interfaces/sceneConfiguration' {
  2007. import { IImageProcessingConfiguration } from "babylonjs-viewer/configuration/interfaces/imageProcessingConfiguration";
  2008. import { IColorGradingConfiguration } from "babylonjs-viewer/configuration/interfaces/colorGradingConfiguration";
  2009. import { IGlowLayerOptions } from "babylonjs";
  2010. export interface ISceneConfiguration {
  2011. debug?: boolean;
  2012. clearColor?: {
  2013. r: number;
  2014. g: number;
  2015. b: number;
  2016. a: number;
  2017. };
  2018. mainColor?: {
  2019. r?: number;
  2020. g?: number;
  2021. b?: number;
  2022. };
  2023. imageProcessingConfiguration?: IImageProcessingConfiguration;
  2024. environmentTexture?: string;
  2025. colorGrading?: IColorGradingConfiguration;
  2026. environmentRotationY?: number;
  2027. /**
  2028. * Deprecated, please use default rendering pipeline
  2029. */
  2030. glow?: boolean | IGlowLayerOptions;
  2031. disableHdr?: boolean;
  2032. renderInBackground?: boolean;
  2033. disableCameraControl?: boolean;
  2034. animationPropertiesOverride?: {
  2035. [propName: string]: any;
  2036. };
  2037. defaultMaterial?: {
  2038. materialType: "standard" | "pbr";
  2039. [propName: string]: any;
  2040. };
  2041. flags?: {
  2042. shadowsEnabled?: boolean;
  2043. particlesEnabled?: boolean;
  2044. collisionsEnabled?: boolean;
  2045. lightsEnabled?: boolean;
  2046. texturesEnabled?: boolean;
  2047. lensFlaresEnabled?: boolean;
  2048. proceduralTexturesEnabled?: boolean;
  2049. renderTargetsEnabled?: boolean;
  2050. spritesEnabled?: boolean;
  2051. skeletonsEnabled?: boolean;
  2052. audioEnabled?: boolean;
  2053. };
  2054. }
  2055. }
  2056. declare module 'babylonjs-viewer/configuration/interfaces/sceneOptimizerConfiguration' {
  2057. export interface ISceneOptimizerConfiguration {
  2058. targetFrameRate?: number;
  2059. trackerDuration?: number;
  2060. autoGeneratePriorities?: boolean;
  2061. improvementMode?: boolean;
  2062. degradation?: string;
  2063. types?: {
  2064. texture?: ISceneOptimizerParameters;
  2065. hardwareScaling?: ISceneOptimizerParameters;
  2066. shadow?: ISceneOptimizerParameters;
  2067. postProcess?: ISceneOptimizerParameters;
  2068. lensFlare?: ISceneOptimizerParameters;
  2069. particles?: ISceneOptimizerParameters;
  2070. renderTarget?: ISceneOptimizerParameters;
  2071. mergeMeshes?: ISceneOptimizerParameters;
  2072. };
  2073. custom?: string;
  2074. }
  2075. export interface ISceneOptimizerParameters {
  2076. priority?: number;
  2077. maximumSize?: number;
  2078. step?: number;
  2079. }
  2080. }
  2081. declare module 'babylonjs-viewer/configuration/interfaces/skyboxConfiguration' {
  2082. import { IImageProcessingConfiguration } from "babylonjs-viewer/configuration/interfaces/imageProcessingConfiguration";
  2083. export interface ISkyboxConfiguration {
  2084. cubeTexture?: {
  2085. noMipMap?: boolean;
  2086. gammaSpace?: boolean;
  2087. url?: string | Array<string>;
  2088. };
  2089. color?: {
  2090. r: number;
  2091. g: number;
  2092. b: number;
  2093. };
  2094. pbr?: boolean;
  2095. scale?: number;
  2096. blur?: number;
  2097. material?: {
  2098. imageProcessingConfiguration?: IImageProcessingConfiguration;
  2099. [propName: string]: any;
  2100. };
  2101. infiniteDistance?: boolean;
  2102. }
  2103. }
  2104. declare module 'babylonjs-viewer/configuration/interfaces/templateConfiguration' {
  2105. /**
  2106. * A single template configuration object
  2107. */
  2108. export interface ITemplateConfiguration {
  2109. /**
  2110. * can be either the id of the template's html element or a URL.
  2111. * See - http://doc.babylonjs.com/extensions/the_templating_system#location-vs-html
  2112. */
  2113. location?: string;
  2114. /**
  2115. * If no location is provided you can provide here the raw html of this template.
  2116. * See http://doc.babylonjs.com/extensions/the_templating_system#location-vs-html
  2117. */
  2118. html?: string;
  2119. id?: string;
  2120. /**
  2121. * Parameters that will be delivered to the template and will render it accordingly.
  2122. */
  2123. params?: {
  2124. [key: string]: string | number | boolean | object;
  2125. };
  2126. /**
  2127. * Events to attach to this template.
  2128. * event name is the key. the value can either be a boolean (attach to the parent element)
  2129. * or a map of html id elements.
  2130. *
  2131. * See - http://doc.babylonjs.com/extensions/the_templating_system#event-binding
  2132. */
  2133. events?: {
  2134. pointerdown?: boolean | {
  2135. [id: string]: boolean;
  2136. };
  2137. pointerup?: boolean | {
  2138. [id: string]: boolean;
  2139. };
  2140. pointermove?: boolean | {
  2141. [id: string]: boolean;
  2142. };
  2143. pointerover?: boolean | {
  2144. [id: string]: boolean;
  2145. };
  2146. pointerout?: boolean | {
  2147. [id: string]: boolean;
  2148. };
  2149. pointerenter?: boolean | {
  2150. [id: string]: boolean;
  2151. };
  2152. pointerleave?: boolean | {
  2153. [id: string]: boolean;
  2154. };
  2155. pointercancel?: boolean | {
  2156. [id: string]: boolean;
  2157. };
  2158. click?: boolean | {
  2159. [id: string]: boolean;
  2160. };
  2161. dragstart?: boolean | {
  2162. [id: string]: boolean;
  2163. };
  2164. drop?: boolean | {
  2165. [id: string]: boolean;
  2166. };
  2167. [key: string]: boolean | {
  2168. [id: string]: boolean;
  2169. } | undefined;
  2170. };
  2171. }
  2172. }
  2173. declare module 'babylonjs-viewer/labs/environmentSerializer' {
  2174. import { Vector3 } from "babylonjs";
  2175. import { TextureCube } from 'babylonjs-viewer/labs/texture';
  2176. /**
  2177. * Spherical polynomial coefficients (counter part to spherical harmonic coefficients used in shader irradiance calculation)
  2178. * @ignoreChildren
  2179. */
  2180. export interface SphericalPolynomalCoefficients {
  2181. x: Vector3;
  2182. y: Vector3;
  2183. z: Vector3;
  2184. xx: Vector3;
  2185. yy: Vector3;
  2186. zz: Vector3;
  2187. yz: Vector3;
  2188. zx: Vector3;
  2189. xy: Vector3;
  2190. }
  2191. /**
  2192. * Wraps data and maps required for environments with physically based rendering
  2193. */
  2194. export interface PBREnvironment {
  2195. /**
  2196. * Spherical Polynomial Coefficients representing an irradiance map
  2197. */
  2198. irradiancePolynomialCoefficients: SphericalPolynomalCoefficients;
  2199. /**
  2200. * Specular cubemap
  2201. */
  2202. specularTexture?: TextureCube;
  2203. /**
  2204. * A scale factor applied to RGB values after reading from environment maps
  2205. */
  2206. textureIntensityScale: number;
  2207. }
  2208. /**
  2209. * Environment map representations: layouts, projections and approximations
  2210. */
  2211. export type MapType = 'irradiance_sh_coefficients_9' | 'cubemap_faces';
  2212. /**
  2213. * Image type used for environment map
  2214. */
  2215. export type ImageType = 'png';
  2216. /**
  2217. * A generic field in JSON that report's its type
  2218. */
  2219. export interface TypedObject<T> {
  2220. type: T;
  2221. }
  2222. /**
  2223. * Describes a range of bytes starting at byte pos (inclusive) and finishing at byte pos + length - 1
  2224. */
  2225. export interface ByteRange {
  2226. pos: number;
  2227. length: number;
  2228. }
  2229. /**
  2230. * Complete Spectre Environment JSON Descriptor
  2231. */
  2232. export interface EnvJsonDescriptor {
  2233. radiance: TypedObject<MapType>;
  2234. irradiance: TypedObject<MapType>;
  2235. specular: TypedObject<MapType>;
  2236. }
  2237. /**
  2238. * Spherical harmonic coefficients to provide an irradiance map
  2239. */
  2240. export interface IrradianceSHCoefficients9 extends TypedObject<MapType> {
  2241. l00: Array<number>;
  2242. l1_1: Array<number>;
  2243. l10: Array<number>;
  2244. l11: Array<number>;
  2245. l2_2: Array<number>;
  2246. l2_1: Array<number>;
  2247. l20: Array<number>;
  2248. l21: Array<number>;
  2249. l22: Array<number>;
  2250. }
  2251. /**
  2252. * A generic set of images, where the image content is specified by byte ranges in the mipmaps field
  2253. */
  2254. export interface ImageSet<T> extends TypedObject<MapType> {
  2255. imageType: ImageType;
  2256. width: number;
  2257. height: number;
  2258. mipmaps: Array<T>;
  2259. multiplier: number;
  2260. }
  2261. /**
  2262. * A set of cubemap faces
  2263. */
  2264. export type CubemapFaces = ImageSet<Array<ByteRange>>;
  2265. /**
  2266. * A single image containing an atlas of equirectangular-projection maps across all mip levels
  2267. */
  2268. export type EquirectangularMipmapAtlas = ImageSet<ByteRange>;
  2269. /**
  2270. * A static class proving methods to aid parsing Spectre environment files
  2271. */
  2272. export class EnvironmentDeserializer {
  2273. /**
  2274. * Parses an arraybuffer into a new PBREnvironment object
  2275. * @param arrayBuffer The arraybuffer of the Spectre environment file
  2276. * @return a PBREnvironment object
  2277. */
  2278. static Parse(arrayBuffer: ArrayBuffer): PBREnvironment;
  2279. }
  2280. }
  2281. declare module 'babylonjs-viewer/labs/texture' {
  2282. import { Scene, CubeTexture, BaseTexture } from "babylonjs";
  2283. /**
  2284. * WebGL Pixel Formats
  2285. */
  2286. export const enum PixelFormat {
  2287. DEPTH_COMPONENT = 6402,
  2288. ALPHA = 6406,
  2289. RGB = 6407,
  2290. RGBA = 6408,
  2291. LUMINANCE = 6409,
  2292. LUMINANCE_ALPHA = 6410,
  2293. }
  2294. /**
  2295. * WebGL Pixel Types
  2296. */
  2297. export const enum PixelType {
  2298. UNSIGNED_BYTE = 5121,
  2299. UNSIGNED_SHORT_4_4_4_4 = 32819,
  2300. UNSIGNED_SHORT_5_5_5_1 = 32820,
  2301. UNSIGNED_SHORT_5_6_5 = 33635,
  2302. }
  2303. /**
  2304. * WebGL Texture Magnification Filter
  2305. */
  2306. export const enum TextureMagFilter {
  2307. NEAREST = 9728,
  2308. LINEAR = 9729,
  2309. }
  2310. /**
  2311. * WebGL Texture Minification Filter
  2312. */
  2313. export const enum TextureMinFilter {
  2314. NEAREST = 9728,
  2315. LINEAR = 9729,
  2316. NEAREST_MIPMAP_NEAREST = 9984,
  2317. LINEAR_MIPMAP_NEAREST = 9985,
  2318. NEAREST_MIPMAP_LINEAR = 9986,
  2319. LINEAR_MIPMAP_LINEAR = 9987,
  2320. }
  2321. /**
  2322. * WebGL Texture Wrap Modes
  2323. */
  2324. export const enum TextureWrapMode {
  2325. REPEAT = 10497,
  2326. CLAMP_TO_EDGE = 33071,
  2327. MIRRORED_REPEAT = 33648,
  2328. }
  2329. /**
  2330. * Raw texture data and descriptor sufficient for WebGL texture upload
  2331. */
  2332. export interface TextureData {
  2333. /**
  2334. * Width of image
  2335. */
  2336. width: number;
  2337. /**
  2338. * Height of image
  2339. */
  2340. height: number;
  2341. /**
  2342. * Format of pixels in data
  2343. */
  2344. format: PixelFormat;
  2345. /**
  2346. * Row byte alignment of pixels in data
  2347. */
  2348. alignment: number;
  2349. /**
  2350. * Pixel data
  2351. */
  2352. data: ArrayBufferView;
  2353. }
  2354. /**
  2355. * Wraps sampling parameters for a WebGL texture
  2356. */
  2357. export interface SamplingParameters {
  2358. /**
  2359. * Magnification mode when upsampling from a WebGL texture
  2360. */
  2361. magFilter?: TextureMagFilter;
  2362. /**
  2363. * Minification mode when upsampling from a WebGL texture
  2364. */
  2365. minFilter?: TextureMinFilter;
  2366. /**
  2367. * X axis wrapping mode when sampling out of a WebGL texture bounds
  2368. */
  2369. wrapS?: TextureWrapMode;
  2370. /**
  2371. * Y axis wrapping mode when sampling out of a WebGL texture bounds
  2372. */
  2373. wrapT?: TextureWrapMode;
  2374. /**
  2375. * Anisotropic filtering samples
  2376. */
  2377. maxAnisotropy?: number;
  2378. }
  2379. /**
  2380. * Represents a valid WebGL texture source for use in texImage2D
  2381. */
  2382. export type TextureSource = TextureData | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
  2383. /**
  2384. * A generic set of texture mipmaps (where index 0 has the largest dimension)
  2385. */
  2386. export type Mipmaps<T> = Array<T>;
  2387. /**
  2388. * A set of 6 cubemap arranged in the order [+x, -x, +y, -y, +z, -z]
  2389. */
  2390. export type Faces<T> = Array<T>;
  2391. /**
  2392. * A set of texture mipmaps specifically for 2D textures in WebGL (where index 0 has the largest dimension)
  2393. */
  2394. export type Mipmaps2D = Mipmaps<TextureSource>;
  2395. /**
  2396. * A set of texture mipmaps specifically for cubemap textures in WebGL (where index 0 has the largest dimension)
  2397. */
  2398. export type MipmapsCube = Mipmaps<Faces<TextureSource>>;
  2399. /**
  2400. * A minimal WebGL cubemap descriptor
  2401. */
  2402. export class TextureCube {
  2403. internalFormat: PixelFormat;
  2404. type: PixelType;
  2405. source: MipmapsCube;
  2406. /**
  2407. * Returns the width of a face of the texture or 0 if not available
  2408. */
  2409. readonly Width: number;
  2410. /**
  2411. * Returns the height of a face of the texture or 0 if not available
  2412. */
  2413. readonly Height: number;
  2414. /**
  2415. * constructor
  2416. * @param internalFormat WebGL pixel format for the texture on the GPU
  2417. * @param type WebGL pixel type of the supplied data and texture on the GPU
  2418. * @param source An array containing mipmap levels of faces, where each mipmap level is an array of faces and each face is a TextureSource object
  2419. */
  2420. constructor(internalFormat: PixelFormat, type: PixelType, source?: MipmapsCube);
  2421. }
  2422. /**
  2423. * A static class providing methods to aid working with Bablyon textures.
  2424. */
  2425. export class TextureUtils {
  2426. /**
  2427. * A prefix used when storing a babylon texture object reference on a Spectre texture object
  2428. */
  2429. static BabylonTextureKeyPrefix: string;
  2430. /**
  2431. * Controls anisotropic filtering for deserialized textures.
  2432. */
  2433. static MaxAnisotropy: number;
  2434. /**
  2435. * Returns a BabylonCubeTexture instance from a Spectre texture cube, subject to sampling parameters.
  2436. * If such a texture has already been requested in the past, this texture will be returned, otherwise a new one will be created.
  2437. * The advantage of this is to enable working with texture objects without the need to initialize on the GPU until desired.
  2438. * @param scene A Babylon Scene instance
  2439. * @param textureCube A Spectre TextureCube object
  2440. * @param parameters WebGL texture sampling parameters
  2441. * @param automaticMipmaps Pass true to enable automatic mipmap generation where possible (requires power of images)
  2442. * @param environment Specifies that the texture will be used as an environment
  2443. * @param singleLod Specifies that the texture will be a singleLod (for environment)
  2444. * @return Babylon cube texture
  2445. */
  2446. static GetBabylonCubeTexture(scene: Scene, textureCube: TextureCube, automaticMipmaps: boolean, environment?: boolean, singleLod?: boolean): CubeTexture;
  2447. /**
  2448. * Applies Spectre SamplingParameters to a Babylon texture by directly setting texture parameters on the internal WebGLTexture as well as setting Babylon fields
  2449. * @param babylonTexture Babylon texture to apply texture to (requires the Babylon texture has an initialize _texture field)
  2450. * @param parameters Spectre SamplingParameters to apply
  2451. */
  2452. static ApplySamplingParameters(babylonTexture: BaseTexture, parameters: SamplingParameters): void;
  2453. /**
  2454. * Environment preprocessing dedicated value (Internal Use or Advanced only).
  2455. */
  2456. static EnvironmentLODScale: number;
  2457. /**
  2458. * Environment preprocessing dedicated value (Internal Use or Advanced only)..
  2459. */
  2460. static EnvironmentLODOffset: number;
  2461. }
  2462. }