babylonjs.loaders.module.d.ts 59 KB

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