babylonjs.loaders.module.d.ts 41 KB

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