babylon.viewer.module.d.ts 111 KB

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