babylonjs.loaders.module.d.ts 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  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. * Function called before loading a url referenced by the asset.
  198. */
  199. preprocessUrlAsync: (url: string) => Promise<string>;
  200. /**
  201. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  202. */
  203. onMeshLoadedObservable: Observable<AbstractMesh>;
  204. /**
  205. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  206. */
  207. onTextureLoadedObservable: Observable<BaseTexture>;
  208. /**
  209. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  210. */
  211. onMaterialLoadedObservable: Observable<Material>;
  212. /**
  213. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  214. */
  215. onCameraLoadedObservable: Observable<Camera>;
  216. /**
  217. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  218. * For assets with LODs, raised when all of the LODs are complete.
  219. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  220. */
  221. onCompleteObservable: Observable<IGLTFLoader>;
  222. /**
  223. * Observable raised after the loader is disposed.
  224. */
  225. onDisposeObservable: Observable<IGLTFLoader>;
  226. /**
  227. * Observable raised after a loader extension is created.
  228. * Set additional options for a loader extension in this event.
  229. */
  230. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  231. /**
  232. * Loader state or null if the loader is not active.
  233. */
  234. state: Nullable<GLTFLoaderState>;
  235. /**
  236. * Imports meshes from the given data and adds them to the scene.
  237. */
  238. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  239. meshes: AbstractMesh[];
  240. particleSystems: ParticleSystem[];
  241. skeletons: Skeleton[];
  242. animationGroups: AnimationGroup[];
  243. }>;
  244. /**
  245. * Loads all objects from the given data and adds them to the scene.
  246. */
  247. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  248. }
  249. /**
  250. * File loader for loading glTF files into a scene.
  251. */
  252. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  253. /**
  254. * Factory function that creates a glTF 1.0 loader
  255. */
  256. static CreateGLTFLoaderV1: () => IGLTFLoader;
  257. /**
  258. * Factory function that creates a glTF 2.0 loader
  259. */
  260. static CreateGLTFLoaderV2: () => IGLTFLoader;
  261. /**
  262. * Raised when the asset has been parsed
  263. */
  264. onParsedObservable: Observable<IGLTFLoaderData>;
  265. private _onParsedObserver;
  266. /**
  267. * Raised when the asset has been parsed
  268. */
  269. onParsed: (loaderData: IGLTFLoaderData) => void;
  270. /**
  271. * 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.
  272. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  273. * Defaults to true.
  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. */
  280. static HomogeneousCoordinates: boolean;
  281. /**
  282. * The coordinate system mode. Defaults to AUTO.
  283. */
  284. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  285. /**
  286. * The animation start mode. Defaults to FIRST.
  287. */
  288. animationStartMode: GLTFLoaderAnimationStartMode;
  289. /**
  290. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  291. */
  292. compileMaterials: boolean;
  293. /**
  294. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  295. */
  296. useClipPlane: boolean;
  297. /**
  298. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  299. */
  300. compileShadowGenerators: boolean;
  301. /**
  302. * Function called before loading a url referenced by the asset.
  303. */
  304. preprocessUrlAsync: (url: string) => Promise<string>;
  305. /**
  306. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  307. */
  308. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  309. private _onMeshLoadedObserver;
  310. /**
  311. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  312. */
  313. onMeshLoaded: (mesh: AbstractMesh) => void;
  314. /**
  315. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  316. */
  317. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  318. private _onTextureLoadedObserver;
  319. /**
  320. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  321. */
  322. onTextureLoaded: (texture: BaseTexture) => void;
  323. /**
  324. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  325. */
  326. readonly onMaterialLoadedObservable: Observable<Material>;
  327. private _onMaterialLoadedObserver;
  328. /**
  329. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  330. */
  331. onMaterialLoaded: (material: Material) => void;
  332. /**
  333. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  334. */
  335. readonly onCameraLoadedObservable: Observable<Camera>;
  336. private _onCameraLoadedObserver;
  337. /**
  338. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  339. */
  340. onCameraLoaded: (camera: Camera) => void;
  341. /**
  342. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  343. * For assets with LODs, raised when all of the LODs are complete.
  344. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  345. */
  346. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  347. private _onCompleteObserver;
  348. /**
  349. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  350. */
  351. onComplete: () => void;
  352. /**
  353. * Observable raised after the loader is disposed.
  354. */
  355. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  356. private _onDisposeObserver;
  357. /**
  358. * Callback raised after the loader is disposed.
  359. */
  360. onDispose: () => void;
  361. /**
  362. * Observable raised after a loader extension is created.
  363. * Set additional options for a loader extension in this event.
  364. */
  365. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  366. private _onExtensionLoadedObserver;
  367. /**
  368. * Callback raised after a loader extension is created.
  369. */
  370. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  371. /**
  372. * Returns a promise that resolves when the asset is completely loaded.
  373. * @returns a promise that resolves when the asset is completely loaded.
  374. */
  375. whenCompleteAsync(): Promise<void>;
  376. /**
  377. * The loader state or null if the loader is not active.
  378. */
  379. readonly loaderState: Nullable<GLTFLoaderState>;
  380. private _loader;
  381. /**
  382. * Name of the loader ("gltf")
  383. */
  384. name: string;
  385. /**
  386. * Supported file extensions of the loader (.gltf, .glb)
  387. */
  388. extensions: ISceneLoaderPluginExtensions;
  389. /**
  390. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  391. */
  392. dispose(): void;
  393. /**
  394. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  395. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  396. * @param scene the scene the meshes should be added to
  397. * @param data the glTF data to load
  398. * @param rootUrl root url to load from
  399. * @param onProgress event that fires when loading progress has occured
  400. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  401. */
  402. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  403. meshes: AbstractMesh[];
  404. particleSystems: ParticleSystem[];
  405. skeletons: Skeleton[];
  406. animationGroups: AnimationGroup[];
  407. }>;
  408. /**
  409. * Imports all objects from the loaded glTF data and adds them to the scene
  410. * @param scene the scene the objects should be added to
  411. * @param data the glTF data to load
  412. * @param rootUrl root url to load from
  413. * @param onProgress event that fires when loading progress has occured
  414. * @returns a promise which completes when objects have been loaded to the scene
  415. */
  416. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  417. /**
  418. * Load into an asset container.
  419. * @param scene The scene to load into
  420. * @param data The data to import
  421. * @param rootUrl The root url for scene and resources
  422. * @param onProgress The callback when the load progresses
  423. * @returns The loaded asset container
  424. */
  425. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  426. /**
  427. * If the data string can be loaded directly.
  428. * @param data string contianing the file data
  429. * @returns if the data can be loaded directly
  430. */
  431. canDirectLoad(data: string): boolean;
  432. /**
  433. * Rewrites a url by combining a root url and response url.
  434. */
  435. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  436. /**
  437. * Instantiates a glTF file loader plugin.
  438. * @returns the created plugin
  439. */
  440. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  441. private _parse(data);
  442. private _getLoader(loaderData);
  443. private static _parseBinary(data);
  444. private static _parseV1(binaryReader);
  445. private static _parseV2(binaryReader);
  446. private static _parseVersion(version);
  447. private static _compareVersion(a, b);
  448. private static _decodeBufferToText(buffer);
  449. }
  450. }
  451. declare module BABYLON.GLTF1 {
  452. /**
  453. * Enums
  454. */
  455. enum EComponentType {
  456. BYTE = 5120,
  457. UNSIGNED_BYTE = 5121,
  458. SHORT = 5122,
  459. UNSIGNED_SHORT = 5123,
  460. FLOAT = 5126,
  461. }
  462. enum EShaderType {
  463. FRAGMENT = 35632,
  464. VERTEX = 35633,
  465. }
  466. enum EParameterType {
  467. BYTE = 5120,
  468. UNSIGNED_BYTE = 5121,
  469. SHORT = 5122,
  470. UNSIGNED_SHORT = 5123,
  471. INT = 5124,
  472. UNSIGNED_INT = 5125,
  473. FLOAT = 5126,
  474. FLOAT_VEC2 = 35664,
  475. FLOAT_VEC3 = 35665,
  476. FLOAT_VEC4 = 35666,
  477. INT_VEC2 = 35667,
  478. INT_VEC3 = 35668,
  479. INT_VEC4 = 35669,
  480. BOOL = 35670,
  481. BOOL_VEC2 = 35671,
  482. BOOL_VEC3 = 35672,
  483. BOOL_VEC4 = 35673,
  484. FLOAT_MAT2 = 35674,
  485. FLOAT_MAT3 = 35675,
  486. FLOAT_MAT4 = 35676,
  487. SAMPLER_2D = 35678,
  488. }
  489. enum ETextureWrapMode {
  490. CLAMP_TO_EDGE = 33071,
  491. MIRRORED_REPEAT = 33648,
  492. REPEAT = 10497,
  493. }
  494. enum ETextureFilterType {
  495. NEAREST = 9728,
  496. LINEAR = 9728,
  497. NEAREST_MIPMAP_NEAREST = 9984,
  498. LINEAR_MIPMAP_NEAREST = 9985,
  499. NEAREST_MIPMAP_LINEAR = 9986,
  500. LINEAR_MIPMAP_LINEAR = 9987,
  501. }
  502. enum ETextureFormat {
  503. ALPHA = 6406,
  504. RGB = 6407,
  505. RGBA = 6408,
  506. LUMINANCE = 6409,
  507. LUMINANCE_ALPHA = 6410,
  508. }
  509. enum ECullingType {
  510. FRONT = 1028,
  511. BACK = 1029,
  512. FRONT_AND_BACK = 1032,
  513. }
  514. enum EBlendingFunction {
  515. ZERO = 0,
  516. ONE = 1,
  517. SRC_COLOR = 768,
  518. ONE_MINUS_SRC_COLOR = 769,
  519. DST_COLOR = 774,
  520. ONE_MINUS_DST_COLOR = 775,
  521. SRC_ALPHA = 770,
  522. ONE_MINUS_SRC_ALPHA = 771,
  523. DST_ALPHA = 772,
  524. ONE_MINUS_DST_ALPHA = 773,
  525. CONSTANT_COLOR = 32769,
  526. ONE_MINUS_CONSTANT_COLOR = 32770,
  527. CONSTANT_ALPHA = 32771,
  528. ONE_MINUS_CONSTANT_ALPHA = 32772,
  529. SRC_ALPHA_SATURATE = 776,
  530. }
  531. /**
  532. * Interfaces
  533. */
  534. interface IGLTFProperty {
  535. extensions?: {
  536. [key: string]: any;
  537. };
  538. extras?: Object;
  539. }
  540. interface IGLTFChildRootProperty extends IGLTFProperty {
  541. name?: string;
  542. }
  543. interface IGLTFAccessor extends IGLTFChildRootProperty {
  544. bufferView: string;
  545. byteOffset: number;
  546. byteStride: number;
  547. count: number;
  548. type: string;
  549. componentType: EComponentType;
  550. max?: number[];
  551. min?: number[];
  552. name?: string;
  553. }
  554. interface IGLTFBufferView extends IGLTFChildRootProperty {
  555. buffer: string;
  556. byteOffset: number;
  557. byteLength: number;
  558. byteStride: number;
  559. target?: number;
  560. }
  561. interface IGLTFBuffer extends IGLTFChildRootProperty {
  562. uri: string;
  563. byteLength?: number;
  564. type?: string;
  565. }
  566. interface IGLTFShader extends IGLTFChildRootProperty {
  567. uri: string;
  568. type: EShaderType;
  569. }
  570. interface IGLTFProgram extends IGLTFChildRootProperty {
  571. attributes: string[];
  572. fragmentShader: string;
  573. vertexShader: string;
  574. }
  575. interface IGLTFTechniqueParameter {
  576. type: number;
  577. count?: number;
  578. semantic?: string;
  579. node?: string;
  580. value?: number | boolean | string | Array<any>;
  581. source?: string;
  582. babylonValue?: any;
  583. }
  584. interface IGLTFTechniqueCommonProfile {
  585. lightingModel: string;
  586. texcoordBindings: Object;
  587. parameters?: Array<any>;
  588. }
  589. interface IGLTFTechniqueStatesFunctions {
  590. blendColor?: number[];
  591. blendEquationSeparate?: number[];
  592. blendFuncSeparate?: number[];
  593. colorMask: boolean[];
  594. cullFace: number[];
  595. }
  596. interface IGLTFTechniqueStates {
  597. enable: number[];
  598. functions: IGLTFTechniqueStatesFunctions;
  599. }
  600. interface IGLTFTechnique extends IGLTFChildRootProperty {
  601. parameters: {
  602. [key: string]: IGLTFTechniqueParameter;
  603. };
  604. program: string;
  605. attributes: {
  606. [key: string]: string;
  607. };
  608. uniforms: {
  609. [key: string]: string;
  610. };
  611. states: IGLTFTechniqueStates;
  612. }
  613. interface IGLTFMaterial extends IGLTFChildRootProperty {
  614. technique?: string;
  615. values: string[];
  616. }
  617. interface IGLTFMeshPrimitive extends IGLTFProperty {
  618. attributes: {
  619. [key: string]: string;
  620. };
  621. indices: string;
  622. material: string;
  623. mode?: number;
  624. }
  625. interface IGLTFMesh extends IGLTFChildRootProperty {
  626. primitives: IGLTFMeshPrimitive[];
  627. }
  628. interface IGLTFImage extends IGLTFChildRootProperty {
  629. uri: string;
  630. }
  631. interface IGLTFSampler extends IGLTFChildRootProperty {
  632. magFilter?: number;
  633. minFilter?: number;
  634. wrapS?: number;
  635. wrapT?: number;
  636. }
  637. interface IGLTFTexture extends IGLTFChildRootProperty {
  638. sampler: string;
  639. source: string;
  640. format?: ETextureFormat;
  641. internalFormat?: ETextureFormat;
  642. target?: number;
  643. type?: number;
  644. babylonTexture?: Texture;
  645. }
  646. interface IGLTFAmbienLight {
  647. color?: number[];
  648. }
  649. interface IGLTFDirectionalLight {
  650. color?: number[];
  651. }
  652. interface IGLTFPointLight {
  653. color?: number[];
  654. constantAttenuation?: number;
  655. linearAttenuation?: number;
  656. quadraticAttenuation?: number;
  657. }
  658. interface IGLTFSpotLight {
  659. color?: number[];
  660. constantAttenuation?: number;
  661. fallOfAngle?: number;
  662. fallOffExponent?: number;
  663. linearAttenuation?: number;
  664. quadraticAttenuation?: number;
  665. }
  666. interface IGLTFLight extends IGLTFChildRootProperty {
  667. type: string;
  668. }
  669. interface IGLTFCameraOrthographic {
  670. xmag: number;
  671. ymag: number;
  672. zfar: number;
  673. znear: number;
  674. }
  675. interface IGLTFCameraPerspective {
  676. aspectRatio: number;
  677. yfov: number;
  678. zfar: number;
  679. znear: number;
  680. }
  681. interface IGLTFCamera extends IGLTFChildRootProperty {
  682. type: string;
  683. }
  684. interface IGLTFAnimationChannelTarget {
  685. id: string;
  686. path: string;
  687. }
  688. interface IGLTFAnimationChannel {
  689. sampler: string;
  690. target: IGLTFAnimationChannelTarget;
  691. }
  692. interface IGLTFAnimationSampler {
  693. input: string;
  694. output: string;
  695. interpolation?: string;
  696. }
  697. interface IGLTFAnimation extends IGLTFChildRootProperty {
  698. channels?: IGLTFAnimationChannel[];
  699. parameters?: {
  700. [key: string]: string;
  701. };
  702. samplers?: {
  703. [key: string]: IGLTFAnimationSampler;
  704. };
  705. }
  706. interface IGLTFNodeInstanceSkin {
  707. skeletons: string[];
  708. skin: string;
  709. meshes: string[];
  710. }
  711. interface IGLTFSkins extends IGLTFChildRootProperty {
  712. bindShapeMatrix: number[];
  713. inverseBindMatrices: string;
  714. jointNames: string[];
  715. babylonSkeleton?: Skeleton;
  716. }
  717. interface IGLTFNode extends IGLTFChildRootProperty {
  718. camera?: string;
  719. children: string[];
  720. skin?: string;
  721. jointName?: string;
  722. light?: string;
  723. matrix: number[];
  724. mesh?: string;
  725. meshes?: string[];
  726. rotation?: number[];
  727. scale?: number[];
  728. translation?: number[];
  729. babylonNode?: Node;
  730. }
  731. interface IGLTFScene extends IGLTFChildRootProperty {
  732. nodes: string[];
  733. }
  734. /**
  735. * Runtime
  736. */
  737. interface IGLTFRuntime {
  738. extensions: {
  739. [key: string]: any;
  740. };
  741. accessors: {
  742. [key: string]: IGLTFAccessor;
  743. };
  744. buffers: {
  745. [key: string]: IGLTFBuffer;
  746. };
  747. bufferViews: {
  748. [key: string]: IGLTFBufferView;
  749. };
  750. meshes: {
  751. [key: string]: IGLTFMesh;
  752. };
  753. lights: {
  754. [key: string]: IGLTFLight;
  755. };
  756. cameras: {
  757. [key: string]: IGLTFCamera;
  758. };
  759. nodes: {
  760. [key: string]: IGLTFNode;
  761. };
  762. images: {
  763. [key: string]: IGLTFImage;
  764. };
  765. textures: {
  766. [key: string]: IGLTFTexture;
  767. };
  768. shaders: {
  769. [key: string]: IGLTFShader;
  770. };
  771. programs: {
  772. [key: string]: IGLTFProgram;
  773. };
  774. samplers: {
  775. [key: string]: IGLTFSampler;
  776. };
  777. techniques: {
  778. [key: string]: IGLTFTechnique;
  779. };
  780. materials: {
  781. [key: string]: IGLTFMaterial;
  782. };
  783. animations: {
  784. [key: string]: IGLTFAnimation;
  785. };
  786. skins: {
  787. [key: string]: IGLTFSkins;
  788. };
  789. currentScene?: Object;
  790. scenes: {
  791. [key: string]: IGLTFScene;
  792. };
  793. extensionsUsed: string[];
  794. extensionsRequired?: string[];
  795. buffersCount: number;
  796. shaderscount: number;
  797. scene: Scene;
  798. rootUrl: string;
  799. loadedBufferCount: number;
  800. loadedBufferViews: {
  801. [name: string]: ArrayBufferView;
  802. };
  803. loadedShaderCount: number;
  804. importOnlyMeshes: boolean;
  805. importMeshesNames?: string[];
  806. dummyNodes: Node[];
  807. }
  808. /**
  809. * Bones
  810. */
  811. interface INodeToRoot {
  812. bone: Bone;
  813. node: IGLTFNode;
  814. id: string;
  815. }
  816. interface IJointNode {
  817. node: IGLTFNode;
  818. id: string;
  819. }
  820. }
  821. declare module BABYLON.GLTF1 {
  822. /**
  823. * Implementation of the base glTF spec
  824. */
  825. class GLTFLoaderBase {
  826. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  827. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  828. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  829. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  830. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  831. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  832. }
  833. /**
  834. * glTF V1 Loader
  835. */
  836. class GLTFLoader implements IGLTFLoader {
  837. static Extensions: {
  838. [name: string]: GLTFLoaderExtension;
  839. };
  840. static RegisterExtension(extension: GLTFLoaderExtension): void;
  841. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  842. animationStartMode: GLTFLoaderAnimationStartMode;
  843. compileMaterials: boolean;
  844. useClipPlane: boolean;
  845. compileShadowGenerators: boolean;
  846. preprocessUrlAsync: (url: string) => Promise<string>;
  847. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  848. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  849. readonly onMaterialLoadedObservable: Observable<Material>;
  850. readonly onCameraLoadedObservable: Observable<Camera>;
  851. readonly onCompleteObservable: Observable<IGLTFLoader>;
  852. readonly onDisposeObservable: Observable<IGLTFLoader>;
  853. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  854. state: Nullable<GLTFLoaderState>;
  855. dispose(): void;
  856. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  857. /**
  858. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  859. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  860. * @param scene the scene the meshes should be added to
  861. * @param data gltf data containing information of the meshes in a loaded file
  862. * @param rootUrl root url to load from
  863. * @param onProgress event that fires when loading progress has occured
  864. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  865. */
  866. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  867. meshes: AbstractMesh[];
  868. particleSystems: ParticleSystem[];
  869. skeletons: Skeleton[];
  870. animationGroups: AnimationGroup[];
  871. }>;
  872. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  873. /**
  874. * Imports all objects from a loaded gltf file and adds them to the scene
  875. * @param scene the scene the objects should be added to
  876. * @param data gltf data containing information of the meshes in a loaded file
  877. * @param rootUrl root url to load from
  878. * @param onProgress event that fires when loading progress has occured
  879. * @returns a promise which completes when objects have been loaded to the scene
  880. */
  881. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  882. private _loadShadersAsync(gltfRuntime, onload);
  883. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  884. private _createNodes(gltfRuntime);
  885. }
  886. }
  887. declare module BABYLON.GLTF1 {
  888. /**
  889. * Utils functions for GLTF
  890. */
  891. class GLTFUtils {
  892. /**
  893. * Sets the given "parameter" matrix
  894. * @param scene: the {BABYLON.Scene} object
  895. * @param source: the source node where to pick the matrix
  896. * @param parameter: the GLTF technique parameter
  897. * @param uniformName: the name of the shader's uniform
  898. * @param shaderMaterial: the shader material
  899. */
  900. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  901. /**
  902. * Sets the given "parameter" matrix
  903. * @param shaderMaterial: the shader material
  904. * @param uniform: the name of the shader's uniform
  905. * @param value: the value of the uniform
  906. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  907. */
  908. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  909. /**
  910. * Returns the wrap mode of the texture
  911. * @param mode: the mode value
  912. */
  913. static GetWrapMode(mode: number): number;
  914. /**
  915. * Returns the byte stride giving an accessor
  916. * @param accessor: the GLTF accessor objet
  917. */
  918. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  919. /**
  920. * Returns the texture filter mode giving a mode value
  921. * @param mode: the filter mode value
  922. */
  923. static GetTextureFilterMode(mode: number): ETextureFilterType;
  924. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  925. /**
  926. * Returns a buffer from its accessor
  927. * @param gltfRuntime: the GLTF runtime
  928. * @param accessor: the GLTF accessor
  929. */
  930. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  931. /**
  932. * Decodes a buffer view into a string
  933. * @param view: the buffer view
  934. */
  935. static DecodeBufferToText(view: ArrayBufferView): string;
  936. /**
  937. * Returns the default material of gltf. Related to
  938. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  939. * @param scene: the Babylon.js scene
  940. */
  941. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  942. private static _DefaultMaterial;
  943. }
  944. }
  945. declare module BABYLON.GLTF1 {
  946. abstract class GLTFLoaderExtension {
  947. private _name;
  948. constructor(name: string);
  949. readonly name: string;
  950. /**
  951. * Defines an override for loading the runtime
  952. * Return true to stop further extensions from loading the runtime
  953. */
  954. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  955. /**
  956. * Defines an onverride for creating gltf runtime
  957. * Return true to stop further extensions from creating the runtime
  958. */
  959. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  960. /**
  961. * Defines an override for loading buffers
  962. * Return true to stop further extensions from loading this buffer
  963. */
  964. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  965. /**
  966. * Defines an override for loading texture buffers
  967. * Return true to stop further extensions from loading this texture data
  968. */
  969. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  970. /**
  971. * Defines an override for creating textures
  972. * Return true to stop further extensions from loading this texture
  973. */
  974. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  975. /**
  976. * Defines an override for loading shader strings
  977. * Return true to stop further extensions from loading this shader data
  978. */
  979. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  980. /**
  981. * Defines an override for loading materials
  982. * Return true to stop further extensions from loading this material
  983. */
  984. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  985. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  986. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  987. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  988. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  989. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  990. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  991. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  992. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  993. private static ApplyExtensions(func, defaultFunc);
  994. }
  995. }
  996. declare module BABYLON.GLTF1 {
  997. class GLTFBinaryExtension extends GLTFLoaderExtension {
  998. private _bin;
  999. constructor();
  1000. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  1001. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  1002. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  1003. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  1004. }
  1005. }
  1006. declare module BABYLON.GLTF1 {
  1007. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  1008. constructor();
  1009. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  1010. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  1011. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  1012. }
  1013. }
  1014. declare module BABYLON.GLTF2 {
  1015. /** @hidden */
  1016. interface _IArrayItem {
  1017. _index: number;
  1018. }
  1019. /** @hidden */
  1020. class _ArrayItem {
  1021. /** @hidden */
  1022. static Assign(values?: _IArrayItem[]): void;
  1023. }
  1024. }
  1025. declare module BABYLON.GLTF2 {
  1026. /** @hidden */
  1027. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  1028. _data?: Promise<ArrayBufferView>;
  1029. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1030. }
  1031. /** @hidden */
  1032. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  1033. }
  1034. /** @hidden */
  1035. interface _ILoaderAnimationSamplerData {
  1036. input: Float32Array;
  1037. interpolation: AnimationSamplerInterpolation;
  1038. output: Float32Array;
  1039. }
  1040. /** @hidden */
  1041. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  1042. _data: Promise<_ILoaderAnimationSamplerData>;
  1043. }
  1044. /** @hidden */
  1045. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  1046. channels: _ILoaderAnimationChannel[];
  1047. samplers: _ILoaderAnimationSampler[];
  1048. _babylonAnimationGroup?: AnimationGroup;
  1049. }
  1050. /** @hidden */
  1051. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  1052. _data?: Promise<ArrayBufferView>;
  1053. }
  1054. /** @hidden */
  1055. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  1056. _data?: Promise<ArrayBufferView>;
  1057. _babylonBuffer?: Promise<Buffer>;
  1058. }
  1059. /** @hidden */
  1060. interface _ILoaderCamera extends ICamera, _IArrayItem {
  1061. }
  1062. /** @hidden */
  1063. interface _ILoaderImage extends IImage, _IArrayItem {
  1064. _objectURL?: Promise<string>;
  1065. }
  1066. /** @hidden */
  1067. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  1068. _babylonData?: {
  1069. [drawMode: number]: {
  1070. material: Material;
  1071. meshes: AbstractMesh[];
  1072. loaded: Promise<void>;
  1073. };
  1074. };
  1075. }
  1076. /** @hidden */
  1077. interface _ILoaderMesh extends IMesh, _IArrayItem {
  1078. primitives: _ILoaderMeshPrimitive[];
  1079. }
  1080. /** @hidden */
  1081. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  1082. }
  1083. /** @hidden */
  1084. interface _ILoaderNode extends INode, _IArrayItem {
  1085. _parent: _ILoaderNode;
  1086. _babylonMesh?: Mesh;
  1087. _primitiveBabylonMeshes?: Mesh[];
  1088. _babylonAnimationTargets?: Node[];
  1089. _numMorphTargets?: number;
  1090. }
  1091. /** @hidden */
  1092. interface _ILoaderSamplerData {
  1093. noMipMaps: boolean;
  1094. samplingMode: number;
  1095. wrapU: number;
  1096. wrapV: number;
  1097. }
  1098. /** @hidden */
  1099. interface _ILoaderSampler extends ISampler, _IArrayItem {
  1100. _data?: _ILoaderSamplerData;
  1101. }
  1102. /** @hidden */
  1103. interface _ILoaderScene extends IScene, _IArrayItem {
  1104. }
  1105. /** @hidden */
  1106. interface _ILoaderSkin extends ISkin, _IArrayItem {
  1107. _babylonSkeleton?: Skeleton;
  1108. _loaded?: Promise<void>;
  1109. }
  1110. /** @hidden */
  1111. interface _ILoaderTexture extends ITexture, _IArrayItem {
  1112. }
  1113. /** @hidden */
  1114. interface _ILoaderGLTF extends IGLTF {
  1115. accessors?: _ILoaderAccessor[];
  1116. animations?: _ILoaderAnimation[];
  1117. buffers?: _ILoaderBuffer[];
  1118. bufferViews?: _ILoaderBufferView[];
  1119. cameras?: _ILoaderCamera[];
  1120. images?: _ILoaderImage[];
  1121. materials?: _ILoaderMaterial[];
  1122. meshes?: _ILoaderMesh[];
  1123. nodes?: _ILoaderNode[];
  1124. samplers?: _ILoaderSampler[];
  1125. scenes?: _ILoaderScene[];
  1126. skins?: _ILoaderSkin[];
  1127. textures?: _ILoaderTexture[];
  1128. }
  1129. }
  1130. /**
  1131. * Defines the module used to import/export glTF 2.0 assets
  1132. */
  1133. declare module BABYLON.GLTF2 {
  1134. /** @hidden */
  1135. interface _MaterialConstructor<T extends Material> {
  1136. readonly prototype: T;
  1137. new (name: string, scene: Scene): T;
  1138. }
  1139. /**
  1140. * Loader for loading a glTF 2.0 asset
  1141. */
  1142. class GLTFLoader implements IGLTFLoader {
  1143. /** @hidden */
  1144. _gltf: _ILoaderGLTF;
  1145. /** @hidden */
  1146. _babylonScene: Scene;
  1147. /** @hidden */
  1148. _completePromises: Promise<void>[];
  1149. private _disposed;
  1150. private _state;
  1151. private _extensions;
  1152. private _rootUrl;
  1153. private _rootBabylonMesh;
  1154. private _defaultSampler;
  1155. private _defaultBabylonMaterials;
  1156. private _progressCallback?;
  1157. private _requests;
  1158. private static _ExtensionNames;
  1159. private static _ExtensionFactories;
  1160. /** @hidden */
  1161. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1162. /**
  1163. * Mode that determines the coordinate system to use.
  1164. */
  1165. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  1166. /**
  1167. * Mode that determines what animations will start.
  1168. */
  1169. animationStartMode: GLTFLoaderAnimationStartMode;
  1170. /**
  1171. * Defines if the loader should compile materials.
  1172. */
  1173. compileMaterials: boolean;
  1174. /**
  1175. * Defines if the loader should also compile materials with clip planes.
  1176. */
  1177. useClipPlane: boolean;
  1178. /**
  1179. * Defines if the loader should compile shadow generators.
  1180. */
  1181. compileShadowGenerators: boolean;
  1182. /**
  1183. * Function called before loading a url referenced by the asset.
  1184. */
  1185. preprocessUrlAsync: (url: string) => Promise<string>;
  1186. /**
  1187. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  1188. */
  1189. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  1190. /**
  1191. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  1192. */
  1193. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  1194. /**
  1195. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  1196. */
  1197. readonly onMaterialLoadedObservable: Observable<Material>;
  1198. /**
  1199. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  1200. */
  1201. readonly onCameraLoadedObservable: Observable<Camera>;
  1202. /**
  1203. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  1204. * For assets with LODs, raised when all of the LODs are complete.
  1205. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  1206. */
  1207. readonly onCompleteObservable: Observable<IGLTFLoader>;
  1208. /**
  1209. * Observable raised after the loader is disposed.
  1210. */
  1211. readonly onDisposeObservable: Observable<IGLTFLoader>;
  1212. /**
  1213. * Observable raised after a loader extension is created.
  1214. * Set additional options for a loader extension in this event.
  1215. */
  1216. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  1217. /**
  1218. * Loader state or null if the loader is not active.
  1219. */
  1220. readonly state: Nullable<GLTFLoaderState>;
  1221. /**
  1222. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  1223. */
  1224. dispose(): void;
  1225. /**
  1226. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  1227. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1228. * @param scene the scene the meshes should be added to
  1229. * @param data the glTF data to load
  1230. * @param rootUrl root url to load from
  1231. * @param onProgress event that fires when loading progress has occured
  1232. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1233. */
  1234. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1235. meshes: AbstractMesh[];
  1236. particleSystems: ParticleSystem[];
  1237. skeletons: Skeleton[];
  1238. animationGroups: AnimationGroup[];
  1239. }>;
  1240. /**
  1241. * Imports all objects from the loaded glTF data and adds them to the scene
  1242. * @param scene the scene the objects should be added to
  1243. * @param data the glTF data to load
  1244. * @param rootUrl root url to load from
  1245. * @param onProgress event that fires when loading progress has occured
  1246. * @returns a promise which completes when objects have been loaded to the scene
  1247. */
  1248. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1249. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  1250. private _loadExtensions();
  1251. private _loadData(data);
  1252. private _setupData();
  1253. private _checkExtensions();
  1254. private _createRootNode();
  1255. private _loadNodesAsync(nodes);
  1256. /** @hidden */
  1257. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1258. private _forEachPrimitive(node, callback);
  1259. private _getMeshes();
  1260. private _getSkeletons();
  1261. private _getAnimationGroups();
  1262. private _startAnimations();
  1263. /** @hidden */
  1264. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1265. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1266. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1267. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1268. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1269. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1270. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1271. private static _LoadTransform(node, babylonNode);
  1272. private _loadSkinAsync(context, node, mesh, skin);
  1273. private _loadBones(context, skin);
  1274. private _loadBone(node, skin, babylonBones);
  1275. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1276. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1277. private _getNodeMatrix(node);
  1278. private _loadCamera(context, camera, babylonMesh);
  1279. private _loadAnimationsAsync();
  1280. private _loadAnimationAsync(context, animation);
  1281. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1282. private _loadAnimationSamplerAsync(context, sampler);
  1283. private _loadBufferAsync(context, buffer);
  1284. /** @hidden */
  1285. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1286. private _loadIndicesAccessorAsync(context, accessor);
  1287. private _loadFloatAccessorAsync(context, accessor);
  1288. /** @hidden */
  1289. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1290. private _loadVertexAccessorAsync(context, accessor, kind);
  1291. private _getDefaultMaterial(drawMode);
  1292. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1293. /** @hidden */
  1294. _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1295. /** @hidden */
  1296. _createMaterial<T extends Material>(type: _MaterialConstructor<T>, name: string, drawMode: number): T;
  1297. /** @hidden */
  1298. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1299. /** @hidden */
  1300. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1301. /** @hidden */
  1302. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1303. private _loadSampler(context, sampler);
  1304. private _loadImageAsync(context, image);
  1305. /** @hidden */
  1306. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1307. private _onProgress();
  1308. /** @hidden */
  1309. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1310. private static _GetTextureWrapMode(context, mode);
  1311. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1312. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1313. private static _GetNumComponents(context, type);
  1314. private static _ValidateUri(uri);
  1315. private static _GetDrawMode(context, mode);
  1316. private _compileMaterialsAsync();
  1317. private _compileShadowGeneratorsAsync();
  1318. private _clear();
  1319. /** @hidden */
  1320. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1321. }
  1322. }
  1323. declare module BABYLON.GLTF2 {
  1324. /**
  1325. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1326. */
  1327. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1328. enabled: boolean;
  1329. readonly abstract name: string;
  1330. protected _loader: GLTFLoader;
  1331. constructor(loader: GLTFLoader);
  1332. dispose(): void;
  1333. /** Override this method to modify the default behavior for loading scenes. */
  1334. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1335. /** Override this method to modify the default behavior for loading nodes. */
  1336. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1337. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  1338. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1339. /** Override this method to modify the default behavior for loading materials. */
  1340. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1341. /** Override this method to modify the default behavior for loading uris. */
  1342. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1343. /** Helper method called by a loader extension to load an glTF extension. */
  1344. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>>;
  1345. /** Helper method called by the loader to allow extensions to override loading scenes. */
  1346. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1347. /** Helper method called by the loader to allow extensions to override loading nodes. */
  1348. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1349. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  1350. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1351. /** Helper method called by the loader to allow extensions to override loading materials. */
  1352. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1353. /** Helper method called by the loader to allow extensions to override loading uris. */
  1354. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1355. }
  1356. }
  1357. /**
  1358. * Defines the module of the glTF 2.0 loader extensions.
  1359. */
  1360. declare module BABYLON.GLTF2.Extensions {
  1361. }
  1362. declare module BABYLON.GLTF2.Extensions {
  1363. /**
  1364. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1365. */
  1366. class MSFT_lod extends GLTFLoaderExtension {
  1367. readonly name: string;
  1368. /**
  1369. * Maximum number of LODs to load, starting from the lowest LOD.
  1370. */
  1371. maxLODsToLoad: number;
  1372. private _loadingNodeLOD;
  1373. private _loadNodeSignals;
  1374. private _loadingMaterialLOD;
  1375. private _loadMaterialSignals;
  1376. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1377. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1378. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1379. /**
  1380. * Gets an array of LOD properties from lowest to highest.
  1381. */
  1382. private _getLODs<T>(context, property, array, ids);
  1383. }
  1384. }
  1385. declare module BABYLON.GLTF2.Extensions {
  1386. /**
  1387. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1388. */
  1389. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1390. readonly name: string;
  1391. private _dracoCompression;
  1392. constructor(loader: GLTFLoader);
  1393. dispose(): void;
  1394. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1395. }
  1396. }
  1397. declare module BABYLON.GLTF2.Extensions {
  1398. /**
  1399. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1400. */
  1401. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1402. readonly name: string;
  1403. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1404. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1405. }
  1406. }
  1407. declare module BABYLON.GLTF2.Extensions {
  1408. /**
  1409. * [Specification](https://github.com/donmccurdy/glTF/tree/feat-khr-materials-cmnConstant/extensions/2.0/Khronos/KHR_materials_unlit) (Experimental)
  1410. */
  1411. class KHR_materials_unlit extends GLTFLoaderExtension {
  1412. readonly name: string;
  1413. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1414. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1415. }
  1416. }
  1417. declare module BABYLON.GLTF2.Extensions {
  1418. /**
  1419. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1420. */
  1421. class KHR_lights extends GLTFLoaderExtension {
  1422. readonly name: string;
  1423. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1424. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1425. private readonly _lights;
  1426. }
  1427. }