babylonjs.loaders.d.ts 103 KB

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