babylon.viewer.d.ts 101 KB

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