babylon.glTFFileLoader.d.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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.GLTF1 {
  30. /**
  31. * Enums
  32. */
  33. enum EComponentType {
  34. BYTE = 5120,
  35. UNSIGNED_BYTE = 5121,
  36. SHORT = 5122,
  37. UNSIGNED_SHORT = 5123,
  38. FLOAT = 5126,
  39. }
  40. enum EShaderType {
  41. FRAGMENT = 35632,
  42. VERTEX = 35633,
  43. }
  44. enum EParameterType {
  45. BYTE = 5120,
  46. UNSIGNED_BYTE = 5121,
  47. SHORT = 5122,
  48. UNSIGNED_SHORT = 5123,
  49. INT = 5124,
  50. UNSIGNED_INT = 5125,
  51. FLOAT = 5126,
  52. FLOAT_VEC2 = 35664,
  53. FLOAT_VEC3 = 35665,
  54. FLOAT_VEC4 = 35666,
  55. INT_VEC2 = 35667,
  56. INT_VEC3 = 35668,
  57. INT_VEC4 = 35669,
  58. BOOL = 35670,
  59. BOOL_VEC2 = 35671,
  60. BOOL_VEC3 = 35672,
  61. BOOL_VEC4 = 35673,
  62. FLOAT_MAT2 = 35674,
  63. FLOAT_MAT3 = 35675,
  64. FLOAT_MAT4 = 35676,
  65. SAMPLER_2D = 35678,
  66. }
  67. enum ETextureWrapMode {
  68. CLAMP_TO_EDGE = 33071,
  69. MIRRORED_REPEAT = 33648,
  70. REPEAT = 10497,
  71. }
  72. enum ETextureFilterType {
  73. NEAREST = 9728,
  74. LINEAR = 9728,
  75. NEAREST_MIPMAP_NEAREST = 9984,
  76. LINEAR_MIPMAP_NEAREST = 9985,
  77. NEAREST_MIPMAP_LINEAR = 9986,
  78. LINEAR_MIPMAP_LINEAR = 9987,
  79. }
  80. enum ETextureFormat {
  81. ALPHA = 6406,
  82. RGB = 6407,
  83. RGBA = 6408,
  84. LUMINANCE = 6409,
  85. LUMINANCE_ALPHA = 6410,
  86. }
  87. enum ECullingType {
  88. FRONT = 1028,
  89. BACK = 1029,
  90. FRONT_AND_BACK = 1032,
  91. }
  92. enum EBlendingFunction {
  93. ZERO = 0,
  94. ONE = 1,
  95. SRC_COLOR = 768,
  96. ONE_MINUS_SRC_COLOR = 769,
  97. DST_COLOR = 774,
  98. ONE_MINUS_DST_COLOR = 775,
  99. SRC_ALPHA = 770,
  100. ONE_MINUS_SRC_ALPHA = 771,
  101. DST_ALPHA = 772,
  102. ONE_MINUS_DST_ALPHA = 773,
  103. CONSTANT_COLOR = 32769,
  104. ONE_MINUS_CONSTANT_COLOR = 32770,
  105. CONSTANT_ALPHA = 32771,
  106. ONE_MINUS_CONSTANT_ALPHA = 32772,
  107. SRC_ALPHA_SATURATE = 776,
  108. }
  109. /**
  110. * Interfaces
  111. */
  112. interface IGLTFProperty {
  113. extensions?: Object;
  114. extras?: Object;
  115. }
  116. interface IGLTFChildRootProperty extends IGLTFProperty {
  117. name?: string;
  118. }
  119. interface IGLTFAccessor extends IGLTFChildRootProperty {
  120. bufferView: string;
  121. byteOffset: number;
  122. byteStride: number;
  123. count: number;
  124. type: string;
  125. componentType: EComponentType;
  126. max?: number[];
  127. min?: number[];
  128. name?: string;
  129. }
  130. interface IGLTFBufferView extends IGLTFChildRootProperty {
  131. buffer: string;
  132. byteOffset: number;
  133. byteLength: number;
  134. target?: number;
  135. }
  136. interface IGLTFBuffer extends IGLTFChildRootProperty {
  137. uri: string;
  138. byteLength?: number;
  139. type?: string;
  140. }
  141. interface IGLTFShader extends IGLTFChildRootProperty {
  142. uri: string;
  143. type: EShaderType;
  144. }
  145. interface IGLTFProgram extends IGLTFChildRootProperty {
  146. attributes: string[];
  147. fragmentShader: string;
  148. vertexShader: string;
  149. }
  150. interface IGLTFTechniqueParameter {
  151. type: number;
  152. count?: number;
  153. semantic?: string;
  154. node?: string;
  155. value?: number | boolean | string | Array<any>;
  156. source?: string;
  157. babylonValue?: any;
  158. }
  159. interface IGLTFTechniqueCommonProfile {
  160. lightingModel: string;
  161. texcoordBindings: Object;
  162. parameters?: Array<any>;
  163. }
  164. interface IGLTFTechniqueStatesFunctions {
  165. blendColor?: number[];
  166. blendEquationSeparate?: number[];
  167. blendFuncSeparate?: number[];
  168. colorMask: boolean[];
  169. cullFace: number[];
  170. }
  171. interface IGLTFTechniqueStates {
  172. enable: number[];
  173. functions: IGLTFTechniqueStatesFunctions;
  174. }
  175. interface IGLTFTechnique extends IGLTFChildRootProperty {
  176. parameters: Object;
  177. program: string;
  178. attributes: Object;
  179. uniforms: Object;
  180. states: IGLTFTechniqueStates;
  181. }
  182. interface IGLTFMaterial extends IGLTFChildRootProperty {
  183. technique?: string;
  184. values: string[];
  185. }
  186. interface IGLTFMeshPrimitive extends IGLTFProperty {
  187. attributes: Object;
  188. indices: string;
  189. material: string;
  190. mode?: number;
  191. }
  192. interface IGLTFMesh extends IGLTFChildRootProperty {
  193. primitives: IGLTFMeshPrimitive[];
  194. }
  195. interface IGLTFImage extends IGLTFChildRootProperty {
  196. uri: string;
  197. }
  198. interface IGLTFSampler extends IGLTFChildRootProperty {
  199. magFilter?: number;
  200. minFilter?: number;
  201. wrapS?: number;
  202. wrapT?: number;
  203. }
  204. interface IGLTFTexture extends IGLTFChildRootProperty {
  205. sampler: string;
  206. source: string;
  207. format?: ETextureFormat;
  208. internalFormat?: ETextureFormat;
  209. target?: number;
  210. type?: number;
  211. babylonTexture?: Texture;
  212. }
  213. interface IGLTFAmbienLight {
  214. color?: number[];
  215. }
  216. interface IGLTFDirectionalLight {
  217. color?: number[];
  218. }
  219. interface IGLTFPointLight {
  220. color?: number[];
  221. constantAttenuation?: number;
  222. linearAttenuation?: number;
  223. quadraticAttenuation?: number;
  224. }
  225. interface IGLTFSpotLight {
  226. color?: number[];
  227. constantAttenuation?: number;
  228. fallOfAngle?: number;
  229. fallOffExponent?: number;
  230. linearAttenuation?: number;
  231. quadraticAttenuation?: number;
  232. }
  233. interface IGLTFLight extends IGLTFChildRootProperty {
  234. type: string;
  235. }
  236. interface IGLTFCameraOrthographic {
  237. xmag: number;
  238. ymag: number;
  239. zfar: number;
  240. znear: number;
  241. }
  242. interface IGLTFCameraPerspective {
  243. aspectRatio: number;
  244. yfov: number;
  245. zfar: number;
  246. znear: number;
  247. }
  248. interface IGLTFCamera extends IGLTFChildRootProperty {
  249. type: string;
  250. }
  251. interface IGLTFAnimationChannelTarget {
  252. id: string;
  253. path: string;
  254. }
  255. interface IGLTFAnimationChannel {
  256. sampler: string;
  257. target: IGLTFAnimationChannelTarget;
  258. }
  259. interface IGLTFAnimationSampler {
  260. input: string;
  261. output: string;
  262. interpolation?: string;
  263. }
  264. interface IGLTFAnimation extends IGLTFChildRootProperty {
  265. channels?: IGLTFAnimationChannel[];
  266. parameters?: Object;
  267. samplers?: Object;
  268. }
  269. interface IGLTFNodeInstanceSkin {
  270. skeletons: string[];
  271. skin: string;
  272. meshes: string[];
  273. }
  274. interface IGLTFSkins extends IGLTFChildRootProperty {
  275. bindShapeMatrix: number[];
  276. inverseBindMatrices: string;
  277. jointNames: string[];
  278. babylonSkeleton?: Skeleton;
  279. }
  280. interface IGLTFNode extends IGLTFChildRootProperty {
  281. camera?: string;
  282. children: string[];
  283. skin?: string;
  284. jointName?: string;
  285. light?: string;
  286. matrix: number[];
  287. mesh?: string;
  288. meshes?: string[];
  289. rotation?: number[];
  290. scale?: number[];
  291. translation?: number[];
  292. babylonNode?: Node;
  293. }
  294. interface IGLTFScene extends IGLTFChildRootProperty {
  295. nodes: string[];
  296. }
  297. /**
  298. * Runtime
  299. */
  300. interface IGLTFRuntime {
  301. extensions: Object;
  302. accessors: Object;
  303. buffers: Object;
  304. bufferViews: Object;
  305. meshes: Object;
  306. lights: Object;
  307. cameras: Object;
  308. nodes: Object;
  309. images: Object;
  310. textures: Object;
  311. shaders: Object;
  312. programs: Object;
  313. samplers: Object;
  314. techniques: Object;
  315. materials: Object;
  316. animations: Object;
  317. skins: Object;
  318. currentScene?: Object;
  319. scenes: Object;
  320. extensionsUsed: string[];
  321. extensionsRequired?: string[];
  322. buffersCount: number;
  323. shaderscount: number;
  324. scene: Scene;
  325. rootUrl: string;
  326. loadedBufferCount: number;
  327. loadedBufferViews: {
  328. [name: string]: ArrayBufferView;
  329. };
  330. loadedShaderCount: number;
  331. importOnlyMeshes: boolean;
  332. importMeshesNames?: string[];
  333. dummyNodes: Node[];
  334. }
  335. /**
  336. * Bones
  337. */
  338. interface INodeToRoot {
  339. bone: Bone;
  340. node: IGLTFNode;
  341. id: string;
  342. }
  343. interface IJointNode {
  344. node: IGLTFNode;
  345. id: string;
  346. }
  347. }
  348. declare module BABYLON.GLTF1 {
  349. /**
  350. * Implementation of the base glTF spec
  351. */
  352. class GLTFLoaderBase {
  353. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  354. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void, onProgress?: () => void): void;
  355. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): void;
  356. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: () => void): void;
  357. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): void;
  358. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void;
  359. }
  360. /**
  361. * glTF V1 Loader
  362. */
  363. class GLTFLoader implements IGLTFLoader {
  364. static Extensions: {
  365. [name: string]: GLTFLoaderExtension;
  366. };
  367. static RegisterExtension(extension: GLTFLoaderExtension): void;
  368. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void, onProgress?: () => void): boolean;
  369. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  370. private _loadShadersAsync(gltfRuntime, onload);
  371. private _loadBuffersAsync(gltfRuntime, onload, onProgress?);
  372. private _createNodes(gltfRuntime);
  373. }
  374. }
  375. declare module BABYLON.GLTF1 {
  376. /**
  377. * Utils functions for GLTF
  378. */
  379. class GLTFUtils {
  380. /**
  381. * Sets the given "parameter" matrix
  382. * @param scene: the {BABYLON.Scene} object
  383. * @param source: the source node where to pick the matrix
  384. * @param parameter: the GLTF technique parameter
  385. * @param uniformName: the name of the shader's uniform
  386. * @param shaderMaterial: the shader material
  387. */
  388. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  389. /**
  390. * Sets the given "parameter" matrix
  391. * @param shaderMaterial: the shader material
  392. * @param uniform: the name of the shader's uniform
  393. * @param value: the value of the uniform
  394. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  395. */
  396. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  397. /**
  398. * If the uri is a base64 string
  399. * @param uri: the uri to test
  400. */
  401. static IsBase64(uri: string): boolean;
  402. /**
  403. * Decode the base64 uri
  404. * @param uri: the uri to decode
  405. */
  406. static DecodeBase64(uri: string): ArrayBuffer;
  407. /**
  408. * Returns the wrap mode of the texture
  409. * @param mode: the mode value
  410. */
  411. static GetWrapMode(mode: number): number;
  412. /**
  413. * Returns the byte stride giving an accessor
  414. * @param accessor: the GLTF accessor objet
  415. */
  416. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  417. /**
  418. * Returns the texture filter mode giving a mode value
  419. * @param mode: the filter mode value
  420. */
  421. static GetTextureFilterMode(mode: number): ETextureFilterType;
  422. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  423. /**
  424. * Returns a buffer from its accessor
  425. * @param gltfRuntime: the GLTF runtime
  426. * @param accessor: the GLTF accessor
  427. */
  428. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  429. /**
  430. * Decodes a buffer view into a string
  431. * @param view: the buffer view
  432. */
  433. static DecodeBufferToText(view: ArrayBufferView): string;
  434. /**
  435. * Returns the default material of gltf. Related to
  436. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  437. * @param scene: the Babylon.js scene
  438. */
  439. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  440. private static _DefaultMaterial;
  441. }
  442. }
  443. declare module BABYLON.GLTF1 {
  444. abstract class GLTFLoaderExtension {
  445. private _name;
  446. constructor(name: string);
  447. readonly name: string;
  448. /**
  449. * Defines an override for loading the runtime
  450. * Return true to stop further extensions from loading the runtime
  451. */
  452. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): boolean;
  453. /**
  454. * Defines an onverride for creating gltf runtime
  455. * Return true to stop further extensions from creating the runtime
  456. */
  457. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): boolean;
  458. /**
  459. * Defines an override for loading buffers
  460. * Return true to stop further extensions from loading this buffer
  461. */
  462. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void, onProgress?: () => void): boolean;
  463. /**
  464. * Defines an override for loading texture buffers
  465. * Return true to stop further extensions from loading this texture data
  466. */
  467. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  468. /**
  469. * Defines an override for creating textures
  470. * Return true to stop further extensions from loading this texture
  471. */
  472. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: () => void): boolean;
  473. /**
  474. * Defines an override for loading shader strings
  475. * Return true to stop further extensions from loading this shader data
  476. */
  477. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): boolean;
  478. /**
  479. * Defines an override for loading materials
  480. * Return true to stop further extensions from loading this material
  481. */
  482. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): boolean;
  483. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): void;
  484. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): void;
  485. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: () => void, onProgress?: () => void): void;
  486. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: () => void): void;
  487. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: () => void): void;
  488. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void;
  489. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  490. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  491. private static ApplyExtensions(func, defaultFunc);
  492. }
  493. }
  494. declare module BABYLON.GLTF1 {
  495. class GLTFBinaryExtension extends GLTFLoaderExtension {
  496. private _bin;
  497. constructor();
  498. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): boolean;
  499. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  500. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  501. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): boolean;
  502. }
  503. }
  504. declare module BABYLON.GLTF1 {
  505. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  506. constructor();
  507. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): boolean;
  508. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): boolean;
  509. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  510. }
  511. }
  512. declare module BABYLON.GLTF2 {
  513. /**
  514. * Enums
  515. */
  516. enum EComponentType {
  517. BYTE = 5120,
  518. UNSIGNED_BYTE = 5121,
  519. SHORT = 5122,
  520. UNSIGNED_SHORT = 5123,
  521. UNSIGNED_INT = 5125,
  522. FLOAT = 5126,
  523. }
  524. enum EMeshPrimitiveMode {
  525. POINTS = 0,
  526. LINES = 1,
  527. LINE_LOOP = 2,
  528. LINE_STRIP = 3,
  529. TRIANGLES = 4,
  530. TRIANGLE_STRIP = 5,
  531. TRIANGLE_FAN = 6,
  532. }
  533. enum ETextureMagFilter {
  534. NEAREST = 9728,
  535. LINEAR = 9729,
  536. }
  537. enum ETextureMinFilter {
  538. NEAREST = 9728,
  539. LINEAR = 9729,
  540. NEAREST_MIPMAP_NEAREST = 9984,
  541. LINEAR_MIPMAP_NEAREST = 9985,
  542. NEAREST_MIPMAP_LINEAR = 9986,
  543. LINEAR_MIPMAP_LINEAR = 9987,
  544. }
  545. enum ETextureWrapMode {
  546. CLAMP_TO_EDGE = 33071,
  547. MIRRORED_REPEAT = 33648,
  548. REPEAT = 10497,
  549. }
  550. /**
  551. * Interfaces
  552. */
  553. interface IGLTFProperty {
  554. extensions?: Object;
  555. extras?: any;
  556. }
  557. interface IGLTFChildRootProperty extends IGLTFProperty {
  558. name?: string;
  559. }
  560. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  561. bufferView: number;
  562. byteOffset?: number;
  563. componentType: EComponentType;
  564. }
  565. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  566. bufferView: number;
  567. byteOffset?: number;
  568. }
  569. interface IGLTFAccessorSparse extends IGLTFProperty {
  570. count: number;
  571. indices: IGLTFAccessorSparseIndices;
  572. values: IGLTFAccessorSparseValues;
  573. }
  574. interface IGLTFAccessor extends IGLTFChildRootProperty {
  575. bufferView?: number;
  576. byteOffset?: number;
  577. componentType: EComponentType;
  578. normalized?: boolean;
  579. count: number;
  580. type: string;
  581. max: number[];
  582. min: number[];
  583. sparse?: IGLTFAccessorSparse;
  584. }
  585. interface IGLTFAnimationChannel extends IGLTFProperty {
  586. sampler: number;
  587. target: IGLTFAnimationChannelTarget;
  588. }
  589. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  590. node: number;
  591. path: string;
  592. }
  593. interface IGLTFAnimationSampler extends IGLTFProperty {
  594. input: number;
  595. interpolation?: string;
  596. output: number;
  597. }
  598. interface IGLTFAnimation extends IGLTFChildRootProperty {
  599. channels: IGLTFAnimationChannel[];
  600. samplers: IGLTFAnimationSampler[];
  601. }
  602. interface IGLTFAssetProfile extends IGLTFProperty {
  603. api?: string;
  604. version?: string;
  605. }
  606. interface IGLTFAsset extends IGLTFChildRootProperty {
  607. copyright?: string;
  608. generator?: string;
  609. profile?: IGLTFAssetProfile;
  610. version: string;
  611. }
  612. interface IGLTFBuffer extends IGLTFChildRootProperty {
  613. uri?: string;
  614. byteLength: number;
  615. loadedBufferView: ArrayBufferView;
  616. }
  617. interface IGLTFBufferView extends IGLTFChildRootProperty {
  618. buffer: number;
  619. byteOffset?: number;
  620. byteLength: number;
  621. byteStride?: number;
  622. }
  623. interface IGLTFCameraOrthographic extends IGLTFProperty {
  624. xmag: number;
  625. ymag: number;
  626. zfar: number;
  627. znear: number;
  628. }
  629. interface IGLTFCameraPerspective extends IGLTFProperty {
  630. aspectRatio: number;
  631. yfov: number;
  632. zfar: number;
  633. znear: number;
  634. }
  635. interface IGLTFCamera extends IGLTFChildRootProperty {
  636. orthographic?: IGLTFCameraOrthographic;
  637. perspective?: IGLTFCameraPerspective;
  638. type: string;
  639. }
  640. interface IGLTFImage extends IGLTFChildRootProperty {
  641. uri?: string;
  642. mimeType?: string;
  643. bufferView?: number;
  644. }
  645. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  646. scale: number;
  647. }
  648. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  649. strength: number;
  650. }
  651. interface IGLTFMaterialPbrMetallicRoughness {
  652. baseColorFactor: number[];
  653. baseColorTexture: IGLTFTextureInfo;
  654. metallicFactor: number;
  655. roughnessFactor: number;
  656. metallicRoughnessTexture: IGLTFTextureInfo;
  657. }
  658. interface IGLTFMaterial extends IGLTFChildRootProperty {
  659. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  660. normalTexture?: IGLTFMaterialNormalTextureInfo;
  661. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  662. emissiveTexture?: IGLTFTextureInfo;
  663. emissiveFactor?: number[];
  664. alphaMode?: string;
  665. alphaCutoff: number;
  666. doubleSided?: boolean;
  667. babylonMaterial?: PBRMaterial;
  668. }
  669. interface IGLTFMeshPrimitive extends IGLTFProperty {
  670. attributes: {
  671. [name: string]: number;
  672. };
  673. indices?: number;
  674. material?: number;
  675. mode?: EMeshPrimitiveMode;
  676. targets?: [{
  677. [name: string]: number;
  678. }];
  679. }
  680. interface IGLTFMesh extends IGLTFChildRootProperty {
  681. primitives: IGLTFMeshPrimitive[];
  682. weights?: number[];
  683. }
  684. interface IGLTFNode extends IGLTFChildRootProperty {
  685. camera?: number;
  686. children?: number[];
  687. skin?: number;
  688. matrix?: number[];
  689. mesh?: number;
  690. rotation?: number[];
  691. scale?: number[];
  692. translation?: number[];
  693. weights?: number[];
  694. babylonNode?: Node;
  695. }
  696. interface IGLTFSampler extends IGLTFChildRootProperty {
  697. magFilter?: ETextureMagFilter;
  698. minFilter?: ETextureMinFilter;
  699. wrapS?: ETextureWrapMode;
  700. wrapT?: ETextureWrapMode;
  701. }
  702. interface IGLTFScene extends IGLTFChildRootProperty {
  703. nodes: number[];
  704. }
  705. interface IGLTFSkin extends IGLTFChildRootProperty {
  706. inverseBindMatrices?: number;
  707. skeleton?: number;
  708. joints: number[];
  709. babylonSkeleton?: Skeleton;
  710. }
  711. interface IGLTFTexture extends IGLTFChildRootProperty {
  712. sampler?: number;
  713. source: number;
  714. babylonTextures: Texture[];
  715. blobURL: string;
  716. }
  717. interface IGLTFTextureInfo {
  718. index: number;
  719. texCoord?: number;
  720. }
  721. interface IGLTF extends IGLTFProperty {
  722. accessors?: IGLTFAccessor[];
  723. animations?: IGLTFAnimation[];
  724. asset: IGLTFAsset;
  725. buffers?: IGLTFBuffer[];
  726. bufferViews?: IGLTFBufferView[];
  727. cameras?: IGLTFCamera[];
  728. extensionsUsed?: string[];
  729. extensionsRequired?: string[];
  730. glExtensionsUsed?: string[];
  731. images?: IGLTFImage[];
  732. materials?: IGLTFMaterial[];
  733. meshes?: IGLTFMesh[];
  734. nodes?: IGLTFNode[];
  735. samplers?: IGLTFSampler[];
  736. scene?: number;
  737. scenes?: IGLTFScene[];
  738. skins?: IGLTFSkin[];
  739. textures?: IGLTFTexture[];
  740. }
  741. interface IGLTFRuntime {
  742. gltf: IGLTF;
  743. babylonScene: Scene;
  744. rootUrl: string;
  745. importOnlyMeshes: boolean;
  746. importMeshesNames?: string[];
  747. defaultMaterial?: PBRMaterial;
  748. }
  749. /**
  750. * Bones
  751. */
  752. interface INodeToRoot {
  753. bone: Bone;
  754. node: IGLTFNode;
  755. index: number;
  756. }
  757. interface IJointNode {
  758. node: IGLTFNode;
  759. index: number;
  760. }
  761. }
  762. declare module BABYLON.GLTF2 {
  763. /**
  764. * glTF File Loader Plugin
  765. */
  766. class GLTFLoader implements IGLTFLoader {
  767. static Extensions: {
  768. [name: string]: GLTFLoaderExtension;
  769. };
  770. static RegisterExtension(extension: GLTFLoaderExtension): void;
  771. static LoadMaterial(runtime: IGLTFRuntime, index: number): IGLTFMaterial;
  772. static LoadCoreMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void;
  773. private static _loadMetallicRoughnessMaterialPropertiesAsync(runtime, material, onSuccess, onError);
  774. static LoadCommonMaterialPropertiesAsync(runtime: IGLTFRuntime, material: IGLTFMaterial, onSuccess: () => void, onError: () => void): void;
  775. static LoadAlphaProperties(runtime: IGLTFRuntime, material: IGLTFMaterial): void;
  776. static LoadTextureAsync(runtime: IGLTFRuntime, textureInfo: IGLTFTextureInfo, onSuccess: (babylonTexture: Texture) => void, onError: () => void): void;
  777. private static _createTextureAsync(runtime, texture, texCoord, url, onSuccess, onError);
  778. /**
  779. * Import meshes
  780. */
  781. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void): void;
  782. /**
  783. * Load scene
  784. */
  785. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  786. private static _loadBuffersAsync(runtime, onSuccess, onError);
  787. private static _loadBufferAsync(runtime, index, onSuccess, onError);
  788. private static _loadMaterialsAsync(runtime, onSuccess, onError);
  789. private static _createRuntime(scene, data, rootUrl, importOnlyMeshes);
  790. }
  791. }
  792. declare module BABYLON.GLTF2 {
  793. /**
  794. * Utils functions for GLTF
  795. */
  796. class GLTFUtils {
  797. /**
  798. * If the uri is a base64 string
  799. * @param uri: the uri to test
  800. */
  801. static IsBase64(uri: string): boolean;
  802. /**
  803. * Decode the base64 uri
  804. * @param uri: the uri to decode
  805. */
  806. static DecodeBase64(uri: string): ArrayBuffer;
  807. /**
  808. * Returns the wrap mode of the texture
  809. * @param mode: the mode value
  810. */
  811. static GetWrapMode(mode: number): number;
  812. /**
  813. * Returns the byte stride giving an accessor
  814. * @param accessor: the GLTF accessor objet
  815. */
  816. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  817. /**
  818. * Returns the texture filter mode giving a mode value
  819. * @param mode: the filter mode value
  820. */
  821. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  822. static GetBufferFromBufferView(runtime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  823. /**
  824. * Returns a buffer from its accessor
  825. * @param runtime: the GLTF runtime
  826. * @param accessor: the GLTF accessor
  827. */
  828. static GetBufferFromAccessor(runtime: IGLTFRuntime, accessor: IGLTFAccessor): ArrayBufferView;
  829. /**
  830. * Decodes a buffer view into a string
  831. * @param view: the buffer view
  832. */
  833. static DecodeBufferToText(view: ArrayBufferView): string;
  834. /**
  835. * Returns the default material of gltf.
  836. * @param scene: the Babylon.js scene
  837. */
  838. static GetDefaultMaterial(runtime: IGLTFRuntime): PBRMaterial;
  839. }
  840. }
  841. declare module BABYLON.GLTF2 {
  842. abstract class GLTFLoaderExtension {
  843. private _name;
  844. enabled: boolean;
  845. constructor(name: string);
  846. readonly name: string;
  847. protected postCreateRuntime(runtime: IGLTFRuntime): void;
  848. protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean;
  849. static PostCreateRuntime(runtime: IGLTFRuntime): void;
  850. static LoadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void;
  851. }
  852. }
  853. declare module BABYLON.GLTF2 {
  854. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  855. constructor();
  856. protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean;
  857. }
  858. }