babylonjs.loaders.module.d.ts 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<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, onError);
  135. private _getLoader(loaderData, onError);
  136. private static _parseBinary(data, onError);
  137. private static _parseV1(binaryReader, onError);
  138. private static _parseV2(binaryReader, onError);
  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: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<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: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<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 _loadAllVertexDataAsync(context, mesh, onSuccess);
  968. private _loadVertexDataAsync(context, mesh, primitive, onSuccess);
  969. private _createMorphTargets(context, node, mesh);
  970. private _loadMorphTargets(context, node, mesh);
  971. private _loadAllMorphTargetVertexDataAsync(context, node, mesh, onSuccess);
  972. private _loadMorphTargetVertexDataAsync(context, vertexData, attributes, onSuccess);
  973. private _loadTransform(node);
  974. private _loadSkin(context, skin);
  975. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  976. private _loadBones(context, skin, inverseBindMatrixData);
  977. private _loadBone(node, skin, inverseBindMatrixData, babylonBones);
  978. private _getNodeMatrix(node);
  979. private _traverseNodes(context, indices, action, parentNode?);
  980. _traverseNode(context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: Nullable<IGLTFNode>) => boolean, parentNode?: Nullable<IGLTFNode>): void;
  981. private _loadAnimations();
  982. private _loadAnimationChannel(animation, channelContext, channel, samplerContext, sampler);
  983. private _loadBufferAsync(context, buffer, onSuccess);
  984. private _loadBufferViewAsync(context, bufferView, onSuccess);
  985. private _loadAccessorAsync(context, accessor, onSuccess);
  986. private _getNumComponentsOfType(type);
  987. private _buildArrayBuffer<T>(typedArray, data, byteOffset, count, numComponents, byteStride);
  988. _addPendingData(data: any): void;
  989. _removePendingData(data: any): void;
  990. _addLoaderPendingData(data: any): void;
  991. _removeLoaderPendingData(data: any): void;
  992. _whenAction(action: () => void, onComplete: () => void): void;
  993. private _getDefaultMaterial();
  994. private _loadMaterialMetallicRoughnessProperties(context, material);
  995. _loadMaterial(context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): void;
  996. _createPbrMaterial(material: IGLTFMaterial): void;
  997. _loadMaterialBaseProperties(context: string, material: IGLTFMaterial): void;
  998. _loadMaterialAlphaProperties(context: string, material: IGLTFMaterial, colorFactor: number[]): void;
  999. _loadTexture(context: string, texture: IGLTFTexture, coordinatesIndex: number): Texture;
  1000. private _loadImage(context, image, onSuccess);
  1001. _loadUri(context: string, uri: string, onSuccess: (data: ArrayBufferView) => void): void;
  1002. _tryCatchOnError(handler: () => void): void;
  1003. }
  1004. }
  1005. declare module BABYLON.GLTF2 {
  1006. /**
  1007. * Utils functions for GLTF
  1008. */
  1009. class GLTFUtils {
  1010. /**
  1011. * If the uri is a base64 string
  1012. * @param uri: the uri to test
  1013. */
  1014. static IsBase64(uri: string): boolean;
  1015. /**
  1016. * Decode the base64 uri
  1017. * @param uri: the uri to decode
  1018. */
  1019. static DecodeBase64(uri: string): ArrayBuffer;
  1020. static ValidateUri(uri: string): boolean;
  1021. static AssignIndices(array?: Array<{
  1022. index?: number;
  1023. }>): void;
  1024. static GetArrayItem<T>(array: Nullable<ArrayLike<T>> | undefined, index: number): Nullable<T>;
  1025. static GetTextureWrapMode(mode: ETextureWrapMode): number;
  1026. static GetTextureSamplingMode(magFilter?: ETextureMagFilter, minFilter?: ETextureMinFilter): number;
  1027. }
  1028. }
  1029. declare module BABYLON.GLTF2 {
  1030. abstract class GLTFLoaderExtension {
  1031. enabled: boolean;
  1032. readonly abstract name: string;
  1033. protected _traverseNode(loader: GLTFLoader, context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: Nullable<IGLTFNode>): boolean;
  1034. protected _loadNode(loader: GLTFLoader, context: string, node: IGLTFNode): boolean;
  1035. protected _loadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  1036. protected _loadExtension<T>(property: IGLTFProperty, action: (extension: T, onComplete: () => void) => void): boolean;
  1037. static _Extensions: GLTFLoaderExtension[];
  1038. static TraverseNode(loader: GLTFLoader, context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: Nullable<IGLTFNode>): boolean;
  1039. static LoadNode(loader: GLTFLoader, context: string, node: IGLTFNode): boolean;
  1040. static LoadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  1041. private static _ApplyExtensions(action);
  1042. }
  1043. }
  1044. declare module BABYLON.GLTF2.Extensions {
  1045. class MSFTLOD extends GLTFLoaderExtension {
  1046. /**
  1047. * Specify the minimal delay between LODs in ms (default = 250)
  1048. */
  1049. static MinimalLODDelay: number;
  1050. readonly name: string;
  1051. protected _traverseNode(loader: GLTFLoader, context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  1052. protected _loadNode(loader: GLTFLoader, context: string, node: IGLTFNode): boolean;
  1053. private _loadNodeLOD(loader, context, nodes, index, onComplete);
  1054. protected _loadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  1055. private _loadMaterialLOD(loader, context, materials, index, assign, onComplete);
  1056. }
  1057. }
  1058. declare module BABYLON.GLTF2.Extensions {
  1059. class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
  1060. readonly name: string;
  1061. protected _loadMaterial(loader: GLTFLoader, context: string, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  1062. private _loadSpecularGlossinessProperties(loader, context, material, properties);
  1063. }
  1064. }