babylon.glTFFileLoader.d.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. accessors: Object;
  275. buffers: Object;
  276. bufferViews: Object;
  277. meshes: Object;
  278. lights: Object;
  279. cameras: Object;
  280. nodes: Object;
  281. images: Object;
  282. textures: Object;
  283. shaders: Object;
  284. programs: Object;
  285. samplers: Object;
  286. techniques: Object;
  287. materials: Object;
  288. animations: Object;
  289. skins: Object;
  290. currentScene: Object;
  291. extensionsUsed: string[];
  292. buffersCount: number;
  293. shaderscount: number;
  294. scene: Scene;
  295. rootUrl: string;
  296. loadedBufferCount: number;
  297. loadedBufferViews: {
  298. [name: string]: ArrayBufferView;
  299. };
  300. loadedShaderCount: number;
  301. importOnlyMeshes: boolean;
  302. importMeshesNames?: string[];
  303. dummyNodes: Node[];
  304. }
  305. /**
  306. * Bones
  307. */
  308. interface INodeToRoot {
  309. bone: Bone;
  310. node: IGLTFNode;
  311. id: string;
  312. }
  313. interface IJointNode {
  314. node: IGLTFNode;
  315. id: string;
  316. }
  317. }
  318. /// <reference path="../../../dist/preview release/babylon.d.ts" />
  319. declare module BABYLON {
  320. /**
  321. * Implementation of the base glTF spec
  322. */
  323. class GLTFFileLoaderBase {
  324. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  325. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): void;
  326. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): void;
  327. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: () => void): void;
  328. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): void;
  329. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void;
  330. }
  331. /**
  332. * glTF File Loader Plugin
  333. */
  334. class GLTFFileLoader implements ISceneLoaderPluginAsync {
  335. /**
  336. * Public members
  337. */
  338. extensions: ISceneLoaderPluginExtensions;
  339. /**
  340. * Private members
  341. */
  342. /**
  343. * Static members
  344. */
  345. static MakeYUP: boolean;
  346. static HomogeneousCoordinates: boolean;
  347. static Extensions: {
  348. [name: string]: GLTFFileLoaderExtension;
  349. };
  350. static RegisterExtension(extension: GLTFFileLoaderExtension): void;
  351. /**
  352. * Import meshes
  353. */
  354. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError?: () => void): boolean;
  355. /**
  356. * Load scene
  357. */
  358. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: () => void, onError: () => void): boolean;
  359. private _loadShadersAsync(gltfRuntime, onload);
  360. private _loadBuffersAsync(gltfRuntime, onload);
  361. private _createNodes(gltfRuntime);
  362. }
  363. }
  364. /// <reference path="../../../dist/preview release/babylon.d.ts" />
  365. declare module BABYLON {
  366. /**
  367. * Utils functions for GLTF
  368. */
  369. class GLTFUtils {
  370. /**
  371. * Sets the given "parameter" matrix
  372. * @param scene: the {BABYLON.Scene} object
  373. * @param source: the source node where to pick the matrix
  374. * @param parameter: the GLTF technique parameter
  375. * @param uniformName: the name of the shader's uniform
  376. * @param shaderMaterial: the shader material
  377. */
  378. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  379. /**
  380. * Sets the given "parameter" matrix
  381. * @param shaderMaterial: the shader material
  382. * @param uniform: the name of the shader's uniform
  383. * @param value: the value of the uniform
  384. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  385. */
  386. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  387. /**
  388. * If the uri is a base64 string
  389. * @param uri: the uri to test
  390. */
  391. static IsBase64(uri: string): boolean;
  392. /**
  393. * Decode the base64 uri
  394. * @param uri: the uri to decode
  395. */
  396. static DecodeBase64(uri: string): ArrayBuffer;
  397. /**
  398. * Returns the wrap mode of the texture
  399. * @param mode: the mode value
  400. */
  401. static GetWrapMode(mode: number): number;
  402. /**
  403. * Returns the byte stride giving an accessor
  404. * @param accessor: the GLTF accessor objet
  405. */
  406. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  407. /**
  408. * Returns the texture filter mode giving a mode value
  409. * @param mode: the filter mode value
  410. */
  411. static GetTextureFilterMode(mode: number): ETextureFilterType;
  412. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  413. /**
  414. * Returns a buffer from its accessor
  415. * @param gltfRuntime: the GLTF runtime
  416. * @param accessor: the GLTF accessor
  417. */
  418. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  419. /**
  420. * Decodes a buffer view into a string
  421. * @param view: the buffer view
  422. */
  423. static DecodeBufferToText(view: ArrayBufferView): string;
  424. }
  425. }
  426. /// <reference path="../../../dist/preview release/babylon.d.ts" />
  427. declare module BABYLON {
  428. abstract class GLTFFileLoaderExtension {
  429. private _name;
  430. constructor(name: string);
  431. readonly name: string;
  432. /**
  433. * Defines an override for loading the runtime
  434. * Return true to stop further extensions from loading the runtime
  435. */
  436. loadRuntimeAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): boolean;
  437. /**
  438. * Defines an override for loading buffers
  439. * Return true to stop further extensions from loading this buffer
  440. */
  441. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  442. /**
  443. * Defines an override for loading texture buffers
  444. * Return true to stop further extensions from loading this texture data
  445. */
  446. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  447. /**
  448. * Defines an override for creating textures
  449. * Return true to stop further extensions from loading this texture
  450. */
  451. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: () => void): boolean;
  452. /**
  453. * Defines an override for loading shader strings
  454. * Return true to stop further extensions from loading this shader data
  455. */
  456. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): boolean;
  457. /**
  458. * Defines an override for loading materials
  459. * Return true to stop further extensions from loading this material
  460. */
  461. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): boolean;
  462. static LoadRuntimeAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): void;
  463. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: () => void): void;
  464. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: () => void): void;
  465. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: () => void): void;
  466. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void;
  467. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  468. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  469. private static ApplyExtensions(func, defaultFunc);
  470. }
  471. }
  472. /// <reference path="../../../dist/preview release/babylon.d.ts" />
  473. declare module BABYLON {
  474. class GLTFBinaryExtension extends GLTFFileLoaderExtension {
  475. private _binary;
  476. constructor();
  477. loadRuntimeAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: () => void): boolean;
  478. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  479. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: () => void): boolean;
  480. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: () => void): boolean;
  481. private _parseBinary(data);
  482. }
  483. }