babylon.viewer.module.d.ts 111 KB

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