babylon.glTF2FileLoader.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. babylonMesh?: Mesh;
  215. babylonSkinToBones?: {
  216. [skin: number]: Bone;
  217. };
  218. babylonAnimationTargets?: Node[];
  219. }
  220. interface IGLTFSampler extends IGLTFChildRootProperty {
  221. magFilter?: ETextureMagFilter;
  222. minFilter?: ETextureMinFilter;
  223. wrapS?: ETextureWrapMode;
  224. wrapT?: ETextureWrapMode;
  225. }
  226. interface IGLTFScene extends IGLTFChildRootProperty {
  227. nodes: number[];
  228. }
  229. interface IGLTFSkin extends IGLTFChildRootProperty {
  230. inverseBindMatrices?: number;
  231. skeleton?: number;
  232. joints: number[];
  233. index?: number;
  234. babylonSkeleton?: Skeleton;
  235. }
  236. interface IGLTFTexture extends IGLTFChildRootProperty {
  237. sampler?: number;
  238. source: number;
  239. babylonTextures?: Texture[];
  240. blobURL?: string;
  241. }
  242. interface IGLTFTextureInfo {
  243. index: number;
  244. texCoord?: number;
  245. }
  246. interface IGLTF extends IGLTFProperty {
  247. accessors?: IGLTFAccessor[];
  248. animations?: IGLTFAnimation[];
  249. asset: IGLTFAsset;
  250. buffers?: IGLTFBuffer[];
  251. bufferViews?: IGLTFBufferView[];
  252. cameras?: IGLTFCamera[];
  253. extensionsUsed?: string[];
  254. extensionsRequired?: string[];
  255. glExtensionsUsed?: string[];
  256. images?: IGLTFImage[];
  257. materials?: IGLTFMaterial[];
  258. meshes?: IGLTFMesh[];
  259. nodes?: IGLTFNode[];
  260. samplers?: IGLTFSampler[];
  261. scene?: number;
  262. scenes?: IGLTFScene[];
  263. skins?: IGLTFSkin[];
  264. textures?: IGLTFTexture[];
  265. }
  266. }
  267. declare module BABYLON.GLTF2 {
  268. class GLTFLoader implements IGLTFLoader {
  269. private _gltf;
  270. private _pendingCount;
  271. private _onLoaded;
  272. private _errors;
  273. private _babylonScene;
  274. private _rootUrl;
  275. private _defaultMaterial;
  276. static Extensions: {
  277. [name: string]: GLTFLoaderExtension;
  278. };
  279. static RegisterExtension(extension: GLTFLoaderExtension): void;
  280. static LoadMaterial(index: number): IGLTFMaterial;
  281. static LoadCoreMaterial(index: number): Material;
  282. static LoadCommonMaterialProperties(material: IGLTFMaterial): void;
  283. static LoadAlphaProperties(material: IGLTFMaterial): void;
  284. static LoadTexture(textureInfo: IGLTFTextureInfo): Texture;
  285. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void;
  286. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  287. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onError);
  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, parentNode);
  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 _traverseScene(nodeNames, scene, action);
  303. private _traverseNode(nodeNames, 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. private _addPendingData(data);
  310. private _removePendingData(data);
  311. private _getDefaultMaterial();
  312. private _loadMaterial(index);
  313. private _loadCoreMaterial(index);
  314. private _loadCommonMaterialProperties(material);
  315. private _loadAlphaProperties(material);
  316. private _loadTexture(textureInfo);
  317. }
  318. }
  319. declare module BABYLON.GLTF2 {
  320. /**
  321. * Utils functions for GLTF
  322. */
  323. class GLTFUtils {
  324. /**
  325. * If the uri is a base64 string
  326. * @param uri: the uri to test
  327. */
  328. static IsBase64(uri: string): boolean;
  329. /**
  330. * Decode the base64 uri
  331. * @param uri: the uri to decode
  332. */
  333. static DecodeBase64(uri: string): ArrayBuffer;
  334. /**
  335. * Returns the wrap mode of the texture
  336. * @param mode: the mode value
  337. */
  338. static GetWrapMode(mode: number): number;
  339. /**
  340. * Returns the byte stride giving an accessor
  341. * @param accessor: the GLTF accessor objet
  342. */
  343. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  344. /**
  345. * Returns the texture filter mode giving a mode value
  346. * @param mode: the filter mode value
  347. */
  348. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  349. /**
  350. * Decodes a buffer view into a string
  351. * @param view: the buffer view
  352. */
  353. static DecodeBufferToText(view: ArrayBufferView): string;
  354. }
  355. }
  356. declare module BABYLON.GLTF2 {
  357. abstract class GLTFLoaderExtension {
  358. private _name;
  359. enabled: boolean;
  360. constructor(name: string);
  361. readonly name: string;
  362. protected loadMaterial(index: number): Material;
  363. static LoadMaterial(index: number): Material;
  364. }
  365. }
  366. declare module BABYLON.GLTF2 {
  367. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  368. constructor();
  369. protected loadMaterial(index: number): Material;
  370. }
  371. }