babylonjs.loaders.module.d.ts 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  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. * Mode that determines the coordinate system to use.
  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. * Mode that determines what animations will start.
  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. * Interface that contains the data for the glTF asset.
  131. */
  132. interface IGLTFLoaderData {
  133. /**
  134. * JSON that represents the glTF.
  135. */
  136. json: Object;
  137. /**
  138. * The BIN chunk of a binary glTF
  139. */
  140. bin: Nullable<ArrayBufferView>;
  141. }
  142. /**
  143. * Interface for extending the loader.
  144. */
  145. interface IGLTFLoaderExtension {
  146. /**
  147. * The name of this extension.
  148. */
  149. readonly name: string;
  150. /**
  151. * Defines whether this extension is enabled.
  152. */
  153. enabled: boolean;
  154. }
  155. /**
  156. * Loader 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. * Loader interface.
  174. */
  175. interface IGLTFLoader extends IDisposable {
  176. /**
  177. * Mode that determines the coordinate system to use.
  178. */
  179. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  180. /**
  181. * Mode that determines what animations will start.
  182. */
  183. animationStartMode: GLTFLoaderAnimationStartMode;
  184. /**
  185. * Defines if the loader should compile materials.
  186. */
  187. compileMaterials: boolean;
  188. /**
  189. * Defines if the loader should also compile materials with clip planes.
  190. */
  191. useClipPlane: boolean;
  192. /**
  193. * Defines if the loader should compile shadow generators.
  194. */
  195. compileShadowGenerators: boolean;
  196. /**
  197. * Defines if the Alpha blended materials are only applied as coverage.
  198. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  199. * If true, no extra effects are applied to transparent pixels.
  200. */
  201. transparencyAsCoverage: boolean;
  202. /** @hidden */
  203. _normalizeAnimationGroupsToBeginAtZero: boolean;
  204. /**
  205. * Function called before loading a url referenced by the asset.
  206. */
  207. preprocessUrlAsync: (url: string) => Promise<string>;
  208. /**
  209. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  210. */
  211. onMeshLoadedObservable: Observable<AbstractMesh>;
  212. /**
  213. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  214. */
  215. onTextureLoadedObservable: Observable<BaseTexture>;
  216. /**
  217. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  218. */
  219. onMaterialLoadedObservable: Observable<Material>;
  220. /**
  221. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  222. */
  223. onCameraLoadedObservable: Observable<Camera>;
  224. /**
  225. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  226. * For assets with LODs, raised when all of the LODs are complete.
  227. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  228. */
  229. onCompleteObservable: Observable<IGLTFLoader>;
  230. /**
  231. * Observable raised after the loader is disposed.
  232. */
  233. onDisposeObservable: Observable<IGLTFLoader>;
  234. /**
  235. * Observable raised after a loader extension is created.
  236. * Set additional options for a loader extension in this event.
  237. */
  238. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  239. /**
  240. * Loader state or null if the loader is not active.
  241. */
  242. state: Nullable<GLTFLoaderState>;
  243. /**
  244. * Imports meshes from the given data and adds them to the scene.
  245. */
  246. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  247. meshes: AbstractMesh[];
  248. particleSystems: ParticleSystem[];
  249. skeletons: Skeleton[];
  250. animationGroups: AnimationGroup[];
  251. }>;
  252. /**
  253. * Loads all objects from the given data and adds them to the scene.
  254. */
  255. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  256. }
  257. /**
  258. * File loader for loading glTF files into a scene.
  259. */
  260. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  261. /** @hidden */
  262. static _CreateGLTFLoaderV1: () => IGLTFLoader;
  263. /** @hidden */
  264. static _CreateGLTFLoaderV2: () => IGLTFLoader;
  265. /**
  266. * Raised when the asset has been parsed
  267. */
  268. onParsedObservable: Observable<IGLTFLoaderData>;
  269. private _onParsedObserver;
  270. /**
  271. * Raised when the asset has been parsed
  272. */
  273. onParsed: (loaderData: IGLTFLoaderData) => void;
  274. /**
  275. * 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.
  276. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  277. * Defaults to true.
  278. * @hidden
  279. */
  280. static IncrementalLoading: boolean;
  281. /**
  282. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  283. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  284. * @hidden
  285. */
  286. static HomogeneousCoordinates: boolean;
  287. /**
  288. * The coordinate system mode. Defaults to AUTO.
  289. */
  290. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  291. /**
  292. * The animation start mode. Defaults to FIRST.
  293. */
  294. animationStartMode: GLTFLoaderAnimationStartMode;
  295. /**
  296. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  297. */
  298. compileMaterials: boolean;
  299. /**
  300. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  301. */
  302. useClipPlane: boolean;
  303. /**
  304. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  305. */
  306. compileShadowGenerators: boolean;
  307. /**
  308. * Defines if the Alpha blended materials are only applied as coverage.
  309. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  310. * If true, no extra effects are applied to transparent pixels.
  311. */
  312. transparencyAsCoverage: boolean;
  313. /** @hidden */
  314. _normalizeAnimationGroupsToBeginAtZero: boolean;
  315. /**
  316. * Function called before loading a url referenced by the asset.
  317. */
  318. preprocessUrlAsync: (url: string) => Promise<string>;
  319. /**
  320. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  321. */
  322. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  323. private _onMeshLoadedObserver;
  324. /**
  325. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  326. */
  327. onMeshLoaded: (mesh: AbstractMesh) => void;
  328. /**
  329. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  330. */
  331. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  332. private _onTextureLoadedObserver;
  333. /**
  334. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  335. */
  336. onTextureLoaded: (texture: BaseTexture) => void;
  337. /**
  338. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  339. */
  340. readonly onMaterialLoadedObservable: Observable<Material>;
  341. private _onMaterialLoadedObserver;
  342. /**
  343. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  344. */
  345. onMaterialLoaded: (material: Material) => void;
  346. /**
  347. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  348. */
  349. readonly onCameraLoadedObservable: Observable<Camera>;
  350. private _onCameraLoadedObserver;
  351. /**
  352. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  353. */
  354. onCameraLoaded: (camera: Camera) => void;
  355. /**
  356. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  357. * For assets with LODs, raised when all of the LODs are complete.
  358. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  359. */
  360. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  361. private _onCompleteObserver;
  362. /**
  363. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  364. */
  365. onComplete: () => void;
  366. /**
  367. * Observable raised after the loader is disposed.
  368. */
  369. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  370. private _onDisposeObserver;
  371. /**
  372. * Callback raised after the loader is disposed.
  373. */
  374. onDispose: () => void;
  375. /**
  376. * Observable raised after a loader extension is created.
  377. * Set additional options for a loader extension in this event.
  378. */
  379. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  380. private _onExtensionLoadedObserver;
  381. /**
  382. * Callback raised after a loader extension is created.
  383. */
  384. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  385. /**
  386. * Returns a promise that resolves when the asset is completely loaded.
  387. * @returns a promise that resolves when the asset is completely loaded.
  388. */
  389. whenCompleteAsync(): Promise<void>;
  390. /**
  391. * The loader state or null if the loader is not active.
  392. */
  393. readonly loaderState: Nullable<GLTFLoaderState>;
  394. private _loader;
  395. /**
  396. * Name of the loader ("gltf")
  397. */
  398. name: string;
  399. /**
  400. * Supported file extensions of the loader (.gltf, .glb)
  401. */
  402. extensions: ISceneLoaderPluginExtensions;
  403. /**
  404. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  405. */
  406. dispose(): void;
  407. /**
  408. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  409. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  410. * @param scene the scene the meshes should be added to
  411. * @param data the glTF data to load
  412. * @param rootUrl root url to load from
  413. * @param onProgress event that fires when loading progress has occured
  414. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  415. */
  416. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  417. meshes: AbstractMesh[];
  418. particleSystems: ParticleSystem[];
  419. skeletons: Skeleton[];
  420. animationGroups: AnimationGroup[];
  421. }>;
  422. /**
  423. * Imports all objects from the loaded glTF data and adds them to the scene
  424. * @param scene the scene the objects should be added to
  425. * @param data the glTF data to load
  426. * @param rootUrl root url to load from
  427. * @param onProgress event that fires when loading progress has occured
  428. * @returns a promise which completes when objects have been loaded to the scene
  429. */
  430. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  431. /**
  432. * Load into an asset container.
  433. * @param scene The scene to load into
  434. * @param data The data to import
  435. * @param rootUrl The root url for scene and resources
  436. * @param onProgress The callback when the load progresses
  437. * @returns The loaded asset container
  438. */
  439. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  440. /**
  441. * If the data string can be loaded directly.
  442. * @param data string contianing the file data
  443. * @returns if the data can be loaded directly
  444. */
  445. canDirectLoad(data: string): boolean;
  446. /**
  447. * Rewrites a url by combining a root url and response url.
  448. */
  449. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  450. /**
  451. * Instantiates a glTF file loader plugin.
  452. * @returns the created plugin
  453. */
  454. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  455. private _parse(data);
  456. private _getLoader(loaderData);
  457. private static _parseBinary(data);
  458. private static _parseV1(binaryReader);
  459. private static _parseV2(binaryReader);
  460. private static _parseVersion(version);
  461. private static _compareVersion(a, b);
  462. private static _decodeBufferToText(buffer);
  463. }
  464. }
  465. declare module BABYLON.GLTF1 {
  466. /**
  467. * Enums
  468. */
  469. enum EComponentType {
  470. BYTE = 5120,
  471. UNSIGNED_BYTE = 5121,
  472. SHORT = 5122,
  473. UNSIGNED_SHORT = 5123,
  474. FLOAT = 5126,
  475. }
  476. enum EShaderType {
  477. FRAGMENT = 35632,
  478. VERTEX = 35633,
  479. }
  480. enum EParameterType {
  481. BYTE = 5120,
  482. UNSIGNED_BYTE = 5121,
  483. SHORT = 5122,
  484. UNSIGNED_SHORT = 5123,
  485. INT = 5124,
  486. UNSIGNED_INT = 5125,
  487. FLOAT = 5126,
  488. FLOAT_VEC2 = 35664,
  489. FLOAT_VEC3 = 35665,
  490. FLOAT_VEC4 = 35666,
  491. INT_VEC2 = 35667,
  492. INT_VEC3 = 35668,
  493. INT_VEC4 = 35669,
  494. BOOL = 35670,
  495. BOOL_VEC2 = 35671,
  496. BOOL_VEC3 = 35672,
  497. BOOL_VEC4 = 35673,
  498. FLOAT_MAT2 = 35674,
  499. FLOAT_MAT3 = 35675,
  500. FLOAT_MAT4 = 35676,
  501. SAMPLER_2D = 35678,
  502. }
  503. enum ETextureWrapMode {
  504. CLAMP_TO_EDGE = 33071,
  505. MIRRORED_REPEAT = 33648,
  506. REPEAT = 10497,
  507. }
  508. enum ETextureFilterType {
  509. NEAREST = 9728,
  510. LINEAR = 9728,
  511. NEAREST_MIPMAP_NEAREST = 9984,
  512. LINEAR_MIPMAP_NEAREST = 9985,
  513. NEAREST_MIPMAP_LINEAR = 9986,
  514. LINEAR_MIPMAP_LINEAR = 9987,
  515. }
  516. enum ETextureFormat {
  517. ALPHA = 6406,
  518. RGB = 6407,
  519. RGBA = 6408,
  520. LUMINANCE = 6409,
  521. LUMINANCE_ALPHA = 6410,
  522. }
  523. enum ECullingType {
  524. FRONT = 1028,
  525. BACK = 1029,
  526. FRONT_AND_BACK = 1032,
  527. }
  528. enum EBlendingFunction {
  529. ZERO = 0,
  530. ONE = 1,
  531. SRC_COLOR = 768,
  532. ONE_MINUS_SRC_COLOR = 769,
  533. DST_COLOR = 774,
  534. ONE_MINUS_DST_COLOR = 775,
  535. SRC_ALPHA = 770,
  536. ONE_MINUS_SRC_ALPHA = 771,
  537. DST_ALPHA = 772,
  538. ONE_MINUS_DST_ALPHA = 773,
  539. CONSTANT_COLOR = 32769,
  540. ONE_MINUS_CONSTANT_COLOR = 32770,
  541. CONSTANT_ALPHA = 32771,
  542. ONE_MINUS_CONSTANT_ALPHA = 32772,
  543. SRC_ALPHA_SATURATE = 776,
  544. }
  545. /**
  546. * Interfaces
  547. */
  548. interface IGLTFProperty {
  549. extensions?: {
  550. [key: string]: any;
  551. };
  552. extras?: Object;
  553. }
  554. interface IGLTFChildRootProperty extends IGLTFProperty {
  555. name?: string;
  556. }
  557. interface IGLTFAccessor extends IGLTFChildRootProperty {
  558. bufferView: string;
  559. byteOffset: number;
  560. byteStride: number;
  561. count: number;
  562. type: string;
  563. componentType: EComponentType;
  564. max?: number[];
  565. min?: number[];
  566. name?: string;
  567. }
  568. interface IGLTFBufferView extends IGLTFChildRootProperty {
  569. buffer: string;
  570. byteOffset: number;
  571. byteLength: number;
  572. byteStride: number;
  573. target?: number;
  574. }
  575. interface IGLTFBuffer extends IGLTFChildRootProperty {
  576. uri: string;
  577. byteLength?: number;
  578. type?: string;
  579. }
  580. interface IGLTFShader extends IGLTFChildRootProperty {
  581. uri: string;
  582. type: EShaderType;
  583. }
  584. interface IGLTFProgram extends IGLTFChildRootProperty {
  585. attributes: string[];
  586. fragmentShader: string;
  587. vertexShader: string;
  588. }
  589. interface IGLTFTechniqueParameter {
  590. type: number;
  591. count?: number;
  592. semantic?: string;
  593. node?: string;
  594. value?: number | boolean | string | Array<any>;
  595. source?: string;
  596. babylonValue?: any;
  597. }
  598. interface IGLTFTechniqueCommonProfile {
  599. lightingModel: string;
  600. texcoordBindings: Object;
  601. parameters?: Array<any>;
  602. }
  603. interface IGLTFTechniqueStatesFunctions {
  604. blendColor?: number[];
  605. blendEquationSeparate?: number[];
  606. blendFuncSeparate?: number[];
  607. colorMask: boolean[];
  608. cullFace: number[];
  609. }
  610. interface IGLTFTechniqueStates {
  611. enable: number[];
  612. functions: IGLTFTechniqueStatesFunctions;
  613. }
  614. interface IGLTFTechnique extends IGLTFChildRootProperty {
  615. parameters: {
  616. [key: string]: IGLTFTechniqueParameter;
  617. };
  618. program: string;
  619. attributes: {
  620. [key: string]: string;
  621. };
  622. uniforms: {
  623. [key: string]: string;
  624. };
  625. states: IGLTFTechniqueStates;
  626. }
  627. interface IGLTFMaterial extends IGLTFChildRootProperty {
  628. technique?: string;
  629. values: string[];
  630. }
  631. interface IGLTFMeshPrimitive extends IGLTFProperty {
  632. attributes: {
  633. [key: string]: string;
  634. };
  635. indices: string;
  636. material: string;
  637. mode?: number;
  638. }
  639. interface IGLTFMesh extends IGLTFChildRootProperty {
  640. primitives: IGLTFMeshPrimitive[];
  641. }
  642. interface IGLTFImage extends IGLTFChildRootProperty {
  643. uri: string;
  644. }
  645. interface IGLTFSampler extends IGLTFChildRootProperty {
  646. magFilter?: number;
  647. minFilter?: number;
  648. wrapS?: number;
  649. wrapT?: number;
  650. }
  651. interface IGLTFTexture extends IGLTFChildRootProperty {
  652. sampler: string;
  653. source: string;
  654. format?: ETextureFormat;
  655. internalFormat?: ETextureFormat;
  656. target?: number;
  657. type?: number;
  658. babylonTexture?: Texture;
  659. }
  660. interface IGLTFAmbienLight {
  661. color?: number[];
  662. }
  663. interface IGLTFDirectionalLight {
  664. color?: number[];
  665. }
  666. interface IGLTFPointLight {
  667. color?: number[];
  668. constantAttenuation?: number;
  669. linearAttenuation?: number;
  670. quadraticAttenuation?: number;
  671. }
  672. interface IGLTFSpotLight {
  673. color?: number[];
  674. constantAttenuation?: number;
  675. fallOfAngle?: number;
  676. fallOffExponent?: number;
  677. linearAttenuation?: number;
  678. quadraticAttenuation?: number;
  679. }
  680. interface IGLTFLight extends IGLTFChildRootProperty {
  681. type: string;
  682. }
  683. interface IGLTFCameraOrthographic {
  684. xmag: number;
  685. ymag: number;
  686. zfar: number;
  687. znear: number;
  688. }
  689. interface IGLTFCameraPerspective {
  690. aspectRatio: number;
  691. yfov: number;
  692. zfar: number;
  693. znear: number;
  694. }
  695. interface IGLTFCamera extends IGLTFChildRootProperty {
  696. type: string;
  697. }
  698. interface IGLTFAnimationChannelTarget {
  699. id: string;
  700. path: string;
  701. }
  702. interface IGLTFAnimationChannel {
  703. sampler: string;
  704. target: IGLTFAnimationChannelTarget;
  705. }
  706. interface IGLTFAnimationSampler {
  707. input: string;
  708. output: string;
  709. interpolation?: string;
  710. }
  711. interface IGLTFAnimation extends IGLTFChildRootProperty {
  712. channels?: IGLTFAnimationChannel[];
  713. parameters?: {
  714. [key: string]: string;
  715. };
  716. samplers?: {
  717. [key: string]: IGLTFAnimationSampler;
  718. };
  719. }
  720. interface IGLTFNodeInstanceSkin {
  721. skeletons: string[];
  722. skin: string;
  723. meshes: string[];
  724. }
  725. interface IGLTFSkins extends IGLTFChildRootProperty {
  726. bindShapeMatrix: number[];
  727. inverseBindMatrices: string;
  728. jointNames: string[];
  729. babylonSkeleton?: Skeleton;
  730. }
  731. interface IGLTFNode extends IGLTFChildRootProperty {
  732. camera?: string;
  733. children: string[];
  734. skin?: string;
  735. jointName?: string;
  736. light?: string;
  737. matrix: number[];
  738. mesh?: string;
  739. meshes?: string[];
  740. rotation?: number[];
  741. scale?: number[];
  742. translation?: number[];
  743. babylonNode?: Node;
  744. }
  745. interface IGLTFScene extends IGLTFChildRootProperty {
  746. nodes: string[];
  747. }
  748. /**
  749. * Runtime
  750. */
  751. interface IGLTFRuntime {
  752. extensions: {
  753. [key: string]: any;
  754. };
  755. accessors: {
  756. [key: string]: IGLTFAccessor;
  757. };
  758. buffers: {
  759. [key: string]: IGLTFBuffer;
  760. };
  761. bufferViews: {
  762. [key: string]: IGLTFBufferView;
  763. };
  764. meshes: {
  765. [key: string]: IGLTFMesh;
  766. };
  767. lights: {
  768. [key: string]: IGLTFLight;
  769. };
  770. cameras: {
  771. [key: string]: IGLTFCamera;
  772. };
  773. nodes: {
  774. [key: string]: IGLTFNode;
  775. };
  776. images: {
  777. [key: string]: IGLTFImage;
  778. };
  779. textures: {
  780. [key: string]: IGLTFTexture;
  781. };
  782. shaders: {
  783. [key: string]: IGLTFShader;
  784. };
  785. programs: {
  786. [key: string]: IGLTFProgram;
  787. };
  788. samplers: {
  789. [key: string]: IGLTFSampler;
  790. };
  791. techniques: {
  792. [key: string]: IGLTFTechnique;
  793. };
  794. materials: {
  795. [key: string]: IGLTFMaterial;
  796. };
  797. animations: {
  798. [key: string]: IGLTFAnimation;
  799. };
  800. skins: {
  801. [key: string]: IGLTFSkins;
  802. };
  803. currentScene?: Object;
  804. scenes: {
  805. [key: string]: IGLTFScene;
  806. };
  807. extensionsUsed: string[];
  808. extensionsRequired?: string[];
  809. buffersCount: number;
  810. shaderscount: number;
  811. scene: Scene;
  812. rootUrl: string;
  813. loadedBufferCount: number;
  814. loadedBufferViews: {
  815. [name: string]: ArrayBufferView;
  816. };
  817. loadedShaderCount: number;
  818. importOnlyMeshes: boolean;
  819. importMeshesNames?: string[];
  820. dummyNodes: Node[];
  821. }
  822. /**
  823. * Bones
  824. */
  825. interface INodeToRoot {
  826. bone: Bone;
  827. node: IGLTFNode;
  828. id: string;
  829. }
  830. interface IJointNode {
  831. node: IGLTFNode;
  832. id: string;
  833. }
  834. }
  835. declare module BABYLON.GLTF1 {
  836. /**
  837. * Implementation of the base glTF spec
  838. */
  839. class GLTFLoaderBase {
  840. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  841. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  842. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  843. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  844. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  845. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  846. }
  847. /**
  848. * glTF V1 Loader
  849. */
  850. class GLTFLoader implements IGLTFLoader {
  851. static Extensions: {
  852. [name: string]: GLTFLoaderExtension;
  853. };
  854. static RegisterExtension(extension: GLTFLoaderExtension): void;
  855. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  856. animationStartMode: GLTFLoaderAnimationStartMode;
  857. compileMaterials: boolean;
  858. useClipPlane: boolean;
  859. compileShadowGenerators: boolean;
  860. transparencyAsCoverage: boolean;
  861. _normalizeAnimationGroupsToBeginAtZero: boolean;
  862. preprocessUrlAsync: (url: string) => Promise<string>;
  863. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  864. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  865. readonly onMaterialLoadedObservable: Observable<Material>;
  866. readonly onCameraLoadedObservable: Observable<Camera>;
  867. readonly onCompleteObservable: Observable<IGLTFLoader>;
  868. readonly onDisposeObservable: Observable<IGLTFLoader>;
  869. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  870. state: Nullable<GLTFLoaderState>;
  871. dispose(): void;
  872. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  873. /**
  874. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  875. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  876. * @param scene the scene the meshes should be added to
  877. * @param data gltf data containing information of the meshes in a loaded file
  878. * @param rootUrl root url to load from
  879. * @param onProgress event that fires when loading progress has occured
  880. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  881. */
  882. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  883. meshes: AbstractMesh[];
  884. particleSystems: ParticleSystem[];
  885. skeletons: Skeleton[];
  886. animationGroups: AnimationGroup[];
  887. }>;
  888. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  889. /**
  890. * Imports all objects from a loaded gltf file and adds them to the scene
  891. * @param scene the scene the objects should be added to
  892. * @param data gltf data containing information of the meshes in a loaded file
  893. * @param rootUrl root url to load from
  894. * @param onProgress event that fires when loading progress has occured
  895. * @returns a promise which completes when objects have been loaded to the scene
  896. */
  897. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  898. private _loadShadersAsync(gltfRuntime, onload);
  899. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  900. private _createNodes(gltfRuntime);
  901. }
  902. }
  903. declare module BABYLON.GLTF1 {
  904. /**
  905. * Utils functions for GLTF
  906. */
  907. class GLTFUtils {
  908. /**
  909. * Sets the given "parameter" matrix
  910. * @param scene: the {BABYLON.Scene} object
  911. * @param source: the source node where to pick the matrix
  912. * @param parameter: the GLTF technique parameter
  913. * @param uniformName: the name of the shader's uniform
  914. * @param shaderMaterial: the shader material
  915. */
  916. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  917. /**
  918. * Sets the given "parameter" matrix
  919. * @param shaderMaterial: the shader material
  920. * @param uniform: the name of the shader's uniform
  921. * @param value: the value of the uniform
  922. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  923. */
  924. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  925. /**
  926. * Returns the wrap mode of the texture
  927. * @param mode: the mode value
  928. */
  929. static GetWrapMode(mode: number): number;
  930. /**
  931. * Returns the byte stride giving an accessor
  932. * @param accessor: the GLTF accessor objet
  933. */
  934. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  935. /**
  936. * Returns the texture filter mode giving a mode value
  937. * @param mode: the filter mode value
  938. */
  939. static GetTextureFilterMode(mode: number): ETextureFilterType;
  940. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  941. /**
  942. * Returns a buffer from its accessor
  943. * @param gltfRuntime: the GLTF runtime
  944. * @param accessor: the GLTF accessor
  945. */
  946. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  947. /**
  948. * Decodes a buffer view into a string
  949. * @param view: the buffer view
  950. */
  951. static DecodeBufferToText(view: ArrayBufferView): string;
  952. /**
  953. * Returns the default material of gltf. Related to
  954. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  955. * @param scene: the Babylon.js scene
  956. */
  957. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  958. private static _DefaultMaterial;
  959. }
  960. }
  961. declare module BABYLON.GLTF1 {
  962. abstract class GLTFLoaderExtension {
  963. private _name;
  964. constructor(name: string);
  965. readonly name: string;
  966. /**
  967. * Defines an override for loading the runtime
  968. * Return true to stop further extensions from loading the runtime
  969. */
  970. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  971. /**
  972. * Defines an onverride for creating gltf runtime
  973. * Return true to stop further extensions from creating the runtime
  974. */
  975. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  976. /**
  977. * Defines an override for loading buffers
  978. * Return true to stop further extensions from loading this buffer
  979. */
  980. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  981. /**
  982. * Defines an override for loading texture buffers
  983. * Return true to stop further extensions from loading this texture data
  984. */
  985. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  986. /**
  987. * Defines an override for creating textures
  988. * Return true to stop further extensions from loading this texture
  989. */
  990. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  991. /**
  992. * Defines an override for loading shader strings
  993. * Return true to stop further extensions from loading this shader data
  994. */
  995. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  996. /**
  997. * Defines an override for loading materials
  998. * Return true to stop further extensions from loading this material
  999. */
  1000. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  1001. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  1002. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  1003. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  1004. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  1005. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  1006. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  1007. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  1008. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  1009. private static ApplyExtensions(func, defaultFunc);
  1010. }
  1011. }
  1012. declare module BABYLON.GLTF1 {
  1013. class GLTFBinaryExtension extends GLTFLoaderExtension {
  1014. private _bin;
  1015. constructor();
  1016. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  1017. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  1018. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  1019. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  1020. }
  1021. }
  1022. declare module BABYLON.GLTF1 {
  1023. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  1024. constructor();
  1025. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  1026. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  1027. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  1028. }
  1029. }
  1030. declare module BABYLON.GLTF2 {
  1031. /** @hidden */
  1032. interface _IArrayItem {
  1033. _index: number;
  1034. }
  1035. /** @hidden */
  1036. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  1037. _data?: Promise<ArrayBufferView>;
  1038. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1039. }
  1040. /** @hidden */
  1041. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  1042. }
  1043. /** @hidden */
  1044. interface _ILoaderAnimationSamplerData {
  1045. input: Float32Array;
  1046. interpolation: AnimationSamplerInterpolation;
  1047. output: Float32Array;
  1048. }
  1049. /** @hidden */
  1050. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  1051. _data?: Promise<_ILoaderAnimationSamplerData>;
  1052. }
  1053. /** @hidden */
  1054. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  1055. channels: _ILoaderAnimationChannel[];
  1056. samplers: _ILoaderAnimationSampler[];
  1057. _babylonAnimationGroup?: AnimationGroup;
  1058. }
  1059. /** @hidden */
  1060. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  1061. _data?: Promise<ArrayBufferView>;
  1062. }
  1063. /** @hidden */
  1064. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  1065. _data?: Promise<ArrayBufferView>;
  1066. _babylonBuffer?: Promise<Buffer>;
  1067. }
  1068. /** @hidden */
  1069. interface _ILoaderCamera extends ICamera, _IArrayItem {
  1070. }
  1071. /** @hidden */
  1072. interface _ILoaderImage extends IImage, _IArrayItem {
  1073. _blob?: Promise<Blob>;
  1074. }
  1075. /** @hidden */
  1076. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  1077. _babylonData?: {
  1078. [drawMode: number]: {
  1079. material: Material;
  1080. meshes: AbstractMesh[];
  1081. loaded: Promise<void>;
  1082. };
  1083. };
  1084. }
  1085. /** @hidden */
  1086. interface _ILoaderMesh extends IMesh, _IArrayItem {
  1087. primitives: _ILoaderMeshPrimitive[];
  1088. }
  1089. /** @hidden */
  1090. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  1091. }
  1092. /** @hidden */
  1093. interface _ILoaderNode extends INode, _IArrayItem {
  1094. _parent?: _ILoaderNode;
  1095. _babylonMesh?: Mesh;
  1096. _primitiveBabylonMeshes?: Mesh[];
  1097. _babylonBones?: Bone[];
  1098. _numMorphTargets?: number;
  1099. }
  1100. /** @hidden */
  1101. interface _ILoaderSamplerData {
  1102. noMipMaps: boolean;
  1103. samplingMode: number;
  1104. wrapU: number;
  1105. wrapV: number;
  1106. }
  1107. /** @hidden */
  1108. interface _ILoaderSampler extends ISampler, _IArrayItem {
  1109. _data?: _ILoaderSamplerData;
  1110. }
  1111. /** @hidden */
  1112. interface _ILoaderScene extends IScene, _IArrayItem {
  1113. }
  1114. /** @hidden */
  1115. interface _ILoaderSkin extends ISkin, _IArrayItem {
  1116. _babylonSkeleton?: Skeleton;
  1117. _loaded?: Promise<void>;
  1118. }
  1119. /** @hidden */
  1120. interface _ILoaderTexture extends ITexture, _IArrayItem {
  1121. }
  1122. /** @hidden */
  1123. interface _ILoaderGLTF extends IGLTF {
  1124. accessors?: _ILoaderAccessor[];
  1125. animations?: _ILoaderAnimation[];
  1126. buffers?: _ILoaderBuffer[];
  1127. bufferViews?: _ILoaderBufferView[];
  1128. cameras?: _ILoaderCamera[];
  1129. images?: _ILoaderImage[];
  1130. materials?: _ILoaderMaterial[];
  1131. meshes?: _ILoaderMesh[];
  1132. nodes?: _ILoaderNode[];
  1133. samplers?: _ILoaderSampler[];
  1134. scenes?: _ILoaderScene[];
  1135. skins?: _ILoaderSkin[];
  1136. textures?: _ILoaderTexture[];
  1137. }
  1138. }
  1139. /**
  1140. * Defines the module used to import/export glTF 2.0 assets
  1141. */
  1142. declare module BABYLON.GLTF2 {
  1143. /**
  1144. * Loader for loading a glTF 2.0 asset
  1145. */
  1146. class GLTFLoader implements IGLTFLoader {
  1147. /** @hidden */
  1148. _gltf: _ILoaderGLTF;
  1149. /** @hidden */
  1150. _babylonScene: Scene;
  1151. /** @hidden */
  1152. _completePromises: Promise<void>[];
  1153. /** @hidden */
  1154. _onReadyObservable: Observable<IGLTFLoader>;
  1155. private _disposed;
  1156. private _state;
  1157. private _extensions;
  1158. private _rootUrl;
  1159. private _rootBabylonMesh;
  1160. private _defaultSampler;
  1161. private _defaultBabylonMaterials;
  1162. private _progressCallback?;
  1163. private _requests;
  1164. private static _ExtensionNames;
  1165. private static _ExtensionFactories;
  1166. /** @hidden */
  1167. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1168. /**
  1169. * Mode that determines the coordinate system to use.
  1170. */
  1171. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  1172. /**
  1173. * Mode that determines what animations will start.
  1174. */
  1175. animationStartMode: GLTFLoaderAnimationStartMode;
  1176. /**
  1177. * Defines if the loader should compile materials.
  1178. */
  1179. compileMaterials: boolean;
  1180. /**
  1181. * Defines if the loader should also compile materials with clip planes.
  1182. */
  1183. useClipPlane: boolean;
  1184. /**
  1185. * Defines if the loader should compile shadow generators.
  1186. */
  1187. compileShadowGenerators: boolean;
  1188. /**
  1189. * Defines if the Alpha blended materials are only applied as coverage.
  1190. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  1191. * If true, no extra effects are applied to transparent pixels.
  1192. */
  1193. transparencyAsCoverage: boolean;
  1194. /** @hidden */
  1195. _normalizeAnimationGroupsToBeginAtZero: boolean;
  1196. /**
  1197. * Function called before loading a url referenced by the asset.
  1198. */
  1199. preprocessUrlAsync: (url: string) => Promise<string>;
  1200. /**
  1201. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  1202. */
  1203. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  1204. /**
  1205. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  1206. */
  1207. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  1208. /**
  1209. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  1210. */
  1211. readonly onMaterialLoadedObservable: Observable<Material>;
  1212. /**
  1213. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  1214. */
  1215. readonly onCameraLoadedObservable: Observable<Camera>;
  1216. /**
  1217. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  1218. * For assets with LODs, raised when all of the LODs are complete.
  1219. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  1220. */
  1221. readonly onCompleteObservable: Observable<IGLTFLoader>;
  1222. /**
  1223. * Observable raised after the loader is disposed.
  1224. */
  1225. readonly onDisposeObservable: Observable<IGLTFLoader>;
  1226. /**
  1227. * Observable raised after a loader extension is created.
  1228. * Set additional options for a loader extension in this event.
  1229. */
  1230. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  1231. /**
  1232. * Loader state or null if the loader is not active.
  1233. */
  1234. readonly state: Nullable<GLTFLoaderState>;
  1235. /**
  1236. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  1237. */
  1238. dispose(): void;
  1239. /**
  1240. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  1241. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1242. * @param scene the scene the meshes should be added to
  1243. * @param data the glTF data to load
  1244. * @param rootUrl root url to load from
  1245. * @param onProgress event that fires when loading progress has occured
  1246. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1247. */
  1248. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1249. meshes: AbstractMesh[];
  1250. particleSystems: ParticleSystem[];
  1251. skeletons: Skeleton[];
  1252. animationGroups: AnimationGroup[];
  1253. }>;
  1254. /**
  1255. * Imports all objects from the loaded glTF data and adds them to the scene
  1256. * @param scene the scene the objects should be added to
  1257. * @param data the glTF data to load
  1258. * @param rootUrl root url to load from
  1259. * @param onProgress event that fires when loading progress has occured
  1260. * @returns a promise which completes when objects have been loaded to the scene
  1261. */
  1262. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1263. private _loadAsync(nodes);
  1264. private _loadData(data);
  1265. private _setupData();
  1266. private _loadExtensions();
  1267. private _checkExtensions();
  1268. private _createRootNode();
  1269. private _loadNodesAsync(nodes);
  1270. /** @hidden */
  1271. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1272. private _forEachPrimitive(node, callback);
  1273. private _getMeshes();
  1274. private _getSkeletons();
  1275. private _getAnimationGroups();
  1276. private _startAnimations();
  1277. /** @hidden */
  1278. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1279. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1280. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1281. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1282. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1283. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1284. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1285. private static _LoadTransform(node, babylonNode);
  1286. private _loadSkinAsync(context, node, mesh, skin);
  1287. private _loadBones(context, skin);
  1288. private _loadBone(node, skin, babylonBones);
  1289. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1290. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1291. private _getNodeMatrix(node);
  1292. private _loadCamera(context, camera, babylonMesh);
  1293. private _loadAnimationsAsync();
  1294. private _loadAnimationAsync(context, animation);
  1295. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1296. private _loadAnimationSamplerAsync(context, sampler);
  1297. private _loadBufferAsync(context, buffer);
  1298. /** @hidden */
  1299. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1300. private _loadIndicesAccessorAsync(context, accessor);
  1301. private _loadFloatAccessorAsync(context, accessor);
  1302. /** @hidden */
  1303. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1304. private _loadVertexAccessorAsync(context, accessor, kind);
  1305. private _getDefaultMaterial(drawMode);
  1306. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1307. /** @hidden */
  1308. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1309. /** @hidden */
  1310. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1311. /** @hidden */
  1312. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1313. /** @hidden */
  1314. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1315. /** @hidden */
  1316. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1317. private _loadSampler(context, sampler);
  1318. private _loadImageAsync(context, image);
  1319. /** @hidden */
  1320. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1321. private _onProgress();
  1322. /** @hidden */
  1323. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1324. private static _GetTextureWrapMode(context, mode);
  1325. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1326. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1327. private static _GetNumComponents(context, type);
  1328. private static _ValidateUri(uri);
  1329. private static _GetDrawMode(context, mode);
  1330. private _compileMaterialsAsync();
  1331. private _compileShadowGeneratorsAsync();
  1332. private _clear();
  1333. /** @hidden */
  1334. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1335. }
  1336. }
  1337. declare module BABYLON.GLTF2 {
  1338. /**
  1339. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1340. */
  1341. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1342. /**
  1343. * Gets or sets a boolean indicating if the extension is enabled
  1344. */
  1345. enabled: boolean;
  1346. /**
  1347. * Gets or sets extension name
  1348. */
  1349. readonly abstract name: string;
  1350. protected _loader: GLTFLoader;
  1351. /**
  1352. * Creates new GLTFLoaderExtension
  1353. * @param loader defines the GLTFLoader to use
  1354. */
  1355. constructor(loader: GLTFLoader);
  1356. /**
  1357. * Release all resources
  1358. */
  1359. dispose(): void;
  1360. /**
  1361. * Override this method to modify the default behavior for loading scenes.
  1362. * @hidden
  1363. */
  1364. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1365. /**
  1366. * Override this method to modify the default behavior for loading nodes.
  1367. * @hidden
  1368. */
  1369. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1370. /**
  1371. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1372. * @hidden
  1373. */
  1374. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1375. /**
  1376. * Override this method to modify the default behavior for loading materials.
  1377. * @hidden
  1378. */
  1379. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1380. /**
  1381. * Override this method to modify the default behavior for loading textures.
  1382. * @hidden
  1383. */
  1384. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1385. /**
  1386. * Override this method to modify the default behavior for loading uris.
  1387. * @hidden
  1388. */
  1389. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1390. /**
  1391. * Helper method called by a loader extension to load an glTF extension.
  1392. * @hidden
  1393. */
  1394. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1395. /**
  1396. * Helper method called by the loader to allow extensions to override loading scenes.
  1397. * @hidden
  1398. */
  1399. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1400. /**
  1401. * Helper method called by the loader to allow extensions to override loading scenes.
  1402. * @hidden
  1403. */
  1404. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1405. /**
  1406. * Helper method called by the loader to allow extensions to override loading nodes.
  1407. * @hidden
  1408. */
  1409. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1410. /**
  1411. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1412. * @hidden
  1413. */
  1414. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1415. /**
  1416. * Helper method called by the loader to allow extensions to override loading materials.
  1417. * @hidden
  1418. */
  1419. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1420. /**
  1421. * Helper method called by the loader to allow extensions to override loading textures.
  1422. * @hidden
  1423. */
  1424. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1425. /**
  1426. * Helper method called by the loader to allow extensions to override loading uris.
  1427. * @hidden
  1428. */
  1429. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1430. }
  1431. }
  1432. /**
  1433. * Defines the module of the glTF 2.0 loader extensions.
  1434. */
  1435. declare module BABYLON.GLTF2.Extensions {
  1436. }
  1437. declare module BABYLON.GLTF2.Extensions {
  1438. /**
  1439. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1440. */
  1441. class MSFT_lod extends GLTFLoaderExtension {
  1442. readonly name: string;
  1443. /**
  1444. * Maximum number of LODs to load, starting from the lowest LOD.
  1445. */
  1446. maxLODsToLoad: number;
  1447. /**
  1448. * Observable raised when all node LODs of one level are loaded.
  1449. * The event data is the index of the loaded LOD starting from zero.
  1450. * Dispose the loader to cancel the loading of the next level of LODs.
  1451. */
  1452. onNodeLODsLoadedObservable: Observable<number>;
  1453. /**
  1454. * Observable raised when all material LODs of one level are loaded.
  1455. * The event data is the index of the loaded LOD starting from zero.
  1456. * Dispose the loader to cancel the loading of the next level of LODs.
  1457. */
  1458. onMaterialLODsLoadedObservable: Observable<number>;
  1459. private _loadingNodeLOD;
  1460. private _loadNodeSignals;
  1461. private _loadNodePromises;
  1462. private _loadingMaterialLOD;
  1463. private _loadMaterialSignals;
  1464. private _loadMaterialPromises;
  1465. constructor(loader: GLTFLoader);
  1466. dispose(): void;
  1467. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1468. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1469. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1470. /**
  1471. * Gets an array of LOD properties from lowest to highest.
  1472. */
  1473. private _getLODs<T>(context, property, array, ids);
  1474. }
  1475. }
  1476. declare module BABYLON.GLTF2.Extensions {
  1477. /** @hidden */
  1478. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1479. readonly name: string;
  1480. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1481. }
  1482. }
  1483. declare module BABYLON.GLTF2.Extensions {
  1484. /** @hidden */
  1485. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1486. readonly name: string;
  1487. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1488. }
  1489. }
  1490. declare module BABYLON.GLTF2.Extensions {
  1491. /**
  1492. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1493. */
  1494. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1495. readonly name: string;
  1496. private _dracoCompression;
  1497. constructor(loader: GLTFLoader);
  1498. dispose(): void;
  1499. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1500. }
  1501. }
  1502. declare module BABYLON.GLTF2.Extensions {
  1503. /**
  1504. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1505. */
  1506. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1507. readonly name: string;
  1508. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1509. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1510. }
  1511. }
  1512. declare module BABYLON.GLTF2.Extensions {
  1513. /**
  1514. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1515. */
  1516. class KHR_materials_unlit extends GLTFLoaderExtension {
  1517. readonly name: string;
  1518. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1519. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1520. }
  1521. }
  1522. declare module BABYLON.GLTF2.Extensions {
  1523. /**
  1524. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1525. */
  1526. class KHR_lights extends GLTFLoaderExtension {
  1527. readonly name: string;
  1528. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1529. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1530. private readonly _lights;
  1531. }
  1532. }
  1533. declare module BABYLON.GLTF2.Extensions {
  1534. /**
  1535. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1536. */
  1537. class KHR_texture_transform extends GLTFLoaderExtension {
  1538. readonly name: string;
  1539. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1540. }
  1541. }