babylon.glTF2FileLoader.d.ts 35 KB

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