babylon.viewer.module.d.ts 112 KB

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