babylon.glTFFileLoader.d.ts 31 KB

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