babylonjs.loaders.module.d.ts 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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(view);
  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?: Object;
  233. extras?: Object;
  234. }
  235. interface IGLTFChildRootProperty extends IGLTFProperty {
  236. name?: string;
  237. }
  238. interface IGLTFAccessor extends IGLTFChildRootProperty {
  239. bufferView: string;
  240. byteOffset: number;
  241. byteStride: number;
  242. count: number;
  243. type: string;
  244. componentType: EComponentType;
  245. max?: number[];
  246. min?: number[];
  247. name?: string;
  248. }
  249. interface IGLTFBufferView extends IGLTFChildRootProperty {
  250. buffer: string;
  251. byteOffset: number;
  252. byteLength: number;
  253. byteStride: number;
  254. target?: number;
  255. }
  256. interface IGLTFBuffer extends IGLTFChildRootProperty {
  257. uri: string;
  258. byteLength?: number;
  259. type?: string;
  260. }
  261. interface IGLTFShader extends IGLTFChildRootProperty {
  262. uri: string;
  263. type: EShaderType;
  264. }
  265. interface IGLTFProgram extends IGLTFChildRootProperty {
  266. attributes: string[];
  267. fragmentShader: string;
  268. vertexShader: string;
  269. }
  270. interface IGLTFTechniqueParameter {
  271. type: number;
  272. count?: number;
  273. semantic?: string;
  274. node?: string;
  275. value?: number | boolean | string | Array<any>;
  276. source?: string;
  277. babylonValue?: any;
  278. }
  279. interface IGLTFTechniqueCommonProfile {
  280. lightingModel: string;
  281. texcoordBindings: Object;
  282. parameters?: Array<any>;
  283. }
  284. interface IGLTFTechniqueStatesFunctions {
  285. blendColor?: number[];
  286. blendEquationSeparate?: number[];
  287. blendFuncSeparate?: number[];
  288. colorMask: boolean[];
  289. cullFace: number[];
  290. }
  291. interface IGLTFTechniqueStates {
  292. enable: number[];
  293. functions: IGLTFTechniqueStatesFunctions;
  294. }
  295. interface IGLTFTechnique extends IGLTFChildRootProperty {
  296. parameters: Object;
  297. program: string;
  298. attributes: Object;
  299. uniforms: Object;
  300. states: IGLTFTechniqueStates;
  301. }
  302. interface IGLTFMaterial extends IGLTFChildRootProperty {
  303. technique?: string;
  304. values: string[];
  305. }
  306. interface IGLTFMeshPrimitive extends IGLTFProperty {
  307. attributes: Object;
  308. indices: string;
  309. material: string;
  310. mode?: number;
  311. }
  312. interface IGLTFMesh extends IGLTFChildRootProperty {
  313. primitives: IGLTFMeshPrimitive[];
  314. }
  315. interface IGLTFImage extends IGLTFChildRootProperty {
  316. uri: string;
  317. }
  318. interface IGLTFSampler extends IGLTFChildRootProperty {
  319. magFilter?: number;
  320. minFilter?: number;
  321. wrapS?: number;
  322. wrapT?: number;
  323. }
  324. interface IGLTFTexture extends IGLTFChildRootProperty {
  325. sampler: string;
  326. source: string;
  327. format?: ETextureFormat;
  328. internalFormat?: ETextureFormat;
  329. target?: number;
  330. type?: number;
  331. babylonTexture?: Texture;
  332. }
  333. interface IGLTFAmbienLight {
  334. color?: number[];
  335. }
  336. interface IGLTFDirectionalLight {
  337. color?: number[];
  338. }
  339. interface IGLTFPointLight {
  340. color?: number[];
  341. constantAttenuation?: number;
  342. linearAttenuation?: number;
  343. quadraticAttenuation?: number;
  344. }
  345. interface IGLTFSpotLight {
  346. color?: number[];
  347. constantAttenuation?: number;
  348. fallOfAngle?: number;
  349. fallOffExponent?: number;
  350. linearAttenuation?: number;
  351. quadraticAttenuation?: number;
  352. }
  353. interface IGLTFLight extends IGLTFChildRootProperty {
  354. type: string;
  355. }
  356. interface IGLTFCameraOrthographic {
  357. xmag: number;
  358. ymag: number;
  359. zfar: number;
  360. znear: number;
  361. }
  362. interface IGLTFCameraPerspective {
  363. aspectRatio: number;
  364. yfov: number;
  365. zfar: number;
  366. znear: number;
  367. }
  368. interface IGLTFCamera extends IGLTFChildRootProperty {
  369. type: string;
  370. }
  371. interface IGLTFAnimationChannelTarget {
  372. id: string;
  373. path: string;
  374. }
  375. interface IGLTFAnimationChannel {
  376. sampler: string;
  377. target: IGLTFAnimationChannelTarget;
  378. }
  379. interface IGLTFAnimationSampler {
  380. input: string;
  381. output: string;
  382. interpolation?: string;
  383. }
  384. interface IGLTFAnimation extends IGLTFChildRootProperty {
  385. channels?: IGLTFAnimationChannel[];
  386. parameters?: Object;
  387. samplers?: Object;
  388. }
  389. interface IGLTFNodeInstanceSkin {
  390. skeletons: string[];
  391. skin: string;
  392. meshes: string[];
  393. }
  394. interface IGLTFSkins extends IGLTFChildRootProperty {
  395. bindShapeMatrix: number[];
  396. inverseBindMatrices: string;
  397. jointNames: string[];
  398. babylonSkeleton?: Skeleton;
  399. }
  400. interface IGLTFNode extends IGLTFChildRootProperty {
  401. camera?: string;
  402. children: string[];
  403. skin?: string;
  404. jointName?: string;
  405. light?: string;
  406. matrix: number[];
  407. mesh?: string;
  408. meshes?: string[];
  409. rotation?: number[];
  410. scale?: number[];
  411. translation?: number[];
  412. babylonNode?: Node;
  413. }
  414. interface IGLTFScene extends IGLTFChildRootProperty {
  415. nodes: string[];
  416. }
  417. /**
  418. * Runtime
  419. */
  420. interface IGLTFRuntime {
  421. extensions: Object;
  422. accessors: Object;
  423. buffers: Object;
  424. bufferViews: Object;
  425. meshes: Object;
  426. lights: Object;
  427. cameras: Object;
  428. nodes: Object;
  429. images: Object;
  430. textures: Object;
  431. shaders: Object;
  432. programs: Object;
  433. samplers: Object;
  434. techniques: Object;
  435. materials: Object;
  436. animations: Object;
  437. skins: Object;
  438. currentScene?: Object;
  439. scenes: Object;
  440. extensionsUsed: string[];
  441. extensionsRequired?: string[];
  442. buffersCount: number;
  443. shaderscount: number;
  444. scene: Scene;
  445. rootUrl: string;
  446. loadedBufferCount: number;
  447. loadedBufferViews: {
  448. [name: string]: ArrayBufferView;
  449. };
  450. loadedShaderCount: number;
  451. importOnlyMeshes: boolean;
  452. importMeshesNames?: string[];
  453. dummyNodes: Node[];
  454. }
  455. /**
  456. * Bones
  457. */
  458. interface INodeToRoot {
  459. bone: Bone;
  460. node: IGLTFNode;
  461. id: string;
  462. }
  463. interface IJointNode {
  464. node: IGLTFNode;
  465. id: string;
  466. }
  467. }
  468. declare module BABYLON.GLTF1 {
  469. /**
  470. * Implementation of the base glTF spec
  471. */
  472. class GLTFLoaderBase {
  473. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  474. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  475. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): void;
  476. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  477. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): void;
  478. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  479. }
  480. /**
  481. * glTF V1 Loader
  482. */
  483. class GLTFLoader implements IGLTFLoader {
  484. static Extensions: {
  485. [name: string]: GLTFLoaderExtension;
  486. };
  487. static RegisterExtension(extension: GLTFLoaderExtension): void;
  488. 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;
  489. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  490. private _loadShadersAsync(gltfRuntime, onload);
  491. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  492. private _createNodes(gltfRuntime);
  493. }
  494. }
  495. declare module BABYLON.GLTF1 {
  496. /**
  497. * Utils functions for GLTF
  498. */
  499. class GLTFUtils {
  500. /**
  501. * Sets the given "parameter" matrix
  502. * @param scene: the {BABYLON.Scene} object
  503. * @param source: the source node where to pick the matrix
  504. * @param parameter: the GLTF technique parameter
  505. * @param uniformName: the name of the shader's uniform
  506. * @param shaderMaterial: the shader material
  507. */
  508. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  509. /**
  510. * Sets the given "parameter" matrix
  511. * @param shaderMaterial: the shader material
  512. * @param uniform: the name of the shader's uniform
  513. * @param value: the value of the uniform
  514. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  515. */
  516. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  517. /**
  518. * If the uri is a base64 string
  519. * @param uri: the uri to test
  520. */
  521. static IsBase64(uri: string): boolean;
  522. /**
  523. * Decode the base64 uri
  524. * @param uri: the uri to decode
  525. */
  526. static DecodeBase64(uri: string): ArrayBuffer;
  527. /**
  528. * Returns the wrap mode of the texture
  529. * @param mode: the mode value
  530. */
  531. static GetWrapMode(mode: number): number;
  532. /**
  533. * Returns the byte stride giving an accessor
  534. * @param accessor: the GLTF accessor objet
  535. */
  536. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  537. /**
  538. * Returns the texture filter mode giving a mode value
  539. * @param mode: the filter mode value
  540. */
  541. static GetTextureFilterMode(mode: number): ETextureFilterType;
  542. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  543. /**
  544. * Returns a buffer from its accessor
  545. * @param gltfRuntime: the GLTF runtime
  546. * @param accessor: the GLTF accessor
  547. */
  548. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  549. /**
  550. * Decodes a buffer view into a string
  551. * @param view: the buffer view
  552. */
  553. static DecodeBufferToText(view: ArrayBufferView): string;
  554. /**
  555. * Returns the default material of gltf. Related to
  556. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  557. * @param scene: the Babylon.js scene
  558. */
  559. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  560. private static _DefaultMaterial;
  561. }
  562. }
  563. declare module BABYLON.GLTF1 {
  564. abstract class GLTFLoaderExtension {
  565. private _name;
  566. constructor(name: string);
  567. readonly name: string;
  568. /**
  569. * Defines an override for loading the runtime
  570. * Return true to stop further extensions from loading the runtime
  571. */
  572. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  573. /**
  574. * Defines an onverride for creating gltf runtime
  575. * Return true to stop further extensions from creating the runtime
  576. */
  577. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  578. /**
  579. * Defines an override for loading buffers
  580. * Return true to stop further extensions from loading this buffer
  581. */
  582. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  583. /**
  584. * Defines an override for loading texture buffers
  585. * Return true to stop further extensions from loading this texture data
  586. */
  587. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  588. /**
  589. * Defines an override for creating textures
  590. * Return true to stop further extensions from loading this texture
  591. */
  592. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  593. /**
  594. * Defines an override for loading shader strings
  595. * Return true to stop further extensions from loading this shader data
  596. */
  597. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  598. /**
  599. * Defines an override for loading materials
  600. * Return true to stop further extensions from loading this material
  601. */
  602. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  603. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): void;
  604. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): void;
  605. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  606. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  607. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: (message: string) => void): void;
  608. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  609. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  610. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  611. private static ApplyExtensions(func, defaultFunc);
  612. }
  613. }
  614. declare module BABYLON.GLTF1 {
  615. class GLTFBinaryExtension extends GLTFLoaderExtension {
  616. private _bin;
  617. constructor();
  618. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  619. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  620. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  621. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  622. }
  623. }
  624. declare module BABYLON.GLTF1 {
  625. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  626. constructor();
  627. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  628. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  629. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  630. }
  631. }
  632. declare module BABYLON.GLTF2 {
  633. /**
  634. * Enums
  635. */
  636. enum EComponentType {
  637. BYTE = 5120,
  638. UNSIGNED_BYTE = 5121,
  639. SHORT = 5122,
  640. UNSIGNED_SHORT = 5123,
  641. UNSIGNED_INT = 5125,
  642. FLOAT = 5126,
  643. }
  644. enum EMeshPrimitiveMode {
  645. POINTS = 0,
  646. LINES = 1,
  647. LINE_LOOP = 2,
  648. LINE_STRIP = 3,
  649. TRIANGLES = 4,
  650. TRIANGLE_STRIP = 5,
  651. TRIANGLE_FAN = 6,
  652. }
  653. enum ETextureMagFilter {
  654. NEAREST = 9728,
  655. LINEAR = 9729,
  656. }
  657. enum ETextureMinFilter {
  658. NEAREST = 9728,
  659. LINEAR = 9729,
  660. NEAREST_MIPMAP_NEAREST = 9984,
  661. LINEAR_MIPMAP_NEAREST = 9985,
  662. NEAREST_MIPMAP_LINEAR = 9986,
  663. LINEAR_MIPMAP_LINEAR = 9987,
  664. }
  665. enum ETextureWrapMode {
  666. CLAMP_TO_EDGE = 33071,
  667. MIRRORED_REPEAT = 33648,
  668. REPEAT = 10497,
  669. }
  670. /**
  671. * Interfaces
  672. */
  673. interface IGLTFProperty {
  674. extensions?: Object;
  675. extras?: any;
  676. }
  677. interface IGLTFChildRootProperty extends IGLTFProperty {
  678. name?: string;
  679. }
  680. interface IGLTFAccessorSparseIndices extends IGLTFProperty {
  681. bufferView: number;
  682. byteOffset?: number;
  683. componentType: EComponentType;
  684. }
  685. interface IGLTFAccessorSparseValues extends IGLTFProperty {
  686. bufferView: number;
  687. byteOffset?: number;
  688. }
  689. interface IGLTFAccessorSparse extends IGLTFProperty {
  690. count: number;
  691. indices: IGLTFAccessorSparseIndices;
  692. values: IGLTFAccessorSparseValues;
  693. }
  694. interface IGLTFAccessor extends IGLTFChildRootProperty {
  695. bufferView?: number;
  696. byteOffset?: number;
  697. componentType: EComponentType;
  698. normalized?: boolean;
  699. count: number;
  700. type: string;
  701. max: number[];
  702. min: number[];
  703. sparse?: IGLTFAccessorSparse;
  704. }
  705. interface IGLTFAnimationChannel extends IGLTFProperty {
  706. sampler: number;
  707. target: IGLTFAnimationChannelTarget;
  708. }
  709. interface IGLTFAnimationChannelTarget extends IGLTFProperty {
  710. node: number;
  711. path: string;
  712. }
  713. interface IGLTFAnimationSampler extends IGLTFProperty {
  714. input: number;
  715. interpolation?: string;
  716. output: number;
  717. }
  718. interface IGLTFAnimation extends IGLTFChildRootProperty {
  719. channels: IGLTFAnimationChannel[];
  720. samplers: IGLTFAnimationSampler[];
  721. targets?: any[];
  722. }
  723. interface IGLTFAsset extends IGLTFChildRootProperty {
  724. copyright?: string;
  725. generator?: string;
  726. version: string;
  727. minVersion?: string;
  728. }
  729. interface IGLTFBuffer extends IGLTFChildRootProperty {
  730. uri?: string;
  731. byteLength: number;
  732. loadedData: ArrayBufferView;
  733. loadedObservable: Observable<IGLTFBuffer>;
  734. }
  735. interface IGLTFBufferView extends IGLTFChildRootProperty {
  736. buffer: number;
  737. byteOffset?: number;
  738. byteLength: number;
  739. byteStride?: number;
  740. }
  741. interface IGLTFCameraOrthographic extends IGLTFProperty {
  742. xmag: number;
  743. ymag: number;
  744. zfar: number;
  745. znear: number;
  746. }
  747. interface IGLTFCameraPerspective extends IGLTFProperty {
  748. aspectRatio: number;
  749. yfov: number;
  750. zfar: number;
  751. znear: number;
  752. }
  753. interface IGLTFCamera extends IGLTFChildRootProperty {
  754. orthographic?: IGLTFCameraOrthographic;
  755. perspective?: IGLTFCameraPerspective;
  756. type: string;
  757. }
  758. interface IGLTFImage extends IGLTFChildRootProperty {
  759. uri?: string;
  760. mimeType?: string;
  761. bufferView?: number;
  762. }
  763. interface IGLTFMaterialNormalTextureInfo extends IGLTFTextureInfo {
  764. scale: number;
  765. }
  766. interface IGLTFMaterialOcclusionTextureInfo extends IGLTFTextureInfo {
  767. strength: number;
  768. }
  769. interface IGLTFMaterialPbrMetallicRoughness {
  770. baseColorFactor: number[];
  771. baseColorTexture: IGLTFTextureInfo;
  772. metallicFactor: number;
  773. roughnessFactor: number;
  774. metallicRoughnessTexture: IGLTFTextureInfo;
  775. }
  776. interface IGLTFMaterial extends IGLTFChildRootProperty {
  777. pbrMetallicRoughness?: IGLTFMaterialPbrMetallicRoughness;
  778. normalTexture?: IGLTFMaterialNormalTextureInfo;
  779. occlusionTexture?: IGLTFMaterialOcclusionTextureInfo;
  780. emissiveTexture?: IGLTFTextureInfo;
  781. emissiveFactor?: number[];
  782. alphaMode?: string;
  783. alphaCutoff: number;
  784. doubleSided?: boolean;
  785. index?: number;
  786. babylonMaterial?: Material;
  787. }
  788. interface IGLTFMeshPrimitive extends IGLTFProperty {
  789. attributes: {
  790. [name: string]: number;
  791. };
  792. indices?: number;
  793. material?: number;
  794. mode?: EMeshPrimitiveMode;
  795. targets?: {
  796. [name: string]: number;
  797. }[];
  798. }
  799. interface IGLTFMesh extends IGLTFChildRootProperty {
  800. primitives: IGLTFMeshPrimitive[];
  801. weights?: number[];
  802. }
  803. interface IGLTFNode extends IGLTFChildRootProperty {
  804. camera?: number;
  805. children?: number[];
  806. skin?: number;
  807. matrix?: number[];
  808. mesh?: number;
  809. rotation?: number[];
  810. scale?: number[];
  811. translation?: number[];
  812. weights?: number[];
  813. index?: number;
  814. parent?: IGLTFNode;
  815. babylonMesh?: Mesh;
  816. babylonBones?: {
  817. [skin: number]: Bone;
  818. };
  819. babylonAnimationTargets?: Node[];
  820. }
  821. interface IGLTFSampler extends IGLTFChildRootProperty {
  822. magFilter?: ETextureMagFilter;
  823. minFilter?: ETextureMinFilter;
  824. wrapS?: ETextureWrapMode;
  825. wrapT?: ETextureWrapMode;
  826. }
  827. interface IGLTFScene extends IGLTFChildRootProperty {
  828. nodes: number[];
  829. }
  830. interface IGLTFSkin extends IGLTFChildRootProperty {
  831. inverseBindMatrices?: number;
  832. skeleton?: number;
  833. joints: number[];
  834. index?: number;
  835. babylonSkeleton?: Skeleton;
  836. }
  837. interface IGLTFTexture extends IGLTFChildRootProperty {
  838. sampler?: number;
  839. source: number;
  840. url?: string;
  841. dataReadyObservable?: Observable<IGLTFTexture>;
  842. }
  843. interface IGLTFTextureInfo {
  844. index: number;
  845. texCoord?: number;
  846. }
  847. interface IGLTF extends IGLTFProperty {
  848. accessors?: IGLTFAccessor[];
  849. animations?: IGLTFAnimation[];
  850. asset: IGLTFAsset;
  851. buffers?: IGLTFBuffer[];
  852. bufferViews?: IGLTFBufferView[];
  853. cameras?: IGLTFCamera[];
  854. extensionsUsed?: string[];
  855. extensionsRequired?: string[];
  856. images?: IGLTFImage[];
  857. materials?: IGLTFMaterial[];
  858. meshes?: IGLTFMesh[];
  859. nodes?: IGLTFNode[];
  860. samplers?: IGLTFSampler[];
  861. scene?: number;
  862. scenes?: IGLTFScene[];
  863. skins?: IGLTFSkin[];
  864. textures?: IGLTFTexture[];
  865. }
  866. }
  867. declare module BABYLON.GLTF2 {
  868. class GLTFLoader implements IGLTFLoader, IDisposable {
  869. _gltf: IGLTF;
  870. _babylonScene: Scene;
  871. private _parent;
  872. private _rootUrl;
  873. private _defaultMaterial;
  874. private _rootNode;
  875. private _successCallback;
  876. private _progressCallback;
  877. private _errorCallback;
  878. private _renderReady;
  879. private _disposed;
  880. private _renderReadyObservable;
  881. private _renderPendingCount;
  882. private _loaderPendingCount;
  883. private _loaderTrackers;
  884. static Extensions: {
  885. [name: string]: GLTFLoaderExtension;
  886. };
  887. static RegisterExtension(extension: GLTFLoaderExtension): void;
  888. constructor(parent: GLTFFileLoader);
  889. dispose(): void;
  890. 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;
  891. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void): void;
  892. private _loadAsync(nodeNames, scene, data, rootUrl, onSuccess, onProgress, onError);
  893. _onError(message: string): void;
  894. private _onProgress(event);
  895. _executeWhenRenderReady(func: () => void): void;
  896. private _onRenderReady();
  897. private _onComplete();
  898. private _loadData(data);
  899. private _getMeshes();
  900. private _getSkeletons();
  901. private _getAnimationTargets();
  902. private _startAnimations();
  903. private _loadScene(nodeNames);
  904. _loadNode(node: IGLTFNode): void;
  905. private _loadMesh(node, mesh);
  906. private _loadVertexDataAsync(primitive, onSuccess);
  907. private _createMorphTargets(node, mesh, primitive, babylonMesh);
  908. private _loadMorphTargetsData(mesh, primitive, vertexData, babylonMesh);
  909. private _loadTransform(node);
  910. private _loadSkin(skin);
  911. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  912. private _loadBones(skin, inverseBindMatrixData);
  913. private _loadBone(node, skin, inverseBindMatrixData, babylonBones);
  914. private _getNodeMatrix(node);
  915. private _traverseNodes(indices, action, parentNode?);
  916. _traverseNode(index: number, action: (node: IGLTFNode, index: number, parentNode: IGLTFNode) => boolean, parentNode?: IGLTFNode): void;
  917. private _loadAnimations();
  918. private _loadAnimationChannel(animation, animationIndex, channelIndex);
  919. private _validateUri(uri);
  920. private _loadBufferAsync(buffer, onSuccess);
  921. private _buildInt8ArrayBuffer(buffer, byteOffset, byteLength, byteStride, bytePerComponent);
  922. private _buildUint8ArrayBuffer(buffer, byteOffset, byteLength, byteStride, bytePerComponent);
  923. private _buildInt16ArrayBuffer(buffer, byteOffset, byteLength, byteStride, bytePerComponent);
  924. private _buildUint16ArrayBuffer(buffer, byteOffset, byteLength, byteStride, bytePerComponent);
  925. private _buildUint32ArrayBuffer(buffer, byteOffset, byteLength, byteStride, bytePerComponent);
  926. private _buildFloat32ArrayBuffer(buffer, byteOffset, byteLength, byteStride, bytePerComponent);
  927. private _extractInterleavedData(sourceBuffer, targetBuffer, bytePerComponent, stride, length);
  928. private _loadBufferViewAsync(bufferView, byteOffset, byteLength, bytePerComponent, componentType, onSuccess);
  929. private _loadAccessorAsync(accessor, onSuccess);
  930. private _getByteStrideFromType(accessor);
  931. _addPendingData(data: any): void;
  932. _removePendingData(data: any): void;
  933. _addLoaderPendingData(data: any): void;
  934. _removeLoaderPendingData(data: any): void;
  935. _whenAction(action: () => void, onComplete: () => void): void;
  936. private _getDefaultMaterial();
  937. private _loadMaterialMetallicRoughnessProperties(material);
  938. _loadMaterial(material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): void;
  939. _createPbrMaterial(material: IGLTFMaterial): void;
  940. _loadMaterialBaseProperties(material: IGLTFMaterial): void;
  941. _loadMaterialAlphaProperties(material: IGLTFMaterial, colorFactor?: number[]): void;
  942. _loadTexture(textureInfo: IGLTFTextureInfo): Texture;
  943. _getArrayItem<T>(array: ArrayLike<T>, index: number, name: string): T;
  944. }
  945. }
  946. declare module BABYLON.GLTF2 {
  947. /**
  948. * Utils functions for GLTF
  949. */
  950. class GLTFUtils {
  951. /**
  952. * If the uri is a base64 string
  953. * @param uri: the uri to test
  954. */
  955. static IsBase64(uri: string): boolean;
  956. /**
  957. * Decode the base64 uri
  958. * @param uri: the uri to decode
  959. */
  960. static DecodeBase64(uri: string): ArrayBuffer;
  961. static ForEach(view: Uint16Array | Uint32Array | Float32Array, func: (nvalue: number, index: number) => void): void;
  962. static GetTextureWrapMode(mode: ETextureWrapMode): number;
  963. static GetTextureSamplingMode(magFilter: ETextureMagFilter, minFilter: ETextureMinFilter): number;
  964. /**
  965. * Decodes a buffer view into a string
  966. * @param view: the buffer view
  967. */
  968. static DecodeBufferToText(view: ArrayBufferView): string;
  969. }
  970. }
  971. declare module BABYLON.GLTF2 {
  972. abstract class GLTFLoaderExtension {
  973. enabled: boolean;
  974. readonly abstract name: string;
  975. protected _traverseNode(loader: GLTFLoader, index: number, action: (node: IGLTFNode, index: number, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  976. protected _loadNode(loader: GLTFLoader, node: IGLTFNode): boolean;
  977. protected _loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  978. protected _loadExtension<T>(property: IGLTFProperty, action: (extension: T, onComplete: () => void) => void): boolean;
  979. static _Extensions: GLTFLoaderExtension[];
  980. static TraverseNode(loader: GLTFLoader, index: number, action: (node: IGLTFNode, index: number, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  981. static LoadNode(loader: GLTFLoader, node: IGLTFNode): boolean;
  982. static LoadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  983. private static _ApplyExtensions(action);
  984. }
  985. }
  986. declare module BABYLON.GLTF2.Extensions {
  987. class MSFTLOD extends GLTFLoaderExtension {
  988. /**
  989. * Specify the minimal delay between LODs in ms (default = 250)
  990. */
  991. static MinimalLODDelay: number;
  992. readonly name: string;
  993. protected _traverseNode(loader: GLTFLoader, index: number, action: (node: IGLTFNode, index: number, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): boolean;
  994. protected _loadNode(loader: GLTFLoader, node: IGLTFNode): boolean;
  995. private _loadNodeLOD(loader, nodes, index, onComplete);
  996. protected _loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  997. private _loadMaterialLOD(loader, materials, index, assign, onComplete);
  998. }
  999. }
  1000. declare module BABYLON.GLTF2.Extensions {
  1001. class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
  1002. readonly name: string;
  1003. protected _loadMaterial(loader: GLTFLoader, material: IGLTFMaterial, assign: (babylonMaterial: Material, isNew: boolean) => void): boolean;
  1004. private _loadSpecularGlossinessProperties(loader, material, properties);
  1005. }
  1006. }