babylon.glTF2FileLoader.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /// <reference path="../../../dist/preview release/babylon.d.ts" />
  2. declare module BABYLON {
  3. interface IGLTFLoaderData {
  4. json: Object;
  5. bin: ArrayBufferView;
  6. }
  7. interface IGLTFLoader {
  8. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onsuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onerror?: () => void) => boolean;
  9. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onsuccess: () => void, onerror: () => void) => boolean;
  10. }
  11. class GLTFFileLoader implements ISceneLoaderPluginAsync {
  12. static GLTFLoaderV1: IGLTFLoader;
  13. static GLTFLoaderV2: IGLTFLoader;
  14. static HomogeneousCoordinates: boolean;
  15. static IncrementalLoading: boolean;
  16. extensions: ISceneLoaderPluginExtensions;
  17. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void): boolean;
  18. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: () => void, onError: () => void): 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. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  30. declare module BABYLON.GLTF2 {
  31. /**
  32. * Enums
  33. */
  34. enum EBufferViewTarget {
  35. ARRAY_BUFFER = 34962,
  36. ELEMENT_ARRAY_BUFFER = 34963,
  37. }
  38. enum EComponentType {
  39. BYTE = 5120,
  40. UNSIGNED_BYTE = 5121,
  41. SHORT = 5122,
  42. UNSIGNED_SHORT = 5123,
  43. FLOAT = 5126,
  44. }
  45. enum EMeshPrimitiveMode {
  46. POINTS = 0,
  47. LINES = 1,
  48. LINE_LOOP = 2,
  49. LINE_STRIP = 3,
  50. TRIANGLES = 4,
  51. TRIANGLE_STRIP = 5,
  52. TRIANGLE_FAN = 6,
  53. }
  54. enum EParameterType {
  55. BYTE = 5120,
  56. UNSIGNED_BYTE = 5121,
  57. SHORT = 5122,
  58. UNSIGNED_SHORT = 5123,
  59. INT = 5124,
  60. UNSIGNED_INT = 5125,
  61. FLOAT = 5126,
  62. FLOAT_VEC2 = 35664,
  63. FLOAT_VEC3 = 35665,
  64. FLOAT_VEC4 = 35666,
  65. INT_VEC2 = 35667,
  66. INT_VEC3 = 35668,
  67. INT_VEC4 = 35669,
  68. BOOL = 35670,
  69. BOOL_VEC2 = 35671,
  70. BOOL_VEC3 = 35672,
  71. BOOL_VEC4 = 35673,
  72. FLOAT_MAT2 = 35674,
  73. FLOAT_MAT3 = 35675,
  74. FLOAT_MAT4 = 35676,
  75. SAMPLER_2D = 35678,
  76. }
  77. enum ETextureMagFilter {
  78. NEAREST = 9728,
  79. LINEAR = 9728,
  80. }
  81. enum ETextureMinFilter {
  82. NEAREST = 9728,
  83. LINEAR = 9728,
  84. NEAREST_MIPMAP_NEAREST = 9984,
  85. LINEAR_MIPMAP_NEAREST = 9985,
  86. NEAREST_MIPMAP_LINEAR = 9986,
  87. LINEAR_MIPMAP_LINEAR = 9987,
  88. }
  89. enum ETextureFormat {
  90. ALPHA = 6406,
  91. RGB = 6407,
  92. RGBA = 6408,
  93. LUMINANCE = 6409,
  94. LUMINANCE_ALPHA = 6410,
  95. }
  96. enum ETextureTarget {
  97. TEXTURE_2D = 3553,
  98. }
  99. enum ETextureType {
  100. UNSIGNED_BYTE = 5121,
  101. UNSIGNED_SHORT_5_6_5 = 33635,
  102. UNSIGNED_SHORT_4_4_4_4 = 32819,
  103. UNSIGNED_SHORT_5_5_5_1 = 32820,
  104. }
  105. enum ETextureWrapMode {
  106. CLAMP_TO_EDGE = 33071,
  107. MIRRORED_REPEAT = 33648,
  108. REPEAT = 10497,
  109. }
  110. /**
  111. * Interfaces
  112. */
  113. interface IGLTFProperty {
  114. extensions?: Object;
  115. extras?: any;
  116. }
  117. interface IGLTFChildRootProperty extends IGLTFProperty {
  118. name?: string;
  119. }
  120. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  121. bufferView: number;
  122. byteOffset?: number;
  123. componentType: EComponentType;
  124. }
  125. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  126. bufferView: number;
  127. byteOffset?: number;
  128. }
  129. interface IGLTFAccessorSparse extends IGLTFProperty {
  130. count: number;
  131. indices: IGLTFAccessorSparseIndices;
  132. values: IGLTFAccessorSparseValues;
  133. }
  134. interface IGLTFAccessor extends IGLTFChildRootProperty {
  135. bufferView?: number;
  136. byteOffset?: number;
  137. componentType: EComponentType;
  138. normalized?: boolean;
  139. count: number;
  140. type: string;
  141. max: number[];
  142. min: number[];
  143. sparse?: IGLTFAccessorSparse;
  144. }
  145. interface IGLTFAnimationChannel extends IGLTFProperty {
  146. sampler: number;
  147. target: IGLTFAnimationChannelTarget;
  148. }
  149. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  150. node: number;
  151. path: string;
  152. }
  153. interface IGLTFAnimationSampler extends IGLTFProperty {
  154. input: number;
  155. interpolation?: string;
  156. output: number;
  157. }
  158. interface IGLTFAnimation extends IGLTFChildRootProperty {
  159. channels: IGLTFAnimationChannel[];
  160. samplers: IGLTFAnimationSampler[];
  161. }
  162. interface IGLTFAssetProfile extends IGLTFProperty {
  163. api?: string;
  164. version?: string;
  165. }
  166. interface IGLTFAsset extends IGLTFChildRootProperty {
  167. copyright?: string;
  168. generator?: string;
  169. profile?: IGLTFAssetProfile;
  170. version: string;
  171. }
  172. interface IGLTFBuffer extends IGLTFChildRootProperty {
  173. uri?: string;
  174. byteLength: number;
  175. loadedBufferView: ArrayBufferView;
  176. }
  177. interface IGLTFBufferView extends IGLTFChildRootProperty {
  178. buffer: number;
  179. byteOffset: number;
  180. byteLength: number;
  181. byteStride?: number;
  182. target?: EBufferViewTarget;
  183. }
  184. interface IGLTFCameraOrthographic extends IGLTFProperty {
  185. xmag: number;
  186. ymag: number;
  187. zfar: number;
  188. znear: number;
  189. }
  190. interface IGLTFCameraPerspective extends IGLTFProperty {
  191. aspectRatio: number;
  192. yfov: number;
  193. zfar: number;
  194. znear: number;
  195. }
  196. interface IGLTFCamera extends IGLTFChildRootProperty {
  197. orthographic?: IGLTFCameraOrthographic;
  198. perspective?: IGLTFCameraPerspective;
  199. type: string;
  200. }
  201. interface IGLTFImage extends IGLTFChildRootProperty {
  202. uri?: string;
  203. mimeType?: string;
  204. bufferView?: number;
  205. }
  206. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  207. scale: number;
  208. }
  209. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  210. strength: number;
  211. }
  212. interface IGLTFMaterialPbrMetallicRoughness {
  213. baseColorFactor: number[];
  214. baseColorTexture: IGLTFTextureInfo;
  215. metallicFactor: number;
  216. roughnessFactor: number;
  217. metallicRoughnessTexture: IGLTFTextureInfo;
  218. }
  219. interface IGLTFMaterial extends IGLTFChildRootProperty {
  220. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  221. normalTexture?: IGLTFMaterialNormalTextureInfo;
  222. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  223. emissiveTexture?: IGLTFTextureInfo;
  224. emissiveFactor?: number[];
  225. alphaMode?: string;
  226. alphaCutoff: number;
  227. doubleSided?: boolean;
  228. babylonMaterial?: PBRMaterial;
  229. }
  230. interface IGLTFMeshPrimitive extends IGLTFProperty {
  231. attributes: {
  232. [name: string]: number;
  233. };
  234. indices?: number;
  235. material?: number;
  236. mode?: EMeshPrimitiveMode;
  237. targets?: number[];
  238. }
  239. interface IGLTFMesh extends IGLTFChildRootProperty {
  240. primitives: IGLTFMeshPrimitive[];
  241. weights?: number[];
  242. }
  243. interface IGLTFNode extends IGLTFChildRootProperty {
  244. camera?: number;
  245. children?: number[];
  246. skin?: number;
  247. matrix?: number[];
  248. mesh?: number;
  249. rotation?: number[];
  250. scale?: number[];
  251. translation?: number[];
  252. weights?: number[];
  253. babylonNode?: Node;
  254. }
  255. interface IGLTFSampler extends IGLTFChildRootProperty {
  256. magFilter?: ETextureMagFilter;
  257. minFilter?: ETextureMinFilter;
  258. wrapS?: ETextureWrapMode;
  259. wrapT?: ETextureWrapMode;
  260. }
  261. interface IGLTFScene extends IGLTFChildRootProperty {
  262. nodes: number[];
  263. }
  264. interface IGLTFSkin extends IGLTFChildRootProperty {
  265. inverseBindMatrices?: number;
  266. skeleton?: number;
  267. joints: number[];
  268. babylonSkeleton?: Skeleton;
  269. }
  270. interface IGLTFTexture extends IGLTFChildRootProperty {
  271. format?: ETextureFormat;
  272. internalFormat?: ETextureFormat;
  273. sampler: number;
  274. source: number;
  275. target?: ETextureTarget;
  276. type?: ETextureType;
  277. babylonTexture?: Texture;
  278. }
  279. interface IGLTFTextureInfo {
  280. index: number;
  281. texCoord?: number;
  282. }
  283. interface IGLTF extends IGLTFProperty {
  284. accessors?: IGLTFAccessor[];
  285. animations?: IGLTFAnimation[];
  286. asset: IGLTFAsset;
  287. buffers?: IGLTFBuffer[];
  288. bufferViews?: IGLTFBufferView[];
  289. cameras?: IGLTFCamera[];
  290. extensionsUsed?: string[];
  291. extensionsRequired?: string[];
  292. glExtensionsUsed?: string[];
  293. images?: IGLTFImage[];
  294. materials?: IGLTFMaterial[];
  295. meshes?: IGLTFMesh[];
  296. nodes?: IGLTFNode[];
  297. samplers?: IGLTFSampler[];
  298. scene?: number;
  299. scenes?: IGLTFScene[];
  300. skins?: IGLTFSkin[];
  301. textures?: IGLTFTexture[];
  302. }
  303. interface IGLTFRuntime {
  304. gltf: IGLTF;
  305. babylonScene: Scene;
  306. rootUrl: string;
  307. importOnlyMeshes: boolean;
  308. importMeshesNames?: string[];
  309. defaultMaterial?: PBRMaterial;
  310. }
  311. /**
  312. * Bones
  313. */
  314. interface INodeToRoot {
  315. bone: Bone;
  316. node: IGLTFNode;
  317. index: number;
  318. }
  319. interface IJointNode {
  320. node: IGLTFNode;
  321. index: number;
  322. }
  323. }
  324. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  325. declare module BABYLON.GLTF2 {
  326. /**
  327. * glTF File Loader Plugin
  328. */
  329. class GLTFLoader implements IGLTFLoader {
  330. static Extensions: {
  331. [name: string]: GLTFLoaderExtension;
  332. };
  333. static RegisterExtension(extension: GLTFLoaderExtension): void;
  334. static LoadMaterial(runtime: IGLTFRuntime, index: number): IGLTFMaterial;
  335. static LoadMetallicRoughnessMaterialProperties: (runtime: IGLTFRuntime, material: IGLTFMaterial) => void;
  336. static LoadCommonMaterialProperties(runtime: IGLTFRuntime, material: IGLTFMaterial): void;
  337. static LoadAlphaProperties(runtime: IGLTFRuntime, material: IGLTFMaterial): void;
  338. static LoadTextureAsync(runtime: IGLTFRuntime, textureInfo: IGLTFTextureInfo, onSuccess: (babylonTexture: Texture) => void, onError: () => void): void;
  339. static CreateTextureAsync(runtime: IGLTFRuntime, textureInfo: IGLTFTextureInfo, buffer: ArrayBufferView, mimeType: string, onSuccess: (babylonTexture: Texture) => void, onError: () => void): void;
  340. /**
  341. * Import meshes
  342. */
  343. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void): boolean;
  344. /**
  345. * Load scene
  346. */
  347. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): boolean;
  348. private _loadBuffersAsync(runtime, onSuccess, onError);
  349. private _loadBufferAsync(runtime, index, onSuccess, onError);
  350. private _createRuntime(scene, data, rootUrl, importOnlyMeshes);
  351. }
  352. }
  353. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  354. declare module BABYLON.GLTF2 {
  355. /**
  356. * Utils functions for GLTF
  357. */
  358. class GLTFUtils {
  359. /**
  360. * If the uri is a base64 string
  361. * @param uri: the uri to test
  362. */
  363. static IsBase64(uri: string): boolean;
  364. /**
  365. * Decode the base64 uri
  366. * @param uri: the uri to decode
  367. */
  368. static DecodeBase64(uri: string): ArrayBuffer;
  369. /**
  370. * Returns the wrap mode of the texture
  371. * @param mode: the mode value
  372. */
  373. static GetWrapMode(mode: number): number;
  374. /**
  375. * Returns the byte stride giving an accessor
  376. * @param accessor: the GLTF accessor objet
  377. */
  378. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  379. /**
  380. * Returns the texture filter mode giving a mode value
  381. * @param mode: the filter mode value
  382. */
  383. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  384. static GetBufferFromBufferView(runtime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  385. /**
  386. * Returns a buffer from its accessor
  387. * @param runtime: the GLTF runtime
  388. * @param accessor: the GLTF accessor
  389. */
  390. static GetBufferFromAccessor(runtime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  391. /**
  392. * Decodes a buffer view into a string
  393. * @param view: the buffer view
  394. */
  395. static DecodeBufferToText(view: ArrayBufferView): string;
  396. /**
  397. * Returns the default material of gltf.
  398. * @param scene: the Babylon.js scene
  399. */
  400. static GetDefaultMaterial(runtime: IGLTFRuntime): PBRMaterial;
  401. }
  402. }
  403. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  404. declare module BABYLON.GLTF2 {
  405. abstract class GLTFLoaderExtension {
  406. private _name;
  407. constructor(name: string);
  408. readonly name: string;
  409. protected postCreateRuntime(runtime: IGLTFRuntime): void;
  410. protected loadMaterial(runtime: IGLTFRuntime, index: number): boolean;
  411. static PostCreateRuntime(runtime: IGLTFRuntime): void;
  412. static LoadMaterial(runtime: IGLTFRuntime, index: number): void;
  413. }
  414. }
  415. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  416. declare module BABYLON.GLTF2 {
  417. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  418. constructor();
  419. protected loadMaterial(runtime: IGLTFRuntime, index: number): boolean;
  420. }
  421. }