babylonjs.loaders.module.d.ts 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. /// <reference types="babylonjs"/>
  2. declare module 'babylonjs-loaders' {
  3. export = BABYLON;
  4. }
  5. declare module BABYLON {
  6. class STLFileLoader implements ISceneLoaderPlugin {
  7. solidPattern: RegExp;
  8. facetsPattern: RegExp;
  9. normalPattern: RegExp;
  10. vertexPattern: RegExp;
  11. name: string;
  12. extensions: ISceneLoaderPluginExtensions;
  13. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  14. load(scene: Scene, data: any, rootUrl: string): boolean;
  15. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  16. private isBinary(data);
  17. private parseBinary(mesh, data);
  18. private parseASCII(mesh, solidData);
  19. }
  20. }
  21. declare module BABYLON {
  22. /**
  23. * Class reading and parsing the MTL file bundled with the obj file.
  24. */
  25. class MTLFileLoader {
  26. materials: BABYLON.StandardMaterial[];
  27. /**
  28. * This function will read the mtl file and create each material described inside
  29. * This function could be improve by adding :
  30. * -some component missing (Ni, Tf...)
  31. * -including the specific options available
  32. *
  33. * @param scene
  34. * @param data
  35. * @param rootUrl
  36. */
  37. parseMTL(scene: BABYLON.Scene, data: string, rootUrl: string): void;
  38. /**
  39. * Gets the texture for the material.
  40. *
  41. * If the material is imported from input file,
  42. * We sanitize the url to ensure it takes the textre from aside the material.
  43. *
  44. * @param rootUrl The root url to load from
  45. * @param value The value stored in the mtl
  46. * @return The Texture
  47. */
  48. private static _getTexture(rootUrl, value, scene);
  49. }
  50. class OBJFileLoader implements ISceneLoaderPlugin {
  51. static OPTIMIZE_WITH_UV: boolean;
  52. name: string;
  53. extensions: string;
  54. obj: RegExp;
  55. group: RegExp;
  56. mtllib: RegExp;
  57. usemtl: RegExp;
  58. smooth: RegExp;
  59. vertexPattern: RegExp;
  60. normalPattern: RegExp;
  61. uvPattern: RegExp;
  62. facePattern1: RegExp;
  63. facePattern2: RegExp;
  64. facePattern3: RegExp;
  65. facePattern4: RegExp;
  66. /**
  67. * Calls synchronously the MTL file attached to this obj.
  68. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  69. * Without this function materials are not displayed in the first frame (but displayed after).
  70. * In consequence it is impossible to get material information in your HTML file
  71. *
  72. * @param url The URL of the MTL file
  73. * @param rootUrl
  74. * @param onSuccess Callback function to be called when the MTL file is loaded
  75. * @private
  76. */
  77. private _loadMTL(url, rootUrl, onSuccess);
  78. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  79. load(scene: Scene, data: string, rootUrl: string): boolean;
  80. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  81. /**
  82. * Read the OBJ file and create an Array of meshes.
  83. * Each mesh contains all information given by the OBJ and the MTL file.
  84. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  85. *
  86. * @param meshesNames
  87. * @param scene BABYLON.Scene The scene where are displayed the data
  88. * @param data String The content of the obj file
  89. * @param rootUrl String The path to the folder
  90. * @returns Array<AbstractMesh>
  91. * @private
  92. */
  93. private _parseSolid(meshesNames, scene, data, rootUrl);
  94. }
  95. }
  96. declare module BABYLON {
  97. enum GLTFLoaderCoordinateSystemMode {
  98. /**
  99. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  100. */
  101. AUTO = 0,
  102. /**
  103. * Sets the useRightHandedSystem flag on the scene.
  104. */
  105. FORCE_RIGHT_HANDED = 1,
  106. }
  107. enum GLTFLoaderAnimationStartMode {
  108. /**
  109. * No animation will start.
  110. */
  111. NONE = 0,
  112. /**
  113. * The first animation will start.
  114. */
  115. FIRST = 1,
  116. /**
  117. * All animations will start.
  118. */
  119. ALL = 2,
  120. }
  121. interface IGLTFLoaderData {
  122. json: Object;
  123. bin: Nullable<ArrayBufferView>;
  124. }
  125. enum GLTFLoaderState {
  126. Loading = 0,
  127. Ready = 1,
  128. Complete = 2,
  129. }
  130. interface IGLTFLoaderExtension {
  131. enabled: boolean;
  132. }
  133. interface IGLTFLoaderExtensions {
  134. [name: string]: IGLTFLoaderExtension;
  135. }
  136. interface IGLTFLoader extends IDisposable {
  137. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  138. animationStartMode: GLTFLoaderAnimationStartMode;
  139. compileMaterials: boolean;
  140. useClipPlane: boolean;
  141. compileShadowGenerators: boolean;
  142. onDisposeObservable: Observable<IGLTFLoader>;
  143. onMeshLoadedObservable: Observable<AbstractMesh>;
  144. onTextureLoadedObservable: Observable<BaseTexture>;
  145. onMaterialLoadedObservable: Observable<Material>;
  146. onCompleteObservable: Observable<IGLTFLoader>;
  147. state: Nullable<GLTFLoaderState>;
  148. extensions: Nullable<IGLTFLoaderExtensions>;
  149. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  150. meshes: AbstractMesh[];
  151. particleSystems: ParticleSystem[];
  152. skeletons: Skeleton[];
  153. }>;
  154. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  155. }
  156. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  157. static CreateGLTFLoaderV1: () => IGLTFLoader;
  158. static CreateGLTFLoaderV2: () => IGLTFLoader;
  159. /**
  160. * Raised when the asset has been parsed.
  161. * The data.json property stores the glTF JSON.
  162. * The data.bin property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
  163. */
  164. onParsedObservable: Observable<IGLTFLoaderData>;
  165. private _onParsedObserver;
  166. onParsed: (loaderData: IGLTFLoaderData) => void;
  167. static IncrementalLoading: boolean;
  168. static HomogeneousCoordinates: boolean;
  169. /**
  170. * The coordinate system mode (AUTO, FORCE_RIGHT_HANDED).
  171. */
  172. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  173. /**
  174. * The animation start mode (NONE, FIRST, ALL).
  175. */
  176. animationStartMode: GLTFLoaderAnimationStartMode;
  177. /**
  178. * Set to true to compile materials before raising the success callback.
  179. */
  180. compileMaterials: boolean;
  181. /**
  182. * Set to true to also compile materials with clip planes.
  183. */
  184. useClipPlane: boolean;
  185. /**
  186. * Set to true to compile shadow generators before raising the success callback.
  187. */
  188. compileShadowGenerators: boolean;
  189. /**
  190. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  191. */
  192. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  193. private _onMeshLoadedObserver;
  194. onMeshLoaded: (mesh: AbstractMesh) => void;
  195. /**
  196. * Raised when the loader creates a texture after parsing the glTF properties of the texture.
  197. */
  198. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  199. private _onTextureLoadedObserver;
  200. onTextureLoaded: (Texture: BaseTexture) => void;
  201. /**
  202. * Raised when the loader creates a material after parsing the glTF properties of the material.
  203. */
  204. readonly onMaterialLoadedObservable: Observable<Material>;
  205. private _onMaterialLoadedObserver;
  206. onMaterialLoaded: (Material: Material) => void;
  207. /**
  208. * Raised when the asset is completely loaded, immediately before the loader is disposed.
  209. * For assets with LODs, raised when all of the LODs are complete.
  210. * For assets without LODs, raised when the model is complete, immediately after onSuccess.
  211. */
  212. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  213. private _onCompleteObserver;
  214. onComplete: () => void;
  215. /**
  216. * Raised when the loader is disposed.
  217. */
  218. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  219. private _onDisposeObserver;
  220. onDispose: () => void;
  221. /**
  222. * The loader state or null if not active.
  223. */
  224. readonly loaderState: Nullable<GLTFLoaderState>;
  225. /**
  226. * The loader extensions or null if not active.
  227. */
  228. readonly loaderExtensions: Nullable<IGLTFLoaderExtensions>;
  229. private _loader;
  230. name: string;
  231. extensions: ISceneLoaderPluginExtensions;
  232. /**
  233. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  234. */
  235. dispose(): void;
  236. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  237. meshes: AbstractMesh[];
  238. particleSystems: ParticleSystem[];
  239. skeletons: Skeleton[];
  240. }>;
  241. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  242. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  243. canDirectLoad(data: string): boolean;
  244. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  245. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  246. private _parse(data);
  247. private _getLoader(loaderData);
  248. private static _parseBinary(data);
  249. private static _parseV1(binaryReader);
  250. private static _parseV2(binaryReader);
  251. private static _parseVersion(version);
  252. private static _compareVersion(a, b);
  253. private static _decodeBufferToText(buffer);
  254. }
  255. }
  256. declare module BABYLON.GLTF1 {
  257. /**
  258. * Enums
  259. */
  260. enum EComponentType {
  261. BYTE = 5120,
  262. UNSIGNED_BYTE = 5121,
  263. SHORT = 5122,
  264. UNSIGNED_SHORT = 5123,
  265. FLOAT = 5126,
  266. }
  267. enum EShaderType {
  268. FRAGMENT = 35632,
  269. VERTEX = 35633,
  270. }
  271. enum EParameterType {
  272. BYTE = 5120,
  273. UNSIGNED_BYTE = 5121,
  274. SHORT = 5122,
  275. UNSIGNED_SHORT = 5123,
  276. INT = 5124,
  277. UNSIGNED_INT = 5125,
  278. FLOAT = 5126,
  279. FLOAT_VEC2 = 35664,
  280. FLOAT_VEC3 = 35665,
  281. FLOAT_VEC4 = 35666,
  282. INT_VEC2 = 35667,
  283. INT_VEC3 = 35668,
  284. INT_VEC4 = 35669,
  285. BOOL = 35670,
  286. BOOL_VEC2 = 35671,
  287. BOOL_VEC3 = 35672,
  288. BOOL_VEC4 = 35673,
  289. FLOAT_MAT2 = 35674,
  290. FLOAT_MAT3 = 35675,
  291. FLOAT_MAT4 = 35676,
  292. SAMPLER_2D = 35678,
  293. }
  294. enum ETextureWrapMode {
  295. CLAMP_TO_EDGE = 33071,
  296. MIRRORED_REPEAT = 33648,
  297. REPEAT = 10497,
  298. }
  299. enum ETextureFilterType {
  300. NEAREST = 9728,
  301. LINEAR = 9728,
  302. NEAREST_MIPMAP_NEAREST = 9984,
  303. LINEAR_MIPMAP_NEAREST = 9985,
  304. NEAREST_MIPMAP_LINEAR = 9986,
  305. LINEAR_MIPMAP_LINEAR = 9987,
  306. }
  307. enum ETextureFormat {
  308. ALPHA = 6406,
  309. RGB = 6407,
  310. RGBA = 6408,
  311. LUMINANCE = 6409,
  312. LUMINANCE_ALPHA = 6410,
  313. }
  314. enum ECullingType {
  315. FRONT = 1028,
  316. BACK = 1029,
  317. FRONT_AND_BACK = 1032,
  318. }
  319. enum EBlendingFunction {
  320. ZERO = 0,
  321. ONE = 1,
  322. SRC_COLOR = 768,
  323. ONE_MINUS_SRC_COLOR = 769,
  324. DST_COLOR = 774,
  325. ONE_MINUS_DST_COLOR = 775,
  326. SRC_ALPHA = 770,
  327. ONE_MINUS_SRC_ALPHA = 771,
  328. DST_ALPHA = 772,
  329. ONE_MINUS_DST_ALPHA = 773,
  330. CONSTANT_COLOR = 32769,
  331. ONE_MINUS_CONSTANT_COLOR = 32770,
  332. CONSTANT_ALPHA = 32771,
  333. ONE_MINUS_CONSTANT_ALPHA = 32772,
  334. SRC_ALPHA_SATURATE = 776,
  335. }
  336. /**
  337. * Interfaces
  338. */
  339. interface IGLTFProperty {
  340. extensions?: {
  341. [key: string]: any;
  342. };
  343. extras?: Object;
  344. }
  345. interface IGLTFChildRootProperty extends IGLTFProperty {
  346. name?: string;
  347. }
  348. interface IGLTFAccessor extends IGLTFChildRootProperty {
  349. bufferView: string;
  350. byteOffset: number;
  351. byteStride: number;
  352. count: number;
  353. type: string;
  354. componentType: EComponentType;
  355. max?: number[];
  356. min?: number[];
  357. name?: string;
  358. }
  359. interface IGLTFBufferView extends IGLTFChildRootProperty {
  360. buffer: string;
  361. byteOffset: number;
  362. byteLength: number;
  363. byteStride: number;
  364. target?: number;
  365. }
  366. interface IGLTFBuffer extends IGLTFChildRootProperty {
  367. uri: string;
  368. byteLength?: number;
  369. type?: string;
  370. }
  371. interface IGLTFShader extends IGLTFChildRootProperty {
  372. uri: string;
  373. type: EShaderType;
  374. }
  375. interface IGLTFProgram extends IGLTFChildRootProperty {
  376. attributes: string[];
  377. fragmentShader: string;
  378. vertexShader: string;
  379. }
  380. interface IGLTFTechniqueParameter {
  381. type: number;
  382. count?: number;
  383. semantic?: string;
  384. node?: string;
  385. value?: number | boolean | string | Array<any>;
  386. source?: string;
  387. babylonValue?: any;
  388. }
  389. interface IGLTFTechniqueCommonProfile {
  390. lightingModel: string;
  391. texcoordBindings: Object;
  392. parameters?: Array<any>;
  393. }
  394. interface IGLTFTechniqueStatesFunctions {
  395. blendColor?: number[];
  396. blendEquationSeparate?: number[];
  397. blendFuncSeparate?: number[];
  398. colorMask: boolean[];
  399. cullFace: number[];
  400. }
  401. interface IGLTFTechniqueStates {
  402. enable: number[];
  403. functions: IGLTFTechniqueStatesFunctions;
  404. }
  405. interface IGLTFTechnique extends IGLTFChildRootProperty {
  406. parameters: {
  407. [key: string]: IGLTFTechniqueParameter;
  408. };
  409. program: string;
  410. attributes: {
  411. [key: string]: string;
  412. };
  413. uniforms: {
  414. [key: string]: string;
  415. };
  416. states: IGLTFTechniqueStates;
  417. }
  418. interface IGLTFMaterial extends IGLTFChildRootProperty {
  419. technique?: string;
  420. values: string[];
  421. }
  422. interface IGLTFMeshPrimitive extends IGLTFProperty {
  423. attributes: {
  424. [key: string]: string;
  425. };
  426. indices: string;
  427. material: string;
  428. mode?: number;
  429. }
  430. interface IGLTFMesh extends IGLTFChildRootProperty {
  431. primitives: IGLTFMeshPrimitive[];
  432. }
  433. interface IGLTFImage extends IGLTFChildRootProperty {
  434. uri: string;
  435. }
  436. interface IGLTFSampler extends IGLTFChildRootProperty {
  437. magFilter?: number;
  438. minFilter?: number;
  439. wrapS?: number;
  440. wrapT?: number;
  441. }
  442. interface IGLTFTexture extends IGLTFChildRootProperty {
  443. sampler: string;
  444. source: string;
  445. format?: ETextureFormat;
  446. internalFormat?: ETextureFormat;
  447. target?: number;
  448. type?: number;
  449. babylonTexture?: Texture;
  450. }
  451. interface IGLTFAmbienLight {
  452. color?: number[];
  453. }
  454. interface IGLTFDirectionalLight {
  455. color?: number[];
  456. }
  457. interface IGLTFPointLight {
  458. color?: number[];
  459. constantAttenuation?: number;
  460. linearAttenuation?: number;
  461. quadraticAttenuation?: number;
  462. }
  463. interface IGLTFSpotLight {
  464. color?: number[];
  465. constantAttenuation?: number;
  466. fallOfAngle?: number;
  467. fallOffExponent?: number;
  468. linearAttenuation?: number;
  469. quadraticAttenuation?: number;
  470. }
  471. interface IGLTFLight extends IGLTFChildRootProperty {
  472. type: string;
  473. }
  474. interface IGLTFCameraOrthographic {
  475. xmag: number;
  476. ymag: number;
  477. zfar: number;
  478. znear: number;
  479. }
  480. interface IGLTFCameraPerspective {
  481. aspectRatio: number;
  482. yfov: number;
  483. zfar: number;
  484. znear: number;
  485. }
  486. interface IGLTFCamera extends IGLTFChildRootProperty {
  487. type: string;
  488. }
  489. interface IGLTFAnimationChannelTarget {
  490. id: string;
  491. path: string;
  492. }
  493. interface IGLTFAnimationChannel {
  494. sampler: string;
  495. target: IGLTFAnimationChannelTarget;
  496. }
  497. interface IGLTFAnimationSampler {
  498. input: string;
  499. output: string;
  500. interpolation?: string;
  501. }
  502. interface IGLTFAnimation extends IGLTFChildRootProperty {
  503. channels?: IGLTFAnimationChannel[];
  504. parameters?: {
  505. [key: string]: string;
  506. };
  507. samplers?: {
  508. [key: string]: IGLTFAnimationSampler;
  509. };
  510. }
  511. interface IGLTFNodeInstanceSkin {
  512. skeletons: string[];
  513. skin: string;
  514. meshes: string[];
  515. }
  516. interface IGLTFSkins extends IGLTFChildRootProperty {
  517. bindShapeMatrix: number[];
  518. inverseBindMatrices: string;
  519. jointNames: string[];
  520. babylonSkeleton?: Skeleton;
  521. }
  522. interface IGLTFNode extends IGLTFChildRootProperty {
  523. camera?: string;
  524. children: string[];
  525. skin?: string;
  526. jointName?: string;
  527. light?: string;
  528. matrix: number[];
  529. mesh?: string;
  530. meshes?: string[];
  531. rotation?: number[];
  532. scale?: number[];
  533. translation?: number[];
  534. babylonNode?: Node;
  535. }
  536. interface IGLTFScene extends IGLTFChildRootProperty {
  537. nodes: string[];
  538. }
  539. /**
  540. * Runtime
  541. */
  542. interface IGLTFRuntime {
  543. extensions: {
  544. [key: string]: any;
  545. };
  546. accessors: {
  547. [key: string]: IGLTFAccessor;
  548. };
  549. buffers: {
  550. [key: string]: IGLTFBuffer;
  551. };
  552. bufferViews: {
  553. [key: string]: IGLTFBufferView;
  554. };
  555. meshes: {
  556. [key: string]: IGLTFMesh;
  557. };
  558. lights: {
  559. [key: string]: IGLTFLight;
  560. };
  561. cameras: {
  562. [key: string]: IGLTFCamera;
  563. };
  564. nodes: {
  565. [key: string]: IGLTFNode;
  566. };
  567. images: {
  568. [key: string]: IGLTFImage;
  569. };
  570. textures: {
  571. [key: string]: IGLTFTexture;
  572. };
  573. shaders: {
  574. [key: string]: IGLTFShader;
  575. };
  576. programs: {
  577. [key: string]: IGLTFProgram;
  578. };
  579. samplers: {
  580. [key: string]: IGLTFSampler;
  581. };
  582. techniques: {
  583. [key: string]: IGLTFTechnique;
  584. };
  585. materials: {
  586. [key: string]: IGLTFMaterial;
  587. };
  588. animations: {
  589. [key: string]: IGLTFAnimation;
  590. };
  591. skins: {
  592. [key: string]: IGLTFSkins;
  593. };
  594. currentScene?: Object;
  595. scenes: {
  596. [key: string]: IGLTFScene;
  597. };
  598. extensionsUsed: string[];
  599. extensionsRequired?: string[];
  600. buffersCount: number;
  601. shaderscount: number;
  602. scene: Scene;
  603. rootUrl: string;
  604. loadedBufferCount: number;
  605. loadedBufferViews: {
  606. [name: string]: ArrayBufferView;
  607. };
  608. loadedShaderCount: number;
  609. importOnlyMeshes: boolean;
  610. importMeshesNames?: string[];
  611. dummyNodes: Node[];
  612. }
  613. /**
  614. * Bones
  615. */
  616. interface INodeToRoot {
  617. bone: Bone;
  618. node: IGLTFNode;
  619. id: string;
  620. }
  621. interface IJointNode {
  622. node: IGLTFNode;
  623. id: string;
  624. }
  625. }
  626. declare module BABYLON.GLTF1 {
  627. /**
  628. * Implementation of the base glTF spec
  629. */
  630. class GLTFLoaderBase {
  631. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  632. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  633. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  634. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  635. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): void;
  636. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  637. }
  638. /**
  639. * glTF V1 Loader
  640. */
  641. class GLTFLoader implements IGLTFLoader {
  642. static Extensions: {
  643. [name: string]: GLTFLoaderExtension;
  644. };
  645. static RegisterExtension(extension: GLTFLoaderExtension): void;
  646. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  647. animationStartMode: GLTFLoaderAnimationStartMode;
  648. compileMaterials: boolean;
  649. useClipPlane: boolean;
  650. compileShadowGenerators: boolean;
  651. onDisposeObservable: Observable<IGLTFLoader>;
  652. onMeshLoadedObservable: Observable<AbstractMesh>;
  653. onTextureLoadedObservable: Observable<BaseTexture>;
  654. onMaterialLoadedObservable: Observable<Material>;
  655. onCompleteObservable: Observable<IGLTFLoader>;
  656. state: Nullable<GLTFLoaderState>;
  657. extensions: Nullable<IGLTFLoaderExtensions>;
  658. dispose(): void;
  659. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError);
  660. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress: (event: SceneLoaderProgressEvent) => void): Promise<{
  661. meshes: AbstractMesh[];
  662. particleSystems: ParticleSystem[];
  663. skeletons: Skeleton[];
  664. }>;
  665. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress, onError);
  666. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  667. private _loadShadersAsync(gltfRuntime, onload);
  668. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  669. private _createNodes(gltfRuntime);
  670. }
  671. }
  672. declare module BABYLON.GLTF1 {
  673. /**
  674. * Utils functions for GLTF
  675. */
  676. class GLTFUtils {
  677. /**
  678. * Sets the given "parameter" matrix
  679. * @param scene: the {BABYLON.Scene} object
  680. * @param source: the source node where to pick the matrix
  681. * @param parameter: the GLTF technique parameter
  682. * @param uniformName: the name of the shader's uniform
  683. * @param shaderMaterial: the shader material
  684. */
  685. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  686. /**
  687. * Sets the given "parameter" matrix
  688. * @param shaderMaterial: the shader material
  689. * @param uniform: the name of the shader's uniform
  690. * @param value: the value of the uniform
  691. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  692. */
  693. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  694. /**
  695. * Returns the wrap mode of the texture
  696. * @param mode: the mode value
  697. */
  698. static GetWrapMode(mode: number): number;
  699. /**
  700. * Returns the byte stride giving an accessor
  701. * @param accessor: the GLTF accessor objet
  702. */
  703. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  704. /**
  705. * Returns the texture filter mode giving a mode value
  706. * @param mode: the filter mode value
  707. */
  708. static GetTextureFilterMode(mode: number): ETextureFilterType;
  709. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  710. /**
  711. * Returns a buffer from its accessor
  712. * @param gltfRuntime: the GLTF runtime
  713. * @param accessor: the GLTF accessor
  714. */
  715. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  716. /**
  717. * Decodes a buffer view into a string
  718. * @param view: the buffer view
  719. */
  720. static DecodeBufferToText(view: ArrayBufferView): string;
  721. /**
  722. * Returns the default material of gltf. Related to
  723. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  724. * @param scene: the Babylon.js scene
  725. */
  726. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  727. private static _DefaultMaterial;
  728. }
  729. }
  730. declare module BABYLON.GLTF1 {
  731. abstract class GLTFLoaderExtension {
  732. private _name;
  733. constructor(name: string);
  734. readonly name: string;
  735. /**
  736. * Defines an override for loading the runtime
  737. * Return true to stop further extensions from loading the runtime
  738. */
  739. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  740. /**
  741. * Defines an onverride for creating gltf runtime
  742. * Return true to stop further extensions from creating the runtime
  743. */
  744. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  745. /**
  746. * Defines an override for loading buffers
  747. * Return true to stop further extensions from loading this buffer
  748. */
  749. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  750. /**
  751. * Defines an override for loading texture buffers
  752. * Return true to stop further extensions from loading this texture data
  753. */
  754. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  755. /**
  756. * Defines an override for creating textures
  757. * Return true to stop further extensions from loading this texture
  758. */
  759. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  760. /**
  761. * Defines an override for loading shader strings
  762. * Return true to stop further extensions from loading this shader data
  763. */
  764. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  765. /**
  766. * Defines an override for loading materials
  767. * Return true to stop further extensions from loading this material
  768. */
  769. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  770. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): void;
  771. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): void;
  772. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  773. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  774. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: (message: string) => void): void;
  775. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  776. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  777. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  778. private static ApplyExtensions(func, defaultFunc);
  779. }
  780. }
  781. declare module BABYLON.GLTF1 {
  782. class GLTFBinaryExtension extends GLTFLoaderExtension {
  783. private _bin;
  784. constructor();
  785. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  786. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  787. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  788. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  789. }
  790. }
  791. declare module BABYLON.GLTF1 {
  792. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  793. constructor();
  794. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  795. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  796. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  797. }
  798. }
  799. declare module BABYLON.GLTF2 {
  800. interface TypedArray extends ArrayBufferView {
  801. [index: number]: number;
  802. }
  803. interface IArrayItem {
  804. _index: number;
  805. }
  806. class ArrayItem {
  807. static Assign(values?: IArrayItem[]): void;
  808. }
  809. }
  810. declare module BABYLON.GLTF2 {
  811. interface ILoaderAccessor extends IAccessor, IArrayItem {
  812. _data?: Promise<TypedArray>;
  813. }
  814. interface ILoaderAnimationChannel extends IAnimationChannel, IArrayItem {
  815. _babylonAnimationGroup: AnimationGroup;
  816. }
  817. interface ILoaderAnimationSamplerData {
  818. input: Float32Array;
  819. interpolation: AnimationSamplerInterpolation;
  820. output: Float32Array;
  821. }
  822. interface ILoaderAnimationSampler extends IAnimationSampler, IArrayItem {
  823. _data: Promise<ILoaderAnimationSamplerData>;
  824. }
  825. interface ILoaderAnimation extends IAnimation, IArrayItem {
  826. channels: ILoaderAnimationChannel[];
  827. samplers: ILoaderAnimationSampler[];
  828. _babylonAnimationGroup: Nullable<AnimationGroup>;
  829. }
  830. interface ILoaderBuffer extends IBuffer, IArrayItem {
  831. _data?: Promise<ArrayBufferView>;
  832. }
  833. interface ILoaderBufferView extends IBufferView, IArrayItem {
  834. _data?: Promise<ArrayBufferView>;
  835. }
  836. interface ILoaderCamera extends ICamera, IArrayItem {
  837. }
  838. interface ILoaderImage extends IImage, IArrayItem {
  839. _objectURL?: Promise<string>;
  840. }
  841. interface ILoaderMaterial extends IMaterial, IArrayItem {
  842. _babylonMaterial?: Material;
  843. _babylonMeshes?: AbstractMesh[];
  844. _loaded?: Promise<void>;
  845. }
  846. interface ILoaderMesh extends IMesh, IArrayItem {
  847. primitives: ILoaderMeshPrimitive[];
  848. }
  849. interface ILoaderMeshPrimitive extends IMeshPrimitive, IArrayItem {
  850. }
  851. interface ILoaderNode extends INode, IArrayItem {
  852. _parent: ILoaderNode;
  853. _babylonMesh?: Mesh;
  854. _primitiveBabylonMeshes?: Mesh[];
  855. _babylonAnimationTargets?: Node[];
  856. _numMorphTargets?: number;
  857. }
  858. interface ILoaderSamplerData {
  859. noMipMaps: boolean;
  860. samplingMode: number;
  861. wrapU: number;
  862. wrapV: number;
  863. }
  864. interface ILoaderSampler extends ISampler, IArrayItem {
  865. _data?: ILoaderSamplerData;
  866. }
  867. interface ILoaderScene extends IScene, IArrayItem {
  868. }
  869. interface ILoaderSkin extends ISkin, IArrayItem {
  870. _babylonSkeleton: Nullable<Skeleton>;
  871. _loaded?: Promise<void>;
  872. }
  873. interface ILoaderTexture extends ITexture, IArrayItem {
  874. }
  875. interface ILoaderGLTF extends IGLTF {
  876. accessors?: ILoaderAccessor[];
  877. animations?: ILoaderAnimation[];
  878. buffers?: ILoaderBuffer[];
  879. bufferViews?: ILoaderBufferView[];
  880. cameras?: ILoaderCamera[];
  881. images?: ILoaderImage[];
  882. materials?: ILoaderMaterial[];
  883. meshes?: ILoaderMesh[];
  884. nodes?: ILoaderNode[];
  885. samplers?: ILoaderSampler[];
  886. scenes?: ILoaderScene[];
  887. skins?: ILoaderSkin[];
  888. textures?: ILoaderTexture[];
  889. }
  890. }
  891. declare module BABYLON.GLTF2 {
  892. class GLTFLoader implements IGLTFLoader {
  893. _gltf: ILoaderGLTF;
  894. _babylonScene: Scene;
  895. _completePromises: Promise<void>[];
  896. private _disposed;
  897. private _state;
  898. private _extensions;
  899. private _rootUrl;
  900. private _rootBabylonMesh;
  901. private _defaultSampler;
  902. private _progressCallback?;
  903. private _requests;
  904. private static _Names;
  905. private static _Factories;
  906. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  907. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  908. animationStartMode: GLTFLoaderAnimationStartMode;
  909. compileMaterials: boolean;
  910. useClipPlane: boolean;
  911. compileShadowGenerators: boolean;
  912. readonly onDisposeObservable: Observable<IGLTFLoader>;
  913. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  914. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  915. readonly onMaterialLoadedObservable: Observable<Material>;
  916. readonly onCompleteObservable: Observable<IGLTFLoader>;
  917. readonly state: Nullable<GLTFLoaderState>;
  918. readonly extensions: IGLTFLoaderExtensions;
  919. constructor();
  920. dispose(): void;
  921. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  922. meshes: AbstractMesh[];
  923. particleSystems: ParticleSystem[];
  924. skeletons: Skeleton[];
  925. }>;
  926. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  927. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  928. private _loadData(data);
  929. private _setupData();
  930. private _createRootNode();
  931. private _loadNodesAsync(nodes);
  932. _loadSceneAsync(context: string, scene: ILoaderScene): Promise<void>;
  933. private _getMeshes();
  934. private _getSkeletons();
  935. private _startAnimations();
  936. _loadNodeAsync(context: string, node: ILoaderNode): Promise<void>;
  937. private _loadMeshAsync(context, node, mesh);
  938. private _loadPrimitiveAsync(context, node, mesh, primitive);
  939. private _loadVertexDataAsync(context, primitive, babylonMesh);
  940. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  941. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonVertexData);
  942. private _loadMorphTargetVertexDataAsync(context, babylonVertexData, attributes, babylonMorphTarget);
  943. private static _ConvertToFloat32Array(context, accessor, data);
  944. private static _ConvertVec3ToVec4(context, data);
  945. private static _LoadTransform(node, babylonNode);
  946. private _loadSkinAsync(context, node, mesh, skin);
  947. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  948. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  949. private _loadBones(context, skin, inverseBindMatricesData);
  950. private _loadBone(node, skin, inverseBindMatricesData, babylonBones);
  951. private _getNodeMatrix(node);
  952. private _loadAnimationsAsync();
  953. private _loadAnimationAsync(context, animation);
  954. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  955. private _loadAnimationSamplerAsync(context, sampler);
  956. private _loadBufferAsync(context, buffer);
  957. private _loadBufferViewAsync(context, bufferView);
  958. private _loadAccessorAsync(context, accessor);
  959. private _buildArrayBuffer<T>(typedArray, data, byteOffset, count, numComponents, byteStride?);
  960. private _getDefaultMaterial();
  961. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material);
  962. _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Promise<void>;
  963. _createMaterial(material: ILoaderMaterial): PBRMaterial;
  964. _loadMaterialBasePropertiesAsync(context: string, material: ILoaderMaterial): Promise<void>;
  965. _loadMaterialAlphaProperties(context: string, material: ILoaderMaterial): void;
  966. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  967. private _loadSampler(context, sampler);
  968. private _loadImageAsync(context, image);
  969. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  970. private _onProgress();
  971. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  972. private static _GetTextureWrapMode(context, mode);
  973. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  974. private static _GetNumComponents(context, type);
  975. private static _ValidateUri(uri);
  976. private _compileMaterialsAsync();
  977. private _compileShadowGeneratorsAsync();
  978. private _abortRequests();
  979. private _releaseResources();
  980. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  981. }
  982. }
  983. declare module BABYLON.GLTF2 {
  984. abstract class GLTFLoaderExtension {
  985. enabled: boolean;
  986. protected _loader: GLTFLoader;
  987. constructor(loader: GLTFLoader);
  988. protected readonly abstract _name: string;
  989. /** Override this method to modify the default behavior for loading scenes. */
  990. protected _loadSceneAsync(context: string, node: ILoaderScene): Nullable<Promise<void>>;
  991. /** Override this method to modify the default behavior for loading nodes. */
  992. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  993. /** Override this method to modify the default behavior for loading materials. */
  994. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  995. /** Override this method to modify the default behavior for loading uris. */
  996. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  997. /** Helper method called by a loader extension to load an glTF extension. */
  998. protected _loadExtensionAsync<T>(context: string, property: IProperty, actionAsync: (context: string, extension: T) => Promise<void>): Nullable<Promise<void>>;
  999. /** Helper method called by the loader to allow extensions to override loading scenes. */
  1000. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1001. /** Helper method called by the loader to allow extensions to override loading nodes. */
  1002. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1003. /** Helper method called by the loader to allow extensions to override loading materials. */
  1004. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  1005. /** Helper method called by the loader to allow extensions to override loading uris. */
  1006. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1007. }
  1008. }
  1009. declare module BABYLON.GLTF2.Extensions {
  1010. class MSFTLOD extends GLTFLoaderExtension {
  1011. private _loadingNodeLOD;
  1012. private _loadNodeSignals;
  1013. private _loadingMaterialLOD;
  1014. private _loadMaterialSignals;
  1015. protected readonly _name: string;
  1016. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1017. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  1018. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1019. /**
  1020. * Gets an array of LOD properties from lowest to highest.
  1021. */
  1022. private static _GetLODs<T>(context, property, array, ids);
  1023. }
  1024. }
  1025. declare module BABYLON.GLTF2.Extensions {
  1026. class KHRMaterialsPbrSpecularGlossiness extends GLTFLoaderExtension {
  1027. protected readonly _name: string;
  1028. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  1029. private _loadSpecularGlossinessPropertiesAsync(loader, context, material, properties);
  1030. }
  1031. }
  1032. declare module BABYLON.GLTF2.Extensions {
  1033. class KHRLights extends GLTFLoaderExtension {
  1034. protected readonly _name: string;
  1035. protected _loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1036. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1037. private readonly _lights;
  1038. }
  1039. }