babylon.glTFFileLoader.d.ts 34 KB

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