babylonjs.loaders.d.ts 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524
  1. declare module BABYLON {
  2. /**
  3. * Configuration for glTF validation
  4. */
  5. export interface IGLTFValidationConfiguration {
  6. /**
  7. * The url of the glTF validator.
  8. */
  9. url: string;
  10. }
  11. /**
  12. * glTF validation
  13. */
  14. export class GLTFValidation {
  15. /**
  16. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  17. */
  18. static Configuration: IGLTFValidationConfiguration;
  19. private static _LoadScriptPromise;
  20. /**
  21. * Validate a glTF asset using the glTF-Validator.
  22. * @param data The JSON of a glTF or the array buffer of a binary glTF
  23. * @param rootUrl The root url for the glTF
  24. * @param fileName The file name for the glTF
  25. * @param getExternalResource The callback to get external resources for the glTF validator
  26. * @returns A promise that resolves with the glTF validation results once complete
  27. */
  28. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<BABYLON.GLTF2.IGLTFValidationResults>;
  29. }
  30. }
  31. declare module BABYLON {
  32. /**
  33. * Mode that determines the coordinate system to use.
  34. */
  35. export enum GLTFLoaderCoordinateSystemMode {
  36. /**
  37. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  38. */
  39. AUTO = 0,
  40. /**
  41. * Sets the useRightHandedSystem flag on the scene.
  42. */
  43. FORCE_RIGHT_HANDED = 1
  44. }
  45. /**
  46. * Mode that determines what animations will start.
  47. */
  48. export enum GLTFLoaderAnimationStartMode {
  49. /**
  50. * No animation will start.
  51. */
  52. NONE = 0,
  53. /**
  54. * The first animation will start.
  55. */
  56. FIRST = 1,
  57. /**
  58. * All animations will start.
  59. */
  60. ALL = 2
  61. }
  62. /**
  63. * Interface that contains the data for the glTF asset.
  64. */
  65. export interface IGLTFLoaderData {
  66. /**
  67. * The object that represents the glTF JSON.
  68. */
  69. json: Object;
  70. /**
  71. * The BIN chunk of a binary glTF.
  72. */
  73. bin: Nullable<IDataBuffer>;
  74. }
  75. /**
  76. * Interface for extending the loader.
  77. */
  78. export interface IGLTFLoaderExtension {
  79. /**
  80. * The name of this extension.
  81. */
  82. readonly name: string;
  83. /**
  84. * Defines whether this extension is enabled.
  85. */
  86. enabled: boolean;
  87. /**
  88. * Defines the order of this extension.
  89. * The loader sorts the extensions using these values when loading.
  90. */
  91. order?: number;
  92. }
  93. /**
  94. * Loader state.
  95. */
  96. export enum GLTFLoaderState {
  97. /**
  98. * The asset is loading.
  99. */
  100. LOADING = 0,
  101. /**
  102. * The asset is ready for rendering.
  103. */
  104. READY = 1,
  105. /**
  106. * The asset is completely loaded.
  107. */
  108. COMPLETE = 2
  109. }
  110. /** @hidden */
  111. export interface IImportMeshAsyncOutput {
  112. meshes: AbstractMesh[];
  113. particleSystems: IParticleSystem[];
  114. skeletons: Skeleton[];
  115. animationGroups: AnimationGroup[];
  116. lights: Light[];
  117. transformNodes: TransformNode[];
  118. }
  119. /** @hidden */
  120. export interface IGLTFLoader extends IDisposable {
  121. readonly state: Nullable<GLTFLoaderState>;
  122. importMeshAsync: (meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<IImportMeshAsyncOutput>;
  123. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  124. }
  125. /**
  126. * File loader for loading glTF files into a scene.
  127. */
  128. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  129. /** @hidden */
  130. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  131. /** @hidden */
  132. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  133. /**
  134. * Raised when the asset has been parsed
  135. */
  136. onParsedObservable: Observable<IGLTFLoaderData>;
  137. private _onParsedObserver;
  138. /**
  139. * Raised when the asset has been parsed
  140. */
  141. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  142. /**
  143. * 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.
  144. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  145. * Defaults to true.
  146. * @hidden
  147. */
  148. static IncrementalLoading: boolean;
  149. /**
  150. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  151. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  152. * @hidden
  153. */
  154. static HomogeneousCoordinates: boolean;
  155. /**
  156. * The coordinate system mode. Defaults to AUTO.
  157. */
  158. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  159. /**
  160. * The animation start mode. Defaults to FIRST.
  161. */
  162. animationStartMode: GLTFLoaderAnimationStartMode;
  163. /**
  164. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  165. */
  166. compileMaterials: boolean;
  167. /**
  168. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  169. */
  170. useClipPlane: boolean;
  171. /**
  172. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  173. */
  174. compileShadowGenerators: boolean;
  175. /**
  176. * Defines if the Alpha blended materials are only applied as coverage.
  177. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  178. * If true, no extra effects are applied to transparent pixels.
  179. */
  180. transparencyAsCoverage: boolean;
  181. /**
  182. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  183. * Enabling will disable offline support and glTF validator.
  184. * Defaults to false.
  185. */
  186. useRangeRequests: boolean;
  187. /**
  188. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  189. */
  190. createInstances: boolean;
  191. /**
  192. * Function called before loading a url referenced by the asset.
  193. */
  194. preprocessUrlAsync: (url: string) => Promise<string>;
  195. /**
  196. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  197. */
  198. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  199. private _onMeshLoadedObserver;
  200. /**
  201. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  202. */
  203. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  204. /**
  205. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  206. */
  207. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  208. private _onTextureLoadedObserver;
  209. /**
  210. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  211. */
  212. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  213. /**
  214. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  215. */
  216. readonly onMaterialLoadedObservable: Observable<Material>;
  217. private _onMaterialLoadedObserver;
  218. /**
  219. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  220. */
  221. set onMaterialLoaded(callback: (material: Material) => void);
  222. /**
  223. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  224. */
  225. readonly onCameraLoadedObservable: Observable<Camera>;
  226. private _onCameraLoadedObserver;
  227. /**
  228. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  229. */
  230. set onCameraLoaded(callback: (camera: Camera) => void);
  231. /**
  232. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  233. * For assets with LODs, raised when all of the LODs are complete.
  234. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  235. */
  236. readonly onCompleteObservable: Observable<void>;
  237. private _onCompleteObserver;
  238. /**
  239. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  240. * For assets with LODs, raised when all of the LODs are complete.
  241. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  242. */
  243. set onComplete(callback: () => void);
  244. /**
  245. * Observable raised when an error occurs.
  246. */
  247. readonly onErrorObservable: Observable<any>;
  248. private _onErrorObserver;
  249. /**
  250. * Callback raised when an error occurs.
  251. */
  252. set onError(callback: (reason: any) => void);
  253. /**
  254. * Observable raised after the loader is disposed.
  255. */
  256. readonly onDisposeObservable: Observable<void>;
  257. private _onDisposeObserver;
  258. /**
  259. * Callback raised after the loader is disposed.
  260. */
  261. set onDispose(callback: () => void);
  262. /**
  263. * Observable raised after a loader extension is created.
  264. * Set additional options for a loader extension in this event.
  265. */
  266. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  267. private _onExtensionLoadedObserver;
  268. /**
  269. * Callback raised after a loader extension is created.
  270. */
  271. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  272. /**
  273. * Defines if the loader logging is enabled.
  274. */
  275. get loggingEnabled(): boolean;
  276. set loggingEnabled(value: boolean);
  277. /**
  278. * Defines if the loader should capture performance counters.
  279. */
  280. get capturePerformanceCounters(): boolean;
  281. set capturePerformanceCounters(value: boolean);
  282. /**
  283. * Defines if the loader should validate the asset.
  284. */
  285. validate: boolean;
  286. /**
  287. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  288. */
  289. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  290. private _onValidatedObserver;
  291. /**
  292. * Callback raised after a loader extension is created.
  293. */
  294. set onValidated(callback: (results: BABYLON.GLTF2.IGLTFValidationResults) => void);
  295. private _loader;
  296. private _progressCallback?;
  297. private _requests;
  298. /**
  299. * Name of the loader ("gltf")
  300. */
  301. name: string;
  302. /** @hidden */
  303. extensions: ISceneLoaderPluginExtensions;
  304. /**
  305. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  306. */
  307. dispose(): void;
  308. /** @hidden */
  309. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  310. /** @hidden */
  311. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  312. /** @hidden */
  313. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  314. meshes: AbstractMesh[];
  315. particleSystems: IParticleSystem[];
  316. skeletons: Skeleton[];
  317. animationGroups: AnimationGroup[];
  318. }>;
  319. /** @hidden */
  320. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  321. /** @hidden */
  322. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  323. /** @hidden */
  324. canDirectLoad(data: string): boolean;
  325. /** @hidden */
  326. directLoad(scene: Scene, data: string): any;
  327. /**
  328. * The callback that allows custom handling of the root url based on the response url.
  329. * @param rootUrl the original root url
  330. * @param responseURL the response url if available
  331. * @returns the new root url
  332. */
  333. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  334. /** @hidden */
  335. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  336. /**
  337. * The loader state or null if the loader is not active.
  338. */
  339. get loaderState(): Nullable<GLTFLoaderState>;
  340. /**
  341. * Returns a promise that resolves when the asset is completely loaded.
  342. * @returns a promise that resolves when the asset is completely loaded.
  343. */
  344. whenCompleteAsync(): Promise<void>;
  345. /** @hidden */
  346. _loadFile(url: string, scene: Scene, onSuccess: (data: string | ArrayBuffer) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest) => void): IFileRequest;
  347. /** @hidden */
  348. _requestFile(url: string, scene: Scene, onSuccess: (data: string | ArrayBuffer, request?: WebRequest) => void, useArrayBuffer?: boolean, onError?: (error: RequestFileError) => void, onOpened?: (request: WebRequest) => void): IFileRequest;
  349. private _onProgress;
  350. private _validate;
  351. private _getLoader;
  352. private _parseJson;
  353. private _unpackBinaryAsync;
  354. private _unpackBinaryV1Async;
  355. private _unpackBinaryV2Async;
  356. private static _parseVersion;
  357. private static _compareVersion;
  358. private static readonly _logSpaces;
  359. private _logIndentLevel;
  360. private _loggingEnabled;
  361. /** @hidden */
  362. _log: (message: string) => void;
  363. /** @hidden */
  364. _logOpen(message: string): void;
  365. /** @hidden */
  366. _logClose(): void;
  367. private _logEnabled;
  368. private _logDisabled;
  369. private _capturePerformanceCounters;
  370. /** @hidden */
  371. _startPerformanceCounter: (counterName: string) => void;
  372. /** @hidden */
  373. _endPerformanceCounter: (counterName: string) => void;
  374. private _startPerformanceCounterEnabled;
  375. private _startPerformanceCounterDisabled;
  376. private _endPerformanceCounterEnabled;
  377. private _endPerformanceCounterDisabled;
  378. }
  379. }
  380. declare module BABYLON.GLTF1 {
  381. /**
  382. * Enums
  383. * @hidden
  384. */
  385. export enum EComponentType {
  386. BYTE = 5120,
  387. UNSIGNED_BYTE = 5121,
  388. SHORT = 5122,
  389. UNSIGNED_SHORT = 5123,
  390. FLOAT = 5126
  391. }
  392. /** @hidden */
  393. export enum EShaderType {
  394. FRAGMENT = 35632,
  395. VERTEX = 35633
  396. }
  397. /** @hidden */
  398. export enum EParameterType {
  399. BYTE = 5120,
  400. UNSIGNED_BYTE = 5121,
  401. SHORT = 5122,
  402. UNSIGNED_SHORT = 5123,
  403. INT = 5124,
  404. UNSIGNED_INT = 5125,
  405. FLOAT = 5126,
  406. FLOAT_VEC2 = 35664,
  407. FLOAT_VEC3 = 35665,
  408. FLOAT_VEC4 = 35666,
  409. INT_VEC2 = 35667,
  410. INT_VEC3 = 35668,
  411. INT_VEC4 = 35669,
  412. BOOL = 35670,
  413. BOOL_VEC2 = 35671,
  414. BOOL_VEC3 = 35672,
  415. BOOL_VEC4 = 35673,
  416. FLOAT_MAT2 = 35674,
  417. FLOAT_MAT3 = 35675,
  418. FLOAT_MAT4 = 35676,
  419. SAMPLER_2D = 35678
  420. }
  421. /** @hidden */
  422. export enum ETextureWrapMode {
  423. CLAMP_TO_EDGE = 33071,
  424. MIRRORED_REPEAT = 33648,
  425. REPEAT = 10497
  426. }
  427. /** @hidden */
  428. export enum ETextureFilterType {
  429. NEAREST = 9728,
  430. LINEAR = 9728,
  431. NEAREST_MIPMAP_NEAREST = 9984,
  432. LINEAR_MIPMAP_NEAREST = 9985,
  433. NEAREST_MIPMAP_LINEAR = 9986,
  434. LINEAR_MIPMAP_LINEAR = 9987
  435. }
  436. /** @hidden */
  437. export enum ETextureFormat {
  438. ALPHA = 6406,
  439. RGB = 6407,
  440. RGBA = 6408,
  441. LUMINANCE = 6409,
  442. LUMINANCE_ALPHA = 6410
  443. }
  444. /** @hidden */
  445. export enum ECullingType {
  446. FRONT = 1028,
  447. BACK = 1029,
  448. FRONT_AND_BACK = 1032
  449. }
  450. /** @hidden */
  451. export enum EBlendingFunction {
  452. ZERO = 0,
  453. ONE = 1,
  454. SRC_COLOR = 768,
  455. ONE_MINUS_SRC_COLOR = 769,
  456. DST_COLOR = 774,
  457. ONE_MINUS_DST_COLOR = 775,
  458. SRC_ALPHA = 770,
  459. ONE_MINUS_SRC_ALPHA = 771,
  460. DST_ALPHA = 772,
  461. ONE_MINUS_DST_ALPHA = 773,
  462. CONSTANT_COLOR = 32769,
  463. ONE_MINUS_CONSTANT_COLOR = 32770,
  464. CONSTANT_ALPHA = 32771,
  465. ONE_MINUS_CONSTANT_ALPHA = 32772,
  466. SRC_ALPHA_SATURATE = 776
  467. }
  468. /** @hidden */
  469. export interface IGLTFProperty {
  470. extensions?: {
  471. [key: string]: any;
  472. };
  473. extras?: Object;
  474. }
  475. /** @hidden */
  476. export interface IGLTFChildRootProperty extends IGLTFProperty {
  477. name?: string;
  478. }
  479. /** @hidden */
  480. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  481. bufferView: string;
  482. byteOffset: number;
  483. byteStride: number;
  484. count: number;
  485. type: string;
  486. componentType: EComponentType;
  487. max?: number[];
  488. min?: number[];
  489. name?: string;
  490. }
  491. /** @hidden */
  492. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  493. buffer: string;
  494. byteOffset: number;
  495. byteLength: number;
  496. byteStride: number;
  497. target?: number;
  498. }
  499. /** @hidden */
  500. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  501. uri: string;
  502. byteLength?: number;
  503. type?: string;
  504. }
  505. /** @hidden */
  506. export interface IGLTFShader extends IGLTFChildRootProperty {
  507. uri: string;
  508. type: EShaderType;
  509. }
  510. /** @hidden */
  511. export interface IGLTFProgram extends IGLTFChildRootProperty {
  512. attributes: string[];
  513. fragmentShader: string;
  514. vertexShader: string;
  515. }
  516. /** @hidden */
  517. export interface IGLTFTechniqueParameter {
  518. type: number;
  519. count?: number;
  520. semantic?: string;
  521. node?: string;
  522. value?: number | boolean | string | Array<any>;
  523. source?: string;
  524. babylonValue?: any;
  525. }
  526. /** @hidden */
  527. export interface IGLTFTechniqueCommonProfile {
  528. lightingModel: string;
  529. texcoordBindings: Object;
  530. parameters?: Array<any>;
  531. }
  532. /** @hidden */
  533. export interface IGLTFTechniqueStatesFunctions {
  534. blendColor?: number[];
  535. blendEquationSeparate?: number[];
  536. blendFuncSeparate?: number[];
  537. colorMask: boolean[];
  538. cullFace: number[];
  539. }
  540. /** @hidden */
  541. export interface IGLTFTechniqueStates {
  542. enable: number[];
  543. functions: IGLTFTechniqueStatesFunctions;
  544. }
  545. /** @hidden */
  546. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  547. parameters: {
  548. [key: string]: IGLTFTechniqueParameter;
  549. };
  550. program: string;
  551. attributes: {
  552. [key: string]: string;
  553. };
  554. uniforms: {
  555. [key: string]: string;
  556. };
  557. states: IGLTFTechniqueStates;
  558. }
  559. /** @hidden */
  560. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  561. technique?: string;
  562. values: string[];
  563. }
  564. /** @hidden */
  565. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  566. attributes: {
  567. [key: string]: string;
  568. };
  569. indices: string;
  570. material: string;
  571. mode?: number;
  572. }
  573. /** @hidden */
  574. export interface IGLTFMesh extends IGLTFChildRootProperty {
  575. primitives: IGLTFMeshPrimitive[];
  576. }
  577. /** @hidden */
  578. export interface IGLTFImage extends IGLTFChildRootProperty {
  579. uri: string;
  580. }
  581. /** @hidden */
  582. export interface IGLTFSampler extends IGLTFChildRootProperty {
  583. magFilter?: number;
  584. minFilter?: number;
  585. wrapS?: number;
  586. wrapT?: number;
  587. }
  588. /** @hidden */
  589. export interface IGLTFTexture extends IGLTFChildRootProperty {
  590. sampler: string;
  591. source: string;
  592. format?: ETextureFormat;
  593. internalFormat?: ETextureFormat;
  594. target?: number;
  595. type?: number;
  596. babylonTexture?: Texture;
  597. }
  598. /** @hidden */
  599. export interface IGLTFAmbienLight {
  600. color?: number[];
  601. }
  602. /** @hidden */
  603. export interface IGLTFDirectionalLight {
  604. color?: number[];
  605. }
  606. /** @hidden */
  607. export interface IGLTFPointLight {
  608. color?: number[];
  609. constantAttenuation?: number;
  610. linearAttenuation?: number;
  611. quadraticAttenuation?: number;
  612. }
  613. /** @hidden */
  614. export interface IGLTFSpotLight {
  615. color?: number[];
  616. constantAttenuation?: number;
  617. fallOfAngle?: number;
  618. fallOffExponent?: number;
  619. linearAttenuation?: number;
  620. quadraticAttenuation?: number;
  621. }
  622. /** @hidden */
  623. export interface IGLTFLight extends IGLTFChildRootProperty {
  624. type: string;
  625. }
  626. /** @hidden */
  627. export interface IGLTFCameraOrthographic {
  628. xmag: number;
  629. ymag: number;
  630. zfar: number;
  631. znear: number;
  632. }
  633. /** @hidden */
  634. export interface IGLTFCameraPerspective {
  635. aspectRatio: number;
  636. yfov: number;
  637. zfar: number;
  638. znear: number;
  639. }
  640. /** @hidden */
  641. export interface IGLTFCamera extends IGLTFChildRootProperty {
  642. type: string;
  643. }
  644. /** @hidden */
  645. export interface IGLTFAnimationChannelTarget {
  646. id: string;
  647. path: string;
  648. }
  649. /** @hidden */
  650. export interface IGLTFAnimationChannel {
  651. sampler: string;
  652. target: IGLTFAnimationChannelTarget;
  653. }
  654. /** @hidden */
  655. export interface IGLTFAnimationSampler {
  656. input: string;
  657. output: string;
  658. interpolation?: string;
  659. }
  660. /** @hidden */
  661. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  662. channels?: IGLTFAnimationChannel[];
  663. parameters?: {
  664. [key: string]: string;
  665. };
  666. samplers?: {
  667. [key: string]: IGLTFAnimationSampler;
  668. };
  669. }
  670. /** @hidden */
  671. export interface IGLTFNodeInstanceSkin {
  672. skeletons: string[];
  673. skin: string;
  674. meshes: string[];
  675. }
  676. /** @hidden */
  677. export interface IGLTFSkins extends IGLTFChildRootProperty {
  678. bindShapeMatrix: number[];
  679. inverseBindMatrices: string;
  680. jointNames: string[];
  681. babylonSkeleton?: Skeleton;
  682. }
  683. /** @hidden */
  684. export interface IGLTFNode extends IGLTFChildRootProperty {
  685. camera?: string;
  686. children: string[];
  687. skin?: string;
  688. jointName?: string;
  689. light?: string;
  690. matrix: number[];
  691. mesh?: string;
  692. meshes?: string[];
  693. rotation?: number[];
  694. scale?: number[];
  695. translation?: number[];
  696. babylonNode?: Node;
  697. }
  698. /** @hidden */
  699. export interface IGLTFScene extends IGLTFChildRootProperty {
  700. nodes: string[];
  701. }
  702. /** @hidden */
  703. export interface IGLTFRuntime {
  704. extensions: {
  705. [key: string]: any;
  706. };
  707. accessors: {
  708. [key: string]: IGLTFAccessor;
  709. };
  710. buffers: {
  711. [key: string]: IGLTFBuffer;
  712. };
  713. bufferViews: {
  714. [key: string]: IGLTFBufferView;
  715. };
  716. meshes: {
  717. [key: string]: IGLTFMesh;
  718. };
  719. lights: {
  720. [key: string]: IGLTFLight;
  721. };
  722. cameras: {
  723. [key: string]: IGLTFCamera;
  724. };
  725. nodes: {
  726. [key: string]: IGLTFNode;
  727. };
  728. images: {
  729. [key: string]: IGLTFImage;
  730. };
  731. textures: {
  732. [key: string]: IGLTFTexture;
  733. };
  734. shaders: {
  735. [key: string]: IGLTFShader;
  736. };
  737. programs: {
  738. [key: string]: IGLTFProgram;
  739. };
  740. samplers: {
  741. [key: string]: IGLTFSampler;
  742. };
  743. techniques: {
  744. [key: string]: IGLTFTechnique;
  745. };
  746. materials: {
  747. [key: string]: IGLTFMaterial;
  748. };
  749. animations: {
  750. [key: string]: IGLTFAnimation;
  751. };
  752. skins: {
  753. [key: string]: IGLTFSkins;
  754. };
  755. currentScene?: Object;
  756. scenes: {
  757. [key: string]: IGLTFScene;
  758. };
  759. extensionsUsed: string[];
  760. extensionsRequired?: string[];
  761. buffersCount: number;
  762. shaderscount: number;
  763. scene: Scene;
  764. rootUrl: string;
  765. loadedBufferCount: number;
  766. loadedBufferViews: {
  767. [name: string]: ArrayBufferView;
  768. };
  769. loadedShaderCount: number;
  770. importOnlyMeshes: boolean;
  771. importMeshesNames?: string[];
  772. dummyNodes: Node[];
  773. forAssetContainer: boolean;
  774. }
  775. /** @hidden */
  776. export interface INodeToRoot {
  777. bone: Bone;
  778. node: IGLTFNode;
  779. id: string;
  780. }
  781. /** @hidden */
  782. export interface IJointNode {
  783. node: IGLTFNode;
  784. id: string;
  785. }
  786. }
  787. declare module BABYLON.GLTF1 {
  788. /**
  789. * Utils functions for GLTF
  790. * @hidden
  791. */
  792. export class GLTFUtils {
  793. /**
  794. * Sets the given "parameter" matrix
  795. * @param scene: the Scene object
  796. * @param source: the source node where to pick the matrix
  797. * @param parameter: the GLTF technique parameter
  798. * @param uniformName: the name of the shader's uniform
  799. * @param shaderMaterial: the shader material
  800. */
  801. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  802. /**
  803. * Sets the given "parameter" matrix
  804. * @param shaderMaterial: the shader material
  805. * @param uniform: the name of the shader's uniform
  806. * @param value: the value of the uniform
  807. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  808. */
  809. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  810. /**
  811. * Returns the wrap mode of the texture
  812. * @param mode: the mode value
  813. */
  814. static GetWrapMode(mode: number): number;
  815. /**
  816. * Returns the byte stride giving an accessor
  817. * @param accessor: the GLTF accessor objet
  818. */
  819. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  820. /**
  821. * Returns the texture filter mode giving a mode value
  822. * @param mode: the filter mode value
  823. */
  824. static GetTextureFilterMode(mode: number): ETextureFilterType;
  825. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  826. /**
  827. * Returns a buffer from its accessor
  828. * @param gltfRuntime: the GLTF runtime
  829. * @param accessor: the GLTF accessor
  830. */
  831. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  832. /**
  833. * Decodes a buffer view into a string
  834. * @param view: the buffer view
  835. */
  836. static DecodeBufferToText(view: ArrayBufferView): string;
  837. /**
  838. * Returns the default material of gltf. Related to
  839. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  840. * @param scene: the Babylon.js scene
  841. */
  842. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  843. private static _DefaultMaterial;
  844. }
  845. }
  846. declare module BABYLON.GLTF1 {
  847. /**
  848. * Implementation of the base glTF spec
  849. * @hidden
  850. */
  851. export class GLTFLoaderBase {
  852. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  853. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  854. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  855. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  856. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  857. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  858. }
  859. /**
  860. * glTF V1 Loader
  861. * @hidden
  862. */
  863. export class GLTFLoader implements IGLTFLoader {
  864. static Extensions: {
  865. [name: string]: GLTFLoaderExtension;
  866. };
  867. static RegisterExtension(extension: GLTFLoaderExtension): void;
  868. state: Nullable<GLTFLoaderState>;
  869. dispose(): void;
  870. private _importMeshAsync;
  871. /**
  872. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  873. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  874. * @param scene the scene the meshes should be added to
  875. * @param forAssetContainer defines if the entities must be stored in the scene
  876. * @param data gltf data containing information of the meshes in a loaded file
  877. * @param rootUrl root url to load from
  878. * @param onProgress event that fires when loading progress has occured
  879. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  880. */
  881. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void): Promise<IImportMeshAsyncOutput>;
  882. private _loadAsync;
  883. /**
  884. * Imports all objects from a loaded gltf file and adds them to the scene
  885. * @param scene the scene the objects should be added to
  886. * @param data gltf data containing information of the meshes in a loaded file
  887. * @param rootUrl root url to load from
  888. * @param onProgress event that fires when loading progress has occured
  889. * @returns a promise which completes when objects have been loaded to the scene
  890. */
  891. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void): Promise<void>;
  892. private _loadShadersAsync;
  893. private _loadBuffersAsync;
  894. private _createNodes;
  895. }
  896. /** @hidden */
  897. export abstract class GLTFLoaderExtension {
  898. private _name;
  899. constructor(name: string);
  900. get name(): string;
  901. /**
  902. * Defines an override for loading the runtime
  903. * Return true to stop further extensions from loading the runtime
  904. */
  905. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  906. /**
  907. * Defines an onverride for creating gltf runtime
  908. * Return true to stop further extensions from creating the runtime
  909. */
  910. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  911. /**
  912. * Defines an override for loading buffers
  913. * Return true to stop further extensions from loading this buffer
  914. */
  915. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  916. /**
  917. * Defines an override for loading texture buffers
  918. * Return true to stop further extensions from loading this texture data
  919. */
  920. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  921. /**
  922. * Defines an override for creating textures
  923. * Return true to stop further extensions from loading this texture
  924. */
  925. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  926. /**
  927. * Defines an override for loading shader strings
  928. * Return true to stop further extensions from loading this shader data
  929. */
  930. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  931. /**
  932. * Defines an override for loading materials
  933. * Return true to stop further extensions from loading this material
  934. */
  935. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  936. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  937. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  938. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  939. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  940. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  941. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  942. private static LoadTextureBufferAsync;
  943. private static CreateTextureAsync;
  944. private static ApplyExtensions;
  945. }
  946. }
  947. declare module BABYLON.GLTF1 {
  948. /** @hidden */
  949. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  950. private _bin;
  951. constructor();
  952. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  953. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  954. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  955. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  956. }
  957. }
  958. declare module BABYLON.GLTF1 {
  959. /** @hidden */
  960. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  961. constructor();
  962. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  963. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  964. private _loadTexture;
  965. }
  966. }
  967. declare module BABYLON.GLTF2.Loader {
  968. /**
  969. * Loader interface with an index field.
  970. */
  971. export interface IArrayItem {
  972. /**
  973. * The index of this item in the array.
  974. */
  975. index: number;
  976. }
  977. /**
  978. * Loader interface with additional members.
  979. */
  980. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  981. /** @hidden */
  982. _data?: Promise<ArrayBufferView>;
  983. /** @hidden */
  984. _babylonVertexBuffer?: Promise<VertexBuffer>;
  985. }
  986. /**
  987. * Loader interface with additional members.
  988. */
  989. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  990. }
  991. /** @hidden */
  992. export interface _IAnimationSamplerData {
  993. input: Float32Array;
  994. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  995. output: Float32Array;
  996. }
  997. /**
  998. * Loader interface with additional members.
  999. */
  1000. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  1001. /** @hidden */
  1002. _data?: Promise<_IAnimationSamplerData>;
  1003. }
  1004. /**
  1005. * Loader interface with additional members.
  1006. */
  1007. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  1008. channels: IAnimationChannel[];
  1009. samplers: IAnimationSampler[];
  1010. /** @hidden */
  1011. _babylonAnimationGroup?: AnimationGroup;
  1012. }
  1013. /**
  1014. * Loader interface with additional members.
  1015. */
  1016. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  1017. /** @hidden */
  1018. _data?: Promise<ArrayBufferView>;
  1019. }
  1020. /**
  1021. * Loader interface with additional members.
  1022. */
  1023. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  1024. /** @hidden */
  1025. _data?: Promise<ArrayBufferView>;
  1026. /** @hidden */
  1027. _babylonBuffer?: Promise<Buffer>;
  1028. }
  1029. /**
  1030. * Loader interface with additional members.
  1031. */
  1032. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  1033. }
  1034. /**
  1035. * Loader interface with additional members.
  1036. */
  1037. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  1038. /** @hidden */
  1039. _data?: Promise<ArrayBufferView>;
  1040. }
  1041. /**
  1042. * Loader interface with additional members.
  1043. */
  1044. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1045. }
  1046. /**
  1047. * Loader interface with additional members.
  1048. */
  1049. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1050. }
  1051. /**
  1052. * Loader interface with additional members.
  1053. */
  1054. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  1055. baseColorTexture?: ITextureInfo;
  1056. metallicRoughnessTexture?: ITextureInfo;
  1057. }
  1058. /**
  1059. * Loader interface with additional members.
  1060. */
  1061. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  1062. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1063. normalTexture?: IMaterialNormalTextureInfo;
  1064. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1065. emissiveTexture?: ITextureInfo;
  1066. /** @hidden */
  1067. _data?: {
  1068. [babylonDrawMode: number]: {
  1069. babylonMaterial: Material;
  1070. babylonMeshes: AbstractMesh[];
  1071. promise: Promise<void>;
  1072. };
  1073. };
  1074. }
  1075. /**
  1076. * Loader interface with additional members.
  1077. */
  1078. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  1079. primitives: IMeshPrimitive[];
  1080. }
  1081. /**
  1082. * Loader interface with additional members.
  1083. */
  1084. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  1085. /** @hidden */
  1086. _instanceData?: {
  1087. babylonSourceMesh: Mesh;
  1088. promise: Promise<any>;
  1089. };
  1090. }
  1091. /**
  1092. * Loader interface with additional members.
  1093. */
  1094. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  1095. /**
  1096. * The parent glTF node.
  1097. */
  1098. parent?: INode;
  1099. /** @hidden */
  1100. _babylonTransformNode?: TransformNode;
  1101. /** @hidden */
  1102. _primitiveBabylonMeshes?: AbstractMesh[];
  1103. /** @hidden */
  1104. _babylonBones?: Bone[];
  1105. /** @hidden */
  1106. _numMorphTargets?: number;
  1107. }
  1108. /** @hidden */
  1109. export interface _ISamplerData {
  1110. noMipMaps: boolean;
  1111. samplingMode: number;
  1112. wrapU: number;
  1113. wrapV: number;
  1114. }
  1115. /**
  1116. * Loader interface with additional members.
  1117. */
  1118. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  1119. /** @hidden */
  1120. _data?: _ISamplerData;
  1121. }
  1122. /**
  1123. * Loader interface with additional members.
  1124. */
  1125. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  1126. }
  1127. /**
  1128. * Loader interface with additional members.
  1129. */
  1130. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  1131. /** @hidden */
  1132. _data?: {
  1133. babylonSkeleton: Skeleton;
  1134. promise: Promise<void>;
  1135. };
  1136. }
  1137. /**
  1138. * Loader interface with additional members.
  1139. */
  1140. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  1141. }
  1142. /**
  1143. * Loader interface with additional members.
  1144. */
  1145. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  1146. }
  1147. /**
  1148. * Loader interface with additional members.
  1149. */
  1150. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  1151. accessors?: IAccessor[];
  1152. animations?: IAnimation[];
  1153. buffers?: IBuffer[];
  1154. bufferViews?: IBufferView[];
  1155. cameras?: ICamera[];
  1156. images?: IImage[];
  1157. materials?: IMaterial[];
  1158. meshes?: IMesh[];
  1159. nodes?: INode[];
  1160. samplers?: ISampler[];
  1161. scenes?: IScene[];
  1162. skins?: ISkin[];
  1163. textures?: ITexture[];
  1164. }
  1165. }
  1166. declare module BABYLON.GLTF2 {
  1167. /**
  1168. * Interface for a glTF loader extension.
  1169. */
  1170. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  1171. /**
  1172. * Called after the loader state changes to LOADING.
  1173. */
  1174. onLoading?(): void;
  1175. /**
  1176. * Called after the loader state changes to READY.
  1177. */
  1178. onReady?(): void;
  1179. /**
  1180. * Define this method to modify the default behavior when loading scenes.
  1181. * @param context The context when loading the asset
  1182. * @param scene The glTF scene property
  1183. * @returns A promise that resolves when the load is complete or null if not handled
  1184. */
  1185. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1186. /**
  1187. * Define this method to modify the default behavior when loading nodes.
  1188. * @param context The context when loading the asset
  1189. * @param node The glTF node property
  1190. * @param assign A function called synchronously after parsing the glTF properties
  1191. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1192. */
  1193. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1194. /**
  1195. * Define this method to modify the default behavior when loading cameras.
  1196. * @param context The context when loading the asset
  1197. * @param camera The glTF camera property
  1198. * @param assign A function called synchronously after parsing the glTF properties
  1199. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1200. */
  1201. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1202. /**
  1203. * @hidden
  1204. * Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1205. * @param context The context when loading the asset
  1206. * @param primitive The glTF mesh primitive property
  1207. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1208. */
  1209. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1210. /**
  1211. * @hidden
  1212. * Define this method to modify the default behavior when loading data for mesh primitives.
  1213. * @param context The context when loading the asset
  1214. * @param name The mesh name when loading the asset
  1215. * @param node The glTF node when loading the asset
  1216. * @param mesh The glTF mesh when loading the asset
  1217. * @param primitive The glTF mesh primitive property
  1218. * @param assign A function called synchronously after parsing the glTF properties
  1219. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1220. */
  1221. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  1222. /**
  1223. * @hidden
  1224. * Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1225. * @param context The context when loading the asset
  1226. * @param material The glTF material property
  1227. * @param assign A function called synchronously after parsing the glTF properties
  1228. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1229. */
  1230. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1231. /**
  1232. * Define this method to modify the default behavior when creating materials.
  1233. * @param context The context when loading the asset
  1234. * @param material The glTF material property
  1235. * @param babylonDrawMode The draw mode for the Babylon material
  1236. * @returns The Babylon material or null if not handled
  1237. */
  1238. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1239. /**
  1240. * Define this method to modify the default behavior when loading material properties.
  1241. * @param context The context when loading the asset
  1242. * @param material The glTF material property
  1243. * @param babylonMaterial The Babylon material
  1244. * @returns A promise that resolves when the load is complete or null if not handled
  1245. */
  1246. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1247. /**
  1248. * Define this method to modify the default behavior when loading texture infos.
  1249. * @param context The context when loading the asset
  1250. * @param textureInfo The glTF texture info property
  1251. * @param assign A function called synchronously after parsing the glTF properties
  1252. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1253. */
  1254. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1255. /**
  1256. * @hidden
  1257. * Define this method to modify the default behavior when loading textures.
  1258. * @param context The context when loading the asset
  1259. * @param texture The glTF texture property
  1260. * @param assign A function called synchronously after parsing the glTF properties
  1261. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1262. */
  1263. _loadTextureAsync?(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1264. /**
  1265. * Define this method to modify the default behavior when loading animations.
  1266. * @param context The context when loading the asset
  1267. * @param animation The glTF animation property
  1268. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1269. */
  1270. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1271. /**
  1272. * @hidden
  1273. * Define this method to modify the default behavior when loading skins.
  1274. * @param context The context when loading the asset
  1275. * @param node The glTF node property
  1276. * @param skin The glTF skin property
  1277. * @returns A promise that resolves when the load is complete or null if not handled
  1278. */
  1279. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1280. /**
  1281. * @hidden
  1282. * Define this method to modify the default behavior when loading uris.
  1283. * @param context The context when loading the asset
  1284. * @param property The glTF property associated with the uri
  1285. * @param uri The uri to load
  1286. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1287. */
  1288. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1289. /**
  1290. * Define this method to modify the default behavior when loading buffer views.
  1291. * @param context The context when loading the asset
  1292. * @param bufferView The glTF buffer view property
  1293. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1294. */
  1295. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1296. /**
  1297. * Define this method to modify the default behavior when loading buffers.
  1298. * @param context The context when loading the asset
  1299. * @param buffer The glTF buffer property
  1300. * @param byteOffset The byte offset to load
  1301. * @param byteLength The byte length to load
  1302. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1303. */
  1304. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  1305. }
  1306. }
  1307. declare module BABYLON.GLTF2 {
  1308. /**
  1309. * Helper class for working with arrays when loading the glTF asset
  1310. */
  1311. export class ArrayItem {
  1312. /**
  1313. * Gets an item from the given array.
  1314. * @param context The context when loading the asset
  1315. * @param array The array to get the item from
  1316. * @param index The index to the array
  1317. * @returns The array item
  1318. */
  1319. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1320. /**
  1321. * Assign an `index` field to each item of the given array.
  1322. * @param array The array of items
  1323. */
  1324. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  1325. }
  1326. /**
  1327. * The glTF 2.0 loader
  1328. */
  1329. export class GLTFLoader implements IGLTFLoader {
  1330. /** @hidden */
  1331. _completePromises: Promise<any>[];
  1332. /** @hidden */
  1333. _forAssetContainer: boolean;
  1334. /** Storage */
  1335. _babylonLights: Light[];
  1336. /** @hidden */
  1337. _disableInstancedMesh: number;
  1338. private _disposed;
  1339. private _parent;
  1340. private _state;
  1341. private _extensions;
  1342. private _rootUrl;
  1343. private _fileName;
  1344. private _uniqueRootUrl;
  1345. private _gltf;
  1346. private _bin;
  1347. private _babylonScene;
  1348. private _rootBabylonMesh;
  1349. private _defaultBabylonMaterialData;
  1350. private static _RegisteredExtensions;
  1351. /**
  1352. * The default glTF sampler.
  1353. */
  1354. static readonly DefaultSampler: ISampler;
  1355. /**
  1356. * Registers a loader extension.
  1357. * @param name The name of the loader extension.
  1358. * @param factory The factory function that creates the loader extension.
  1359. */
  1360. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1361. /**
  1362. * Unregisters a loader extension.
  1363. * @param name The name of the loader extension.
  1364. * @returns A boolean indicating whether the extension has been unregistered
  1365. */
  1366. static UnregisterExtension(name: string): boolean;
  1367. /**
  1368. * The loader state.
  1369. */
  1370. get state(): Nullable<GLTFLoaderState>;
  1371. /**
  1372. * The object that represents the glTF JSON.
  1373. */
  1374. get gltf(): IGLTF;
  1375. /**
  1376. * The BIN chunk of a binary glTF.
  1377. */
  1378. get bin(): Nullable<IDataBuffer>;
  1379. /**
  1380. * The parent file loader.
  1381. */
  1382. get parent(): GLTFFileLoader;
  1383. /**
  1384. * The Babylon scene when loading the asset.
  1385. */
  1386. get babylonScene(): Scene;
  1387. /**
  1388. * The root Babylon mesh when loading the asset.
  1389. */
  1390. get rootBabylonMesh(): Mesh;
  1391. /** @hidden */
  1392. constructor(parent: GLTFFileLoader);
  1393. /** @hidden */
  1394. dispose(): void;
  1395. /** @hidden */
  1396. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<IImportMeshAsyncOutput>;
  1397. /** @hidden */
  1398. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1399. private _loadAsync;
  1400. private _loadData;
  1401. private _setupData;
  1402. private _loadExtensions;
  1403. private _checkExtensions;
  1404. private _setState;
  1405. private _createRootNode;
  1406. /**
  1407. * Loads a glTF scene.
  1408. * @param context The context when loading the asset
  1409. * @param scene The glTF scene property
  1410. * @returns A promise that resolves when the load is complete
  1411. */
  1412. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1413. private _forEachPrimitive;
  1414. private _getMeshes;
  1415. private _getTransformNodes;
  1416. private _getSkeletons;
  1417. private _getAnimationGroups;
  1418. private _startAnimations;
  1419. /**
  1420. * Loads a glTF node.
  1421. * @param context The context when loading the asset
  1422. * @param node The glTF node property
  1423. * @param assign A function called synchronously after parsing the glTF properties
  1424. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1425. */
  1426. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1427. private _loadMeshAsync;
  1428. /**
  1429. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1430. * @param context The context when loading the asset
  1431. * @param name The mesh name when loading the asset
  1432. * @param node The glTF node when loading the asset
  1433. * @param mesh The glTF mesh when loading the asset
  1434. * @param primitive The glTF mesh primitive property
  1435. * @param assign A function called synchronously after parsing the glTF properties
  1436. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1437. */
  1438. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1439. private _loadVertexDataAsync;
  1440. private _createMorphTargets;
  1441. private _loadMorphTargetsAsync;
  1442. private _loadMorphTargetVertexDataAsync;
  1443. private static _LoadTransform;
  1444. private _loadSkinAsync;
  1445. private _loadBones;
  1446. private _loadBone;
  1447. private _loadSkinInverseBindMatricesDataAsync;
  1448. private _updateBoneMatrices;
  1449. private _getNodeMatrix;
  1450. /**
  1451. * Loads a glTF camera.
  1452. * @param context The context when loading the asset
  1453. * @param camera The glTF camera property
  1454. * @param assign A function called synchronously after parsing the glTF properties
  1455. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1456. */
  1457. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1458. private _loadAnimationsAsync;
  1459. /**
  1460. * Loads a glTF animation.
  1461. * @param context The context when loading the asset
  1462. * @param animation The glTF animation property
  1463. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1464. */
  1465. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1466. /**
  1467. * @hidden Loads a glTF animation channel.
  1468. * @param context The context when loading the asset
  1469. * @param animationContext The context of the animation when loading the asset
  1470. * @param animation The glTF animation property
  1471. * @param channel The glTF animation channel property
  1472. * @param babylonAnimationGroup The babylon animation group property
  1473. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1474. * @returns A void promise when the channel load is complete
  1475. */
  1476. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1477. private _loadAnimationSamplerAsync;
  1478. private _loadBufferAsync;
  1479. /**
  1480. * Loads a glTF buffer view.
  1481. * @param context The context when loading the asset
  1482. * @param bufferView The glTF buffer view property
  1483. * @returns A promise that resolves with the loaded data when the load is complete
  1484. */
  1485. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1486. private _loadAccessorAsync;
  1487. /** @hidden */
  1488. _loadFloatAccessorAsync(context: string, accessor: IAccessor): Promise<Float32Array>;
  1489. private _loadIndicesAccessorAsync;
  1490. private _loadVertexBufferViewAsync;
  1491. private _loadVertexAccessorAsync;
  1492. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1493. /** @hidden */
  1494. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1495. private _createDefaultMaterial;
  1496. /**
  1497. * Creates a Babylon material from a glTF material.
  1498. * @param context The context when loading the asset
  1499. * @param material The glTF material property
  1500. * @param babylonDrawMode The draw mode for the Babylon material
  1501. * @returns The Babylon material
  1502. */
  1503. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1504. /**
  1505. * Loads properties from a glTF material into a Babylon material.
  1506. * @param context The context when loading the asset
  1507. * @param material The glTF material property
  1508. * @param babylonMaterial The Babylon material
  1509. * @returns A promise that resolves when the load is complete
  1510. */
  1511. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1512. /**
  1513. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1514. * @param context The context when loading the asset
  1515. * @param material The glTF material property
  1516. * @param babylonMaterial The Babylon material
  1517. * @returns A promise that resolves when the load is complete
  1518. */
  1519. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1520. /**
  1521. * Loads the alpha properties from a glTF material into a Babylon material.
  1522. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1523. * @param context The context when loading the asset
  1524. * @param material The glTF material property
  1525. * @param babylonMaterial The Babylon material
  1526. */
  1527. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1528. /**
  1529. * Loads a glTF texture info.
  1530. * @param context The context when loading the asset
  1531. * @param textureInfo The glTF texture info property
  1532. * @param assign A function called synchronously after parsing the glTF properties
  1533. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1534. */
  1535. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1536. /** @hidden */
  1537. _loadTextureAsync(context: string, texture: ITexture, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1538. /** @hidden */
  1539. _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1540. private _loadSampler;
  1541. /**
  1542. * Loads a glTF image.
  1543. * @param context The context when loading the asset
  1544. * @param image The glTF image property
  1545. * @returns A promise that resolves with the loaded data when the load is complete
  1546. */
  1547. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1548. /**
  1549. * Loads a glTF uri.
  1550. * @param context The context when loading the asset
  1551. * @param property The glTF property associated with the uri
  1552. * @param uri The base64 or relative uri
  1553. * @returns A promise that resolves with the loaded data when the load is complete
  1554. */
  1555. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1556. /**
  1557. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1558. * @param babylonObject the Babylon object with metadata
  1559. * @param pointer the JSON pointer
  1560. */
  1561. static AddPointerMetadata(babylonObject: {
  1562. metadata: any;
  1563. }, pointer: string): void;
  1564. private static _GetTextureWrapMode;
  1565. private static _GetTextureSamplingMode;
  1566. private static _GetTypedArrayConstructor;
  1567. private static _GetTypedArray;
  1568. private static _GetNumComponents;
  1569. private static _ValidateUri;
  1570. /** @hidden */
  1571. static _GetDrawMode(context: string, mode: number | undefined): number;
  1572. private _compileMaterialsAsync;
  1573. private _compileShadowGeneratorsAsync;
  1574. private _forEachExtensions;
  1575. private _applyExtensions;
  1576. private _extensionsOnLoading;
  1577. private _extensionsOnReady;
  1578. private _extensionsLoadSceneAsync;
  1579. private _extensionsLoadNodeAsync;
  1580. private _extensionsLoadCameraAsync;
  1581. private _extensionsLoadVertexDataAsync;
  1582. private _extensionsLoadMeshPrimitiveAsync;
  1583. private _extensionsLoadMaterialAsync;
  1584. private _extensionsCreateMaterial;
  1585. private _extensionsLoadMaterialPropertiesAsync;
  1586. private _extensionsLoadTextureInfoAsync;
  1587. private _extensionsLoadTextureAsync;
  1588. private _extensionsLoadAnimationAsync;
  1589. private _extensionsLoadSkinAsync;
  1590. private _extensionsLoadUriAsync;
  1591. private _extensionsLoadBufferViewAsync;
  1592. private _extensionsLoadBufferAsync;
  1593. /**
  1594. * Helper method called by a loader extension to load an glTF extension.
  1595. * @param context The context when loading the asset
  1596. * @param property The glTF property to load the extension from
  1597. * @param extensionName The name of the extension to load
  1598. * @param actionAsync The action to run
  1599. * @returns The promise returned by actionAsync or null if the extension does not exist
  1600. */
  1601. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1602. /**
  1603. * Helper method called by a loader extension to load a glTF extra.
  1604. * @param context The context when loading the asset
  1605. * @param property The glTF property to load the extra from
  1606. * @param extensionName The name of the extension to load
  1607. * @param actionAsync The action to run
  1608. * @returns The promise returned by actionAsync or null if the extra does not exist
  1609. */
  1610. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1611. /**
  1612. * Checks for presence of an extension.
  1613. * @param name The name of the extension to check
  1614. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1615. */
  1616. isExtensionUsed(name: string): boolean;
  1617. /**
  1618. * Increments the indentation level and logs a message.
  1619. * @param message The message to log
  1620. */
  1621. logOpen(message: string): void;
  1622. /**
  1623. * Decrements the indentation level.
  1624. */
  1625. logClose(): void;
  1626. /**
  1627. * Logs a message
  1628. * @param message The message to log
  1629. */
  1630. log(message: string): void;
  1631. /**
  1632. * Starts a performance counter.
  1633. * @param counterName The name of the performance counter
  1634. */
  1635. startPerformanceCounter(counterName: string): void;
  1636. /**
  1637. * Ends a performance counter.
  1638. * @param counterName The name of the performance counter
  1639. */
  1640. endPerformanceCounter(counterName: string): void;
  1641. }
  1642. }
  1643. declare module BABYLON.GLTF2.Loader.Extensions {
  1644. /**
  1645. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1646. */
  1647. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1648. /**
  1649. * The name of this extension.
  1650. */
  1651. readonly name: string;
  1652. /**
  1653. * Defines whether this extension is enabled.
  1654. */
  1655. enabled: boolean;
  1656. private _loader;
  1657. private _lights?;
  1658. /** @hidden */
  1659. constructor(loader: GLTFLoader);
  1660. /** @hidden */
  1661. dispose(): void;
  1662. /** @hidden */
  1663. onLoading(): void;
  1664. /** @hidden */
  1665. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1666. private _loadLightAsync;
  1667. }
  1668. }
  1669. declare module BABYLON.GLTF2.Loader.Extensions {
  1670. /**
  1671. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  1672. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  1673. * !!! Experimental Extension Subject to Changes !!!
  1674. */
  1675. export class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
  1676. /**
  1677. * The name of this extension.
  1678. */
  1679. readonly name: string;
  1680. /**
  1681. * Defines whether this extension is enabled.
  1682. */
  1683. enabled: boolean;
  1684. private _loader;
  1685. /** @hidden */
  1686. constructor(loader: GLTFLoader);
  1687. /** @hidden */
  1688. dispose(): void;
  1689. /** @hidden */
  1690. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1691. }
  1692. }
  1693. declare module BABYLON.GLTF2.Loader.Extensions {
  1694. /**
  1695. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1696. */
  1697. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1698. /**
  1699. * The name of this extension.
  1700. */
  1701. readonly name: string;
  1702. /**
  1703. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1704. */
  1705. dracoCompression?: DracoCompression;
  1706. /**
  1707. * Defines whether this extension is enabled.
  1708. */
  1709. enabled: boolean;
  1710. private _loader;
  1711. /** @hidden */
  1712. constructor(loader: GLTFLoader);
  1713. /** @hidden */
  1714. dispose(): void;
  1715. /** @hidden */
  1716. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1717. }
  1718. }
  1719. declare module BABYLON.GLTF2.Loader.Extensions {
  1720. /**
  1721. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  1722. */
  1723. export class KHR_lights implements IGLTFLoaderExtension {
  1724. /**
  1725. * The name of this extension.
  1726. */
  1727. readonly name: string;
  1728. /**
  1729. * Defines whether this extension is enabled.
  1730. */
  1731. enabled: boolean;
  1732. private _loader;
  1733. private _lights?;
  1734. /** @hidden */
  1735. constructor(loader: GLTFLoader);
  1736. /** @hidden */
  1737. dispose(): void;
  1738. /** @hidden */
  1739. onLoading(): void;
  1740. /** @hidden */
  1741. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1742. }
  1743. }
  1744. declare module BABYLON.GLTF2.Loader.Extensions {
  1745. /**
  1746. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1747. */
  1748. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1749. /**
  1750. * The name of this extension.
  1751. */
  1752. readonly name: string;
  1753. /**
  1754. * Defines whether this extension is enabled.
  1755. */
  1756. enabled: boolean;
  1757. /**
  1758. * Defines a number that determines the order the extensions are applied.
  1759. */
  1760. order: number;
  1761. private _loader;
  1762. /** @hidden */
  1763. constructor(loader: GLTFLoader);
  1764. /** @hidden */
  1765. dispose(): void;
  1766. /** @hidden */
  1767. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1768. private _loadSpecularGlossinessPropertiesAsync;
  1769. }
  1770. }
  1771. declare module BABYLON.GLTF2.Loader.Extensions {
  1772. /**
  1773. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1774. */
  1775. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1776. /**
  1777. * The name of this extension.
  1778. */
  1779. readonly name: string;
  1780. /**
  1781. * Defines whether this extension is enabled.
  1782. */
  1783. enabled: boolean;
  1784. /**
  1785. * Defines a number that determines the order the extensions are applied.
  1786. */
  1787. order: number;
  1788. private _loader;
  1789. /** @hidden */
  1790. constructor(loader: GLTFLoader);
  1791. /** @hidden */
  1792. dispose(): void;
  1793. /** @hidden */
  1794. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1795. private _loadUnlitPropertiesAsync;
  1796. }
  1797. }
  1798. declare module BABYLON.GLTF2.Loader.Extensions {
  1799. /**
  1800. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1801. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1802. * !!! Experimental Extension Subject to Changes !!!
  1803. */
  1804. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1805. /**
  1806. * The name of this extension.
  1807. */
  1808. readonly name: string;
  1809. /**
  1810. * Defines whether this extension is enabled.
  1811. */
  1812. enabled: boolean;
  1813. /**
  1814. * Defines a number that determines the order the extensions are applied.
  1815. */
  1816. order: number;
  1817. private _loader;
  1818. /** @hidden */
  1819. constructor(loader: GLTFLoader);
  1820. /** @hidden */
  1821. dispose(): void;
  1822. /** @hidden */
  1823. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1824. private _loadClearCoatPropertiesAsync;
  1825. }
  1826. }
  1827. declare module BABYLON.GLTF2.Loader.Extensions {
  1828. /**
  1829. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  1830. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1831. * !!! Experimental Extension Subject to Changes !!!
  1832. */
  1833. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1834. /**
  1835. * The name of this extension.
  1836. */
  1837. readonly name: string;
  1838. /**
  1839. * Defines whether this extension is enabled.
  1840. */
  1841. enabled: boolean;
  1842. /**
  1843. * Defines a number that determines the order the extensions are applied.
  1844. */
  1845. order: number;
  1846. private _loader;
  1847. /** @hidden */
  1848. constructor(loader: GLTFLoader);
  1849. /** @hidden */
  1850. dispose(): void;
  1851. /** @hidden */
  1852. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1853. private _loadSheenPropertiesAsync;
  1854. }
  1855. }
  1856. declare module BABYLON.GLTF2.Loader.Extensions {
  1857. /**
  1858. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  1859. * !!! Experimental Extension Subject to Changes !!!
  1860. */
  1861. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1862. /**
  1863. * The name of this extension.
  1864. */
  1865. readonly name: string;
  1866. /**
  1867. * Defines whether this extension is enabled.
  1868. */
  1869. enabled: boolean;
  1870. /**
  1871. * Defines a number that determines the order the extensions are applied.
  1872. */
  1873. order: number;
  1874. private _loader;
  1875. /** @hidden */
  1876. constructor(loader: GLTFLoader);
  1877. /** @hidden */
  1878. dispose(): void;
  1879. /** @hidden */
  1880. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1881. private _loadSpecularPropertiesAsync;
  1882. }
  1883. }
  1884. declare module BABYLON.GLTF2.Loader.Extensions {
  1885. /**
  1886. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  1887. * !!! Experimental Extension Subject to Changes !!!
  1888. */
  1889. export class KHR_materials_ior implements IGLTFLoaderExtension {
  1890. /**
  1891. * Default ior Value from the spec.
  1892. */
  1893. private static readonly _DEFAULT_IOR;
  1894. /**
  1895. * The name of this extension.
  1896. */
  1897. readonly name: string;
  1898. /**
  1899. * Defines whether this extension is enabled.
  1900. */
  1901. enabled: boolean;
  1902. /**
  1903. * Defines a number that determines the order the extensions are applied.
  1904. */
  1905. order: number;
  1906. private _loader;
  1907. /** @hidden */
  1908. constructor(loader: GLTFLoader);
  1909. /** @hidden */
  1910. dispose(): void;
  1911. /** @hidden */
  1912. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1913. private _loadIorPropertiesAsync;
  1914. }
  1915. }
  1916. declare module BABYLON.GLTF2.Loader.Extensions {
  1917. /**
  1918. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  1919. * !!! Experimental Extension Subject to Changes !!!
  1920. */
  1921. export class KHR_materials_variants implements IGLTFLoaderExtension {
  1922. /**
  1923. * The name of this extension.
  1924. */
  1925. readonly name: string;
  1926. /**
  1927. * Defines whether this extension is enabled.
  1928. */
  1929. enabled: boolean;
  1930. private _loader;
  1931. /** @hidden */
  1932. constructor(loader: GLTFLoader);
  1933. /** @hidden */
  1934. dispose(): void;
  1935. /**
  1936. * Gets the list of available variant tag names for this asset.
  1937. * @param rootMesh The glTF root mesh
  1938. * @returns the list of all the variant names for this model
  1939. */
  1940. static GetAvailableVariants(rootMesh: Mesh): string[];
  1941. /**
  1942. * Select a variant given a variant tag name or a list of variant tag names.
  1943. * @param rootMesh The glTF root mesh
  1944. * @param variantName The variant name(s) to select.
  1945. */
  1946. static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void;
  1947. /**
  1948. * Reset back to the original before selecting a variant.
  1949. * @param rootMesh The glTF root mesh
  1950. */
  1951. static Reset(rootMesh: Mesh): void;
  1952. /**
  1953. * Gets the last selected variant tag name(s) or null if original.
  1954. * @param rootMesh The glTF root mesh
  1955. * @returns The selected variant tag name(s).
  1956. */
  1957. static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]>;
  1958. private static _GetExtensionMetadata;
  1959. /** @hidden */
  1960. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  1961. }
  1962. }
  1963. declare module BABYLON.GLTF2.Loader.Extensions {
  1964. /**
  1965. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  1966. * !!! Experimental Extension Subject to Changes !!!
  1967. */
  1968. export class KHR_materials_transmission implements IGLTFLoaderExtension {
  1969. /**
  1970. * The name of this extension.
  1971. */
  1972. readonly name: string;
  1973. /**
  1974. * Defines whether this extension is enabled.
  1975. */
  1976. enabled: boolean;
  1977. /**
  1978. * Defines a number that determines the order the extensions are applied.
  1979. */
  1980. order: number;
  1981. private _loader;
  1982. /** @hidden */
  1983. constructor(loader: GLTFLoader);
  1984. /** @hidden */
  1985. dispose(): void;
  1986. /** @hidden */
  1987. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1988. private _loadTransparentPropertiesAsync;
  1989. }
  1990. }
  1991. declare module BABYLON.GLTF2.Loader.Extensions {
  1992. /**
  1993. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1994. */
  1995. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1996. /**
  1997. * The name of this extension.
  1998. */
  1999. readonly name: string;
  2000. /**
  2001. * Defines whether this extension is enabled.
  2002. */
  2003. enabled: boolean;
  2004. /** @hidden */
  2005. constructor(loader: GLTFLoader);
  2006. /** @hidden */
  2007. dispose(): void;
  2008. }
  2009. }
  2010. declare module BABYLON.GLTF2.Loader.Extensions {
  2011. /**
  2012. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  2013. * !!! Experimental Extension Subject to Changes !!!
  2014. */
  2015. export class KHR_texture_basisu implements IGLTFLoaderExtension {
  2016. /** The name of this extension. */
  2017. readonly name: string;
  2018. /** Defines whether this extension is enabled. */
  2019. enabled: boolean;
  2020. private _loader;
  2021. /** @hidden */
  2022. constructor(loader: GLTFLoader);
  2023. /** @hidden */
  2024. dispose(): void;
  2025. /** @hidden */
  2026. _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2027. }
  2028. }
  2029. declare module BABYLON.GLTF2.Loader.Extensions {
  2030. /**
  2031. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  2032. */
  2033. export class KHR_texture_transform implements IGLTFLoaderExtension {
  2034. /**
  2035. * The name of this extension.
  2036. */
  2037. readonly name: string;
  2038. /**
  2039. * Defines whether this extension is enabled.
  2040. */
  2041. enabled: boolean;
  2042. private _loader;
  2043. /** @hidden */
  2044. constructor(loader: GLTFLoader);
  2045. /** @hidden */
  2046. dispose(): void;
  2047. /** @hidden */
  2048. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2049. }
  2050. }
  2051. declare module BABYLON.GLTF2.Loader.Extensions {
  2052. /**
  2053. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  2054. * !!! Experimental Extension Subject to Changes !!!
  2055. */
  2056. export class KHR_xmp implements IGLTFLoaderExtension {
  2057. /**
  2058. * The name of this extension.
  2059. */
  2060. readonly name: string;
  2061. /**
  2062. * Defines whether this extension is enabled.
  2063. */
  2064. enabled: boolean;
  2065. /**
  2066. * Defines a number that determines the order the extensions are applied.
  2067. */
  2068. order: number;
  2069. private _loader;
  2070. /** @hidden */
  2071. constructor(loader: GLTFLoader);
  2072. /** @hidden */
  2073. dispose(): void;
  2074. /**
  2075. * Called after the loader state changes to LOADING.
  2076. */
  2077. onLoading(): void;
  2078. }
  2079. }
  2080. declare module BABYLON.GLTF2.Loader.Extensions {
  2081. /**
  2082. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2083. */
  2084. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  2085. /**
  2086. * The name of this extension.
  2087. */
  2088. readonly name: string;
  2089. /**
  2090. * Defines whether this extension is enabled.
  2091. */
  2092. enabled: boolean;
  2093. private _loader;
  2094. private _clips;
  2095. private _emitters;
  2096. /** @hidden */
  2097. constructor(loader: GLTFLoader);
  2098. /** @hidden */
  2099. dispose(): void;
  2100. /** @hidden */
  2101. onLoading(): void;
  2102. /** @hidden */
  2103. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2104. /** @hidden */
  2105. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2106. /** @hidden */
  2107. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2108. private _loadClipAsync;
  2109. private _loadEmitterAsync;
  2110. private _getEventAction;
  2111. private _loadAnimationEventAsync;
  2112. }
  2113. }
  2114. declare module BABYLON.GLTF2.Loader.Extensions {
  2115. /**
  2116. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2117. */
  2118. export class MSFT_lod implements IGLTFLoaderExtension {
  2119. /**
  2120. * The name of this extension.
  2121. */
  2122. readonly name: string;
  2123. /**
  2124. * Defines whether this extension is enabled.
  2125. */
  2126. enabled: boolean;
  2127. /**
  2128. * Defines a number that determines the order the extensions are applied.
  2129. */
  2130. order: number;
  2131. /**
  2132. * Maximum number of LODs to load, starting from the lowest LOD.
  2133. */
  2134. maxLODsToLoad: number;
  2135. /**
  2136. * Observable raised when all node LODs of one level are loaded.
  2137. * The event data is the index of the loaded LOD starting from zero.
  2138. * Dispose the loader to cancel the loading of the next level of LODs.
  2139. */
  2140. onNodeLODsLoadedObservable: Observable<number>;
  2141. /**
  2142. * Observable raised when all material LODs of one level are loaded.
  2143. * The event data is the index of the loaded LOD starting from zero.
  2144. * Dispose the loader to cancel the loading of the next level of LODs.
  2145. */
  2146. onMaterialLODsLoadedObservable: Observable<number>;
  2147. private _loader;
  2148. private _bufferLODs;
  2149. private _nodeIndexLOD;
  2150. private _nodeSignalLODs;
  2151. private _nodePromiseLODs;
  2152. private _nodeBufferLODs;
  2153. private _materialIndexLOD;
  2154. private _materialSignalLODs;
  2155. private _materialPromiseLODs;
  2156. private _materialBufferLODs;
  2157. /** @hidden */
  2158. constructor(loader: GLTFLoader);
  2159. /** @hidden */
  2160. dispose(): void;
  2161. /** @hidden */
  2162. onReady(): void;
  2163. /** @hidden */
  2164. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2165. /** @hidden */
  2166. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2167. /** @hidden */
  2168. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2169. /** @hidden */
  2170. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2171. /** @hidden */
  2172. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2173. private _loadBufferLOD;
  2174. /**
  2175. * Gets an array of LOD properties from lowest to highest.
  2176. */
  2177. private _getLODs;
  2178. private _disposeTransformNode;
  2179. private _disposeMaterials;
  2180. }
  2181. }
  2182. declare module BABYLON.GLTF2.Loader.Extensions {
  2183. /** @hidden */
  2184. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2185. readonly name: string;
  2186. enabled: boolean;
  2187. private _loader;
  2188. constructor(loader: GLTFLoader);
  2189. dispose(): void;
  2190. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2191. }
  2192. }
  2193. declare module BABYLON.GLTF2.Loader.Extensions {
  2194. /** @hidden */
  2195. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2196. readonly name: string;
  2197. enabled: boolean;
  2198. private _loader;
  2199. constructor(loader: GLTFLoader);
  2200. dispose(): void;
  2201. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2202. }
  2203. }
  2204. declare module BABYLON.GLTF2.Loader.Extensions {
  2205. /**
  2206. * Store glTF extras (if present) in BJS objects' metadata
  2207. */
  2208. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2209. /**
  2210. * The name of this extension.
  2211. */
  2212. readonly name: string;
  2213. /**
  2214. * Defines whether this extension is enabled.
  2215. */
  2216. enabled: boolean;
  2217. private _loader;
  2218. private _assignExtras;
  2219. /** @hidden */
  2220. constructor(loader: GLTFLoader);
  2221. /** @hidden */
  2222. dispose(): void;
  2223. /** @hidden */
  2224. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2225. /** @hidden */
  2226. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2227. /** @hidden */
  2228. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2229. }
  2230. }
  2231. declare module BABYLON {
  2232. /**
  2233. * Class reading and parsing the MTL file bundled with the obj file.
  2234. */
  2235. export class MTLFileLoader {
  2236. /**
  2237. * Invert Y-Axis of referenced textures on load
  2238. */
  2239. static INVERT_TEXTURE_Y: boolean;
  2240. /**
  2241. * All material loaded from the mtl will be set here
  2242. */
  2243. materials: StandardMaterial[];
  2244. /**
  2245. * This function will read the mtl file and create each material described inside
  2246. * This function could be improve by adding :
  2247. * -some component missing (Ni, Tf...)
  2248. * -including the specific options available
  2249. *
  2250. * @param scene defines the scene the material will be created in
  2251. * @param data defines the mtl data to parse
  2252. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2253. * @param forAssetContainer defines if the material should be registered in the scene
  2254. */
  2255. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  2256. /**
  2257. * Gets the texture for the material.
  2258. *
  2259. * If the material is imported from input file,
  2260. * We sanitize the url to ensure it takes the textre from aside the material.
  2261. *
  2262. * @param rootUrl The root url to load from
  2263. * @param value The value stored in the mtl
  2264. * @return The Texture
  2265. */
  2266. private static _getTexture;
  2267. }
  2268. }
  2269. declare module BABYLON {
  2270. /**
  2271. * Options for loading OBJ/MTL files
  2272. */
  2273. type MeshLoadOptions = {
  2274. /**
  2275. * Defines if UVs are optimized by default during load.
  2276. */
  2277. OptimizeWithUV: boolean;
  2278. /**
  2279. * Defines custom scaling of UV coordinates of loaded meshes.
  2280. */
  2281. UVScaling: Vector2;
  2282. /**
  2283. * Invert model on y-axis (does a model scaling inversion)
  2284. */
  2285. InvertY: boolean;
  2286. /**
  2287. * Invert Y-Axis of referenced textures on load
  2288. */
  2289. InvertTextureY: boolean;
  2290. /**
  2291. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2292. */
  2293. ImportVertexColors: boolean;
  2294. /**
  2295. * Compute the normals for the model, even if normals are present in the file.
  2296. */
  2297. ComputeNormals: boolean;
  2298. /**
  2299. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2300. */
  2301. SkipMaterials: boolean;
  2302. /**
  2303. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2304. */
  2305. MaterialLoadingFailsSilently: boolean;
  2306. };
  2307. /**
  2308. * OBJ file type loader.
  2309. * This is a babylon scene loader plugin.
  2310. */
  2311. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2312. /**
  2313. * Defines if UVs are optimized by default during load.
  2314. */
  2315. static OPTIMIZE_WITH_UV: boolean;
  2316. /**
  2317. * Invert model on y-axis (does a model scaling inversion)
  2318. */
  2319. static INVERT_Y: boolean;
  2320. /**
  2321. * Invert Y-Axis of referenced textures on load
  2322. */
  2323. static get INVERT_TEXTURE_Y(): boolean;
  2324. static set INVERT_TEXTURE_Y(value: boolean);
  2325. /**
  2326. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2327. */
  2328. static IMPORT_VERTEX_COLORS: boolean;
  2329. /**
  2330. * Compute the normals for the model, even if normals are present in the file.
  2331. */
  2332. static COMPUTE_NORMALS: boolean;
  2333. /**
  2334. * Defines custom scaling of UV coordinates of loaded meshes.
  2335. */
  2336. static UV_SCALING: Vector2;
  2337. /**
  2338. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2339. */
  2340. static SKIP_MATERIALS: boolean;
  2341. /**
  2342. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2343. *
  2344. * Defaults to true for backwards compatibility.
  2345. */
  2346. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2347. /**
  2348. * Defines the name of the plugin.
  2349. */
  2350. name: string;
  2351. /**
  2352. * Defines the extension the plugin is able to load.
  2353. */
  2354. extensions: string;
  2355. /** @hidden */
  2356. obj: RegExp;
  2357. /** @hidden */
  2358. group: RegExp;
  2359. /** @hidden */
  2360. mtllib: RegExp;
  2361. /** @hidden */
  2362. usemtl: RegExp;
  2363. /** @hidden */
  2364. smooth: RegExp;
  2365. /** @hidden */
  2366. vertexPattern: RegExp;
  2367. /** @hidden */
  2368. normalPattern: RegExp;
  2369. /** @hidden */
  2370. uvPattern: RegExp;
  2371. /** @hidden */
  2372. facePattern1: RegExp;
  2373. /** @hidden */
  2374. facePattern2: RegExp;
  2375. /** @hidden */
  2376. facePattern3: RegExp;
  2377. /** @hidden */
  2378. facePattern4: RegExp;
  2379. /** @hidden */
  2380. facePattern5: RegExp;
  2381. private _forAssetContainer;
  2382. private _meshLoadOptions;
  2383. /**
  2384. * Creates loader for .OBJ files
  2385. *
  2386. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2387. */
  2388. constructor(meshLoadOptions?: MeshLoadOptions);
  2389. private static get currentMeshLoadOptions();
  2390. /**
  2391. * Calls synchronously the MTL file attached to this obj.
  2392. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2393. * Without this function materials are not displayed in the first frame (but displayed after).
  2394. * In consequence it is impossible to get material information in your HTML file
  2395. *
  2396. * @param url The URL of the MTL file
  2397. * @param rootUrl
  2398. * @param onSuccess Callback function to be called when the MTL file is loaded
  2399. * @private
  2400. */
  2401. private _loadMTL;
  2402. /**
  2403. * Instantiates a OBJ file loader plugin.
  2404. * @returns the created plugin
  2405. */
  2406. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2407. /**
  2408. * If the data string can be loaded directly.
  2409. *
  2410. * @param data string containing the file data
  2411. * @returns if the data can be loaded directly
  2412. */
  2413. canDirectLoad(data: string): boolean;
  2414. /**
  2415. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2416. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2417. * @param scene the scene the meshes should be added to
  2418. * @param data the OBJ data to load
  2419. * @param rootUrl root url to load from
  2420. * @param onProgress event that fires when loading progress has occured
  2421. * @param fileName Defines the name of the file to load
  2422. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2423. */
  2424. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2425. meshes: AbstractMesh[];
  2426. particleSystems: IParticleSystem[];
  2427. skeletons: Skeleton[];
  2428. animationGroups: AnimationGroup[];
  2429. }>;
  2430. /**
  2431. * Imports all objects from the loaded OBJ data and adds them to the scene
  2432. * @param scene the scene the objects should be added to
  2433. * @param data the OBJ data to load
  2434. * @param rootUrl root url to load from
  2435. * @param onProgress event that fires when loading progress has occured
  2436. * @param fileName Defines the name of the file to load
  2437. * @returns a promise which completes when objects have been loaded to the scene
  2438. */
  2439. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2440. /**
  2441. * Load into an asset container.
  2442. * @param scene The scene to load into
  2443. * @param data The data to import
  2444. * @param rootUrl The root url for scene and resources
  2445. * @param onProgress The callback when the load progresses
  2446. * @param fileName Defines the name of the file to load
  2447. * @returns The loaded asset container
  2448. */
  2449. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2450. /**
  2451. * Read the OBJ file and create an Array of meshes.
  2452. * Each mesh contains all information given by the OBJ and the MTL file.
  2453. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2454. *
  2455. * @param meshesNames
  2456. * @param scene Scene The scene where are displayed the data
  2457. * @param data String The content of the obj file
  2458. * @param rootUrl String The path to the folder
  2459. * @returns Array<AbstractMesh>
  2460. * @private
  2461. */
  2462. private _parseSolid;
  2463. }
  2464. }
  2465. declare module BABYLON {
  2466. /**
  2467. * STL file type loader.
  2468. * This is a babylon scene loader plugin.
  2469. */
  2470. export class STLFileLoader implements ISceneLoaderPlugin {
  2471. /** @hidden */
  2472. solidPattern: RegExp;
  2473. /** @hidden */
  2474. facetsPattern: RegExp;
  2475. /** @hidden */
  2476. normalPattern: RegExp;
  2477. /** @hidden */
  2478. vertexPattern: RegExp;
  2479. /**
  2480. * Defines the name of the plugin.
  2481. */
  2482. name: string;
  2483. /**
  2484. * Defines the extensions the stl loader is able to load.
  2485. * force data to come in as an ArrayBuffer
  2486. * we'll convert to string if it looks like it's an ASCII .stl
  2487. */
  2488. extensions: ISceneLoaderPluginExtensions;
  2489. /**
  2490. * Import meshes into a scene.
  2491. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2492. * @param scene The scene to import into
  2493. * @param data The data to import
  2494. * @param rootUrl The root url for scene and resources
  2495. * @param meshes The meshes array to import into
  2496. * @param particleSystems The particle systems array to import into
  2497. * @param skeletons The skeletons array to import into
  2498. * @param onError The callback when import fails
  2499. * @returns True if successful or false otherwise
  2500. */
  2501. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2502. /**
  2503. * Load into a scene.
  2504. * @param scene The scene to load into
  2505. * @param data The data to import
  2506. * @param rootUrl The root url for scene and resources
  2507. * @param onError The callback when import fails
  2508. * @returns true if successful or false otherwise
  2509. */
  2510. load(scene: Scene, data: any, rootUrl: string): boolean;
  2511. /**
  2512. * Load into an asset container.
  2513. * @param scene The scene to load into
  2514. * @param data The data to import
  2515. * @param rootUrl The root url for scene and resources
  2516. * @param onError The callback when import fails
  2517. * @returns The loaded asset container
  2518. */
  2519. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2520. private _isBinary;
  2521. private _parseBinary;
  2522. private _parseASCII;
  2523. }
  2524. }