babylon.viewer.d.ts 102 KB

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