babylon.glTF2FileLoader.d.ts 45 KB

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