babylon.glTFFileLoader.d.ts 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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. onComplete: () => void;
  24. name: string;
  25. extensions: ISceneLoaderPluginExtensions;
  26. 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;
  27. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  28. canDirectLoad(data: string): boolean;
  29. private static _parse(data, onError);
  30. private _getLoader(loaderData, onError);
  31. private static _parseBinary(data, onError);
  32. private static _parseV1(binaryReader, onError);
  33. private static _parseV2(binaryReader, onError);
  34. private static _parseVersion(version);
  35. private static _compareVersion(a, b);
  36. private static _decodeBufferToText(view);
  37. }
  38. }
  39. declare module BABYLON.GLTF1 {
  40. /**
  41. * Enums
  42. */
  43. enum EComponentType {
  44. BYTE = 5120,
  45. UNSIGNED_BYTE = 5121,
  46. SHORT = 5122,
  47. UNSIGNED_SHORT = 5123,
  48. FLOAT = 5126,
  49. }
  50. enum EShaderType {
  51. FRAGMENT = 35632,
  52. VERTEX = 35633,
  53. }
  54. enum EParameterType {
  55. BYTE = 5120,
  56. UNSIGNED_BYTE = 5121,
  57. SHORT = 5122,
  58. UNSIGNED_SHORT = 5123,
  59. INT = 5124,
  60. UNSIGNED_INT = 5125,
  61. FLOAT = 5126,
  62. FLOAT_VEC2 = 35664,
  63. FLOAT_VEC3 = 35665,
  64. FLOAT_VEC4 = 35666,
  65. INT_VEC2 = 35667,
  66. INT_VEC3 = 35668,
  67. INT_VEC4 = 35669,
  68. BOOL = 35670,
  69. BOOL_VEC2 = 35671,
  70. BOOL_VEC3 = 35672,
  71. BOOL_VEC4 = 35673,
  72. FLOAT_MAT2 = 35674,
  73. FLOAT_MAT3 = 35675,
  74. FLOAT_MAT4 = 35676,
  75. SAMPLER_2D = 35678,
  76. }
  77. enum ETextureWrapMode {
  78. CLAMP_TO_EDGE = 33071,
  79. MIRRORED_REPEAT = 33648,
  80. REPEAT = 10497,
  81. }
  82. enum ETextureFilterType {
  83. NEAREST = 9728,
  84. LINEAR = 9728,
  85. NEAREST_MIPMAP_NEAREST = 9984,
  86. LINEAR_MIPMAP_NEAREST = 9985,
  87. NEAREST_MIPMAP_LINEAR = 9986,
  88. LINEAR_MIPMAP_LINEAR = 9987,
  89. }
  90. enum ETextureFormat {
  91. ALPHA = 6406,
  92. RGB = 6407,
  93. RGBA = 6408,
  94. LUMINANCE = 6409,
  95. LUMINANCE_ALPHA = 6410,
  96. }
  97. enum ECullingType {
  98. FRONT = 1028,
  99. BACK = 1029,
  100. FRONT_AND_BACK = 1032,
  101. }
  102. enum EBlendingFunction {
  103. ZERO = 0,
  104. ONE = 1,
  105. SRC_COLOR = 768,
  106. ONE_MINUS_SRC_COLOR = 769,
  107. DST_COLOR = 774,
  108. ONE_MINUS_DST_COLOR = 775,
  109. SRC_ALPHA = 770,
  110. ONE_MINUS_SRC_ALPHA = 771,
  111. DST_ALPHA = 772,
  112. ONE_MINUS_DST_ALPHA = 773,
  113. CONSTANT_COLOR = 32769,
  114. ONE_MINUS_CONSTANT_COLOR = 32770,
  115. CONSTANT_ALPHA = 32771,
  116. ONE_MINUS_CONSTANT_ALPHA = 32772,
  117. SRC_ALPHA_SATURATE = 776,
  118. }
  119. /**
  120. * Interfaces
  121. */
  122. interface IGLTFProperty {
  123. extensions?: Object;
  124. extras?: Object;
  125. }
  126. interface IGLTFChildRootProperty extends IGLTFProperty {
  127. name?: string;
  128. }
  129. interface IGLTFAccessor extends IGLTFChildRootProperty {
  130. bufferView: string;
  131. byteOffset: number;
  132. byteStride: number;
  133. count: number;
  134. type: string;
  135. componentType: EComponentType;
  136. max?: number[];
  137. min?: number[];
  138. name?: string;
  139. }
  140. interface IGLTFBufferView extends IGLTFChildRootProperty {
  141. buffer: string;
  142. byteOffset: number;
  143. byteLength: number;
  144. target?: number;
  145. }
  146. interface IGLTFBuffer extends IGLTFChildRootProperty {
  147. uri: string;
  148. byteLength?: number;
  149. type?: string;
  150. }
  151. interface IGLTFShader extends IGLTFChildRootProperty {
  152. uri: string;
  153. type: EShaderType;
  154. }
  155. interface IGLTFProgram extends IGLTFChildRootProperty {
  156. attributes: string[];
  157. fragmentShader: string;
  158. vertexShader: string;
  159. }
  160. interface IGLTFTechniqueParameter {
  161. type: number;
  162. count?: number;
  163. semantic?: string;
  164. node?: string;
  165. value?: number | boolean | string | Array<any>;
  166. source?: string;
  167. babylonValue?: any;
  168. }
  169. interface IGLTFTechniqueCommonProfile {
  170. lightingModel: string;
  171. texcoordBindings: Object;
  172. parameters?: Array<any>;
  173. }
  174. interface IGLTFTechniqueStatesFunctions {
  175. blendColor?: number[];
  176. blendEquationSeparate?: number[];
  177. blendFuncSeparate?: number[];
  178. colorMask: boolean[];
  179. cullFace: number[];
  180. }
  181. interface IGLTFTechniqueStates {
  182. enable: number[];
  183. functions: IGLTFTechniqueStatesFunctions;
  184. }
  185. interface IGLTFTechnique extends IGLTFChildRootProperty {
  186. parameters: Object;
  187. program: string;
  188. attributes: Object;
  189. uniforms: Object;
  190. states: IGLTFTechniqueStates;
  191. }
  192. interface IGLTFMaterial extends IGLTFChildRootProperty {
  193. technique?: string;
  194. values: string[];
  195. }
  196. interface IGLTFMeshPrimitive extends IGLTFProperty {
  197. attributes: Object;
  198. indices: string;
  199. material: string;
  200. mode?: number;
  201. }
  202. interface IGLTFMesh extends IGLTFChildRootProperty {
  203. primitives: IGLTFMeshPrimitive[];
  204. }
  205. interface IGLTFImage extends IGLTFChildRootProperty {
  206. uri: string;
  207. }
  208. interface IGLTFSampler extends IGLTFChildRootProperty {
  209. magFilter?: number;
  210. minFilter?: number;
  211. wrapS?: number;
  212. wrapT?: number;
  213. }
  214. interface IGLTFTexture extends IGLTFChildRootProperty {
  215. sampler: string;
  216. source: string;
  217. format?: ETextureFormat;
  218. internalFormat?: ETextureFormat;
  219. target?: number;
  220. type?: number;
  221. babylonTexture?: Texture;
  222. }
  223. interface IGLTFAmbienLight {
  224. color?: number[];
  225. }
  226. interface IGLTFDirectionalLight {
  227. color?: number[];
  228. }
  229. interface IGLTFPointLight {
  230. color?: number[];
  231. constantAttenuation?: number;
  232. linearAttenuation?: number;
  233. quadraticAttenuation?: number;
  234. }
  235. interface IGLTFSpotLight {
  236. color?: number[];
  237. constantAttenuation?: number;
  238. fallOfAngle?: number;
  239. fallOffExponent?: number;
  240. linearAttenuation?: number;
  241. quadraticAttenuation?: number;
  242. }
  243. interface IGLTFLight extends IGLTFChildRootProperty {
  244. type: string;
  245. }
  246. interface IGLTFCameraOrthographic {
  247. xmag: number;
  248. ymag: number;
  249. zfar: number;
  250. znear: number;
  251. }
  252. interface IGLTFCameraPerspective {
  253. aspectRatio: number;
  254. yfov: number;
  255. zfar: number;
  256. znear: number;
  257. }
  258. interface IGLTFCamera extends IGLTFChildRootProperty {
  259. type: string;
  260. }
  261. interface IGLTFAnimationChannelTarget {
  262. id: string;
  263. path: string;
  264. }
  265. interface IGLTFAnimationChannel {
  266. sampler: string;
  267. target: IGLTFAnimationChannelTarget;
  268. }
  269. interface IGLTFAnimationSampler {
  270. input: string;
  271. output: string;
  272. interpolation?: string;
  273. }
  274. interface IGLTFAnimation extends IGLTFChildRootProperty {
  275. channels?: IGLTFAnimationChannel[];
  276. parameters?: Object;
  277. samplers?: Object;
  278. }
  279. interface IGLTFNodeInstanceSkin {
  280. skeletons: string[];
  281. skin: string;
  282. meshes: string[];
  283. }
  284. interface IGLTFSkins extends IGLTFChildRootProperty {
  285. bindShapeMatrix: number[];
  286. inverseBindMatrices: string;
  287. jointNames: string[];
  288. babylonSkeleton?: Skeleton;
  289. }
  290. interface IGLTFNode extends IGLTFChildRootProperty {
  291. camera?: string;
  292. children: string[];
  293. skin?: string;
  294. jointName?: string;
  295. light?: string;
  296. matrix: number[];
  297. mesh?: string;
  298. meshes?: string[];
  299. rotation?: number[];
  300. scale?: number[];
  301. translation?: number[];
  302. babylonNode?: Node;
  303. }
  304. interface IGLTFScene extends IGLTFChildRootProperty {
  305. nodes: string[];
  306. }
  307. /**
  308. * Runtime
  309. */
  310. interface IGLTFRuntime {
  311. extensions: Object;
  312. accessors: Object;
  313. buffers: Object;
  314. bufferViews: Object;
  315. meshes: Object;
  316. lights: Object;
  317. cameras: Object;
  318. nodes: Object;
  319. images: Object;
  320. textures: Object;
  321. shaders: Object;
  322. programs: Object;
  323. samplers: Object;
  324. techniques: Object;
  325. materials: Object;
  326. animations: Object;
  327. skins: Object;
  328. currentScene?: Object;
  329. scenes: Object;
  330. extensionsUsed: string[];
  331. extensionsRequired?: string[];
  332. buffersCount: number;
  333. shaderscount: number;
  334. scene: Scene;
  335. rootUrl: string;
  336. loadedBufferCount: number;
  337. loadedBufferViews: {
  338. [name: string]: ArrayBufferView;
  339. };
  340. loadedShaderCount: number;
  341. importOnlyMeshes: boolean;
  342. importMeshesNames?: string[];
  343. dummyNodes: Node[];
  344. }
  345. /**
  346. * Bones
  347. */
  348. interface INodeToRoot {
  349. bone: Bone;
  350. node: IGLTFNode;
  351. id: string;
  352. }
  353. interface IJointNode {
  354. node: IGLTFNode;
  355. id: string;
  356. }
  357. }
  358. declare module BABYLON.GLTF1 {
  359. /**
  360. * Implementation of the base glTF spec
  361. */
  362. class GLTFLoaderBase {
  363. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  364. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  365. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): void;
  366. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  367. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): void;
  368. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  369. }
  370. /**
  371. * glTF V1 Loader
  372. */
  373. class GLTFLoader implements IGLTFLoader {
  374. static Extensions: {
  375. [name: string]: GLTFLoaderExtension;
  376. };
  377. static RegisterExtension(extension: GLTFLoaderExtension): void;
  378. 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;
  379. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  380. private _loadShadersAsync(gltfRuntime, onload);
  381. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  382. private _createNodes(gltfRuntime);
  383. }
  384. }
  385. declare module BABYLON.GLTF1 {
  386. /**
  387. * Utils functions for GLTF
  388. */
  389. class GLTFUtils {
  390. /**
  391. * Sets the given "parameter" matrix
  392. * @param scene: the {BABYLON.Scene} object
  393. * @param source: the source node where to pick the matrix
  394. * @param parameter: the GLTF technique parameter
  395. * @param uniformName: the name of the shader's uniform
  396. * @param shaderMaterial: the shader material
  397. */
  398. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  399. /**
  400. * Sets the given "parameter" matrix
  401. * @param shaderMaterial: the shader material
  402. * @param uniform: the name of the shader's uniform
  403. * @param value: the value of the uniform
  404. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  405. */
  406. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  407. /**
  408. * If the uri is a base64 string
  409. * @param uri: the uri to test
  410. */
  411. static IsBase64(uri: string): boolean;
  412. /**
  413. * Decode the base64 uri
  414. * @param uri: the uri to decode
  415. */
  416. static DecodeBase64(uri: string): ArrayBuffer;
  417. /**
  418. * Returns the wrap mode of the texture
  419. * @param mode: the mode value
  420. */
  421. static GetWrapMode(mode: number): number;
  422. /**
  423. * Returns the byte stride giving an accessor
  424. * @param accessor: the GLTF accessor objet
  425. */
  426. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  427. /**
  428. * Returns the texture filter mode giving a mode value
  429. * @param mode: the filter mode value
  430. */
  431. static GetTextureFilterMode(mode: number): ETextureFilterType;
  432. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  433. /**
  434. * Returns a buffer from its accessor
  435. * @param gltfRuntime: the GLTF runtime
  436. * @param accessor: the GLTF accessor
  437. */
  438. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  439. /**
  440. * Decodes a buffer view into a string
  441. * @param view: the buffer view
  442. */
  443. static DecodeBufferToText(view: ArrayBufferView): string;
  444. /**
  445. * Returns the default material of gltf. Related to
  446. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  447. * @param scene: the Babylon.js scene
  448. */
  449. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  450. private static _DefaultMaterial;
  451. }
  452. }
  453. declare module BABYLON.GLTF1 {
  454. abstract class GLTFLoaderExtension {
  455. private _name;
  456. constructor(name: string);
  457. readonly name: string;
  458. /**
  459. * Defines an override for loading the runtime
  460. * Return true to stop further extensions from loading the runtime
  461. */
  462. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  463. /**
  464. * Defines an onverride for creating gltf runtime
  465. * Return true to stop further extensions from creating the runtime
  466. */
  467. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  468. /**
  469. * Defines an override for loading buffers
  470. * Return true to stop further extensions from loading this buffer
  471. */
  472. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  473. /**
  474. * Defines an override for loading texture buffers
  475. * Return true to stop further extensions from loading this texture data
  476. */
  477. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  478. /**
  479. * Defines an override for creating textures
  480. * Return true to stop further extensions from loading this texture
  481. */
  482. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  483. /**
  484. * Defines an override for loading shader strings
  485. * Return true to stop further extensions from loading this shader data
  486. */
  487. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  488. /**
  489. * Defines an override for loading materials
  490. * Return true to stop further extensions from loading this material
  491. */
  492. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  493. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): void;
  494. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): void;
  495. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  496. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  497. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: (message: string) => void): void;
  498. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  499. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  500. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  501. private static ApplyExtensions(func, defaultFunc);
  502. }
  503. }
  504. declare module BABYLON.GLTF1 {
  505. class GLTFBinaryExtension extends GLTFLoaderExtension {
  506. private _bin;
  507. constructor();
  508. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  509. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  510. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  511. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  512. }
  513. }
  514. declare module BABYLON.GLTF1 {
  515. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  516. constructor();
  517. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  518. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  519. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  520. }
  521. }
  522. declare module BABYLON.GLTF2 {
  523. /**
  524. * Enums
  525. */
  526. enum EComponentType {
  527. BYTE = 5120,
  528. UNSIGNED_BYTE = 5121,
  529. SHORT = 5122,
  530. UNSIGNED_SHORT = 5123,
  531. UNSIGNED_INT = 5125,
  532. FLOAT = 5126,
  533. }
  534. enum EMeshPrimitiveMode {
  535. POINTS = 0,
  536. LINES = 1,
  537. LINE_LOOP = 2,
  538. LINE_STRIP = 3,
  539. TRIANGLES = 4,
  540. TRIANGLE_STRIP = 5,
  541. TRIANGLE_FAN = 6,
  542. }
  543. enum ETextureMagFilter {
  544. NEAREST = 9728,
  545. LINEAR = 9729,
  546. }
  547. enum ETextureMinFilter {
  548. NEAREST = 9728,
  549. LINEAR = 9729,
  550. NEAREST_MIPMAP_NEAREST = 9984,
  551. LINEAR_MIPMAP_NEAREST = 9985,
  552. NEAREST_MIPMAP_LINEAR = 9986,
  553. LINEAR_MIPMAP_LINEAR = 9987,
  554. }
  555. enum ETextureWrapMode {
  556. CLAMP_TO_EDGE = 33071,
  557. MIRRORED_REPEAT = 33648,
  558. REPEAT = 10497,
  559. }
  560. /**
  561. * Interfaces
  562. */
  563. interface IGLTFProperty {
  564. extensions?: Object;
  565. extras?: any;
  566. }
  567. interface IGLTFChildRootProperty extends IGLTFProperty {
  568. name?: string;
  569. }
  570. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  571. bufferView: number;
  572. byteOffset?: number;
  573. componentType: EComponentType;
  574. }
  575. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  576. bufferView: number;
  577. byteOffset?: number;
  578. }
  579. interface IGLTFAccessorSparse extends IGLTFProperty {
  580. count: number;
  581. indices: IGLTFAccessorSparseIndices;
  582. values: IGLTFAccessorSparseValues;
  583. }
  584. interface IGLTFAccessor extends IGLTFChildRootProperty {
  585. bufferView?: number;
  586. byteOffset?: number;
  587. componentType: EComponentType;
  588. normalized?: boolean;
  589. count: number;
  590. type: string;
  591. max: number[];
  592. min: number[];
  593. sparse?: IGLTFAccessorSparse;
  594. }
  595. interface IGLTFAnimationChannel extends IGLTFProperty {
  596. sampler: number;
  597. target: IGLTFAnimationChannelTarget;
  598. }
  599. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  600. node: number;
  601. path: string;
  602. }
  603. interface IGLTFAnimationSampler extends IGLTFProperty {
  604. input: number;
  605. interpolation?: string;
  606. output: number;
  607. }
  608. interface IGLTFAnimation extends IGLTFChildRootProperty {
  609. channels: IGLTFAnimationChannel[];
  610. samplers: IGLTFAnimationSampler[];
  611. targets?: any[];
  612. }
  613. interface IGLTFAsset extends IGLTFChildRootProperty {
  614. copyright?: string;
  615. generator?: string;
  616. version: string;
  617. minVersion?: string;
  618. }
  619. interface IGLTFBuffer extends IGLTFChildRootProperty {
  620. uri?: string;
  621. byteLength: number;
  622. loadedData: ArrayBufferView;
  623. loadedObservable: Observable<IGLTFBuffer>;
  624. }
  625. interface IGLTFBufferView extends IGLTFChildRootProperty {
  626. buffer: number;
  627. byteOffset?: number;
  628. byteLength: number;
  629. byteStride?: number;
  630. }
  631. interface IGLTFCameraOrthographic extends IGLTFProperty {
  632. xmag: number;
  633. ymag: number;
  634. zfar: number;
  635. znear: number;
  636. }
  637. interface IGLTFCameraPerspective extends IGLTFProperty {
  638. aspectRatio: number;
  639. yfov: number;
  640. zfar: number;
  641. znear: number;
  642. }
  643. interface IGLTFCamera extends IGLTFChildRootProperty {
  644. orthographic?: IGLTFCameraOrthographic;
  645. perspective?: IGLTFCameraPerspective;
  646. type: string;
  647. }
  648. interface IGLTFImage extends IGLTFChildRootProperty {
  649. uri?: string;
  650. mimeType?: string;
  651. bufferView?: number;
  652. }
  653. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  654. scale: number;
  655. }
  656. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  657. strength: number;
  658. }
  659. interface IGLTFMaterialPbrMetallicRoughness {
  660. baseColorFactor: number[];
  661. baseColorTexture: IGLTFTextureInfo;
  662. metallicFactor: number;
  663. roughnessFactor: number;
  664. metallicRoughnessTexture: IGLTFTextureInfo;
  665. }
  666. interface IGLTFMaterial extends IGLTFChildRootProperty {
  667. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  668. normalTexture?: IGLTFMaterialNormalTextureInfo;
  669. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  670. emissiveTexture?: IGLTFTextureInfo;
  671. emissiveFactor?: number[];
  672. alphaMode?: string;
  673. alphaCutoff: number;
  674. doubleSided?: boolean;
  675. index?: number;
  676. babylonMaterial?: Material;
  677. }
  678. interface IGLTFMeshPrimitive extends IGLTFProperty {
  679. attributes: {
  680. [name: string]: number;
  681. };
  682. indices?: number;
  683. material?: number;
  684. mode?: EMeshPrimitiveMode;
  685. targets?: [{
  686. [name: string]: number;
  687. }];
  688. }
  689. interface IGLTFMesh extends IGLTFChildRootProperty {
  690. primitives: IGLTFMeshPrimitive[];
  691. weights?: number[];
  692. }
  693. interface IGLTFNode extends IGLTFChildRootProperty {
  694. camera?: number;
  695. children?: number[];
  696. skin?: number;
  697. matrix?: number[];
  698. mesh?: number;
  699. rotation?: number[];
  700. scale?: number[];
  701. translation?: number[];
  702. weights?: number[];
  703. index?: number;
  704. parent?: IGLTFNode;
  705. babylonMesh?: Mesh;
  706. babylonSkinToBones?: {
  707. [skin: number]: Bone;
  708. };
  709. babylonAnimationTargets?: Node[];
  710. }
  711. interface IGLTFSampler extends IGLTFChildRootProperty {
  712. magFilter?: ETextureMagFilter;
  713. minFilter?: ETextureMinFilter;
  714. wrapS?: ETextureWrapMode;
  715. wrapT?: ETextureWrapMode;
  716. }
  717. interface IGLTFScene extends IGLTFChildRootProperty {
  718. nodes: number[];
  719. }
  720. interface IGLTFSkin extends IGLTFChildRootProperty {
  721. inverseBindMatrices?: number;
  722. skeleton?: number;
  723. joints: number[];
  724. index?: number;
  725. babylonSkeleton?: Skeleton;
  726. }
  727. interface IGLTFTexture extends IGLTFChildRootProperty {
  728. sampler?: number;
  729. source: number;
  730. babylonTextures?: Texture[];
  731. }
  732. interface IGLTFTextureInfo {
  733. index: number;
  734. texCoord?: number;
  735. }
  736. interface IGLTF extends IGLTFProperty {
  737. accessors?: IGLTFAccessor[];
  738. animations?: IGLTFAnimation[];
  739. asset: IGLTFAsset;
  740. buffers?: IGLTFBuffer[];
  741. bufferViews?: IGLTFBufferView[];
  742. cameras?: IGLTFCamera[];
  743. extensionsUsed?: string[];
  744. extensionsRequired?: string[];
  745. glExtensionsUsed?: string[];
  746. images?: IGLTFImage[];
  747. materials?: IGLTFMaterial[];
  748. meshes?: IGLTFMesh[];
  749. nodes?: IGLTFNode[];
  750. samplers?: IGLTFSampler[];
  751. scene?: number;
  752. scenes?: IGLTFScene[];
  753. skins?: IGLTFSkin[];
  754. textures?: IGLTFTexture[];
  755. }
  756. }
  757. declare module BABYLON.GLTF2 {
  758. class GLTFLoader implements IGLTFLoader, IDisposable {
  759. private _parent;
  760. private _gltf;
  761. private _babylonScene;
  762. private _rootUrl;
  763. private _defaultMaterial;
  764. private _successCallback;
  765. private _progressCallback;
  766. private _errorCallback;
  767. private _renderReady;
  768. private _disposed;
  769. private _objectURLs;
  770. private _renderReadyObservable;
  771. private _renderPendingCount;
  772. private _loaderPendingCount;
  773. static Extensions: {
  774. [name: string]: GLTFLoaderExtension;
  775. };
  776. static RegisterExtension(extension: GLTFLoaderExtension): void;
  777. readonly gltf: IGLTF;
  778. readonly babylonScene: Scene;
  779. executeWhenRenderReady(func: () => void): void;
  780. constructor(parent: GLTFFileLoader);
  781. dispose(): void;
  782. 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;
  783. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  784. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onProgress, onError);
  785. private _onError(message);
  786. private _onProgress(event);
  787. private _onRenderReady();
  788. private _onLoaderComplete();
  789. private _loadData(data);
  790. private _addRightHandToLeftHandRootTransform();
  791. private _getMeshes();
  792. private _getSkeletons();
  793. private _getAnimationTargets();
  794. private _showMeshes();
  795. private _startAnimations();
  796. private _loadScene(nodeNames);
  797. private _loadSkin(node);
  798. private _updateBone(node, parentNode, skin, inverseBindMatrixData);
  799. private _createBone(node, skin);
  800. private _loadMesh(node);
  801. private _loadMeshData(node, mesh, babylonMesh);
  802. private _loadVertexDataAsync(primitive, onSuccess);
  803. private _createMorphTargets(node, mesh, primitive, babylonMesh);
  804. private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
  805. private _loadTransform(node, babylonMesh);
  806. private _traverseNodes(indices, action, parentNode?);
  807. private _traverseNode(index, action, parentNode?);
  808. private _loadAnimations();
  809. private _loadAnimationChannel(animation, animationIndex, channelIndex);
  810. private _loadBufferAsync(index, onSuccess);
  811. private _loadBufferViewAsync(bufferView, byteOffset, byteLength, componentType, onSuccess);
  812. private _loadAccessorAsync(accessor, onSuccess);
  813. private _getByteStrideFromType(accessor);
  814. addPendingData(data: any): void;
  815. removePendingData(data: any): void;
  816. addLoaderPendingData(data: any): void;
  817. removeLoaderPendingData(data: any): void;
  818. private _getDefaultMaterial();
  819. private _loadMaterialMetallicRoughnessProperties(material);
  820. loadMaterial(material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): void;
  821. createPbrMaterial(material: IGLTFMaterial): void;
  822. loadMaterialBaseProperties(material: IGLTFMaterial): void;
  823. loadMaterialAlphaProperties(material: IGLTFMaterial, colorFactor?: number[]): void;
  824. loadTexture(textureInfo: IGLTFTextureInfo): Texture;
  825. }
  826. }
  827. declare module BABYLON.GLTF2 {
  828. /**
  829. * Utils functions for GLTF
  830. */
  831. class GLTFUtils {
  832. /**
  833. * If the uri is a base64 string
  834. * @param uri: the uri to test
  835. */
  836. static IsBase64(uri: string): boolean;
  837. /**
  838. * Decode the base64 uri
  839. * @param uri: the uri to decode
  840. */
  841. static DecodeBase64(uri: string): ArrayBuffer;
  842. static ForEach(view: Uint16Array | Uint32Array | Float32Array, func: (nvalue: number, index: number) => void): void;
  843. static GetTextureWrapMode(mode: ETextureWrapMode): number;
  844. static GetTextureSamplingMode(magFilter: ETextureMagFilter, minFilter: ETextureMinFilter): number;
  845. /**
  846. * Decodes a buffer view into a string
  847. * @param view: the buffer view
  848. */
  849. static DecodeBufferToText(view: ArrayBufferView): string;
  850. }
  851. }
  852. declare module BABYLON.GLTF2 {
  853. abstract class GLTFLoaderExtension {
  854. enabled: boolean;
  855. readonly abstract name: string;
  856. protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  857. static _Extensions: GLTFLoaderExtension[];
  858. static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  859. private static _ApplyExtensions(action);
  860. }
  861. }
  862. declare module BABYLON.GLTF2.Extensions {
  863. class MSFTLOD extends GLTFLoaderExtension {
  864. readonly name: string;
  865. protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  866. private loadMaterialLOD(loader, material, materialLODs, lod, assign);
  867. }
  868. }
  869. declare module BABYLON.GLTF2.Extensions {
  870. class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
  871. readonly name: string;
  872. protected loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  873. private _loadSpecularGlossinessProperties(loader, material, properties);
  874. }
  875. }