babylon.viewer.d.ts 101 KB

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