babylon.viewer.d.ts 98 KB

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