babylon.glTF1FileLoader.d.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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. }