babylonjs.loaders.module.d.ts 57 KB

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