babylon.viewer.module.d.ts 96 KB

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