babylonjs.loaders.module.d.ts 61 KB

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