babylon.glTFFileLoader.d.ts 55 KB

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