babylonjs.loaders.d.ts 62 KB

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