babylonjs.loaders.d.ts 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. declare module BABYLON {
  2. class STLFileLoader implements ISceneLoaderPlugin {
  3. solidPattern: RegExp;
  4. facetsPattern: RegExp;
  5. normalPattern: RegExp;
  6. vertexPattern: RegExp;
  7. name: string;
  8. extensions: ISceneLoaderPluginExtensions;
  9. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  10. load(scene: Scene, data: any, rootUrl: string): boolean;
  11. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  12. private isBinary(data);
  13. private parseBinary(mesh, data);
  14. private parseASCII(mesh, solidData);
  15. }
  16. }
  17. declare module BABYLON {
  18. /**
  19. * Class reading and parsing the MTL file bundled with the obj file.
  20. */
  21. class MTLFileLoader {
  22. materials: BABYLON.StandardMaterial[];
  23. /**
  24. * This function will read the mtl file and create each material described inside
  25. * This function could be improve by adding :
  26. * -some component missing (Ni, Tf...)
  27. * -including the specific options available
  28. *
  29. * @param scene
  30. * @param data
  31. * @param rootUrl
  32. */
  33. parseMTL(scene: BABYLON.Scene, data: string | ArrayBuffer, rootUrl: string): void;
  34. /**
  35. * Gets the texture for the material.
  36. *
  37. * If the material is imported from input file,
  38. * We sanitize the url to ensure it takes the textre from aside the material.
  39. *
  40. * @param rootUrl The root url to load from
  41. * @param value The value stored in the mtl
  42. * @return The Texture
  43. */
  44. private static _getTexture(rootUrl, value, scene);
  45. }
  46. class OBJFileLoader implements ISceneLoaderPlugin {
  47. static OPTIMIZE_WITH_UV: boolean;
  48. static INVERT_Y: boolean;
  49. name: string;
  50. extensions: string;
  51. obj: RegExp;
  52. group: RegExp;
  53. mtllib: RegExp;
  54. usemtl: RegExp;
  55. smooth: RegExp;
  56. vertexPattern: RegExp;
  57. normalPattern: RegExp;
  58. uvPattern: RegExp;
  59. facePattern1: RegExp;
  60. facePattern2: RegExp;
  61. facePattern3: RegExp;
  62. facePattern4: RegExp;
  63. /**
  64. * Calls synchronously the MTL file attached to this obj.
  65. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  66. * Without this function materials are not displayed in the first frame (but displayed after).
  67. * In consequence it is impossible to get material information in your HTML file
  68. *
  69. * @param url The URL of the MTL file
  70. * @param rootUrl
  71. * @param onSuccess Callback function to be called when the MTL file is loaded
  72. * @private
  73. */
  74. private _loadMTL(url, rootUrl, onSuccess);
  75. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  76. load(scene: Scene, data: string, rootUrl: string): boolean;
  77. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  78. /**
  79. * Read the OBJ file and create an Array of meshes.
  80. * Each mesh contains all information given by the OBJ and the MTL file.
  81. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  82. *
  83. * @param meshesNames
  84. * @param scene BABYLON.Scene The scene where are displayed the data
  85. * @param data String The content of the obj file
  86. * @param rootUrl String The path to the folder
  87. * @returns Array<AbstractMesh>
  88. * @private
  89. */
  90. private _parseSolid(meshesNames, scene, data, rootUrl);
  91. }
  92. }
  93. declare module BABYLON {
  94. /**
  95. * Mode that determines the coordinate system to use.
  96. */
  97. enum GLTFLoaderCoordinateSystemMode {
  98. /**
  99. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  100. */
  101. AUTO = 0,
  102. /**
  103. * Sets the useRightHandedSystem flag on the scene.
  104. */
  105. FORCE_RIGHT_HANDED = 1,
  106. }
  107. /**
  108. * Mode that determines what animations will start.
  109. */
  110. enum GLTFLoaderAnimationStartMode {
  111. /**
  112. * No animation will start.
  113. */
  114. NONE = 0,
  115. /**
  116. * The first animation will start.
  117. */
  118. FIRST = 1,
  119. /**
  120. * All animations will start.
  121. */
  122. ALL = 2,
  123. }
  124. /**
  125. * Interface that contains the data for the glTF asset.
  126. */
  127. interface IGLTFLoaderData {
  128. /**
  129. * JSON that represents the glTF.
  130. */
  131. json: Object;
  132. /**
  133. * The BIN chunk of a binary glTF
  134. */
  135. bin: Nullable<ArrayBufferView>;
  136. }
  137. /**
  138. * Interface for extending the loader.
  139. */
  140. interface IGLTFLoaderExtension {
  141. /**
  142. * The name of this extension.
  143. */
  144. readonly name: string;
  145. /**
  146. * Defines whether this extension is enabled.
  147. */
  148. enabled: boolean;
  149. }
  150. /**
  151. * Loader state.
  152. */
  153. enum GLTFLoaderState {
  154. /**
  155. * The asset is loading.
  156. */
  157. LOADING = 0,
  158. /**
  159. * The asset is ready for rendering.
  160. */
  161. READY = 1,
  162. /**
  163. * The asset is completely loaded.
  164. */
  165. COMPLETE = 2,
  166. }
  167. /**
  168. * Loader interface.
  169. */
  170. interface IGLTFLoader extends IDisposable {
  171. /**
  172. * Mode that determines the coordinate system to use.
  173. */
  174. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  175. /**
  176. * Mode that determines what animations will start.
  177. */
  178. animationStartMode: GLTFLoaderAnimationStartMode;
  179. /**
  180. * Defines if the loader should compile materials.
  181. */
  182. compileMaterials: boolean;
  183. /**
  184. * Defines if the loader should also compile materials with clip planes.
  185. */
  186. useClipPlane: boolean;
  187. /**
  188. * Defines if the loader should compile shadow generators.
  189. */
  190. compileShadowGenerators: boolean;
  191. /**
  192. * Defines if the Alpha blended materials are only applied as coverage.
  193. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  194. * If true, no extra effects are applied to transparent pixels.
  195. */
  196. transparencyAsCoverage: boolean;
  197. /** @hidden */
  198. _normalizeAnimationGroupsToBeginAtZero: boolean;
  199. /**
  200. * Function called before loading a url referenced by the asset.
  201. */
  202. preprocessUrlAsync: (url: string) => Promise<string>;
  203. /**
  204. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  205. */
  206. onMeshLoadedObservable: Observable<AbstractMesh>;
  207. /**
  208. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  209. */
  210. onTextureLoadedObservable: Observable<BaseTexture>;
  211. /**
  212. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  213. */
  214. onMaterialLoadedObservable: Observable<Material>;
  215. /**
  216. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  217. */
  218. onCameraLoadedObservable: Observable<Camera>;
  219. /**
  220. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  221. * For assets with LODs, raised when all of the LODs are complete.
  222. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  223. */
  224. onCompleteObservable: Observable<IGLTFLoader>;
  225. /**
  226. * Observable raised after the loader is disposed.
  227. */
  228. onDisposeObservable: Observable<IGLTFLoader>;
  229. /**
  230. * Observable raised after a loader extension is created.
  231. * Set additional options for a loader extension in this event.
  232. */
  233. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  234. /**
  235. * Loader state or null if the loader is not active.
  236. */
  237. state: Nullable<GLTFLoaderState>;
  238. /**
  239. * Imports meshes from the given data and adds them to the scene.
  240. */
  241. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  242. meshes: AbstractMesh[];
  243. particleSystems: ParticleSystem[];
  244. skeletons: Skeleton[];
  245. animationGroups: AnimationGroup[];
  246. }>;
  247. /**
  248. * Loads all objects from the given data and adds them to the scene.
  249. */
  250. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  251. }
  252. /**
  253. * File loader for loading glTF files into a scene.
  254. */
  255. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  256. /** @hidden */
  257. static _CreateGLTFLoaderV1: () => IGLTFLoader;
  258. /** @hidden */
  259. static _CreateGLTFLoaderV2: () => IGLTFLoader;
  260. /**
  261. * Raised when the asset has been parsed
  262. */
  263. onParsedObservable: Observable<IGLTFLoaderData>;
  264. private _onParsedObserver;
  265. /**
  266. * Raised when the asset has been parsed
  267. */
  268. onParsed: (loaderData: IGLTFLoaderData) => void;
  269. /**
  270. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  271. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  272. * Defaults to true.
  273. * @hidden
  274. */
  275. static IncrementalLoading: boolean;
  276. /**
  277. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  278. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  279. * @hidden
  280. */
  281. static HomogeneousCoordinates: boolean;
  282. /**
  283. * The coordinate system mode. Defaults to AUTO.
  284. */
  285. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  286. /**
  287. * The animation start mode. Defaults to FIRST.
  288. */
  289. animationStartMode: GLTFLoaderAnimationStartMode;
  290. /**
  291. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  292. */
  293. compileMaterials: boolean;
  294. /**
  295. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  296. */
  297. useClipPlane: boolean;
  298. /**
  299. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  300. */
  301. compileShadowGenerators: boolean;
  302. /**
  303. * Defines if the Alpha blended materials are only applied as coverage.
  304. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  305. * If true, no extra effects are applied to transparent pixels.
  306. */
  307. transparencyAsCoverage: boolean;
  308. /** @hidden */
  309. _normalizeAnimationGroupsToBeginAtZero: boolean;
  310. /**
  311. * Function called before loading a url referenced by the asset.
  312. */
  313. preprocessUrlAsync: (url: string) => Promise<string>;
  314. /**
  315. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  316. */
  317. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  318. private _onMeshLoadedObserver;
  319. /**
  320. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  321. */
  322. onMeshLoaded: (mesh: AbstractMesh) => void;
  323. /**
  324. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  325. */
  326. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  327. private _onTextureLoadedObserver;
  328. /**
  329. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  330. */
  331. onTextureLoaded: (texture: BaseTexture) => void;
  332. /**
  333. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  334. */
  335. readonly onMaterialLoadedObservable: Observable<Material>;
  336. private _onMaterialLoadedObserver;
  337. /**
  338. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  339. */
  340. onMaterialLoaded: (material: Material) => void;
  341. /**
  342. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  343. */
  344. readonly onCameraLoadedObservable: Observable<Camera>;
  345. private _onCameraLoadedObserver;
  346. /**
  347. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  348. */
  349. onCameraLoaded: (camera: Camera) => void;
  350. /**
  351. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  352. * For assets with LODs, raised when all of the LODs are complete.
  353. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  354. */
  355. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  356. private _onCompleteObserver;
  357. /**
  358. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  359. */
  360. onComplete: () => void;
  361. /**
  362. * Observable raised after the loader is disposed.
  363. */
  364. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  365. private _onDisposeObserver;
  366. /**
  367. * Callback raised after the loader is disposed.
  368. */
  369. onDispose: () => void;
  370. /**
  371. * Observable raised after a loader extension is created.
  372. * Set additional options for a loader extension in this event.
  373. */
  374. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  375. private _onExtensionLoadedObserver;
  376. /**
  377. * Callback raised after a loader extension is created.
  378. */
  379. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  380. /**
  381. * Returns a promise that resolves when the asset is completely loaded.
  382. * @returns a promise that resolves when the asset is completely loaded.
  383. */
  384. whenCompleteAsync(): Promise<void>;
  385. /**
  386. * The loader state or null if the loader is not active.
  387. */
  388. readonly loaderState: Nullable<GLTFLoaderState>;
  389. private _loader;
  390. /**
  391. * Name of the loader ("gltf")
  392. */
  393. name: string;
  394. /**
  395. * Supported file extensions of the loader (.gltf, .glb)
  396. */
  397. extensions: ISceneLoaderPluginExtensions;
  398. /**
  399. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  400. */
  401. dispose(): void;
  402. /**
  403. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  404. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  405. * @param scene the scene the meshes should be added to
  406. * @param data the glTF data to load
  407. * @param rootUrl root url to load from
  408. * @param onProgress event that fires when loading progress has occured
  409. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  410. */
  411. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  412. meshes: AbstractMesh[];
  413. particleSystems: ParticleSystem[];
  414. skeletons: Skeleton[];
  415. animationGroups: AnimationGroup[];
  416. }>;
  417. /**
  418. * Imports all objects from the loaded glTF data and adds them to the scene
  419. * @param scene the scene the objects should be added to
  420. * @param data the glTF data to load
  421. * @param rootUrl root url to load from
  422. * @param onProgress event that fires when loading progress has occured
  423. * @returns a promise which completes when objects have been loaded to the scene
  424. */
  425. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  426. /**
  427. * Load into an asset container.
  428. * @param scene The scene to load into
  429. * @param data The data to import
  430. * @param rootUrl The root url for scene and resources
  431. * @param onProgress The callback when the load progresses
  432. * @returns The loaded asset container
  433. */
  434. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  435. /**
  436. * If the data string can be loaded directly.
  437. * @param data string contianing the file data
  438. * @returns if the data can be loaded directly
  439. */
  440. canDirectLoad(data: string): boolean;
  441. /**
  442. * Rewrites a url by combining a root url and response url.
  443. */
  444. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  445. /**
  446. * Instantiates a glTF file loader plugin.
  447. * @returns the created plugin
  448. */
  449. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  450. private _parse(data);
  451. private _getLoader(loaderData);
  452. private static _parseBinary(data);
  453. private static _parseV1(binaryReader);
  454. private static _parseV2(binaryReader);
  455. private static _parseVersion(version);
  456. private static _compareVersion(a, b);
  457. private static _decodeBufferToText(buffer);
  458. }
  459. }
  460. declare module BABYLON.GLTF1 {
  461. /**
  462. * Enums
  463. */
  464. enum EComponentType {
  465. BYTE = 5120,
  466. UNSIGNED_BYTE = 5121,
  467. SHORT = 5122,
  468. UNSIGNED_SHORT = 5123,
  469. FLOAT = 5126,
  470. }
  471. enum EShaderType {
  472. FRAGMENT = 35632,
  473. VERTEX = 35633,
  474. }
  475. enum EParameterType {
  476. BYTE = 5120,
  477. UNSIGNED_BYTE = 5121,
  478. SHORT = 5122,
  479. UNSIGNED_SHORT = 5123,
  480. INT = 5124,
  481. UNSIGNED_INT = 5125,
  482. FLOAT = 5126,
  483. FLOAT_VEC2 = 35664,
  484. FLOAT_VEC3 = 35665,
  485. FLOAT_VEC4 = 35666,
  486. INT_VEC2 = 35667,
  487. INT_VEC3 = 35668,
  488. INT_VEC4 = 35669,
  489. BOOL = 35670,
  490. BOOL_VEC2 = 35671,
  491. BOOL_VEC3 = 35672,
  492. BOOL_VEC4 = 35673,
  493. FLOAT_MAT2 = 35674,
  494. FLOAT_MAT3 = 35675,
  495. FLOAT_MAT4 = 35676,
  496. SAMPLER_2D = 35678,
  497. }
  498. enum ETextureWrapMode {
  499. CLAMP_TO_EDGE = 33071,
  500. MIRRORED_REPEAT = 33648,
  501. REPEAT = 10497,
  502. }
  503. enum ETextureFilterType {
  504. NEAREST = 9728,
  505. LINEAR = 9728,
  506. NEAREST_MIPMAP_NEAREST = 9984,
  507. LINEAR_MIPMAP_NEAREST = 9985,
  508. NEAREST_MIPMAP_LINEAR = 9986,
  509. LINEAR_MIPMAP_LINEAR = 9987,
  510. }
  511. enum ETextureFormat {
  512. ALPHA = 6406,
  513. RGB = 6407,
  514. RGBA = 6408,
  515. LUMINANCE = 6409,
  516. LUMINANCE_ALPHA = 6410,
  517. }
  518. enum ECullingType {
  519. FRONT = 1028,
  520. BACK = 1029,
  521. FRONT_AND_BACK = 1032,
  522. }
  523. enum EBlendingFunction {
  524. ZERO = 0,
  525. ONE = 1,
  526. SRC_COLOR = 768,
  527. ONE_MINUS_SRC_COLOR = 769,
  528. DST_COLOR = 774,
  529. ONE_MINUS_DST_COLOR = 775,
  530. SRC_ALPHA = 770,
  531. ONE_MINUS_SRC_ALPHA = 771,
  532. DST_ALPHA = 772,
  533. ONE_MINUS_DST_ALPHA = 773,
  534. CONSTANT_COLOR = 32769,
  535. ONE_MINUS_CONSTANT_COLOR = 32770,
  536. CONSTANT_ALPHA = 32771,
  537. ONE_MINUS_CONSTANT_ALPHA = 32772,
  538. SRC_ALPHA_SATURATE = 776,
  539. }
  540. /**
  541. * Interfaces
  542. */
  543. interface IGLTFProperty {
  544. extensions?: {
  545. [key: string]: any;
  546. };
  547. extras?: Object;
  548. }
  549. interface IGLTFChildRootProperty extends IGLTFProperty {
  550. name?: string;
  551. }
  552. interface IGLTFAccessor extends IGLTFChildRootProperty {
  553. bufferView: string;
  554. byteOffset: number;
  555. byteStride: number;
  556. count: number;
  557. type: string;
  558. componentType: EComponentType;
  559. max?: number[];
  560. min?: number[];
  561. name?: string;
  562. }
  563. interface IGLTFBufferView extends IGLTFChildRootProperty {
  564. buffer: string;
  565. byteOffset: number;
  566. byteLength: number;
  567. byteStride: number;
  568. target?: number;
  569. }
  570. interface IGLTFBuffer extends IGLTFChildRootProperty {
  571. uri: string;
  572. byteLength?: number;
  573. type?: string;
  574. }
  575. interface IGLTFShader extends IGLTFChildRootProperty {
  576. uri: string;
  577. type: EShaderType;
  578. }
  579. interface IGLTFProgram extends IGLTFChildRootProperty {
  580. attributes: string[];
  581. fragmentShader: string;
  582. vertexShader: string;
  583. }
  584. interface IGLTFTechniqueParameter {
  585. type: number;
  586. count?: number;
  587. semantic?: string;
  588. node?: string;
  589. value?: number | boolean | string | Array<any>;
  590. source?: string;
  591. babylonValue?: any;
  592. }
  593. interface IGLTFTechniqueCommonProfile {
  594. lightingModel: string;
  595. texcoordBindings: Object;
  596. parameters?: Array<any>;
  597. }
  598. interface IGLTFTechniqueStatesFunctions {
  599. blendColor?: number[];
  600. blendEquationSeparate?: number[];
  601. blendFuncSeparate?: number[];
  602. colorMask: boolean[];
  603. cullFace: number[];
  604. }
  605. interface IGLTFTechniqueStates {
  606. enable: number[];
  607. functions: IGLTFTechniqueStatesFunctions;
  608. }
  609. interface IGLTFTechnique extends IGLTFChildRootProperty {
  610. parameters: {
  611. [key: string]: IGLTFTechniqueParameter;
  612. };
  613. program: string;
  614. attributes: {
  615. [key: string]: string;
  616. };
  617. uniforms: {
  618. [key: string]: string;
  619. };
  620. states: IGLTFTechniqueStates;
  621. }
  622. interface IGLTFMaterial extends IGLTFChildRootProperty {
  623. technique?: string;
  624. values: string[];
  625. }
  626. interface IGLTFMeshPrimitive extends IGLTFProperty {
  627. attributes: {
  628. [key: string]: string;
  629. };
  630. indices: string;
  631. material: string;
  632. mode?: number;
  633. }
  634. interface IGLTFMesh extends IGLTFChildRootProperty {
  635. primitives: IGLTFMeshPrimitive[];
  636. }
  637. interface IGLTFImage extends IGLTFChildRootProperty {
  638. uri: string;
  639. }
  640. interface IGLTFSampler extends IGLTFChildRootProperty {
  641. magFilter?: number;
  642. minFilter?: number;
  643. wrapS?: number;
  644. wrapT?: number;
  645. }
  646. interface IGLTFTexture extends IGLTFChildRootProperty {
  647. sampler: string;
  648. source: string;
  649. format?: ETextureFormat;
  650. internalFormat?: ETextureFormat;
  651. target?: number;
  652. type?: number;
  653. babylonTexture?: Texture;
  654. }
  655. interface IGLTFAmbienLight {
  656. color?: number[];
  657. }
  658. interface IGLTFDirectionalLight {
  659. color?: number[];
  660. }
  661. interface IGLTFPointLight {
  662. color?: number[];
  663. constantAttenuation?: number;
  664. linearAttenuation?: number;
  665. quadraticAttenuation?: number;
  666. }
  667. interface IGLTFSpotLight {
  668. color?: number[];
  669. constantAttenuation?: number;
  670. fallOfAngle?: number;
  671. fallOffExponent?: number;
  672. linearAttenuation?: number;
  673. quadraticAttenuation?: number;
  674. }
  675. interface IGLTFLight extends IGLTFChildRootProperty {
  676. type: string;
  677. }
  678. interface IGLTFCameraOrthographic {
  679. xmag: number;
  680. ymag: number;
  681. zfar: number;
  682. znear: number;
  683. }
  684. interface IGLTFCameraPerspective {
  685. aspectRatio: number;
  686. yfov: number;
  687. zfar: number;
  688. znear: number;
  689. }
  690. interface IGLTFCamera extends IGLTFChildRootProperty {
  691. type: string;
  692. }
  693. interface IGLTFAnimationChannelTarget {
  694. id: string;
  695. path: string;
  696. }
  697. interface IGLTFAnimationChannel {
  698. sampler: string;
  699. target: IGLTFAnimationChannelTarget;
  700. }
  701. interface IGLTFAnimationSampler {
  702. input: string;
  703. output: string;
  704. interpolation?: string;
  705. }
  706. interface IGLTFAnimation extends IGLTFChildRootProperty {
  707. channels?: IGLTFAnimationChannel[];
  708. parameters?: {
  709. [key: string]: string;
  710. };
  711. samplers?: {
  712. [key: string]: IGLTFAnimationSampler;
  713. };
  714. }
  715. interface IGLTFNodeInstanceSkin {
  716. skeletons: string[];
  717. skin: string;
  718. meshes: string[];
  719. }
  720. interface IGLTFSkins extends IGLTFChildRootProperty {
  721. bindShapeMatrix: number[];
  722. inverseBindMatrices: string;
  723. jointNames: string[];
  724. babylonSkeleton?: Skeleton;
  725. }
  726. interface IGLTFNode extends IGLTFChildRootProperty {
  727. camera?: string;
  728. children: string[];
  729. skin?: string;
  730. jointName?: string;
  731. light?: string;
  732. matrix: number[];
  733. mesh?: string;
  734. meshes?: string[];
  735. rotation?: number[];
  736. scale?: number[];
  737. translation?: number[];
  738. babylonNode?: Node;
  739. }
  740. interface IGLTFScene extends IGLTFChildRootProperty {
  741. nodes: string[];
  742. }
  743. /**
  744. * Runtime
  745. */
  746. interface IGLTFRuntime {
  747. extensions: {
  748. [key: string]: any;
  749. };
  750. accessors: {
  751. [key: string]: IGLTFAccessor;
  752. };
  753. buffers: {
  754. [key: string]: IGLTFBuffer;
  755. };
  756. bufferViews: {
  757. [key: string]: IGLTFBufferView;
  758. };
  759. meshes: {
  760. [key: string]: IGLTFMesh;
  761. };
  762. lights: {
  763. [key: string]: IGLTFLight;
  764. };
  765. cameras: {
  766. [key: string]: IGLTFCamera;
  767. };
  768. nodes: {
  769. [key: string]: IGLTFNode;
  770. };
  771. images: {
  772. [key: string]: IGLTFImage;
  773. };
  774. textures: {
  775. [key: string]: IGLTFTexture;
  776. };
  777. shaders: {
  778. [key: string]: IGLTFShader;
  779. };
  780. programs: {
  781. [key: string]: IGLTFProgram;
  782. };
  783. samplers: {
  784. [key: string]: IGLTFSampler;
  785. };
  786. techniques: {
  787. [key: string]: IGLTFTechnique;
  788. };
  789. materials: {
  790. [key: string]: IGLTFMaterial;
  791. };
  792. animations: {
  793. [key: string]: IGLTFAnimation;
  794. };
  795. skins: {
  796. [key: string]: IGLTFSkins;
  797. };
  798. currentScene?: Object;
  799. scenes: {
  800. [key: string]: IGLTFScene;
  801. };
  802. extensionsUsed: string[];
  803. extensionsRequired?: string[];
  804. buffersCount: number;
  805. shaderscount: number;
  806. scene: Scene;
  807. rootUrl: string;
  808. loadedBufferCount: number;
  809. loadedBufferViews: {
  810. [name: string]: ArrayBufferView;
  811. };
  812. loadedShaderCount: number;
  813. importOnlyMeshes: boolean;
  814. importMeshesNames?: string[];
  815. dummyNodes: Node[];
  816. }
  817. /**
  818. * Bones
  819. */
  820. interface INodeToRoot {
  821. bone: Bone;
  822. node: IGLTFNode;
  823. id: string;
  824. }
  825. interface IJointNode {
  826. node: IGLTFNode;
  827. id: string;
  828. }
  829. }
  830. declare module BABYLON.GLTF1 {
  831. /**
  832. * Implementation of the base glTF spec
  833. */
  834. class GLTFLoaderBase {
  835. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  836. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  837. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  838. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  839. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  840. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  841. }
  842. /**
  843. * glTF V1 Loader
  844. */
  845. class GLTFLoader implements IGLTFLoader {
  846. static Extensions: {
  847. [name: string]: GLTFLoaderExtension;
  848. };
  849. static RegisterExtension(extension: GLTFLoaderExtension): void;
  850. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  851. animationStartMode: GLTFLoaderAnimationStartMode;
  852. compileMaterials: boolean;
  853. useClipPlane: boolean;
  854. compileShadowGenerators: boolean;
  855. transparencyAsCoverage: boolean;
  856. _normalizeAnimationGroupsToBeginAtZero: boolean;
  857. preprocessUrlAsync: (url: string) => Promise<string>;
  858. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  859. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  860. readonly onMaterialLoadedObservable: Observable<Material>;
  861. readonly onCameraLoadedObservable: Observable<Camera>;
  862. readonly onCompleteObservable: Observable<IGLTFLoader>;
  863. readonly onDisposeObservable: Observable<IGLTFLoader>;
  864. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  865. state: Nullable<GLTFLoaderState>;
  866. dispose(): void;
  867. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  868. /**
  869. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  870. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  871. * @param scene the scene the meshes should be added to
  872. * @param data gltf data containing information of the meshes in a loaded file
  873. * @param rootUrl root url to load from
  874. * @param onProgress event that fires when loading progress has occured
  875. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  876. */
  877. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  878. meshes: AbstractMesh[];
  879. particleSystems: ParticleSystem[];
  880. skeletons: Skeleton[];
  881. animationGroups: AnimationGroup[];
  882. }>;
  883. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  884. /**
  885. * Imports all objects from a loaded gltf file and adds them to the scene
  886. * @param scene the scene the objects should be added to
  887. * @param data gltf data containing information of the meshes in a loaded file
  888. * @param rootUrl root url to load from
  889. * @param onProgress event that fires when loading progress has occured
  890. * @returns a promise which completes when objects have been loaded to the scene
  891. */
  892. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  893. private _loadShadersAsync(gltfRuntime, onload);
  894. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  895. private _createNodes(gltfRuntime);
  896. }
  897. }
  898. declare module BABYLON.GLTF1 {
  899. /**
  900. * Utils functions for GLTF
  901. */
  902. class GLTFUtils {
  903. /**
  904. * Sets the given "parameter" matrix
  905. * @param scene: the {BABYLON.Scene} object
  906. * @param source: the source node where to pick the matrix
  907. * @param parameter: the GLTF technique parameter
  908. * @param uniformName: the name of the shader's uniform
  909. * @param shaderMaterial: the shader material
  910. */
  911. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  912. /**
  913. * Sets the given "parameter" matrix
  914. * @param shaderMaterial: the shader material
  915. * @param uniform: the name of the shader's uniform
  916. * @param value: the value of the uniform
  917. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  918. */
  919. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  920. /**
  921. * Returns the wrap mode of the texture
  922. * @param mode: the mode value
  923. */
  924. static GetWrapMode(mode: number): number;
  925. /**
  926. * Returns the byte stride giving an accessor
  927. * @param accessor: the GLTF accessor objet
  928. */
  929. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  930. /**
  931. * Returns the texture filter mode giving a mode value
  932. * @param mode: the filter mode value
  933. */
  934. static GetTextureFilterMode(mode: number): ETextureFilterType;
  935. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  936. /**
  937. * Returns a buffer from its accessor
  938. * @param gltfRuntime: the GLTF runtime
  939. * @param accessor: the GLTF accessor
  940. */
  941. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  942. /**
  943. * Decodes a buffer view into a string
  944. * @param view: the buffer view
  945. */
  946. static DecodeBufferToText(view: ArrayBufferView): string;
  947. /**
  948. * Returns the default material of gltf. Related to
  949. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  950. * @param scene: the Babylon.js scene
  951. */
  952. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  953. private static _DefaultMaterial;
  954. }
  955. }
  956. declare module BABYLON.GLTF1 {
  957. abstract class GLTFLoaderExtension {
  958. private _name;
  959. constructor(name: string);
  960. readonly name: string;
  961. /**
  962. * Defines an override for loading the runtime
  963. * Return true to stop further extensions from loading the runtime
  964. */
  965. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  966. /**
  967. * Defines an onverride for creating gltf runtime
  968. * Return true to stop further extensions from creating the runtime
  969. */
  970. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  971. /**
  972. * Defines an override for loading buffers
  973. * Return true to stop further extensions from loading this buffer
  974. */
  975. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  976. /**
  977. * Defines an override for loading texture buffers
  978. * Return true to stop further extensions from loading this texture data
  979. */
  980. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  981. /**
  982. * Defines an override for creating textures
  983. * Return true to stop further extensions from loading this texture
  984. */
  985. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  986. /**
  987. * Defines an override for loading shader strings
  988. * Return true to stop further extensions from loading this shader data
  989. */
  990. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  991. /**
  992. * Defines an override for loading materials
  993. * Return true to stop further extensions from loading this material
  994. */
  995. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  996. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  997. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  998. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  999. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  1000. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  1001. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  1002. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  1003. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  1004. private static ApplyExtensions(func, defaultFunc);
  1005. }
  1006. }
  1007. declare module BABYLON.GLTF1 {
  1008. class GLTFBinaryExtension extends GLTFLoaderExtension {
  1009. private _bin;
  1010. constructor();
  1011. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  1012. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  1013. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  1014. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  1015. }
  1016. }
  1017. declare module BABYLON.GLTF1 {
  1018. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  1019. constructor();
  1020. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  1021. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  1022. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  1023. }
  1024. }
  1025. declare module BABYLON.GLTF2 {
  1026. /** @hidden */
  1027. interface _IArrayItem {
  1028. _index: number;
  1029. }
  1030. /** @hidden */
  1031. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  1032. _data?: Promise<ArrayBufferView>;
  1033. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1034. }
  1035. /** @hidden */
  1036. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  1037. }
  1038. /** @hidden */
  1039. interface _ILoaderAnimationSamplerData {
  1040. input: Float32Array;
  1041. interpolation: AnimationSamplerInterpolation;
  1042. output: Float32Array;
  1043. }
  1044. /** @hidden */
  1045. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  1046. _data?: Promise<_ILoaderAnimationSamplerData>;
  1047. }
  1048. /** @hidden */
  1049. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  1050. channels: _ILoaderAnimationChannel[];
  1051. samplers: _ILoaderAnimationSampler[];
  1052. _babylonAnimationGroup?: AnimationGroup;
  1053. }
  1054. /** @hidden */
  1055. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  1056. _data?: Promise<ArrayBufferView>;
  1057. }
  1058. /** @hidden */
  1059. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  1060. _data?: Promise<ArrayBufferView>;
  1061. _babylonBuffer?: Promise<Buffer>;
  1062. }
  1063. /** @hidden */
  1064. interface _ILoaderCamera extends ICamera, _IArrayItem {
  1065. }
  1066. /** @hidden */
  1067. interface _ILoaderImage extends IImage, _IArrayItem {
  1068. _blob?: Promise<Blob>;
  1069. }
  1070. /** @hidden */
  1071. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  1072. _babylonData?: {
  1073. [drawMode: number]: {
  1074. material: Material;
  1075. meshes: AbstractMesh[];
  1076. loaded: Promise<void>;
  1077. };
  1078. };
  1079. }
  1080. /** @hidden */
  1081. interface _ILoaderMesh extends IMesh, _IArrayItem {
  1082. primitives: _ILoaderMeshPrimitive[];
  1083. }
  1084. /** @hidden */
  1085. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  1086. }
  1087. /** @hidden */
  1088. interface _ILoaderNode extends INode, _IArrayItem {
  1089. _parent?: _ILoaderNode;
  1090. _babylonMesh?: Mesh;
  1091. _primitiveBabylonMeshes?: Mesh[];
  1092. _babylonBones?: Bone[];
  1093. _numMorphTargets?: number;
  1094. }
  1095. /** @hidden */
  1096. interface _ILoaderSamplerData {
  1097. noMipMaps: boolean;
  1098. samplingMode: number;
  1099. wrapU: number;
  1100. wrapV: number;
  1101. }
  1102. /** @hidden */
  1103. interface _ILoaderSampler extends ISampler, _IArrayItem {
  1104. _data?: _ILoaderSamplerData;
  1105. }
  1106. /** @hidden */
  1107. interface _ILoaderScene extends IScene, _IArrayItem {
  1108. }
  1109. /** @hidden */
  1110. interface _ILoaderSkin extends ISkin, _IArrayItem {
  1111. _babylonSkeleton?: Skeleton;
  1112. _loaded?: Promise<void>;
  1113. }
  1114. /** @hidden */
  1115. interface _ILoaderTexture extends ITexture, _IArrayItem {
  1116. }
  1117. /** @hidden */
  1118. interface _ILoaderGLTF extends IGLTF {
  1119. accessors?: _ILoaderAccessor[];
  1120. animations?: _ILoaderAnimation[];
  1121. buffers?: _ILoaderBuffer[];
  1122. bufferViews?: _ILoaderBufferView[];
  1123. cameras?: _ILoaderCamera[];
  1124. images?: _ILoaderImage[];
  1125. materials?: _ILoaderMaterial[];
  1126. meshes?: _ILoaderMesh[];
  1127. nodes?: _ILoaderNode[];
  1128. samplers?: _ILoaderSampler[];
  1129. scenes?: _ILoaderScene[];
  1130. skins?: _ILoaderSkin[];
  1131. textures?: _ILoaderTexture[];
  1132. }
  1133. }
  1134. /**
  1135. * Defines the module used to import/export glTF 2.0 assets
  1136. */
  1137. declare module BABYLON.GLTF2 {
  1138. /**
  1139. * Loader for loading a glTF 2.0 asset
  1140. */
  1141. class GLTFLoader implements IGLTFLoader {
  1142. /** @hidden */
  1143. _gltf: _ILoaderGLTF;
  1144. /** @hidden */
  1145. _babylonScene: Scene;
  1146. /** @hidden */
  1147. _completePromises: Promise<void>[];
  1148. /** @hidden */
  1149. _onReadyObservable: Observable<IGLTFLoader>;
  1150. private _disposed;
  1151. private _state;
  1152. private _extensions;
  1153. private _rootUrl;
  1154. private _rootBabylonMesh;
  1155. private _defaultSampler;
  1156. private _defaultBabylonMaterials;
  1157. private _progressCallback?;
  1158. private _requests;
  1159. private static _ExtensionNames;
  1160. private static _ExtensionFactories;
  1161. /** @hidden */
  1162. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1163. /**
  1164. * Mode that determines the coordinate system to use.
  1165. */
  1166. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  1167. /**
  1168. * Mode that determines what animations will start.
  1169. */
  1170. animationStartMode: GLTFLoaderAnimationStartMode;
  1171. /**
  1172. * Defines if the loader should compile materials.
  1173. */
  1174. compileMaterials: boolean;
  1175. /**
  1176. * Defines if the loader should also compile materials with clip planes.
  1177. */
  1178. useClipPlane: boolean;
  1179. /**
  1180. * Defines if the loader should compile shadow generators.
  1181. */
  1182. compileShadowGenerators: boolean;
  1183. /**
  1184. * Defines if the Alpha blended materials are only applied as coverage.
  1185. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  1186. * If true, no extra effects are applied to transparent pixels.
  1187. */
  1188. transparencyAsCoverage: boolean;
  1189. /** @hidden */
  1190. _normalizeAnimationGroupsToBeginAtZero: boolean;
  1191. /**
  1192. * Function called before loading a url referenced by the asset.
  1193. */
  1194. preprocessUrlAsync: (url: string) => Promise<string>;
  1195. /**
  1196. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  1197. */
  1198. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  1199. /**
  1200. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  1201. */
  1202. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  1203. /**
  1204. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  1205. */
  1206. readonly onMaterialLoadedObservable: Observable<Material>;
  1207. /**
  1208. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  1209. */
  1210. readonly onCameraLoadedObservable: Observable<Camera>;
  1211. /**
  1212. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  1213. * For assets with LODs, raised when all of the LODs are complete.
  1214. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  1215. */
  1216. readonly onCompleteObservable: Observable<IGLTFLoader>;
  1217. /**
  1218. * Observable raised after the loader is disposed.
  1219. */
  1220. readonly onDisposeObservable: Observable<IGLTFLoader>;
  1221. /**
  1222. * Observable raised after a loader extension is created.
  1223. * Set additional options for a loader extension in this event.
  1224. */
  1225. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  1226. /**
  1227. * Loader state or null if the loader is not active.
  1228. */
  1229. readonly state: Nullable<GLTFLoaderState>;
  1230. /**
  1231. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  1232. */
  1233. dispose(): void;
  1234. /**
  1235. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  1236. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1237. * @param scene the scene the meshes should be added to
  1238. * @param data the glTF data to load
  1239. * @param rootUrl root url to load from
  1240. * @param onProgress event that fires when loading progress has occured
  1241. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1242. */
  1243. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1244. meshes: AbstractMesh[];
  1245. particleSystems: ParticleSystem[];
  1246. skeletons: Skeleton[];
  1247. animationGroups: AnimationGroup[];
  1248. }>;
  1249. /**
  1250. * Imports all objects from the loaded glTF data and adds them to the scene
  1251. * @param scene the scene the objects should be added to
  1252. * @param data the glTF data to load
  1253. * @param rootUrl root url to load from
  1254. * @param onProgress event that fires when loading progress has occured
  1255. * @returns a promise which completes when objects have been loaded to the scene
  1256. */
  1257. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1258. private _loadAsync(nodes);
  1259. private _loadData(data);
  1260. private _setupData();
  1261. private _loadExtensions();
  1262. private _checkExtensions();
  1263. private _createRootNode();
  1264. private _loadNodesAsync(nodes);
  1265. /** @hidden */
  1266. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1267. private _forEachPrimitive(node, callback);
  1268. private _getMeshes();
  1269. private _getSkeletons();
  1270. private _getAnimationGroups();
  1271. private _startAnimations();
  1272. /** @hidden */
  1273. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1274. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1275. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1276. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1277. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1278. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1279. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1280. private static _LoadTransform(node, babylonNode);
  1281. private _loadSkinAsync(context, node, mesh, skin);
  1282. private _loadBones(context, skin);
  1283. private _loadBone(node, skin, babylonBones);
  1284. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1285. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1286. private _getNodeMatrix(node);
  1287. private _loadCamera(context, camera, babylonMesh);
  1288. private _loadAnimationsAsync();
  1289. private _loadAnimationAsync(context, animation);
  1290. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1291. private _loadAnimationSamplerAsync(context, sampler);
  1292. private _loadBufferAsync(context, buffer);
  1293. /** @hidden */
  1294. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1295. private _loadIndicesAccessorAsync(context, accessor);
  1296. private _loadFloatAccessorAsync(context, accessor);
  1297. /** @hidden */
  1298. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1299. private _loadVertexAccessorAsync(context, accessor, kind);
  1300. private _getDefaultMaterial(drawMode);
  1301. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1302. /** @hidden */
  1303. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1304. /** @hidden */
  1305. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1306. /** @hidden */
  1307. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1308. /** @hidden */
  1309. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1310. /** @hidden */
  1311. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1312. private _loadSampler(context, sampler);
  1313. private _loadImageAsync(context, image);
  1314. /** @hidden */
  1315. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1316. private _onProgress();
  1317. /** @hidden */
  1318. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1319. private static _GetTextureWrapMode(context, mode);
  1320. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1321. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1322. private static _GetNumComponents(context, type);
  1323. private static _ValidateUri(uri);
  1324. private static _GetDrawMode(context, mode);
  1325. private _compileMaterialsAsync();
  1326. private _compileShadowGeneratorsAsync();
  1327. private _clear();
  1328. /** @hidden */
  1329. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1330. }
  1331. }
  1332. declare module BABYLON.GLTF2 {
  1333. /**
  1334. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1335. */
  1336. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1337. /**
  1338. * Gets or sets a boolean indicating if the extension is enabled
  1339. */
  1340. enabled: boolean;
  1341. /**
  1342. * Gets or sets extension name
  1343. */
  1344. readonly abstract name: string;
  1345. protected _loader: GLTFLoader;
  1346. /**
  1347. * Creates new GLTFLoaderExtension
  1348. * @param loader defines the GLTFLoader to use
  1349. */
  1350. constructor(loader: GLTFLoader);
  1351. /**
  1352. * Release all resources
  1353. */
  1354. dispose(): void;
  1355. /**
  1356. * Override this method to modify the default behavior for loading scenes.
  1357. * @hidden
  1358. */
  1359. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1360. /**
  1361. * Override this method to modify the default behavior for loading nodes.
  1362. * @hidden
  1363. */
  1364. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1365. /**
  1366. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1367. * @hidden
  1368. */
  1369. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1370. /**
  1371. * Override this method to modify the default behavior for loading materials.
  1372. * @hidden
  1373. */
  1374. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1375. /**
  1376. * Override this method to modify the default behavior for loading textures.
  1377. * @hidden
  1378. */
  1379. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1380. /**
  1381. * Override this method to modify the default behavior for loading uris.
  1382. * @hidden
  1383. */
  1384. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1385. /**
  1386. * Helper method called by a loader extension to load an glTF extension.
  1387. * @hidden
  1388. */
  1389. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1390. /**
  1391. * Helper method called by the loader to allow extensions to override loading scenes.
  1392. * @hidden
  1393. */
  1394. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1395. /**
  1396. * Helper method called by the loader to allow extensions to override loading scenes.
  1397. * @hidden
  1398. */
  1399. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1400. /**
  1401. * Helper method called by the loader to allow extensions to override loading nodes.
  1402. * @hidden
  1403. */
  1404. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1405. /**
  1406. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1407. * @hidden
  1408. */
  1409. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1410. /**
  1411. * Helper method called by the loader to allow extensions to override loading materials.
  1412. * @hidden
  1413. */
  1414. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1415. /**
  1416. * Helper method called by the loader to allow extensions to override loading textures.
  1417. * @hidden
  1418. */
  1419. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1420. /**
  1421. * Helper method called by the loader to allow extensions to override loading uris.
  1422. * @hidden
  1423. */
  1424. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1425. }
  1426. }
  1427. /**
  1428. * Defines the module of the glTF 2.0 loader extensions.
  1429. */
  1430. declare module BABYLON.GLTF2.Extensions {
  1431. }
  1432. declare module BABYLON.GLTF2.Extensions {
  1433. /**
  1434. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1435. */
  1436. class MSFT_lod extends GLTFLoaderExtension {
  1437. readonly name: string;
  1438. /**
  1439. * Maximum number of LODs to load, starting from the lowest LOD.
  1440. */
  1441. maxLODsToLoad: number;
  1442. /**
  1443. * Observable raised when all node LODs of one level are loaded.
  1444. * The event data is the index of the loaded LOD starting from zero.
  1445. * Dispose the loader to cancel the loading of the next level of LODs.
  1446. */
  1447. onNodeLODsLoadedObservable: Observable<number>;
  1448. /**
  1449. * Observable raised when all material LODs of one level are loaded.
  1450. * The event data is the index of the loaded LOD starting from zero.
  1451. * Dispose the loader to cancel the loading of the next level of LODs.
  1452. */
  1453. onMaterialLODsLoadedObservable: Observable<number>;
  1454. private _loadingNodeLOD;
  1455. private _loadNodeSignals;
  1456. private _loadNodePromises;
  1457. private _loadingMaterialLOD;
  1458. private _loadMaterialSignals;
  1459. private _loadMaterialPromises;
  1460. constructor(loader: GLTFLoader);
  1461. dispose(): void;
  1462. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1463. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1464. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1465. /**
  1466. * Gets an array of LOD properties from lowest to highest.
  1467. */
  1468. private _getLODs<T>(context, property, array, ids);
  1469. }
  1470. }
  1471. declare module BABYLON.GLTF2.Extensions {
  1472. /** @hidden */
  1473. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1474. readonly name: string;
  1475. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1476. }
  1477. }
  1478. declare module BABYLON.GLTF2.Extensions {
  1479. /** @hidden */
  1480. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1481. readonly name: string;
  1482. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1483. }
  1484. }
  1485. declare module BABYLON.GLTF2.Extensions {
  1486. /**
  1487. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1488. */
  1489. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1490. readonly name: string;
  1491. private _dracoCompression;
  1492. constructor(loader: GLTFLoader);
  1493. dispose(): void;
  1494. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1495. }
  1496. }
  1497. declare module BABYLON.GLTF2.Extensions {
  1498. /**
  1499. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1500. */
  1501. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1502. readonly name: string;
  1503. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1504. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1505. }
  1506. }
  1507. declare module BABYLON.GLTF2.Extensions {
  1508. /**
  1509. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1510. */
  1511. class KHR_materials_unlit extends GLTFLoaderExtension {
  1512. readonly name: string;
  1513. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1514. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1515. }
  1516. }
  1517. declare module BABYLON.GLTF2.Extensions {
  1518. /**
  1519. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1520. */
  1521. class KHR_lights extends GLTFLoaderExtension {
  1522. readonly name: string;
  1523. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1524. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1525. private readonly _lights;
  1526. }
  1527. }
  1528. declare module BABYLON.GLTF2.Extensions {
  1529. /**
  1530. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1531. */
  1532. class KHR_texture_transform extends GLTFLoaderExtension {
  1533. readonly name: string;
  1534. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1535. }
  1536. }