babylon.viewer.d.ts 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505
  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. }
  1404. }
  1405. declare module BabylonViewer {
  1406. export interface IModelConfiguration {
  1407. id?: string;
  1408. url?: string;
  1409. root?: string;
  1410. file?: string | File;
  1411. loader?: string;
  1412. position?: {
  1413. x: number;
  1414. y: number;
  1415. z: number;
  1416. };
  1417. rotation?: {
  1418. x: number;
  1419. y: number;
  1420. z: number;
  1421. w?: number;
  1422. };
  1423. scaling?: {
  1424. x: number;
  1425. y: number;
  1426. z: number;
  1427. };
  1428. parentObjectIndex?: number;
  1429. castShadow?: boolean;
  1430. receiveShadows?: boolean;
  1431. normalize?: boolean | {
  1432. center?: boolean;
  1433. unitSize?: boolean;
  1434. parentIndex?: number;
  1435. };
  1436. title?: string;
  1437. subtitle?: string;
  1438. thumbnail?: string;
  1439. animation?: {
  1440. autoStart?: boolean | string;
  1441. playOnce?: boolean;
  1442. autoStartIndex?: number;
  1443. };
  1444. entryAnimation?: IModelAnimationConfiguration;
  1445. exitAnimation?: IModelAnimationConfiguration;
  1446. material?: {
  1447. directEnabled?: boolean;
  1448. directIntensity?: number;
  1449. emissiveIntensity?: number;
  1450. environmentIntensity?: number;
  1451. [propName: string]: any;
  1452. };
  1453. /**
  1454. * Rotation offset axis definition
  1455. */
  1456. rotationOffsetAxis?: {
  1457. x: number;
  1458. y: number;
  1459. z: number;
  1460. };
  1461. /**
  1462. * the offset angle
  1463. */
  1464. rotationOffsetAngle?: number;
  1465. loaderConfiguration?: {
  1466. maxLODsToLoad?: number;
  1467. progressiveLoading?: boolean;
  1468. };
  1469. }
  1470. }
  1471. declare module BabylonViewer {
  1472. /**
  1473. * Get a loader plugin according to its name.
  1474. * The plugin will be cached and will be reused if called for again.
  1475. *
  1476. * @param name the name of the plugin
  1477. */
  1478. export function getLoaderPluginByName(name: string): ILoaderPlugin;
  1479. /**
  1480. *
  1481. */
  1482. export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
  1483. }
  1484. declare module BabylonViewer {
  1485. export * from 'babylonjs-viewer/configuration/interfaces/cameraConfiguration';
  1486. export * from 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration';
  1487. export * from 'babylonjs-viewer/configuration/interfaces/defaultRenderingPipelineConfiguration';
  1488. export * from 'babylonjs-viewer/configuration/interfaces/groundConfiguration';
  1489. export * from 'babylonjs-viewer/configuration/interfaces/imageProcessingConfiguration';
  1490. export * from 'babylonjs-viewer/configuration/interfaces/lightConfiguration';
  1491. export * from 'babylonjs-viewer/configuration/interfaces/modelAnimationConfiguration';
  1492. export * from 'babylonjs-viewer/configuration/interfaces/modelConfiguration';
  1493. export * from 'babylonjs-viewer/configuration/interfaces/observersConfiguration';
  1494. export * from 'babylonjs-viewer/configuration/interfaces/sceneConfiguration';
  1495. export * from 'babylonjs-viewer/configuration/interfaces/sceneOptimizerConfiguration';
  1496. export * from 'babylonjs-viewer/configuration/interfaces/skyboxConfiguration';
  1497. export * from 'babylonjs-viewer/configuration/interfaces/templateConfiguration';
  1498. }
  1499. declare module BabylonViewer {
  1500. /**
  1501. * The EventManager is in charge of registering user interctions with the viewer.
  1502. * It is used in the TemplateManager
  1503. */
  1504. export class EventManager {
  1505. constructor(_templateManager: TemplateManager);
  1506. /**
  1507. * Register a new callback to a specific template.
  1508. * The best example for the usage can be found in the DefaultViewer
  1509. *
  1510. * @param templateName the templateName to register the event to
  1511. * @param callback The callback to be executed
  1512. * @param eventType the type of event to register
  1513. * @param selector an optional selector. if not defined the parent object in the template will be selected
  1514. */
  1515. registerCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
  1516. /**
  1517. * This will remove a registered event from the defined template.
  1518. * Each one of the variables apart from the template name are optional, but one must be provided.
  1519. *
  1520. * @param templateName the templateName
  1521. * @param callback the callback to remove (optional)
  1522. * @param eventType the event type to remove (optional)
  1523. * @param selector the selector from which to remove the event (optional)
  1524. */
  1525. unregisterCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
  1526. /**
  1527. * Dispose the event manager
  1528. */
  1529. dispose(): void;
  1530. }
  1531. }
  1532. declare module BabylonViewer {
  1533. /**
  1534. * The ViewerLabs class will hold functions that are not (!) backwards compatible.
  1535. * The APIs in all labs-related classes and configuration might change.
  1536. * Once stable, lab features will be moved to the publis API and configuration object.
  1537. */
  1538. export class ViewerLabs {
  1539. constructor(_scene: BABYLON.Scene);
  1540. assetsRootURL: string;
  1541. environment: PBREnvironment;
  1542. /**
  1543. * Loads an environment map from a given URL
  1544. * @param url URL of environment map
  1545. * @param onSuccess Callback fired after environment successfully applied to the scene
  1546. * @param onProgress Callback fired at progress events while loading the environment map
  1547. * @param onError Callback fired when the load fails
  1548. */
  1549. loadEnvironment(url: string, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1550. /**
  1551. * Loads an environment map from a given URL
  1552. * @param buffer ArrayBuffer containing environment map
  1553. * @param onSuccess Callback fired after environment successfully applied to the scene
  1554. * @param onProgress Callback fired at progress events while loading the environment map
  1555. * @param onError Callback fired when the load fails
  1556. */
  1557. loadEnvironment(buffer: ArrayBuffer, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1558. /**
  1559. * Sets the environment to an already loaded environment
  1560. * @param env PBREnvironment instance
  1561. * @param onSuccess Callback fired after environment successfully applied to the scene
  1562. * @param onProgress Callback fired at progress events while loading the environment map
  1563. * @param onError Callback fired when the load fails
  1564. */
  1565. loadEnvironment(env: PBREnvironment, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1566. /**
  1567. * Applies an `EnvironmentMapConfiguration` to the scene
  1568. * @param environmentMapConfiguration Environment map configuration to apply
  1569. */
  1570. applyEnvironmentMapConfiguration(rotationY?: number): void;
  1571. /**
  1572. * Get an environment asset url by using the configuration if the path is not absolute.
  1573. * @param url Asset url
  1574. * @returns The Asset url using the `environmentAssetsRootURL` if the url is not an absolute path.
  1575. */
  1576. getAssetUrl(url: string): string;
  1577. rotateShadowLight(shadowLight: BABYLON.ShadowLight, amount: number, point?: BABYLON.Vector3, axis?: BABYLON.Vector3, target?: BABYLON.Vector3): void;
  1578. }
  1579. }
  1580. declare module BabylonViewer {
  1581. /**
  1582. * Defines an animation to be applied to a model (translation, scale or rotation).
  1583. */
  1584. export interface IModelAnimationConfiguration {
  1585. /**
  1586. * Time of animation, in seconds
  1587. */
  1588. time?: number;
  1589. /**
  1590. * Scale to apply
  1591. */
  1592. scaling?: {
  1593. x: number;
  1594. y: number;
  1595. z: number;
  1596. };
  1597. /**
  1598. * Easing function to apply
  1599. */
  1600. easingFunction?: number;
  1601. /**
  1602. * An Easing mode to apply to the easing function
  1603. * See BABYLON.EasingFunction
  1604. */
  1605. easingMode?: number;
  1606. }
  1607. }
  1608. declare module BabylonViewer {
  1609. export class TelemetryLoaderPlugin implements ILoaderPlugin {
  1610. onInit(loader: BABYLON.ISceneLoaderPlugin | BABYLON.ISceneLoaderPluginAsync, model: ViewerModel): void;
  1611. onLoaded(model: ViewerModel): void;
  1612. onError(message: string, exception: any): void;
  1613. onComplete(): void;
  1614. }
  1615. }
  1616. declare module BabylonViewer {
  1617. /**
  1618. * A loder plugin to use MSFT_lod extension correctly (glTF)
  1619. */
  1620. export class MSFTLodLoaderPlugin implements ILoaderPlugin {
  1621. onInit(loader: BABYLON.ISceneLoaderPlugin | BABYLON.ISceneLoaderPluginAsync, model: ViewerModel): void;
  1622. onExtensionLoaded(extension: BABYLON.IGLTFLoaderExtension): void;
  1623. }
  1624. }
  1625. declare module BabylonViewer {
  1626. /**
  1627. * Force-apply material configuration right after a material was loaded.
  1628. */
  1629. export class ApplyMaterialConfigPlugin implements ILoaderPlugin {
  1630. onInit(loader: BABYLON.ISceneLoaderPlugin | BABYLON.ISceneLoaderPluginAsync, model: ViewerModel): void;
  1631. onMaterialLoaded(material: BABYLON.Material): void;
  1632. }
  1633. }
  1634. declare module BabylonViewer {
  1635. /**
  1636. * A (PBR) material will be extended using this function.
  1637. * This function will hold extra default configuration for the viewer, if not implemented in Babylon itself.
  1638. */
  1639. export class ExtendedMaterialLoaderPlugin implements ILoaderPlugin {
  1640. onMaterialLoaded(baseMaterial: BABYLON.Material): void;
  1641. }
  1642. }
  1643. declare module BabylonViewer {
  1644. export interface ICameraConfiguration {
  1645. position?: {
  1646. x: number;
  1647. y: number;
  1648. z: number;
  1649. };
  1650. rotation?: {
  1651. x: number;
  1652. y: number;
  1653. z: number;
  1654. w: number;
  1655. };
  1656. fov?: number;
  1657. fovMode?: number;
  1658. minZ?: number;
  1659. maxZ?: number;
  1660. inertia?: number;
  1661. exposure?: number;
  1662. pinchPrecision?: number;
  1663. behaviors?: {
  1664. [name: string]: boolean | number | ICameraBehaviorConfiguration;
  1665. };
  1666. disableCameraControl?: boolean;
  1667. disableCtrlForPanning?: boolean;
  1668. disableAutoFocus?: boolean;
  1669. [propName: string]: any;
  1670. }
  1671. export interface ICameraBehaviorConfiguration {
  1672. type: number;
  1673. [propName: string]: any;
  1674. }
  1675. }
  1676. declare module BabylonViewer {
  1677. /**
  1678. * The Color Grading Configuration groups the different settings used to define the color grading used in the viewer.
  1679. */
  1680. export interface IColorGradingConfiguration {
  1681. /**
  1682. * Transform data string, encoded as determined by transformDataFormat.
  1683. */
  1684. transformData: string;
  1685. /**
  1686. * The encoding format of TransformData (currently only raw-base16 is supported).
  1687. */
  1688. transformDataFormat: string;
  1689. /**
  1690. * The weight of the transform
  1691. */
  1692. transformWeight: number;
  1693. /**
  1694. * Color curve colorFilterHueGlobal value
  1695. */
  1696. colorFilterHueGlobal: number;
  1697. /**
  1698. * Color curve colorFilterHueShadows value
  1699. */
  1700. colorFilterHueShadows: number;
  1701. /**
  1702. * Color curve colorFilterHueMidtones value
  1703. */
  1704. colorFilterHueMidtones: number;
  1705. /**
  1706. * Color curve colorFilterHueHighlights value
  1707. */
  1708. colorFilterHueHighlights: number;
  1709. /**
  1710. * Color curve colorFilterDensityGlobal value
  1711. */
  1712. colorFilterDensityGlobal: number;
  1713. /**
  1714. * Color curve colorFilterDensityShadows value
  1715. */
  1716. colorFilterDensityShadows: number;
  1717. /**
  1718. * Color curve colorFilterDensityMidtones value
  1719. */
  1720. colorFilterDensityMidtones: number;
  1721. /**
  1722. * Color curve colorFilterDensityHighlights value
  1723. */
  1724. colorFilterDensityHighlights: number;
  1725. /**
  1726. * Color curve saturationGlobal value
  1727. */
  1728. saturationGlobal: number;
  1729. /**
  1730. * Color curve saturationShadows value
  1731. */
  1732. saturationShadows: number;
  1733. /**
  1734. * Color curve saturationMidtones value
  1735. */
  1736. saturationMidtones: number;
  1737. /**
  1738. * Color curve saturationHighlights value
  1739. */
  1740. saturationHighlights: number;
  1741. /**
  1742. * Color curve exposureGlobal value
  1743. */
  1744. exposureGlobal: number;
  1745. /**
  1746. * Color curve exposureShadows value
  1747. */
  1748. exposureShadows: number;
  1749. /**
  1750. * Color curve exposureMidtones value
  1751. */
  1752. exposureMidtones: number;
  1753. /**
  1754. * Color curve exposureHighlights value
  1755. */
  1756. exposureHighlights: number;
  1757. }
  1758. }
  1759. declare module BabylonViewer {
  1760. export interface IDefaultRenderingPipelineConfiguration {
  1761. sharpenEnabled?: boolean;
  1762. bloomEnabled?: boolean;
  1763. bloomThreshold?: number;
  1764. depthOfFieldEnabled?: boolean;
  1765. depthOfFieldBlurLevel?: BABYLON.DepthOfFieldEffectBlurLevel;
  1766. fxaaEnabled?: boolean;
  1767. imageProcessingEnabled?: boolean;
  1768. defaultPipelineTextureType?: number;
  1769. bloomScale?: number;
  1770. chromaticAberrationEnabled?: boolean;
  1771. grainEnabled?: boolean;
  1772. bloomKernel?: number;
  1773. hardwareScaleLevel?: number;
  1774. bloomWeight?: number;
  1775. hdr?: boolean;
  1776. samples?: number;
  1777. glowLayerEnabled?: boolean;
  1778. }
  1779. }
  1780. declare module BabylonViewer {
  1781. export interface IGroundConfiguration {
  1782. size?: number;
  1783. receiveShadows?: boolean;
  1784. shadowLevel?: number;
  1785. shadowOnly?: boolean;
  1786. mirror?: boolean | {
  1787. sizeRatio?: number;
  1788. blurKernel?: number;
  1789. amount?: number;
  1790. fresnelWeight?: number;
  1791. fallOffDistance?: number;
  1792. textureType?: number;
  1793. };
  1794. texture?: string;
  1795. color?: {
  1796. r: number;
  1797. g: number;
  1798. b: number;
  1799. };
  1800. opacity?: number;
  1801. material?: {
  1802. [propName: string]: any;
  1803. };
  1804. }
  1805. }
  1806. declare module BabylonViewer {
  1807. export interface IImageProcessingConfiguration {
  1808. colorGradingEnabled?: boolean;
  1809. colorCurvesEnabled?: boolean;
  1810. colorCurves?: {
  1811. globalHue?: number;
  1812. globalDensity?: number;
  1813. globalSaturation?: number;
  1814. globalExposure?: number;
  1815. highlightsHue?: number;
  1816. highlightsDensity?: number;
  1817. highlightsSaturation?: number;
  1818. highlightsExposure?: number;
  1819. midtonesHue?: number;
  1820. midtonesDensity?: number;
  1821. midtonesSaturation?: number;
  1822. midtonesExposure?: number;
  1823. shadowsHue?: number;
  1824. shadowsDensity?: number;
  1825. shadowsSaturation?: number;
  1826. shadowsExposure?: number;
  1827. };
  1828. colorGradingWithGreenDepth?: boolean;
  1829. colorGradingBGR?: boolean;
  1830. exposure?: number;
  1831. toneMappingEnabled?: boolean;
  1832. contrast?: number;
  1833. vignetteEnabled?: boolean;
  1834. vignetteStretch?: number;
  1835. vignetteCentreX?: number;
  1836. vignetteCentreY?: number;
  1837. vignetteWeight?: number;
  1838. vignetteColor?: {
  1839. r: number;
  1840. g: number;
  1841. b: number;
  1842. a?: number;
  1843. };
  1844. vignetteCameraFov?: number;
  1845. vignetteBlendMode?: number;
  1846. vignetteM?: boolean;
  1847. applyByPostProcess?: boolean;
  1848. isEnabled?: boolean;
  1849. }
  1850. }
  1851. declare module BabylonViewer {
  1852. export interface ILightConfiguration {
  1853. type: number;
  1854. name?: string;
  1855. disabled?: boolean;
  1856. position?: {
  1857. x: number;
  1858. y: number;
  1859. z: number;
  1860. };
  1861. target?: {
  1862. x: number;
  1863. y: number;
  1864. z: number;
  1865. };
  1866. direction?: {
  1867. x: number;
  1868. y: number;
  1869. z: number;
  1870. };
  1871. diffuse?: {
  1872. r: number;
  1873. g: number;
  1874. b: number;
  1875. };
  1876. specular?: {
  1877. r: number;
  1878. g: number;
  1879. b: number;
  1880. };
  1881. intensity?: number;
  1882. intensityMode?: number;
  1883. radius?: number;
  1884. shadownEnabled?: boolean;
  1885. shadowConfig?: {
  1886. useBlurExponentialShadowMap?: boolean;
  1887. useBlurCloseExponentialShadowMap?: boolean;
  1888. useKernelBlur?: boolean;
  1889. blurKernel?: number;
  1890. blurScale?: number;
  1891. minZ?: number;
  1892. maxZ?: number;
  1893. frustumSize?: number;
  1894. angleScale?: number;
  1895. frustumEdgeFalloff?: number;
  1896. [propName: string]: any;
  1897. };
  1898. spotAngle?: number;
  1899. shadowFieldOfView?: number;
  1900. shadowBufferSize?: number;
  1901. shadowFrustumSize?: number;
  1902. shadowMinZ?: number;
  1903. shadowMaxZ?: number;
  1904. [propName: string]: any;
  1905. behaviors?: {
  1906. [name: string]: number | {
  1907. type: number;
  1908. [propName: string]: any;
  1909. };
  1910. };
  1911. }
  1912. }
  1913. declare module BabylonViewer {
  1914. export interface IObserversConfiguration {
  1915. onEngineInit?: string;
  1916. onSceneInit?: string;
  1917. onModelLoaded?: string;
  1918. }
  1919. }
  1920. declare module BabylonViewer {
  1921. export interface ISceneConfiguration {
  1922. debug?: boolean;
  1923. clearColor?: {
  1924. r: number;
  1925. g: number;
  1926. b: number;
  1927. a: number;
  1928. };
  1929. mainColor?: {
  1930. r?: number;
  1931. g?: number;
  1932. b?: number;
  1933. };
  1934. imageProcessingConfiguration?: IImageProcessingConfiguration;
  1935. environmentTexture?: string;
  1936. colorGrading?: IColorGradingConfiguration;
  1937. environmentRotationY?: number;
  1938. /**
  1939. * Deprecated, please use default rendering pipeline
  1940. */
  1941. glow?: boolean | BABYLON.IGlowLayerOptions;
  1942. disableHdr?: boolean;
  1943. renderInBackground?: boolean;
  1944. disableCameraControl?: boolean;
  1945. animationPropertiesOverride?: {
  1946. [propName: string]: any;
  1947. };
  1948. defaultMaterial?: {
  1949. materialType: "standard" | "pbr";
  1950. [propName: string]: any;
  1951. };
  1952. flags?: {
  1953. shadowsEnabled?: boolean;
  1954. particlesEnabled?: boolean;
  1955. collisionsEnabled?: boolean;
  1956. lightsEnabled?: boolean;
  1957. texturesEnabled?: boolean;
  1958. lensFlaresEnabled?: boolean;
  1959. proceduralTexturesEnabled?: boolean;
  1960. renderTargetsEnabled?: boolean;
  1961. spritesEnabled?: boolean;
  1962. skeletonsEnabled?: boolean;
  1963. audioEnabled?: boolean;
  1964. };
  1965. }
  1966. }
  1967. declare module BabylonViewer {
  1968. export interface ISceneOptimizerConfiguration {
  1969. targetFrameRate?: number;
  1970. trackerDuration?: number;
  1971. autoGeneratePriorities?: boolean;
  1972. improvementMode?: boolean;
  1973. degradation?: string;
  1974. types?: {
  1975. texture?: ISceneOptimizerParameters;
  1976. hardwareScaling?: ISceneOptimizerParameters;
  1977. shadow?: ISceneOptimizerParameters;
  1978. postProcess?: ISceneOptimizerParameters;
  1979. lensFlare?: ISceneOptimizerParameters;
  1980. particles?: ISceneOptimizerParameters;
  1981. renderTarget?: ISceneOptimizerParameters;
  1982. mergeMeshes?: ISceneOptimizerParameters;
  1983. };
  1984. custom?: string;
  1985. }
  1986. export interface ISceneOptimizerParameters {
  1987. priority?: number;
  1988. maximumSize?: number;
  1989. step?: number;
  1990. }
  1991. }
  1992. declare module BabylonViewer {
  1993. export interface ISkyboxConfiguration {
  1994. cubeTexture?: {
  1995. noMipMap?: boolean;
  1996. gammaSpace?: boolean;
  1997. url?: string | Array<string>;
  1998. };
  1999. color?: {
  2000. r: number;
  2001. g: number;
  2002. b: number;
  2003. };
  2004. pbr?: boolean;
  2005. scale?: number;
  2006. blur?: number;
  2007. material?: {
  2008. imageProcessingConfiguration?: IImageProcessingConfiguration;
  2009. [propName: string]: any;
  2010. };
  2011. infiniteDistance?: boolean;
  2012. }
  2013. }
  2014. declare module BabylonViewer {
  2015. /**
  2016. * A single template configuration object
  2017. */
  2018. export interface ITemplateConfiguration {
  2019. /**
  2020. * can be either the id of the template's html element or a URL.
  2021. * See - http://doc.babylonjs.com/extensions/the_templating_system#location-vs-html
  2022. */
  2023. location?: string;
  2024. /**
  2025. * If no location is provided you can provide here the raw html of this template.
  2026. * See http://doc.babylonjs.com/extensions/the_templating_system#location-vs-html
  2027. */
  2028. html?: string;
  2029. id?: string;
  2030. /**
  2031. * Parameters that will be delivered to the template and will render it accordingly.
  2032. */
  2033. params?: {
  2034. [key: string]: string | number | boolean | object;
  2035. };
  2036. /**
  2037. * Events to attach to this template.
  2038. * event name is the key. the value can either be a boolean (attach to the parent element)
  2039. * or a map of html id elements.
  2040. *
  2041. * See - http://doc.babylonjs.com/extensions/the_templating_system#event-binding
  2042. */
  2043. events?: {
  2044. pointerdown?: boolean | {
  2045. [id: string]: boolean;
  2046. };
  2047. pointerup?: boolean | {
  2048. [id: string]: boolean;
  2049. };
  2050. pointermove?: boolean | {
  2051. [id: string]: boolean;
  2052. };
  2053. pointerover?: boolean | {
  2054. [id: string]: boolean;
  2055. };
  2056. pointerout?: boolean | {
  2057. [id: string]: boolean;
  2058. };
  2059. pointerenter?: boolean | {
  2060. [id: string]: boolean;
  2061. };
  2062. pointerleave?: boolean | {
  2063. [id: string]: boolean;
  2064. };
  2065. pointercancel?: boolean | {
  2066. [id: string]: boolean;
  2067. };
  2068. click?: boolean | {
  2069. [id: string]: boolean;
  2070. };
  2071. dragstart?: boolean | {
  2072. [id: string]: boolean;
  2073. };
  2074. drop?: boolean | {
  2075. [id: string]: boolean;
  2076. };
  2077. [key: string]: boolean | {
  2078. [id: string]: boolean;
  2079. } | undefined;
  2080. };
  2081. }
  2082. }
  2083. declare module BabylonViewer {
  2084. /**
  2085. * Spherical polynomial coefficients (counter part to spherical harmonic coefficients used in shader irradiance calculation)
  2086. * @ignoreChildren
  2087. */
  2088. export interface SphericalPolynomalCoefficients {
  2089. x: BABYLON.Vector3;
  2090. y: BABYLON.Vector3;
  2091. z: BABYLON.Vector3;
  2092. xx: BABYLON.Vector3;
  2093. yy: BABYLON.Vector3;
  2094. zz: BABYLON.Vector3;
  2095. yz: BABYLON.Vector3;
  2096. zx: BABYLON.Vector3;
  2097. xy: BABYLON.Vector3;
  2098. }
  2099. /**
  2100. * Wraps data and maps required for environments with physically based rendering
  2101. */
  2102. export interface PBREnvironment {
  2103. /**
  2104. * Spherical Polynomial Coefficients representing an irradiance map
  2105. */
  2106. irradiancePolynomialCoefficients: SphericalPolynomalCoefficients;
  2107. /**
  2108. * Specular cubemap
  2109. */
  2110. specularTexture?: TextureCube;
  2111. /**
  2112. * A scale factor applied to RGB values after reading from environment maps
  2113. */
  2114. textureIntensityScale: number;
  2115. }
  2116. /**
  2117. * Environment map representations: layouts, projections and approximations
  2118. */
  2119. export type MapType = 'irradiance_sh_coefficients_9' | 'cubemap_faces';
  2120. /**
  2121. * Image type used for environment map
  2122. */
  2123. export type ImageType = 'png';
  2124. /**
  2125. * A generic field in JSON that report's its type
  2126. */
  2127. export interface TypedObject<T> {
  2128. type: T;
  2129. }
  2130. /**
  2131. * Describes a range of bytes starting at byte pos (inclusive) and finishing at byte pos + length - 1
  2132. */
  2133. export interface ByteRange {
  2134. pos: number;
  2135. length: number;
  2136. }
  2137. /**
  2138. * Complete Spectre Environment JSON Descriptor
  2139. */
  2140. export interface EnvJsonDescriptor {
  2141. radiance: TypedObject<MapType>;
  2142. irradiance: TypedObject<MapType>;
  2143. specular: TypedObject<MapType>;
  2144. }
  2145. /**
  2146. * Spherical harmonic coefficients to provide an irradiance map
  2147. */
  2148. export interface IrradianceSHCoefficients9 extends TypedObject<MapType> {
  2149. l00: Array<number>;
  2150. l1_1: Array<number>;
  2151. l10: Array<number>;
  2152. l11: Array<number>;
  2153. l2_2: Array<number>;
  2154. l2_1: Array<number>;
  2155. l20: Array<number>;
  2156. l21: Array<number>;
  2157. l22: Array<number>;
  2158. }
  2159. /**
  2160. * A generic set of images, where the image content is specified by byte ranges in the mipmaps field
  2161. */
  2162. export interface ImageSet<T> extends TypedObject<MapType> {
  2163. imageType: ImageType;
  2164. width: number;
  2165. height: number;
  2166. mipmaps: Array<T>;
  2167. multiplier: number;
  2168. }
  2169. /**
  2170. * A set of cubemap faces
  2171. */
  2172. export type CubemapFaces = ImageSet<Array<ByteRange>>;
  2173. /**
  2174. * A single image containing an atlas of equirectangular-projection maps across all mip levels
  2175. */
  2176. export type EquirectangularMipmapAtlas = ImageSet<ByteRange>;
  2177. /**
  2178. * A static class proving methods to aid parsing Spectre environment files
  2179. */
  2180. export class EnvironmentDeserializer {
  2181. /**
  2182. * Parses an arraybuffer into a new PBREnvironment object
  2183. * @param arrayBuffer The arraybuffer of the Spectre environment file
  2184. * @return a PBREnvironment object
  2185. */
  2186. static Parse(arrayBuffer: ArrayBuffer): PBREnvironment;
  2187. }
  2188. }
  2189. declare module BabylonViewer {
  2190. /**
  2191. * WebGL Pixel Formats
  2192. */
  2193. export const enum PixelFormat {
  2194. DEPTH_COMPONENT = 6402,
  2195. ALPHA = 6406,
  2196. RGB = 6407,
  2197. RGBA = 6408,
  2198. LUMINANCE = 6409,
  2199. LUMINANCE_ALPHA = 6410,
  2200. }
  2201. /**
  2202. * WebGL Pixel Types
  2203. */
  2204. export const enum PixelType {
  2205. UNSIGNED_BYTE = 5121,
  2206. UNSIGNED_SHORT_4_4_4_4 = 32819,
  2207. UNSIGNED_SHORT_5_5_5_1 = 32820,
  2208. UNSIGNED_SHORT_5_6_5 = 33635,
  2209. }
  2210. /**
  2211. * WebGL Texture Magnification Filter
  2212. */
  2213. export const enum TextureMagFilter {
  2214. NEAREST = 9728,
  2215. LINEAR = 9729,
  2216. }
  2217. /**
  2218. * WebGL Texture Minification Filter
  2219. */
  2220. export const enum TextureMinFilter {
  2221. NEAREST = 9728,
  2222. LINEAR = 9729,
  2223. NEAREST_MIPMAP_NEAREST = 9984,
  2224. LINEAR_MIPMAP_NEAREST = 9985,
  2225. NEAREST_MIPMAP_LINEAR = 9986,
  2226. LINEAR_MIPMAP_LINEAR = 9987,
  2227. }
  2228. /**
  2229. * WebGL Texture Wrap Modes
  2230. */
  2231. export const enum TextureWrapMode {
  2232. REPEAT = 10497,
  2233. CLAMP_TO_EDGE = 33071,
  2234. MIRRORED_REPEAT = 33648,
  2235. }
  2236. /**
  2237. * Raw texture data and descriptor sufficient for WebGL texture upload
  2238. */
  2239. export interface TextureData {
  2240. /**
  2241. * Width of image
  2242. */
  2243. width: number;
  2244. /**
  2245. * Height of image
  2246. */
  2247. height: number;
  2248. /**
  2249. * Format of pixels in data
  2250. */
  2251. format: PixelFormat;
  2252. /**
  2253. * Row byte alignment of pixels in data
  2254. */
  2255. alignment: number;
  2256. /**
  2257. * Pixel data
  2258. */
  2259. data: ArrayBufferView;
  2260. }
  2261. /**
  2262. * Wraps sampling parameters for a WebGL texture
  2263. */
  2264. export interface SamplingParameters {
  2265. /**
  2266. * Magnification mode when upsampling from a WebGL texture
  2267. */
  2268. magFilter?: TextureMagFilter;
  2269. /**
  2270. * Minification mode when upsampling from a WebGL texture
  2271. */
  2272. minFilter?: TextureMinFilter;
  2273. /**
  2274. * X axis wrapping mode when sampling out of a WebGL texture bounds
  2275. */
  2276. wrapS?: TextureWrapMode;
  2277. /**
  2278. * Y axis wrapping mode when sampling out of a WebGL texture bounds
  2279. */
  2280. wrapT?: TextureWrapMode;
  2281. /**
  2282. * Anisotropic filtering samples
  2283. */
  2284. maxAnisotropy?: number;
  2285. }
  2286. /**
  2287. * Represents a valid WebGL texture source for use in texImage2D
  2288. */
  2289. export type TextureSource = TextureData | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
  2290. /**
  2291. * A generic set of texture mipmaps (where index 0 has the largest dimension)
  2292. */
  2293. export type Mipmaps<T> = Array<T>;
  2294. /**
  2295. * A set of 6 cubemap arranged in the order [+x, -x, +y, -y, +z, -z]
  2296. */
  2297. export type Faces<T> = Array<T>;
  2298. /**
  2299. * A set of texture mipmaps specifically for 2D textures in WebGL (where index 0 has the largest dimension)
  2300. */
  2301. export type Mipmaps2D = Mipmaps<TextureSource>;
  2302. /**
  2303. * A set of texture mipmaps specifically for cubemap textures in WebGL (where index 0 has the largest dimension)
  2304. */
  2305. export type MipmapsCube = Mipmaps<Faces<TextureSource>>;
  2306. /**
  2307. * A minimal WebGL cubemap descriptor
  2308. */
  2309. export class TextureCube {
  2310. internalFormat: PixelFormat;
  2311. type: PixelType;
  2312. source: MipmapsCube;
  2313. /**
  2314. * Returns the width of a face of the texture or 0 if not available
  2315. */
  2316. readonly Width: number;
  2317. /**
  2318. * Returns the height of a face of the texture or 0 if not available
  2319. */
  2320. readonly Height: number;
  2321. /**
  2322. * constructor
  2323. * @param internalFormat WebGL pixel format for the texture on the GPU
  2324. * @param type WebGL pixel type of the supplied data and texture on the GPU
  2325. * @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
  2326. */
  2327. constructor(internalFormat: PixelFormat, type: PixelType, source?: MipmapsCube);
  2328. }
  2329. /**
  2330. * A static class providing methods to aid working with Bablyon textures.
  2331. */
  2332. export class TextureUtils {
  2333. /**
  2334. * A prefix used when storing a babylon texture object reference on a Spectre texture object
  2335. */
  2336. static BabylonTextureKeyPrefix: string;
  2337. /**
  2338. * Controls anisotropic filtering for deserialized textures.
  2339. */
  2340. static MaxAnisotropy: number;
  2341. /**
  2342. * Returns a BabylonCubeTexture instance from a Spectre texture cube, subject to sampling parameters.
  2343. * If such a texture has already been requested in the past, this texture will be returned, otherwise a new one will be created.
  2344. * The advantage of this is to enable working with texture objects without the need to initialize on the GPU until desired.
  2345. * @param scene A Babylon BABYLON.Scene instance
  2346. * @param textureCube A Spectre TextureCube object
  2347. * @param parameters WebGL texture sampling parameters
  2348. * @param automaticMipmaps Pass true to enable automatic mipmap generation where possible (requires power of images)
  2349. * @param environment Specifies that the texture will be used as an environment
  2350. * @param singleLod Specifies that the texture will be a singleLod (for environment)
  2351. * @return Babylon cube texture
  2352. */
  2353. static GetBabylonCubeTexture(scene: BABYLON.Scene, textureCube: TextureCube, automaticMipmaps: boolean, environment?: boolean, singleLod?: boolean): BABYLON.CubeTexture;
  2354. /**
  2355. * Applies Spectre SamplingParameters to a Babylon texture by directly setting texture parameters on the internal WebGLTexture as well as setting Babylon fields
  2356. * @param babylonTexture Babylon texture to apply texture to (requires the Babylon texture has an initialize _texture field)
  2357. * @param parameters Spectre SamplingParameters to apply
  2358. */
  2359. static ApplySamplingParameters(babylonTexture: BABYLON.BaseTexture, parameters: SamplingParameters): void;
  2360. /**
  2361. * Environment preprocessing dedicated value (Internal Use or Advanced only).
  2362. */
  2363. static EnvironmentLODScale: number;
  2364. /**
  2365. * Environment preprocessing dedicated value (Internal Use or Advanced only)..
  2366. */
  2367. static EnvironmentLODOffset: number;
  2368. }
  2369. }