babylon.glTF1FileLoader.d.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. declare module BABYLON {
  2. interface IGLTFLoaderData {
  3. json: Object;
  4. bin: ArrayBufferView;
  5. }
  6. interface IGLTFLoader {
  7. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onsuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onerror: () => void) => void;
  8. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onsuccess: () => void, onerror: () => void) => void;
  9. }
  10. class GLTFFileLoader implements ISceneLoaderPluginAsync {
  11. static GLTFLoaderV1: IGLTFLoader;
  12. static GLTFLoaderV2: IGLTFLoader;
  13. static HomogeneousCoordinates: boolean;
  14. static IncrementalLoading: boolean;
  15. extensions: ISceneLoaderPluginExtensions;
  16. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void;
  17. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  18. canDirectLoad(data: string): boolean;
  19. private static _parse(data);
  20. private _getLoader(loaderData);
  21. private static _parseBinary(data);
  22. private static _parseV1(binaryReader);
  23. private static _parseV2(binaryReader);
  24. private static _parseVersion(version);
  25. private static _compareVersion(a, b);
  26. private static _decodeBufferToText(view);
  27. }
  28. }
  29. declare module BABYLON.GLTF1 {
  30. /**
  31. * Enums
  32. */
  33. enum EComponentType {
  34. BYTE = 5120,
  35. UNSIGNED_BYTE = 5121,
  36. SHORT = 5122,
  37. UNSIGNED_SHORT = 5123,
  38. FLOAT = 5126,
  39. }
  40. enum EShaderType {
  41. FRAGMENT = 35632,
  42. VERTEX = 35633,
  43. }
  44. enum EParameterType {
  45. BYTE = 5120,
  46. UNSIGNED_BYTE = 5121,
  47. SHORT = 5122,
  48. UNSIGNED_SHORT = 5123,
  49. INT = 5124,
  50. UNSIGNED_INT = 5125,
  51. FLOAT = 5126,
  52. FLOAT_VEC2 = 35664,
  53. FLOAT_VEC3 = 35665,
  54. FLOAT_VEC4 = 35666,
  55. INT_VEC2 = 35667,
  56. INT_VEC3 = 35668,
  57. INT_VEC4 = 35669,
  58. BOOL = 35670,
  59. BOOL_VEC2 = 35671,
  60. BOOL_VEC3 = 35672,
  61. BOOL_VEC4 = 35673,
  62. FLOAT_MAT2 = 35674,
  63. FLOAT_MAT3 = 35675,
  64. FLOAT_MAT4 = 35676,
  65. SAMPLER_2D = 35678,
  66. }
  67. enum ETextureWrapMode {
  68. CLAMP_TO_EDGE = 33071,
  69. MIRRORED_REPEAT = 33648,
  70. REPEAT = 10497,
  71. }
  72. enum ETextureFilterType {
  73. NEAREST = 9728,
  74. LINEAR = 9728,
  75. NEAREST_MIPMAP_NEAREST = 9984,
  76. LINEAR_MIPMAP_NEAREST = 9985,
  77. NEAREST_MIPMAP_LINEAR = 9986,
  78. LINEAR_MIPMAP_LINEAR = 9987,
  79. }
  80. enum ETextureFormat {
  81. ALPHA = 6406,
  82. RGB = 6407,
  83. RGBA = 6408,
  84. LUMINANCE = 6409,
  85. LUMINANCE_ALPHA = 6410,
  86. }
  87. enum ECullingType {
  88. FRONT = 1028,
  89. BACK = 1029,
  90. FRONT_AND_BACK = 1032,
  91. }
  92. enum EBlendingFunction {
  93. ZERO = 0,
  94. ONE = 1,
  95. SRC_COLOR = 768,
  96. ONE_MINUS_SRC_COLOR = 769,
  97. DST_COLOR = 774,
  98. ONE_MINUS_DST_COLOR = 775,
  99. SRC_ALPHA = 770,
  100. ONE_MINUS_SRC_ALPHA = 771,
  101. DST_ALPHA = 772,
  102. ONE_MINUS_DST_ALPHA = 773,
  103. CONSTANT_COLOR = 32769,
  104. ONE_MINUS_CONSTANT_COLOR = 32770,
  105. CONSTANT_ALPHA = 32771,
  106. ONE_MINUS_CONSTANT_ALPHA = 32772,
  107. SRC_ALPHA_SATURATE = 776,
  108. }
  109. /**
  110. * Interfaces
  111. */
  112. interface IGLTFProperty {
  113. extensions?: Object;
  114. extras?: Object;
  115. }
  116. interface IGLTFChildRootProperty extends IGLTFProperty {
  117. name?: string;
  118. }
  119. interface IGLTFAccessor extends IGLTFChildRootProperty {
  120. bufferView: string;
  121. byteOffset: number;
  122. byteStride: number;
  123. count: number;
  124. type: string;
  125. componentType: EComponentType;
  126. max?: number[];
  127. min?: number[];
  128. name?: string;
  129. }
  130. interface IGLTFBufferView extends IGLTFChildRootProperty {
  131. buffer: string;
  132. byteOffset: number;
  133. byteLength: number;
  134. target?: number;
  135. }
  136. interface IGLTFBuffer extends IGLTFChildRootProperty {
  137. uri: string;
  138. byteLength?: number;
  139. type?: string;
  140. }
  141. interface IGLTFShader extends IGLTFChildRootProperty {
  142. uri: string;
  143. type: EShaderType;
  144. }
  145. interface IGLTFProgram extends IGLTFChildRootProperty {
  146. attributes: string[];
  147. fragmentShader: string;
  148. vertexShader: string;
  149. }
  150. interface IGLTFTechniqueParameter {
  151. type: number;
  152. count?: number;
  153. semantic?: string;
  154. node?: string;
  155. value?: number | boolean | string | Array<any>;
  156. source?: string;
  157. babylonValue?: any;
  158. }
  159. interface IGLTFTechniqueCommonProfile {
  160. lightingModel: string;
  161. texcoordBindings: Object;
  162. parameters?: Array<any>;
  163. }
  164. interface IGLTFTechniqueStatesFunctions {
  165. blendColor?: number[];
  166. blendEquationSeparate?: number[];
  167. blendFuncSeparate?: number[];
  168. colorMask: boolean[];
  169. cullFace: number[];
  170. }
  171. interface IGLTFTechniqueStates {
  172. enable: number[];
  173. functions: IGLTFTechniqueStatesFunctions;
  174. }
  175. interface IGLTFTechnique extends IGLTFChildRootProperty {
  176. parameters: Object;
  177. program: string;
  178. attributes: Object;
  179. uniforms: Object;
  180. states: IGLTFTechniqueStates;
  181. }
  182. interface IGLTFMaterial extends IGLTFChildRootProperty {
  183. technique?: string;
  184. values: string[];
  185. }
  186. interface IGLTFMeshPrimitive extends IGLTFProperty {
  187. attributes: Object;
  188. indices: string;
  189. material: string;
  190. mode?: number;
  191. }
  192. interface IGLTFMesh extends IGLTFChildRootProperty {
  193. primitives: IGLTFMeshPrimitive[];
  194. }
  195. interface IGLTFImage extends IGLTFChildRootProperty {
  196. uri: string;
  197. }
  198. interface IGLTFSampler extends IGLTFChildRootProperty {
  199. magFilter?: number;
  200. minFilter?: number;
  201. wrapS?: number;
  202. wrapT?: number;
  203. }
  204. interface IGLTFTexture extends IGLTFChildRootProperty {
  205. sampler: string;
  206. source: string;
  207. format?: ETextureFormat;
  208. internalFormat?: ETextureFormat;
  209. target?: number;
  210. type?: number;
  211. babylonTexture?: Texture;
  212. }
  213. interface IGLTFAmbienLight {
  214. color?: number[];
  215. }
  216. interface IGLTFDirectionalLight {
  217. color?: number[];
  218. }
  219. interface IGLTFPointLight {
  220. color?: number[];
  221. constantAttenuation?: number;
  222. linearAttenuation?: number;
  223. quadraticAttenuation?: number;
  224. }
  225. interface IGLTFSpotLight {
  226. color?: number[];
  227. constantAttenuation?: number;
  228. fallOfAngle?: number;
  229. fallOffExponent?: number;
  230. linearAttenuation?: number;
  231. quadraticAttenuation?: number;
  232. }
  233. interface IGLTFLight extends IGLTFChildRootProperty {
  234. type: string;
  235. }
  236. interface IGLTFCameraOrthographic {
  237. xmag: number;
  238. ymag: number;
  239. zfar: number;
  240. znear: number;
  241. }
  242. interface IGLTFCameraPerspective {
  243. aspectRatio: number;
  244. yfov: number;
  245. zfar: number;
  246. znear: number;
  247. }
  248. interface IGLTFCamera extends IGLTFChildRootProperty {
  249. type: string;
  250. }
  251. interface IGLTFAnimationChannelTarget {
  252. id: string;
  253. path: string;
  254. }
  255. interface IGLTFAnimationChannel {
  256. sampler: string;
  257. target: IGLTFAnimationChannelTarget;
  258. }
  259. interface IGLTFAnimationSampler {
  260. input: string;
  261. output: string;
  262. interpolation?: string;
  263. }
  264. interface IGLTFAnimation extends IGLTFChildRootProperty {
  265. channels?: IGLTFAnimationChannel[];
  266. parameters?: Object;
  267. samplers?: Object;
  268. }
  269. interface IGLTFNodeInstanceSkin {
  270. skeletons: string[];
  271. skin: string;
  272. meshes: string[];
  273. }
  274. interface IGLTFSkins extends IGLTFChildRootProperty {
  275. bindShapeMatrix: number[];
  276. inverseBindMatrices: string;
  277. jointNames: string[];
  278. babylonSkeleton?: Skeleton;
  279. }
  280. interface IGLTFNode extends IGLTFChildRootProperty {
  281. camera?: string;
  282. children: string[];
  283. skin?: string;
  284. jointName?: string;
  285. light?: string;
  286. matrix: number[];
  287. mesh?: string;
  288. meshes?: string[];
  289. rotation?: number[];
  290. scale?: number[];
  291. translation?: number[];
  292. babylonNode?: Node;
  293. }
  294. interface IGLTFScene extends IGLTFChildRootProperty {
  295. nodes: string[];
  296. }
  297. /**
  298. * Runtime
  299. */
  300. interface IGLTFRuntime {
  301. extensions: Object;
  302. accessors: Object;
  303. buffers: Object;
  304. bufferViews: Object;
  305. meshes: Object;
  306. lights: Object;
  307. cameras: Object;
  308. nodes: Object;
  309. images: Object;
  310. textures: Object;
  311. shaders: Object;
  312. programs: Object;
  313. samplers: Object;
  314. techniques: Object;
  315. materials: Object;
  316. animations: Object;
  317. skins: Object;
  318. currentScene?: Object;
  319. scenes: Object;
  320. extensionsUsed: string[];
  321. extensionsRequired?: string[];
  322. buffersCount: number;
  323. shaderscount: number;
  324. scene: Scene;
  325. rootUrl: string;
  326. loadedBufferCount: number;
  327. loadedBufferViews: {
  328. [name: string]: ArrayBufferView;
  329. };
  330. loadedShaderCount: number;
  331. importOnlyMeshes: boolean;
  332. importMeshesNames?: string[];
  333. dummyNodes: Node[];
  334. }
  335. /**
  336. * Bones
  337. */
  338. interface INodeToRoot {
  339. bone: Bone;
  340. node: IGLTFNode;
  341. id: string;
  342. }
  343. interface IJointNode {
  344. node: IGLTFNode;
  345. id: string;
  346. }
  347. }
  348. declare module BABYLON.GLTF1 {
  349. /**
  350. * Implementation of the base glTF spec
  351. */
  352. class GLTFLoaderBase {
  353. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  354. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void, onProgress?: () => void): void;
  355. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): void;
  356. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: () => void): void;
  357. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): void;
  358. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void;
  359. }
  360. /**
  361. * glTF V1 Loader
  362. */
  363. class GLTFLoader implements IGLTFLoader {
  364. static Extensions: {
  365. [name: string]: GLTFLoaderExtension;
  366. };
  367. static RegisterExtension(extension: GLTFLoaderExtension): void;
  368. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void, onProgress?: () => void): boolean;
  369. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onError: () => void): void;
  370. private _loadShadersAsync(gltfRuntime, onload);
  371. private _loadBuffersAsync(gltfRuntime, onload, onProgress?);
  372. private _createNodes(gltfRuntime);
  373. }
  374. }
  375. declare module BABYLON.GLTF1 {
  376. /**
  377. * Utils functions for GLTF
  378. */
  379. class GLTFUtils {
  380. /**
  381. * Sets the given "parameter" matrix
  382. * @param scene: the {BABYLON.Scene} object
  383. * @param source: the source node where to pick the matrix
  384. * @param parameter: the GLTF technique parameter
  385. * @param uniformName: the name of the shader's uniform
  386. * @param shaderMaterial: the shader material
  387. */
  388. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  389. /**
  390. * Sets the given "parameter" matrix
  391. * @param shaderMaterial: the shader material
  392. * @param uniform: the name of the shader's uniform
  393. * @param value: the value of the uniform
  394. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  395. */
  396. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  397. /**
  398. * If the uri is a base64 string
  399. * @param uri: the uri to test
  400. */
  401. static IsBase64(uri: string): boolean;
  402. /**
  403. * Decode the base64 uri
  404. * @param uri: the uri to decode
  405. */
  406. static DecodeBase64(uri: string): ArrayBuffer;
  407. /**
  408. * Returns the wrap mode of the texture
  409. * @param mode: the mode value
  410. */
  411. static GetWrapMode(mode: number): number;
  412. /**
  413. * Returns the byte stride giving an accessor
  414. * @param accessor: the GLTF accessor objet
  415. */
  416. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  417. /**
  418. * Returns the texture filter mode giving a mode value
  419. * @param mode: the filter mode value
  420. */
  421. static GetTextureFilterMode(mode: number): ETextureFilterType;
  422. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  423. /**
  424. * Returns a buffer from its accessor
  425. * @param gltfRuntime: the GLTF runtime
  426. * @param accessor: the GLTF accessor
  427. */
  428. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  429. /**
  430. * Decodes a buffer view into a string
  431. * @param view: the buffer view
  432. */
  433. static DecodeBufferToText(view: ArrayBufferView): string;
  434. /**
  435. * Returns the default material of gltf. Related to
  436. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  437. * @param scene: the Babylon.js scene
  438. */
  439. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  440. private static _DefaultMaterial;
  441. }
  442. }
  443. declare module BABYLON.GLTF1 {
  444. abstract class GLTFLoaderExtension {
  445. private _name;
  446. constructor(name: string);
  447. readonly name: string;
  448. /**
  449. * Defines an override for loading the runtime
  450. * Return true to stop further extensions from loading the runtime
  451. */
  452. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): boolean;
  453. /**
  454. * Defines an onverride for creating gltf runtime
  455. * Return true to stop further extensions from creating the runtime
  456. */
  457. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): boolean;
  458. /**
  459. * Defines an override for loading buffers
  460. * Return true to stop further extensions from loading this buffer
  461. */
  462. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void, onProgress?: () => void): boolean;
  463. /**
  464. * Defines an override for loading texture buffers
  465. * Return true to stop further extensions from loading this texture data
  466. */
  467. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  468. /**
  469. * Defines an override for creating textures
  470. * Return true to stop further extensions from loading this texture
  471. */
  472. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: () => void): boolean;
  473. /**
  474. * Defines an override for loading shader strings
  475. * Return true to stop further extensions from loading this shader data
  476. */
  477. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): boolean;
  478. /**
  479. * Defines an override for loading materials
  480. * Return true to stop further extensions from loading this material
  481. */
  482. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): boolean;
  483. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): void;
  484. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): void;
  485. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: () => void, onProgress?: () => void): void;
  486. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: () => void): void;
  487. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: () => void): void;
  488. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void;
  489. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  490. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  491. private static ApplyExtensions(func, defaultFunc);
  492. }
  493. }
  494. declare module BABYLON.GLTF1 {
  495. class GLTFBinaryExtension extends GLTFLoaderExtension {
  496. private _bin;
  497. constructor();
  498. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): boolean;
  499. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  500. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  501. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): boolean;
  502. }
  503. }
  504. declare module BABYLON.GLTF1 {
  505. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  506. constructor();
  507. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): boolean;
  508. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): boolean;
  509. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  510. }
  511. }