babylon.glTF2FileLoader.d.ts 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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: ParticleSystem[];
  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. */
  194. onComplete: () => void;
  195. /**
  196. * Observable raised after the loader is disposed.
  197. */
  198. readonly onDisposeObservable: Observable<void>;
  199. private _onDisposeObserver;
  200. /**
  201. * Callback raised after the loader is disposed.
  202. */
  203. onDispose: () => void;
  204. /**
  205. * Observable raised after a loader extension is created.
  206. * Set additional options for a loader extension in this event.
  207. */
  208. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  209. private _onExtensionLoadedObserver;
  210. /**
  211. * Callback raised after a loader extension is created.
  212. */
  213. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  214. /**
  215. * Returns a promise that resolves when the asset is completely loaded.
  216. * @returns a promise that resolves when the asset is completely loaded.
  217. */
  218. whenCompleteAsync(): Promise<void>;
  219. /**
  220. * The loader state or null if the loader is not active.
  221. */
  222. readonly loaderState: Nullable<GLTFLoaderState>;
  223. /**
  224. * Defines if the loader logging is enabled.
  225. */
  226. loggingEnabled: boolean;
  227. /**
  228. * Defines if the loader should capture performance counters.
  229. */
  230. capturePerformanceCounters: boolean;
  231. private _loader;
  232. /**
  233. * Name of the loader ("gltf")
  234. */
  235. name: string;
  236. /**
  237. * Supported file extensions of the loader (.gltf, .glb)
  238. */
  239. extensions: ISceneLoaderPluginExtensions;
  240. /**
  241. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  242. */
  243. dispose(): void;
  244. /** @hidden */
  245. _clear(): void;
  246. /**
  247. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  248. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  249. * @param scene the scene the meshes should be added to
  250. * @param data the glTF data to load
  251. * @param rootUrl root url to load from
  252. * @param onProgress event that fires when loading progress has occured
  253. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  254. */
  255. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  256. meshes: AbstractMesh[];
  257. particleSystems: ParticleSystem[];
  258. skeletons: Skeleton[];
  259. animationGroups: AnimationGroup[];
  260. }>;
  261. /**
  262. * Imports all objects from the loaded glTF data and adds them to the scene
  263. * @param scene the scene the objects should be added to
  264. * @param data the glTF data to load
  265. * @param rootUrl root url to load from
  266. * @param onProgress event that fires when loading progress has occured
  267. * @returns a promise which completes when objects have been loaded to the scene
  268. */
  269. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  270. /**
  271. * Load into an asset container.
  272. * @param scene The scene to load into
  273. * @param data The data to import
  274. * @param rootUrl The root url for scene and resources
  275. * @param onProgress The callback when the load progresses
  276. * @returns The loaded asset container
  277. */
  278. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  279. /**
  280. * If the data string can be loaded directly.
  281. * @param data string contianing the file data
  282. * @returns if the data can be loaded directly
  283. */
  284. canDirectLoad(data: string): boolean;
  285. /**
  286. * Rewrites a url by combining a root url and response url.
  287. */
  288. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  289. /**
  290. * Instantiates a glTF file loader plugin.
  291. * @returns the created plugin
  292. */
  293. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  294. private _parse(data);
  295. private _getLoader(loaderData);
  296. private _parseBinary(data);
  297. private _parseV1(binaryReader);
  298. private _parseV2(binaryReader);
  299. private static _parseVersion(version);
  300. private static _compareVersion(a, b);
  301. private static _decodeBufferToText(buffer);
  302. private static readonly _logSpaces;
  303. private _logIndentLevel;
  304. private _loggingEnabled;
  305. /** @hidden */
  306. _log: (message: string) => void;
  307. /** @hidden */
  308. _logOpen(message: string): void;
  309. /** @hidden */
  310. _logClose(): void;
  311. private _logEnabled(message);
  312. private _logDisabled(message);
  313. private _capturePerformanceCounters;
  314. /** @hidden */
  315. _startPerformanceCounter: (counterName: string) => void;
  316. /** @hidden */
  317. _endPerformanceCounter: (counterName: string) => void;
  318. private _startPerformanceCounterEnabled(counterName);
  319. private _startPerformanceCounterDisabled(counterName);
  320. private _endPerformanceCounterEnabled(counterName);
  321. private _endPerformanceCounterDisabled(counterName);
  322. }
  323. }
  324. declare module BABYLON.GLTF2 {
  325. /** @hidden */
  326. interface _IArrayItem {
  327. _index: number;
  328. }
  329. /** @hidden */
  330. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  331. _data?: Promise<ArrayBufferView>;
  332. _babylonVertexBuffer?: Promise<VertexBuffer>;
  333. }
  334. /** @hidden */
  335. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  336. }
  337. /** @hidden */
  338. interface _ILoaderAnimationSamplerData {
  339. input: Float32Array;
  340. interpolation: AnimationSamplerInterpolation;
  341. output: Float32Array;
  342. }
  343. /** @hidden */
  344. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  345. _data?: Promise<_ILoaderAnimationSamplerData>;
  346. }
  347. /** @hidden */
  348. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  349. channels: _ILoaderAnimationChannel[];
  350. samplers: _ILoaderAnimationSampler[];
  351. _babylonAnimationGroup?: AnimationGroup;
  352. }
  353. /** @hidden */
  354. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  355. _data?: Promise<ArrayBufferView>;
  356. }
  357. /** @hidden */
  358. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  359. _data?: Promise<ArrayBufferView>;
  360. _babylonBuffer?: Promise<Buffer>;
  361. }
  362. /** @hidden */
  363. interface _ILoaderCamera extends ICamera, _IArrayItem {
  364. }
  365. /** @hidden */
  366. interface _ILoaderImage extends IImage, _IArrayItem {
  367. _blob?: Promise<Blob>;
  368. }
  369. /** @hidden */
  370. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  371. _babylonData?: {
  372. [drawMode: number]: {
  373. material: Material;
  374. meshes: AbstractMesh[];
  375. loaded: Promise<void>;
  376. };
  377. };
  378. }
  379. /** @hidden */
  380. interface _ILoaderMesh extends IMesh, _IArrayItem {
  381. primitives: _ILoaderMeshPrimitive[];
  382. }
  383. /** @hidden */
  384. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  385. }
  386. /** @hidden */
  387. interface _ILoaderNode extends INode, _IArrayItem {
  388. _parent?: _ILoaderNode;
  389. _babylonMesh?: Mesh;
  390. _primitiveBabylonMeshes?: Mesh[];
  391. _babylonBones?: Bone[];
  392. _numMorphTargets?: number;
  393. }
  394. /** @hidden */
  395. interface _ILoaderSamplerData {
  396. noMipMaps: boolean;
  397. samplingMode: number;
  398. wrapU: number;
  399. wrapV: number;
  400. }
  401. /** @hidden */
  402. interface _ILoaderSampler extends ISampler, _IArrayItem {
  403. _data?: _ILoaderSamplerData;
  404. }
  405. /** @hidden */
  406. interface _ILoaderScene extends IScene, _IArrayItem {
  407. }
  408. /** @hidden */
  409. interface _ILoaderSkin extends ISkin, _IArrayItem {
  410. _babylonSkeleton?: Skeleton;
  411. _loaded?: Promise<void>;
  412. }
  413. /** @hidden */
  414. interface _ILoaderTexture extends ITexture, _IArrayItem {
  415. }
  416. /** @hidden */
  417. interface _ILoaderGLTF extends IGLTF {
  418. accessors?: _ILoaderAccessor[];
  419. animations?: _ILoaderAnimation[];
  420. buffers?: _ILoaderBuffer[];
  421. bufferViews?: _ILoaderBufferView[];
  422. cameras?: _ILoaderCamera[];
  423. images?: _ILoaderImage[];
  424. materials?: _ILoaderMaterial[];
  425. meshes?: _ILoaderMesh[];
  426. nodes?: _ILoaderNode[];
  427. samplers?: _ILoaderSampler[];
  428. scenes?: _ILoaderScene[];
  429. skins?: _ILoaderSkin[];
  430. textures?: _ILoaderTexture[];
  431. }
  432. }
  433. /**
  434. * Defines the module used to import/export glTF 2.0 assets
  435. */
  436. declare module BABYLON.GLTF2 {
  437. /** @hidden */
  438. class GLTFLoader implements IGLTFLoader {
  439. _parent: GLTFFileLoader;
  440. _gltf: _ILoaderGLTF;
  441. _babylonScene: Scene;
  442. _readyPromise: Promise<void>;
  443. _completePromises: Promise<void>[];
  444. private _disposed;
  445. private _state;
  446. private _extensions;
  447. private _rootUrl;
  448. private _rootBabylonMesh;
  449. private _defaultSampler;
  450. private _defaultBabylonMaterials;
  451. private _progressCallback?;
  452. private _requests;
  453. private static _ExtensionNames;
  454. private static _ExtensionFactories;
  455. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  456. /**
  457. * Loader state or null if the loader is not active.
  458. */
  459. readonly state: Nullable<GLTFLoaderState>;
  460. constructor(parent: GLTFFileLoader);
  461. dispose(): void;
  462. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  463. meshes: AbstractMesh[];
  464. particleSystems: ParticleSystem[];
  465. skeletons: Skeleton[];
  466. animationGroups: AnimationGroup[];
  467. }>;
  468. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  469. private _loadAsync(nodes);
  470. private _loadData(data);
  471. private _setupData();
  472. private _loadExtensions();
  473. private _checkExtensions();
  474. private _createRootNode();
  475. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  476. private _forEachPrimitive(node, callback);
  477. private _getMeshes();
  478. private _getSkeletons();
  479. private _getAnimationGroups();
  480. private _startAnimations();
  481. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  482. private _loadMeshAsync(context, node, mesh, babylonMesh);
  483. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  484. private _loadVertexDataAsync(context, primitive, babylonMesh);
  485. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  486. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  487. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  488. private static _LoadTransform(node, babylonNode);
  489. private _loadSkinAsync(context, node, mesh, skin);
  490. private _loadBones(context, skin);
  491. private _loadBone(node, skin, babylonBones);
  492. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  493. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  494. private _getNodeMatrix(node);
  495. private _loadCamera(context, camera, babylonMesh);
  496. private _loadAnimationsAsync();
  497. private _loadAnimationAsync(context, animation);
  498. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  499. private _loadAnimationSamplerAsync(context, sampler);
  500. private _loadBufferAsync(context, buffer);
  501. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  502. private _loadIndicesAccessorAsync(context, accessor);
  503. private _loadFloatAccessorAsync(context, accessor);
  504. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  505. private _loadVertexAccessorAsync(context, accessor, kind);
  506. private _getDefaultMaterial(drawMode);
  507. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  508. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  509. _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  510. _createMaterial(name: string, drawMode: number): PBRMaterial;
  511. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  512. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  513. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  514. private _loadSampler(context, sampler);
  515. private _loadImageAsync(context, image);
  516. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  517. private _onProgress();
  518. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  519. private static _GetTextureWrapMode(context, mode);
  520. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  521. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  522. private static _GetNumComponents(context, type);
  523. private static _ValidateUri(uri);
  524. private static _GetDrawMode(context, mode);
  525. private _compileMaterialsAsync();
  526. private _compileShadowGeneratorsAsync();
  527. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  528. }
  529. }
  530. declare module BABYLON.GLTF2 {
  531. /**
  532. * Abstract class that can be implemented to extend existing glTF loader behavior.
  533. */
  534. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  535. /**
  536. * Gets or sets a boolean indicating if the extension is enabled
  537. */
  538. enabled: boolean;
  539. /**
  540. * Gets or sets extension name
  541. */
  542. readonly abstract name: string;
  543. protected _loader: GLTFLoader;
  544. /**
  545. * Creates new GLTFLoaderExtension
  546. * @param loader defines the GLTFLoader to use
  547. */
  548. constructor(loader: GLTFLoader);
  549. /**
  550. * Release all resources
  551. */
  552. dispose(): void;
  553. /**
  554. * Override this method to modify the default behavior for loading scenes.
  555. * @hidden
  556. */
  557. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  558. /**
  559. * Override this method to modify the default behavior for loading nodes.
  560. * @hidden
  561. */
  562. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  563. /**
  564. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  565. * @hidden
  566. */
  567. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  568. /**
  569. * Override this method to modify the default behavior for loading materials.
  570. * @hidden
  571. */
  572. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  573. /**
  574. * Override this method to modify the default behavior for loading material properties.
  575. * @hidden
  576. */
  577. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  578. /**
  579. * Override this method to modify the default behavior for loading textures.
  580. * @hidden
  581. */
  582. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  583. /**
  584. * Override this method to modify the default behavior for loading uris.
  585. * @hidden
  586. */
  587. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  588. /**
  589. * Helper method called by a loader extension to load an glTF extension.
  590. * @hidden
  591. */
  592. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  593. /**
  594. * Helper method called by the loader to allow extensions to override loading scenes.
  595. * @hidden
  596. */
  597. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  598. /**
  599. * Helper method called by the loader to allow extensions to override loading scenes.
  600. * @hidden
  601. */
  602. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  603. /**
  604. * Helper method called by the loader to allow extensions to override loading nodes.
  605. * @hidden
  606. */
  607. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  608. /**
  609. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  610. * @hidden
  611. */
  612. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  613. /**
  614. * Helper method called by the loader to allow extensions to override loading materials.
  615. * @hidden
  616. */
  617. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  618. /**
  619. * Helper method called by the loader to allow extensions to override loading material properties.
  620. * @hidden
  621. */
  622. static _LoadMaterialPropertiesAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  623. /**
  624. * Helper method called by the loader to allow extensions to override loading textures.
  625. * @hidden
  626. */
  627. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  628. /**
  629. * Helper method called by the loader to allow extensions to override loading uris.
  630. * @hidden
  631. */
  632. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  633. }
  634. }
  635. /**
  636. * Defines the module of the glTF 2.0 loader extensions.
  637. */
  638. declare module BABYLON.GLTF2.Extensions {
  639. }
  640. declare module BABYLON.GLTF2.Extensions {
  641. /**
  642. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  643. */
  644. class MSFT_lod extends GLTFLoaderExtension {
  645. readonly name: string;
  646. /**
  647. * Maximum number of LODs to load, starting from the lowest LOD.
  648. */
  649. maxLODsToLoad: number;
  650. /**
  651. * Observable raised when all node LODs of one level are loaded.
  652. * The event data is the index of the loaded LOD starting from zero.
  653. * Dispose the loader to cancel the loading of the next level of LODs.
  654. */
  655. onNodeLODsLoadedObservable: Observable<number>;
  656. /**
  657. * Observable raised when all material LODs of one level are loaded.
  658. * The event data is the index of the loaded LOD starting from zero.
  659. * Dispose the loader to cancel the loading of the next level of LODs.
  660. */
  661. onMaterialLODsLoadedObservable: Observable<number>;
  662. private _nodeIndexLOD;
  663. private _nodeSignalLODs;
  664. private _nodePromiseLODs;
  665. private _materialIndexLOD;
  666. private _materialSignalLODs;
  667. private _materialPromiseLODs;
  668. constructor(loader: GLTFLoader);
  669. dispose(): void;
  670. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  671. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  672. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  673. /**
  674. * Gets an array of LOD properties from lowest to highest.
  675. */
  676. private _getLODs<T>(context, property, array, ids);
  677. private _disposeUnusedMaterials();
  678. }
  679. }
  680. declare module BABYLON.GLTF2.Extensions {
  681. /** @hidden */
  682. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  683. readonly name: string;
  684. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  685. }
  686. }
  687. declare module BABYLON.GLTF2.Extensions {
  688. /** @hidden */
  689. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  690. readonly name: string;
  691. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  692. }
  693. }
  694. declare module BABYLON.GLTF2.Extensions {
  695. /**
  696. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  697. */
  698. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  699. readonly name: string;
  700. private _dracoCompression;
  701. constructor(loader: GLTFLoader);
  702. dispose(): void;
  703. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  704. }
  705. }
  706. declare module BABYLON.GLTF2.Extensions {
  707. /**
  708. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  709. */
  710. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  711. readonly name: string;
  712. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  713. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  714. }
  715. }
  716. declare module BABYLON.GLTF2.Extensions {
  717. /**
  718. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  719. */
  720. class KHR_materials_unlit extends GLTFLoaderExtension {
  721. readonly name: string;
  722. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  723. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  724. }
  725. }
  726. declare module BABYLON.GLTF2.Extensions {
  727. /**
  728. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  729. */
  730. class KHR_lights extends GLTFLoaderExtension {
  731. readonly name: string;
  732. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  733. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  734. private readonly _lights;
  735. }
  736. }
  737. declare module BABYLON.GLTF2.Extensions {
  738. /**
  739. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  740. */
  741. class KHR_texture_transform extends GLTFLoaderExtension {
  742. readonly name: string;
  743. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  744. }
  745. }