babylon.viewer.d.ts 101 KB

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