babylon.glTF2FileLoader.d.ts 33 KB

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