babylon.viewer.module.d.ts 110 KB

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