babylon.glTF2FileLoader.d.ts 32 KB

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