babylon.glTF2FileLoader.d.ts 13 KB

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