babylon.glTFFileLoader.d.ts 34 KB

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