babylon.viewer.d.ts 93 KB

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