babylon.glTF2FileLoader.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. private static _parse(data);
  19. private _getLoader(loaderData);
  20. private static _parseBinary(data);
  21. private static _parseV1(binaryReader);
  22. private static _parseV2(binaryReader);
  23. private static _parseVersion(version);
  24. private static _compareVersion(a, b);
  25. private static _decodeBufferToText(view);
  26. }
  27. }
  28. declare module BABYLON.GLTF2 {
  29. /**
  30. * Enums
  31. */
  32. enum EComponentType {
  33. BYTE = 5120,
  34. UNSIGNED_BYTE = 5121,
  35. SHORT = 5122,
  36. UNSIGNED_SHORT = 5123,
  37. UNSIGNED_INT = 5125,
  38. FLOAT = 5126,
  39. }
  40. enum EMeshPrimitiveMode {
  41. POINTS = 0,
  42. LINES = 1,
  43. LINE_LOOP = 2,
  44. LINE_STRIP = 3,
  45. TRIANGLES = 4,
  46. TRIANGLE_STRIP = 5,
  47. TRIANGLE_FAN = 6,
  48. }
  49. enum ETextureMagFilter {
  50. NEAREST = 9728,
  51. LINEAR = 9729,
  52. }
  53. enum ETextureMinFilter {
  54. NEAREST = 9728,
  55. LINEAR = 9729,
  56. NEAREST_MIPMAP_NEAREST = 9984,
  57. LINEAR_MIPMAP_NEAREST = 9985,
  58. NEAREST_MIPMAP_LINEAR = 9986,
  59. LINEAR_MIPMAP_LINEAR = 9987,
  60. }
  61. enum ETextureWrapMode {
  62. CLAMP_TO_EDGE = 33071,
  63. MIRRORED_REPEAT = 33648,
  64. REPEAT = 10497,
  65. }
  66. /**
  67. * Interfaces
  68. */
  69. interface IGLTFProperty {
  70. extensions?: Object;
  71. extras?: any;
  72. }
  73. interface IGLTFChildRootProperty extends IGLTFProperty {
  74. name?: string;
  75. }
  76. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  77. bufferView: number;
  78. byteOffset?: number;
  79. componentType: EComponentType;
  80. }
  81. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  82. bufferView: number;
  83. byteOffset?: number;
  84. }
  85. interface IGLTFAccessorSparse extends IGLTFProperty {
  86. count: number;
  87. indices: IGLTFAccessorSparseIndices;
  88. values: IGLTFAccessorSparseValues;
  89. }
  90. interface IGLTFAccessor extends IGLTFChildRootProperty {
  91. bufferView?: number;
  92. byteOffset?: number;
  93. componentType: EComponentType;
  94. normalized?: boolean;
  95. count: number;
  96. type: string;
  97. max: number[];
  98. min: number[];
  99. sparse?: IGLTFAccessorSparse;
  100. }
  101. interface IGLTFAnimationChannel extends IGLTFProperty {
  102. sampler: number;
  103. target: IGLTFAnimationChannelTarget;
  104. }
  105. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  106. node: number;
  107. path: string;
  108. }
  109. interface IGLTFAnimationSampler extends IGLTFProperty {
  110. input: number;
  111. interpolation?: string;
  112. output: number;
  113. }
  114. interface IGLTFAnimation extends IGLTFChildRootProperty {
  115. channels: IGLTFAnimationChannel[];
  116. samplers: IGLTFAnimationSampler[];
  117. }
  118. interface IGLTFAssetProfile extends IGLTFProperty {
  119. api?: string;
  120. version?: string;
  121. }
  122. interface IGLTFAsset extends IGLTFChildRootProperty {
  123. copyright?: string;
  124. generator?: string;
  125. profile?: IGLTFAssetProfile;
  126. version: string;
  127. }
  128. interface IGLTFBuffer extends IGLTFChildRootProperty {
  129. uri?: string;
  130. byteLength: number;
  131. loadedBufferView: ArrayBufferView;
  132. }
  133. interface IGLTFBufferView extends IGLTFChildRootProperty {
  134. buffer: number;
  135. byteOffset?: number;
  136. byteLength: number;
  137. byteStride?: number;
  138. }
  139. interface IGLTFCameraOrthographic extends IGLTFProperty {
  140. xmag: number;
  141. ymag: number;
  142. zfar: number;
  143. znear: number;
  144. }
  145. interface IGLTFCameraPerspective extends IGLTFProperty {
  146. aspectRatio: number;
  147. yfov: number;
  148. zfar: number;
  149. znear: number;
  150. }
  151. interface IGLTFCamera extends IGLTFChildRootProperty {
  152. orthographic?: IGLTFCameraOrthographic;
  153. perspective?: IGLTFCameraPerspective;
  154. type: string;
  155. }
  156. interface IGLTFImage extends IGLTFChildRootProperty {
  157. uri?: string;
  158. mimeType?: string;
  159. bufferView?: number;
  160. }
  161. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  162. scale: number;
  163. }
  164. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  165. strength: number;
  166. }
  167. interface IGLTFMaterialPbrMetallicRoughness {
  168. baseColorFactor: number[];
  169. baseColorTexture: IGLTFTextureInfo;
  170. metallicFactor: number;
  171. roughnessFactor: number;
  172. metallicRoughnessTexture: IGLTFTextureInfo;
  173. }
  174. interface IGLTFMaterial extends IGLTFChildRootProperty {
  175. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  176. normalTexture?: IGLTFMaterialNormalTextureInfo;
  177. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  178. emissiveTexture?: IGLTFTextureInfo;
  179. emissiveFactor?: number[];
  180. alphaMode?: string;
  181. alphaCutoff: number;
  182. doubleSided?: boolean;
  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. babylonNode?: Node;
  211. }
  212. interface IGLTFSampler extends IGLTFChildRootProperty {
  213. magFilter?: ETextureMagFilter;
  214. minFilter?: ETextureMinFilter;
  215. wrapS?: ETextureWrapMode;
  216. wrapT?: ETextureWrapMode;
  217. }
  218. interface IGLTFScene extends IGLTFChildRootProperty {
  219. nodes: number[];
  220. }
  221. interface IGLTFSkin extends IGLTFChildRootProperty {
  222. inverseBindMatrices?: number;
  223. skeleton?: number;
  224. joints: number[];
  225. babylonSkeleton?: Skeleton;
  226. }
  227. interface IGLTFTexture extends IGLTFChildRootProperty {
  228. sampler?: number;
  229. source: number;
  230. babylonTextures: Texture[];
  231. blobURL: string;
  232. }
  233. interface IGLTFTextureInfo {
  234. index: number;
  235. texCoord?: number;
  236. }
  237. interface IGLTF extends IGLTFProperty {
  238. accessors?: IGLTFAccessor[];
  239. animations?: IGLTFAnimation[];
  240. asset: IGLTFAsset;
  241. buffers?: IGLTFBuffer[];
  242. bufferViews?: IGLTFBufferView[];
  243. cameras?: IGLTFCamera[];
  244. extensionsUsed?: string[];
  245. extensionsRequired?: string[];
  246. glExtensionsUsed?: string[];
  247. images?: IGLTFImage[];
  248. materials?: IGLTFMaterial[];
  249. meshes?: IGLTFMesh[];
  250. nodes?: IGLTFNode[];
  251. samplers?: IGLTFSampler[];
  252. scene?: number;
  253. scenes?: IGLTFScene[];
  254. skins?: IGLTFSkin[];
  255. textures?: IGLTFTexture[];
  256. }
  257. interface IGLTFRuntime {
  258. gltf: IGLTF;
  259. babylonScene: Scene;
  260. rootUrl: string;
  261. importOnlyMeshes: boolean;
  262. importMeshesNames?: string[];
  263. defaultMaterial?: PBRMaterial;
  264. }
  265. /**
  266. * Bones
  267. */
  268. interface INodeToRoot {
  269. bone: Bone;
  270. node: IGLTFNode;
  271. index: number;
  272. }
  273. interface IJointNode {
  274. node: IGLTFNode;
  275. index: number;
  276. }
  277. }
  278. declare module BABYLON.GLTF2 {
  279. /**
  280. * glTF File Loader Plugin
  281. */
  282. class GLTFLoader implements IGLTFLoader {
  283. static Extensions: {
  284. [name: string]: GLTFLoaderExtension;
  285. };
  286. static RegisterExtension(extension: GLTFLoaderExtension): void;
  287. static LoadMaterial(runtime: IGLTFRuntime, index: number): IGLTFMaterial;
  288. static LoadCoreMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void;
  289. private static _loadMetallicRoughnessMaterialPropertiesAsync(runtime, material, onSuccess, onError);
  290. static LoadCommonMaterialPropertiesAsync(runtime: IGLTFRuntime, material: IGLTFMaterial, onSuccess: () => void, onError: () => void): void;
  291. static LoadAlphaProperties(runtime: IGLTFRuntime, material: IGLTFMaterial): void;
  292. static LoadTextureAsync(runtime: IGLTFRuntime, textureInfo: IGLTFTextureInfo, onSuccess: (babylonTexture: Texture) => void, onError: () => void): void;
  293. private static _createTextureAsync(runtime, texture, texCoord, url, onSuccess, onError);
  294. /**
  295. * Import meshes
  296. */
  297. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void): void;
  298. /**
  299. * Load scene
  300. */
  301. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  302. private static _loadBuffersAsync(runtime, onSuccess, onError);
  303. private static _loadBufferAsync(runtime, index, onSuccess, onError);
  304. private static _loadMaterialsAsync(runtime, onSuccess, onError);
  305. private static _createRuntime(scene, data, rootUrl, importOnlyMeshes);
  306. }
  307. }
  308. declare module BABYLON.GLTF2 {
  309. /**
  310. * Utils functions for GLTF
  311. */
  312. class GLTFUtils {
  313. /**
  314. * If the uri is a base64 string
  315. * @param uri: the uri to test
  316. */
  317. static IsBase64(uri: string): boolean;
  318. /**
  319. * Decode the base64 uri
  320. * @param uri: the uri to decode
  321. */
  322. static DecodeBase64(uri: string): ArrayBuffer;
  323. /**
  324. * Returns the wrap mode of the texture
  325. * @param mode: the mode value
  326. */
  327. static GetWrapMode(mode: number): number;
  328. /**
  329. * Returns the byte stride giving an accessor
  330. * @param accessor: the GLTF accessor objet
  331. */
  332. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  333. /**
  334. * Returns the texture filter mode giving a mode value
  335. * @param mode: the filter mode value
  336. */
  337. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  338. static GetBufferFromBufferView(runtime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  339. /**
  340. * Returns a buffer from its accessor
  341. * @param runtime: the GLTF runtime
  342. * @param accessor: the GLTF accessor
  343. */
  344. static GetBufferFromAccessor(runtime: IGLTFRuntime, accessor: IGLTFAccessor): ArrayBufferView;
  345. /**
  346. * Decodes a buffer view into a string
  347. * @param view: the buffer view
  348. */
  349. static DecodeBufferToText(view: ArrayBufferView): string;
  350. /**
  351. * Returns the default material of gltf.
  352. * @param scene: the Babylon.js scene
  353. */
  354. static GetDefaultMaterial(runtime: IGLTFRuntime): PBRMaterial;
  355. }
  356. }
  357. declare module BABYLON.GLTF2 {
  358. abstract class GLTFLoaderExtension {
  359. private _name;
  360. enabled: boolean;
  361. constructor(name: string);
  362. readonly name: string;
  363. protected postCreateRuntime(runtime: IGLTFRuntime): void;
  364. protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean;
  365. static PostCreateRuntime(runtime: IGLTFRuntime): void;
  366. static LoadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void;
  367. }
  368. }
  369. declare module BABYLON.GLTF2 {
  370. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  371. constructor();
  372. protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean;
  373. }
  374. }