babylon.glTFFileLoader.d.ts 18 KB

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