babylonjs.loaders.module.d.ts 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  1. /// <reference types="babylonjs"/>
  2. /// <reference types="babylonjs-gltf2interface"/>
  3. declare module 'babylonjs-loaders' {
  4. export = BABYLON;
  5. }
  6. declare module BABYLON {
  7. class STLFileLoader implements ISceneLoaderPlugin {
  8. solidPattern: RegExp;
  9. facetsPattern: RegExp;
  10. normalPattern: RegExp;
  11. vertexPattern: RegExp;
  12. name: string;
  13. extensions: ISceneLoaderPluginExtensions;
  14. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  15. load(scene: Scene, data: any, rootUrl: string): boolean;
  16. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  17. private isBinary(data);
  18. private parseBinary(mesh, data);
  19. private parseASCII(mesh, solidData);
  20. }
  21. }
  22. declare module BABYLON {
  23. /**
  24. * Class reading and parsing the MTL file bundled with the obj file.
  25. */
  26. class MTLFileLoader {
  27. materials: BABYLON.StandardMaterial[];
  28. /**
  29. * This function will read the mtl file and create each material described inside
  30. * This function could be improve by adding :
  31. * -some component missing (Ni, Tf...)
  32. * -including the specific options available
  33. *
  34. * @param scene
  35. * @param data
  36. * @param rootUrl
  37. */
  38. parseMTL(scene: BABYLON.Scene, data: string | ArrayBuffer, rootUrl: string): void;
  39. /**
  40. * Gets the texture for the material.
  41. *
  42. * If the material is imported from input file,
  43. * We sanitize the url to ensure it takes the textre from aside the material.
  44. *
  45. * @param rootUrl The root url to load from
  46. * @param value The value stored in the mtl
  47. * @return The Texture
  48. */
  49. private static _getTexture(rootUrl, value, scene);
  50. }
  51. class OBJFileLoader implements ISceneLoaderPlugin {
  52. static OPTIMIZE_WITH_UV: boolean;
  53. static INVERT_Y: boolean;
  54. name: string;
  55. extensions: string;
  56. obj: RegExp;
  57. group: RegExp;
  58. mtllib: RegExp;
  59. usemtl: RegExp;
  60. smooth: RegExp;
  61. vertexPattern: RegExp;
  62. normalPattern: RegExp;
  63. uvPattern: RegExp;
  64. facePattern1: RegExp;
  65. facePattern2: RegExp;
  66. facePattern3: RegExp;
  67. facePattern4: RegExp;
  68. /**
  69. * Calls synchronously the MTL file attached to this obj.
  70. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  71. * Without this function materials are not displayed in the first frame (but displayed after).
  72. * In consequence it is impossible to get material information in your HTML file
  73. *
  74. * @param url The URL of the MTL file
  75. * @param rootUrl
  76. * @param onSuccess Callback function to be called when the MTL file is loaded
  77. * @private
  78. */
  79. private _loadMTL(url, rootUrl, onSuccess);
  80. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  81. load(scene: Scene, data: string, rootUrl: string): boolean;
  82. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  83. /**
  84. * Read the OBJ file and create an Array of meshes.
  85. * Each mesh contains all information given by the OBJ and the MTL file.
  86. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  87. *
  88. * @param meshesNames
  89. * @param scene BABYLON.Scene The scene where are displayed the data
  90. * @param data String The content of the obj file
  91. * @param rootUrl String The path to the folder
  92. * @returns Array<AbstractMesh>
  93. * @private
  94. */
  95. private _parseSolid(meshesNames, scene, data, rootUrl);
  96. }
  97. }
  98. declare module BABYLON {
  99. /**
  100. * Coordinate system mode that will be used when loading from the gltf file
  101. */
  102. enum GLTFLoaderCoordinateSystemMode {
  103. /**
  104. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  105. */
  106. AUTO = 0,
  107. /**
  108. * Sets the useRightHandedSystem flag on the scene.
  109. */
  110. FORCE_RIGHT_HANDED = 1,
  111. }
  112. /**
  113. * Animation mode that determines which animations should be started when a file is loaded
  114. */
  115. enum GLTFLoaderAnimationStartMode {
  116. /**
  117. * No animation will start.
  118. */
  119. NONE = 0,
  120. /**
  121. * The first animation will start.
  122. */
  123. FIRST = 1,
  124. /**
  125. * All animations will start.
  126. */
  127. ALL = 2,
  128. }
  129. /**
  130. * Loaded gltf data
  131. */
  132. interface IGLTFLoaderData {
  133. /**
  134. * Loaded json string converted to an object
  135. */
  136. json: Object;
  137. /**
  138. * Loaded ArrayBufferView
  139. */
  140. bin: Nullable<ArrayBufferView>;
  141. }
  142. /**
  143. * Gltf extension interface
  144. */
  145. interface IGLTFLoaderExtension {
  146. /**
  147. * The name of this extension.
  148. */
  149. readonly name: string;
  150. /**
  151. * Whether this extension is enabled.
  152. */
  153. enabled: boolean;
  154. }
  155. /**
  156. * Loading state
  157. */
  158. enum GLTFLoaderState {
  159. /**
  160. * The asset is loading.
  161. */
  162. LOADING = 0,
  163. /**
  164. * The asset is ready for rendering.
  165. */
  166. READY = 1,
  167. /**
  168. * The asset is completely loaded.
  169. */
  170. COMPLETE = 2,
  171. }
  172. /**
  173. * GLTF loader interface
  174. */
  175. interface IGLTFLoader extends IDisposable {
  176. /**
  177. * Coordinate system that will be used when loading from the gltf file
  178. */
  179. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  180. /**
  181. * Animation mode that determines which animations should be started when a file is loaded
  182. */
  183. animationStartMode: GLTFLoaderAnimationStartMode;
  184. /**
  185. * If the materials in the file should automatically be compiled
  186. */
  187. compileMaterials: boolean;
  188. /**
  189. * If a clip plane should be usede when loading meshes in the file
  190. */
  191. useClipPlane: boolean;
  192. /**
  193. * If shadow generators should automatically be compiled
  194. */
  195. compileShadowGenerators: boolean;
  196. /**
  197. * Observable that fires each time a mesh is loaded
  198. */
  199. onMeshLoadedObservable: Observable<AbstractMesh>;
  200. /**
  201. * Observable that fires each time a texture is loaded
  202. */
  203. onTextureLoadedObservable: Observable<BaseTexture>;
  204. /**
  205. * Observable that fires each time a material is loaded
  206. */
  207. onMaterialLoadedObservable: Observable<Material>;
  208. /**
  209. * Observable that fires when the load has completed
  210. */
  211. onCompleteObservable: Observable<IGLTFLoader>;
  212. /**
  213. * Observable that fires when the loader is disposed
  214. */
  215. onDisposeObservable: Observable<IGLTFLoader>;
  216. /**
  217. * Observable that fire when an extension is loaded
  218. */
  219. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  220. /**
  221. * Loader state
  222. */
  223. state: Nullable<GLTFLoaderState>;
  224. /**
  225. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  226. */
  227. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  228. meshes: AbstractMesh[];
  229. particleSystems: ParticleSystem[];
  230. skeletons: Skeleton[];
  231. animationGroups: AnimationGroup[];
  232. }>;
  233. /**
  234. * Imports all objects from a loaded gltf file and adds them to the scene
  235. */
  236. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  237. }
  238. /** File loader to load gltf files into a babylon scene */
  239. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  240. /** Creates a gltf 1.0 file loader */
  241. static CreateGLTFLoaderV1: () => IGLTFLoader;
  242. /** Creates a gltf 2.0 file loader */
  243. static CreateGLTFLoaderV2: () => IGLTFLoader;
  244. /**
  245. * Raised when the asset has been parsed.
  246. * The data.json property stores the glTF JSON.
  247. * The data.bin property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
  248. */
  249. onParsedObservable: Observable<IGLTFLoaderData>;
  250. private _onParsedObserver;
  251. /** Raised when the asset has been parsed. */
  252. onParsed: (loaderData: IGLTFLoaderData) => void;
  253. /**
  254. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders. Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled. Defaults to true.
  255. */
  256. static IncrementalLoading: boolean;
  257. /**
  258. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters. Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates
  259. */
  260. static HomogeneousCoordinates: boolean;
  261. /**
  262. * The coordinate system mode (AUTO, FORCE_RIGHT_HANDED). Defaults to AUTO.
  263. * - AUTO - Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  264. * - FORCE_RIGHT_HANDED - Sets the useRightHandedSystem flag on the scene.
  265. */
  266. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  267. /**
  268. * The animation start mode (NONE, FIRST, ALL). Defaults to FIRST.
  269. * - NONE - No animation will start.
  270. * - FIRST - The first animation will start.
  271. * - ALL - All animations will start.
  272. */
  273. animationStartMode: GLTFLoaderAnimationStartMode;
  274. /**
  275. * Set to true to compile materials before raising the success callback. Defaults to false.
  276. */
  277. compileMaterials: boolean;
  278. /**
  279. * Set to true to also compile materials with clip planes. Defaults to false.
  280. */
  281. useClipPlane: boolean;
  282. /**
  283. * Set to true to compile shadow generators before raising the success callback. Defaults to false.
  284. */
  285. compileShadowGenerators: boolean;
  286. /**
  287. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  288. */
  289. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  290. private _onMeshLoadedObserver;
  291. /**
  292. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh. (onMeshLoadedObservable is likely desired instead.)
  293. */
  294. onMeshLoaded: (mesh: AbstractMesh) => void;
  295. /**
  296. * Raised when the loader creates a texture after parsing the glTF properties of the texture.
  297. */
  298. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  299. private _onTextureLoadedObserver;
  300. /**
  301. * Method called when a texture has been loaded (onTextureLoadedObservable is likely desired instead.)
  302. */
  303. onTextureLoaded: (texture: BaseTexture) => void;
  304. /**
  305. * Raised when the loader creates a material after parsing the glTF properties of the material.
  306. */
  307. readonly onMaterialLoadedObservable: Observable<Material>;
  308. private _onMaterialLoadedObserver;
  309. /**
  310. * Method when the loader creates a material after parsing the glTF properties of the material. (onMaterialLoadedObservable is likely desired instead.)
  311. */
  312. onMaterialLoaded: (material: Material) => void;
  313. /**
  314. * Raised when the asset is completely loaded, immediately before the loader is disposed.
  315. * For assets with LODs, raised when all of the LODs are complete.
  316. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  317. */
  318. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  319. private _onCompleteObserver;
  320. /**
  321. * Raised when the asset is completely loaded, immediately before the loader is disposed. (onCompleteObservable is likely desired instead.)
  322. */
  323. onComplete: () => void;
  324. /**
  325. * Raised after the loader is disposed.
  326. */
  327. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  328. private _onDisposeObserver;
  329. /**
  330. * Raised after the loader is disposed. (onDisposeObservable is likely desired instead.)
  331. */
  332. onDispose: () => void;
  333. /**
  334. * Raised after a loader extension is created.
  335. * Set additional options for a loader extension in this event.
  336. */
  337. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  338. private _onExtensionLoadedObserver;
  339. /**
  340. * Raised after a loader extension is created. (onExtensionLoadedObservable is likely desired instead.)
  341. */
  342. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  343. /**
  344. * Returns a promise that resolves when the asset is completely loaded.
  345. * @returns A promise that resolves when the asset is completely loaded.
  346. */
  347. whenCompleteAsync(): Promise<void>;
  348. /**
  349. * The loader state (LOADING, READY, COMPLETE) or null if the loader is not active.
  350. */
  351. readonly loaderState: Nullable<GLTFLoaderState>;
  352. private _loader;
  353. /**
  354. * Name of the loader ("gltf")
  355. */
  356. name: string;
  357. /**
  358. * Supported file extensions of the loader (.gltf, .glb)
  359. */
  360. extensions: ISceneLoaderPluginExtensions;
  361. /**
  362. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  363. */
  364. dispose(): void;
  365. /**
  366. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  367. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  368. * @param scene the scene the meshes should be added to
  369. * @param data gltf data containing information of the meshes in a loaded file
  370. * @param rootUrl root url to load from
  371. * @param onProgress event that fires when loading progress has occured
  372. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  373. */
  374. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  375. meshes: AbstractMesh[];
  376. particleSystems: ParticleSystem[];
  377. skeletons: Skeleton[];
  378. animationGroups: AnimationGroup[];
  379. }>;
  380. /**
  381. * Imports all objects from a loaded gltf file and adds them to the scene
  382. * @param scene the scene the objects should be added to
  383. * @param data gltf data containing information of the meshes in a loaded file
  384. * @param rootUrl root url to load from
  385. * @param onProgress event that fires when loading progress has occured
  386. * @returns a promise which completes when objects have been loaded to the scene
  387. */
  388. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  389. /**
  390. * Load into an asset container.
  391. * @param scene The scene to load into
  392. * @param data The data to import
  393. * @param rootUrl The root url for scene and resources
  394. * @param onProgress The callback when the load progresses
  395. * @returns The loaded asset container
  396. */
  397. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  398. /**
  399. * If the data string can be loaded directly
  400. * @param data string contianing the file data
  401. * @returns if the data can be loaded directly
  402. */
  403. canDirectLoad(data: string): boolean;
  404. /**
  405. * Rewrites a url by combining a root url and response url
  406. */
  407. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  408. /**
  409. * Instantiates a gltf file loader plugin
  410. * @returns the created plugin
  411. */
  412. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  413. private _parse(data);
  414. private _getLoader(loaderData);
  415. private static _parseBinary(data);
  416. private static _parseV1(binaryReader);
  417. private static _parseV2(binaryReader);
  418. private static _parseVersion(version);
  419. private static _compareVersion(a, b);
  420. private static _decodeBufferToText(buffer);
  421. }
  422. }
  423. declare module BABYLON.GLTF1 {
  424. /**
  425. * Enums
  426. */
  427. enum EComponentType {
  428. BYTE = 5120,
  429. UNSIGNED_BYTE = 5121,
  430. SHORT = 5122,
  431. UNSIGNED_SHORT = 5123,
  432. FLOAT = 5126,
  433. }
  434. enum EShaderType {
  435. FRAGMENT = 35632,
  436. VERTEX = 35633,
  437. }
  438. enum EParameterType {
  439. BYTE = 5120,
  440. UNSIGNED_BYTE = 5121,
  441. SHORT = 5122,
  442. UNSIGNED_SHORT = 5123,
  443. INT = 5124,
  444. UNSIGNED_INT = 5125,
  445. FLOAT = 5126,
  446. FLOAT_VEC2 = 35664,
  447. FLOAT_VEC3 = 35665,
  448. FLOAT_VEC4 = 35666,
  449. INT_VEC2 = 35667,
  450. INT_VEC3 = 35668,
  451. INT_VEC4 = 35669,
  452. BOOL = 35670,
  453. BOOL_VEC2 = 35671,
  454. BOOL_VEC3 = 35672,
  455. BOOL_VEC4 = 35673,
  456. FLOAT_MAT2 = 35674,
  457. FLOAT_MAT3 = 35675,
  458. FLOAT_MAT4 = 35676,
  459. SAMPLER_2D = 35678,
  460. }
  461. enum ETextureWrapMode {
  462. CLAMP_TO_EDGE = 33071,
  463. MIRRORED_REPEAT = 33648,
  464. REPEAT = 10497,
  465. }
  466. enum ETextureFilterType {
  467. NEAREST = 9728,
  468. LINEAR = 9728,
  469. NEAREST_MIPMAP_NEAREST = 9984,
  470. LINEAR_MIPMAP_NEAREST = 9985,
  471. NEAREST_MIPMAP_LINEAR = 9986,
  472. LINEAR_MIPMAP_LINEAR = 9987,
  473. }
  474. enum ETextureFormat {
  475. ALPHA = 6406,
  476. RGB = 6407,
  477. RGBA = 6408,
  478. LUMINANCE = 6409,
  479. LUMINANCE_ALPHA = 6410,
  480. }
  481. enum ECullingType {
  482. FRONT = 1028,
  483. BACK = 1029,
  484. FRONT_AND_BACK = 1032,
  485. }
  486. enum EBlendingFunction {
  487. ZERO = 0,
  488. ONE = 1,
  489. SRC_COLOR = 768,
  490. ONE_MINUS_SRC_COLOR = 769,
  491. DST_COLOR = 774,
  492. ONE_MINUS_DST_COLOR = 775,
  493. SRC_ALPHA = 770,
  494. ONE_MINUS_SRC_ALPHA = 771,
  495. DST_ALPHA = 772,
  496. ONE_MINUS_DST_ALPHA = 773,
  497. CONSTANT_COLOR = 32769,
  498. ONE_MINUS_CONSTANT_COLOR = 32770,
  499. CONSTANT_ALPHA = 32771,
  500. ONE_MINUS_CONSTANT_ALPHA = 32772,
  501. SRC_ALPHA_SATURATE = 776,
  502. }
  503. /**
  504. * Interfaces
  505. */
  506. interface IGLTFProperty {
  507. extensions?: {
  508. [key: string]: any;
  509. };
  510. extras?: Object;
  511. }
  512. interface IGLTFChildRootProperty extends IGLTFProperty {
  513. name?: string;
  514. }
  515. interface IGLTFAccessor extends IGLTFChildRootProperty {
  516. bufferView: string;
  517. byteOffset: number;
  518. byteStride: number;
  519. count: number;
  520. type: string;
  521. componentType: EComponentType;
  522. max?: number[];
  523. min?: number[];
  524. name?: string;
  525. }
  526. interface IGLTFBufferView extends IGLTFChildRootProperty {
  527. buffer: string;
  528. byteOffset: number;
  529. byteLength: number;
  530. byteStride: number;
  531. target?: number;
  532. }
  533. interface IGLTFBuffer extends IGLTFChildRootProperty {
  534. uri: string;
  535. byteLength?: number;
  536. type?: string;
  537. }
  538. interface IGLTFShader extends IGLTFChildRootProperty {
  539. uri: string;
  540. type: EShaderType;
  541. }
  542. interface IGLTFProgram extends IGLTFChildRootProperty {
  543. attributes: string[];
  544. fragmentShader: string;
  545. vertexShader: string;
  546. }
  547. interface IGLTFTechniqueParameter {
  548. type: number;
  549. count?: number;
  550. semantic?: string;
  551. node?: string;
  552. value?: number | boolean | string | Array<any>;
  553. source?: string;
  554. babylonValue?: any;
  555. }
  556. interface IGLTFTechniqueCommonProfile {
  557. lightingModel: string;
  558. texcoordBindings: Object;
  559. parameters?: Array<any>;
  560. }
  561. interface IGLTFTechniqueStatesFunctions {
  562. blendColor?: number[];
  563. blendEquationSeparate?: number[];
  564. blendFuncSeparate?: number[];
  565. colorMask: boolean[];
  566. cullFace: number[];
  567. }
  568. interface IGLTFTechniqueStates {
  569. enable: number[];
  570. functions: IGLTFTechniqueStatesFunctions;
  571. }
  572. interface IGLTFTechnique extends IGLTFChildRootProperty {
  573. parameters: {
  574. [key: string]: IGLTFTechniqueParameter;
  575. };
  576. program: string;
  577. attributes: {
  578. [key: string]: string;
  579. };
  580. uniforms: {
  581. [key: string]: string;
  582. };
  583. states: IGLTFTechniqueStates;
  584. }
  585. interface IGLTFMaterial extends IGLTFChildRootProperty {
  586. technique?: string;
  587. values: string[];
  588. }
  589. interface IGLTFMeshPrimitive extends IGLTFProperty {
  590. attributes: {
  591. [key: string]: string;
  592. };
  593. indices: string;
  594. material: string;
  595. mode?: number;
  596. }
  597. interface IGLTFMesh extends IGLTFChildRootProperty {
  598. primitives: IGLTFMeshPrimitive[];
  599. }
  600. interface IGLTFImage extends IGLTFChildRootProperty {
  601. uri: string;
  602. }
  603. interface IGLTFSampler extends IGLTFChildRootProperty {
  604. magFilter?: number;
  605. minFilter?: number;
  606. wrapS?: number;
  607. wrapT?: number;
  608. }
  609. interface IGLTFTexture extends IGLTFChildRootProperty {
  610. sampler: string;
  611. source: string;
  612. format?: ETextureFormat;
  613. internalFormat?: ETextureFormat;
  614. target?: number;
  615. type?: number;
  616. babylonTexture?: Texture;
  617. }
  618. interface IGLTFAmbienLight {
  619. color?: number[];
  620. }
  621. interface IGLTFDirectionalLight {
  622. color?: number[];
  623. }
  624. interface IGLTFPointLight {
  625. color?: number[];
  626. constantAttenuation?: number;
  627. linearAttenuation?: number;
  628. quadraticAttenuation?: number;
  629. }
  630. interface IGLTFSpotLight {
  631. color?: number[];
  632. constantAttenuation?: number;
  633. fallOfAngle?: number;
  634. fallOffExponent?: number;
  635. linearAttenuation?: number;
  636. quadraticAttenuation?: number;
  637. }
  638. interface IGLTFLight extends IGLTFChildRootProperty {
  639. type: string;
  640. }
  641. interface IGLTFCameraOrthographic {
  642. xmag: number;
  643. ymag: number;
  644. zfar: number;
  645. znear: number;
  646. }
  647. interface IGLTFCameraPerspective {
  648. aspectRatio: number;
  649. yfov: number;
  650. zfar: number;
  651. znear: number;
  652. }
  653. interface IGLTFCamera extends IGLTFChildRootProperty {
  654. type: string;
  655. }
  656. interface IGLTFAnimationChannelTarget {
  657. id: string;
  658. path: string;
  659. }
  660. interface IGLTFAnimationChannel {
  661. sampler: string;
  662. target: IGLTFAnimationChannelTarget;
  663. }
  664. interface IGLTFAnimationSampler {
  665. input: string;
  666. output: string;
  667. interpolation?: string;
  668. }
  669. interface IGLTFAnimation extends IGLTFChildRootProperty {
  670. channels?: IGLTFAnimationChannel[];
  671. parameters?: {
  672. [key: string]: string;
  673. };
  674. samplers?: {
  675. [key: string]: IGLTFAnimationSampler;
  676. };
  677. }
  678. interface IGLTFNodeInstanceSkin {
  679. skeletons: string[];
  680. skin: string;
  681. meshes: string[];
  682. }
  683. interface IGLTFSkins extends IGLTFChildRootProperty {
  684. bindShapeMatrix: number[];
  685. inverseBindMatrices: string;
  686. jointNames: string[];
  687. babylonSkeleton?: Skeleton;
  688. }
  689. interface IGLTFNode extends IGLTFChildRootProperty {
  690. camera?: string;
  691. children: string[];
  692. skin?: string;
  693. jointName?: string;
  694. light?: string;
  695. matrix: number[];
  696. mesh?: string;
  697. meshes?: string[];
  698. rotation?: number[];
  699. scale?: number[];
  700. translation?: number[];
  701. babylonNode?: Node;
  702. }
  703. interface IGLTFScene extends IGLTFChildRootProperty {
  704. nodes: string[];
  705. }
  706. /**
  707. * Runtime
  708. */
  709. interface IGLTFRuntime {
  710. extensions: {
  711. [key: string]: any;
  712. };
  713. accessors: {
  714. [key: string]: IGLTFAccessor;
  715. };
  716. buffers: {
  717. [key: string]: IGLTFBuffer;
  718. };
  719. bufferViews: {
  720. [key: string]: IGLTFBufferView;
  721. };
  722. meshes: {
  723. [key: string]: IGLTFMesh;
  724. };
  725. lights: {
  726. [key: string]: IGLTFLight;
  727. };
  728. cameras: {
  729. [key: string]: IGLTFCamera;
  730. };
  731. nodes: {
  732. [key: string]: IGLTFNode;
  733. };
  734. images: {
  735. [key: string]: IGLTFImage;
  736. };
  737. textures: {
  738. [key: string]: IGLTFTexture;
  739. };
  740. shaders: {
  741. [key: string]: IGLTFShader;
  742. };
  743. programs: {
  744. [key: string]: IGLTFProgram;
  745. };
  746. samplers: {
  747. [key: string]: IGLTFSampler;
  748. };
  749. techniques: {
  750. [key: string]: IGLTFTechnique;
  751. };
  752. materials: {
  753. [key: string]: IGLTFMaterial;
  754. };
  755. animations: {
  756. [key: string]: IGLTFAnimation;
  757. };
  758. skins: {
  759. [key: string]: IGLTFSkins;
  760. };
  761. currentScene?: Object;
  762. scenes: {
  763. [key: string]: IGLTFScene;
  764. };
  765. extensionsUsed: string[];
  766. extensionsRequired?: string[];
  767. buffersCount: number;
  768. shaderscount: number;
  769. scene: Scene;
  770. rootUrl: string;
  771. loadedBufferCount: number;
  772. loadedBufferViews: {
  773. [name: string]: ArrayBufferView;
  774. };
  775. loadedShaderCount: number;
  776. importOnlyMeshes: boolean;
  777. importMeshesNames?: string[];
  778. dummyNodes: Node[];
  779. }
  780. /**
  781. * Bones
  782. */
  783. interface INodeToRoot {
  784. bone: Bone;
  785. node: IGLTFNode;
  786. id: string;
  787. }
  788. interface IJointNode {
  789. node: IGLTFNode;
  790. id: string;
  791. }
  792. }
  793. declare module BABYLON.GLTF1 {
  794. /**
  795. * Implementation of the base glTF spec
  796. */
  797. class GLTFLoaderBase {
  798. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  799. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  800. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  801. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  802. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  803. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  804. }
  805. /**
  806. * glTF V1 Loader
  807. */
  808. class GLTFLoader implements IGLTFLoader {
  809. static Extensions: {
  810. [name: string]: GLTFLoaderExtension;
  811. };
  812. static RegisterExtension(extension: GLTFLoaderExtension): void;
  813. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  814. animationStartMode: GLTFLoaderAnimationStartMode;
  815. compileMaterials: boolean;
  816. useClipPlane: boolean;
  817. compileShadowGenerators: boolean;
  818. onDisposeObservable: Observable<IGLTFLoader>;
  819. onMeshLoadedObservable: Observable<AbstractMesh>;
  820. onTextureLoadedObservable: Observable<BaseTexture>;
  821. onMaterialLoadedObservable: Observable<Material>;
  822. onCompleteObservable: Observable<IGLTFLoader>;
  823. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  824. /**
  825. * State of the loader
  826. */
  827. state: Nullable<GLTFLoaderState>;
  828. dispose(): void;
  829. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  830. /**
  831. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  832. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  833. * @param scene the scene the meshes should be added to
  834. * @param data gltf data containing information of the meshes in a loaded file
  835. * @param rootUrl root url to load from
  836. * @param onProgress event that fires when loading progress has occured
  837. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  838. */
  839. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  840. meshes: AbstractMesh[];
  841. particleSystems: ParticleSystem[];
  842. skeletons: Skeleton[];
  843. animationGroups: AnimationGroup[];
  844. }>;
  845. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  846. /**
  847. * Imports all objects from a loaded gltf file and adds them to the scene
  848. * @param scene the scene the objects should be added to
  849. * @param data gltf data containing information of the meshes in a loaded file
  850. * @param rootUrl root url to load from
  851. * @param onProgress event that fires when loading progress has occured
  852. * @returns a promise which completes when objects have been loaded to the scene
  853. */
  854. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  855. private _loadShadersAsync(gltfRuntime, onload);
  856. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  857. private _createNodes(gltfRuntime);
  858. }
  859. }
  860. declare module BABYLON.GLTF1 {
  861. /**
  862. * Utils functions for GLTF
  863. */
  864. class GLTFUtils {
  865. /**
  866. * Sets the given "parameter" matrix
  867. * @param scene: the {BABYLON.Scene} object
  868. * @param source: the source node where to pick the matrix
  869. * @param parameter: the GLTF technique parameter
  870. * @param uniformName: the name of the shader's uniform
  871. * @param shaderMaterial: the shader material
  872. */
  873. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  874. /**
  875. * Sets the given "parameter" matrix
  876. * @param shaderMaterial: the shader material
  877. * @param uniform: the name of the shader's uniform
  878. * @param value: the value of the uniform
  879. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  880. */
  881. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  882. /**
  883. * Returns the wrap mode of the texture
  884. * @param mode: the mode value
  885. */
  886. static GetWrapMode(mode: number): number;
  887. /**
  888. * Returns the byte stride giving an accessor
  889. * @param accessor: the GLTF accessor objet
  890. */
  891. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  892. /**
  893. * Returns the texture filter mode giving a mode value
  894. * @param mode: the filter mode value
  895. */
  896. static GetTextureFilterMode(mode: number): ETextureFilterType;
  897. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  898. /**
  899. * Returns a buffer from its accessor
  900. * @param gltfRuntime: the GLTF runtime
  901. * @param accessor: the GLTF accessor
  902. */
  903. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  904. /**
  905. * Decodes a buffer view into a string
  906. * @param view: the buffer view
  907. */
  908. static DecodeBufferToText(view: ArrayBufferView): string;
  909. /**
  910. * Returns the default material of gltf. Related to
  911. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  912. * @param scene: the Babylon.js scene
  913. */
  914. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  915. private static _DefaultMaterial;
  916. }
  917. }
  918. declare module BABYLON.GLTF1 {
  919. abstract class GLTFLoaderExtension {
  920. private _name;
  921. constructor(name: string);
  922. readonly name: string;
  923. /**
  924. * Defines an override for loading the runtime
  925. * Return true to stop further extensions from loading the runtime
  926. */
  927. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  928. /**
  929. * Defines an onverride for creating gltf runtime
  930. * Return true to stop further extensions from creating the runtime
  931. */
  932. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  933. /**
  934. * Defines an override for loading buffers
  935. * Return true to stop further extensions from loading this buffer
  936. */
  937. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  938. /**
  939. * Defines an override for loading texture buffers
  940. * Return true to stop further extensions from loading this texture data
  941. */
  942. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  943. /**
  944. * Defines an override for creating textures
  945. * Return true to stop further extensions from loading this texture
  946. */
  947. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  948. /**
  949. * Defines an override for loading shader strings
  950. * Return true to stop further extensions from loading this shader data
  951. */
  952. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  953. /**
  954. * Defines an override for loading materials
  955. * Return true to stop further extensions from loading this material
  956. */
  957. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  958. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  959. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  960. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  961. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  962. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  963. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  964. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  965. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  966. private static ApplyExtensions(func, defaultFunc);
  967. }
  968. }
  969. declare module BABYLON.GLTF1 {
  970. class GLTFBinaryExtension extends GLTFLoaderExtension {
  971. private _bin;
  972. constructor();
  973. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  974. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  975. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  976. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  977. }
  978. }
  979. declare module BABYLON.GLTF1 {
  980. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  981. constructor();
  982. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  983. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  984. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  985. }
  986. }
  987. declare module BABYLON.GLTF2 {
  988. /** Array item which contains it's index in an array */
  989. interface IArrayItem {
  990. _index: number;
  991. }
  992. /** Array item helper methods */
  993. class ArrayItem {
  994. /** Sets the index of each array element to its index in the array */
  995. static Assign(values?: IArrayItem[]): void;
  996. }
  997. }
  998. /**
  999. * GLTF2 module for babylon
  1000. */
  1001. declare module BABYLON.GLTF2 {
  1002. /**
  1003. * Interface to access data and vertex buffer associated with a file
  1004. */
  1005. interface ILoaderAccessor extends IAccessor, IArrayItem {
  1006. _data?: Promise<ArrayBufferView>;
  1007. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1008. }
  1009. /**
  1010. * Loader's animation channel
  1011. */
  1012. interface ILoaderAnimationChannel extends IAnimationChannel, IArrayItem {
  1013. }
  1014. /**
  1015. * Container for animation keyframe data
  1016. */
  1017. interface ILoaderAnimationSamplerData {
  1018. input: Float32Array;
  1019. interpolation: AnimationSamplerInterpolation;
  1020. output: Float32Array;
  1021. }
  1022. /**
  1023. * Keyframe data
  1024. */
  1025. interface ILoaderAnimationSampler extends IAnimationSampler, IArrayItem {
  1026. _data: Promise<ILoaderAnimationSamplerData>;
  1027. }
  1028. /**
  1029. * Loader animation
  1030. */
  1031. interface ILoaderAnimation extends IAnimation, IArrayItem {
  1032. channels: ILoaderAnimationChannel[];
  1033. samplers: ILoaderAnimationSampler[];
  1034. _babylonAnimationGroup?: AnimationGroup;
  1035. }
  1036. /**
  1037. * Loader buffer
  1038. */
  1039. interface ILoaderBuffer extends IBuffer, IArrayItem {
  1040. _data?: Promise<ArrayBufferView>;
  1041. }
  1042. /**
  1043. * Loader's buffer data
  1044. */
  1045. interface ILoaderBufferView extends IBufferView, IArrayItem {
  1046. _data?: Promise<ArrayBufferView>;
  1047. _babylonBuffer?: Promise<Buffer>;
  1048. }
  1049. /**
  1050. * Loader's loaded camera data
  1051. */
  1052. interface ILoaderCamera extends ICamera, IArrayItem {
  1053. }
  1054. /**
  1055. * Loaded image specified by url
  1056. */
  1057. interface ILoaderImage extends IImage, IArrayItem {
  1058. _objectURL?: Promise<string>;
  1059. }
  1060. /**
  1061. * Loaded material data
  1062. */
  1063. interface ILoaderMaterial extends IMaterial, IArrayItem {
  1064. _babylonData?: {
  1065. [drawMode: number]: {
  1066. material: Material;
  1067. meshes: AbstractMesh[];
  1068. loaded: Promise<void>;
  1069. };
  1070. };
  1071. }
  1072. /**
  1073. * Loader mesh data
  1074. */
  1075. interface ILoaderMesh extends IMesh, IArrayItem {
  1076. primitives: ILoaderMeshPrimitive[];
  1077. }
  1078. /**
  1079. * Loader mesh data
  1080. */
  1081. interface ILoaderMeshPrimitive extends IMeshPrimitive, IArrayItem {
  1082. }
  1083. /**
  1084. * Node for traversing loader data
  1085. */
  1086. interface ILoaderNode extends INode, IArrayItem {
  1087. _parent: ILoaderNode;
  1088. _babylonMesh?: Mesh;
  1089. _primitiveBabylonMeshes?: Mesh[];
  1090. _babylonAnimationTargets?: Node[];
  1091. _numMorphTargets?: number;
  1092. }
  1093. /**
  1094. * Sampler data
  1095. */
  1096. interface ILoaderSamplerData {
  1097. noMipMaps: boolean;
  1098. samplingMode: number;
  1099. wrapU: number;
  1100. wrapV: number;
  1101. }
  1102. /**
  1103. * Sampler data
  1104. */
  1105. interface ILoaderSampler extends ISampler, IArrayItem {
  1106. _data?: ILoaderSamplerData;
  1107. }
  1108. /**
  1109. * Loader's scene
  1110. */
  1111. interface ILoaderScene extends IScene, IArrayItem {
  1112. }
  1113. /**
  1114. * Loader's skeleton data
  1115. */
  1116. interface ILoaderSkin extends ISkin, IArrayItem {
  1117. _babylonSkeleton?: Skeleton;
  1118. _loaded?: Promise<void>;
  1119. }
  1120. /**
  1121. * Loader's texture
  1122. */
  1123. interface ILoaderTexture extends ITexture, IArrayItem {
  1124. }
  1125. /**
  1126. * Loaded GLTF data
  1127. */
  1128. interface ILoaderGLTF extends IGLTF {
  1129. accessors?: ILoaderAccessor[];
  1130. animations?: ILoaderAnimation[];
  1131. buffers?: ILoaderBuffer[];
  1132. bufferViews?: ILoaderBufferView[];
  1133. cameras?: ILoaderCamera[];
  1134. images?: ILoaderImage[];
  1135. materials?: ILoaderMaterial[];
  1136. meshes?: ILoaderMesh[];
  1137. nodes?: ILoaderNode[];
  1138. samplers?: ILoaderSampler[];
  1139. scenes?: ILoaderScene[];
  1140. skins?: ILoaderSkin[];
  1141. textures?: ILoaderTexture[];
  1142. }
  1143. }
  1144. /**
  1145. * Defines the GLTF2 module used to import/export GLTF 2.0 files
  1146. */
  1147. declare module BABYLON.GLTF2 {
  1148. /**
  1149. * Interface for a meterial with a constructor
  1150. */
  1151. interface MaterialConstructor<T extends Material> {
  1152. /**
  1153. * The material class
  1154. */
  1155. readonly prototype: T;
  1156. /**
  1157. * Instatiates a material
  1158. * @param name name of the material
  1159. * @param scene the scene the material will be added to
  1160. */
  1161. new (name: string, scene: Scene): T;
  1162. }
  1163. /**
  1164. * Used to load from a GLTF2 file
  1165. */
  1166. class GLTFLoader implements IGLTFLoader {
  1167. /**
  1168. * @ignore
  1169. */
  1170. _gltf: ILoaderGLTF;
  1171. /**
  1172. * @ignore
  1173. */
  1174. _babylonScene: Scene;
  1175. /**
  1176. * @ignore
  1177. */
  1178. _completePromises: Promise<void>[];
  1179. private _disposed;
  1180. private _state;
  1181. private _extensions;
  1182. private _rootUrl;
  1183. private _rootBabylonMesh;
  1184. private _defaultSampler;
  1185. private _defaultBabylonMaterials;
  1186. private _progressCallback?;
  1187. private _requests;
  1188. private static _Names;
  1189. private static _Factories;
  1190. /**
  1191. * @ignore, registers the loader
  1192. * @param name name of the loader
  1193. * @param factory function that converts a loader to a loader extension
  1194. */
  1195. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1196. /**
  1197. * Coordinate system that will be used when loading from the gltf file
  1198. */
  1199. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  1200. /**
  1201. * Animation mode that determines which animations should be started when a file is loaded
  1202. */
  1203. animationStartMode: GLTFLoaderAnimationStartMode;
  1204. /**
  1205. * If the materials in the file should automatically be compiled
  1206. */
  1207. compileMaterials: boolean;
  1208. /**
  1209. * If a clip plane should be usede when loading meshes in the file
  1210. */
  1211. useClipPlane: boolean;
  1212. /**
  1213. * If shadow generators should automatically be compiled
  1214. */
  1215. compileShadowGenerators: boolean;
  1216. /**
  1217. * Observable that fires when the loader is disposed
  1218. */
  1219. readonly onDisposeObservable: Observable<IGLTFLoader>;
  1220. /**
  1221. * Observable that fires each time a mesh is loaded
  1222. */
  1223. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  1224. /**
  1225. * Observable that fires each time a texture is loaded
  1226. */
  1227. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  1228. /**
  1229. * Observable that fires each time a material is loaded
  1230. */
  1231. readonly onMaterialLoadedObservable: Observable<Material>;
  1232. /**
  1233. * Observable that fires each time an extension is loaded
  1234. */
  1235. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  1236. /**
  1237. * Observable that fires when the load has completed
  1238. */
  1239. readonly onCompleteObservable: Observable<IGLTFLoader>;
  1240. /**
  1241. * The current state of the loader
  1242. */
  1243. readonly state: Nullable<GLTFLoaderState>;
  1244. /**
  1245. * Disposes of the loader
  1246. */
  1247. dispose(): void;
  1248. /**
  1249. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  1250. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1251. * @param scene the scene the meshes should be added to
  1252. * @param data gltf data containing information of the meshes in a loaded file
  1253. * @param rootUrl root url to load from
  1254. * @param onProgress event that fires when loading progress has occured
  1255. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1256. */
  1257. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1258. meshes: AbstractMesh[];
  1259. particleSystems: ParticleSystem[];
  1260. skeletons: Skeleton[];
  1261. animationGroups: AnimationGroup[];
  1262. }>;
  1263. /**
  1264. * Imports all objects from a loaded gltf file and adds them to the scene
  1265. * @param scene the scene the objects should be added to
  1266. * @param data gltf data containing information of the meshes in a loaded file
  1267. * @param rootUrl root url to load from
  1268. * @param onProgress event that fires when loading progress has occured
  1269. * @returns a promise which completes when objects have been loaded to the scene
  1270. */
  1271. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1272. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  1273. private _loadExtensions();
  1274. private _loadData(data);
  1275. private _setupData();
  1276. private _checkExtensions();
  1277. private _createRootNode();
  1278. private _loadNodesAsync(nodes);
  1279. /**
  1280. * @ignore
  1281. */
  1282. _loadSceneAsync(context: string, scene: ILoaderScene): Promise<void>;
  1283. private _forEachPrimitive(node, callback);
  1284. private _getMeshes();
  1285. private _getSkeletons();
  1286. private _getAnimationGroups();
  1287. private _startAnimations();
  1288. /**
  1289. * @ignore
  1290. */
  1291. _loadNodeAsync(context: string, node: ILoaderNode): Promise<void>;
  1292. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1293. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1294. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1295. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1296. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1297. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1298. private static _LoadTransform(node, babylonNode);
  1299. private _loadSkinAsync(context, node, mesh, skin);
  1300. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1301. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  1302. private _loadBones(context, skin, inverseBindMatricesData);
  1303. private _loadBone(node, skin, inverseBindMatricesData, babylonBones);
  1304. private _getNodeMatrix(node);
  1305. private _loadAnimationsAsync();
  1306. private _loadAnimationAsync(context, animation);
  1307. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1308. private _loadAnimationSamplerAsync(context, sampler);
  1309. private _loadBufferAsync(context, buffer);
  1310. /**
  1311. * @ignore
  1312. */
  1313. _loadBufferViewAsync(context: string, bufferView: ILoaderBufferView): Promise<ArrayBufferView>;
  1314. private _loadAccessorAsync(context, accessor);
  1315. /**
  1316. * @ignore
  1317. */
  1318. _loadVertexBufferViewAsync(context: string, bufferView: ILoaderBufferView, kind: string): Promise<Buffer>;
  1319. private _loadVertexAccessorAsync(context, accessor, kind);
  1320. private _getDefaultMaterial(drawMode);
  1321. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1322. /**
  1323. * @ignore
  1324. */
  1325. _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1326. /**
  1327. * @ignore
  1328. */
  1329. _createMaterial<T extends Material>(type: MaterialConstructor<T>, name: string, drawMode: number): T;
  1330. /**
  1331. * @ignore
  1332. */
  1333. _loadMaterialBasePropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1334. /**
  1335. * @ignore
  1336. */
  1337. _loadMaterialAlphaProperties(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1338. /**
  1339. * @ignore
  1340. */
  1341. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1342. private _loadSampler(context, sampler);
  1343. private _loadImageAsync(context, image);
  1344. /**
  1345. * @ignore
  1346. */
  1347. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1348. private _onProgress();
  1349. /**
  1350. * @ignore
  1351. */
  1352. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1353. private static _GetTextureWrapMode(context, mode);
  1354. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1355. private static _GetNumComponents(context, type);
  1356. private static _ValidateUri(uri);
  1357. private static _GetDrawMode(context, mode);
  1358. private _compileMaterialsAsync();
  1359. private _compileShadowGeneratorsAsync();
  1360. private _clear();
  1361. /**
  1362. * @ignore
  1363. */
  1364. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1365. }
  1366. }
  1367. declare module BABYLON.GLTF2 {
  1368. /**
  1369. * Abstract class that can be implemented to extend existing gltf loader behavior.
  1370. */
  1371. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1372. enabled: boolean;
  1373. readonly abstract name: string;
  1374. protected _loader: GLTFLoader;
  1375. constructor(loader: GLTFLoader);
  1376. dispose(): void;
  1377. /** Override this method to modify the default behavior for loading scenes. */
  1378. protected _loadSceneAsync(context: string, node: ILoaderScene): Nullable<Promise<void>>;
  1379. /** Override this method to modify the default behavior for loading nodes. */
  1380. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1381. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  1382. protected _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1383. /** Override this method to modify the default behavior for loading materials. */
  1384. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1385. /** Override this method to modify the default behavior for loading uris. */
  1386. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1387. /** Helper method called by a loader extension to load an glTF extension. */
  1388. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>>;
  1389. /** Helper method called by the loader to allow extensions to override loading scenes. */
  1390. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1391. /** Helper method called by the loader to allow extensions to override loading nodes. */
  1392. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1393. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  1394. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1395. /** Helper method called by the loader to allow extensions to override loading materials. */
  1396. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1397. /** Helper method called by the loader to allow extensions to override loading uris. */
  1398. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1399. }
  1400. }
  1401. declare module BABYLON.GLTF2.Extensions {
  1402. class MSFT_lod extends GLTFLoaderExtension {
  1403. readonly name: string;
  1404. /**
  1405. * Maximum number of LODs to load, starting from the lowest LOD.
  1406. */
  1407. maxLODsToLoad: number;
  1408. private _loadingNodeLOD;
  1409. private _loadNodeSignals;
  1410. private _loadingMaterialLOD;
  1411. private _loadMaterialSignals;
  1412. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1413. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1414. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1415. /**
  1416. * Gets an array of LOD properties from lowest to highest.
  1417. */
  1418. private _getLODs<T>(context, property, array, ids);
  1419. }
  1420. }
  1421. /** Module defining extensions to gltf */
  1422. declare module BABYLON.GLTF2.Extensions {
  1423. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1424. readonly name: string;
  1425. private _dracoCompression;
  1426. constructor(loader: GLTFLoader);
  1427. dispose(): void;
  1428. protected _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1429. }
  1430. }
  1431. declare module BABYLON.GLTF2.Extensions {
  1432. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1433. readonly name: string;
  1434. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1435. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1436. }
  1437. }
  1438. declare module BABYLON.GLTF2.Extensions {
  1439. class KHR_materials_unlit extends GLTFLoaderExtension {
  1440. readonly name: string;
  1441. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1442. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1443. }
  1444. }
  1445. declare module BABYLON.GLTF2.Extensions {
  1446. class KHR_lights extends GLTFLoaderExtension {
  1447. readonly name: string;
  1448. protected _loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1449. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1450. private readonly _lights;
  1451. }
  1452. }