babylonjs.loaders.module.d.ts 56 KB

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