babylon.viewer.module.d.ts 111 KB

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