babylon.glTF1FileLoader.d.ts 19 KB

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