babylon.viewer.d.ts 101 KB

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