babylon.glTF2FileLoader.d.ts 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. declare module BABYLON {
  2. /**
  3. * Mode that determines the coordinate system to use.
  4. */
  5. enum GLTFLoaderCoordinateSystemMode {
  6. /**
  7. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8. */
  9. AUTO = 0,
  10. /**
  11. * Sets the useRightHandedSystem flag on the scene.
  12. */
  13. FORCE_RIGHT_HANDED = 1,
  14. }
  15. /**
  16. * Mode that determines what animations will start.
  17. */
  18. enum GLTFLoaderAnimationStartMode {
  19. /**
  20. * No animation will start.
  21. */
  22. NONE = 0,
  23. /**
  24. * The first animation will start.
  25. */
  26. FIRST = 1,
  27. /**
  28. * All animations will start.
  29. */
  30. ALL = 2,
  31. }
  32. /**
  33. * Interface that contains the data for the glTF asset.
  34. */
  35. interface IGLTFLoaderData {
  36. /**
  37. * JSON that represents the glTF.
  38. */
  39. json: Object;
  40. /**
  41. * The BIN chunk of a binary glTF
  42. */
  43. bin: Nullable<ArrayBufferView>;
  44. }
  45. /**
  46. * Interface for extending the loader.
  47. */
  48. interface IGLTFLoaderExtension {
  49. /**
  50. * The name of this extension.
  51. */
  52. readonly name: string;
  53. /**
  54. * Defines whether this extension is enabled.
  55. */
  56. enabled: boolean;
  57. }
  58. /**
  59. * Loader state.
  60. */
  61. enum GLTFLoaderState {
  62. /**
  63. * The asset is loading.
  64. */
  65. LOADING = 0,
  66. /**
  67. * The asset is ready for rendering.
  68. */
  69. READY = 1,
  70. /**
  71. * The asset is completely loaded.
  72. */
  73. COMPLETE = 2,
  74. }
  75. /**
  76. * Loader interface.
  77. */
  78. interface IGLTFLoader extends IDisposable {
  79. /**
  80. * Mode that determines the coordinate system to use.
  81. */
  82. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  83. /**
  84. * Mode that determines what animations will start.
  85. */
  86. animationStartMode: GLTFLoaderAnimationStartMode;
  87. /**
  88. * Defines if the loader should compile materials.
  89. */
  90. compileMaterials: boolean;
  91. /**
  92. * Defines if the loader should also compile materials with clip planes.
  93. */
  94. useClipPlane: boolean;
  95. /**
  96. * Defines if the loader should compile shadow generators.
  97. */
  98. compileShadowGenerators: boolean;
  99. /**
  100. * Defines if the Alpha blended materials are only applied as coverage.
  101. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  102. * If true, no extra effects are applied to transparent pixels.
  103. */
  104. transparencyAsCoverage: boolean;
  105. /**
  106. * Function called before loading a url referenced by the asset.
  107. */
  108. preprocessUrlAsync: (url: string) => Promise<string>;
  109. /**
  110. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  111. */
  112. onMeshLoadedObservable: Observable<AbstractMesh>;
  113. /**
  114. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  115. */
  116. onTextureLoadedObservable: Observable<BaseTexture>;
  117. /**
  118. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  119. */
  120. onMaterialLoadedObservable: Observable<Material>;
  121. /**
  122. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  123. */
  124. onCameraLoadedObservable: Observable<Camera>;
  125. /**
  126. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  127. * For assets with LODs, raised when all of the LODs are complete.
  128. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  129. */
  130. onCompleteObservable: Observable<IGLTFLoader>;
  131. /**
  132. * Observable raised after the loader is disposed.
  133. */
  134. onDisposeObservable: Observable<IGLTFLoader>;
  135. /**
  136. * Observable raised after a loader extension is created.
  137. * Set additional options for a loader extension in this event.
  138. */
  139. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  140. /**
  141. * Loader state or null if the loader is not active.
  142. */
  143. state: Nullable<GLTFLoaderState>;
  144. /**
  145. * Imports meshes from the given data and adds them to the scene.
  146. */
  147. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  148. meshes: AbstractMesh[];
  149. particleSystems: ParticleSystem[];
  150. skeletons: Skeleton[];
  151. animationGroups: AnimationGroup[];
  152. }>;
  153. /**
  154. * Loads all objects from the given data and adds them to the scene.
  155. */
  156. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  157. }
  158. /**
  159. * File loader for loading glTF files into a scene.
  160. */
  161. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  162. /**
  163. * Factory function that creates a glTF 1.0 loader
  164. */
  165. static CreateGLTFLoaderV1: () => IGLTFLoader;
  166. /**
  167. * Factory function that creates a glTF 2.0 loader
  168. */
  169. static CreateGLTFLoaderV2: () => IGLTFLoader;
  170. /**
  171. * Raised when the asset has been parsed
  172. */
  173. onParsedObservable: Observable<IGLTFLoaderData>;
  174. private _onParsedObserver;
  175. /**
  176. * Raised when the asset has been parsed
  177. */
  178. onParsed: (loaderData: IGLTFLoaderData) => void;
  179. /**
  180. * 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.
  181. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  182. * Defaults to true.
  183. */
  184. static IncrementalLoading: boolean;
  185. /**
  186. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  187. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  188. */
  189. static HomogeneousCoordinates: boolean;
  190. /**
  191. * The coordinate system mode. Defaults to AUTO.
  192. */
  193. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  194. /**
  195. * The animation start mode. Defaults to FIRST.
  196. */
  197. animationStartMode: GLTFLoaderAnimationStartMode;
  198. /**
  199. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  200. */
  201. compileMaterials: boolean;
  202. /**
  203. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  204. */
  205. useClipPlane: boolean;
  206. /**
  207. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  208. */
  209. compileShadowGenerators: boolean;
  210. /**
  211. * Defines if the Alpha blended materials are only applied as coverage.
  212. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  213. * If true, no extra effects are applied to transparent pixels.
  214. */
  215. transparencyAsCoverage: boolean;
  216. /**
  217. * Function called before loading a url referenced by the asset.
  218. */
  219. preprocessUrlAsync: (url: string) => Promise<string>;
  220. /**
  221. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  222. */
  223. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  224. private _onMeshLoadedObserver;
  225. /**
  226. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  227. */
  228. onMeshLoaded: (mesh: AbstractMesh) => void;
  229. /**
  230. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  231. */
  232. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  233. private _onTextureLoadedObserver;
  234. /**
  235. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  236. */
  237. onTextureLoaded: (texture: BaseTexture) => void;
  238. /**
  239. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  240. */
  241. readonly onMaterialLoadedObservable: Observable<Material>;
  242. private _onMaterialLoadedObserver;
  243. /**
  244. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  245. */
  246. onMaterialLoaded: (material: Material) => void;
  247. /**
  248. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  249. */
  250. readonly onCameraLoadedObservable: Observable<Camera>;
  251. private _onCameraLoadedObserver;
  252. /**
  253. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  254. */
  255. onCameraLoaded: (camera: Camera) => void;
  256. /**
  257. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  258. * For assets with LODs, raised when all of the LODs are complete.
  259. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  260. */
  261. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  262. private _onCompleteObserver;
  263. /**
  264. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  265. */
  266. onComplete: () => void;
  267. /**
  268. * Observable raised after the loader is disposed.
  269. */
  270. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  271. private _onDisposeObserver;
  272. /**
  273. * Callback raised after the loader is disposed.
  274. */
  275. onDispose: () => void;
  276. /**
  277. * Observable raised after a loader extension is created.
  278. * Set additional options for a loader extension in this event.
  279. */
  280. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  281. private _onExtensionLoadedObserver;
  282. /**
  283. * Callback raised after a loader extension is created.
  284. */
  285. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  286. /**
  287. * Returns a promise that resolves when the asset is completely loaded.
  288. * @returns a promise that resolves when the asset is completely loaded.
  289. */
  290. whenCompleteAsync(): Promise<void>;
  291. /**
  292. * The loader state or null if the loader is not active.
  293. */
  294. readonly loaderState: Nullable<GLTFLoaderState>;
  295. private _loader;
  296. /**
  297. * Name of the loader ("gltf")
  298. */
  299. name: string;
  300. /**
  301. * Supported file extensions of the loader (.gltf, .glb)
  302. */
  303. extensions: ISceneLoaderPluginExtensions;
  304. /**
  305. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  306. */
  307. dispose(): void;
  308. /**
  309. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  310. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  311. * @param scene the scene the meshes should be added to
  312. * @param data the glTF data to load
  313. * @param rootUrl root url to load from
  314. * @param onProgress event that fires when loading progress has occured
  315. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  316. */
  317. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  318. meshes: AbstractMesh[];
  319. particleSystems: ParticleSystem[];
  320. skeletons: Skeleton[];
  321. animationGroups: AnimationGroup[];
  322. }>;
  323. /**
  324. * Imports all objects from the loaded glTF data and adds them to the scene
  325. * @param scene the scene the objects should be added to
  326. * @param data the glTF data to load
  327. * @param rootUrl root url to load from
  328. * @param onProgress event that fires when loading progress has occured
  329. * @returns a promise which completes when objects have been loaded to the scene
  330. */
  331. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  332. /**
  333. * Load into an asset container.
  334. * @param scene The scene to load into
  335. * @param data The data to import
  336. * @param rootUrl The root url for scene and resources
  337. * @param onProgress The callback when the load progresses
  338. * @returns The loaded asset container
  339. */
  340. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  341. /**
  342. * If the data string can be loaded directly.
  343. * @param data string contianing the file data
  344. * @returns if the data can be loaded directly
  345. */
  346. canDirectLoad(data: string): boolean;
  347. /**
  348. * Rewrites a url by combining a root url and response url.
  349. */
  350. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  351. /**
  352. * Instantiates a glTF file loader plugin.
  353. * @returns the created plugin
  354. */
  355. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  356. private _parse(data);
  357. private _getLoader(loaderData);
  358. private static _parseBinary(data);
  359. private static _parseV1(binaryReader);
  360. private static _parseV2(binaryReader);
  361. private static _parseVersion(version);
  362. private static _compareVersion(a, b);
  363. private static _decodeBufferToText(buffer);
  364. }
  365. }
  366. declare module BABYLON.GLTF2 {
  367. /** @hidden */
  368. interface _IArrayItem {
  369. _index: number;
  370. }
  371. /** @hidden */
  372. class _ArrayItem {
  373. /** @hidden */
  374. static Assign(values?: _IArrayItem[]): void;
  375. }
  376. }
  377. declare module BABYLON.GLTF2 {
  378. /** @hidden */
  379. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  380. _data?: Promise<ArrayBufferView>;
  381. _babylonVertexBuffer?: Promise<VertexBuffer>;
  382. }
  383. /** @hidden */
  384. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  385. }
  386. /** @hidden */
  387. interface _ILoaderAnimationSamplerData {
  388. input: Float32Array;
  389. interpolation: AnimationSamplerInterpolation;
  390. output: Float32Array;
  391. }
  392. /** @hidden */
  393. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  394. _data: Promise<_ILoaderAnimationSamplerData>;
  395. }
  396. /** @hidden */
  397. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  398. channels: _ILoaderAnimationChannel[];
  399. samplers: _ILoaderAnimationSampler[];
  400. _babylonAnimationGroup?: AnimationGroup;
  401. }
  402. /** @hidden */
  403. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  404. _data?: Promise<ArrayBufferView>;
  405. }
  406. /** @hidden */
  407. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  408. _data?: Promise<ArrayBufferView>;
  409. _babylonBuffer?: Promise<Buffer>;
  410. }
  411. /** @hidden */
  412. interface _ILoaderCamera extends ICamera, _IArrayItem {
  413. }
  414. /** @hidden */
  415. interface _ILoaderImage extends IImage, _IArrayItem {
  416. _objectURL?: Promise<string>;
  417. }
  418. /** @hidden */
  419. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  420. _babylonData?: {
  421. [drawMode: number]: {
  422. material: Material;
  423. meshes: AbstractMesh[];
  424. loaded: Promise<void>;
  425. };
  426. };
  427. }
  428. /** @hidden */
  429. interface _ILoaderMesh extends IMesh, _IArrayItem {
  430. primitives: _ILoaderMeshPrimitive[];
  431. }
  432. /** @hidden */
  433. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  434. }
  435. /** @hidden */
  436. interface _ILoaderNode extends INode, _IArrayItem {
  437. _parent: _ILoaderNode;
  438. _babylonMesh?: Mesh;
  439. _primitiveBabylonMeshes?: Mesh[];
  440. _babylonBones?: Bone[];
  441. _numMorphTargets?: number;
  442. }
  443. /** @hidden */
  444. interface _ILoaderSamplerData {
  445. noMipMaps: boolean;
  446. samplingMode: number;
  447. wrapU: number;
  448. wrapV: number;
  449. }
  450. /** @hidden */
  451. interface _ILoaderSampler extends ISampler, _IArrayItem {
  452. _data?: _ILoaderSamplerData;
  453. }
  454. /** @hidden */
  455. interface _ILoaderScene extends IScene, _IArrayItem {
  456. }
  457. /** @hidden */
  458. interface _ILoaderSkin extends ISkin, _IArrayItem {
  459. _babylonSkeleton?: Skeleton;
  460. _loaded?: Promise<void>;
  461. }
  462. /** @hidden */
  463. interface _ILoaderTexture extends ITexture, _IArrayItem {
  464. }
  465. /** @hidden */
  466. interface _ILoaderGLTF extends IGLTF {
  467. accessors?: _ILoaderAccessor[];
  468. animations?: _ILoaderAnimation[];
  469. buffers?: _ILoaderBuffer[];
  470. bufferViews?: _ILoaderBufferView[];
  471. cameras?: _ILoaderCamera[];
  472. images?: _ILoaderImage[];
  473. materials?: _ILoaderMaterial[];
  474. meshes?: _ILoaderMesh[];
  475. nodes?: _ILoaderNode[];
  476. samplers?: _ILoaderSampler[];
  477. scenes?: _ILoaderScene[];
  478. skins?: _ILoaderSkin[];
  479. textures?: _ILoaderTexture[];
  480. }
  481. }
  482. /**
  483. * Defines the module used to import/export glTF 2.0 assets
  484. */
  485. declare module BABYLON.GLTF2 {
  486. /**
  487. * Loader for loading a glTF 2.0 asset
  488. */
  489. class GLTFLoader implements IGLTFLoader {
  490. /** @hidden */
  491. _gltf: _ILoaderGLTF;
  492. /** @hidden */
  493. _babylonScene: Scene;
  494. /** @hidden */
  495. _completePromises: Promise<void>[];
  496. private _disposed;
  497. private _state;
  498. private _extensions;
  499. private _rootUrl;
  500. private _rootBabylonMesh;
  501. private _defaultSampler;
  502. private _defaultBabylonMaterials;
  503. private _progressCallback?;
  504. private _requests;
  505. private static _ExtensionNames;
  506. private static _ExtensionFactories;
  507. /** @hidden */
  508. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  509. /**
  510. * Mode that determines the coordinate system to use.
  511. */
  512. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  513. /**
  514. * Mode that determines what animations will start.
  515. */
  516. animationStartMode: GLTFLoaderAnimationStartMode;
  517. /**
  518. * Defines if the loader should compile materials.
  519. */
  520. compileMaterials: boolean;
  521. /**
  522. * Defines if the loader should also compile materials with clip planes.
  523. */
  524. useClipPlane: boolean;
  525. /**
  526. * Defines if the loader should compile shadow generators.
  527. */
  528. compileShadowGenerators: boolean;
  529. /**
  530. * Defines if the Alpha blended materials are only applied as coverage.
  531. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  532. * If true, no extra effects are applied to transparent pixels.
  533. */
  534. transparencyAsCoverage: boolean;
  535. /**
  536. * Function called before loading a url referenced by the asset.
  537. */
  538. preprocessUrlAsync: (url: string) => Promise<string>;
  539. /**
  540. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  541. */
  542. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  543. /**
  544. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  545. */
  546. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  547. /**
  548. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  549. */
  550. readonly onMaterialLoadedObservable: Observable<Material>;
  551. /**
  552. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  553. */
  554. readonly onCameraLoadedObservable: Observable<Camera>;
  555. /**
  556. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  557. * For assets with LODs, raised when all of the LODs are complete.
  558. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  559. */
  560. readonly onCompleteObservable: Observable<IGLTFLoader>;
  561. /**
  562. * Observable raised after the loader is disposed.
  563. */
  564. readonly onDisposeObservable: Observable<IGLTFLoader>;
  565. /**
  566. * Observable raised after a loader extension is created.
  567. * Set additional options for a loader extension in this event.
  568. */
  569. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  570. /**
  571. * Loader state or null if the loader is not active.
  572. */
  573. readonly state: Nullable<GLTFLoaderState>;
  574. /**
  575. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  576. */
  577. dispose(): void;
  578. /**
  579. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  580. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  581. * @param scene the scene the meshes should be added to
  582. * @param data the glTF data to load
  583. * @param rootUrl root url to load from
  584. * @param onProgress event that fires when loading progress has occured
  585. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  586. */
  587. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  588. meshes: AbstractMesh[];
  589. particleSystems: ParticleSystem[];
  590. skeletons: Skeleton[];
  591. animationGroups: AnimationGroup[];
  592. }>;
  593. /**
  594. * Imports all objects from the loaded glTF data and adds them to the scene
  595. * @param scene the scene the objects should be added to
  596. * @param data the glTF data to load
  597. * @param rootUrl root url to load from
  598. * @param onProgress event that fires when loading progress has occured
  599. * @returns a promise which completes when objects have been loaded to the scene
  600. */
  601. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  602. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  603. private _loadData(data);
  604. private _setupData();
  605. private _loadExtensions();
  606. private _checkExtensions();
  607. private _createRootNode();
  608. private _loadNodesAsync(nodes);
  609. /** @hidden */
  610. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  611. private _forEachPrimitive(node, callback);
  612. private _getMeshes();
  613. private _getSkeletons();
  614. private _getAnimationGroups();
  615. private _startAnimations();
  616. /** @hidden */
  617. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  618. private _loadMeshAsync(context, node, mesh, babylonMesh);
  619. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  620. private _loadVertexDataAsync(context, primitive, babylonMesh);
  621. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  622. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  623. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  624. private static _LoadTransform(node, babylonNode);
  625. private _loadSkinAsync(context, node, mesh, skin);
  626. private _loadBones(context, skin);
  627. private _loadBone(node, skin, babylonBones);
  628. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  629. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  630. private _getNodeMatrix(node);
  631. private _loadCamera(context, camera, babylonMesh);
  632. private _loadAnimationsAsync();
  633. private _loadAnimationAsync(context, animation);
  634. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  635. private _loadAnimationSamplerAsync(context, sampler);
  636. private _loadBufferAsync(context, buffer);
  637. /** @hidden */
  638. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  639. private _loadIndicesAccessorAsync(context, accessor);
  640. private _loadFloatAccessorAsync(context, accessor);
  641. /** @hidden */
  642. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  643. private _loadVertexAccessorAsync(context, accessor, kind);
  644. private _getDefaultMaterial(drawMode);
  645. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  646. /** @hidden */
  647. _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  648. /** @hidden */
  649. _createMaterial(name: string, drawMode: number): PBRMaterial;
  650. /** @hidden */
  651. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  652. /** @hidden */
  653. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  654. /** @hidden */
  655. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  656. private _loadSampler(context, sampler);
  657. private _loadImageAsync(context, image);
  658. /** @hidden */
  659. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  660. private _onProgress();
  661. /** @hidden */
  662. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  663. private static _GetTextureWrapMode(context, mode);
  664. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  665. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  666. private static _GetNumComponents(context, type);
  667. private static _ValidateUri(uri);
  668. private static _GetDrawMode(context, mode);
  669. private _compileMaterialsAsync();
  670. private _compileShadowGeneratorsAsync();
  671. private _clear();
  672. /** @hidden */
  673. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  674. }
  675. }
  676. declare module BABYLON.GLTF2 {
  677. /**
  678. * Abstract class that can be implemented to extend existing glTF loader behavior.
  679. */
  680. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  681. enabled: boolean;
  682. readonly abstract name: string;
  683. protected _loader: GLTFLoader;
  684. constructor(loader: GLTFLoader);
  685. dispose(): void;
  686. /** Override this method to modify the default behavior for loading scenes. */
  687. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  688. /** Override this method to modify the default behavior for loading nodes. */
  689. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  690. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  691. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  692. /** Override this method to modify the default behavior for loading materials. */
  693. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  694. /** Override this method to modify the default behavior for loading uris. */
  695. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  696. /** Helper method called by a loader extension to load an glTF extension. */
  697. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>>;
  698. /** Helper method called by the loader to allow extensions to override loading scenes. */
  699. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  700. /** Helper method called by the loader to allow extensions to override loading nodes. */
  701. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  702. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  703. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  704. /** Helper method called by the loader to allow extensions to override loading materials. */
  705. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  706. /** Helper method called by the loader to allow extensions to override loading uris. */
  707. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  708. }
  709. }
  710. /**
  711. * Defines the module of the glTF 2.0 loader extensions.
  712. */
  713. declare module BABYLON.GLTF2.Extensions {
  714. }
  715. declare module BABYLON.GLTF2.Extensions {
  716. /**
  717. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  718. */
  719. class MSFT_lod extends GLTFLoaderExtension {
  720. readonly name: string;
  721. /**
  722. * Maximum number of LODs to load, starting from the lowest LOD.
  723. */
  724. maxLODsToLoad: number;
  725. private _loadingNodeLOD;
  726. private _loadNodeSignals;
  727. private _loadingMaterialLOD;
  728. private _loadMaterialSignals;
  729. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  730. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  731. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  732. /**
  733. * Gets an array of LOD properties from lowest to highest.
  734. */
  735. private _getLODs<T>(context, property, array, ids);
  736. }
  737. }
  738. declare module BABYLON.GLTF2.Extensions {
  739. /** @hidden */
  740. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  741. readonly name: string;
  742. constructor(loader: GLTFLoader);
  743. private _onMaterialLoaded;
  744. }
  745. }
  746. declare module BABYLON.GLTF2.Extensions {
  747. /** @hidden */
  748. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  749. readonly name: string;
  750. constructor(loader: GLTFLoader);
  751. private _onMaterialLoaded;
  752. }
  753. }
  754. declare module BABYLON.GLTF2.Extensions {
  755. /**
  756. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  757. */
  758. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  759. readonly name: string;
  760. private _dracoCompression;
  761. constructor(loader: GLTFLoader);
  762. dispose(): void;
  763. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  764. }
  765. }
  766. declare module BABYLON.GLTF2.Extensions {
  767. /**
  768. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  769. */
  770. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  771. readonly name: string;
  772. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  773. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  774. }
  775. }
  776. declare module BABYLON.GLTF2.Extensions {
  777. /**
  778. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  779. */
  780. class KHR_materials_unlit extends GLTFLoaderExtension {
  781. readonly name: string;
  782. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  783. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  784. }
  785. }
  786. declare module BABYLON.GLTF2.Extensions {
  787. /**
  788. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  789. */
  790. class KHR_lights extends GLTFLoaderExtension {
  791. readonly name: string;
  792. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  793. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  794. private readonly _lights;
  795. }
  796. }