babylonjs.loaders.d.ts 92 KB

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