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