babylon.glTFFileLoader.d.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. targets?: any[];
  602. }
  603. interface IGLTFAssetProfile extends IGLTFProperty {
  604. api?: string;
  605. version?: string;
  606. }
  607. interface IGLTFAsset extends IGLTFChildRootProperty {
  608. copyright?: string;
  609. generator?: string;
  610. profile?: IGLTFAssetProfile;
  611. version: string;
  612. }
  613. interface IGLTFBuffer extends IGLTFChildRootProperty {
  614. uri?: string;
  615. byteLength: number;
  616. loadedData: ArrayBufferView;
  617. loadedObservable: Observable<IGLTFBuffer>;
  618. }
  619. interface IGLTFBufferView extends IGLTFChildRootProperty {
  620. buffer: number;
  621. byteOffset?: number;
  622. byteLength: number;
  623. byteStride?: number;
  624. }
  625. interface IGLTFCameraOrthographic extends IGLTFProperty {
  626. xmag: number;
  627. ymag: number;
  628. zfar: number;
  629. znear: number;
  630. }
  631. interface IGLTFCameraPerspective extends IGLTFProperty {
  632. aspectRatio: number;
  633. yfov: number;
  634. zfar: number;
  635. znear: number;
  636. }
  637. interface IGLTFCamera extends IGLTFChildRootProperty {
  638. orthographic?: IGLTFCameraOrthographic;
  639. perspective?: IGLTFCameraPerspective;
  640. type: string;
  641. }
  642. interface IGLTFImage extends IGLTFChildRootProperty {
  643. uri?: string;
  644. mimeType?: string;
  645. bufferView?: number;
  646. }
  647. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  648. scale: number;
  649. }
  650. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  651. strength: number;
  652. }
  653. interface IGLTFMaterialPbrMetallicRoughness {
  654. baseColorFactor: number[];
  655. baseColorTexture: IGLTFTextureInfo;
  656. metallicFactor: number;
  657. roughnessFactor: number;
  658. metallicRoughnessTexture: IGLTFTextureInfo;
  659. }
  660. interface IGLTFMaterial extends IGLTFChildRootProperty {
  661. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  662. normalTexture?: IGLTFMaterialNormalTextureInfo;
  663. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  664. emissiveTexture?: IGLTFTextureInfo;
  665. emissiveFactor?: number[];
  666. alphaMode?: string;
  667. alphaCutoff: number;
  668. doubleSided?: boolean;
  669. babylonMaterial?: PBRMaterial;
  670. }
  671. interface IGLTFMeshPrimitive extends IGLTFProperty {
  672. attributes: {
  673. [name: string]: number;
  674. };
  675. indices?: number;
  676. material?: number;
  677. mode?: EMeshPrimitiveMode;
  678. targets?: [{
  679. [name: string]: number;
  680. }];
  681. }
  682. interface IGLTFMesh extends IGLTFChildRootProperty {
  683. primitives: IGLTFMeshPrimitive[];
  684. weights?: number[];
  685. }
  686. interface IGLTFNode extends IGLTFChildRootProperty {
  687. camera?: number;
  688. children?: number[];
  689. skin?: number;
  690. matrix?: number[];
  691. mesh?: number;
  692. rotation?: number[];
  693. scale?: number[];
  694. translation?: number[];
  695. weights?: number[];
  696. index?: number;
  697. babylonNode?: Node;
  698. }
  699. interface IGLTFSampler extends IGLTFChildRootProperty {
  700. magFilter?: ETextureMagFilter;
  701. minFilter?: ETextureMinFilter;
  702. wrapS?: ETextureWrapMode;
  703. wrapT?: ETextureWrapMode;
  704. }
  705. interface IGLTFScene extends IGLTFChildRootProperty {
  706. nodes: number[];
  707. }
  708. interface IGLTFSkin extends IGLTFChildRootProperty {
  709. inverseBindMatrices?: number;
  710. skeleton?: number;
  711. joints: number[];
  712. babylonSkeleton?: Skeleton;
  713. }
  714. interface IGLTFTexture extends IGLTFChildRootProperty {
  715. sampler?: number;
  716. source: number;
  717. babylonTextures?: Texture[];
  718. blobURL?: string;
  719. }
  720. interface IGLTFTextureInfo {
  721. index: number;
  722. texCoord?: number;
  723. }
  724. interface IGLTF extends IGLTFProperty {
  725. accessors?: IGLTFAccessor[];
  726. animations?: IGLTFAnimation[];
  727. asset: IGLTFAsset;
  728. buffers?: IGLTFBuffer[];
  729. bufferViews?: IGLTFBufferView[];
  730. cameras?: IGLTFCamera[];
  731. extensionsUsed?: string[];
  732. extensionsRequired?: string[];
  733. glExtensionsUsed?: string[];
  734. images?: IGLTFImage[];
  735. materials?: IGLTFMaterial[];
  736. meshes?: IGLTFMesh[];
  737. nodes?: IGLTFNode[];
  738. samplers?: IGLTFSampler[];
  739. scene?: number;
  740. scenes?: IGLTFScene[];
  741. skins?: IGLTFSkin[];
  742. textures?: IGLTFTexture[];
  743. }
  744. }
  745. declare module BABYLON.GLTF2 {
  746. class GLTFLoader implements IGLTFLoader {
  747. private _gltf;
  748. private _pendingCount;
  749. private _onLoaded;
  750. private _errors;
  751. private _babylonScene;
  752. private _rootUrl;
  753. private _defaultMaterial;
  754. static Extensions: {
  755. [name: string]: GLTFLoaderExtension;
  756. };
  757. static RegisterExtension(extension: GLTFLoaderExtension): void;
  758. static LoadMaterial(index: number): IGLTFMaterial;
  759. static LoadCoreMaterial(index: number): Material;
  760. static LoadCommonMaterialProperties(material: IGLTFMaterial): void;
  761. static LoadAlphaProperties(material: IGLTFMaterial): void;
  762. static LoadTexture(textureInfo: IGLTFTextureInfo): Texture;
  763. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void;
  764. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  765. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onError);
  766. private _loadData(data);
  767. private _showMeshes();
  768. private _startFirstAnimation();
  769. private _clear();
  770. private _loadScene(nodeNames);
  771. private _loadSkin(node);
  772. private _updateBone(node, parentNode, skin, inverseBindMatrixData);
  773. private _loadMesh(node, parentNode);
  774. private _loadMeshData(node, mesh, babylonMesh);
  775. private _loadVertexDataAsync(primitive, onSuccess);
  776. private _createMorphTargets(node, mesh, primitive, babylonMesh);
  777. private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
  778. private _loadTransform(node, babylonMesh);
  779. private _traverseScene(nodeNames, scene, action);
  780. private _traverseNode(nodeNames, index, action, parentNode?);
  781. private _loadAnimations();
  782. private _loadAnimationChannel(animation, animationIndex, channelIndex);
  783. private _loadBufferAsync(index, onSuccess);
  784. private _loadBufferViewAsync(bufferView, byteOffset, byteLength, componentType, onSuccess);
  785. private _loadAccessorAsync(accessor, onSuccess);
  786. private _addPendingData(data);
  787. private _removePendingData(data);
  788. private _getDefaultMaterial();
  789. private _loadMaterial(index);
  790. private _loadCoreMaterial(index);
  791. private _loadCommonMaterialProperties(material);
  792. private _loadAlphaProperties(material);
  793. private _loadTexture(textureInfo);
  794. }
  795. }
  796. declare module BABYLON.GLTF2 {
  797. /**
  798. * Utils functions for GLTF
  799. */
  800. class GLTFUtils {
  801. /**
  802. * If the uri is a base64 string
  803. * @param uri: the uri to test
  804. */
  805. static IsBase64(uri: string): boolean;
  806. /**
  807. * Decode the base64 uri
  808. * @param uri: the uri to decode
  809. */
  810. static DecodeBase64(uri: string): ArrayBuffer;
  811. /**
  812. * Returns the wrap mode of the texture
  813. * @param mode: the mode value
  814. */
  815. static GetWrapMode(mode: number): number;
  816. /**
  817. * Returns the byte stride giving an accessor
  818. * @param accessor: the GLTF accessor objet
  819. */
  820. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  821. /**
  822. * Returns the texture filter mode giving a mode value
  823. * @param mode: the filter mode value
  824. */
  825. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  826. /**
  827. * Decodes a buffer view into a string
  828. * @param view: the buffer view
  829. */
  830. static DecodeBufferToText(view: ArrayBufferView): string;
  831. }
  832. }
  833. declare module BABYLON.GLTF2 {
  834. abstract class GLTFLoaderExtension {
  835. private _name;
  836. enabled: boolean;
  837. constructor(name: string);
  838. readonly name: string;
  839. protected loadMaterial(index: number): Material;
  840. static LoadMaterial(index: number): Material;
  841. }
  842. }
  843. declare module BABYLON.GLTF2 {
  844. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  845. constructor();
  846. protected loadMaterial(index: number): Material;
  847. }
  848. }