babylonjs.loaders.module.d.ts 202 KB

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