babylon.viewer.d.ts 90 KB

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