babylon.glTF2FileLoader.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 IGLTFAssetProfile extends IGLTFProperty {
  121. api?: string;
  122. version?: string;
  123. }
  124. interface IGLTFAsset extends IGLTFChildRootProperty {
  125. copyright?: string;
  126. generator?: string;
  127. profile?: IGLTFAssetProfile;
  128. version: string;
  129. }
  130. interface IGLTFBuffer extends IGLTFChildRootProperty {
  131. uri?: string;
  132. byteLength: number;
  133. loadedData: ArrayBufferView;
  134. loadedObservable: Observable<IGLTFBuffer>;
  135. }
  136. interface IGLTFBufferView extends IGLTFChildRootProperty {
  137. buffer: number;
  138. byteOffset?: number;
  139. byteLength: number;
  140. byteStride?: number;
  141. }
  142. interface IGLTFCameraOrthographic extends IGLTFProperty {
  143. xmag: number;
  144. ymag: number;
  145. zfar: number;
  146. znear: number;
  147. }
  148. interface IGLTFCameraPerspective extends IGLTFProperty {
  149. aspectRatio: number;
  150. yfov: number;
  151. zfar: number;
  152. znear: number;
  153. }
  154. interface IGLTFCamera extends IGLTFChildRootProperty {
  155. orthographic?: IGLTFCameraOrthographic;
  156. perspective?: IGLTFCameraPerspective;
  157. type: string;
  158. }
  159. interface IGLTFImage extends IGLTFChildRootProperty {
  160. uri?: string;
  161. mimeType?: string;
  162. bufferView?: number;
  163. }
  164. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  165. scale: number;
  166. }
  167. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  168. strength: number;
  169. }
  170. interface IGLTFMaterialPbrMetallicRoughness {
  171. baseColorFactor: number[];
  172. baseColorTexture: IGLTFTextureInfo;
  173. metallicFactor: number;
  174. roughnessFactor: number;
  175. metallicRoughnessTexture: IGLTFTextureInfo;
  176. }
  177. interface IGLTFMaterial extends IGLTFChildRootProperty {
  178. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  179. normalTexture?: IGLTFMaterialNormalTextureInfo;
  180. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  181. emissiveTexture?: IGLTFTextureInfo;
  182. emissiveFactor?: number[];
  183. alphaMode?: string;
  184. alphaCutoff: number;
  185. doubleSided?: boolean;
  186. babylonMaterial?: PBRMaterial;
  187. }
  188. interface IGLTFMeshPrimitive extends IGLTFProperty {
  189. attributes: {
  190. [name: string]: number;
  191. };
  192. indices?: number;
  193. material?: number;
  194. mode?: EMeshPrimitiveMode;
  195. targets?: [{
  196. [name: string]: number;
  197. }];
  198. }
  199. interface IGLTFMesh extends IGLTFChildRootProperty {
  200. primitives: IGLTFMeshPrimitive[];
  201. weights?: number[];
  202. }
  203. interface IGLTFNode extends IGLTFChildRootProperty {
  204. camera?: number;
  205. children?: number[];
  206. skin?: number;
  207. matrix?: number[];
  208. mesh?: number;
  209. rotation?: number[];
  210. scale?: number[];
  211. translation?: number[];
  212. weights?: number[];
  213. index?: number;
  214. babylonNode?: Node;
  215. }
  216. interface IGLTFSampler extends IGLTFChildRootProperty {
  217. magFilter?: ETextureMagFilter;
  218. minFilter?: ETextureMinFilter;
  219. wrapS?: ETextureWrapMode;
  220. wrapT?: ETextureWrapMode;
  221. }
  222. interface IGLTFScene extends IGLTFChildRootProperty {
  223. nodes: number[];
  224. }
  225. interface IGLTFSkin extends IGLTFChildRootProperty {
  226. inverseBindMatrices?: number;
  227. skeleton?: number;
  228. joints: number[];
  229. babylonSkeleton?: Skeleton;
  230. }
  231. interface IGLTFTexture extends IGLTFChildRootProperty {
  232. sampler?: number;
  233. source: number;
  234. babylonTextures?: Texture[];
  235. blobURL?: string;
  236. }
  237. interface IGLTFTextureInfo {
  238. index: number;
  239. texCoord?: number;
  240. }
  241. interface IGLTF extends IGLTFProperty {
  242. accessors?: IGLTFAccessor[];
  243. animations?: IGLTFAnimation[];
  244. asset: IGLTFAsset;
  245. buffers?: IGLTFBuffer[];
  246. bufferViews?: IGLTFBufferView[];
  247. cameras?: IGLTFCamera[];
  248. extensionsUsed?: string[];
  249. extensionsRequired?: string[];
  250. glExtensionsUsed?: string[];
  251. images?: IGLTFImage[];
  252. materials?: IGLTFMaterial[];
  253. meshes?: IGLTFMesh[];
  254. nodes?: IGLTFNode[];
  255. samplers?: IGLTFSampler[];
  256. scene?: number;
  257. scenes?: IGLTFScene[];
  258. skins?: IGLTFSkin[];
  259. textures?: IGLTFTexture[];
  260. }
  261. }
  262. declare module BABYLON.GLTF2 {
  263. class GLTFLoader implements IGLTFLoader {
  264. private _gltf;
  265. private _pendingCount;
  266. private _onLoaded;
  267. private _errors;
  268. private _babylonScene;
  269. private _rootUrl;
  270. private _defaultMaterial;
  271. static Extensions: {
  272. [name: string]: GLTFLoaderExtension;
  273. };
  274. static RegisterExtension(extension: GLTFLoaderExtension): void;
  275. static LoadMaterial(index: number): IGLTFMaterial;
  276. static LoadCoreMaterial(index: number): Material;
  277. static LoadCommonMaterialProperties(material: IGLTFMaterial): void;
  278. static LoadAlphaProperties(material: IGLTFMaterial): void;
  279. static LoadTexture(textureInfo: IGLTFTextureInfo): Texture;
  280. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void;
  281. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  282. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onError);
  283. private _loadData(data);
  284. private _showMeshes();
  285. private _startFirstAnimation();
  286. private _clear();
  287. private _loadScene(nodeNames);
  288. private _loadSkin(node);
  289. private _updateBone(node, parentNode, skin, inverseBindMatrixData);
  290. private _loadMesh(node, parentNode);
  291. private _loadMeshData(node, mesh, babylonMesh);
  292. private _loadVertexDataAsync(primitive, onSuccess);
  293. private _createMorphTargets(node, mesh, primitive, babylonMesh);
  294. private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
  295. private _loadTransform(node, babylonMesh);
  296. private _traverseScene(nodeNames, scene, action);
  297. private _traverseNode(nodeNames, index, action, parentNode?);
  298. private _loadAnimations();
  299. private _loadAnimationChannel(animation, animationIndex, channelIndex);
  300. private _loadBufferAsync(index, onSuccess);
  301. private _loadBufferViewAsync(bufferView, byteOffset, byteLength, componentType, onSuccess);
  302. private _loadAccessorAsync(accessor, onSuccess);
  303. private _addPendingData(data);
  304. private _removePendingData(data);
  305. private _getDefaultMaterial();
  306. private _loadMaterial(index);
  307. private _loadCoreMaterial(index);
  308. private _loadCommonMaterialProperties(material);
  309. private _loadAlphaProperties(material);
  310. private _loadTexture(textureInfo);
  311. }
  312. }
  313. declare module BABYLON.GLTF2 {
  314. /**
  315. * Utils functions for GLTF
  316. */
  317. class GLTFUtils {
  318. /**
  319. * If the uri is a base64 string
  320. * @param uri: the uri to test
  321. */
  322. static IsBase64(uri: string): boolean;
  323. /**
  324. * Decode the base64 uri
  325. * @param uri: the uri to decode
  326. */
  327. static DecodeBase64(uri: string): ArrayBuffer;
  328. /**
  329. * Returns the wrap mode of the texture
  330. * @param mode: the mode value
  331. */
  332. static GetWrapMode(mode: number): number;
  333. /**
  334. * Returns the byte stride giving an accessor
  335. * @param accessor: the GLTF accessor objet
  336. */
  337. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  338. /**
  339. * Returns the texture filter mode giving a mode value
  340. * @param mode: the filter mode value
  341. */
  342. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  343. /**
  344. * Decodes a buffer view into a string
  345. * @param view: the buffer view
  346. */
  347. static DecodeBufferToText(view: ArrayBufferView): string;
  348. }
  349. }
  350. declare module BABYLON.GLTF2 {
  351. abstract class GLTFLoaderExtension {
  352. private _name;
  353. enabled: boolean;
  354. constructor(name: string);
  355. readonly name: string;
  356. protected loadMaterial(index: number): Material;
  357. static LoadMaterial(index: number): Material;
  358. }
  359. }
  360. declare module BABYLON.GLTF2 {
  361. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  362. constructor();
  363. protected loadMaterial(index: number): Material;
  364. }
  365. }