babylonjs.loaders.d.ts 101 KB

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