babylon.viewer.module.d.ts 108 KB

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