babylon.viewer.d.ts 90 KB

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