babylonjs.loaders.d.ts 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  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<ParticleSystem[]>, 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 ISceneLoaderPlugin {
  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. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  76. load(scene: Scene, data: string, rootUrl: string): boolean;
  77. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  78. /**
  79. * Read the OBJ file and create an Array of meshes.
  80. * Each mesh contains all information given by the OBJ and the MTL file.
  81. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  82. *
  83. * @param meshesNames
  84. * @param scene BABYLON.Scene The scene where are displayed the data
  85. * @param data String The content of the obj file
  86. * @param rootUrl String The path to the folder
  87. * @returns Array<AbstractMesh>
  88. * @private
  89. */
  90. private _parseSolid(meshesNames, scene, data, rootUrl);
  91. }
  92. }
  93. declare module BABYLON {
  94. /**
  95. * Mode that determines the coordinate system to use.
  96. */
  97. enum GLTFLoaderCoordinateSystemMode {
  98. /**
  99. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  100. */
  101. AUTO = 0,
  102. /**
  103. * Sets the useRightHandedSystem flag on the scene.
  104. */
  105. FORCE_RIGHT_HANDED = 1,
  106. }
  107. /**
  108. * Mode that determines what animations will start.
  109. */
  110. enum GLTFLoaderAnimationStartMode {
  111. /**
  112. * No animation will start.
  113. */
  114. NONE = 0,
  115. /**
  116. * The first animation will start.
  117. */
  118. FIRST = 1,
  119. /**
  120. * All animations will start.
  121. */
  122. ALL = 2,
  123. }
  124. /**
  125. * Interface that contains the data for the glTF asset.
  126. */
  127. interface IGLTFLoaderData {
  128. /**
  129. * JSON that represents the glTF.
  130. */
  131. json: Object;
  132. /**
  133. * The BIN chunk of a binary glTF
  134. */
  135. bin: Nullable<ArrayBufferView>;
  136. }
  137. /**
  138. * Interface for extending the loader.
  139. */
  140. interface IGLTFLoaderExtension {
  141. /**
  142. * The name of this extension.
  143. */
  144. readonly name: string;
  145. /**
  146. * Defines whether this extension is enabled.
  147. */
  148. enabled: boolean;
  149. }
  150. /**
  151. * Loader state.
  152. */
  153. enum GLTFLoaderState {
  154. /**
  155. * The asset is loading.
  156. */
  157. LOADING = 0,
  158. /**
  159. * The asset is ready for rendering.
  160. */
  161. READY = 1,
  162. /**
  163. * The asset is completely loaded.
  164. */
  165. COMPLETE = 2,
  166. }
  167. /**
  168. * Loader interface.
  169. */
  170. interface IGLTFLoader extends IDisposable {
  171. /**
  172. * Mode that determines the coordinate system to use.
  173. */
  174. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  175. /**
  176. * Mode that determines what animations will start.
  177. */
  178. animationStartMode: GLTFLoaderAnimationStartMode;
  179. /**
  180. * Defines if the loader should compile materials.
  181. */
  182. compileMaterials: boolean;
  183. /**
  184. * Defines if the loader should also compile materials with clip planes.
  185. */
  186. useClipPlane: boolean;
  187. /**
  188. * Defines if the loader should compile shadow generators.
  189. */
  190. compileShadowGenerators: boolean;
  191. /**
  192. * Defines if the Alpha blended materials are only applied as coverage.
  193. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  194. * If true, no extra effects are applied to transparent pixels.
  195. */
  196. transparencyAsCoverage: boolean;
  197. /** @hidden */
  198. _normalizeAnimationGroupsToBeginAtZero: boolean;
  199. /**
  200. * Function called before loading a url referenced by the asset.
  201. */
  202. preprocessUrlAsync: (url: string) => Promise<string>;
  203. /**
  204. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  205. */
  206. onMeshLoadedObservable: Observable<AbstractMesh>;
  207. /**
  208. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  209. */
  210. onTextureLoadedObservable: Observable<BaseTexture>;
  211. /**
  212. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  213. */
  214. onMaterialLoadedObservable: Observable<Material>;
  215. /**
  216. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  217. */
  218. onCameraLoadedObservable: Observable<Camera>;
  219. /**
  220. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  221. * For assets with LODs, raised when all of the LODs are complete.
  222. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  223. */
  224. onCompleteObservable: Observable<IGLTFLoader>;
  225. /**
  226. * Observable raised after the loader is disposed.
  227. */
  228. onDisposeObservable: Observable<IGLTFLoader>;
  229. /**
  230. * Observable raised after a loader extension is created.
  231. * Set additional options for a loader extension in this event.
  232. */
  233. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  234. /**
  235. * Loader state or null if the loader is not active.
  236. */
  237. state: Nullable<GLTFLoaderState>;
  238. /**
  239. * Imports meshes from the given data and adds them to the scene.
  240. */
  241. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  242. meshes: AbstractMesh[];
  243. particleSystems: ParticleSystem[];
  244. skeletons: Skeleton[];
  245. animationGroups: AnimationGroup[];
  246. }>;
  247. /**
  248. * Loads all objects from the given data and adds them to the scene.
  249. */
  250. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  251. }
  252. /**
  253. * File loader for loading glTF files into a scene.
  254. */
  255. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  256. /**
  257. * Factory function that creates a glTF 1.0 loader
  258. */
  259. static CreateGLTFLoaderV1: () => IGLTFLoader;
  260. /**
  261. * Factory function that creates a glTF 2.0 loader
  262. */
  263. static CreateGLTFLoaderV2: () => IGLTFLoader;
  264. /**
  265. * Raised when the asset has been parsed
  266. */
  267. onParsedObservable: Observable<IGLTFLoaderData>;
  268. private _onParsedObserver;
  269. /**
  270. * Raised when the asset has been parsed
  271. */
  272. onParsed: (loaderData: IGLTFLoaderData) => void;
  273. /**
  274. * 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.
  275. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  276. * Defaults to true.
  277. */
  278. static IncrementalLoading: boolean;
  279. /**
  280. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  281. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  282. */
  283. static HomogeneousCoordinates: boolean;
  284. /**
  285. * The coordinate system mode. Defaults to AUTO.
  286. */
  287. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  288. /**
  289. * The animation start mode. Defaults to FIRST.
  290. */
  291. animationStartMode: GLTFLoaderAnimationStartMode;
  292. /**
  293. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  294. */
  295. compileMaterials: boolean;
  296. /**
  297. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  298. */
  299. useClipPlane: boolean;
  300. /**
  301. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  302. */
  303. compileShadowGenerators: boolean;
  304. /**
  305. * Defines if the Alpha blended materials are only applied as coverage.
  306. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  307. * If true, no extra effects are applied to transparent pixels.
  308. */
  309. transparencyAsCoverage: boolean;
  310. /** @hidden */
  311. _normalizeAnimationGroupsToBeginAtZero: boolean;
  312. /**
  313. * Function called before loading a url referenced by the asset.
  314. */
  315. preprocessUrlAsync: (url: string) => Promise<string>;
  316. /**
  317. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  318. */
  319. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  320. private _onMeshLoadedObserver;
  321. /**
  322. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  323. */
  324. onMeshLoaded: (mesh: AbstractMesh) => void;
  325. /**
  326. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  327. */
  328. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  329. private _onTextureLoadedObserver;
  330. /**
  331. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  332. */
  333. onTextureLoaded: (texture: BaseTexture) => void;
  334. /**
  335. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  336. */
  337. readonly onMaterialLoadedObservable: Observable<Material>;
  338. private _onMaterialLoadedObserver;
  339. /**
  340. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  341. */
  342. onMaterialLoaded: (material: Material) => void;
  343. /**
  344. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  345. */
  346. readonly onCameraLoadedObservable: Observable<Camera>;
  347. private _onCameraLoadedObserver;
  348. /**
  349. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  350. */
  351. onCameraLoaded: (camera: Camera) => void;
  352. /**
  353. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  354. * For assets with LODs, raised when all of the LODs are complete.
  355. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  356. */
  357. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  358. private _onCompleteObserver;
  359. /**
  360. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  361. */
  362. onComplete: () => void;
  363. /**
  364. * Observable raised after the loader is disposed.
  365. */
  366. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  367. private _onDisposeObserver;
  368. /**
  369. * Callback raised after the loader is disposed.
  370. */
  371. onDispose: () => void;
  372. /**
  373. * Observable raised after a loader extension is created.
  374. * Set additional options for a loader extension in this event.
  375. */
  376. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  377. private _onExtensionLoadedObserver;
  378. /**
  379. * Callback raised after a loader extension is created.
  380. */
  381. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  382. /**
  383. * Returns a promise that resolves when the asset is completely loaded.
  384. * @returns a promise that resolves when the asset is completely loaded.
  385. */
  386. whenCompleteAsync(): Promise<void>;
  387. /**
  388. * The loader state or null if the loader is not active.
  389. */
  390. readonly loaderState: Nullable<GLTFLoaderState>;
  391. private _loader;
  392. /**
  393. * Name of the loader ("gltf")
  394. */
  395. name: string;
  396. /**
  397. * Supported file extensions of the loader (.gltf, .glb)
  398. */
  399. extensions: ISceneLoaderPluginExtensions;
  400. /**
  401. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  402. */
  403. dispose(): void;
  404. /**
  405. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  406. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  407. * @param scene the scene the meshes should be added to
  408. * @param data the glTF data to load
  409. * @param rootUrl root url to load from
  410. * @param onProgress event that fires when loading progress has occured
  411. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  412. */
  413. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  414. meshes: AbstractMesh[];
  415. particleSystems: ParticleSystem[];
  416. skeletons: Skeleton[];
  417. animationGroups: AnimationGroup[];
  418. }>;
  419. /**
  420. * Imports all objects from the loaded glTF data and adds them to the scene
  421. * @param scene the scene the objects should be added to
  422. * @param data the glTF data to load
  423. * @param rootUrl root url to load from
  424. * @param onProgress event that fires when loading progress has occured
  425. * @returns a promise which completes when objects have been loaded to the scene
  426. */
  427. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  428. /**
  429. * Load into an asset container.
  430. * @param scene The scene to load into
  431. * @param data The data to import
  432. * @param rootUrl The root url for scene and resources
  433. * @param onProgress The callback when the load progresses
  434. * @returns The loaded asset container
  435. */
  436. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  437. /**
  438. * If the data string can be loaded directly.
  439. * @param data string contianing the file data
  440. * @returns if the data can be loaded directly
  441. */
  442. canDirectLoad(data: string): boolean;
  443. /**
  444. * Rewrites a url by combining a root url and response url.
  445. */
  446. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  447. /**
  448. * Instantiates a glTF file loader plugin.
  449. * @returns the created plugin
  450. */
  451. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  452. private _parse(data);
  453. private _getLoader(loaderData);
  454. private static _parseBinary(data);
  455. private static _parseV1(binaryReader);
  456. private static _parseV2(binaryReader);
  457. private static _parseVersion(version);
  458. private static _compareVersion(a, b);
  459. private static _decodeBufferToText(buffer);
  460. }
  461. }
  462. declare module BABYLON.GLTF1 {
  463. /**
  464. * Enums
  465. */
  466. enum EComponentType {
  467. BYTE = 5120,
  468. UNSIGNED_BYTE = 5121,
  469. SHORT = 5122,
  470. UNSIGNED_SHORT = 5123,
  471. FLOAT = 5126,
  472. }
  473. enum EShaderType {
  474. FRAGMENT = 35632,
  475. VERTEX = 35633,
  476. }
  477. enum EParameterType {
  478. BYTE = 5120,
  479. UNSIGNED_BYTE = 5121,
  480. SHORT = 5122,
  481. UNSIGNED_SHORT = 5123,
  482. INT = 5124,
  483. UNSIGNED_INT = 5125,
  484. FLOAT = 5126,
  485. FLOAT_VEC2 = 35664,
  486. FLOAT_VEC3 = 35665,
  487. FLOAT_VEC4 = 35666,
  488. INT_VEC2 = 35667,
  489. INT_VEC3 = 35668,
  490. INT_VEC4 = 35669,
  491. BOOL = 35670,
  492. BOOL_VEC2 = 35671,
  493. BOOL_VEC3 = 35672,
  494. BOOL_VEC4 = 35673,
  495. FLOAT_MAT2 = 35674,
  496. FLOAT_MAT3 = 35675,
  497. FLOAT_MAT4 = 35676,
  498. SAMPLER_2D = 35678,
  499. }
  500. enum ETextureWrapMode {
  501. CLAMP_TO_EDGE = 33071,
  502. MIRRORED_REPEAT = 33648,
  503. REPEAT = 10497,
  504. }
  505. enum ETextureFilterType {
  506. NEAREST = 9728,
  507. LINEAR = 9728,
  508. NEAREST_MIPMAP_NEAREST = 9984,
  509. LINEAR_MIPMAP_NEAREST = 9985,
  510. NEAREST_MIPMAP_LINEAR = 9986,
  511. LINEAR_MIPMAP_LINEAR = 9987,
  512. }
  513. enum ETextureFormat {
  514. ALPHA = 6406,
  515. RGB = 6407,
  516. RGBA = 6408,
  517. LUMINANCE = 6409,
  518. LUMINANCE_ALPHA = 6410,
  519. }
  520. enum ECullingType {
  521. FRONT = 1028,
  522. BACK = 1029,
  523. FRONT_AND_BACK = 1032,
  524. }
  525. enum EBlendingFunction {
  526. ZERO = 0,
  527. ONE = 1,
  528. SRC_COLOR = 768,
  529. ONE_MINUS_SRC_COLOR = 769,
  530. DST_COLOR = 774,
  531. ONE_MINUS_DST_COLOR = 775,
  532. SRC_ALPHA = 770,
  533. ONE_MINUS_SRC_ALPHA = 771,
  534. DST_ALPHA = 772,
  535. ONE_MINUS_DST_ALPHA = 773,
  536. CONSTANT_COLOR = 32769,
  537. ONE_MINUS_CONSTANT_COLOR = 32770,
  538. CONSTANT_ALPHA = 32771,
  539. ONE_MINUS_CONSTANT_ALPHA = 32772,
  540. SRC_ALPHA_SATURATE = 776,
  541. }
  542. /**
  543. * Interfaces
  544. */
  545. interface IGLTFProperty {
  546. extensions?: {
  547. [key: string]: any;
  548. };
  549. extras?: Object;
  550. }
  551. interface IGLTFChildRootProperty extends IGLTFProperty {
  552. name?: string;
  553. }
  554. interface IGLTFAccessor extends IGLTFChildRootProperty {
  555. bufferView: string;
  556. byteOffset: number;
  557. byteStride: number;
  558. count: number;
  559. type: string;
  560. componentType: EComponentType;
  561. max?: number[];
  562. min?: number[];
  563. name?: string;
  564. }
  565. interface IGLTFBufferView extends IGLTFChildRootProperty {
  566. buffer: string;
  567. byteOffset: number;
  568. byteLength: number;
  569. byteStride: number;
  570. target?: number;
  571. }
  572. interface IGLTFBuffer extends IGLTFChildRootProperty {
  573. uri: string;
  574. byteLength?: number;
  575. type?: string;
  576. }
  577. interface IGLTFShader extends IGLTFChildRootProperty {
  578. uri: string;
  579. type: EShaderType;
  580. }
  581. interface IGLTFProgram extends IGLTFChildRootProperty {
  582. attributes: string[];
  583. fragmentShader: string;
  584. vertexShader: string;
  585. }
  586. interface IGLTFTechniqueParameter {
  587. type: number;
  588. count?: number;
  589. semantic?: string;
  590. node?: string;
  591. value?: number | boolean | string | Array<any>;
  592. source?: string;
  593. babylonValue?: any;
  594. }
  595. interface IGLTFTechniqueCommonProfile {
  596. lightingModel: string;
  597. texcoordBindings: Object;
  598. parameters?: Array<any>;
  599. }
  600. interface IGLTFTechniqueStatesFunctions {
  601. blendColor?: number[];
  602. blendEquationSeparate?: number[];
  603. blendFuncSeparate?: number[];
  604. colorMask: boolean[];
  605. cullFace: number[];
  606. }
  607. interface IGLTFTechniqueStates {
  608. enable: number[];
  609. functions: IGLTFTechniqueStatesFunctions;
  610. }
  611. interface IGLTFTechnique extends IGLTFChildRootProperty {
  612. parameters: {
  613. [key: string]: IGLTFTechniqueParameter;
  614. };
  615. program: string;
  616. attributes: {
  617. [key: string]: string;
  618. };
  619. uniforms: {
  620. [key: string]: string;
  621. };
  622. states: IGLTFTechniqueStates;
  623. }
  624. interface IGLTFMaterial extends IGLTFChildRootProperty {
  625. technique?: string;
  626. values: string[];
  627. }
  628. interface IGLTFMeshPrimitive extends IGLTFProperty {
  629. attributes: {
  630. [key: string]: string;
  631. };
  632. indices: string;
  633. material: string;
  634. mode?: number;
  635. }
  636. interface IGLTFMesh extends IGLTFChildRootProperty {
  637. primitives: IGLTFMeshPrimitive[];
  638. }
  639. interface IGLTFImage extends IGLTFChildRootProperty {
  640. uri: string;
  641. }
  642. interface IGLTFSampler extends IGLTFChildRootProperty {
  643. magFilter?: number;
  644. minFilter?: number;
  645. wrapS?: number;
  646. wrapT?: number;
  647. }
  648. interface IGLTFTexture extends IGLTFChildRootProperty {
  649. sampler: string;
  650. source: string;
  651. format?: ETextureFormat;
  652. internalFormat?: ETextureFormat;
  653. target?: number;
  654. type?: number;
  655. babylonTexture?: Texture;
  656. }
  657. interface IGLTFAmbienLight {
  658. color?: number[];
  659. }
  660. interface IGLTFDirectionalLight {
  661. color?: number[];
  662. }
  663. interface IGLTFPointLight {
  664. color?: number[];
  665. constantAttenuation?: number;
  666. linearAttenuation?: number;
  667. quadraticAttenuation?: number;
  668. }
  669. interface IGLTFSpotLight {
  670. color?: number[];
  671. constantAttenuation?: number;
  672. fallOfAngle?: number;
  673. fallOffExponent?: number;
  674. linearAttenuation?: number;
  675. quadraticAttenuation?: number;
  676. }
  677. interface IGLTFLight extends IGLTFChildRootProperty {
  678. type: string;
  679. }
  680. interface IGLTFCameraOrthographic {
  681. xmag: number;
  682. ymag: number;
  683. zfar: number;
  684. znear: number;
  685. }
  686. interface IGLTFCameraPerspective {
  687. aspectRatio: number;
  688. yfov: number;
  689. zfar: number;
  690. znear: number;
  691. }
  692. interface IGLTFCamera extends IGLTFChildRootProperty {
  693. type: string;
  694. }
  695. interface IGLTFAnimationChannelTarget {
  696. id: string;
  697. path: string;
  698. }
  699. interface IGLTFAnimationChannel {
  700. sampler: string;
  701. target: IGLTFAnimationChannelTarget;
  702. }
  703. interface IGLTFAnimationSampler {
  704. input: string;
  705. output: string;
  706. interpolation?: string;
  707. }
  708. interface IGLTFAnimation extends IGLTFChildRootProperty {
  709. channels?: IGLTFAnimationChannel[];
  710. parameters?: {
  711. [key: string]: string;
  712. };
  713. samplers?: {
  714. [key: string]: IGLTFAnimationSampler;
  715. };
  716. }
  717. interface IGLTFNodeInstanceSkin {
  718. skeletons: string[];
  719. skin: string;
  720. meshes: string[];
  721. }
  722. interface IGLTFSkins extends IGLTFChildRootProperty {
  723. bindShapeMatrix: number[];
  724. inverseBindMatrices: string;
  725. jointNames: string[];
  726. babylonSkeleton?: Skeleton;
  727. }
  728. interface IGLTFNode extends IGLTFChildRootProperty {
  729. camera?: string;
  730. children: string[];
  731. skin?: string;
  732. jointName?: string;
  733. light?: string;
  734. matrix: number[];
  735. mesh?: string;
  736. meshes?: string[];
  737. rotation?: number[];
  738. scale?: number[];
  739. translation?: number[];
  740. babylonNode?: Node;
  741. }
  742. interface IGLTFScene extends IGLTFChildRootProperty {
  743. nodes: string[];
  744. }
  745. /**
  746. * Runtime
  747. */
  748. interface IGLTFRuntime {
  749. extensions: {
  750. [key: string]: any;
  751. };
  752. accessors: {
  753. [key: string]: IGLTFAccessor;
  754. };
  755. buffers: {
  756. [key: string]: IGLTFBuffer;
  757. };
  758. bufferViews: {
  759. [key: string]: IGLTFBufferView;
  760. };
  761. meshes: {
  762. [key: string]: IGLTFMesh;
  763. };
  764. lights: {
  765. [key: string]: IGLTFLight;
  766. };
  767. cameras: {
  768. [key: string]: IGLTFCamera;
  769. };
  770. nodes: {
  771. [key: string]: IGLTFNode;
  772. };
  773. images: {
  774. [key: string]: IGLTFImage;
  775. };
  776. textures: {
  777. [key: string]: IGLTFTexture;
  778. };
  779. shaders: {
  780. [key: string]: IGLTFShader;
  781. };
  782. programs: {
  783. [key: string]: IGLTFProgram;
  784. };
  785. samplers: {
  786. [key: string]: IGLTFSampler;
  787. };
  788. techniques: {
  789. [key: string]: IGLTFTechnique;
  790. };
  791. materials: {
  792. [key: string]: IGLTFMaterial;
  793. };
  794. animations: {
  795. [key: string]: IGLTFAnimation;
  796. };
  797. skins: {
  798. [key: string]: IGLTFSkins;
  799. };
  800. currentScene?: Object;
  801. scenes: {
  802. [key: string]: IGLTFScene;
  803. };
  804. extensionsUsed: string[];
  805. extensionsRequired?: string[];
  806. buffersCount: number;
  807. shaderscount: number;
  808. scene: Scene;
  809. rootUrl: string;
  810. loadedBufferCount: number;
  811. loadedBufferViews: {
  812. [name: string]: ArrayBufferView;
  813. };
  814. loadedShaderCount: number;
  815. importOnlyMeshes: boolean;
  816. importMeshesNames?: string[];
  817. dummyNodes: Node[];
  818. }
  819. /**
  820. * Bones
  821. */
  822. interface INodeToRoot {
  823. bone: Bone;
  824. node: IGLTFNode;
  825. id: string;
  826. }
  827. interface IJointNode {
  828. node: IGLTFNode;
  829. id: string;
  830. }
  831. }
  832. declare module BABYLON.GLTF1 {
  833. /**
  834. * Implementation of the base glTF spec
  835. */
  836. class GLTFLoaderBase {
  837. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  838. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  839. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  840. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  841. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  842. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  843. }
  844. /**
  845. * glTF V1 Loader
  846. */
  847. class GLTFLoader implements IGLTFLoader {
  848. static Extensions: {
  849. [name: string]: GLTFLoaderExtension;
  850. };
  851. static RegisterExtension(extension: GLTFLoaderExtension): void;
  852. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  853. animationStartMode: GLTFLoaderAnimationStartMode;
  854. compileMaterials: boolean;
  855. useClipPlane: boolean;
  856. compileShadowGenerators: boolean;
  857. transparencyAsCoverage: boolean;
  858. _normalizeAnimationGroupsToBeginAtZero: 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. _blob?: Promise<Blob>;
  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. _babylonBones?: Bone[];
  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. /** @hidden */
  1197. _normalizeAnimationGroupsToBeginAtZero: boolean;
  1198. /**
  1199. * Function called before loading a url referenced by the asset.
  1200. */
  1201. preprocessUrlAsync: (url: string) => Promise<string>;
  1202. /**
  1203. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  1204. */
  1205. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  1206. /**
  1207. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  1208. */
  1209. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  1210. /**
  1211. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  1212. */
  1213. readonly onMaterialLoadedObservable: Observable<Material>;
  1214. /**
  1215. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  1216. */
  1217. readonly onCameraLoadedObservable: Observable<Camera>;
  1218. /**
  1219. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  1220. * For assets with LODs, raised when all of the LODs are complete.
  1221. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  1222. */
  1223. readonly onCompleteObservable: Observable<IGLTFLoader>;
  1224. /**
  1225. * Observable raised after the loader is disposed.
  1226. */
  1227. readonly onDisposeObservable: Observable<IGLTFLoader>;
  1228. /**
  1229. * Observable raised after a loader extension is created.
  1230. * Set additional options for a loader extension in this event.
  1231. */
  1232. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  1233. /**
  1234. * Loader state or null if the loader is not active.
  1235. */
  1236. readonly state: Nullable<GLTFLoaderState>;
  1237. /**
  1238. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  1239. */
  1240. dispose(): void;
  1241. /**
  1242. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  1243. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1244. * @param scene the scene the meshes should be added to
  1245. * @param data the glTF data to load
  1246. * @param rootUrl root url to load from
  1247. * @param onProgress event that fires when loading progress has occured
  1248. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1249. */
  1250. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1251. meshes: AbstractMesh[];
  1252. particleSystems: ParticleSystem[];
  1253. skeletons: Skeleton[];
  1254. animationGroups: AnimationGroup[];
  1255. }>;
  1256. /**
  1257. * Imports all objects from the loaded glTF data and adds them to the scene
  1258. * @param scene the scene the objects should be added to
  1259. * @param data the glTF data to load
  1260. * @param rootUrl root url to load from
  1261. * @param onProgress event that fires when loading progress has occured
  1262. * @returns a promise which completes when objects have been loaded to the scene
  1263. */
  1264. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1265. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  1266. private _loadData(data);
  1267. private _setupData();
  1268. private _loadExtensions();
  1269. private _checkExtensions();
  1270. private _createRootNode();
  1271. private _loadNodesAsync(nodes);
  1272. /** @hidden */
  1273. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1274. private _forEachPrimitive(node, callback);
  1275. private _getMeshes();
  1276. private _getSkeletons();
  1277. private _getAnimationGroups();
  1278. private _startAnimations();
  1279. /** @hidden */
  1280. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1281. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1282. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1283. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1284. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1285. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1286. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1287. private static _LoadTransform(node, babylonNode);
  1288. private _loadSkinAsync(context, node, mesh, skin);
  1289. private _loadBones(context, skin);
  1290. private _loadBone(node, skin, babylonBones);
  1291. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1292. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1293. private _getNodeMatrix(node);
  1294. private _loadCamera(context, camera, babylonMesh);
  1295. private _loadAnimationsAsync();
  1296. private _loadAnimationAsync(context, animation);
  1297. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1298. private _loadAnimationSamplerAsync(context, sampler);
  1299. private _loadBufferAsync(context, buffer);
  1300. /** @hidden */
  1301. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1302. private _loadIndicesAccessorAsync(context, accessor);
  1303. private _loadFloatAccessorAsync(context, accessor);
  1304. /** @hidden */
  1305. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1306. private _loadVertexAccessorAsync(context, accessor, kind);
  1307. private _getDefaultMaterial(drawMode);
  1308. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1309. /** @hidden */
  1310. _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1311. /** @hidden */
  1312. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1313. /** @hidden */
  1314. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1315. /** @hidden */
  1316. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1317. /** @hidden */
  1318. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1319. private _loadSampler(context, sampler);
  1320. private _loadImageAsync(context, image);
  1321. /** @hidden */
  1322. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1323. private _onProgress();
  1324. /** @hidden */
  1325. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1326. private static _GetTextureWrapMode(context, mode);
  1327. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1328. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1329. private static _GetNumComponents(context, type);
  1330. private static _ValidateUri(uri);
  1331. private static _GetDrawMode(context, mode);
  1332. private _compileMaterialsAsync();
  1333. private _compileShadowGeneratorsAsync();
  1334. private _clear();
  1335. /** @hidden */
  1336. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1337. }
  1338. }
  1339. declare module BABYLON.GLTF2 {
  1340. /**
  1341. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1342. */
  1343. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1344. enabled: boolean;
  1345. readonly abstract name: string;
  1346. protected _loader: GLTFLoader;
  1347. constructor(loader: GLTFLoader);
  1348. dispose(): void;
  1349. /** Override this method to modify the default behavior for loading scenes. */
  1350. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1351. /** Override this method to modify the default behavior for loading nodes. */
  1352. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1353. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  1354. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1355. /** Override this method to modify the default behavior for loading materials. */
  1356. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1357. /** Override this method to modify the default behavior for loading textures. */
  1358. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1359. /** Override this method to modify the default behavior for loading uris. */
  1360. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1361. /** Helper method called by a loader extension to load an glTF extension. */
  1362. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>>;
  1363. /** Helper method called by the loader to allow extensions to override loading scenes. */
  1364. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1365. /** Helper method called by the loader to allow extensions to override loading nodes. */
  1366. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1367. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  1368. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1369. /** Helper method called by the loader to allow extensions to override loading materials. */
  1370. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1371. /** Helper method called by the loader to allow extensions to override loading textures. */
  1372. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1373. /** Helper method called by the loader to allow extensions to override loading uris. */
  1374. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1375. }
  1376. }
  1377. /**
  1378. * Defines the module of the glTF 2.0 loader extensions.
  1379. */
  1380. declare module BABYLON.GLTF2.Extensions {
  1381. }
  1382. declare module BABYLON.GLTF2.Extensions {
  1383. /**
  1384. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1385. */
  1386. class MSFT_lod extends GLTFLoaderExtension {
  1387. readonly name: string;
  1388. /**
  1389. * Maximum number of LODs to load, starting from the lowest LOD.
  1390. */
  1391. maxLODsToLoad: number;
  1392. private _loadingNodeLOD;
  1393. private _loadNodeSignals;
  1394. private _loadingMaterialLOD;
  1395. private _loadMaterialSignals;
  1396. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1397. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1398. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1399. /**
  1400. * Gets an array of LOD properties from lowest to highest.
  1401. */
  1402. private _getLODs<T>(context, property, array, ids);
  1403. }
  1404. }
  1405. declare module BABYLON.GLTF2.Extensions {
  1406. /** @hidden */
  1407. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1408. readonly name: string;
  1409. constructor(loader: GLTFLoader);
  1410. private _onMaterialLoaded;
  1411. }
  1412. }
  1413. declare module BABYLON.GLTF2.Extensions {
  1414. /** @hidden */
  1415. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1416. readonly name: string;
  1417. constructor(loader: GLTFLoader);
  1418. private _onMaterialLoaded;
  1419. }
  1420. }
  1421. declare module BABYLON.GLTF2.Extensions {
  1422. /**
  1423. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1424. */
  1425. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1426. readonly name: string;
  1427. private _dracoCompression;
  1428. constructor(loader: GLTFLoader);
  1429. dispose(): void;
  1430. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1431. }
  1432. }
  1433. declare module BABYLON.GLTF2.Extensions {
  1434. /**
  1435. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1436. */
  1437. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1438. readonly name: string;
  1439. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1440. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1441. }
  1442. }
  1443. declare module BABYLON.GLTF2.Extensions {
  1444. /**
  1445. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1446. */
  1447. class KHR_materials_unlit extends GLTFLoaderExtension {
  1448. readonly name: string;
  1449. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1450. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1451. }
  1452. }
  1453. declare module BABYLON.GLTF2.Extensions {
  1454. /**
  1455. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1456. */
  1457. class KHR_lights extends GLTFLoaderExtension {
  1458. readonly name: string;
  1459. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1460. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1461. private readonly _lights;
  1462. }
  1463. }
  1464. declare module BABYLON.GLTF2.Extensions {
  1465. /**
  1466. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1467. */
  1468. class KHR_texture_transform extends GLTFLoaderExtension {
  1469. readonly name: string;
  1470. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1471. }
  1472. }