babylon.viewer.d.ts 93 KB

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