babylon.glTFFileLoader.d.ts 37 KB

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