babylon.viewer.d.ts 98 KB

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