babylonjs.loaders.module.d.ts 40 KB

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