babylonjs.loaders.module.d.ts 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. /// <reference types="babylonjs"/>
  2. /// <reference types="babylonjs-gltf2interface"/>
  3. declare module 'babylonjs-loaders' {
  4. export = BABYLON;
  5. }
  6. declare module BABYLON {
  7. class STLFileLoader implements ISceneLoaderPlugin {
  8. solidPattern: RegExp;
  9. facetsPattern: RegExp;
  10. normalPattern: RegExp;
  11. vertexPattern: RegExp;
  12. name: string;
  13. extensions: ISceneLoaderPluginExtensions;
  14. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  15. load(scene: Scene, data: any, rootUrl: string): boolean;
  16. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  17. private isBinary(data);
  18. private parseBinary(mesh, data);
  19. private parseASCII(mesh, solidData);
  20. }
  21. }
  22. declare module BABYLON {
  23. /**
  24. * Class reading and parsing the MTL file bundled with the obj file.
  25. */
  26. class MTLFileLoader {
  27. materials: BABYLON.StandardMaterial[];
  28. /**
  29. * This function will read the mtl file and create each material described inside
  30. * This function could be improve by adding :
  31. * -some component missing (Ni, Tf...)
  32. * -including the specific options available
  33. *
  34. * @param scene
  35. * @param data
  36. * @param rootUrl
  37. */
  38. parseMTL(scene: BABYLON.Scene, data: string | ArrayBuffer, rootUrl: string): void;
  39. /**
  40. * Gets the texture for the material.
  41. *
  42. * If the material is imported from input file,
  43. * We sanitize the url to ensure it takes the textre from aside the material.
  44. *
  45. * @param rootUrl The root url to load from
  46. * @param value The value stored in the mtl
  47. * @return The Texture
  48. */
  49. private static _getTexture(rootUrl, value, scene);
  50. }
  51. class OBJFileLoader implements ISceneLoaderPluginAsync {
  52. static OPTIMIZE_WITH_UV: boolean;
  53. static INVERT_Y: boolean;
  54. name: string;
  55. extensions: string;
  56. obj: RegExp;
  57. group: RegExp;
  58. mtllib: RegExp;
  59. usemtl: RegExp;
  60. smooth: RegExp;
  61. vertexPattern: RegExp;
  62. normalPattern: RegExp;
  63. uvPattern: RegExp;
  64. facePattern1: RegExp;
  65. facePattern2: RegExp;
  66. facePattern3: RegExp;
  67. facePattern4: RegExp;
  68. /**
  69. * Calls synchronously the MTL file attached to this obj.
  70. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  71. * Without this function materials are not displayed in the first frame (but displayed after).
  72. * In consequence it is impossible to get material information in your HTML file
  73. *
  74. * @param url The URL of the MTL file
  75. * @param rootUrl
  76. * @param onSuccess Callback function to be called when the MTL file is loaded
  77. * @private
  78. */
  79. private _loadMTL(url, rootUrl, onSuccess);
  80. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  81. meshes: AbstractMesh[];
  82. particleSystems: ParticleSystem[];
  83. skeletons: Skeleton[];
  84. animationGroups: AnimationGroup[];
  85. }>;
  86. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  87. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  88. /**
  89. * Read the OBJ file and create an Array of meshes.
  90. * Each mesh contains all information given by the OBJ and the MTL file.
  91. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  92. *
  93. * @param meshesNames
  94. * @param scene BABYLON.Scene The scene where are displayed the data
  95. * @param data String The content of the obj file
  96. * @param rootUrl String The path to the folder
  97. * @returns Array<AbstractMesh>
  98. * @private
  99. */
  100. private _parseSolid(meshesNames, scene, data, rootUrl);
  101. }
  102. }
  103. declare module BABYLON {
  104. /**
  105. * Mode that determines the coordinate system to use.
  106. */
  107. enum GLTFLoaderCoordinateSystemMode {
  108. /**
  109. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  110. */
  111. AUTO = 0,
  112. /**
  113. * Sets the useRightHandedSystem flag on the scene.
  114. */
  115. FORCE_RIGHT_HANDED = 1,
  116. }
  117. /**
  118. * Mode that determines what animations will start.
  119. */
  120. enum GLTFLoaderAnimationStartMode {
  121. /**
  122. * No animation will start.
  123. */
  124. NONE = 0,
  125. /**
  126. * The first animation will start.
  127. */
  128. FIRST = 1,
  129. /**
  130. * All animations will start.
  131. */
  132. ALL = 2,
  133. }
  134. /**
  135. * Interface that contains the data for the glTF asset.
  136. */
  137. interface IGLTFLoaderData {
  138. /**
  139. * JSON that represents the glTF.
  140. */
  141. json: Object;
  142. /**
  143. * The BIN chunk of a binary glTF
  144. */
  145. bin: Nullable<ArrayBufferView>;
  146. }
  147. /**
  148. * Interface for extending the loader.
  149. */
  150. interface IGLTFLoaderExtension {
  151. /**
  152. * The name of this extension.
  153. */
  154. readonly name: string;
  155. /**
  156. * Defines whether this extension is enabled.
  157. */
  158. enabled: boolean;
  159. }
  160. /**
  161. * Loader state.
  162. */
  163. enum GLTFLoaderState {
  164. /**
  165. * The asset is loading.
  166. */
  167. LOADING = 0,
  168. /**
  169. * The asset is ready for rendering.
  170. */
  171. READY = 1,
  172. /**
  173. * The asset is completely loaded.
  174. */
  175. COMPLETE = 2,
  176. }
  177. /** @hidden */
  178. interface IGLTFLoader extends IDisposable {
  179. readonly state: Nullable<GLTFLoaderState>;
  180. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  181. meshes: AbstractMesh[];
  182. particleSystems: ParticleSystem[];
  183. skeletons: Skeleton[];
  184. animationGroups: AnimationGroup[];
  185. }>;
  186. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  187. }
  188. /**
  189. * File loader for loading glTF files into a scene.
  190. */
  191. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  192. /** @hidden */
  193. static _CreateGLTFLoaderV1: (parent: GLTFFileLoader) => IGLTFLoader;
  194. /** @hidden */
  195. static _CreateGLTFLoaderV2: (parent: GLTFFileLoader) => IGLTFLoader;
  196. /**
  197. * Raised when the asset has been parsed
  198. */
  199. onParsedObservable: Observable<IGLTFLoaderData>;
  200. private _onParsedObserver;
  201. /**
  202. * Raised when the asset has been parsed
  203. */
  204. onParsed: (loaderData: IGLTFLoaderData) => void;
  205. /**
  206. * 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.
  207. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  208. * Defaults to true.
  209. * @hidden
  210. */
  211. static IncrementalLoading: boolean;
  212. /**
  213. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  214. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  215. * @hidden
  216. */
  217. static HomogeneousCoordinates: boolean;
  218. /**
  219. * The coordinate system mode. Defaults to AUTO.
  220. */
  221. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  222. /**
  223. * The animation start mode. Defaults to FIRST.
  224. */
  225. animationStartMode: GLTFLoaderAnimationStartMode;
  226. /**
  227. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  228. */
  229. compileMaterials: boolean;
  230. /**
  231. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  232. */
  233. useClipPlane: boolean;
  234. /**
  235. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  236. */
  237. compileShadowGenerators: boolean;
  238. /**
  239. * Defines if the Alpha blended materials are only applied as coverage.
  240. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  241. * If true, no extra effects are applied to transparent pixels.
  242. */
  243. transparencyAsCoverage: boolean;
  244. /** @hidden */
  245. _normalizeAnimationGroupsToBeginAtZero: boolean;
  246. /**
  247. * Function called before loading a url referenced by the asset.
  248. */
  249. preprocessUrlAsync: (url: string) => Promise<string>;
  250. /**
  251. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  252. */
  253. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  254. private _onMeshLoadedObserver;
  255. /**
  256. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  257. */
  258. onMeshLoaded: (mesh: AbstractMesh) => void;
  259. /**
  260. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  261. */
  262. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  263. private _onTextureLoadedObserver;
  264. /**
  265. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  266. */
  267. onTextureLoaded: (texture: BaseTexture) => void;
  268. /**
  269. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  270. */
  271. readonly onMaterialLoadedObservable: Observable<Material>;
  272. private _onMaterialLoadedObserver;
  273. /**
  274. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  275. */
  276. onMaterialLoaded: (material: Material) => void;
  277. /**
  278. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  279. */
  280. readonly onCameraLoadedObservable: Observable<Camera>;
  281. private _onCameraLoadedObserver;
  282. /**
  283. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  284. */
  285. onCameraLoaded: (camera: Camera) => void;
  286. /**
  287. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  288. * For assets with LODs, raised when all of the LODs are complete.
  289. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  290. */
  291. readonly onCompleteObservable: Observable<void>;
  292. private _onCompleteObserver;
  293. /**
  294. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  295. */
  296. onComplete: () => void;
  297. /**
  298. * Observable raised after the loader is disposed.
  299. */
  300. readonly onDisposeObservable: Observable<void>;
  301. private _onDisposeObserver;
  302. /**
  303. * Callback raised after the loader is disposed.
  304. */
  305. onDispose: () => void;
  306. /**
  307. * Observable raised after a loader extension is created.
  308. * Set additional options for a loader extension in this event.
  309. */
  310. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  311. private _onExtensionLoadedObserver;
  312. /**
  313. * Callback raised after a loader extension is created.
  314. */
  315. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  316. /**
  317. * Returns a promise that resolves when the asset is completely loaded.
  318. * @returns a promise that resolves when the asset is completely loaded.
  319. */
  320. whenCompleteAsync(): Promise<void>;
  321. /**
  322. * The loader state or null if the loader is not active.
  323. */
  324. readonly loaderState: Nullable<GLTFLoaderState>;
  325. /**
  326. * Defines if the loader logging is enabled.
  327. */
  328. loggingEnabled: boolean;
  329. /**
  330. * Defines if the loader should capture performance counters.
  331. */
  332. capturePerformanceCounters: boolean;
  333. private _loader;
  334. /**
  335. * Name of the loader ("gltf")
  336. */
  337. name: string;
  338. /**
  339. * Supported file extensions of the loader (.gltf, .glb)
  340. */
  341. extensions: ISceneLoaderPluginExtensions;
  342. /**
  343. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  344. */
  345. dispose(): void;
  346. /** @hidden */
  347. _clear(): void;
  348. /**
  349. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  350. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  351. * @param scene the scene the meshes should be added to
  352. * @param data the glTF data to load
  353. * @param rootUrl root url to load from
  354. * @param onProgress event that fires when loading progress has occured
  355. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  356. */
  357. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  358. meshes: AbstractMesh[];
  359. particleSystems: ParticleSystem[];
  360. skeletons: Skeleton[];
  361. animationGroups: AnimationGroup[];
  362. }>;
  363. /**
  364. * Imports all objects from the loaded glTF data and adds them to the scene
  365. * @param scene the scene the objects should be added to
  366. * @param data the glTF data to load
  367. * @param rootUrl root url to load from
  368. * @param onProgress event that fires when loading progress has occured
  369. * @returns a promise which completes when objects have been loaded to the scene
  370. */
  371. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  372. /**
  373. * Load into an asset container.
  374. * @param scene The scene to load into
  375. * @param data The data to import
  376. * @param rootUrl The root url for scene and resources
  377. * @param onProgress The callback when the load progresses
  378. * @returns The loaded asset container
  379. */
  380. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  381. /**
  382. * If the data string can be loaded directly.
  383. * @param data string contianing the file data
  384. * @returns if the data can be loaded directly
  385. */
  386. canDirectLoad(data: string): boolean;
  387. /**
  388. * Rewrites a url by combining a root url and response url.
  389. */
  390. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  391. /**
  392. * Instantiates a glTF file loader plugin.
  393. * @returns the created plugin
  394. */
  395. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  396. private _parse(data);
  397. private _getLoader(loaderData);
  398. private _parseBinary(data);
  399. private _parseV1(binaryReader);
  400. private _parseV2(binaryReader);
  401. private static _parseVersion(version);
  402. private static _compareVersion(a, b);
  403. private static _decodeBufferToText(buffer);
  404. private static readonly _logSpaces;
  405. private _logIndentLevel;
  406. private _loggingEnabled;
  407. /** @hidden */
  408. _log: (message: string) => void;
  409. /** @hidden */
  410. _logOpen(message: string): void;
  411. /** @hidden */
  412. _logClose(): void;
  413. private _logEnabled(message);
  414. private _logDisabled(message);
  415. private _capturePerformanceCounters;
  416. /** @hidden */
  417. _startPerformanceCounter: (counterName: string) => void;
  418. /** @hidden */
  419. _endPerformanceCounter: (counterName: string) => void;
  420. private _startPerformanceCounterEnabled(counterName);
  421. private _startPerformanceCounterDisabled(counterName);
  422. private _endPerformanceCounterEnabled(counterName);
  423. private _endPerformanceCounterDisabled(counterName);
  424. }
  425. }
  426. declare module BABYLON.GLTF1 {
  427. /**
  428. * Enums
  429. */
  430. enum EComponentType {
  431. BYTE = 5120,
  432. UNSIGNED_BYTE = 5121,
  433. SHORT = 5122,
  434. UNSIGNED_SHORT = 5123,
  435. FLOAT = 5126,
  436. }
  437. enum EShaderType {
  438. FRAGMENT = 35632,
  439. VERTEX = 35633,
  440. }
  441. enum EParameterType {
  442. BYTE = 5120,
  443. UNSIGNED_BYTE = 5121,
  444. SHORT = 5122,
  445. UNSIGNED_SHORT = 5123,
  446. INT = 5124,
  447. UNSIGNED_INT = 5125,
  448. FLOAT = 5126,
  449. FLOAT_VEC2 = 35664,
  450. FLOAT_VEC3 = 35665,
  451. FLOAT_VEC4 = 35666,
  452. INT_VEC2 = 35667,
  453. INT_VEC3 = 35668,
  454. INT_VEC4 = 35669,
  455. BOOL = 35670,
  456. BOOL_VEC2 = 35671,
  457. BOOL_VEC3 = 35672,
  458. BOOL_VEC4 = 35673,
  459. FLOAT_MAT2 = 35674,
  460. FLOAT_MAT3 = 35675,
  461. FLOAT_MAT4 = 35676,
  462. SAMPLER_2D = 35678,
  463. }
  464. enum ETextureWrapMode {
  465. CLAMP_TO_EDGE = 33071,
  466. MIRRORED_REPEAT = 33648,
  467. REPEAT = 10497,
  468. }
  469. enum ETextureFilterType {
  470. NEAREST = 9728,
  471. LINEAR = 9728,
  472. NEAREST_MIPMAP_NEAREST = 9984,
  473. LINEAR_MIPMAP_NEAREST = 9985,
  474. NEAREST_MIPMAP_LINEAR = 9986,
  475. LINEAR_MIPMAP_LINEAR = 9987,
  476. }
  477. enum ETextureFormat {
  478. ALPHA = 6406,
  479. RGB = 6407,
  480. RGBA = 6408,
  481. LUMINANCE = 6409,
  482. LUMINANCE_ALPHA = 6410,
  483. }
  484. enum ECullingType {
  485. FRONT = 1028,
  486. BACK = 1029,
  487. FRONT_AND_BACK = 1032,
  488. }
  489. enum EBlendingFunction {
  490. ZERO = 0,
  491. ONE = 1,
  492. SRC_COLOR = 768,
  493. ONE_MINUS_SRC_COLOR = 769,
  494. DST_COLOR = 774,
  495. ONE_MINUS_DST_COLOR = 775,
  496. SRC_ALPHA = 770,
  497. ONE_MINUS_SRC_ALPHA = 771,
  498. DST_ALPHA = 772,
  499. ONE_MINUS_DST_ALPHA = 773,
  500. CONSTANT_COLOR = 32769,
  501. ONE_MINUS_CONSTANT_COLOR = 32770,
  502. CONSTANT_ALPHA = 32771,
  503. ONE_MINUS_CONSTANT_ALPHA = 32772,
  504. SRC_ALPHA_SATURATE = 776,
  505. }
  506. /**
  507. * Interfaces
  508. */
  509. interface IGLTFProperty {
  510. extensions?: {
  511. [key: string]: any;
  512. };
  513. extras?: Object;
  514. }
  515. interface IGLTFChildRootProperty extends IGLTFProperty {
  516. name?: string;
  517. }
  518. interface IGLTFAccessor extends IGLTFChildRootProperty {
  519. bufferView: string;
  520. byteOffset: number;
  521. byteStride: number;
  522. count: number;
  523. type: string;
  524. componentType: EComponentType;
  525. max?: number[];
  526. min?: number[];
  527. name?: string;
  528. }
  529. interface IGLTFBufferView extends IGLTFChildRootProperty {
  530. buffer: string;
  531. byteOffset: number;
  532. byteLength: number;
  533. byteStride: number;
  534. target?: number;
  535. }
  536. interface IGLTFBuffer extends IGLTFChildRootProperty {
  537. uri: string;
  538. byteLength?: number;
  539. type?: string;
  540. }
  541. interface IGLTFShader extends IGLTFChildRootProperty {
  542. uri: string;
  543. type: EShaderType;
  544. }
  545. interface IGLTFProgram extends IGLTFChildRootProperty {
  546. attributes: string[];
  547. fragmentShader: string;
  548. vertexShader: string;
  549. }
  550. interface IGLTFTechniqueParameter {
  551. type: number;
  552. count?: number;
  553. semantic?: string;
  554. node?: string;
  555. value?: number | boolean | string | Array<any>;
  556. source?: string;
  557. babylonValue?: any;
  558. }
  559. interface IGLTFTechniqueCommonProfile {
  560. lightingModel: string;
  561. texcoordBindings: Object;
  562. parameters?: Array<any>;
  563. }
  564. interface IGLTFTechniqueStatesFunctions {
  565. blendColor?: number[];
  566. blendEquationSeparate?: number[];
  567. blendFuncSeparate?: number[];
  568. colorMask: boolean[];
  569. cullFace: number[];
  570. }
  571. interface IGLTFTechniqueStates {
  572. enable: number[];
  573. functions: IGLTFTechniqueStatesFunctions;
  574. }
  575. interface IGLTFTechnique extends IGLTFChildRootProperty {
  576. parameters: {
  577. [key: string]: IGLTFTechniqueParameter;
  578. };
  579. program: string;
  580. attributes: {
  581. [key: string]: string;
  582. };
  583. uniforms: {
  584. [key: string]: string;
  585. };
  586. states: IGLTFTechniqueStates;
  587. }
  588. interface IGLTFMaterial extends IGLTFChildRootProperty {
  589. technique?: string;
  590. values: string[];
  591. }
  592. interface IGLTFMeshPrimitive extends IGLTFProperty {
  593. attributes: {
  594. [key: string]: string;
  595. };
  596. indices: string;
  597. material: string;
  598. mode?: number;
  599. }
  600. interface IGLTFMesh extends IGLTFChildRootProperty {
  601. primitives: IGLTFMeshPrimitive[];
  602. }
  603. interface IGLTFImage extends IGLTFChildRootProperty {
  604. uri: string;
  605. }
  606. interface IGLTFSampler extends IGLTFChildRootProperty {
  607. magFilter?: number;
  608. minFilter?: number;
  609. wrapS?: number;
  610. wrapT?: number;
  611. }
  612. interface IGLTFTexture extends IGLTFChildRootProperty {
  613. sampler: string;
  614. source: string;
  615. format?: ETextureFormat;
  616. internalFormat?: ETextureFormat;
  617. target?: number;
  618. type?: number;
  619. babylonTexture?: Texture;
  620. }
  621. interface IGLTFAmbienLight {
  622. color?: number[];
  623. }
  624. interface IGLTFDirectionalLight {
  625. color?: number[];
  626. }
  627. interface IGLTFPointLight {
  628. color?: number[];
  629. constantAttenuation?: number;
  630. linearAttenuation?: number;
  631. quadraticAttenuation?: number;
  632. }
  633. interface IGLTFSpotLight {
  634. color?: number[];
  635. constantAttenuation?: number;
  636. fallOfAngle?: number;
  637. fallOffExponent?: number;
  638. linearAttenuation?: number;
  639. quadraticAttenuation?: number;
  640. }
  641. interface IGLTFLight extends IGLTFChildRootProperty {
  642. type: string;
  643. }
  644. interface IGLTFCameraOrthographic {
  645. xmag: number;
  646. ymag: number;
  647. zfar: number;
  648. znear: number;
  649. }
  650. interface IGLTFCameraPerspective {
  651. aspectRatio: number;
  652. yfov: number;
  653. zfar: number;
  654. znear: number;
  655. }
  656. interface IGLTFCamera extends IGLTFChildRootProperty {
  657. type: string;
  658. }
  659. interface IGLTFAnimationChannelTarget {
  660. id: string;
  661. path: string;
  662. }
  663. interface IGLTFAnimationChannel {
  664. sampler: string;
  665. target: IGLTFAnimationChannelTarget;
  666. }
  667. interface IGLTFAnimationSampler {
  668. input: string;
  669. output: string;
  670. interpolation?: string;
  671. }
  672. interface IGLTFAnimation extends IGLTFChildRootProperty {
  673. channels?: IGLTFAnimationChannel[];
  674. parameters?: {
  675. [key: string]: string;
  676. };
  677. samplers?: {
  678. [key: string]: IGLTFAnimationSampler;
  679. };
  680. }
  681. interface IGLTFNodeInstanceSkin {
  682. skeletons: string[];
  683. skin: string;
  684. meshes: string[];
  685. }
  686. interface IGLTFSkins extends IGLTFChildRootProperty {
  687. bindShapeMatrix: number[];
  688. inverseBindMatrices: string;
  689. jointNames: string[];
  690. babylonSkeleton?: Skeleton;
  691. }
  692. interface IGLTFNode extends IGLTFChildRootProperty {
  693. camera?: string;
  694. children: string[];
  695. skin?: string;
  696. jointName?: string;
  697. light?: string;
  698. matrix: number[];
  699. mesh?: string;
  700. meshes?: string[];
  701. rotation?: number[];
  702. scale?: number[];
  703. translation?: number[];
  704. babylonNode?: Node;
  705. }
  706. interface IGLTFScene extends IGLTFChildRootProperty {
  707. nodes: string[];
  708. }
  709. /**
  710. * Runtime
  711. */
  712. interface IGLTFRuntime {
  713. extensions: {
  714. [key: string]: any;
  715. };
  716. accessors: {
  717. [key: string]: IGLTFAccessor;
  718. };
  719. buffers: {
  720. [key: string]: IGLTFBuffer;
  721. };
  722. bufferViews: {
  723. [key: string]: IGLTFBufferView;
  724. };
  725. meshes: {
  726. [key: string]: IGLTFMesh;
  727. };
  728. lights: {
  729. [key: string]: IGLTFLight;
  730. };
  731. cameras: {
  732. [key: string]: IGLTFCamera;
  733. };
  734. nodes: {
  735. [key: string]: IGLTFNode;
  736. };
  737. images: {
  738. [key: string]: IGLTFImage;
  739. };
  740. textures: {
  741. [key: string]: IGLTFTexture;
  742. };
  743. shaders: {
  744. [key: string]: IGLTFShader;
  745. };
  746. programs: {
  747. [key: string]: IGLTFProgram;
  748. };
  749. samplers: {
  750. [key: string]: IGLTFSampler;
  751. };
  752. techniques: {
  753. [key: string]: IGLTFTechnique;
  754. };
  755. materials: {
  756. [key: string]: IGLTFMaterial;
  757. };
  758. animations: {
  759. [key: string]: IGLTFAnimation;
  760. };
  761. skins: {
  762. [key: string]: IGLTFSkins;
  763. };
  764. currentScene?: Object;
  765. scenes: {
  766. [key: string]: IGLTFScene;
  767. };
  768. extensionsUsed: string[];
  769. extensionsRequired?: string[];
  770. buffersCount: number;
  771. shaderscount: number;
  772. scene: Scene;
  773. rootUrl: string;
  774. loadedBufferCount: number;
  775. loadedBufferViews: {
  776. [name: string]: ArrayBufferView;
  777. };
  778. loadedShaderCount: number;
  779. importOnlyMeshes: boolean;
  780. importMeshesNames?: string[];
  781. dummyNodes: Node[];
  782. }
  783. /**
  784. * Bones
  785. */
  786. interface INodeToRoot {
  787. bone: Bone;
  788. node: IGLTFNode;
  789. id: string;
  790. }
  791. interface IJointNode {
  792. node: IGLTFNode;
  793. id: string;
  794. }
  795. }
  796. declare module BABYLON.GLTF1 {
  797. /**
  798. * Implementation of the base glTF spec
  799. */
  800. class GLTFLoaderBase {
  801. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  802. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  803. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  804. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  805. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  806. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  807. }
  808. /**
  809. * glTF V1 Loader
  810. */
  811. class GLTFLoader implements IGLTFLoader {
  812. static Extensions: {
  813. [name: string]: GLTFLoaderExtension;
  814. };
  815. static RegisterExtension(extension: GLTFLoaderExtension): void;
  816. state: Nullable<GLTFLoaderState>;
  817. dispose(): void;
  818. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  819. /**
  820. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  821. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  822. * @param scene the scene the meshes should be added to
  823. * @param data gltf data containing information of the meshes in a loaded file
  824. * @param rootUrl root url to load from
  825. * @param onProgress event that fires when loading progress has occured
  826. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  827. */
  828. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  829. meshes: AbstractMesh[];
  830. particleSystems: ParticleSystem[];
  831. skeletons: Skeleton[];
  832. animationGroups: AnimationGroup[];
  833. }>;
  834. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  835. /**
  836. * Imports all objects from a loaded gltf file and adds them to the scene
  837. * @param scene the scene the objects should be added to
  838. * @param data gltf data containing information of the meshes in a loaded file
  839. * @param rootUrl root url to load from
  840. * @param onProgress event that fires when loading progress has occured
  841. * @returns a promise which completes when objects have been loaded to the scene
  842. */
  843. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  844. private _loadShadersAsync(gltfRuntime, onload);
  845. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  846. private _createNodes(gltfRuntime);
  847. }
  848. }
  849. declare module BABYLON.GLTF1 {
  850. /**
  851. * Utils functions for GLTF
  852. */
  853. class GLTFUtils {
  854. /**
  855. * Sets the given "parameter" matrix
  856. * @param scene: the {BABYLON.Scene} object
  857. * @param source: the source node where to pick the matrix
  858. * @param parameter: the GLTF technique parameter
  859. * @param uniformName: the name of the shader's uniform
  860. * @param shaderMaterial: the shader material
  861. */
  862. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  863. /**
  864. * Sets the given "parameter" matrix
  865. * @param shaderMaterial: the shader material
  866. * @param uniform: the name of the shader's uniform
  867. * @param value: the value of the uniform
  868. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  869. */
  870. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  871. /**
  872. * Returns the wrap mode of the texture
  873. * @param mode: the mode value
  874. */
  875. static GetWrapMode(mode: number): number;
  876. /**
  877. * Returns the byte stride giving an accessor
  878. * @param accessor: the GLTF accessor objet
  879. */
  880. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  881. /**
  882. * Returns the texture filter mode giving a mode value
  883. * @param mode: the filter mode value
  884. */
  885. static GetTextureFilterMode(mode: number): ETextureFilterType;
  886. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  887. /**
  888. * Returns a buffer from its accessor
  889. * @param gltfRuntime: the GLTF runtime
  890. * @param accessor: the GLTF accessor
  891. */
  892. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  893. /**
  894. * Decodes a buffer view into a string
  895. * @param view: the buffer view
  896. */
  897. static DecodeBufferToText(view: ArrayBufferView): string;
  898. /**
  899. * Returns the default material of gltf. Related to
  900. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  901. * @param scene: the Babylon.js scene
  902. */
  903. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  904. private static _DefaultMaterial;
  905. }
  906. }
  907. declare module BABYLON.GLTF1 {
  908. abstract class GLTFLoaderExtension {
  909. private _name;
  910. constructor(name: string);
  911. readonly name: string;
  912. /**
  913. * Defines an override for loading the runtime
  914. * Return true to stop further extensions from loading the runtime
  915. */
  916. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  917. /**
  918. * Defines an onverride for creating gltf runtime
  919. * Return true to stop further extensions from creating the runtime
  920. */
  921. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  922. /**
  923. * Defines an override for loading buffers
  924. * Return true to stop further extensions from loading this buffer
  925. */
  926. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  927. /**
  928. * Defines an override for loading texture buffers
  929. * Return true to stop further extensions from loading this texture data
  930. */
  931. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  932. /**
  933. * Defines an override for creating textures
  934. * Return true to stop further extensions from loading this texture
  935. */
  936. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  937. /**
  938. * Defines an override for loading shader strings
  939. * Return true to stop further extensions from loading this shader data
  940. */
  941. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  942. /**
  943. * Defines an override for loading materials
  944. * Return true to stop further extensions from loading this material
  945. */
  946. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  947. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  948. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  949. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  950. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  951. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  952. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  953. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  954. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  955. private static ApplyExtensions(func, defaultFunc);
  956. }
  957. }
  958. declare module BABYLON.GLTF1 {
  959. class GLTFBinaryExtension extends GLTFLoaderExtension {
  960. private _bin;
  961. constructor();
  962. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  963. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  964. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  965. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  966. }
  967. }
  968. declare module BABYLON.GLTF1 {
  969. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  970. constructor();
  971. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  972. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  973. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  974. }
  975. }
  976. declare module BABYLON.GLTF2 {
  977. /** @hidden */
  978. interface _IArrayItem {
  979. _index: number;
  980. }
  981. /** @hidden */
  982. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  983. _data?: Promise<ArrayBufferView>;
  984. _babylonVertexBuffer?: Promise<VertexBuffer>;
  985. }
  986. /** @hidden */
  987. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  988. }
  989. /** @hidden */
  990. interface _ILoaderAnimationSamplerData {
  991. input: Float32Array;
  992. interpolation: AnimationSamplerInterpolation;
  993. output: Float32Array;
  994. }
  995. /** @hidden */
  996. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  997. _data?: Promise<_ILoaderAnimationSamplerData>;
  998. }
  999. /** @hidden */
  1000. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  1001. channels: _ILoaderAnimationChannel[];
  1002. samplers: _ILoaderAnimationSampler[];
  1003. _babylonAnimationGroup?: AnimationGroup;
  1004. }
  1005. /** @hidden */
  1006. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  1007. _data?: Promise<ArrayBufferView>;
  1008. }
  1009. /** @hidden */
  1010. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  1011. _data?: Promise<ArrayBufferView>;
  1012. _babylonBuffer?: Promise<Buffer>;
  1013. }
  1014. /** @hidden */
  1015. interface _ILoaderCamera extends ICamera, _IArrayItem {
  1016. }
  1017. /** @hidden */
  1018. interface _ILoaderImage extends IImage, _IArrayItem {
  1019. _blob?: Promise<Blob>;
  1020. }
  1021. /** @hidden */
  1022. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  1023. _babylonData?: {
  1024. [drawMode: number]: {
  1025. material: Material;
  1026. meshes: AbstractMesh[];
  1027. loaded: Promise<void>;
  1028. };
  1029. };
  1030. }
  1031. /** @hidden */
  1032. interface _ILoaderMesh extends IMesh, _IArrayItem {
  1033. primitives: _ILoaderMeshPrimitive[];
  1034. }
  1035. /** @hidden */
  1036. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  1037. }
  1038. /** @hidden */
  1039. interface _ILoaderNode extends INode, _IArrayItem {
  1040. _parent?: _ILoaderNode;
  1041. _babylonMesh?: Mesh;
  1042. _primitiveBabylonMeshes?: Mesh[];
  1043. _babylonBones?: Bone[];
  1044. _numMorphTargets?: number;
  1045. }
  1046. /** @hidden */
  1047. interface _ILoaderSamplerData {
  1048. noMipMaps: boolean;
  1049. samplingMode: number;
  1050. wrapU: number;
  1051. wrapV: number;
  1052. }
  1053. /** @hidden */
  1054. interface _ILoaderSampler extends ISampler, _IArrayItem {
  1055. _data?: _ILoaderSamplerData;
  1056. }
  1057. /** @hidden */
  1058. interface _ILoaderScene extends IScene, _IArrayItem {
  1059. }
  1060. /** @hidden */
  1061. interface _ILoaderSkin extends ISkin, _IArrayItem {
  1062. _babylonSkeleton?: Skeleton;
  1063. _loaded?: Promise<void>;
  1064. }
  1065. /** @hidden */
  1066. interface _ILoaderTexture extends ITexture, _IArrayItem {
  1067. }
  1068. /** @hidden */
  1069. interface _ILoaderGLTF extends IGLTF {
  1070. accessors?: _ILoaderAccessor[];
  1071. animations?: _ILoaderAnimation[];
  1072. buffers?: _ILoaderBuffer[];
  1073. bufferViews?: _ILoaderBufferView[];
  1074. cameras?: _ILoaderCamera[];
  1075. images?: _ILoaderImage[];
  1076. materials?: _ILoaderMaterial[];
  1077. meshes?: _ILoaderMesh[];
  1078. nodes?: _ILoaderNode[];
  1079. samplers?: _ILoaderSampler[];
  1080. scenes?: _ILoaderScene[];
  1081. skins?: _ILoaderSkin[];
  1082. textures?: _ILoaderTexture[];
  1083. }
  1084. }
  1085. /**
  1086. * Defines the module used to import/export glTF 2.0 assets
  1087. */
  1088. declare module BABYLON.GLTF2 {
  1089. /** @hidden */
  1090. class GLTFLoader implements IGLTFLoader {
  1091. _parent: GLTFFileLoader;
  1092. _gltf: _ILoaderGLTF;
  1093. _babylonScene: Scene;
  1094. _readyPromise: Promise<void>;
  1095. _completePromises: Promise<void>[];
  1096. private _disposed;
  1097. private _state;
  1098. private _extensions;
  1099. private _rootUrl;
  1100. private _rootBabylonMesh;
  1101. private _defaultSampler;
  1102. private _defaultBabylonMaterials;
  1103. private _progressCallback?;
  1104. private _requests;
  1105. private static _ExtensionNames;
  1106. private static _ExtensionFactories;
  1107. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1108. /**
  1109. * Loader state or null if the loader is not active.
  1110. */
  1111. readonly state: Nullable<GLTFLoaderState>;
  1112. constructor(parent: GLTFFileLoader);
  1113. dispose(): void;
  1114. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1115. meshes: AbstractMesh[];
  1116. particleSystems: ParticleSystem[];
  1117. skeletons: Skeleton[];
  1118. animationGroups: AnimationGroup[];
  1119. }>;
  1120. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1121. private _loadAsync(nodes);
  1122. private _loadData(data);
  1123. private _setupData();
  1124. private _loadExtensions();
  1125. private _checkExtensions();
  1126. private _createRootNode();
  1127. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1128. private _forEachPrimitive(node, callback);
  1129. private _getMeshes();
  1130. private _getSkeletons();
  1131. private _getAnimationGroups();
  1132. private _startAnimations();
  1133. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1134. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1135. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1136. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1137. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1138. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1139. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1140. private static _LoadTransform(node, babylonNode);
  1141. private _loadSkinAsync(context, node, mesh, skin);
  1142. private _loadBones(context, skin);
  1143. private _loadBone(node, skin, babylonBones);
  1144. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1145. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1146. private _getNodeMatrix(node);
  1147. private _loadCamera(context, camera, babylonMesh);
  1148. private _loadAnimationsAsync();
  1149. private _loadAnimationAsync(context, animation);
  1150. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1151. private _loadAnimationSamplerAsync(context, sampler);
  1152. private _loadBufferAsync(context, buffer);
  1153. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1154. private _loadIndicesAccessorAsync(context, accessor);
  1155. private _loadFloatAccessorAsync(context, accessor);
  1156. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1157. private _loadVertexAccessorAsync(context, accessor, kind);
  1158. private _getDefaultMaterial(drawMode);
  1159. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1160. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1161. _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  1162. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1163. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1164. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1165. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1166. private _loadSampler(context, sampler);
  1167. private _loadImageAsync(context, image);
  1168. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1169. private _onProgress();
  1170. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1171. private static _GetTextureWrapMode(context, mode);
  1172. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1173. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1174. private static _GetNumComponents(context, type);
  1175. private static _ValidateUri(uri);
  1176. private static _GetDrawMode(context, mode);
  1177. private _compileMaterialsAsync();
  1178. private _compileShadowGeneratorsAsync();
  1179. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1180. }
  1181. }
  1182. declare module BABYLON.GLTF2 {
  1183. /**
  1184. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1185. */
  1186. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1187. /**
  1188. * Gets or sets a boolean indicating if the extension is enabled
  1189. */
  1190. enabled: boolean;
  1191. /**
  1192. * Gets or sets extension name
  1193. */
  1194. readonly abstract name: string;
  1195. protected _loader: GLTFLoader;
  1196. /**
  1197. * Creates new GLTFLoaderExtension
  1198. * @param loader defines the GLTFLoader to use
  1199. */
  1200. constructor(loader: GLTFLoader);
  1201. /**
  1202. * Release all resources
  1203. */
  1204. dispose(): void;
  1205. /**
  1206. * Override this method to modify the default behavior for loading scenes.
  1207. * @hidden
  1208. */
  1209. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1210. /**
  1211. * Override this method to modify the default behavior for loading nodes.
  1212. * @hidden
  1213. */
  1214. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1215. /**
  1216. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1217. * @hidden
  1218. */
  1219. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1220. /**
  1221. * Override this method to modify the default behavior for loading materials.
  1222. * @hidden
  1223. */
  1224. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1225. /**
  1226. * Override this method to modify the default behavior for loading material properties.
  1227. * @hidden
  1228. */
  1229. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1230. /**
  1231. * Override this method to modify the default behavior for loading textures.
  1232. * @hidden
  1233. */
  1234. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1235. /**
  1236. * Override this method to modify the default behavior for loading uris.
  1237. * @hidden
  1238. */
  1239. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1240. /**
  1241. * Helper method called by a loader extension to load an glTF extension.
  1242. * @hidden
  1243. */
  1244. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1245. /**
  1246. * Helper method called by the loader to allow extensions to override loading scenes.
  1247. * @hidden
  1248. */
  1249. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1250. /**
  1251. * Helper method called by the loader to allow extensions to override loading scenes.
  1252. * @hidden
  1253. */
  1254. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1255. /**
  1256. * Helper method called by the loader to allow extensions to override loading nodes.
  1257. * @hidden
  1258. */
  1259. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1260. /**
  1261. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1262. * @hidden
  1263. */
  1264. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1265. /**
  1266. * Helper method called by the loader to allow extensions to override loading materials.
  1267. * @hidden
  1268. */
  1269. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1270. /**
  1271. * Helper method called by the loader to allow extensions to override loading material properties.
  1272. * @hidden
  1273. */
  1274. static _LoadMaterialPropertiesAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1275. /**
  1276. * Helper method called by the loader to allow extensions to override loading textures.
  1277. * @hidden
  1278. */
  1279. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1280. /**
  1281. * Helper method called by the loader to allow extensions to override loading uris.
  1282. * @hidden
  1283. */
  1284. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1285. }
  1286. }
  1287. /**
  1288. * Defines the module of the glTF 2.0 loader extensions.
  1289. */
  1290. declare module BABYLON.GLTF2.Extensions {
  1291. }
  1292. declare module BABYLON.GLTF2.Extensions {
  1293. /**
  1294. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1295. */
  1296. class MSFT_lod extends GLTFLoaderExtension {
  1297. readonly name: string;
  1298. /**
  1299. * Maximum number of LODs to load, starting from the lowest LOD.
  1300. */
  1301. maxLODsToLoad: number;
  1302. /**
  1303. * Observable raised when all node LODs of one level are loaded.
  1304. * The event data is the index of the loaded LOD starting from zero.
  1305. * Dispose the loader to cancel the loading of the next level of LODs.
  1306. */
  1307. onNodeLODsLoadedObservable: Observable<number>;
  1308. /**
  1309. * Observable raised when all material LODs of one level are loaded.
  1310. * The event data is the index of the loaded LOD starting from zero.
  1311. * Dispose the loader to cancel the loading of the next level of LODs.
  1312. */
  1313. onMaterialLODsLoadedObservable: Observable<number>;
  1314. private _nodeIndexLOD;
  1315. private _nodeSignalLODs;
  1316. private _nodePromiseLODs;
  1317. private _materialIndexLOD;
  1318. private _materialSignalLODs;
  1319. private _materialPromiseLODs;
  1320. constructor(loader: GLTFLoader);
  1321. dispose(): void;
  1322. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1323. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1324. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1325. /**
  1326. * Gets an array of LOD properties from lowest to highest.
  1327. */
  1328. private _getLODs<T>(context, property, array, ids);
  1329. private _disposeUnusedMaterials();
  1330. }
  1331. }
  1332. declare module BABYLON.GLTF2.Extensions {
  1333. /** @hidden */
  1334. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1335. readonly name: string;
  1336. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1337. }
  1338. }
  1339. declare module BABYLON.GLTF2.Extensions {
  1340. /** @hidden */
  1341. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1342. readonly name: string;
  1343. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1344. }
  1345. }
  1346. declare module BABYLON.GLTF2.Extensions {
  1347. /**
  1348. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1349. */
  1350. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1351. readonly name: string;
  1352. private _dracoCompression;
  1353. constructor(loader: GLTFLoader);
  1354. dispose(): void;
  1355. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1356. }
  1357. }
  1358. declare module BABYLON.GLTF2.Extensions {
  1359. /**
  1360. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1361. */
  1362. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1363. readonly name: string;
  1364. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1365. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1366. }
  1367. }
  1368. declare module BABYLON.GLTF2.Extensions {
  1369. /**
  1370. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1371. */
  1372. class KHR_materials_unlit extends GLTFLoaderExtension {
  1373. readonly name: string;
  1374. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1375. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1376. }
  1377. }
  1378. declare module BABYLON.GLTF2.Extensions {
  1379. /**
  1380. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1381. */
  1382. class KHR_lights extends GLTFLoaderExtension {
  1383. readonly name: string;
  1384. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1385. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1386. private readonly _lights;
  1387. }
  1388. }
  1389. declare module BABYLON.GLTF2.Extensions {
  1390. /**
  1391. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1392. */
  1393. class KHR_texture_transform extends GLTFLoaderExtension {
  1394. readonly name: string;
  1395. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1396. }
  1397. }