babylonjs.loaders.module.d.ts 38 KB

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