babylon.glTF2FileLoader.d.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. /** @hidden */
  337. interface _IArrayItem {
  338. _index: number;
  339. }
  340. /** @hidden */
  341. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  342. _data?: Promise<ArrayBufferView>;
  343. _babylonVertexBuffer?: Promise<VertexBuffer>;
  344. }
  345. /** @hidden */
  346. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  347. }
  348. /** @hidden */
  349. interface _ILoaderAnimationSamplerData {
  350. input: Float32Array;
  351. interpolation: AnimationSamplerInterpolation;
  352. output: Float32Array;
  353. }
  354. /** @hidden */
  355. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  356. _data?: Promise<_ILoaderAnimationSamplerData>;
  357. }
  358. /** @hidden */
  359. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  360. channels: _ILoaderAnimationChannel[];
  361. samplers: _ILoaderAnimationSampler[];
  362. _babylonAnimationGroup?: AnimationGroup;
  363. }
  364. /** @hidden */
  365. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  366. _data?: Promise<ArrayBufferView>;
  367. }
  368. /** @hidden */
  369. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  370. _data?: Promise<ArrayBufferView>;
  371. _babylonBuffer?: Promise<Buffer>;
  372. }
  373. /** @hidden */
  374. interface _ILoaderCamera extends ICamera, _IArrayItem {
  375. }
  376. /** @hidden */
  377. interface _ILoaderImage extends IImage, _IArrayItem {
  378. _data?: Promise<ArrayBufferView>;
  379. }
  380. /** @hidden */
  381. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  382. _babylonData?: {
  383. [drawMode: number]: {
  384. material: Material;
  385. meshes: AbstractMesh[];
  386. loaded: Promise<void>;
  387. };
  388. };
  389. }
  390. /** @hidden */
  391. interface _ILoaderMesh extends IMesh, _IArrayItem {
  392. primitives: _ILoaderMeshPrimitive[];
  393. }
  394. /** @hidden */
  395. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  396. }
  397. /** @hidden */
  398. interface _ILoaderNode extends INode, _IArrayItem {
  399. _parent?: _ILoaderNode;
  400. _babylonMesh?: Mesh;
  401. _primitiveBabylonMeshes?: Mesh[];
  402. _babylonBones?: Bone[];
  403. _numMorphTargets?: number;
  404. }
  405. /** @hidden */
  406. interface _ILoaderSamplerData {
  407. noMipMaps: boolean;
  408. samplingMode: number;
  409. wrapU: number;
  410. wrapV: number;
  411. }
  412. /** @hidden */
  413. interface _ILoaderSampler extends ISampler, _IArrayItem {
  414. _data?: _ILoaderSamplerData;
  415. }
  416. /** @hidden */
  417. interface _ILoaderScene extends IScene, _IArrayItem {
  418. }
  419. /** @hidden */
  420. interface _ILoaderSkin extends ISkin, _IArrayItem {
  421. _babylonSkeleton?: Skeleton;
  422. _loaded?: Promise<void>;
  423. }
  424. /** @hidden */
  425. interface _ILoaderTexture extends ITexture, _IArrayItem {
  426. }
  427. /** @hidden */
  428. interface _ILoaderGLTF extends IGLTF {
  429. accessors?: _ILoaderAccessor[];
  430. animations?: _ILoaderAnimation[];
  431. buffers?: _ILoaderBuffer[];
  432. bufferViews?: _ILoaderBufferView[];
  433. cameras?: _ILoaderCamera[];
  434. images?: _ILoaderImage[];
  435. materials?: _ILoaderMaterial[];
  436. meshes?: _ILoaderMesh[];
  437. nodes?: _ILoaderNode[];
  438. samplers?: _ILoaderSampler[];
  439. scenes?: _ILoaderScene[];
  440. skins?: _ILoaderSkin[];
  441. textures?: _ILoaderTexture[];
  442. }
  443. }
  444. /**
  445. * Defines the module used to import/export glTF 2.0 assets
  446. */
  447. declare module BABYLON.GLTF2 {
  448. /** @hidden */
  449. class _ArrayItem {
  450. static Assign(values?: _IArrayItem[]): void;
  451. }
  452. /** @hidden */
  453. class GLTFLoader implements IGLTFLoader {
  454. _parent: GLTFFileLoader;
  455. _gltf: _ILoaderGLTF;
  456. _babylonScene: Scene;
  457. _completePromises: Promise<void>[];
  458. private _disposed;
  459. private _state;
  460. private _extensions;
  461. private _rootUrl;
  462. private _rootBabylonMesh;
  463. private _defaultSampler;
  464. private _defaultBabylonMaterials;
  465. private _progressCallback?;
  466. private _requests;
  467. private static _ExtensionNames;
  468. private static _ExtensionFactories;
  469. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  470. readonly state: Nullable<GLTFLoaderState>;
  471. constructor(parent: GLTFFileLoader);
  472. dispose(): void;
  473. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  474. meshes: AbstractMesh[];
  475. particleSystems: IParticleSystem[];
  476. skeletons: Skeleton[];
  477. animationGroups: AnimationGroup[];
  478. }>;
  479. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  480. private _loadAsync;
  481. private _loadData;
  482. private _setupData;
  483. private _loadExtensions;
  484. private _checkExtensions;
  485. private _setState;
  486. private _createRootNode;
  487. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  488. private _forEachPrimitive;
  489. private _getMeshes;
  490. private _getSkeletons;
  491. private _getAnimationGroups;
  492. private _startAnimations;
  493. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  494. private _loadMeshAsync;
  495. private _loadPrimitiveAsync;
  496. private _loadVertexDataAsync;
  497. private _createMorphTargets;
  498. private _loadMorphTargetsAsync;
  499. private _loadMorphTargetVertexDataAsync;
  500. private static _LoadTransform;
  501. private _loadSkinAsync;
  502. private _loadBones;
  503. private _loadBone;
  504. private _loadSkinInverseBindMatricesDataAsync;
  505. private _updateBoneMatrices;
  506. private _getNodeMatrix;
  507. private _loadCamera;
  508. private _loadAnimationsAsync;
  509. private _loadAnimationAsync;
  510. private _loadAnimationChannelAsync;
  511. private _loadAnimationSamplerAsync;
  512. private _loadBufferAsync;
  513. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  514. private _loadIndicesAccessorAsync;
  515. private _loadFloatAccessorAsync;
  516. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  517. private _loadVertexAccessorAsync;
  518. private _getDefaultMaterial;
  519. private _loadMaterialMetallicRoughnessPropertiesAsync;
  520. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  521. _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  522. _createMaterial(name: string, drawMode: number): PBRMaterial;
  523. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  524. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  525. _loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Promise<void>;
  526. _loadTextureAsync(context: string, texture: _ILoaderTexture, assign: (babylonTexture: Texture) => void): Promise<void>;
  527. private _loadSampler;
  528. _loadImageAsync(context: string, image: _ILoaderImage): Promise<ArrayBufferView>;
  529. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  530. private _onProgress;
  531. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  532. private static _GetTextureWrapMode;
  533. private static _GetTextureSamplingMode;
  534. private static _GetTypedArray;
  535. private static _GetNumComponents;
  536. private static _ValidateUri;
  537. private static _GetDrawMode;
  538. private _compileMaterialsAsync;
  539. private _compileShadowGeneratorsAsync;
  540. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  541. _forEachExtensions(action: (extension: GLTFLoaderExtension) => void): void;
  542. }
  543. }
  544. declare module BABYLON.GLTF2 {
  545. /**
  546. * Abstract class that can be implemented to extend existing glTF loader behavior.
  547. */
  548. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  549. /**
  550. * Gets or sets a boolean indicating if the extension is enabled
  551. */
  552. enabled: boolean;
  553. /**
  554. * Gets or sets extension name
  555. */
  556. abstract readonly name: string;
  557. protected _loader: GLTFLoader;
  558. /**
  559. * Creates new GLTFLoaderExtension
  560. * @param loader defines the GLTFLoader to use
  561. */
  562. constructor(loader: GLTFLoader);
  563. /**
  564. * Release all resources
  565. */
  566. dispose(): void;
  567. /**
  568. * Override this method to do work after the state changes to LOADING.
  569. */
  570. protected _onLoading(): void;
  571. /**
  572. * Override this method to do work after the state changes to READY.
  573. */
  574. protected _onReady(): void;
  575. /**
  576. * Override this method to modify the default behavior for loading scenes.
  577. * @hidden
  578. */
  579. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  580. /**
  581. * Override this method to modify the default behavior for loading nodes.
  582. * @hidden
  583. */
  584. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  585. /**
  586. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  587. * @hidden
  588. */
  589. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  590. /**
  591. * Override this method to modify the default behavior for loading materials.
  592. * @hidden
  593. */
  594. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  595. /**
  596. * Override this method to modify the default behavior for loading material properties.
  597. * @hidden
  598. */
  599. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  600. /**
  601. * Override this method to modify the default behavior for loading texture infos.
  602. * @hidden
  603. */
  604. protected _loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  605. /**
  606. * Override this method to modify the default behavior for loading textures.
  607. * @hidden
  608. */
  609. protected _loadTextureAsync(context: string, texture: _ILoaderTexture, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  610. /**
  611. * Override this method to modify the default behavior for loading uris.
  612. * @hidden
  613. */
  614. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  615. /**
  616. * Helper method called by a loader extension to load an glTF extension.
  617. * @hidden
  618. */
  619. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  620. /**
  621. * Helper method called by the loader to allow extensions to override loading scenes.
  622. * @hidden
  623. */
  624. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  625. /**
  626. * Helper method called by the loader after the state changes to LOADING.
  627. * @hidden
  628. */
  629. static _OnLoading(loader: GLTFLoader): void;
  630. /**
  631. * Helper method called by the loader after the state changes to READY.
  632. * @hidden
  633. */
  634. static _OnReady(loader: GLTFLoader): void;
  635. /**
  636. * Helper method called by the loader to allow extensions to override loading scenes.
  637. * @hidden
  638. */
  639. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  640. /**
  641. * Helper method called by the loader to allow extensions to override loading nodes.
  642. * @hidden
  643. */
  644. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  645. /**
  646. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  647. * @hidden
  648. */
  649. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  650. /**
  651. * Helper method called by the loader to allow extensions to override loading materials.
  652. * @hidden
  653. */
  654. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  655. /**
  656. * Helper method called by the loader to allow extensions to override loading material properties.
  657. * @hidden
  658. */
  659. static _LoadMaterialPropertiesAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  660. /**
  661. * Helper method called by the loader to allow extensions to override loading texture infos.
  662. * @hidden
  663. */
  664. static _LoadTextureInfoAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  665. /**
  666. * Helper method called by the loader to allow extensions to override loading textures.
  667. * @hidden
  668. */
  669. static _LoadTextureAsync(loader: GLTFLoader, context: string, texture: _ILoaderTexture, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  670. /**
  671. * Helper method called by the loader to allow extensions to override loading uris.
  672. * @hidden
  673. */
  674. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  675. }
  676. }
  677. /**
  678. * Defines the module of the glTF 2.0 loader extensions.
  679. */
  680. declare module BABYLON.GLTF2.Extensions {
  681. }
  682. declare module BABYLON.GLTF2.Extensions {
  683. /**
  684. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  685. */
  686. class MSFT_lod extends GLTFLoaderExtension {
  687. readonly name: string;
  688. /**
  689. * Maximum number of LODs to load, starting from the lowest LOD.
  690. */
  691. maxLODsToLoad: number;
  692. /**
  693. * Observable raised when all node LODs of one level are loaded.
  694. * The event data is the index of the loaded LOD starting from zero.
  695. * Dispose the loader to cancel the loading of the next level of LODs.
  696. */
  697. onNodeLODsLoadedObservable: Observable<number>;
  698. /**
  699. * Observable raised when all material LODs of one level are loaded.
  700. * The event data is the index of the loaded LOD starting from zero.
  701. * Dispose the loader to cancel the loading of the next level of LODs.
  702. */
  703. onMaterialLODsLoadedObservable: Observable<number>;
  704. private _nodeIndexLOD;
  705. private _nodeSignalLODs;
  706. private _nodePromiseLODs;
  707. private _materialIndexLOD;
  708. private _materialSignalLODs;
  709. private _materialPromiseLODs;
  710. dispose(): void;
  711. protected _onReady(): void;
  712. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  713. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  714. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  715. /**
  716. * Gets an array of LOD properties from lowest to highest.
  717. */
  718. private _getLODs;
  719. private _disposeUnusedMaterials;
  720. }
  721. }
  722. declare module BABYLON.GLTF2.Extensions {
  723. /** @hidden */
  724. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  725. readonly name: string;
  726. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  727. }
  728. }
  729. declare module BABYLON.GLTF2.Extensions {
  730. /** @hidden */
  731. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  732. readonly name: string;
  733. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  734. private _convertColorsToLinear;
  735. }
  736. }
  737. declare module BABYLON.GLTF2.Extensions {
  738. /**
  739. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  740. */
  741. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  742. readonly name: string;
  743. private _dracoCompression;
  744. constructor(loader: GLTFLoader);
  745. dispose(): void;
  746. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  747. }
  748. }
  749. declare module BABYLON.GLTF2.Extensions {
  750. /**
  751. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  752. */
  753. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  754. readonly name: string;
  755. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  756. private _loadSpecularGlossinessPropertiesAsync;
  757. }
  758. }
  759. declare module BABYLON.GLTF2.Extensions {
  760. /**
  761. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  762. */
  763. class KHR_materials_unlit extends GLTFLoaderExtension {
  764. readonly name: string;
  765. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  766. private _loadUnlitPropertiesAsync;
  767. }
  768. }
  769. declare module BABYLON.GLTF2.Extensions {
  770. /**
  771. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  772. */
  773. class KHR_lights extends GLTFLoaderExtension {
  774. readonly name: string;
  775. private _lights?;
  776. protected _onLoading(): void;
  777. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  778. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  779. }
  780. }
  781. declare module BABYLON.GLTF2.Extensions {
  782. /**
  783. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  784. */
  785. class KHR_texture_transform extends GLTFLoaderExtension {
  786. readonly name: string;
  787. protected _loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  788. }
  789. }
  790. declare module BABYLON.GLTF2.Extensions {
  791. /**
  792. * [Specification](TODO) (Experimental)
  793. */
  794. class EXT_lights_imageBased extends GLTFLoaderExtension {
  795. readonly name: string;
  796. private _lights?;
  797. protected _onLoading(): void;
  798. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  799. private _loadLightAsync;
  800. }
  801. }