babylonjs.loaders.d.ts 56 KB

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