babylon.viewer.module.d.ts 110 KB

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