babylon.viewer.module.d.ts 96 KB

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