babylon.viewer.d.ts 102 KB

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