babylon.glTFFileLoader.d.ts 58 KB

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