babylonjs.loaders.d.ts 97 KB

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