babylon.glTF2FileLoader.d.ts 33 KB

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