babylonjs.loaders.module.d.ts 38 KB

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