babylonjs.loaders.module.d.ts 62 KB

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