babylon.glTFFileLoader.d.ts 37 KB

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