babylon.glTFFileLoader.d.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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 EComponentType {
  524. BYTE = 5120,
  525. UNSIGNED_BYTE = 5121,
  526. SHORT = 5122,
  527. UNSIGNED_SHORT = 5123,
  528. UNSIGNED_INT = 5125,
  529. FLOAT = 5126,
  530. }
  531. enum EMeshPrimitiveMode {
  532. POINTS = 0,
  533. LINES = 1,
  534. LINE_LOOP = 2,
  535. LINE_STRIP = 3,
  536. TRIANGLES = 4,
  537. TRIANGLE_STRIP = 5,
  538. TRIANGLE_FAN = 6,
  539. }
  540. enum ETextureMagFilter {
  541. NEAREST = 9728,
  542. LINEAR = 9729,
  543. }
  544. enum ETextureMinFilter {
  545. NEAREST = 9728,
  546. LINEAR = 9729,
  547. NEAREST_MIPMAP_NEAREST = 9984,
  548. LINEAR_MIPMAP_NEAREST = 9985,
  549. NEAREST_MIPMAP_LINEAR = 9986,
  550. LINEAR_MIPMAP_LINEAR = 9987,
  551. }
  552. enum ETextureWrapMode {
  553. CLAMP_TO_EDGE = 33071,
  554. MIRRORED_REPEAT = 33648,
  555. REPEAT = 10497,
  556. }
  557. /**
  558. * Interfaces
  559. */
  560. interface IGLTFProperty {
  561. extensions?: Object;
  562. extras?: any;
  563. }
  564. interface IGLTFChildRootProperty extends IGLTFProperty {
  565. name?: string;
  566. }
  567. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  568. bufferView: number;
  569. byteOffset?: number;
  570. componentType: EComponentType;
  571. }
  572. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  573. bufferView: number;
  574. byteOffset?: number;
  575. }
  576. interface IGLTFAccessorSparse extends IGLTFProperty {
  577. count: number;
  578. indices: IGLTFAccessorSparseIndices;
  579. values: IGLTFAccessorSparseValues;
  580. }
  581. interface IGLTFAccessor extends IGLTFChildRootProperty {
  582. bufferView?: number;
  583. byteOffset?: number;
  584. componentType: EComponentType;
  585. normalized?: boolean;
  586. count: number;
  587. type: string;
  588. max: number[];
  589. min: number[];
  590. sparse?: IGLTFAccessorSparse;
  591. }
  592. interface IGLTFAnimationChannel extends IGLTFProperty {
  593. sampler: number;
  594. target: IGLTFAnimationChannelTarget;
  595. }
  596. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  597. node: number;
  598. path: string;
  599. }
  600. interface IGLTFAnimationSampler extends IGLTFProperty {
  601. input: number;
  602. interpolation?: string;
  603. output: number;
  604. }
  605. interface IGLTFAnimation extends IGLTFChildRootProperty {
  606. channels: IGLTFAnimationChannel[];
  607. samplers: IGLTFAnimationSampler[];
  608. }
  609. interface IGLTFAssetProfile extends IGLTFProperty {
  610. api?: string;
  611. version?: string;
  612. }
  613. interface IGLTFAsset extends IGLTFChildRootProperty {
  614. copyright?: string;
  615. generator?: string;
  616. profile?: IGLTFAssetProfile;
  617. version: string;
  618. }
  619. interface IGLTFBuffer extends IGLTFChildRootProperty {
  620. uri?: string;
  621. byteLength: number;
  622. loadedBufferView: ArrayBufferView;
  623. }
  624. interface IGLTFBufferView extends IGLTFChildRootProperty {
  625. buffer: number;
  626. byteOffset?: number;
  627. byteLength: number;
  628. byteStride?: number;
  629. }
  630. interface IGLTFCameraOrthographic extends IGLTFProperty {
  631. xmag: number;
  632. ymag: number;
  633. zfar: number;
  634. znear: number;
  635. }
  636. interface IGLTFCameraPerspective extends IGLTFProperty {
  637. aspectRatio: number;
  638. yfov: number;
  639. zfar: number;
  640. znear: number;
  641. }
  642. interface IGLTFCamera extends IGLTFChildRootProperty {
  643. orthographic?: IGLTFCameraOrthographic;
  644. perspective?: IGLTFCameraPerspective;
  645. type: string;
  646. }
  647. interface IGLTFImage extends IGLTFChildRootProperty {
  648. uri?: string;
  649. mimeType?: string;
  650. bufferView?: number;
  651. }
  652. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  653. scale: number;
  654. }
  655. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  656. strength: number;
  657. }
  658. interface IGLTFMaterialPbrMetallicRoughness {
  659. baseColorFactor: number[];
  660. baseColorTexture: IGLTFTextureInfo;
  661. metallicFactor: number;
  662. roughnessFactor: number;
  663. metallicRoughnessTexture: IGLTFTextureInfo;
  664. }
  665. interface IGLTFMaterial extends IGLTFChildRootProperty {
  666. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  667. normalTexture?: IGLTFMaterialNormalTextureInfo;
  668. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  669. emissiveTexture?: IGLTFTextureInfo;
  670. emissiveFactor?: number[];
  671. alphaMode?: string;
  672. alphaCutoff: number;
  673. doubleSided?: boolean;
  674. babylonMaterial?: PBRMaterial;
  675. }
  676. interface IGLTFMeshPrimitive extends IGLTFProperty {
  677. attributes: {
  678. [name: string]: number;
  679. };
  680. indices?: number;
  681. material?: number;
  682. mode?: EMeshPrimitiveMode;
  683. targets?: [{
  684. [name: string]: number;
  685. }];
  686. }
  687. interface IGLTFMesh extends IGLTFChildRootProperty {
  688. primitives: IGLTFMeshPrimitive[];
  689. weights?: number[];
  690. }
  691. interface IGLTFNode extends IGLTFChildRootProperty {
  692. camera?: number;
  693. children?: number[];
  694. skin?: number;
  695. matrix?: number[];
  696. mesh?: number;
  697. rotation?: number[];
  698. scale?: number[];
  699. translation?: number[];
  700. weights?: number[];
  701. babylonNode?: Node;
  702. }
  703. interface IGLTFSampler extends IGLTFChildRootProperty {
  704. magFilter?: ETextureMagFilter;
  705. minFilter?: ETextureMinFilter;
  706. wrapS?: ETextureWrapMode;
  707. wrapT?: ETextureWrapMode;
  708. }
  709. interface IGLTFScene extends IGLTFChildRootProperty {
  710. nodes: number[];
  711. }
  712. interface IGLTFSkin extends IGLTFChildRootProperty {
  713. inverseBindMatrices?: number;
  714. skeleton?: number;
  715. joints: number[];
  716. babylonSkeleton?: Skeleton;
  717. }
  718. interface IGLTFTexture extends IGLTFChildRootProperty {
  719. sampler?: number;
  720. source: number;
  721. babylonTextures: Texture[];
  722. blobURL: string;
  723. }
  724. interface IGLTFTextureInfo {
  725. index: number;
  726. texCoord?: number;
  727. }
  728. interface IGLTF extends IGLTFProperty {
  729. accessors?: IGLTFAccessor[];
  730. animations?: IGLTFAnimation[];
  731. asset: IGLTFAsset;
  732. buffers?: IGLTFBuffer[];
  733. bufferViews?: IGLTFBufferView[];
  734. cameras?: IGLTFCamera[];
  735. extensionsUsed?: string[];
  736. extensionsRequired?: string[];
  737. glExtensionsUsed?: string[];
  738. images?: IGLTFImage[];
  739. materials?: IGLTFMaterial[];
  740. meshes?: IGLTFMesh[];
  741. nodes?: IGLTFNode[];
  742. samplers?: IGLTFSampler[];
  743. scene?: number;
  744. scenes?: IGLTFScene[];
  745. skins?: IGLTFSkin[];
  746. textures?: IGLTFTexture[];
  747. }
  748. interface IGLTFRuntime {
  749. gltf: IGLTF;
  750. babylonScene: Scene;
  751. rootUrl: string;
  752. importOnlyMeshes: boolean;
  753. importMeshesNames?: string[];
  754. defaultMaterial?: PBRMaterial;
  755. }
  756. /**
  757. * Bones
  758. */
  759. interface INodeToRoot {
  760. bone: Bone;
  761. node: IGLTFNode;
  762. index: number;
  763. }
  764. interface IJointNode {
  765. node: IGLTFNode;
  766. index: number;
  767. }
  768. }
  769. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  770. declare module BABYLON.GLTF2 {
  771. /**
  772. * glTF File Loader Plugin
  773. */
  774. class GLTFLoader implements IGLTFLoader {
  775. static Extensions: {
  776. [name: string]: GLTFLoaderExtension;
  777. };
  778. static RegisterExtension(extension: GLTFLoaderExtension): void;
  779. static LoadMaterial(runtime: IGLTFRuntime, index: number): IGLTFMaterial;
  780. static LoadMetallicRoughnessMaterialPropertiesAsync(runtime: IGLTFRuntime, material: IGLTFMaterial, onSuccess: () => void, onError: () => void): void;
  781. static LoadCommonMaterialPropertiesAsync(runtime: IGLTFRuntime, material: IGLTFMaterial, onSuccess: () => void, onError: () => void): void;
  782. static LoadAlphaProperties(runtime: IGLTFRuntime, material: IGLTFMaterial): void;
  783. static LoadTextureAsync(runtime: IGLTFRuntime, textureInfo: IGLTFTextureInfo, onSuccess: (babylonTexture: Texture) => void, onError: () => void): void;
  784. private static _createTextureAsync(runtime, texture, texCoord, url, onSuccess, onError);
  785. /**
  786. * Import meshes
  787. */
  788. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void): void;
  789. /**
  790. * Load scene
  791. */
  792. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  793. private static _loadBuffersAsync(runtime, onSuccess, onError);
  794. private static _loadBufferAsync(runtime, index, onSuccess, onError);
  795. private static _loadMaterialsAsync(runtime, onSuccess, onError);
  796. private static _createRuntime(scene, data, rootUrl, importOnlyMeshes);
  797. }
  798. }
  799. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  800. declare module BABYLON.GLTF2 {
  801. /**
  802. * Utils functions for GLTF
  803. */
  804. class GLTFUtils {
  805. /**
  806. * If the uri is a base64 string
  807. * @param uri: the uri to test
  808. */
  809. static IsBase64(uri: string): boolean;
  810. /**
  811. * Decode the base64 uri
  812. * @param uri: the uri to decode
  813. */
  814. static DecodeBase64(uri: string): ArrayBuffer;
  815. /**
  816. * Returns the wrap mode of the texture
  817. * @param mode: the mode value
  818. */
  819. static GetWrapMode(mode: number): number;
  820. /**
  821. * Returns the byte stride giving an accessor
  822. * @param accessor: the GLTF accessor objet
  823. */
  824. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  825. /**
  826. * Returns the texture filter mode giving a mode value
  827. * @param mode: the filter mode value
  828. */
  829. static GetTextureFilterMode(mode: number): ETextureMinFilter;
  830. static GetBufferFromBufferView(runtime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  831. /**
  832. * Returns a buffer from its accessor
  833. * @param runtime: the GLTF runtime
  834. * @param accessor: the GLTF accessor
  835. */
  836. static GetBufferFromAccessor(runtime: IGLTFRuntime, accessor: IGLTFAccessor): ArrayBufferView;
  837. /**
  838. * Decodes a buffer view into a string
  839. * @param view: the buffer view
  840. */
  841. static DecodeBufferToText(view: ArrayBufferView): string;
  842. /**
  843. * Returns the default material of gltf.
  844. * @param scene: the Babylon.js scene
  845. */
  846. static GetDefaultMaterial(runtime: IGLTFRuntime): PBRMaterial;
  847. }
  848. }
  849. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  850. declare module BABYLON.GLTF2 {
  851. abstract class GLTFLoaderExtension {
  852. private _name;
  853. constructor(name: string);
  854. readonly name: string;
  855. protected postCreateRuntime(runtime: IGLTFRuntime): void;
  856. protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean;
  857. static PostCreateRuntime(runtime: IGLTFRuntime): void;
  858. static LoadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void;
  859. }
  860. }
  861. /// <reference path="../../../../dist/preview release/babylon.d.ts" />
  862. declare module BABYLON.GLTF2 {
  863. class GLTFMaterialsPbrSpecularGlossinessExtension extends GLTFLoaderExtension {
  864. constructor();
  865. protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean;
  866. }
  867. }