babylon.glTF2FileLoader.d.ts 31 KB

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