babylon.viewer.module.d.ts 110 KB

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