babylon.viewer.module.d.ts 98 KB

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