babylon.glTFFileLoader.d.ts 37 KB

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