babylonjs.loaders.d.ts 62 KB

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