babylonjs.loaders.d.ts 57 KB

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