babylon.viewer.d.ts 99 KB

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