babylon.glTFFileLoader.d.ts 32 KB

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