babylonjs.loaders.d.ts 57 KB

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