babylonjs.loaders.d.ts 101 KB

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