babylon.viewer.module.d.ts 99 KB

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