babylon.viewer.module.d.ts 107 KB

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