babylon.viewer.module.d.ts 98 KB

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