babylon.glTF2FileLoader.d.ts 13 KB

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