babylon.viewer.module.d.ts 92 KB

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