babylonjs.loaders.module.d.ts 55 KB

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