babylonjs.loaders.module.d.ts 57 KB

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