babylonjs.loaders.module.d.ts 63 KB

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