babylon.viewer.d.ts 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289
  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. hdr?: boolean;
  1021. samples?: number;
  1022. glowLayerEnabled?: boolean;
  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. /**
  1150. * Deprecated, please use default rendering pipeline
  1151. */
  1152. glow?: boolean | BABYLON.IGlowLayerOptions;
  1153. disableHdr?: boolean;
  1154. renderInBackground?: boolean;
  1155. disableCameraControl?: boolean;
  1156. animationPropertiesOverride?: {
  1157. [propName: string]: any;
  1158. };
  1159. defaultMaterial?: {
  1160. materialType: "standard" | "pbr";
  1161. [propName: string]: any;
  1162. };
  1163. flags?: {
  1164. shadowsEnabled?: boolean;
  1165. particlesEnabled?: boolean;
  1166. collisionsEnabled?: boolean;
  1167. lightsEnabled?: boolean;
  1168. texturesEnabled?: boolean;
  1169. lensFlaresEnabled?: boolean;
  1170. proceduralTexturesEnabled?: boolean;
  1171. renderTargetsEnabled?: boolean;
  1172. spritesEnabled?: boolean;
  1173. skeletonsEnabled?: boolean;
  1174. audioEnabled?: boolean;
  1175. };
  1176. }
  1177. /**
  1178. * The Color Grading Configuration groups the different settings used to define the color grading used in the viewer.
  1179. */
  1180. export interface IColorGradingConfiguration {
  1181. /**
  1182. * Transform data string, encoded as determined by transformDataFormat.
  1183. */
  1184. transformData: string;
  1185. /**
  1186. * The encoding format of TransformData (currently only raw-base16 is supported).
  1187. */
  1188. transformDataFormat: string;
  1189. /**
  1190. * The weight of the transform
  1191. */
  1192. transformWeight: number;
  1193. /**
  1194. * Color curve colorFilterHueGlobal value
  1195. */
  1196. colorFilterHueGlobal: number;
  1197. /**
  1198. * Color curve colorFilterHueShadows value
  1199. */
  1200. colorFilterHueShadows: number;
  1201. /**
  1202. * Color curve colorFilterHueMidtones value
  1203. */
  1204. colorFilterHueMidtones: number;
  1205. /**
  1206. * Color curve colorFilterHueHighlights value
  1207. */
  1208. colorFilterHueHighlights: number;
  1209. /**
  1210. * Color curve colorFilterDensityGlobal value
  1211. */
  1212. colorFilterDensityGlobal: number;
  1213. /**
  1214. * Color curve colorFilterDensityShadows value
  1215. */
  1216. colorFilterDensityShadows: number;
  1217. /**
  1218. * Color curve colorFilterDensityMidtones value
  1219. */
  1220. colorFilterDensityMidtones: number;
  1221. /**
  1222. * Color curve colorFilterDensityHighlights value
  1223. */
  1224. colorFilterDensityHighlights: number;
  1225. /**
  1226. * Color curve saturationGlobal value
  1227. */
  1228. saturationGlobal: number;
  1229. /**
  1230. * Color curve saturationShadows value
  1231. */
  1232. saturationShadows: number;
  1233. /**
  1234. * Color curve saturationMidtones value
  1235. */
  1236. saturationMidtones: number;
  1237. /**
  1238. * Color curve saturationHighlights value
  1239. */
  1240. saturationHighlights: number;
  1241. /**
  1242. * Color curve exposureGlobal value
  1243. */
  1244. exposureGlobal: number;
  1245. /**
  1246. * Color curve exposureShadows value
  1247. */
  1248. exposureShadows: number;
  1249. /**
  1250. * Color curve exposureMidtones value
  1251. */
  1252. exposureMidtones: number;
  1253. /**
  1254. * Color curve exposureHighlights value
  1255. */
  1256. exposureHighlights: number;
  1257. }
  1258. export interface ISceneOptimizerConfiguration {
  1259. targetFrameRate?: number;
  1260. trackerDuration?: number;
  1261. autoGeneratePriorities?: boolean;
  1262. improvementMode?: boolean;
  1263. degradation?: string;
  1264. types?: {
  1265. texture?: ISceneOptimizerParameters;
  1266. hardwareScaling?: ISceneOptimizerParameters;
  1267. shadow?: ISceneOptimizerParameters;
  1268. postProcess?: ISceneOptimizerParameters;
  1269. lensFlare?: ISceneOptimizerParameters;
  1270. particles?: ISceneOptimizerParameters;
  1271. renderTarget?: ISceneOptimizerParameters;
  1272. mergeMeshes?: ISceneOptimizerParameters;
  1273. };
  1274. custom?: string;
  1275. }
  1276. export interface IObserversConfiguration {
  1277. onEngineInit?: string;
  1278. onSceneInit?: string;
  1279. onModelLoaded?: string;
  1280. }
  1281. export interface ICameraConfiguration {
  1282. position?: {
  1283. x: number;
  1284. y: number;
  1285. z: number;
  1286. };
  1287. rotation?: {
  1288. x: number;
  1289. y: number;
  1290. z: number;
  1291. w: number;
  1292. };
  1293. fov?: number;
  1294. fovMode?: number;
  1295. minZ?: number;
  1296. maxZ?: number;
  1297. inertia?: number;
  1298. exposure?: number;
  1299. pinchPrecision?: number;
  1300. behaviors?: {
  1301. [name: string]: number | {
  1302. type: number;
  1303. [propName: string]: any;
  1304. };
  1305. };
  1306. disableCameraControl?: boolean;
  1307. disableCtrlForPanning?: boolean;
  1308. disableAutoFocus?: boolean;
  1309. [propName: string]: any;
  1310. }
  1311. export interface ILightConfiguration {
  1312. type: number;
  1313. name?: string;
  1314. disabled?: boolean;
  1315. position?: {
  1316. x: number;
  1317. y: number;
  1318. z: number;
  1319. };
  1320. target?: {
  1321. x: number;
  1322. y: number;
  1323. z: number;
  1324. };
  1325. direction?: {
  1326. x: number;
  1327. y: number;
  1328. z: number;
  1329. };
  1330. diffuse?: {
  1331. r: number;
  1332. g: number;
  1333. b: number;
  1334. };
  1335. specular?: {
  1336. r: number;
  1337. g: number;
  1338. b: number;
  1339. };
  1340. intensity?: number;
  1341. intensityMode?: number;
  1342. radius?: number;
  1343. shadownEnabled?: boolean;
  1344. shadowConfig?: {
  1345. useBlurExponentialShadowMap?: boolean;
  1346. useBlurCloseExponentialShadowMap?: boolean;
  1347. useKernelBlur?: boolean;
  1348. blurKernel?: number;
  1349. blurScale?: number;
  1350. minZ?: number;
  1351. maxZ?: number;
  1352. frustumSize?: number;
  1353. angleScale?: number;
  1354. frustumEdgeFalloff?: number;
  1355. [propName: string]: any;
  1356. };
  1357. spotAngle?: number;
  1358. shadowFieldOfView?: number;
  1359. shadowBufferSize?: number;
  1360. shadowFrustumSize?: number;
  1361. shadowMinZ?: number;
  1362. shadowMaxZ?: number;
  1363. [propName: string]: any;
  1364. behaviors?: {
  1365. [name: string]: number | {
  1366. type: number;
  1367. [propName: string]: any;
  1368. };
  1369. };
  1370. }
  1371. export interface ISceneOptimizerParameters {
  1372. priority?: number;
  1373. maximumSize?: number;
  1374. step?: number;
  1375. }
  1376. export interface IImageProcessingConfiguration {
  1377. colorGradingEnabled?: boolean;
  1378. colorCurvesEnabled?: boolean;
  1379. colorCurves?: {
  1380. globalHue?: number;
  1381. globalDensity?: number;
  1382. globalSaturation?: number;
  1383. globalExposure?: number;
  1384. highlightsHue?: number;
  1385. highlightsDensity?: number;
  1386. highlightsSaturation?: number;
  1387. highlightsExposure?: number;
  1388. midtonesHue?: number;
  1389. midtonesDensity?: number;
  1390. midtonesSaturation?: number;
  1391. midtonesExposure?: number;
  1392. shadowsHue?: number;
  1393. shadowsDensity?: number;
  1394. shadowsSaturation?: number;
  1395. shadowsExposure?: number;
  1396. };
  1397. colorGradingWithGreenDepth?: boolean;
  1398. colorGradingBGR?: boolean;
  1399. exposure?: number;
  1400. toneMappingEnabled?: boolean;
  1401. contrast?: number;
  1402. vignetteEnabled?: boolean;
  1403. vignetteStretch?: number;
  1404. vignetteCentreX?: number;
  1405. vignetteCentreY?: number;
  1406. vignetteWeight?: number;
  1407. vignetteColor?: {
  1408. r: number;
  1409. g: number;
  1410. b: number;
  1411. a?: number;
  1412. };
  1413. vignetteCameraFov?: number;
  1414. vignetteBlendMode?: number;
  1415. vignetteM?: boolean;
  1416. applyByPostProcess?: boolean;
  1417. isEnabled?: boolean;
  1418. }
  1419. }
  1420. declare module BabylonViewer {
  1421. /**
  1422. * A single template configuration object
  1423. */
  1424. export interface ITemplateConfiguration {
  1425. /**
  1426. * can be either the id of the template's html element or a URL.
  1427. * See - http://doc.babylonjs.com/extensions/the_templating_system#location-vs-html
  1428. */
  1429. location?: string;
  1430. /**
  1431. * If no location is provided you can provide here the raw html of this template.
  1432. * See http://doc.babylonjs.com/extensions/the_templating_system#location-vs-html
  1433. */
  1434. html?: string;
  1435. id?: string;
  1436. /**
  1437. * Parameters that will be delivered to the template and will render it accordingly.
  1438. */
  1439. params?: {
  1440. [key: string]: string | number | boolean | object;
  1441. };
  1442. /**
  1443. * Events to attach to this template.
  1444. * event name is the key. the value can either be a boolean (attach to the parent element)
  1445. * or a map of html id elements.
  1446. *
  1447. * See - http://doc.babylonjs.com/extensions/the_templating_system#event-binding
  1448. */
  1449. events?: {
  1450. pointerdown?: boolean | {
  1451. [id: string]: boolean;
  1452. };
  1453. pointerup?: boolean | {
  1454. [id: string]: boolean;
  1455. };
  1456. pointermove?: boolean | {
  1457. [id: string]: boolean;
  1458. };
  1459. pointerover?: boolean | {
  1460. [id: string]: boolean;
  1461. };
  1462. pointerout?: boolean | {
  1463. [id: string]: boolean;
  1464. };
  1465. pointerenter?: boolean | {
  1466. [id: string]: boolean;
  1467. };
  1468. pointerleave?: boolean | {
  1469. [id: string]: boolean;
  1470. };
  1471. pointercancel?: boolean | {
  1472. [id: string]: boolean;
  1473. };
  1474. click?: boolean | {
  1475. [id: string]: boolean;
  1476. };
  1477. dragstart?: boolean | {
  1478. [id: string]: boolean;
  1479. };
  1480. drop?: boolean | {
  1481. [id: string]: boolean;
  1482. };
  1483. [key: string]: boolean | {
  1484. [id: string]: boolean;
  1485. } | undefined;
  1486. };
  1487. }
  1488. /**
  1489. * The object sent when an event is triggered
  1490. */
  1491. export interface EventCallback {
  1492. event: Event;
  1493. template: Template;
  1494. selector: string;
  1495. payload?: any;
  1496. }
  1497. /**
  1498. * The template manager, a member of the viewer class, will manage the viewer's templates and generate the HTML.
  1499. * The template manager managers a single viewer and can be seen as the collection of all sub-templates of the viewer.
  1500. */
  1501. export class TemplateManager {
  1502. containerElement: HTMLElement;
  1503. /**
  1504. * Will be triggered when any template is initialized
  1505. */
  1506. onTemplateInit: BABYLON.Observable<Template>;
  1507. /**
  1508. * Will be triggered when any template is fully loaded
  1509. */
  1510. onTemplateLoaded: BABYLON.Observable<Template>;
  1511. /**
  1512. * Will be triggered when a template state changes
  1513. */
  1514. onTemplateStateChange: BABYLON.Observable<Template>;
  1515. /**
  1516. * Will be triggered when all templates finished loading
  1517. */
  1518. onAllLoaded: BABYLON.Observable<TemplateManager>;
  1519. /**
  1520. * Will be triggered when any event on any template is triggered.
  1521. */
  1522. onEventTriggered: BABYLON.Observable<EventCallback>;
  1523. /**
  1524. * This template manager's event manager. In charge of callback registrations to native event types
  1525. */
  1526. eventManager: EventManager;
  1527. constructor(containerElement: HTMLElement);
  1528. /**
  1529. * Initialize the template(s) for the viewer. Called bay the Viewer class
  1530. * @param templates the templates to be used to initialize the main template
  1531. */
  1532. initTemplate(templates: {
  1533. [key: string]: ITemplateConfiguration;
  1534. }): Promise<void>;
  1535. /**
  1536. * Get the canvas in the template tree.
  1537. * There must be one and only one canvas inthe template.
  1538. */
  1539. getCanvas(): HTMLCanvasElement | null;
  1540. /**
  1541. * Get a specific template from the template tree
  1542. * @param name the name of the template to load
  1543. */
  1544. getTemplate(name: string): Template | undefined;
  1545. /**
  1546. * Dispose the template manager
  1547. */
  1548. dispose(): void;
  1549. }
  1550. /**
  1551. * This class represents a single template in the viewer's template tree.
  1552. * An example for a template is a single canvas, an overlay (containing sub-templates) or the navigation bar.
  1553. * A template is injected using the template manager in the correct position.
  1554. * The template is rendered using Handlebars and can use Handlebars' features (such as parameter injection)
  1555. *
  1556. * For further information please refer to the documentation page, https://doc.babylonjs.com
  1557. */
  1558. export class Template {
  1559. name: string;
  1560. /**
  1561. * Will be triggered when the template is loaded
  1562. */
  1563. onLoaded: BABYLON.Observable<Template>;
  1564. /**
  1565. * will be triggered when the template is appended to the tree
  1566. */
  1567. onAppended: BABYLON.Observable<Template>;
  1568. /**
  1569. * Will be triggered when the template's state changed (shown, hidden)
  1570. */
  1571. onStateChange: BABYLON.Observable<Template>;
  1572. /**
  1573. * Will be triggered when an event is triggered on ths template.
  1574. * The event is a native browser event (like mouse or pointer events)
  1575. */
  1576. onEventTriggered: BABYLON.Observable<EventCallback>;
  1577. /**
  1578. * is the template loaded?
  1579. */
  1580. isLoaded: boolean;
  1581. /**
  1582. * This is meant to be used to track the show and hide functions.
  1583. * This is NOT (!!) a flag to check if the element is actually visible to the user.
  1584. */
  1585. isShown: boolean;
  1586. /**
  1587. * Is this template a part of the HTML tree (the template manager injected it)
  1588. */
  1589. isInHtmlTree: boolean;
  1590. /**
  1591. * The HTML element containing this template
  1592. */
  1593. parent: HTMLElement;
  1594. /**
  1595. * A promise that is fulfilled when the template finished loading.
  1596. */
  1597. initPromise: Promise<Template>;
  1598. constructor(name: string, _configuration: ITemplateConfiguration);
  1599. /**
  1600. * Some templates have parameters (like background color for example).
  1601. * The parameters are provided to Handlebars which in turn generates the template.
  1602. * This function will update the template with the new parameters
  1603. *
  1604. * Note that when updating parameters the events will be registered again (after being cleared).
  1605. *
  1606. * @param params the new template parameters
  1607. */
  1608. updateParams(params: {
  1609. [key: string]: string | number | boolean | object;
  1610. }, append?: boolean): void;
  1611. /**
  1612. * Get the template'S configuration
  1613. */
  1614. readonly configuration: ITemplateConfiguration;
  1615. /**
  1616. * A template can be a parent element for other templates or HTML elements.
  1617. * This function will deliver all child HTML elements of this template.
  1618. */
  1619. getChildElements(): Array<string>;
  1620. /**
  1621. * Appending the template to a parent HTML element.
  1622. * If a parent is already set and you wish to replace the old HTML with new one, forceRemove should be true.
  1623. * @param parent the parent to which the template is added
  1624. * @param forceRemove if the parent already exists, shoud the template be removed from it?
  1625. */
  1626. appendTo(parent: HTMLElement, forceRemove?: boolean): void;
  1627. /**
  1628. * Show the template using the provided visibilityFunction, or natively using display: flex.
  1629. * The provided function returns a promise that should be fullfilled when the element is shown.
  1630. * Since it is a promise async operations are more than possible.
  1631. * See the default viewer for an opacity example.
  1632. * @param visibilityFunction The function to execute to show the template.
  1633. */
  1634. show(visibilityFunction?: (template: Template) => Promise<Template>): Promise<Template>;
  1635. /**
  1636. * Hide the template using the provided visibilityFunction, or natively using display: none.
  1637. * The provided function returns a promise that should be fullfilled when the element is hidden.
  1638. * Since it is a promise async operations are more than possible.
  1639. * See the default viewer for an opacity example.
  1640. * @param visibilityFunction The function to execute to show the template.
  1641. */
  1642. hide(visibilityFunction?: (template: Template) => Promise<Template>): Promise<Template>;
  1643. /**
  1644. * Dispose this template
  1645. */
  1646. dispose(): void;
  1647. }
  1648. }
  1649. declare module BabylonViewer {
  1650. /**
  1651. * This interface describes the structure of the variable sent with the configuration observables of the scene manager.
  1652. * O - the type of object we are dealing with (Light, BABYLON.ArcRotateCamera, BABYLON.Scene, etc')
  1653. * T - the configuration type
  1654. */
  1655. export interface IPostConfigurationCallback<OBJ, CONF> {
  1656. newConfiguration: CONF;
  1657. sceneManager: SceneManager;
  1658. object: OBJ;
  1659. model?: ViewerModel;
  1660. }
  1661. export class SceneManager {
  1662. /**
  1663. * Will notify when the scene was initialized
  1664. */
  1665. onSceneInitObservable: BABYLON.Observable<BABYLON.Scene>;
  1666. /**
  1667. * Will notify after the scene was configured. Can be used to further configure the scene
  1668. */
  1669. onSceneConfiguredObservable: BABYLON.Observable<IPostConfigurationCallback<BABYLON.Scene, ISceneConfiguration>>;
  1670. /**
  1671. * Will notify after the scene optimized was configured. Can be used to further configure the scene optimizer
  1672. */
  1673. onSceneOptimizerConfiguredObservable: BABYLON.Observable<IPostConfigurationCallback<BABYLON.SceneOptimizer, ISceneOptimizerConfiguration | boolean>>;
  1674. /**
  1675. * Will notify after the camera was configured. Can be used to further configure the camera
  1676. */
  1677. onCameraConfiguredObservable: BABYLON.Observable<IPostConfigurationCallback<BABYLON.ArcRotateCamera, ICameraConfiguration>>;
  1678. /**
  1679. * Will notify after the lights were configured. Can be used to further configure lights
  1680. */
  1681. onLightsConfiguredObservable: BABYLON.Observable<IPostConfigurationCallback<Array<BABYLON.Light>, {
  1682. [name: string]: ILightConfiguration | boolean;
  1683. }>>;
  1684. /**
  1685. * Will notify after the model(s) were configured. Can be used to further configure models
  1686. */
  1687. onModelsConfiguredObservable: BABYLON.Observable<IPostConfigurationCallback<Array<ViewerModel>, IModelConfiguration>>;
  1688. /**
  1689. * Will notify after the envirnoment was configured. Can be used to further configure the environment
  1690. */
  1691. onEnvironmentConfiguredObservable: BABYLON.Observable<IPostConfigurationCallback<BABYLON.EnvironmentHelper, {
  1692. skybox?: ISkyboxConfiguration | boolean;
  1693. ground?: IGroundConfiguration | boolean;
  1694. }>>;
  1695. /**
  1696. * The Babylon BABYLON.Scene of this viewer
  1697. */
  1698. scene: BABYLON.Scene;
  1699. /**
  1700. * The camera used in this viewer
  1701. */
  1702. camera: BABYLON.ArcRotateCamera;
  1703. /**
  1704. * Babylon's scene optimizer
  1705. */
  1706. sceneOptimizer: BABYLON.SceneOptimizer;
  1707. /**
  1708. * Models displayed in this viewer.
  1709. */
  1710. models: Array<ViewerModel>;
  1711. /**
  1712. * Babylon's environment helper of this viewer
  1713. */
  1714. environmentHelper: BABYLON.EnvironmentHelper;
  1715. protected _defaultHighpTextureType: number;
  1716. protected _shadowGeneratorBias: number;
  1717. protected _defaultPipelineTextureType: number;
  1718. /**
  1719. * The maximum number of shadows supported by the curent viewer
  1720. */
  1721. protected _maxShadows: number;
  1722. /**
  1723. * The labs variable consists of objects that will have their API change.
  1724. * Please be careful when using labs in production.
  1725. */
  1726. labs: ViewerLabs;
  1727. readonly defaultRenderingPipeline: BABYLON.Nullable<BABYLON.DefaultRenderingPipeline>;
  1728. constructor(_viewer: AbstractViewer);
  1729. /**
  1730. * Returns a boolean representing HDR support
  1731. */
  1732. readonly isHdrSupported: boolean;
  1733. /**
  1734. * Return the main color defined in the configuration.
  1735. */
  1736. readonly mainColor: BABYLON.Color3;
  1737. readonly reflectionColor: BABYLON.Color3;
  1738. animationBlendingEnabled: boolean;
  1739. /**
  1740. * Should shadows be rendered every frame, or only once and stop.
  1741. * This can be used to optimize a scene.
  1742. *
  1743. * Not that the shadows will NOT disapear but will remain in place.
  1744. * @param process if true shadows will be updated once every frame. if false they will stop being updated.
  1745. */
  1746. processShadows: boolean;
  1747. groundEnabled: boolean;
  1748. /**
  1749. * sets wether the reflection is disabled.
  1750. */
  1751. groundMirrorEnabled: boolean;
  1752. defaultRenderingPipelineEnabled: boolean;
  1753. /**
  1754. * Sets the engine flags to unlock all babylon features.
  1755. * Can also be configured using the scene.flags configuration object
  1756. */
  1757. unlockBabylonFeatures(): void;
  1758. /**
  1759. * initialize the scene. Calling this function again will dispose the old scene, if exists.
  1760. */
  1761. initScene(sceneConfiguration?: ISceneConfiguration, optimizerConfiguration?: boolean | ISceneOptimizerConfiguration): Promise<BABYLON.Scene>;
  1762. clearScene(clearModels?: boolean, clearLights?: boolean): void;
  1763. /**
  1764. * This will update the scene's configuration, including camera, lights, environment.
  1765. * @param newConfiguration the delta that should be configured. This includes only the changes
  1766. * @param globalConfiguration The global configuration object, after the new configuration was merged into it
  1767. */
  1768. updateConfiguration(newConfiguration: Partial<ViewerConfiguration>, globalConfiguration: ViewerConfiguration): void;
  1769. bloomEnabled: boolean;
  1770. fxaaEnabled: boolean;
  1771. /**
  1772. * internally configure the scene using the provided configuration.
  1773. * The scene will not be recreated, but just updated.
  1774. * @param sceneConfig the (new) scene configuration
  1775. */
  1776. protected _configureScene(sceneConfig: ISceneConfiguration): void;
  1777. /**
  1778. * Configure the scene optimizer.
  1779. * The existing scene optimizer will be disposed and a new one will be created.
  1780. * @param optimizerConfig the (new) optimizer configuration
  1781. */
  1782. protected _configureOptimizer(optimizerConfig: ISceneOptimizerConfiguration | boolean): void;
  1783. /**
  1784. * (Re) configure the camera. The camera will only be created once and from this point will only be reconfigured.
  1785. * @param cameraConfig the new camera configuration
  1786. * @param model optionally use the model to configure the camera.
  1787. */
  1788. protected _configureCamera(cameraConfig?: ICameraConfiguration): void;
  1789. protected _configureEnvironment(skyboxConifguration?: ISkyboxConfiguration | boolean, groundConfiguration?: IGroundConfiguration | boolean): Promise<BABYLON.Scene> | undefined;
  1790. /**
  1791. * configure the lights.
  1792. *
  1793. * @param lightsConfiguration the (new) light(s) configuration
  1794. * @param model optionally use the model to configure the camera.
  1795. */
  1796. protected _configureLights(lightsConfiguration?: {
  1797. [name: string]: ILightConfiguration | boolean;
  1798. }): void;
  1799. /**
  1800. * Gets the shadow map blur kernel according to the light configuration.
  1801. * @param light The light used to generate the shadows
  1802. * @param bufferSize The size of the shadow map
  1803. * @return the kernel blur size
  1804. */
  1805. getBlurKernel(light: BABYLON.IShadowLight, bufferSize: number): number;
  1806. /**
  1807. * Alters render settings to reduce features based on hardware feature limitations
  1808. * @param enableHDR Allows the viewer to run in HDR mode.
  1809. */
  1810. protected _handleHardwareLimitations(enableHDR?: boolean): void;
  1811. /**
  1812. * Dispoe the entire viewer including the scene and the engine
  1813. */
  1814. dispose(): void;
  1815. }
  1816. }
  1817. declare module BabylonViewer {
  1818. /**
  1819. * The configuration loader will load the configuration object from any source and will use the defined mapper to
  1820. * parse the object and return a conform ViewerConfiguration.
  1821. * It is a private member of the scene.
  1822. */
  1823. export class ConfigurationLoader {
  1824. constructor(_enableCache?: boolean);
  1825. /**
  1826. * load a configuration object that is defined in the initial configuration provided.
  1827. * The viewer configuration can extend different types of configuration objects and have an extra configuration defined.
  1828. *
  1829. * @param initConfig the initial configuration that has the definitions of further configuration to load.
  1830. * @param callback an optional callback that will be called sync, if noconfiguration needs to be loaded or configuration is payload-only
  1831. * @returns A promise that delivers the extended viewer configuration, when done.
  1832. */
  1833. loadConfiguration(initConfig?: ViewerConfiguration, callback?: (config: ViewerConfiguration) => void): Promise<ViewerConfiguration>;
  1834. /**
  1835. * Dispose the configuration loader. This will cancel file requests, if active.
  1836. */
  1837. dispose(): void;
  1838. }
  1839. }
  1840. declare module BabylonViewer {
  1841. /**
  1842. * The EventManager is in charge of registering user interctions with the viewer.
  1843. * It is used in the TemplateManager
  1844. */
  1845. export class EventManager {
  1846. constructor(_templateManager: TemplateManager);
  1847. /**
  1848. * Register a new callback to a specific template.
  1849. * The best example for the usage can be found in the DefaultViewer
  1850. *
  1851. * @param templateName the templateName to register the event to
  1852. * @param callback The callback to be executed
  1853. * @param eventType the type of event to register
  1854. * @param selector an optional selector. if not defined the parent object in the template will be selected
  1855. */
  1856. registerCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
  1857. /**
  1858. * This will remove a registered event from the defined template.
  1859. * Each one of the variables apart from the template name are optional, but one must be provided.
  1860. *
  1861. * @param templateName the templateName
  1862. * @param callback the callback to remove (optional)
  1863. * @param eventType the event type to remove (optional)
  1864. * @param selector the selector from which to remove the event (optional)
  1865. */
  1866. unregisterCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
  1867. /**
  1868. * Dispose the event manager
  1869. */
  1870. dispose(): void;
  1871. }
  1872. }
  1873. declare module BabylonViewer {
  1874. /**
  1875. * The ViewerLabs class will hold functions that are not (!) backwards compatible.
  1876. * The APIs in all labs-related classes and configuration might change.
  1877. * Once stable, lab features will be moved to the publis API and configuration object.
  1878. */
  1879. export class ViewerLabs {
  1880. constructor(_sceneManager: SceneManager);
  1881. assetsRootURL: string;
  1882. environment: PBREnvironment;
  1883. /**
  1884. * Loads an environment map from a given URL
  1885. * @param url URL of environment map
  1886. * @param onSuccess Callback fired after environment successfully applied to the scene
  1887. * @param onProgress Callback fired at progress events while loading the environment map
  1888. * @param onError Callback fired when the load fails
  1889. */
  1890. loadEnvironment(url: string, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1891. /**
  1892. * Loads an environment map from a given URL
  1893. * @param buffer ArrayBuffer containing environment map
  1894. * @param onSuccess Callback fired after environment successfully applied to the scene
  1895. * @param onProgress Callback fired at progress events while loading the environment map
  1896. * @param onError Callback fired when the load fails
  1897. */
  1898. loadEnvironment(buffer: ArrayBuffer, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1899. /**
  1900. * Sets the environment to an already loaded environment
  1901. * @param env PBREnvironment instance
  1902. * @param onSuccess Callback fired after environment successfully applied to the scene
  1903. * @param onProgress Callback fired at progress events while loading the environment map
  1904. * @param onError Callback fired when the load fails
  1905. */
  1906. loadEnvironment(env: PBREnvironment, onSuccess?: (env: PBREnvironment) => void, onProgress?: (bytesLoaded: number, bytesTotal: number) => void, onError?: (e: any) => void): void;
  1907. /**
  1908. * Applies an `EnvironmentMapConfiguration` to the scene
  1909. * @param environmentMapConfiguration Environment map configuration to apply
  1910. */
  1911. applyEnvironmentMapConfiguration(rotationY?: number): void;
  1912. /**
  1913. * Get an environment asset url by using the configuration if the path is not absolute.
  1914. * @param url Asset url
  1915. * @returns The Asset url using the `environmentAssetsRootURL` if the url is not an absolute path.
  1916. */
  1917. getAssetUrl(url: string): string;
  1918. }
  1919. }
  1920. declare module BabylonViewer {
  1921. /**
  1922. * Spherical polynomial coefficients (counter part to spherical harmonic coefficients used in shader irradiance calculation)
  1923. * @ignoreChildren
  1924. */
  1925. export interface SphericalPolynomalCoefficients {
  1926. x: BABYLON.Vector3;
  1927. y: BABYLON.Vector3;
  1928. z: BABYLON.Vector3;
  1929. xx: BABYLON.Vector3;
  1930. yy: BABYLON.Vector3;
  1931. zz: BABYLON.Vector3;
  1932. yz: BABYLON.Vector3;
  1933. zx: BABYLON.Vector3;
  1934. xy: BABYLON.Vector3;
  1935. }
  1936. /**
  1937. * Wraps data and maps required for environments with physically based rendering
  1938. */
  1939. export interface PBREnvironment {
  1940. /**
  1941. * Spherical Polynomial Coefficients representing an irradiance map
  1942. */
  1943. irradiancePolynomialCoefficients: SphericalPolynomalCoefficients;
  1944. /**
  1945. * Specular cubemap
  1946. */
  1947. specularTexture?: TextureCube;
  1948. /**
  1949. * A scale factor applied to RGB values after reading from environment maps
  1950. */
  1951. textureIntensityScale: number;
  1952. }
  1953. /**
  1954. * Environment map representations: layouts, projections and approximations
  1955. */
  1956. export type MapType = 'irradiance_sh_coefficients_9' | 'cubemap_faces';
  1957. /**
  1958. * Image type used for environment map
  1959. */
  1960. export type ImageType = 'png';
  1961. /**
  1962. * A generic field in JSON that report's its type
  1963. */
  1964. export interface TypedObject<T> {
  1965. type: T;
  1966. }
  1967. /**
  1968. * Describes a range of bytes starting at byte pos (inclusive) and finishing at byte pos + length - 1
  1969. */
  1970. export interface ByteRange {
  1971. pos: number;
  1972. length: number;
  1973. }
  1974. /**
  1975. * Complete Spectre Environment JSON Descriptor
  1976. */
  1977. export interface EnvJsonDescriptor {
  1978. radiance: TypedObject<MapType>;
  1979. irradiance: TypedObject<MapType>;
  1980. specular: TypedObject<MapType>;
  1981. }
  1982. /**
  1983. * Spherical harmonic coefficients to provide an irradiance map
  1984. */
  1985. export interface IrradianceSHCoefficients9 extends TypedObject<MapType> {
  1986. l00: Array<number>;
  1987. l1_1: Array<number>;
  1988. l10: Array<number>;
  1989. l11: Array<number>;
  1990. l2_2: Array<number>;
  1991. l2_1: Array<number>;
  1992. l20: Array<number>;
  1993. l21: Array<number>;
  1994. l22: Array<number>;
  1995. }
  1996. /**
  1997. * A generic set of images, where the image content is specified by byte ranges in the mipmaps field
  1998. */
  1999. export interface ImageSet<T> extends TypedObject<MapType> {
  2000. imageType: ImageType;
  2001. width: number;
  2002. height: number;
  2003. mipmaps: Array<T>;
  2004. multiplier: number;
  2005. }
  2006. /**
  2007. * A set of cubemap faces
  2008. */
  2009. export type CubemapFaces = ImageSet<Array<ByteRange>>;
  2010. /**
  2011. * A single image containing an atlas of equirectangular-projection maps across all mip levels
  2012. */
  2013. export type EquirectangularMipmapAtlas = ImageSet<ByteRange>;
  2014. /**
  2015. * A static class proving methods to aid parsing Spectre environment files
  2016. */
  2017. export class EnvironmentDeserializer {
  2018. /**
  2019. * Parses an arraybuffer into a new PBREnvironment object
  2020. * @param arrayBuffer The arraybuffer of the Spectre environment file
  2021. * @return a PBREnvironment object
  2022. */
  2023. static Parse(arrayBuffer: ArrayBuffer): PBREnvironment;
  2024. }
  2025. }
  2026. declare module BabylonViewer {
  2027. /**
  2028. * WebGL Pixel Formats
  2029. */
  2030. export const enum PixelFormat {
  2031. DEPTH_COMPONENT = 6402,
  2032. ALPHA = 6406,
  2033. RGB = 6407,
  2034. RGBA = 6408,
  2035. LUMINANCE = 6409,
  2036. LUMINANCE_ALPHA = 6410,
  2037. }
  2038. /**
  2039. * WebGL Pixel Types
  2040. */
  2041. export const enum PixelType {
  2042. UNSIGNED_BYTE = 5121,
  2043. UNSIGNED_SHORT_4_4_4_4 = 32819,
  2044. UNSIGNED_SHORT_5_5_5_1 = 32820,
  2045. UNSIGNED_SHORT_5_6_5 = 33635,
  2046. }
  2047. /**
  2048. * WebGL Texture Magnification Filter
  2049. */
  2050. export const enum TextureMagFilter {
  2051. NEAREST = 9728,
  2052. LINEAR = 9729,
  2053. }
  2054. /**
  2055. * WebGL Texture Minification Filter
  2056. */
  2057. export const enum TextureMinFilter {
  2058. NEAREST = 9728,
  2059. LINEAR = 9729,
  2060. NEAREST_MIPMAP_NEAREST = 9984,
  2061. LINEAR_MIPMAP_NEAREST = 9985,
  2062. NEAREST_MIPMAP_LINEAR = 9986,
  2063. LINEAR_MIPMAP_LINEAR = 9987,
  2064. }
  2065. /**
  2066. * WebGL Texture Wrap Modes
  2067. */
  2068. export const enum TextureWrapMode {
  2069. REPEAT = 10497,
  2070. CLAMP_TO_EDGE = 33071,
  2071. MIRRORED_REPEAT = 33648,
  2072. }
  2073. /**
  2074. * Raw texture data and descriptor sufficient for WebGL texture upload
  2075. */
  2076. export interface TextureData {
  2077. /**
  2078. * Width of image
  2079. */
  2080. width: number;
  2081. /**
  2082. * Height of image
  2083. */
  2084. height: number;
  2085. /**
  2086. * Format of pixels in data
  2087. */
  2088. format: PixelFormat;
  2089. /**
  2090. * Row byte alignment of pixels in data
  2091. */
  2092. alignment: number;
  2093. /**
  2094. * Pixel data
  2095. */
  2096. data: ArrayBufferView;
  2097. }
  2098. /**
  2099. * Wraps sampling parameters for a WebGL texture
  2100. */
  2101. export interface SamplingParameters {
  2102. /**
  2103. * Magnification mode when upsampling from a WebGL texture
  2104. */
  2105. magFilter?: TextureMagFilter;
  2106. /**
  2107. * Minification mode when upsampling from a WebGL texture
  2108. */
  2109. minFilter?: TextureMinFilter;
  2110. /**
  2111. * X axis wrapping mode when sampling out of a WebGL texture bounds
  2112. */
  2113. wrapS?: TextureWrapMode;
  2114. /**
  2115. * Y axis wrapping mode when sampling out of a WebGL texture bounds
  2116. */
  2117. wrapT?: TextureWrapMode;
  2118. /**
  2119. * Anisotropic filtering samples
  2120. */
  2121. maxAnisotropy?: number;
  2122. }
  2123. /**
  2124. * Represents a valid WebGL texture source for use in texImage2D
  2125. */
  2126. export type TextureSource = TextureData | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
  2127. /**
  2128. * A generic set of texture mipmaps (where index 0 has the largest dimension)
  2129. */
  2130. export type Mipmaps<T> = Array<T>;
  2131. /**
  2132. * A set of 6 cubemap arranged in the order [+x, -x, +y, -y, +z, -z]
  2133. */
  2134. export type Faces<T> = Array<T>;
  2135. /**
  2136. * A set of texture mipmaps specifically for 2D textures in WebGL (where index 0 has the largest dimension)
  2137. */
  2138. export type Mipmaps2D = Mipmaps<TextureSource>;
  2139. /**
  2140. * A set of texture mipmaps specifically for cubemap textures in WebGL (where index 0 has the largest dimension)
  2141. */
  2142. export type MipmapsCube = Mipmaps<Faces<TextureSource>>;
  2143. /**
  2144. * A minimal WebGL cubemap descriptor
  2145. */
  2146. export class TextureCube {
  2147. internalFormat: PixelFormat;
  2148. type: PixelType;
  2149. source: MipmapsCube;
  2150. /**
  2151. * Returns the width of a face of the texture or 0 if not available
  2152. */
  2153. readonly Width: number;
  2154. /**
  2155. * Returns the height of a face of the texture or 0 if not available
  2156. */
  2157. readonly Height: number;
  2158. /**
  2159. * constructor
  2160. * @param internalFormat WebGL pixel format for the texture on the GPU
  2161. * @param type WebGL pixel type of the supplied data and texture on the GPU
  2162. * @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
  2163. */
  2164. constructor(internalFormat: PixelFormat, type: PixelType, source?: MipmapsCube);
  2165. }
  2166. /**
  2167. * A static class providing methods to aid working with Bablyon textures.
  2168. */
  2169. export class TextureUtils {
  2170. /**
  2171. * A prefix used when storing a babylon texture object reference on a Spectre texture object
  2172. */
  2173. static BabylonTextureKeyPrefix: string;
  2174. /**
  2175. * Controls anisotropic filtering for deserialized textures.
  2176. */
  2177. static MaxAnisotropy: number;
  2178. /**
  2179. * Returns a BabylonCubeTexture instance from a Spectre texture cube, subject to sampling parameters.
  2180. * If such a texture has already been requested in the past, this texture will be returned, otherwise a new one will be created.
  2181. * The advantage of this is to enable working with texture objects without the need to initialize on the GPU until desired.
  2182. * @param scene A Babylon BABYLON.Scene instance
  2183. * @param textureCube A Spectre TextureCube object
  2184. * @param parameters WebGL texture sampling parameters
  2185. * @param automaticMipmaps Pass true to enable automatic mipmap generation where possible (requires power of images)
  2186. * @param environment Specifies that the texture will be used as an environment
  2187. * @param singleLod Specifies that the texture will be a singleLod (for environment)
  2188. * @return Babylon cube texture
  2189. */
  2190. static GetBabylonCubeTexture(scene: BABYLON.Scene, textureCube: TextureCube, automaticMipmaps: boolean, environment?: boolean, singleLod?: boolean): BABYLON.CubeTexture;
  2191. /**
  2192. * Applies Spectre SamplingParameters to a Babylon texture by directly setting texture parameters on the internal WebGLTexture as well as setting Babylon fields
  2193. * @param babylonTexture Babylon texture to apply texture to (requires the Babylon texture has an initialize _texture field)
  2194. * @param parameters Spectre SamplingParameters to apply
  2195. */
  2196. static ApplySamplingParameters(babylonTexture: BABYLON.BaseTexture, parameters: SamplingParameters): void;
  2197. /**
  2198. * Environment preprocessing dedicated value (Internal Use or Advanced only).
  2199. */
  2200. static EnvironmentLODScale: number;
  2201. /**
  2202. * Environment preprocessing dedicated value (Internal Use or Advanced only)..
  2203. */
  2204. static EnvironmentLODOffset: number;
  2205. }
  2206. }