babylon.glTF2FileLoader.d.ts 45 KB

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