babylon.glTFFileLoader.d.ts 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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?: Object;
  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: Object;
  204. program: string;
  205. attributes: Object;
  206. uniforms: Object;
  207. states: IGLTFTechniqueStates;
  208. }
  209. interface IGLTFMaterial extends IGLTFChildRootProperty {
  210. technique?: string;
  211. values: string[];
  212. }
  213. interface IGLTFMeshPrimitive extends IGLTFProperty {
  214. attributes: Object;
  215. indices: string;
  216. material: string;
  217. mode?: number;
  218. }
  219. interface IGLTFMesh extends IGLTFChildRootProperty {
  220. primitives: IGLTFMeshPrimitive[];
  221. }
  222. interface IGLTFImage extends IGLTFChildRootProperty {
  223. uri: string;
  224. }
  225. interface IGLTFSampler extends IGLTFChildRootProperty {
  226. magFilter?: number;
  227. minFilter?: number;
  228. wrapS?: number;
  229. wrapT?: number;
  230. }
  231. interface IGLTFTexture extends IGLTFChildRootProperty {
  232. sampler: string;
  233. source: string;
  234. format?: ETextureFormat;
  235. internalFormat?: ETextureFormat;
  236. target?: number;
  237. type?: number;
  238. babylonTexture?: Texture;
  239. }
  240. interface IGLTFAmbienLight {
  241. color?: number[];
  242. }
  243. interface IGLTFDirectionalLight {
  244. color?: number[];
  245. }
  246. interface IGLTFPointLight {
  247. color?: number[];
  248. constantAttenuation?: number;
  249. linearAttenuation?: number;
  250. quadraticAttenuation?: number;
  251. }
  252. interface IGLTFSpotLight {
  253. color?: number[];
  254. constantAttenuation?: number;
  255. fallOfAngle?: number;
  256. fallOffExponent?: number;
  257. linearAttenuation?: number;
  258. quadraticAttenuation?: number;
  259. }
  260. interface IGLTFLight extends IGLTFChildRootProperty {
  261. type: string;
  262. }
  263. interface IGLTFCameraOrthographic {
  264. xmag: number;
  265. ymag: number;
  266. zfar: number;
  267. znear: number;
  268. }
  269. interface IGLTFCameraPerspective {
  270. aspectRatio: number;
  271. yfov: number;
  272. zfar: number;
  273. znear: number;
  274. }
  275. interface IGLTFCamera extends IGLTFChildRootProperty {
  276. type: string;
  277. }
  278. interface IGLTFAnimationChannelTarget {
  279. id: string;
  280. path: string;
  281. }
  282. interface IGLTFAnimationChannel {
  283. sampler: string;
  284. target: IGLTFAnimationChannelTarget;
  285. }
  286. interface IGLTFAnimationSampler {
  287. input: string;
  288. output: string;
  289. interpolation?: string;
  290. }
  291. interface IGLTFAnimation extends IGLTFChildRootProperty {
  292. channels?: IGLTFAnimationChannel[];
  293. parameters?: Object;
  294. samplers?: Object;
  295. }
  296. interface IGLTFNodeInstanceSkin {
  297. skeletons: string[];
  298. skin: string;
  299. meshes: string[];
  300. }
  301. interface IGLTFSkins extends IGLTFChildRootProperty {
  302. bindShapeMatrix: number[];
  303. inverseBindMatrices: string;
  304. jointNames: string[];
  305. babylonSkeleton?: Skeleton;
  306. }
  307. interface IGLTFNode extends IGLTFChildRootProperty {
  308. camera?: string;
  309. children: string[];
  310. skin?: string;
  311. jointName?: string;
  312. light?: string;
  313. matrix: number[];
  314. mesh?: string;
  315. meshes?: string[];
  316. rotation?: number[];
  317. scale?: number[];
  318. translation?: number[];
  319. babylonNode?: Node;
  320. }
  321. interface IGLTFScene extends IGLTFChildRootProperty {
  322. nodes: string[];
  323. }
  324. /**
  325. * Runtime
  326. */
  327. interface IGLTFRuntime {
  328. extensions: Object;
  329. accessors: Object;
  330. buffers: Object;
  331. bufferViews: Object;
  332. meshes: Object;
  333. lights: Object;
  334. cameras: Object;
  335. nodes: Object;
  336. images: Object;
  337. textures: Object;
  338. shaders: Object;
  339. programs: Object;
  340. samplers: Object;
  341. techniques: Object;
  342. materials: Object;
  343. animations: Object;
  344. skins: Object;
  345. currentScene?: Object;
  346. scenes: Object;
  347. extensionsUsed: string[];
  348. extensionsRequired?: string[];
  349. buffersCount: number;
  350. shaderscount: number;
  351. scene: Scene;
  352. rootUrl: string;
  353. loadedBufferCount: number;
  354. loadedBufferViews: {
  355. [name: string]: ArrayBufferView;
  356. };
  357. loadedShaderCount: number;
  358. importOnlyMeshes: boolean;
  359. importMeshesNames?: string[];
  360. dummyNodes: Node[];
  361. }
  362. /**
  363. * Bones
  364. */
  365. interface INodeToRoot {
  366. bone: Bone;
  367. node: IGLTFNode;
  368. id: string;
  369. }
  370. interface IJointNode {
  371. node: IGLTFNode;
  372. id: string;
  373. }
  374. }
  375. declare module BABYLON.GLTF1 {
  376. /**
  377. * Implementation of the base glTF spec
  378. */
  379. class GLTFLoaderBase {
  380. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  381. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  382. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): void;
  383. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  384. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): void;
  385. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  386. }
  387. /**
  388. * glTF V1 Loader
  389. */
  390. class GLTFLoader implements IGLTFLoader {
  391. static Extensions: {
  392. [name: string]: GLTFLoaderExtension;
  393. };
  394. static RegisterExtension(extension: GLTFLoaderExtension): void;
  395. 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;
  396. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  397. private _loadShadersAsync(gltfRuntime, onload);
  398. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  399. private _createNodes(gltfRuntime);
  400. }
  401. }
  402. declare module BABYLON.GLTF1 {
  403. /**
  404. * Utils functions for GLTF
  405. */
  406. class GLTFUtils {
  407. /**
  408. * Sets the given "parameter" matrix
  409. * @param scene: the {BABYLON.Scene} object
  410. * @param source: the source node where to pick the matrix
  411. * @param parameter: the GLTF technique parameter
  412. * @param uniformName: the name of the shader's uniform
  413. * @param shaderMaterial: the shader material
  414. */
  415. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  416. /**
  417. * Sets the given "parameter" matrix
  418. * @param shaderMaterial: the shader material
  419. * @param uniform: the name of the shader's uniform
  420. * @param value: the value of the uniform
  421. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  422. */
  423. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  424. /**
  425. * If the uri is a base64 string
  426. * @param uri: the uri to test
  427. */
  428. static IsBase64(uri: string): boolean;
  429. /**
  430. * Decode the base64 uri
  431. * @param uri: the uri to decode
  432. */
  433. static DecodeBase64(uri: string): ArrayBuffer;
  434. /**
  435. * Returns the wrap mode of the texture
  436. * @param mode: the mode value
  437. */
  438. static GetWrapMode(mode: number): number;
  439. /**
  440. * Returns the byte stride giving an accessor
  441. * @param accessor: the GLTF accessor objet
  442. */
  443. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  444. /**
  445. * Returns the texture filter mode giving a mode value
  446. * @param mode: the filter mode value
  447. */
  448. static GetTextureFilterMode(mode: number): ETextureFilterType;
  449. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  450. /**
  451. * Returns a buffer from its accessor
  452. * @param gltfRuntime: the GLTF runtime
  453. * @param accessor: the GLTF accessor
  454. */
  455. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  456. /**
  457. * Decodes a buffer view into a string
  458. * @param view: the buffer view
  459. */
  460. static DecodeBufferToText(view: ArrayBufferView): string;
  461. /**
  462. * Returns the default material of gltf. Related to
  463. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  464. * @param scene: the Babylon.js scene
  465. */
  466. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  467. private static _DefaultMaterial;
  468. }
  469. }
  470. declare module BABYLON.GLTF1 {
  471. abstract class GLTFLoaderExtension {
  472. private _name;
  473. constructor(name: string);
  474. readonly name: string;
  475. /**
  476. * Defines an override for loading the runtime
  477. * Return true to stop further extensions from loading the runtime
  478. */
  479. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  480. /**
  481. * Defines an onverride for creating gltf runtime
  482. * Return true to stop further extensions from creating the runtime
  483. */
  484. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  485. /**
  486. * Defines an override for loading buffers
  487. * Return true to stop further extensions from loading this buffer
  488. */
  489. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  490. /**
  491. * Defines an override for loading texture buffers
  492. * Return true to stop further extensions from loading this texture data
  493. */
  494. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  495. /**
  496. * Defines an override for creating textures
  497. * Return true to stop further extensions from loading this texture
  498. */
  499. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  500. /**
  501. * Defines an override for loading shader strings
  502. * Return true to stop further extensions from loading this shader data
  503. */
  504. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  505. /**
  506. * Defines an override for loading materials
  507. * Return true to stop further extensions from loading this material
  508. */
  509. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  510. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): void;
  511. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): void;
  512. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  513. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  514. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: (message: string) => void): void;
  515. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  516. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  517. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  518. private static ApplyExtensions(func, defaultFunc);
  519. }
  520. }
  521. declare module BABYLON.GLTF1 {
  522. class GLTFBinaryExtension extends GLTFLoaderExtension {
  523. private _bin;
  524. constructor();
  525. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  526. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  527. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  528. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  529. }
  530. }
  531. declare module BABYLON.GLTF1 {
  532. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  533. constructor();
  534. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  535. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  536. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  537. }
  538. }
  539. declare module BABYLON.GLTF2 {
  540. /**
  541. * Enums
  542. */
  543. enum EComponentType {
  544. BYTE = 5120,
  545. UNSIGNED_BYTE = 5121,
  546. SHORT = 5122,
  547. UNSIGNED_SHORT = 5123,
  548. UNSIGNED_INT = 5125,
  549. FLOAT = 5126,
  550. }
  551. enum EMeshPrimitiveMode {
  552. POINTS = 0,
  553. LINES = 1,
  554. LINE_LOOP = 2,
  555. LINE_STRIP = 3,
  556. TRIANGLES = 4,
  557. TRIANGLE_STRIP = 5,
  558. TRIANGLE_FAN = 6,
  559. }
  560. enum ETextureMagFilter {
  561. NEAREST = 9728,
  562. LINEAR = 9729,
  563. }
  564. enum ETextureMinFilter {
  565. NEAREST = 9728,
  566. LINEAR = 9729,
  567. NEAREST_MIPMAP_NEAREST = 9984,
  568. LINEAR_MIPMAP_NEAREST = 9985,
  569. NEAREST_MIPMAP_LINEAR = 9986,
  570. LINEAR_MIPMAP_LINEAR = 9987,
  571. }
  572. enum ETextureWrapMode {
  573. CLAMP_TO_EDGE = 33071,
  574. MIRRORED_REPEAT = 33648,
  575. REPEAT = 10497,
  576. }
  577. /**
  578. * Interfaces
  579. */
  580. interface IGLTFProperty {
  581. extensions?: Object;
  582. extras?: any;
  583. }
  584. interface IGLTFChildRootProperty extends IGLTFProperty {
  585. name?: string;
  586. }
  587. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  588. bufferView: number;
  589. byteOffset?: number;
  590. componentType: EComponentType;
  591. }
  592. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  593. bufferView: number;
  594. byteOffset?: number;
  595. }
  596. interface IGLTFAccessorSparse extends IGLTFProperty {
  597. count: number;
  598. indices: IGLTFAccessorSparseIndices;
  599. values: IGLTFAccessorSparseValues;
  600. }
  601. interface IGLTFAccessor extends IGLTFChildRootProperty {
  602. bufferView?: number;
  603. byteOffset?: number;
  604. componentType: EComponentType;
  605. normalized?: boolean;
  606. count: number;
  607. type: string;
  608. max: number[];
  609. min: number[];
  610. sparse?: IGLTFAccessorSparse;
  611. index?: number;
  612. }
  613. interface IGLTFAnimationChannel extends IGLTFProperty {
  614. sampler: number;
  615. target: IGLTFAnimationChannelTarget;
  616. }
  617. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  618. node: number;
  619. path: string;
  620. }
  621. interface IGLTFAnimationSampler extends IGLTFProperty {
  622. input: number;
  623. interpolation?: string;
  624. output: number;
  625. }
  626. interface IGLTFAnimation extends IGLTFChildRootProperty {
  627. channels: IGLTFAnimationChannel[];
  628. samplers: IGLTFAnimationSampler[];
  629. index?: number;
  630. targets?: any[];
  631. }
  632. interface IGLTFAsset extends IGLTFChildRootProperty {
  633. copyright?: string;
  634. generator?: string;
  635. version: string;
  636. minVersion?: string;
  637. }
  638. interface IGLTFBuffer extends IGLTFChildRootProperty {
  639. uri?: string;
  640. byteLength: number;
  641. index?: number;
  642. loadedData?: ArrayBufferView;
  643. loadedObservable?: Observable<IGLTFBuffer>;
  644. }
  645. interface IGLTFBufferView extends IGLTFChildRootProperty {
  646. buffer: number;
  647. byteOffset?: number;
  648. byteLength: number;
  649. byteStride?: number;
  650. index?: number;
  651. }
  652. interface IGLTFCameraOrthographic extends IGLTFProperty {
  653. xmag: number;
  654. ymag: number;
  655. zfar: number;
  656. znear: number;
  657. }
  658. interface IGLTFCameraPerspective extends IGLTFProperty {
  659. aspectRatio: number;
  660. yfov: number;
  661. zfar: number;
  662. znear: number;
  663. }
  664. interface IGLTFCamera extends IGLTFChildRootProperty {
  665. orthographic?: IGLTFCameraOrthographic;
  666. perspective?: IGLTFCameraPerspective;
  667. type: string;
  668. }
  669. interface IGLTFImage extends IGLTFChildRootProperty {
  670. uri?: string;
  671. mimeType?: string;
  672. bufferView?: number;
  673. index?: number;
  674. }
  675. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  676. scale: number;
  677. }
  678. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  679. strength: number;
  680. }
  681. interface IGLTFMaterialPbrMetallicRoughness {
  682. baseColorFactor: number[];
  683. baseColorTexture: IGLTFTextureInfo;
  684. metallicFactor: number;
  685. roughnessFactor: number;
  686. metallicRoughnessTexture: IGLTFTextureInfo;
  687. }
  688. interface IGLTFMaterial extends IGLTFChildRootProperty {
  689. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  690. normalTexture?: IGLTFMaterialNormalTextureInfo;
  691. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  692. emissiveTexture?: IGLTFTextureInfo;
  693. emissiveFactor?: number[];
  694. alphaMode?: string;
  695. alphaCutoff: number;
  696. doubleSided?: boolean;
  697. index?: number;
  698. babylonMaterial?: Material;
  699. }
  700. interface IGLTFMeshPrimitive extends IGLTFProperty {
  701. attributes: {
  702. [name: string]: number;
  703. };
  704. indices?: number;
  705. material?: number;
  706. mode?: EMeshPrimitiveMode;
  707. targets?: {
  708. [name: string]: number;
  709. }[];
  710. }
  711. interface IGLTFMesh extends IGLTFChildRootProperty {
  712. primitives: IGLTFMeshPrimitive[];
  713. weights?: number[];
  714. index?: number;
  715. }
  716. interface IGLTFNode extends IGLTFChildRootProperty {
  717. camera?: number;
  718. children?: number[];
  719. skin?: number;
  720. matrix?: number[];
  721. mesh?: number;
  722. rotation?: number[];
  723. scale?: number[];
  724. translation?: number[];
  725. weights?: number[];
  726. index?: number;
  727. parent?: IGLTFNode;
  728. babylonMesh?: Mesh;
  729. babylonBones?: {
  730. [skin: number]: Bone;
  731. };
  732. babylonAnimationTargets?: Node[];
  733. }
  734. interface IGLTFSampler extends IGLTFChildRootProperty {
  735. magFilter?: ETextureMagFilter;
  736. minFilter?: ETextureMinFilter;
  737. wrapS?: ETextureWrapMode;
  738. wrapT?: ETextureWrapMode;
  739. }
  740. interface IGLTFScene extends IGLTFChildRootProperty {
  741. nodes: number[];
  742. index?: number;
  743. }
  744. interface IGLTFSkin extends IGLTFChildRootProperty {
  745. inverseBindMatrices?: number;
  746. skeleton?: number;
  747. joints: number[];
  748. index?: number;
  749. babylonSkeleton?: Skeleton;
  750. }
  751. interface IGLTFTexture extends IGLTFChildRootProperty {
  752. sampler?: number;
  753. source: number;
  754. index?: number;
  755. url?: string;
  756. dataReadyObservable?: Observable<IGLTFTexture>;
  757. }
  758. interface IGLTFTextureInfo {
  759. index: number;
  760. texCoord?: number;
  761. }
  762. interface IGLTF extends IGLTFProperty {
  763. accessors?: IGLTFAccessor[];
  764. animations?: IGLTFAnimation[];
  765. asset: IGLTFAsset;
  766. buffers?: IGLTFBuffer[];
  767. bufferViews?: IGLTFBufferView[];
  768. cameras?: IGLTFCamera[];
  769. extensionsUsed?: string[];
  770. extensionsRequired?: string[];
  771. images?: IGLTFImage[];
  772. materials?: IGLTFMaterial[];
  773. meshes?: IGLTFMesh[];
  774. nodes?: IGLTFNode[];
  775. samplers?: IGLTFSampler[];
  776. scene?: number;
  777. scenes?: IGLTFScene[];
  778. skins?: IGLTFSkin[];
  779. textures?: IGLTFTexture[];
  780. }
  781. }
  782. declare module BABYLON.GLTF2 {
  783. class GLTFLoader implements IGLTFLoader, IDisposable {
  784. _gltf: IGLTF;
  785. _babylonScene: Scene;
  786. private _parent;
  787. private _rootUrl;
  788. private _defaultMaterial;
  789. private _rootNode;
  790. private _successCallback;
  791. private _progressCallback;
  792. private _errorCallback;
  793. private _renderReady;
  794. private _disposed;
  795. private _renderReadyObservable;
  796. private _renderPendingCount;
  797. private _loaderPendingCount;
  798. private _loaderTrackers;
  799. static Extensions: {
  800. [name: string]: GLTFLoaderExtension;
  801. };
  802. static RegisterExtension(extension: GLTFLoaderExtension): void;
  803. constructor(parent: GLTFFileLoader);
  804. dispose(): void;
  805. 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;
  806. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  807. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onProgress, onError);
  808. private _onError(message);
  809. private _onProgress(event);
  810. _executeWhenRenderReady(func: () => void): void;
  811. private _onRenderReady();
  812. private _onComplete();
  813. private _loadData(data);
  814. private _getMeshes();
  815. private _getSkeletons();
  816. private _getAnimationTargets();
  817. private _startAnimations();
  818. private _loadDefaultScene(nodeNames);
  819. private _loadScene(context, scene, nodeNames);
  820. _loadNode(context: string, node: IGLTFNode): void;
  821. private _loadMesh(context, node, mesh);
  822. private _loadPrimitive(context, node, mesh, primitive, onSuccess);
  823. private _loadVertexDataAsync(context, mesh, primitive, onSuccess);
  824. private _createMorphTargets(node, mesh, primitive);
  825. private _loadMorphTargetsData(context, mesh, primitive, vertexData, babylonMesh);
  826. private _loadTransform(node);
  827. private _loadSkin(context, skin);
  828. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  829. private _loadBones(context, skin, inverseBindMatrixData);
  830. private _loadBone(node, skin, inverseBindMatrixData, babylonBones);
  831. private _getNodeMatrix(node);
  832. private _traverseNodes(context, indices, action, parentNode?);
  833. _traverseNode(context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode?: IGLTFNode): void;
  834. private _loadAnimations();
  835. private _loadAnimationChannel(animation, channelContext, channel, samplerContext, sampler);
  836. private _loadBufferAsync(context, buffer, onSuccess);
  837. private _loadBufferViewAsync(context, bufferView, onSuccess);
  838. private _loadAccessorAsync(context, accessor, onSuccess);
  839. private _getNumComponentsOfType(type);
  840. private _buildArrayBuffer<T>(typedArray, context, data, byteOffset, count, numComponents, byteStride);
  841. _addPendingData(data: any): void;
  842. _removePendingData(data: any): void;
  843. _addLoaderPendingData(data: any): void;
  844. _removeLoaderPendingData(data: any): void;
  845. _whenAction(action: () => void, onComplete: () => void): void;
  846. private _getDefaultMaterial();
  847. private _loadMaterialMetallicRoughnessProperties(context, material);
  848. _loadMaterial(context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): void;
  849. _createPbrMaterial(material: IGLTFMaterial): void;
  850. _loadMaterialBaseProperties(context: string, material: IGLTFMaterial): void;
  851. _loadMaterialAlphaProperties(context: string, material: IGLTFMaterial, colorFactor: number[]): void;
  852. _loadTexture(context: string, texture: IGLTFTexture, coordinatesIndex: number): Texture;
  853. private _loadImage(context, image, onSuccess);
  854. _tryCatchOnError(handler: () => void): void;
  855. }
  856. }
  857. declare module BABYLON.GLTF2 {
  858. /**
  859. * Utils functions for GLTF
  860. */
  861. class GLTFUtils {
  862. /**
  863. * If the uri is a base64 string
  864. * @param uri: the uri to test
  865. */
  866. static IsBase64(uri: string): boolean;
  867. /**
  868. * Decode the base64 uri
  869. * @param uri: the uri to decode
  870. */
  871. static DecodeBase64(uri: string): ArrayBuffer;
  872. static ForEach(view: Uint16Array | Uint32Array | Float32Array, func: (nvalue: number, index: number) => void): void;
  873. static ValidateUri(uri: string): boolean;
  874. static AssignIndices(array: Array<{
  875. index?: number;
  876. }>): void;
  877. static GetArrayItem<T>(array: ArrayLike<T>, index: number): T;
  878. static GetTextureWrapMode(mode: ETextureWrapMode): number;
  879. static GetTextureSamplingMode(magFilter: ETextureMagFilter, minFilter: ETextureMinFilter): number;
  880. /**
  881. * Decodes a buffer view into a string
  882. * @param view: the buffer view
  883. */
  884. static DecodeBufferToText(view: ArrayBufferView): string;
  885. }
  886. }
  887. declare module BABYLON.GLTF2 {
  888. abstract class GLTFLoaderExtension {
  889. enabled: boolean;
  890. readonly abstract name: string;
  891. protected _traverseNode(loader: GLTFLoader, context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  892. protected _loadNode(loader: GLTFLoader, context: string, node: IGLTFNode): boolean;
  893. protected _loadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  894. protected _loadExtension<T>(property: IGLTFProperty, action: (extension: T, onComplete: () => void) => void): boolean;
  895. static _Extensions: GLTFLoaderExtension[];
  896. static TraverseNode(loader: GLTFLoader, context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  897. static LoadNode(loader: GLTFLoader, context: string, node: IGLTFNode): boolean;
  898. static LoadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  899. private static _ApplyExtensions(action);
  900. }
  901. }
  902. declare module BABYLON.GLTF2.Extensions {
  903. class MSFTLOD extends GLTFLoaderExtension {
  904. /**
  905. * Specify the minimal delay between LODs in ms (default = 250)
  906. */
  907. static MinimalLODDelay: number;
  908. readonly name: string;
  909. protected _traverseNode(loader: GLTFLoader, context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  910. protected _loadNode(loader: GLTFLoader, context: string, node: IGLTFNode): boolean;
  911. private _loadNodeLOD(loader, context, nodes, index, onComplete);
  912. protected _loadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  913. private _loadMaterialLOD(loader, context, materials, index, assign, onComplete);
  914. }
  915. }
  916. declare module BABYLON.GLTF2.Extensions {
  917. class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
  918. readonly name: string;
  919. protected _loadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  920. private _loadSpecularGlossinessProperties(loader, context, material, properties);
  921. }
  922. }