babylon.glTF2FileLoader.d.ts 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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. * Object that represents the glTF JSON.
  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. /** @hidden */
  76. interface IGLTFLoader extends IDisposable {
  77. readonly state: Nullable<GLTFLoaderState>;
  78. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  79. meshes: AbstractMesh[];
  80. particleSystems: IParticleSystem[];
  81. skeletons: Skeleton[];
  82. animationGroups: AnimationGroup[];
  83. }>;
  84. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  85. }
  86. /**
  87. * File loader for loading glTF files into a scene.
  88. */
  89. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  90. /** @hidden */
  91. static _CreateGLTFLoaderV1: (parent: GLTFFileLoader) => IGLTFLoader;
  92. /** @hidden */
  93. static _CreateGLTFLoaderV2: (parent: GLTFFileLoader) => IGLTFLoader;
  94. /**
  95. * Raised when the asset has been parsed
  96. */
  97. onParsedObservable: Observable<IGLTFLoaderData>;
  98. private _onParsedObserver;
  99. /**
  100. * Raised when the asset has been parsed
  101. */
  102. onParsed: (loaderData: IGLTFLoaderData) => void;
  103. /**
  104. * 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.
  105. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  106. * Defaults to true.
  107. * @hidden
  108. */
  109. static IncrementalLoading: boolean;
  110. /**
  111. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  112. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  113. * @hidden
  114. */
  115. static HomogeneousCoordinates: boolean;
  116. /**
  117. * The coordinate system mode. Defaults to AUTO.
  118. */
  119. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  120. /**
  121. * The animation start mode. Defaults to FIRST.
  122. */
  123. animationStartMode: GLTFLoaderAnimationStartMode;
  124. /**
  125. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  126. */
  127. compileMaterials: boolean;
  128. /**
  129. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  130. */
  131. useClipPlane: boolean;
  132. /**
  133. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  134. */
  135. compileShadowGenerators: boolean;
  136. /**
  137. * Defines if the Alpha blended materials are only applied as coverage.
  138. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  139. * If true, no extra effects are applied to transparent pixels.
  140. */
  141. transparencyAsCoverage: boolean;
  142. /**
  143. * Function called before loading a url referenced by the asset.
  144. */
  145. preprocessUrlAsync: (url: string) => Promise<string>;
  146. /**
  147. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  148. */
  149. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  150. private _onMeshLoadedObserver;
  151. /**
  152. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  153. */
  154. onMeshLoaded: (mesh: AbstractMesh) => void;
  155. /**
  156. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  157. */
  158. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  159. private _onTextureLoadedObserver;
  160. /**
  161. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  162. */
  163. onTextureLoaded: (texture: BaseTexture) => void;
  164. /**
  165. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  166. */
  167. readonly onMaterialLoadedObservable: Observable<Material>;
  168. private _onMaterialLoadedObserver;
  169. /**
  170. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  171. */
  172. onMaterialLoaded: (material: Material) => void;
  173. /**
  174. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  175. */
  176. readonly onCameraLoadedObservable: Observable<Camera>;
  177. private _onCameraLoadedObserver;
  178. /**
  179. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  180. */
  181. onCameraLoaded: (camera: Camera) => void;
  182. /**
  183. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  184. * For assets with LODs, raised when all of the LODs are complete.
  185. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  186. */
  187. readonly onCompleteObservable: Observable<void>;
  188. private _onCompleteObserver;
  189. /**
  190. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  191. * For assets with LODs, raised when all of the LODs are complete.
  192. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  193. */
  194. onComplete: () => void;
  195. /**
  196. * Observable raised when an error occurs.
  197. */
  198. readonly onErrorObservable: Observable<any>;
  199. private _onErrorObserver;
  200. /**
  201. * Callback raised when an error occurs.
  202. */
  203. onError: (reason: any) => void;
  204. /**
  205. * Observable raised after the loader is disposed.
  206. */
  207. readonly onDisposeObservable: Observable<void>;
  208. private _onDisposeObserver;
  209. /**
  210. * Callback raised after the loader is disposed.
  211. */
  212. onDispose: () => void;
  213. /**
  214. * Observable raised after a loader extension is created.
  215. * Set additional options for a loader extension in this event.
  216. */
  217. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  218. private _onExtensionLoadedObserver;
  219. /**
  220. * Callback raised after a loader extension is created.
  221. */
  222. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  223. /**
  224. * Defines if the loader logging is enabled.
  225. */
  226. loggingEnabled: boolean;
  227. /**
  228. * Defines if the loader should capture performance counters.
  229. */
  230. capturePerformanceCounters: boolean;
  231. /**
  232. * Defines if the loader should validate the asset.
  233. */
  234. validate: boolean;
  235. /**
  236. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  237. */
  238. readonly onValidatedObservable: Observable<IGLTFValidationResults>;
  239. private _onValidatedObserver;
  240. /**
  241. * Callback raised after a loader extension is created.
  242. */
  243. onValidated: (results: IGLTFValidationResults) => void;
  244. private _loader;
  245. /**
  246. * Name of the loader ("gltf")
  247. */
  248. name: string;
  249. /**
  250. * Supported file extensions of the loader (.gltf, .glb)
  251. */
  252. extensions: ISceneLoaderPluginExtensions;
  253. /**
  254. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  255. */
  256. dispose(): void;
  257. /** @hidden */
  258. _clear(): void;
  259. /**
  260. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  261. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  262. * @param scene the scene the meshes should be added to
  263. * @param data the glTF data to load
  264. * @param rootUrl root url to load from
  265. * @param onProgress event that fires when loading progress has occured
  266. * @param fileName Defines the name of the file to load
  267. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  268. */
  269. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  270. meshes: AbstractMesh[];
  271. particleSystems: IParticleSystem[];
  272. skeletons: Skeleton[];
  273. animationGroups: AnimationGroup[];
  274. }>;
  275. /**
  276. * Imports all objects from the loaded glTF data and adds them to the scene
  277. * @param scene the scene the objects should be added to
  278. * @param data the glTF data to load
  279. * @param rootUrl root url to load from
  280. * @param onProgress event that fires when loading progress has occured
  281. * @param fileName Defines the name of the file to load
  282. * @returns a promise which completes when objects have been loaded to the scene
  283. */
  284. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  285. /**
  286. * Load into an asset container.
  287. * @param scene The scene to load into
  288. * @param data The data to import
  289. * @param rootUrl The root url for scene and resources
  290. * @param onProgress The callback when the load progresses
  291. * @param fileName Defines the name of the file to load
  292. * @returns The loaded asset container
  293. */
  294. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  295. /**
  296. * If the data string can be loaded directly.
  297. * @param data string contianing the file data
  298. * @returns if the data can be loaded directly
  299. */
  300. canDirectLoad(data: string): boolean;
  301. /**
  302. * Rewrites a url by combining a root url and response url.
  303. */
  304. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  305. /**
  306. * Instantiates a glTF file loader plugin.
  307. * @returns the created plugin
  308. */
  309. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  310. /**
  311. * The loader state or null if the loader is not active.
  312. */
  313. readonly loaderState: Nullable<GLTFLoaderState>;
  314. /**
  315. * Returns a promise that resolves when the asset is completely loaded.
  316. * @returns a promise that resolves when the asset is completely loaded.
  317. */
  318. whenCompleteAsync(): Promise<void>;
  319. private _parseAsync;
  320. private _validateAsync;
  321. private _getLoader;
  322. private _unpackBinary;
  323. private _unpackBinaryV1;
  324. private _unpackBinaryV2;
  325. private static _parseVersion;
  326. private static _compareVersion;
  327. private static _decodeBufferToText;
  328. private static readonly _logSpaces;
  329. private _logIndentLevel;
  330. private _loggingEnabled;
  331. /** @hidden */
  332. _log: (message: string) => void;
  333. /** @hidden */
  334. _logOpen(message: string): void;
  335. /** @hidden */
  336. _logClose(): void;
  337. private _logEnabled;
  338. private _logDisabled;
  339. private _capturePerformanceCounters;
  340. /** @hidden */
  341. _startPerformanceCounter: (counterName: string) => void;
  342. /** @hidden */
  343. _endPerformanceCounter: (counterName: string) => void;
  344. private _startPerformanceCounterEnabled;
  345. private _startPerformanceCounterDisabled;
  346. private _endPerformanceCounterEnabled;
  347. private _endPerformanceCounterDisabled;
  348. }
  349. }
  350. declare module BABYLON.GLTF2.Loader {
  351. /**
  352. * Loader interface with an index field.
  353. */
  354. interface IArrayItem {
  355. /**
  356. * The index of this item in the array.
  357. */
  358. index: number;
  359. }
  360. /**
  361. * Loader interface with additional members.
  362. */
  363. interface IAccessor extends GLTF2.IAccessor, IArrayItem {
  364. /** @hidden */
  365. _data?: Promise<ArrayBufferView>;
  366. /** @hidden */
  367. _babylonVertexBuffer?: Promise<VertexBuffer>;
  368. }
  369. /**
  370. * Loader interface with additional members.
  371. */
  372. interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
  373. }
  374. /** @hidden */
  375. interface _IAnimationSamplerData {
  376. input: Float32Array;
  377. interpolation: AnimationSamplerInterpolation;
  378. output: Float32Array;
  379. }
  380. /**
  381. * Loader interface with additional members.
  382. */
  383. interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
  384. /** @hidden */
  385. _data?: Promise<_IAnimationSamplerData>;
  386. }
  387. /**
  388. * Loader interface with additional members.
  389. */
  390. interface IAnimation extends GLTF2.IAnimation, IArrayItem {
  391. channels: IAnimationChannel[];
  392. samplers: IAnimationSampler[];
  393. /** @hidden */
  394. _babylonAnimationGroup?: AnimationGroup;
  395. }
  396. /**
  397. * Loader interface with additional members.
  398. */
  399. interface IBuffer extends GLTF2.IBuffer, IArrayItem {
  400. /** @hidden */
  401. _data?: Promise<ArrayBufferView>;
  402. }
  403. /**
  404. * Loader interface with additional members.
  405. */
  406. interface IBufferView extends GLTF2.IBufferView, IArrayItem {
  407. /** @hidden */
  408. _data?: Promise<ArrayBufferView>;
  409. /** @hidden */
  410. _babylonBuffer?: Promise<Buffer>;
  411. }
  412. /**
  413. * Loader interface with additional members.
  414. */
  415. interface ICamera extends GLTF2.ICamera, IArrayItem {
  416. }
  417. /**
  418. * Loader interface with additional members.
  419. */
  420. interface IImage extends GLTF2.IImage, IArrayItem {
  421. /** @hidden */
  422. _data?: Promise<ArrayBufferView>;
  423. }
  424. /**
  425. * Loader interface with additional members.
  426. */
  427. interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  428. }
  429. /**
  430. * Loader interface with additional members.
  431. */
  432. interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  433. }
  434. /**
  435. * Loader interface with additional members.
  436. */
  437. interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
  438. baseColorTexture?: ITextureInfo;
  439. metallicRoughnessTexture?: ITextureInfo;
  440. }
  441. /**
  442. * Loader interface with additional members.
  443. */
  444. interface IMaterial extends GLTF2.IMaterial, IArrayItem {
  445. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  446. normalTexture?: IMaterialNormalTextureInfo;
  447. occlusionTexture?: IMaterialOcclusionTextureInfo;
  448. emissiveTexture?: ITextureInfo;
  449. /** @hidden */
  450. _babylonData?: {
  451. [drawMode: number]: {
  452. material: Material;
  453. meshes: AbstractMesh[];
  454. promise: Promise<void>;
  455. };
  456. };
  457. }
  458. /**
  459. * Loader interface with additional members.
  460. */
  461. interface IMesh extends GLTF2.IMesh, IArrayItem {
  462. primitives: IMeshPrimitive[];
  463. }
  464. /**
  465. * Loader interface with additional members.
  466. */
  467. interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
  468. }
  469. /**
  470. * Loader interface with additional members.
  471. */
  472. interface INode extends GLTF2.INode, IArrayItem {
  473. /**
  474. * The parent glTF node.
  475. */
  476. parent?: INode;
  477. /** @hidden */
  478. _babylonMesh?: Mesh;
  479. /** @hidden */
  480. _primitiveBabylonMeshes?: Mesh[];
  481. /** @hidden */
  482. _babylonBones?: Bone[];
  483. /** @hidden */
  484. _numMorphTargets?: number;
  485. }
  486. /** @hidden */
  487. interface _ISamplerData {
  488. noMipMaps: boolean;
  489. samplingMode: number;
  490. wrapU: number;
  491. wrapV: number;
  492. }
  493. /**
  494. * Loader interface with additional members.
  495. */
  496. interface ISampler extends GLTF2.ISampler, IArrayItem {
  497. /** @hidden */
  498. _data?: _ISamplerData;
  499. }
  500. /**
  501. * Loader interface with additional members.
  502. */
  503. interface IScene extends GLTF2.IScene, IArrayItem {
  504. }
  505. /**
  506. * Loader interface with additional members.
  507. */
  508. interface ISkin extends GLTF2.ISkin, IArrayItem {
  509. /** @hidden */
  510. _babylonSkeleton?: Skeleton;
  511. /** @hidden */
  512. _promise?: Promise<void>;
  513. }
  514. /**
  515. * Loader interface with additional members.
  516. */
  517. interface ITexture extends GLTF2.ITexture, IArrayItem {
  518. }
  519. /**
  520. * Loader interface with additional members.
  521. */
  522. interface ITextureInfo extends GLTF2.ITextureInfo {
  523. }
  524. /**
  525. * Loader interface with additional members.
  526. */
  527. interface IGLTF extends GLTF2.IGLTF {
  528. accessors?: IAccessor[];
  529. animations?: IAnimation[];
  530. buffers?: IBuffer[];
  531. bufferViews?: IBufferView[];
  532. cameras?: ICamera[];
  533. images?: IImage[];
  534. materials?: IMaterial[];
  535. meshes?: IMesh[];
  536. nodes?: INode[];
  537. samplers?: ISampler[];
  538. scenes?: IScene[];
  539. skins?: ISkin[];
  540. textures?: ITexture[];
  541. }
  542. }
  543. /**
  544. * Defines the module for importing and exporting glTF 2.0 assets
  545. */
  546. declare module BABYLON.GLTF2 {
  547. /**
  548. * Helper class for working with arrays when loading the glTF asset
  549. */
  550. class ArrayItem {
  551. /**
  552. * Gets an item from the given array.
  553. * @param context The context when loading the asset
  554. * @param array The array to get the item from
  555. * @param index The index to the array
  556. * @returns The array item
  557. */
  558. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  559. /**
  560. * Assign an `index` field to each item of the given array.
  561. * @param array The array of items
  562. */
  563. static Assign(array?: Loader.IArrayItem[]): void;
  564. }
  565. /**
  566. * The glTF 2.0 loader
  567. */
  568. class GLTFLoader implements IGLTFLoader {
  569. /** The glTF object parsed from the JSON. */
  570. gltf: Loader.IGLTF;
  571. /** The Babylon scene when loading the asset. */
  572. babylonScene: Scene;
  573. /** @hidden */
  574. _completePromises: Promise<any>[];
  575. private _disposed;
  576. private _parent;
  577. private _state;
  578. private _extensions;
  579. private _rootUrl;
  580. private _fileName;
  581. private _uniqueRootUrl;
  582. private _rootBabylonMesh;
  583. private _defaultBabylonMaterialData;
  584. private _progressCallback?;
  585. private _requests;
  586. private static readonly _DefaultSampler;
  587. private static _ExtensionNames;
  588. private static _ExtensionFactories;
  589. /**
  590. * Registers a loader extension.
  591. * @param name The name of the loader extension.
  592. * @param factory The factory function that creates the loader extension.
  593. */
  594. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  595. /**
  596. * Unregisters a loader extension.
  597. * @param name The name of the loader extenion.
  598. * @returns A boolean indicating whether the extension has been unregistered
  599. */
  600. static UnregisterExtension(name: string): boolean;
  601. /**
  602. * Gets the loader state.
  603. */
  604. readonly state: Nullable<GLTFLoaderState>;
  605. /** @hidden */
  606. constructor(parent: GLTFFileLoader);
  607. /** @hidden */
  608. dispose(): void;
  609. /** @hidden */
  610. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  611. meshes: AbstractMesh[];
  612. particleSystems: IParticleSystem[];
  613. skeletons: Skeleton[];
  614. animationGroups: AnimationGroup[];
  615. }>;
  616. /** @hidden */
  617. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  618. private _loadAsync;
  619. private _loadData;
  620. private _setupData;
  621. private _loadExtensions;
  622. private _checkExtensions;
  623. private _setState;
  624. private _createRootNode;
  625. /**
  626. * Loads a glTF scene.
  627. * @param context The context when loading the asset
  628. * @param scene The glTF scene property
  629. * @returns A promise that resolves when the load is complete
  630. */
  631. loadSceneAsync(context: string, scene: Loader.IScene): Promise<void>;
  632. private _forEachPrimitive;
  633. private _getMeshes;
  634. private _getSkeletons;
  635. private _getAnimationGroups;
  636. private _startAnimations;
  637. /**
  638. * Loads a glTF node.
  639. * @param context The context when loading the asset
  640. * @param node The glTF node property
  641. * @param assign A function called synchronously after parsing the glTF properties
  642. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  643. */
  644. loadNodeAsync(context: string, node: Loader.INode, assign?: (babylonMesh: Mesh) => void): Promise<Mesh>;
  645. private _loadMeshAsync;
  646. private _loadMeshPrimitiveAsync;
  647. private _loadVertexDataAsync;
  648. private _createMorphTargets;
  649. private _loadMorphTargetsAsync;
  650. private _loadMorphTargetVertexDataAsync;
  651. private static _LoadTransform;
  652. private _loadSkinAsync;
  653. private _loadBones;
  654. private _loadBone;
  655. private _loadSkinInverseBindMatricesDataAsync;
  656. private _updateBoneMatrices;
  657. private _getNodeMatrix;
  658. /**
  659. * Loads a glTF camera.
  660. * @param context The context when loading the asset
  661. * @param camera The glTF camera property
  662. * @param assign A function called synchronously after parsing the glTF properties
  663. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  664. */
  665. loadCameraAsync(context: string, camera: Loader.ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  666. private _loadAnimationsAsync;
  667. /**
  668. * Loads a glTF animation.
  669. * @param context The context when loading the asset
  670. * @param animation The glTF animation property
  671. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  672. */
  673. loadAnimationAsync(context: string, animation: Loader.IAnimation): Promise<AnimationGroup>;
  674. private _loadAnimationChannelAsync;
  675. private _loadAnimationSamplerAsync;
  676. private _loadBufferAsync;
  677. /**
  678. * Loads a glTF buffer view.
  679. * @param context The context when loading the asset
  680. * @param bufferView The glTF buffer view property
  681. * @returns A promise that resolves with the loaded data when the load is complete
  682. */
  683. loadBufferViewAsync(context: string, bufferView: Loader.IBufferView): Promise<ArrayBufferView>;
  684. private _loadIndicesAccessorAsync;
  685. private _loadFloatAccessorAsync;
  686. private _loadVertexBufferViewAsync;
  687. private _loadVertexAccessorAsync;
  688. private _loadMaterialMetallicRoughnessPropertiesAsync;
  689. /** @hidden */
  690. _loadMaterialAsync(context: string, material: Loader.IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  691. private _createDefaultMaterial;
  692. /**
  693. * Creates a Babylon material from a glTF material.
  694. * @param context The context when loading the asset
  695. * @param material The glTF material property
  696. * @param babylonDrawMode The draw mode for the Babylon material
  697. * @returns The Babylon material
  698. */
  699. createMaterial(context: string, material: Loader.IMaterial, babylonDrawMode: number): Material;
  700. /**
  701. * Loads properties from a glTF material into a Babylon material.
  702. * @param context The context when loading the asset
  703. * @param material The glTF material property
  704. * @param babylonMaterial The Babylon material
  705. * @returns A promise that resolves when the load is complete
  706. */
  707. loadMaterialPropertiesAsync(context: string, material: Loader.IMaterial, babylonMaterial: Material): Promise<void>;
  708. /**
  709. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  710. * @param context The context when loading the asset
  711. * @param material The glTF material property
  712. * @param babylonMaterial The Babylon material
  713. * @returns A promise that resolves when the load is complete
  714. */
  715. loadMaterialBasePropertiesAsync(context: string, material: Loader.IMaterial, babylonMaterial: Material): Promise<void>;
  716. /**
  717. * Loads the alpha properties from a glTF material into a Babylon material.
  718. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  719. * @param context The context when loading the asset
  720. * @param material The glTF material property
  721. * @param babylonMaterial The Babylon material
  722. */
  723. loadMaterialAlphaProperties(context: string, material: Loader.IMaterial, babylonMaterial: Material): void;
  724. /**
  725. * Loads a glTF texture info.
  726. * @param context The context when loading the asset
  727. * @param textureInfo The glTF texture info property
  728. * @param assign A function called synchronously after parsing the glTF properties
  729. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  730. */
  731. loadTextureInfoAsync(context: string, textureInfo: Loader.ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  732. private _loadTextureAsync;
  733. private _loadSampler;
  734. /**
  735. * Loads a glTF image.
  736. * @param context The context when loading the asset
  737. * @param image The glTF image property
  738. * @returns A promise that resolves with the loaded data when the load is complete
  739. */
  740. loadImageAsync(context: string, image: Loader.IImage): Promise<ArrayBufferView>;
  741. /**
  742. * Loads a glTF uri.
  743. * @param context The context when loading the asset
  744. * @param uri The base64 or relative uri
  745. * @returns A promise that resolves with the loaded data when the load is complete
  746. */
  747. loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  748. private _onProgress;
  749. private static _GetTextureWrapMode;
  750. private static _GetTextureSamplingMode;
  751. private static _GetTypedArray;
  752. private static _GetNumComponents;
  753. private static _ValidateUri;
  754. private static _GetDrawMode;
  755. private _compileMaterialsAsync;
  756. private _compileShadowGeneratorsAsync;
  757. private _forEachExtensions;
  758. private _applyExtensions;
  759. private _extensionsOnLoading;
  760. private _extensionsOnReady;
  761. private _extensionsLoadSceneAsync;
  762. private _extensionsLoadNodeAsync;
  763. private _extensionsLoadCameraAsync;
  764. private _extensionsLoadVertexDataAsync;
  765. private _extensionsLoadMaterialAsync;
  766. private _extensionsCreateMaterial;
  767. private _extensionsLoadMaterialPropertiesAsync;
  768. private _extensionsLoadTextureInfoAsync;
  769. private _extensionsLoadAnimationAsync;
  770. private _extensionsLoadUriAsync;
  771. /**
  772. * Helper method called by a loader extension to load an glTF extension.
  773. * @param context The context when loading the asset
  774. * @param property The glTF property to load the extension from
  775. * @param extensionName The name of the extension to load
  776. * @param actionAsync The action to run
  777. * @returns The promise returned by actionAsync or null if the extension does not exist
  778. */
  779. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  780. /**
  781. * Helper method called by a loader extension to load a glTF extra.
  782. * @param context The context when loading the asset
  783. * @param property The glTF property to load the extra from
  784. * @param extensionName The name of the extension to load
  785. * @param actionAsync The action to run
  786. * @returns The promise returned by actionAsync or null if the extra does not exist
  787. */
  788. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  789. /**
  790. * Increments the indentation level and logs a message.
  791. * @param message The message to log
  792. */
  793. logOpen(message: string): void;
  794. /**
  795. * Decrements the indentation level.
  796. */
  797. logClose(): void;
  798. /**
  799. * Logs a message
  800. * @param message The message to log
  801. */
  802. log(message: string): void;
  803. /**
  804. * Starts a performance counter.
  805. * @param counterName The name of the performance counter
  806. */
  807. startPerformanceCounter(counterName: string): void;
  808. /**
  809. * Ends a performance counter.
  810. * @param counterName The name of the performance counter
  811. */
  812. endPerformanceCounter(counterName: string): void;
  813. }
  814. }
  815. declare module BABYLON.GLTF2 {
  816. /**
  817. * Interface for a glTF loader extension.
  818. */
  819. interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  820. /**
  821. * Called after the loader state changes to LOADING.
  822. */
  823. onLoading?(): void;
  824. /**
  825. * Called after the loader state changes to READY.
  826. */
  827. onReady?(): void;
  828. /**
  829. * Define this method to modify the default behavior when loading scenes.
  830. * @param context The context when loading the asset
  831. * @param scene The glTF scene property
  832. * @returns A promise that resolves when the load is complete or null if not handled
  833. */
  834. loadSceneAsync?(context: string, scene: Loader.IScene): Nullable<Promise<void>>;
  835. /**
  836. * Define this method to modify the default behavior when loading nodes.
  837. * @param context The context when loading the asset
  838. * @param node The glTF node property
  839. * @param assign A function called synchronously after parsing the glTF properties
  840. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete or null if not handled
  841. */
  842. loadNodeAsync?(context: string, node: Loader.INode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  843. /**
  844. * Define this method to modify the default behavior when loading cameras.
  845. * @param context The context when loading the asset
  846. * @param camera The glTF camera property
  847. * @param assign A function called synchronously after parsing the glTF properties
  848. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  849. */
  850. loadCameraAsync?(context: string, camera: Loader.ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  851. /**
  852. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  853. * @param context The context when loading the asset
  854. * @param primitive The glTF mesh primitive property
  855. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  856. */
  857. _loadVertexDataAsync?(context: string, primitive: Loader.IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  858. /**
  859. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  860. * @param context The context when loading the asset
  861. * @param material The glTF material property
  862. * @param assign A function called synchronously after parsing the glTF properties
  863. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  864. */
  865. _loadMaterialAsync?(context: string, material: Loader.IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  866. /**
  867. * Define this method to modify the default behavior when creating materials.
  868. * @param context The context when loading the asset
  869. * @param material The glTF material property
  870. * @param babylonDrawMode The draw mode for the Babylon material
  871. * @returns The Babylon material or null if not handled
  872. */
  873. createMaterial?(context: string, material: Loader.IMaterial, babylonDrawMode: number): Nullable<Material>;
  874. /**
  875. * Define this method to modify the default behavior when loading material properties.
  876. * @param context The context when loading the asset
  877. * @param material The glTF material property
  878. * @param babylonMaterial The Babylon material
  879. * @returns A promise that resolves when the load is complete or null if not handled
  880. */
  881. loadMaterialPropertiesAsync?(context: string, material: Loader.IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  882. /**
  883. * Define this method to modify the default behavior when loading texture infos.
  884. * @param context The context when loading the asset
  885. * @param textureInfo The glTF texture info property
  886. * @param assign A function called synchronously after parsing the glTF properties
  887. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  888. */
  889. loadTextureInfoAsync?(context: string, textureInfo: Loader.ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  890. /**
  891. * Define this method to modify the default behavior when loading animations.
  892. * @param context The context when loading the asset
  893. * @param animation The glTF animation property
  894. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  895. */
  896. loadAnimationAsync?(context: string, animation: Loader.IAnimation): Nullable<Promise<AnimationGroup>>;
  897. /**
  898. * Define this method to modify the default behavior when loading uris.
  899. * @param context The context when loading the asset
  900. * @param uri The uri to load
  901. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  902. */
  903. _loadUriAsync?(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  904. }
  905. }
  906. /**
  907. * Defines the module for the built-in glTF 2.0 loader extensions.
  908. */
  909. declare module BABYLON.GLTF2.Loader.Extensions {
  910. }
  911. declare module BABYLON.GLTF2.Loader.Extensions {
  912. /**
  913. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  914. */
  915. class MSFT_lod implements IGLTFLoaderExtension {
  916. /** The name of this extension. */
  917. readonly name: string;
  918. /** Defines whether this extension is enabled. */
  919. enabled: boolean;
  920. /**
  921. * Maximum number of LODs to load, starting from the lowest LOD.
  922. */
  923. maxLODsToLoad: number;
  924. /**
  925. * Observable raised when all node LODs of one level are loaded.
  926. * The event data is the index of the loaded LOD starting from zero.
  927. * Dispose the loader to cancel the loading of the next level of LODs.
  928. */
  929. onNodeLODsLoadedObservable: Observable<number>;
  930. /**
  931. * Observable raised when all material LODs of one level are loaded.
  932. * The event data is the index of the loaded LOD starting from zero.
  933. * Dispose the loader to cancel the loading of the next level of LODs.
  934. */
  935. onMaterialLODsLoadedObservable: Observable<number>;
  936. private _loader;
  937. private _nodeIndexLOD;
  938. private _nodeSignalLODs;
  939. private _nodePromiseLODs;
  940. private _materialIndexLOD;
  941. private _materialSignalLODs;
  942. private _materialPromiseLODs;
  943. /** @hidden */
  944. constructor(loader: GLTFLoader);
  945. /** @hidden */
  946. dispose(): void;
  947. /** @hidden */
  948. onReady(): void;
  949. /** @hidden */
  950. loadNodeAsync(context: string, node: INode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  951. /** @hidden */
  952. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  953. /** @hidden */
  954. _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  955. /**
  956. * Gets an array of LOD properties from lowest to highest.
  957. */
  958. private _getLODs;
  959. private _disposeUnusedMaterials;
  960. }
  961. }
  962. declare module BABYLON.GLTF2.Loader.Extensions {
  963. /** @hidden */
  964. class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  965. readonly name: string;
  966. enabled: boolean;
  967. private _loader;
  968. constructor(loader: GLTFLoader);
  969. dispose(): void;
  970. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  971. }
  972. }
  973. declare module BABYLON.GLTF2.Loader.Extensions {
  974. /** @hidden */
  975. class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  976. readonly name: string;
  977. enabled: boolean;
  978. private _loader;
  979. constructor(loader: GLTFLoader);
  980. dispose(): void;
  981. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  982. }
  983. }
  984. declare module BABYLON.GLTF2.Loader.Extensions {
  985. /**
  986. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  987. */
  988. class MSFT_audio_emitter implements IGLTFLoaderExtension {
  989. /** The name of this extension. */
  990. readonly name: string;
  991. /** Defines whether this extension is enabled. */
  992. enabled: boolean;
  993. private _loader;
  994. private _clips;
  995. private _emitters;
  996. /** @hidden */
  997. constructor(loader: GLTFLoader);
  998. /** @hidden */
  999. dispose(): void;
  1000. /** @hidden */
  1001. onLoading(): void;
  1002. /** @hidden */
  1003. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1004. /** @hidden */
  1005. loadNodeAsync(context: string, node: INode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  1006. /** @hidden */
  1007. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1008. private _loadClipAsync;
  1009. private _loadEmitterAsync;
  1010. private _getEventAction;
  1011. private _loadAnimationEventAsync;
  1012. }
  1013. }
  1014. declare module BABYLON.GLTF2.Loader.Extensions {
  1015. /**
  1016. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1017. */
  1018. class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1019. /** The name of this extension. */
  1020. readonly name: string;
  1021. /** Defines whether this extension is enabled. */
  1022. enabled: boolean;
  1023. private _loader;
  1024. private _dracoCompression?;
  1025. /** @hidden */
  1026. constructor(loader: GLTFLoader);
  1027. /** @hidden */
  1028. dispose(): void;
  1029. /** @hidden */
  1030. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1031. }
  1032. }
  1033. declare module BABYLON.GLTF2.Loader.Extensions {
  1034. /**
  1035. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1036. */
  1037. class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1038. /** The name of this extension. */
  1039. readonly name: string;
  1040. /** Defines whether this extension is enabled. */
  1041. enabled: boolean;
  1042. private _loader;
  1043. /** @hidden */
  1044. constructor(loader: GLTFLoader);
  1045. /** @hidden */
  1046. dispose(): void;
  1047. /** @hidden */
  1048. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1049. private _loadSpecularGlossinessPropertiesAsync;
  1050. }
  1051. }
  1052. declare module BABYLON.GLTF2.Loader.Extensions {
  1053. /**
  1054. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1055. */
  1056. class KHR_materials_unlit implements IGLTFLoaderExtension {
  1057. /** The name of this extension. */
  1058. readonly name: string;
  1059. /** Defines whether this extension is enabled. */
  1060. enabled: boolean;
  1061. private _loader;
  1062. /** @hidden */
  1063. constructor(loader: GLTFLoader);
  1064. /** @hidden */
  1065. dispose(): void;
  1066. /** @hidden */
  1067. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1068. private _loadUnlitPropertiesAsync;
  1069. }
  1070. }
  1071. declare module BABYLON.GLTF2.Loader.Extensions {
  1072. /**
  1073. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1074. */
  1075. class KHR_lights implements IGLTFLoaderExtension {
  1076. /** The name of this extension. */
  1077. readonly name: string;
  1078. /** Defines whether this extension is enabled. */
  1079. enabled: boolean;
  1080. private _loader;
  1081. private _lights?;
  1082. /** @hidden */
  1083. constructor(loader: GLTFLoader);
  1084. /** @hidden */
  1085. dispose(): void;
  1086. /** @hidden */
  1087. onLoading(): void;
  1088. /** @hidden */
  1089. loadNodeAsync(context: string, node: INode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>>;
  1090. }
  1091. }
  1092. declare module BABYLON.GLTF2.Loader.Extensions {
  1093. /**
  1094. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1095. */
  1096. class KHR_texture_transform implements IGLTFLoaderExtension {
  1097. /** The name of this extension. */
  1098. readonly name: string;
  1099. /** Defines whether this extension is enabled. */
  1100. enabled: boolean;
  1101. private _loader;
  1102. /** @hidden */
  1103. constructor(loader: GLTFLoader);
  1104. /** @hidden */
  1105. dispose(): void;
  1106. /** @hidden */
  1107. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1108. }
  1109. }
  1110. declare module BABYLON.GLTF2.Loader.Extensions {
  1111. /**
  1112. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  1113. */
  1114. class EXT_lights_image_based implements IGLTFLoaderExtension {
  1115. /** The name of this extension. */
  1116. readonly name: string;
  1117. /** Defines whether this extension is enabled. */
  1118. enabled: boolean;
  1119. private _loader;
  1120. private _lights?;
  1121. /** @hidden */
  1122. constructor(loader: GLTFLoader);
  1123. /** @hidden */
  1124. dispose(): void;
  1125. /** @hidden */
  1126. onLoading(): void;
  1127. /** @hidden */
  1128. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1129. private _loadLightAsync;
  1130. }
  1131. }