babylonjs.loaders.module.d.ts 58 KB

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