babylon.viewer.d.ts 101 KB

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