babylonjs.loaders.module.d.ts 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818
  1. declare module "babylonjs-loaders/glTF/glTFFileLoader" {
  2. import * as GLTF2 from "babylonjs-gltf2interface";
  3. import { Nullable } from "babylonjs/types";
  4. import { Observable } from "babylonjs/Misc/observable";
  5. import { Camera } from "babylonjs/Cameras/camera";
  6. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  7. import { Skeleton } from "babylonjs/Bones/skeleton";
  8. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  9. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  10. import { Material } from "babylonjs/Materials/material";
  11. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  12. import { ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  13. import { AssetContainer } from "babylonjs/assetContainer";
  14. import { Scene, IDisposable } from "babylonjs/scene";
  15. import { WebRequest } from "babylonjs/Misc/webRequest";
  16. import { IFileRequest } from "babylonjs/Misc/fileRequest";
  17. import { IDataBuffer } from 'babylonjs/Misc/dataReader';
  18. /**
  19. * Mode that determines the coordinate system to use.
  20. */
  21. export enum GLTFLoaderCoordinateSystemMode {
  22. /**
  23. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  24. */
  25. AUTO = 0,
  26. /**
  27. * Sets the useRightHandedSystem flag on the scene.
  28. */
  29. FORCE_RIGHT_HANDED = 1
  30. }
  31. /**
  32. * Mode that determines what animations will start.
  33. */
  34. export enum GLTFLoaderAnimationStartMode {
  35. /**
  36. * No animation will start.
  37. */
  38. NONE = 0,
  39. /**
  40. * The first animation will start.
  41. */
  42. FIRST = 1,
  43. /**
  44. * All animations will start.
  45. */
  46. ALL = 2
  47. }
  48. /**
  49. * Interface that contains the data for the glTF asset.
  50. */
  51. export interface IGLTFLoaderData {
  52. /**
  53. * The object that represents the glTF JSON.
  54. */
  55. json: Object;
  56. /**
  57. * The BIN chunk of a binary glTF.
  58. */
  59. bin: Nullable<IDataBuffer>;
  60. }
  61. /**
  62. * Interface for extending the loader.
  63. */
  64. export interface IGLTFLoaderExtension {
  65. /**
  66. * The name of this extension.
  67. */
  68. readonly name: string;
  69. /**
  70. * Defines whether this extension is enabled.
  71. */
  72. enabled: boolean;
  73. /**
  74. * Defines the order of this extension.
  75. * The loader sorts the extensions using these values when loading.
  76. */
  77. order?: number;
  78. }
  79. /**
  80. * Loader state.
  81. */
  82. export enum GLTFLoaderState {
  83. /**
  84. * The asset is loading.
  85. */
  86. LOADING = 0,
  87. /**
  88. * The asset is ready for rendering.
  89. */
  90. READY = 1,
  91. /**
  92. * The asset is completely loaded.
  93. */
  94. COMPLETE = 2
  95. }
  96. /** @hidden */
  97. export interface IGLTFLoader extends IDisposable {
  98. readonly state: Nullable<GLTFLoaderState>;
  99. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  100. meshes: AbstractMesh[];
  101. particleSystems: IParticleSystem[];
  102. skeletons: Skeleton[];
  103. animationGroups: AnimationGroup[];
  104. }>;
  105. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  106. }
  107. /**
  108. * File loader for loading glTF files into a scene.
  109. */
  110. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  111. /** @hidden */
  112. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  113. /** @hidden */
  114. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  115. /**
  116. * Raised when the asset has been parsed
  117. */
  118. onParsedObservable: Observable<IGLTFLoaderData>;
  119. private _onParsedObserver;
  120. /**
  121. * Raised when the asset has been parsed
  122. */
  123. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  124. /**
  125. * 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.
  126. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  127. * Defaults to true.
  128. * @hidden
  129. */
  130. static IncrementalLoading: boolean;
  131. /**
  132. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  133. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  134. * @hidden
  135. */
  136. static HomogeneousCoordinates: boolean;
  137. /**
  138. * The coordinate system mode. Defaults to AUTO.
  139. */
  140. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  141. /**
  142. * The animation start mode. Defaults to FIRST.
  143. */
  144. animationStartMode: GLTFLoaderAnimationStartMode;
  145. /**
  146. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  147. */
  148. compileMaterials: boolean;
  149. /**
  150. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  151. */
  152. useClipPlane: boolean;
  153. /**
  154. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  155. */
  156. compileShadowGenerators: boolean;
  157. /**
  158. * Defines if the Alpha blended materials are only applied as coverage.
  159. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  160. * If true, no extra effects are applied to transparent pixels.
  161. */
  162. transparencyAsCoverage: boolean;
  163. /**
  164. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  165. * Enabling will disable offline support and glTF validator.
  166. * Defaults to false.
  167. */
  168. useRangeRequests: boolean;
  169. /**
  170. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  171. */
  172. createInstances: boolean;
  173. /**
  174. * Function called before loading a url referenced by the asset.
  175. */
  176. preprocessUrlAsync: (url: string) => Promise<string>;
  177. /**
  178. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  179. */
  180. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  181. private _onMeshLoadedObserver;
  182. /**
  183. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  184. */
  185. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  186. /**
  187. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  188. */
  189. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  190. private _onTextureLoadedObserver;
  191. /**
  192. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  193. */
  194. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  195. /**
  196. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  197. */
  198. readonly onMaterialLoadedObservable: Observable<Material>;
  199. private _onMaterialLoadedObserver;
  200. /**
  201. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  202. */
  203. set onMaterialLoaded(callback: (material: Material) => void);
  204. /**
  205. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  206. */
  207. readonly onCameraLoadedObservable: Observable<Camera>;
  208. private _onCameraLoadedObserver;
  209. /**
  210. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  211. */
  212. set onCameraLoaded(callback: (camera: Camera) => void);
  213. /**
  214. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  215. * For assets with LODs, raised when all of the LODs are complete.
  216. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  217. */
  218. readonly onCompleteObservable: Observable<void>;
  219. private _onCompleteObserver;
  220. /**
  221. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  222. * For assets with LODs, raised when all of the LODs are complete.
  223. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  224. */
  225. set onComplete(callback: () => void);
  226. /**
  227. * Observable raised when an error occurs.
  228. */
  229. readonly onErrorObservable: Observable<any>;
  230. private _onErrorObserver;
  231. /**
  232. * Callback raised when an error occurs.
  233. */
  234. set onError(callback: (reason: any) => void);
  235. /**
  236. * Observable raised after the loader is disposed.
  237. */
  238. readonly onDisposeObservable: Observable<void>;
  239. private _onDisposeObserver;
  240. /**
  241. * Callback raised after the loader is disposed.
  242. */
  243. set onDispose(callback: () => void);
  244. /**
  245. * Observable raised after a loader extension is created.
  246. * Set additional options for a loader extension in this event.
  247. */
  248. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  249. private _onExtensionLoadedObserver;
  250. /**
  251. * Callback raised after a loader extension is created.
  252. */
  253. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  254. /**
  255. * Defines if the loader logging is enabled.
  256. */
  257. get loggingEnabled(): boolean;
  258. set loggingEnabled(value: boolean);
  259. /**
  260. * Defines if the loader should capture performance counters.
  261. */
  262. get capturePerformanceCounters(): boolean;
  263. set capturePerformanceCounters(value: boolean);
  264. /**
  265. * Defines if the loader should validate the asset.
  266. */
  267. validate: boolean;
  268. /**
  269. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  270. */
  271. readonly onValidatedObservable: Observable<GLTF2.IGLTFValidationResults>;
  272. private _onValidatedObserver;
  273. /**
  274. * Callback raised after a loader extension is created.
  275. */
  276. set onValidated(callback: (results: GLTF2.IGLTFValidationResults) => void);
  277. private _loader;
  278. /**
  279. * Name of the loader ("gltf")
  280. */
  281. name: string;
  282. /** @hidden */
  283. extensions: ISceneLoaderPluginExtensions;
  284. /**
  285. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  286. */
  287. dispose(): void;
  288. /** @hidden */
  289. _clear(): void;
  290. /** @hidden */
  291. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  292. /** @hidden */
  293. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  294. /** @hidden */
  295. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  296. meshes: AbstractMesh[];
  297. particleSystems: IParticleSystem[];
  298. skeletons: Skeleton[];
  299. animationGroups: AnimationGroup[];
  300. }>;
  301. /** @hidden */
  302. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  303. /** @hidden */
  304. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  305. /** @hidden */
  306. canDirectLoad(data: string): boolean;
  307. /** @hidden */
  308. directLoad(scene: Scene, data: string): any;
  309. /**
  310. * The callback that allows custom handling of the root url based on the response url.
  311. * @param rootUrl the original root url
  312. * @param responseURL the response url if available
  313. * @returns the new root url
  314. */
  315. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  316. /** @hidden */
  317. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  318. /**
  319. * The loader state or null if the loader is not active.
  320. */
  321. get loaderState(): Nullable<GLTFLoaderState>;
  322. /**
  323. * Returns a promise that resolves when the asset is completely loaded.
  324. * @returns a promise that resolves when the asset is completely loaded.
  325. */
  326. whenCompleteAsync(): Promise<void>;
  327. private _validateAsync;
  328. private _getLoader;
  329. private _parseJson;
  330. private _unpackBinaryAsync;
  331. private _unpackBinaryV1Async;
  332. private _unpackBinaryV2Async;
  333. private static _parseVersion;
  334. private static _compareVersion;
  335. private static readonly _logSpaces;
  336. private _logIndentLevel;
  337. private _loggingEnabled;
  338. /** @hidden */
  339. _log: (message: string) => void;
  340. /** @hidden */
  341. _logOpen(message: string): void;
  342. /** @hidden */
  343. _logClose(): void;
  344. private _logEnabled;
  345. private _logDisabled;
  346. private _capturePerformanceCounters;
  347. /** @hidden */
  348. _startPerformanceCounter: (counterName: string) => void;
  349. /** @hidden */
  350. _endPerformanceCounter: (counterName: string) => void;
  351. private _startPerformanceCounterEnabled;
  352. private _startPerformanceCounterDisabled;
  353. private _endPerformanceCounterEnabled;
  354. private _endPerformanceCounterDisabled;
  355. }
  356. }
  357. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces" {
  358. import { Bone } from "babylonjs/Bones/bone";
  359. import { Skeleton } from "babylonjs/Bones/skeleton";
  360. import { Texture } from "babylonjs/Materials/Textures/texture";
  361. import { Node } from "babylonjs/node";
  362. import { Scene } from "babylonjs/scene";
  363. /**
  364. * Enums
  365. * @hidden
  366. */
  367. export enum EComponentType {
  368. BYTE = 5120,
  369. UNSIGNED_BYTE = 5121,
  370. SHORT = 5122,
  371. UNSIGNED_SHORT = 5123,
  372. FLOAT = 5126
  373. }
  374. /** @hidden */
  375. export enum EShaderType {
  376. FRAGMENT = 35632,
  377. VERTEX = 35633
  378. }
  379. /** @hidden */
  380. export enum EParameterType {
  381. BYTE = 5120,
  382. UNSIGNED_BYTE = 5121,
  383. SHORT = 5122,
  384. UNSIGNED_SHORT = 5123,
  385. INT = 5124,
  386. UNSIGNED_INT = 5125,
  387. FLOAT = 5126,
  388. FLOAT_VEC2 = 35664,
  389. FLOAT_VEC3 = 35665,
  390. FLOAT_VEC4 = 35666,
  391. INT_VEC2 = 35667,
  392. INT_VEC3 = 35668,
  393. INT_VEC4 = 35669,
  394. BOOL = 35670,
  395. BOOL_VEC2 = 35671,
  396. BOOL_VEC3 = 35672,
  397. BOOL_VEC4 = 35673,
  398. FLOAT_MAT2 = 35674,
  399. FLOAT_MAT3 = 35675,
  400. FLOAT_MAT4 = 35676,
  401. SAMPLER_2D = 35678
  402. }
  403. /** @hidden */
  404. export enum ETextureWrapMode {
  405. CLAMP_TO_EDGE = 33071,
  406. MIRRORED_REPEAT = 33648,
  407. REPEAT = 10497
  408. }
  409. /** @hidden */
  410. export enum ETextureFilterType {
  411. NEAREST = 9728,
  412. LINEAR = 9728,
  413. NEAREST_MIPMAP_NEAREST = 9984,
  414. LINEAR_MIPMAP_NEAREST = 9985,
  415. NEAREST_MIPMAP_LINEAR = 9986,
  416. LINEAR_MIPMAP_LINEAR = 9987
  417. }
  418. /** @hidden */
  419. export enum ETextureFormat {
  420. ALPHA = 6406,
  421. RGB = 6407,
  422. RGBA = 6408,
  423. LUMINANCE = 6409,
  424. LUMINANCE_ALPHA = 6410
  425. }
  426. /** @hidden */
  427. export enum ECullingType {
  428. FRONT = 1028,
  429. BACK = 1029,
  430. FRONT_AND_BACK = 1032
  431. }
  432. /** @hidden */
  433. export enum EBlendingFunction {
  434. ZERO = 0,
  435. ONE = 1,
  436. SRC_COLOR = 768,
  437. ONE_MINUS_SRC_COLOR = 769,
  438. DST_COLOR = 774,
  439. ONE_MINUS_DST_COLOR = 775,
  440. SRC_ALPHA = 770,
  441. ONE_MINUS_SRC_ALPHA = 771,
  442. DST_ALPHA = 772,
  443. ONE_MINUS_DST_ALPHA = 773,
  444. CONSTANT_COLOR = 32769,
  445. ONE_MINUS_CONSTANT_COLOR = 32770,
  446. CONSTANT_ALPHA = 32771,
  447. ONE_MINUS_CONSTANT_ALPHA = 32772,
  448. SRC_ALPHA_SATURATE = 776
  449. }
  450. /** @hidden */
  451. export interface IGLTFProperty {
  452. extensions?: {
  453. [key: string]: any;
  454. };
  455. extras?: Object;
  456. }
  457. /** @hidden */
  458. export interface IGLTFChildRootProperty extends IGLTFProperty {
  459. name?: string;
  460. }
  461. /** @hidden */
  462. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  463. bufferView: string;
  464. byteOffset: number;
  465. byteStride: number;
  466. count: number;
  467. type: string;
  468. componentType: EComponentType;
  469. max?: number[];
  470. min?: number[];
  471. name?: string;
  472. }
  473. /** @hidden */
  474. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  475. buffer: string;
  476. byteOffset: number;
  477. byteLength: number;
  478. byteStride: number;
  479. target?: number;
  480. }
  481. /** @hidden */
  482. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  483. uri: string;
  484. byteLength?: number;
  485. type?: string;
  486. }
  487. /** @hidden */
  488. export interface IGLTFShader extends IGLTFChildRootProperty {
  489. uri: string;
  490. type: EShaderType;
  491. }
  492. /** @hidden */
  493. export interface IGLTFProgram extends IGLTFChildRootProperty {
  494. attributes: string[];
  495. fragmentShader: string;
  496. vertexShader: string;
  497. }
  498. /** @hidden */
  499. export interface IGLTFTechniqueParameter {
  500. type: number;
  501. count?: number;
  502. semantic?: string;
  503. node?: string;
  504. value?: number | boolean | string | Array<any>;
  505. source?: string;
  506. babylonValue?: any;
  507. }
  508. /** @hidden */
  509. export interface IGLTFTechniqueCommonProfile {
  510. lightingModel: string;
  511. texcoordBindings: Object;
  512. parameters?: Array<any>;
  513. }
  514. /** @hidden */
  515. export interface IGLTFTechniqueStatesFunctions {
  516. blendColor?: number[];
  517. blendEquationSeparate?: number[];
  518. blendFuncSeparate?: number[];
  519. colorMask: boolean[];
  520. cullFace: number[];
  521. }
  522. /** @hidden */
  523. export interface IGLTFTechniqueStates {
  524. enable: number[];
  525. functions: IGLTFTechniqueStatesFunctions;
  526. }
  527. /** @hidden */
  528. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  529. parameters: {
  530. [key: string]: IGLTFTechniqueParameter;
  531. };
  532. program: string;
  533. attributes: {
  534. [key: string]: string;
  535. };
  536. uniforms: {
  537. [key: string]: string;
  538. };
  539. states: IGLTFTechniqueStates;
  540. }
  541. /** @hidden */
  542. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  543. technique?: string;
  544. values: string[];
  545. }
  546. /** @hidden */
  547. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  548. attributes: {
  549. [key: string]: string;
  550. };
  551. indices: string;
  552. material: string;
  553. mode?: number;
  554. }
  555. /** @hidden */
  556. export interface IGLTFMesh extends IGLTFChildRootProperty {
  557. primitives: IGLTFMeshPrimitive[];
  558. }
  559. /** @hidden */
  560. export interface IGLTFImage extends IGLTFChildRootProperty {
  561. uri: string;
  562. }
  563. /** @hidden */
  564. export interface IGLTFSampler extends IGLTFChildRootProperty {
  565. magFilter?: number;
  566. minFilter?: number;
  567. wrapS?: number;
  568. wrapT?: number;
  569. }
  570. /** @hidden */
  571. export interface IGLTFTexture extends IGLTFChildRootProperty {
  572. sampler: string;
  573. source: string;
  574. format?: ETextureFormat;
  575. internalFormat?: ETextureFormat;
  576. target?: number;
  577. type?: number;
  578. babylonTexture?: Texture;
  579. }
  580. /** @hidden */
  581. export interface IGLTFAmbienLight {
  582. color?: number[];
  583. }
  584. /** @hidden */
  585. export interface IGLTFDirectionalLight {
  586. color?: number[];
  587. }
  588. /** @hidden */
  589. export interface IGLTFPointLight {
  590. color?: number[];
  591. constantAttenuation?: number;
  592. linearAttenuation?: number;
  593. quadraticAttenuation?: number;
  594. }
  595. /** @hidden */
  596. export interface IGLTFSpotLight {
  597. color?: number[];
  598. constantAttenuation?: number;
  599. fallOfAngle?: number;
  600. fallOffExponent?: number;
  601. linearAttenuation?: number;
  602. quadraticAttenuation?: number;
  603. }
  604. /** @hidden */
  605. export interface IGLTFLight extends IGLTFChildRootProperty {
  606. type: string;
  607. }
  608. /** @hidden */
  609. export interface IGLTFCameraOrthographic {
  610. xmag: number;
  611. ymag: number;
  612. zfar: number;
  613. znear: number;
  614. }
  615. /** @hidden */
  616. export interface IGLTFCameraPerspective {
  617. aspectRatio: number;
  618. yfov: number;
  619. zfar: number;
  620. znear: number;
  621. }
  622. /** @hidden */
  623. export interface IGLTFCamera extends IGLTFChildRootProperty {
  624. type: string;
  625. }
  626. /** @hidden */
  627. export interface IGLTFAnimationChannelTarget {
  628. id: string;
  629. path: string;
  630. }
  631. /** @hidden */
  632. export interface IGLTFAnimationChannel {
  633. sampler: string;
  634. target: IGLTFAnimationChannelTarget;
  635. }
  636. /** @hidden */
  637. export interface IGLTFAnimationSampler {
  638. input: string;
  639. output: string;
  640. interpolation?: string;
  641. }
  642. /** @hidden */
  643. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  644. channels?: IGLTFAnimationChannel[];
  645. parameters?: {
  646. [key: string]: string;
  647. };
  648. samplers?: {
  649. [key: string]: IGLTFAnimationSampler;
  650. };
  651. }
  652. /** @hidden */
  653. export interface IGLTFNodeInstanceSkin {
  654. skeletons: string[];
  655. skin: string;
  656. meshes: string[];
  657. }
  658. /** @hidden */
  659. export interface IGLTFSkins extends IGLTFChildRootProperty {
  660. bindShapeMatrix: number[];
  661. inverseBindMatrices: string;
  662. jointNames: string[];
  663. babylonSkeleton?: Skeleton;
  664. }
  665. /** @hidden */
  666. export interface IGLTFNode extends IGLTFChildRootProperty {
  667. camera?: string;
  668. children: string[];
  669. skin?: string;
  670. jointName?: string;
  671. light?: string;
  672. matrix: number[];
  673. mesh?: string;
  674. meshes?: string[];
  675. rotation?: number[];
  676. scale?: number[];
  677. translation?: number[];
  678. babylonNode?: Node;
  679. }
  680. /** @hidden */
  681. export interface IGLTFScene extends IGLTFChildRootProperty {
  682. nodes: string[];
  683. }
  684. /** @hidden */
  685. export interface IGLTFRuntime {
  686. extensions: {
  687. [key: string]: any;
  688. };
  689. accessors: {
  690. [key: string]: IGLTFAccessor;
  691. };
  692. buffers: {
  693. [key: string]: IGLTFBuffer;
  694. };
  695. bufferViews: {
  696. [key: string]: IGLTFBufferView;
  697. };
  698. meshes: {
  699. [key: string]: IGLTFMesh;
  700. };
  701. lights: {
  702. [key: string]: IGLTFLight;
  703. };
  704. cameras: {
  705. [key: string]: IGLTFCamera;
  706. };
  707. nodes: {
  708. [key: string]: IGLTFNode;
  709. };
  710. images: {
  711. [key: string]: IGLTFImage;
  712. };
  713. textures: {
  714. [key: string]: IGLTFTexture;
  715. };
  716. shaders: {
  717. [key: string]: IGLTFShader;
  718. };
  719. programs: {
  720. [key: string]: IGLTFProgram;
  721. };
  722. samplers: {
  723. [key: string]: IGLTFSampler;
  724. };
  725. techniques: {
  726. [key: string]: IGLTFTechnique;
  727. };
  728. materials: {
  729. [key: string]: IGLTFMaterial;
  730. };
  731. animations: {
  732. [key: string]: IGLTFAnimation;
  733. };
  734. skins: {
  735. [key: string]: IGLTFSkins;
  736. };
  737. currentScene?: Object;
  738. scenes: {
  739. [key: string]: IGLTFScene;
  740. };
  741. extensionsUsed: string[];
  742. extensionsRequired?: string[];
  743. buffersCount: number;
  744. shaderscount: number;
  745. scene: Scene;
  746. rootUrl: string;
  747. loadedBufferCount: number;
  748. loadedBufferViews: {
  749. [name: string]: ArrayBufferView;
  750. };
  751. loadedShaderCount: number;
  752. importOnlyMeshes: boolean;
  753. importMeshesNames?: string[];
  754. dummyNodes: Node[];
  755. }
  756. /** @hidden */
  757. export interface INodeToRoot {
  758. bone: Bone;
  759. node: IGLTFNode;
  760. id: string;
  761. }
  762. /** @hidden */
  763. export interface IJointNode {
  764. node: IGLTFNode;
  765. id: string;
  766. }
  767. }
  768. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderUtils" {
  769. import { IGLTFTechniqueParameter, IGLTFAccessor, ETextureFilterType, IGLTFRuntime, IGLTFBufferView, EComponentType } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  770. import { Effect } from "babylonjs/Materials/effect";
  771. import { ShaderMaterial } from "babylonjs/Materials/shaderMaterial";
  772. import { Node } from "babylonjs/node";
  773. import { Scene } from "babylonjs/scene";
  774. /**
  775. * Utils functions for GLTF
  776. * @hidden
  777. */
  778. export class GLTFUtils {
  779. /**
  780. * Sets the given "parameter" matrix
  781. * @param scene: the Scene object
  782. * @param source: the source node where to pick the matrix
  783. * @param parameter: the GLTF technique parameter
  784. * @param uniformName: the name of the shader's uniform
  785. * @param shaderMaterial: the shader material
  786. */
  787. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  788. /**
  789. * Sets the given "parameter" matrix
  790. * @param shaderMaterial: the shader material
  791. * @param uniform: the name of the shader's uniform
  792. * @param value: the value of the uniform
  793. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  794. */
  795. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  796. /**
  797. * Returns the wrap mode of the texture
  798. * @param mode: the mode value
  799. */
  800. static GetWrapMode(mode: number): number;
  801. /**
  802. * Returns the byte stride giving an accessor
  803. * @param accessor: the GLTF accessor objet
  804. */
  805. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  806. /**
  807. * Returns the texture filter mode giving a mode value
  808. * @param mode: the filter mode value
  809. */
  810. static GetTextureFilterMode(mode: number): ETextureFilterType;
  811. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  812. /**
  813. * Returns a buffer from its accessor
  814. * @param gltfRuntime: the GLTF runtime
  815. * @param accessor: the GLTF accessor
  816. */
  817. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  818. /**
  819. * Decodes a buffer view into a string
  820. * @param view: the buffer view
  821. */
  822. static DecodeBufferToText(view: ArrayBufferView): string;
  823. /**
  824. * Returns the default material of gltf. Related to
  825. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  826. * @param scene: the Babylon.js scene
  827. */
  828. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  829. private static _DefaultMaterial;
  830. }
  831. }
  832. declare module "babylonjs-loaders/glTF/1.0/glTFLoader" {
  833. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  834. import { Nullable } from "babylonjs/types";
  835. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  836. import { Skeleton } from "babylonjs/Bones/skeleton";
  837. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  838. import { Material } from "babylonjs/Materials/material";
  839. import { Texture } from "babylonjs/Materials/Textures/texture";
  840. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  841. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  842. import { Scene } from "babylonjs/scene";
  843. import { IGLTFLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  844. /**
  845. * Implementation of the base glTF spec
  846. * @hidden
  847. */
  848. export class GLTFLoaderBase {
  849. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  850. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  851. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  852. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  853. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  854. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  855. }
  856. /**
  857. * glTF V1 Loader
  858. * @hidden
  859. */
  860. export class GLTFLoader implements IGLTFLoader {
  861. static Extensions: {
  862. [name: string]: GLTFLoaderExtension;
  863. };
  864. static RegisterExtension(extension: GLTFLoaderExtension): void;
  865. state: Nullable<GLTFLoaderState>;
  866. dispose(): void;
  867. private _importMeshAsync;
  868. /**
  869. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  870. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  871. * @param scene the scene the meshes should be added to
  872. * @param data gltf data containing information of the meshes in a loaded file
  873. * @param rootUrl root url to load from
  874. * @param onProgress event that fires when loading progress has occured
  875. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  876. */
  877. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  878. meshes: AbstractMesh[];
  879. particleSystems: IParticleSystem[];
  880. skeletons: Skeleton[];
  881. animationGroups: AnimationGroup[];
  882. }>;
  883. private _loadAsync;
  884. /**
  885. * Imports all objects from a loaded gltf file and adds them to the scene
  886. * @param scene the scene the objects should be added to
  887. * @param data gltf data containing information of the meshes in a loaded file
  888. * @param rootUrl root url to load from
  889. * @param onProgress event that fires when loading progress has occured
  890. * @returns a promise which completes when objects have been loaded to the scene
  891. */
  892. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  893. private _loadShadersAsync;
  894. private _loadBuffersAsync;
  895. private _createNodes;
  896. }
  897. /** @hidden */
  898. export abstract class GLTFLoaderExtension {
  899. private _name;
  900. constructor(name: string);
  901. get name(): string;
  902. /**
  903. * Defines an override for loading the runtime
  904. * Return true to stop further extensions from loading the runtime
  905. */
  906. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  907. /**
  908. * Defines an onverride for creating gltf runtime
  909. * Return true to stop further extensions from creating the runtime
  910. */
  911. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  912. /**
  913. * Defines an override for loading buffers
  914. * Return true to stop further extensions from loading this buffer
  915. */
  916. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  917. /**
  918. * Defines an override for loading texture buffers
  919. * Return true to stop further extensions from loading this texture data
  920. */
  921. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  922. /**
  923. * Defines an override for creating textures
  924. * Return true to stop further extensions from loading this texture
  925. */
  926. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  927. /**
  928. * Defines an override for loading shader strings
  929. * Return true to stop further extensions from loading this shader data
  930. */
  931. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  932. /**
  933. * Defines an override for loading materials
  934. * Return true to stop further extensions from loading this material
  935. */
  936. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  937. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  938. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  939. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  940. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  941. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  942. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  943. private static LoadTextureBufferAsync;
  944. private static CreateTextureAsync;
  945. private static ApplyExtensions;
  946. }
  947. }
  948. declare module "babylonjs-loaders/glTF/1.0/glTFBinaryExtension" {
  949. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  950. import { Scene } from "babylonjs/scene";
  951. import { IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  952. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  953. /** @hidden */
  954. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  955. private _bin;
  956. constructor();
  957. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  958. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  959. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  960. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  961. }
  962. }
  963. declare module "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension" {
  964. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  965. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  966. import { Material } from "babylonjs/Materials/material";
  967. /** @hidden */
  968. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  969. constructor();
  970. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  971. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  972. private _loadTexture;
  973. }
  974. }
  975. declare module "babylonjs-loaders/glTF/1.0/index" {
  976. export * from "babylonjs-loaders/glTF/1.0/glTFBinaryExtension";
  977. export * from "babylonjs-loaders/glTF/1.0/glTFLoader";
  978. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  979. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderUtils";
  980. export * from "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension";
  981. }
  982. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces" {
  983. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  984. import { Bone } from "babylonjs/Bones/bone";
  985. import { Skeleton } from "babylonjs/Bones/skeleton";
  986. import { Material } from "babylonjs/Materials/material";
  987. import { TransformNode } from "babylonjs/Meshes/transformNode";
  988. import { Buffer, VertexBuffer } from "babylonjs/Meshes/buffer";
  989. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  990. import { Mesh } from "babylonjs/Meshes/mesh";
  991. import * as GLTF2 from "babylonjs-gltf2interface";
  992. /**
  993. * Loader interface with an index field.
  994. */
  995. export interface IArrayItem {
  996. /**
  997. * The index of this item in the array.
  998. */
  999. index: number;
  1000. }
  1001. /**
  1002. * Loader interface with additional members.
  1003. */
  1004. export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
  1005. /** @hidden */
  1006. _data?: Promise<ArrayBufferView>;
  1007. /** @hidden */
  1008. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1009. }
  1010. /**
  1011. * Loader interface with additional members.
  1012. */
  1013. export interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
  1014. }
  1015. /** @hidden */
  1016. export interface _IAnimationSamplerData {
  1017. input: Float32Array;
  1018. interpolation: GLTF2.AnimationSamplerInterpolation;
  1019. output: Float32Array;
  1020. }
  1021. /**
  1022. * Loader interface with additional members.
  1023. */
  1024. export interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
  1025. /** @hidden */
  1026. _data?: Promise<_IAnimationSamplerData>;
  1027. }
  1028. /**
  1029. * Loader interface with additional members.
  1030. */
  1031. export interface IAnimation extends GLTF2.IAnimation, IArrayItem {
  1032. channels: IAnimationChannel[];
  1033. samplers: IAnimationSampler[];
  1034. /** @hidden */
  1035. _babylonAnimationGroup?: AnimationGroup;
  1036. }
  1037. /**
  1038. * Loader interface with additional members.
  1039. */
  1040. export interface IBuffer extends GLTF2.IBuffer, IArrayItem {
  1041. /** @hidden */
  1042. _data?: Promise<ArrayBufferView>;
  1043. }
  1044. /**
  1045. * Loader interface with additional members.
  1046. */
  1047. export interface IBufferView extends GLTF2.IBufferView, IArrayItem {
  1048. /** @hidden */
  1049. _data?: Promise<ArrayBufferView>;
  1050. /** @hidden */
  1051. _babylonBuffer?: Promise<Buffer>;
  1052. }
  1053. /**
  1054. * Loader interface with additional members.
  1055. */
  1056. export interface ICamera extends GLTF2.ICamera, IArrayItem {
  1057. }
  1058. /**
  1059. * Loader interface with additional members.
  1060. */
  1061. export interface IImage extends GLTF2.IImage, IArrayItem {
  1062. /** @hidden */
  1063. _data?: Promise<ArrayBufferView>;
  1064. }
  1065. /**
  1066. * Loader interface with additional members.
  1067. */
  1068. export interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1069. }
  1070. /**
  1071. * Loader interface with additional members.
  1072. */
  1073. export interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1074. }
  1075. /**
  1076. * Loader interface with additional members.
  1077. */
  1078. export interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
  1079. baseColorTexture?: ITextureInfo;
  1080. metallicRoughnessTexture?: ITextureInfo;
  1081. }
  1082. /**
  1083. * Loader interface with additional members.
  1084. */
  1085. export interface IMaterial extends GLTF2.IMaterial, IArrayItem {
  1086. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1087. normalTexture?: IMaterialNormalTextureInfo;
  1088. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1089. emissiveTexture?: ITextureInfo;
  1090. /** @hidden */
  1091. _data?: {
  1092. [babylonDrawMode: number]: {
  1093. babylonMaterial: Material;
  1094. babylonMeshes: AbstractMesh[];
  1095. promise: Promise<void>;
  1096. };
  1097. };
  1098. }
  1099. /**
  1100. * Loader interface with additional members.
  1101. */
  1102. export interface IMesh extends GLTF2.IMesh, IArrayItem {
  1103. primitives: IMeshPrimitive[];
  1104. }
  1105. /**
  1106. * Loader interface with additional members.
  1107. */
  1108. export interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
  1109. /** @hidden */
  1110. _instanceData?: {
  1111. babylonSourceMesh: Mesh;
  1112. promise: Promise<any>;
  1113. };
  1114. }
  1115. /**
  1116. * Loader interface with additional members.
  1117. */
  1118. export interface INode extends GLTF2.INode, IArrayItem {
  1119. /**
  1120. * The parent glTF node.
  1121. */
  1122. parent?: INode;
  1123. /** @hidden */
  1124. _babylonTransformNode?: TransformNode;
  1125. /** @hidden */
  1126. _primitiveBabylonMeshes?: AbstractMesh[];
  1127. /** @hidden */
  1128. _babylonBones?: Bone[];
  1129. /** @hidden */
  1130. _numMorphTargets?: number;
  1131. }
  1132. /** @hidden */
  1133. export interface _ISamplerData {
  1134. noMipMaps: boolean;
  1135. samplingMode: number;
  1136. wrapU: number;
  1137. wrapV: number;
  1138. }
  1139. /**
  1140. * Loader interface with additional members.
  1141. */
  1142. export interface ISampler extends GLTF2.ISampler, IArrayItem {
  1143. /** @hidden */
  1144. _data?: _ISamplerData;
  1145. }
  1146. /**
  1147. * Loader interface with additional members.
  1148. */
  1149. export interface IScene extends GLTF2.IScene, IArrayItem {
  1150. }
  1151. /**
  1152. * Loader interface with additional members.
  1153. */
  1154. export interface ISkin extends GLTF2.ISkin, IArrayItem {
  1155. /** @hidden */
  1156. _data?: {
  1157. babylonSkeleton: Skeleton;
  1158. promise: Promise<void>;
  1159. };
  1160. }
  1161. /**
  1162. * Loader interface with additional members.
  1163. */
  1164. export interface ITexture extends GLTF2.ITexture, IArrayItem {
  1165. }
  1166. /**
  1167. * Loader interface with additional members.
  1168. */
  1169. export interface ITextureInfo extends GLTF2.ITextureInfo {
  1170. }
  1171. /**
  1172. * Loader interface with additional members.
  1173. */
  1174. export interface IGLTF extends GLTF2.IGLTF {
  1175. accessors?: IAccessor[];
  1176. animations?: IAnimation[];
  1177. buffers?: IBuffer[];
  1178. bufferViews?: IBufferView[];
  1179. cameras?: ICamera[];
  1180. images?: IImage[];
  1181. materials?: IMaterial[];
  1182. meshes?: IMesh[];
  1183. nodes?: INode[];
  1184. samplers?: ISampler[];
  1185. scenes?: IScene[];
  1186. skins?: ISkin[];
  1187. textures?: ITexture[];
  1188. }
  1189. }
  1190. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderExtension" {
  1191. import { Nullable } from "babylonjs/types";
  1192. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1193. import { Material } from "babylonjs/Materials/material";
  1194. import { Camera } from "babylonjs/Cameras/camera";
  1195. import { Geometry } from "babylonjs/Meshes/geometry";
  1196. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1197. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1198. import { Mesh } from "babylonjs/Meshes/mesh";
  1199. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1200. import { IDisposable } from "babylonjs/scene";
  1201. import { IScene, INode, IMesh, ISkin, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation, IBufferView, IBuffer } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1202. import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "babylonjs-loaders/glTF/glTFFileLoader";
  1203. import { IProperty } from 'babylonjs-gltf2interface';
  1204. /**
  1205. * Interface for a glTF loader extension.
  1206. */
  1207. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  1208. /**
  1209. * Called after the loader state changes to LOADING.
  1210. */
  1211. onLoading?(): void;
  1212. /**
  1213. * Called after the loader state changes to READY.
  1214. */
  1215. onReady?(): void;
  1216. /**
  1217. * Define this method to modify the default behavior when loading scenes.
  1218. * @param context The context when loading the asset
  1219. * @param scene The glTF scene property
  1220. * @returns A promise that resolves when the load is complete or null if not handled
  1221. */
  1222. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1223. /**
  1224. * Define this method to modify the default behavior when loading nodes.
  1225. * @param context The context when loading the asset
  1226. * @param node The glTF node property
  1227. * @param assign A function called synchronously after parsing the glTF properties
  1228. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1229. */
  1230. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1231. /**
  1232. * Define this method to modify the default behavior when loading cameras.
  1233. * @param context The context when loading the asset
  1234. * @param camera The glTF camera property
  1235. * @param assign A function called synchronously after parsing the glTF properties
  1236. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1237. */
  1238. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1239. /**
  1240. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1241. * @param context The context when loading the asset
  1242. * @param primitive The glTF mesh primitive property
  1243. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1244. */
  1245. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1246. /**
  1247. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1248. * @param context The context when loading the asset
  1249. * @param name The mesh name when loading the asset
  1250. * @param node The glTF node when loading the asset
  1251. * @param mesh The glTF mesh when loading the asset
  1252. * @param primitive The glTF mesh primitive property
  1253. * @param assign A function called synchronously after parsing the glTF properties
  1254. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1255. */
  1256. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1257. /**
  1258. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1259. * @param context The context when loading the asset
  1260. * @param material The glTF material property
  1261. * @param assign A function called synchronously after parsing the glTF properties
  1262. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1263. */
  1264. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1265. /**
  1266. * Define this method to modify the default behavior when creating materials.
  1267. * @param context The context when loading the asset
  1268. * @param material The glTF material property
  1269. * @param babylonDrawMode The draw mode for the Babylon material
  1270. * @returns The Babylon material or null if not handled
  1271. */
  1272. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1273. /**
  1274. * Define this method to modify the default behavior when loading material properties.
  1275. * @param context The context when loading the asset
  1276. * @param material The glTF material property
  1277. * @param babylonMaterial The Babylon material
  1278. * @returns A promise that resolves when the load is complete or null if not handled
  1279. */
  1280. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1281. /**
  1282. * Define this method to modify the default behavior when loading texture infos.
  1283. * @param context The context when loading the asset
  1284. * @param textureInfo The glTF texture info property
  1285. * @param assign A function called synchronously after parsing the glTF properties
  1286. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1287. */
  1288. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1289. /**
  1290. * Define this method to modify the default behavior when loading animations.
  1291. * @param context The context when loading the asset
  1292. * @param animation The glTF animation property
  1293. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1294. */
  1295. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1296. /**
  1297. * @hidden Define this method to modify the default behavior when loading skins.
  1298. * @param context The context when loading the asset
  1299. * @param node The glTF node property
  1300. * @param skin The glTF skin property
  1301. * @returns A promise that resolves when the load is complete or null if not handled
  1302. */
  1303. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1304. /**
  1305. * @hidden Define this method to modify the default behavior when loading uris.
  1306. * @param context The context when loading the asset
  1307. * @param property The glTF property associated with the uri
  1308. * @param uri The uri to load
  1309. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1310. */
  1311. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1312. /**
  1313. * Define this method to modify the default behavior when loading buffer views.
  1314. * @param context The context when loading the asset
  1315. * @param bufferView The glTF buffer view property
  1316. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1317. */
  1318. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1319. /**
  1320. * Define this method to modify the default behavior when loading buffers.
  1321. * @param context The context when loading the asset
  1322. * @param buffer The glTF buffer property
  1323. * @param byteOffset The byte offset to load
  1324. * @param byteLength The byte length to load
  1325. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1326. */
  1327. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  1328. }
  1329. }
  1330. declare module "babylonjs-loaders/glTF/2.0/glTFLoader" {
  1331. import { Nullable } from "babylonjs/types";
  1332. import { Camera } from "babylonjs/Cameras/camera";
  1333. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1334. import { Skeleton } from "babylonjs/Bones/skeleton";
  1335. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1336. import { Material } from "babylonjs/Materials/material";
  1337. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1338. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1339. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1340. import { Mesh } from "babylonjs/Meshes/mesh";
  1341. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  1342. import { Scene } from "babylonjs/scene";
  1343. import { IProperty } from "babylonjs-gltf2interface";
  1344. import { IGLTF, INode, IScene, IMesh, ICamera, IAnimation, IAnimationChannel, IBufferView, IMaterial, ITextureInfo, IImage, IMeshPrimitive, IArrayItem as IArrItem } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1345. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1346. import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  1347. import { IAnimatable } from 'babylonjs/Animations/animatable.interface';
  1348. import { IDataBuffer } from 'babylonjs/Misc/dataReader';
  1349. /**
  1350. * Helper class for working with arrays when loading the glTF asset
  1351. */
  1352. export class ArrayItem {
  1353. /**
  1354. * Gets an item from the given array.
  1355. * @param context The context when loading the asset
  1356. * @param array The array to get the item from
  1357. * @param index The index to the array
  1358. * @returns The array item
  1359. */
  1360. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1361. /**
  1362. * Assign an `index` field to each item of the given array.
  1363. * @param array The array of items
  1364. */
  1365. static Assign(array?: IArrItem[]): void;
  1366. }
  1367. /**
  1368. * The glTF 2.0 loader
  1369. */
  1370. export class GLTFLoader implements IGLTFLoader {
  1371. /** @hidden */
  1372. _completePromises: Promise<any>[];
  1373. private _disposed;
  1374. private _parent;
  1375. private _state;
  1376. private _extensions;
  1377. private _rootUrl;
  1378. private _fileName;
  1379. private _uniqueRootUrl;
  1380. private _gltf;
  1381. private _bin;
  1382. private _babylonScene;
  1383. private _rootBabylonMesh;
  1384. private _defaultBabylonMaterialData;
  1385. private _progressCallback?;
  1386. private _requests;
  1387. private static readonly _DefaultSampler;
  1388. private static _RegisteredExtensions;
  1389. /**
  1390. * Registers a loader extension.
  1391. * @param name The name of the loader extension.
  1392. * @param factory The factory function that creates the loader extension.
  1393. */
  1394. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1395. /**
  1396. * Unregisters a loader extension.
  1397. * @param name The name of the loader extension.
  1398. * @returns A boolean indicating whether the extension has been unregistered
  1399. */
  1400. static UnregisterExtension(name: string): boolean;
  1401. /**
  1402. * Gets the loader state.
  1403. */
  1404. get state(): Nullable<GLTFLoaderState>;
  1405. /**
  1406. * The object that represents the glTF JSON.
  1407. */
  1408. get gltf(): IGLTF;
  1409. /**
  1410. * The BIN chunk of a binary glTF.
  1411. */
  1412. get bin(): Nullable<IDataBuffer>;
  1413. /**
  1414. * The parent file loader.
  1415. */
  1416. get parent(): GLTFFileLoader;
  1417. /**
  1418. * The Babylon scene when loading the asset.
  1419. */
  1420. get babylonScene(): Scene;
  1421. /**
  1422. * The root Babylon mesh when loading the asset.
  1423. */
  1424. get rootBabylonMesh(): Mesh;
  1425. /** @hidden */
  1426. constructor(parent: GLTFFileLoader);
  1427. /** @hidden */
  1428. dispose(): void;
  1429. /** @hidden */
  1430. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1431. meshes: AbstractMesh[];
  1432. particleSystems: IParticleSystem[];
  1433. skeletons: Skeleton[];
  1434. animationGroups: AnimationGroup[];
  1435. }>;
  1436. /** @hidden */
  1437. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1438. private _loadAsync;
  1439. private _loadData;
  1440. private _setupData;
  1441. private _loadExtensions;
  1442. private _checkExtensions;
  1443. private _setState;
  1444. private _createRootNode;
  1445. /**
  1446. * Loads a glTF scene.
  1447. * @param context The context when loading the asset
  1448. * @param scene The glTF scene property
  1449. * @returns A promise that resolves when the load is complete
  1450. */
  1451. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1452. private _forEachPrimitive;
  1453. private _getMeshes;
  1454. private _getSkeletons;
  1455. private _getAnimationGroups;
  1456. private _startAnimations;
  1457. /**
  1458. * Loads a glTF node.
  1459. * @param context The context when loading the asset
  1460. * @param node The glTF node property
  1461. * @param assign A function called synchronously after parsing the glTF properties
  1462. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1463. */
  1464. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1465. private _loadMeshAsync;
  1466. /**
  1467. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1468. * @param context The context when loading the asset
  1469. * @param name The mesh name when loading the asset
  1470. * @param node The glTF node when loading the asset
  1471. * @param mesh The glTF mesh when loading the asset
  1472. * @param primitive The glTF mesh primitive property
  1473. * @param assign A function called synchronously after parsing the glTF properties
  1474. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1475. */
  1476. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1477. private _loadVertexDataAsync;
  1478. private _createMorphTargets;
  1479. private _loadMorphTargetsAsync;
  1480. private _loadMorphTargetVertexDataAsync;
  1481. private static _LoadTransform;
  1482. private _loadSkinAsync;
  1483. private _loadBones;
  1484. private _loadBone;
  1485. private _loadSkinInverseBindMatricesDataAsync;
  1486. private _updateBoneMatrices;
  1487. private _getNodeMatrix;
  1488. /**
  1489. * Loads a glTF camera.
  1490. * @param context The context when loading the asset
  1491. * @param camera The glTF camera property
  1492. * @param assign A function called synchronously after parsing the glTF properties
  1493. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1494. */
  1495. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1496. private _loadAnimationsAsync;
  1497. /**
  1498. * Loads a glTF animation.
  1499. * @param context The context when loading the asset
  1500. * @param animation The glTF animation property
  1501. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1502. */
  1503. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1504. /**
  1505. * @hidden Loads a glTF animation channel.
  1506. * @param context The context when loading the asset
  1507. * @param animationContext The context of the animation when loading the asset
  1508. * @param animation The glTF animation property
  1509. * @param channel The glTF animation channel property
  1510. * @param babylonAnimationGroup The babylon animation group property
  1511. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1512. * @returns A void promise when the channel load is complete
  1513. */
  1514. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1515. private _loadAnimationSamplerAsync;
  1516. private _loadBufferAsync;
  1517. /**
  1518. * Loads a glTF buffer view.
  1519. * @param context The context when loading the asset
  1520. * @param bufferView The glTF buffer view property
  1521. * @returns A promise that resolves with the loaded data when the load is complete
  1522. */
  1523. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1524. private _loadAccessorAsync;
  1525. private _loadFloatAccessorAsync;
  1526. private _loadIndicesAccessorAsync;
  1527. private _loadVertexBufferViewAsync;
  1528. private _loadVertexAccessorAsync;
  1529. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1530. /** @hidden */
  1531. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1532. private _createDefaultMaterial;
  1533. /**
  1534. * Creates a Babylon material from a glTF material.
  1535. * @param context The context when loading the asset
  1536. * @param material The glTF material property
  1537. * @param babylonDrawMode The draw mode for the Babylon material
  1538. * @returns The Babylon material
  1539. */
  1540. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1541. /**
  1542. * Loads properties from a glTF material into a Babylon material.
  1543. * @param context The context when loading the asset
  1544. * @param material The glTF material property
  1545. * @param babylonMaterial The Babylon material
  1546. * @returns A promise that resolves when the load is complete
  1547. */
  1548. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1549. /**
  1550. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1551. * @param context The context when loading the asset
  1552. * @param material The glTF material property
  1553. * @param babylonMaterial The Babylon material
  1554. * @returns A promise that resolves when the load is complete
  1555. */
  1556. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1557. /**
  1558. * Loads the alpha properties from a glTF material into a Babylon material.
  1559. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1560. * @param context The context when loading the asset
  1561. * @param material The glTF material property
  1562. * @param babylonMaterial The Babylon material
  1563. */
  1564. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1565. /**
  1566. * Loads a glTF texture info.
  1567. * @param context The context when loading the asset
  1568. * @param textureInfo The glTF texture info property
  1569. * @param assign A function called synchronously after parsing the glTF properties
  1570. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1571. */
  1572. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1573. private _loadTextureAsync;
  1574. private _loadSampler;
  1575. /**
  1576. * Loads a glTF image.
  1577. * @param context The context when loading the asset
  1578. * @param image The glTF image property
  1579. * @returns A promise that resolves with the loaded data when the load is complete
  1580. */
  1581. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1582. /**
  1583. * Loads a glTF uri.
  1584. * @param context The context when loading the asset
  1585. * @param property The glTF property associated with the uri
  1586. * @param uri The base64 or relative uri
  1587. * @returns A promise that resolves with the loaded data when the load is complete
  1588. */
  1589. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1590. private _onProgress;
  1591. /**
  1592. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1593. * @param babylonObject the Babylon object with metadata
  1594. * @param pointer the JSON pointer
  1595. */
  1596. static AddPointerMetadata(babylonObject: {
  1597. metadata: any;
  1598. }, pointer: string): void;
  1599. private static _GetTextureWrapMode;
  1600. private static _GetTextureSamplingMode;
  1601. private static _GetTypedArrayConstructor;
  1602. private static _GetTypedArray;
  1603. private static _GetNumComponents;
  1604. private static _ValidateUri;
  1605. private static _GetDrawMode;
  1606. private _compileMaterialsAsync;
  1607. private _compileShadowGeneratorsAsync;
  1608. private _forEachExtensions;
  1609. private _applyExtensions;
  1610. private _extensionsOnLoading;
  1611. private _extensionsOnReady;
  1612. private _extensionsLoadSceneAsync;
  1613. private _extensionsLoadNodeAsync;
  1614. private _extensionsLoadCameraAsync;
  1615. private _extensionsLoadVertexDataAsync;
  1616. private _extensionsLoadMeshPrimitiveAsync;
  1617. private _extensionsLoadMaterialAsync;
  1618. private _extensionsCreateMaterial;
  1619. private _extensionsLoadMaterialPropertiesAsync;
  1620. private _extensionsLoadTextureInfoAsync;
  1621. private _extensionsLoadAnimationAsync;
  1622. private _extensionsLoadSkinAsync;
  1623. private _extensionsLoadUriAsync;
  1624. private _extensionsLoadBufferViewAsync;
  1625. private _extensionsLoadBufferAsync;
  1626. /**
  1627. * Helper method called by a loader extension to load an glTF extension.
  1628. * @param context The context when loading the asset
  1629. * @param property The glTF property to load the extension from
  1630. * @param extensionName The name of the extension to load
  1631. * @param actionAsync The action to run
  1632. * @returns The promise returned by actionAsync or null if the extension does not exist
  1633. */
  1634. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1635. /**
  1636. * Helper method called by a loader extension to load a glTF extra.
  1637. * @param context The context when loading the asset
  1638. * @param property The glTF property to load the extra from
  1639. * @param extensionName The name of the extension to load
  1640. * @param actionAsync The action to run
  1641. * @returns The promise returned by actionAsync or null if the extra does not exist
  1642. */
  1643. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1644. /**
  1645. * Checks for presence of an extension.
  1646. * @param name The name of the extension to check
  1647. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1648. */
  1649. isExtensionUsed(name: string): boolean;
  1650. /**
  1651. * Increments the indentation level and logs a message.
  1652. * @param message The message to log
  1653. */
  1654. logOpen(message: string): void;
  1655. /**
  1656. * Decrements the indentation level.
  1657. */
  1658. logClose(): void;
  1659. /**
  1660. * Logs a message
  1661. * @param message The message to log
  1662. */
  1663. log(message: string): void;
  1664. /**
  1665. * Starts a performance counter.
  1666. * @param counterName The name of the performance counter
  1667. */
  1668. startPerformanceCounter(counterName: string): void;
  1669. /**
  1670. * Ends a performance counter.
  1671. * @param counterName The name of the performance counter
  1672. */
  1673. endPerformanceCounter(counterName: string): void;
  1674. }
  1675. }
  1676. declare module "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based" {
  1677. import { Nullable } from "babylonjs/types";
  1678. import { IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1679. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1680. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1681. /**
  1682. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1683. */
  1684. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1685. /**
  1686. * The name of this extension.
  1687. */
  1688. readonly name: string;
  1689. /**
  1690. * Defines whether this extension is enabled.
  1691. */
  1692. enabled: boolean;
  1693. private _loader;
  1694. private _lights?;
  1695. /** @hidden */
  1696. constructor(loader: GLTFLoader);
  1697. /** @hidden */
  1698. dispose(): void;
  1699. /** @hidden */
  1700. onLoading(): void;
  1701. /** @hidden */
  1702. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1703. private _loadLightAsync;
  1704. }
  1705. }
  1706. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression" {
  1707. import { DracoCompression } from "babylonjs/Meshes/Compression/dracoCompression";
  1708. import { Nullable } from "babylonjs/types";
  1709. import { Geometry } from "babylonjs/Meshes/geometry";
  1710. import { Mesh } from "babylonjs/Meshes/mesh";
  1711. import { IMeshPrimitive } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1712. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1713. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1714. /**
  1715. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1716. */
  1717. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1718. /**
  1719. * The name of this extension.
  1720. */
  1721. readonly name: string;
  1722. /**
  1723. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1724. */
  1725. dracoCompression?: DracoCompression;
  1726. /**
  1727. * Defines whether this extension is enabled.
  1728. */
  1729. enabled: boolean;
  1730. private _loader;
  1731. /** @hidden */
  1732. constructor(loader: GLTFLoader);
  1733. /** @hidden */
  1734. dispose(): void;
  1735. /** @hidden */
  1736. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1737. }
  1738. }
  1739. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual" {
  1740. import { Nullable } from "babylonjs/types";
  1741. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1742. import { INode } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1743. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1744. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1745. /**
  1746. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  1747. */
  1748. export class KHR_lights implements IGLTFLoaderExtension {
  1749. /**
  1750. * The name of this extension.
  1751. */
  1752. readonly name: string;
  1753. /**
  1754. * Defines whether this extension is enabled.
  1755. */
  1756. enabled: boolean;
  1757. private _loader;
  1758. private _lights?;
  1759. /** @hidden */
  1760. constructor(loader: GLTFLoader);
  1761. /** @hidden */
  1762. dispose(): void;
  1763. /** @hidden */
  1764. onLoading(): void;
  1765. /** @hidden */
  1766. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1767. }
  1768. }
  1769. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness" {
  1770. import { Nullable } from "babylonjs/types";
  1771. import { Material } from "babylonjs/Materials/material";
  1772. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1773. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1774. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1775. /**
  1776. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1777. */
  1778. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1779. /**
  1780. * The name of this extension.
  1781. */
  1782. readonly name: string;
  1783. /**
  1784. * Defines whether this extension is enabled.
  1785. */
  1786. enabled: boolean;
  1787. /**
  1788. * Defines a number that determines the order the extensions are applied.
  1789. */
  1790. order: number;
  1791. private _loader;
  1792. /** @hidden */
  1793. constructor(loader: GLTFLoader);
  1794. /** @hidden */
  1795. dispose(): void;
  1796. /** @hidden */
  1797. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1798. private _loadSpecularGlossinessPropertiesAsync;
  1799. }
  1800. }
  1801. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit" {
  1802. import { Nullable } from "babylonjs/types";
  1803. import { Material } from "babylonjs/Materials/material";
  1804. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1805. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1806. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1807. /**
  1808. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1809. */
  1810. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1811. /**
  1812. * The name of this extension.
  1813. */
  1814. readonly name: string;
  1815. /**
  1816. * Defines whether this extension is enabled.
  1817. */
  1818. enabled: boolean;
  1819. /**
  1820. * Defines a number that determines the order the extensions are applied.
  1821. */
  1822. order: number;
  1823. private _loader;
  1824. /** @hidden */
  1825. constructor(loader: GLTFLoader);
  1826. /** @hidden */
  1827. dispose(): void;
  1828. /** @hidden */
  1829. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1830. private _loadUnlitPropertiesAsync;
  1831. }
  1832. }
  1833. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_clearcoat" {
  1834. import { Nullable } from "babylonjs/types";
  1835. import { Material } from "babylonjs/Materials/material";
  1836. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1837. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1838. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1839. /**
  1840. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1841. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1842. * !!! Experimental Extension Subject to Changes !!!
  1843. */
  1844. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1845. /**
  1846. * The name of this extension.
  1847. */
  1848. readonly name: string;
  1849. /**
  1850. * Defines whether this extension is enabled.
  1851. */
  1852. enabled: boolean;
  1853. /**
  1854. * Defines a number that determines the order the extensions are applied.
  1855. */
  1856. order: number;
  1857. private _loader;
  1858. /** @hidden */
  1859. constructor(loader: GLTFLoader);
  1860. /** @hidden */
  1861. dispose(): void;
  1862. /** @hidden */
  1863. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1864. private _loadClearCoatPropertiesAsync;
  1865. }
  1866. }
  1867. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_sheen" {
  1868. import { Nullable } from "babylonjs/types";
  1869. import { Material } from "babylonjs/Materials/material";
  1870. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1871. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1872. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1873. /**
  1874. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  1875. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1876. * !!! Experimental Extension Subject to Changes !!!
  1877. */
  1878. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1879. /**
  1880. * The name of this extension.
  1881. */
  1882. readonly name: string;
  1883. /**
  1884. * Defines whether this extension is enabled.
  1885. */
  1886. enabled: boolean;
  1887. /**
  1888. * Defines a number that determines the order the extensions are applied.
  1889. */
  1890. order: number;
  1891. private _loader;
  1892. /** @hidden */
  1893. constructor(loader: GLTFLoader);
  1894. /** @hidden */
  1895. dispose(): void;
  1896. /** @hidden */
  1897. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1898. private _loadSheenPropertiesAsync;
  1899. }
  1900. }
  1901. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_specular" {
  1902. import { Nullable } from "babylonjs/types";
  1903. import { Material } from "babylonjs/Materials/material";
  1904. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1905. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1906. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1907. /**
  1908. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1909. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1910. * !!! Experimental Extension Subject to Changes !!!
  1911. */
  1912. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1913. /**
  1914. * The name of this extension.
  1915. */
  1916. readonly name: string;
  1917. /**
  1918. * Defines whether this extension is enabled.
  1919. */
  1920. enabled: boolean;
  1921. /**
  1922. * Defines a number that determines the order the extensions are applied.
  1923. */
  1924. order: number;
  1925. private _loader;
  1926. /** @hidden */
  1927. constructor(loader: GLTFLoader);
  1928. /** @hidden */
  1929. dispose(): void;
  1930. /** @hidden */
  1931. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1932. private _loadSpecularPropertiesAsync;
  1933. }
  1934. }
  1935. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_mesh_quantization" {
  1936. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1937. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1938. /**
  1939. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1940. */
  1941. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1942. /**
  1943. * The name of this extension.
  1944. */
  1945. readonly name: string;
  1946. /**
  1947. * Defines whether this extension is enabled.
  1948. */
  1949. enabled: boolean;
  1950. /** @hidden */
  1951. constructor(loader: GLTFLoader);
  1952. /** @hidden */
  1953. dispose(): void;
  1954. }
  1955. }
  1956. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform" {
  1957. import { Nullable } from "babylonjs/types";
  1958. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1959. import { ITextureInfo } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1960. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1961. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1962. /**
  1963. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1964. */
  1965. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1966. /**
  1967. * The name of this extension.
  1968. */
  1969. readonly name: string;
  1970. /**
  1971. * Defines whether this extension is enabled.
  1972. */
  1973. enabled: boolean;
  1974. private _loader;
  1975. /** @hidden */
  1976. constructor(loader: GLTFLoader);
  1977. /** @hidden */
  1978. dispose(): void;
  1979. /** @hidden */
  1980. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1981. }
  1982. }
  1983. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter" {
  1984. import { Nullable } from "babylonjs/types";
  1985. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1986. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1987. import { IScene, INode, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1988. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1989. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1990. /**
  1991. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1992. */
  1993. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1994. /**
  1995. * The name of this extension.
  1996. */
  1997. readonly name: string;
  1998. /**
  1999. * Defines whether this extension is enabled.
  2000. */
  2001. enabled: boolean;
  2002. private _loader;
  2003. private _clips;
  2004. private _emitters;
  2005. /** @hidden */
  2006. constructor(loader: GLTFLoader);
  2007. /** @hidden */
  2008. dispose(): void;
  2009. /** @hidden */
  2010. onLoading(): void;
  2011. /** @hidden */
  2012. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2013. /** @hidden */
  2014. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2015. /** @hidden */
  2016. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2017. private _loadClipAsync;
  2018. private _loadEmitterAsync;
  2019. private _getEventAction;
  2020. private _loadAnimationEventAsync;
  2021. }
  2022. }
  2023. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod" {
  2024. import { Nullable } from "babylonjs/types";
  2025. import { Observable } from "babylonjs/Misc/observable";
  2026. import { Material } from "babylonjs/Materials/material";
  2027. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2028. import { Mesh } from "babylonjs/Meshes/mesh";
  2029. import { INode, IMaterial, IBuffer } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2030. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2031. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2032. import { IProperty } from 'babylonjs-gltf2interface';
  2033. /**
  2034. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2035. */
  2036. export class MSFT_lod implements IGLTFLoaderExtension {
  2037. /**
  2038. * The name of this extension.
  2039. */
  2040. readonly name: string;
  2041. /**
  2042. * Defines whether this extension is enabled.
  2043. */
  2044. enabled: boolean;
  2045. /**
  2046. * Defines a number that determines the order the extensions are applied.
  2047. */
  2048. order: number;
  2049. /**
  2050. * Maximum number of LODs to load, starting from the lowest LOD.
  2051. */
  2052. maxLODsToLoad: number;
  2053. /**
  2054. * Observable raised when all node LODs of one level are loaded.
  2055. * The event data is the index of the loaded LOD starting from zero.
  2056. * Dispose the loader to cancel the loading of the next level of LODs.
  2057. */
  2058. onNodeLODsLoadedObservable: Observable<number>;
  2059. /**
  2060. * Observable raised when all material LODs of one level are loaded.
  2061. * The event data is the index of the loaded LOD starting from zero.
  2062. * Dispose the loader to cancel the loading of the next level of LODs.
  2063. */
  2064. onMaterialLODsLoadedObservable: Observable<number>;
  2065. private _loader;
  2066. private _nodeIndexLOD;
  2067. private _nodeSignalLODs;
  2068. private _nodePromiseLODs;
  2069. private _materialIndexLOD;
  2070. private _materialSignalLODs;
  2071. private _materialPromiseLODs;
  2072. private _indexLOD;
  2073. private _bufferLODs;
  2074. /** @hidden */
  2075. constructor(loader: GLTFLoader);
  2076. /** @hidden */
  2077. dispose(): void;
  2078. /** @hidden */
  2079. onReady(): void;
  2080. /** @hidden */
  2081. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2082. /** @hidden */
  2083. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2084. /** @hidden */
  2085. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2086. /** @hidden */
  2087. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2088. private _loadBufferLOD;
  2089. /**
  2090. * Gets an array of LOD properties from lowest to highest.
  2091. */
  2092. private _getLODs;
  2093. private _disposeUnusedMaterials;
  2094. }
  2095. }
  2096. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh" {
  2097. import { Nullable } from "babylonjs/types";
  2098. import { Material } from "babylonjs/Materials/material";
  2099. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2100. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2101. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2102. /** @hidden */
  2103. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2104. readonly name: string;
  2105. enabled: boolean;
  2106. private _loader;
  2107. constructor(loader: GLTFLoader);
  2108. dispose(): void;
  2109. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2110. }
  2111. }
  2112. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors" {
  2113. import { Nullable } from "babylonjs/types";
  2114. import { Material } from "babylonjs/Materials/material";
  2115. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2116. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2117. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2118. /** @hidden */
  2119. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2120. readonly name: string;
  2121. enabled: boolean;
  2122. private _loader;
  2123. constructor(loader: GLTFLoader);
  2124. dispose(): void;
  2125. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2126. }
  2127. }
  2128. declare module "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata" {
  2129. import { Nullable } from "babylonjs/types";
  2130. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2131. import { Camera } from "babylonjs/Cameras/camera";
  2132. import { INode, ICamera, IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2133. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2134. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2135. import { Material } from "babylonjs/Materials/material";
  2136. /**
  2137. * Store glTF extras (if present) in BJS objects' metadata
  2138. */
  2139. export class ExtrasAsMetadata 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 _assignExtras;
  2150. /** @hidden */
  2151. constructor(loader: GLTFLoader);
  2152. /** @hidden */
  2153. dispose(): void;
  2154. /** @hidden */
  2155. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2156. /** @hidden */
  2157. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2158. /** @hidden */
  2159. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2160. }
  2161. }
  2162. declare module "babylonjs-loaders/glTF/2.0/Extensions/index" {
  2163. export * from "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based";
  2164. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
  2165. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual";
  2166. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness";
  2167. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit";
  2168. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_clearcoat";
  2169. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_sheen";
  2170. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_specular";
  2171. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_mesh_quantization";
  2172. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform";
  2173. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter";
  2174. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod";
  2175. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh";
  2176. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors";
  2177. export * from "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata";
  2178. }
  2179. declare module "babylonjs-loaders/glTF/2.0/index" {
  2180. export * from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2181. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2182. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2183. export * from "babylonjs-loaders/glTF/2.0/Extensions/index";
  2184. }
  2185. declare module "babylonjs-loaders/glTF/index" {
  2186. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2187. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2188. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2189. export { GLTF1, GLTF2 };
  2190. }
  2191. declare module "babylonjs-loaders/OBJ/objFileLoader" {
  2192. import { Vector2 } from "babylonjs/Maths/math";
  2193. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  2194. import { Skeleton } from "babylonjs/Bones/skeleton";
  2195. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2196. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  2197. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2198. import { ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin } from "babylonjs/Loading/sceneLoader";
  2199. import { AssetContainer } from "babylonjs/assetContainer";
  2200. import { Scene } from "babylonjs/scene";
  2201. /**
  2202. * Class reading and parsing the MTL file bundled with the obj file.
  2203. */
  2204. export class MTLFileLoader {
  2205. /**
  2206. * All material loaded from the mtl will be set here
  2207. */
  2208. materials: StandardMaterial[];
  2209. /**
  2210. * This function will read the mtl file and create each material described inside
  2211. * This function could be improve by adding :
  2212. * -some component missing (Ni, Tf...)
  2213. * -including the specific options available
  2214. *
  2215. * @param scene defines the scene the material will be created in
  2216. * @param data defines the mtl data to parse
  2217. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2218. */
  2219. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  2220. /**
  2221. * Gets the texture for the material.
  2222. *
  2223. * If the material is imported from input file,
  2224. * We sanitize the url to ensure it takes the textre from aside the material.
  2225. *
  2226. * @param rootUrl The root url to load from
  2227. * @param value The value stored in the mtl
  2228. * @return The Texture
  2229. */
  2230. private static _getTexture;
  2231. }
  2232. /**
  2233. * Options for loading OBJ/MTL files
  2234. */
  2235. type MeshLoadOptions = {
  2236. /**
  2237. * Defines if UVs are optimized by default during load.
  2238. */
  2239. OptimizeWithUV: boolean;
  2240. /**
  2241. * Defines custom scaling of UV coordinates of loaded meshes.
  2242. */
  2243. UVScaling: Vector2;
  2244. /**
  2245. * Invert model on y-axis (does a model scaling inversion)
  2246. */
  2247. InvertY: boolean;
  2248. /**
  2249. * Invert Y-Axis of referenced textures on load
  2250. */
  2251. InvertTextureY: boolean;
  2252. /**
  2253. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2254. */
  2255. ImportVertexColors: boolean;
  2256. /**
  2257. * Compute the normals for the model, even if normals are present in the file.
  2258. */
  2259. ComputeNormals: boolean;
  2260. /**
  2261. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2262. */
  2263. SkipMaterials: boolean;
  2264. /**
  2265. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2266. */
  2267. MaterialLoadingFailsSilently: boolean;
  2268. };
  2269. /**
  2270. * OBJ file type loader.
  2271. * This is a babylon scene loader plugin.
  2272. */
  2273. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2274. /**
  2275. * Defines if UVs are optimized by default during load.
  2276. */
  2277. static OPTIMIZE_WITH_UV: boolean;
  2278. /**
  2279. * Invert model on y-axis (does a model scaling inversion)
  2280. */
  2281. static INVERT_Y: boolean;
  2282. /**
  2283. * Invert Y-Axis of referenced textures on load
  2284. */
  2285. static INVERT_TEXTURE_Y: boolean;
  2286. /**
  2287. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2288. */
  2289. static IMPORT_VERTEX_COLORS: boolean;
  2290. /**
  2291. * Compute the normals for the model, even if normals are present in the file.
  2292. */
  2293. static COMPUTE_NORMALS: boolean;
  2294. /**
  2295. * Defines custom scaling of UV coordinates of loaded meshes.
  2296. */
  2297. static UV_SCALING: Vector2;
  2298. /**
  2299. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2300. */
  2301. static SKIP_MATERIALS: boolean;
  2302. /**
  2303. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2304. *
  2305. * Defaults to true for backwards compatibility.
  2306. */
  2307. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2308. /**
  2309. * Defines the name of the plugin.
  2310. */
  2311. name: string;
  2312. /**
  2313. * Defines the extension the plugin is able to load.
  2314. */
  2315. extensions: string;
  2316. /** @hidden */
  2317. obj: RegExp;
  2318. /** @hidden */
  2319. group: RegExp;
  2320. /** @hidden */
  2321. mtllib: RegExp;
  2322. /** @hidden */
  2323. usemtl: RegExp;
  2324. /** @hidden */
  2325. smooth: RegExp;
  2326. /** @hidden */
  2327. vertexPattern: RegExp;
  2328. /** @hidden */
  2329. normalPattern: RegExp;
  2330. /** @hidden */
  2331. uvPattern: RegExp;
  2332. /** @hidden */
  2333. facePattern1: RegExp;
  2334. /** @hidden */
  2335. facePattern2: RegExp;
  2336. /** @hidden */
  2337. facePattern3: RegExp;
  2338. /** @hidden */
  2339. facePattern4: RegExp;
  2340. /** @hidden */
  2341. facePattern5: RegExp;
  2342. private _meshLoadOptions;
  2343. /**
  2344. * Creates loader for .OBJ files
  2345. *
  2346. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2347. */
  2348. constructor(meshLoadOptions?: MeshLoadOptions);
  2349. private static get currentMeshLoadOptions();
  2350. /**
  2351. * Calls synchronously the MTL file attached to this obj.
  2352. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2353. * Without this function materials are not displayed in the first frame (but displayed after).
  2354. * In consequence it is impossible to get material information in your HTML file
  2355. *
  2356. * @param url The URL of the MTL file
  2357. * @param rootUrl
  2358. * @param onSuccess Callback function to be called when the MTL file is loaded
  2359. * @private
  2360. */
  2361. private _loadMTL;
  2362. /**
  2363. * Instantiates a OBJ file loader plugin.
  2364. * @returns the created plugin
  2365. */
  2366. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2367. /**
  2368. * If the data string can be loaded directly.
  2369. *
  2370. * @param data string containing the file data
  2371. * @returns if the data can be loaded directly
  2372. */
  2373. canDirectLoad(data: string): boolean;
  2374. /**
  2375. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2376. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2377. * @param scene the scene the meshes should be added to
  2378. * @param data the OBJ data to load
  2379. * @param rootUrl root url to load from
  2380. * @param onProgress event that fires when loading progress has occured
  2381. * @param fileName Defines the name of the file to load
  2382. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2383. */
  2384. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2385. meshes: AbstractMesh[];
  2386. particleSystems: IParticleSystem[];
  2387. skeletons: Skeleton[];
  2388. animationGroups: AnimationGroup[];
  2389. }>;
  2390. /**
  2391. * Imports all objects from the loaded OBJ data and adds them to the scene
  2392. * @param scene the scene the objects should be added to
  2393. * @param data the OBJ data to load
  2394. * @param rootUrl root url to load from
  2395. * @param onProgress event that fires when loading progress has occured
  2396. * @param fileName Defines the name of the file to load
  2397. * @returns a promise which completes when objects have been loaded to the scene
  2398. */
  2399. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2400. /**
  2401. * Load into an asset container.
  2402. * @param scene The scene to load into
  2403. * @param data The data to import
  2404. * @param rootUrl The root url for scene and resources
  2405. * @param onProgress The callback when the load progresses
  2406. * @param fileName Defines the name of the file to load
  2407. * @returns The loaded asset container
  2408. */
  2409. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2410. /**
  2411. * Read the OBJ file and create an Array of meshes.
  2412. * Each mesh contains all information given by the OBJ and the MTL file.
  2413. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2414. *
  2415. * @param meshesNames
  2416. * @param scene Scene The scene where are displayed the data
  2417. * @param data String The content of the obj file
  2418. * @param rootUrl String The path to the folder
  2419. * @returns Array<AbstractMesh>
  2420. * @private
  2421. */
  2422. private _parseSolid;
  2423. }
  2424. }
  2425. declare module "babylonjs-loaders/OBJ/index" {
  2426. export * from "babylonjs-loaders/OBJ/objFileLoader";
  2427. }
  2428. declare module "babylonjs-loaders/STL/stlFileLoader" {
  2429. import { Nullable } from "babylonjs/types";
  2430. import { Skeleton } from "babylonjs/Bones/skeleton";
  2431. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2432. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2433. import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  2434. import { AssetContainer } from "babylonjs/assetContainer";
  2435. import { Scene } from "babylonjs/scene";
  2436. /**
  2437. * STL file type loader.
  2438. * This is a babylon scene loader plugin.
  2439. */
  2440. export class STLFileLoader implements ISceneLoaderPlugin {
  2441. /** @hidden */
  2442. solidPattern: RegExp;
  2443. /** @hidden */
  2444. facetsPattern: RegExp;
  2445. /** @hidden */
  2446. normalPattern: RegExp;
  2447. /** @hidden */
  2448. vertexPattern: RegExp;
  2449. /**
  2450. * Defines the name of the plugin.
  2451. */
  2452. name: string;
  2453. /**
  2454. * Defines the extensions the stl loader is able to load.
  2455. * force data to come in as an ArrayBuffer
  2456. * we'll convert to string if it looks like it's an ASCII .stl
  2457. */
  2458. extensions: ISceneLoaderPluginExtensions;
  2459. /**
  2460. * Import meshes into a scene.
  2461. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2462. * @param scene The scene to import into
  2463. * @param data The data to import
  2464. * @param rootUrl The root url for scene and resources
  2465. * @param meshes The meshes array to import into
  2466. * @param particleSystems The particle systems array to import into
  2467. * @param skeletons The skeletons array to import into
  2468. * @param onError The callback when import fails
  2469. * @returns True if successful or false otherwise
  2470. */
  2471. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2472. /**
  2473. * Load into a scene.
  2474. * @param scene The scene to load into
  2475. * @param data The data to import
  2476. * @param rootUrl The root url for scene and resources
  2477. * @param onError The callback when import fails
  2478. * @returns true if successful or false otherwise
  2479. */
  2480. load(scene: Scene, data: any, rootUrl: string): boolean;
  2481. /**
  2482. * Load into an asset container.
  2483. * @param scene The scene to load into
  2484. * @param data The data to import
  2485. * @param rootUrl The root url for scene and resources
  2486. * @param onError The callback when import fails
  2487. * @returns The loaded asset container
  2488. */
  2489. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2490. private _isBinary;
  2491. private _parseBinary;
  2492. private _parseASCII;
  2493. }
  2494. }
  2495. declare module "babylonjs-loaders/STL/index" {
  2496. export * from "babylonjs-loaders/STL/stlFileLoader";
  2497. }
  2498. declare module "babylonjs-loaders/index" {
  2499. export * from "babylonjs-loaders/glTF/index";
  2500. export * from "babylonjs-loaders/OBJ/index";
  2501. export * from "babylonjs-loaders/STL/index";
  2502. }
  2503. declare module "babylonjs-loaders/legacy/legacy-glTF" {
  2504. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2505. }
  2506. declare module "babylonjs-loaders/legacy/legacy-glTF1" {
  2507. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2508. export { GLTF1 };
  2509. }
  2510. declare module "babylonjs-loaders/legacy/legacy-glTF1FileLoader" {
  2511. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2512. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2513. }
  2514. declare module "babylonjs-loaders/legacy/legacy-glTF2" {
  2515. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2516. export { GLTF2 };
  2517. }
  2518. declare module "babylonjs-loaders/legacy/legacy-glTF2FileLoader" {
  2519. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2520. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2521. }
  2522. declare module "babylonjs-loaders/legacy/legacy-glTFFileLoader" {
  2523. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2524. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2525. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2526. }
  2527. declare module "babylonjs-loaders/legacy/legacy-objFileLoader" {
  2528. export * from "babylonjs-loaders/OBJ/index";
  2529. }
  2530. declare module "babylonjs-loaders/legacy/legacy-stlFileLoader" {
  2531. export * from "babylonjs-loaders/STL/index";
  2532. }
  2533. declare module "babylonjs-loaders/legacy/legacy" {
  2534. import "babylonjs-loaders/index";
  2535. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2536. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2537. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2538. export * from "babylonjs-loaders/legacy/legacy-objFileLoader";
  2539. export * from "babylonjs-loaders/legacy/legacy-stlFileLoader";
  2540. }
  2541. declare module "babylonjs-loaders" {
  2542. export * from "babylonjs-loaders/legacy/legacy";
  2543. }
  2544. declare module BABYLON {
  2545. /**
  2546. * Mode that determines the coordinate system to use.
  2547. */
  2548. export enum GLTFLoaderCoordinateSystemMode {
  2549. /**
  2550. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2551. */
  2552. AUTO = 0,
  2553. /**
  2554. * Sets the useRightHandedSystem flag on the scene.
  2555. */
  2556. FORCE_RIGHT_HANDED = 1
  2557. }
  2558. /**
  2559. * Mode that determines what animations will start.
  2560. */
  2561. export enum GLTFLoaderAnimationStartMode {
  2562. /**
  2563. * No animation will start.
  2564. */
  2565. NONE = 0,
  2566. /**
  2567. * The first animation will start.
  2568. */
  2569. FIRST = 1,
  2570. /**
  2571. * All animations will start.
  2572. */
  2573. ALL = 2
  2574. }
  2575. /**
  2576. * Interface that contains the data for the glTF asset.
  2577. */
  2578. export interface IGLTFLoaderData {
  2579. /**
  2580. * The object that represents the glTF JSON.
  2581. */
  2582. json: Object;
  2583. /**
  2584. * The BIN chunk of a binary glTF.
  2585. */
  2586. bin: Nullable<IDataBuffer>;
  2587. }
  2588. /**
  2589. * Interface for extending the loader.
  2590. */
  2591. export interface IGLTFLoaderExtension {
  2592. /**
  2593. * The name of this extension.
  2594. */
  2595. readonly name: string;
  2596. /**
  2597. * Defines whether this extension is enabled.
  2598. */
  2599. enabled: boolean;
  2600. /**
  2601. * Defines the order of this extension.
  2602. * The loader sorts the extensions using these values when loading.
  2603. */
  2604. order?: number;
  2605. }
  2606. /**
  2607. * Loader state.
  2608. */
  2609. export enum GLTFLoaderState {
  2610. /**
  2611. * The asset is loading.
  2612. */
  2613. LOADING = 0,
  2614. /**
  2615. * The asset is ready for rendering.
  2616. */
  2617. READY = 1,
  2618. /**
  2619. * The asset is completely loaded.
  2620. */
  2621. COMPLETE = 2
  2622. }
  2623. /** @hidden */
  2624. export interface IGLTFLoader extends IDisposable {
  2625. readonly state: Nullable<GLTFLoaderState>;
  2626. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  2627. meshes: AbstractMesh[];
  2628. particleSystems: IParticleSystem[];
  2629. skeletons: Skeleton[];
  2630. animationGroups: AnimationGroup[];
  2631. }>;
  2632. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  2633. }
  2634. /**
  2635. * File loader for loading glTF files into a scene.
  2636. */
  2637. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2638. /** @hidden */
  2639. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2640. /** @hidden */
  2641. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2642. /**
  2643. * Raised when the asset has been parsed
  2644. */
  2645. onParsedObservable: Observable<IGLTFLoaderData>;
  2646. private _onParsedObserver;
  2647. /**
  2648. * Raised when the asset has been parsed
  2649. */
  2650. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  2651. /**
  2652. * 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.
  2653. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  2654. * Defaults to true.
  2655. * @hidden
  2656. */
  2657. static IncrementalLoading: boolean;
  2658. /**
  2659. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  2660. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  2661. * @hidden
  2662. */
  2663. static HomogeneousCoordinates: boolean;
  2664. /**
  2665. * The coordinate system mode. Defaults to AUTO.
  2666. */
  2667. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  2668. /**
  2669. * The animation start mode. Defaults to FIRST.
  2670. */
  2671. animationStartMode: GLTFLoaderAnimationStartMode;
  2672. /**
  2673. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2674. */
  2675. compileMaterials: boolean;
  2676. /**
  2677. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2678. */
  2679. useClipPlane: boolean;
  2680. /**
  2681. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2682. */
  2683. compileShadowGenerators: boolean;
  2684. /**
  2685. * Defines if the Alpha blended materials are only applied as coverage.
  2686. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2687. * If true, no extra effects are applied to transparent pixels.
  2688. */
  2689. transparencyAsCoverage: boolean;
  2690. /**
  2691. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  2692. * Enabling will disable offline support and glTF validator.
  2693. * Defaults to false.
  2694. */
  2695. useRangeRequests: boolean;
  2696. /**
  2697. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  2698. */
  2699. createInstances: boolean;
  2700. /**
  2701. * Function called before loading a url referenced by the asset.
  2702. */
  2703. preprocessUrlAsync: (url: string) => Promise<string>;
  2704. /**
  2705. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2706. */
  2707. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  2708. private _onMeshLoadedObserver;
  2709. /**
  2710. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2711. */
  2712. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  2713. /**
  2714. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2715. */
  2716. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  2717. private _onTextureLoadedObserver;
  2718. /**
  2719. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2720. */
  2721. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  2722. /**
  2723. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2724. */
  2725. readonly onMaterialLoadedObservable: Observable<Material>;
  2726. private _onMaterialLoadedObserver;
  2727. /**
  2728. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2729. */
  2730. set onMaterialLoaded(callback: (material: Material) => void);
  2731. /**
  2732. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2733. */
  2734. readonly onCameraLoadedObservable: Observable<Camera>;
  2735. private _onCameraLoadedObserver;
  2736. /**
  2737. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2738. */
  2739. set onCameraLoaded(callback: (camera: Camera) => void);
  2740. /**
  2741. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2742. * For assets with LODs, raised when all of the LODs are complete.
  2743. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2744. */
  2745. readonly onCompleteObservable: Observable<void>;
  2746. private _onCompleteObserver;
  2747. /**
  2748. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2749. * For assets with LODs, raised when all of the LODs are complete.
  2750. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2751. */
  2752. set onComplete(callback: () => void);
  2753. /**
  2754. * Observable raised when an error occurs.
  2755. */
  2756. readonly onErrorObservable: Observable<any>;
  2757. private _onErrorObserver;
  2758. /**
  2759. * Callback raised when an error occurs.
  2760. */
  2761. set onError(callback: (reason: any) => void);
  2762. /**
  2763. * Observable raised after the loader is disposed.
  2764. */
  2765. readonly onDisposeObservable: Observable<void>;
  2766. private _onDisposeObserver;
  2767. /**
  2768. * Callback raised after the loader is disposed.
  2769. */
  2770. set onDispose(callback: () => void);
  2771. /**
  2772. * Observable raised after a loader extension is created.
  2773. * Set additional options for a loader extension in this event.
  2774. */
  2775. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  2776. private _onExtensionLoadedObserver;
  2777. /**
  2778. * Callback raised after a loader extension is created.
  2779. */
  2780. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  2781. /**
  2782. * Defines if the loader logging is enabled.
  2783. */
  2784. get loggingEnabled(): boolean;
  2785. set loggingEnabled(value: boolean);
  2786. /**
  2787. * Defines if the loader should capture performance counters.
  2788. */
  2789. get capturePerformanceCounters(): boolean;
  2790. set capturePerformanceCounters(value: boolean);
  2791. /**
  2792. * Defines if the loader should validate the asset.
  2793. */
  2794. validate: boolean;
  2795. /**
  2796. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2797. */
  2798. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  2799. private _onValidatedObserver;
  2800. /**
  2801. * Callback raised after a loader extension is created.
  2802. */
  2803. set onValidated(callback: (results: BABYLON.GLTF2.IGLTFValidationResults) => void);
  2804. private _loader;
  2805. /**
  2806. * Name of the loader ("gltf")
  2807. */
  2808. name: string;
  2809. /** @hidden */
  2810. extensions: ISceneLoaderPluginExtensions;
  2811. /**
  2812. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2813. */
  2814. dispose(): void;
  2815. /** @hidden */
  2816. _clear(): void;
  2817. /** @hidden */
  2818. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  2819. /** @hidden */
  2820. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  2821. /** @hidden */
  2822. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2823. meshes: AbstractMesh[];
  2824. particleSystems: IParticleSystem[];
  2825. skeletons: Skeleton[];
  2826. animationGroups: AnimationGroup[];
  2827. }>;
  2828. /** @hidden */
  2829. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2830. /** @hidden */
  2831. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2832. /** @hidden */
  2833. canDirectLoad(data: string): boolean;
  2834. /** @hidden */
  2835. directLoad(scene: Scene, data: string): any;
  2836. /**
  2837. * The callback that allows custom handling of the root url based on the response url.
  2838. * @param rootUrl the original root url
  2839. * @param responseURL the response url if available
  2840. * @returns the new root url
  2841. */
  2842. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  2843. /** @hidden */
  2844. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  2845. /**
  2846. * The loader state or null if the loader is not active.
  2847. */
  2848. get loaderState(): Nullable<GLTFLoaderState>;
  2849. /**
  2850. * Returns a promise that resolves when the asset is completely loaded.
  2851. * @returns a promise that resolves when the asset is completely loaded.
  2852. */
  2853. whenCompleteAsync(): Promise<void>;
  2854. private _validateAsync;
  2855. private _getLoader;
  2856. private _parseJson;
  2857. private _unpackBinaryAsync;
  2858. private _unpackBinaryV1Async;
  2859. private _unpackBinaryV2Async;
  2860. private static _parseVersion;
  2861. private static _compareVersion;
  2862. private static readonly _logSpaces;
  2863. private _logIndentLevel;
  2864. private _loggingEnabled;
  2865. /** @hidden */
  2866. _log: (message: string) => void;
  2867. /** @hidden */
  2868. _logOpen(message: string): void;
  2869. /** @hidden */
  2870. _logClose(): void;
  2871. private _logEnabled;
  2872. private _logDisabled;
  2873. private _capturePerformanceCounters;
  2874. /** @hidden */
  2875. _startPerformanceCounter: (counterName: string) => void;
  2876. /** @hidden */
  2877. _endPerformanceCounter: (counterName: string) => void;
  2878. private _startPerformanceCounterEnabled;
  2879. private _startPerformanceCounterDisabled;
  2880. private _endPerformanceCounterEnabled;
  2881. private _endPerformanceCounterDisabled;
  2882. }
  2883. }
  2884. declare module BABYLON.GLTF1 {
  2885. /**
  2886. * Enums
  2887. * @hidden
  2888. */
  2889. export enum EComponentType {
  2890. BYTE = 5120,
  2891. UNSIGNED_BYTE = 5121,
  2892. SHORT = 5122,
  2893. UNSIGNED_SHORT = 5123,
  2894. FLOAT = 5126
  2895. }
  2896. /** @hidden */
  2897. export enum EShaderType {
  2898. FRAGMENT = 35632,
  2899. VERTEX = 35633
  2900. }
  2901. /** @hidden */
  2902. export enum EParameterType {
  2903. BYTE = 5120,
  2904. UNSIGNED_BYTE = 5121,
  2905. SHORT = 5122,
  2906. UNSIGNED_SHORT = 5123,
  2907. INT = 5124,
  2908. UNSIGNED_INT = 5125,
  2909. FLOAT = 5126,
  2910. FLOAT_VEC2 = 35664,
  2911. FLOAT_VEC3 = 35665,
  2912. FLOAT_VEC4 = 35666,
  2913. INT_VEC2 = 35667,
  2914. INT_VEC3 = 35668,
  2915. INT_VEC4 = 35669,
  2916. BOOL = 35670,
  2917. BOOL_VEC2 = 35671,
  2918. BOOL_VEC3 = 35672,
  2919. BOOL_VEC4 = 35673,
  2920. FLOAT_MAT2 = 35674,
  2921. FLOAT_MAT3 = 35675,
  2922. FLOAT_MAT4 = 35676,
  2923. SAMPLER_2D = 35678
  2924. }
  2925. /** @hidden */
  2926. export enum ETextureWrapMode {
  2927. CLAMP_TO_EDGE = 33071,
  2928. MIRRORED_REPEAT = 33648,
  2929. REPEAT = 10497
  2930. }
  2931. /** @hidden */
  2932. export enum ETextureFilterType {
  2933. NEAREST = 9728,
  2934. LINEAR = 9728,
  2935. NEAREST_MIPMAP_NEAREST = 9984,
  2936. LINEAR_MIPMAP_NEAREST = 9985,
  2937. NEAREST_MIPMAP_LINEAR = 9986,
  2938. LINEAR_MIPMAP_LINEAR = 9987
  2939. }
  2940. /** @hidden */
  2941. export enum ETextureFormat {
  2942. ALPHA = 6406,
  2943. RGB = 6407,
  2944. RGBA = 6408,
  2945. LUMINANCE = 6409,
  2946. LUMINANCE_ALPHA = 6410
  2947. }
  2948. /** @hidden */
  2949. export enum ECullingType {
  2950. FRONT = 1028,
  2951. BACK = 1029,
  2952. FRONT_AND_BACK = 1032
  2953. }
  2954. /** @hidden */
  2955. export enum EBlendingFunction {
  2956. ZERO = 0,
  2957. ONE = 1,
  2958. SRC_COLOR = 768,
  2959. ONE_MINUS_SRC_COLOR = 769,
  2960. DST_COLOR = 774,
  2961. ONE_MINUS_DST_COLOR = 775,
  2962. SRC_ALPHA = 770,
  2963. ONE_MINUS_SRC_ALPHA = 771,
  2964. DST_ALPHA = 772,
  2965. ONE_MINUS_DST_ALPHA = 773,
  2966. CONSTANT_COLOR = 32769,
  2967. ONE_MINUS_CONSTANT_COLOR = 32770,
  2968. CONSTANT_ALPHA = 32771,
  2969. ONE_MINUS_CONSTANT_ALPHA = 32772,
  2970. SRC_ALPHA_SATURATE = 776
  2971. }
  2972. /** @hidden */
  2973. export interface IGLTFProperty {
  2974. extensions?: {
  2975. [key: string]: any;
  2976. };
  2977. extras?: Object;
  2978. }
  2979. /** @hidden */
  2980. export interface IGLTFChildRootProperty extends IGLTFProperty {
  2981. name?: string;
  2982. }
  2983. /** @hidden */
  2984. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  2985. bufferView: string;
  2986. byteOffset: number;
  2987. byteStride: number;
  2988. count: number;
  2989. type: string;
  2990. componentType: EComponentType;
  2991. max?: number[];
  2992. min?: number[];
  2993. name?: string;
  2994. }
  2995. /** @hidden */
  2996. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  2997. buffer: string;
  2998. byteOffset: number;
  2999. byteLength: number;
  3000. byteStride: number;
  3001. target?: number;
  3002. }
  3003. /** @hidden */
  3004. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  3005. uri: string;
  3006. byteLength?: number;
  3007. type?: string;
  3008. }
  3009. /** @hidden */
  3010. export interface IGLTFShader extends IGLTFChildRootProperty {
  3011. uri: string;
  3012. type: EShaderType;
  3013. }
  3014. /** @hidden */
  3015. export interface IGLTFProgram extends IGLTFChildRootProperty {
  3016. attributes: string[];
  3017. fragmentShader: string;
  3018. vertexShader: string;
  3019. }
  3020. /** @hidden */
  3021. export interface IGLTFTechniqueParameter {
  3022. type: number;
  3023. count?: number;
  3024. semantic?: string;
  3025. node?: string;
  3026. value?: number | boolean | string | Array<any>;
  3027. source?: string;
  3028. babylonValue?: any;
  3029. }
  3030. /** @hidden */
  3031. export interface IGLTFTechniqueCommonProfile {
  3032. lightingModel: string;
  3033. texcoordBindings: Object;
  3034. parameters?: Array<any>;
  3035. }
  3036. /** @hidden */
  3037. export interface IGLTFTechniqueStatesFunctions {
  3038. blendColor?: number[];
  3039. blendEquationSeparate?: number[];
  3040. blendFuncSeparate?: number[];
  3041. colorMask: boolean[];
  3042. cullFace: number[];
  3043. }
  3044. /** @hidden */
  3045. export interface IGLTFTechniqueStates {
  3046. enable: number[];
  3047. functions: IGLTFTechniqueStatesFunctions;
  3048. }
  3049. /** @hidden */
  3050. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  3051. parameters: {
  3052. [key: string]: IGLTFTechniqueParameter;
  3053. };
  3054. program: string;
  3055. attributes: {
  3056. [key: string]: string;
  3057. };
  3058. uniforms: {
  3059. [key: string]: string;
  3060. };
  3061. states: IGLTFTechniqueStates;
  3062. }
  3063. /** @hidden */
  3064. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  3065. technique?: string;
  3066. values: string[];
  3067. }
  3068. /** @hidden */
  3069. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  3070. attributes: {
  3071. [key: string]: string;
  3072. };
  3073. indices: string;
  3074. material: string;
  3075. mode?: number;
  3076. }
  3077. /** @hidden */
  3078. export interface IGLTFMesh extends IGLTFChildRootProperty {
  3079. primitives: IGLTFMeshPrimitive[];
  3080. }
  3081. /** @hidden */
  3082. export interface IGLTFImage extends IGLTFChildRootProperty {
  3083. uri: string;
  3084. }
  3085. /** @hidden */
  3086. export interface IGLTFSampler extends IGLTFChildRootProperty {
  3087. magFilter?: number;
  3088. minFilter?: number;
  3089. wrapS?: number;
  3090. wrapT?: number;
  3091. }
  3092. /** @hidden */
  3093. export interface IGLTFTexture extends IGLTFChildRootProperty {
  3094. sampler: string;
  3095. source: string;
  3096. format?: ETextureFormat;
  3097. internalFormat?: ETextureFormat;
  3098. target?: number;
  3099. type?: number;
  3100. babylonTexture?: Texture;
  3101. }
  3102. /** @hidden */
  3103. export interface IGLTFAmbienLight {
  3104. color?: number[];
  3105. }
  3106. /** @hidden */
  3107. export interface IGLTFDirectionalLight {
  3108. color?: number[];
  3109. }
  3110. /** @hidden */
  3111. export interface IGLTFPointLight {
  3112. color?: number[];
  3113. constantAttenuation?: number;
  3114. linearAttenuation?: number;
  3115. quadraticAttenuation?: number;
  3116. }
  3117. /** @hidden */
  3118. export interface IGLTFSpotLight {
  3119. color?: number[];
  3120. constantAttenuation?: number;
  3121. fallOfAngle?: number;
  3122. fallOffExponent?: number;
  3123. linearAttenuation?: number;
  3124. quadraticAttenuation?: number;
  3125. }
  3126. /** @hidden */
  3127. export interface IGLTFLight extends IGLTFChildRootProperty {
  3128. type: string;
  3129. }
  3130. /** @hidden */
  3131. export interface IGLTFCameraOrthographic {
  3132. xmag: number;
  3133. ymag: number;
  3134. zfar: number;
  3135. znear: number;
  3136. }
  3137. /** @hidden */
  3138. export interface IGLTFCameraPerspective {
  3139. aspectRatio: number;
  3140. yfov: number;
  3141. zfar: number;
  3142. znear: number;
  3143. }
  3144. /** @hidden */
  3145. export interface IGLTFCamera extends IGLTFChildRootProperty {
  3146. type: string;
  3147. }
  3148. /** @hidden */
  3149. export interface IGLTFAnimationChannelTarget {
  3150. id: string;
  3151. path: string;
  3152. }
  3153. /** @hidden */
  3154. export interface IGLTFAnimationChannel {
  3155. sampler: string;
  3156. target: IGLTFAnimationChannelTarget;
  3157. }
  3158. /** @hidden */
  3159. export interface IGLTFAnimationSampler {
  3160. input: string;
  3161. output: string;
  3162. interpolation?: string;
  3163. }
  3164. /** @hidden */
  3165. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  3166. channels?: IGLTFAnimationChannel[];
  3167. parameters?: {
  3168. [key: string]: string;
  3169. };
  3170. samplers?: {
  3171. [key: string]: IGLTFAnimationSampler;
  3172. };
  3173. }
  3174. /** @hidden */
  3175. export interface IGLTFNodeInstanceSkin {
  3176. skeletons: string[];
  3177. skin: string;
  3178. meshes: string[];
  3179. }
  3180. /** @hidden */
  3181. export interface IGLTFSkins extends IGLTFChildRootProperty {
  3182. bindShapeMatrix: number[];
  3183. inverseBindMatrices: string;
  3184. jointNames: string[];
  3185. babylonSkeleton?: Skeleton;
  3186. }
  3187. /** @hidden */
  3188. export interface IGLTFNode extends IGLTFChildRootProperty {
  3189. camera?: string;
  3190. children: string[];
  3191. skin?: string;
  3192. jointName?: string;
  3193. light?: string;
  3194. matrix: number[];
  3195. mesh?: string;
  3196. meshes?: string[];
  3197. rotation?: number[];
  3198. scale?: number[];
  3199. translation?: number[];
  3200. babylonNode?: Node;
  3201. }
  3202. /** @hidden */
  3203. export interface IGLTFScene extends IGLTFChildRootProperty {
  3204. nodes: string[];
  3205. }
  3206. /** @hidden */
  3207. export interface IGLTFRuntime {
  3208. extensions: {
  3209. [key: string]: any;
  3210. };
  3211. accessors: {
  3212. [key: string]: IGLTFAccessor;
  3213. };
  3214. buffers: {
  3215. [key: string]: IGLTFBuffer;
  3216. };
  3217. bufferViews: {
  3218. [key: string]: IGLTFBufferView;
  3219. };
  3220. meshes: {
  3221. [key: string]: IGLTFMesh;
  3222. };
  3223. lights: {
  3224. [key: string]: IGLTFLight;
  3225. };
  3226. cameras: {
  3227. [key: string]: IGLTFCamera;
  3228. };
  3229. nodes: {
  3230. [key: string]: IGLTFNode;
  3231. };
  3232. images: {
  3233. [key: string]: IGLTFImage;
  3234. };
  3235. textures: {
  3236. [key: string]: IGLTFTexture;
  3237. };
  3238. shaders: {
  3239. [key: string]: IGLTFShader;
  3240. };
  3241. programs: {
  3242. [key: string]: IGLTFProgram;
  3243. };
  3244. samplers: {
  3245. [key: string]: IGLTFSampler;
  3246. };
  3247. techniques: {
  3248. [key: string]: IGLTFTechnique;
  3249. };
  3250. materials: {
  3251. [key: string]: IGLTFMaterial;
  3252. };
  3253. animations: {
  3254. [key: string]: IGLTFAnimation;
  3255. };
  3256. skins: {
  3257. [key: string]: IGLTFSkins;
  3258. };
  3259. currentScene?: Object;
  3260. scenes: {
  3261. [key: string]: IGLTFScene;
  3262. };
  3263. extensionsUsed: string[];
  3264. extensionsRequired?: string[];
  3265. buffersCount: number;
  3266. shaderscount: number;
  3267. scene: Scene;
  3268. rootUrl: string;
  3269. loadedBufferCount: number;
  3270. loadedBufferViews: {
  3271. [name: string]: ArrayBufferView;
  3272. };
  3273. loadedShaderCount: number;
  3274. importOnlyMeshes: boolean;
  3275. importMeshesNames?: string[];
  3276. dummyNodes: Node[];
  3277. }
  3278. /** @hidden */
  3279. export interface INodeToRoot {
  3280. bone: Bone;
  3281. node: IGLTFNode;
  3282. id: string;
  3283. }
  3284. /** @hidden */
  3285. export interface IJointNode {
  3286. node: IGLTFNode;
  3287. id: string;
  3288. }
  3289. }
  3290. declare module BABYLON.GLTF1 {
  3291. /**
  3292. * Utils functions for GLTF
  3293. * @hidden
  3294. */
  3295. export class GLTFUtils {
  3296. /**
  3297. * Sets the given "parameter" matrix
  3298. * @param scene: the Scene object
  3299. * @param source: the source node where to pick the matrix
  3300. * @param parameter: the GLTF technique parameter
  3301. * @param uniformName: the name of the shader's uniform
  3302. * @param shaderMaterial: the shader material
  3303. */
  3304. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  3305. /**
  3306. * Sets the given "parameter" matrix
  3307. * @param shaderMaterial: the shader material
  3308. * @param uniform: the name of the shader's uniform
  3309. * @param value: the value of the uniform
  3310. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3311. */
  3312. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  3313. /**
  3314. * Returns the wrap mode of the texture
  3315. * @param mode: the mode value
  3316. */
  3317. static GetWrapMode(mode: number): number;
  3318. /**
  3319. * Returns the byte stride giving an accessor
  3320. * @param accessor: the GLTF accessor objet
  3321. */
  3322. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  3323. /**
  3324. * Returns the texture filter mode giving a mode value
  3325. * @param mode: the filter mode value
  3326. */
  3327. static GetTextureFilterMode(mode: number): ETextureFilterType;
  3328. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  3329. /**
  3330. * Returns a buffer from its accessor
  3331. * @param gltfRuntime: the GLTF runtime
  3332. * @param accessor: the GLTF accessor
  3333. */
  3334. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  3335. /**
  3336. * Decodes a buffer view into a string
  3337. * @param view: the buffer view
  3338. */
  3339. static DecodeBufferToText(view: ArrayBufferView): string;
  3340. /**
  3341. * Returns the default material of gltf. Related to
  3342. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3343. * @param scene: the Babylon.js scene
  3344. */
  3345. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  3346. private static _DefaultMaterial;
  3347. }
  3348. }
  3349. declare module BABYLON.GLTF1 {
  3350. /**
  3351. * Implementation of the base glTF spec
  3352. * @hidden
  3353. */
  3354. export class GLTFLoaderBase {
  3355. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  3356. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3357. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  3358. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3359. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  3360. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3361. }
  3362. /**
  3363. * glTF V1 Loader
  3364. * @hidden
  3365. */
  3366. export class GLTFLoader implements IGLTFLoader {
  3367. static Extensions: {
  3368. [name: string]: GLTFLoaderExtension;
  3369. };
  3370. static RegisterExtension(extension: GLTFLoaderExtension): void;
  3371. state: Nullable<GLTFLoaderState>;
  3372. dispose(): void;
  3373. private _importMeshAsync;
  3374. /**
  3375. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3376. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3377. * @param scene the scene the meshes should be added to
  3378. * @param data gltf data containing information of the meshes in a loaded file
  3379. * @param rootUrl root url to load from
  3380. * @param onProgress event that fires when loading progress has occured
  3381. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3382. */
  3383. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  3384. meshes: AbstractMesh[];
  3385. particleSystems: IParticleSystem[];
  3386. skeletons: Skeleton[];
  3387. animationGroups: AnimationGroup[];
  3388. }>;
  3389. private _loadAsync;
  3390. /**
  3391. * Imports all objects from a loaded gltf file and adds them to the scene
  3392. * @param scene the scene the objects should be added to
  3393. * @param data gltf data containing information of the meshes in a loaded file
  3394. * @param rootUrl root url to load from
  3395. * @param onProgress event that fires when loading progress has occured
  3396. * @returns a promise which completes when objects have been loaded to the scene
  3397. */
  3398. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  3399. private _loadShadersAsync;
  3400. private _loadBuffersAsync;
  3401. private _createNodes;
  3402. }
  3403. /** @hidden */
  3404. export abstract class GLTFLoaderExtension {
  3405. private _name;
  3406. constructor(name: string);
  3407. get name(): string;
  3408. /**
  3409. * Defines an override for loading the runtime
  3410. * Return true to stop further extensions from loading the runtime
  3411. */
  3412. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  3413. /**
  3414. * Defines an onverride for creating gltf runtime
  3415. * Return true to stop further extensions from creating the runtime
  3416. */
  3417. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  3418. /**
  3419. * Defines an override for loading buffers
  3420. * Return true to stop further extensions from loading this buffer
  3421. */
  3422. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  3423. /**
  3424. * Defines an override for loading texture buffers
  3425. * Return true to stop further extensions from loading this texture data
  3426. */
  3427. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3428. /**
  3429. * Defines an override for creating textures
  3430. * Return true to stop further extensions from loading this texture
  3431. */
  3432. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  3433. /**
  3434. * Defines an override for loading shader strings
  3435. * Return true to stop further extensions from loading this shader data
  3436. */
  3437. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3438. /**
  3439. * Defines an override for loading materials
  3440. * Return true to stop further extensions from loading this material
  3441. */
  3442. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3443. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  3444. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  3445. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3446. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3447. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  3448. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3449. private static LoadTextureBufferAsync;
  3450. private static CreateTextureAsync;
  3451. private static ApplyExtensions;
  3452. }
  3453. }
  3454. declare module BABYLON.GLTF1 {
  3455. /** @hidden */
  3456. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  3457. private _bin;
  3458. constructor();
  3459. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  3460. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3461. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3462. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3463. }
  3464. }
  3465. declare module BABYLON.GLTF1 {
  3466. /** @hidden */
  3467. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  3468. constructor();
  3469. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  3470. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3471. private _loadTexture;
  3472. }
  3473. }
  3474. declare module BABYLON.GLTF2.Loader {
  3475. /**
  3476. * Loader interface with an index field.
  3477. */
  3478. export interface IArrayItem {
  3479. /**
  3480. * The index of this item in the array.
  3481. */
  3482. index: number;
  3483. }
  3484. /**
  3485. * Loader interface with additional members.
  3486. */
  3487. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  3488. /** @hidden */
  3489. _data?: Promise<ArrayBufferView>;
  3490. /** @hidden */
  3491. _babylonVertexBuffer?: Promise<VertexBuffer>;
  3492. }
  3493. /**
  3494. * Loader interface with additional members.
  3495. */
  3496. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  3497. }
  3498. /** @hidden */
  3499. export interface _IAnimationSamplerData {
  3500. input: Float32Array;
  3501. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  3502. output: Float32Array;
  3503. }
  3504. /**
  3505. * Loader interface with additional members.
  3506. */
  3507. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  3508. /** @hidden */
  3509. _data?: Promise<_IAnimationSamplerData>;
  3510. }
  3511. /**
  3512. * Loader interface with additional members.
  3513. */
  3514. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  3515. channels: IAnimationChannel[];
  3516. samplers: IAnimationSampler[];
  3517. /** @hidden */
  3518. _babylonAnimationGroup?: AnimationGroup;
  3519. }
  3520. /**
  3521. * Loader interface with additional members.
  3522. */
  3523. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  3524. /** @hidden */
  3525. _data?: Promise<ArrayBufferView>;
  3526. }
  3527. /**
  3528. * Loader interface with additional members.
  3529. */
  3530. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  3531. /** @hidden */
  3532. _data?: Promise<ArrayBufferView>;
  3533. /** @hidden */
  3534. _babylonBuffer?: Promise<Buffer>;
  3535. }
  3536. /**
  3537. * Loader interface with additional members.
  3538. */
  3539. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  3540. }
  3541. /**
  3542. * Loader interface with additional members.
  3543. */
  3544. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  3545. /** @hidden */
  3546. _data?: Promise<ArrayBufferView>;
  3547. }
  3548. /**
  3549. * Loader interface with additional members.
  3550. */
  3551. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  3552. }
  3553. /**
  3554. * Loader interface with additional members.
  3555. */
  3556. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  3557. }
  3558. /**
  3559. * Loader interface with additional members.
  3560. */
  3561. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  3562. baseColorTexture?: ITextureInfo;
  3563. metallicRoughnessTexture?: ITextureInfo;
  3564. }
  3565. /**
  3566. * Loader interface with additional members.
  3567. */
  3568. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  3569. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  3570. normalTexture?: IMaterialNormalTextureInfo;
  3571. occlusionTexture?: IMaterialOcclusionTextureInfo;
  3572. emissiveTexture?: ITextureInfo;
  3573. /** @hidden */
  3574. _data?: {
  3575. [babylonDrawMode: number]: {
  3576. babylonMaterial: Material;
  3577. babylonMeshes: AbstractMesh[];
  3578. promise: Promise<void>;
  3579. };
  3580. };
  3581. }
  3582. /**
  3583. * Loader interface with additional members.
  3584. */
  3585. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  3586. primitives: IMeshPrimitive[];
  3587. }
  3588. /**
  3589. * Loader interface with additional members.
  3590. */
  3591. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  3592. /** @hidden */
  3593. _instanceData?: {
  3594. babylonSourceMesh: Mesh;
  3595. promise: Promise<any>;
  3596. };
  3597. }
  3598. /**
  3599. * Loader interface with additional members.
  3600. */
  3601. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  3602. /**
  3603. * The parent glTF node.
  3604. */
  3605. parent?: INode;
  3606. /** @hidden */
  3607. _babylonTransformNode?: TransformNode;
  3608. /** @hidden */
  3609. _primitiveBabylonMeshes?: AbstractMesh[];
  3610. /** @hidden */
  3611. _babylonBones?: Bone[];
  3612. /** @hidden */
  3613. _numMorphTargets?: number;
  3614. }
  3615. /** @hidden */
  3616. export interface _ISamplerData {
  3617. noMipMaps: boolean;
  3618. samplingMode: number;
  3619. wrapU: number;
  3620. wrapV: number;
  3621. }
  3622. /**
  3623. * Loader interface with additional members.
  3624. */
  3625. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  3626. /** @hidden */
  3627. _data?: _ISamplerData;
  3628. }
  3629. /**
  3630. * Loader interface with additional members.
  3631. */
  3632. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  3633. }
  3634. /**
  3635. * Loader interface with additional members.
  3636. */
  3637. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  3638. /** @hidden */
  3639. _data?: {
  3640. babylonSkeleton: Skeleton;
  3641. promise: Promise<void>;
  3642. };
  3643. }
  3644. /**
  3645. * Loader interface with additional members.
  3646. */
  3647. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  3648. }
  3649. /**
  3650. * Loader interface with additional members.
  3651. */
  3652. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  3653. }
  3654. /**
  3655. * Loader interface with additional members.
  3656. */
  3657. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  3658. accessors?: IAccessor[];
  3659. animations?: IAnimation[];
  3660. buffers?: IBuffer[];
  3661. bufferViews?: IBufferView[];
  3662. cameras?: ICamera[];
  3663. images?: IImage[];
  3664. materials?: IMaterial[];
  3665. meshes?: IMesh[];
  3666. nodes?: INode[];
  3667. samplers?: ISampler[];
  3668. scenes?: IScene[];
  3669. skins?: ISkin[];
  3670. textures?: ITexture[];
  3671. }
  3672. }
  3673. declare module BABYLON.GLTF2 {
  3674. /**
  3675. * Interface for a glTF loader extension.
  3676. */
  3677. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  3678. /**
  3679. * Called after the loader state changes to LOADING.
  3680. */
  3681. onLoading?(): void;
  3682. /**
  3683. * Called after the loader state changes to READY.
  3684. */
  3685. onReady?(): void;
  3686. /**
  3687. * Define this method to modify the default behavior when loading scenes.
  3688. * @param context The context when loading the asset
  3689. * @param scene The glTF scene property
  3690. * @returns A promise that resolves when the load is complete or null if not handled
  3691. */
  3692. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  3693. /**
  3694. * Define this method to modify the default behavior when loading nodes.
  3695. * @param context The context when loading the asset
  3696. * @param node The glTF node property
  3697. * @param assign A function called synchronously after parsing the glTF properties
  3698. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  3699. */
  3700. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3701. /**
  3702. * Define this method to modify the default behavior when loading cameras.
  3703. * @param context The context when loading the asset
  3704. * @param camera The glTF camera property
  3705. * @param assign A function called synchronously after parsing the glTF properties
  3706. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  3707. */
  3708. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  3709. /**
  3710. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  3711. * @param context The context when loading the asset
  3712. * @param primitive The glTF mesh primitive property
  3713. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  3714. */
  3715. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3716. /**
  3717. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3718. * @param context The context when loading the asset
  3719. * @param name The mesh name when loading the asset
  3720. * @param node The glTF node when loading the asset
  3721. * @param mesh The glTF mesh when loading the asset
  3722. * @param primitive The glTF mesh primitive property
  3723. * @param assign A function called synchronously after parsing the glTF properties
  3724. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3725. */
  3726. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3727. /**
  3728. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  3729. * @param context The context when loading the asset
  3730. * @param material The glTF material property
  3731. * @param assign A function called synchronously after parsing the glTF properties
  3732. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  3733. */
  3734. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3735. /**
  3736. * Define this method to modify the default behavior when creating materials.
  3737. * @param context The context when loading the asset
  3738. * @param material The glTF material property
  3739. * @param babylonDrawMode The draw mode for the Babylon material
  3740. * @returns The Babylon material or null if not handled
  3741. */
  3742. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  3743. /**
  3744. * Define this method to modify the default behavior when loading material properties.
  3745. * @param context The context when loading the asset
  3746. * @param material The glTF material property
  3747. * @param babylonMaterial The Babylon material
  3748. * @returns A promise that resolves when the load is complete or null if not handled
  3749. */
  3750. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3751. /**
  3752. * Define this method to modify the default behavior when loading texture infos.
  3753. * @param context The context when loading the asset
  3754. * @param textureInfo The glTF texture info property
  3755. * @param assign A function called synchronously after parsing the glTF properties
  3756. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  3757. */
  3758. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3759. /**
  3760. * Define this method to modify the default behavior when loading animations.
  3761. * @param context The context when loading the asset
  3762. * @param animation The glTF animation property
  3763. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  3764. */
  3765. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3766. /**
  3767. * @hidden Define this method to modify the default behavior when loading skins.
  3768. * @param context The context when loading the asset
  3769. * @param node The glTF node property
  3770. * @param skin The glTF skin property
  3771. * @returns A promise that resolves when the load is complete or null if not handled
  3772. */
  3773. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  3774. /**
  3775. * @hidden Define this method to modify the default behavior when loading uris.
  3776. * @param context The context when loading the asset
  3777. * @param property The glTF property associated with the uri
  3778. * @param uri The uri to load
  3779. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3780. */
  3781. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  3782. /**
  3783. * Define this method to modify the default behavior when loading buffer views.
  3784. * @param context The context when loading the asset
  3785. * @param bufferView The glTF buffer view property
  3786. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3787. */
  3788. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  3789. /**
  3790. * Define this method to modify the default behavior when loading buffers.
  3791. * @param context The context when loading the asset
  3792. * @param buffer The glTF buffer property
  3793. * @param byteOffset The byte offset to load
  3794. * @param byteLength The byte length to load
  3795. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3796. */
  3797. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  3798. }
  3799. }
  3800. declare module BABYLON.GLTF2 {
  3801. /**
  3802. * Helper class for working with arrays when loading the glTF asset
  3803. */
  3804. export class ArrayItem {
  3805. /**
  3806. * Gets an item from the given array.
  3807. * @param context The context when loading the asset
  3808. * @param array The array to get the item from
  3809. * @param index The index to the array
  3810. * @returns The array item
  3811. */
  3812. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  3813. /**
  3814. * Assign an `index` field to each item of the given array.
  3815. * @param array The array of items
  3816. */
  3817. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  3818. }
  3819. /**
  3820. * The glTF 2.0 loader
  3821. */
  3822. export class GLTFLoader implements IGLTFLoader {
  3823. /** @hidden */
  3824. _completePromises: Promise<any>[];
  3825. private _disposed;
  3826. private _parent;
  3827. private _state;
  3828. private _extensions;
  3829. private _rootUrl;
  3830. private _fileName;
  3831. private _uniqueRootUrl;
  3832. private _gltf;
  3833. private _bin;
  3834. private _babylonScene;
  3835. private _rootBabylonMesh;
  3836. private _defaultBabylonMaterialData;
  3837. private _progressCallback?;
  3838. private _requests;
  3839. private static readonly _DefaultSampler;
  3840. private static _RegisteredExtensions;
  3841. /**
  3842. * Registers a loader extension.
  3843. * @param name The name of the loader extension.
  3844. * @param factory The factory function that creates the loader extension.
  3845. */
  3846. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  3847. /**
  3848. * Unregisters a loader extension.
  3849. * @param name The name of the loader extension.
  3850. * @returns A boolean indicating whether the extension has been unregistered
  3851. */
  3852. static UnregisterExtension(name: string): boolean;
  3853. /**
  3854. * Gets the loader state.
  3855. */
  3856. get state(): Nullable<GLTFLoaderState>;
  3857. /**
  3858. * The object that represents the glTF JSON.
  3859. */
  3860. get gltf(): IGLTF;
  3861. /**
  3862. * The BIN chunk of a binary glTF.
  3863. */
  3864. get bin(): Nullable<IDataBuffer>;
  3865. /**
  3866. * The parent file loader.
  3867. */
  3868. get parent(): GLTFFileLoader;
  3869. /**
  3870. * The Babylon scene when loading the asset.
  3871. */
  3872. get babylonScene(): Scene;
  3873. /**
  3874. * The root Babylon mesh when loading the asset.
  3875. */
  3876. get rootBabylonMesh(): Mesh;
  3877. /** @hidden */
  3878. constructor(parent: GLTFFileLoader);
  3879. /** @hidden */
  3880. dispose(): void;
  3881. /** @hidden */
  3882. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  3883. meshes: AbstractMesh[];
  3884. particleSystems: IParticleSystem[];
  3885. skeletons: Skeleton[];
  3886. animationGroups: AnimationGroup[];
  3887. }>;
  3888. /** @hidden */
  3889. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  3890. private _loadAsync;
  3891. private _loadData;
  3892. private _setupData;
  3893. private _loadExtensions;
  3894. private _checkExtensions;
  3895. private _setState;
  3896. private _createRootNode;
  3897. /**
  3898. * Loads a glTF scene.
  3899. * @param context The context when loading the asset
  3900. * @param scene The glTF scene property
  3901. * @returns A promise that resolves when the load is complete
  3902. */
  3903. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  3904. private _forEachPrimitive;
  3905. private _getMeshes;
  3906. private _getSkeletons;
  3907. private _getAnimationGroups;
  3908. private _startAnimations;
  3909. /**
  3910. * Loads a glTF node.
  3911. * @param context The context when loading the asset
  3912. * @param node The glTF node property
  3913. * @param assign A function called synchronously after parsing the glTF properties
  3914. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  3915. */
  3916. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  3917. private _loadMeshAsync;
  3918. /**
  3919. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3920. * @param context The context when loading the asset
  3921. * @param name The mesh name when loading the asset
  3922. * @param node The glTF node when loading the asset
  3923. * @param mesh The glTF mesh when loading the asset
  3924. * @param primitive The glTF mesh primitive property
  3925. * @param assign A function called synchronously after parsing the glTF properties
  3926. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3927. */
  3928. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3929. private _loadVertexDataAsync;
  3930. private _createMorphTargets;
  3931. private _loadMorphTargetsAsync;
  3932. private _loadMorphTargetVertexDataAsync;
  3933. private static _LoadTransform;
  3934. private _loadSkinAsync;
  3935. private _loadBones;
  3936. private _loadBone;
  3937. private _loadSkinInverseBindMatricesDataAsync;
  3938. private _updateBoneMatrices;
  3939. private _getNodeMatrix;
  3940. /**
  3941. * Loads a glTF camera.
  3942. * @param context The context when loading the asset
  3943. * @param camera The glTF camera property
  3944. * @param assign A function called synchronously after parsing the glTF properties
  3945. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3946. */
  3947. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  3948. private _loadAnimationsAsync;
  3949. /**
  3950. * Loads a glTF animation.
  3951. * @param context The context when loading the asset
  3952. * @param animation The glTF animation property
  3953. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3954. */
  3955. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  3956. /**
  3957. * @hidden Loads a glTF animation channel.
  3958. * @param context The context when loading the asset
  3959. * @param animationContext The context of the animation when loading the asset
  3960. * @param animation The glTF animation property
  3961. * @param channel The glTF animation channel property
  3962. * @param babylonAnimationGroup The babylon animation group property
  3963. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  3964. * @returns A void promise when the channel load is complete
  3965. */
  3966. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  3967. private _loadAnimationSamplerAsync;
  3968. private _loadBufferAsync;
  3969. /**
  3970. * Loads a glTF buffer view.
  3971. * @param context The context when loading the asset
  3972. * @param bufferView The glTF buffer view property
  3973. * @returns A promise that resolves with the loaded data when the load is complete
  3974. */
  3975. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  3976. private _loadAccessorAsync;
  3977. private _loadFloatAccessorAsync;
  3978. private _loadIndicesAccessorAsync;
  3979. private _loadVertexBufferViewAsync;
  3980. private _loadVertexAccessorAsync;
  3981. private _loadMaterialMetallicRoughnessPropertiesAsync;
  3982. /** @hidden */
  3983. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  3984. private _createDefaultMaterial;
  3985. /**
  3986. * Creates a Babylon material from a glTF material.
  3987. * @param context The context when loading the asset
  3988. * @param material The glTF material property
  3989. * @param babylonDrawMode The draw mode for the Babylon material
  3990. * @returns The Babylon material
  3991. */
  3992. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  3993. /**
  3994. * Loads properties from a glTF material into a Babylon material.
  3995. * @param context The context when loading the asset
  3996. * @param material The glTF material property
  3997. * @param babylonMaterial The Babylon material
  3998. * @returns A promise that resolves when the load is complete
  3999. */
  4000. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  4001. /**
  4002. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  4003. * @param context The context when loading the asset
  4004. * @param material The glTF material property
  4005. * @param babylonMaterial The Babylon material
  4006. * @returns A promise that resolves when the load is complete
  4007. */
  4008. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  4009. /**
  4010. * Loads the alpha properties from a glTF material into a Babylon material.
  4011. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  4012. * @param context The context when loading the asset
  4013. * @param material The glTF material property
  4014. * @param babylonMaterial The Babylon material
  4015. */
  4016. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  4017. /**
  4018. * Loads a glTF texture info.
  4019. * @param context The context when loading the asset
  4020. * @param textureInfo The glTF texture info property
  4021. * @param assign A function called synchronously after parsing the glTF properties
  4022. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  4023. */
  4024. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  4025. private _loadTextureAsync;
  4026. private _loadSampler;
  4027. /**
  4028. * Loads a glTF image.
  4029. * @param context The context when loading the asset
  4030. * @param image The glTF image property
  4031. * @returns A promise that resolves with the loaded data when the load is complete
  4032. */
  4033. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  4034. /**
  4035. * Loads a glTF uri.
  4036. * @param context The context when loading the asset
  4037. * @param property The glTF property associated with the uri
  4038. * @param uri The base64 or relative uri
  4039. * @returns A promise that resolves with the loaded data when the load is complete
  4040. */
  4041. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  4042. private _onProgress;
  4043. /**
  4044. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  4045. * @param babylonObject the Babylon object with metadata
  4046. * @param pointer the JSON pointer
  4047. */
  4048. static AddPointerMetadata(babylonObject: {
  4049. metadata: any;
  4050. }, pointer: string): void;
  4051. private static _GetTextureWrapMode;
  4052. private static _GetTextureSamplingMode;
  4053. private static _GetTypedArrayConstructor;
  4054. private static _GetTypedArray;
  4055. private static _GetNumComponents;
  4056. private static _ValidateUri;
  4057. private static _GetDrawMode;
  4058. private _compileMaterialsAsync;
  4059. private _compileShadowGeneratorsAsync;
  4060. private _forEachExtensions;
  4061. private _applyExtensions;
  4062. private _extensionsOnLoading;
  4063. private _extensionsOnReady;
  4064. private _extensionsLoadSceneAsync;
  4065. private _extensionsLoadNodeAsync;
  4066. private _extensionsLoadCameraAsync;
  4067. private _extensionsLoadVertexDataAsync;
  4068. private _extensionsLoadMeshPrimitiveAsync;
  4069. private _extensionsLoadMaterialAsync;
  4070. private _extensionsCreateMaterial;
  4071. private _extensionsLoadMaterialPropertiesAsync;
  4072. private _extensionsLoadTextureInfoAsync;
  4073. private _extensionsLoadAnimationAsync;
  4074. private _extensionsLoadSkinAsync;
  4075. private _extensionsLoadUriAsync;
  4076. private _extensionsLoadBufferViewAsync;
  4077. private _extensionsLoadBufferAsync;
  4078. /**
  4079. * Helper method called by a loader extension to load an glTF extension.
  4080. * @param context The context when loading the asset
  4081. * @param property The glTF property to load the extension from
  4082. * @param extensionName The name of the extension to load
  4083. * @param actionAsync The action to run
  4084. * @returns The promise returned by actionAsync or null if the extension does not exist
  4085. */
  4086. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  4087. /**
  4088. * Helper method called by a loader extension to load a glTF extra.
  4089. * @param context The context when loading the asset
  4090. * @param property The glTF property to load the extra from
  4091. * @param extensionName The name of the extension to load
  4092. * @param actionAsync The action to run
  4093. * @returns The promise returned by actionAsync or null if the extra does not exist
  4094. */
  4095. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  4096. /**
  4097. * Checks for presence of an extension.
  4098. * @param name The name of the extension to check
  4099. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  4100. */
  4101. isExtensionUsed(name: string): boolean;
  4102. /**
  4103. * Increments the indentation level and logs a message.
  4104. * @param message The message to log
  4105. */
  4106. logOpen(message: string): void;
  4107. /**
  4108. * Decrements the indentation level.
  4109. */
  4110. logClose(): void;
  4111. /**
  4112. * Logs a message
  4113. * @param message The message to log
  4114. */
  4115. log(message: string): void;
  4116. /**
  4117. * Starts a performance counter.
  4118. * @param counterName The name of the performance counter
  4119. */
  4120. startPerformanceCounter(counterName: string): void;
  4121. /**
  4122. * Ends a performance counter.
  4123. * @param counterName The name of the performance counter
  4124. */
  4125. endPerformanceCounter(counterName: string): void;
  4126. }
  4127. }
  4128. declare module BABYLON.GLTF2.Loader.Extensions {
  4129. /**
  4130. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  4131. */
  4132. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  4133. /**
  4134. * The name of this extension.
  4135. */
  4136. readonly name: string;
  4137. /**
  4138. * Defines whether this extension is enabled.
  4139. */
  4140. enabled: boolean;
  4141. private _loader;
  4142. private _lights?;
  4143. /** @hidden */
  4144. constructor(loader: GLTFLoader);
  4145. /** @hidden */
  4146. dispose(): void;
  4147. /** @hidden */
  4148. onLoading(): void;
  4149. /** @hidden */
  4150. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4151. private _loadLightAsync;
  4152. }
  4153. }
  4154. declare module BABYLON.GLTF2.Loader.Extensions {
  4155. /**
  4156. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4157. */
  4158. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  4159. /**
  4160. * The name of this extension.
  4161. */
  4162. readonly name: string;
  4163. /**
  4164. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  4165. */
  4166. dracoCompression?: DracoCompression;
  4167. /**
  4168. * Defines whether this extension is enabled.
  4169. */
  4170. enabled: boolean;
  4171. private _loader;
  4172. /** @hidden */
  4173. constructor(loader: GLTFLoader);
  4174. /** @hidden */
  4175. dispose(): void;
  4176. /** @hidden */
  4177. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  4178. }
  4179. }
  4180. declare module BABYLON.GLTF2.Loader.Extensions {
  4181. /**
  4182. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  4183. */
  4184. export class KHR_lights implements IGLTFLoaderExtension {
  4185. /**
  4186. * The name of this extension.
  4187. */
  4188. readonly name: string;
  4189. /**
  4190. * Defines whether this extension is enabled.
  4191. */
  4192. enabled: boolean;
  4193. private _loader;
  4194. private _lights?;
  4195. /** @hidden */
  4196. constructor(loader: GLTFLoader);
  4197. /** @hidden */
  4198. dispose(): void;
  4199. /** @hidden */
  4200. onLoading(): void;
  4201. /** @hidden */
  4202. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4203. }
  4204. }
  4205. declare module BABYLON.GLTF2.Loader.Extensions {
  4206. /**
  4207. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4208. */
  4209. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  4210. /**
  4211. * The name of this extension.
  4212. */
  4213. readonly name: string;
  4214. /**
  4215. * Defines whether this extension is enabled.
  4216. */
  4217. enabled: boolean;
  4218. /**
  4219. * Defines a number that determines the order the extensions are applied.
  4220. */
  4221. order: number;
  4222. private _loader;
  4223. /** @hidden */
  4224. constructor(loader: GLTFLoader);
  4225. /** @hidden */
  4226. dispose(): void;
  4227. /** @hidden */
  4228. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4229. private _loadSpecularGlossinessPropertiesAsync;
  4230. }
  4231. }
  4232. declare module BABYLON.GLTF2.Loader.Extensions {
  4233. /**
  4234. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4235. */
  4236. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  4237. /**
  4238. * The name of this extension.
  4239. */
  4240. readonly name: string;
  4241. /**
  4242. * Defines whether this extension is enabled.
  4243. */
  4244. enabled: boolean;
  4245. /**
  4246. * Defines a number that determines the order the extensions are applied.
  4247. */
  4248. order: number;
  4249. private _loader;
  4250. /** @hidden */
  4251. constructor(loader: GLTFLoader);
  4252. /** @hidden */
  4253. dispose(): void;
  4254. /** @hidden */
  4255. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4256. private _loadUnlitPropertiesAsync;
  4257. }
  4258. }
  4259. declare module BABYLON.GLTF2.Loader.Extensions {
  4260. /**
  4261. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4262. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4263. * !!! Experimental Extension Subject to Changes !!!
  4264. */
  4265. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  4266. /**
  4267. * The name of this extension.
  4268. */
  4269. readonly name: string;
  4270. /**
  4271. * Defines whether this extension is enabled.
  4272. */
  4273. enabled: boolean;
  4274. /**
  4275. * Defines a number that determines the order the extensions are applied.
  4276. */
  4277. order: number;
  4278. private _loader;
  4279. /** @hidden */
  4280. constructor(loader: GLTFLoader);
  4281. /** @hidden */
  4282. dispose(): void;
  4283. /** @hidden */
  4284. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4285. private _loadClearCoatPropertiesAsync;
  4286. }
  4287. }
  4288. declare module BABYLON.GLTF2.Loader.Extensions {
  4289. /**
  4290. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4291. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4292. * !!! Experimental Extension Subject to Changes !!!
  4293. */
  4294. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  4295. /**
  4296. * The name of this extension.
  4297. */
  4298. readonly name: string;
  4299. /**
  4300. * Defines whether this extension is enabled.
  4301. */
  4302. enabled: boolean;
  4303. /**
  4304. * Defines a number that determines the order the extensions are applied.
  4305. */
  4306. order: number;
  4307. private _loader;
  4308. /** @hidden */
  4309. constructor(loader: GLTFLoader);
  4310. /** @hidden */
  4311. dispose(): void;
  4312. /** @hidden */
  4313. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4314. private _loadSheenPropertiesAsync;
  4315. }
  4316. }
  4317. declare module BABYLON.GLTF2.Loader.Extensions {
  4318. /**
  4319. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4320. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4321. * !!! Experimental Extension Subject to Changes !!!
  4322. */
  4323. export class KHR_materials_specular implements IGLTFLoaderExtension {
  4324. /**
  4325. * The name of this extension.
  4326. */
  4327. readonly name: string;
  4328. /**
  4329. * Defines whether this extension is enabled.
  4330. */
  4331. enabled: boolean;
  4332. /**
  4333. * Defines a number that determines the order the extensions are applied.
  4334. */
  4335. order: number;
  4336. private _loader;
  4337. /** @hidden */
  4338. constructor(loader: GLTFLoader);
  4339. /** @hidden */
  4340. dispose(): void;
  4341. /** @hidden */
  4342. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4343. private _loadSpecularPropertiesAsync;
  4344. }
  4345. }
  4346. declare module BABYLON.GLTF2.Loader.Extensions {
  4347. /**
  4348. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  4349. */
  4350. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  4351. /**
  4352. * The name of this extension.
  4353. */
  4354. readonly name: string;
  4355. /**
  4356. * Defines whether this extension is enabled.
  4357. */
  4358. enabled: boolean;
  4359. /** @hidden */
  4360. constructor(loader: GLTFLoader);
  4361. /** @hidden */
  4362. dispose(): void;
  4363. }
  4364. }
  4365. declare module BABYLON.GLTF2.Loader.Extensions {
  4366. /**
  4367. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4368. */
  4369. export class KHR_texture_transform implements IGLTFLoaderExtension {
  4370. /**
  4371. * The name of this extension.
  4372. */
  4373. readonly name: string;
  4374. /**
  4375. * Defines whether this extension is enabled.
  4376. */
  4377. enabled: boolean;
  4378. private _loader;
  4379. /** @hidden */
  4380. constructor(loader: GLTFLoader);
  4381. /** @hidden */
  4382. dispose(): void;
  4383. /** @hidden */
  4384. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  4385. }
  4386. }
  4387. declare module BABYLON.GLTF2.Loader.Extensions {
  4388. /**
  4389. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4390. */
  4391. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  4392. /**
  4393. * The name of this extension.
  4394. */
  4395. readonly name: string;
  4396. /**
  4397. * Defines whether this extension is enabled.
  4398. */
  4399. enabled: boolean;
  4400. private _loader;
  4401. private _clips;
  4402. private _emitters;
  4403. /** @hidden */
  4404. constructor(loader: GLTFLoader);
  4405. /** @hidden */
  4406. dispose(): void;
  4407. /** @hidden */
  4408. onLoading(): void;
  4409. /** @hidden */
  4410. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4411. /** @hidden */
  4412. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4413. /** @hidden */
  4414. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  4415. private _loadClipAsync;
  4416. private _loadEmitterAsync;
  4417. private _getEventAction;
  4418. private _loadAnimationEventAsync;
  4419. }
  4420. }
  4421. declare module BABYLON.GLTF2.Loader.Extensions {
  4422. /**
  4423. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4424. */
  4425. export class MSFT_lod implements IGLTFLoaderExtension {
  4426. /**
  4427. * The name of this extension.
  4428. */
  4429. readonly name: string;
  4430. /**
  4431. * Defines whether this extension is enabled.
  4432. */
  4433. enabled: boolean;
  4434. /**
  4435. * Defines a number that determines the order the extensions are applied.
  4436. */
  4437. order: number;
  4438. /**
  4439. * Maximum number of LODs to load, starting from the lowest LOD.
  4440. */
  4441. maxLODsToLoad: number;
  4442. /**
  4443. * Observable raised when all node LODs of one level are loaded.
  4444. * The event data is the index of the loaded LOD starting from zero.
  4445. * Dispose the loader to cancel the loading of the next level of LODs.
  4446. */
  4447. onNodeLODsLoadedObservable: Observable<number>;
  4448. /**
  4449. * Observable raised when all material LODs of one level are loaded.
  4450. * The event data is the index of the loaded LOD starting from zero.
  4451. * Dispose the loader to cancel the loading of the next level of LODs.
  4452. */
  4453. onMaterialLODsLoadedObservable: Observable<number>;
  4454. private _loader;
  4455. private _nodeIndexLOD;
  4456. private _nodeSignalLODs;
  4457. private _nodePromiseLODs;
  4458. private _materialIndexLOD;
  4459. private _materialSignalLODs;
  4460. private _materialPromiseLODs;
  4461. private _indexLOD;
  4462. private _bufferLODs;
  4463. /** @hidden */
  4464. constructor(loader: GLTFLoader);
  4465. /** @hidden */
  4466. dispose(): void;
  4467. /** @hidden */
  4468. onReady(): void;
  4469. /** @hidden */
  4470. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4471. /** @hidden */
  4472. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  4473. /** @hidden */
  4474. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  4475. /** @hidden */
  4476. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  4477. private _loadBufferLOD;
  4478. /**
  4479. * Gets an array of LOD properties from lowest to highest.
  4480. */
  4481. private _getLODs;
  4482. private _disposeUnusedMaterials;
  4483. }
  4484. }
  4485. declare module BABYLON.GLTF2.Loader.Extensions {
  4486. /** @hidden */
  4487. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  4488. readonly name: string;
  4489. enabled: boolean;
  4490. private _loader;
  4491. constructor(loader: GLTFLoader);
  4492. dispose(): void;
  4493. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4494. }
  4495. }
  4496. declare module BABYLON.GLTF2.Loader.Extensions {
  4497. /** @hidden */
  4498. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  4499. readonly name: string;
  4500. enabled: boolean;
  4501. private _loader;
  4502. constructor(loader: GLTFLoader);
  4503. dispose(): void;
  4504. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4505. }
  4506. }
  4507. declare module BABYLON.GLTF2.Loader.Extensions {
  4508. /**
  4509. * Store glTF extras (if present) in BJS objects' metadata
  4510. */
  4511. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  4512. /**
  4513. * The name of this extension.
  4514. */
  4515. readonly name: string;
  4516. /**
  4517. * Defines whether this extension is enabled.
  4518. */
  4519. enabled: boolean;
  4520. private _loader;
  4521. private _assignExtras;
  4522. /** @hidden */
  4523. constructor(loader: GLTFLoader);
  4524. /** @hidden */
  4525. dispose(): void;
  4526. /** @hidden */
  4527. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4528. /** @hidden */
  4529. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  4530. /** @hidden */
  4531. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  4532. }
  4533. }
  4534. declare module BABYLON {
  4535. /**
  4536. * Class reading and parsing the MTL file bundled with the obj file.
  4537. */
  4538. export class MTLFileLoader {
  4539. /**
  4540. * All material loaded from the mtl will be set here
  4541. */
  4542. materials: StandardMaterial[];
  4543. /**
  4544. * This function will read the mtl file and create each material described inside
  4545. * This function could be improve by adding :
  4546. * -some component missing (Ni, Tf...)
  4547. * -including the specific options available
  4548. *
  4549. * @param scene defines the scene the material will be created in
  4550. * @param data defines the mtl data to parse
  4551. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  4552. */
  4553. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  4554. /**
  4555. * Gets the texture for the material.
  4556. *
  4557. * If the material is imported from input file,
  4558. * We sanitize the url to ensure it takes the textre from aside the material.
  4559. *
  4560. * @param rootUrl The root url to load from
  4561. * @param value The value stored in the mtl
  4562. * @return The Texture
  4563. */
  4564. private static _getTexture;
  4565. }
  4566. /**
  4567. * Options for loading OBJ/MTL files
  4568. */
  4569. type MeshLoadOptions = {
  4570. /**
  4571. * Defines if UVs are optimized by default during load.
  4572. */
  4573. OptimizeWithUV: boolean;
  4574. /**
  4575. * Defines custom scaling of UV coordinates of loaded meshes.
  4576. */
  4577. UVScaling: Vector2;
  4578. /**
  4579. * Invert model on y-axis (does a model scaling inversion)
  4580. */
  4581. InvertY: boolean;
  4582. /**
  4583. * Invert Y-Axis of referenced textures on load
  4584. */
  4585. InvertTextureY: boolean;
  4586. /**
  4587. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4588. */
  4589. ImportVertexColors: boolean;
  4590. /**
  4591. * Compute the normals for the model, even if normals are present in the file.
  4592. */
  4593. ComputeNormals: boolean;
  4594. /**
  4595. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4596. */
  4597. SkipMaterials: boolean;
  4598. /**
  4599. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4600. */
  4601. MaterialLoadingFailsSilently: boolean;
  4602. };
  4603. /**
  4604. * OBJ file type loader.
  4605. * This is a babylon scene loader plugin.
  4606. */
  4607. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  4608. /**
  4609. * Defines if UVs are optimized by default during load.
  4610. */
  4611. static OPTIMIZE_WITH_UV: boolean;
  4612. /**
  4613. * Invert model on y-axis (does a model scaling inversion)
  4614. */
  4615. static INVERT_Y: boolean;
  4616. /**
  4617. * Invert Y-Axis of referenced textures on load
  4618. */
  4619. static INVERT_TEXTURE_Y: boolean;
  4620. /**
  4621. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4622. */
  4623. static IMPORT_VERTEX_COLORS: boolean;
  4624. /**
  4625. * Compute the normals for the model, even if normals are present in the file.
  4626. */
  4627. static COMPUTE_NORMALS: boolean;
  4628. /**
  4629. * Defines custom scaling of UV coordinates of loaded meshes.
  4630. */
  4631. static UV_SCALING: Vector2;
  4632. /**
  4633. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4634. */
  4635. static SKIP_MATERIALS: boolean;
  4636. /**
  4637. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4638. *
  4639. * Defaults to true for backwards compatibility.
  4640. */
  4641. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  4642. /**
  4643. * Defines the name of the plugin.
  4644. */
  4645. name: string;
  4646. /**
  4647. * Defines the extension the plugin is able to load.
  4648. */
  4649. extensions: string;
  4650. /** @hidden */
  4651. obj: RegExp;
  4652. /** @hidden */
  4653. group: RegExp;
  4654. /** @hidden */
  4655. mtllib: RegExp;
  4656. /** @hidden */
  4657. usemtl: RegExp;
  4658. /** @hidden */
  4659. smooth: RegExp;
  4660. /** @hidden */
  4661. vertexPattern: RegExp;
  4662. /** @hidden */
  4663. normalPattern: RegExp;
  4664. /** @hidden */
  4665. uvPattern: RegExp;
  4666. /** @hidden */
  4667. facePattern1: RegExp;
  4668. /** @hidden */
  4669. facePattern2: RegExp;
  4670. /** @hidden */
  4671. facePattern3: RegExp;
  4672. /** @hidden */
  4673. facePattern4: RegExp;
  4674. /** @hidden */
  4675. facePattern5: RegExp;
  4676. private _meshLoadOptions;
  4677. /**
  4678. * Creates loader for .OBJ files
  4679. *
  4680. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  4681. */
  4682. constructor(meshLoadOptions?: MeshLoadOptions);
  4683. private static get currentMeshLoadOptions();
  4684. /**
  4685. * Calls synchronously the MTL file attached to this obj.
  4686. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  4687. * Without this function materials are not displayed in the first frame (but displayed after).
  4688. * In consequence it is impossible to get material information in your HTML file
  4689. *
  4690. * @param url The URL of the MTL file
  4691. * @param rootUrl
  4692. * @param onSuccess Callback function to be called when the MTL file is loaded
  4693. * @private
  4694. */
  4695. private _loadMTL;
  4696. /**
  4697. * Instantiates a OBJ file loader plugin.
  4698. * @returns the created plugin
  4699. */
  4700. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  4701. /**
  4702. * If the data string can be loaded directly.
  4703. *
  4704. * @param data string containing the file data
  4705. * @returns if the data can be loaded directly
  4706. */
  4707. canDirectLoad(data: string): boolean;
  4708. /**
  4709. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  4710. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  4711. * @param scene the scene the meshes should be added to
  4712. * @param data the OBJ data to load
  4713. * @param rootUrl root url to load from
  4714. * @param onProgress event that fires when loading progress has occured
  4715. * @param fileName Defines the name of the file to load
  4716. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  4717. */
  4718. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  4719. meshes: AbstractMesh[];
  4720. particleSystems: IParticleSystem[];
  4721. skeletons: Skeleton[];
  4722. animationGroups: AnimationGroup[];
  4723. }>;
  4724. /**
  4725. * Imports all objects from the loaded OBJ data and adds them to the scene
  4726. * @param scene the scene the objects should be added to
  4727. * @param data the OBJ data to load
  4728. * @param rootUrl root url to load from
  4729. * @param onProgress event that fires when loading progress has occured
  4730. * @param fileName Defines the name of the file to load
  4731. * @returns a promise which completes when objects have been loaded to the scene
  4732. */
  4733. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  4734. /**
  4735. * Load into an asset container.
  4736. * @param scene The scene to load into
  4737. * @param data The data to import
  4738. * @param rootUrl The root url for scene and resources
  4739. * @param onProgress The callback when the load progresses
  4740. * @param fileName Defines the name of the file to load
  4741. * @returns The loaded asset container
  4742. */
  4743. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  4744. /**
  4745. * Read the OBJ file and create an Array of meshes.
  4746. * Each mesh contains all information given by the OBJ and the MTL file.
  4747. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  4748. *
  4749. * @param meshesNames
  4750. * @param scene Scene The scene where are displayed the data
  4751. * @param data String The content of the obj file
  4752. * @param rootUrl String The path to the folder
  4753. * @returns Array<AbstractMesh>
  4754. * @private
  4755. */
  4756. private _parseSolid;
  4757. }
  4758. }
  4759. declare module BABYLON {
  4760. /**
  4761. * STL file type loader.
  4762. * This is a babylon scene loader plugin.
  4763. */
  4764. export class STLFileLoader implements ISceneLoaderPlugin {
  4765. /** @hidden */
  4766. solidPattern: RegExp;
  4767. /** @hidden */
  4768. facetsPattern: RegExp;
  4769. /** @hidden */
  4770. normalPattern: RegExp;
  4771. /** @hidden */
  4772. vertexPattern: RegExp;
  4773. /**
  4774. * Defines the name of the plugin.
  4775. */
  4776. name: string;
  4777. /**
  4778. * Defines the extensions the stl loader is able to load.
  4779. * force data to come in as an ArrayBuffer
  4780. * we'll convert to string if it looks like it's an ASCII .stl
  4781. */
  4782. extensions: ISceneLoaderPluginExtensions;
  4783. /**
  4784. * Import meshes into a scene.
  4785. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  4786. * @param scene The scene to import into
  4787. * @param data The data to import
  4788. * @param rootUrl The root url for scene and resources
  4789. * @param meshes The meshes array to import into
  4790. * @param particleSystems The particle systems array to import into
  4791. * @param skeletons The skeletons array to import into
  4792. * @param onError The callback when import fails
  4793. * @returns True if successful or false otherwise
  4794. */
  4795. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  4796. /**
  4797. * Load into a scene.
  4798. * @param scene The scene to load into
  4799. * @param data The data to import
  4800. * @param rootUrl The root url for scene and resources
  4801. * @param onError The callback when import fails
  4802. * @returns true if successful or false otherwise
  4803. */
  4804. load(scene: Scene, data: any, rootUrl: string): boolean;
  4805. /**
  4806. * Load into an asset container.
  4807. * @param scene The scene to load into
  4808. * @param data The data to import
  4809. * @param rootUrl The root url for scene and resources
  4810. * @param onError The callback when import fails
  4811. * @returns The loaded asset container
  4812. */
  4813. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  4814. private _isBinary;
  4815. private _parseBinary;
  4816. private _parseASCII;
  4817. }
  4818. }