babylon.viewer.d.ts 92 KB

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