babylonjs.loaders.d.ts 57 KB

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