babylonjs.loaders.d.ts 57 KB

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