babylon.glTF1FileLoader.d.ts 20 KB

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