babylon.viewer.d.ts 99 KB

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