babylon.glTFFileLoader.d.ts 52 KB

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