babylon.glTFFileLoader.d.ts 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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.GLTF1 {
  325. /**
  326. * Enums
  327. */
  328. enum EComponentType {
  329. BYTE = 5120,
  330. UNSIGNED_BYTE = 5121,
  331. SHORT = 5122,
  332. UNSIGNED_SHORT = 5123,
  333. FLOAT = 5126,
  334. }
  335. enum EShaderType {
  336. FRAGMENT = 35632,
  337. VERTEX = 35633,
  338. }
  339. enum EParameterType {
  340. BYTE = 5120,
  341. UNSIGNED_BYTE = 5121,
  342. SHORT = 5122,
  343. UNSIGNED_SHORT = 5123,
  344. INT = 5124,
  345. UNSIGNED_INT = 5125,
  346. FLOAT = 5126,
  347. FLOAT_VEC2 = 35664,
  348. FLOAT_VEC3 = 35665,
  349. FLOAT_VEC4 = 35666,
  350. INT_VEC2 = 35667,
  351. INT_VEC3 = 35668,
  352. INT_VEC4 = 35669,
  353. BOOL = 35670,
  354. BOOL_VEC2 = 35671,
  355. BOOL_VEC3 = 35672,
  356. BOOL_VEC4 = 35673,
  357. FLOAT_MAT2 = 35674,
  358. FLOAT_MAT3 = 35675,
  359. FLOAT_MAT4 = 35676,
  360. SAMPLER_2D = 35678,
  361. }
  362. enum ETextureWrapMode {
  363. CLAMP_TO_EDGE = 33071,
  364. MIRRORED_REPEAT = 33648,
  365. REPEAT = 10497,
  366. }
  367. enum ETextureFilterType {
  368. NEAREST = 9728,
  369. LINEAR = 9728,
  370. NEAREST_MIPMAP_NEAREST = 9984,
  371. LINEAR_MIPMAP_NEAREST = 9985,
  372. NEAREST_MIPMAP_LINEAR = 9986,
  373. LINEAR_MIPMAP_LINEAR = 9987,
  374. }
  375. enum ETextureFormat {
  376. ALPHA = 6406,
  377. RGB = 6407,
  378. RGBA = 6408,
  379. LUMINANCE = 6409,
  380. LUMINANCE_ALPHA = 6410,
  381. }
  382. enum ECullingType {
  383. FRONT = 1028,
  384. BACK = 1029,
  385. FRONT_AND_BACK = 1032,
  386. }
  387. enum EBlendingFunction {
  388. ZERO = 0,
  389. ONE = 1,
  390. SRC_COLOR = 768,
  391. ONE_MINUS_SRC_COLOR = 769,
  392. DST_COLOR = 774,
  393. ONE_MINUS_DST_COLOR = 775,
  394. SRC_ALPHA = 770,
  395. ONE_MINUS_SRC_ALPHA = 771,
  396. DST_ALPHA = 772,
  397. ONE_MINUS_DST_ALPHA = 773,
  398. CONSTANT_COLOR = 32769,
  399. ONE_MINUS_CONSTANT_COLOR = 32770,
  400. CONSTANT_ALPHA = 32771,
  401. ONE_MINUS_CONSTANT_ALPHA = 32772,
  402. SRC_ALPHA_SATURATE = 776,
  403. }
  404. /**
  405. * Interfaces
  406. */
  407. interface IGLTFProperty {
  408. extensions?: {
  409. [key: string]: any;
  410. };
  411. extras?: Object;
  412. }
  413. interface IGLTFChildRootProperty extends IGLTFProperty {
  414. name?: string;
  415. }
  416. interface IGLTFAccessor extends IGLTFChildRootProperty {
  417. bufferView: string;
  418. byteOffset: number;
  419. byteStride: number;
  420. count: number;
  421. type: string;
  422. componentType: EComponentType;
  423. max?: number[];
  424. min?: number[];
  425. name?: string;
  426. }
  427. interface IGLTFBufferView extends IGLTFChildRootProperty {
  428. buffer: string;
  429. byteOffset: number;
  430. byteLength: number;
  431. byteStride: number;
  432. target?: number;
  433. }
  434. interface IGLTFBuffer extends IGLTFChildRootProperty {
  435. uri: string;
  436. byteLength?: number;
  437. type?: string;
  438. }
  439. interface IGLTFShader extends IGLTFChildRootProperty {
  440. uri: string;
  441. type: EShaderType;
  442. }
  443. interface IGLTFProgram extends IGLTFChildRootProperty {
  444. attributes: string[];
  445. fragmentShader: string;
  446. vertexShader: string;
  447. }
  448. interface IGLTFTechniqueParameter {
  449. type: number;
  450. count?: number;
  451. semantic?: string;
  452. node?: string;
  453. value?: number | boolean | string | Array<any>;
  454. source?: string;
  455. babylonValue?: any;
  456. }
  457. interface IGLTFTechniqueCommonProfile {
  458. lightingModel: string;
  459. texcoordBindings: Object;
  460. parameters?: Array<any>;
  461. }
  462. interface IGLTFTechniqueStatesFunctions {
  463. blendColor?: number[];
  464. blendEquationSeparate?: number[];
  465. blendFuncSeparate?: number[];
  466. colorMask: boolean[];
  467. cullFace: number[];
  468. }
  469. interface IGLTFTechniqueStates {
  470. enable: number[];
  471. functions: IGLTFTechniqueStatesFunctions;
  472. }
  473. interface IGLTFTechnique extends IGLTFChildRootProperty {
  474. parameters: {
  475. [key: string]: IGLTFTechniqueParameter;
  476. };
  477. program: string;
  478. attributes: {
  479. [key: string]: string;
  480. };
  481. uniforms: {
  482. [key: string]: string;
  483. };
  484. states: IGLTFTechniqueStates;
  485. }
  486. interface IGLTFMaterial extends IGLTFChildRootProperty {
  487. technique?: string;
  488. values: string[];
  489. }
  490. interface IGLTFMeshPrimitive extends IGLTFProperty {
  491. attributes: {
  492. [key: string]: string;
  493. };
  494. indices: string;
  495. material: string;
  496. mode?: number;
  497. }
  498. interface IGLTFMesh extends IGLTFChildRootProperty {
  499. primitives: IGLTFMeshPrimitive[];
  500. }
  501. interface IGLTFImage extends IGLTFChildRootProperty {
  502. uri: string;
  503. }
  504. interface IGLTFSampler extends IGLTFChildRootProperty {
  505. magFilter?: number;
  506. minFilter?: number;
  507. wrapS?: number;
  508. wrapT?: number;
  509. }
  510. interface IGLTFTexture extends IGLTFChildRootProperty {
  511. sampler: string;
  512. source: string;
  513. format?: ETextureFormat;
  514. internalFormat?: ETextureFormat;
  515. target?: number;
  516. type?: number;
  517. babylonTexture?: Texture;
  518. }
  519. interface IGLTFAmbienLight {
  520. color?: number[];
  521. }
  522. interface IGLTFDirectionalLight {
  523. color?: number[];
  524. }
  525. interface IGLTFPointLight {
  526. color?: number[];
  527. constantAttenuation?: number;
  528. linearAttenuation?: number;
  529. quadraticAttenuation?: number;
  530. }
  531. interface IGLTFSpotLight {
  532. color?: number[];
  533. constantAttenuation?: number;
  534. fallOfAngle?: number;
  535. fallOffExponent?: number;
  536. linearAttenuation?: number;
  537. quadraticAttenuation?: number;
  538. }
  539. interface IGLTFLight extends IGLTFChildRootProperty {
  540. type: string;
  541. }
  542. interface IGLTFCameraOrthographic {
  543. xmag: number;
  544. ymag: number;
  545. zfar: number;
  546. znear: number;
  547. }
  548. interface IGLTFCameraPerspective {
  549. aspectRatio: number;
  550. yfov: number;
  551. zfar: number;
  552. znear: number;
  553. }
  554. interface IGLTFCamera extends IGLTFChildRootProperty {
  555. type: string;
  556. }
  557. interface IGLTFAnimationChannelTarget {
  558. id: string;
  559. path: string;
  560. }
  561. interface IGLTFAnimationChannel {
  562. sampler: string;
  563. target: IGLTFAnimationChannelTarget;
  564. }
  565. interface IGLTFAnimationSampler {
  566. input: string;
  567. output: string;
  568. interpolation?: string;
  569. }
  570. interface IGLTFAnimation extends IGLTFChildRootProperty {
  571. channels?: IGLTFAnimationChannel[];
  572. parameters?: {
  573. [key: string]: string;
  574. };
  575. samplers?: {
  576. [key: string]: IGLTFAnimationSampler;
  577. };
  578. }
  579. interface IGLTFNodeInstanceSkin {
  580. skeletons: string[];
  581. skin: string;
  582. meshes: string[];
  583. }
  584. interface IGLTFSkins extends IGLTFChildRootProperty {
  585. bindShapeMatrix: number[];
  586. inverseBindMatrices: string;
  587. jointNames: string[];
  588. babylonSkeleton?: Skeleton;
  589. }
  590. interface IGLTFNode extends IGLTFChildRootProperty {
  591. camera?: string;
  592. children: string[];
  593. skin?: string;
  594. jointName?: string;
  595. light?: string;
  596. matrix: number[];
  597. mesh?: string;
  598. meshes?: string[];
  599. rotation?: number[];
  600. scale?: number[];
  601. translation?: number[];
  602. babylonNode?: Node;
  603. }
  604. interface IGLTFScene extends IGLTFChildRootProperty {
  605. nodes: string[];
  606. }
  607. /**
  608. * Runtime
  609. */
  610. interface IGLTFRuntime {
  611. extensions: {
  612. [key: string]: any;
  613. };
  614. accessors: {
  615. [key: string]: IGLTFAccessor;
  616. };
  617. buffers: {
  618. [key: string]: IGLTFBuffer;
  619. };
  620. bufferViews: {
  621. [key: string]: IGLTFBufferView;
  622. };
  623. meshes: {
  624. [key: string]: IGLTFMesh;
  625. };
  626. lights: {
  627. [key: string]: IGLTFLight;
  628. };
  629. cameras: {
  630. [key: string]: IGLTFCamera;
  631. };
  632. nodes: {
  633. [key: string]: IGLTFNode;
  634. };
  635. images: {
  636. [key: string]: IGLTFImage;
  637. };
  638. textures: {
  639. [key: string]: IGLTFTexture;
  640. };
  641. shaders: {
  642. [key: string]: IGLTFShader;
  643. };
  644. programs: {
  645. [key: string]: IGLTFProgram;
  646. };
  647. samplers: {
  648. [key: string]: IGLTFSampler;
  649. };
  650. techniques: {
  651. [key: string]: IGLTFTechnique;
  652. };
  653. materials: {
  654. [key: string]: IGLTFMaterial;
  655. };
  656. animations: {
  657. [key: string]: IGLTFAnimation;
  658. };
  659. skins: {
  660. [key: string]: IGLTFSkins;
  661. };
  662. currentScene?: Object;
  663. scenes: {
  664. [key: string]: IGLTFScene;
  665. };
  666. extensionsUsed: string[];
  667. extensionsRequired?: string[];
  668. buffersCount: number;
  669. shaderscount: number;
  670. scene: Scene;
  671. rootUrl: string;
  672. loadedBufferCount: number;
  673. loadedBufferViews: {
  674. [name: string]: ArrayBufferView;
  675. };
  676. loadedShaderCount: number;
  677. importOnlyMeshes: boolean;
  678. importMeshesNames?: string[];
  679. dummyNodes: Node[];
  680. }
  681. /**
  682. * Bones
  683. */
  684. interface INodeToRoot {
  685. bone: Bone;
  686. node: IGLTFNode;
  687. id: string;
  688. }
  689. interface IJointNode {
  690. node: IGLTFNode;
  691. id: string;
  692. }
  693. }
  694. declare module BABYLON.GLTF1 {
  695. /**
  696. * Implementation of the base glTF spec
  697. */
  698. class GLTFLoaderBase {
  699. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  700. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  701. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  702. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  703. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  704. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  705. }
  706. /**
  707. * glTF V1 Loader
  708. */
  709. class GLTFLoader implements IGLTFLoader {
  710. static Extensions: {
  711. [name: string]: GLTFLoaderExtension;
  712. };
  713. static RegisterExtension(extension: GLTFLoaderExtension): void;
  714. state: Nullable<GLTFLoaderState>;
  715. dispose(): void;
  716. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  717. /**
  718. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  719. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  720. * @param scene the scene the meshes should be added to
  721. * @param data gltf data containing information of the meshes in a loaded file
  722. * @param rootUrl root url to load from
  723. * @param onProgress event that fires when loading progress has occured
  724. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  725. */
  726. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  727. meshes: AbstractMesh[];
  728. particleSystems: ParticleSystem[];
  729. skeletons: Skeleton[];
  730. animationGroups: AnimationGroup[];
  731. }>;
  732. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  733. /**
  734. * Imports all objects from a loaded gltf file and adds them to the scene
  735. * @param scene the scene the objects should be added to
  736. * @param data gltf data containing information of the meshes in a loaded file
  737. * @param rootUrl root url to load from
  738. * @param onProgress event that fires when loading progress has occured
  739. * @returns a promise which completes when objects have been loaded to the scene
  740. */
  741. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  742. private _loadShadersAsync(gltfRuntime, onload);
  743. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  744. private _createNodes(gltfRuntime);
  745. }
  746. }
  747. declare module BABYLON.GLTF1 {
  748. /**
  749. * Utils functions for GLTF
  750. */
  751. class GLTFUtils {
  752. /**
  753. * Sets the given "parameter" matrix
  754. * @param scene: the {BABYLON.Scene} object
  755. * @param source: the source node where to pick the matrix
  756. * @param parameter: the GLTF technique parameter
  757. * @param uniformName: the name of the shader's uniform
  758. * @param shaderMaterial: the shader material
  759. */
  760. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  761. /**
  762. * Sets the given "parameter" matrix
  763. * @param shaderMaterial: the shader material
  764. * @param uniform: the name of the shader's uniform
  765. * @param value: the value of the uniform
  766. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  767. */
  768. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  769. /**
  770. * Returns the wrap mode of the texture
  771. * @param mode: the mode value
  772. */
  773. static GetWrapMode(mode: number): number;
  774. /**
  775. * Returns the byte stride giving an accessor
  776. * @param accessor: the GLTF accessor objet
  777. */
  778. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  779. /**
  780. * Returns the texture filter mode giving a mode value
  781. * @param mode: the filter mode value
  782. */
  783. static GetTextureFilterMode(mode: number): ETextureFilterType;
  784. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  785. /**
  786. * Returns a buffer from its accessor
  787. * @param gltfRuntime: the GLTF runtime
  788. * @param accessor: the GLTF accessor
  789. */
  790. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  791. /**
  792. * Decodes a buffer view into a string
  793. * @param view: the buffer view
  794. */
  795. static DecodeBufferToText(view: ArrayBufferView): string;
  796. /**
  797. * Returns the default material of gltf. Related to
  798. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  799. * @param scene: the Babylon.js scene
  800. */
  801. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  802. private static _DefaultMaterial;
  803. }
  804. }
  805. declare module BABYLON.GLTF1 {
  806. abstract class GLTFLoaderExtension {
  807. private _name;
  808. constructor(name: string);
  809. readonly name: string;
  810. /**
  811. * Defines an override for loading the runtime
  812. * Return true to stop further extensions from loading the runtime
  813. */
  814. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  815. /**
  816. * Defines an onverride for creating gltf runtime
  817. * Return true to stop further extensions from creating the runtime
  818. */
  819. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  820. /**
  821. * Defines an override for loading buffers
  822. * Return true to stop further extensions from loading this buffer
  823. */
  824. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  825. /**
  826. * Defines an override for loading texture buffers
  827. * Return true to stop further extensions from loading this texture data
  828. */
  829. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  830. /**
  831. * Defines an override for creating textures
  832. * Return true to stop further extensions from loading this texture
  833. */
  834. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  835. /**
  836. * Defines an override for loading shader strings
  837. * Return true to stop further extensions from loading this shader data
  838. */
  839. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  840. /**
  841. * Defines an override for loading materials
  842. * Return true to stop further extensions from loading this material
  843. */
  844. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  845. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  846. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  847. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  848. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  849. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  850. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  851. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  852. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  853. private static ApplyExtensions(func, defaultFunc);
  854. }
  855. }
  856. declare module BABYLON.GLTF1 {
  857. class GLTFBinaryExtension extends GLTFLoaderExtension {
  858. private _bin;
  859. constructor();
  860. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  861. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  862. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  863. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  864. }
  865. }
  866. declare module BABYLON.GLTF1 {
  867. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  868. constructor();
  869. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  870. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  871. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  872. }
  873. }
  874. declare module BABYLON.GLTF2 {
  875. /** @hidden */
  876. interface _IArrayItem {
  877. _index: number;
  878. }
  879. /** @hidden */
  880. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  881. _data?: Promise<ArrayBufferView>;
  882. _babylonVertexBuffer?: Promise<VertexBuffer>;
  883. }
  884. /** @hidden */
  885. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  886. }
  887. /** @hidden */
  888. interface _ILoaderAnimationSamplerData {
  889. input: Float32Array;
  890. interpolation: AnimationSamplerInterpolation;
  891. output: Float32Array;
  892. }
  893. /** @hidden */
  894. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  895. _data?: Promise<_ILoaderAnimationSamplerData>;
  896. }
  897. /** @hidden */
  898. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  899. channels: _ILoaderAnimationChannel[];
  900. samplers: _ILoaderAnimationSampler[];
  901. _babylonAnimationGroup?: AnimationGroup;
  902. }
  903. /** @hidden */
  904. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  905. _data?: Promise<ArrayBufferView>;
  906. }
  907. /** @hidden */
  908. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  909. _data?: Promise<ArrayBufferView>;
  910. _babylonBuffer?: Promise<Buffer>;
  911. }
  912. /** @hidden */
  913. interface _ILoaderCamera extends ICamera, _IArrayItem {
  914. }
  915. /** @hidden */
  916. interface _ILoaderImage extends IImage, _IArrayItem {
  917. _blob?: Promise<Blob>;
  918. }
  919. /** @hidden */
  920. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  921. _babylonData?: {
  922. [drawMode: number]: {
  923. material: Material;
  924. meshes: AbstractMesh[];
  925. loaded: Promise<void>;
  926. };
  927. };
  928. }
  929. /** @hidden */
  930. interface _ILoaderMesh extends IMesh, _IArrayItem {
  931. primitives: _ILoaderMeshPrimitive[];
  932. }
  933. /** @hidden */
  934. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  935. }
  936. /** @hidden */
  937. interface _ILoaderNode extends INode, _IArrayItem {
  938. _parent?: _ILoaderNode;
  939. _babylonMesh?: Mesh;
  940. _primitiveBabylonMeshes?: Mesh[];
  941. _babylonBones?: Bone[];
  942. _numMorphTargets?: number;
  943. }
  944. /** @hidden */
  945. interface _ILoaderSamplerData {
  946. noMipMaps: boolean;
  947. samplingMode: number;
  948. wrapU: number;
  949. wrapV: number;
  950. }
  951. /** @hidden */
  952. interface _ILoaderSampler extends ISampler, _IArrayItem {
  953. _data?: _ILoaderSamplerData;
  954. }
  955. /** @hidden */
  956. interface _ILoaderScene extends IScene, _IArrayItem {
  957. }
  958. /** @hidden */
  959. interface _ILoaderSkin extends ISkin, _IArrayItem {
  960. _babylonSkeleton?: Skeleton;
  961. _loaded?: Promise<void>;
  962. }
  963. /** @hidden */
  964. interface _ILoaderTexture extends ITexture, _IArrayItem {
  965. }
  966. /** @hidden */
  967. interface _ILoaderGLTF extends IGLTF {
  968. accessors?: _ILoaderAccessor[];
  969. animations?: _ILoaderAnimation[];
  970. buffers?: _ILoaderBuffer[];
  971. bufferViews?: _ILoaderBufferView[];
  972. cameras?: _ILoaderCamera[];
  973. images?: _ILoaderImage[];
  974. materials?: _ILoaderMaterial[];
  975. meshes?: _ILoaderMesh[];
  976. nodes?: _ILoaderNode[];
  977. samplers?: _ILoaderSampler[];
  978. scenes?: _ILoaderScene[];
  979. skins?: _ILoaderSkin[];
  980. textures?: _ILoaderTexture[];
  981. }
  982. }
  983. /**
  984. * Defines the module used to import/export glTF 2.0 assets
  985. */
  986. declare module BABYLON.GLTF2 {
  987. /** @hidden */
  988. class GLTFLoader implements IGLTFLoader {
  989. _parent: GLTFFileLoader;
  990. _gltf: _ILoaderGLTF;
  991. _babylonScene: Scene;
  992. _readyPromise: Promise<void>;
  993. _completePromises: Promise<void>[];
  994. private _disposed;
  995. private _state;
  996. private _extensions;
  997. private _rootUrl;
  998. private _rootBabylonMesh;
  999. private _defaultSampler;
  1000. private _defaultBabylonMaterials;
  1001. private _progressCallback?;
  1002. private _requests;
  1003. private static _ExtensionNames;
  1004. private static _ExtensionFactories;
  1005. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1006. /**
  1007. * Loader state or null if the loader is not active.
  1008. */
  1009. readonly state: Nullable<GLTFLoaderState>;
  1010. constructor(parent: GLTFFileLoader);
  1011. dispose(): void;
  1012. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1013. meshes: AbstractMesh[];
  1014. particleSystems: ParticleSystem[];
  1015. skeletons: Skeleton[];
  1016. animationGroups: AnimationGroup[];
  1017. }>;
  1018. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1019. private _loadAsync(nodes);
  1020. private _loadData(data);
  1021. private _setupData();
  1022. private _loadExtensions();
  1023. private _checkExtensions();
  1024. private _createRootNode();
  1025. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1026. private _forEachPrimitive(node, callback);
  1027. private _getMeshes();
  1028. private _getSkeletons();
  1029. private _getAnimationGroups();
  1030. private _startAnimations();
  1031. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1032. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1033. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1034. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1035. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1036. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1037. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1038. private static _LoadTransform(node, babylonNode);
  1039. private _loadSkinAsync(context, node, mesh, skin);
  1040. private _loadBones(context, skin);
  1041. private _loadBone(node, skin, babylonBones);
  1042. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1043. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1044. private _getNodeMatrix(node);
  1045. private _loadCamera(context, camera, babylonMesh);
  1046. private _loadAnimationsAsync();
  1047. private _loadAnimationAsync(context, animation);
  1048. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1049. private _loadAnimationSamplerAsync(context, sampler);
  1050. private _loadBufferAsync(context, buffer);
  1051. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1052. private _loadIndicesAccessorAsync(context, accessor);
  1053. private _loadFloatAccessorAsync(context, accessor);
  1054. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1055. private _loadVertexAccessorAsync(context, accessor, kind);
  1056. private _getDefaultMaterial(drawMode);
  1057. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1058. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1059. _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  1060. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1061. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1062. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1063. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1064. private _loadSampler(context, sampler);
  1065. private _loadImageAsync(context, image);
  1066. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1067. private _onProgress();
  1068. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1069. private static _GetTextureWrapMode(context, mode);
  1070. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1071. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1072. private static _GetNumComponents(context, type);
  1073. private static _ValidateUri(uri);
  1074. private static _GetDrawMode(context, mode);
  1075. private _compileMaterialsAsync();
  1076. private _compileShadowGeneratorsAsync();
  1077. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1078. }
  1079. }
  1080. declare module BABYLON.GLTF2 {
  1081. /**
  1082. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1083. */
  1084. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1085. /**
  1086. * Gets or sets a boolean indicating if the extension is enabled
  1087. */
  1088. enabled: boolean;
  1089. /**
  1090. * Gets or sets extension name
  1091. */
  1092. readonly abstract name: string;
  1093. protected _loader: GLTFLoader;
  1094. /**
  1095. * Creates new GLTFLoaderExtension
  1096. * @param loader defines the GLTFLoader to use
  1097. */
  1098. constructor(loader: GLTFLoader);
  1099. /**
  1100. * Release all resources
  1101. */
  1102. dispose(): void;
  1103. /**
  1104. * Override this method to modify the default behavior for loading scenes.
  1105. * @hidden
  1106. */
  1107. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1108. /**
  1109. * Override this method to modify the default behavior for loading nodes.
  1110. * @hidden
  1111. */
  1112. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1113. /**
  1114. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1115. * @hidden
  1116. */
  1117. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1118. /**
  1119. * Override this method to modify the default behavior for loading materials.
  1120. * @hidden
  1121. */
  1122. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1123. /**
  1124. * Override this method to modify the default behavior for loading material properties.
  1125. * @hidden
  1126. */
  1127. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1128. /**
  1129. * Override this method to modify the default behavior for loading textures.
  1130. * @hidden
  1131. */
  1132. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1133. /**
  1134. * Override this method to modify the default behavior for loading uris.
  1135. * @hidden
  1136. */
  1137. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1138. /**
  1139. * Helper method called by a loader extension to load an glTF extension.
  1140. * @hidden
  1141. */
  1142. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1143. /**
  1144. * Helper method called by the loader to allow extensions to override loading scenes.
  1145. * @hidden
  1146. */
  1147. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1148. /**
  1149. * Helper method called by the loader to allow extensions to override loading scenes.
  1150. * @hidden
  1151. */
  1152. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1153. /**
  1154. * Helper method called by the loader to allow extensions to override loading nodes.
  1155. * @hidden
  1156. */
  1157. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1158. /**
  1159. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1160. * @hidden
  1161. */
  1162. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1163. /**
  1164. * Helper method called by the loader to allow extensions to override loading materials.
  1165. * @hidden
  1166. */
  1167. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1168. /**
  1169. * Helper method called by the loader to allow extensions to override loading material properties.
  1170. * @hidden
  1171. */
  1172. static _LoadMaterialPropertiesAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1173. /**
  1174. * Helper method called by the loader to allow extensions to override loading textures.
  1175. * @hidden
  1176. */
  1177. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1178. /**
  1179. * Helper method called by the loader to allow extensions to override loading uris.
  1180. * @hidden
  1181. */
  1182. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1183. }
  1184. }
  1185. /**
  1186. * Defines the module of the glTF 2.0 loader extensions.
  1187. */
  1188. declare module BABYLON.GLTF2.Extensions {
  1189. }
  1190. declare module BABYLON.GLTF2.Extensions {
  1191. /**
  1192. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1193. */
  1194. class MSFT_lod extends GLTFLoaderExtension {
  1195. readonly name: string;
  1196. /**
  1197. * Maximum number of LODs to load, starting from the lowest LOD.
  1198. */
  1199. maxLODsToLoad: number;
  1200. /**
  1201. * Observable raised when all node LODs of one level are loaded.
  1202. * The event data is the index of the loaded LOD starting from zero.
  1203. * Dispose the loader to cancel the loading of the next level of LODs.
  1204. */
  1205. onNodeLODsLoadedObservable: Observable<number>;
  1206. /**
  1207. * Observable raised when all material LODs of one level are loaded.
  1208. * The event data is the index of the loaded LOD starting from zero.
  1209. * Dispose the loader to cancel the loading of the next level of LODs.
  1210. */
  1211. onMaterialLODsLoadedObservable: Observable<number>;
  1212. private _nodeIndexLOD;
  1213. private _nodeSignalLODs;
  1214. private _nodePromiseLODs;
  1215. private _materialIndexLOD;
  1216. private _materialSignalLODs;
  1217. private _materialPromiseLODs;
  1218. constructor(loader: GLTFLoader);
  1219. dispose(): void;
  1220. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1221. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1222. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1223. /**
  1224. * Gets an array of LOD properties from lowest to highest.
  1225. */
  1226. private _getLODs<T>(context, property, array, ids);
  1227. private _disposeUnusedMaterials();
  1228. }
  1229. }
  1230. declare module BABYLON.GLTF2.Extensions {
  1231. /** @hidden */
  1232. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1233. readonly name: string;
  1234. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1235. }
  1236. }
  1237. declare module BABYLON.GLTF2.Extensions {
  1238. /** @hidden */
  1239. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1240. readonly name: string;
  1241. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1242. }
  1243. }
  1244. declare module BABYLON.GLTF2.Extensions {
  1245. /**
  1246. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1247. */
  1248. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1249. readonly name: string;
  1250. private _dracoCompression;
  1251. constructor(loader: GLTFLoader);
  1252. dispose(): void;
  1253. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1254. }
  1255. }
  1256. declare module BABYLON.GLTF2.Extensions {
  1257. /**
  1258. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1259. */
  1260. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1261. readonly name: string;
  1262. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1263. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1264. }
  1265. }
  1266. declare module BABYLON.GLTF2.Extensions {
  1267. /**
  1268. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1269. */
  1270. class KHR_materials_unlit extends GLTFLoaderExtension {
  1271. readonly name: string;
  1272. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1273. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1274. }
  1275. }
  1276. declare module BABYLON.GLTF2.Extensions {
  1277. /**
  1278. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1279. */
  1280. class KHR_lights extends GLTFLoaderExtension {
  1281. readonly name: string;
  1282. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1283. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1284. private readonly _lights;
  1285. }
  1286. }
  1287. declare module BABYLON.GLTF2.Extensions {
  1288. /**
  1289. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1290. */
  1291. class KHR_texture_transform extends GLTFLoaderExtension {
  1292. readonly name: string;
  1293. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1294. }
  1295. }