babylon.glTF2FileLoader.d.ts 32 KB

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