babylonjs.loaders.module.d.ts 57 KB

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