babylonjs.loaders.d.ts 104 KB

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