babylon.viewer.module.d.ts 111 KB

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