babylonjs.loaders.d.ts 56 KB

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