babylon.viewer.d.ts 105 KB

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