babylon.viewer.d.ts 100 KB

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