babylon.viewer.module.d.ts 98 KB

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