babylon.viewer.d.ts 101 KB

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