babylon.viewer.d.ts 105 KB

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