babylon.glTF2FileLoader.d.ts 14 KB

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