babylon.viewer.module.d.ts 96 KB

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