babylon.glTF2FileLoader.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. declare module BABYLON {
  2. interface IGLTFLoaderData {
  3. json: Object;
  4. bin: ArrayBufferView;
  5. }
  6. interface IGLTFLoader {
  7. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onsuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onerror: () => void) => void;
  8. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onsuccess: () => void, onerror: () => void) => void;
  9. }
  10. class GLTFFileLoader implements ISceneLoaderPluginAsync {
  11. static GLTFLoaderV1: IGLTFLoader;
  12. static GLTFLoaderV2: IGLTFLoader;
  13. static HomogeneousCoordinates: boolean;
  14. static IncrementalLoading: boolean;
  15. extensions: ISceneLoaderPluginExtensions;
  16. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void;
  17. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  18. canDirectLoad(data: string): boolean;
  19. private static _parse(data);
  20. private _getLoader(loaderData);
  21. private static _parseBinary(data);
  22. private static _parseV1(binaryReader);
  23. private static _parseV2(binaryReader);
  24. private static _parseVersion(version);
  25. private static _compareVersion(a, b);
  26. private static _decodeBufferToText(view);
  27. }
  28. }
  29. declare module BABYLON.GLTF2 {
  30. /**
  31. * Enums
  32. */
  33. enum EComponentType {
  34. BYTE = 5120,
  35. UNSIGNED_BYTE = 5121,
  36. SHORT = 5122,
  37. UNSIGNED_SHORT = 5123,
  38. UNSIGNED_INT = 5125,
  39. FLOAT = 5126,
  40. }
  41. enum EMeshPrimitiveMode {
  42. POINTS = 0,
  43. LINES = 1,
  44. LINE_LOOP = 2,
  45. LINE_STRIP = 3,
  46. TRIANGLES = 4,
  47. TRIANGLE_STRIP = 5,
  48. TRIANGLE_FAN = 6,
  49. }
  50. enum ETextureMagFilter {
  51. NEAREST = 9728,
  52. LINEAR = 9729,
  53. }
  54. enum ETextureMinFilter {
  55. NEAREST = 9728,
  56. LINEAR = 9729,
  57. NEAREST_MIPMAP_NEAREST = 9984,
  58. LINEAR_MIPMAP_NEAREST = 9985,
  59. NEAREST_MIPMAP_LINEAR = 9986,
  60. LINEAR_MIPMAP_LINEAR = 9987,
  61. }
  62. enum ETextureWrapMode {
  63. CLAMP_TO_EDGE = 33071,
  64. MIRRORED_REPEAT = 33648,
  65. REPEAT = 10497,
  66. }
  67. /**
  68. * Interfaces
  69. */
  70. interface IGLTFProperty {
  71. extensions?: Object;
  72. extras?: any;
  73. }
  74. interface IGLTFChildRootProperty extends IGLTFProperty {
  75. name?: string;
  76. }
  77. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  78. bufferView: number;
  79. byteOffset?: number;
  80. componentType: EComponentType;
  81. }
  82. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  83. bufferView: number;
  84. byteOffset?: number;
  85. }
  86. interface IGLTFAccessorSparse extends IGLTFProperty {
  87. count: number;
  88. indices: IGLTFAccessorSparseIndices;
  89. values: IGLTFAccessorSparseValues;
  90. }
  91. interface IGLTFAccessor extends IGLTFChildRootProperty {
  92. bufferView?: number;
  93. byteOffset?: number;
  94. componentType: EComponentType;
  95. normalized?: boolean;
  96. count: number;
  97. type: string;
  98. max: number[];
  99. min: number[];
  100. sparse?: IGLTFAccessorSparse;
  101. }
  102. interface IGLTFAnimationChannel extends IGLTFProperty {
  103. sampler: number;
  104. target: IGLTFAnimationChannelTarget;
  105. }
  106. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  107. node: number;
  108. path: string;
  109. }
  110. interface IGLTFAnimationSampler extends IGLTFProperty {
  111. input: number;
  112. interpolation?: string;
  113. output: number;
  114. }
  115. interface IGLTFAnimation extends IGLTFChildRootProperty {
  116. channels: IGLTFAnimationChannel[];
  117. samplers: IGLTFAnimationSampler[];
  118. targets?: any[];
  119. }
  120. interface IGLTFAsset extends IGLTFChildRootProperty {
  121. copyright?: string;
  122. generator?: string;
  123. version: string;
  124. minVersion?: string;
  125. }
  126. interface IGLTFBuffer extends IGLTFChildRootProperty {
  127. uri?: string;
  128. byteLength: number;
  129. loadedData: ArrayBufferView;
  130. loadedObservable: Observable<IGLTFBuffer>;
  131. }
  132. interface IGLTFBufferView extends IGLTFChildRootProperty {
  133. buffer: number;
  134. byteOffset?: number;
  135. byteLength: number;
  136. byteStride?: number;
  137. }
  138. interface IGLTFCameraOrthographic extends IGLTFProperty {
  139. xmag: number;
  140. ymag: number;
  141. zfar: number;
  142. znear: number;
  143. }
  144. interface IGLTFCameraPerspective extends IGLTFProperty {
  145. aspectRatio: number;
  146. yfov: number;
  147. zfar: number;
  148. znear: number;
  149. }
  150. interface IGLTFCamera extends IGLTFChildRootProperty {
  151. orthographic?: IGLTFCameraOrthographic;
  152. perspective?: IGLTFCameraPerspective;
  153. type: string;
  154. }
  155. interface IGLTFImage extends IGLTFChildRootProperty {
  156. uri?: string;
  157. mimeType?: string;
  158. bufferView?: number;
  159. }
  160. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  161. scale: number;
  162. }
  163. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  164. strength: number;
  165. }
  166. interface IGLTFMaterialPbrMetallicRoughness {
  167. baseColorFactor: number[];
  168. baseColorTexture: IGLTFTextureInfo;
  169. metallicFactor: number;
  170. roughnessFactor: number;
  171. metallicRoughnessTexture: IGLTFTextureInfo;
  172. }
  173. interface IGLTFMaterial extends IGLTFChildRootProperty {
  174. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  175. normalTexture?: IGLTFMaterialNormalTextureInfo;
  176. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  177. emissiveTexture?: IGLTFTextureInfo;
  178. emissiveFactor?: number[];
  179. alphaMode?: string;
  180. alphaCutoff: number;
  181. doubleSided?: boolean;
  182. index?: number;
  183. babylonMaterial?: PBRMaterial;
  184. }
  185. interface IGLTFMeshPrimitive extends IGLTFProperty {
  186. attributes: {
  187. [name: string]: number;
  188. };
  189. indices?: number;
  190. material?: number;
  191. mode?: EMeshPrimitiveMode;
  192. targets?: [{
  193. [name: string]: number;
  194. }];
  195. }
  196. interface IGLTFMesh extends IGLTFChildRootProperty {
  197. primitives: IGLTFMeshPrimitive[];
  198. weights?: number[];
  199. }
  200. interface IGLTFNode extends IGLTFChildRootProperty {
  201. camera?: number;
  202. children?: number[];
  203. skin?: number;
  204. matrix?: number[];
  205. mesh?: number;
  206. rotation?: number[];
  207. scale?: number[];
  208. translation?: number[];
  209. weights?: number[];
  210. index?: number;
  211. parent?: IGLTFNode;
  212. babylonMesh?: Mesh;
  213. babylonSkinToBones?: {
  214. [skin: number]: Bone;
  215. };
  216. babylonAnimationTargets?: Node[];
  217. }
  218. interface IGLTFSampler extends IGLTFChildRootProperty {
  219. magFilter?: ETextureMagFilter;
  220. minFilter?: ETextureMinFilter;
  221. wrapS?: ETextureWrapMode;
  222. wrapT?: ETextureWrapMode;
  223. }
  224. interface IGLTFScene extends IGLTFChildRootProperty {
  225. nodes: number[];
  226. }
  227. interface IGLTFSkin extends IGLTFChildRootProperty {
  228. inverseBindMatrices?: number;
  229. skeleton?: number;
  230. joints: number[];
  231. index?: number;
  232. babylonSkeleton?: Skeleton;
  233. }
  234. interface IGLTFTexture extends IGLTFChildRootProperty {
  235. sampler?: number;
  236. source: number;
  237. babylonTextures?: Texture[];
  238. blobURL?: string;
  239. }
  240. interface IGLTFTextureInfo {
  241. index: number;
  242. texCoord?: number;
  243. }
  244. interface IGLTF extends IGLTFProperty {
  245. accessors?: IGLTFAccessor[];
  246. animations?: IGLTFAnimation[];
  247. asset: IGLTFAsset;
  248. buffers?: IGLTFBuffer[];
  249. bufferViews?: IGLTFBufferView[];
  250. cameras?: IGLTFCamera[];
  251. extensionsUsed?: string[];
  252. extensionsRequired?: string[];
  253. glExtensionsUsed?: string[];
  254. images?: IGLTFImage[];
  255. materials?: IGLTFMaterial[];
  256. meshes?: IGLTFMesh[];
  257. nodes?: IGLTFNode[];
  258. samplers?: IGLTFSampler[];
  259. scene?: number;
  260. scenes?: IGLTFScene[];
  261. skins?: IGLTFSkin[];
  262. textures?: IGLTFTexture[];
  263. }
  264. }
  265. declare module BABYLON.GLTF2 {
  266. class GLTFLoader implements IGLTFLoader {
  267. private _gltf;
  268. private _errors;
  269. private _babylonScene;
  270. private _rootUrl;
  271. private _defaultMaterial;
  272. private _onSuccess;
  273. private _onError;
  274. private _renderReady;
  275. private _renderPendingCount;
  276. private _loaderPendingCount;
  277. static Extensions: {
  278. [name: string]: GLTFLoaderExtension;
  279. };
  280. static RegisterExtension(extension: GLTFLoaderExtension): void;
  281. readonly gltf: IGLTF;
  282. readonly babylonScene: Scene;
  283. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void;
  284. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  285. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onError);
  286. private _onRenderReady();
  287. private _onLoaderComplete();
  288. private _loadData(data);
  289. private _showMeshes();
  290. private _startAnimations();
  291. private _clear();
  292. private _loadScene(nodeNames);
  293. private _loadSkin(node);
  294. private _updateBone(node, parentNode, skin, inverseBindMatrixData);
  295. private _createBone(node, skin);
  296. private _loadMesh(node);
  297. private _loadMeshData(node, mesh, babylonMesh);
  298. private _loadVertexDataAsync(primitive, onSuccess);
  299. private _createMorphTargets(node, mesh, primitive, babylonMesh);
  300. private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
  301. private _loadTransform(node, babylonMesh);
  302. private _traverseNodes(indices, action, parentNode?);
  303. private _traverseNode(index, action, parentNode?);
  304. private _loadAnimations();
  305. private _loadAnimationChannel(animation, animationIndex, channelIndex);
  306. private _loadBufferAsync(index, onSuccess);
  307. private _loadBufferViewAsync(bufferView, byteOffset, byteLength, componentType, onSuccess);
  308. private _loadAccessorAsync(accessor, onSuccess);
  309. addPendingData(data: any): void;
  310. removePendingData(data: any): void;
  311. addLoaderPendingData(data: any): void;
  312. removeLoaderPendingData(data: any): void;
  313. private _getDefaultMaterial();
  314. private _loadMaterialMetallicRoughnessProperties(material);
  315. loadMaterial(index: number, assign: (material: Material) => void): void;
  316. createPbrMaterial(material: IGLTFMaterial): void;
  317. loadMaterialBaseProperties(material: IGLTFMaterial): void;
  318. loadMaterialAlphaProperties(material: IGLTFMaterial): void;
  319. loadTexture(textureInfo: IGLTFTextureInfo): Texture;
  320. }
  321. }
  322. declare module BABYLON.GLTF2 {
  323. /**
  324. * Utils functions for GLTF
  325. */
  326. class GLTFUtils {
  327. /**
  328. * If the uri is a base64 string
  329. * @param uri: the uri to test
  330. */
  331. static IsBase64(uri: string): boolean;
  332. /**
  333. * Decode the base64 uri
  334. * @param uri: the uri to decode
  335. */
  336. static DecodeBase64(uri: string): ArrayBuffer;
  337. /**
  338. * Returns the wrap mode of the texture
  339. * @param mode: the mode value
  340. */
  341. static GetWrapMode(mode: number): number;
  342. /**
  343. * Returns the byte stride giving an accessor
  344. * @param accessor: the GLTF accessor objet
  345. */
  346. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  347. /**
  348. * Returns the texture filter mode giving a mode value
  349. * @param mode: the filter mode value
  350. */
  351. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  352. /**
  353. * Decodes a buffer view into a string
  354. * @param view: the buffer view
  355. */
  356. static DecodeBufferToText(view: ArrayBufferView): string;
  357. }
  358. }
  359. declare module BABYLON.GLTF2 {
  360. abstract class GLTFLoaderExtension {
  361. enabled: boolean;
  362. readonly abstract name: string;
  363. protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
  364. static _Extensions: GLTFLoaderExtension[];
  365. static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
  366. private static _ApplyExtensions(action);
  367. }
  368. }
  369. declare module BABYLON.GLTF2.Extensions {
  370. class MSFTLOD extends GLTFLoaderExtension {
  371. readonly name: string;
  372. protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
  373. private loadMaterialLOD(loader, material, materialLODs, lod, assign);
  374. }
  375. }
  376. declare module BABYLON.GLTF2.Extensions {
  377. class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
  378. readonly name: string;
  379. protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (material: Material) => void): boolean;
  380. }
  381. }