babylon.viewer.d.ts 99 KB

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