babylon.glTFFileLoader.d.ts 31 KB

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