babylon.viewer.module.d.ts 110 KB

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